2 * Copyright (c) 2011 Chelsio Communications, Inc.
4 * Written by: Navdeep Parhar <np@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
32 #include "opt_inet6.h"
34 #include <sys/param.h>
37 #include <sys/kernel.h>
39 #include <sys/module.h>
40 #include <sys/malloc.h>
41 #include <sys/queue.h>
42 #include <sys/taskqueue.h>
43 #include <sys/pciio.h>
44 #include <dev/pci/pcireg.h>
45 #include <dev/pci/pcivar.h>
46 #include <dev/pci/pci_private.h>
47 #include <sys/firmware.h>
50 #include <sys/socket.h>
51 #include <sys/sockio.h>
52 #include <sys/sysctl.h>
53 #include <net/ethernet.h>
55 #include <net/if_types.h>
56 #include <net/if_dl.h>
57 #include <net/if_vlan_var.h>
58 #if defined(__i386__) || defined(__amd64__)
63 #include "common/common.h"
64 #include "common/t4_msg.h"
65 #include "common/t4_regs.h"
66 #include "common/t4_regs_values.h"
69 #include "t4_mp_ring.h"
71 /* T4 bus driver interface */
72 static int t4_probe(device_t);
73 static int t4_attach(device_t);
74 static int t4_detach(device_t);
75 static device_method_t t4_methods[] = {
76 DEVMETHOD(device_probe, t4_probe),
77 DEVMETHOD(device_attach, t4_attach),
78 DEVMETHOD(device_detach, t4_detach),
82 static driver_t t4_driver = {
85 sizeof(struct adapter)
89 /* T4 port (cxgbe) interface */
90 static int cxgbe_probe(device_t);
91 static int cxgbe_attach(device_t);
92 static int cxgbe_detach(device_t);
93 static device_method_t cxgbe_methods[] = {
94 DEVMETHOD(device_probe, cxgbe_probe),
95 DEVMETHOD(device_attach, cxgbe_attach),
96 DEVMETHOD(device_detach, cxgbe_detach),
99 static driver_t cxgbe_driver = {
102 sizeof(struct port_info)
105 static d_ioctl_t t4_ioctl;
106 static d_open_t t4_open;
107 static d_close_t t4_close;
109 static struct cdevsw t4_cdevsw = {
110 .d_version = D_VERSION,
118 /* T5 bus driver interface */
119 static int t5_probe(device_t);
120 static device_method_t t5_methods[] = {
121 DEVMETHOD(device_probe, t5_probe),
122 DEVMETHOD(device_attach, t4_attach),
123 DEVMETHOD(device_detach, t4_detach),
127 static driver_t t5_driver = {
130 sizeof(struct adapter)
134 /* T5 port (cxl) interface */
135 static driver_t cxl_driver = {
138 sizeof(struct port_info)
141 static struct cdevsw t5_cdevsw = {
142 .d_version = D_VERSION,
150 /* ifnet + media interface */
151 static void cxgbe_init(void *);
152 static int cxgbe_ioctl(struct ifnet *, unsigned long, caddr_t);
153 static int cxgbe_transmit(struct ifnet *, struct mbuf *);
154 static void cxgbe_qflush(struct ifnet *);
155 static uint64_t cxgbe_get_counter(struct ifnet *, ift_counter);
156 static int cxgbe_media_change(struct ifnet *);
157 static void cxgbe_media_status(struct ifnet *, struct ifmediareq *);
159 MALLOC_DEFINE(M_CXGBE, "cxgbe", "Chelsio T4/T5 Ethernet driver and services");
162 * Correct lock order when you need to acquire multiple locks is t4_list_lock,
163 * then ADAPTER_LOCK, then t4_uld_list_lock.
165 static struct sx t4_list_lock;
166 SLIST_HEAD(, adapter) t4_list;
168 static struct sx t4_uld_list_lock;
169 SLIST_HEAD(, uld_info) t4_uld_list;
173 * Tunables. See tweak_tunables() too.
175 * Each tunable is set to a default value here if it's known at compile-time.
176 * Otherwise it is set to -1 as an indication to tweak_tunables() that it should
177 * provide a reasonable default when the driver is loaded.
179 * Tunables applicable to both T4 and T5 are under hw.cxgbe. Those specific to
180 * T5 are under hw.cxl.
184 * Number of queues for tx and rx, 10G and 1G, NIC and offload.
187 static int t4_ntxq10g = -1;
188 TUNABLE_INT("hw.cxgbe.ntxq10g", &t4_ntxq10g);
191 static int t4_nrxq10g = -1;
192 TUNABLE_INT("hw.cxgbe.nrxq10g", &t4_nrxq10g);
195 static int t4_ntxq1g = -1;
196 TUNABLE_INT("hw.cxgbe.ntxq1g", &t4_ntxq1g);
199 static int t4_nrxq1g = -1;
200 TUNABLE_INT("hw.cxgbe.nrxq1g", &t4_nrxq1g);
202 static int t4_rsrv_noflowq = 0;
203 TUNABLE_INT("hw.cxgbe.rsrv_noflowq", &t4_rsrv_noflowq);
206 #define NOFLDTXQ_10G 8
207 static int t4_nofldtxq10g = -1;
208 TUNABLE_INT("hw.cxgbe.nofldtxq10g", &t4_nofldtxq10g);
210 #define NOFLDRXQ_10G 2
211 static int t4_nofldrxq10g = -1;
212 TUNABLE_INT("hw.cxgbe.nofldrxq10g", &t4_nofldrxq10g);
214 #define NOFLDTXQ_1G 2
215 static int t4_nofldtxq1g = -1;
216 TUNABLE_INT("hw.cxgbe.nofldtxq1g", &t4_nofldtxq1g);
218 #define NOFLDRXQ_1G 1
219 static int t4_nofldrxq1g = -1;
220 TUNABLE_INT("hw.cxgbe.nofldrxq1g", &t4_nofldrxq1g);
225 static int t4_nnmtxq10g = -1;
226 TUNABLE_INT("hw.cxgbe.nnmtxq10g", &t4_nnmtxq10g);
229 static int t4_nnmrxq10g = -1;
230 TUNABLE_INT("hw.cxgbe.nnmrxq10g", &t4_nnmrxq10g);
233 static int t4_nnmtxq1g = -1;
234 TUNABLE_INT("hw.cxgbe.nnmtxq1g", &t4_nnmtxq1g);
237 static int t4_nnmrxq1g = -1;
238 TUNABLE_INT("hw.cxgbe.nnmrxq1g", &t4_nnmrxq1g);
242 * Holdoff parameters for 10G and 1G ports.
244 #define TMR_IDX_10G 1
245 static int t4_tmr_idx_10g = TMR_IDX_10G;
246 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_10G", &t4_tmr_idx_10g);
248 #define PKTC_IDX_10G (-1)
249 static int t4_pktc_idx_10g = PKTC_IDX_10G;
250 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_10G", &t4_pktc_idx_10g);
253 static int t4_tmr_idx_1g = TMR_IDX_1G;
254 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_1G", &t4_tmr_idx_1g);
256 #define PKTC_IDX_1G (-1)
257 static int t4_pktc_idx_1g = PKTC_IDX_1G;
258 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_1G", &t4_pktc_idx_1g);
261 * Size (# of entries) of each tx and rx queue.
263 static unsigned int t4_qsize_txq = TX_EQ_QSIZE;
264 TUNABLE_INT("hw.cxgbe.qsize_txq", &t4_qsize_txq);
266 static unsigned int t4_qsize_rxq = RX_IQ_QSIZE;
267 TUNABLE_INT("hw.cxgbe.qsize_rxq", &t4_qsize_rxq);
270 * Interrupt types allowed (bits 0, 1, 2 = INTx, MSI, MSI-X respectively).
272 static int t4_intr_types = INTR_MSIX | INTR_MSI | INTR_INTX;
273 TUNABLE_INT("hw.cxgbe.interrupt_types", &t4_intr_types);
276 * Configuration file.
278 #define DEFAULT_CF "default"
279 #define FLASH_CF "flash"
280 #define UWIRE_CF "uwire"
281 #define FPGA_CF "fpga"
282 static char t4_cfg_file[32] = DEFAULT_CF;
283 TUNABLE_STR("hw.cxgbe.config_file", t4_cfg_file, sizeof(t4_cfg_file));
286 * PAUSE settings (bit 0, 1 = rx_pause, tx_pause respectively).
287 * rx_pause = 1 to heed incoming PAUSE frames, 0 to ignore them.
288 * tx_pause = 1 to emit PAUSE frames when the rx FIFO reaches its high water
289 * mark or when signalled to do so, 0 to never emit PAUSE.
291 static int t4_pause_settings = PAUSE_TX | PAUSE_RX;
292 TUNABLE_INT("hw.cxgbe.pause_settings", &t4_pause_settings);
295 * Firmware auto-install by driver during attach (0, 1, 2 = prohibited, allowed,
296 * encouraged respectively).
298 static unsigned int t4_fw_install = 1;
299 TUNABLE_INT("hw.cxgbe.fw_install", &t4_fw_install);
302 * ASIC features that will be used. Disable the ones you don't want so that the
303 * chip resources aren't wasted on features that will not be used.
305 static int t4_linkcaps_allowed = 0; /* No DCBX, PPP, etc. by default */
306 TUNABLE_INT("hw.cxgbe.linkcaps_allowed", &t4_linkcaps_allowed);
308 static int t4_niccaps_allowed = FW_CAPS_CONFIG_NIC;
309 TUNABLE_INT("hw.cxgbe.niccaps_allowed", &t4_niccaps_allowed);
311 static int t4_toecaps_allowed = -1;
312 TUNABLE_INT("hw.cxgbe.toecaps_allowed", &t4_toecaps_allowed);
314 static int t4_rdmacaps_allowed = 0;
315 TUNABLE_INT("hw.cxgbe.rdmacaps_allowed", &t4_rdmacaps_allowed);
317 static int t4_iscsicaps_allowed = 0;
318 TUNABLE_INT("hw.cxgbe.iscsicaps_allowed", &t4_iscsicaps_allowed);
320 static int t4_fcoecaps_allowed = 0;
321 TUNABLE_INT("hw.cxgbe.fcoecaps_allowed", &t4_fcoecaps_allowed);
323 static int t5_write_combine = 0;
324 TUNABLE_INT("hw.cxl.write_combine", &t5_write_combine);
326 struct intrs_and_queues {
327 uint16_t intr_type; /* INTx, MSI, or MSI-X */
328 uint16_t nirq; /* Total # of vectors */
329 uint16_t intr_flags_10g;/* Interrupt flags for each 10G port */
330 uint16_t intr_flags_1g; /* Interrupt flags for each 1G port */
331 uint16_t ntxq10g; /* # of NIC txq's for each 10G port */
332 uint16_t nrxq10g; /* # of NIC rxq's for each 10G port */
333 uint16_t ntxq1g; /* # of NIC txq's for each 1G port */
334 uint16_t nrxq1g; /* # of NIC rxq's for each 1G port */
335 uint16_t rsrv_noflowq; /* Flag whether to reserve queue 0 */
337 uint16_t nofldtxq10g; /* # of TOE txq's for each 10G port */
338 uint16_t nofldrxq10g; /* # of TOE rxq's for each 10G port */
339 uint16_t nofldtxq1g; /* # of TOE txq's for each 1G port */
340 uint16_t nofldrxq1g; /* # of TOE rxq's for each 1G port */
343 uint16_t nnmtxq10g; /* # of netmap txq's for each 10G port */
344 uint16_t nnmrxq10g; /* # of netmap rxq's for each 10G port */
345 uint16_t nnmtxq1g; /* # of netmap txq's for each 1G port */
346 uint16_t nnmrxq1g; /* # of netmap rxq's for each 1G port */
350 struct filter_entry {
351 uint32_t valid:1; /* filter allocated and valid */
352 uint32_t locked:1; /* filter is administratively locked */
353 uint32_t pending:1; /* filter action is pending firmware reply */
354 uint32_t smtidx:8; /* Source MAC Table index for smac */
355 struct l2t_entry *l2t; /* Layer Two Table entry for dmac */
357 struct t4_filter_specification fs;
360 static int map_bars_0_and_4(struct adapter *);
361 static int map_bar_2(struct adapter *);
362 static void setup_memwin(struct adapter *);
363 static int validate_mem_range(struct adapter *, uint32_t, int);
364 static int fwmtype_to_hwmtype(int);
365 static int validate_mt_off_len(struct adapter *, int, uint32_t, int,
367 static void memwin_info(struct adapter *, int, uint32_t *, uint32_t *);
368 static uint32_t position_memwin(struct adapter *, int, uint32_t);
369 static int cfg_itype_and_nqueues(struct adapter *, int, int,
370 struct intrs_and_queues *);
371 static int prep_firmware(struct adapter *);
372 static int partition_resources(struct adapter *, const struct firmware *,
374 static int get_params__pre_init(struct adapter *);
375 static int get_params__post_init(struct adapter *);
376 static int set_params__post_init(struct adapter *);
377 static void t4_set_desc(struct adapter *);
378 static void build_medialist(struct port_info *, struct ifmedia *);
379 static int cxgbe_init_synchronized(struct port_info *);
380 static int cxgbe_uninit_synchronized(struct port_info *);
381 static int setup_intr_handlers(struct adapter *);
382 static void quiesce_txq(struct adapter *, struct sge_txq *);
383 static void quiesce_wrq(struct adapter *, struct sge_wrq *);
384 static void quiesce_iq(struct adapter *, struct sge_iq *);
385 static void quiesce_fl(struct adapter *, struct sge_fl *);
386 static int t4_alloc_irq(struct adapter *, struct irq *, int rid,
387 driver_intr_t *, void *, char *);
388 static int t4_free_irq(struct adapter *, struct irq *);
389 static void reg_block_dump(struct adapter *, uint8_t *, unsigned int,
391 static void t4_get_regs(struct adapter *, struct t4_regdump *, uint8_t *);
392 static void cxgbe_refresh_stats(struct adapter *, struct port_info *);
393 static void cxgbe_tick(void *);
394 static void cxgbe_vlan_config(void *, struct ifnet *, uint16_t);
395 static int cpl_not_handled(struct sge_iq *, const struct rss_header *,
397 static int an_not_handled(struct sge_iq *, const struct rsp_ctrl *);
398 static int fw_msg_not_handled(struct adapter *, const __be64 *);
399 static int t4_sysctls(struct adapter *);
400 static int cxgbe_sysctls(struct port_info *);
401 static int sysctl_int_array(SYSCTL_HANDLER_ARGS);
402 static int sysctl_bitfield(SYSCTL_HANDLER_ARGS);
403 static int sysctl_btphy(SYSCTL_HANDLER_ARGS);
404 static int sysctl_noflowq(SYSCTL_HANDLER_ARGS);
405 static int sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS);
406 static int sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS);
407 static int sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS);
408 static int sysctl_qsize_txq(SYSCTL_HANDLER_ARGS);
409 static int sysctl_pause_settings(SYSCTL_HANDLER_ARGS);
410 static int sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS);
411 static int sysctl_temperature(SYSCTL_HANDLER_ARGS);
413 static int sysctl_cctrl(SYSCTL_HANDLER_ARGS);
414 static int sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS);
415 static int sysctl_cim_la(SYSCTL_HANDLER_ARGS);
416 static int sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS);
417 static int sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS);
418 static int sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS);
419 static int sysctl_cpl_stats(SYSCTL_HANDLER_ARGS);
420 static int sysctl_ddp_stats(SYSCTL_HANDLER_ARGS);
421 static int sysctl_devlog(SYSCTL_HANDLER_ARGS);
422 static int sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS);
423 static int sysctl_hw_sched(SYSCTL_HANDLER_ARGS);
424 static int sysctl_lb_stats(SYSCTL_HANDLER_ARGS);
425 static int sysctl_linkdnrc(SYSCTL_HANDLER_ARGS);
426 static int sysctl_meminfo(SYSCTL_HANDLER_ARGS);
427 static int sysctl_mps_tcam(SYSCTL_HANDLER_ARGS);
428 static int sysctl_path_mtus(SYSCTL_HANDLER_ARGS);
429 static int sysctl_pm_stats(SYSCTL_HANDLER_ARGS);
430 static int sysctl_rdma_stats(SYSCTL_HANDLER_ARGS);
431 static int sysctl_tcp_stats(SYSCTL_HANDLER_ARGS);
432 static int sysctl_tids(SYSCTL_HANDLER_ARGS);
433 static int sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS);
434 static int sysctl_tp_la(SYSCTL_HANDLER_ARGS);
435 static int sysctl_tx_rate(SYSCTL_HANDLER_ARGS);
436 static int sysctl_ulprx_la(SYSCTL_HANDLER_ARGS);
437 static int sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS);
439 static uint32_t fconf_to_mode(uint32_t);
440 static uint32_t mode_to_fconf(uint32_t);
441 static uint32_t fspec_to_fconf(struct t4_filter_specification *);
442 static int get_filter_mode(struct adapter *, uint32_t *);
443 static int set_filter_mode(struct adapter *, uint32_t);
444 static inline uint64_t get_filter_hits(struct adapter *, uint32_t);
445 static int get_filter(struct adapter *, struct t4_filter *);
446 static int set_filter(struct adapter *, struct t4_filter *);
447 static int del_filter(struct adapter *, struct t4_filter *);
448 static void clear_filter(struct filter_entry *);
449 static int set_filter_wr(struct adapter *, int);
450 static int del_filter_wr(struct adapter *, int);
451 static int get_sge_context(struct adapter *, struct t4_sge_context *);
452 static int load_fw(struct adapter *, struct t4_data *);
453 static int read_card_mem(struct adapter *, int, struct t4_mem_range *);
454 static int read_i2c(struct adapter *, struct t4_i2c_data *);
455 static int set_sched_class(struct adapter *, struct t4_sched_params *);
456 static int set_sched_queue(struct adapter *, struct t4_sched_queue *);
458 static int toe_capability(struct port_info *, int);
460 static int mod_event(module_t, int, void *);
466 {0xa000, "Chelsio Terminator 4 FPGA"},
467 {0x4400, "Chelsio T440-dbg"},
468 {0x4401, "Chelsio T420-CR"},
469 {0x4402, "Chelsio T422-CR"},
470 {0x4403, "Chelsio T440-CR"},
471 {0x4404, "Chelsio T420-BCH"},
472 {0x4405, "Chelsio T440-BCH"},
473 {0x4406, "Chelsio T440-CH"},
474 {0x4407, "Chelsio T420-SO"},
475 {0x4408, "Chelsio T420-CX"},
476 {0x4409, "Chelsio T420-BT"},
477 {0x440a, "Chelsio T404-BT"},
478 {0x440e, "Chelsio T440-LP-CR"},
480 {0xb000, "Chelsio Terminator 5 FPGA"},
481 {0x5400, "Chelsio T580-dbg"},
482 {0x5401, "Chelsio T520-CR"}, /* 2 x 10G */
483 {0x5402, "Chelsio T522-CR"}, /* 2 x 10G, 2 X 1G */
484 {0x5403, "Chelsio T540-CR"}, /* 4 x 10G */
485 {0x5407, "Chelsio T520-SO"}, /* 2 x 10G, nomem */
486 {0x5409, "Chelsio T520-BT"}, /* 2 x 10GBaseT */
487 {0x540a, "Chelsio T504-BT"}, /* 4 x 1G */
488 {0x540d, "Chelsio T580-CR"}, /* 2 x 40G */
489 {0x540e, "Chelsio T540-LP-CR"}, /* 4 x 10G */
490 {0x5410, "Chelsio T580-LP-CR"}, /* 2 x 40G */
491 {0x5411, "Chelsio T520-LL-CR"}, /* 2 x 10G */
492 {0x5412, "Chelsio T560-CR"}, /* 1 x 40G, 2 x 10G */
493 {0x5414, "Chelsio T580-LP-SO-CR"}, /* 2 x 40G, nomem */
494 {0x5415, "Chelsio T502-BT"}, /* 2 x 1G */
496 {0x5404, "Chelsio T520-BCH"},
497 {0x5405, "Chelsio T540-BCH"},
498 {0x5406, "Chelsio T540-CH"},
499 {0x5408, "Chelsio T520-CX"},
500 {0x540b, "Chelsio B520-SR"},
501 {0x540c, "Chelsio B504-BT"},
502 {0x540f, "Chelsio Amsterdam"},
503 {0x5413, "Chelsio T580-CHR"},
509 * service_iq() has an iq and needs the fl. Offset of fl from the iq should be
510 * exactly the same for both rxq and ofld_rxq.
512 CTASSERT(offsetof(struct sge_ofld_rxq, iq) == offsetof(struct sge_rxq, iq));
513 CTASSERT(offsetof(struct sge_ofld_rxq, fl) == offsetof(struct sge_rxq, fl));
516 /* No easy way to include t4_msg.h before adapter.h so we check this way */
517 CTASSERT(nitems(((struct adapter *)0)->cpl_handler) == NUM_CPL_CMDS);
518 CTASSERT(nitems(((struct adapter *)0)->fw_msg_handler) == NUM_FW6_TYPES);
520 CTASSERT(sizeof(struct cluster_metadata) <= CL_METADATA_SIZE);
523 t4_probe(device_t dev)
526 uint16_t v = pci_get_vendor(dev);
527 uint16_t d = pci_get_device(dev);
528 uint8_t f = pci_get_function(dev);
530 if (v != PCI_VENDOR_ID_CHELSIO)
533 /* Attach only to PF0 of the FPGA */
534 if (d == 0xa000 && f != 0)
537 for (i = 0; i < nitems(t4_pciids); i++) {
538 if (d == t4_pciids[i].device) {
539 device_set_desc(dev, t4_pciids[i].desc);
540 return (BUS_PROBE_DEFAULT);
548 t5_probe(device_t dev)
551 uint16_t v = pci_get_vendor(dev);
552 uint16_t d = pci_get_device(dev);
553 uint8_t f = pci_get_function(dev);
555 if (v != PCI_VENDOR_ID_CHELSIO)
558 /* Attach only to PF0 of the FPGA */
559 if (d == 0xb000 && f != 0)
562 for (i = 0; i < nitems(t5_pciids); i++) {
563 if (d == t5_pciids[i].device) {
564 device_set_desc(dev, t5_pciids[i].desc);
565 return (BUS_PROBE_DEFAULT);
573 t4_attach(device_t dev)
576 int rc = 0, i, n10g, n1g, rqidx, tqidx;
577 struct intrs_and_queues iaq;
580 int ofld_rqidx, ofld_tqidx;
583 int nm_rqidx, nm_tqidx;
587 sc = device_get_softc(dev);
590 pci_enable_busmaster(dev);
591 if (pci_find_cap(dev, PCIY_EXPRESS, &i) == 0) {
594 pci_set_max_read_req(dev, 4096);
595 v = pci_read_config(dev, i + PCIER_DEVICE_CTL, 2);
596 v |= PCIEM_CTL_RELAXED_ORD_ENABLE;
597 pci_write_config(dev, i + PCIER_DEVICE_CTL, v, 2);
599 sc->params.pci.mps = 128 << ((v & PCIEM_CTL_MAX_PAYLOAD) >> 5);
603 mtx_init(&sc->ifp_lock, sc->ifp_lockname, 0, MTX_DEF);
604 snprintf(sc->ifp_lockname, sizeof(sc->ifp_lockname), "%s tracer",
605 device_get_nameunit(dev));
607 snprintf(sc->lockname, sizeof(sc->lockname), "%s",
608 device_get_nameunit(dev));
609 mtx_init(&sc->sc_lock, sc->lockname, 0, MTX_DEF);
610 sx_xlock(&t4_list_lock);
611 SLIST_INSERT_HEAD(&t4_list, sc, link);
612 sx_xunlock(&t4_list_lock);
614 mtx_init(&sc->sfl_lock, "starving freelists", 0, MTX_DEF);
615 TAILQ_INIT(&sc->sfl);
616 callout_init(&sc->sfl_callout, CALLOUT_MPSAFE);
618 mtx_init(&sc->regwin_lock, "register and memory window", 0, MTX_DEF);
620 rc = map_bars_0_and_4(sc);
622 goto done; /* error message displayed already */
625 * This is the real PF# to which we're attaching. Works from within PCI
626 * passthrough environments too, where pci_get_function() could return a
627 * different PF# depending on the passthrough configuration. We need to
628 * use the real PF# in all our communication with the firmware.
630 sc->pf = G_SOURCEPF(t4_read_reg(sc, A_PL_WHOAMI));
633 memset(sc->chan_map, 0xff, sizeof(sc->chan_map));
634 sc->an_handler = an_not_handled;
635 for (i = 0; i < nitems(sc->cpl_handler); i++)
636 sc->cpl_handler[i] = cpl_not_handled;
637 for (i = 0; i < nitems(sc->fw_msg_handler); i++)
638 sc->fw_msg_handler[i] = fw_msg_not_handled;
639 t4_register_cpl_handler(sc, CPL_SET_TCB_RPL, t4_filter_rpl);
640 t4_register_cpl_handler(sc, CPL_TRACE_PKT, t4_trace_pkt);
641 t4_register_cpl_handler(sc, CPL_TRACE_PKT_T5, t5_trace_pkt);
642 t4_init_sge_cpl_handlers(sc);
644 /* Prepare the adapter for operation */
645 rc = -t4_prep_adapter(sc);
647 device_printf(dev, "failed to prepare adapter: %d.\n", rc);
652 * Do this really early, with the memory windows set up even before the
653 * character device. The userland tool's register i/o and mem read
654 * will work even in "recovery mode".
657 sc->cdev = make_dev(is_t4(sc) ? &t4_cdevsw : &t5_cdevsw,
658 device_get_unit(dev), UID_ROOT, GID_WHEEL, 0600, "%s",
659 device_get_nameunit(dev));
660 if (sc->cdev == NULL)
661 device_printf(dev, "failed to create nexus char device.\n");
663 sc->cdev->si_drv1 = sc;
665 /* Go no further if recovery mode has been requested. */
666 if (TUNABLE_INT_FETCH("hw.cxgbe.sos", &i) && i != 0) {
667 device_printf(dev, "recovery mode.\n");
671 #if defined(__i386__)
672 if ((cpu_feature & CPUID_CX8) == 0) {
673 device_printf(dev, "64 bit atomics not available.\n");
679 /* Prepare the firmware for operation */
680 rc = prep_firmware(sc);
682 goto done; /* error message displayed already */
684 rc = get_params__post_init(sc);
686 goto done; /* error message displayed already */
688 rc = set_params__post_init(sc);
690 goto done; /* error message displayed already */
694 goto done; /* error message displayed already */
696 rc = t4_create_dma_tag(sc);
698 goto done; /* error message displayed already */
701 * First pass over all the ports - allocate VIs and initialize some
702 * basic parameters like mac address, port type, etc. We also figure
703 * out whether a port is 10G or 1G and use that information when
704 * calculating how many interrupts to attempt to allocate.
707 for_each_port(sc, i) {
708 struct port_info *pi;
710 pi = malloc(sizeof(*pi), M_CXGBE, M_ZERO | M_WAITOK);
713 /* These must be set before t4_port_init */
717 /* Allocate the vi and initialize parameters like mac addr */
718 rc = -t4_port_init(pi, sc->mbox, sc->pf, 0);
720 device_printf(dev, "unable to initialize port %d: %d\n",
727 pi->link_cfg.requested_fc &= ~(PAUSE_TX | PAUSE_RX);
728 pi->link_cfg.requested_fc |= t4_pause_settings;
729 pi->link_cfg.fc &= ~(PAUSE_TX | PAUSE_RX);
730 pi->link_cfg.fc |= t4_pause_settings;
732 rc = -t4_link_start(sc, sc->mbox, pi->tx_chan, &pi->link_cfg);
734 device_printf(dev, "port %d l1cfg failed: %d\n", i, rc);
740 snprintf(pi->lockname, sizeof(pi->lockname), "%sp%d",
741 device_get_nameunit(dev), i);
742 mtx_init(&pi->pi_lock, pi->lockname, 0, MTX_DEF);
743 sc->chan_map[pi->tx_chan] = i;
745 if (is_10G_port(pi) || is_40G_port(pi)) {
747 pi->tmr_idx = t4_tmr_idx_10g;
748 pi->pktc_idx = t4_pktc_idx_10g;
751 pi->tmr_idx = t4_tmr_idx_1g;
752 pi->pktc_idx = t4_pktc_idx_1g;
755 pi->xact_addr_filt = -1;
758 pi->qsize_rxq = t4_qsize_rxq;
759 pi->qsize_txq = t4_qsize_txq;
761 pi->dev = device_add_child(dev, is_t4(sc) ? "cxgbe" : "cxl", -1);
762 if (pi->dev == NULL) {
764 "failed to add device for port %d.\n", i);
768 device_set_softc(pi->dev, pi);
772 * Interrupt type, # of interrupts, # of rx/tx queues, etc.
774 rc = cfg_itype_and_nqueues(sc, n10g, n1g, &iaq);
776 goto done; /* error message displayed already */
778 sc->intr_type = iaq.intr_type;
779 sc->intr_count = iaq.nirq;
782 s->nrxq = n10g * iaq.nrxq10g + n1g * iaq.nrxq1g;
783 s->ntxq = n10g * iaq.ntxq10g + n1g * iaq.ntxq1g;
784 s->neq = s->ntxq + s->nrxq; /* the free list in an rxq is an eq */
785 s->neq += sc->params.nports + 1;/* ctrl queues: 1 per port + 1 mgmt */
786 s->niq = s->nrxq + 1; /* 1 extra for firmware event queue */
788 if (is_offload(sc)) {
789 s->nofldrxq = n10g * iaq.nofldrxq10g + n1g * iaq.nofldrxq1g;
790 s->nofldtxq = n10g * iaq.nofldtxq10g + n1g * iaq.nofldtxq1g;
791 s->neq += s->nofldtxq + s->nofldrxq;
792 s->niq += s->nofldrxq;
794 s->ofld_rxq = malloc(s->nofldrxq * sizeof(struct sge_ofld_rxq),
795 M_CXGBE, M_ZERO | M_WAITOK);
796 s->ofld_txq = malloc(s->nofldtxq * sizeof(struct sge_wrq),
797 M_CXGBE, M_ZERO | M_WAITOK);
801 s->nnmrxq = n10g * iaq.nnmrxq10g + n1g * iaq.nnmrxq1g;
802 s->nnmtxq = n10g * iaq.nnmtxq10g + n1g * iaq.nnmtxq1g;
803 s->neq += s->nnmtxq + s->nnmrxq;
806 s->nm_rxq = malloc(s->nnmrxq * sizeof(struct sge_nm_rxq),
807 M_CXGBE, M_ZERO | M_WAITOK);
808 s->nm_txq = malloc(s->nnmtxq * sizeof(struct sge_nm_txq),
809 M_CXGBE, M_ZERO | M_WAITOK);
812 s->ctrlq = malloc(sc->params.nports * sizeof(struct sge_wrq), M_CXGBE,
814 s->rxq = malloc(s->nrxq * sizeof(struct sge_rxq), M_CXGBE,
816 s->txq = malloc(s->ntxq * sizeof(struct sge_txq), M_CXGBE,
818 s->iqmap = malloc(s->niq * sizeof(struct sge_iq *), M_CXGBE,
820 s->eqmap = malloc(s->neq * sizeof(struct sge_eq *), M_CXGBE,
823 sc->irq = malloc(sc->intr_count * sizeof(struct irq), M_CXGBE,
826 t4_init_l2t(sc, M_WAITOK);
829 * Second pass over the ports. This time we know the number of rx and
830 * tx queues that each port should get.
834 ofld_rqidx = ofld_tqidx = 0;
837 nm_rqidx = nm_tqidx = 0;
839 for_each_port(sc, i) {
840 struct port_info *pi = sc->port[i];
845 pi->first_rxq = rqidx;
846 pi->first_txq = tqidx;
847 if (is_10G_port(pi) || is_40G_port(pi)) {
848 pi->flags |= iaq.intr_flags_10g;
849 pi->nrxq = iaq.nrxq10g;
850 pi->ntxq = iaq.ntxq10g;
852 pi->flags |= iaq.intr_flags_1g;
853 pi->nrxq = iaq.nrxq1g;
854 pi->ntxq = iaq.ntxq1g;
858 pi->rsrv_noflowq = iaq.rsrv_noflowq ? 1 : 0;
860 pi->rsrv_noflowq = 0;
865 if (is_offload(sc)) {
866 pi->first_ofld_rxq = ofld_rqidx;
867 pi->first_ofld_txq = ofld_tqidx;
868 if (is_10G_port(pi) || is_40G_port(pi)) {
869 pi->nofldrxq = iaq.nofldrxq10g;
870 pi->nofldtxq = iaq.nofldtxq10g;
872 pi->nofldrxq = iaq.nofldrxq1g;
873 pi->nofldtxq = iaq.nofldtxq1g;
875 ofld_rqidx += pi->nofldrxq;
876 ofld_tqidx += pi->nofldtxq;
880 pi->first_nm_rxq = nm_rqidx;
881 pi->first_nm_txq = nm_tqidx;
882 if (is_10G_port(pi) || is_40G_port(pi)) {
883 pi->nnmrxq = iaq.nnmrxq10g;
884 pi->nnmtxq = iaq.nnmtxq10g;
886 pi->nnmrxq = iaq.nnmrxq1g;
887 pi->nnmtxq = iaq.nnmtxq1g;
889 nm_rqidx += pi->nnmrxq;
890 nm_tqidx += pi->nnmtxq;
894 rc = setup_intr_handlers(sc);
897 "failed to setup interrupt handlers: %d\n", rc);
901 rc = bus_generic_attach(dev);
904 "failed to attach all child ports: %d\n", rc);
908 switch (sc->params.pci.speed) {
923 "PCIe x%d (%s GTS/s) (%d), %d ports, %d %s interrupt%s, %d eq, %d iq\n",
924 sc->params.pci.width, pcie_ts, sc->params.pci.speed,
925 sc->params.nports, sc->intr_count,
926 sc->intr_type == INTR_MSIX ? "MSI-X" :
927 (sc->intr_type == INTR_MSI ? "MSI" : "INTx"),
928 sc->intr_count > 1 ? "s" : "", sc->sge.neq, sc->sge.niq);
933 if (rc != 0 && sc->cdev) {
934 /* cdev was created and so cxgbetool works; recover that way. */
936 "error during attach, adapter is now in recovery mode.\n");
952 t4_detach(device_t dev)
955 struct port_info *pi;
958 sc = device_get_softc(dev);
960 if (sc->flags & FULL_INIT_DONE)
964 destroy_dev(sc->cdev);
968 rc = bus_generic_detach(dev);
971 "failed to detach child devices: %d\n", rc);
975 for (i = 0; i < sc->intr_count; i++)
976 t4_free_irq(sc, &sc->irq[i]);
978 for (i = 0; i < MAX_NPORTS; i++) {
981 t4_free_vi(sc, sc->mbox, sc->pf, 0, pi->viid);
983 device_delete_child(dev, pi->dev);
985 mtx_destroy(&pi->pi_lock);
990 if (sc->flags & FULL_INIT_DONE)
991 adapter_full_uninit(sc);
993 if (sc->flags & FW_OK)
994 t4_fw_bye(sc, sc->mbox);
996 if (sc->intr_type == INTR_MSI || sc->intr_type == INTR_MSIX)
997 pci_release_msi(dev);
1000 bus_release_resource(dev, SYS_RES_MEMORY, sc->regs_rid,
1004 bus_release_resource(dev, SYS_RES_MEMORY, sc->udbs_rid,
1008 bus_release_resource(dev, SYS_RES_MEMORY, sc->msix_rid,
1012 t4_free_l2t(sc->l2t);
1015 free(sc->sge.ofld_rxq, M_CXGBE);
1016 free(sc->sge.ofld_txq, M_CXGBE);
1019 free(sc->sge.nm_rxq, M_CXGBE);
1020 free(sc->sge.nm_txq, M_CXGBE);
1022 free(sc->irq, M_CXGBE);
1023 free(sc->sge.rxq, M_CXGBE);
1024 free(sc->sge.txq, M_CXGBE);
1025 free(sc->sge.ctrlq, M_CXGBE);
1026 free(sc->sge.iqmap, M_CXGBE);
1027 free(sc->sge.eqmap, M_CXGBE);
1028 free(sc->tids.ftid_tab, M_CXGBE);
1029 t4_destroy_dma_tag(sc);
1030 if (mtx_initialized(&sc->sc_lock)) {
1031 sx_xlock(&t4_list_lock);
1032 SLIST_REMOVE(&t4_list, sc, adapter, link);
1033 sx_xunlock(&t4_list_lock);
1034 mtx_destroy(&sc->sc_lock);
1037 if (mtx_initialized(&sc->tids.ftid_lock))
1038 mtx_destroy(&sc->tids.ftid_lock);
1039 if (mtx_initialized(&sc->sfl_lock))
1040 mtx_destroy(&sc->sfl_lock);
1041 if (mtx_initialized(&sc->ifp_lock))
1042 mtx_destroy(&sc->ifp_lock);
1043 if (mtx_initialized(&sc->regwin_lock))
1044 mtx_destroy(&sc->regwin_lock);
1046 bzero(sc, sizeof(*sc));
1052 cxgbe_probe(device_t dev)
1055 struct port_info *pi = device_get_softc(dev);
1057 snprintf(buf, sizeof(buf), "port %d", pi->port_id);
1058 device_set_desc_copy(dev, buf);
1060 return (BUS_PROBE_DEFAULT);
1063 #define T4_CAP (IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_HWCSUM | \
1064 IFCAP_VLAN_HWCSUM | IFCAP_TSO | IFCAP_JUMBO_MTU | IFCAP_LRO | \
1065 IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWCSUM_IPV6 | IFCAP_HWSTATS)
1066 #define T4_CAP_ENABLE (T4_CAP)
1069 cxgbe_attach(device_t dev)
1071 struct port_info *pi = device_get_softc(dev);
1076 /* Allocate an ifnet and set it up */
1077 ifp = if_alloc(IFT_ETHER);
1079 device_printf(dev, "Cannot allocate ifnet\n");
1085 callout_init(&pi->tick, CALLOUT_MPSAFE);
1087 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1088 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1090 ifp->if_init = cxgbe_init;
1091 ifp->if_ioctl = cxgbe_ioctl;
1092 ifp->if_transmit = cxgbe_transmit;
1093 ifp->if_qflush = cxgbe_qflush;
1094 ifp->if_get_counter = cxgbe_get_counter;
1096 ifp->if_capabilities = T4_CAP;
1098 if (is_offload(pi->adapter))
1099 ifp->if_capabilities |= IFCAP_TOE;
1101 ifp->if_capenable = T4_CAP_ENABLE;
1102 ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_IP | CSUM_TSO |
1103 CSUM_UDP_IPV6 | CSUM_TCP_IPV6;
1105 ifp->if_hw_tsomax = 65536 - (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
1106 ifp->if_hw_tsomaxsegcount = TX_SGL_SEGS;
1107 ifp->if_hw_tsomaxsegsize = 65536;
1109 /* Initialize ifmedia for this port */
1110 ifmedia_init(&pi->media, IFM_IMASK, cxgbe_media_change,
1111 cxgbe_media_status);
1112 build_medialist(pi, &pi->media);
1114 pi->vlan_c = EVENTHANDLER_REGISTER(vlan_config, cxgbe_vlan_config, ifp,
1115 EVENTHANDLER_PRI_ANY);
1117 ether_ifattach(ifp, pi->hw_addr);
1120 s = malloc(n, M_CXGBE, M_WAITOK);
1121 o = snprintf(s, n, "%d txq, %d rxq (NIC)", pi->ntxq, pi->nrxq);
1124 if (is_offload(pi->adapter)) {
1125 o += snprintf(s + o, n - o, "; %d txq, %d rxq (TOE)",
1126 pi->nofldtxq, pi->nofldrxq);
1131 o += snprintf(s + o, n - o, "; %d txq, %d rxq (netmap)", pi->nnmtxq,
1135 device_printf(dev, "%s\n", s);
1139 /* nm_media handled here to keep implementation private to this file */
1140 ifmedia_init(&pi->nm_media, IFM_IMASK, cxgbe_media_change,
1141 cxgbe_media_status);
1142 build_medialist(pi, &pi->nm_media);
1143 create_netmap_ifnet(pi); /* logs errors it something fails */
1151 cxgbe_detach(device_t dev)
1153 struct port_info *pi = device_get_softc(dev);
1154 struct adapter *sc = pi->adapter;
1155 struct ifnet *ifp = pi->ifp;
1157 /* Tell if_ioctl and if_init that the port is going away */
1162 mtx_sleep(&sc->flags, &sc->sc_lock, 0, "t4detach", 0);
1165 sc->last_op = "t4detach";
1166 sc->last_op_thr = curthread;
1170 if (pi->flags & HAS_TRACEQ) {
1171 sc->traceq = -1; /* cloner should not create ifnet */
1172 t4_tracer_port_detach(sc);
1176 EVENTHANDLER_DEREGISTER(vlan_config, pi->vlan_c);
1179 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1180 callout_stop(&pi->tick);
1182 callout_drain(&pi->tick);
1184 /* Let detach proceed even if these fail. */
1185 cxgbe_uninit_synchronized(pi);
1186 port_full_uninit(pi);
1188 ifmedia_removeall(&pi->media);
1189 ether_ifdetach(pi->ifp);
1193 /* XXXNM: equivalent of cxgbe_uninit_synchronized to ifdown nm_ifp */
1194 destroy_netmap_ifnet(pi);
1206 cxgbe_init(void *arg)
1208 struct port_info *pi = arg;
1209 struct adapter *sc = pi->adapter;
1211 if (begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4init") != 0)
1213 cxgbe_init_synchronized(pi);
1214 end_synchronized_op(sc, 0);
1218 cxgbe_ioctl(struct ifnet *ifp, unsigned long cmd, caddr_t data)
1220 int rc = 0, mtu, flags, can_sleep;
1221 struct port_info *pi = ifp->if_softc;
1222 struct adapter *sc = pi->adapter;
1223 struct ifreq *ifr = (struct ifreq *)data;
1229 if ((mtu < ETHERMIN) || (mtu > ETHERMTU_JUMBO))
1232 rc = begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4mtu");
1236 if (pi->flags & PORT_INIT_DONE) {
1237 t4_update_fl_bufsize(ifp);
1238 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1239 rc = update_mac_settings(ifp, XGMAC_MTU);
1241 end_synchronized_op(sc, 0);
1247 rc = begin_synchronized_op(sc, pi,
1248 can_sleep ? (SLEEP_OK | INTR_OK) : HOLD_LOCK, "t4flg");
1252 if (ifp->if_flags & IFF_UP) {
1253 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1254 flags = pi->if_flags;
1255 if ((ifp->if_flags ^ flags) &
1256 (IFF_PROMISC | IFF_ALLMULTI)) {
1257 if (can_sleep == 1) {
1258 end_synchronized_op(sc, 0);
1262 rc = update_mac_settings(ifp,
1263 XGMAC_PROMISC | XGMAC_ALLMULTI);
1266 if (can_sleep == 0) {
1267 end_synchronized_op(sc, LOCK_HELD);
1271 rc = cxgbe_init_synchronized(pi);
1273 pi->if_flags = ifp->if_flags;
1274 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1275 if (can_sleep == 0) {
1276 end_synchronized_op(sc, LOCK_HELD);
1280 rc = cxgbe_uninit_synchronized(pi);
1282 end_synchronized_op(sc, can_sleep ? 0 : LOCK_HELD);
1286 case SIOCDELMULTI: /* these two are called with a mutex held :-( */
1287 rc = begin_synchronized_op(sc, pi, HOLD_LOCK, "t4multi");
1290 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1291 rc = update_mac_settings(ifp, XGMAC_MCADDRS);
1292 end_synchronized_op(sc, LOCK_HELD);
1296 rc = begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4cap");
1300 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1301 if (mask & IFCAP_TXCSUM) {
1302 ifp->if_capenable ^= IFCAP_TXCSUM;
1303 ifp->if_hwassist ^= (CSUM_TCP | CSUM_UDP | CSUM_IP);
1305 if (IFCAP_TSO4 & ifp->if_capenable &&
1306 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1307 ifp->if_capenable &= ~IFCAP_TSO4;
1309 "tso4 disabled due to -txcsum.\n");
1312 if (mask & IFCAP_TXCSUM_IPV6) {
1313 ifp->if_capenable ^= IFCAP_TXCSUM_IPV6;
1314 ifp->if_hwassist ^= (CSUM_UDP_IPV6 | CSUM_TCP_IPV6);
1316 if (IFCAP_TSO6 & ifp->if_capenable &&
1317 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1318 ifp->if_capenable &= ~IFCAP_TSO6;
1320 "tso6 disabled due to -txcsum6.\n");
1323 if (mask & IFCAP_RXCSUM)
1324 ifp->if_capenable ^= IFCAP_RXCSUM;
1325 if (mask & IFCAP_RXCSUM_IPV6)
1326 ifp->if_capenable ^= IFCAP_RXCSUM_IPV6;
1329 * Note that we leave CSUM_TSO alone (it is always set). The
1330 * kernel takes both IFCAP_TSOx and CSUM_TSO into account before
1331 * sending a TSO request our way, so it's sufficient to toggle
1334 if (mask & IFCAP_TSO4) {
1335 if (!(IFCAP_TSO4 & ifp->if_capenable) &&
1336 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1337 if_printf(ifp, "enable txcsum first.\n");
1341 ifp->if_capenable ^= IFCAP_TSO4;
1343 if (mask & IFCAP_TSO6) {
1344 if (!(IFCAP_TSO6 & ifp->if_capenable) &&
1345 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1346 if_printf(ifp, "enable txcsum6 first.\n");
1350 ifp->if_capenable ^= IFCAP_TSO6;
1352 if (mask & IFCAP_LRO) {
1353 #if defined(INET) || defined(INET6)
1355 struct sge_rxq *rxq;
1357 ifp->if_capenable ^= IFCAP_LRO;
1358 for_each_rxq(pi, i, rxq) {
1359 if (ifp->if_capenable & IFCAP_LRO)
1360 rxq->iq.flags |= IQ_LRO_ENABLED;
1362 rxq->iq.flags &= ~IQ_LRO_ENABLED;
1367 if (mask & IFCAP_TOE) {
1368 int enable = (ifp->if_capenable ^ mask) & IFCAP_TOE;
1370 rc = toe_capability(pi, enable);
1374 ifp->if_capenable ^= mask;
1377 if (mask & IFCAP_VLAN_HWTAGGING) {
1378 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
1379 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1380 rc = update_mac_settings(ifp, XGMAC_VLANEX);
1382 if (mask & IFCAP_VLAN_MTU) {
1383 ifp->if_capenable ^= IFCAP_VLAN_MTU;
1385 /* Need to find out how to disable auto-mtu-inflation */
1387 if (mask & IFCAP_VLAN_HWTSO)
1388 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
1389 if (mask & IFCAP_VLAN_HWCSUM)
1390 ifp->if_capenable ^= IFCAP_VLAN_HWCSUM;
1392 #ifdef VLAN_CAPABILITIES
1393 VLAN_CAPABILITIES(ifp);
1396 end_synchronized_op(sc, 0);
1401 ifmedia_ioctl(ifp, ifr, &pi->media, cmd);
1405 struct ifi2creq i2c;
1407 rc = copyin(ifr->ifr_data, &i2c, sizeof(i2c));
1410 if (i2c.dev_addr != 0xA0 && i2c.dev_addr != 0xA2) {
1414 if (i2c.len > sizeof(i2c.data)) {
1418 rc = begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4i2c");
1421 rc = -t4_i2c_rd(sc, sc->mbox, pi->port_id, i2c.dev_addr,
1422 i2c.offset, i2c.len, &i2c.data[0]);
1423 end_synchronized_op(sc, 0);
1425 rc = copyout(&i2c, ifr->ifr_data, sizeof(i2c));
1430 rc = ether_ioctl(ifp, cmd, data);
1437 cxgbe_transmit(struct ifnet *ifp, struct mbuf *m)
1439 struct port_info *pi = ifp->if_softc;
1440 struct adapter *sc = pi->adapter;
1441 struct sge_txq *txq;
1446 MPASS(m->m_nextpkt == NULL); /* not quite ready for this yet */
1448 if (__predict_false(pi->link_cfg.link_ok == 0)) {
1454 if (__predict_false(rc != 0)) {
1455 MPASS(m == NULL); /* was freed already */
1456 atomic_add_int(&pi->tx_parse_error, 1); /* rare, atomic is ok */
1461 txq = &sc->sge.txq[pi->first_txq];
1462 if (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE)
1463 txq += ((m->m_pkthdr.flowid % (pi->ntxq - pi->rsrv_noflowq)) +
1467 rc = mp_ring_enqueue(txq->r, items, 1, 4096);
1468 if (__predict_false(rc != 0))
1475 cxgbe_qflush(struct ifnet *ifp)
1477 struct port_info *pi = ifp->if_softc;
1478 struct sge_txq *txq;
1481 /* queues do not exist if !PORT_INIT_DONE. */
1482 if (pi->flags & PORT_INIT_DONE) {
1483 for_each_txq(pi, i, txq) {
1485 txq->eq.flags &= ~EQ_ENABLED;
1487 while (!mp_ring_is_idle(txq->r)) {
1488 mp_ring_check_drainage(txq->r, 0);
1497 cxgbe_get_counter(struct ifnet *ifp, ift_counter c)
1499 struct port_info *pi = ifp->if_softc;
1500 struct adapter *sc = pi->adapter;
1501 struct port_stats *s = &pi->stats;
1503 cxgbe_refresh_stats(sc, pi);
1506 case IFCOUNTER_IPACKETS:
1507 return (s->rx_frames - s->rx_pause);
1509 case IFCOUNTER_IERRORS:
1510 return (s->rx_jabber + s->rx_runt + s->rx_too_long +
1511 s->rx_fcs_err + s->rx_len_err);
1513 case IFCOUNTER_OPACKETS:
1514 return (s->tx_frames - s->tx_pause);
1516 case IFCOUNTER_OERRORS:
1517 return (s->tx_error_frames);
1519 case IFCOUNTER_IBYTES:
1520 return (s->rx_octets - s->rx_pause * 64);
1522 case IFCOUNTER_OBYTES:
1523 return (s->tx_octets - s->tx_pause * 64);
1525 case IFCOUNTER_IMCASTS:
1526 return (s->rx_mcast_frames - s->rx_pause);
1528 case IFCOUNTER_OMCASTS:
1529 return (s->tx_mcast_frames - s->tx_pause);
1531 case IFCOUNTER_IQDROPS:
1532 return (s->rx_ovflow0 + s->rx_ovflow1 + s->rx_ovflow2 +
1533 s->rx_ovflow3 + s->rx_trunc0 + s->rx_trunc1 + s->rx_trunc2 +
1534 s->rx_trunc3 + pi->tnl_cong_drops);
1536 case IFCOUNTER_OQDROPS: {
1540 if (pi->flags & PORT_INIT_DONE) {
1542 struct sge_txq *txq;
1544 for_each_txq(pi, i, txq)
1545 drops += counter_u64_fetch(txq->r->drops);
1553 return (if_get_counter_default(ifp, c));
1558 cxgbe_media_change(struct ifnet *ifp)
1560 struct port_info *pi = ifp->if_softc;
1562 device_printf(pi->dev, "%s unimplemented.\n", __func__);
1564 return (EOPNOTSUPP);
1568 cxgbe_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
1570 struct port_info *pi = ifp->if_softc;
1571 struct ifmedia *media = NULL;
1572 struct ifmedia_entry *cur;
1573 int speed = pi->link_cfg.speed;
1575 int data = (pi->port_type << 8) | pi->mod_type;
1581 else if (ifp == pi->nm_ifp)
1582 media = &pi->nm_media;
1584 MPASS(media != NULL);
1586 cur = media->ifm_cur;
1587 MPASS(cur->ifm_data == data);
1589 ifmr->ifm_status = IFM_AVALID;
1590 if (!pi->link_cfg.link_ok)
1593 ifmr->ifm_status |= IFM_ACTIVE;
1595 /* active and current will differ iff current media is autoselect. */
1596 if (IFM_SUBTYPE(cur->ifm_media) != IFM_AUTO)
1599 ifmr->ifm_active = IFM_ETHER | IFM_FDX;
1600 if (speed == SPEED_10000)
1601 ifmr->ifm_active |= IFM_10G_T;
1602 else if (speed == SPEED_1000)
1603 ifmr->ifm_active |= IFM_1000_T;
1604 else if (speed == SPEED_100)
1605 ifmr->ifm_active |= IFM_100_TX;
1606 else if (speed == SPEED_10)
1607 ifmr->ifm_active |= IFM_10_T;
1609 KASSERT(0, ("%s: link up but speed unknown (%u)", __func__,
1614 t4_fatal_err(struct adapter *sc)
1616 t4_set_reg_field(sc, A_SGE_CONTROL, F_GLOBALENABLE, 0);
1617 t4_intr_disable(sc);
1618 log(LOG_EMERG, "%s: encountered fatal error, adapter stopped.\n",
1619 device_get_nameunit(sc->dev));
1623 map_bars_0_and_4(struct adapter *sc)
1625 sc->regs_rid = PCIR_BAR(0);
1626 sc->regs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
1627 &sc->regs_rid, RF_ACTIVE);
1628 if (sc->regs_res == NULL) {
1629 device_printf(sc->dev, "cannot map registers.\n");
1632 sc->bt = rman_get_bustag(sc->regs_res);
1633 sc->bh = rman_get_bushandle(sc->regs_res);
1634 sc->mmio_len = rman_get_size(sc->regs_res);
1635 setbit(&sc->doorbells, DOORBELL_KDB);
1637 sc->msix_rid = PCIR_BAR(4);
1638 sc->msix_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
1639 &sc->msix_rid, RF_ACTIVE);
1640 if (sc->msix_res == NULL) {
1641 device_printf(sc->dev, "cannot map MSI-X BAR.\n");
1649 map_bar_2(struct adapter *sc)
1653 * T4: only iWARP driver uses the userspace doorbells. There is no need
1654 * to map it if RDMA is disabled.
1656 if (is_t4(sc) && sc->rdmacaps == 0)
1659 sc->udbs_rid = PCIR_BAR(2);
1660 sc->udbs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
1661 &sc->udbs_rid, RF_ACTIVE);
1662 if (sc->udbs_res == NULL) {
1663 device_printf(sc->dev, "cannot map doorbell BAR.\n");
1666 sc->udbs_base = rman_get_virtual(sc->udbs_res);
1669 setbit(&sc->doorbells, DOORBELL_UDB);
1670 #if defined(__i386__) || defined(__amd64__)
1671 if (t5_write_combine) {
1675 * Enable write combining on BAR2. This is the
1676 * userspace doorbell BAR and is split into 128B
1677 * (UDBS_SEG_SIZE) doorbell regions, each associated
1678 * with an egress queue. The first 64B has the doorbell
1679 * and the second 64B can be used to submit a tx work
1680 * request with an implicit doorbell.
1683 rc = pmap_change_attr((vm_offset_t)sc->udbs_base,
1684 rman_get_size(sc->udbs_res), PAT_WRITE_COMBINING);
1686 clrbit(&sc->doorbells, DOORBELL_UDB);
1687 setbit(&sc->doorbells, DOORBELL_WCWR);
1688 setbit(&sc->doorbells, DOORBELL_UDBWC);
1690 device_printf(sc->dev,
1691 "couldn't enable write combining: %d\n",
1695 t4_write_reg(sc, A_SGE_STAT_CFG,
1696 V_STATSOURCE_T5(7) | V_STATMODE(0));
1704 static const struct memwin t4_memwin[] = {
1705 { MEMWIN0_BASE, MEMWIN0_APERTURE },
1706 { MEMWIN1_BASE, MEMWIN1_APERTURE },
1707 { MEMWIN2_BASE_T4, MEMWIN2_APERTURE_T4 }
1710 static const struct memwin t5_memwin[] = {
1711 { MEMWIN0_BASE, MEMWIN0_APERTURE },
1712 { MEMWIN1_BASE, MEMWIN1_APERTURE },
1713 { MEMWIN2_BASE_T5, MEMWIN2_APERTURE_T5 },
1717 setup_memwin(struct adapter *sc)
1719 const struct memwin *mw;
1725 * Read low 32b of bar0 indirectly via the hardware backdoor
1726 * mechanism. Works from within PCI passthrough environments
1727 * too, where rman_get_start() can return a different value. We
1728 * need to program the T4 memory window decoders with the actual
1729 * addresses that will be coming across the PCIe link.
1731 bar0 = t4_hw_pci_read_cfg4(sc, PCIR_BAR(0));
1732 bar0 &= (uint32_t) PCIM_BAR_MEM_BASE;
1735 n = nitems(t4_memwin);
1737 /* T5 uses the relative offset inside the PCIe BAR */
1741 n = nitems(t5_memwin);
1744 for (i = 0; i < n; i++, mw++) {
1746 PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, i),
1747 (mw->base + bar0) | V_BIR(0) |
1748 V_WINDOW(ilog2(mw->aperture) - 10));
1752 t4_read_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 2));
1756 * Verify that the memory range specified by the addr/len pair is valid and lies
1757 * entirely within a single region (EDCx or MCx).
1760 validate_mem_range(struct adapter *sc, uint32_t addr, int len)
1762 uint32_t em, addr_len, maddr, mlen;
1764 /* Memory can only be accessed in naturally aligned 4 byte units */
1765 if (addr & 3 || len & 3 || len == 0)
1768 /* Enabled memories */
1769 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
1770 if (em & F_EDRAM0_ENABLE) {
1771 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
1772 maddr = G_EDRAM0_BASE(addr_len) << 20;
1773 mlen = G_EDRAM0_SIZE(addr_len) << 20;
1774 if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1775 addr + len <= maddr + mlen)
1778 if (em & F_EDRAM1_ENABLE) {
1779 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
1780 maddr = G_EDRAM1_BASE(addr_len) << 20;
1781 mlen = G_EDRAM1_SIZE(addr_len) << 20;
1782 if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1783 addr + len <= maddr + mlen)
1786 if (em & F_EXT_MEM_ENABLE) {
1787 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
1788 maddr = G_EXT_MEM_BASE(addr_len) << 20;
1789 mlen = G_EXT_MEM_SIZE(addr_len) << 20;
1790 if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1791 addr + len <= maddr + mlen)
1794 if (!is_t4(sc) && em & F_EXT_MEM1_ENABLE) {
1795 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
1796 maddr = G_EXT_MEM1_BASE(addr_len) << 20;
1797 mlen = G_EXT_MEM1_SIZE(addr_len) << 20;
1798 if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1799 addr + len <= maddr + mlen)
1807 fwmtype_to_hwmtype(int mtype)
1811 case FW_MEMTYPE_EDC0:
1813 case FW_MEMTYPE_EDC1:
1815 case FW_MEMTYPE_EXTMEM:
1817 case FW_MEMTYPE_EXTMEM1:
1820 panic("%s: cannot translate fw mtype %d.", __func__, mtype);
1825 * Verify that the memory range specified by the memtype/offset/len pair is
1826 * valid and lies entirely within the memtype specified. The global address of
1827 * the start of the range is returned in addr.
1830 validate_mt_off_len(struct adapter *sc, int mtype, uint32_t off, int len,
1833 uint32_t em, addr_len, maddr, mlen;
1835 /* Memory can only be accessed in naturally aligned 4 byte units */
1836 if (off & 3 || len & 3 || len == 0)
1839 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
1840 switch (fwmtype_to_hwmtype(mtype)) {
1842 if (!(em & F_EDRAM0_ENABLE))
1844 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
1845 maddr = G_EDRAM0_BASE(addr_len) << 20;
1846 mlen = G_EDRAM0_SIZE(addr_len) << 20;
1849 if (!(em & F_EDRAM1_ENABLE))
1851 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
1852 maddr = G_EDRAM1_BASE(addr_len) << 20;
1853 mlen = G_EDRAM1_SIZE(addr_len) << 20;
1856 if (!(em & F_EXT_MEM_ENABLE))
1858 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
1859 maddr = G_EXT_MEM_BASE(addr_len) << 20;
1860 mlen = G_EXT_MEM_SIZE(addr_len) << 20;
1863 if (is_t4(sc) || !(em & F_EXT_MEM1_ENABLE))
1865 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
1866 maddr = G_EXT_MEM1_BASE(addr_len) << 20;
1867 mlen = G_EXT_MEM1_SIZE(addr_len) << 20;
1873 if (mlen > 0 && off < mlen && off + len <= mlen) {
1874 *addr = maddr + off; /* global address */
1882 memwin_info(struct adapter *sc, int win, uint32_t *base, uint32_t *aperture)
1884 const struct memwin *mw;
1887 KASSERT(win >= 0 && win < nitems(t4_memwin),
1888 ("%s: incorrect memwin# (%d)", __func__, win));
1889 mw = &t4_memwin[win];
1891 KASSERT(win >= 0 && win < nitems(t5_memwin),
1892 ("%s: incorrect memwin# (%d)", __func__, win));
1893 mw = &t5_memwin[win];
1898 if (aperture != NULL)
1899 *aperture = mw->aperture;
1903 * Positions the memory window such that it can be used to access the specified
1904 * address in the chip's address space. The return value is the offset of addr
1905 * from the start of the window.
1908 position_memwin(struct adapter *sc, int n, uint32_t addr)
1913 KASSERT(n >= 0 && n <= 3,
1914 ("%s: invalid window %d.", __func__, n));
1915 KASSERT((addr & 3) == 0,
1916 ("%s: addr (0x%x) is not at a 4B boundary.", __func__, addr));
1920 start = addr & ~0xf; /* start must be 16B aligned */
1922 pf = V_PFNUM(sc->pf);
1923 start = addr & ~0x7f; /* start must be 128B aligned */
1925 reg = PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, n);
1927 t4_write_reg(sc, reg, start | pf);
1928 t4_read_reg(sc, reg);
1930 return (addr - start);
1934 cfg_itype_and_nqueues(struct adapter *sc, int n10g, int n1g,
1935 struct intrs_and_queues *iaq)
1937 int rc, itype, navail, nrxq10g, nrxq1g, n;
1938 int nofldrxq10g = 0, nofldrxq1g = 0;
1939 int nnmrxq10g = 0, nnmrxq1g = 0;
1941 bzero(iaq, sizeof(*iaq));
1943 iaq->ntxq10g = t4_ntxq10g;
1944 iaq->ntxq1g = t4_ntxq1g;
1945 iaq->nrxq10g = nrxq10g = t4_nrxq10g;
1946 iaq->nrxq1g = nrxq1g = t4_nrxq1g;
1947 iaq->rsrv_noflowq = t4_rsrv_noflowq;
1949 if (is_offload(sc)) {
1950 iaq->nofldtxq10g = t4_nofldtxq10g;
1951 iaq->nofldtxq1g = t4_nofldtxq1g;
1952 iaq->nofldrxq10g = nofldrxq10g = t4_nofldrxq10g;
1953 iaq->nofldrxq1g = nofldrxq1g = t4_nofldrxq1g;
1957 iaq->nnmtxq10g = t4_nnmtxq10g;
1958 iaq->nnmtxq1g = t4_nnmtxq1g;
1959 iaq->nnmrxq10g = nnmrxq10g = t4_nnmrxq10g;
1960 iaq->nnmrxq1g = nnmrxq1g = t4_nnmrxq1g;
1963 for (itype = INTR_MSIX; itype; itype >>= 1) {
1965 if ((itype & t4_intr_types) == 0)
1966 continue; /* not allowed */
1968 if (itype == INTR_MSIX)
1969 navail = pci_msix_count(sc->dev);
1970 else if (itype == INTR_MSI)
1971 navail = pci_msi_count(sc->dev);
1978 iaq->intr_type = itype;
1979 iaq->intr_flags_10g = 0;
1980 iaq->intr_flags_1g = 0;
1983 * Best option: an interrupt vector for errors, one for the
1984 * firmware event queue, and one for every rxq (NIC, TOE, and
1987 iaq->nirq = T4_EXTRA_INTR;
1988 iaq->nirq += n10g * (nrxq10g + nofldrxq10g + nnmrxq10g);
1989 iaq->nirq += n1g * (nrxq1g + nofldrxq1g + nnmrxq1g);
1990 if (iaq->nirq <= navail &&
1991 (itype != INTR_MSI || powerof2(iaq->nirq))) {
1992 iaq->intr_flags_10g = INTR_ALL;
1993 iaq->intr_flags_1g = INTR_ALL;
1998 * Second best option: a vector for errors, one for the firmware
1999 * event queue, and vectors for either all the NIC rx queues or
2000 * all the TOE rx queues. The queues that don't get vectors
2001 * will forward their interrupts to those that do.
2003 * Note: netmap rx queues cannot be created early and so they
2004 * can't be setup to receive forwarded interrupts for others.
2006 iaq->nirq = T4_EXTRA_INTR;
2007 if (nrxq10g >= nofldrxq10g) {
2008 iaq->intr_flags_10g = INTR_RXQ;
2009 iaq->nirq += n10g * nrxq10g;
2011 iaq->nnmrxq10g = min(nnmrxq10g, nrxq10g);
2014 iaq->intr_flags_10g = INTR_OFLD_RXQ;
2015 iaq->nirq += n10g * nofldrxq10g;
2017 iaq->nnmrxq10g = min(nnmrxq10g, nofldrxq10g);
2020 if (nrxq1g >= nofldrxq1g) {
2021 iaq->intr_flags_1g = INTR_RXQ;
2022 iaq->nirq += n1g * nrxq1g;
2024 iaq->nnmrxq1g = min(nnmrxq1g, nrxq1g);
2027 iaq->intr_flags_1g = INTR_OFLD_RXQ;
2028 iaq->nirq += n1g * nofldrxq1g;
2030 iaq->nnmrxq1g = min(nnmrxq1g, nofldrxq1g);
2033 if (iaq->nirq <= navail &&
2034 (itype != INTR_MSI || powerof2(iaq->nirq)))
2038 * Next best option: an interrupt vector for errors, one for the
2039 * firmware event queue, and at least one per port. At this
2040 * point we know we'll have to downsize nrxq and/or nofldrxq
2041 * and/or nnmrxq to fit what's available to us.
2043 iaq->nirq = T4_EXTRA_INTR;
2044 iaq->nirq += n10g + n1g;
2045 if (iaq->nirq <= navail) {
2046 int leftover = navail - iaq->nirq;
2049 int target = max(nrxq10g, nofldrxq10g);
2051 iaq->intr_flags_10g = nrxq10g >= nofldrxq10g ?
2052 INTR_RXQ : INTR_OFLD_RXQ;
2055 while (n < target && leftover >= n10g) {
2060 iaq->nrxq10g = min(n, nrxq10g);
2062 iaq->nofldrxq10g = min(n, nofldrxq10g);
2065 iaq->nnmrxq10g = min(n, nnmrxq10g);
2070 int target = max(nrxq1g, nofldrxq1g);
2072 iaq->intr_flags_1g = nrxq1g >= nofldrxq1g ?
2073 INTR_RXQ : INTR_OFLD_RXQ;
2076 while (n < target && leftover >= n1g) {
2081 iaq->nrxq1g = min(n, nrxq1g);
2083 iaq->nofldrxq1g = min(n, nofldrxq1g);
2086 iaq->nnmrxq1g = min(n, nnmrxq1g);
2090 if (itype != INTR_MSI || powerof2(iaq->nirq))
2095 * Least desirable option: one interrupt vector for everything.
2097 iaq->nirq = iaq->nrxq10g = iaq->nrxq1g = 1;
2098 iaq->intr_flags_10g = iaq->intr_flags_1g = 0;
2101 iaq->nofldrxq10g = iaq->nofldrxq1g = 1;
2104 iaq->nnmrxq10g = iaq->nnmrxq1g = 1;
2110 if (itype == INTR_MSIX)
2111 rc = pci_alloc_msix(sc->dev, &navail);
2112 else if (itype == INTR_MSI)
2113 rc = pci_alloc_msi(sc->dev, &navail);
2116 if (navail == iaq->nirq)
2120 * Didn't get the number requested. Use whatever number
2121 * the kernel is willing to allocate (it's in navail).
2123 device_printf(sc->dev, "fewer vectors than requested, "
2124 "type=%d, req=%d, rcvd=%d; will downshift req.\n",
2125 itype, iaq->nirq, navail);
2126 pci_release_msi(sc->dev);
2130 device_printf(sc->dev,
2131 "failed to allocate vectors:%d, type=%d, req=%d, rcvd=%d\n",
2132 itype, rc, iaq->nirq, navail);
2135 device_printf(sc->dev,
2136 "failed to find a usable interrupt type. "
2137 "allowed=%d, msi-x=%d, msi=%d, intx=1", t4_intr_types,
2138 pci_msix_count(sc->dev), pci_msi_count(sc->dev));
2143 #define FW_VERSION(chip) ( \
2144 V_FW_HDR_FW_VER_MAJOR(chip##FW_VERSION_MAJOR) | \
2145 V_FW_HDR_FW_VER_MINOR(chip##FW_VERSION_MINOR) | \
2146 V_FW_HDR_FW_VER_MICRO(chip##FW_VERSION_MICRO) | \
2147 V_FW_HDR_FW_VER_BUILD(chip##FW_VERSION_BUILD))
2148 #define FW_INTFVER(chip, intf) (chip##FW_HDR_INTFVER_##intf)
2154 struct fw_hdr fw_hdr; /* XXX: waste of space, need a sparse struct */
2158 .kld_name = "t4fw_cfg",
2159 .fw_mod_name = "t4fw",
2161 .chip = FW_HDR_CHIP_T4,
2162 .fw_ver = htobe32_const(FW_VERSION(T4)),
2163 .intfver_nic = FW_INTFVER(T4, NIC),
2164 .intfver_vnic = FW_INTFVER(T4, VNIC),
2165 .intfver_ofld = FW_INTFVER(T4, OFLD),
2166 .intfver_ri = FW_INTFVER(T4, RI),
2167 .intfver_iscsipdu = FW_INTFVER(T4, ISCSIPDU),
2168 .intfver_iscsi = FW_INTFVER(T4, ISCSI),
2169 .intfver_fcoepdu = FW_INTFVER(T4, FCOEPDU),
2170 .intfver_fcoe = FW_INTFVER(T4, FCOE),
2174 .kld_name = "t5fw_cfg",
2175 .fw_mod_name = "t5fw",
2177 .chip = FW_HDR_CHIP_T5,
2178 .fw_ver = htobe32_const(FW_VERSION(T5)),
2179 .intfver_nic = FW_INTFVER(T5, NIC),
2180 .intfver_vnic = FW_INTFVER(T5, VNIC),
2181 .intfver_ofld = FW_INTFVER(T5, OFLD),
2182 .intfver_ri = FW_INTFVER(T5, RI),
2183 .intfver_iscsipdu = FW_INTFVER(T5, ISCSIPDU),
2184 .intfver_iscsi = FW_INTFVER(T5, ISCSI),
2185 .intfver_fcoepdu = FW_INTFVER(T5, FCOEPDU),
2186 .intfver_fcoe = FW_INTFVER(T5, FCOE),
2191 static struct fw_info *
2192 find_fw_info(int chip)
2196 for (i = 0; i < nitems(fw_info); i++) {
2197 if (fw_info[i].chip == chip)
2198 return (&fw_info[i]);
2204 * Is the given firmware API compatible with the one the driver was compiled
2208 fw_compatible(const struct fw_hdr *hdr1, const struct fw_hdr *hdr2)
2211 /* short circuit if it's the exact same firmware version */
2212 if (hdr1->chip == hdr2->chip && hdr1->fw_ver == hdr2->fw_ver)
2216 * XXX: Is this too conservative? Perhaps I should limit this to the
2217 * features that are supported in the driver.
2219 #define SAME_INTF(x) (hdr1->intfver_##x == hdr2->intfver_##x)
2220 if (hdr1->chip == hdr2->chip && SAME_INTF(nic) && SAME_INTF(vnic) &&
2221 SAME_INTF(ofld) && SAME_INTF(ri) && SAME_INTF(iscsipdu) &&
2222 SAME_INTF(iscsi) && SAME_INTF(fcoepdu) && SAME_INTF(fcoe))
2230 * The firmware in the KLD is usable, but should it be installed? This routine
2231 * explains itself in detail if it indicates the KLD firmware should be
2235 should_install_kld_fw(struct adapter *sc, int card_fw_usable, int k, int c)
2239 if (!card_fw_usable) {
2240 reason = "incompatible or unusable";
2245 reason = "older than the version bundled with this driver";
2249 if (t4_fw_install == 2 && k != c) {
2250 reason = "different than the version bundled with this driver";
2257 if (t4_fw_install == 0) {
2258 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
2259 "but the driver is prohibited from installing a different "
2260 "firmware on the card.\n",
2261 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
2262 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason);
2267 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
2268 "installing firmware %u.%u.%u.%u on card.\n",
2269 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
2270 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason,
2271 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
2272 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
2277 * Establish contact with the firmware and determine if we are the master driver
2278 * or not, and whether we are responsible for chip initialization.
2281 prep_firmware(struct adapter *sc)
2283 const struct firmware *fw = NULL, *default_cfg;
2284 int rc, pf, card_fw_usable, kld_fw_usable, need_fw_reset = 1;
2285 enum dev_state state;
2286 struct fw_info *fw_info;
2287 struct fw_hdr *card_fw; /* fw on the card */
2288 const struct fw_hdr *kld_fw; /* fw in the KLD */
2289 const struct fw_hdr *drv_fw; /* fw header the driver was compiled
2292 /* Contact firmware. */
2293 rc = t4_fw_hello(sc, sc->mbox, sc->mbox, MASTER_MAY, &state);
2294 if (rc < 0 || state == DEV_STATE_ERR) {
2296 device_printf(sc->dev,
2297 "failed to connect to the firmware: %d, %d.\n", rc, state);
2302 sc->flags |= MASTER_PF;
2303 else if (state == DEV_STATE_UNINIT) {
2305 * We didn't get to be the master so we definitely won't be
2306 * configuring the chip. It's a bug if someone else hasn't
2307 * configured it already.
2309 device_printf(sc->dev, "couldn't be master(%d), "
2310 "device not already initialized either(%d).\n", rc, state);
2314 /* This is the firmware whose headers the driver was compiled against */
2315 fw_info = find_fw_info(chip_id(sc));
2316 if (fw_info == NULL) {
2317 device_printf(sc->dev,
2318 "unable to look up firmware information for chip %d.\n",
2322 drv_fw = &fw_info->fw_hdr;
2325 * The firmware KLD contains many modules. The KLD name is also the
2326 * name of the module that contains the default config file.
2328 default_cfg = firmware_get(fw_info->kld_name);
2330 /* Read the header of the firmware on the card */
2331 card_fw = malloc(sizeof(*card_fw), M_CXGBE, M_ZERO | M_WAITOK);
2332 rc = -t4_read_flash(sc, FLASH_FW_START,
2333 sizeof (*card_fw) / sizeof (uint32_t), (uint32_t *)card_fw, 1);
2335 card_fw_usable = fw_compatible(drv_fw, (const void*)card_fw);
2337 device_printf(sc->dev,
2338 "Unable to read card's firmware header: %d\n", rc);
2342 /* This is the firmware in the KLD */
2343 fw = firmware_get(fw_info->fw_mod_name);
2345 kld_fw = (const void *)fw->data;
2346 kld_fw_usable = fw_compatible(drv_fw, kld_fw);
2352 if (card_fw_usable && card_fw->fw_ver == drv_fw->fw_ver &&
2353 (!kld_fw_usable || kld_fw->fw_ver == drv_fw->fw_ver)) {
2355 * Common case: the firmware on the card is an exact match and
2356 * the KLD is an exact match too, or the KLD is
2357 * absent/incompatible. Note that t4_fw_install = 2 is ignored
2358 * here -- use cxgbetool loadfw if you want to reinstall the
2359 * same firmware as the one on the card.
2361 } else if (kld_fw_usable && state == DEV_STATE_UNINIT &&
2362 should_install_kld_fw(sc, card_fw_usable, be32toh(kld_fw->fw_ver),
2363 be32toh(card_fw->fw_ver))) {
2365 rc = -t4_fw_upgrade(sc, sc->mbox, fw->data, fw->datasize, 0);
2367 device_printf(sc->dev,
2368 "failed to install firmware: %d\n", rc);
2372 /* Installed successfully, update the cached header too. */
2373 memcpy(card_fw, kld_fw, sizeof(*card_fw));
2375 need_fw_reset = 0; /* already reset as part of load_fw */
2378 if (!card_fw_usable) {
2381 d = ntohl(drv_fw->fw_ver);
2382 c = ntohl(card_fw->fw_ver);
2383 k = kld_fw ? ntohl(kld_fw->fw_ver) : 0;
2385 device_printf(sc->dev, "Cannot find a usable firmware: "
2386 "fw_install %d, chip state %d, "
2387 "driver compiled with %d.%d.%d.%d, "
2388 "card has %d.%d.%d.%d, KLD has %d.%d.%d.%d\n",
2389 t4_fw_install, state,
2390 G_FW_HDR_FW_VER_MAJOR(d), G_FW_HDR_FW_VER_MINOR(d),
2391 G_FW_HDR_FW_VER_MICRO(d), G_FW_HDR_FW_VER_BUILD(d),
2392 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
2393 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c),
2394 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
2395 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
2400 /* We're using whatever's on the card and it's known to be good. */
2401 sc->params.fw_vers = ntohl(card_fw->fw_ver);
2402 snprintf(sc->fw_version, sizeof(sc->fw_version), "%u.%u.%u.%u",
2403 G_FW_HDR_FW_VER_MAJOR(sc->params.fw_vers),
2404 G_FW_HDR_FW_VER_MINOR(sc->params.fw_vers),
2405 G_FW_HDR_FW_VER_MICRO(sc->params.fw_vers),
2406 G_FW_HDR_FW_VER_BUILD(sc->params.fw_vers));
2407 t4_get_tp_version(sc, &sc->params.tp_vers);
2410 if (need_fw_reset &&
2411 (rc = -t4_fw_reset(sc, sc->mbox, F_PIORSTMODE | F_PIORST)) != 0) {
2412 device_printf(sc->dev, "firmware reset failed: %d.\n", rc);
2413 if (rc != ETIMEDOUT && rc != EIO)
2414 t4_fw_bye(sc, sc->mbox);
2419 rc = get_params__pre_init(sc);
2421 goto done; /* error message displayed already */
2423 /* Partition adapter resources as specified in the config file. */
2424 if (state == DEV_STATE_UNINIT) {
2426 KASSERT(sc->flags & MASTER_PF,
2427 ("%s: trying to change chip settings when not master.",
2430 rc = partition_resources(sc, default_cfg, fw_info->kld_name);
2432 goto done; /* error message displayed already */
2434 t4_tweak_chip_settings(sc);
2436 /* get basic stuff going */
2437 rc = -t4_fw_initialize(sc, sc->mbox);
2439 device_printf(sc->dev, "fw init failed: %d.\n", rc);
2443 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "pf%d", pf);
2448 free(card_fw, M_CXGBE);
2450 firmware_put(fw, FIRMWARE_UNLOAD);
2451 if (default_cfg != NULL)
2452 firmware_put(default_cfg, FIRMWARE_UNLOAD);
2457 #define FW_PARAM_DEV(param) \
2458 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
2459 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
2460 #define FW_PARAM_PFVF(param) \
2461 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
2462 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param))
2465 * Partition chip resources for use between various PFs, VFs, etc.
2468 partition_resources(struct adapter *sc, const struct firmware *default_cfg,
2469 const char *name_prefix)
2471 const struct firmware *cfg = NULL;
2473 struct fw_caps_config_cmd caps;
2474 uint32_t mtype, moff, finicsum, cfcsum;
2477 * Figure out what configuration file to use. Pick the default config
2478 * file for the card if the user hasn't specified one explicitly.
2480 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", t4_cfg_file);
2481 if (strncmp(t4_cfg_file, DEFAULT_CF, sizeof(t4_cfg_file)) == 0) {
2482 /* Card specific overrides go here. */
2483 if (pci_get_device(sc->dev) == 0x440a)
2484 snprintf(sc->cfg_file, sizeof(sc->cfg_file), UWIRE_CF);
2486 snprintf(sc->cfg_file, sizeof(sc->cfg_file), FPGA_CF);
2490 * We need to load another module if the profile is anything except
2491 * "default" or "flash".
2493 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) != 0 &&
2494 strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
2497 snprintf(s, sizeof(s), "%s_%s", name_prefix, sc->cfg_file);
2498 cfg = firmware_get(s);
2500 if (default_cfg != NULL) {
2501 device_printf(sc->dev,
2502 "unable to load module \"%s\" for "
2503 "configuration profile \"%s\", will use "
2504 "the default config file instead.\n",
2506 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
2509 device_printf(sc->dev,
2510 "unable to load module \"%s\" for "
2511 "configuration profile \"%s\", will use "
2512 "the config file on the card's flash "
2513 "instead.\n", s, sc->cfg_file);
2514 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
2520 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) == 0 &&
2521 default_cfg == NULL) {
2522 device_printf(sc->dev,
2523 "default config file not available, will use the config "
2524 "file on the card's flash instead.\n");
2525 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", FLASH_CF);
2528 if (strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
2530 const uint32_t *cfdata;
2531 uint32_t param, val, addr, off, mw_base, mw_aperture;
2533 KASSERT(cfg != NULL || default_cfg != NULL,
2534 ("%s: no config to upload", __func__));
2537 * Ask the firmware where it wants us to upload the config file.
2539 param = FW_PARAM_DEV(CF);
2540 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
2542 /* No support for config file? Shouldn't happen. */
2543 device_printf(sc->dev,
2544 "failed to query config file location: %d.\n", rc);
2547 mtype = G_FW_PARAMS_PARAM_Y(val);
2548 moff = G_FW_PARAMS_PARAM_Z(val) << 16;
2551 * XXX: sheer laziness. We deliberately added 4 bytes of
2552 * useless stuffing/comments at the end of the config file so
2553 * it's ok to simply throw away the last remaining bytes when
2554 * the config file is not an exact multiple of 4. This also
2555 * helps with the validate_mt_off_len check.
2558 cflen = cfg->datasize & ~3;
2561 cflen = default_cfg->datasize & ~3;
2562 cfdata = default_cfg->data;
2565 if (cflen > FLASH_CFG_MAX_SIZE) {
2566 device_printf(sc->dev,
2567 "config file too long (%d, max allowed is %d). "
2568 "Will try to use the config on the card, if any.\n",
2569 cflen, FLASH_CFG_MAX_SIZE);
2570 goto use_config_on_flash;
2573 rc = validate_mt_off_len(sc, mtype, moff, cflen, &addr);
2575 device_printf(sc->dev,
2576 "%s: addr (%d/0x%x) or len %d is not valid: %d. "
2577 "Will try to use the config on the card, if any.\n",
2578 __func__, mtype, moff, cflen, rc);
2579 goto use_config_on_flash;
2582 memwin_info(sc, 2, &mw_base, &mw_aperture);
2584 off = position_memwin(sc, 2, addr);
2585 n = min(cflen, mw_aperture - off);
2586 for (i = 0; i < n; i += 4)
2587 t4_write_reg(sc, mw_base + off + i, *cfdata++);
2592 use_config_on_flash:
2593 mtype = FW_MEMTYPE_FLASH;
2594 moff = t4_flash_cfg_addr(sc);
2597 bzero(&caps, sizeof(caps));
2598 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
2599 F_FW_CMD_REQUEST | F_FW_CMD_READ);
2600 caps.cfvalid_to_len16 = htobe32(F_FW_CAPS_CONFIG_CMD_CFVALID |
2601 V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
2602 V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(moff >> 16) | FW_LEN16(caps));
2603 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
2605 device_printf(sc->dev,
2606 "failed to pre-process config file: %d "
2607 "(mtype %d, moff 0x%x).\n", rc, mtype, moff);
2611 finicsum = be32toh(caps.finicsum);
2612 cfcsum = be32toh(caps.cfcsum);
2613 if (finicsum != cfcsum) {
2614 device_printf(sc->dev,
2615 "WARNING: config file checksum mismatch: %08x %08x\n",
2618 sc->cfcsum = cfcsum;
2620 #define LIMIT_CAPS(x) do { \
2621 caps.x &= htobe16(t4_##x##_allowed); \
2625 * Let the firmware know what features will (not) be used so it can tune
2626 * things accordingly.
2628 LIMIT_CAPS(linkcaps);
2629 LIMIT_CAPS(niccaps);
2630 LIMIT_CAPS(toecaps);
2631 LIMIT_CAPS(rdmacaps);
2632 LIMIT_CAPS(iscsicaps);
2633 LIMIT_CAPS(fcoecaps);
2636 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
2637 F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
2638 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
2639 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), NULL);
2641 device_printf(sc->dev,
2642 "failed to process config file: %d.\n", rc);
2646 firmware_put(cfg, FIRMWARE_UNLOAD);
2651 * Retrieve parameters that are needed (or nice to have) very early.
2654 get_params__pre_init(struct adapter *sc)
2657 uint32_t param[2], val[2];
2658 struct fw_devlog_cmd cmd;
2659 struct devlog_params *dlog = &sc->params.devlog;
2661 param[0] = FW_PARAM_DEV(PORTVEC);
2662 param[1] = FW_PARAM_DEV(CCLK);
2663 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
2665 device_printf(sc->dev,
2666 "failed to query parameters (pre_init): %d.\n", rc);
2670 sc->params.portvec = val[0];
2671 sc->params.nports = bitcount32(val[0]);
2672 sc->params.vpd.cclk = val[1];
2674 /* Read device log parameters. */
2675 bzero(&cmd, sizeof(cmd));
2676 cmd.op_to_write = htobe32(V_FW_CMD_OP(FW_DEVLOG_CMD) |
2677 F_FW_CMD_REQUEST | F_FW_CMD_READ);
2678 cmd.retval_len16 = htobe32(FW_LEN16(cmd));
2679 rc = -t4_wr_mbox(sc, sc->mbox, &cmd, sizeof(cmd), &cmd);
2681 device_printf(sc->dev,
2682 "failed to get devlog parameters: %d.\n", rc);
2683 bzero(dlog, sizeof (*dlog));
2684 rc = 0; /* devlog isn't critical for device operation */
2686 val[0] = be32toh(cmd.memtype_devlog_memaddr16_devlog);
2687 dlog->memtype = G_FW_DEVLOG_CMD_MEMTYPE_DEVLOG(val[0]);
2688 dlog->start = G_FW_DEVLOG_CMD_MEMADDR16_DEVLOG(val[0]) << 4;
2689 dlog->size = be32toh(cmd.memsize_devlog);
2696 * Retrieve various parameters that are of interest to the driver. The device
2697 * has been initialized by the firmware at this point.
2700 get_params__post_init(struct adapter *sc)
2703 uint32_t param[7], val[7];
2704 struct fw_caps_config_cmd caps;
2706 param[0] = FW_PARAM_PFVF(IQFLINT_START);
2707 param[1] = FW_PARAM_PFVF(EQ_START);
2708 param[2] = FW_PARAM_PFVF(FILTER_START);
2709 param[3] = FW_PARAM_PFVF(FILTER_END);
2710 param[4] = FW_PARAM_PFVF(L2T_START);
2711 param[5] = FW_PARAM_PFVF(L2T_END);
2712 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
2714 device_printf(sc->dev,
2715 "failed to query parameters (post_init): %d.\n", rc);
2719 sc->sge.iq_start = val[0];
2720 sc->sge.eq_start = val[1];
2721 sc->tids.ftid_base = val[2];
2722 sc->tids.nftids = val[3] - val[2] + 1;
2723 sc->params.ftid_min = val[2];
2724 sc->params.ftid_max = val[3];
2725 sc->vres.l2t.start = val[4];
2726 sc->vres.l2t.size = val[5] - val[4] + 1;
2727 KASSERT(sc->vres.l2t.size <= L2T_SIZE,
2728 ("%s: L2 table size (%u) larger than expected (%u)",
2729 __func__, sc->vres.l2t.size, L2T_SIZE));
2731 /* get capabilites */
2732 bzero(&caps, sizeof(caps));
2733 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
2734 F_FW_CMD_REQUEST | F_FW_CMD_READ);
2735 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
2736 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
2738 device_printf(sc->dev,
2739 "failed to get card capabilities: %d.\n", rc);
2743 #define READ_CAPS(x) do { \
2744 sc->x = htobe16(caps.x); \
2746 READ_CAPS(linkcaps);
2749 READ_CAPS(rdmacaps);
2750 READ_CAPS(iscsicaps);
2751 READ_CAPS(fcoecaps);
2753 if (sc->niccaps & FW_CAPS_CONFIG_NIC_ETHOFLD) {
2754 param[0] = FW_PARAM_PFVF(ETHOFLD_START);
2755 param[1] = FW_PARAM_PFVF(ETHOFLD_END);
2756 param[2] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
2757 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 3, param, val);
2759 device_printf(sc->dev,
2760 "failed to query NIC parameters: %d.\n", rc);
2763 sc->tids.etid_base = val[0];
2764 sc->params.etid_min = val[0];
2765 sc->tids.netids = val[1] - val[0] + 1;
2766 sc->params.netids = sc->tids.netids;
2767 sc->params.eo_wr_cred = val[2];
2768 sc->params.ethoffload = 1;
2772 /* query offload-related parameters */
2773 param[0] = FW_PARAM_DEV(NTID);
2774 param[1] = FW_PARAM_PFVF(SERVER_START);
2775 param[2] = FW_PARAM_PFVF(SERVER_END);
2776 param[3] = FW_PARAM_PFVF(TDDP_START);
2777 param[4] = FW_PARAM_PFVF(TDDP_END);
2778 param[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
2779 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
2781 device_printf(sc->dev,
2782 "failed to query TOE parameters: %d.\n", rc);
2785 sc->tids.ntids = val[0];
2786 sc->tids.natids = min(sc->tids.ntids / 2, MAX_ATIDS);
2787 sc->tids.stid_base = val[1];
2788 sc->tids.nstids = val[2] - val[1] + 1;
2789 sc->vres.ddp.start = val[3];
2790 sc->vres.ddp.size = val[4] - val[3] + 1;
2791 sc->params.ofldq_wr_cred = val[5];
2792 sc->params.offload = 1;
2795 param[0] = FW_PARAM_PFVF(STAG_START);
2796 param[1] = FW_PARAM_PFVF(STAG_END);
2797 param[2] = FW_PARAM_PFVF(RQ_START);
2798 param[3] = FW_PARAM_PFVF(RQ_END);
2799 param[4] = FW_PARAM_PFVF(PBL_START);
2800 param[5] = FW_PARAM_PFVF(PBL_END);
2801 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
2803 device_printf(sc->dev,
2804 "failed to query RDMA parameters(1): %d.\n", rc);
2807 sc->vres.stag.start = val[0];
2808 sc->vres.stag.size = val[1] - val[0] + 1;
2809 sc->vres.rq.start = val[2];
2810 sc->vres.rq.size = val[3] - val[2] + 1;
2811 sc->vres.pbl.start = val[4];
2812 sc->vres.pbl.size = val[5] - val[4] + 1;
2814 param[0] = FW_PARAM_PFVF(SQRQ_START);
2815 param[1] = FW_PARAM_PFVF(SQRQ_END);
2816 param[2] = FW_PARAM_PFVF(CQ_START);
2817 param[3] = FW_PARAM_PFVF(CQ_END);
2818 param[4] = FW_PARAM_PFVF(OCQ_START);
2819 param[5] = FW_PARAM_PFVF(OCQ_END);
2820 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
2822 device_printf(sc->dev,
2823 "failed to query RDMA parameters(2): %d.\n", rc);
2826 sc->vres.qp.start = val[0];
2827 sc->vres.qp.size = val[1] - val[0] + 1;
2828 sc->vres.cq.start = val[2];
2829 sc->vres.cq.size = val[3] - val[2] + 1;
2830 sc->vres.ocq.start = val[4];
2831 sc->vres.ocq.size = val[5] - val[4] + 1;
2833 if (sc->iscsicaps) {
2834 param[0] = FW_PARAM_PFVF(ISCSI_START);
2835 param[1] = FW_PARAM_PFVF(ISCSI_END);
2836 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
2838 device_printf(sc->dev,
2839 "failed to query iSCSI parameters: %d.\n", rc);
2842 sc->vres.iscsi.start = val[0];
2843 sc->vres.iscsi.size = val[1] - val[0] + 1;
2847 * We've got the params we wanted to query via the firmware. Now grab
2848 * some others directly from the chip.
2850 rc = t4_read_chip_settings(sc);
2856 set_params__post_init(struct adapter *sc)
2858 uint32_t param, val;
2860 /* ask for encapsulated CPLs */
2861 param = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
2863 (void)t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
2868 #undef FW_PARAM_PFVF
2872 t4_set_desc(struct adapter *sc)
2875 struct adapter_params *p = &sc->params;
2877 snprintf(buf, sizeof(buf), "Chelsio %s %sNIC (rev %d), S/N:%s, "
2878 "P/N:%s, E/C:%s", p->vpd.id, is_offload(sc) ? "R" : "",
2879 chip_rev(sc), p->vpd.sn, p->vpd.pn, p->vpd.ec);
2881 device_set_desc_copy(sc->dev, buf);
2885 build_medialist(struct port_info *pi, struct ifmedia *media)
2891 ifmedia_removeall(media);
2893 m = IFM_ETHER | IFM_FDX;
2894 data = (pi->port_type << 8) | pi->mod_type;
2896 switch(pi->port_type) {
2897 case FW_PORT_TYPE_BT_XFI:
2898 ifmedia_add(media, m | IFM_10G_T, data, NULL);
2901 case FW_PORT_TYPE_BT_XAUI:
2902 ifmedia_add(media, m | IFM_10G_T, data, NULL);
2905 case FW_PORT_TYPE_BT_SGMII:
2906 ifmedia_add(media, m | IFM_1000_T, data, NULL);
2907 ifmedia_add(media, m | IFM_100_TX, data, NULL);
2908 ifmedia_add(media, IFM_ETHER | IFM_AUTO, data, NULL);
2909 ifmedia_set(media, IFM_ETHER | IFM_AUTO);
2912 case FW_PORT_TYPE_CX4:
2913 ifmedia_add(media, m | IFM_10G_CX4, data, NULL);
2914 ifmedia_set(media, m | IFM_10G_CX4);
2917 case FW_PORT_TYPE_QSFP_10G:
2918 case FW_PORT_TYPE_SFP:
2919 case FW_PORT_TYPE_FIBER_XFI:
2920 case FW_PORT_TYPE_FIBER_XAUI:
2921 switch (pi->mod_type) {
2923 case FW_PORT_MOD_TYPE_LR:
2924 ifmedia_add(media, m | IFM_10G_LR, data, NULL);
2925 ifmedia_set(media, m | IFM_10G_LR);
2928 case FW_PORT_MOD_TYPE_SR:
2929 ifmedia_add(media, m | IFM_10G_SR, data, NULL);
2930 ifmedia_set(media, m | IFM_10G_SR);
2933 case FW_PORT_MOD_TYPE_LRM:
2934 ifmedia_add(media, m | IFM_10G_LRM, data, NULL);
2935 ifmedia_set(media, m | IFM_10G_LRM);
2938 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
2939 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
2940 ifmedia_add(media, m | IFM_10G_TWINAX, data, NULL);
2941 ifmedia_set(media, m | IFM_10G_TWINAX);
2944 case FW_PORT_MOD_TYPE_NONE:
2946 ifmedia_add(media, m | IFM_NONE, data, NULL);
2947 ifmedia_set(media, m | IFM_NONE);
2950 case FW_PORT_MOD_TYPE_NA:
2951 case FW_PORT_MOD_TYPE_ER:
2953 device_printf(pi->dev,
2954 "unknown port_type (%d), mod_type (%d)\n",
2955 pi->port_type, pi->mod_type);
2956 ifmedia_add(media, m | IFM_UNKNOWN, data, NULL);
2957 ifmedia_set(media, m | IFM_UNKNOWN);
2962 case FW_PORT_TYPE_QSFP:
2963 switch (pi->mod_type) {
2965 case FW_PORT_MOD_TYPE_LR:
2966 ifmedia_add(media, m | IFM_40G_LR4, data, NULL);
2967 ifmedia_set(media, m | IFM_40G_LR4);
2970 case FW_PORT_MOD_TYPE_SR:
2971 ifmedia_add(media, m | IFM_40G_SR4, data, NULL);
2972 ifmedia_set(media, m | IFM_40G_SR4);
2975 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
2976 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
2977 ifmedia_add(media, m | IFM_40G_CR4, data, NULL);
2978 ifmedia_set(media, m | IFM_40G_CR4);
2981 case FW_PORT_MOD_TYPE_NONE:
2983 ifmedia_add(media, m | IFM_NONE, data, NULL);
2984 ifmedia_set(media, m | IFM_NONE);
2988 device_printf(pi->dev,
2989 "unknown port_type (%d), mod_type (%d)\n",
2990 pi->port_type, pi->mod_type);
2991 ifmedia_add(media, m | IFM_UNKNOWN, data, NULL);
2992 ifmedia_set(media, m | IFM_UNKNOWN);
2998 device_printf(pi->dev,
2999 "unknown port_type (%d), mod_type (%d)\n", pi->port_type,
3001 ifmedia_add(media, m | IFM_UNKNOWN, data, NULL);
3002 ifmedia_set(media, m | IFM_UNKNOWN);
3009 #define FW_MAC_EXACT_CHUNK 7
3012 * Program the port's XGMAC based on parameters in ifnet. The caller also
3013 * indicates which parameters should be programmed (the rest are left alone).
3016 update_mac_settings(struct ifnet *ifp, int flags)
3019 struct port_info *pi = ifp->if_softc;
3020 struct adapter *sc = pi->adapter;
3021 int mtu = -1, promisc = -1, allmulti = -1, vlanex = -1;
3022 uint16_t viid = 0xffff;
3023 int16_t *xact_addr_filt = NULL;
3025 ASSERT_SYNCHRONIZED_OP(sc);
3026 KASSERT(flags, ("%s: not told what to update.", __func__));
3028 if (ifp == pi->ifp) {
3030 xact_addr_filt = &pi->xact_addr_filt;
3033 else if (ifp == pi->nm_ifp) {
3035 xact_addr_filt = &pi->nm_xact_addr_filt;
3038 if (flags & XGMAC_MTU)
3041 if (flags & XGMAC_PROMISC)
3042 promisc = ifp->if_flags & IFF_PROMISC ? 1 : 0;
3044 if (flags & XGMAC_ALLMULTI)
3045 allmulti = ifp->if_flags & IFF_ALLMULTI ? 1 : 0;
3047 if (flags & XGMAC_VLANEX)
3048 vlanex = ifp->if_capenable & IFCAP_VLAN_HWTAGGING ? 1 : 0;
3050 if (flags & (XGMAC_MTU|XGMAC_PROMISC|XGMAC_ALLMULTI|XGMAC_VLANEX)) {
3051 rc = -t4_set_rxmode(sc, sc->mbox, viid, mtu, promisc, allmulti,
3054 if_printf(ifp, "set_rxmode (%x) failed: %d\n", flags,
3060 if (flags & XGMAC_UCADDR) {
3061 uint8_t ucaddr[ETHER_ADDR_LEN];
3063 bcopy(IF_LLADDR(ifp), ucaddr, sizeof(ucaddr));
3064 rc = t4_change_mac(sc, sc->mbox, viid, *xact_addr_filt, ucaddr,
3068 if_printf(ifp, "change_mac failed: %d\n", rc);
3071 *xact_addr_filt = rc;
3076 if (flags & XGMAC_MCADDRS) {
3077 const uint8_t *mcaddr[FW_MAC_EXACT_CHUNK];
3080 struct ifmultiaddr *ifma;
3083 if_maddr_rlock(ifp);
3084 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
3085 if (ifma->ifma_addr->sa_family != AF_LINK)
3088 LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
3089 MPASS(ETHER_IS_MULTICAST(mcaddr[i]));
3092 if (i == FW_MAC_EXACT_CHUNK) {
3093 rc = t4_alloc_mac_filt(sc, sc->mbox, viid, del,
3094 i, mcaddr, NULL, &hash, 0);
3097 for (j = 0; j < i; j++) {
3099 "failed to add mc address"
3101 "%02x:%02x:%02x rc=%d\n",
3102 mcaddr[j][0], mcaddr[j][1],
3103 mcaddr[j][2], mcaddr[j][3],
3104 mcaddr[j][4], mcaddr[j][5],
3114 rc = t4_alloc_mac_filt(sc, sc->mbox, viid, del, i,
3115 mcaddr, NULL, &hash, 0);
3118 for (j = 0; j < i; j++) {
3120 "failed to add mc address"
3122 "%02x:%02x:%02x rc=%d\n",
3123 mcaddr[j][0], mcaddr[j][1],
3124 mcaddr[j][2], mcaddr[j][3],
3125 mcaddr[j][4], mcaddr[j][5],
3132 rc = -t4_set_addr_hash(sc, sc->mbox, viid, 0, hash, 0);
3134 if_printf(ifp, "failed to set mc address hash: %d", rc);
3136 if_maddr_runlock(ifp);
3143 begin_synchronized_op(struct adapter *sc, struct port_info *pi, int flags,
3149 /* the caller thinks it's ok to sleep, but is it really? */
3150 if (flags & SLEEP_OK)
3151 pause("t4slptst", 1);
3162 if (pi && IS_DOOMED(pi)) {
3172 if (!(flags & SLEEP_OK)) {
3177 if (mtx_sleep(&sc->flags, &sc->sc_lock, pri, wmesg, 0)) {
3183 KASSERT(!IS_BUSY(sc), ("%s: controller busy.", __func__));
3186 sc->last_op = wmesg;
3187 sc->last_op_thr = curthread;
3191 if (!(flags & HOLD_LOCK) || rc)
3198 end_synchronized_op(struct adapter *sc, int flags)
3201 if (flags & LOCK_HELD)
3202 ADAPTER_LOCK_ASSERT_OWNED(sc);
3206 KASSERT(IS_BUSY(sc), ("%s: controller not busy.", __func__));
3213 cxgbe_init_synchronized(struct port_info *pi)
3215 struct adapter *sc = pi->adapter;
3216 struct ifnet *ifp = pi->ifp;
3218 struct sge_txq *txq;
3220 ASSERT_SYNCHRONIZED_OP(sc);
3222 if (isset(&sc->open_device_map, pi->port_id)) {
3223 KASSERT(ifp->if_drv_flags & IFF_DRV_RUNNING,
3224 ("mismatch between open_device_map and if_drv_flags"));
3225 return (0); /* already running */
3228 if (!(sc->flags & FULL_INIT_DONE) &&
3229 ((rc = adapter_full_init(sc)) != 0))
3230 return (rc); /* error message displayed already */
3232 if (!(pi->flags & PORT_INIT_DONE) &&
3233 ((rc = port_full_init(pi)) != 0))
3234 return (rc); /* error message displayed already */
3236 rc = update_mac_settings(ifp, XGMAC_ALL);
3238 goto done; /* error message displayed already */
3240 rc = -t4_enable_vi(sc, sc->mbox, pi->viid, true, true);
3242 if_printf(ifp, "enable_vi failed: %d\n", rc);
3247 * Can't fail from this point onwards. Review cxgbe_uninit_synchronized
3251 for_each_txq(pi, i, txq) {
3253 txq->eq.flags |= EQ_ENABLED;
3258 * The first iq of the first port to come up is used for tracing.
3260 if (sc->traceq < 0) {
3261 sc->traceq = sc->sge.rxq[pi->first_rxq].iq.abs_id;
3262 t4_write_reg(sc, is_t4(sc) ? A_MPS_TRC_RSS_CONTROL :
3263 A_MPS_T5_TRC_RSS_CONTROL, V_RSSCONTROL(pi->tx_chan) |
3264 V_QUEUENUMBER(sc->traceq));
3265 pi->flags |= HAS_TRACEQ;
3269 setbit(&sc->open_device_map, pi->port_id);
3271 ifp->if_drv_flags |= IFF_DRV_RUNNING;
3274 callout_reset(&pi->tick, hz, cxgbe_tick, pi);
3277 cxgbe_uninit_synchronized(pi);
3286 cxgbe_uninit_synchronized(struct port_info *pi)
3288 struct adapter *sc = pi->adapter;
3289 struct ifnet *ifp = pi->ifp;
3291 struct sge_txq *txq;
3293 ASSERT_SYNCHRONIZED_OP(sc);
3295 if (!(pi->flags & PORT_INIT_DONE)) {
3296 KASSERT(!(ifp->if_drv_flags & IFF_DRV_RUNNING),
3297 ("uninited port is running"));
3302 * Disable the VI so that all its data in either direction is discarded
3303 * by the MPS. Leave everything else (the queues, interrupts, and 1Hz
3304 * tick) intact as the TP can deliver negative advice or data that it's
3305 * holding in its RAM (for an offloaded connection) even after the VI is
3308 rc = -t4_enable_vi(sc, sc->mbox, pi->viid, false, false);
3310 if_printf(ifp, "disable_vi failed: %d\n", rc);
3314 for_each_txq(pi, i, txq) {
3316 txq->eq.flags &= ~EQ_ENABLED;
3320 clrbit(&sc->open_device_map, pi->port_id);
3322 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
3325 pi->link_cfg.link_ok = 0;
3326 pi->link_cfg.speed = 0;
3328 t4_os_link_changed(sc, pi->port_id, 0, -1);
3334 * It is ok for this function to fail midway and return right away. t4_detach
3335 * will walk the entire sc->irq list and clean up whatever is valid.
3338 setup_intr_handlers(struct adapter *sc)
3343 struct port_info *pi;
3344 struct sge_rxq *rxq;
3346 struct sge_ofld_rxq *ofld_rxq;
3349 struct sge_nm_rxq *nm_rxq;
3356 rid = sc->intr_type == INTR_INTX ? 0 : 1;
3357 if (sc->intr_count == 1)
3358 return (t4_alloc_irq(sc, irq, rid, t4_intr_all, sc, "all"));
3360 /* Multiple interrupts. */
3361 KASSERT(sc->intr_count >= T4_EXTRA_INTR + sc->params.nports,
3362 ("%s: too few intr.", __func__));
3364 /* The first one is always error intr */
3365 rc = t4_alloc_irq(sc, irq, rid, t4_intr_err, sc, "err");
3371 /* The second one is always the firmware event queue */
3372 rc = t4_alloc_irq(sc, irq, rid, t4_intr_evt, &sc->sge.fwq, "evt");
3378 for_each_port(sc, p) {
3381 if (pi->flags & INTR_RXQ) {
3382 for_each_rxq(pi, q, rxq) {
3383 snprintf(s, sizeof(s), "%d.%d", p, q);
3384 rc = t4_alloc_irq(sc, irq, rid, t4_intr, rxq,
3393 if (pi->flags & INTR_OFLD_RXQ) {
3394 for_each_ofld_rxq(pi, q, ofld_rxq) {
3395 snprintf(s, sizeof(s), "%d,%d", p, q);
3396 rc = t4_alloc_irq(sc, irq, rid, t4_intr,
3406 if (pi->flags & INTR_NM_RXQ) {
3407 for_each_nm_rxq(pi, q, nm_rxq) {
3408 snprintf(s, sizeof(s), "%d-%d", p, q);
3409 rc = t4_alloc_irq(sc, irq, rid, t4_nm_intr,
3419 MPASS(irq == &sc->irq[sc->intr_count]);
3425 adapter_full_init(struct adapter *sc)
3429 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
3430 KASSERT((sc->flags & FULL_INIT_DONE) == 0,
3431 ("%s: FULL_INIT_DONE already", __func__));
3434 * queues that belong to the adapter (not any particular port).
3436 rc = t4_setup_adapter_queues(sc);
3440 for (i = 0; i < nitems(sc->tq); i++) {
3441 sc->tq[i] = taskqueue_create("t4 taskq", M_NOWAIT,
3442 taskqueue_thread_enqueue, &sc->tq[i]);
3443 if (sc->tq[i] == NULL) {
3444 device_printf(sc->dev,
3445 "failed to allocate task queue %d\n", i);
3449 taskqueue_start_threads(&sc->tq[i], 1, PI_NET, "%s tq%d",
3450 device_get_nameunit(sc->dev), i);
3454 sc->flags |= FULL_INIT_DONE;
3457 adapter_full_uninit(sc);
3463 adapter_full_uninit(struct adapter *sc)
3467 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
3469 t4_teardown_adapter_queues(sc);
3471 for (i = 0; i < nitems(sc->tq) && sc->tq[i]; i++) {
3472 taskqueue_free(sc->tq[i]);
3476 sc->flags &= ~FULL_INIT_DONE;
3482 port_full_init(struct port_info *pi)
3484 struct adapter *sc = pi->adapter;
3485 struct ifnet *ifp = pi->ifp;
3487 struct sge_rxq *rxq;
3490 ASSERT_SYNCHRONIZED_OP(sc);
3491 KASSERT((pi->flags & PORT_INIT_DONE) == 0,
3492 ("%s: PORT_INIT_DONE already", __func__));
3494 sysctl_ctx_init(&pi->ctx);
3495 pi->flags |= PORT_SYSCTL_CTX;
3498 * Allocate tx/rx/fl queues for this port.
3500 rc = t4_setup_port_queues(pi);
3502 goto done; /* error message displayed already */
3505 * Setup RSS for this port. Save a copy of the RSS table for later use.
3507 rss = malloc(pi->rss_size * sizeof (*rss), M_CXGBE, M_ZERO | M_WAITOK);
3508 for (i = 0; i < pi->rss_size;) {
3509 for_each_rxq(pi, j, rxq) {
3510 rss[i++] = rxq->iq.abs_id;
3511 if (i == pi->rss_size)
3516 rc = -t4_config_rss_range(sc, sc->mbox, pi->viid, 0, pi->rss_size, rss,
3519 if_printf(ifp, "rss_config failed: %d\n", rc);
3524 pi->flags |= PORT_INIT_DONE;
3527 port_full_uninit(pi);
3536 port_full_uninit(struct port_info *pi)
3538 struct adapter *sc = pi->adapter;
3540 struct sge_rxq *rxq;
3541 struct sge_txq *txq;
3543 struct sge_ofld_rxq *ofld_rxq;
3544 struct sge_wrq *ofld_txq;
3547 if (pi->flags & PORT_INIT_DONE) {
3549 /* Need to quiesce queues. */
3551 quiesce_wrq(sc, &sc->sge.ctrlq[pi->port_id]);
3553 for_each_txq(pi, i, txq) {
3554 quiesce_txq(sc, txq);
3558 for_each_ofld_txq(pi, i, ofld_txq) {
3559 quiesce_wrq(sc, ofld_txq);
3563 for_each_rxq(pi, i, rxq) {
3564 quiesce_iq(sc, &rxq->iq);
3565 quiesce_fl(sc, &rxq->fl);
3569 for_each_ofld_rxq(pi, i, ofld_rxq) {
3570 quiesce_iq(sc, &ofld_rxq->iq);
3571 quiesce_fl(sc, &ofld_rxq->fl);
3574 free(pi->rss, M_CXGBE);
3577 t4_teardown_port_queues(pi);
3578 pi->flags &= ~PORT_INIT_DONE;
3584 quiesce_txq(struct adapter *sc, struct sge_txq *txq)
3586 struct sge_eq *eq = &txq->eq;
3587 struct sge_qstat *spg = (void *)&eq->desc[eq->sidx];
3589 (void) sc; /* unused */
3593 MPASS((eq->flags & EQ_ENABLED) == 0);
3597 /* Wait for the mp_ring to empty. */
3598 while (!mp_ring_is_idle(txq->r)) {
3599 mp_ring_check_drainage(txq->r, 0);
3600 pause("rquiesce", 1);
3603 /* Then wait for the hardware to finish. */
3604 while (spg->cidx != htobe16(eq->pidx))
3605 pause("equiesce", 1);
3607 /* Finally, wait for the driver to reclaim all descriptors. */
3608 while (eq->cidx != eq->pidx)
3609 pause("dquiesce", 1);
3613 quiesce_wrq(struct adapter *sc, struct sge_wrq *wrq)
3620 quiesce_iq(struct adapter *sc, struct sge_iq *iq)
3622 (void) sc; /* unused */
3624 /* Synchronize with the interrupt handler */
3625 while (!atomic_cmpset_int(&iq->state, IQS_IDLE, IQS_DISABLED))
3630 quiesce_fl(struct adapter *sc, struct sge_fl *fl)
3632 mtx_lock(&sc->sfl_lock);
3634 fl->flags |= FL_DOOMED;
3636 mtx_unlock(&sc->sfl_lock);
3638 callout_drain(&sc->sfl_callout);
3639 KASSERT((fl->flags & FL_STARVING) == 0,
3640 ("%s: still starving", __func__));
3644 t4_alloc_irq(struct adapter *sc, struct irq *irq, int rid,
3645 driver_intr_t *handler, void *arg, char *name)
3650 irq->res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &irq->rid,
3651 RF_SHAREABLE | RF_ACTIVE);
3652 if (irq->res == NULL) {
3653 device_printf(sc->dev,
3654 "failed to allocate IRQ for rid %d, name %s.\n", rid, name);
3658 rc = bus_setup_intr(sc->dev, irq->res, INTR_MPSAFE | INTR_TYPE_NET,
3659 NULL, handler, arg, &irq->tag);
3661 device_printf(sc->dev,
3662 "failed to setup interrupt for rid %d, name %s: %d\n",
3665 bus_describe_intr(sc->dev, irq->res, irq->tag, name);
3671 t4_free_irq(struct adapter *sc, struct irq *irq)
3674 bus_teardown_intr(sc->dev, irq->res, irq->tag);
3676 bus_release_resource(sc->dev, SYS_RES_IRQ, irq->rid, irq->res);
3678 bzero(irq, sizeof(*irq));
3684 reg_block_dump(struct adapter *sc, uint8_t *buf, unsigned int start,
3687 uint32_t *p = (uint32_t *)(buf + start);
3689 for ( ; start <= end; start += sizeof(uint32_t))
3690 *p++ = t4_read_reg(sc, start);
3694 t4_get_regs(struct adapter *sc, struct t4_regdump *regs, uint8_t *buf)
3697 const unsigned int *reg_ranges;
3698 static const unsigned int t4_reg_ranges[] = {
3918 static const unsigned int t5_reg_ranges[] = {
4359 reg_ranges = &t4_reg_ranges[0];
4360 n = nitems(t4_reg_ranges);
4362 reg_ranges = &t5_reg_ranges[0];
4363 n = nitems(t5_reg_ranges);
4366 regs->version = chip_id(sc) | chip_rev(sc) << 10;
4367 for (i = 0; i < n; i += 2)
4368 reg_block_dump(sc, buf, reg_ranges[i], reg_ranges[i + 1]);
4372 cxgbe_refresh_stats(struct adapter *sc, struct port_info *pi)
4375 u_int v, tnl_cong_drops;
4377 const struct timeval interval = {0, 250000}; /* 250ms */
4380 timevalsub(&tv, &interval);
4381 if (timevalcmp(&tv, &pi->last_refreshed, <))
4385 t4_get_port_stats(sc, pi->tx_chan, &pi->stats);
4386 for (i = 0; i < NCHAN; i++) {
4387 if (pi->rx_chan_map & (1 << i)) {
4388 mtx_lock(&sc->regwin_lock);
4389 t4_read_indirect(sc, A_TP_MIB_INDEX, A_TP_MIB_DATA, &v,
4390 1, A_TP_MIB_TNL_CNG_DROP_0 + i);
4391 mtx_unlock(&sc->regwin_lock);
4392 tnl_cong_drops += v;
4395 pi->tnl_cong_drops = tnl_cong_drops;
4396 getmicrotime(&pi->last_refreshed);
4400 cxgbe_tick(void *arg)
4402 struct port_info *pi = arg;
4403 struct adapter *sc = pi->adapter;
4404 struct ifnet *ifp = pi->ifp;
4407 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
4409 return; /* without scheduling another callout */
4412 cxgbe_refresh_stats(sc, pi);
4414 callout_schedule(&pi->tick, hz);
4419 cxgbe_vlan_config(void *arg, struct ifnet *ifp, uint16_t vid)
4423 if (arg != ifp || ifp->if_type != IFT_ETHER)
4426 vlan = VLAN_DEVAT(ifp, vid);
4427 VLAN_SETCOOKIE(vlan, ifp);
4431 cpl_not_handled(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
4435 panic("%s: opcode 0x%02x on iq %p with payload %p",
4436 __func__, rss->opcode, iq, m);
4438 log(LOG_ERR, "%s: opcode 0x%02x on iq %p with payload %p\n",
4439 __func__, rss->opcode, iq, m);
4446 t4_register_cpl_handler(struct adapter *sc, int opcode, cpl_handler_t h)
4448 uintptr_t *loc, new;
4450 if (opcode >= nitems(sc->cpl_handler))
4453 new = h ? (uintptr_t)h : (uintptr_t)cpl_not_handled;
4454 loc = (uintptr_t *) &sc->cpl_handler[opcode];
4455 atomic_store_rel_ptr(loc, new);
4461 an_not_handled(struct sge_iq *iq, const struct rsp_ctrl *ctrl)
4465 panic("%s: async notification on iq %p (ctrl %p)", __func__, iq, ctrl);
4467 log(LOG_ERR, "%s: async notification on iq %p (ctrl %p)\n",
4468 __func__, iq, ctrl);
4474 t4_register_an_handler(struct adapter *sc, an_handler_t h)
4476 uintptr_t *loc, new;
4478 new = h ? (uintptr_t)h : (uintptr_t)an_not_handled;
4479 loc = (uintptr_t *) &sc->an_handler;
4480 atomic_store_rel_ptr(loc, new);
4486 fw_msg_not_handled(struct adapter *sc, const __be64 *rpl)
4488 const struct cpl_fw6_msg *cpl =
4489 __containerof(rpl, struct cpl_fw6_msg, data[0]);
4492 panic("%s: fw_msg type %d", __func__, cpl->type);
4494 log(LOG_ERR, "%s: fw_msg type %d\n", __func__, cpl->type);
4500 t4_register_fw_msg_handler(struct adapter *sc, int type, fw_msg_handler_t h)
4502 uintptr_t *loc, new;
4504 if (type >= nitems(sc->fw_msg_handler))
4508 * These are dispatched by the handler for FW{4|6}_CPL_MSG using the CPL
4509 * handler dispatch table. Reject any attempt to install a handler for
4512 if (type == FW_TYPE_RSSCPL || type == FW6_TYPE_RSSCPL)
4515 new = h ? (uintptr_t)h : (uintptr_t)fw_msg_not_handled;
4516 loc = (uintptr_t *) &sc->fw_msg_handler[type];
4517 atomic_store_rel_ptr(loc, new);
4523 t4_sysctls(struct adapter *sc)
4525 struct sysctl_ctx_list *ctx;
4526 struct sysctl_oid *oid;
4527 struct sysctl_oid_list *children, *c0;
4528 static char *caps[] = {
4529 "\20\1PPP\2QFC\3DCBX", /* caps[0] linkcaps */
4530 "\20\1NIC\2VM\3IDS\4UM\5UM_ISGL" /* caps[1] niccaps */
4531 "\6HASHFILTER\7ETHOFLD",
4532 "\20\1TOE", /* caps[2] toecaps */
4533 "\20\1RDDP\2RDMAC", /* caps[3] rdmacaps */
4534 "\20\1INITIATOR_PDU\2TARGET_PDU" /* caps[4] iscsicaps */
4535 "\3INITIATOR_CNXOFLD\4TARGET_CNXOFLD"
4536 "\5INITIATOR_SSNOFLD\6TARGET_SSNOFLD",
4537 "\20\1INITIATOR\2TARGET\3CTRL_OFLD" /* caps[5] fcoecaps */
4538 "\4PO_INITIAOR\5PO_TARGET"
4540 static char *doorbells = {"\20\1UDB\2WCWR\3UDBWC\4KDB"};
4542 ctx = device_get_sysctl_ctx(sc->dev);
4547 oid = device_get_sysctl_tree(sc->dev);
4548 c0 = children = SYSCTL_CHILDREN(oid);
4550 sc->sc_do_rxcopy = 1;
4551 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "do_rx_copy", CTLFLAG_RW,
4552 &sc->sc_do_rxcopy, 1, "Do RX copy of small frames");
4554 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nports", CTLFLAG_RD, NULL,
4555 sc->params.nports, "# of ports");
4557 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "hw_revision", CTLFLAG_RD,
4558 NULL, chip_rev(sc), "chip hardware revision");
4560 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "firmware_version",
4561 CTLFLAG_RD, sc->fw_version, 0, "firmware version");
4563 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "cf",
4564 CTLFLAG_RD, sc->cfg_file, 0, "configuration file");
4566 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "cfcsum", CTLFLAG_RD, NULL,
4567 sc->cfcsum, "config file checksum");
4569 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "doorbells",
4570 CTLTYPE_STRING | CTLFLAG_RD, doorbells, sc->doorbells,
4571 sysctl_bitfield, "A", "available doorbells");
4573 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "linkcaps",
4574 CTLTYPE_STRING | CTLFLAG_RD, caps[0], sc->linkcaps,
4575 sysctl_bitfield, "A", "available link capabilities");
4577 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "niccaps",
4578 CTLTYPE_STRING | CTLFLAG_RD, caps[1], sc->niccaps,
4579 sysctl_bitfield, "A", "available NIC capabilities");
4581 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "toecaps",
4582 CTLTYPE_STRING | CTLFLAG_RD, caps[2], sc->toecaps,
4583 sysctl_bitfield, "A", "available TCP offload capabilities");
4585 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rdmacaps",
4586 CTLTYPE_STRING | CTLFLAG_RD, caps[3], sc->rdmacaps,
4587 sysctl_bitfield, "A", "available RDMA capabilities");
4589 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "iscsicaps",
4590 CTLTYPE_STRING | CTLFLAG_RD, caps[4], sc->iscsicaps,
4591 sysctl_bitfield, "A", "available iSCSI capabilities");
4593 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fcoecaps",
4594 CTLTYPE_STRING | CTLFLAG_RD, caps[5], sc->fcoecaps,
4595 sysctl_bitfield, "A", "available FCoE capabilities");
4597 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "core_clock", CTLFLAG_RD, NULL,
4598 sc->params.vpd.cclk, "core clock frequency (in KHz)");
4600 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_timers",
4601 CTLTYPE_STRING | CTLFLAG_RD, sc->sge.timer_val,
4602 sizeof(sc->sge.timer_val), sysctl_int_array, "A",
4603 "interrupt holdoff timer values (us)");
4605 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pkt_counts",
4606 CTLTYPE_STRING | CTLFLAG_RD, sc->sge.counter_val,
4607 sizeof(sc->sge.counter_val), sysctl_int_array, "A",
4608 "interrupt holdoff packet counter values");
4610 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nfilters", CTLFLAG_RD,
4611 NULL, sc->tids.nftids, "number of filters");
4613 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature", CTLTYPE_INT |
4614 CTLFLAG_RD, sc, 0, sysctl_temperature, "I",
4615 "chip temperature (in Celsius)");
4617 t4_sge_sysctls(sc, ctx, children);
4619 sc->lro_timeout = 100;
4620 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "lro_timeout", CTLFLAG_RW,
4621 &sc->lro_timeout, 0, "lro inactive-flush timeout (in us)");
4625 * dev.t4nex.X.misc. Marked CTLFLAG_SKIP to avoid information overload.
4627 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "misc",
4628 CTLFLAG_RD | CTLFLAG_SKIP, NULL,
4629 "logs and miscellaneous information");
4630 children = SYSCTL_CHILDREN(oid);
4632 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cctrl",
4633 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4634 sysctl_cctrl, "A", "congestion control");
4636 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp0",
4637 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4638 sysctl_cim_ibq_obq, "A", "CIM IBQ 0 (TP0)");
4640 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp1",
4641 CTLTYPE_STRING | CTLFLAG_RD, sc, 1,
4642 sysctl_cim_ibq_obq, "A", "CIM IBQ 1 (TP1)");
4644 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ulp",
4645 CTLTYPE_STRING | CTLFLAG_RD, sc, 2,
4646 sysctl_cim_ibq_obq, "A", "CIM IBQ 2 (ULP)");
4648 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge0",
4649 CTLTYPE_STRING | CTLFLAG_RD, sc, 3,
4650 sysctl_cim_ibq_obq, "A", "CIM IBQ 3 (SGE0)");
4652 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge1",
4653 CTLTYPE_STRING | CTLFLAG_RD, sc, 4,
4654 sysctl_cim_ibq_obq, "A", "CIM IBQ 4 (SGE1)");
4656 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ncsi",
4657 CTLTYPE_STRING | CTLFLAG_RD, sc, 5,
4658 sysctl_cim_ibq_obq, "A", "CIM IBQ 5 (NCSI)");
4660 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_la",
4661 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4662 sysctl_cim_la, "A", "CIM logic analyzer");
4664 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ma_la",
4665 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4666 sysctl_cim_ma_la, "A", "CIM MA logic analyzer");
4668 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp0",
4669 CTLTYPE_STRING | CTLFLAG_RD, sc, 0 + CIM_NUM_IBQ,
4670 sysctl_cim_ibq_obq, "A", "CIM OBQ 0 (ULP0)");
4672 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp1",
4673 CTLTYPE_STRING | CTLFLAG_RD, sc, 1 + CIM_NUM_IBQ,
4674 sysctl_cim_ibq_obq, "A", "CIM OBQ 1 (ULP1)");
4676 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp2",
4677 CTLTYPE_STRING | CTLFLAG_RD, sc, 2 + CIM_NUM_IBQ,
4678 sysctl_cim_ibq_obq, "A", "CIM OBQ 2 (ULP2)");
4680 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp3",
4681 CTLTYPE_STRING | CTLFLAG_RD, sc, 3 + CIM_NUM_IBQ,
4682 sysctl_cim_ibq_obq, "A", "CIM OBQ 3 (ULP3)");
4684 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge",
4685 CTLTYPE_STRING | CTLFLAG_RD, sc, 4 + CIM_NUM_IBQ,
4686 sysctl_cim_ibq_obq, "A", "CIM OBQ 4 (SGE)");
4688 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ncsi",
4689 CTLTYPE_STRING | CTLFLAG_RD, sc, 5 + CIM_NUM_IBQ,
4690 sysctl_cim_ibq_obq, "A", "CIM OBQ 5 (NCSI)");
4693 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge0_rx",
4694 CTLTYPE_STRING | CTLFLAG_RD, sc, 6 + CIM_NUM_IBQ,
4695 sysctl_cim_ibq_obq, "A", "CIM OBQ 6 (SGE0-RX)");
4697 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge1_rx",
4698 CTLTYPE_STRING | CTLFLAG_RD, sc, 7 + CIM_NUM_IBQ,
4699 sysctl_cim_ibq_obq, "A", "CIM OBQ 7 (SGE1-RX)");
4702 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_pif_la",
4703 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4704 sysctl_cim_pif_la, "A", "CIM PIF logic analyzer");
4706 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_qcfg",
4707 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4708 sysctl_cim_qcfg, "A", "CIM queue configuration");
4710 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cpl_stats",
4711 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4712 sysctl_cpl_stats, "A", "CPL statistics");
4714 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ddp_stats",
4715 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4716 sysctl_ddp_stats, "A", "non-TCP DDP statistics");
4718 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "devlog",
4719 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4720 sysctl_devlog, "A", "firmware's device log");
4722 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fcoe_stats",
4723 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4724 sysctl_fcoe_stats, "A", "FCoE statistics");
4726 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "hw_sched",
4727 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4728 sysctl_hw_sched, "A", "hardware scheduler ");
4730 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "l2t",
4731 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4732 sysctl_l2t, "A", "hardware L2 table");
4734 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "lb_stats",
4735 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4736 sysctl_lb_stats, "A", "loopback statistics");
4738 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "meminfo",
4739 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4740 sysctl_meminfo, "A", "memory regions");
4742 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "mps_tcam",
4743 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4744 sysctl_mps_tcam, "A", "MPS TCAM entries");
4746 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "path_mtus",
4747 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4748 sysctl_path_mtus, "A", "path MTUs");
4750 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pm_stats",
4751 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4752 sysctl_pm_stats, "A", "PM statistics");
4754 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rdma_stats",
4755 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4756 sysctl_rdma_stats, "A", "RDMA statistics");
4758 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tcp_stats",
4759 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4760 sysctl_tcp_stats, "A", "TCP statistics");
4762 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tids",
4763 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4764 sysctl_tids, "A", "TID information");
4766 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_err_stats",
4767 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4768 sysctl_tp_err_stats, "A", "TP error statistics");
4770 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_la",
4771 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4772 sysctl_tp_la, "A", "TP logic analyzer");
4774 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_rate",
4775 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4776 sysctl_tx_rate, "A", "Tx rate");
4778 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ulprx_la",
4779 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4780 sysctl_ulprx_la, "A", "ULPRX logic analyzer");
4783 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "wcwr_stats",
4784 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4785 sysctl_wcwr_stats, "A", "write combined work requests");
4790 if (is_offload(sc)) {
4794 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "toe", CTLFLAG_RD,
4795 NULL, "TOE parameters");
4796 children = SYSCTL_CHILDREN(oid);
4798 sc->tt.sndbuf = 256 * 1024;
4799 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "sndbuf", CTLFLAG_RW,
4800 &sc->tt.sndbuf, 0, "max hardware send buffer size");
4803 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ddp", CTLFLAG_RW,
4804 &sc->tt.ddp, 0, "DDP allowed");
4806 sc->tt.indsz = G_INDICATESIZE(t4_read_reg(sc, A_TP_PARA_REG5));
4807 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "indsz", CTLFLAG_RW,
4808 &sc->tt.indsz, 0, "DDP max indicate size allowed");
4811 G_RXCOALESCESIZE(t4_read_reg(sc, A_TP_PARA_REG2));
4812 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ddp_thres", CTLFLAG_RW,
4813 &sc->tt.ddp_thres, 0, "DDP threshold");
4815 sc->tt.rx_coalesce = 1;
4816 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_coalesce",
4817 CTLFLAG_RW, &sc->tt.rx_coalesce, 0, "receive coalescing");
4819 sc->tt.tx_align = 1;
4820 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_align",
4821 CTLFLAG_RW, &sc->tt.tx_align, 0, "chop and align payload");
4830 cxgbe_sysctls(struct port_info *pi)
4832 struct sysctl_ctx_list *ctx;
4833 struct sysctl_oid *oid;
4834 struct sysctl_oid_list *children;
4835 struct adapter *sc = pi->adapter;
4837 ctx = device_get_sysctl_ctx(pi->dev);
4842 oid = device_get_sysctl_tree(pi->dev);
4843 children = SYSCTL_CHILDREN(oid);
4845 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "linkdnrc", CTLTYPE_STRING |
4846 CTLFLAG_RD, pi, 0, sysctl_linkdnrc, "A", "reason why link is down");
4847 if (pi->port_type == FW_PORT_TYPE_BT_XAUI) {
4848 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature",
4849 CTLTYPE_INT | CTLFLAG_RD, pi, 0, sysctl_btphy, "I",
4850 "PHY temperature (in Celsius)");
4851 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fw_version",
4852 CTLTYPE_INT | CTLFLAG_RD, pi, 1, sysctl_btphy, "I",
4853 "PHY firmware version");
4855 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nrxq", CTLFLAG_RD,
4856 &pi->nrxq, 0, "# of rx queues");
4857 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ntxq", CTLFLAG_RD,
4858 &pi->ntxq, 0, "# of tx queues");
4859 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_rxq", CTLFLAG_RD,
4860 &pi->first_rxq, 0, "index of first rx queue");
4861 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_txq", CTLFLAG_RD,
4862 &pi->first_txq, 0, "index of first tx queue");
4863 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rsrv_noflowq", CTLTYPE_INT |
4864 CTLFLAG_RW, pi, 0, sysctl_noflowq, "IU",
4865 "Reserve queue 0 for non-flowid packets");
4868 if (is_offload(sc)) {
4869 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldrxq", CTLFLAG_RD,
4871 "# of rx queues for offloaded TCP connections");
4872 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldtxq", CTLFLAG_RD,
4874 "# of tx queues for offloaded TCP connections");
4875 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_rxq",
4876 CTLFLAG_RD, &pi->first_ofld_rxq, 0,
4877 "index of first TOE rx queue");
4878 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_txq",
4879 CTLFLAG_RD, &pi->first_ofld_txq, 0,
4880 "index of first TOE tx queue");
4884 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmrxq", CTLFLAG_RD,
4885 &pi->nnmrxq, 0, "# of rx queues for netmap");
4886 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmtxq", CTLFLAG_RD,
4887 &pi->nnmtxq, 0, "# of tx queues for netmap");
4888 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_rxq",
4889 CTLFLAG_RD, &pi->first_nm_rxq, 0,
4890 "index of first netmap rx queue");
4891 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_txq",
4892 CTLFLAG_RD, &pi->first_nm_txq, 0,
4893 "index of first netmap tx queue");
4896 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx",
4897 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_holdoff_tmr_idx, "I",
4898 "holdoff timer index");
4899 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx",
4900 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_holdoff_pktc_idx, "I",
4901 "holdoff packet counter index");
4903 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_rxq",
4904 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_qsize_rxq, "I",
4906 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_txq",
4907 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_qsize_txq, "I",
4910 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pause_settings",
4911 CTLTYPE_STRING | CTLFLAG_RW, pi, PAUSE_TX, sysctl_pause_settings,
4912 "A", "PAUSE settings (bit 0 = rx_pause, bit 1 = tx_pause)");
4915 * dev.cxgbe.X.stats.
4917 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats", CTLFLAG_RD,
4918 NULL, "port statistics");
4919 children = SYSCTL_CHILDREN(oid);
4920 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "tx_parse_error", CTLFLAG_RD,
4921 &pi->tx_parse_error, 0,
4922 "# of tx packets with invalid length or # of segments");
4924 #define SYSCTL_ADD_T4_REG64(pi, name, desc, reg) \
4925 SYSCTL_ADD_OID(ctx, children, OID_AUTO, name, \
4926 CTLTYPE_U64 | CTLFLAG_RD, sc, reg, \
4927 sysctl_handle_t4_reg64, "QU", desc)
4929 SYSCTL_ADD_T4_REG64(pi, "tx_octets", "# of octets in good frames",
4930 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BYTES_L));
4931 SYSCTL_ADD_T4_REG64(pi, "tx_frames", "total # of good frames",
4932 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_FRAMES_L));
4933 SYSCTL_ADD_T4_REG64(pi, "tx_bcast_frames", "# of broadcast frames",
4934 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BCAST_L));
4935 SYSCTL_ADD_T4_REG64(pi, "tx_mcast_frames", "# of multicast frames",
4936 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_MCAST_L));
4937 SYSCTL_ADD_T4_REG64(pi, "tx_ucast_frames", "# of unicast frames",
4938 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_UCAST_L));
4939 SYSCTL_ADD_T4_REG64(pi, "tx_error_frames", "# of error frames",
4940 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_ERROR_L));
4941 SYSCTL_ADD_T4_REG64(pi, "tx_frames_64",
4942 "# of tx frames in this range",
4943 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_64B_L));
4944 SYSCTL_ADD_T4_REG64(pi, "tx_frames_65_127",
4945 "# of tx frames in this range",
4946 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_65B_127B_L));
4947 SYSCTL_ADD_T4_REG64(pi, "tx_frames_128_255",
4948 "# of tx frames in this range",
4949 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_128B_255B_L));
4950 SYSCTL_ADD_T4_REG64(pi, "tx_frames_256_511",
4951 "# of tx frames in this range",
4952 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_256B_511B_L));
4953 SYSCTL_ADD_T4_REG64(pi, "tx_frames_512_1023",
4954 "# of tx frames in this range",
4955 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_512B_1023B_L));
4956 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1024_1518",
4957 "# of tx frames in this range",
4958 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1024B_1518B_L));
4959 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1519_max",
4960 "# of tx frames in this range",
4961 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1519B_MAX_L));
4962 SYSCTL_ADD_T4_REG64(pi, "tx_drop", "# of dropped tx frames",
4963 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_DROP_L));
4964 SYSCTL_ADD_T4_REG64(pi, "tx_pause", "# of pause frames transmitted",
4965 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PAUSE_L));
4966 SYSCTL_ADD_T4_REG64(pi, "tx_ppp0", "# of PPP prio 0 frames transmitted",
4967 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP0_L));
4968 SYSCTL_ADD_T4_REG64(pi, "tx_ppp1", "# of PPP prio 1 frames transmitted",
4969 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP1_L));
4970 SYSCTL_ADD_T4_REG64(pi, "tx_ppp2", "# of PPP prio 2 frames transmitted",
4971 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP2_L));
4972 SYSCTL_ADD_T4_REG64(pi, "tx_ppp3", "# of PPP prio 3 frames transmitted",
4973 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP3_L));
4974 SYSCTL_ADD_T4_REG64(pi, "tx_ppp4", "# of PPP prio 4 frames transmitted",
4975 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP4_L));
4976 SYSCTL_ADD_T4_REG64(pi, "tx_ppp5", "# of PPP prio 5 frames transmitted",
4977 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP5_L));
4978 SYSCTL_ADD_T4_REG64(pi, "tx_ppp6", "# of PPP prio 6 frames transmitted",
4979 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP6_L));
4980 SYSCTL_ADD_T4_REG64(pi, "tx_ppp7", "# of PPP prio 7 frames transmitted",
4981 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP7_L));
4983 SYSCTL_ADD_T4_REG64(pi, "rx_octets", "# of octets in good frames",
4984 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BYTES_L));
4985 SYSCTL_ADD_T4_REG64(pi, "rx_frames", "total # of good frames",
4986 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_FRAMES_L));
4987 SYSCTL_ADD_T4_REG64(pi, "rx_bcast_frames", "# of broadcast frames",
4988 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BCAST_L));
4989 SYSCTL_ADD_T4_REG64(pi, "rx_mcast_frames", "# of multicast frames",
4990 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MCAST_L));
4991 SYSCTL_ADD_T4_REG64(pi, "rx_ucast_frames", "# of unicast frames",
4992 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_UCAST_L));
4993 SYSCTL_ADD_T4_REG64(pi, "rx_too_long", "# of frames exceeding MTU",
4994 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_ERROR_L));
4995 SYSCTL_ADD_T4_REG64(pi, "rx_jabber", "# of jabber frames",
4996 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_CRC_ERROR_L));
4997 SYSCTL_ADD_T4_REG64(pi, "rx_fcs_err",
4998 "# of frames received with bad FCS",
4999 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_CRC_ERROR_L));
5000 SYSCTL_ADD_T4_REG64(pi, "rx_len_err",
5001 "# of frames received with length error",
5002 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LEN_ERROR_L));
5003 SYSCTL_ADD_T4_REG64(pi, "rx_symbol_err", "symbol errors",
5004 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_SYM_ERROR_L));
5005 SYSCTL_ADD_T4_REG64(pi, "rx_runt", "# of short frames received",
5006 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LESS_64B_L));
5007 SYSCTL_ADD_T4_REG64(pi, "rx_frames_64",
5008 "# of rx frames in this range",
5009 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_64B_L));
5010 SYSCTL_ADD_T4_REG64(pi, "rx_frames_65_127",
5011 "# of rx frames in this range",
5012 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_65B_127B_L));
5013 SYSCTL_ADD_T4_REG64(pi, "rx_frames_128_255",
5014 "# of rx frames in this range",
5015 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_128B_255B_L));
5016 SYSCTL_ADD_T4_REG64(pi, "rx_frames_256_511",
5017 "# of rx frames in this range",
5018 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_256B_511B_L));
5019 SYSCTL_ADD_T4_REG64(pi, "rx_frames_512_1023",
5020 "# of rx frames in this range",
5021 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_512B_1023B_L));
5022 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1024_1518",
5023 "# of rx frames in this range",
5024 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1024B_1518B_L));
5025 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1519_max",
5026 "# of rx frames in this range",
5027 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1519B_MAX_L));
5028 SYSCTL_ADD_T4_REG64(pi, "rx_pause", "# of pause frames received",
5029 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PAUSE_L));
5030 SYSCTL_ADD_T4_REG64(pi, "rx_ppp0", "# of PPP prio 0 frames received",
5031 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP0_L));
5032 SYSCTL_ADD_T4_REG64(pi, "rx_ppp1", "# of PPP prio 1 frames received",
5033 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP1_L));
5034 SYSCTL_ADD_T4_REG64(pi, "rx_ppp2", "# of PPP prio 2 frames received",
5035 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP2_L));
5036 SYSCTL_ADD_T4_REG64(pi, "rx_ppp3", "# of PPP prio 3 frames received",
5037 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP3_L));
5038 SYSCTL_ADD_T4_REG64(pi, "rx_ppp4", "# of PPP prio 4 frames received",
5039 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP4_L));
5040 SYSCTL_ADD_T4_REG64(pi, "rx_ppp5", "# of PPP prio 5 frames received",
5041 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP5_L));
5042 SYSCTL_ADD_T4_REG64(pi, "rx_ppp6", "# of PPP prio 6 frames received",
5043 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP6_L));
5044 SYSCTL_ADD_T4_REG64(pi, "rx_ppp7", "# of PPP prio 7 frames received",
5045 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP7_L));
5047 #undef SYSCTL_ADD_T4_REG64
5049 #define SYSCTL_ADD_T4_PORTSTAT(name, desc) \
5050 SYSCTL_ADD_UQUAD(ctx, children, OID_AUTO, #name, CTLFLAG_RD, \
5051 &pi->stats.name, desc)
5053 /* We get these from port_stats and they may be stale by upto 1s */
5054 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow0,
5055 "# drops due to buffer-group 0 overflows");
5056 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow1,
5057 "# drops due to buffer-group 1 overflows");
5058 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow2,
5059 "# drops due to buffer-group 2 overflows");
5060 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow3,
5061 "# drops due to buffer-group 3 overflows");
5062 SYSCTL_ADD_T4_PORTSTAT(rx_trunc0,
5063 "# of buffer-group 0 truncated packets");
5064 SYSCTL_ADD_T4_PORTSTAT(rx_trunc1,
5065 "# of buffer-group 1 truncated packets");
5066 SYSCTL_ADD_T4_PORTSTAT(rx_trunc2,
5067 "# of buffer-group 2 truncated packets");
5068 SYSCTL_ADD_T4_PORTSTAT(rx_trunc3,
5069 "# of buffer-group 3 truncated packets");
5071 #undef SYSCTL_ADD_T4_PORTSTAT
5077 sysctl_int_array(SYSCTL_HANDLER_ARGS)
5082 sbuf_new(&sb, NULL, 32, SBUF_AUTOEXTEND);
5083 for (i = arg1; arg2; arg2 -= sizeof(int), i++)
5084 sbuf_printf(&sb, "%d ", *i);
5087 rc = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
5093 sysctl_bitfield(SYSCTL_HANDLER_ARGS)
5098 rc = sysctl_wire_old_buffer(req, 0);
5102 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
5106 sbuf_printf(sb, "%b", (int)arg2, (char *)arg1);
5107 rc = sbuf_finish(sb);
5114 sysctl_btphy(SYSCTL_HANDLER_ARGS)
5116 struct port_info *pi = arg1;
5118 struct adapter *sc = pi->adapter;
5122 rc = begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4btt");
5125 /* XXX: magic numbers */
5126 rc = -t4_mdio_rd(sc, sc->mbox, pi->mdio_addr, 0x1e, op ? 0x20 : 0xc820,
5128 end_synchronized_op(sc, 0);
5134 rc = sysctl_handle_int(oidp, &v, 0, req);
5139 sysctl_noflowq(SYSCTL_HANDLER_ARGS)
5141 struct port_info *pi = arg1;
5144 val = pi->rsrv_noflowq;
5145 rc = sysctl_handle_int(oidp, &val, 0, req);
5146 if (rc != 0 || req->newptr == NULL)
5149 if ((val >= 1) && (pi->ntxq > 1))
5150 pi->rsrv_noflowq = 1;
5152 pi->rsrv_noflowq = 0;
5158 sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS)
5160 struct port_info *pi = arg1;
5161 struct adapter *sc = pi->adapter;
5163 struct sge_rxq *rxq;
5165 struct sge_ofld_rxq *ofld_rxq;
5171 rc = sysctl_handle_int(oidp, &idx, 0, req);
5172 if (rc != 0 || req->newptr == NULL)
5175 if (idx < 0 || idx >= SGE_NTIMERS)
5178 rc = begin_synchronized_op(sc, pi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5183 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(pi->pktc_idx != -1);
5184 for_each_rxq(pi, i, rxq) {
5185 #ifdef atomic_store_rel_8
5186 atomic_store_rel_8(&rxq->iq.intr_params, v);
5188 rxq->iq.intr_params = v;
5192 for_each_ofld_rxq(pi, i, ofld_rxq) {
5193 #ifdef atomic_store_rel_8
5194 atomic_store_rel_8(&ofld_rxq->iq.intr_params, v);
5196 ofld_rxq->iq.intr_params = v;
5202 end_synchronized_op(sc, LOCK_HELD);
5207 sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS)
5209 struct port_info *pi = arg1;
5210 struct adapter *sc = pi->adapter;
5215 rc = sysctl_handle_int(oidp, &idx, 0, req);
5216 if (rc != 0 || req->newptr == NULL)
5219 if (idx < -1 || idx >= SGE_NCOUNTERS)
5222 rc = begin_synchronized_op(sc, pi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5227 if (pi->flags & PORT_INIT_DONE)
5228 rc = EBUSY; /* cannot be changed once the queues are created */
5232 end_synchronized_op(sc, LOCK_HELD);
5237 sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS)
5239 struct port_info *pi = arg1;
5240 struct adapter *sc = pi->adapter;
5243 qsize = pi->qsize_rxq;
5245 rc = sysctl_handle_int(oidp, &qsize, 0, req);
5246 if (rc != 0 || req->newptr == NULL)
5249 if (qsize < 128 || (qsize & 7))
5252 rc = begin_synchronized_op(sc, pi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5257 if (pi->flags & PORT_INIT_DONE)
5258 rc = EBUSY; /* cannot be changed once the queues are created */
5260 pi->qsize_rxq = qsize;
5262 end_synchronized_op(sc, LOCK_HELD);
5267 sysctl_qsize_txq(SYSCTL_HANDLER_ARGS)
5269 struct port_info *pi = arg1;
5270 struct adapter *sc = pi->adapter;
5273 qsize = pi->qsize_txq;
5275 rc = sysctl_handle_int(oidp, &qsize, 0, req);
5276 if (rc != 0 || req->newptr == NULL)
5279 if (qsize < 128 || qsize > 65536)
5282 rc = begin_synchronized_op(sc, pi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5287 if (pi->flags & PORT_INIT_DONE)
5288 rc = EBUSY; /* cannot be changed once the queues are created */
5290 pi->qsize_txq = qsize;
5292 end_synchronized_op(sc, LOCK_HELD);
5297 sysctl_pause_settings(SYSCTL_HANDLER_ARGS)
5299 struct port_info *pi = arg1;
5300 struct adapter *sc = pi->adapter;
5301 struct link_config *lc = &pi->link_cfg;
5304 if (req->newptr == NULL) {
5306 static char *bits = "\20\1PAUSE_RX\2PAUSE_TX";
5308 rc = sysctl_wire_old_buffer(req, 0);
5312 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
5316 sbuf_printf(sb, "%b", lc->fc & (PAUSE_TX | PAUSE_RX), bits);
5317 rc = sbuf_finish(sb);
5323 s[0] = '0' + (lc->requested_fc & (PAUSE_TX | PAUSE_RX));
5326 rc = sysctl_handle_string(oidp, s, sizeof(s), req);
5332 if (s[0] < '0' || s[0] > '9')
5333 return (EINVAL); /* not a number */
5335 if (n & ~(PAUSE_TX | PAUSE_RX))
5336 return (EINVAL); /* some other bit is set too */
5338 rc = begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4PAUSE");
5341 if ((lc->requested_fc & (PAUSE_TX | PAUSE_RX)) != n) {
5342 int link_ok = lc->link_ok;
5344 lc->requested_fc &= ~(PAUSE_TX | PAUSE_RX);
5345 lc->requested_fc |= n;
5346 rc = -t4_link_start(sc, sc->mbox, pi->tx_chan, lc);
5347 lc->link_ok = link_ok; /* restore */
5349 end_synchronized_op(sc, 0);
5356 sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS)
5358 struct adapter *sc = arg1;
5362 val = t4_read_reg64(sc, reg);
5364 return (sysctl_handle_64(oidp, &val, 0, req));
5368 sysctl_temperature(SYSCTL_HANDLER_ARGS)
5370 struct adapter *sc = arg1;
5372 uint32_t param, val;
5374 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4temp");
5377 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
5378 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) |
5379 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_TMP);
5380 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
5381 end_synchronized_op(sc, 0);
5385 /* unknown is returned as 0 but we display -1 in that case */
5386 t = val == 0 ? -1 : val;
5388 rc = sysctl_handle_int(oidp, &t, 0, req);
5394 sysctl_cctrl(SYSCTL_HANDLER_ARGS)
5396 struct adapter *sc = arg1;
5399 uint16_t incr[NMTUS][NCCTRL_WIN];
5400 static const char *dec_fac[] = {
5401 "0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
5405 rc = sysctl_wire_old_buffer(req, 0);
5409 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
5413 t4_read_cong_tbl(sc, incr);
5415 for (i = 0; i < NCCTRL_WIN; ++i) {
5416 sbuf_printf(sb, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
5417 incr[0][i], incr[1][i], incr[2][i], incr[3][i], incr[4][i],
5418 incr[5][i], incr[6][i], incr[7][i]);
5419 sbuf_printf(sb, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
5420 incr[8][i], incr[9][i], incr[10][i], incr[11][i],
5421 incr[12][i], incr[13][i], incr[14][i], incr[15][i],
5422 sc->params.a_wnd[i], dec_fac[sc->params.b_wnd[i]]);
5425 rc = sbuf_finish(sb);
5431 static const char *qname[CIM_NUM_IBQ + CIM_NUM_OBQ_T5] = {
5432 "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI", /* ibq's */
5433 "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI", /* obq's */
5434 "SGE0-RX", "SGE1-RX" /* additional obq's (T5 onwards) */
5438 sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS)
5440 struct adapter *sc = arg1;
5442 int rc, i, n, qid = arg2;
5445 u_int cim_num_obq = is_t4(sc) ? CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
5447 KASSERT(qid >= 0 && qid < CIM_NUM_IBQ + cim_num_obq,
5448 ("%s: bad qid %d\n", __func__, qid));
5450 if (qid < CIM_NUM_IBQ) {
5453 n = 4 * CIM_IBQ_SIZE;
5454 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
5455 rc = t4_read_cim_ibq(sc, qid, buf, n);
5457 /* outbound queue */
5460 n = 4 * cim_num_obq * CIM_OBQ_SIZE;
5461 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
5462 rc = t4_read_cim_obq(sc, qid, buf, n);
5469 n = rc * sizeof(uint32_t); /* rc has # of words actually read */
5471 rc = sysctl_wire_old_buffer(req, 0);
5475 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
5481 sbuf_printf(sb, "%s%d %s", qtype , qid, qname[arg2]);
5482 for (i = 0, p = buf; i < n; i += 16, p += 4)
5483 sbuf_printf(sb, "\n%#06x: %08x %08x %08x %08x", i, p[0], p[1],
5486 rc = sbuf_finish(sb);
5494 sysctl_cim_la(SYSCTL_HANDLER_ARGS)
5496 struct adapter *sc = arg1;
5502 rc = -t4_cim_read(sc, A_UP_UP_DBG_LA_CFG, 1, &cfg);
5506 rc = sysctl_wire_old_buffer(req, 0);
5510 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
5514 buf = malloc(sc->params.cim_la_size * sizeof(uint32_t), M_CXGBE,
5517 rc = -t4_cim_read_la(sc, buf, NULL);
5521 sbuf_printf(sb, "Status Data PC%s",
5522 cfg & F_UPDBGLACAPTPCONLY ? "" :
5523 " LS0Stat LS0Addr LS0Data");
5525 KASSERT((sc->params.cim_la_size & 7) == 0,
5526 ("%s: p will walk off the end of buf", __func__));
5528 for (p = buf; p < &buf[sc->params.cim_la_size]; p += 8) {
5529 if (cfg & F_UPDBGLACAPTPCONLY) {
5530 sbuf_printf(sb, "\n %02x %08x %08x", p[5] & 0xff,
5532 sbuf_printf(sb, "\n %02x %02x%06x %02x%06x",
5533 (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8,
5534 p[4] & 0xff, p[5] >> 8);
5535 sbuf_printf(sb, "\n %02x %x%07x %x%07x",
5536 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
5537 p[1] & 0xf, p[2] >> 4);
5540 "\n %02x %x%07x %x%07x %08x %08x "
5542 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
5543 p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5],
5548 rc = sbuf_finish(sb);
5556 sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS)
5558 struct adapter *sc = arg1;
5564 rc = sysctl_wire_old_buffer(req, 0);
5568 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
5572 buf = malloc(2 * CIM_MALA_SIZE * 5 * sizeof(uint32_t), M_CXGBE,
5575 t4_cim_read_ma_la(sc, buf, buf + 5 * CIM_MALA_SIZE);
5578 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
5579 sbuf_printf(sb, "\n%02x%08x%08x%08x%08x", p[4], p[3], p[2],
5583 sbuf_printf(sb, "\n\nCnt ID Tag UE Data RDY VLD");
5584 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
5585 sbuf_printf(sb, "\n%3u %2u %x %u %08x%08x %u %u",
5586 (p[2] >> 10) & 0xff, (p[2] >> 7) & 7,
5587 (p[2] >> 3) & 0xf, (p[2] >> 2) & 1,
5588 (p[1] >> 2) | ((p[2] & 3) << 30),
5589 (p[0] >> 2) | ((p[1] & 3) << 30), (p[0] >> 1) & 1,
5593 rc = sbuf_finish(sb);
5600 sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS)
5602 struct adapter *sc = arg1;
5608 rc = sysctl_wire_old_buffer(req, 0);
5612 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
5616 buf = malloc(2 * CIM_PIFLA_SIZE * 6 * sizeof(uint32_t), M_CXGBE,
5619 t4_cim_read_pif_la(sc, buf, buf + 6 * CIM_PIFLA_SIZE, NULL, NULL);
5622 sbuf_printf(sb, "Cntl ID DataBE Addr Data");
5623 for (i = 0; i < CIM_MALA_SIZE; i++, p += 6) {
5624 sbuf_printf(sb, "\n %02x %02x %04x %08x %08x%08x%08x%08x",
5625 (p[5] >> 22) & 0xff, (p[5] >> 16) & 0x3f, p[5] & 0xffff,
5626 p[4], p[3], p[2], p[1], p[0]);
5629 sbuf_printf(sb, "\n\nCntl ID Data");
5630 for (i = 0; i < CIM_MALA_SIZE; i++, p += 6) {
5631 sbuf_printf(sb, "\n %02x %02x %08x%08x%08x%08x",
5632 (p[4] >> 6) & 0xff, p[4] & 0x3f, p[3], p[2], p[1], p[0]);
5635 rc = sbuf_finish(sb);
5642 sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS)
5644 struct adapter *sc = arg1;
5647 uint16_t base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
5648 uint16_t size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
5649 uint16_t thres[CIM_NUM_IBQ];
5650 uint32_t obq_wr[2 * CIM_NUM_OBQ_T5], *wr = obq_wr;
5651 uint32_t stat[4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5)], *p = stat;
5652 u_int cim_num_obq, ibq_rdaddr, obq_rdaddr, nq;
5655 cim_num_obq = CIM_NUM_OBQ;
5656 ibq_rdaddr = A_UP_IBQ_0_RDADDR;
5657 obq_rdaddr = A_UP_OBQ_0_REALADDR;
5659 cim_num_obq = CIM_NUM_OBQ_T5;
5660 ibq_rdaddr = A_UP_IBQ_0_SHADOW_RDADDR;
5661 obq_rdaddr = A_UP_OBQ_0_SHADOW_REALADDR;
5663 nq = CIM_NUM_IBQ + cim_num_obq;
5665 rc = -t4_cim_read(sc, ibq_rdaddr, 4 * nq, stat);
5667 rc = -t4_cim_read(sc, obq_rdaddr, 2 * cim_num_obq, obq_wr);
5671 t4_read_cimq_cfg(sc, base, size, thres);
5673 rc = sysctl_wire_old_buffer(req, 0);
5677 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
5681 sbuf_printf(sb, "Queue Base Size Thres RdPtr WrPtr SOP EOP Avail");
5683 for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
5684 sbuf_printf(sb, "\n%7s %5x %5u %5u %6x %4x %4u %4u %5u",
5685 qname[i], base[i], size[i], thres[i], G_IBQRDADDR(p[0]),
5686 G_IBQWRADDR(p[1]), G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
5687 G_QUEREMFLITS(p[2]) * 16);
5688 for ( ; i < nq; i++, p += 4, wr += 2)
5689 sbuf_printf(sb, "\n%7s %5x %5u %12x %4x %4u %4u %5u", qname[i],
5690 base[i], size[i], G_QUERDADDR(p[0]) & 0x3fff,
5691 wr[0] - base[i], G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
5692 G_QUEREMFLITS(p[2]) * 16);
5694 rc = sbuf_finish(sb);
5701 sysctl_cpl_stats(SYSCTL_HANDLER_ARGS)
5703 struct adapter *sc = arg1;
5706 struct tp_cpl_stats stats;
5708 rc = sysctl_wire_old_buffer(req, 0);
5712 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
5716 t4_tp_get_cpl_stats(sc, &stats);
5718 sbuf_printf(sb, " channel 0 channel 1 channel 2 "
5720 sbuf_printf(sb, "CPL requests: %10u %10u %10u %10u\n",
5721 stats.req[0], stats.req[1], stats.req[2], stats.req[3]);
5722 sbuf_printf(sb, "CPL responses: %10u %10u %10u %10u",
5723 stats.rsp[0], stats.rsp[1], stats.rsp[2], stats.rsp[3]);
5725 rc = sbuf_finish(sb);
5732 sysctl_ddp_stats(SYSCTL_HANDLER_ARGS)
5734 struct adapter *sc = arg1;
5737 struct tp_usm_stats stats;
5739 rc = sysctl_wire_old_buffer(req, 0);
5743 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
5747 t4_get_usm_stats(sc, &stats);
5749 sbuf_printf(sb, "Frames: %u\n", stats.frames);
5750 sbuf_printf(sb, "Octets: %ju\n", stats.octets);
5751 sbuf_printf(sb, "Drops: %u", stats.drops);
5753 rc = sbuf_finish(sb);
5759 const char *devlog_level_strings[] = {
5760 [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
5761 [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
5762 [FW_DEVLOG_LEVEL_ERR] = "ERR",
5763 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
5764 [FW_DEVLOG_LEVEL_INFO] = "INFO",
5765 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
5768 const char *devlog_facility_strings[] = {
5769 [FW_DEVLOG_FACILITY_CORE] = "CORE",
5770 [FW_DEVLOG_FACILITY_CF] = "CF",
5771 [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
5772 [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
5773 [FW_DEVLOG_FACILITY_RES] = "RES",
5774 [FW_DEVLOG_FACILITY_HW] = "HW",
5775 [FW_DEVLOG_FACILITY_FLR] = "FLR",
5776 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
5777 [FW_DEVLOG_FACILITY_PHY] = "PHY",
5778 [FW_DEVLOG_FACILITY_MAC] = "MAC",
5779 [FW_DEVLOG_FACILITY_PORT] = "PORT",
5780 [FW_DEVLOG_FACILITY_VI] = "VI",
5781 [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
5782 [FW_DEVLOG_FACILITY_ACL] = "ACL",
5783 [FW_DEVLOG_FACILITY_TM] = "TM",
5784 [FW_DEVLOG_FACILITY_QFC] = "QFC",
5785 [FW_DEVLOG_FACILITY_DCB] = "DCB",
5786 [FW_DEVLOG_FACILITY_ETH] = "ETH",
5787 [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
5788 [FW_DEVLOG_FACILITY_RI] = "RI",
5789 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
5790 [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
5791 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
5792 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE"
5796 sysctl_devlog(SYSCTL_HANDLER_ARGS)
5798 struct adapter *sc = arg1;
5799 struct devlog_params *dparams = &sc->params.devlog;
5800 struct fw_devlog_e *buf, *e;
5801 int i, j, rc, nentries, first = 0, m;
5803 uint64_t ftstamp = UINT64_MAX;
5805 if (dparams->start == 0) {
5806 dparams->memtype = FW_MEMTYPE_EDC0;
5807 dparams->start = 0x84000;
5808 dparams->size = 32768;
5811 nentries = dparams->size / sizeof(struct fw_devlog_e);
5813 buf = malloc(dparams->size, M_CXGBE, M_NOWAIT);
5817 m = fwmtype_to_hwmtype(dparams->memtype);
5818 rc = -t4_mem_read(sc, m, dparams->start, dparams->size, (void *)buf);
5822 for (i = 0; i < nentries; i++) {
5825 if (e->timestamp == 0)
5828 e->timestamp = be64toh(e->timestamp);
5829 e->seqno = be32toh(e->seqno);
5830 for (j = 0; j < 8; j++)
5831 e->params[j] = be32toh(e->params[j]);
5833 if (e->timestamp < ftstamp) {
5834 ftstamp = e->timestamp;
5839 if (buf[first].timestamp == 0)
5840 goto done; /* nothing in the log */
5842 rc = sysctl_wire_old_buffer(req, 0);
5846 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
5851 sbuf_printf(sb, "%10s %15s %8s %8s %s\n",
5852 "Seq#", "Tstamp", "Level", "Facility", "Message");
5857 if (e->timestamp == 0)
5860 sbuf_printf(sb, "%10d %15ju %8s %8s ",
5861 e->seqno, e->timestamp,
5862 (e->level < nitems(devlog_level_strings) ?
5863 devlog_level_strings[e->level] : "UNKNOWN"),
5864 (e->facility < nitems(devlog_facility_strings) ?
5865 devlog_facility_strings[e->facility] : "UNKNOWN"));
5866 sbuf_printf(sb, e->fmt, e->params[0], e->params[1],
5867 e->params[2], e->params[3], e->params[4],
5868 e->params[5], e->params[6], e->params[7]);
5870 if (++i == nentries)
5872 } while (i != first);
5874 rc = sbuf_finish(sb);
5882 sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS)
5884 struct adapter *sc = arg1;
5887 struct tp_fcoe_stats stats[4];
5889 rc = sysctl_wire_old_buffer(req, 0);
5893 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
5897 t4_get_fcoe_stats(sc, 0, &stats[0]);
5898 t4_get_fcoe_stats(sc, 1, &stats[1]);
5899 t4_get_fcoe_stats(sc, 2, &stats[2]);
5900 t4_get_fcoe_stats(sc, 3, &stats[3]);
5902 sbuf_printf(sb, " channel 0 channel 1 "
5903 "channel 2 channel 3\n");
5904 sbuf_printf(sb, "octetsDDP: %16ju %16ju %16ju %16ju\n",
5905 stats[0].octetsDDP, stats[1].octetsDDP, stats[2].octetsDDP,
5906 stats[3].octetsDDP);
5907 sbuf_printf(sb, "framesDDP: %16u %16u %16u %16u\n", stats[0].framesDDP,
5908 stats[1].framesDDP, stats[2].framesDDP, stats[3].framesDDP);
5909 sbuf_printf(sb, "framesDrop: %16u %16u %16u %16u",
5910 stats[0].framesDrop, stats[1].framesDrop, stats[2].framesDrop,
5911 stats[3].framesDrop);
5913 rc = sbuf_finish(sb);
5920 sysctl_hw_sched(SYSCTL_HANDLER_ARGS)
5922 struct adapter *sc = arg1;
5925 unsigned int map, kbps, ipg, mode;
5926 unsigned int pace_tab[NTX_SCHED];
5928 rc = sysctl_wire_old_buffer(req, 0);
5932 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
5936 map = t4_read_reg(sc, A_TP_TX_MOD_QUEUE_REQ_MAP);
5937 mode = G_TIMERMODE(t4_read_reg(sc, A_TP_MOD_CONFIG));
5938 t4_read_pace_tbl(sc, pace_tab);
5940 sbuf_printf(sb, "Scheduler Mode Channel Rate (Kbps) "
5941 "Class IPG (0.1 ns) Flow IPG (us)");
5943 for (i = 0; i < NTX_SCHED; ++i, map >>= 2) {
5944 t4_get_tx_sched(sc, i, &kbps, &ipg);
5945 sbuf_printf(sb, "\n %u %-5s %u ", i,
5946 (mode & (1 << i)) ? "flow" : "class", map & 3);
5948 sbuf_printf(sb, "%9u ", kbps);
5950 sbuf_printf(sb, " disabled ");
5953 sbuf_printf(sb, "%13u ", ipg);
5955 sbuf_printf(sb, " disabled ");
5958 sbuf_printf(sb, "%10u", pace_tab[i]);
5960 sbuf_printf(sb, " disabled");
5963 rc = sbuf_finish(sb);
5970 sysctl_lb_stats(SYSCTL_HANDLER_ARGS)
5972 struct adapter *sc = arg1;
5976 struct lb_port_stats s[2];
5977 static const char *stat_name[] = {
5978 "OctetsOK:", "FramesOK:", "BcastFrames:", "McastFrames:",
5979 "UcastFrames:", "ErrorFrames:", "Frames64:", "Frames65To127:",
5980 "Frames128To255:", "Frames256To511:", "Frames512To1023:",
5981 "Frames1024To1518:", "Frames1519ToMax:", "FramesDropped:",
5982 "BG0FramesDropped:", "BG1FramesDropped:", "BG2FramesDropped:",
5983 "BG3FramesDropped:", "BG0FramesTrunc:", "BG1FramesTrunc:",
5984 "BG2FramesTrunc:", "BG3FramesTrunc:"
5987 rc = sysctl_wire_old_buffer(req, 0);
5991 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
5995 memset(s, 0, sizeof(s));
5997 for (i = 0; i < 4; i += 2) {
5998 t4_get_lb_stats(sc, i, &s[0]);
5999 t4_get_lb_stats(sc, i + 1, &s[1]);
6003 sbuf_printf(sb, "%s Loopback %u"
6004 " Loopback %u", i == 0 ? "" : "\n", i, i + 1);
6006 for (j = 0; j < nitems(stat_name); j++)
6007 sbuf_printf(sb, "\n%-17s %20ju %20ju", stat_name[j],
6011 rc = sbuf_finish(sb);
6018 sysctl_linkdnrc(SYSCTL_HANDLER_ARGS)
6021 struct port_info *pi = arg1;
6023 static const char *linkdnreasons[] = {
6024 "non-specific", "remote fault", "autoneg failed", "reserved3",
6025 "PHY overheated", "unknown", "rx los", "reserved7"
6028 rc = sysctl_wire_old_buffer(req, 0);
6031 sb = sbuf_new_for_sysctl(NULL, NULL, 64, req);
6035 if (pi->linkdnrc < 0)
6036 sbuf_printf(sb, "n/a");
6037 else if (pi->linkdnrc < nitems(linkdnreasons))
6038 sbuf_printf(sb, "%s", linkdnreasons[pi->linkdnrc]);
6040 sbuf_printf(sb, "%d", pi->linkdnrc);
6042 rc = sbuf_finish(sb);
6055 mem_desc_cmp(const void *a, const void *b)
6057 return ((const struct mem_desc *)a)->base -
6058 ((const struct mem_desc *)b)->base;
6062 mem_region_show(struct sbuf *sb, const char *name, unsigned int from,
6067 size = to - from + 1;
6071 /* XXX: need humanize_number(3) in libkern for a more readable 'size' */
6072 sbuf_printf(sb, "%-15s %#x-%#x [%u]\n", name, from, to, size);
6076 sysctl_meminfo(SYSCTL_HANDLER_ARGS)
6078 struct adapter *sc = arg1;
6081 uint32_t lo, hi, used, alloc;
6082 static const char *memory[] = {"EDC0:", "EDC1:", "MC:", "MC0:", "MC1:"};
6083 static const char *region[] = {
6084 "DBQ contexts:", "IMSG contexts:", "FLM cache:", "TCBs:",
6085 "Pstructs:", "Timers:", "Rx FL:", "Tx FL:", "Pstruct FL:",
6086 "Tx payload:", "Rx payload:", "LE hash:", "iSCSI region:",
6087 "TDDP region:", "TPT region:", "STAG region:", "RQ region:",
6088 "RQUDP region:", "PBL region:", "TXPBL region:",
6089 "DBVFIFO region:", "ULPRX state:", "ULPTX state:",
6092 struct mem_desc avail[4];
6093 struct mem_desc mem[nitems(region) + 3]; /* up to 3 holes */
6094 struct mem_desc *md = mem;
6096 rc = sysctl_wire_old_buffer(req, 0);
6100 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6104 for (i = 0; i < nitems(mem); i++) {
6109 /* Find and sort the populated memory ranges */
6111 lo = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
6112 if (lo & F_EDRAM0_ENABLE) {
6113 hi = t4_read_reg(sc, A_MA_EDRAM0_BAR);
6114 avail[i].base = G_EDRAM0_BASE(hi) << 20;
6115 avail[i].limit = avail[i].base + (G_EDRAM0_SIZE(hi) << 20);
6119 if (lo & F_EDRAM1_ENABLE) {
6120 hi = t4_read_reg(sc, A_MA_EDRAM1_BAR);
6121 avail[i].base = G_EDRAM1_BASE(hi) << 20;
6122 avail[i].limit = avail[i].base + (G_EDRAM1_SIZE(hi) << 20);
6126 if (lo & F_EXT_MEM_ENABLE) {
6127 hi = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
6128 avail[i].base = G_EXT_MEM_BASE(hi) << 20;
6129 avail[i].limit = avail[i].base +
6130 (G_EXT_MEM_SIZE(hi) << 20);
6131 avail[i].idx = is_t4(sc) ? 2 : 3; /* Call it MC for T4 */
6134 if (!is_t4(sc) && lo & F_EXT_MEM1_ENABLE) {
6135 hi = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
6136 avail[i].base = G_EXT_MEM1_BASE(hi) << 20;
6137 avail[i].limit = avail[i].base +
6138 (G_EXT_MEM1_SIZE(hi) << 20);
6142 if (!i) /* no memory available */
6144 qsort(avail, i, sizeof(struct mem_desc), mem_desc_cmp);
6146 (md++)->base = t4_read_reg(sc, A_SGE_DBQ_CTXT_BADDR);
6147 (md++)->base = t4_read_reg(sc, A_SGE_IMSG_CTXT_BADDR);
6148 (md++)->base = t4_read_reg(sc, A_SGE_FLM_CACHE_BADDR);
6149 (md++)->base = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
6150 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_BASE);
6151 (md++)->base = t4_read_reg(sc, A_TP_CMM_TIMER_BASE);
6152 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_RX_FLST_BASE);
6153 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_TX_FLST_BASE);
6154 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_PS_FLST_BASE);
6156 /* the next few have explicit upper bounds */
6157 md->base = t4_read_reg(sc, A_TP_PMM_TX_BASE);
6158 md->limit = md->base - 1 +
6159 t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE) *
6160 G_PMTXMAXPAGE(t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE));
6163 md->base = t4_read_reg(sc, A_TP_PMM_RX_BASE);
6164 md->limit = md->base - 1 +
6165 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) *
6166 G_PMRXMAXPAGE(t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE));
6169 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
6170 hi = t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4;
6171 md->base = t4_read_reg(sc, A_LE_DB_HASH_TID_BASE);
6172 md->limit = (sc->tids.ntids - hi) * 16 + md->base - 1;
6175 md->idx = nitems(region); /* hide it */
6179 #define ulp_region(reg) \
6180 md->base = t4_read_reg(sc, A_ULP_ ## reg ## _LLIMIT);\
6181 (md++)->limit = t4_read_reg(sc, A_ULP_ ## reg ## _ULIMIT)
6183 ulp_region(RX_ISCSI);
6184 ulp_region(RX_TDDP);
6186 ulp_region(RX_STAG);
6188 ulp_region(RX_RQUDP);
6194 md->idx = nitems(region);
6195 if (!is_t4(sc) && t4_read_reg(sc, A_SGE_CONTROL2) & F_VFIFO_ENABLE) {
6196 md->base = G_BASEADDR(t4_read_reg(sc, A_SGE_DBVFIFO_BADDR));
6197 md->limit = md->base + (G_DBVFIFO_SIZE((t4_read_reg(sc,
6198 A_SGE_DBVFIFO_SIZE))) << 2) - 1;
6202 md->base = t4_read_reg(sc, A_ULP_RX_CTX_BASE);
6203 md->limit = md->base + sc->tids.ntids - 1;
6205 md->base = t4_read_reg(sc, A_ULP_TX_ERR_TABLE_BASE);
6206 md->limit = md->base + sc->tids.ntids - 1;
6209 md->base = sc->vres.ocq.start;
6210 if (sc->vres.ocq.size)
6211 md->limit = md->base + sc->vres.ocq.size - 1;
6213 md->idx = nitems(region); /* hide it */
6216 /* add any address-space holes, there can be up to 3 */
6217 for (n = 0; n < i - 1; n++)
6218 if (avail[n].limit < avail[n + 1].base)
6219 (md++)->base = avail[n].limit;
6221 (md++)->base = avail[n].limit;
6224 qsort(mem, n, sizeof(struct mem_desc), mem_desc_cmp);
6226 for (lo = 0; lo < i; lo++)
6227 mem_region_show(sb, memory[avail[lo].idx], avail[lo].base,
6228 avail[lo].limit - 1);
6230 sbuf_printf(sb, "\n");
6231 for (i = 0; i < n; i++) {
6232 if (mem[i].idx >= nitems(region))
6233 continue; /* skip holes */
6235 mem[i].limit = i < n - 1 ? mem[i + 1].base - 1 : ~0;
6236 mem_region_show(sb, region[mem[i].idx], mem[i].base,
6240 sbuf_printf(sb, "\n");
6241 lo = t4_read_reg(sc, A_CIM_SDRAM_BASE_ADDR);
6242 hi = t4_read_reg(sc, A_CIM_SDRAM_ADDR_SIZE) + lo - 1;
6243 mem_region_show(sb, "uP RAM:", lo, hi);
6245 lo = t4_read_reg(sc, A_CIM_EXTMEM2_BASE_ADDR);
6246 hi = t4_read_reg(sc, A_CIM_EXTMEM2_ADDR_SIZE) + lo - 1;
6247 mem_region_show(sb, "uP Extmem2:", lo, hi);
6249 lo = t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE);
6250 sbuf_printf(sb, "\n%u Rx pages of size %uKiB for %u channels\n",
6252 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) >> 10,
6253 (lo & F_PMRXNUMCHN) ? 2 : 1);
6255 lo = t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE);
6256 hi = t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE);
6257 sbuf_printf(sb, "%u Tx pages of size %u%ciB for %u channels\n",
6259 hi >= (1 << 20) ? (hi >> 20) : (hi >> 10),
6260 hi >= (1 << 20) ? 'M' : 'K', 1 << G_PMTXNUMCHN(lo));
6261 sbuf_printf(sb, "%u p-structs\n",
6262 t4_read_reg(sc, A_TP_CMM_MM_MAX_PSTRUCT));
6264 for (i = 0; i < 4; i++) {
6265 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV0 + i * 4);
6268 alloc = G_ALLOC(lo);
6270 used = G_T5_USED(lo);
6271 alloc = G_T5_ALLOC(lo);
6273 sbuf_printf(sb, "\nPort %d using %u pages out of %u allocated",
6276 for (i = 0; i < 4; i++) {
6277 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV4 + i * 4);
6280 alloc = G_ALLOC(lo);
6282 used = G_T5_USED(lo);
6283 alloc = G_T5_ALLOC(lo);
6286 "\nLoopback %d using %u pages out of %u allocated",
6290 rc = sbuf_finish(sb);
6297 tcamxy2valmask(uint64_t x, uint64_t y, uint8_t *addr, uint64_t *mask)
6301 memcpy(addr, (char *)&y + 2, ETHER_ADDR_LEN);
6305 sysctl_mps_tcam(SYSCTL_HANDLER_ARGS)
6307 struct adapter *sc = arg1;
6311 rc = sysctl_wire_old_buffer(req, 0);
6315 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6320 "Idx Ethernet address Mask Vld Ports PF"
6321 " VF Replication P0 P1 P2 P3 ML");
6322 n = is_t4(sc) ? NUM_MPS_CLS_SRAM_L_INSTANCES :
6323 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
6324 for (i = 0; i < n; i++) {
6325 uint64_t tcamx, tcamy, mask;
6326 uint32_t cls_lo, cls_hi;
6327 uint8_t addr[ETHER_ADDR_LEN];
6329 tcamy = t4_read_reg64(sc, MPS_CLS_TCAM_Y_L(i));
6330 tcamx = t4_read_reg64(sc, MPS_CLS_TCAM_X_L(i));
6331 cls_lo = t4_read_reg(sc, MPS_CLS_SRAM_L(i));
6332 cls_hi = t4_read_reg(sc, MPS_CLS_SRAM_H(i));
6337 tcamxy2valmask(tcamx, tcamy, addr, &mask);
6338 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x %012jx"
6339 " %c %#x%4u%4d", i, addr[0], addr[1], addr[2],
6340 addr[3], addr[4], addr[5], (uintmax_t)mask,
6341 (cls_lo & F_SRAM_VLD) ? 'Y' : 'N',
6342 G_PORTMAP(cls_hi), G_PF(cls_lo),
6343 (cls_lo & F_VF_VALID) ? G_VF(cls_lo) : -1);
6345 if (cls_lo & F_REPLICATE) {
6346 struct fw_ldst_cmd ldst_cmd;
6348 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
6349 ldst_cmd.op_to_addrspace =
6350 htobe32(V_FW_CMD_OP(FW_LDST_CMD) |
6351 F_FW_CMD_REQUEST | F_FW_CMD_READ |
6352 V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MPS));
6353 ldst_cmd.cycles_to_len16 = htobe32(FW_LEN16(ldst_cmd));
6354 ldst_cmd.u.mps.fid_ctl =
6355 htobe16(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) |
6356 V_FW_LDST_CMD_CTL(i));
6358 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK,
6362 rc = -t4_wr_mbox(sc, sc->mbox, &ldst_cmd,
6363 sizeof(ldst_cmd), &ldst_cmd);
6364 end_synchronized_op(sc, 0);
6368 " ------------ error %3u ------------", rc);
6371 sbuf_printf(sb, " %08x %08x %08x %08x",
6372 be32toh(ldst_cmd.u.mps.rplc127_96),
6373 be32toh(ldst_cmd.u.mps.rplc95_64),
6374 be32toh(ldst_cmd.u.mps.rplc63_32),
6375 be32toh(ldst_cmd.u.mps.rplc31_0));
6378 sbuf_printf(sb, "%36s", "");
6380 sbuf_printf(sb, "%4u%3u%3u%3u %#3x", G_SRAM_PRIO0(cls_lo),
6381 G_SRAM_PRIO1(cls_lo), G_SRAM_PRIO2(cls_lo),
6382 G_SRAM_PRIO3(cls_lo), (cls_lo >> S_MULTILISTEN0) & 0xf);
6386 (void) sbuf_finish(sb);
6388 rc = sbuf_finish(sb);
6395 sysctl_path_mtus(SYSCTL_HANDLER_ARGS)
6397 struct adapter *sc = arg1;
6400 uint16_t mtus[NMTUS];
6402 rc = sysctl_wire_old_buffer(req, 0);
6406 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6410 t4_read_mtu_tbl(sc, mtus, NULL);
6412 sbuf_printf(sb, "%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u",
6413 mtus[0], mtus[1], mtus[2], mtus[3], mtus[4], mtus[5], mtus[6],
6414 mtus[7], mtus[8], mtus[9], mtus[10], mtus[11], mtus[12], mtus[13],
6415 mtus[14], mtus[15]);
6417 rc = sbuf_finish(sb);
6424 sysctl_pm_stats(SYSCTL_HANDLER_ARGS)
6426 struct adapter *sc = arg1;
6429 uint32_t cnt[PM_NSTATS];
6430 uint64_t cyc[PM_NSTATS];
6431 static const char *rx_stats[] = {
6432 "Read:", "Write bypass:", "Write mem:", "Flush:"
6434 static const char *tx_stats[] = {
6435 "Read:", "Write bypass:", "Write mem:", "Bypass + mem:"
6438 rc = sysctl_wire_old_buffer(req, 0);
6442 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6446 t4_pmtx_get_stats(sc, cnt, cyc);
6447 sbuf_printf(sb, " Tx pcmds Tx bytes");
6448 for (i = 0; i < ARRAY_SIZE(tx_stats); i++)
6449 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], cnt[i],
6452 t4_pmrx_get_stats(sc, cnt, cyc);
6453 sbuf_printf(sb, "\n Rx pcmds Rx bytes");
6454 for (i = 0; i < ARRAY_SIZE(rx_stats); i++)
6455 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], cnt[i],
6458 rc = sbuf_finish(sb);
6465 sysctl_rdma_stats(SYSCTL_HANDLER_ARGS)
6467 struct adapter *sc = arg1;
6470 struct tp_rdma_stats stats;
6472 rc = sysctl_wire_old_buffer(req, 0);
6476 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6480 t4_tp_get_rdma_stats(sc, &stats);
6481 sbuf_printf(sb, "NoRQEModDefferals: %u\n", stats.rqe_dfr_mod);
6482 sbuf_printf(sb, "NoRQEPktDefferals: %u", stats.rqe_dfr_pkt);
6484 rc = sbuf_finish(sb);
6491 sysctl_tcp_stats(SYSCTL_HANDLER_ARGS)
6493 struct adapter *sc = arg1;
6496 struct tp_tcp_stats v4, v6;
6498 rc = sysctl_wire_old_buffer(req, 0);
6502 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6506 t4_tp_get_tcp_stats(sc, &v4, &v6);
6509 sbuf_printf(sb, "OutRsts: %20u %20u\n",
6510 v4.tcpOutRsts, v6.tcpOutRsts);
6511 sbuf_printf(sb, "InSegs: %20ju %20ju\n",
6512 v4.tcpInSegs, v6.tcpInSegs);
6513 sbuf_printf(sb, "OutSegs: %20ju %20ju\n",
6514 v4.tcpOutSegs, v6.tcpOutSegs);
6515 sbuf_printf(sb, "RetransSegs: %20ju %20ju",
6516 v4.tcpRetransSegs, v6.tcpRetransSegs);
6518 rc = sbuf_finish(sb);
6525 sysctl_tids(SYSCTL_HANDLER_ARGS)
6527 struct adapter *sc = arg1;
6530 struct tid_info *t = &sc->tids;
6532 rc = sysctl_wire_old_buffer(req, 0);
6536 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6541 sbuf_printf(sb, "ATID range: 0-%u, in use: %u\n", t->natids - 1,
6546 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
6547 uint32_t b = t4_read_reg(sc, A_LE_DB_SERVER_INDEX) / 4;
6550 sbuf_printf(sb, "TID range: 0-%u, %u-%u", b - 1,
6551 t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4,
6554 sbuf_printf(sb, "TID range: %u-%u",
6555 t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4,
6559 sbuf_printf(sb, "TID range: 0-%u", t->ntids - 1);
6560 sbuf_printf(sb, ", in use: %u\n",
6561 atomic_load_acq_int(&t->tids_in_use));
6565 sbuf_printf(sb, "STID range: %u-%u, in use: %u\n", t->stid_base,
6566 t->stid_base + t->nstids - 1, t->stids_in_use);
6570 sbuf_printf(sb, "FTID range: %u-%u\n", t->ftid_base,
6571 t->ftid_base + t->nftids - 1);
6575 sbuf_printf(sb, "ETID range: %u-%u\n", t->etid_base,
6576 t->etid_base + t->netids - 1);
6579 sbuf_printf(sb, "HW TID usage: %u IP users, %u IPv6 users",
6580 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV4),
6581 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV6));
6583 rc = sbuf_finish(sb);
6590 sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS)
6592 struct adapter *sc = arg1;
6595 struct tp_err_stats stats;
6597 rc = sysctl_wire_old_buffer(req, 0);
6601 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6605 t4_tp_get_err_stats(sc, &stats);
6607 sbuf_printf(sb, " channel 0 channel 1 channel 2 "
6609 sbuf_printf(sb, "macInErrs: %10u %10u %10u %10u\n",
6610 stats.macInErrs[0], stats.macInErrs[1], stats.macInErrs[2],
6611 stats.macInErrs[3]);
6612 sbuf_printf(sb, "hdrInErrs: %10u %10u %10u %10u\n",
6613 stats.hdrInErrs[0], stats.hdrInErrs[1], stats.hdrInErrs[2],
6614 stats.hdrInErrs[3]);
6615 sbuf_printf(sb, "tcpInErrs: %10u %10u %10u %10u\n",
6616 stats.tcpInErrs[0], stats.tcpInErrs[1], stats.tcpInErrs[2],
6617 stats.tcpInErrs[3]);
6618 sbuf_printf(sb, "tcp6InErrs: %10u %10u %10u %10u\n",
6619 stats.tcp6InErrs[0], stats.tcp6InErrs[1], stats.tcp6InErrs[2],
6620 stats.tcp6InErrs[3]);
6621 sbuf_printf(sb, "tnlCongDrops: %10u %10u %10u %10u\n",
6622 stats.tnlCongDrops[0], stats.tnlCongDrops[1], stats.tnlCongDrops[2],
6623 stats.tnlCongDrops[3]);
6624 sbuf_printf(sb, "tnlTxDrops: %10u %10u %10u %10u\n",
6625 stats.tnlTxDrops[0], stats.tnlTxDrops[1], stats.tnlTxDrops[2],
6626 stats.tnlTxDrops[3]);
6627 sbuf_printf(sb, "ofldVlanDrops: %10u %10u %10u %10u\n",
6628 stats.ofldVlanDrops[0], stats.ofldVlanDrops[1],
6629 stats.ofldVlanDrops[2], stats.ofldVlanDrops[3]);
6630 sbuf_printf(sb, "ofldChanDrops: %10u %10u %10u %10u\n\n",
6631 stats.ofldChanDrops[0], stats.ofldChanDrops[1],
6632 stats.ofldChanDrops[2], stats.ofldChanDrops[3]);
6633 sbuf_printf(sb, "ofldNoNeigh: %u\nofldCongDefer: %u",
6634 stats.ofldNoNeigh, stats.ofldCongDefer);
6636 rc = sbuf_finish(sb);
6649 field_desc_show(struct sbuf *sb, uint64_t v, const struct field_desc *f)
6655 uint64_t mask = (1ULL << f->width) - 1;
6656 int len = snprintf(buf, sizeof(buf), "%s: %ju", f->name,
6657 ((uintmax_t)v >> f->start) & mask);
6659 if (line_size + len >= 79) {
6661 sbuf_printf(sb, "\n ");
6663 sbuf_printf(sb, "%s ", buf);
6664 line_size += len + 1;
6667 sbuf_printf(sb, "\n");
6670 static struct field_desc tp_la0[] = {
6671 { "RcfOpCodeOut", 60, 4 },
6673 { "WcfState", 52, 4 },
6674 { "RcfOpcSrcOut", 50, 2 },
6675 { "CRxError", 49, 1 },
6676 { "ERxError", 48, 1 },
6677 { "SanityFailed", 47, 1 },
6678 { "SpuriousMsg", 46, 1 },
6679 { "FlushInputMsg", 45, 1 },
6680 { "FlushInputCpl", 44, 1 },
6681 { "RssUpBit", 43, 1 },
6682 { "RssFilterHit", 42, 1 },
6684 { "InitTcb", 31, 1 },
6685 { "LineNumber", 24, 7 },
6687 { "EdataOut", 22, 1 },
6689 { "CdataOut", 20, 1 },
6690 { "EreadPdu", 19, 1 },
6691 { "CreadPdu", 18, 1 },
6692 { "TunnelPkt", 17, 1 },
6693 { "RcfPeerFin", 16, 1 },
6694 { "RcfReasonOut", 12, 4 },
6695 { "TxCchannel", 10, 2 },
6696 { "RcfTxChannel", 8, 2 },
6697 { "RxEchannel", 6, 2 },
6698 { "RcfRxChannel", 5, 1 },
6699 { "RcfDataOutSrdy", 4, 1 },
6701 { "RxOoDvld", 2, 1 },
6702 { "RxCongestion", 1, 1 },
6703 { "TxCongestion", 0, 1 },
6707 static struct field_desc tp_la1[] = {
6708 { "CplCmdIn", 56, 8 },
6709 { "CplCmdOut", 48, 8 },
6710 { "ESynOut", 47, 1 },
6711 { "EAckOut", 46, 1 },
6712 { "EFinOut", 45, 1 },
6713 { "ERstOut", 44, 1 },
6718 { "DataIn", 39, 1 },
6719 { "DataInVld", 38, 1 },
6721 { "RxBufEmpty", 36, 1 },
6723 { "RxFbCongestion", 34, 1 },
6724 { "TxFbCongestion", 33, 1 },
6725 { "TxPktSumSrdy", 32, 1 },
6726 { "RcfUlpType", 28, 4 },
6728 { "Ebypass", 26, 1 },
6730 { "Static0", 24, 1 },
6732 { "Cbypass", 22, 1 },
6734 { "CPktOut", 20, 1 },
6735 { "RxPagePoolFull", 18, 2 },
6736 { "RxLpbkPkt", 17, 1 },
6737 { "TxLpbkPkt", 16, 1 },
6738 { "RxVfValid", 15, 1 },
6739 { "SynLearned", 14, 1 },
6740 { "SetDelEntry", 13, 1 },
6741 { "SetInvEntry", 12, 1 },
6742 { "CpcmdDvld", 11, 1 },
6743 { "CpcmdSave", 10, 1 },
6744 { "RxPstructsFull", 8, 2 },
6745 { "EpcmdDvld", 7, 1 },
6746 { "EpcmdFlush", 6, 1 },
6747 { "EpcmdTrimPrefix", 5, 1 },
6748 { "EpcmdTrimPostfix", 4, 1 },
6749 { "ERssIp4Pkt", 3, 1 },
6750 { "ERssIp6Pkt", 2, 1 },
6751 { "ERssTcpUdpPkt", 1, 1 },
6752 { "ERssFceFipPkt", 0, 1 },
6756 static struct field_desc tp_la2[] = {
6757 { "CplCmdIn", 56, 8 },
6758 { "MpsVfVld", 55, 1 },
6765 { "DataIn", 39, 1 },
6766 { "DataInVld", 38, 1 },
6768 { "RxBufEmpty", 36, 1 },
6770 { "RxFbCongestion", 34, 1 },
6771 { "TxFbCongestion", 33, 1 },
6772 { "TxPktSumSrdy", 32, 1 },
6773 { "RcfUlpType", 28, 4 },
6775 { "Ebypass", 26, 1 },
6777 { "Static0", 24, 1 },
6779 { "Cbypass", 22, 1 },
6781 { "CPktOut", 20, 1 },
6782 { "RxPagePoolFull", 18, 2 },
6783 { "RxLpbkPkt", 17, 1 },
6784 { "TxLpbkPkt", 16, 1 },
6785 { "RxVfValid", 15, 1 },
6786 { "SynLearned", 14, 1 },
6787 { "SetDelEntry", 13, 1 },
6788 { "SetInvEntry", 12, 1 },
6789 { "CpcmdDvld", 11, 1 },
6790 { "CpcmdSave", 10, 1 },
6791 { "RxPstructsFull", 8, 2 },
6792 { "EpcmdDvld", 7, 1 },
6793 { "EpcmdFlush", 6, 1 },
6794 { "EpcmdTrimPrefix", 5, 1 },
6795 { "EpcmdTrimPostfix", 4, 1 },
6796 { "ERssIp4Pkt", 3, 1 },
6797 { "ERssIp6Pkt", 2, 1 },
6798 { "ERssTcpUdpPkt", 1, 1 },
6799 { "ERssFceFipPkt", 0, 1 },
6804 tp_la_show(struct sbuf *sb, uint64_t *p, int idx)
6807 field_desc_show(sb, *p, tp_la0);
6811 tp_la_show2(struct sbuf *sb, uint64_t *p, int idx)
6815 sbuf_printf(sb, "\n");
6816 field_desc_show(sb, p[0], tp_la0);
6817 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
6818 field_desc_show(sb, p[1], tp_la0);
6822 tp_la_show3(struct sbuf *sb, uint64_t *p, int idx)
6826 sbuf_printf(sb, "\n");
6827 field_desc_show(sb, p[0], tp_la0);
6828 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
6829 field_desc_show(sb, p[1], (p[0] & (1 << 17)) ? tp_la2 : tp_la1);
6833 sysctl_tp_la(SYSCTL_HANDLER_ARGS)
6835 struct adapter *sc = arg1;
6840 void (*show_func)(struct sbuf *, uint64_t *, int);
6842 rc = sysctl_wire_old_buffer(req, 0);
6846 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6850 buf = malloc(TPLA_SIZE * sizeof(uint64_t), M_CXGBE, M_ZERO | M_WAITOK);
6852 t4_tp_read_la(sc, buf, NULL);
6855 switch (G_DBGLAMODE(t4_read_reg(sc, A_TP_DBG_LA_CONFIG))) {
6858 show_func = tp_la_show2;
6862 show_func = tp_la_show3;
6866 show_func = tp_la_show;
6869 for (i = 0; i < TPLA_SIZE / inc; i++, p += inc)
6870 (*show_func)(sb, p, i);
6872 rc = sbuf_finish(sb);
6879 sysctl_tx_rate(SYSCTL_HANDLER_ARGS)
6881 struct adapter *sc = arg1;
6884 u64 nrate[NCHAN], orate[NCHAN];
6886 rc = sysctl_wire_old_buffer(req, 0);
6890 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6894 t4_get_chan_txrate(sc, nrate, orate);
6895 sbuf_printf(sb, " channel 0 channel 1 channel 2 "
6897 sbuf_printf(sb, "NIC B/s: %10ju %10ju %10ju %10ju\n",
6898 nrate[0], nrate[1], nrate[2], nrate[3]);
6899 sbuf_printf(sb, "Offload B/s: %10ju %10ju %10ju %10ju",
6900 orate[0], orate[1], orate[2], orate[3]);
6902 rc = sbuf_finish(sb);
6909 sysctl_ulprx_la(SYSCTL_HANDLER_ARGS)
6911 struct adapter *sc = arg1;
6916 rc = sysctl_wire_old_buffer(req, 0);
6920 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6924 buf = malloc(ULPRX_LA_SIZE * 8 * sizeof(uint32_t), M_CXGBE,
6927 t4_ulprx_read_la(sc, buf);
6930 sbuf_printf(sb, " Pcmd Type Message"
6932 for (i = 0; i < ULPRX_LA_SIZE; i++, p += 8) {
6933 sbuf_printf(sb, "\n%08x%08x %4x %08x %08x%08x%08x%08x",
6934 p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
6937 rc = sbuf_finish(sb);
6944 sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS)
6946 struct adapter *sc = arg1;
6950 rc = sysctl_wire_old_buffer(req, 0);
6954 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6958 v = t4_read_reg(sc, A_SGE_STAT_CFG);
6959 if (G_STATSOURCE_T5(v) == 7) {
6960 if (G_STATMODE(v) == 0) {
6961 sbuf_printf(sb, "total %d, incomplete %d",
6962 t4_read_reg(sc, A_SGE_STAT_TOTAL),
6963 t4_read_reg(sc, A_SGE_STAT_MATCH));
6964 } else if (G_STATMODE(v) == 1) {
6965 sbuf_printf(sb, "total %d, data overflow %d",
6966 t4_read_reg(sc, A_SGE_STAT_TOTAL),
6967 t4_read_reg(sc, A_SGE_STAT_MATCH));
6970 rc = sbuf_finish(sb);
6978 fconf_to_mode(uint32_t fconf)
6982 mode = T4_FILTER_IPv4 | T4_FILTER_IPv6 | T4_FILTER_IP_SADDR |
6983 T4_FILTER_IP_DADDR | T4_FILTER_IP_SPORT | T4_FILTER_IP_DPORT;
6985 if (fconf & F_FRAGMENTATION)
6986 mode |= T4_FILTER_IP_FRAGMENT;
6988 if (fconf & F_MPSHITTYPE)
6989 mode |= T4_FILTER_MPS_HIT_TYPE;
6991 if (fconf & F_MACMATCH)
6992 mode |= T4_FILTER_MAC_IDX;
6994 if (fconf & F_ETHERTYPE)
6995 mode |= T4_FILTER_ETH_TYPE;
6997 if (fconf & F_PROTOCOL)
6998 mode |= T4_FILTER_IP_PROTO;
7001 mode |= T4_FILTER_IP_TOS;
7004 mode |= T4_FILTER_VLAN;
7006 if (fconf & F_VNIC_ID)
7007 mode |= T4_FILTER_VNIC;
7010 mode |= T4_FILTER_PORT;
7013 mode |= T4_FILTER_FCoE;
7019 mode_to_fconf(uint32_t mode)
7023 if (mode & T4_FILTER_IP_FRAGMENT)
7024 fconf |= F_FRAGMENTATION;
7026 if (mode & T4_FILTER_MPS_HIT_TYPE)
7027 fconf |= F_MPSHITTYPE;
7029 if (mode & T4_FILTER_MAC_IDX)
7030 fconf |= F_MACMATCH;
7032 if (mode & T4_FILTER_ETH_TYPE)
7033 fconf |= F_ETHERTYPE;
7035 if (mode & T4_FILTER_IP_PROTO)
7036 fconf |= F_PROTOCOL;
7038 if (mode & T4_FILTER_IP_TOS)
7041 if (mode & T4_FILTER_VLAN)
7044 if (mode & T4_FILTER_VNIC)
7047 if (mode & T4_FILTER_PORT)
7050 if (mode & T4_FILTER_FCoE)
7057 fspec_to_fconf(struct t4_filter_specification *fs)
7061 if (fs->val.frag || fs->mask.frag)
7062 fconf |= F_FRAGMENTATION;
7064 if (fs->val.matchtype || fs->mask.matchtype)
7065 fconf |= F_MPSHITTYPE;
7067 if (fs->val.macidx || fs->mask.macidx)
7068 fconf |= F_MACMATCH;
7070 if (fs->val.ethtype || fs->mask.ethtype)
7071 fconf |= F_ETHERTYPE;
7073 if (fs->val.proto || fs->mask.proto)
7074 fconf |= F_PROTOCOL;
7076 if (fs->val.tos || fs->mask.tos)
7079 if (fs->val.vlan_vld || fs->mask.vlan_vld)
7082 if (fs->val.vnic_vld || fs->mask.vnic_vld)
7085 if (fs->val.iport || fs->mask.iport)
7088 if (fs->val.fcoe || fs->mask.fcoe)
7095 get_filter_mode(struct adapter *sc, uint32_t *mode)
7100 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
7105 t4_read_indirect(sc, A_TP_PIO_ADDR, A_TP_PIO_DATA, &fconf, 1,
7108 if (sc->params.tp.vlan_pri_map != fconf) {
7109 log(LOG_WARNING, "%s: cached filter mode out of sync %x %x.\n",
7110 device_get_nameunit(sc->dev), sc->params.tp.vlan_pri_map,
7112 sc->params.tp.vlan_pri_map = fconf;
7115 *mode = fconf_to_mode(sc->params.tp.vlan_pri_map);
7117 end_synchronized_op(sc, LOCK_HELD);
7122 set_filter_mode(struct adapter *sc, uint32_t mode)
7127 fconf = mode_to_fconf(mode);
7129 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
7134 if (sc->tids.ftids_in_use > 0) {
7140 if (sc->offload_map) {
7147 rc = -t4_set_filter_mode(sc, fconf);
7149 sc->filter_mode = fconf;
7155 end_synchronized_op(sc, LOCK_HELD);
7159 static inline uint64_t
7160 get_filter_hits(struct adapter *sc, uint32_t fid)
7162 uint32_t mw_base, off, tcb_base = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
7165 memwin_info(sc, 0, &mw_base, NULL);
7166 off = position_memwin(sc, 0,
7167 tcb_base + (fid + sc->tids.ftid_base) * TCB_SIZE);
7169 hits = t4_read_reg64(sc, mw_base + off + 16);
7170 hits = be64toh(hits);
7172 hits = t4_read_reg(sc, mw_base + off + 24);
7173 hits = be32toh(hits);
7180 get_filter(struct adapter *sc, struct t4_filter *t)
7182 int i, rc, nfilters = sc->tids.nftids;
7183 struct filter_entry *f;
7185 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
7190 if (sc->tids.ftids_in_use == 0 || sc->tids.ftid_tab == NULL ||
7191 t->idx >= nfilters) {
7192 t->idx = 0xffffffff;
7196 f = &sc->tids.ftid_tab[t->idx];
7197 for (i = t->idx; i < nfilters; i++, f++) {
7200 t->l2tidx = f->l2t ? f->l2t->idx : 0;
7201 t->smtidx = f->smtidx;
7203 t->hits = get_filter_hits(sc, t->idx);
7205 t->hits = UINT64_MAX;
7212 t->idx = 0xffffffff;
7214 end_synchronized_op(sc, LOCK_HELD);
7219 set_filter(struct adapter *sc, struct t4_filter *t)
7221 unsigned int nfilters, nports;
7222 struct filter_entry *f;
7225 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setf");
7229 nfilters = sc->tids.nftids;
7230 nports = sc->params.nports;
7232 if (nfilters == 0) {
7237 if (!(sc->flags & FULL_INIT_DONE)) {
7242 if (t->idx >= nfilters) {
7247 /* Validate against the global filter mode */
7248 if ((sc->params.tp.vlan_pri_map | fspec_to_fconf(&t->fs)) !=
7249 sc->params.tp.vlan_pri_map) {
7254 if (t->fs.action == FILTER_SWITCH && t->fs.eport >= nports) {
7259 if (t->fs.val.iport >= nports) {
7264 /* Can't specify an iq if not steering to it */
7265 if (!t->fs.dirsteer && t->fs.iq) {
7270 /* IPv6 filter idx must be 4 aligned */
7271 if (t->fs.type == 1 &&
7272 ((t->idx & 0x3) || t->idx + 4 >= nfilters)) {
7277 if (sc->tids.ftid_tab == NULL) {
7278 KASSERT(sc->tids.ftids_in_use == 0,
7279 ("%s: no memory allocated but filters_in_use > 0",
7282 sc->tids.ftid_tab = malloc(sizeof (struct filter_entry) *
7283 nfilters, M_CXGBE, M_NOWAIT | M_ZERO);
7284 if (sc->tids.ftid_tab == NULL) {
7288 mtx_init(&sc->tids.ftid_lock, "T4 filters", 0, MTX_DEF);
7291 for (i = 0; i < 4; i++) {
7292 f = &sc->tids.ftid_tab[t->idx + i];
7294 if (f->pending || f->valid) {
7303 if (t->fs.type == 0)
7307 f = &sc->tids.ftid_tab[t->idx];
7310 rc = set_filter_wr(sc, t->idx);
7312 end_synchronized_op(sc, 0);
7315 mtx_lock(&sc->tids.ftid_lock);
7317 if (f->pending == 0) {
7318 rc = f->valid ? 0 : EIO;
7322 if (mtx_sleep(&sc->tids.ftid_tab, &sc->tids.ftid_lock,
7323 PCATCH, "t4setfw", 0)) {
7328 mtx_unlock(&sc->tids.ftid_lock);
7334 del_filter(struct adapter *sc, struct t4_filter *t)
7336 unsigned int nfilters;
7337 struct filter_entry *f;
7340 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4delf");
7344 nfilters = sc->tids.nftids;
7346 if (nfilters == 0) {
7351 if (sc->tids.ftid_tab == NULL || sc->tids.ftids_in_use == 0 ||
7352 t->idx >= nfilters) {
7357 if (!(sc->flags & FULL_INIT_DONE)) {
7362 f = &sc->tids.ftid_tab[t->idx];
7374 t->fs = f->fs; /* extra info for the caller */
7375 rc = del_filter_wr(sc, t->idx);
7379 end_synchronized_op(sc, 0);
7382 mtx_lock(&sc->tids.ftid_lock);
7384 if (f->pending == 0) {
7385 rc = f->valid ? EIO : 0;
7389 if (mtx_sleep(&sc->tids.ftid_tab, &sc->tids.ftid_lock,
7390 PCATCH, "t4delfw", 0)) {
7395 mtx_unlock(&sc->tids.ftid_lock);
7402 clear_filter(struct filter_entry *f)
7405 t4_l2t_release(f->l2t);
7407 bzero(f, sizeof (*f));
7411 set_filter_wr(struct adapter *sc, int fidx)
7413 struct filter_entry *f = &sc->tids.ftid_tab[fidx];
7414 struct fw_filter_wr *fwr;
7416 struct wrq_cookie cookie;
7418 ASSERT_SYNCHRONIZED_OP(sc);
7420 if (f->fs.newdmac || f->fs.newvlan) {
7421 /* This filter needs an L2T entry; allocate one. */
7422 f->l2t = t4_l2t_alloc_switching(sc->l2t);
7425 if (t4_l2t_set_switching(sc, f->l2t, f->fs.vlan, f->fs.eport,
7427 t4_l2t_release(f->l2t);
7433 ftid = sc->tids.ftid_base + fidx;
7435 fwr = start_wrq_wr(&sc->sge.mgmtq, howmany(sizeof(*fwr), 16), &cookie);
7438 bzero(fwr, sizeof(*fwr));
7440 fwr->op_pkd = htobe32(V_FW_WR_OP(FW_FILTER_WR));
7441 fwr->len16_pkd = htobe32(FW_LEN16(*fwr));
7443 htobe32(V_FW_FILTER_WR_TID(ftid) |
7444 V_FW_FILTER_WR_RQTYPE(f->fs.type) |
7445 V_FW_FILTER_WR_NOREPLY(0) |
7446 V_FW_FILTER_WR_IQ(f->fs.iq));
7447 fwr->del_filter_to_l2tix =
7448 htobe32(V_FW_FILTER_WR_RPTTID(f->fs.rpttid) |
7449 V_FW_FILTER_WR_DROP(f->fs.action == FILTER_DROP) |
7450 V_FW_FILTER_WR_DIRSTEER(f->fs.dirsteer) |
7451 V_FW_FILTER_WR_MASKHASH(f->fs.maskhash) |
7452 V_FW_FILTER_WR_DIRSTEERHASH(f->fs.dirsteerhash) |
7453 V_FW_FILTER_WR_LPBK(f->fs.action == FILTER_SWITCH) |
7454 V_FW_FILTER_WR_DMAC(f->fs.newdmac) |
7455 V_FW_FILTER_WR_SMAC(f->fs.newsmac) |
7456 V_FW_FILTER_WR_INSVLAN(f->fs.newvlan == VLAN_INSERT ||
7457 f->fs.newvlan == VLAN_REWRITE) |
7458 V_FW_FILTER_WR_RMVLAN(f->fs.newvlan == VLAN_REMOVE ||
7459 f->fs.newvlan == VLAN_REWRITE) |
7460 V_FW_FILTER_WR_HITCNTS(f->fs.hitcnts) |
7461 V_FW_FILTER_WR_TXCHAN(f->fs.eport) |
7462 V_FW_FILTER_WR_PRIO(f->fs.prio) |
7463 V_FW_FILTER_WR_L2TIX(f->l2t ? f->l2t->idx : 0));
7464 fwr->ethtype = htobe16(f->fs.val.ethtype);
7465 fwr->ethtypem = htobe16(f->fs.mask.ethtype);
7466 fwr->frag_to_ovlan_vldm =
7467 (V_FW_FILTER_WR_FRAG(f->fs.val.frag) |
7468 V_FW_FILTER_WR_FRAGM(f->fs.mask.frag) |
7469 V_FW_FILTER_WR_IVLAN_VLD(f->fs.val.vlan_vld) |
7470 V_FW_FILTER_WR_OVLAN_VLD(f->fs.val.vnic_vld) |
7471 V_FW_FILTER_WR_IVLAN_VLDM(f->fs.mask.vlan_vld) |
7472 V_FW_FILTER_WR_OVLAN_VLDM(f->fs.mask.vnic_vld));
7474 fwr->rx_chan_rx_rpl_iq = htobe16(V_FW_FILTER_WR_RX_CHAN(0) |
7475 V_FW_FILTER_WR_RX_RPL_IQ(sc->sge.fwq.abs_id));
7476 fwr->maci_to_matchtypem =
7477 htobe32(V_FW_FILTER_WR_MACI(f->fs.val.macidx) |
7478 V_FW_FILTER_WR_MACIM(f->fs.mask.macidx) |
7479 V_FW_FILTER_WR_FCOE(f->fs.val.fcoe) |
7480 V_FW_FILTER_WR_FCOEM(f->fs.mask.fcoe) |
7481 V_FW_FILTER_WR_PORT(f->fs.val.iport) |
7482 V_FW_FILTER_WR_PORTM(f->fs.mask.iport) |
7483 V_FW_FILTER_WR_MATCHTYPE(f->fs.val.matchtype) |
7484 V_FW_FILTER_WR_MATCHTYPEM(f->fs.mask.matchtype));
7485 fwr->ptcl = f->fs.val.proto;
7486 fwr->ptclm = f->fs.mask.proto;
7487 fwr->ttyp = f->fs.val.tos;
7488 fwr->ttypm = f->fs.mask.tos;
7489 fwr->ivlan = htobe16(f->fs.val.vlan);
7490 fwr->ivlanm = htobe16(f->fs.mask.vlan);
7491 fwr->ovlan = htobe16(f->fs.val.vnic);
7492 fwr->ovlanm = htobe16(f->fs.mask.vnic);
7493 bcopy(f->fs.val.dip, fwr->lip, sizeof (fwr->lip));
7494 bcopy(f->fs.mask.dip, fwr->lipm, sizeof (fwr->lipm));
7495 bcopy(f->fs.val.sip, fwr->fip, sizeof (fwr->fip));
7496 bcopy(f->fs.mask.sip, fwr->fipm, sizeof (fwr->fipm));
7497 fwr->lp = htobe16(f->fs.val.dport);
7498 fwr->lpm = htobe16(f->fs.mask.dport);
7499 fwr->fp = htobe16(f->fs.val.sport);
7500 fwr->fpm = htobe16(f->fs.mask.sport);
7502 bcopy(f->fs.smac, fwr->sma, sizeof (fwr->sma));
7505 sc->tids.ftids_in_use++;
7507 commit_wrq_wr(&sc->sge.mgmtq, fwr, &cookie);
7512 del_filter_wr(struct adapter *sc, int fidx)
7514 struct filter_entry *f = &sc->tids.ftid_tab[fidx];
7515 struct fw_filter_wr *fwr;
7517 struct wrq_cookie cookie;
7519 ftid = sc->tids.ftid_base + fidx;
7521 fwr = start_wrq_wr(&sc->sge.mgmtq, howmany(sizeof(*fwr), 16), &cookie);
7524 bzero(fwr, sizeof (*fwr));
7526 t4_mk_filtdelwr(ftid, fwr, sc->sge.fwq.abs_id);
7529 commit_wrq_wr(&sc->sge.mgmtq, fwr, &cookie);
7534 t4_filter_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
7536 struct adapter *sc = iq->adapter;
7537 const struct cpl_set_tcb_rpl *rpl = (const void *)(rss + 1);
7538 unsigned int idx = GET_TID(rpl);
7540 struct filter_entry *f;
7542 KASSERT(m == NULL, ("%s: payload with opcode %02x", __func__,
7545 if (is_ftid(sc, idx)) {
7547 idx -= sc->tids.ftid_base;
7548 f = &sc->tids.ftid_tab[idx];
7549 rc = G_COOKIE(rpl->cookie);
7551 mtx_lock(&sc->tids.ftid_lock);
7552 if (rc == FW_FILTER_WR_FLT_ADDED) {
7553 KASSERT(f->pending, ("%s: filter[%u] isn't pending.",
7555 f->smtidx = (be64toh(rpl->oldval) >> 24) & 0xff;
7556 f->pending = 0; /* asynchronous setup completed */
7559 if (rc != FW_FILTER_WR_FLT_DELETED) {
7560 /* Add or delete failed, display an error */
7562 "filter %u setup failed with error %u\n",
7567 sc->tids.ftids_in_use--;
7569 wakeup(&sc->tids.ftid_tab);
7570 mtx_unlock(&sc->tids.ftid_lock);
7577 get_sge_context(struct adapter *sc, struct t4_sge_context *cntxt)
7581 if (cntxt->cid > M_CTXTQID)
7584 if (cntxt->mem_id != CTXT_EGRESS && cntxt->mem_id != CTXT_INGRESS &&
7585 cntxt->mem_id != CTXT_FLM && cntxt->mem_id != CTXT_CNM)
7588 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ctxt");
7592 if (sc->flags & FW_OK) {
7593 rc = -t4_sge_ctxt_rd(sc, sc->mbox, cntxt->cid, cntxt->mem_id,
7600 * Read via firmware failed or wasn't even attempted. Read directly via
7603 rc = -t4_sge_ctxt_rd_bd(sc, cntxt->cid, cntxt->mem_id, &cntxt->data[0]);
7605 end_synchronized_op(sc, 0);
7610 load_fw(struct adapter *sc, struct t4_data *fw)
7615 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldfw");
7619 if (sc->flags & FULL_INIT_DONE) {
7624 fw_data = malloc(fw->len, M_CXGBE, M_WAITOK);
7625 if (fw_data == NULL) {
7630 rc = copyin(fw->data, fw_data, fw->len);
7632 rc = -t4_load_fw(sc, fw_data, fw->len);
7634 free(fw_data, M_CXGBE);
7636 end_synchronized_op(sc, 0);
7641 read_card_mem(struct adapter *sc, int win, struct t4_mem_range *mr)
7643 uint32_t addr, off, remaining, i, n;
7645 uint32_t mw_base, mw_aperture;
7649 rc = validate_mem_range(sc, mr->addr, mr->len);
7653 memwin_info(sc, win, &mw_base, &mw_aperture);
7654 buf = b = malloc(min(mr->len, mw_aperture), M_CXGBE, M_WAITOK);
7656 remaining = mr->len;
7657 dst = (void *)mr->data;
7660 off = position_memwin(sc, win, addr);
7662 /* number of bytes that we'll copy in the inner loop */
7663 n = min(remaining, mw_aperture - off);
7664 for (i = 0; i < n; i += 4)
7665 *b++ = t4_read_reg(sc, mw_base + off + i);
7667 rc = copyout(buf, dst, n);
7682 read_i2c(struct adapter *sc, struct t4_i2c_data *i2cd)
7686 if (i2cd->len == 0 || i2cd->port_id >= sc->params.nports)
7689 if (i2cd->len > sizeof(i2cd->data))
7692 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4i2crd");
7695 rc = -t4_i2c_rd(sc, sc->mbox, i2cd->port_id, i2cd->dev_addr,
7696 i2cd->offset, i2cd->len, &i2cd->data[0]);
7697 end_synchronized_op(sc, 0);
7703 in_range(int val, int lo, int hi)
7706 return (val < 0 || (val <= hi && val >= lo));
7710 set_sched_class(struct adapter *sc, struct t4_sched_params *p)
7712 int fw_subcmd, fw_type, rc;
7714 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setsc");
7718 if (!(sc->flags & FULL_INIT_DONE)) {
7724 * Translate the cxgbetool parameters into T4 firmware parameters. (The
7725 * sub-command and type are in common locations.)
7727 if (p->subcmd == SCHED_CLASS_SUBCMD_CONFIG)
7728 fw_subcmd = FW_SCHED_SC_CONFIG;
7729 else if (p->subcmd == SCHED_CLASS_SUBCMD_PARAMS)
7730 fw_subcmd = FW_SCHED_SC_PARAMS;
7735 if (p->type == SCHED_CLASS_TYPE_PACKET)
7736 fw_type = FW_SCHED_TYPE_PKTSCHED;
7742 if (fw_subcmd == FW_SCHED_SC_CONFIG) {
7743 /* Vet our parameters ..*/
7744 if (p->u.config.minmax < 0) {
7749 /* And pass the request to the firmware ...*/
7750 rc = -t4_sched_config(sc, fw_type, p->u.config.minmax, 1);
7754 if (fw_subcmd == FW_SCHED_SC_PARAMS) {
7760 if (p->u.params.level == SCHED_CLASS_LEVEL_CL_RL)
7761 fw_level = FW_SCHED_PARAMS_LEVEL_CL_RL;
7762 else if (p->u.params.level == SCHED_CLASS_LEVEL_CL_WRR)
7763 fw_level = FW_SCHED_PARAMS_LEVEL_CL_WRR;
7764 else if (p->u.params.level == SCHED_CLASS_LEVEL_CH_RL)
7765 fw_level = FW_SCHED_PARAMS_LEVEL_CH_RL;
7771 if (p->u.params.mode == SCHED_CLASS_MODE_CLASS)
7772 fw_mode = FW_SCHED_PARAMS_MODE_CLASS;
7773 else if (p->u.params.mode == SCHED_CLASS_MODE_FLOW)
7774 fw_mode = FW_SCHED_PARAMS_MODE_FLOW;
7780 if (p->u.params.rateunit == SCHED_CLASS_RATEUNIT_BITS)
7781 fw_rateunit = FW_SCHED_PARAMS_UNIT_BITRATE;
7782 else if (p->u.params.rateunit == SCHED_CLASS_RATEUNIT_PKTS)
7783 fw_rateunit = FW_SCHED_PARAMS_UNIT_PKTRATE;
7789 if (p->u.params.ratemode == SCHED_CLASS_RATEMODE_REL)
7790 fw_ratemode = FW_SCHED_PARAMS_RATE_REL;
7791 else if (p->u.params.ratemode == SCHED_CLASS_RATEMODE_ABS)
7792 fw_ratemode = FW_SCHED_PARAMS_RATE_ABS;
7798 /* Vet our parameters ... */
7799 if (!in_range(p->u.params.channel, 0, 3) ||
7800 !in_range(p->u.params.cl, 0, is_t4(sc) ? 15 : 16) ||
7801 !in_range(p->u.params.minrate, 0, 10000000) ||
7802 !in_range(p->u.params.maxrate, 0, 10000000) ||
7803 !in_range(p->u.params.weight, 0, 100)) {
7809 * Translate any unset parameters into the firmware's
7810 * nomenclature and/or fail the call if the parameters
7813 if (p->u.params.rateunit < 0 || p->u.params.ratemode < 0 ||
7814 p->u.params.channel < 0 || p->u.params.cl < 0) {
7818 if (p->u.params.minrate < 0)
7819 p->u.params.minrate = 0;
7820 if (p->u.params.maxrate < 0) {
7821 if (p->u.params.level == SCHED_CLASS_LEVEL_CL_RL ||
7822 p->u.params.level == SCHED_CLASS_LEVEL_CH_RL) {
7826 p->u.params.maxrate = 0;
7828 if (p->u.params.weight < 0) {
7829 if (p->u.params.level == SCHED_CLASS_LEVEL_CL_WRR) {
7833 p->u.params.weight = 0;
7835 if (p->u.params.pktsize < 0) {
7836 if (p->u.params.level == SCHED_CLASS_LEVEL_CL_RL ||
7837 p->u.params.level == SCHED_CLASS_LEVEL_CH_RL) {
7841 p->u.params.pktsize = 0;
7844 /* See what the firmware thinks of the request ... */
7845 rc = -t4_sched_params(sc, fw_type, fw_level, fw_mode,
7846 fw_rateunit, fw_ratemode, p->u.params.channel,
7847 p->u.params.cl, p->u.params.minrate, p->u.params.maxrate,
7848 p->u.params.weight, p->u.params.pktsize, 1);
7854 end_synchronized_op(sc, 0);
7859 set_sched_queue(struct adapter *sc, struct t4_sched_queue *p)
7861 struct port_info *pi = NULL;
7862 struct sge_txq *txq;
7863 uint32_t fw_mnem, fw_queue, fw_class;
7866 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setsq");
7870 if (!(sc->flags & FULL_INIT_DONE)) {
7875 if (p->port >= sc->params.nports) {
7880 pi = sc->port[p->port];
7881 if (!in_range(p->queue, 0, pi->ntxq - 1) || !in_range(p->cl, 0, 7)) {
7887 * Create a template for the FW_PARAMS_CMD mnemonic and value (TX
7888 * Scheduling Class in this case).
7890 fw_mnem = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DMAQ) |
7891 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DMAQ_EQ_SCHEDCLASS_ETH));
7892 fw_class = p->cl < 0 ? 0xffffffff : p->cl;
7895 * If op.queue is non-negative, then we're only changing the scheduling
7896 * on a single specified TX queue.
7898 if (p->queue >= 0) {
7899 txq = &sc->sge.txq[pi->first_txq + p->queue];
7900 fw_queue = (fw_mnem | V_FW_PARAMS_PARAM_YZ(txq->eq.cntxt_id));
7901 rc = -t4_set_params(sc, sc->mbox, sc->pf, 0, 1, &fw_queue,
7907 * Change the scheduling on all the TX queues for the
7910 for_each_txq(pi, i, txq) {
7911 fw_queue = (fw_mnem | V_FW_PARAMS_PARAM_YZ(txq->eq.cntxt_id));
7912 rc = -t4_set_params(sc, sc->mbox, sc->pf, 0, 1, &fw_queue,
7920 end_synchronized_op(sc, 0);
7925 t4_os_find_pci_capability(struct adapter *sc, int cap)
7929 return (pci_find_cap(sc->dev, cap, &i) == 0 ? i : 0);
7933 t4_os_pci_save_state(struct adapter *sc)
7936 struct pci_devinfo *dinfo;
7939 dinfo = device_get_ivars(dev);
7941 pci_cfg_save(dev, dinfo, 0);
7946 t4_os_pci_restore_state(struct adapter *sc)
7949 struct pci_devinfo *dinfo;
7952 dinfo = device_get_ivars(dev);
7954 pci_cfg_restore(dev, dinfo);
7959 t4_os_portmod_changed(const struct adapter *sc, int idx)
7961 struct port_info *pi = sc->port[idx];
7962 static const char *mod_str[] = {
7963 NULL, "LR", "SR", "ER", "TWINAX", "active TWINAX", "LRM"
7966 build_medialist(pi, &pi->media);
7968 build_medialist(pi, &pi->nm_media);
7971 if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
7972 if_printf(pi->ifp, "transceiver unplugged.\n");
7973 else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
7974 if_printf(pi->ifp, "unknown transceiver inserted.\n");
7975 else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
7976 if_printf(pi->ifp, "unsupported transceiver inserted.\n");
7977 else if (pi->mod_type > 0 && pi->mod_type < nitems(mod_str)) {
7978 if_printf(pi->ifp, "%s transceiver inserted.\n",
7979 mod_str[pi->mod_type]);
7981 if_printf(pi->ifp, "transceiver (type %d) inserted.\n",
7987 t4_os_link_changed(struct adapter *sc, int idx, int link_stat, int reason)
7989 struct port_info *pi = sc->port[idx];
7990 struct ifnet *ifp = pi->ifp;
7994 ifp->if_baudrate = IF_Mbps(pi->link_cfg.speed);
7995 if_link_state_change(ifp, LINK_STATE_UP);
7998 pi->linkdnrc = reason;
7999 if_link_state_change(ifp, LINK_STATE_DOWN);
8004 t4_iterate(void (*func)(struct adapter *, void *), void *arg)
8008 sx_slock(&t4_list_lock);
8009 SLIST_FOREACH(sc, &t4_list, link) {
8011 * func should not make any assumptions about what state sc is
8012 * in - the only guarantee is that sc->sc_lock is a valid lock.
8016 sx_sunlock(&t4_list_lock);
8020 t4_open(struct cdev *dev, int flags, int type, struct thread *td)
8026 t4_close(struct cdev *dev, int flags, int type, struct thread *td)
8032 t4_ioctl(struct cdev *dev, unsigned long cmd, caddr_t data, int fflag,
8036 struct adapter *sc = dev->si_drv1;
8038 rc = priv_check(td, PRIV_DRIVER);
8043 case CHELSIO_T4_GETREG: {
8044 struct t4_reg *edata = (struct t4_reg *)data;
8046 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
8049 if (edata->size == 4)
8050 edata->val = t4_read_reg(sc, edata->addr);
8051 else if (edata->size == 8)
8052 edata->val = t4_read_reg64(sc, edata->addr);
8058 case CHELSIO_T4_SETREG: {
8059 struct t4_reg *edata = (struct t4_reg *)data;
8061 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
8064 if (edata->size == 4) {
8065 if (edata->val & 0xffffffff00000000)
8067 t4_write_reg(sc, edata->addr, (uint32_t) edata->val);
8068 } else if (edata->size == 8)
8069 t4_write_reg64(sc, edata->addr, edata->val);
8074 case CHELSIO_T4_REGDUMP: {
8075 struct t4_regdump *regs = (struct t4_regdump *)data;
8076 int reglen = is_t4(sc) ? T4_REGDUMP_SIZE : T5_REGDUMP_SIZE;
8079 if (regs->len < reglen) {
8080 regs->len = reglen; /* hint to the caller */
8085 buf = malloc(reglen, M_CXGBE, M_WAITOK | M_ZERO);
8086 t4_get_regs(sc, regs, buf);
8087 rc = copyout(buf, regs->data, reglen);
8091 case CHELSIO_T4_GET_FILTER_MODE:
8092 rc = get_filter_mode(sc, (uint32_t *)data);
8094 case CHELSIO_T4_SET_FILTER_MODE:
8095 rc = set_filter_mode(sc, *(uint32_t *)data);
8097 case CHELSIO_T4_GET_FILTER:
8098 rc = get_filter(sc, (struct t4_filter *)data);
8100 case CHELSIO_T4_SET_FILTER:
8101 rc = set_filter(sc, (struct t4_filter *)data);
8103 case CHELSIO_T4_DEL_FILTER:
8104 rc = del_filter(sc, (struct t4_filter *)data);
8106 case CHELSIO_T4_GET_SGE_CONTEXT:
8107 rc = get_sge_context(sc, (struct t4_sge_context *)data);
8109 case CHELSIO_T4_LOAD_FW:
8110 rc = load_fw(sc, (struct t4_data *)data);
8112 case CHELSIO_T4_GET_MEM:
8113 rc = read_card_mem(sc, 2, (struct t4_mem_range *)data);
8115 case CHELSIO_T4_GET_I2C:
8116 rc = read_i2c(sc, (struct t4_i2c_data *)data);
8118 case CHELSIO_T4_CLEAR_STATS: {
8120 u_int port_id = *(uint32_t *)data;
8121 struct port_info *pi;
8123 if (port_id >= sc->params.nports)
8125 pi = sc->port[port_id];
8128 t4_clr_port_stats(sc, pi->tx_chan);
8129 pi->tx_parse_error = 0;
8131 if (pi->flags & PORT_INIT_DONE) {
8132 struct sge_rxq *rxq;
8133 struct sge_txq *txq;
8134 struct sge_wrq *wrq;
8136 for_each_rxq(pi, i, rxq) {
8137 #if defined(INET) || defined(INET6)
8138 rxq->lro.lro_queued = 0;
8139 rxq->lro.lro_flushed = 0;
8142 rxq->vlan_extraction = 0;
8145 for_each_txq(pi, i, txq) {
8148 txq->vlan_insertion = 0;
8152 txq->txpkts0_wrs = 0;
8153 txq->txpkts1_wrs = 0;
8154 txq->txpkts0_pkts = 0;
8155 txq->txpkts1_pkts = 0;
8156 mp_ring_reset_stats(txq->r);
8160 /* nothing to clear for each ofld_rxq */
8162 for_each_ofld_txq(pi, i, wrq) {
8163 wrq->tx_wrs_direct = 0;
8164 wrq->tx_wrs_copied = 0;
8167 wrq = &sc->sge.ctrlq[pi->port_id];
8168 wrq->tx_wrs_direct = 0;
8169 wrq->tx_wrs_copied = 0;
8173 case CHELSIO_T4_SCHED_CLASS:
8174 rc = set_sched_class(sc, (struct t4_sched_params *)data);
8176 case CHELSIO_T4_SCHED_QUEUE:
8177 rc = set_sched_queue(sc, (struct t4_sched_queue *)data);
8179 case CHELSIO_T4_GET_TRACER:
8180 rc = t4_get_tracer(sc, (struct t4_tracer *)data);
8182 case CHELSIO_T4_SET_TRACER:
8183 rc = t4_set_tracer(sc, (struct t4_tracer *)data);
8194 t4_iscsi_init(struct ifnet *ifp, unsigned int tag_mask,
8195 const unsigned int *pgsz_order)
8197 struct port_info *pi = ifp->if_softc;
8198 struct adapter *sc = pi->adapter;
8200 t4_write_reg(sc, A_ULP_RX_ISCSI_TAGMASK, tag_mask);
8201 t4_write_reg(sc, A_ULP_RX_ISCSI_PSZ, V_HPZ0(pgsz_order[0]) |
8202 V_HPZ1(pgsz_order[1]) | V_HPZ2(pgsz_order[2]) |
8203 V_HPZ3(pgsz_order[3]));
8207 toe_capability(struct port_info *pi, int enable)
8210 struct adapter *sc = pi->adapter;
8212 ASSERT_SYNCHRONIZED_OP(sc);
8214 if (!is_offload(sc))
8218 if (!(sc->flags & FULL_INIT_DONE)) {
8219 rc = cxgbe_init_synchronized(pi);
8224 if (isset(&sc->offload_map, pi->port_id))
8227 if (!(sc->flags & TOM_INIT_DONE)) {
8228 rc = t4_activate_uld(sc, ULD_TOM);
8231 "You must kldload t4_tom.ko before trying "
8232 "to enable TOE on a cxgbe interface.\n");
8236 KASSERT(sc->tom_softc != NULL,
8237 ("%s: TOM activated but softc NULL", __func__));
8238 KASSERT(sc->flags & TOM_INIT_DONE,
8239 ("%s: TOM activated but flag not set", __func__));
8242 setbit(&sc->offload_map, pi->port_id);
8244 if (!isset(&sc->offload_map, pi->port_id))
8247 KASSERT(sc->flags & TOM_INIT_DONE,
8248 ("%s: TOM never initialized?", __func__));
8249 clrbit(&sc->offload_map, pi->port_id);
8256 * Add an upper layer driver to the global list.
8259 t4_register_uld(struct uld_info *ui)
8264 sx_xlock(&t4_uld_list_lock);
8265 SLIST_FOREACH(u, &t4_uld_list, link) {
8266 if (u->uld_id == ui->uld_id) {
8272 SLIST_INSERT_HEAD(&t4_uld_list, ui, link);
8275 sx_xunlock(&t4_uld_list_lock);
8280 t4_unregister_uld(struct uld_info *ui)
8285 sx_xlock(&t4_uld_list_lock);
8287 SLIST_FOREACH(u, &t4_uld_list, link) {
8289 if (ui->refcount > 0) {
8294 SLIST_REMOVE(&t4_uld_list, ui, uld_info, link);
8300 sx_xunlock(&t4_uld_list_lock);
8305 t4_activate_uld(struct adapter *sc, int id)
8308 struct uld_info *ui;
8310 ASSERT_SYNCHRONIZED_OP(sc);
8312 sx_slock(&t4_uld_list_lock);
8314 SLIST_FOREACH(ui, &t4_uld_list, link) {
8315 if (ui->uld_id == id) {
8316 if (!(sc->flags & FULL_INIT_DONE)) {
8317 rc = adapter_full_init(sc);
8322 rc = ui->activate(sc);
8329 sx_sunlock(&t4_uld_list_lock);
8335 t4_deactivate_uld(struct adapter *sc, int id)
8338 struct uld_info *ui;
8340 ASSERT_SYNCHRONIZED_OP(sc);
8342 sx_slock(&t4_uld_list_lock);
8344 SLIST_FOREACH(ui, &t4_uld_list, link) {
8345 if (ui->uld_id == id) {
8346 rc = ui->deactivate(sc);
8353 sx_sunlock(&t4_uld_list_lock);
8360 * Come up with reasonable defaults for some of the tunables, provided they're
8361 * not set by the user (in which case we'll use the values as is).
8364 tweak_tunables(void)
8366 int nc = mp_ncpus; /* our snapshot of the number of CPUs */
8369 t4_ntxq10g = min(nc, NTXQ_10G);
8372 t4_ntxq1g = min(nc, NTXQ_1G);
8375 t4_nrxq10g = min(nc, NRXQ_10G);
8378 t4_nrxq1g = min(nc, NRXQ_1G);
8381 if (t4_nofldtxq10g < 1)
8382 t4_nofldtxq10g = min(nc, NOFLDTXQ_10G);
8384 if (t4_nofldtxq1g < 1)
8385 t4_nofldtxq1g = min(nc, NOFLDTXQ_1G);
8387 if (t4_nofldrxq10g < 1)
8388 t4_nofldrxq10g = min(nc, NOFLDRXQ_10G);
8390 if (t4_nofldrxq1g < 1)
8391 t4_nofldrxq1g = min(nc, NOFLDRXQ_1G);
8393 if (t4_toecaps_allowed == -1)
8394 t4_toecaps_allowed = FW_CAPS_CONFIG_TOE;
8396 if (t4_toecaps_allowed == -1)
8397 t4_toecaps_allowed = 0;
8401 if (t4_nnmtxq10g < 1)
8402 t4_nnmtxq10g = min(nc, NNMTXQ_10G);
8404 if (t4_nnmtxq1g < 1)
8405 t4_nnmtxq1g = min(nc, NNMTXQ_1G);
8407 if (t4_nnmrxq10g < 1)
8408 t4_nnmrxq10g = min(nc, NNMRXQ_10G);
8410 if (t4_nnmrxq1g < 1)
8411 t4_nnmrxq1g = min(nc, NNMRXQ_1G);
8414 if (t4_tmr_idx_10g < 0 || t4_tmr_idx_10g >= SGE_NTIMERS)
8415 t4_tmr_idx_10g = TMR_IDX_10G;
8417 if (t4_pktc_idx_10g < -1 || t4_pktc_idx_10g >= SGE_NCOUNTERS)
8418 t4_pktc_idx_10g = PKTC_IDX_10G;
8420 if (t4_tmr_idx_1g < 0 || t4_tmr_idx_1g >= SGE_NTIMERS)
8421 t4_tmr_idx_1g = TMR_IDX_1G;
8423 if (t4_pktc_idx_1g < -1 || t4_pktc_idx_1g >= SGE_NCOUNTERS)
8424 t4_pktc_idx_1g = PKTC_IDX_1G;
8426 if (t4_qsize_txq < 128)
8429 if (t4_qsize_rxq < 128)
8431 while (t4_qsize_rxq & 7)
8434 t4_intr_types &= INTR_MSIX | INTR_MSI | INTR_INTX;
8437 static struct sx mlu; /* mod load unload */
8438 SX_SYSINIT(cxgbe_mlu, &mlu, "cxgbe mod load/unload");
8441 mod_event(module_t mod, int cmd, void *arg)
8444 static int loaded = 0;
8449 if (loaded++ == 0) {
8451 sx_init(&t4_list_lock, "T4/T5 adapters");
8452 SLIST_INIT(&t4_list);
8454 sx_init(&t4_uld_list_lock, "T4/T5 ULDs");
8455 SLIST_INIT(&t4_uld_list);
8457 t4_tracer_modload();
8465 if (--loaded == 0) {
8468 sx_slock(&t4_list_lock);
8469 if (!SLIST_EMPTY(&t4_list)) {
8471 sx_sunlock(&t4_list_lock);
8475 sx_slock(&t4_uld_list_lock);
8476 if (!SLIST_EMPTY(&t4_uld_list)) {
8478 sx_sunlock(&t4_uld_list_lock);
8479 sx_sunlock(&t4_list_lock);
8484 while (tries++ < 5 && t4_sge_extfree_refs() != 0) {
8485 uprintf("%ju clusters with custom free routine "
8486 "still is use.\n", t4_sge_extfree_refs());
8487 pause("t4unload", 2 * hz);
8490 sx_sunlock(&t4_uld_list_lock);
8492 sx_sunlock(&t4_list_lock);
8494 if (t4_sge_extfree_refs() == 0) {
8495 t4_tracer_modunload();
8497 sx_destroy(&t4_uld_list_lock);
8499 sx_destroy(&t4_list_lock);
8504 loaded++; /* undo earlier decrement */
8515 static devclass_t t4_devclass, t5_devclass;
8516 static devclass_t cxgbe_devclass, cxl_devclass;
8518 DRIVER_MODULE(t4nex, pci, t4_driver, t4_devclass, mod_event, 0);
8519 MODULE_VERSION(t4nex, 1);
8520 MODULE_DEPEND(t4nex, firmware, 1, 1, 1);
8522 DRIVER_MODULE(t5nex, pci, t5_driver, t5_devclass, mod_event, 0);
8523 MODULE_VERSION(t5nex, 1);
8524 MODULE_DEPEND(t5nex, firmware, 1, 1, 1);
8526 DRIVER_MODULE(cxgbe, t4nex, cxgbe_driver, cxgbe_devclass, 0, 0);
8527 MODULE_VERSION(cxgbe, 1);
8529 DRIVER_MODULE(cxl, t5nex, cxl_driver, cxl_devclass, 0, 0);
8530 MODULE_VERSION(cxl, 1);