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/systm.h>
40 #include <sys/counter.h>
41 #include <sys/module.h>
42 #include <sys/malloc.h>
43 #include <sys/queue.h>
44 #include <sys/taskqueue.h>
45 #include <sys/pciio.h>
46 #include <dev/pci/pcireg.h>
47 #include <dev/pci/pcivar.h>
48 #include <dev/pci/pci_private.h>
49 #include <sys/firmware.h>
52 #include <sys/socket.h>
53 #include <sys/sockio.h>
54 #include <sys/sysctl.h>
55 #include <net/ethernet.h>
57 #include <net/if_types.h>
58 #include <net/if_dl.h>
59 #include <net/if_vlan_var.h>
61 #include <net/rss_config.h>
63 #if defined(__i386__) || defined(__amd64__)
68 #include "common/common.h"
69 #include "common/t4_msg.h"
70 #include "common/t4_regs.h"
71 #include "common/t4_regs_values.h"
74 #include "t4_mp_ring.h"
76 /* T4 bus driver interface */
77 static int t4_probe(device_t);
78 static int t4_attach(device_t);
79 static int t4_detach(device_t);
80 static device_method_t t4_methods[] = {
81 DEVMETHOD(device_probe, t4_probe),
82 DEVMETHOD(device_attach, t4_attach),
83 DEVMETHOD(device_detach, t4_detach),
87 static driver_t t4_driver = {
90 sizeof(struct adapter)
94 /* T4 port (cxgbe) interface */
95 static int cxgbe_probe(device_t);
96 static int cxgbe_attach(device_t);
97 static int cxgbe_detach(device_t);
98 static device_method_t cxgbe_methods[] = {
99 DEVMETHOD(device_probe, cxgbe_probe),
100 DEVMETHOD(device_attach, cxgbe_attach),
101 DEVMETHOD(device_detach, cxgbe_detach),
104 static driver_t cxgbe_driver = {
107 sizeof(struct port_info)
110 /* T4 VI (vcxgbe) interface */
111 static int vcxgbe_probe(device_t);
112 static int vcxgbe_attach(device_t);
113 static int vcxgbe_detach(device_t);
114 static device_method_t vcxgbe_methods[] = {
115 DEVMETHOD(device_probe, vcxgbe_probe),
116 DEVMETHOD(device_attach, vcxgbe_attach),
117 DEVMETHOD(device_detach, vcxgbe_detach),
120 static driver_t vcxgbe_driver = {
123 sizeof(struct vi_info)
126 static d_ioctl_t t4_ioctl;
127 static d_open_t t4_open;
128 static d_close_t t4_close;
130 static struct cdevsw t4_cdevsw = {
131 .d_version = D_VERSION,
139 /* T5 bus driver interface */
140 static int t5_probe(device_t);
141 static device_method_t t5_methods[] = {
142 DEVMETHOD(device_probe, t5_probe),
143 DEVMETHOD(device_attach, t4_attach),
144 DEVMETHOD(device_detach, t4_detach),
148 static driver_t t5_driver = {
151 sizeof(struct adapter)
155 /* T5 port (cxl) interface */
156 static driver_t cxl_driver = {
159 sizeof(struct port_info)
162 /* T5 VI (vcxl) interface */
163 static driver_t vcxl_driver = {
166 sizeof(struct vi_info)
169 static struct cdevsw t5_cdevsw = {
170 .d_version = D_VERSION,
178 /* ifnet + media interface */
179 static void cxgbe_init(void *);
180 static int cxgbe_ioctl(struct ifnet *, unsigned long, caddr_t);
181 static int cxgbe_transmit(struct ifnet *, struct mbuf *);
182 static void cxgbe_qflush(struct ifnet *);
183 static int cxgbe_media_change(struct ifnet *);
184 static void cxgbe_media_status(struct ifnet *, struct ifmediareq *);
186 MALLOC_DEFINE(M_CXGBE, "cxgbe", "Chelsio T4/T5 Ethernet driver and services");
189 * Correct lock order when you need to acquire multiple locks is t4_list_lock,
190 * then ADAPTER_LOCK, then t4_uld_list_lock.
192 static struct sx t4_list_lock;
193 SLIST_HEAD(, adapter) t4_list;
195 static struct sx t4_uld_list_lock;
196 SLIST_HEAD(, uld_info) t4_uld_list;
200 * Tunables. See tweak_tunables() too.
202 * Each tunable is set to a default value here if it's known at compile-time.
203 * Otherwise it is set to -1 as an indication to tweak_tunables() that it should
204 * provide a reasonable default when the driver is loaded.
206 * Tunables applicable to both T4 and T5 are under hw.cxgbe. Those specific to
207 * T5 are under hw.cxl.
211 * Number of queues for tx and rx, 10G and 1G, NIC and offload.
214 static int t4_ntxq10g = -1;
215 TUNABLE_INT("hw.cxgbe.ntxq10g", &t4_ntxq10g);
218 static int t4_nrxq10g = -1;
219 TUNABLE_INT("hw.cxgbe.nrxq10g", &t4_nrxq10g);
222 static int t4_ntxq1g = -1;
223 TUNABLE_INT("hw.cxgbe.ntxq1g", &t4_ntxq1g);
226 static int t4_nrxq1g = -1;
227 TUNABLE_INT("hw.cxgbe.nrxq1g", &t4_nrxq1g);
230 static int t4_ntxq_vi = -1;
231 TUNABLE_INT("hw.cxgbe.ntxq_vi", &t4_ntxq_vi);
234 static int t4_nrxq_vi = -1;
235 TUNABLE_INT("hw.cxgbe.nrxq_vi", &t4_nrxq_vi);
237 static int t4_rsrv_noflowq = 0;
238 TUNABLE_INT("hw.cxgbe.rsrv_noflowq", &t4_rsrv_noflowq);
241 #define NOFLDTXQ_10G 8
242 static int t4_nofldtxq10g = -1;
243 TUNABLE_INT("hw.cxgbe.nofldtxq10g", &t4_nofldtxq10g);
245 #define NOFLDRXQ_10G 2
246 static int t4_nofldrxq10g = -1;
247 TUNABLE_INT("hw.cxgbe.nofldrxq10g", &t4_nofldrxq10g);
249 #define NOFLDTXQ_1G 2
250 static int t4_nofldtxq1g = -1;
251 TUNABLE_INT("hw.cxgbe.nofldtxq1g", &t4_nofldtxq1g);
253 #define NOFLDRXQ_1G 1
254 static int t4_nofldrxq1g = -1;
255 TUNABLE_INT("hw.cxgbe.nofldrxq1g", &t4_nofldrxq1g);
257 #define NOFLDTXQ_VI 1
258 static int t4_nofldtxq_vi = -1;
259 TUNABLE_INT("hw.cxgbe.nofldtxq_vi", &t4_nofldtxq_vi);
261 #define NOFLDRXQ_VI 1
262 static int t4_nofldrxq_vi = -1;
263 TUNABLE_INT("hw.cxgbe.nofldrxq_vi", &t4_nofldrxq_vi);
268 static int t4_nnmtxq_vi = -1;
269 TUNABLE_INT("hw.cxgbe.nnmtxq_vi", &t4_nnmtxq_vi);
272 static int t4_nnmrxq_vi = -1;
273 TUNABLE_INT("hw.cxgbe.nnmrxq_vi", &t4_nnmrxq_vi);
277 * Holdoff parameters for 10G and 1G ports.
279 #define TMR_IDX_10G 1
280 static int t4_tmr_idx_10g = TMR_IDX_10G;
281 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_10G", &t4_tmr_idx_10g);
283 #define PKTC_IDX_10G (-1)
284 static int t4_pktc_idx_10g = PKTC_IDX_10G;
285 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_10G", &t4_pktc_idx_10g);
288 static int t4_tmr_idx_1g = TMR_IDX_1G;
289 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_1G", &t4_tmr_idx_1g);
291 #define PKTC_IDX_1G (-1)
292 static int t4_pktc_idx_1g = PKTC_IDX_1G;
293 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_1G", &t4_pktc_idx_1g);
296 * Size (# of entries) of each tx and rx queue.
298 static unsigned int t4_qsize_txq = TX_EQ_QSIZE;
299 TUNABLE_INT("hw.cxgbe.qsize_txq", &t4_qsize_txq);
301 static unsigned int t4_qsize_rxq = RX_IQ_QSIZE;
302 TUNABLE_INT("hw.cxgbe.qsize_rxq", &t4_qsize_rxq);
305 * Interrupt types allowed (bits 0, 1, 2 = INTx, MSI, MSI-X respectively).
307 static int t4_intr_types = INTR_MSIX | INTR_MSI | INTR_INTX;
308 TUNABLE_INT("hw.cxgbe.interrupt_types", &t4_intr_types);
311 * Configuration file.
313 #define DEFAULT_CF "default"
314 #define FLASH_CF "flash"
315 #define UWIRE_CF "uwire"
316 #define FPGA_CF "fpga"
317 static char t4_cfg_file[32] = DEFAULT_CF;
318 TUNABLE_STR("hw.cxgbe.config_file", t4_cfg_file, sizeof(t4_cfg_file));
321 * PAUSE settings (bit 0, 1 = rx_pause, tx_pause respectively).
322 * rx_pause = 1 to heed incoming PAUSE frames, 0 to ignore them.
323 * tx_pause = 1 to emit PAUSE frames when the rx FIFO reaches its high water
324 * mark or when signalled to do so, 0 to never emit PAUSE.
326 static int t4_pause_settings = PAUSE_TX | PAUSE_RX;
327 TUNABLE_INT("hw.cxgbe.pause_settings", &t4_pause_settings);
330 * Firmware auto-install by driver during attach (0, 1, 2 = prohibited, allowed,
331 * encouraged respectively).
333 static unsigned int t4_fw_install = 1;
334 TUNABLE_INT("hw.cxgbe.fw_install", &t4_fw_install);
337 * ASIC features that will be used. Disable the ones you don't want so that the
338 * chip resources aren't wasted on features that will not be used.
340 static int t4_linkcaps_allowed = 0; /* No DCBX, PPP, etc. by default */
341 TUNABLE_INT("hw.cxgbe.linkcaps_allowed", &t4_linkcaps_allowed);
343 static int t4_niccaps_allowed = FW_CAPS_CONFIG_NIC;
344 TUNABLE_INT("hw.cxgbe.niccaps_allowed", &t4_niccaps_allowed);
346 static int t4_toecaps_allowed = -1;
347 TUNABLE_INT("hw.cxgbe.toecaps_allowed", &t4_toecaps_allowed);
349 static int t4_rdmacaps_allowed = 0;
350 TUNABLE_INT("hw.cxgbe.rdmacaps_allowed", &t4_rdmacaps_allowed);
352 static int t4_iscsicaps_allowed = 0;
353 TUNABLE_INT("hw.cxgbe.iscsicaps_allowed", &t4_iscsicaps_allowed);
355 static int t4_fcoecaps_allowed = 0;
356 TUNABLE_INT("hw.cxgbe.fcoecaps_allowed", &t4_fcoecaps_allowed);
358 static int t5_write_combine = 0;
359 TUNABLE_INT("hw.cxl.write_combine", &t5_write_combine);
361 static int t4_num_vis = 1;
362 TUNABLE_INT("hw.cxgbe.num_vis", &t4_num_vis);
364 /* Functions used by extra VIs to obtain unique MAC addresses for each VI. */
365 static int vi_mac_funcs[] = {
368 FW_VI_FUNC_OPENISCSI,
374 struct intrs_and_queues {
375 uint16_t intr_type; /* INTx, MSI, or MSI-X */
376 uint16_t nirq; /* Total # of vectors */
377 uint16_t intr_flags_10g;/* Interrupt flags for each 10G port */
378 uint16_t intr_flags_1g; /* Interrupt flags for each 1G port */
379 uint16_t ntxq10g; /* # of NIC txq's for each 10G port */
380 uint16_t nrxq10g; /* # of NIC rxq's for each 10G port */
381 uint16_t ntxq1g; /* # of NIC txq's for each 1G port */
382 uint16_t nrxq1g; /* # of NIC rxq's for each 1G port */
383 uint16_t rsrv_noflowq; /* Flag whether to reserve queue 0 */
384 uint16_t nofldtxq10g; /* # of TOE txq's for each 10G port */
385 uint16_t nofldrxq10g; /* # of TOE rxq's for each 10G port */
386 uint16_t nofldtxq1g; /* # of TOE txq's for each 1G port */
387 uint16_t nofldrxq1g; /* # of TOE rxq's for each 1G port */
389 /* The vcxgbe/vcxl interfaces use these and not the ones above. */
390 uint16_t ntxq_vi; /* # of NIC txq's */
391 uint16_t nrxq_vi; /* # of NIC rxq's */
392 uint16_t nofldtxq_vi; /* # of TOE txq's */
393 uint16_t nofldrxq_vi; /* # of TOE rxq's */
394 uint16_t nnmtxq_vi; /* # of netmap txq's */
395 uint16_t nnmrxq_vi; /* # of netmap rxq's */
398 struct filter_entry {
399 uint32_t valid:1; /* filter allocated and valid */
400 uint32_t locked:1; /* filter is administratively locked */
401 uint32_t pending:1; /* filter action is pending firmware reply */
402 uint32_t smtidx:8; /* Source MAC Table index for smac */
403 struct l2t_entry *l2t; /* Layer Two Table entry for dmac */
405 struct t4_filter_specification fs;
408 static int map_bars_0_and_4(struct adapter *);
409 static int map_bar_2(struct adapter *);
410 static void setup_memwin(struct adapter *);
411 static int validate_mem_range(struct adapter *, uint32_t, int);
412 static int fwmtype_to_hwmtype(int);
413 static int validate_mt_off_len(struct adapter *, int, uint32_t, int,
415 static void memwin_info(struct adapter *, int, uint32_t *, uint32_t *);
416 static uint32_t position_memwin(struct adapter *, int, uint32_t);
417 static int cfg_itype_and_nqueues(struct adapter *, int, int, int,
418 struct intrs_and_queues *);
419 static int prep_firmware(struct adapter *);
420 static int partition_resources(struct adapter *, const struct firmware *,
422 static int get_params__pre_init(struct adapter *);
423 static int get_params__post_init(struct adapter *);
424 static int set_params__post_init(struct adapter *);
425 static void t4_set_desc(struct adapter *);
426 static void build_medialist(struct port_info *, struct ifmedia *);
427 static int cxgbe_init_synchronized(struct vi_info *);
428 static int cxgbe_uninit_synchronized(struct vi_info *);
429 static int setup_intr_handlers(struct adapter *);
430 static void quiesce_txq(struct adapter *, struct sge_txq *);
431 static void quiesce_wrq(struct adapter *, struct sge_wrq *);
432 static void quiesce_iq(struct adapter *, struct sge_iq *);
433 static void quiesce_fl(struct adapter *, struct sge_fl *);
434 static int t4_alloc_irq(struct adapter *, struct irq *, int rid,
435 driver_intr_t *, void *, char *);
436 static int t4_free_irq(struct adapter *, struct irq *);
437 static void reg_block_dump(struct adapter *, uint8_t *, unsigned int,
439 static void t4_get_regs(struct adapter *, struct t4_regdump *, uint8_t *);
440 static void vi_refresh_stats(struct adapter *, struct vi_info *);
441 static void cxgbe_refresh_stats(struct adapter *, struct port_info *);
442 static void cxgbe_tick(void *);
443 static void cxgbe_vlan_config(void *, struct ifnet *, uint16_t);
444 static int cpl_not_handled(struct sge_iq *, const struct rss_header *,
446 static int an_not_handled(struct sge_iq *, const struct rsp_ctrl *);
447 static int fw_msg_not_handled(struct adapter *, const __be64 *);
448 static void t4_sysctls(struct adapter *);
449 static void cxgbe_sysctls(struct port_info *);
450 static int sysctl_int_array(SYSCTL_HANDLER_ARGS);
451 static int sysctl_bitfield(SYSCTL_HANDLER_ARGS);
452 static int sysctl_btphy(SYSCTL_HANDLER_ARGS);
453 static int sysctl_noflowq(SYSCTL_HANDLER_ARGS);
454 static int sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS);
455 static int sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS);
456 static int sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS);
457 static int sysctl_qsize_txq(SYSCTL_HANDLER_ARGS);
458 static int sysctl_pause_settings(SYSCTL_HANDLER_ARGS);
459 static int sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS);
460 static int sysctl_temperature(SYSCTL_HANDLER_ARGS);
462 static int sysctl_cctrl(SYSCTL_HANDLER_ARGS);
463 static int sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS);
464 static int sysctl_cim_la(SYSCTL_HANDLER_ARGS);
465 static int sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS);
466 static int sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS);
467 static int sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS);
468 static int sysctl_cpl_stats(SYSCTL_HANDLER_ARGS);
469 static int sysctl_ddp_stats(SYSCTL_HANDLER_ARGS);
470 static int sysctl_devlog(SYSCTL_HANDLER_ARGS);
471 static int sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS);
472 static int sysctl_hw_sched(SYSCTL_HANDLER_ARGS);
473 static int sysctl_lb_stats(SYSCTL_HANDLER_ARGS);
474 static int sysctl_linkdnrc(SYSCTL_HANDLER_ARGS);
475 static int sysctl_meminfo(SYSCTL_HANDLER_ARGS);
476 static int sysctl_mps_tcam(SYSCTL_HANDLER_ARGS);
477 static int sysctl_path_mtus(SYSCTL_HANDLER_ARGS);
478 static int sysctl_pm_stats(SYSCTL_HANDLER_ARGS);
479 static int sysctl_rdma_stats(SYSCTL_HANDLER_ARGS);
480 static int sysctl_tcp_stats(SYSCTL_HANDLER_ARGS);
481 static int sysctl_tids(SYSCTL_HANDLER_ARGS);
482 static int sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS);
483 static int sysctl_tp_la(SYSCTL_HANDLER_ARGS);
484 static int sysctl_tx_rate(SYSCTL_HANDLER_ARGS);
485 static int sysctl_ulprx_la(SYSCTL_HANDLER_ARGS);
486 static int sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS);
488 static uint32_t fconf_to_mode(uint32_t);
489 static uint32_t mode_to_fconf(uint32_t);
490 static uint32_t fspec_to_fconf(struct t4_filter_specification *);
491 static int get_filter_mode(struct adapter *, uint32_t *);
492 static int set_filter_mode(struct adapter *, uint32_t);
493 static inline uint64_t get_filter_hits(struct adapter *, uint32_t);
494 static int get_filter(struct adapter *, struct t4_filter *);
495 static int set_filter(struct adapter *, struct t4_filter *);
496 static int del_filter(struct adapter *, struct t4_filter *);
497 static void clear_filter(struct filter_entry *);
498 static int set_filter_wr(struct adapter *, int);
499 static int del_filter_wr(struct adapter *, int);
500 static int get_sge_context(struct adapter *, struct t4_sge_context *);
501 static int load_fw(struct adapter *, struct t4_data *);
502 static int read_card_mem(struct adapter *, int, struct t4_mem_range *);
503 static int read_i2c(struct adapter *, struct t4_i2c_data *);
504 static int set_sched_class(struct adapter *, struct t4_sched_params *);
505 static int set_sched_queue(struct adapter *, struct t4_sched_queue *);
507 static int toe_capability(struct vi_info *, int);
509 static int mod_event(module_t, int, void *);
515 {0xa000, "Chelsio Terminator 4 FPGA"},
516 {0x4400, "Chelsio T440-dbg"},
517 {0x4401, "Chelsio T420-CR"},
518 {0x4402, "Chelsio T422-CR"},
519 {0x4403, "Chelsio T440-CR"},
520 {0x4404, "Chelsio T420-BCH"},
521 {0x4405, "Chelsio T440-BCH"},
522 {0x4406, "Chelsio T440-CH"},
523 {0x4407, "Chelsio T420-SO"},
524 {0x4408, "Chelsio T420-CX"},
525 {0x4409, "Chelsio T420-BT"},
526 {0x440a, "Chelsio T404-BT"},
527 {0x440e, "Chelsio T440-LP-CR"},
529 {0xb000, "Chelsio Terminator 5 FPGA"},
530 {0x5400, "Chelsio T580-dbg"},
531 {0x5401, "Chelsio T520-CR"}, /* 2 x 10G */
532 {0x5402, "Chelsio T522-CR"}, /* 2 x 10G, 2 X 1G */
533 {0x5403, "Chelsio T540-CR"}, /* 4 x 10G */
534 {0x5407, "Chelsio T520-SO"}, /* 2 x 10G, nomem */
535 {0x5409, "Chelsio T520-BT"}, /* 2 x 10GBaseT */
536 {0x540a, "Chelsio T504-BT"}, /* 4 x 1G */
537 {0x540d, "Chelsio T580-CR"}, /* 2 x 40G */
538 {0x540e, "Chelsio T540-LP-CR"}, /* 4 x 10G */
539 {0x5410, "Chelsio T580-LP-CR"}, /* 2 x 40G */
540 {0x5411, "Chelsio T520-LL-CR"}, /* 2 x 10G */
541 {0x5412, "Chelsio T560-CR"}, /* 1 x 40G, 2 x 10G */
542 {0x5414, "Chelsio T580-LP-SO-CR"}, /* 2 x 40G, nomem */
543 {0x5415, "Chelsio T502-BT"}, /* 2 x 1G */
545 {0x5404, "Chelsio T520-BCH"},
546 {0x5405, "Chelsio T540-BCH"},
547 {0x5406, "Chelsio T540-CH"},
548 {0x5408, "Chelsio T520-CX"},
549 {0x540b, "Chelsio B520-SR"},
550 {0x540c, "Chelsio B504-BT"},
551 {0x540f, "Chelsio Amsterdam"},
552 {0x5413, "Chelsio T580-CHR"},
558 * service_iq() has an iq and needs the fl. Offset of fl from the iq should be
559 * exactly the same for both rxq and ofld_rxq.
561 CTASSERT(offsetof(struct sge_ofld_rxq, iq) == offsetof(struct sge_rxq, iq));
562 CTASSERT(offsetof(struct sge_ofld_rxq, fl) == offsetof(struct sge_rxq, fl));
565 /* No easy way to include t4_msg.h before adapter.h so we check this way */
566 CTASSERT(nitems(((struct adapter *)0)->cpl_handler) == NUM_CPL_CMDS);
567 CTASSERT(nitems(((struct adapter *)0)->fw_msg_handler) == NUM_FW6_TYPES);
569 CTASSERT(sizeof(struct cluster_metadata) <= CL_METADATA_SIZE);
572 t4_probe(device_t dev)
575 uint16_t v = pci_get_vendor(dev);
576 uint16_t d = pci_get_device(dev);
577 uint8_t f = pci_get_function(dev);
579 if (v != PCI_VENDOR_ID_CHELSIO)
582 /* Attach only to PF0 of the FPGA */
583 if (d == 0xa000 && f != 0)
586 for (i = 0; i < nitems(t4_pciids); i++) {
587 if (d == t4_pciids[i].device) {
588 device_set_desc(dev, t4_pciids[i].desc);
589 return (BUS_PROBE_DEFAULT);
597 t5_probe(device_t dev)
600 uint16_t v = pci_get_vendor(dev);
601 uint16_t d = pci_get_device(dev);
602 uint8_t f = pci_get_function(dev);
604 if (v != PCI_VENDOR_ID_CHELSIO)
607 /* Attach only to PF0 of the FPGA */
608 if (d == 0xb000 && f != 0)
611 for (i = 0; i < nitems(t5_pciids); i++) {
612 if (d == t5_pciids[i].device) {
613 device_set_desc(dev, t5_pciids[i].desc);
614 return (BUS_PROBE_DEFAULT);
622 t5_attribute_workaround(device_t dev)
628 * The T5 chips do not properly echo the No Snoop and Relaxed
629 * Ordering attributes when replying to a TLP from a Root
630 * Port. As a workaround, find the parent Root Port and
631 * disable No Snoop and Relaxed Ordering. Note that this
632 * affects all devices under this root port.
634 root_port = pci_find_pcie_root_port(dev);
635 if (root_port == NULL) {
636 device_printf(dev, "Unable to find parent root port\n");
640 v = pcie_adjust_config(root_port, PCIER_DEVICE_CTL,
641 PCIEM_CTL_RELAXED_ORD_ENABLE | PCIEM_CTL_NOSNOOP_ENABLE, 0, 2);
642 if ((v & (PCIEM_CTL_RELAXED_ORD_ENABLE | PCIEM_CTL_NOSNOOP_ENABLE)) !=
644 device_printf(dev, "Disabled No Snoop/Relaxed Ordering on %s\n",
645 device_get_nameunit(root_port));
649 t4_attach(device_t dev)
652 int rc = 0, i, j, n10g, n1g, rqidx, tqidx;
653 struct intrs_and_queues iaq;
656 int ofld_rqidx, ofld_tqidx;
659 int nm_rqidx, nm_tqidx;
663 sc = device_get_softc(dev);
665 TUNABLE_INT_FETCH("hw.cxgbe.debug_flags", &sc->debug_flags);
667 if ((pci_get_device(dev) & 0xff00) == 0x5400)
668 t5_attribute_workaround(dev);
669 pci_enable_busmaster(dev);
670 if (pci_find_cap(dev, PCIY_EXPRESS, &i) == 0) {
673 pci_set_max_read_req(dev, 4096);
674 v = pci_read_config(dev, i + PCIER_DEVICE_CTL, 2);
675 v |= PCIEM_CTL_RELAXED_ORD_ENABLE;
676 pci_write_config(dev, i + PCIER_DEVICE_CTL, v, 2);
678 sc->params.pci.mps = 128 << ((v & PCIEM_CTL_MAX_PAYLOAD) >> 5);
682 mtx_init(&sc->ifp_lock, sc->ifp_lockname, 0, MTX_DEF);
683 snprintf(sc->ifp_lockname, sizeof(sc->ifp_lockname), "%s tracer",
684 device_get_nameunit(dev));
686 snprintf(sc->lockname, sizeof(sc->lockname), "%s",
687 device_get_nameunit(dev));
688 mtx_init(&sc->sc_lock, sc->lockname, 0, MTX_DEF);
689 sx_xlock(&t4_list_lock);
690 SLIST_INSERT_HEAD(&t4_list, sc, link);
691 sx_xunlock(&t4_list_lock);
693 mtx_init(&sc->sfl_lock, "starving freelists", 0, MTX_DEF);
694 TAILQ_INIT(&sc->sfl);
695 callout_init_mtx(&sc->sfl_callout, &sc->sfl_lock, 0);
697 mtx_init(&sc->regwin_lock, "register and memory window", 0, MTX_DEF);
699 rc = map_bars_0_and_4(sc);
701 goto done; /* error message displayed already */
704 * This is the real PF# to which we're attaching. Works from within PCI
705 * passthrough environments too, where pci_get_function() could return a
706 * different PF# depending on the passthrough configuration. We need to
707 * use the real PF# in all our communication with the firmware.
709 sc->pf = G_SOURCEPF(t4_read_reg(sc, A_PL_WHOAMI));
712 memset(sc->chan_map, 0xff, sizeof(sc->chan_map));
713 sc->an_handler = an_not_handled;
714 for (i = 0; i < nitems(sc->cpl_handler); i++)
715 sc->cpl_handler[i] = cpl_not_handled;
716 for (i = 0; i < nitems(sc->fw_msg_handler); i++)
717 sc->fw_msg_handler[i] = fw_msg_not_handled;
718 t4_register_cpl_handler(sc, CPL_SET_TCB_RPL, t4_filter_rpl);
719 t4_register_cpl_handler(sc, CPL_TRACE_PKT, t4_trace_pkt);
720 t4_register_cpl_handler(sc, CPL_TRACE_PKT_T5, t5_trace_pkt);
721 t4_init_sge_cpl_handlers(sc);
723 /* Prepare the adapter for operation */
724 rc = -t4_prep_adapter(sc);
726 device_printf(dev, "failed to prepare adapter: %d.\n", rc);
731 * Do this really early, with the memory windows set up even before the
732 * character device. The userland tool's register i/o and mem read
733 * will work even in "recovery mode".
736 sc->cdev = make_dev(is_t4(sc) ? &t4_cdevsw : &t5_cdevsw,
737 device_get_unit(dev), UID_ROOT, GID_WHEEL, 0600, "%s",
738 device_get_nameunit(dev));
739 if (sc->cdev == NULL)
740 device_printf(dev, "failed to create nexus char device.\n");
742 sc->cdev->si_drv1 = sc;
744 /* Go no further if recovery mode has been requested. */
745 if (TUNABLE_INT_FETCH("hw.cxgbe.sos", &i) && i != 0) {
746 device_printf(dev, "recovery mode.\n");
750 #if defined(__i386__)
751 if ((cpu_feature & CPUID_CX8) == 0) {
752 device_printf(dev, "64 bit atomics not available.\n");
758 /* Prepare the firmware for operation */
759 rc = prep_firmware(sc);
761 goto done; /* error message displayed already */
763 rc = get_params__post_init(sc);
765 goto done; /* error message displayed already */
767 rc = set_params__post_init(sc);
769 goto done; /* error message displayed already */
773 goto done; /* error message displayed already */
775 rc = t4_create_dma_tag(sc);
777 goto done; /* error message displayed already */
780 * Number of VIs to create per-port. The first VI is the "main" regular
781 * VI for the port. The rest are additional virtual interfaces on the
782 * same physical port. Note that the main VI does not have native
783 * netmap support but the extra VIs do.
785 * Limit the number of VIs per port to the number of available
786 * MAC addresses per port.
789 num_vis = t4_num_vis;
792 if (num_vis > nitems(vi_mac_funcs)) {
793 num_vis = nitems(vi_mac_funcs);
794 device_printf(dev, "Number of VIs limited to %d\n", num_vis);
798 * First pass over all the ports - allocate VIs and initialize some
799 * basic parameters like mac address, port type, etc. We also figure
800 * out whether a port is 10G or 1G and use that information when
801 * calculating how many interrupts to attempt to allocate.
804 for_each_port(sc, i) {
805 struct port_info *pi;
807 pi = malloc(sizeof(*pi), M_CXGBE, M_ZERO | M_WAITOK);
810 /* These must be set before t4_port_init */
814 * XXX: vi[0] is special so we can't delay this allocation until
815 * pi->nvi's final value is known.
817 pi->vi = malloc(sizeof(struct vi_info) * num_vis, M_CXGBE,
821 * Allocate the "main" VI and initialize parameters
824 rc = -t4_port_init(pi, sc->mbox, sc->pf, 0);
826 device_printf(dev, "unable to initialize port %d: %d\n",
828 free(pi->vi, M_CXGBE);
834 pi->link_cfg.requested_fc &= ~(PAUSE_TX | PAUSE_RX);
835 pi->link_cfg.requested_fc |= t4_pause_settings;
836 pi->link_cfg.fc &= ~(PAUSE_TX | PAUSE_RX);
837 pi->link_cfg.fc |= t4_pause_settings;
839 rc = -t4_link_start(sc, sc->mbox, pi->tx_chan, &pi->link_cfg);
841 device_printf(dev, "port %d l1cfg failed: %d\n", i, rc);
842 free(pi->vi, M_CXGBE);
848 snprintf(pi->lockname, sizeof(pi->lockname), "%sp%d",
849 device_get_nameunit(dev), i);
850 mtx_init(&pi->pi_lock, pi->lockname, 0, MTX_DEF);
851 sc->chan_map[pi->tx_chan] = i;
853 if (is_10G_port(pi) || is_40G_port(pi)) {
861 pi->dev = device_add_child(dev, is_t4(sc) ? "cxgbe" : "cxl", -1);
862 if (pi->dev == NULL) {
864 "failed to add device for port %d.\n", i);
868 pi->vi[0].dev = pi->dev;
869 device_set_softc(pi->dev, pi);
873 * Interrupt type, # of interrupts, # of rx/tx queues, etc.
875 rc = cfg_itype_and_nqueues(sc, n10g, n1g, num_vis, &iaq);
877 goto done; /* error message displayed already */
878 if (iaq.nrxq_vi + iaq.nofldrxq_vi + iaq.nnmrxq_vi == 0)
881 sc->intr_type = iaq.intr_type;
882 sc->intr_count = iaq.nirq;
885 s->nrxq = n10g * iaq.nrxq10g + n1g * iaq.nrxq1g;
886 s->ntxq = n10g * iaq.ntxq10g + n1g * iaq.ntxq1g;
888 s->nrxq += (n10g + n1g) * (num_vis - 1) * iaq.nrxq_vi;
889 s->ntxq += (n10g + n1g) * (num_vis - 1) * iaq.ntxq_vi;
891 s->neq = s->ntxq + s->nrxq; /* the free list in an rxq is an eq */
892 s->neq += sc->params.nports + 1;/* ctrl queues: 1 per port + 1 mgmt */
893 s->niq = s->nrxq + 1; /* 1 extra for firmware event queue */
895 if (is_offload(sc)) {
896 s->nofldrxq = n10g * iaq.nofldrxq10g + n1g * iaq.nofldrxq1g;
897 s->nofldtxq = n10g * iaq.nofldtxq10g + n1g * iaq.nofldtxq1g;
899 s->nofldrxq += (n10g + n1g) * (num_vis - 1) *
901 s->nofldtxq += (n10g + n1g) * (num_vis - 1) *
904 s->neq += s->nofldtxq + s->nofldrxq;
905 s->niq += s->nofldrxq;
907 s->ofld_rxq = malloc(s->nofldrxq * sizeof(struct sge_ofld_rxq),
908 M_CXGBE, M_ZERO | M_WAITOK);
909 s->ofld_txq = malloc(s->nofldtxq * sizeof(struct sge_wrq),
910 M_CXGBE, M_ZERO | M_WAITOK);
915 s->nnmrxq = (n10g + n1g) * (num_vis - 1) * iaq.nnmrxq_vi;
916 s->nnmtxq = (n10g + n1g) * (num_vis - 1) * iaq.nnmtxq_vi;
918 s->neq += s->nnmtxq + s->nnmrxq;
921 s->nm_rxq = malloc(s->nnmrxq * sizeof(struct sge_nm_rxq),
922 M_CXGBE, M_ZERO | M_WAITOK);
923 s->nm_txq = malloc(s->nnmtxq * sizeof(struct sge_nm_txq),
924 M_CXGBE, M_ZERO | M_WAITOK);
927 s->ctrlq = malloc(sc->params.nports * sizeof(struct sge_wrq), M_CXGBE,
929 s->rxq = malloc(s->nrxq * sizeof(struct sge_rxq), M_CXGBE,
931 s->txq = malloc(s->ntxq * sizeof(struct sge_txq), M_CXGBE,
933 s->iqmap = malloc(s->niq * sizeof(struct sge_iq *), M_CXGBE,
935 s->eqmap = malloc(s->neq * sizeof(struct sge_eq *), M_CXGBE,
938 sc->irq = malloc(sc->intr_count * sizeof(struct irq), M_CXGBE,
941 t4_init_l2t(sc, M_WAITOK);
944 * Second pass over the ports. This time we know the number of rx and
945 * tx queues that each port should get.
949 ofld_rqidx = ofld_tqidx = 0;
952 nm_rqidx = nm_tqidx = 0;
954 for_each_port(sc, i) {
955 struct port_info *pi = sc->port[i];
962 for_each_vi(pi, j, vi) {
964 vi->qsize_rxq = t4_qsize_rxq;
965 vi->qsize_txq = t4_qsize_txq;
967 vi->first_rxq = rqidx;
968 vi->first_txq = tqidx;
969 if (is_10G_port(pi) || is_40G_port(pi)) {
970 vi->tmr_idx = t4_tmr_idx_10g;
971 vi->pktc_idx = t4_pktc_idx_10g;
972 vi->flags |= iaq.intr_flags_10g & INTR_RXQ;
973 vi->nrxq = j == 0 ? iaq.nrxq10g : iaq.nrxq_vi;
974 vi->ntxq = j == 0 ? iaq.ntxq10g : iaq.ntxq_vi;
976 vi->tmr_idx = t4_tmr_idx_1g;
977 vi->pktc_idx = t4_pktc_idx_1g;
978 vi->flags |= iaq.intr_flags_1g & INTR_RXQ;
979 vi->nrxq = j == 0 ? iaq.nrxq1g : iaq.nrxq_vi;
980 vi->ntxq = j == 0 ? iaq.ntxq1g : iaq.ntxq_vi;
985 if (j == 0 && vi->ntxq > 1)
986 vi->rsrv_noflowq = iaq.rsrv_noflowq ? 1 : 0;
988 vi->rsrv_noflowq = 0;
991 vi->first_ofld_rxq = ofld_rqidx;
992 vi->first_ofld_txq = ofld_tqidx;
993 if (is_10G_port(pi) || is_40G_port(pi)) {
994 vi->flags |= iaq.intr_flags_10g & INTR_OFLD_RXQ;
995 vi->nofldrxq = j == 0 ? iaq.nofldrxq10g :
997 vi->nofldtxq = j == 0 ? iaq.nofldtxq10g :
1000 vi->flags |= iaq.intr_flags_1g & INTR_OFLD_RXQ;
1001 vi->nofldrxq = j == 0 ? iaq.nofldrxq1g :
1003 vi->nofldtxq = j == 0 ? iaq.nofldtxq1g :
1006 ofld_rqidx += vi->nofldrxq;
1007 ofld_tqidx += vi->nofldtxq;
1011 vi->first_nm_rxq = nm_rqidx;
1012 vi->first_nm_txq = nm_tqidx;
1013 vi->nnmrxq = iaq.nnmrxq_vi;
1014 vi->nnmtxq = iaq.nnmtxq_vi;
1015 nm_rqidx += vi->nnmrxq;
1016 nm_tqidx += vi->nnmtxq;
1022 rc = setup_intr_handlers(sc);
1025 "failed to setup interrupt handlers: %d\n", rc);
1029 rc = bus_generic_attach(dev);
1032 "failed to attach all child ports: %d\n", rc);
1037 "PCIe gen%d x%d, %d ports, %d %s interrupt%s, %d eq, %d iq\n",
1038 sc->params.pci.speed, sc->params.pci.width, sc->params.nports,
1039 sc->intr_count, sc->intr_type == INTR_MSIX ? "MSI-X" :
1040 (sc->intr_type == INTR_MSI ? "MSI" : "INTx"),
1041 sc->intr_count > 1 ? "s" : "", sc->sge.neq, sc->sge.niq);
1046 if (rc != 0 && sc->cdev) {
1047 /* cdev was created and so cxgbetool works; recover that way. */
1049 "error during attach, adapter is now in recovery mode.\n");
1065 t4_detach(device_t dev)
1068 struct port_info *pi;
1071 sc = device_get_softc(dev);
1073 if (sc->flags & FULL_INIT_DONE)
1074 t4_intr_disable(sc);
1077 destroy_dev(sc->cdev);
1081 rc = bus_generic_detach(dev);
1084 "failed to detach child devices: %d\n", rc);
1088 for (i = 0; i < sc->intr_count; i++)
1089 t4_free_irq(sc, &sc->irq[i]);
1091 for (i = 0; i < MAX_NPORTS; i++) {
1094 t4_free_vi(sc, sc->mbox, sc->pf, 0, pi->vi[0].viid);
1096 device_delete_child(dev, pi->dev);
1098 mtx_destroy(&pi->pi_lock);
1099 free(pi->vi, M_CXGBE);
1104 if (sc->flags & FULL_INIT_DONE)
1105 adapter_full_uninit(sc);
1107 if (sc->flags & FW_OK)
1108 t4_fw_bye(sc, sc->mbox);
1110 if (sc->intr_type == INTR_MSI || sc->intr_type == INTR_MSIX)
1111 pci_release_msi(dev);
1114 bus_release_resource(dev, SYS_RES_MEMORY, sc->regs_rid,
1118 bus_release_resource(dev, SYS_RES_MEMORY, sc->udbs_rid,
1122 bus_release_resource(dev, SYS_RES_MEMORY, sc->msix_rid,
1126 t4_free_l2t(sc->l2t);
1129 free(sc->sge.ofld_rxq, M_CXGBE);
1130 free(sc->sge.ofld_txq, M_CXGBE);
1133 free(sc->sge.nm_rxq, M_CXGBE);
1134 free(sc->sge.nm_txq, M_CXGBE);
1136 free(sc->irq, M_CXGBE);
1137 free(sc->sge.rxq, M_CXGBE);
1138 free(sc->sge.txq, M_CXGBE);
1139 free(sc->sge.ctrlq, M_CXGBE);
1140 free(sc->sge.iqmap, M_CXGBE);
1141 free(sc->sge.eqmap, M_CXGBE);
1142 free(sc->tids.ftid_tab, M_CXGBE);
1143 t4_destroy_dma_tag(sc);
1144 if (mtx_initialized(&sc->sc_lock)) {
1145 sx_xlock(&t4_list_lock);
1146 SLIST_REMOVE(&t4_list, sc, adapter, link);
1147 sx_xunlock(&t4_list_lock);
1148 mtx_destroy(&sc->sc_lock);
1151 callout_drain(&sc->sfl_callout);
1152 if (mtx_initialized(&sc->tids.ftid_lock))
1153 mtx_destroy(&sc->tids.ftid_lock);
1154 if (mtx_initialized(&sc->sfl_lock))
1155 mtx_destroy(&sc->sfl_lock);
1156 if (mtx_initialized(&sc->ifp_lock))
1157 mtx_destroy(&sc->ifp_lock);
1158 if (mtx_initialized(&sc->regwin_lock))
1159 mtx_destroy(&sc->regwin_lock);
1161 bzero(sc, sizeof(*sc));
1167 cxgbe_probe(device_t dev)
1170 struct port_info *pi = device_get_softc(dev);
1172 snprintf(buf, sizeof(buf), "port %d", pi->port_id);
1173 device_set_desc_copy(dev, buf);
1175 return (BUS_PROBE_DEFAULT);
1178 #define T4_CAP (IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_HWCSUM | \
1179 IFCAP_VLAN_HWCSUM | IFCAP_TSO | IFCAP_JUMBO_MTU | IFCAP_LRO | \
1180 IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWCSUM_IPV6 | IFCAP_HWSTATS)
1181 #define T4_CAP_ENABLE (T4_CAP)
1184 cxgbe_vi_attach(device_t dev, struct vi_info *vi)
1189 vi->xact_addr_filt = -1;
1190 callout_init(&vi->tick, 1);
1192 /* Allocate an ifnet and set it up */
1193 ifp = if_alloc(IFT_ETHER);
1195 device_printf(dev, "Cannot allocate ifnet\n");
1201 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1202 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1204 ifp->if_init = cxgbe_init;
1205 ifp->if_ioctl = cxgbe_ioctl;
1206 ifp->if_transmit = cxgbe_transmit;
1207 ifp->if_qflush = cxgbe_qflush;
1209 ifp->if_capabilities = T4_CAP;
1211 if (vi->nofldrxq != 0)
1212 ifp->if_capabilities |= IFCAP_TOE;
1214 ifp->if_capenable = T4_CAP_ENABLE;
1215 ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_IP | CSUM_TSO |
1216 CSUM_UDP_IPV6 | CSUM_TCP_IPV6;
1218 ifp->if_hw_tsomax = 65536 - (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
1219 ifp->if_hw_tsomaxsegcount = TX_SGL_SEGS;
1220 ifp->if_hw_tsomaxsegsize = 65536;
1222 /* Initialize ifmedia for this VI */
1223 ifmedia_init(&vi->media, IFM_IMASK, cxgbe_media_change,
1224 cxgbe_media_status);
1225 build_medialist(vi->pi, &vi->media);
1227 vi->vlan_c = EVENTHANDLER_REGISTER(vlan_config, cxgbe_vlan_config, ifp,
1228 EVENTHANDLER_PRI_ANY);
1230 ether_ifattach(ifp, vi->hw_addr);
1232 if (vi->nnmrxq != 0)
1233 cxgbe_nm_attach(vi);
1235 sb = sbuf_new_auto();
1236 sbuf_printf(sb, "%d txq, %d rxq (NIC)", vi->ntxq, vi->nrxq);
1238 if (ifp->if_capabilities & IFCAP_TOE)
1239 sbuf_printf(sb, "; %d txq, %d rxq (TOE)",
1240 vi->nofldtxq, vi->nofldrxq);
1243 if (ifp->if_capabilities & IFCAP_NETMAP)
1244 sbuf_printf(sb, "; %d txq, %d rxq (netmap)",
1245 vi->nnmtxq, vi->nnmrxq);
1248 device_printf(dev, "%s\n", sbuf_data(sb));
1257 cxgbe_attach(device_t dev)
1259 struct port_info *pi = device_get_softc(dev);
1263 callout_init_mtx(&pi->tick, &pi->pi_lock, 0);
1265 rc = cxgbe_vi_attach(dev, &pi->vi[0]);
1269 for_each_vi(pi, i, vi) {
1272 vi->dev = device_add_child(dev, is_t4(pi->adapter) ?
1273 "vcxgbe" : "vcxl", -1);
1274 if (vi->dev == NULL) {
1275 device_printf(dev, "failed to add VI %d\n", i);
1278 device_set_softc(vi->dev, vi);
1283 bus_generic_attach(dev);
1289 cxgbe_vi_detach(struct vi_info *vi)
1291 struct ifnet *ifp = vi->ifp;
1293 ether_ifdetach(ifp);
1296 EVENTHANDLER_DEREGISTER(vlan_config, vi->vlan_c);
1298 /* Let detach proceed even if these fail. */
1300 if (ifp->if_capabilities & IFCAP_NETMAP)
1301 cxgbe_nm_detach(vi);
1303 cxgbe_uninit_synchronized(vi);
1304 callout_drain(&vi->tick);
1307 ifmedia_removeall(&vi->media);
1313 cxgbe_detach(device_t dev)
1315 struct port_info *pi = device_get_softc(dev);
1316 struct adapter *sc = pi->adapter;
1319 /* Detach the extra VIs first. */
1320 rc = bus_generic_detach(dev);
1323 device_delete_children(dev);
1325 doom_vi(sc, &pi->vi[0]);
1327 if (pi->flags & HAS_TRACEQ) {
1328 sc->traceq = -1; /* cloner should not create ifnet */
1329 t4_tracer_port_detach(sc);
1332 cxgbe_vi_detach(&pi->vi[0]);
1333 callout_drain(&pi->tick);
1335 end_synchronized_op(sc, 0);
1341 cxgbe_init(void *arg)
1343 struct vi_info *vi = arg;
1344 struct adapter *sc = vi->pi->adapter;
1346 if (begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4init") != 0)
1348 cxgbe_init_synchronized(vi);
1349 end_synchronized_op(sc, 0);
1353 cxgbe_ioctl(struct ifnet *ifp, unsigned long cmd, caddr_t data)
1355 int rc = 0, mtu, flags, can_sleep;
1356 struct vi_info *vi = ifp->if_softc;
1357 struct adapter *sc = vi->pi->adapter;
1358 struct ifreq *ifr = (struct ifreq *)data;
1364 if ((mtu < ETHERMIN) || (mtu > ETHERMTU_JUMBO))
1367 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4mtu");
1371 if (vi->flags & VI_INIT_DONE) {
1372 t4_update_fl_bufsize(ifp);
1373 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1374 rc = update_mac_settings(ifp, XGMAC_MTU);
1376 end_synchronized_op(sc, 0);
1382 rc = begin_synchronized_op(sc, vi,
1383 can_sleep ? (SLEEP_OK | INTR_OK) : HOLD_LOCK, "t4flg");
1387 if (ifp->if_flags & IFF_UP) {
1388 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1389 flags = vi->if_flags;
1390 if ((ifp->if_flags ^ flags) &
1391 (IFF_PROMISC | IFF_ALLMULTI)) {
1392 if (can_sleep == 1) {
1393 end_synchronized_op(sc, 0);
1397 rc = update_mac_settings(ifp,
1398 XGMAC_PROMISC | XGMAC_ALLMULTI);
1401 if (can_sleep == 0) {
1402 end_synchronized_op(sc, LOCK_HELD);
1406 rc = cxgbe_init_synchronized(vi);
1408 vi->if_flags = ifp->if_flags;
1409 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1410 if (can_sleep == 0) {
1411 end_synchronized_op(sc, LOCK_HELD);
1415 rc = cxgbe_uninit_synchronized(vi);
1417 end_synchronized_op(sc, can_sleep ? 0 : LOCK_HELD);
1421 case SIOCDELMULTI: /* these two are called with a mutex held :-( */
1422 rc = begin_synchronized_op(sc, vi, HOLD_LOCK, "t4multi");
1425 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1426 rc = update_mac_settings(ifp, XGMAC_MCADDRS);
1427 end_synchronized_op(sc, LOCK_HELD);
1431 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4cap");
1435 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1436 if (mask & IFCAP_TXCSUM) {
1437 ifp->if_capenable ^= IFCAP_TXCSUM;
1438 ifp->if_hwassist ^= (CSUM_TCP | CSUM_UDP | CSUM_IP);
1440 if (IFCAP_TSO4 & ifp->if_capenable &&
1441 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1442 ifp->if_capenable &= ~IFCAP_TSO4;
1444 "tso4 disabled due to -txcsum.\n");
1447 if (mask & IFCAP_TXCSUM_IPV6) {
1448 ifp->if_capenable ^= IFCAP_TXCSUM_IPV6;
1449 ifp->if_hwassist ^= (CSUM_UDP_IPV6 | CSUM_TCP_IPV6);
1451 if (IFCAP_TSO6 & ifp->if_capenable &&
1452 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1453 ifp->if_capenable &= ~IFCAP_TSO6;
1455 "tso6 disabled due to -txcsum6.\n");
1458 if (mask & IFCAP_RXCSUM)
1459 ifp->if_capenable ^= IFCAP_RXCSUM;
1460 if (mask & IFCAP_RXCSUM_IPV6)
1461 ifp->if_capenable ^= IFCAP_RXCSUM_IPV6;
1464 * Note that we leave CSUM_TSO alone (it is always set). The
1465 * kernel takes both IFCAP_TSOx and CSUM_TSO into account before
1466 * sending a TSO request our way, so it's sufficient to toggle
1469 if (mask & IFCAP_TSO4) {
1470 if (!(IFCAP_TSO4 & ifp->if_capenable) &&
1471 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1472 if_printf(ifp, "enable txcsum first.\n");
1476 ifp->if_capenable ^= IFCAP_TSO4;
1478 if (mask & IFCAP_TSO6) {
1479 if (!(IFCAP_TSO6 & ifp->if_capenable) &&
1480 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1481 if_printf(ifp, "enable txcsum6 first.\n");
1485 ifp->if_capenable ^= IFCAP_TSO6;
1487 if (mask & IFCAP_LRO) {
1488 #if defined(INET) || defined(INET6)
1490 struct sge_rxq *rxq;
1492 ifp->if_capenable ^= IFCAP_LRO;
1493 for_each_rxq(vi, i, rxq) {
1494 if (ifp->if_capenable & IFCAP_LRO)
1495 rxq->iq.flags |= IQ_LRO_ENABLED;
1497 rxq->iq.flags &= ~IQ_LRO_ENABLED;
1502 if (mask & IFCAP_TOE) {
1503 int enable = (ifp->if_capenable ^ mask) & IFCAP_TOE;
1505 rc = toe_capability(vi, enable);
1509 ifp->if_capenable ^= mask;
1512 if (mask & IFCAP_VLAN_HWTAGGING) {
1513 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
1514 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1515 rc = update_mac_settings(ifp, XGMAC_VLANEX);
1517 if (mask & IFCAP_VLAN_MTU) {
1518 ifp->if_capenable ^= IFCAP_VLAN_MTU;
1520 /* Need to find out how to disable auto-mtu-inflation */
1522 if (mask & IFCAP_VLAN_HWTSO)
1523 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
1524 if (mask & IFCAP_VLAN_HWCSUM)
1525 ifp->if_capenable ^= IFCAP_VLAN_HWCSUM;
1527 #ifdef VLAN_CAPABILITIES
1528 VLAN_CAPABILITIES(ifp);
1531 end_synchronized_op(sc, 0);
1536 ifmedia_ioctl(ifp, ifr, &vi->media, cmd);
1540 struct ifi2creq i2c;
1542 rc = copyin(ifr->ifr_data, &i2c, sizeof(i2c));
1545 if (i2c.dev_addr != 0xA0 && i2c.dev_addr != 0xA2) {
1549 if (i2c.len > sizeof(i2c.data)) {
1553 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4i2c");
1556 rc = -t4_i2c_rd(sc, sc->mbox, vi->pi->port_id, i2c.dev_addr,
1557 i2c.offset, i2c.len, &i2c.data[0]);
1558 end_synchronized_op(sc, 0);
1560 rc = copyout(&i2c, ifr->ifr_data, sizeof(i2c));
1565 rc = ether_ioctl(ifp, cmd, data);
1572 cxgbe_transmit(struct ifnet *ifp, struct mbuf *m)
1574 struct vi_info *vi = ifp->if_softc;
1575 struct port_info *pi = vi->pi;
1576 struct adapter *sc = pi->adapter;
1577 struct sge_txq *txq;
1582 MPASS(m->m_nextpkt == NULL); /* not quite ready for this yet */
1584 if (__predict_false(pi->link_cfg.link_ok == 0)) {
1590 if (__predict_false(rc != 0)) {
1591 MPASS(m == NULL); /* was freed already */
1592 atomic_add_int(&pi->tx_parse_error, 1); /* rare, atomic is ok */
1597 txq = &sc->sge.txq[vi->first_txq];
1598 if (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE)
1599 txq += ((m->m_pkthdr.flowid % (vi->ntxq - vi->rsrv_noflowq)) +
1603 rc = mp_ring_enqueue(txq->r, items, 1, 4096);
1604 if (__predict_false(rc != 0))
1611 cxgbe_qflush(struct ifnet *ifp)
1613 struct vi_info *vi = ifp->if_softc;
1614 struct sge_txq *txq;
1617 /* queues do not exist if !VI_INIT_DONE. */
1618 if (vi->flags & VI_INIT_DONE) {
1619 for_each_txq(vi, i, txq) {
1621 txq->eq.flags &= ~EQ_ENABLED;
1623 while (!mp_ring_is_idle(txq->r)) {
1624 mp_ring_check_drainage(txq->r, 0);
1633 cxgbe_media_change(struct ifnet *ifp)
1635 struct vi_info *vi = ifp->if_softc;
1637 device_printf(vi->dev, "%s unimplemented.\n", __func__);
1639 return (EOPNOTSUPP);
1643 cxgbe_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
1645 struct vi_info *vi = ifp->if_softc;
1646 struct port_info *pi = vi->pi;
1647 struct ifmedia_entry *cur;
1648 int speed = pi->link_cfg.speed;
1650 cur = vi->media.ifm_cur;
1652 ifmr->ifm_status = IFM_AVALID;
1653 if (!pi->link_cfg.link_ok)
1656 ifmr->ifm_status |= IFM_ACTIVE;
1658 /* active and current will differ iff current media is autoselect. */
1659 if (IFM_SUBTYPE(cur->ifm_media) != IFM_AUTO)
1662 ifmr->ifm_active = IFM_ETHER | IFM_FDX;
1663 if (speed == SPEED_10000)
1664 ifmr->ifm_active |= IFM_10G_T;
1665 else if (speed == SPEED_1000)
1666 ifmr->ifm_active |= IFM_1000_T;
1667 else if (speed == SPEED_100)
1668 ifmr->ifm_active |= IFM_100_TX;
1669 else if (speed == SPEED_10)
1670 ifmr->ifm_active |= IFM_10_T;
1672 KASSERT(0, ("%s: link up but speed unknown (%u)", __func__,
1677 vcxgbe_probe(device_t dev)
1680 struct vi_info *vi = device_get_softc(dev);
1682 snprintf(buf, sizeof(buf), "port %d vi %td", vi->pi->port_id,
1684 device_set_desc_copy(dev, buf);
1686 return (BUS_PROBE_DEFAULT);
1690 vcxgbe_attach(device_t dev)
1693 struct port_info *pi;
1695 int func, index, rc;
1698 vi = device_get_softc(dev);
1702 index = vi - pi->vi;
1703 KASSERT(index < nitems(vi_mac_funcs),
1704 ("%s: VI %s doesn't have a MAC func", __func__,
1705 device_get_nameunit(dev)));
1706 func = vi_mac_funcs[index];
1707 rc = t4_alloc_vi_func(sc, sc->mbox, pi->tx_chan, sc->pf, 0, 1,
1708 vi->hw_addr, &vi->rss_size, func, 0);
1710 device_printf(dev, "Failed to allocate virtual interface "
1711 "for port %d: %d\n", pi->port_id, -rc);
1716 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
1717 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_RSSINFO) |
1718 V_FW_PARAMS_PARAM_YZ(vi->viid);
1719 rc = t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
1721 vi->rss_base = 0xffff;
1723 /* MPASS((val >> 16) == rss_size); */
1724 vi->rss_base = val & 0xffff;
1727 rc = cxgbe_vi_attach(dev, vi);
1729 t4_free_vi(sc, sc->mbox, sc->pf, 0, vi->viid);
1736 vcxgbe_detach(device_t dev)
1741 vi = device_get_softc(dev);
1742 sc = vi->pi->adapter;
1746 cxgbe_vi_detach(vi);
1747 t4_free_vi(sc, sc->mbox, sc->pf, 0, vi->viid);
1749 end_synchronized_op(sc, 0);
1755 t4_fatal_err(struct adapter *sc)
1757 t4_set_reg_field(sc, A_SGE_CONTROL, F_GLOBALENABLE, 0);
1758 t4_intr_disable(sc);
1759 log(LOG_EMERG, "%s: encountered fatal error, adapter stopped.\n",
1760 device_get_nameunit(sc->dev));
1764 map_bars_0_and_4(struct adapter *sc)
1766 sc->regs_rid = PCIR_BAR(0);
1767 sc->regs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
1768 &sc->regs_rid, RF_ACTIVE);
1769 if (sc->regs_res == NULL) {
1770 device_printf(sc->dev, "cannot map registers.\n");
1773 sc->bt = rman_get_bustag(sc->regs_res);
1774 sc->bh = rman_get_bushandle(sc->regs_res);
1775 sc->mmio_len = rman_get_size(sc->regs_res);
1776 setbit(&sc->doorbells, DOORBELL_KDB);
1778 sc->msix_rid = PCIR_BAR(4);
1779 sc->msix_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
1780 &sc->msix_rid, RF_ACTIVE);
1781 if (sc->msix_res == NULL) {
1782 device_printf(sc->dev, "cannot map MSI-X BAR.\n");
1790 map_bar_2(struct adapter *sc)
1794 * T4: only iWARP driver uses the userspace doorbells. There is no need
1795 * to map it if RDMA is disabled.
1797 if (is_t4(sc) && sc->rdmacaps == 0)
1800 sc->udbs_rid = PCIR_BAR(2);
1801 sc->udbs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
1802 &sc->udbs_rid, RF_ACTIVE);
1803 if (sc->udbs_res == NULL) {
1804 device_printf(sc->dev, "cannot map doorbell BAR.\n");
1807 sc->udbs_base = rman_get_virtual(sc->udbs_res);
1810 setbit(&sc->doorbells, DOORBELL_UDB);
1811 #if defined(__i386__) || defined(__amd64__)
1812 if (t5_write_combine) {
1816 * Enable write combining on BAR2. This is the
1817 * userspace doorbell BAR and is split into 128B
1818 * (UDBS_SEG_SIZE) doorbell regions, each associated
1819 * with an egress queue. The first 64B has the doorbell
1820 * and the second 64B can be used to submit a tx work
1821 * request with an implicit doorbell.
1824 rc = pmap_change_attr((vm_offset_t)sc->udbs_base,
1825 rman_get_size(sc->udbs_res), PAT_WRITE_COMBINING);
1827 clrbit(&sc->doorbells, DOORBELL_UDB);
1828 setbit(&sc->doorbells, DOORBELL_WCWR);
1829 setbit(&sc->doorbells, DOORBELL_UDBWC);
1831 device_printf(sc->dev,
1832 "couldn't enable write combining: %d\n",
1836 t4_write_reg(sc, A_SGE_STAT_CFG,
1837 V_STATSOURCE_T5(7) | V_STATMODE(0));
1845 static const struct memwin t4_memwin[] = {
1846 { MEMWIN0_BASE, MEMWIN0_APERTURE },
1847 { MEMWIN1_BASE, MEMWIN1_APERTURE },
1848 { MEMWIN2_BASE_T4, MEMWIN2_APERTURE_T4 }
1851 static const struct memwin t5_memwin[] = {
1852 { MEMWIN0_BASE, MEMWIN0_APERTURE },
1853 { MEMWIN1_BASE, MEMWIN1_APERTURE },
1854 { MEMWIN2_BASE_T5, MEMWIN2_APERTURE_T5 },
1858 setup_memwin(struct adapter *sc)
1860 const struct memwin *mw;
1866 * Read low 32b of bar0 indirectly via the hardware backdoor
1867 * mechanism. Works from within PCI passthrough environments
1868 * too, where rman_get_start() can return a different value. We
1869 * need to program the T4 memory window decoders with the actual
1870 * addresses that will be coming across the PCIe link.
1872 bar0 = t4_hw_pci_read_cfg4(sc, PCIR_BAR(0));
1873 bar0 &= (uint32_t) PCIM_BAR_MEM_BASE;
1876 n = nitems(t4_memwin);
1878 /* T5 uses the relative offset inside the PCIe BAR */
1882 n = nitems(t5_memwin);
1885 for (i = 0; i < n; i++, mw++) {
1887 PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, i),
1888 (mw->base + bar0) | V_BIR(0) |
1889 V_WINDOW(ilog2(mw->aperture) - 10));
1893 t4_read_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 2));
1897 * Verify that the memory range specified by the addr/len pair is valid and lies
1898 * entirely within a single region (EDCx or MCx).
1901 validate_mem_range(struct adapter *sc, uint32_t addr, int len)
1903 uint32_t em, addr_len, maddr, mlen;
1905 /* Memory can only be accessed in naturally aligned 4 byte units */
1906 if (addr & 3 || len & 3 || len == 0)
1909 /* Enabled memories */
1910 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
1911 if (em & F_EDRAM0_ENABLE) {
1912 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
1913 maddr = G_EDRAM0_BASE(addr_len) << 20;
1914 mlen = G_EDRAM0_SIZE(addr_len) << 20;
1915 if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1916 addr + len <= maddr + mlen)
1919 if (em & F_EDRAM1_ENABLE) {
1920 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
1921 maddr = G_EDRAM1_BASE(addr_len) << 20;
1922 mlen = G_EDRAM1_SIZE(addr_len) << 20;
1923 if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1924 addr + len <= maddr + mlen)
1927 if (em & F_EXT_MEM_ENABLE) {
1928 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
1929 maddr = G_EXT_MEM_BASE(addr_len) << 20;
1930 mlen = G_EXT_MEM_SIZE(addr_len) << 20;
1931 if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1932 addr + len <= maddr + mlen)
1935 if (!is_t4(sc) && em & F_EXT_MEM1_ENABLE) {
1936 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
1937 maddr = G_EXT_MEM1_BASE(addr_len) << 20;
1938 mlen = G_EXT_MEM1_SIZE(addr_len) << 20;
1939 if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1940 addr + len <= maddr + mlen)
1948 fwmtype_to_hwmtype(int mtype)
1952 case FW_MEMTYPE_EDC0:
1954 case FW_MEMTYPE_EDC1:
1956 case FW_MEMTYPE_EXTMEM:
1958 case FW_MEMTYPE_EXTMEM1:
1961 panic("%s: cannot translate fw mtype %d.", __func__, mtype);
1966 * Verify that the memory range specified by the memtype/offset/len pair is
1967 * valid and lies entirely within the memtype specified. The global address of
1968 * the start of the range is returned in addr.
1971 validate_mt_off_len(struct adapter *sc, int mtype, uint32_t off, int len,
1974 uint32_t em, addr_len, maddr, mlen;
1976 /* Memory can only be accessed in naturally aligned 4 byte units */
1977 if (off & 3 || len & 3 || len == 0)
1980 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
1981 switch (fwmtype_to_hwmtype(mtype)) {
1983 if (!(em & F_EDRAM0_ENABLE))
1985 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
1986 maddr = G_EDRAM0_BASE(addr_len) << 20;
1987 mlen = G_EDRAM0_SIZE(addr_len) << 20;
1990 if (!(em & F_EDRAM1_ENABLE))
1992 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
1993 maddr = G_EDRAM1_BASE(addr_len) << 20;
1994 mlen = G_EDRAM1_SIZE(addr_len) << 20;
1997 if (!(em & F_EXT_MEM_ENABLE))
1999 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
2000 maddr = G_EXT_MEM_BASE(addr_len) << 20;
2001 mlen = G_EXT_MEM_SIZE(addr_len) << 20;
2004 if (is_t4(sc) || !(em & F_EXT_MEM1_ENABLE))
2006 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
2007 maddr = G_EXT_MEM1_BASE(addr_len) << 20;
2008 mlen = G_EXT_MEM1_SIZE(addr_len) << 20;
2014 if (mlen > 0 && off < mlen && off + len <= mlen) {
2015 *addr = maddr + off; /* global address */
2023 memwin_info(struct adapter *sc, int win, uint32_t *base, uint32_t *aperture)
2025 const struct memwin *mw;
2028 KASSERT(win >= 0 && win < nitems(t4_memwin),
2029 ("%s: incorrect memwin# (%d)", __func__, win));
2030 mw = &t4_memwin[win];
2032 KASSERT(win >= 0 && win < nitems(t5_memwin),
2033 ("%s: incorrect memwin# (%d)", __func__, win));
2034 mw = &t5_memwin[win];
2039 if (aperture != NULL)
2040 *aperture = mw->aperture;
2044 * Positions the memory window such that it can be used to access the specified
2045 * address in the chip's address space. The return value is the offset of addr
2046 * from the start of the window.
2049 position_memwin(struct adapter *sc, int n, uint32_t addr)
2054 KASSERT(n >= 0 && n <= 3,
2055 ("%s: invalid window %d.", __func__, n));
2056 KASSERT((addr & 3) == 0,
2057 ("%s: addr (0x%x) is not at a 4B boundary.", __func__, addr));
2061 start = addr & ~0xf; /* start must be 16B aligned */
2063 pf = V_PFNUM(sc->pf);
2064 start = addr & ~0x7f; /* start must be 128B aligned */
2066 reg = PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, n);
2068 t4_write_reg(sc, reg, start | pf);
2069 t4_read_reg(sc, reg);
2071 return (addr - start);
2075 cfg_itype_and_nqueues(struct adapter *sc, int n10g, int n1g, int num_vis,
2076 struct intrs_and_queues *iaq)
2078 int rc, itype, navail, nrxq10g, nrxq1g, n;
2079 int nofldrxq10g = 0, nofldrxq1g = 0;
2081 bzero(iaq, sizeof(*iaq));
2083 iaq->ntxq10g = t4_ntxq10g;
2084 iaq->ntxq1g = t4_ntxq1g;
2085 iaq->ntxq_vi = t4_ntxq_vi;
2086 iaq->nrxq10g = nrxq10g = t4_nrxq10g;
2087 iaq->nrxq1g = nrxq1g = t4_nrxq1g;
2088 iaq->nrxq_vi = t4_nrxq_vi;
2089 iaq->rsrv_noflowq = t4_rsrv_noflowq;
2091 if (is_offload(sc)) {
2092 iaq->nofldtxq10g = t4_nofldtxq10g;
2093 iaq->nofldtxq1g = t4_nofldtxq1g;
2094 iaq->nofldtxq_vi = t4_nofldtxq_vi;
2095 iaq->nofldrxq10g = nofldrxq10g = t4_nofldrxq10g;
2096 iaq->nofldrxq1g = nofldrxq1g = t4_nofldrxq1g;
2097 iaq->nofldrxq_vi = t4_nofldrxq_vi;
2101 iaq->nnmtxq_vi = t4_nnmtxq_vi;
2102 iaq->nnmrxq_vi = t4_nnmrxq_vi;
2105 for (itype = INTR_MSIX; itype; itype >>= 1) {
2107 if ((itype & t4_intr_types) == 0)
2108 continue; /* not allowed */
2110 if (itype == INTR_MSIX)
2111 navail = pci_msix_count(sc->dev);
2112 else if (itype == INTR_MSI)
2113 navail = pci_msi_count(sc->dev);
2120 iaq->intr_type = itype;
2121 iaq->intr_flags_10g = 0;
2122 iaq->intr_flags_1g = 0;
2125 * Best option: an interrupt vector for errors, one for the
2126 * firmware event queue, and one for every rxq (NIC and TOE) of
2127 * every VI. The VIs that support netmap use the same
2128 * interrupts for the NIC rx queues and the netmap rx queues
2129 * because only one set of queues is active at a time.
2131 iaq->nirq = T4_EXTRA_INTR;
2132 iaq->nirq += n10g * (nrxq10g + nofldrxq10g);
2133 iaq->nirq += n1g * (nrxq1g + nofldrxq1g);
2134 iaq->nirq += (n10g + n1g) * (num_vis - 1) *
2135 max(iaq->nrxq_vi, iaq->nnmrxq_vi); /* See comment above. */
2136 iaq->nirq += (n10g + n1g) * (num_vis - 1) * iaq->nofldrxq_vi;
2137 if (iaq->nirq <= navail &&
2138 (itype != INTR_MSI || powerof2(iaq->nirq))) {
2139 iaq->intr_flags_10g = INTR_ALL;
2140 iaq->intr_flags_1g = INTR_ALL;
2144 /* Disable the VIs (and netmap) if there aren't enough intrs */
2146 device_printf(sc->dev, "virtual interfaces disabled "
2147 "because num_vis=%u with current settings "
2148 "(nrxq10g=%u, nrxq1g=%u, nofldrxq10g=%u, "
2149 "nofldrxq1g=%u, nrxq_vi=%u nofldrxq_vi=%u, "
2150 "nnmrxq_vi=%u) would need %u interrupts but "
2151 "only %u are available.\n", num_vis, nrxq10g,
2152 nrxq1g, nofldrxq10g, nofldrxq1g, iaq->nrxq_vi,
2153 iaq->nofldrxq_vi, iaq->nnmrxq_vi, iaq->nirq,
2156 iaq->ntxq_vi = iaq->nrxq_vi = 0;
2157 iaq->nofldtxq_vi = iaq->nofldrxq_vi = 0;
2158 iaq->nnmtxq_vi = iaq->nnmrxq_vi = 0;
2163 * Second best option: a vector for errors, one for the firmware
2164 * event queue, and vectors for either all the NIC rx queues or
2165 * all the TOE rx queues. The queues that don't get vectors
2166 * will forward their interrupts to those that do.
2168 iaq->nirq = T4_EXTRA_INTR;
2169 if (nrxq10g >= nofldrxq10g) {
2170 iaq->intr_flags_10g = INTR_RXQ;
2171 iaq->nirq += n10g * nrxq10g;
2173 iaq->intr_flags_10g = INTR_OFLD_RXQ;
2174 iaq->nirq += n10g * nofldrxq10g;
2176 if (nrxq1g >= nofldrxq1g) {
2177 iaq->intr_flags_1g = INTR_RXQ;
2178 iaq->nirq += n1g * nrxq1g;
2180 iaq->intr_flags_1g = INTR_OFLD_RXQ;
2181 iaq->nirq += n1g * nofldrxq1g;
2183 if (iaq->nirq <= navail &&
2184 (itype != INTR_MSI || powerof2(iaq->nirq)))
2188 * Next best option: an interrupt vector for errors, one for the
2189 * firmware event queue, and at least one per main-VI. At this
2190 * point we know we'll have to downsize nrxq and/or nofldrxq to
2191 * fit what's available to us.
2193 iaq->nirq = T4_EXTRA_INTR;
2194 iaq->nirq += n10g + n1g;
2195 if (iaq->nirq <= navail) {
2196 int leftover = navail - iaq->nirq;
2199 int target = max(nrxq10g, nofldrxq10g);
2201 iaq->intr_flags_10g = nrxq10g >= nofldrxq10g ?
2202 INTR_RXQ : INTR_OFLD_RXQ;
2205 while (n < target && leftover >= n10g) {
2210 iaq->nrxq10g = min(n, nrxq10g);
2212 iaq->nofldrxq10g = min(n, nofldrxq10g);
2217 int target = max(nrxq1g, nofldrxq1g);
2219 iaq->intr_flags_1g = nrxq1g >= nofldrxq1g ?
2220 INTR_RXQ : INTR_OFLD_RXQ;
2223 while (n < target && leftover >= n1g) {
2228 iaq->nrxq1g = min(n, nrxq1g);
2230 iaq->nofldrxq1g = min(n, nofldrxq1g);
2234 if (itype != INTR_MSI || powerof2(iaq->nirq))
2239 * Least desirable option: one interrupt vector for everything.
2241 iaq->nirq = iaq->nrxq10g = iaq->nrxq1g = 1;
2242 iaq->intr_flags_10g = iaq->intr_flags_1g = 0;
2245 iaq->nofldrxq10g = iaq->nofldrxq1g = 1;
2250 if (itype == INTR_MSIX)
2251 rc = pci_alloc_msix(sc->dev, &navail);
2252 else if (itype == INTR_MSI)
2253 rc = pci_alloc_msi(sc->dev, &navail);
2256 if (navail == iaq->nirq)
2260 * Didn't get the number requested. Use whatever number
2261 * the kernel is willing to allocate (it's in navail).
2263 device_printf(sc->dev, "fewer vectors than requested, "
2264 "type=%d, req=%d, rcvd=%d; will downshift req.\n",
2265 itype, iaq->nirq, navail);
2266 pci_release_msi(sc->dev);
2270 device_printf(sc->dev,
2271 "failed to allocate vectors:%d, type=%d, req=%d, rcvd=%d\n",
2272 itype, rc, iaq->nirq, navail);
2275 device_printf(sc->dev,
2276 "failed to find a usable interrupt type. "
2277 "allowed=%d, msi-x=%d, msi=%d, intx=1", t4_intr_types,
2278 pci_msix_count(sc->dev), pci_msi_count(sc->dev));
2283 #define FW_VERSION(chip) ( \
2284 V_FW_HDR_FW_VER_MAJOR(chip##FW_VERSION_MAJOR) | \
2285 V_FW_HDR_FW_VER_MINOR(chip##FW_VERSION_MINOR) | \
2286 V_FW_HDR_FW_VER_MICRO(chip##FW_VERSION_MICRO) | \
2287 V_FW_HDR_FW_VER_BUILD(chip##FW_VERSION_BUILD))
2288 #define FW_INTFVER(chip, intf) (chip##FW_HDR_INTFVER_##intf)
2294 struct fw_hdr fw_hdr; /* XXX: waste of space, need a sparse struct */
2298 .kld_name = "t4fw_cfg",
2299 .fw_mod_name = "t4fw",
2301 .chip = FW_HDR_CHIP_T4,
2302 .fw_ver = htobe32_const(FW_VERSION(T4)),
2303 .intfver_nic = FW_INTFVER(T4, NIC),
2304 .intfver_vnic = FW_INTFVER(T4, VNIC),
2305 .intfver_ofld = FW_INTFVER(T4, OFLD),
2306 .intfver_ri = FW_INTFVER(T4, RI),
2307 .intfver_iscsipdu = FW_INTFVER(T4, ISCSIPDU),
2308 .intfver_iscsi = FW_INTFVER(T4, ISCSI),
2309 .intfver_fcoepdu = FW_INTFVER(T4, FCOEPDU),
2310 .intfver_fcoe = FW_INTFVER(T4, FCOE),
2314 .kld_name = "t5fw_cfg",
2315 .fw_mod_name = "t5fw",
2317 .chip = FW_HDR_CHIP_T5,
2318 .fw_ver = htobe32_const(FW_VERSION(T5)),
2319 .intfver_nic = FW_INTFVER(T5, NIC),
2320 .intfver_vnic = FW_INTFVER(T5, VNIC),
2321 .intfver_ofld = FW_INTFVER(T5, OFLD),
2322 .intfver_ri = FW_INTFVER(T5, RI),
2323 .intfver_iscsipdu = FW_INTFVER(T5, ISCSIPDU),
2324 .intfver_iscsi = FW_INTFVER(T5, ISCSI),
2325 .intfver_fcoepdu = FW_INTFVER(T5, FCOEPDU),
2326 .intfver_fcoe = FW_INTFVER(T5, FCOE),
2331 static struct fw_info *
2332 find_fw_info(int chip)
2336 for (i = 0; i < nitems(fw_info); i++) {
2337 if (fw_info[i].chip == chip)
2338 return (&fw_info[i]);
2344 * Is the given firmware API compatible with the one the driver was compiled
2348 fw_compatible(const struct fw_hdr *hdr1, const struct fw_hdr *hdr2)
2351 /* short circuit if it's the exact same firmware version */
2352 if (hdr1->chip == hdr2->chip && hdr1->fw_ver == hdr2->fw_ver)
2356 * XXX: Is this too conservative? Perhaps I should limit this to the
2357 * features that are supported in the driver.
2359 #define SAME_INTF(x) (hdr1->intfver_##x == hdr2->intfver_##x)
2360 if (hdr1->chip == hdr2->chip && SAME_INTF(nic) && SAME_INTF(vnic) &&
2361 SAME_INTF(ofld) && SAME_INTF(ri) && SAME_INTF(iscsipdu) &&
2362 SAME_INTF(iscsi) && SAME_INTF(fcoepdu) && SAME_INTF(fcoe))
2370 * The firmware in the KLD is usable, but should it be installed? This routine
2371 * explains itself in detail if it indicates the KLD firmware should be
2375 should_install_kld_fw(struct adapter *sc, int card_fw_usable, int k, int c)
2379 if (!card_fw_usable) {
2380 reason = "incompatible or unusable";
2385 reason = "older than the version bundled with this driver";
2389 if (t4_fw_install == 2 && k != c) {
2390 reason = "different than the version bundled with this driver";
2397 if (t4_fw_install == 0) {
2398 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
2399 "but the driver is prohibited from installing a different "
2400 "firmware on the card.\n",
2401 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
2402 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason);
2407 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
2408 "installing firmware %u.%u.%u.%u on card.\n",
2409 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
2410 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason,
2411 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
2412 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
2417 * Establish contact with the firmware and determine if we are the master driver
2418 * or not, and whether we are responsible for chip initialization.
2421 prep_firmware(struct adapter *sc)
2423 const struct firmware *fw = NULL, *default_cfg;
2424 int rc, pf, card_fw_usable, kld_fw_usable, need_fw_reset = 1;
2425 enum dev_state state;
2426 struct fw_info *fw_info;
2427 struct fw_hdr *card_fw; /* fw on the card */
2428 const struct fw_hdr *kld_fw; /* fw in the KLD */
2429 const struct fw_hdr *drv_fw; /* fw header the driver was compiled
2432 /* Contact firmware. */
2433 rc = t4_fw_hello(sc, sc->mbox, sc->mbox, MASTER_MAY, &state);
2434 if (rc < 0 || state == DEV_STATE_ERR) {
2436 device_printf(sc->dev,
2437 "failed to connect to the firmware: %d, %d.\n", rc, state);
2442 sc->flags |= MASTER_PF;
2443 else if (state == DEV_STATE_UNINIT) {
2445 * We didn't get to be the master so we definitely won't be
2446 * configuring the chip. It's a bug if someone else hasn't
2447 * configured it already.
2449 device_printf(sc->dev, "couldn't be master(%d), "
2450 "device not already initialized either(%d).\n", rc, state);
2454 /* This is the firmware whose headers the driver was compiled against */
2455 fw_info = find_fw_info(chip_id(sc));
2456 if (fw_info == NULL) {
2457 device_printf(sc->dev,
2458 "unable to look up firmware information for chip %d.\n",
2462 drv_fw = &fw_info->fw_hdr;
2465 * The firmware KLD contains many modules. The KLD name is also the
2466 * name of the module that contains the default config file.
2468 default_cfg = firmware_get(fw_info->kld_name);
2470 /* Read the header of the firmware on the card */
2471 card_fw = malloc(sizeof(*card_fw), M_CXGBE, M_ZERO | M_WAITOK);
2472 rc = -t4_read_flash(sc, FLASH_FW_START,
2473 sizeof (*card_fw) / sizeof (uint32_t), (uint32_t *)card_fw, 1);
2475 card_fw_usable = fw_compatible(drv_fw, (const void*)card_fw);
2477 device_printf(sc->dev,
2478 "Unable to read card's firmware header: %d\n", rc);
2482 /* This is the firmware in the KLD */
2483 fw = firmware_get(fw_info->fw_mod_name);
2485 kld_fw = (const void *)fw->data;
2486 kld_fw_usable = fw_compatible(drv_fw, kld_fw);
2492 if (card_fw_usable && card_fw->fw_ver == drv_fw->fw_ver &&
2493 (!kld_fw_usable || kld_fw->fw_ver == drv_fw->fw_ver)) {
2495 * Common case: the firmware on the card is an exact match and
2496 * the KLD is an exact match too, or the KLD is
2497 * absent/incompatible. Note that t4_fw_install = 2 is ignored
2498 * here -- use cxgbetool loadfw if you want to reinstall the
2499 * same firmware as the one on the card.
2501 } else if (kld_fw_usable && state == DEV_STATE_UNINIT &&
2502 should_install_kld_fw(sc, card_fw_usable, be32toh(kld_fw->fw_ver),
2503 be32toh(card_fw->fw_ver))) {
2505 rc = -t4_fw_upgrade(sc, sc->mbox, fw->data, fw->datasize, 0);
2507 device_printf(sc->dev,
2508 "failed to install firmware: %d\n", rc);
2512 /* Installed successfully, update the cached header too. */
2513 memcpy(card_fw, kld_fw, sizeof(*card_fw));
2515 need_fw_reset = 0; /* already reset as part of load_fw */
2518 if (!card_fw_usable) {
2521 d = ntohl(drv_fw->fw_ver);
2522 c = ntohl(card_fw->fw_ver);
2523 k = kld_fw ? ntohl(kld_fw->fw_ver) : 0;
2525 device_printf(sc->dev, "Cannot find a usable firmware: "
2526 "fw_install %d, chip state %d, "
2527 "driver compiled with %d.%d.%d.%d, "
2528 "card has %d.%d.%d.%d, KLD has %d.%d.%d.%d\n",
2529 t4_fw_install, state,
2530 G_FW_HDR_FW_VER_MAJOR(d), G_FW_HDR_FW_VER_MINOR(d),
2531 G_FW_HDR_FW_VER_MICRO(d), G_FW_HDR_FW_VER_BUILD(d),
2532 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
2533 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c),
2534 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
2535 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
2540 /* We're using whatever's on the card and it's known to be good. */
2541 sc->params.fw_vers = ntohl(card_fw->fw_ver);
2542 snprintf(sc->fw_version, sizeof(sc->fw_version), "%u.%u.%u.%u",
2543 G_FW_HDR_FW_VER_MAJOR(sc->params.fw_vers),
2544 G_FW_HDR_FW_VER_MINOR(sc->params.fw_vers),
2545 G_FW_HDR_FW_VER_MICRO(sc->params.fw_vers),
2546 G_FW_HDR_FW_VER_BUILD(sc->params.fw_vers));
2547 t4_get_tp_version(sc, &sc->params.tp_vers);
2550 if (need_fw_reset &&
2551 (rc = -t4_fw_reset(sc, sc->mbox, F_PIORSTMODE | F_PIORST)) != 0) {
2552 device_printf(sc->dev, "firmware reset failed: %d.\n", rc);
2553 if (rc != ETIMEDOUT && rc != EIO)
2554 t4_fw_bye(sc, sc->mbox);
2559 rc = get_params__pre_init(sc);
2561 goto done; /* error message displayed already */
2563 /* Partition adapter resources as specified in the config file. */
2564 if (state == DEV_STATE_UNINIT) {
2566 KASSERT(sc->flags & MASTER_PF,
2567 ("%s: trying to change chip settings when not master.",
2570 rc = partition_resources(sc, default_cfg, fw_info->kld_name);
2572 goto done; /* error message displayed already */
2574 t4_tweak_chip_settings(sc);
2576 /* get basic stuff going */
2577 rc = -t4_fw_initialize(sc, sc->mbox);
2579 device_printf(sc->dev, "fw init failed: %d.\n", rc);
2583 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "pf%d", pf);
2588 free(card_fw, M_CXGBE);
2590 firmware_put(fw, FIRMWARE_UNLOAD);
2591 if (default_cfg != NULL)
2592 firmware_put(default_cfg, FIRMWARE_UNLOAD);
2597 #define FW_PARAM_DEV(param) \
2598 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
2599 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
2600 #define FW_PARAM_PFVF(param) \
2601 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
2602 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param))
2605 * Partition chip resources for use between various PFs, VFs, etc.
2608 partition_resources(struct adapter *sc, const struct firmware *default_cfg,
2609 const char *name_prefix)
2611 const struct firmware *cfg = NULL;
2613 struct fw_caps_config_cmd caps;
2614 uint32_t mtype, moff, finicsum, cfcsum;
2617 * Figure out what configuration file to use. Pick the default config
2618 * file for the card if the user hasn't specified one explicitly.
2620 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", t4_cfg_file);
2621 if (strncmp(t4_cfg_file, DEFAULT_CF, sizeof(t4_cfg_file)) == 0) {
2622 /* Card specific overrides go here. */
2623 if (pci_get_device(sc->dev) == 0x440a)
2624 snprintf(sc->cfg_file, sizeof(sc->cfg_file), UWIRE_CF);
2626 snprintf(sc->cfg_file, sizeof(sc->cfg_file), FPGA_CF);
2630 * We need to load another module if the profile is anything except
2631 * "default" or "flash".
2633 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) != 0 &&
2634 strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
2637 snprintf(s, sizeof(s), "%s_%s", name_prefix, sc->cfg_file);
2638 cfg = firmware_get(s);
2640 if (default_cfg != NULL) {
2641 device_printf(sc->dev,
2642 "unable to load module \"%s\" for "
2643 "configuration profile \"%s\", will use "
2644 "the default config file instead.\n",
2646 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
2649 device_printf(sc->dev,
2650 "unable to load module \"%s\" for "
2651 "configuration profile \"%s\", will use "
2652 "the config file on the card's flash "
2653 "instead.\n", s, sc->cfg_file);
2654 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
2660 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) == 0 &&
2661 default_cfg == NULL) {
2662 device_printf(sc->dev,
2663 "default config file not available, will use the config "
2664 "file on the card's flash instead.\n");
2665 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", FLASH_CF);
2668 if (strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
2670 const uint32_t *cfdata;
2671 uint32_t param, val, addr, off, mw_base, mw_aperture;
2673 KASSERT(cfg != NULL || default_cfg != NULL,
2674 ("%s: no config to upload", __func__));
2677 * Ask the firmware where it wants us to upload the config file.
2679 param = FW_PARAM_DEV(CF);
2680 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
2682 /* No support for config file? Shouldn't happen. */
2683 device_printf(sc->dev,
2684 "failed to query config file location: %d.\n", rc);
2687 mtype = G_FW_PARAMS_PARAM_Y(val);
2688 moff = G_FW_PARAMS_PARAM_Z(val) << 16;
2691 * XXX: sheer laziness. We deliberately added 4 bytes of
2692 * useless stuffing/comments at the end of the config file so
2693 * it's ok to simply throw away the last remaining bytes when
2694 * the config file is not an exact multiple of 4. This also
2695 * helps with the validate_mt_off_len check.
2698 cflen = cfg->datasize & ~3;
2701 cflen = default_cfg->datasize & ~3;
2702 cfdata = default_cfg->data;
2705 if (cflen > FLASH_CFG_MAX_SIZE) {
2706 device_printf(sc->dev,
2707 "config file too long (%d, max allowed is %d). "
2708 "Will try to use the config on the card, if any.\n",
2709 cflen, FLASH_CFG_MAX_SIZE);
2710 goto use_config_on_flash;
2713 rc = validate_mt_off_len(sc, mtype, moff, cflen, &addr);
2715 device_printf(sc->dev,
2716 "%s: addr (%d/0x%x) or len %d is not valid: %d. "
2717 "Will try to use the config on the card, if any.\n",
2718 __func__, mtype, moff, cflen, rc);
2719 goto use_config_on_flash;
2722 memwin_info(sc, 2, &mw_base, &mw_aperture);
2724 off = position_memwin(sc, 2, addr);
2725 n = min(cflen, mw_aperture - off);
2726 for (i = 0; i < n; i += 4)
2727 t4_write_reg(sc, mw_base + off + i, *cfdata++);
2732 use_config_on_flash:
2733 mtype = FW_MEMTYPE_FLASH;
2734 moff = t4_flash_cfg_addr(sc);
2737 bzero(&caps, sizeof(caps));
2738 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
2739 F_FW_CMD_REQUEST | F_FW_CMD_READ);
2740 caps.cfvalid_to_len16 = htobe32(F_FW_CAPS_CONFIG_CMD_CFVALID |
2741 V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
2742 V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(moff >> 16) | FW_LEN16(caps));
2743 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
2745 device_printf(sc->dev,
2746 "failed to pre-process config file: %d "
2747 "(mtype %d, moff 0x%x).\n", rc, mtype, moff);
2751 finicsum = be32toh(caps.finicsum);
2752 cfcsum = be32toh(caps.cfcsum);
2753 if (finicsum != cfcsum) {
2754 device_printf(sc->dev,
2755 "WARNING: config file checksum mismatch: %08x %08x\n",
2758 sc->cfcsum = cfcsum;
2760 #define LIMIT_CAPS(x) do { \
2761 caps.x &= htobe16(t4_##x##_allowed); \
2765 * Let the firmware know what features will (not) be used so it can tune
2766 * things accordingly.
2768 LIMIT_CAPS(linkcaps);
2769 LIMIT_CAPS(niccaps);
2770 LIMIT_CAPS(toecaps);
2771 LIMIT_CAPS(rdmacaps);
2772 LIMIT_CAPS(iscsicaps);
2773 LIMIT_CAPS(fcoecaps);
2776 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
2777 F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
2778 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
2779 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), NULL);
2781 device_printf(sc->dev,
2782 "failed to process config file: %d.\n", rc);
2786 firmware_put(cfg, FIRMWARE_UNLOAD);
2791 * Retrieve parameters that are needed (or nice to have) very early.
2794 get_params__pre_init(struct adapter *sc)
2797 uint32_t param[2], val[2];
2798 struct fw_devlog_cmd cmd;
2799 struct devlog_params *dlog = &sc->params.devlog;
2801 param[0] = FW_PARAM_DEV(PORTVEC);
2802 param[1] = FW_PARAM_DEV(CCLK);
2803 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
2805 device_printf(sc->dev,
2806 "failed to query parameters (pre_init): %d.\n", rc);
2810 sc->params.portvec = val[0];
2811 sc->params.nports = bitcount32(val[0]);
2812 sc->params.vpd.cclk = val[1];
2814 /* Read device log parameters. */
2815 bzero(&cmd, sizeof(cmd));
2816 cmd.op_to_write = htobe32(V_FW_CMD_OP(FW_DEVLOG_CMD) |
2817 F_FW_CMD_REQUEST | F_FW_CMD_READ);
2818 cmd.retval_len16 = htobe32(FW_LEN16(cmd));
2819 rc = -t4_wr_mbox(sc, sc->mbox, &cmd, sizeof(cmd), &cmd);
2821 device_printf(sc->dev,
2822 "failed to get devlog parameters: %d.\n", rc);
2823 bzero(dlog, sizeof (*dlog));
2824 rc = 0; /* devlog isn't critical for device operation */
2826 val[0] = be32toh(cmd.memtype_devlog_memaddr16_devlog);
2827 dlog->memtype = G_FW_DEVLOG_CMD_MEMTYPE_DEVLOG(val[0]);
2828 dlog->start = G_FW_DEVLOG_CMD_MEMADDR16_DEVLOG(val[0]) << 4;
2829 dlog->size = be32toh(cmd.memsize_devlog);
2836 * Retrieve various parameters that are of interest to the driver. The device
2837 * has been initialized by the firmware at this point.
2840 get_params__post_init(struct adapter *sc)
2843 uint32_t param[7], val[7];
2844 struct fw_caps_config_cmd caps;
2846 param[0] = FW_PARAM_PFVF(IQFLINT_START);
2847 param[1] = FW_PARAM_PFVF(EQ_START);
2848 param[2] = FW_PARAM_PFVF(FILTER_START);
2849 param[3] = FW_PARAM_PFVF(FILTER_END);
2850 param[4] = FW_PARAM_PFVF(L2T_START);
2851 param[5] = FW_PARAM_PFVF(L2T_END);
2852 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
2854 device_printf(sc->dev,
2855 "failed to query parameters (post_init): %d.\n", rc);
2859 sc->sge.iq_start = val[0];
2860 sc->sge.eq_start = val[1];
2861 sc->tids.ftid_base = val[2];
2862 sc->tids.nftids = val[3] - val[2] + 1;
2863 sc->params.ftid_min = val[2];
2864 sc->params.ftid_max = val[3];
2865 sc->vres.l2t.start = val[4];
2866 sc->vres.l2t.size = val[5] - val[4] + 1;
2867 KASSERT(sc->vres.l2t.size <= L2T_SIZE,
2868 ("%s: L2 table size (%u) larger than expected (%u)",
2869 __func__, sc->vres.l2t.size, L2T_SIZE));
2871 /* get capabilites */
2872 bzero(&caps, sizeof(caps));
2873 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
2874 F_FW_CMD_REQUEST | F_FW_CMD_READ);
2875 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
2876 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
2878 device_printf(sc->dev,
2879 "failed to get card capabilities: %d.\n", rc);
2883 #define READ_CAPS(x) do { \
2884 sc->x = htobe16(caps.x); \
2886 READ_CAPS(linkcaps);
2889 READ_CAPS(rdmacaps);
2890 READ_CAPS(iscsicaps);
2891 READ_CAPS(fcoecaps);
2893 if (sc->niccaps & FW_CAPS_CONFIG_NIC_ETHOFLD) {
2894 param[0] = FW_PARAM_PFVF(ETHOFLD_START);
2895 param[1] = FW_PARAM_PFVF(ETHOFLD_END);
2896 param[2] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
2897 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 3, param, val);
2899 device_printf(sc->dev,
2900 "failed to query NIC parameters: %d.\n", rc);
2903 sc->tids.etid_base = val[0];
2904 sc->params.etid_min = val[0];
2905 sc->tids.netids = val[1] - val[0] + 1;
2906 sc->params.netids = sc->tids.netids;
2907 sc->params.eo_wr_cred = val[2];
2908 sc->params.ethoffload = 1;
2912 /* query offload-related parameters */
2913 param[0] = FW_PARAM_DEV(NTID);
2914 param[1] = FW_PARAM_PFVF(SERVER_START);
2915 param[2] = FW_PARAM_PFVF(SERVER_END);
2916 param[3] = FW_PARAM_PFVF(TDDP_START);
2917 param[4] = FW_PARAM_PFVF(TDDP_END);
2918 param[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
2919 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
2921 device_printf(sc->dev,
2922 "failed to query TOE parameters: %d.\n", rc);
2925 sc->tids.ntids = val[0];
2926 sc->tids.natids = min(sc->tids.ntids / 2, MAX_ATIDS);
2927 sc->tids.stid_base = val[1];
2928 sc->tids.nstids = val[2] - val[1] + 1;
2929 sc->vres.ddp.start = val[3];
2930 sc->vres.ddp.size = val[4] - val[3] + 1;
2931 sc->params.ofldq_wr_cred = val[5];
2932 sc->params.offload = 1;
2935 param[0] = FW_PARAM_PFVF(STAG_START);
2936 param[1] = FW_PARAM_PFVF(STAG_END);
2937 param[2] = FW_PARAM_PFVF(RQ_START);
2938 param[3] = FW_PARAM_PFVF(RQ_END);
2939 param[4] = FW_PARAM_PFVF(PBL_START);
2940 param[5] = FW_PARAM_PFVF(PBL_END);
2941 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
2943 device_printf(sc->dev,
2944 "failed to query RDMA parameters(1): %d.\n", rc);
2947 sc->vres.stag.start = val[0];
2948 sc->vres.stag.size = val[1] - val[0] + 1;
2949 sc->vres.rq.start = val[2];
2950 sc->vres.rq.size = val[3] - val[2] + 1;
2951 sc->vres.pbl.start = val[4];
2952 sc->vres.pbl.size = val[5] - val[4] + 1;
2954 param[0] = FW_PARAM_PFVF(SQRQ_START);
2955 param[1] = FW_PARAM_PFVF(SQRQ_END);
2956 param[2] = FW_PARAM_PFVF(CQ_START);
2957 param[3] = FW_PARAM_PFVF(CQ_END);
2958 param[4] = FW_PARAM_PFVF(OCQ_START);
2959 param[5] = FW_PARAM_PFVF(OCQ_END);
2960 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
2962 device_printf(sc->dev,
2963 "failed to query RDMA parameters(2): %d.\n", rc);
2966 sc->vres.qp.start = val[0];
2967 sc->vres.qp.size = val[1] - val[0] + 1;
2968 sc->vres.cq.start = val[2];
2969 sc->vres.cq.size = val[3] - val[2] + 1;
2970 sc->vres.ocq.start = val[4];
2971 sc->vres.ocq.size = val[5] - val[4] + 1;
2973 if (sc->iscsicaps) {
2974 param[0] = FW_PARAM_PFVF(ISCSI_START);
2975 param[1] = FW_PARAM_PFVF(ISCSI_END);
2976 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
2978 device_printf(sc->dev,
2979 "failed to query iSCSI parameters: %d.\n", rc);
2982 sc->vres.iscsi.start = val[0];
2983 sc->vres.iscsi.size = val[1] - val[0] + 1;
2987 * We've got the params we wanted to query via the firmware. Now grab
2988 * some others directly from the chip.
2990 rc = t4_read_chip_settings(sc);
2996 set_params__post_init(struct adapter *sc)
2998 uint32_t param, val;
3000 /* ask for encapsulated CPLs */
3001 param = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
3003 (void)t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
3008 #undef FW_PARAM_PFVF
3012 t4_set_desc(struct adapter *sc)
3015 struct adapter_params *p = &sc->params;
3017 snprintf(buf, sizeof(buf), "Chelsio %s %sNIC (rev %d), S/N:%s, "
3018 "P/N:%s, E/C:%s", p->vpd.id, is_offload(sc) ? "R" : "",
3019 chip_rev(sc), p->vpd.sn, p->vpd.pn, p->vpd.ec);
3021 device_set_desc_copy(sc->dev, buf);
3025 build_medialist(struct port_info *pi, struct ifmedia *media)
3031 ifmedia_removeall(media);
3033 m = IFM_ETHER | IFM_FDX;
3035 switch(pi->port_type) {
3036 case FW_PORT_TYPE_BT_XFI:
3037 case FW_PORT_TYPE_BT_XAUI:
3038 ifmedia_add(media, m | IFM_10G_T, 0, NULL);
3041 case FW_PORT_TYPE_BT_SGMII:
3042 ifmedia_add(media, m | IFM_1000_T, 0, NULL);
3043 ifmedia_add(media, m | IFM_100_TX, 0, NULL);
3044 ifmedia_add(media, IFM_ETHER | IFM_AUTO, 0, NULL);
3045 ifmedia_set(media, IFM_ETHER | IFM_AUTO);
3048 case FW_PORT_TYPE_CX4:
3049 ifmedia_add(media, m | IFM_10G_CX4, 0, NULL);
3050 ifmedia_set(media, m | IFM_10G_CX4);
3053 case FW_PORT_TYPE_QSFP_10G:
3054 case FW_PORT_TYPE_SFP:
3055 case FW_PORT_TYPE_FIBER_XFI:
3056 case FW_PORT_TYPE_FIBER_XAUI:
3057 switch (pi->mod_type) {
3059 case FW_PORT_MOD_TYPE_LR:
3060 ifmedia_add(media, m | IFM_10G_LR, 0, NULL);
3061 ifmedia_set(media, m | IFM_10G_LR);
3064 case FW_PORT_MOD_TYPE_SR:
3065 ifmedia_add(media, m | IFM_10G_SR, 0, NULL);
3066 ifmedia_set(media, m | IFM_10G_SR);
3069 case FW_PORT_MOD_TYPE_LRM:
3070 ifmedia_add(media, m | IFM_10G_LRM, 0, NULL);
3071 ifmedia_set(media, m | IFM_10G_LRM);
3074 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
3075 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
3076 ifmedia_add(media, m | IFM_10G_TWINAX, 0, NULL);
3077 ifmedia_set(media, m | IFM_10G_TWINAX);
3080 case FW_PORT_MOD_TYPE_NONE:
3082 ifmedia_add(media, m | IFM_NONE, 0, NULL);
3083 ifmedia_set(media, m | IFM_NONE);
3086 case FW_PORT_MOD_TYPE_NA:
3087 case FW_PORT_MOD_TYPE_ER:
3089 device_printf(pi->dev,
3090 "unknown port_type (%d), mod_type (%d)\n",
3091 pi->port_type, pi->mod_type);
3092 ifmedia_add(media, m | IFM_UNKNOWN, 0, NULL);
3093 ifmedia_set(media, m | IFM_UNKNOWN);
3098 case FW_PORT_TYPE_QSFP:
3099 switch (pi->mod_type) {
3101 case FW_PORT_MOD_TYPE_LR:
3102 ifmedia_add(media, m | IFM_40G_LR4, 0, NULL);
3103 ifmedia_set(media, m | IFM_40G_LR4);
3106 case FW_PORT_MOD_TYPE_SR:
3107 ifmedia_add(media, m | IFM_40G_SR4, 0, NULL);
3108 ifmedia_set(media, m | IFM_40G_SR4);
3111 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
3112 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
3113 ifmedia_add(media, m | IFM_40G_CR4, 0, NULL);
3114 ifmedia_set(media, m | IFM_40G_CR4);
3117 case FW_PORT_MOD_TYPE_NONE:
3119 ifmedia_add(media, m | IFM_NONE, 0, NULL);
3120 ifmedia_set(media, m | IFM_NONE);
3124 device_printf(pi->dev,
3125 "unknown port_type (%d), mod_type (%d)\n",
3126 pi->port_type, pi->mod_type);
3127 ifmedia_add(media, m | IFM_UNKNOWN, 0, NULL);
3128 ifmedia_set(media, m | IFM_UNKNOWN);
3134 device_printf(pi->dev,
3135 "unknown port_type (%d), mod_type (%d)\n", pi->port_type,
3137 ifmedia_add(media, m | IFM_UNKNOWN, 0, NULL);
3138 ifmedia_set(media, m | IFM_UNKNOWN);
3145 #define FW_MAC_EXACT_CHUNK 7
3148 * Program the port's XGMAC based on parameters in ifnet. The caller also
3149 * indicates which parameters should be programmed (the rest are left alone).
3152 update_mac_settings(struct ifnet *ifp, int flags)
3155 struct vi_info *vi = ifp->if_softc;
3156 struct port_info *pi = vi->pi;
3157 struct adapter *sc = pi->adapter;
3158 int mtu = -1, promisc = -1, allmulti = -1, vlanex = -1;
3160 ASSERT_SYNCHRONIZED_OP(sc);
3161 KASSERT(flags, ("%s: not told what to update.", __func__));
3163 if (flags & XGMAC_MTU)
3166 if (flags & XGMAC_PROMISC)
3167 promisc = ifp->if_flags & IFF_PROMISC ? 1 : 0;
3169 if (flags & XGMAC_ALLMULTI)
3170 allmulti = ifp->if_flags & IFF_ALLMULTI ? 1 : 0;
3172 if (flags & XGMAC_VLANEX)
3173 vlanex = ifp->if_capenable & IFCAP_VLAN_HWTAGGING ? 1 : 0;
3175 if (flags & (XGMAC_MTU|XGMAC_PROMISC|XGMAC_ALLMULTI|XGMAC_VLANEX)) {
3176 rc = -t4_set_rxmode(sc, sc->mbox, vi->viid, mtu, promisc,
3177 allmulti, 1, vlanex, false);
3179 if_printf(ifp, "set_rxmode (%x) failed: %d\n", flags,
3185 if (flags & XGMAC_UCADDR) {
3186 uint8_t ucaddr[ETHER_ADDR_LEN];
3188 bcopy(IF_LLADDR(ifp), ucaddr, sizeof(ucaddr));
3189 rc = t4_change_mac(sc, sc->mbox, vi->viid, vi->xact_addr_filt,
3190 ucaddr, true, true);
3193 if_printf(ifp, "change_mac failed: %d\n", rc);
3196 vi->xact_addr_filt = rc;
3201 if (flags & XGMAC_MCADDRS) {
3202 const uint8_t *mcaddr[FW_MAC_EXACT_CHUNK];
3205 struct ifmultiaddr *ifma;
3208 if_maddr_rlock(ifp);
3209 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
3210 if (ifma->ifma_addr->sa_family != AF_LINK)
3213 LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
3214 MPASS(ETHER_IS_MULTICAST(mcaddr[i]));
3217 if (i == FW_MAC_EXACT_CHUNK) {
3218 rc = t4_alloc_mac_filt(sc, sc->mbox, vi->viid,
3219 del, i, mcaddr, NULL, &hash, 0);
3222 for (j = 0; j < i; j++) {
3224 "failed to add mc address"
3226 "%02x:%02x:%02x rc=%d\n",
3227 mcaddr[j][0], mcaddr[j][1],
3228 mcaddr[j][2], mcaddr[j][3],
3229 mcaddr[j][4], mcaddr[j][5],
3239 rc = t4_alloc_mac_filt(sc, sc->mbox, vi->viid, del, i,
3240 mcaddr, NULL, &hash, 0);
3243 for (j = 0; j < i; j++) {
3245 "failed to add mc address"
3247 "%02x:%02x:%02x rc=%d\n",
3248 mcaddr[j][0], mcaddr[j][1],
3249 mcaddr[j][2], mcaddr[j][3],
3250 mcaddr[j][4], mcaddr[j][5],
3257 rc = -t4_set_addr_hash(sc, sc->mbox, vi->viid, 0, hash, 0);
3259 if_printf(ifp, "failed to set mc address hash: %d", rc);
3261 if_maddr_runlock(ifp);
3268 * {begin|end}_synchronized_op must be called from the same thread.
3271 begin_synchronized_op(struct adapter *sc, struct vi_info *vi, int flags,
3277 /* the caller thinks it's ok to sleep, but is it really? */
3278 if (flags & SLEEP_OK)
3279 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
3280 "begin_synchronized_op");
3291 if (vi && IS_DOOMED(vi)) {
3301 if (!(flags & SLEEP_OK)) {
3306 if (mtx_sleep(&sc->flags, &sc->sc_lock, pri, wmesg, 0)) {
3312 KASSERT(!IS_BUSY(sc), ("%s: controller busy.", __func__));
3315 sc->last_op = wmesg;
3316 sc->last_op_thr = curthread;
3317 sc->last_op_flags = flags;
3321 if (!(flags & HOLD_LOCK) || rc)
3328 * Tell if_ioctl and if_init that the VI is going away. This is
3329 * special variant of begin_synchronized_op and must be paired with a
3330 * call to end_synchronized_op.
3333 doom_vi(struct adapter *sc, struct vi_info *vi)
3340 mtx_sleep(&sc->flags, &sc->sc_lock, 0, "t4detach", 0);
3343 sc->last_op = "t4detach";
3344 sc->last_op_thr = curthread;
3345 sc->last_op_flags = 0;
3351 * {begin|end}_synchronized_op must be called from the same thread.
3354 end_synchronized_op(struct adapter *sc, int flags)
3357 if (flags & LOCK_HELD)
3358 ADAPTER_LOCK_ASSERT_OWNED(sc);
3362 KASSERT(IS_BUSY(sc), ("%s: controller not busy.", __func__));
3369 cxgbe_init_synchronized(struct vi_info *vi)
3371 struct port_info *pi = vi->pi;
3372 struct adapter *sc = pi->adapter;
3373 struct ifnet *ifp = vi->ifp;
3375 struct sge_txq *txq;
3377 ASSERT_SYNCHRONIZED_OP(sc);
3379 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
3380 return (0); /* already running */
3382 if (!(sc->flags & FULL_INIT_DONE) &&
3383 ((rc = adapter_full_init(sc)) != 0))
3384 return (rc); /* error message displayed already */
3386 if (!(vi->flags & VI_INIT_DONE) &&
3387 ((rc = vi_full_init(vi)) != 0))
3388 return (rc); /* error message displayed already */
3390 rc = update_mac_settings(ifp, XGMAC_ALL);
3392 goto done; /* error message displayed already */
3394 rc = -t4_enable_vi(sc, sc->mbox, vi->viid, true, true);
3396 if_printf(ifp, "enable_vi failed: %d\n", rc);
3401 * Can't fail from this point onwards. Review cxgbe_uninit_synchronized
3405 for_each_txq(vi, i, txq) {
3407 txq->eq.flags |= EQ_ENABLED;
3412 * The first iq of the first port to come up is used for tracing.
3414 if (sc->traceq < 0 && IS_MAIN_VI(vi)) {
3415 sc->traceq = sc->sge.rxq[vi->first_rxq].iq.abs_id;
3416 t4_write_reg(sc, is_t4(sc) ? A_MPS_TRC_RSS_CONTROL :
3417 A_MPS_T5_TRC_RSS_CONTROL, V_RSSCONTROL(pi->tx_chan) |
3418 V_QUEUENUMBER(sc->traceq));
3419 pi->flags |= HAS_TRACEQ;
3424 ifp->if_drv_flags |= IFF_DRV_RUNNING;
3428 callout_reset(&vi->tick, hz, vi_tick, vi);
3430 callout_reset(&pi->tick, hz, cxgbe_tick, pi);
3434 cxgbe_uninit_synchronized(vi);
3443 cxgbe_uninit_synchronized(struct vi_info *vi)
3445 struct port_info *pi = vi->pi;
3446 struct adapter *sc = pi->adapter;
3447 struct ifnet *ifp = vi->ifp;
3449 struct sge_txq *txq;
3451 ASSERT_SYNCHRONIZED_OP(sc);
3453 if (!(vi->flags & VI_INIT_DONE)) {
3454 KASSERT(!(ifp->if_drv_flags & IFF_DRV_RUNNING),
3455 ("uninited VI is running"));
3460 * Disable the VI so that all its data in either direction is discarded
3461 * by the MPS. Leave everything else (the queues, interrupts, and 1Hz
3462 * tick) intact as the TP can deliver negative advice or data that it's
3463 * holding in its RAM (for an offloaded connection) even after the VI is
3466 rc = -t4_enable_vi(sc, sc->mbox, vi->viid, false, false);
3468 if_printf(ifp, "disable_vi failed: %d\n", rc);
3472 for_each_txq(vi, i, txq) {
3474 txq->eq.flags &= ~EQ_ENABLED;
3480 callout_stop(&pi->tick);
3482 callout_stop(&vi->tick);
3483 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
3487 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
3489 if (pi->up_vis > 0) {
3495 pi->link_cfg.link_ok = 0;
3496 pi->link_cfg.speed = 0;
3498 t4_os_link_changed(sc, pi->port_id, 0, -1);
3504 * It is ok for this function to fail midway and return right away. t4_detach
3505 * will walk the entire sc->irq list and clean up whatever is valid.
3508 setup_intr_handlers(struct adapter *sc)
3510 int rc, rid, p, q, v;
3513 struct port_info *pi;
3515 struct sge *sge = &sc->sge;
3516 struct sge_rxq *rxq;
3518 struct sge_ofld_rxq *ofld_rxq;
3521 struct sge_nm_rxq *nm_rxq;
3528 rid = sc->intr_type == INTR_INTX ? 0 : 1;
3529 if (sc->intr_count == 1)
3530 return (t4_alloc_irq(sc, irq, rid, t4_intr_all, sc, "all"));
3532 /* Multiple interrupts. */
3533 KASSERT(sc->intr_count >= T4_EXTRA_INTR + sc->params.nports,
3534 ("%s: too few intr.", __func__));
3536 /* The first one is always error intr */
3537 rc = t4_alloc_irq(sc, irq, rid, t4_intr_err, sc, "err");
3543 /* The second one is always the firmware event queue */
3544 rc = t4_alloc_irq(sc, irq, rid, t4_intr_evt, &sge->fwq, "evt");
3550 for_each_port(sc, p) {
3552 for_each_vi(pi, v, vi) {
3553 vi->first_intr = rid - 1;
3555 if (vi->nnmrxq > 0) {
3556 int n = max(vi->nrxq, vi->nnmrxq);
3558 MPASS(vi->flags & INTR_RXQ);
3560 rxq = &sge->rxq[vi->first_rxq];
3562 nm_rxq = &sge->nm_rxq[vi->first_nm_rxq];
3564 for (q = 0; q < n; q++) {
3565 snprintf(s, sizeof(s), "%x%c%x", p,
3571 irq->nm_rxq = nm_rxq++;
3573 rc = t4_alloc_irq(sc, irq, rid,
3574 t4_vi_intr, irq, s);
3581 } else if (vi->flags & INTR_RXQ) {
3582 for_each_rxq(vi, q, rxq) {
3583 snprintf(s, sizeof(s), "%x%c%x", p,
3585 rc = t4_alloc_irq(sc, irq, rid,
3595 if (vi->flags & INTR_OFLD_RXQ) {
3596 for_each_ofld_rxq(vi, q, ofld_rxq) {
3597 snprintf(s, sizeof(s), "%x%c%x", p,
3599 rc = t4_alloc_irq(sc, irq, rid,
3600 t4_intr, ofld_rxq, s);
3611 MPASS(irq == &sc->irq[sc->intr_count]);
3617 adapter_full_init(struct adapter *sc)
3621 ASSERT_SYNCHRONIZED_OP(sc);
3622 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
3623 KASSERT((sc->flags & FULL_INIT_DONE) == 0,
3624 ("%s: FULL_INIT_DONE already", __func__));
3627 * queues that belong to the adapter (not any particular port).
3629 rc = t4_setup_adapter_queues(sc);
3633 for (i = 0; i < nitems(sc->tq); i++) {
3634 sc->tq[i] = taskqueue_create("t4 taskq", M_NOWAIT,
3635 taskqueue_thread_enqueue, &sc->tq[i]);
3636 if (sc->tq[i] == NULL) {
3637 device_printf(sc->dev,
3638 "failed to allocate task queue %d\n", i);
3642 taskqueue_start_threads(&sc->tq[i], 1, PI_NET, "%s tq%d",
3643 device_get_nameunit(sc->dev), i);
3647 sc->flags |= FULL_INIT_DONE;
3650 adapter_full_uninit(sc);
3656 adapter_full_uninit(struct adapter *sc)
3660 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
3662 t4_teardown_adapter_queues(sc);
3664 for (i = 0; i < nitems(sc->tq) && sc->tq[i]; i++) {
3665 taskqueue_free(sc->tq[i]);
3669 sc->flags &= ~FULL_INIT_DONE;
3675 #define SUPPORTED_RSS_HASHTYPES (RSS_HASHTYPE_RSS_IPV4 | \
3676 RSS_HASHTYPE_RSS_TCP_IPV4 | RSS_HASHTYPE_RSS_IPV6 | \
3677 RSS_HASHTYPE_RSS_TCP_IPV6 | RSS_HASHTYPE_RSS_UDP_IPV4 | \
3678 RSS_HASHTYPE_RSS_UDP_IPV6)
3680 /* Translates kernel hash types to hardware. */
3682 hashconfig_to_hashen(int hashconfig)
3686 if (hashconfig & RSS_HASHTYPE_RSS_IPV4)
3687 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN;
3688 if (hashconfig & RSS_HASHTYPE_RSS_IPV6)
3689 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN;
3690 if (hashconfig & RSS_HASHTYPE_RSS_UDP_IPV4) {
3691 hashen |= F_FW_RSS_VI_CONFIG_CMD_UDPEN |
3692 F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
3694 if (hashconfig & RSS_HASHTYPE_RSS_UDP_IPV6) {
3695 hashen |= F_FW_RSS_VI_CONFIG_CMD_UDPEN |
3696 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
3698 if (hashconfig & RSS_HASHTYPE_RSS_TCP_IPV4)
3699 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
3700 if (hashconfig & RSS_HASHTYPE_RSS_TCP_IPV6)
3701 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
3706 /* Translates hardware hash types to kernel. */
3708 hashen_to_hashconfig(int hashen)
3712 if (hashen & F_FW_RSS_VI_CONFIG_CMD_UDPEN) {
3714 * If UDP hashing was enabled it must have been enabled for
3715 * either IPv4 or IPv6 (inclusive or). Enabling UDP without
3716 * enabling any 4-tuple hash is nonsense configuration.
3718 MPASS(hashen & (F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN |
3719 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN));
3721 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN)
3722 hashconfig |= RSS_HASHTYPE_RSS_UDP_IPV4;
3723 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN)
3724 hashconfig |= RSS_HASHTYPE_RSS_UDP_IPV6;
3726 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN)
3727 hashconfig |= RSS_HASHTYPE_RSS_TCP_IPV4;
3728 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN)
3729 hashconfig |= RSS_HASHTYPE_RSS_TCP_IPV6;
3730 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN)
3731 hashconfig |= RSS_HASHTYPE_RSS_IPV4;
3732 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN)
3733 hashconfig |= RSS_HASHTYPE_RSS_IPV6;
3735 return (hashconfig);
3740 vi_full_init(struct vi_info *vi)
3742 struct adapter *sc = vi->pi->adapter;
3743 struct ifnet *ifp = vi->ifp;
3745 struct sge_rxq *rxq;
3746 int rc, i, j, hashen;
3748 int nbuckets = rss_getnumbuckets();
3749 int hashconfig = rss_gethashconfig();
3751 uint32_t raw_rss_key[RSS_KEYSIZE / sizeof(uint32_t)];
3752 uint32_t rss_key[RSS_KEYSIZE / sizeof(uint32_t)];
3755 ASSERT_SYNCHRONIZED_OP(sc);
3756 KASSERT((vi->flags & VI_INIT_DONE) == 0,
3757 ("%s: VI_INIT_DONE already", __func__));
3759 sysctl_ctx_init(&vi->ctx);
3760 vi->flags |= VI_SYSCTL_CTX;
3763 * Allocate tx/rx/fl queues for this VI.
3765 rc = t4_setup_vi_queues(vi);
3767 goto done; /* error message displayed already */
3770 * Setup RSS for this VI. Save a copy of the RSS table for later use.
3772 if (vi->nrxq > vi->rss_size) {
3773 if_printf(ifp, "nrxq (%d) > hw RSS table size (%d); "
3774 "some queues will never receive traffic.\n", vi->nrxq,
3776 } else if (vi->rss_size % vi->nrxq) {
3777 if_printf(ifp, "nrxq (%d), hw RSS table size (%d); "
3778 "expect uneven traffic distribution.\n", vi->nrxq,
3782 MPASS(RSS_KEYSIZE == 40);
3783 if (vi->nrxq != nbuckets) {
3784 if_printf(ifp, "nrxq (%d) != kernel RSS buckets (%d);"
3785 "performance will be impacted.\n", vi->nrxq, nbuckets);
3788 rss_getkey((void *)&raw_rss_key[0]);
3789 for (i = 0; i < nitems(rss_key); i++) {
3790 rss_key[i] = htobe32(raw_rss_key[nitems(rss_key) - 1 - i]);
3792 t4_write_rss_key(sc, (void *)&rss_key[0], -1);
3794 rss = malloc(vi->rss_size * sizeof (*rss), M_CXGBE, M_ZERO | M_WAITOK);
3795 for (i = 0; i < vi->rss_size;) {
3797 j = rss_get_indirection_to_bucket(i);
3799 rxq = &sc->sge.rxq[vi->first_rxq + j];
3800 rss[i++] = rxq->iq.abs_id;
3802 for_each_rxq(vi, j, rxq) {
3803 rss[i++] = rxq->iq.abs_id;
3804 if (i == vi->rss_size)
3810 rc = -t4_config_rss_range(sc, sc->mbox, vi->viid, 0, vi->rss_size, rss,
3813 if_printf(ifp, "rss_config failed: %d\n", rc);
3818 hashen = hashconfig_to_hashen(hashconfig);
3821 * We may have had to enable some hashes even though the global config
3822 * wants them disabled. This is a potential problem that must be
3823 * reported to the user.
3825 extra = hashen_to_hashconfig(hashen) ^ hashconfig;
3828 * If we consider only the supported hash types, then the enabled hashes
3829 * are a superset of the requested hashes. In other words, there cannot
3830 * be any supported hash that was requested but not enabled, but there
3831 * can be hashes that were not requested but had to be enabled.
3833 extra &= SUPPORTED_RSS_HASHTYPES;
3834 MPASS((extra & hashconfig) == 0);
3838 "global RSS config (0x%x) cannot be accomodated.\n",
3841 if (extra & RSS_HASHTYPE_RSS_IPV4)
3842 if_printf(ifp, "IPv4 2-tuple hashing forced on.\n");
3843 if (extra & RSS_HASHTYPE_RSS_TCP_IPV4)
3844 if_printf(ifp, "TCP/IPv4 4-tuple hashing forced on.\n");
3845 if (extra & RSS_HASHTYPE_RSS_IPV6)
3846 if_printf(ifp, "IPv6 2-tuple hashing forced on.\n");
3847 if (extra & RSS_HASHTYPE_RSS_TCP_IPV6)
3848 if_printf(ifp, "TCP/IPv6 4-tuple hashing forced on.\n");
3849 if (extra & RSS_HASHTYPE_RSS_UDP_IPV4)
3850 if_printf(ifp, "UDP/IPv4 4-tuple hashing forced on.\n");
3851 if (extra & RSS_HASHTYPE_RSS_UDP_IPV6)
3852 if_printf(ifp, "UDP/IPv6 4-tuple hashing forced on.\n");
3854 hashen = F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN |
3855 F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN |
3856 F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN |
3857 F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN | F_FW_RSS_VI_CONFIG_CMD_UDPEN;
3859 rc = -t4_config_vi_rss(sc, sc->mbox, vi->viid, hashen, rss[0]);
3861 if_printf(ifp, "rss hash/defaultq config failed: %d\n", rc);
3866 vi->flags |= VI_INIT_DONE;
3878 vi_full_uninit(struct vi_info *vi)
3880 struct port_info *pi = vi->pi;
3881 struct adapter *sc = pi->adapter;
3883 struct sge_rxq *rxq;
3884 struct sge_txq *txq;
3886 struct sge_ofld_rxq *ofld_rxq;
3887 struct sge_wrq *ofld_txq;
3890 if (vi->flags & VI_INIT_DONE) {
3892 /* Need to quiesce queues. */
3894 /* XXX: Only for the first VI? */
3896 quiesce_wrq(sc, &sc->sge.ctrlq[pi->port_id]);
3898 for_each_txq(vi, i, txq) {
3899 quiesce_txq(sc, txq);
3903 for_each_ofld_txq(vi, i, ofld_txq) {
3904 quiesce_wrq(sc, ofld_txq);
3908 for_each_rxq(vi, i, rxq) {
3909 quiesce_iq(sc, &rxq->iq);
3910 quiesce_fl(sc, &rxq->fl);
3914 for_each_ofld_rxq(vi, i, ofld_rxq) {
3915 quiesce_iq(sc, &ofld_rxq->iq);
3916 quiesce_fl(sc, &ofld_rxq->fl);
3919 free(vi->rss, M_CXGBE);
3920 free(vi->nm_rss, M_CXGBE);
3923 t4_teardown_vi_queues(vi);
3924 vi->flags &= ~VI_INIT_DONE;
3930 quiesce_txq(struct adapter *sc, struct sge_txq *txq)
3932 struct sge_eq *eq = &txq->eq;
3933 struct sge_qstat *spg = (void *)&eq->desc[eq->sidx];
3935 (void) sc; /* unused */
3939 MPASS((eq->flags & EQ_ENABLED) == 0);
3943 /* Wait for the mp_ring to empty. */
3944 while (!mp_ring_is_idle(txq->r)) {
3945 mp_ring_check_drainage(txq->r, 0);
3946 pause("rquiesce", 1);
3949 /* Then wait for the hardware to finish. */
3950 while (spg->cidx != htobe16(eq->pidx))
3951 pause("equiesce", 1);
3953 /* Finally, wait for the driver to reclaim all descriptors. */
3954 while (eq->cidx != eq->pidx)
3955 pause("dquiesce", 1);
3959 quiesce_wrq(struct adapter *sc, struct sge_wrq *wrq)
3966 quiesce_iq(struct adapter *sc, struct sge_iq *iq)
3968 (void) sc; /* unused */
3970 /* Synchronize with the interrupt handler */
3971 while (!atomic_cmpset_int(&iq->state, IQS_IDLE, IQS_DISABLED))
3976 quiesce_fl(struct adapter *sc, struct sge_fl *fl)
3978 mtx_lock(&sc->sfl_lock);
3980 fl->flags |= FL_DOOMED;
3982 callout_stop(&sc->sfl_callout);
3983 mtx_unlock(&sc->sfl_lock);
3985 KASSERT((fl->flags & FL_STARVING) == 0,
3986 ("%s: still starving", __func__));
3990 t4_alloc_irq(struct adapter *sc, struct irq *irq, int rid,
3991 driver_intr_t *handler, void *arg, char *name)
3996 irq->res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &irq->rid,
3997 RF_SHAREABLE | RF_ACTIVE);
3998 if (irq->res == NULL) {
3999 device_printf(sc->dev,
4000 "failed to allocate IRQ for rid %d, name %s.\n", rid, name);
4004 rc = bus_setup_intr(sc->dev, irq->res, INTR_MPSAFE | INTR_TYPE_NET,
4005 NULL, handler, arg, &irq->tag);
4007 device_printf(sc->dev,
4008 "failed to setup interrupt for rid %d, name %s: %d\n",
4011 bus_describe_intr(sc->dev, irq->res, irq->tag, name);
4017 t4_free_irq(struct adapter *sc, struct irq *irq)
4020 bus_teardown_intr(sc->dev, irq->res, irq->tag);
4022 bus_release_resource(sc->dev, SYS_RES_IRQ, irq->rid, irq->res);
4024 bzero(irq, sizeof(*irq));
4030 reg_block_dump(struct adapter *sc, uint8_t *buf, unsigned int start,
4033 uint32_t *p = (uint32_t *)(buf + start);
4035 for ( ; start <= end; start += sizeof(uint32_t))
4036 *p++ = t4_read_reg(sc, start);
4040 t4_get_regs(struct adapter *sc, struct t4_regdump *regs, uint8_t *buf)
4043 const unsigned int *reg_ranges;
4044 static const unsigned int t4_reg_ranges[] = {
4264 static const unsigned int t5_reg_ranges[] = {
4705 reg_ranges = &t4_reg_ranges[0];
4706 n = nitems(t4_reg_ranges);
4708 reg_ranges = &t5_reg_ranges[0];
4709 n = nitems(t5_reg_ranges);
4712 regs->version = chip_id(sc) | chip_rev(sc) << 10;
4713 for (i = 0; i < n; i += 2)
4714 reg_block_dump(sc, buf, reg_ranges[i], reg_ranges[i + 1]);
4717 #define A_PL_INDIR_CMD 0x1f8
4719 #define S_PL_AUTOINC 31
4720 #define M_PL_AUTOINC 0x1U
4721 #define V_PL_AUTOINC(x) ((x) << S_PL_AUTOINC)
4722 #define G_PL_AUTOINC(x) (((x) >> S_PL_AUTOINC) & M_PL_AUTOINC)
4724 #define S_PL_VFID 20
4725 #define M_PL_VFID 0xffU
4726 #define V_PL_VFID(x) ((x) << S_PL_VFID)
4727 #define G_PL_VFID(x) (((x) >> S_PL_VFID) & M_PL_VFID)
4730 #define M_PL_ADDR 0xfffffU
4731 #define V_PL_ADDR(x) ((x) << S_PL_ADDR)
4732 #define G_PL_ADDR(x) (((x) >> S_PL_ADDR) & M_PL_ADDR)
4734 #define A_PL_INDIR_DATA 0x1fc
4737 read_vf_stat(struct adapter *sc, unsigned int viid, int reg)
4741 mtx_assert(&sc->regwin_lock, MA_OWNED);
4742 t4_write_reg(sc, A_PL_INDIR_CMD, V_PL_AUTOINC(1) |
4743 V_PL_VFID(G_FW_VIID_VIN(viid)) | V_PL_ADDR(VF_MPS_REG(reg)));
4744 stats[0] = t4_read_reg(sc, A_PL_INDIR_DATA);
4745 stats[1] = t4_read_reg(sc, A_PL_INDIR_DATA);
4746 return (((uint64_t)stats[1]) << 32 | stats[0]);
4750 t4_get_vi_stats(struct adapter *sc, unsigned int viid,
4751 struct fw_vi_stats_vf *stats)
4754 #define GET_STAT(name) \
4755 read_vf_stat(sc, viid, A_MPS_VF_STAT_##name##_L)
4757 stats->tx_bcast_bytes = GET_STAT(TX_VF_BCAST_BYTES);
4758 stats->tx_bcast_frames = GET_STAT(TX_VF_BCAST_FRAMES);
4759 stats->tx_mcast_bytes = GET_STAT(TX_VF_MCAST_BYTES);
4760 stats->tx_mcast_frames = GET_STAT(TX_VF_MCAST_FRAMES);
4761 stats->tx_ucast_bytes = GET_STAT(TX_VF_UCAST_BYTES);
4762 stats->tx_ucast_frames = GET_STAT(TX_VF_UCAST_FRAMES);
4763 stats->tx_drop_frames = GET_STAT(TX_VF_DROP_FRAMES);
4764 stats->tx_offload_bytes = GET_STAT(TX_VF_OFFLOAD_BYTES);
4765 stats->tx_offload_frames = GET_STAT(TX_VF_OFFLOAD_FRAMES);
4766 stats->rx_bcast_bytes = GET_STAT(RX_VF_BCAST_BYTES);
4767 stats->rx_bcast_frames = GET_STAT(RX_VF_BCAST_FRAMES);
4768 stats->rx_mcast_bytes = GET_STAT(RX_VF_MCAST_BYTES);
4769 stats->rx_mcast_frames = GET_STAT(RX_VF_MCAST_FRAMES);
4770 stats->rx_ucast_bytes = GET_STAT(RX_VF_UCAST_BYTES);
4771 stats->rx_ucast_frames = GET_STAT(RX_VF_UCAST_FRAMES);
4772 stats->rx_err_frames = GET_STAT(RX_VF_ERR_FRAMES);
4778 t4_clr_vi_stats(struct adapter *sc, unsigned int viid)
4782 t4_write_reg(sc, A_PL_INDIR_CMD, V_PL_AUTOINC(1) |
4783 V_PL_VFID(G_FW_VIID_VIN(viid)) |
4784 V_PL_ADDR(VF_MPS_REG(A_MPS_VF_STAT_TX_VF_BCAST_BYTES_L)));
4785 for (reg = A_MPS_VF_STAT_TX_VF_BCAST_BYTES_L;
4786 reg <= A_MPS_VF_STAT_RX_VF_ERR_FRAMES_H; reg += 4)
4787 t4_write_reg(sc, A_PL_INDIR_DATA, 0);
4791 vi_refresh_stats(struct adapter *sc, struct vi_info *vi)
4793 struct ifnet *ifp = vi->ifp;
4794 struct sge_txq *txq;
4796 struct fw_vi_stats_vf *s = &vi->stats;
4798 const struct timeval interval = {0, 250000}; /* 250ms */
4800 if (!(vi->flags & VI_INIT_DONE))
4804 timevalsub(&tv, &interval);
4805 if (timevalcmp(&tv, &vi->last_refreshed, <))
4808 mtx_lock(&sc->regwin_lock);
4809 t4_get_vi_stats(sc, vi->viid, &vi->stats);
4811 ifp->if_ipackets = s->rx_bcast_frames + s->rx_mcast_frames +
4813 ifp->if_ierrors = s->rx_err_frames;
4814 ifp->if_opackets = s->tx_bcast_frames + s->tx_mcast_frames +
4815 s->tx_ucast_frames + s->tx_offload_frames;
4816 ifp->if_oerrors = s->tx_drop_frames;
4817 ifp->if_ibytes = s->rx_bcast_bytes + s->rx_mcast_bytes +
4819 ifp->if_obytes = s->tx_bcast_bytes + s->tx_mcast_bytes +
4820 s->tx_ucast_bytes + s->tx_offload_bytes;
4821 ifp->if_imcasts = s->rx_mcast_frames;
4822 ifp->if_omcasts = s->tx_mcast_frames;
4825 for_each_txq(vi, i, txq)
4826 drops += counter_u64_fetch(txq->r->drops);
4827 ifp->if_snd.ifq_drops = drops;
4829 getmicrotime(&vi->last_refreshed);
4830 mtx_unlock(&sc->regwin_lock);
4834 cxgbe_refresh_stats(struct adapter *sc, struct port_info *pi)
4836 struct vi_info *vi = &pi->vi[0];
4837 struct ifnet *ifp = vi->ifp;
4838 struct sge_txq *txq;
4840 struct port_stats *s = &pi->stats;
4842 const struct timeval interval = {0, 250000}; /* 250ms */
4845 timevalsub(&tv, &interval);
4846 if (timevalcmp(&tv, &pi->last_refreshed, <))
4849 t4_get_port_stats(sc, pi->tx_chan, s);
4851 ifp->if_opackets = s->tx_frames - s->tx_pause;
4852 ifp->if_ipackets = s->rx_frames - s->rx_pause;
4853 ifp->if_obytes = s->tx_octets - s->tx_pause * 64;
4854 ifp->if_ibytes = s->rx_octets - s->rx_pause * 64;
4855 ifp->if_omcasts = s->tx_mcast_frames - s->tx_pause;
4856 ifp->if_imcasts = s->rx_mcast_frames - s->rx_pause;
4857 ifp->if_iqdrops = s->rx_ovflow0 + s->rx_ovflow1 + s->rx_ovflow2 +
4858 s->rx_ovflow3 + s->rx_trunc0 + s->rx_trunc1 + s->rx_trunc2 +
4860 for (i = 0; i < NCHAN; i++) {
4861 if (pi->rx_chan_map & (1 << i)) {
4864 mtx_lock(&sc->regwin_lock);
4865 t4_read_indirect(sc, A_TP_MIB_INDEX, A_TP_MIB_DATA, &v,
4866 1, A_TP_MIB_TNL_CNG_DROP_0 + i);
4867 mtx_unlock(&sc->regwin_lock);
4868 ifp->if_iqdrops += v;
4873 for_each_txq(vi, i, txq)
4874 drops += counter_u64_fetch(txq->r->drops);
4875 ifp->if_snd.ifq_drops = drops;
4877 ifp->if_oerrors = s->tx_error_frames;
4878 ifp->if_ierrors = s->rx_jabber + s->rx_runt + s->rx_too_long +
4879 s->rx_fcs_err + s->rx_len_err;
4881 getmicrotime(&pi->last_refreshed);
4885 cxgbe_tick(void *arg)
4887 struct port_info *pi = arg;
4888 struct adapter *sc = pi->adapter;
4890 PORT_LOCK_ASSERT_OWNED(pi);
4891 cxgbe_refresh_stats(sc, pi);
4893 callout_schedule(&pi->tick, hz);
4899 struct vi_info *vi = arg;
4900 struct adapter *sc = vi->pi->adapter;
4902 vi_refresh_stats(sc, vi);
4904 callout_schedule(&vi->tick, hz);
4908 cxgbe_vlan_config(void *arg, struct ifnet *ifp, uint16_t vid)
4912 if (arg != ifp || ifp->if_type != IFT_ETHER)
4915 vlan = VLAN_DEVAT(ifp, vid);
4916 VLAN_SETCOOKIE(vlan, ifp);
4920 cpl_not_handled(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
4924 panic("%s: opcode 0x%02x on iq %p with payload %p",
4925 __func__, rss->opcode, iq, m);
4927 log(LOG_ERR, "%s: opcode 0x%02x on iq %p with payload %p\n",
4928 __func__, rss->opcode, iq, m);
4935 t4_register_cpl_handler(struct adapter *sc, int opcode, cpl_handler_t h)
4937 uintptr_t *loc, new;
4939 if (opcode >= nitems(sc->cpl_handler))
4942 new = h ? (uintptr_t)h : (uintptr_t)cpl_not_handled;
4943 loc = (uintptr_t *) &sc->cpl_handler[opcode];
4944 atomic_store_rel_ptr(loc, new);
4950 an_not_handled(struct sge_iq *iq, const struct rsp_ctrl *ctrl)
4954 panic("%s: async notification on iq %p (ctrl %p)", __func__, iq, ctrl);
4956 log(LOG_ERR, "%s: async notification on iq %p (ctrl %p)\n",
4957 __func__, iq, ctrl);
4963 t4_register_an_handler(struct adapter *sc, an_handler_t h)
4965 uintptr_t *loc, new;
4967 new = h ? (uintptr_t)h : (uintptr_t)an_not_handled;
4968 loc = (uintptr_t *) &sc->an_handler;
4969 atomic_store_rel_ptr(loc, new);
4975 fw_msg_not_handled(struct adapter *sc, const __be64 *rpl)
4977 const struct cpl_fw6_msg *cpl =
4978 __containerof(rpl, struct cpl_fw6_msg, data[0]);
4981 panic("%s: fw_msg type %d", __func__, cpl->type);
4983 log(LOG_ERR, "%s: fw_msg type %d\n", __func__, cpl->type);
4989 t4_register_fw_msg_handler(struct adapter *sc, int type, fw_msg_handler_t h)
4991 uintptr_t *loc, new;
4993 if (type >= nitems(sc->fw_msg_handler))
4997 * These are dispatched by the handler for FW{4|6}_CPL_MSG using the CPL
4998 * handler dispatch table. Reject any attempt to install a handler for
5001 if (type == FW_TYPE_RSSCPL || type == FW6_TYPE_RSSCPL)
5004 new = h ? (uintptr_t)h : (uintptr_t)fw_msg_not_handled;
5005 loc = (uintptr_t *) &sc->fw_msg_handler[type];
5006 atomic_store_rel_ptr(loc, new);
5012 t4_sysctls(struct adapter *sc)
5014 struct sysctl_ctx_list *ctx;
5015 struct sysctl_oid *oid;
5016 struct sysctl_oid_list *children, *c0;
5017 static char *caps[] = {
5018 "\20\1PPP\2QFC\3DCBX", /* caps[0] linkcaps */
5019 "\20\1NIC\2VM\3IDS\4UM\5UM_ISGL" /* caps[1] niccaps */
5020 "\6HASHFILTER\7ETHOFLD",
5021 "\20\1TOE", /* caps[2] toecaps */
5022 "\20\1RDDP\2RDMAC", /* caps[3] rdmacaps */
5023 "\20\1INITIATOR_PDU\2TARGET_PDU" /* caps[4] iscsicaps */
5024 "\3INITIATOR_CNXOFLD\4TARGET_CNXOFLD"
5025 "\5INITIATOR_SSNOFLD\6TARGET_SSNOFLD",
5026 "\20\1INITIATOR\2TARGET\3CTRL_OFLD" /* caps[5] fcoecaps */
5027 "\4PO_INITIAOR\5PO_TARGET"
5029 static char *doorbells = {"\20\1UDB\2WCWR\3UDBWC\4KDB"};
5031 ctx = device_get_sysctl_ctx(sc->dev);
5036 oid = device_get_sysctl_tree(sc->dev);
5037 c0 = children = SYSCTL_CHILDREN(oid);
5039 sc->sc_do_rxcopy = 1;
5040 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "do_rx_copy", CTLFLAG_RW,
5041 &sc->sc_do_rxcopy, 1, "Do RX copy of small frames");
5043 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nports", CTLFLAG_RD, NULL,
5044 sc->params.nports, "# of ports");
5046 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "hw_revision", CTLFLAG_RD,
5047 NULL, chip_rev(sc), "chip hardware revision");
5049 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "firmware_version",
5050 CTLFLAG_RD, sc->fw_version, 0, "firmware version");
5052 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "cf",
5053 CTLFLAG_RD, sc->cfg_file, 0, "configuration file");
5055 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "cfcsum", CTLFLAG_RD, NULL,
5056 sc->cfcsum, "config file checksum");
5058 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "doorbells",
5059 CTLTYPE_STRING | CTLFLAG_RD, doorbells, sc->doorbells,
5060 sysctl_bitfield, "A", "available doorbells");
5062 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "linkcaps",
5063 CTLTYPE_STRING | CTLFLAG_RD, caps[0], sc->linkcaps,
5064 sysctl_bitfield, "A", "available link capabilities");
5066 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "niccaps",
5067 CTLTYPE_STRING | CTLFLAG_RD, caps[1], sc->niccaps,
5068 sysctl_bitfield, "A", "available NIC capabilities");
5070 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "toecaps",
5071 CTLTYPE_STRING | CTLFLAG_RD, caps[2], sc->toecaps,
5072 sysctl_bitfield, "A", "available TCP offload capabilities");
5074 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rdmacaps",
5075 CTLTYPE_STRING | CTLFLAG_RD, caps[3], sc->rdmacaps,
5076 sysctl_bitfield, "A", "available RDMA capabilities");
5078 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "iscsicaps",
5079 CTLTYPE_STRING | CTLFLAG_RD, caps[4], sc->iscsicaps,
5080 sysctl_bitfield, "A", "available iSCSI capabilities");
5082 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fcoecaps",
5083 CTLTYPE_STRING | CTLFLAG_RD, caps[5], sc->fcoecaps,
5084 sysctl_bitfield, "A", "available FCoE capabilities");
5086 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "core_clock", CTLFLAG_RD, NULL,
5087 sc->params.vpd.cclk, "core clock frequency (in KHz)");
5089 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_timers",
5090 CTLTYPE_STRING | CTLFLAG_RD, sc->sge.timer_val,
5091 sizeof(sc->sge.timer_val), sysctl_int_array, "A",
5092 "interrupt holdoff timer values (us)");
5094 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pkt_counts",
5095 CTLTYPE_STRING | CTLFLAG_RD, sc->sge.counter_val,
5096 sizeof(sc->sge.counter_val), sysctl_int_array, "A",
5097 "interrupt holdoff packet counter values");
5099 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nfilters", CTLFLAG_RD,
5100 NULL, sc->tids.nftids, "number of filters");
5102 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature", CTLTYPE_INT |
5103 CTLFLAG_RD, sc, 0, sysctl_temperature, "I",
5104 "chip temperature (in Celsius)");
5106 t4_sge_sysctls(sc, ctx, children);
5108 sc->lro_timeout = 100;
5109 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "lro_timeout", CTLFLAG_RW,
5110 &sc->lro_timeout, 0, "lro inactive-flush timeout (in us)");
5112 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "debug_flags", CTLFLAG_RW,
5113 &sc->debug_flags, 0, "flags to enable runtime debugging");
5117 * dev.t4nex.X.misc. Marked CTLFLAG_SKIP to avoid information overload.
5119 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "misc",
5120 CTLFLAG_RD | CTLFLAG_SKIP, NULL,
5121 "logs and miscellaneous information");
5122 children = SYSCTL_CHILDREN(oid);
5124 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cctrl",
5125 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5126 sysctl_cctrl, "A", "congestion control");
5128 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp0",
5129 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5130 sysctl_cim_ibq_obq, "A", "CIM IBQ 0 (TP0)");
5132 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp1",
5133 CTLTYPE_STRING | CTLFLAG_RD, sc, 1,
5134 sysctl_cim_ibq_obq, "A", "CIM IBQ 1 (TP1)");
5136 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ulp",
5137 CTLTYPE_STRING | CTLFLAG_RD, sc, 2,
5138 sysctl_cim_ibq_obq, "A", "CIM IBQ 2 (ULP)");
5140 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge0",
5141 CTLTYPE_STRING | CTLFLAG_RD, sc, 3,
5142 sysctl_cim_ibq_obq, "A", "CIM IBQ 3 (SGE0)");
5144 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge1",
5145 CTLTYPE_STRING | CTLFLAG_RD, sc, 4,
5146 sysctl_cim_ibq_obq, "A", "CIM IBQ 4 (SGE1)");
5148 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ncsi",
5149 CTLTYPE_STRING | CTLFLAG_RD, sc, 5,
5150 sysctl_cim_ibq_obq, "A", "CIM IBQ 5 (NCSI)");
5152 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_la",
5153 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5154 sysctl_cim_la, "A", "CIM logic analyzer");
5156 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ma_la",
5157 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5158 sysctl_cim_ma_la, "A", "CIM MA logic analyzer");
5160 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp0",
5161 CTLTYPE_STRING | CTLFLAG_RD, sc, 0 + CIM_NUM_IBQ,
5162 sysctl_cim_ibq_obq, "A", "CIM OBQ 0 (ULP0)");
5164 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp1",
5165 CTLTYPE_STRING | CTLFLAG_RD, sc, 1 + CIM_NUM_IBQ,
5166 sysctl_cim_ibq_obq, "A", "CIM OBQ 1 (ULP1)");
5168 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp2",
5169 CTLTYPE_STRING | CTLFLAG_RD, sc, 2 + CIM_NUM_IBQ,
5170 sysctl_cim_ibq_obq, "A", "CIM OBQ 2 (ULP2)");
5172 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp3",
5173 CTLTYPE_STRING | CTLFLAG_RD, sc, 3 + CIM_NUM_IBQ,
5174 sysctl_cim_ibq_obq, "A", "CIM OBQ 3 (ULP3)");
5176 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge",
5177 CTLTYPE_STRING | CTLFLAG_RD, sc, 4 + CIM_NUM_IBQ,
5178 sysctl_cim_ibq_obq, "A", "CIM OBQ 4 (SGE)");
5180 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ncsi",
5181 CTLTYPE_STRING | CTLFLAG_RD, sc, 5 + CIM_NUM_IBQ,
5182 sysctl_cim_ibq_obq, "A", "CIM OBQ 5 (NCSI)");
5185 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge0_rx",
5186 CTLTYPE_STRING | CTLFLAG_RD, sc, 6 + CIM_NUM_IBQ,
5187 sysctl_cim_ibq_obq, "A", "CIM OBQ 6 (SGE0-RX)");
5189 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge1_rx",
5190 CTLTYPE_STRING | CTLFLAG_RD, sc, 7 + CIM_NUM_IBQ,
5191 sysctl_cim_ibq_obq, "A", "CIM OBQ 7 (SGE1-RX)");
5194 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_pif_la",
5195 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5196 sysctl_cim_pif_la, "A", "CIM PIF logic analyzer");
5198 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_qcfg",
5199 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5200 sysctl_cim_qcfg, "A", "CIM queue configuration");
5202 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cpl_stats",
5203 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5204 sysctl_cpl_stats, "A", "CPL statistics");
5206 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ddp_stats",
5207 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5208 sysctl_ddp_stats, "A", "non-TCP DDP statistics");
5210 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "devlog",
5211 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5212 sysctl_devlog, "A", "firmware's device log");
5214 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fcoe_stats",
5215 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5216 sysctl_fcoe_stats, "A", "FCoE statistics");
5218 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "hw_sched",
5219 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5220 sysctl_hw_sched, "A", "hardware scheduler ");
5222 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "l2t",
5223 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5224 sysctl_l2t, "A", "hardware L2 table");
5226 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "lb_stats",
5227 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5228 sysctl_lb_stats, "A", "loopback statistics");
5230 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "meminfo",
5231 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5232 sysctl_meminfo, "A", "memory regions");
5234 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "mps_tcam",
5235 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5236 sysctl_mps_tcam, "A", "MPS TCAM entries");
5238 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "path_mtus",
5239 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5240 sysctl_path_mtus, "A", "path MTUs");
5242 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pm_stats",
5243 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5244 sysctl_pm_stats, "A", "PM statistics");
5246 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rdma_stats",
5247 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5248 sysctl_rdma_stats, "A", "RDMA statistics");
5250 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tcp_stats",
5251 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5252 sysctl_tcp_stats, "A", "TCP statistics");
5254 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tids",
5255 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5256 sysctl_tids, "A", "TID information");
5258 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_err_stats",
5259 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5260 sysctl_tp_err_stats, "A", "TP error statistics");
5262 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_la",
5263 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5264 sysctl_tp_la, "A", "TP logic analyzer");
5266 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_rate",
5267 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5268 sysctl_tx_rate, "A", "Tx rate");
5270 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ulprx_la",
5271 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5272 sysctl_ulprx_la, "A", "ULPRX logic analyzer");
5275 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "wcwr_stats",
5276 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5277 sysctl_wcwr_stats, "A", "write combined work requests");
5282 if (is_offload(sc)) {
5286 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "toe", CTLFLAG_RD,
5287 NULL, "TOE parameters");
5288 children = SYSCTL_CHILDREN(oid);
5290 sc->tt.sndbuf = 256 * 1024;
5291 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "sndbuf", CTLFLAG_RW,
5292 &sc->tt.sndbuf, 0, "max hardware send buffer size");
5295 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ddp", CTLFLAG_RW,
5296 &sc->tt.ddp, 0, "DDP allowed");
5298 sc->tt.indsz = G_INDICATESIZE(t4_read_reg(sc, A_TP_PARA_REG5));
5299 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "indsz", CTLFLAG_RW,
5300 &sc->tt.indsz, 0, "DDP max indicate size allowed");
5303 G_RXCOALESCESIZE(t4_read_reg(sc, A_TP_PARA_REG2));
5304 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ddp_thres", CTLFLAG_RW,
5305 &sc->tt.ddp_thres, 0, "DDP threshold");
5307 sc->tt.rx_coalesce = 1;
5308 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_coalesce",
5309 CTLFLAG_RW, &sc->tt.rx_coalesce, 0, "receive coalescing");
5311 sc->tt.tx_align = 1;
5312 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_align",
5313 CTLFLAG_RW, &sc->tt.tx_align, 0, "chop and align payload");
5319 vi_sysctls(struct vi_info *vi)
5321 struct sysctl_ctx_list *ctx;
5322 struct sysctl_oid *oid;
5323 struct sysctl_oid_list *children;
5325 ctx = device_get_sysctl_ctx(vi->dev);
5328 * dev.v?(cxgbe|cxl).X.
5330 oid = device_get_sysctl_tree(vi->dev);
5331 children = SYSCTL_CHILDREN(oid);
5333 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "viid", CTLFLAG_RD, NULL,
5334 vi->viid, "VI identifer");
5335 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nrxq", CTLFLAG_RD,
5336 &vi->nrxq, 0, "# of rx queues");
5337 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ntxq", CTLFLAG_RD,
5338 &vi->ntxq, 0, "# of tx queues");
5339 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_rxq", CTLFLAG_RD,
5340 &vi->first_rxq, 0, "index of first rx queue");
5341 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_txq", CTLFLAG_RD,
5342 &vi->first_txq, 0, "index of first tx queue");
5344 if (IS_MAIN_VI(vi)) {
5345 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rsrv_noflowq",
5346 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_noflowq, "IU",
5347 "Reserve queue 0 for non-flowid packets");
5351 if (vi->nofldrxq != 0) {
5352 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldrxq", CTLFLAG_RD,
5354 "# of rx queues for offloaded TCP connections");
5355 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldtxq", CTLFLAG_RD,
5357 "# of tx queues for offloaded TCP connections");
5358 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_rxq",
5359 CTLFLAG_RD, &vi->first_ofld_rxq, 0,
5360 "index of first TOE rx queue");
5361 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_txq",
5362 CTLFLAG_RD, &vi->first_ofld_txq, 0,
5363 "index of first TOE tx queue");
5367 if (vi->nnmrxq != 0) {
5368 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmrxq", CTLFLAG_RD,
5369 &vi->nnmrxq, 0, "# of netmap rx queues");
5370 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmtxq", CTLFLAG_RD,
5371 &vi->nnmtxq, 0, "# of netmap tx queues");
5372 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_rxq",
5373 CTLFLAG_RD, &vi->first_nm_rxq, 0,
5374 "index of first netmap rx queue");
5375 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_txq",
5376 CTLFLAG_RD, &vi->first_nm_txq, 0,
5377 "index of first netmap tx queue");
5381 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx",
5382 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_holdoff_tmr_idx, "I",
5383 "holdoff timer index");
5384 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx",
5385 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_holdoff_pktc_idx, "I",
5386 "holdoff packet counter index");
5388 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_rxq",
5389 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_qsize_rxq, "I",
5391 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_txq",
5392 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_qsize_txq, "I",
5397 cxgbe_sysctls(struct port_info *pi)
5399 struct sysctl_ctx_list *ctx;
5400 struct sysctl_oid *oid;
5401 struct sysctl_oid_list *children;
5402 struct adapter *sc = pi->adapter;
5404 ctx = device_get_sysctl_ctx(pi->dev);
5409 oid = device_get_sysctl_tree(pi->dev);
5410 children = SYSCTL_CHILDREN(oid);
5412 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "linkdnrc", CTLTYPE_STRING |
5413 CTLFLAG_RD, pi, 0, sysctl_linkdnrc, "A", "reason why link is down");
5414 if (pi->port_type == FW_PORT_TYPE_BT_XAUI) {
5415 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature",
5416 CTLTYPE_INT | CTLFLAG_RD, pi, 0, sysctl_btphy, "I",
5417 "PHY temperature (in Celsius)");
5418 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fw_version",
5419 CTLTYPE_INT | CTLFLAG_RD, pi, 1, sysctl_btphy, "I",
5420 "PHY firmware version");
5423 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pause_settings",
5424 CTLTYPE_STRING | CTLFLAG_RW, pi, PAUSE_TX, sysctl_pause_settings,
5425 "A", "PAUSE settings (bit 0 = rx_pause, bit 1 = tx_pause)");
5428 * dev.cxgbe.X.stats.
5430 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats", CTLFLAG_RD,
5431 NULL, "port statistics");
5432 children = SYSCTL_CHILDREN(oid);
5433 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "tx_parse_error", CTLFLAG_RD,
5434 &pi->tx_parse_error, 0,
5435 "# of tx packets with invalid length or # of segments");
5437 #define SYSCTL_ADD_T4_REG64(pi, name, desc, reg) \
5438 SYSCTL_ADD_OID(ctx, children, OID_AUTO, name, \
5439 CTLTYPE_U64 | CTLFLAG_RD, sc, reg, \
5440 sysctl_handle_t4_reg64, "QU", desc)
5442 SYSCTL_ADD_T4_REG64(pi, "tx_octets", "# of octets in good frames",
5443 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BYTES_L));
5444 SYSCTL_ADD_T4_REG64(pi, "tx_frames", "total # of good frames",
5445 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_FRAMES_L));
5446 SYSCTL_ADD_T4_REG64(pi, "tx_bcast_frames", "# of broadcast frames",
5447 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BCAST_L));
5448 SYSCTL_ADD_T4_REG64(pi, "tx_mcast_frames", "# of multicast frames",
5449 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_MCAST_L));
5450 SYSCTL_ADD_T4_REG64(pi, "tx_ucast_frames", "# of unicast frames",
5451 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_UCAST_L));
5452 SYSCTL_ADD_T4_REG64(pi, "tx_error_frames", "# of error frames",
5453 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_ERROR_L));
5454 SYSCTL_ADD_T4_REG64(pi, "tx_frames_64",
5455 "# of tx frames in this range",
5456 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_64B_L));
5457 SYSCTL_ADD_T4_REG64(pi, "tx_frames_65_127",
5458 "# of tx frames in this range",
5459 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_65B_127B_L));
5460 SYSCTL_ADD_T4_REG64(pi, "tx_frames_128_255",
5461 "# of tx frames in this range",
5462 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_128B_255B_L));
5463 SYSCTL_ADD_T4_REG64(pi, "tx_frames_256_511",
5464 "# of tx frames in this range",
5465 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_256B_511B_L));
5466 SYSCTL_ADD_T4_REG64(pi, "tx_frames_512_1023",
5467 "# of tx frames in this range",
5468 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_512B_1023B_L));
5469 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1024_1518",
5470 "# of tx frames in this range",
5471 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1024B_1518B_L));
5472 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1519_max",
5473 "# of tx frames in this range",
5474 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1519B_MAX_L));
5475 SYSCTL_ADD_T4_REG64(pi, "tx_drop", "# of dropped tx frames",
5476 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_DROP_L));
5477 SYSCTL_ADD_T4_REG64(pi, "tx_pause", "# of pause frames transmitted",
5478 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PAUSE_L));
5479 SYSCTL_ADD_T4_REG64(pi, "tx_ppp0", "# of PPP prio 0 frames transmitted",
5480 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP0_L));
5481 SYSCTL_ADD_T4_REG64(pi, "tx_ppp1", "# of PPP prio 1 frames transmitted",
5482 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP1_L));
5483 SYSCTL_ADD_T4_REG64(pi, "tx_ppp2", "# of PPP prio 2 frames transmitted",
5484 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP2_L));
5485 SYSCTL_ADD_T4_REG64(pi, "tx_ppp3", "# of PPP prio 3 frames transmitted",
5486 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP3_L));
5487 SYSCTL_ADD_T4_REG64(pi, "tx_ppp4", "# of PPP prio 4 frames transmitted",
5488 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP4_L));
5489 SYSCTL_ADD_T4_REG64(pi, "tx_ppp5", "# of PPP prio 5 frames transmitted",
5490 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP5_L));
5491 SYSCTL_ADD_T4_REG64(pi, "tx_ppp6", "# of PPP prio 6 frames transmitted",
5492 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP6_L));
5493 SYSCTL_ADD_T4_REG64(pi, "tx_ppp7", "# of PPP prio 7 frames transmitted",
5494 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP7_L));
5496 SYSCTL_ADD_T4_REG64(pi, "rx_octets", "# of octets in good frames",
5497 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BYTES_L));
5498 SYSCTL_ADD_T4_REG64(pi, "rx_frames", "total # of good frames",
5499 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_FRAMES_L));
5500 SYSCTL_ADD_T4_REG64(pi, "rx_bcast_frames", "# of broadcast frames",
5501 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BCAST_L));
5502 SYSCTL_ADD_T4_REG64(pi, "rx_mcast_frames", "# of multicast frames",
5503 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MCAST_L));
5504 SYSCTL_ADD_T4_REG64(pi, "rx_ucast_frames", "# of unicast frames",
5505 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_UCAST_L));
5506 SYSCTL_ADD_T4_REG64(pi, "rx_too_long", "# of frames exceeding MTU",
5507 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_ERROR_L));
5508 SYSCTL_ADD_T4_REG64(pi, "rx_jabber", "# of jabber frames",
5509 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_CRC_ERROR_L));
5510 SYSCTL_ADD_T4_REG64(pi, "rx_fcs_err",
5511 "# of frames received with bad FCS",
5512 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_CRC_ERROR_L));
5513 SYSCTL_ADD_T4_REG64(pi, "rx_len_err",
5514 "# of frames received with length error",
5515 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LEN_ERROR_L));
5516 SYSCTL_ADD_T4_REG64(pi, "rx_symbol_err", "symbol errors",
5517 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_SYM_ERROR_L));
5518 SYSCTL_ADD_T4_REG64(pi, "rx_runt", "# of short frames received",
5519 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LESS_64B_L));
5520 SYSCTL_ADD_T4_REG64(pi, "rx_frames_64",
5521 "# of rx frames in this range",
5522 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_64B_L));
5523 SYSCTL_ADD_T4_REG64(pi, "rx_frames_65_127",
5524 "# of rx frames in this range",
5525 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_65B_127B_L));
5526 SYSCTL_ADD_T4_REG64(pi, "rx_frames_128_255",
5527 "# of rx frames in this range",
5528 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_128B_255B_L));
5529 SYSCTL_ADD_T4_REG64(pi, "rx_frames_256_511",
5530 "# of rx frames in this range",
5531 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_256B_511B_L));
5532 SYSCTL_ADD_T4_REG64(pi, "rx_frames_512_1023",
5533 "# of rx frames in this range",
5534 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_512B_1023B_L));
5535 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1024_1518",
5536 "# of rx frames in this range",
5537 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1024B_1518B_L));
5538 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1519_max",
5539 "# of rx frames in this range",
5540 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1519B_MAX_L));
5541 SYSCTL_ADD_T4_REG64(pi, "rx_pause", "# of pause frames received",
5542 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PAUSE_L));
5543 SYSCTL_ADD_T4_REG64(pi, "rx_ppp0", "# of PPP prio 0 frames received",
5544 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP0_L));
5545 SYSCTL_ADD_T4_REG64(pi, "rx_ppp1", "# of PPP prio 1 frames received",
5546 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP1_L));
5547 SYSCTL_ADD_T4_REG64(pi, "rx_ppp2", "# of PPP prio 2 frames received",
5548 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP2_L));
5549 SYSCTL_ADD_T4_REG64(pi, "rx_ppp3", "# of PPP prio 3 frames received",
5550 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP3_L));
5551 SYSCTL_ADD_T4_REG64(pi, "rx_ppp4", "# of PPP prio 4 frames received",
5552 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP4_L));
5553 SYSCTL_ADD_T4_REG64(pi, "rx_ppp5", "# of PPP prio 5 frames received",
5554 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP5_L));
5555 SYSCTL_ADD_T4_REG64(pi, "rx_ppp6", "# of PPP prio 6 frames received",
5556 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP6_L));
5557 SYSCTL_ADD_T4_REG64(pi, "rx_ppp7", "# of PPP prio 7 frames received",
5558 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP7_L));
5560 #undef SYSCTL_ADD_T4_REG64
5562 #define SYSCTL_ADD_T4_PORTSTAT(name, desc) \
5563 SYSCTL_ADD_UQUAD(ctx, children, OID_AUTO, #name, CTLFLAG_RD, \
5564 &pi->stats.name, desc)
5566 /* We get these from port_stats and they may be stale by upto 1s */
5567 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow0,
5568 "# drops due to buffer-group 0 overflows");
5569 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow1,
5570 "# drops due to buffer-group 1 overflows");
5571 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow2,
5572 "# drops due to buffer-group 2 overflows");
5573 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow3,
5574 "# drops due to buffer-group 3 overflows");
5575 SYSCTL_ADD_T4_PORTSTAT(rx_trunc0,
5576 "# of buffer-group 0 truncated packets");
5577 SYSCTL_ADD_T4_PORTSTAT(rx_trunc1,
5578 "# of buffer-group 1 truncated packets");
5579 SYSCTL_ADD_T4_PORTSTAT(rx_trunc2,
5580 "# of buffer-group 2 truncated packets");
5581 SYSCTL_ADD_T4_PORTSTAT(rx_trunc3,
5582 "# of buffer-group 3 truncated packets");
5584 #undef SYSCTL_ADD_T4_PORTSTAT
5588 sysctl_int_array(SYSCTL_HANDLER_ARGS)
5590 int rc, *i, space = 0;
5593 sbuf_new(&sb, NULL, 32, SBUF_AUTOEXTEND);
5594 for (i = arg1; arg2; arg2 -= sizeof(int), i++) {
5596 sbuf_printf(&sb, " ");
5597 sbuf_printf(&sb, "%d", *i);
5601 rc = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
5607 sysctl_bitfield(SYSCTL_HANDLER_ARGS)
5612 rc = sysctl_wire_old_buffer(req, 0);
5616 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
5620 sbuf_printf(sb, "%b", (int)arg2, (char *)arg1);
5621 rc = sbuf_finish(sb);
5628 sysctl_btphy(SYSCTL_HANDLER_ARGS)
5630 struct port_info *pi = arg1;
5632 struct adapter *sc = pi->adapter;
5636 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK, "t4btt");
5639 /* XXX: magic numbers */
5640 rc = -t4_mdio_rd(sc, sc->mbox, pi->mdio_addr, 0x1e, op ? 0x20 : 0xc820,
5642 end_synchronized_op(sc, 0);
5648 rc = sysctl_handle_int(oidp, &v, 0, req);
5653 sysctl_noflowq(SYSCTL_HANDLER_ARGS)
5655 struct vi_info *vi = arg1;
5658 val = vi->rsrv_noflowq;
5659 rc = sysctl_handle_int(oidp, &val, 0, req);
5660 if (rc != 0 || req->newptr == NULL)
5663 if ((val >= 1) && (vi->ntxq > 1))
5664 vi->rsrv_noflowq = 1;
5666 vi->rsrv_noflowq = 0;
5672 sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS)
5674 struct vi_info *vi = arg1;
5675 struct adapter *sc = vi->pi->adapter;
5677 struct sge_rxq *rxq;
5679 struct sge_ofld_rxq *ofld_rxq;
5685 rc = sysctl_handle_int(oidp, &idx, 0, req);
5686 if (rc != 0 || req->newptr == NULL)
5689 if (idx < 0 || idx >= SGE_NTIMERS)
5692 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5697 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(vi->pktc_idx != -1);
5698 for_each_rxq(vi, i, rxq) {
5699 #ifdef atomic_store_rel_8
5700 atomic_store_rel_8(&rxq->iq.intr_params, v);
5702 rxq->iq.intr_params = v;
5706 for_each_ofld_rxq(vi, i, ofld_rxq) {
5707 #ifdef atomic_store_rel_8
5708 atomic_store_rel_8(&ofld_rxq->iq.intr_params, v);
5710 ofld_rxq->iq.intr_params = v;
5716 end_synchronized_op(sc, LOCK_HELD);
5721 sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS)
5723 struct vi_info *vi = arg1;
5724 struct adapter *sc = vi->pi->adapter;
5729 rc = sysctl_handle_int(oidp, &idx, 0, req);
5730 if (rc != 0 || req->newptr == NULL)
5733 if (idx < -1 || idx >= SGE_NCOUNTERS)
5736 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5741 if (vi->flags & VI_INIT_DONE)
5742 rc = EBUSY; /* cannot be changed once the queues are created */
5746 end_synchronized_op(sc, LOCK_HELD);
5751 sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS)
5753 struct vi_info *vi = arg1;
5754 struct adapter *sc = vi->pi->adapter;
5757 qsize = vi->qsize_rxq;
5759 rc = sysctl_handle_int(oidp, &qsize, 0, req);
5760 if (rc != 0 || req->newptr == NULL)
5763 if (qsize < 128 || (qsize & 7))
5766 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5771 if (vi->flags & VI_INIT_DONE)
5772 rc = EBUSY; /* cannot be changed once the queues are created */
5774 vi->qsize_rxq = qsize;
5776 end_synchronized_op(sc, LOCK_HELD);
5781 sysctl_qsize_txq(SYSCTL_HANDLER_ARGS)
5783 struct vi_info *vi = arg1;
5784 struct adapter *sc = vi->pi->adapter;
5787 qsize = vi->qsize_txq;
5789 rc = sysctl_handle_int(oidp, &qsize, 0, req);
5790 if (rc != 0 || req->newptr == NULL)
5793 if (qsize < 128 || qsize > 65536)
5796 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5801 if (vi->flags & VI_INIT_DONE)
5802 rc = EBUSY; /* cannot be changed once the queues are created */
5804 vi->qsize_txq = qsize;
5806 end_synchronized_op(sc, LOCK_HELD);
5811 sysctl_pause_settings(SYSCTL_HANDLER_ARGS)
5813 struct port_info *pi = arg1;
5814 struct adapter *sc = pi->adapter;
5815 struct link_config *lc = &pi->link_cfg;
5818 if (req->newptr == NULL) {
5820 static char *bits = "\20\1PAUSE_RX\2PAUSE_TX";
5822 rc = sysctl_wire_old_buffer(req, 0);
5826 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
5830 sbuf_printf(sb, "%b", lc->fc & (PAUSE_TX | PAUSE_RX), bits);
5831 rc = sbuf_finish(sb);
5837 s[0] = '0' + (lc->requested_fc & (PAUSE_TX | PAUSE_RX));
5840 rc = sysctl_handle_string(oidp, s, sizeof(s), req);
5846 if (s[0] < '0' || s[0] > '9')
5847 return (EINVAL); /* not a number */
5849 if (n & ~(PAUSE_TX | PAUSE_RX))
5850 return (EINVAL); /* some other bit is set too */
5852 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK,
5856 if ((lc->requested_fc & (PAUSE_TX | PAUSE_RX)) != n) {
5857 int link_ok = lc->link_ok;
5859 lc->requested_fc &= ~(PAUSE_TX | PAUSE_RX);
5860 lc->requested_fc |= n;
5861 rc = -t4_link_start(sc, sc->mbox, pi->tx_chan, lc);
5862 lc->link_ok = link_ok; /* restore */
5864 end_synchronized_op(sc, 0);
5871 sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS)
5873 struct adapter *sc = arg1;
5877 val = t4_read_reg64(sc, reg);
5879 return (sysctl_handle_64(oidp, &val, 0, req));
5883 sysctl_temperature(SYSCTL_HANDLER_ARGS)
5885 struct adapter *sc = arg1;
5887 uint32_t param, val;
5889 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4temp");
5892 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
5893 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) |
5894 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_TMP);
5895 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
5896 end_synchronized_op(sc, 0);
5900 /* unknown is returned as 0 but we display -1 in that case */
5901 t = val == 0 ? -1 : val;
5903 rc = sysctl_handle_int(oidp, &t, 0, req);
5909 sysctl_cctrl(SYSCTL_HANDLER_ARGS)
5911 struct adapter *sc = arg1;
5914 uint16_t incr[NMTUS][NCCTRL_WIN];
5915 static const char *dec_fac[] = {
5916 "0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
5920 rc = sysctl_wire_old_buffer(req, 0);
5924 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
5928 t4_read_cong_tbl(sc, incr);
5930 for (i = 0; i < NCCTRL_WIN; ++i) {
5931 sbuf_printf(sb, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
5932 incr[0][i], incr[1][i], incr[2][i], incr[3][i], incr[4][i],
5933 incr[5][i], incr[6][i], incr[7][i]);
5934 sbuf_printf(sb, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
5935 incr[8][i], incr[9][i], incr[10][i], incr[11][i],
5936 incr[12][i], incr[13][i], incr[14][i], incr[15][i],
5937 sc->params.a_wnd[i], dec_fac[sc->params.b_wnd[i]]);
5940 rc = sbuf_finish(sb);
5946 static const char *qname[CIM_NUM_IBQ + CIM_NUM_OBQ_T5] = {
5947 "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI", /* ibq's */
5948 "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI", /* obq's */
5949 "SGE0-RX", "SGE1-RX" /* additional obq's (T5 onwards) */
5953 sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS)
5955 struct adapter *sc = arg1;
5957 int rc, i, n, qid = arg2;
5960 u_int cim_num_obq = is_t4(sc) ? CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
5962 KASSERT(qid >= 0 && qid < CIM_NUM_IBQ + cim_num_obq,
5963 ("%s: bad qid %d\n", __func__, qid));
5965 if (qid < CIM_NUM_IBQ) {
5968 n = 4 * CIM_IBQ_SIZE;
5969 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
5970 rc = t4_read_cim_ibq(sc, qid, buf, n);
5972 /* outbound queue */
5975 n = 4 * cim_num_obq * CIM_OBQ_SIZE;
5976 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
5977 rc = t4_read_cim_obq(sc, qid, buf, n);
5984 n = rc * sizeof(uint32_t); /* rc has # of words actually read */
5986 rc = sysctl_wire_old_buffer(req, 0);
5990 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
5996 sbuf_printf(sb, "%s%d %s", qtype , qid, qname[arg2]);
5997 for (i = 0, p = buf; i < n; i += 16, p += 4)
5998 sbuf_printf(sb, "\n%#06x: %08x %08x %08x %08x", i, p[0], p[1],
6001 rc = sbuf_finish(sb);
6009 sysctl_cim_la(SYSCTL_HANDLER_ARGS)
6011 struct adapter *sc = arg1;
6017 rc = -t4_cim_read(sc, A_UP_UP_DBG_LA_CFG, 1, &cfg);
6021 rc = sysctl_wire_old_buffer(req, 0);
6025 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6029 buf = malloc(sc->params.cim_la_size * sizeof(uint32_t), M_CXGBE,
6032 rc = -t4_cim_read_la(sc, buf, NULL);
6036 sbuf_printf(sb, "Status Data PC%s",
6037 cfg & F_UPDBGLACAPTPCONLY ? "" :
6038 " LS0Stat LS0Addr LS0Data");
6040 KASSERT((sc->params.cim_la_size & 7) == 0,
6041 ("%s: p will walk off the end of buf", __func__));
6043 for (p = buf; p < &buf[sc->params.cim_la_size]; p += 8) {
6044 if (cfg & F_UPDBGLACAPTPCONLY) {
6045 sbuf_printf(sb, "\n %02x %08x %08x", p[5] & 0xff,
6047 sbuf_printf(sb, "\n %02x %02x%06x %02x%06x",
6048 (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8,
6049 p[4] & 0xff, p[5] >> 8);
6050 sbuf_printf(sb, "\n %02x %x%07x %x%07x",
6051 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
6052 p[1] & 0xf, p[2] >> 4);
6055 "\n %02x %x%07x %x%07x %08x %08x "
6057 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
6058 p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5],
6063 rc = sbuf_finish(sb);
6071 sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS)
6073 struct adapter *sc = arg1;
6079 rc = sysctl_wire_old_buffer(req, 0);
6083 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6087 buf = malloc(2 * CIM_MALA_SIZE * 5 * sizeof(uint32_t), M_CXGBE,
6090 t4_cim_read_ma_la(sc, buf, buf + 5 * CIM_MALA_SIZE);
6093 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
6094 sbuf_printf(sb, "\n%02x%08x%08x%08x%08x", p[4], p[3], p[2],
6098 sbuf_printf(sb, "\n\nCnt ID Tag UE Data RDY VLD");
6099 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
6100 sbuf_printf(sb, "\n%3u %2u %x %u %08x%08x %u %u",
6101 (p[2] >> 10) & 0xff, (p[2] >> 7) & 7,
6102 (p[2] >> 3) & 0xf, (p[2] >> 2) & 1,
6103 (p[1] >> 2) | ((p[2] & 3) << 30),
6104 (p[0] >> 2) | ((p[1] & 3) << 30), (p[0] >> 1) & 1,
6108 rc = sbuf_finish(sb);
6115 sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS)
6117 struct adapter *sc = arg1;
6123 rc = sysctl_wire_old_buffer(req, 0);
6127 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6131 buf = malloc(2 * CIM_PIFLA_SIZE * 6 * sizeof(uint32_t), M_CXGBE,
6134 t4_cim_read_pif_la(sc, buf, buf + 6 * CIM_PIFLA_SIZE, NULL, NULL);
6137 sbuf_printf(sb, "Cntl ID DataBE Addr Data");
6138 for (i = 0; i < CIM_MALA_SIZE; i++, p += 6) {
6139 sbuf_printf(sb, "\n %02x %02x %04x %08x %08x%08x%08x%08x",
6140 (p[5] >> 22) & 0xff, (p[5] >> 16) & 0x3f, p[5] & 0xffff,
6141 p[4], p[3], p[2], p[1], p[0]);
6144 sbuf_printf(sb, "\n\nCntl ID Data");
6145 for (i = 0; i < CIM_MALA_SIZE; i++, p += 6) {
6146 sbuf_printf(sb, "\n %02x %02x %08x%08x%08x%08x",
6147 (p[4] >> 6) & 0xff, p[4] & 0x3f, p[3], p[2], p[1], p[0]);
6150 rc = sbuf_finish(sb);
6157 sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS)
6159 struct adapter *sc = arg1;
6162 uint16_t base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
6163 uint16_t size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
6164 uint16_t thres[CIM_NUM_IBQ];
6165 uint32_t obq_wr[2 * CIM_NUM_OBQ_T5], *wr = obq_wr;
6166 uint32_t stat[4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5)], *p = stat;
6167 u_int cim_num_obq, ibq_rdaddr, obq_rdaddr, nq;
6170 cim_num_obq = CIM_NUM_OBQ;
6171 ibq_rdaddr = A_UP_IBQ_0_RDADDR;
6172 obq_rdaddr = A_UP_OBQ_0_REALADDR;
6174 cim_num_obq = CIM_NUM_OBQ_T5;
6175 ibq_rdaddr = A_UP_IBQ_0_SHADOW_RDADDR;
6176 obq_rdaddr = A_UP_OBQ_0_SHADOW_REALADDR;
6178 nq = CIM_NUM_IBQ + cim_num_obq;
6180 rc = -t4_cim_read(sc, ibq_rdaddr, 4 * nq, stat);
6182 rc = -t4_cim_read(sc, obq_rdaddr, 2 * cim_num_obq, obq_wr);
6186 t4_read_cimq_cfg(sc, base, size, thres);
6188 rc = sysctl_wire_old_buffer(req, 0);
6192 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
6196 sbuf_printf(sb, "Queue Base Size Thres RdPtr WrPtr SOP EOP Avail");
6198 for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
6199 sbuf_printf(sb, "\n%7s %5x %5u %5u %6x %4x %4u %4u %5u",
6200 qname[i], base[i], size[i], thres[i], G_IBQRDADDR(p[0]),
6201 G_IBQWRADDR(p[1]), G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
6202 G_QUEREMFLITS(p[2]) * 16);
6203 for ( ; i < nq; i++, p += 4, wr += 2)
6204 sbuf_printf(sb, "\n%7s %5x %5u %12x %4x %4u %4u %5u", qname[i],
6205 base[i], size[i], G_QUERDADDR(p[0]) & 0x3fff,
6206 wr[0] - base[i], G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
6207 G_QUEREMFLITS(p[2]) * 16);
6209 rc = sbuf_finish(sb);
6216 sysctl_cpl_stats(SYSCTL_HANDLER_ARGS)
6218 struct adapter *sc = arg1;
6221 struct tp_cpl_stats stats;
6223 rc = sysctl_wire_old_buffer(req, 0);
6227 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6231 t4_tp_get_cpl_stats(sc, &stats);
6233 sbuf_printf(sb, " channel 0 channel 1 channel 2 "
6235 sbuf_printf(sb, "CPL requests: %10u %10u %10u %10u\n",
6236 stats.req[0], stats.req[1], stats.req[2], stats.req[3]);
6237 sbuf_printf(sb, "CPL responses: %10u %10u %10u %10u",
6238 stats.rsp[0], stats.rsp[1], stats.rsp[2], stats.rsp[3]);
6240 rc = sbuf_finish(sb);
6247 sysctl_ddp_stats(SYSCTL_HANDLER_ARGS)
6249 struct adapter *sc = arg1;
6252 struct tp_usm_stats stats;
6254 rc = sysctl_wire_old_buffer(req, 0);
6258 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6262 t4_get_usm_stats(sc, &stats);
6264 sbuf_printf(sb, "Frames: %u\n", stats.frames);
6265 sbuf_printf(sb, "Octets: %ju\n", stats.octets);
6266 sbuf_printf(sb, "Drops: %u", stats.drops);
6268 rc = sbuf_finish(sb);
6274 const char *devlog_level_strings[] = {
6275 [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
6276 [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
6277 [FW_DEVLOG_LEVEL_ERR] = "ERR",
6278 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
6279 [FW_DEVLOG_LEVEL_INFO] = "INFO",
6280 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
6283 const char *devlog_facility_strings[] = {
6284 [FW_DEVLOG_FACILITY_CORE] = "CORE",
6285 [FW_DEVLOG_FACILITY_CF] = "CF",
6286 [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
6287 [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
6288 [FW_DEVLOG_FACILITY_RES] = "RES",
6289 [FW_DEVLOG_FACILITY_HW] = "HW",
6290 [FW_DEVLOG_FACILITY_FLR] = "FLR",
6291 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
6292 [FW_DEVLOG_FACILITY_PHY] = "PHY",
6293 [FW_DEVLOG_FACILITY_MAC] = "MAC",
6294 [FW_DEVLOG_FACILITY_PORT] = "PORT",
6295 [FW_DEVLOG_FACILITY_VI] = "VI",
6296 [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
6297 [FW_DEVLOG_FACILITY_ACL] = "ACL",
6298 [FW_DEVLOG_FACILITY_TM] = "TM",
6299 [FW_DEVLOG_FACILITY_QFC] = "QFC",
6300 [FW_DEVLOG_FACILITY_DCB] = "DCB",
6301 [FW_DEVLOG_FACILITY_ETH] = "ETH",
6302 [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
6303 [FW_DEVLOG_FACILITY_RI] = "RI",
6304 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
6305 [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
6306 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
6307 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE"
6311 sysctl_devlog(SYSCTL_HANDLER_ARGS)
6313 struct adapter *sc = arg1;
6314 struct devlog_params *dparams = &sc->params.devlog;
6315 struct fw_devlog_e *buf, *e;
6316 int i, j, rc, nentries, first = 0, m;
6318 uint64_t ftstamp = UINT64_MAX;
6320 if (dparams->start == 0) {
6321 dparams->memtype = FW_MEMTYPE_EDC0;
6322 dparams->start = 0x84000;
6323 dparams->size = 32768;
6326 nentries = dparams->size / sizeof(struct fw_devlog_e);
6328 buf = malloc(dparams->size, M_CXGBE, M_NOWAIT);
6332 m = fwmtype_to_hwmtype(dparams->memtype);
6333 rc = -t4_mem_read(sc, m, dparams->start, dparams->size, (void *)buf);
6337 for (i = 0; i < nentries; i++) {
6340 if (e->timestamp == 0)
6343 e->timestamp = be64toh(e->timestamp);
6344 e->seqno = be32toh(e->seqno);
6345 for (j = 0; j < 8; j++)
6346 e->params[j] = be32toh(e->params[j]);
6348 if (e->timestamp < ftstamp) {
6349 ftstamp = e->timestamp;
6354 if (buf[first].timestamp == 0)
6355 goto done; /* nothing in the log */
6357 rc = sysctl_wire_old_buffer(req, 0);
6361 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6366 sbuf_printf(sb, "%10s %15s %8s %8s %s\n",
6367 "Seq#", "Tstamp", "Level", "Facility", "Message");
6372 if (e->timestamp == 0)
6375 sbuf_printf(sb, "%10d %15ju %8s %8s ",
6376 e->seqno, e->timestamp,
6377 (e->level < nitems(devlog_level_strings) ?
6378 devlog_level_strings[e->level] : "UNKNOWN"),
6379 (e->facility < nitems(devlog_facility_strings) ?
6380 devlog_facility_strings[e->facility] : "UNKNOWN"));
6381 sbuf_printf(sb, e->fmt, e->params[0], e->params[1],
6382 e->params[2], e->params[3], e->params[4],
6383 e->params[5], e->params[6], e->params[7]);
6385 if (++i == nentries)
6387 } while (i != first);
6389 rc = sbuf_finish(sb);
6397 sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS)
6399 struct adapter *sc = arg1;
6402 struct tp_fcoe_stats stats[4];
6404 rc = sysctl_wire_old_buffer(req, 0);
6408 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6412 t4_get_fcoe_stats(sc, 0, &stats[0]);
6413 t4_get_fcoe_stats(sc, 1, &stats[1]);
6414 t4_get_fcoe_stats(sc, 2, &stats[2]);
6415 t4_get_fcoe_stats(sc, 3, &stats[3]);
6417 sbuf_printf(sb, " channel 0 channel 1 "
6418 "channel 2 channel 3\n");
6419 sbuf_printf(sb, "octetsDDP: %16ju %16ju %16ju %16ju\n",
6420 stats[0].octetsDDP, stats[1].octetsDDP, stats[2].octetsDDP,
6421 stats[3].octetsDDP);
6422 sbuf_printf(sb, "framesDDP: %16u %16u %16u %16u\n", stats[0].framesDDP,
6423 stats[1].framesDDP, stats[2].framesDDP, stats[3].framesDDP);
6424 sbuf_printf(sb, "framesDrop: %16u %16u %16u %16u",
6425 stats[0].framesDrop, stats[1].framesDrop, stats[2].framesDrop,
6426 stats[3].framesDrop);
6428 rc = sbuf_finish(sb);
6435 sysctl_hw_sched(SYSCTL_HANDLER_ARGS)
6437 struct adapter *sc = arg1;
6440 unsigned int map, kbps, ipg, mode;
6441 unsigned int pace_tab[NTX_SCHED];
6443 rc = sysctl_wire_old_buffer(req, 0);
6447 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6451 map = t4_read_reg(sc, A_TP_TX_MOD_QUEUE_REQ_MAP);
6452 mode = G_TIMERMODE(t4_read_reg(sc, A_TP_MOD_CONFIG));
6453 t4_read_pace_tbl(sc, pace_tab);
6455 sbuf_printf(sb, "Scheduler Mode Channel Rate (Kbps) "
6456 "Class IPG (0.1 ns) Flow IPG (us)");
6458 for (i = 0; i < NTX_SCHED; ++i, map >>= 2) {
6459 t4_get_tx_sched(sc, i, &kbps, &ipg);
6460 sbuf_printf(sb, "\n %u %-5s %u ", i,
6461 (mode & (1 << i)) ? "flow" : "class", map & 3);
6463 sbuf_printf(sb, "%9u ", kbps);
6465 sbuf_printf(sb, " disabled ");
6468 sbuf_printf(sb, "%13u ", ipg);
6470 sbuf_printf(sb, " disabled ");
6473 sbuf_printf(sb, "%10u", pace_tab[i]);
6475 sbuf_printf(sb, " disabled");
6478 rc = sbuf_finish(sb);
6485 sysctl_lb_stats(SYSCTL_HANDLER_ARGS)
6487 struct adapter *sc = arg1;
6491 struct lb_port_stats s[2];
6492 static const char *stat_name[] = {
6493 "OctetsOK:", "FramesOK:", "BcastFrames:", "McastFrames:",
6494 "UcastFrames:", "ErrorFrames:", "Frames64:", "Frames65To127:",
6495 "Frames128To255:", "Frames256To511:", "Frames512To1023:",
6496 "Frames1024To1518:", "Frames1519ToMax:", "FramesDropped:",
6497 "BG0FramesDropped:", "BG1FramesDropped:", "BG2FramesDropped:",
6498 "BG3FramesDropped:", "BG0FramesTrunc:", "BG1FramesTrunc:",
6499 "BG2FramesTrunc:", "BG3FramesTrunc:"
6502 rc = sysctl_wire_old_buffer(req, 0);
6506 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6510 memset(s, 0, sizeof(s));
6512 for (i = 0; i < 4; i += 2) {
6513 t4_get_lb_stats(sc, i, &s[0]);
6514 t4_get_lb_stats(sc, i + 1, &s[1]);
6518 sbuf_printf(sb, "%s Loopback %u"
6519 " Loopback %u", i == 0 ? "" : "\n", i, i + 1);
6521 for (j = 0; j < nitems(stat_name); j++)
6522 sbuf_printf(sb, "\n%-17s %20ju %20ju", stat_name[j],
6526 rc = sbuf_finish(sb);
6533 sysctl_linkdnrc(SYSCTL_HANDLER_ARGS)
6536 struct port_info *pi = arg1;
6538 static const char *linkdnreasons[] = {
6539 "non-specific", "remote fault", "autoneg failed", "reserved3",
6540 "PHY overheated", "unknown", "rx los", "reserved7"
6543 rc = sysctl_wire_old_buffer(req, 0);
6546 sb = sbuf_new_for_sysctl(NULL, NULL, 64, req);
6550 if (pi->linkdnrc < 0)
6551 sbuf_printf(sb, "n/a");
6552 else if (pi->linkdnrc < nitems(linkdnreasons))
6553 sbuf_printf(sb, "%s", linkdnreasons[pi->linkdnrc]);
6555 sbuf_printf(sb, "%d", pi->linkdnrc);
6557 rc = sbuf_finish(sb);
6570 mem_desc_cmp(const void *a, const void *b)
6572 return ((const struct mem_desc *)a)->base -
6573 ((const struct mem_desc *)b)->base;
6577 mem_region_show(struct sbuf *sb, const char *name, unsigned int from,
6582 size = to - from + 1;
6586 /* XXX: need humanize_number(3) in libkern for a more readable 'size' */
6587 sbuf_printf(sb, "%-15s %#x-%#x [%u]\n", name, from, to, size);
6591 sysctl_meminfo(SYSCTL_HANDLER_ARGS)
6593 struct adapter *sc = arg1;
6596 uint32_t lo, hi, used, alloc;
6597 static const char *memory[] = {"EDC0:", "EDC1:", "MC:", "MC0:", "MC1:"};
6598 static const char *region[] = {
6599 "DBQ contexts:", "IMSG contexts:", "FLM cache:", "TCBs:",
6600 "Pstructs:", "Timers:", "Rx FL:", "Tx FL:", "Pstruct FL:",
6601 "Tx payload:", "Rx payload:", "LE hash:", "iSCSI region:",
6602 "TDDP region:", "TPT region:", "STAG region:", "RQ region:",
6603 "RQUDP region:", "PBL region:", "TXPBL region:",
6604 "DBVFIFO region:", "ULPRX state:", "ULPTX state:",
6607 struct mem_desc avail[4];
6608 struct mem_desc mem[nitems(region) + 3]; /* up to 3 holes */
6609 struct mem_desc *md = mem;
6611 rc = sysctl_wire_old_buffer(req, 0);
6615 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6619 for (i = 0; i < nitems(mem); i++) {
6624 /* Find and sort the populated memory ranges */
6626 lo = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
6627 if (lo & F_EDRAM0_ENABLE) {
6628 hi = t4_read_reg(sc, A_MA_EDRAM0_BAR);
6629 avail[i].base = G_EDRAM0_BASE(hi) << 20;
6630 avail[i].limit = avail[i].base + (G_EDRAM0_SIZE(hi) << 20);
6634 if (lo & F_EDRAM1_ENABLE) {
6635 hi = t4_read_reg(sc, A_MA_EDRAM1_BAR);
6636 avail[i].base = G_EDRAM1_BASE(hi) << 20;
6637 avail[i].limit = avail[i].base + (G_EDRAM1_SIZE(hi) << 20);
6641 if (lo & F_EXT_MEM_ENABLE) {
6642 hi = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
6643 avail[i].base = G_EXT_MEM_BASE(hi) << 20;
6644 avail[i].limit = avail[i].base +
6645 (G_EXT_MEM_SIZE(hi) << 20);
6646 avail[i].idx = is_t4(sc) ? 2 : 3; /* Call it MC for T4 */
6649 if (!is_t4(sc) && lo & F_EXT_MEM1_ENABLE) {
6650 hi = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
6651 avail[i].base = G_EXT_MEM1_BASE(hi) << 20;
6652 avail[i].limit = avail[i].base +
6653 (G_EXT_MEM1_SIZE(hi) << 20);
6657 if (!i) /* no memory available */
6659 qsort(avail, i, sizeof(struct mem_desc), mem_desc_cmp);
6661 (md++)->base = t4_read_reg(sc, A_SGE_DBQ_CTXT_BADDR);
6662 (md++)->base = t4_read_reg(sc, A_SGE_IMSG_CTXT_BADDR);
6663 (md++)->base = t4_read_reg(sc, A_SGE_FLM_CACHE_BADDR);
6664 (md++)->base = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
6665 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_BASE);
6666 (md++)->base = t4_read_reg(sc, A_TP_CMM_TIMER_BASE);
6667 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_RX_FLST_BASE);
6668 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_TX_FLST_BASE);
6669 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_PS_FLST_BASE);
6671 /* the next few have explicit upper bounds */
6672 md->base = t4_read_reg(sc, A_TP_PMM_TX_BASE);
6673 md->limit = md->base - 1 +
6674 t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE) *
6675 G_PMTXMAXPAGE(t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE));
6678 md->base = t4_read_reg(sc, A_TP_PMM_RX_BASE);
6679 md->limit = md->base - 1 +
6680 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) *
6681 G_PMRXMAXPAGE(t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE));
6684 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
6685 hi = t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4;
6686 md->base = t4_read_reg(sc, A_LE_DB_HASH_TID_BASE);
6687 md->limit = (sc->tids.ntids - hi) * 16 + md->base - 1;
6690 md->idx = nitems(region); /* hide it */
6694 #define ulp_region(reg) \
6695 md->base = t4_read_reg(sc, A_ULP_ ## reg ## _LLIMIT);\
6696 (md++)->limit = t4_read_reg(sc, A_ULP_ ## reg ## _ULIMIT)
6698 ulp_region(RX_ISCSI);
6699 ulp_region(RX_TDDP);
6701 ulp_region(RX_STAG);
6703 ulp_region(RX_RQUDP);
6709 md->idx = nitems(region);
6710 if (!is_t4(sc) && t4_read_reg(sc, A_SGE_CONTROL2) & F_VFIFO_ENABLE) {
6711 md->base = G_BASEADDR(t4_read_reg(sc, A_SGE_DBVFIFO_BADDR));
6712 md->limit = md->base + (G_DBVFIFO_SIZE((t4_read_reg(sc,
6713 A_SGE_DBVFIFO_SIZE))) << 2) - 1;
6717 md->base = t4_read_reg(sc, A_ULP_RX_CTX_BASE);
6718 md->limit = md->base + sc->tids.ntids - 1;
6720 md->base = t4_read_reg(sc, A_ULP_TX_ERR_TABLE_BASE);
6721 md->limit = md->base + sc->tids.ntids - 1;
6724 md->base = sc->vres.ocq.start;
6725 if (sc->vres.ocq.size)
6726 md->limit = md->base + sc->vres.ocq.size - 1;
6728 md->idx = nitems(region); /* hide it */
6731 /* add any address-space holes, there can be up to 3 */
6732 for (n = 0; n < i - 1; n++)
6733 if (avail[n].limit < avail[n + 1].base)
6734 (md++)->base = avail[n].limit;
6736 (md++)->base = avail[n].limit;
6739 qsort(mem, n, sizeof(struct mem_desc), mem_desc_cmp);
6741 for (lo = 0; lo < i; lo++)
6742 mem_region_show(sb, memory[avail[lo].idx], avail[lo].base,
6743 avail[lo].limit - 1);
6745 sbuf_printf(sb, "\n");
6746 for (i = 0; i < n; i++) {
6747 if (mem[i].idx >= nitems(region))
6748 continue; /* skip holes */
6750 mem[i].limit = i < n - 1 ? mem[i + 1].base - 1 : ~0;
6751 mem_region_show(sb, region[mem[i].idx], mem[i].base,
6755 sbuf_printf(sb, "\n");
6756 lo = t4_read_reg(sc, A_CIM_SDRAM_BASE_ADDR);
6757 hi = t4_read_reg(sc, A_CIM_SDRAM_ADDR_SIZE) + lo - 1;
6758 mem_region_show(sb, "uP RAM:", lo, hi);
6760 lo = t4_read_reg(sc, A_CIM_EXTMEM2_BASE_ADDR);
6761 hi = t4_read_reg(sc, A_CIM_EXTMEM2_ADDR_SIZE) + lo - 1;
6762 mem_region_show(sb, "uP Extmem2:", lo, hi);
6764 lo = t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE);
6765 sbuf_printf(sb, "\n%u Rx pages of size %uKiB for %u channels\n",
6767 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) >> 10,
6768 (lo & F_PMRXNUMCHN) ? 2 : 1);
6770 lo = t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE);
6771 hi = t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE);
6772 sbuf_printf(sb, "%u Tx pages of size %u%ciB for %u channels\n",
6774 hi >= (1 << 20) ? (hi >> 20) : (hi >> 10),
6775 hi >= (1 << 20) ? 'M' : 'K', 1 << G_PMTXNUMCHN(lo));
6776 sbuf_printf(sb, "%u p-structs\n",
6777 t4_read_reg(sc, A_TP_CMM_MM_MAX_PSTRUCT));
6779 for (i = 0; i < 4; i++) {
6780 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV0 + i * 4);
6783 alloc = G_ALLOC(lo);
6785 used = G_T5_USED(lo);
6786 alloc = G_T5_ALLOC(lo);
6788 sbuf_printf(sb, "\nPort %d using %u pages out of %u allocated",
6791 for (i = 0; i < 4; i++) {
6792 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV4 + i * 4);
6795 alloc = G_ALLOC(lo);
6797 used = G_T5_USED(lo);
6798 alloc = G_T5_ALLOC(lo);
6801 "\nLoopback %d using %u pages out of %u allocated",
6805 rc = sbuf_finish(sb);
6812 tcamxy2valmask(uint64_t x, uint64_t y, uint8_t *addr, uint64_t *mask)
6816 memcpy(addr, (char *)&y + 2, ETHER_ADDR_LEN);
6820 sysctl_mps_tcam(SYSCTL_HANDLER_ARGS)
6822 struct adapter *sc = arg1;
6826 rc = sysctl_wire_old_buffer(req, 0);
6830 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6835 "Idx Ethernet address Mask Vld Ports PF"
6836 " VF Replication P0 P1 P2 P3 ML");
6837 n = is_t4(sc) ? NUM_MPS_CLS_SRAM_L_INSTANCES :
6838 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
6839 for (i = 0; i < n; i++) {
6840 uint64_t tcamx, tcamy, mask;
6841 uint32_t cls_lo, cls_hi;
6842 uint8_t addr[ETHER_ADDR_LEN];
6844 tcamy = t4_read_reg64(sc, MPS_CLS_TCAM_Y_L(i));
6845 tcamx = t4_read_reg64(sc, MPS_CLS_TCAM_X_L(i));
6846 cls_lo = t4_read_reg(sc, MPS_CLS_SRAM_L(i));
6847 cls_hi = t4_read_reg(sc, MPS_CLS_SRAM_H(i));
6852 tcamxy2valmask(tcamx, tcamy, addr, &mask);
6853 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x %012jx"
6854 " %c %#x%4u%4d", i, addr[0], addr[1], addr[2],
6855 addr[3], addr[4], addr[5], (uintmax_t)mask,
6856 (cls_lo & F_SRAM_VLD) ? 'Y' : 'N',
6857 G_PORTMAP(cls_hi), G_PF(cls_lo),
6858 (cls_lo & F_VF_VALID) ? G_VF(cls_lo) : -1);
6860 if (cls_lo & F_REPLICATE) {
6861 struct fw_ldst_cmd ldst_cmd;
6863 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
6864 ldst_cmd.op_to_addrspace =
6865 htobe32(V_FW_CMD_OP(FW_LDST_CMD) |
6866 F_FW_CMD_REQUEST | F_FW_CMD_READ |
6867 V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MPS));
6868 ldst_cmd.cycles_to_len16 = htobe32(FW_LEN16(ldst_cmd));
6869 ldst_cmd.u.mps.rplc.fid_idx =
6870 htobe16(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) |
6871 V_FW_LDST_CMD_IDX(i));
6873 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK,
6877 rc = -t4_wr_mbox(sc, sc->mbox, &ldst_cmd,
6878 sizeof(ldst_cmd), &ldst_cmd);
6879 end_synchronized_op(sc, 0);
6883 " ------------ error %3u ------------", rc);
6886 sbuf_printf(sb, " %08x %08x %08x %08x",
6887 be32toh(ldst_cmd.u.mps.rplc.rplc127_96),
6888 be32toh(ldst_cmd.u.mps.rplc.rplc95_64),
6889 be32toh(ldst_cmd.u.mps.rplc.rplc63_32),
6890 be32toh(ldst_cmd.u.mps.rplc.rplc31_0));
6893 sbuf_printf(sb, "%36s", "");
6895 sbuf_printf(sb, "%4u%3u%3u%3u %#3x", G_SRAM_PRIO0(cls_lo),
6896 G_SRAM_PRIO1(cls_lo), G_SRAM_PRIO2(cls_lo),
6897 G_SRAM_PRIO3(cls_lo), (cls_lo >> S_MULTILISTEN0) & 0xf);
6901 (void) sbuf_finish(sb);
6903 rc = sbuf_finish(sb);
6910 sysctl_path_mtus(SYSCTL_HANDLER_ARGS)
6912 struct adapter *sc = arg1;
6915 uint16_t mtus[NMTUS];
6917 rc = sysctl_wire_old_buffer(req, 0);
6921 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6925 t4_read_mtu_tbl(sc, mtus, NULL);
6927 sbuf_printf(sb, "%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u",
6928 mtus[0], mtus[1], mtus[2], mtus[3], mtus[4], mtus[5], mtus[6],
6929 mtus[7], mtus[8], mtus[9], mtus[10], mtus[11], mtus[12], mtus[13],
6930 mtus[14], mtus[15]);
6932 rc = sbuf_finish(sb);
6939 sysctl_pm_stats(SYSCTL_HANDLER_ARGS)
6941 struct adapter *sc = arg1;
6944 uint32_t cnt[PM_NSTATS];
6945 uint64_t cyc[PM_NSTATS];
6946 static const char *rx_stats[] = {
6947 "Read:", "Write bypass:", "Write mem:", "Flush:"
6949 static const char *tx_stats[] = {
6950 "Read:", "Write bypass:", "Write mem:", "Bypass + mem:"
6953 rc = sysctl_wire_old_buffer(req, 0);
6957 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6961 t4_pmtx_get_stats(sc, cnt, cyc);
6962 sbuf_printf(sb, " Tx pcmds Tx bytes");
6963 for (i = 0; i < ARRAY_SIZE(tx_stats); i++)
6964 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], cnt[i],
6967 t4_pmrx_get_stats(sc, cnt, cyc);
6968 sbuf_printf(sb, "\n Rx pcmds Rx bytes");
6969 for (i = 0; i < ARRAY_SIZE(rx_stats); i++)
6970 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], cnt[i],
6973 rc = sbuf_finish(sb);
6980 sysctl_rdma_stats(SYSCTL_HANDLER_ARGS)
6982 struct adapter *sc = arg1;
6985 struct tp_rdma_stats stats;
6987 rc = sysctl_wire_old_buffer(req, 0);
6991 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6995 t4_tp_get_rdma_stats(sc, &stats);
6996 sbuf_printf(sb, "NoRQEModDefferals: %u\n", stats.rqe_dfr_mod);
6997 sbuf_printf(sb, "NoRQEPktDefferals: %u", stats.rqe_dfr_pkt);
6999 rc = sbuf_finish(sb);
7006 sysctl_tcp_stats(SYSCTL_HANDLER_ARGS)
7008 struct adapter *sc = arg1;
7011 struct tp_tcp_stats v4, v6;
7013 rc = sysctl_wire_old_buffer(req, 0);
7017 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7021 t4_tp_get_tcp_stats(sc, &v4, &v6);
7024 sbuf_printf(sb, "OutRsts: %20u %20u\n",
7025 v4.tcpOutRsts, v6.tcpOutRsts);
7026 sbuf_printf(sb, "InSegs: %20ju %20ju\n",
7027 v4.tcpInSegs, v6.tcpInSegs);
7028 sbuf_printf(sb, "OutSegs: %20ju %20ju\n",
7029 v4.tcpOutSegs, v6.tcpOutSegs);
7030 sbuf_printf(sb, "RetransSegs: %20ju %20ju",
7031 v4.tcpRetransSegs, v6.tcpRetransSegs);
7033 rc = sbuf_finish(sb);
7040 sysctl_tids(SYSCTL_HANDLER_ARGS)
7042 struct adapter *sc = arg1;
7045 struct tid_info *t = &sc->tids;
7047 rc = sysctl_wire_old_buffer(req, 0);
7051 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7056 sbuf_printf(sb, "ATID range: 0-%u, in use: %u\n", t->natids - 1,
7061 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
7062 uint32_t b = t4_read_reg(sc, A_LE_DB_SERVER_INDEX) / 4;
7065 sbuf_printf(sb, "TID range: 0-%u, %u-%u", b - 1,
7066 t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4,
7069 sbuf_printf(sb, "TID range: %u-%u",
7070 t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4,
7074 sbuf_printf(sb, "TID range: 0-%u", t->ntids - 1);
7075 sbuf_printf(sb, ", in use: %u\n",
7076 atomic_load_acq_int(&t->tids_in_use));
7080 sbuf_printf(sb, "STID range: %u-%u, in use: %u\n", t->stid_base,
7081 t->stid_base + t->nstids - 1, t->stids_in_use);
7085 sbuf_printf(sb, "FTID range: %u-%u\n", t->ftid_base,
7086 t->ftid_base + t->nftids - 1);
7090 sbuf_printf(sb, "ETID range: %u-%u\n", t->etid_base,
7091 t->etid_base + t->netids - 1);
7094 sbuf_printf(sb, "HW TID usage: %u IP users, %u IPv6 users",
7095 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV4),
7096 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV6));
7098 rc = sbuf_finish(sb);
7105 sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS)
7107 struct adapter *sc = arg1;
7110 struct tp_err_stats stats;
7112 rc = sysctl_wire_old_buffer(req, 0);
7116 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7120 t4_tp_get_err_stats(sc, &stats);
7122 sbuf_printf(sb, " channel 0 channel 1 channel 2 "
7124 sbuf_printf(sb, "macInErrs: %10u %10u %10u %10u\n",
7125 stats.macInErrs[0], stats.macInErrs[1], stats.macInErrs[2],
7126 stats.macInErrs[3]);
7127 sbuf_printf(sb, "hdrInErrs: %10u %10u %10u %10u\n",
7128 stats.hdrInErrs[0], stats.hdrInErrs[1], stats.hdrInErrs[2],
7129 stats.hdrInErrs[3]);
7130 sbuf_printf(sb, "tcpInErrs: %10u %10u %10u %10u\n",
7131 stats.tcpInErrs[0], stats.tcpInErrs[1], stats.tcpInErrs[2],
7132 stats.tcpInErrs[3]);
7133 sbuf_printf(sb, "tcp6InErrs: %10u %10u %10u %10u\n",
7134 stats.tcp6InErrs[0], stats.tcp6InErrs[1], stats.tcp6InErrs[2],
7135 stats.tcp6InErrs[3]);
7136 sbuf_printf(sb, "tnlCongDrops: %10u %10u %10u %10u\n",
7137 stats.tnlCongDrops[0], stats.tnlCongDrops[1], stats.tnlCongDrops[2],
7138 stats.tnlCongDrops[3]);
7139 sbuf_printf(sb, "tnlTxDrops: %10u %10u %10u %10u\n",
7140 stats.tnlTxDrops[0], stats.tnlTxDrops[1], stats.tnlTxDrops[2],
7141 stats.tnlTxDrops[3]);
7142 sbuf_printf(sb, "ofldVlanDrops: %10u %10u %10u %10u\n",
7143 stats.ofldVlanDrops[0], stats.ofldVlanDrops[1],
7144 stats.ofldVlanDrops[2], stats.ofldVlanDrops[3]);
7145 sbuf_printf(sb, "ofldChanDrops: %10u %10u %10u %10u\n\n",
7146 stats.ofldChanDrops[0], stats.ofldChanDrops[1],
7147 stats.ofldChanDrops[2], stats.ofldChanDrops[3]);
7148 sbuf_printf(sb, "ofldNoNeigh: %u\nofldCongDefer: %u",
7149 stats.ofldNoNeigh, stats.ofldCongDefer);
7151 rc = sbuf_finish(sb);
7164 field_desc_show(struct sbuf *sb, uint64_t v, const struct field_desc *f)
7170 uint64_t mask = (1ULL << f->width) - 1;
7171 int len = snprintf(buf, sizeof(buf), "%s: %ju", f->name,
7172 ((uintmax_t)v >> f->start) & mask);
7174 if (line_size + len >= 79) {
7176 sbuf_printf(sb, "\n ");
7178 sbuf_printf(sb, "%s ", buf);
7179 line_size += len + 1;
7182 sbuf_printf(sb, "\n");
7185 static struct field_desc tp_la0[] = {
7186 { "RcfOpCodeOut", 60, 4 },
7188 { "WcfState", 52, 4 },
7189 { "RcfOpcSrcOut", 50, 2 },
7190 { "CRxError", 49, 1 },
7191 { "ERxError", 48, 1 },
7192 { "SanityFailed", 47, 1 },
7193 { "SpuriousMsg", 46, 1 },
7194 { "FlushInputMsg", 45, 1 },
7195 { "FlushInputCpl", 44, 1 },
7196 { "RssUpBit", 43, 1 },
7197 { "RssFilterHit", 42, 1 },
7199 { "InitTcb", 31, 1 },
7200 { "LineNumber", 24, 7 },
7202 { "EdataOut", 22, 1 },
7204 { "CdataOut", 20, 1 },
7205 { "EreadPdu", 19, 1 },
7206 { "CreadPdu", 18, 1 },
7207 { "TunnelPkt", 17, 1 },
7208 { "RcfPeerFin", 16, 1 },
7209 { "RcfReasonOut", 12, 4 },
7210 { "TxCchannel", 10, 2 },
7211 { "RcfTxChannel", 8, 2 },
7212 { "RxEchannel", 6, 2 },
7213 { "RcfRxChannel", 5, 1 },
7214 { "RcfDataOutSrdy", 4, 1 },
7216 { "RxOoDvld", 2, 1 },
7217 { "RxCongestion", 1, 1 },
7218 { "TxCongestion", 0, 1 },
7222 static struct field_desc tp_la1[] = {
7223 { "CplCmdIn", 56, 8 },
7224 { "CplCmdOut", 48, 8 },
7225 { "ESynOut", 47, 1 },
7226 { "EAckOut", 46, 1 },
7227 { "EFinOut", 45, 1 },
7228 { "ERstOut", 44, 1 },
7233 { "DataIn", 39, 1 },
7234 { "DataInVld", 38, 1 },
7236 { "RxBufEmpty", 36, 1 },
7238 { "RxFbCongestion", 34, 1 },
7239 { "TxFbCongestion", 33, 1 },
7240 { "TxPktSumSrdy", 32, 1 },
7241 { "RcfUlpType", 28, 4 },
7243 { "Ebypass", 26, 1 },
7245 { "Static0", 24, 1 },
7247 { "Cbypass", 22, 1 },
7249 { "CPktOut", 20, 1 },
7250 { "RxPagePoolFull", 18, 2 },
7251 { "RxLpbkPkt", 17, 1 },
7252 { "TxLpbkPkt", 16, 1 },
7253 { "RxVfValid", 15, 1 },
7254 { "SynLearned", 14, 1 },
7255 { "SetDelEntry", 13, 1 },
7256 { "SetInvEntry", 12, 1 },
7257 { "CpcmdDvld", 11, 1 },
7258 { "CpcmdSave", 10, 1 },
7259 { "RxPstructsFull", 8, 2 },
7260 { "EpcmdDvld", 7, 1 },
7261 { "EpcmdFlush", 6, 1 },
7262 { "EpcmdTrimPrefix", 5, 1 },
7263 { "EpcmdTrimPostfix", 4, 1 },
7264 { "ERssIp4Pkt", 3, 1 },
7265 { "ERssIp6Pkt", 2, 1 },
7266 { "ERssTcpUdpPkt", 1, 1 },
7267 { "ERssFceFipPkt", 0, 1 },
7271 static struct field_desc tp_la2[] = {
7272 { "CplCmdIn", 56, 8 },
7273 { "MpsVfVld", 55, 1 },
7280 { "DataIn", 39, 1 },
7281 { "DataInVld", 38, 1 },
7283 { "RxBufEmpty", 36, 1 },
7285 { "RxFbCongestion", 34, 1 },
7286 { "TxFbCongestion", 33, 1 },
7287 { "TxPktSumSrdy", 32, 1 },
7288 { "RcfUlpType", 28, 4 },
7290 { "Ebypass", 26, 1 },
7292 { "Static0", 24, 1 },
7294 { "Cbypass", 22, 1 },
7296 { "CPktOut", 20, 1 },
7297 { "RxPagePoolFull", 18, 2 },
7298 { "RxLpbkPkt", 17, 1 },
7299 { "TxLpbkPkt", 16, 1 },
7300 { "RxVfValid", 15, 1 },
7301 { "SynLearned", 14, 1 },
7302 { "SetDelEntry", 13, 1 },
7303 { "SetInvEntry", 12, 1 },
7304 { "CpcmdDvld", 11, 1 },
7305 { "CpcmdSave", 10, 1 },
7306 { "RxPstructsFull", 8, 2 },
7307 { "EpcmdDvld", 7, 1 },
7308 { "EpcmdFlush", 6, 1 },
7309 { "EpcmdTrimPrefix", 5, 1 },
7310 { "EpcmdTrimPostfix", 4, 1 },
7311 { "ERssIp4Pkt", 3, 1 },
7312 { "ERssIp6Pkt", 2, 1 },
7313 { "ERssTcpUdpPkt", 1, 1 },
7314 { "ERssFceFipPkt", 0, 1 },
7319 tp_la_show(struct sbuf *sb, uint64_t *p, int idx)
7322 field_desc_show(sb, *p, tp_la0);
7326 tp_la_show2(struct sbuf *sb, uint64_t *p, int idx)
7330 sbuf_printf(sb, "\n");
7331 field_desc_show(sb, p[0], tp_la0);
7332 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
7333 field_desc_show(sb, p[1], tp_la0);
7337 tp_la_show3(struct sbuf *sb, uint64_t *p, int idx)
7341 sbuf_printf(sb, "\n");
7342 field_desc_show(sb, p[0], tp_la0);
7343 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
7344 field_desc_show(sb, p[1], (p[0] & (1 << 17)) ? tp_la2 : tp_la1);
7348 sysctl_tp_la(SYSCTL_HANDLER_ARGS)
7350 struct adapter *sc = arg1;
7355 void (*show_func)(struct sbuf *, uint64_t *, int);
7357 rc = sysctl_wire_old_buffer(req, 0);
7361 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7365 buf = malloc(TPLA_SIZE * sizeof(uint64_t), M_CXGBE, M_ZERO | M_WAITOK);
7367 t4_tp_read_la(sc, buf, NULL);
7370 switch (G_DBGLAMODE(t4_read_reg(sc, A_TP_DBG_LA_CONFIG))) {
7373 show_func = tp_la_show2;
7377 show_func = tp_la_show3;
7381 show_func = tp_la_show;
7384 for (i = 0; i < TPLA_SIZE / inc; i++, p += inc)
7385 (*show_func)(sb, p, i);
7387 rc = sbuf_finish(sb);
7394 sysctl_tx_rate(SYSCTL_HANDLER_ARGS)
7396 struct adapter *sc = arg1;
7399 u64 nrate[NCHAN], orate[NCHAN];
7401 rc = sysctl_wire_old_buffer(req, 0);
7405 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7409 t4_get_chan_txrate(sc, nrate, orate);
7410 sbuf_printf(sb, " channel 0 channel 1 channel 2 "
7412 sbuf_printf(sb, "NIC B/s: %10ju %10ju %10ju %10ju\n",
7413 nrate[0], nrate[1], nrate[2], nrate[3]);
7414 sbuf_printf(sb, "Offload B/s: %10ju %10ju %10ju %10ju",
7415 orate[0], orate[1], orate[2], orate[3]);
7417 rc = sbuf_finish(sb);
7424 sysctl_ulprx_la(SYSCTL_HANDLER_ARGS)
7426 struct adapter *sc = arg1;
7431 rc = sysctl_wire_old_buffer(req, 0);
7435 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7439 buf = malloc(ULPRX_LA_SIZE * 8 * sizeof(uint32_t), M_CXGBE,
7442 t4_ulprx_read_la(sc, buf);
7445 sbuf_printf(sb, " Pcmd Type Message"
7447 for (i = 0; i < ULPRX_LA_SIZE; i++, p += 8) {
7448 sbuf_printf(sb, "\n%08x%08x %4x %08x %08x%08x%08x%08x",
7449 p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
7452 rc = sbuf_finish(sb);
7459 sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS)
7461 struct adapter *sc = arg1;
7465 rc = sysctl_wire_old_buffer(req, 0);
7469 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7473 v = t4_read_reg(sc, A_SGE_STAT_CFG);
7474 if (G_STATSOURCE_T5(v) == 7) {
7475 if (G_STATMODE(v) == 0) {
7476 sbuf_printf(sb, "total %d, incomplete %d",
7477 t4_read_reg(sc, A_SGE_STAT_TOTAL),
7478 t4_read_reg(sc, A_SGE_STAT_MATCH));
7479 } else if (G_STATMODE(v) == 1) {
7480 sbuf_printf(sb, "total %d, data overflow %d",
7481 t4_read_reg(sc, A_SGE_STAT_TOTAL),
7482 t4_read_reg(sc, A_SGE_STAT_MATCH));
7485 rc = sbuf_finish(sb);
7493 fconf_to_mode(uint32_t fconf)
7497 mode = T4_FILTER_IPv4 | T4_FILTER_IPv6 | T4_FILTER_IP_SADDR |
7498 T4_FILTER_IP_DADDR | T4_FILTER_IP_SPORT | T4_FILTER_IP_DPORT;
7500 if (fconf & F_FRAGMENTATION)
7501 mode |= T4_FILTER_IP_FRAGMENT;
7503 if (fconf & F_MPSHITTYPE)
7504 mode |= T4_FILTER_MPS_HIT_TYPE;
7506 if (fconf & F_MACMATCH)
7507 mode |= T4_FILTER_MAC_IDX;
7509 if (fconf & F_ETHERTYPE)
7510 mode |= T4_FILTER_ETH_TYPE;
7512 if (fconf & F_PROTOCOL)
7513 mode |= T4_FILTER_IP_PROTO;
7516 mode |= T4_FILTER_IP_TOS;
7519 mode |= T4_FILTER_VLAN;
7521 if (fconf & F_VNIC_ID)
7522 mode |= T4_FILTER_VNIC;
7525 mode |= T4_FILTER_PORT;
7528 mode |= T4_FILTER_FCoE;
7534 mode_to_fconf(uint32_t mode)
7538 if (mode & T4_FILTER_IP_FRAGMENT)
7539 fconf |= F_FRAGMENTATION;
7541 if (mode & T4_FILTER_MPS_HIT_TYPE)
7542 fconf |= F_MPSHITTYPE;
7544 if (mode & T4_FILTER_MAC_IDX)
7545 fconf |= F_MACMATCH;
7547 if (mode & T4_FILTER_ETH_TYPE)
7548 fconf |= F_ETHERTYPE;
7550 if (mode & T4_FILTER_IP_PROTO)
7551 fconf |= F_PROTOCOL;
7553 if (mode & T4_FILTER_IP_TOS)
7556 if (mode & T4_FILTER_VLAN)
7559 if (mode & T4_FILTER_VNIC)
7562 if (mode & T4_FILTER_PORT)
7565 if (mode & T4_FILTER_FCoE)
7572 fspec_to_fconf(struct t4_filter_specification *fs)
7576 if (fs->val.frag || fs->mask.frag)
7577 fconf |= F_FRAGMENTATION;
7579 if (fs->val.matchtype || fs->mask.matchtype)
7580 fconf |= F_MPSHITTYPE;
7582 if (fs->val.macidx || fs->mask.macidx)
7583 fconf |= F_MACMATCH;
7585 if (fs->val.ethtype || fs->mask.ethtype)
7586 fconf |= F_ETHERTYPE;
7588 if (fs->val.proto || fs->mask.proto)
7589 fconf |= F_PROTOCOL;
7591 if (fs->val.tos || fs->mask.tos)
7594 if (fs->val.vlan_vld || fs->mask.vlan_vld)
7597 if (fs->val.vnic_vld || fs->mask.vnic_vld)
7600 if (fs->val.iport || fs->mask.iport)
7603 if (fs->val.fcoe || fs->mask.fcoe)
7610 get_filter_mode(struct adapter *sc, uint32_t *mode)
7615 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
7620 t4_read_indirect(sc, A_TP_PIO_ADDR, A_TP_PIO_DATA, &fconf, 1,
7623 if (sc->params.tp.vlan_pri_map != fconf) {
7624 log(LOG_WARNING, "%s: cached filter mode out of sync %x %x.\n",
7625 device_get_nameunit(sc->dev), sc->params.tp.vlan_pri_map,
7629 *mode = fconf_to_mode(fconf);
7631 end_synchronized_op(sc, LOCK_HELD);
7636 set_filter_mode(struct adapter *sc, uint32_t mode)
7641 fconf = mode_to_fconf(mode);
7643 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
7648 if (sc->tids.ftids_in_use > 0) {
7654 if (uld_active(sc, ULD_TOM)) {
7660 rc = -t4_set_filter_mode(sc, fconf);
7662 end_synchronized_op(sc, LOCK_HELD);
7666 static inline uint64_t
7667 get_filter_hits(struct adapter *sc, uint32_t fid)
7669 uint32_t mw_base, off, tcb_base = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
7672 memwin_info(sc, 0, &mw_base, NULL);
7673 off = position_memwin(sc, 0,
7674 tcb_base + (fid + sc->tids.ftid_base) * TCB_SIZE);
7676 hits = t4_read_reg64(sc, mw_base + off + 16);
7677 hits = be64toh(hits);
7679 hits = t4_read_reg(sc, mw_base + off + 24);
7680 hits = be32toh(hits);
7687 get_filter(struct adapter *sc, struct t4_filter *t)
7689 int i, rc, nfilters = sc->tids.nftids;
7690 struct filter_entry *f;
7692 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
7697 if (sc->tids.ftids_in_use == 0 || sc->tids.ftid_tab == NULL ||
7698 t->idx >= nfilters) {
7699 t->idx = 0xffffffff;
7703 f = &sc->tids.ftid_tab[t->idx];
7704 for (i = t->idx; i < nfilters; i++, f++) {
7707 t->l2tidx = f->l2t ? f->l2t->idx : 0;
7708 t->smtidx = f->smtidx;
7710 t->hits = get_filter_hits(sc, t->idx);
7712 t->hits = UINT64_MAX;
7719 t->idx = 0xffffffff;
7721 end_synchronized_op(sc, LOCK_HELD);
7726 set_filter(struct adapter *sc, struct t4_filter *t)
7728 unsigned int nfilters, nports;
7729 struct filter_entry *f;
7732 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setf");
7736 nfilters = sc->tids.nftids;
7737 nports = sc->params.nports;
7739 if (nfilters == 0) {
7744 if (!(sc->flags & FULL_INIT_DONE)) {
7749 if (t->idx >= nfilters) {
7754 /* Validate against the global filter mode */
7755 if ((sc->params.tp.vlan_pri_map | fspec_to_fconf(&t->fs)) !=
7756 sc->params.tp.vlan_pri_map) {
7761 if (t->fs.action == FILTER_SWITCH && t->fs.eport >= nports) {
7766 if (t->fs.val.iport >= nports) {
7771 /* Can't specify an iq if not steering to it */
7772 if (!t->fs.dirsteer && t->fs.iq) {
7777 /* IPv6 filter idx must be 4 aligned */
7778 if (t->fs.type == 1 &&
7779 ((t->idx & 0x3) || t->idx + 4 >= nfilters)) {
7784 if (sc->tids.ftid_tab == NULL) {
7785 KASSERT(sc->tids.ftids_in_use == 0,
7786 ("%s: no memory allocated but filters_in_use > 0",
7789 sc->tids.ftid_tab = malloc(sizeof (struct filter_entry) *
7790 nfilters, M_CXGBE, M_NOWAIT | M_ZERO);
7791 if (sc->tids.ftid_tab == NULL) {
7795 mtx_init(&sc->tids.ftid_lock, "T4 filters", 0, MTX_DEF);
7798 for (i = 0; i < 4; i++) {
7799 f = &sc->tids.ftid_tab[t->idx + i];
7801 if (f->pending || f->valid) {
7810 if (t->fs.type == 0)
7814 f = &sc->tids.ftid_tab[t->idx];
7817 rc = set_filter_wr(sc, t->idx);
7819 end_synchronized_op(sc, 0);
7822 mtx_lock(&sc->tids.ftid_lock);
7824 if (f->pending == 0) {
7825 rc = f->valid ? 0 : EIO;
7829 if (mtx_sleep(&sc->tids.ftid_tab, &sc->tids.ftid_lock,
7830 PCATCH, "t4setfw", 0)) {
7835 mtx_unlock(&sc->tids.ftid_lock);
7841 del_filter(struct adapter *sc, struct t4_filter *t)
7843 unsigned int nfilters;
7844 struct filter_entry *f;
7847 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4delf");
7851 nfilters = sc->tids.nftids;
7853 if (nfilters == 0) {
7858 if (sc->tids.ftid_tab == NULL || sc->tids.ftids_in_use == 0 ||
7859 t->idx >= nfilters) {
7864 if (!(sc->flags & FULL_INIT_DONE)) {
7869 f = &sc->tids.ftid_tab[t->idx];
7881 t->fs = f->fs; /* extra info for the caller */
7882 rc = del_filter_wr(sc, t->idx);
7886 end_synchronized_op(sc, 0);
7889 mtx_lock(&sc->tids.ftid_lock);
7891 if (f->pending == 0) {
7892 rc = f->valid ? EIO : 0;
7896 if (mtx_sleep(&sc->tids.ftid_tab, &sc->tids.ftid_lock,
7897 PCATCH, "t4delfw", 0)) {
7902 mtx_unlock(&sc->tids.ftid_lock);
7909 clear_filter(struct filter_entry *f)
7912 t4_l2t_release(f->l2t);
7914 bzero(f, sizeof (*f));
7918 set_filter_wr(struct adapter *sc, int fidx)
7920 struct filter_entry *f = &sc->tids.ftid_tab[fidx];
7921 struct fw_filter_wr *fwr;
7923 struct wrq_cookie cookie;
7925 ASSERT_SYNCHRONIZED_OP(sc);
7927 if (f->fs.newdmac || f->fs.newvlan) {
7928 /* This filter needs an L2T entry; allocate one. */
7929 f->l2t = t4_l2t_alloc_switching(sc->l2t);
7932 if (t4_l2t_set_switching(sc, f->l2t, f->fs.vlan, f->fs.eport,
7934 t4_l2t_release(f->l2t);
7940 ftid = sc->tids.ftid_base + fidx;
7942 fwr = start_wrq_wr(&sc->sge.mgmtq, howmany(sizeof(*fwr), 16), &cookie);
7945 bzero(fwr, sizeof(*fwr));
7947 fwr->op_pkd = htobe32(V_FW_WR_OP(FW_FILTER_WR));
7948 fwr->len16_pkd = htobe32(FW_LEN16(*fwr));
7950 htobe32(V_FW_FILTER_WR_TID(ftid) |
7951 V_FW_FILTER_WR_RQTYPE(f->fs.type) |
7952 V_FW_FILTER_WR_NOREPLY(0) |
7953 V_FW_FILTER_WR_IQ(f->fs.iq));
7954 fwr->del_filter_to_l2tix =
7955 htobe32(V_FW_FILTER_WR_RPTTID(f->fs.rpttid) |
7956 V_FW_FILTER_WR_DROP(f->fs.action == FILTER_DROP) |
7957 V_FW_FILTER_WR_DIRSTEER(f->fs.dirsteer) |
7958 V_FW_FILTER_WR_MASKHASH(f->fs.maskhash) |
7959 V_FW_FILTER_WR_DIRSTEERHASH(f->fs.dirsteerhash) |
7960 V_FW_FILTER_WR_LPBK(f->fs.action == FILTER_SWITCH) |
7961 V_FW_FILTER_WR_DMAC(f->fs.newdmac) |
7962 V_FW_FILTER_WR_SMAC(f->fs.newsmac) |
7963 V_FW_FILTER_WR_INSVLAN(f->fs.newvlan == VLAN_INSERT ||
7964 f->fs.newvlan == VLAN_REWRITE) |
7965 V_FW_FILTER_WR_RMVLAN(f->fs.newvlan == VLAN_REMOVE ||
7966 f->fs.newvlan == VLAN_REWRITE) |
7967 V_FW_FILTER_WR_HITCNTS(f->fs.hitcnts) |
7968 V_FW_FILTER_WR_TXCHAN(f->fs.eport) |
7969 V_FW_FILTER_WR_PRIO(f->fs.prio) |
7970 V_FW_FILTER_WR_L2TIX(f->l2t ? f->l2t->idx : 0));
7971 fwr->ethtype = htobe16(f->fs.val.ethtype);
7972 fwr->ethtypem = htobe16(f->fs.mask.ethtype);
7973 fwr->frag_to_ovlan_vldm =
7974 (V_FW_FILTER_WR_FRAG(f->fs.val.frag) |
7975 V_FW_FILTER_WR_FRAGM(f->fs.mask.frag) |
7976 V_FW_FILTER_WR_IVLAN_VLD(f->fs.val.vlan_vld) |
7977 V_FW_FILTER_WR_OVLAN_VLD(f->fs.val.vnic_vld) |
7978 V_FW_FILTER_WR_IVLAN_VLDM(f->fs.mask.vlan_vld) |
7979 V_FW_FILTER_WR_OVLAN_VLDM(f->fs.mask.vnic_vld));
7981 fwr->rx_chan_rx_rpl_iq = htobe16(V_FW_FILTER_WR_RX_CHAN(0) |
7982 V_FW_FILTER_WR_RX_RPL_IQ(sc->sge.fwq.abs_id));
7983 fwr->maci_to_matchtypem =
7984 htobe32(V_FW_FILTER_WR_MACI(f->fs.val.macidx) |
7985 V_FW_FILTER_WR_MACIM(f->fs.mask.macidx) |
7986 V_FW_FILTER_WR_FCOE(f->fs.val.fcoe) |
7987 V_FW_FILTER_WR_FCOEM(f->fs.mask.fcoe) |
7988 V_FW_FILTER_WR_PORT(f->fs.val.iport) |
7989 V_FW_FILTER_WR_PORTM(f->fs.mask.iport) |
7990 V_FW_FILTER_WR_MATCHTYPE(f->fs.val.matchtype) |
7991 V_FW_FILTER_WR_MATCHTYPEM(f->fs.mask.matchtype));
7992 fwr->ptcl = f->fs.val.proto;
7993 fwr->ptclm = f->fs.mask.proto;
7994 fwr->ttyp = f->fs.val.tos;
7995 fwr->ttypm = f->fs.mask.tos;
7996 fwr->ivlan = htobe16(f->fs.val.vlan);
7997 fwr->ivlanm = htobe16(f->fs.mask.vlan);
7998 fwr->ovlan = htobe16(f->fs.val.vnic);
7999 fwr->ovlanm = htobe16(f->fs.mask.vnic);
8000 bcopy(f->fs.val.dip, fwr->lip, sizeof (fwr->lip));
8001 bcopy(f->fs.mask.dip, fwr->lipm, sizeof (fwr->lipm));
8002 bcopy(f->fs.val.sip, fwr->fip, sizeof (fwr->fip));
8003 bcopy(f->fs.mask.sip, fwr->fipm, sizeof (fwr->fipm));
8004 fwr->lp = htobe16(f->fs.val.dport);
8005 fwr->lpm = htobe16(f->fs.mask.dport);
8006 fwr->fp = htobe16(f->fs.val.sport);
8007 fwr->fpm = htobe16(f->fs.mask.sport);
8009 bcopy(f->fs.smac, fwr->sma, sizeof (fwr->sma));
8012 sc->tids.ftids_in_use++;
8014 commit_wrq_wr(&sc->sge.mgmtq, fwr, &cookie);
8019 del_filter_wr(struct adapter *sc, int fidx)
8021 struct filter_entry *f = &sc->tids.ftid_tab[fidx];
8022 struct fw_filter_wr *fwr;
8024 struct wrq_cookie cookie;
8026 ftid = sc->tids.ftid_base + fidx;
8028 fwr = start_wrq_wr(&sc->sge.mgmtq, howmany(sizeof(*fwr), 16), &cookie);
8031 bzero(fwr, sizeof (*fwr));
8033 t4_mk_filtdelwr(ftid, fwr, sc->sge.fwq.abs_id);
8036 commit_wrq_wr(&sc->sge.mgmtq, fwr, &cookie);
8041 t4_filter_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
8043 struct adapter *sc = iq->adapter;
8044 const struct cpl_set_tcb_rpl *rpl = (const void *)(rss + 1);
8045 unsigned int idx = GET_TID(rpl);
8047 struct filter_entry *f;
8049 KASSERT(m == NULL, ("%s: payload with opcode %02x", __func__,
8052 if (is_ftid(sc, idx)) {
8054 idx -= sc->tids.ftid_base;
8055 f = &sc->tids.ftid_tab[idx];
8056 rc = G_COOKIE(rpl->cookie);
8058 mtx_lock(&sc->tids.ftid_lock);
8059 if (rc == FW_FILTER_WR_FLT_ADDED) {
8060 KASSERT(f->pending, ("%s: filter[%u] isn't pending.",
8062 f->smtidx = (be64toh(rpl->oldval) >> 24) & 0xff;
8063 f->pending = 0; /* asynchronous setup completed */
8066 if (rc != FW_FILTER_WR_FLT_DELETED) {
8067 /* Add or delete failed, display an error */
8069 "filter %u setup failed with error %u\n",
8074 sc->tids.ftids_in_use--;
8076 wakeup(&sc->tids.ftid_tab);
8077 mtx_unlock(&sc->tids.ftid_lock);
8084 get_sge_context(struct adapter *sc, struct t4_sge_context *cntxt)
8088 if (cntxt->cid > M_CTXTQID)
8091 if (cntxt->mem_id != CTXT_EGRESS && cntxt->mem_id != CTXT_INGRESS &&
8092 cntxt->mem_id != CTXT_FLM && cntxt->mem_id != CTXT_CNM)
8095 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ctxt");
8099 if (sc->flags & FW_OK) {
8100 rc = -t4_sge_ctxt_rd(sc, sc->mbox, cntxt->cid, cntxt->mem_id,
8107 * Read via firmware failed or wasn't even attempted. Read directly via
8110 rc = -t4_sge_ctxt_rd_bd(sc, cntxt->cid, cntxt->mem_id, &cntxt->data[0]);
8112 end_synchronized_op(sc, 0);
8117 load_fw(struct adapter *sc, struct t4_data *fw)
8122 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldfw");
8126 if (sc->flags & FULL_INIT_DONE) {
8131 fw_data = malloc(fw->len, M_CXGBE, M_WAITOK);
8132 if (fw_data == NULL) {
8137 rc = copyin(fw->data, fw_data, fw->len);
8139 rc = -t4_load_fw(sc, fw_data, fw->len);
8141 free(fw_data, M_CXGBE);
8143 end_synchronized_op(sc, 0);
8148 read_card_mem(struct adapter *sc, int win, struct t4_mem_range *mr)
8150 uint32_t addr, off, remaining, i, n;
8152 uint32_t mw_base, mw_aperture;
8156 rc = validate_mem_range(sc, mr->addr, mr->len);
8160 memwin_info(sc, win, &mw_base, &mw_aperture);
8161 buf = b = malloc(min(mr->len, mw_aperture), M_CXGBE, M_WAITOK);
8163 remaining = mr->len;
8164 dst = (void *)mr->data;
8167 off = position_memwin(sc, win, addr);
8169 /* number of bytes that we'll copy in the inner loop */
8170 n = min(remaining, mw_aperture - off);
8171 for (i = 0; i < n; i += 4)
8172 *b++ = t4_read_reg(sc, mw_base + off + i);
8174 rc = copyout(buf, dst, n);
8189 read_i2c(struct adapter *sc, struct t4_i2c_data *i2cd)
8193 if (i2cd->len == 0 || i2cd->port_id >= sc->params.nports)
8196 if (i2cd->len > sizeof(i2cd->data))
8199 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4i2crd");
8202 rc = -t4_i2c_rd(sc, sc->mbox, i2cd->port_id, i2cd->dev_addr,
8203 i2cd->offset, i2cd->len, &i2cd->data[0]);
8204 end_synchronized_op(sc, 0);
8210 in_range(int val, int lo, int hi)
8213 return (val < 0 || (val <= hi && val >= lo));
8217 set_sched_class(struct adapter *sc, struct t4_sched_params *p)
8219 int fw_subcmd, fw_type, rc;
8221 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setsc");
8225 if (!(sc->flags & FULL_INIT_DONE)) {
8231 * Translate the cxgbetool parameters into T4 firmware parameters. (The
8232 * sub-command and type are in common locations.)
8234 if (p->subcmd == SCHED_CLASS_SUBCMD_CONFIG)
8235 fw_subcmd = FW_SCHED_SC_CONFIG;
8236 else if (p->subcmd == SCHED_CLASS_SUBCMD_PARAMS)
8237 fw_subcmd = FW_SCHED_SC_PARAMS;
8242 if (p->type == SCHED_CLASS_TYPE_PACKET)
8243 fw_type = FW_SCHED_TYPE_PKTSCHED;
8249 if (fw_subcmd == FW_SCHED_SC_CONFIG) {
8250 /* Vet our parameters ..*/
8251 if (p->u.config.minmax < 0) {
8256 /* And pass the request to the firmware ...*/
8257 rc = -t4_sched_config(sc, fw_type, p->u.config.minmax, 1);
8261 if (fw_subcmd == FW_SCHED_SC_PARAMS) {
8267 if (p->u.params.level == SCHED_CLASS_LEVEL_CL_RL)
8268 fw_level = FW_SCHED_PARAMS_LEVEL_CL_RL;
8269 else if (p->u.params.level == SCHED_CLASS_LEVEL_CL_WRR)
8270 fw_level = FW_SCHED_PARAMS_LEVEL_CL_WRR;
8271 else if (p->u.params.level == SCHED_CLASS_LEVEL_CH_RL)
8272 fw_level = FW_SCHED_PARAMS_LEVEL_CH_RL;
8278 if (p->u.params.mode == SCHED_CLASS_MODE_CLASS)
8279 fw_mode = FW_SCHED_PARAMS_MODE_CLASS;
8280 else if (p->u.params.mode == SCHED_CLASS_MODE_FLOW)
8281 fw_mode = FW_SCHED_PARAMS_MODE_FLOW;
8287 if (p->u.params.rateunit == SCHED_CLASS_RATEUNIT_BITS)
8288 fw_rateunit = FW_SCHED_PARAMS_UNIT_BITRATE;
8289 else if (p->u.params.rateunit == SCHED_CLASS_RATEUNIT_PKTS)
8290 fw_rateunit = FW_SCHED_PARAMS_UNIT_PKTRATE;
8296 if (p->u.params.ratemode == SCHED_CLASS_RATEMODE_REL)
8297 fw_ratemode = FW_SCHED_PARAMS_RATE_REL;
8298 else if (p->u.params.ratemode == SCHED_CLASS_RATEMODE_ABS)
8299 fw_ratemode = FW_SCHED_PARAMS_RATE_ABS;
8305 /* Vet our parameters ... */
8306 if (!in_range(p->u.params.channel, 0, 3) ||
8307 !in_range(p->u.params.cl, 0, is_t4(sc) ? 15 : 16) ||
8308 !in_range(p->u.params.minrate, 0, 10000000) ||
8309 !in_range(p->u.params.maxrate, 0, 10000000) ||
8310 !in_range(p->u.params.weight, 0, 100)) {
8316 * Translate any unset parameters into the firmware's
8317 * nomenclature and/or fail the call if the parameters
8320 if (p->u.params.rateunit < 0 || p->u.params.ratemode < 0 ||
8321 p->u.params.channel < 0 || p->u.params.cl < 0) {
8325 if (p->u.params.minrate < 0)
8326 p->u.params.minrate = 0;
8327 if (p->u.params.maxrate < 0) {
8328 if (p->u.params.level == SCHED_CLASS_LEVEL_CL_RL ||
8329 p->u.params.level == SCHED_CLASS_LEVEL_CH_RL) {
8333 p->u.params.maxrate = 0;
8335 if (p->u.params.weight < 0) {
8336 if (p->u.params.level == SCHED_CLASS_LEVEL_CL_WRR) {
8340 p->u.params.weight = 0;
8342 if (p->u.params.pktsize < 0) {
8343 if (p->u.params.level == SCHED_CLASS_LEVEL_CL_RL ||
8344 p->u.params.level == SCHED_CLASS_LEVEL_CH_RL) {
8348 p->u.params.pktsize = 0;
8351 /* See what the firmware thinks of the request ... */
8352 rc = -t4_sched_params(sc, fw_type, fw_level, fw_mode,
8353 fw_rateunit, fw_ratemode, p->u.params.channel,
8354 p->u.params.cl, p->u.params.minrate, p->u.params.maxrate,
8355 p->u.params.weight, p->u.params.pktsize, 1);
8361 end_synchronized_op(sc, 0);
8366 set_sched_queue(struct adapter *sc, struct t4_sched_queue *p)
8368 struct port_info *pi = NULL;
8370 struct sge_txq *txq;
8371 uint32_t fw_mnem, fw_queue, fw_class;
8374 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setsq");
8378 if (!(sc->flags & FULL_INIT_DONE)) {
8383 if (p->port >= sc->params.nports) {
8388 /* XXX: Only supported for the main VI. */
8389 pi = sc->port[p->port];
8391 if (!in_range(p->queue, 0, vi->ntxq - 1) || !in_range(p->cl, 0, 7)) {
8397 * Create a template for the FW_PARAMS_CMD mnemonic and value (TX
8398 * Scheduling Class in this case).
8400 fw_mnem = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DMAQ) |
8401 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DMAQ_EQ_SCHEDCLASS_ETH));
8402 fw_class = p->cl < 0 ? 0xffffffff : p->cl;
8405 * If op.queue is non-negative, then we're only changing the scheduling
8406 * on a single specified TX queue.
8408 if (p->queue >= 0) {
8409 txq = &sc->sge.txq[vi->first_txq + p->queue];
8410 fw_queue = (fw_mnem | V_FW_PARAMS_PARAM_YZ(txq->eq.cntxt_id));
8411 rc = -t4_set_params(sc, sc->mbox, sc->pf, 0, 1, &fw_queue,
8417 * Change the scheduling on all the TX queues for the
8420 for_each_txq(vi, i, txq) {
8421 fw_queue = (fw_mnem | V_FW_PARAMS_PARAM_YZ(txq->eq.cntxt_id));
8422 rc = -t4_set_params(sc, sc->mbox, sc->pf, 0, 1, &fw_queue,
8430 end_synchronized_op(sc, 0);
8435 t4_os_find_pci_capability(struct adapter *sc, int cap)
8439 return (pci_find_cap(sc->dev, cap, &i) == 0 ? i : 0);
8443 t4_os_pci_save_state(struct adapter *sc)
8446 struct pci_devinfo *dinfo;
8449 dinfo = device_get_ivars(dev);
8451 pci_cfg_save(dev, dinfo, 0);
8456 t4_os_pci_restore_state(struct adapter *sc)
8459 struct pci_devinfo *dinfo;
8462 dinfo = device_get_ivars(dev);
8464 pci_cfg_restore(dev, dinfo);
8469 t4_os_portmod_changed(const struct adapter *sc, int idx)
8471 struct port_info *pi = sc->port[idx];
8475 static const char *mod_str[] = {
8476 NULL, "LR", "SR", "ER", "TWINAX", "active TWINAX", "LRM"
8479 for_each_vi(pi, v, vi) {
8480 build_medialist(pi, &vi->media);
8483 ifp = pi->vi[0].ifp;
8484 if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
8485 if_printf(ifp, "transceiver unplugged.\n");
8486 else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
8487 if_printf(ifp, "unknown transceiver inserted.\n");
8488 else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
8489 if_printf(ifp, "unsupported transceiver inserted.\n");
8490 else if (pi->mod_type > 0 && pi->mod_type < nitems(mod_str)) {
8491 if_printf(ifp, "%s transceiver inserted.\n",
8492 mod_str[pi->mod_type]);
8494 if_printf(ifp, "transceiver (type %d) inserted.\n",
8500 t4_os_link_changed(struct adapter *sc, int idx, int link_stat, int reason)
8502 struct port_info *pi = sc->port[idx];
8511 pi->linkdnrc = reason;
8513 for_each_vi(pi, v, vi) {
8519 ifp->if_baudrate = IF_Mbps(pi->link_cfg.speed);
8520 if_link_state_change(ifp, LINK_STATE_UP);
8522 if_link_state_change(ifp, LINK_STATE_DOWN);
8528 t4_iterate(void (*func)(struct adapter *, void *), void *arg)
8532 sx_slock(&t4_list_lock);
8533 SLIST_FOREACH(sc, &t4_list, link) {
8535 * func should not make any assumptions about what state sc is
8536 * in - the only guarantee is that sc->sc_lock is a valid lock.
8540 sx_sunlock(&t4_list_lock);
8544 t4_open(struct cdev *dev, int flags, int type, struct thread *td)
8550 t4_close(struct cdev *dev, int flags, int type, struct thread *td)
8556 t4_ioctl(struct cdev *dev, unsigned long cmd, caddr_t data, int fflag,
8560 struct adapter *sc = dev->si_drv1;
8562 rc = priv_check(td, PRIV_DRIVER);
8567 case CHELSIO_T4_GETREG: {
8568 struct t4_reg *edata = (struct t4_reg *)data;
8570 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
8573 if (edata->size == 4)
8574 edata->val = t4_read_reg(sc, edata->addr);
8575 else if (edata->size == 8)
8576 edata->val = t4_read_reg64(sc, edata->addr);
8582 case CHELSIO_T4_SETREG: {
8583 struct t4_reg *edata = (struct t4_reg *)data;
8585 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
8588 if (edata->size == 4) {
8589 if (edata->val & 0xffffffff00000000)
8591 t4_write_reg(sc, edata->addr, (uint32_t) edata->val);
8592 } else if (edata->size == 8)
8593 t4_write_reg64(sc, edata->addr, edata->val);
8598 case CHELSIO_T4_REGDUMP: {
8599 struct t4_regdump *regs = (struct t4_regdump *)data;
8600 int reglen = is_t4(sc) ? T4_REGDUMP_SIZE : T5_REGDUMP_SIZE;
8603 if (regs->len < reglen) {
8604 regs->len = reglen; /* hint to the caller */
8609 buf = malloc(reglen, M_CXGBE, M_WAITOK | M_ZERO);
8610 t4_get_regs(sc, regs, buf);
8611 rc = copyout(buf, regs->data, reglen);
8615 case CHELSIO_T4_GET_FILTER_MODE:
8616 rc = get_filter_mode(sc, (uint32_t *)data);
8618 case CHELSIO_T4_SET_FILTER_MODE:
8619 rc = set_filter_mode(sc, *(uint32_t *)data);
8621 case CHELSIO_T4_GET_FILTER:
8622 rc = get_filter(sc, (struct t4_filter *)data);
8624 case CHELSIO_T4_SET_FILTER:
8625 rc = set_filter(sc, (struct t4_filter *)data);
8627 case CHELSIO_T4_DEL_FILTER:
8628 rc = del_filter(sc, (struct t4_filter *)data);
8630 case CHELSIO_T4_GET_SGE_CONTEXT:
8631 rc = get_sge_context(sc, (struct t4_sge_context *)data);
8633 case CHELSIO_T4_LOAD_FW:
8634 rc = load_fw(sc, (struct t4_data *)data);
8636 case CHELSIO_T4_GET_MEM:
8637 rc = read_card_mem(sc, 2, (struct t4_mem_range *)data);
8639 case CHELSIO_T4_GET_I2C:
8640 rc = read_i2c(sc, (struct t4_i2c_data *)data);
8642 case CHELSIO_T4_CLEAR_STATS: {
8644 u_int port_id = *(uint32_t *)data;
8645 struct port_info *pi;
8648 if (port_id >= sc->params.nports)
8650 pi = sc->port[port_id];
8653 t4_clr_port_stats(sc, pi->tx_chan);
8654 pi->tx_parse_error = 0;
8655 mtx_lock(&sc->regwin_lock);
8656 for_each_vi(pi, v, vi) {
8657 if (vi->flags & VI_INIT_DONE)
8658 t4_clr_vi_stats(sc, vi->viid);
8660 mtx_unlock(&sc->regwin_lock);
8663 * Since this command accepts a port, clear stats for
8664 * all VIs on this port.
8666 for_each_vi(pi, v, vi) {
8667 if (vi->flags & VI_INIT_DONE) {
8668 struct sge_rxq *rxq;
8669 struct sge_txq *txq;
8670 struct sge_wrq *wrq;
8672 for_each_rxq(vi, i, rxq) {
8673 #if defined(INET) || defined(INET6)
8674 rxq->lro.lro_queued = 0;
8675 rxq->lro.lro_flushed = 0;
8678 rxq->vlan_extraction = 0;
8681 for_each_txq(vi, i, txq) {
8684 txq->vlan_insertion = 0;
8688 txq->txpkts0_wrs = 0;
8689 txq->txpkts1_wrs = 0;
8690 txq->txpkts0_pkts = 0;
8691 txq->txpkts1_pkts = 0;
8692 mp_ring_reset_stats(txq->r);
8696 /* nothing to clear for each ofld_rxq */
8698 for_each_ofld_txq(vi, i, wrq) {
8699 wrq->tx_wrs_direct = 0;
8700 wrq->tx_wrs_copied = 0;
8704 if (IS_MAIN_VI(vi)) {
8705 wrq = &sc->sge.ctrlq[pi->port_id];
8706 wrq->tx_wrs_direct = 0;
8707 wrq->tx_wrs_copied = 0;
8713 case CHELSIO_T4_SCHED_CLASS:
8714 rc = set_sched_class(sc, (struct t4_sched_params *)data);
8716 case CHELSIO_T4_SCHED_QUEUE:
8717 rc = set_sched_queue(sc, (struct t4_sched_queue *)data);
8719 case CHELSIO_T4_GET_TRACER:
8720 rc = t4_get_tracer(sc, (struct t4_tracer *)data);
8722 case CHELSIO_T4_SET_TRACER:
8723 rc = t4_set_tracer(sc, (struct t4_tracer *)data);
8734 t4_iscsi_init(struct ifnet *ifp, unsigned int tag_mask,
8735 const unsigned int *pgsz_order)
8737 struct vi_info *vi = ifp->if_softc;
8738 struct adapter *sc = vi->pi->adapter;
8740 t4_write_reg(sc, A_ULP_RX_ISCSI_TAGMASK, tag_mask);
8741 t4_write_reg(sc, A_ULP_RX_ISCSI_PSZ, V_HPZ0(pgsz_order[0]) |
8742 V_HPZ1(pgsz_order[1]) | V_HPZ2(pgsz_order[2]) |
8743 V_HPZ3(pgsz_order[3]));
8747 toe_capability(struct vi_info *vi, int enable)
8750 struct port_info *pi = vi->pi;
8751 struct adapter *sc = pi->adapter;
8753 ASSERT_SYNCHRONIZED_OP(sc);
8755 if (!is_offload(sc))
8759 if ((vi->ifp->if_capenable & IFCAP_TOE) != 0) {
8760 /* TOE is already enabled. */
8765 * We need the port's queues around so that we're able to send
8766 * and receive CPLs to/from the TOE even if the ifnet for this
8767 * port has never been UP'd administratively.
8769 if (!(vi->flags & VI_INIT_DONE)) {
8770 rc = vi_full_init(vi);
8774 if (!(pi->vi[0].flags & VI_INIT_DONE)) {
8775 rc = vi_full_init(&pi->vi[0]);
8780 if (isset(&sc->offload_map, pi->port_id)) {
8781 /* TOE is enabled on another VI of this port. */
8786 if (!uld_active(sc, ULD_TOM)) {
8787 rc = t4_activate_uld(sc, ULD_TOM);
8790 "You must kldload t4_tom.ko before trying "
8791 "to enable TOE on a cxgbe interface.\n");
8795 KASSERT(sc->tom_softc != NULL,
8796 ("%s: TOM activated but softc NULL", __func__));
8797 KASSERT(uld_active(sc, ULD_TOM),
8798 ("%s: TOM activated but flag not set", __func__));
8801 /* Activate iWARP and iSCSI too, if the modules are loaded. */
8802 if (!uld_active(sc, ULD_IWARP))
8803 (void) t4_activate_uld(sc, ULD_IWARP);
8804 if (!uld_active(sc, ULD_ISCSI))
8805 (void) t4_activate_uld(sc, ULD_ISCSI);
8808 setbit(&sc->offload_map, pi->port_id);
8812 if (!isset(&sc->offload_map, pi->port_id) || pi->uld_vis > 0)
8815 KASSERT(uld_active(sc, ULD_TOM),
8816 ("%s: TOM never initialized?", __func__));
8817 clrbit(&sc->offload_map, pi->port_id);
8824 * Add an upper layer driver to the global list.
8827 t4_register_uld(struct uld_info *ui)
8832 sx_xlock(&t4_uld_list_lock);
8833 SLIST_FOREACH(u, &t4_uld_list, link) {
8834 if (u->uld_id == ui->uld_id) {
8840 SLIST_INSERT_HEAD(&t4_uld_list, ui, link);
8843 sx_xunlock(&t4_uld_list_lock);
8848 t4_unregister_uld(struct uld_info *ui)
8853 sx_xlock(&t4_uld_list_lock);
8855 SLIST_FOREACH(u, &t4_uld_list, link) {
8857 if (ui->refcount > 0) {
8862 SLIST_REMOVE(&t4_uld_list, ui, uld_info, link);
8868 sx_xunlock(&t4_uld_list_lock);
8873 t4_activate_uld(struct adapter *sc, int id)
8876 struct uld_info *ui;
8878 ASSERT_SYNCHRONIZED_OP(sc);
8880 if (id < 0 || id > ULD_MAX)
8882 rc = EAGAIN; /* kldoad the module with this ULD and try again. */
8884 sx_slock(&t4_uld_list_lock);
8886 SLIST_FOREACH(ui, &t4_uld_list, link) {
8887 if (ui->uld_id == id) {
8888 if (!(sc->flags & FULL_INIT_DONE)) {
8889 rc = adapter_full_init(sc);
8894 rc = ui->activate(sc);
8896 setbit(&sc->active_ulds, id);
8903 sx_sunlock(&t4_uld_list_lock);
8909 t4_deactivate_uld(struct adapter *sc, int id)
8912 struct uld_info *ui;
8914 ASSERT_SYNCHRONIZED_OP(sc);
8916 if (id < 0 || id > ULD_MAX)
8920 sx_slock(&t4_uld_list_lock);
8922 SLIST_FOREACH(ui, &t4_uld_list, link) {
8923 if (ui->uld_id == id) {
8924 rc = ui->deactivate(sc);
8926 clrbit(&sc->active_ulds, id);
8933 sx_sunlock(&t4_uld_list_lock);
8939 uld_active(struct adapter *sc, int uld_id)
8942 MPASS(uld_id >= 0 && uld_id <= ULD_MAX);
8944 return (isset(&sc->active_ulds, uld_id));
8949 * Come up with reasonable defaults for some of the tunables, provided they're
8950 * not set by the user (in which case we'll use the values as is).
8953 tweak_tunables(void)
8955 int nc = mp_ncpus; /* our snapshot of the number of CPUs */
8957 if (t4_ntxq10g < 1) {
8959 t4_ntxq10g = rss_getnumbuckets();
8961 t4_ntxq10g = min(nc, NTXQ_10G);
8965 if (t4_ntxq1g < 1) {
8967 /* XXX: way too many for 1GbE? */
8968 t4_ntxq1g = rss_getnumbuckets();
8970 t4_ntxq1g = min(nc, NTXQ_1G);
8975 t4_ntxq_vi = min(nc, NTXQ_VI);
8977 if (t4_nrxq10g < 1) {
8979 t4_nrxq10g = rss_getnumbuckets();
8981 t4_nrxq10g = min(nc, NRXQ_10G);
8985 if (t4_nrxq1g < 1) {
8987 /* XXX: way too many for 1GbE? */
8988 t4_nrxq1g = rss_getnumbuckets();
8990 t4_nrxq1g = min(nc, NRXQ_1G);
8995 t4_nrxq_vi = min(nc, NRXQ_VI);
8998 if (t4_nofldtxq10g < 1)
8999 t4_nofldtxq10g = min(nc, NOFLDTXQ_10G);
9001 if (t4_nofldtxq1g < 1)
9002 t4_nofldtxq1g = min(nc, NOFLDTXQ_1G);
9004 if (t4_nofldtxq_vi < 1)
9005 t4_nofldtxq_vi = min(nc, NOFLDTXQ_VI);
9007 if (t4_nofldrxq10g < 1)
9008 t4_nofldrxq10g = min(nc, NOFLDRXQ_10G);
9010 if (t4_nofldrxq1g < 1)
9011 t4_nofldrxq1g = min(nc, NOFLDRXQ_1G);
9013 if (t4_nofldrxq_vi < 1)
9014 t4_nofldrxq_vi = min(nc, NOFLDRXQ_VI);
9016 if (t4_toecaps_allowed == -1)
9017 t4_toecaps_allowed = FW_CAPS_CONFIG_TOE;
9019 if (t4_toecaps_allowed == -1)
9020 t4_toecaps_allowed = 0;
9024 if (t4_nnmtxq_vi < 1)
9025 t4_nnmtxq_vi = min(nc, NNMTXQ_VI);
9027 if (t4_nnmrxq_vi < 1)
9028 t4_nnmrxq_vi = min(nc, NNMRXQ_VI);
9031 if (t4_tmr_idx_10g < 0 || t4_tmr_idx_10g >= SGE_NTIMERS)
9032 t4_tmr_idx_10g = TMR_IDX_10G;
9034 if (t4_pktc_idx_10g < -1 || t4_pktc_idx_10g >= SGE_NCOUNTERS)
9035 t4_pktc_idx_10g = PKTC_IDX_10G;
9037 if (t4_tmr_idx_1g < 0 || t4_tmr_idx_1g >= SGE_NTIMERS)
9038 t4_tmr_idx_1g = TMR_IDX_1G;
9040 if (t4_pktc_idx_1g < -1 || t4_pktc_idx_1g >= SGE_NCOUNTERS)
9041 t4_pktc_idx_1g = PKTC_IDX_1G;
9043 if (t4_qsize_txq < 128)
9046 if (t4_qsize_rxq < 128)
9048 while (t4_qsize_rxq & 7)
9051 t4_intr_types &= INTR_MSIX | INTR_MSI | INTR_INTX;
9054 static struct sx mlu; /* mod load unload */
9055 SX_SYSINIT(cxgbe_mlu, &mlu, "cxgbe mod load/unload");
9058 mod_event(module_t mod, int cmd, void *arg)
9061 static int loaded = 0;
9066 if (loaded++ == 0) {
9068 sx_init(&t4_list_lock, "T4/T5 adapters");
9069 SLIST_INIT(&t4_list);
9071 sx_init(&t4_uld_list_lock, "T4/T5 ULDs");
9072 SLIST_INIT(&t4_uld_list);
9074 t4_tracer_modload();
9082 if (--loaded == 0) {
9085 sx_slock(&t4_list_lock);
9086 if (!SLIST_EMPTY(&t4_list)) {
9088 sx_sunlock(&t4_list_lock);
9092 sx_slock(&t4_uld_list_lock);
9093 if (!SLIST_EMPTY(&t4_uld_list)) {
9095 sx_sunlock(&t4_uld_list_lock);
9096 sx_sunlock(&t4_list_lock);
9101 while (tries++ < 5 && t4_sge_extfree_refs() != 0) {
9102 uprintf("%ju clusters with custom free routine "
9103 "still is use.\n", t4_sge_extfree_refs());
9104 pause("t4unload", 2 * hz);
9107 sx_sunlock(&t4_uld_list_lock);
9109 sx_sunlock(&t4_list_lock);
9111 if (t4_sge_extfree_refs() == 0) {
9112 t4_tracer_modunload();
9114 sx_destroy(&t4_uld_list_lock);
9116 sx_destroy(&t4_list_lock);
9121 loaded++; /* undo earlier decrement */
9132 static devclass_t t4_devclass, t5_devclass;
9133 static devclass_t cxgbe_devclass, cxl_devclass;
9134 static devclass_t vcxgbe_devclass, vcxl_devclass;
9136 DRIVER_MODULE(t4nex, pci, t4_driver, t4_devclass, mod_event, 0);
9137 MODULE_VERSION(t4nex, 1);
9138 MODULE_DEPEND(t4nex, firmware, 1, 1, 1);
9140 DRIVER_MODULE(t5nex, pci, t5_driver, t5_devclass, mod_event, 0);
9141 MODULE_VERSION(t5nex, 1);
9142 MODULE_DEPEND(t5nex, firmware, 1, 1, 1);
9144 DRIVER_MODULE(cxgbe, t4nex, cxgbe_driver, cxgbe_devclass, 0, 0);
9145 MODULE_VERSION(cxgbe, 1);
9147 DRIVER_MODULE(cxl, t5nex, cxl_driver, cxl_devclass, 0, 0);
9148 MODULE_VERSION(cxl, 1);
9150 DRIVER_MODULE(vcxgbe, cxgbe, vcxgbe_driver, vcxgbe_devclass, 0, 0);
9151 MODULE_VERSION(vcxgbe, 1);
9153 DRIVER_MODULE(vcxl, cxl, vcxl_driver, vcxl_devclass, 0, 0);
9154 MODULE_VERSION(vcxl, 1);