2 * Copyright (c) 2011 Chelsio Communications, Inc.
4 * Written by: Navdeep Parhar <np@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
32 #include "opt_inet6.h"
34 #include <sys/param.h>
37 #include <sys/kernel.h>
39 #include <sys/module.h>
40 #include <sys/malloc.h>
41 #include <sys/queue.h>
42 #include <sys/taskqueue.h>
43 #include <sys/pciio.h>
44 #include <dev/pci/pcireg.h>
45 #include <dev/pci/pcivar.h>
46 #include <dev/pci/pci_private.h>
47 #include <sys/firmware.h>
50 #include <sys/socket.h>
51 #include <sys/sockio.h>
52 #include <sys/sysctl.h>
53 #include <net/ethernet.h>
55 #include <net/if_types.h>
56 #include <net/if_dl.h>
57 #include <net/if_vlan_var.h>
58 #if defined(__i386__) || defined(__amd64__)
63 #include "common/common.h"
64 #include "common/t4_msg.h"
65 #include "common/t4_regs.h"
66 #include "common/t4_regs_values.h"
70 /* T4 bus driver interface */
71 static int t4_probe(device_t);
72 static int t4_attach(device_t);
73 static int t4_detach(device_t);
74 static device_method_t t4_methods[] = {
75 DEVMETHOD(device_probe, t4_probe),
76 DEVMETHOD(device_attach, t4_attach),
77 DEVMETHOD(device_detach, t4_detach),
81 static driver_t t4_driver = {
84 sizeof(struct adapter)
88 /* T4 port (cxgbe) interface */
89 static int cxgbe_probe(device_t);
90 static int cxgbe_attach(device_t);
91 static int cxgbe_detach(device_t);
92 static device_method_t cxgbe_methods[] = {
93 DEVMETHOD(device_probe, cxgbe_probe),
94 DEVMETHOD(device_attach, cxgbe_attach),
95 DEVMETHOD(device_detach, cxgbe_detach),
98 static driver_t cxgbe_driver = {
101 sizeof(struct port_info)
104 static d_ioctl_t t4_ioctl;
105 static d_open_t t4_open;
106 static d_close_t t4_close;
108 static struct cdevsw t4_cdevsw = {
109 .d_version = D_VERSION,
117 /* T5 bus driver interface */
118 static int t5_probe(device_t);
119 static device_method_t t5_methods[] = {
120 DEVMETHOD(device_probe, t5_probe),
121 DEVMETHOD(device_attach, t4_attach),
122 DEVMETHOD(device_detach, t4_detach),
126 static driver_t t5_driver = {
129 sizeof(struct adapter)
133 /* T5 port (cxl) interface */
134 static driver_t cxl_driver = {
137 sizeof(struct port_info)
140 static struct cdevsw t5_cdevsw = {
141 .d_version = D_VERSION,
149 /* ifnet + media interface */
150 static void cxgbe_init(void *);
151 static int cxgbe_ioctl(struct ifnet *, unsigned long, caddr_t);
152 static int cxgbe_transmit(struct ifnet *, struct mbuf *);
153 static void cxgbe_qflush(struct ifnet *);
154 static int cxgbe_media_change(struct ifnet *);
155 static void cxgbe_media_status(struct ifnet *, struct ifmediareq *);
157 MALLOC_DEFINE(M_CXGBE, "cxgbe", "Chelsio T4/T5 Ethernet driver and services");
160 * Correct lock order when you need to acquire multiple locks is t4_list_lock,
161 * then ADAPTER_LOCK, then t4_uld_list_lock.
163 static struct sx t4_list_lock;
164 SLIST_HEAD(, adapter) t4_list;
166 static struct sx t4_uld_list_lock;
167 SLIST_HEAD(, uld_info) t4_uld_list;
171 * Tunables. See tweak_tunables() too.
173 * Each tunable is set to a default value here if it's known at compile-time.
174 * Otherwise it is set to -1 as an indication to tweak_tunables() that it should
175 * provide a reasonable default when the driver is loaded.
177 * Tunables applicable to both T4 and T5 are under hw.cxgbe. Those specific to
178 * T5 are under hw.cxl.
182 * Number of queues for tx and rx, 10G and 1G, NIC and offload.
185 static int t4_ntxq10g = -1;
186 TUNABLE_INT("hw.cxgbe.ntxq10g", &t4_ntxq10g);
189 static int t4_nrxq10g = -1;
190 TUNABLE_INT("hw.cxgbe.nrxq10g", &t4_nrxq10g);
193 static int t4_ntxq1g = -1;
194 TUNABLE_INT("hw.cxgbe.ntxq1g", &t4_ntxq1g);
197 static int t4_nrxq1g = -1;
198 TUNABLE_INT("hw.cxgbe.nrxq1g", &t4_nrxq1g);
200 static int t4_rsrv_noflowq = 0;
201 TUNABLE_INT("hw.cxgbe.rsrv_noflowq", &t4_rsrv_noflowq);
204 #define NOFLDTXQ_10G 8
205 static int t4_nofldtxq10g = -1;
206 TUNABLE_INT("hw.cxgbe.nofldtxq10g", &t4_nofldtxq10g);
208 #define NOFLDRXQ_10G 2
209 static int t4_nofldrxq10g = -1;
210 TUNABLE_INT("hw.cxgbe.nofldrxq10g", &t4_nofldrxq10g);
212 #define NOFLDTXQ_1G 2
213 static int t4_nofldtxq1g = -1;
214 TUNABLE_INT("hw.cxgbe.nofldtxq1g", &t4_nofldtxq1g);
216 #define NOFLDRXQ_1G 1
217 static int t4_nofldrxq1g = -1;
218 TUNABLE_INT("hw.cxgbe.nofldrxq1g", &t4_nofldrxq1g);
223 static int t4_nnmtxq10g = -1;
224 TUNABLE_INT("hw.cxgbe.nnmtxq10g", &t4_nnmtxq10g);
227 static int t4_nnmrxq10g = -1;
228 TUNABLE_INT("hw.cxgbe.nnmrxq10g", &t4_nnmrxq10g);
231 static int t4_nnmtxq1g = -1;
232 TUNABLE_INT("hw.cxgbe.nnmtxq1g", &t4_nnmtxq1g);
235 static int t4_nnmrxq1g = -1;
236 TUNABLE_INT("hw.cxgbe.nnmrxq1g", &t4_nnmrxq1g);
240 * Holdoff parameters for 10G and 1G ports.
242 #define TMR_IDX_10G 1
243 static int t4_tmr_idx_10g = TMR_IDX_10G;
244 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_10G", &t4_tmr_idx_10g);
246 #define PKTC_IDX_10G (-1)
247 static int t4_pktc_idx_10g = PKTC_IDX_10G;
248 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_10G", &t4_pktc_idx_10g);
251 static int t4_tmr_idx_1g = TMR_IDX_1G;
252 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_1G", &t4_tmr_idx_1g);
254 #define PKTC_IDX_1G (-1)
255 static int t4_pktc_idx_1g = PKTC_IDX_1G;
256 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_1G", &t4_pktc_idx_1g);
259 * Size (# of entries) of each tx and rx queue.
261 static unsigned int t4_qsize_txq = TX_EQ_QSIZE;
262 TUNABLE_INT("hw.cxgbe.qsize_txq", &t4_qsize_txq);
264 static unsigned int t4_qsize_rxq = RX_IQ_QSIZE;
265 TUNABLE_INT("hw.cxgbe.qsize_rxq", &t4_qsize_rxq);
268 * Interrupt types allowed (bits 0, 1, 2 = INTx, MSI, MSI-X respectively).
270 static int t4_intr_types = INTR_MSIX | INTR_MSI | INTR_INTX;
271 TUNABLE_INT("hw.cxgbe.interrupt_types", &t4_intr_types);
274 * Configuration file.
276 #define DEFAULT_CF "default"
277 #define FLASH_CF "flash"
278 #define UWIRE_CF "uwire"
279 #define FPGA_CF "fpga"
280 static char t4_cfg_file[32] = DEFAULT_CF;
281 TUNABLE_STR("hw.cxgbe.config_file", t4_cfg_file, sizeof(t4_cfg_file));
284 * PAUSE settings (bit 0, 1 = rx_pause, tx_pause respectively).
285 * rx_pause = 1 to heed incoming PAUSE frames, 0 to ignore them.
286 * tx_pause = 1 to emit PAUSE frames when the rx FIFO reaches its high water
287 * mark or when signalled to do so, 0 to never emit PAUSE.
289 static int t4_pause_settings = PAUSE_TX | PAUSE_RX;
290 TUNABLE_INT("hw.cxgbe.pause_settings", &t4_pause_settings);
293 * Firmware auto-install by driver during attach (0, 1, 2 = prohibited, allowed,
294 * encouraged respectively).
296 static unsigned int t4_fw_install = 1;
297 TUNABLE_INT("hw.cxgbe.fw_install", &t4_fw_install);
300 * ASIC features that will be used. Disable the ones you don't want so that the
301 * chip resources aren't wasted on features that will not be used.
303 static int t4_linkcaps_allowed = 0; /* No DCBX, PPP, etc. by default */
304 TUNABLE_INT("hw.cxgbe.linkcaps_allowed", &t4_linkcaps_allowed);
306 static int t4_niccaps_allowed = FW_CAPS_CONFIG_NIC;
307 TUNABLE_INT("hw.cxgbe.niccaps_allowed", &t4_niccaps_allowed);
309 static int t4_toecaps_allowed = -1;
310 TUNABLE_INT("hw.cxgbe.toecaps_allowed", &t4_toecaps_allowed);
312 static int t4_rdmacaps_allowed = 0;
313 TUNABLE_INT("hw.cxgbe.rdmacaps_allowed", &t4_rdmacaps_allowed);
315 static int t4_iscsicaps_allowed = 0;
316 TUNABLE_INT("hw.cxgbe.iscsicaps_allowed", &t4_iscsicaps_allowed);
318 static int t4_fcoecaps_allowed = 0;
319 TUNABLE_INT("hw.cxgbe.fcoecaps_allowed", &t4_fcoecaps_allowed);
321 static int t5_write_combine = 0;
322 TUNABLE_INT("hw.cxl.write_combine", &t5_write_combine);
324 struct intrs_and_queues {
325 uint16_t intr_type; /* INTx, MSI, or MSI-X */
326 uint16_t nirq; /* Total # of vectors */
327 uint16_t intr_flags_10g;/* Interrupt flags for each 10G port */
328 uint16_t intr_flags_1g; /* Interrupt flags for each 1G port */
329 uint16_t ntxq10g; /* # of NIC txq's for each 10G port */
330 uint16_t nrxq10g; /* # of NIC rxq's for each 10G port */
331 uint16_t ntxq1g; /* # of NIC txq's for each 1G port */
332 uint16_t nrxq1g; /* # of NIC rxq's for each 1G port */
333 uint16_t rsrv_noflowq; /* Flag whether to reserve queue 0 */
335 uint16_t nofldtxq10g; /* # of TOE txq's for each 10G port */
336 uint16_t nofldrxq10g; /* # of TOE rxq's for each 10G port */
337 uint16_t nofldtxq1g; /* # of TOE txq's for each 1G port */
338 uint16_t nofldrxq1g; /* # of TOE rxq's for each 1G port */
341 uint16_t nnmtxq10g; /* # of netmap txq's for each 10G port */
342 uint16_t nnmrxq10g; /* # of netmap rxq's for each 10G port */
343 uint16_t nnmtxq1g; /* # of netmap txq's for each 1G port */
344 uint16_t nnmrxq1g; /* # of netmap rxq's for each 1G port */
348 struct filter_entry {
349 uint32_t valid:1; /* filter allocated and valid */
350 uint32_t locked:1; /* filter is administratively locked */
351 uint32_t pending:1; /* filter action is pending firmware reply */
352 uint32_t smtidx:8; /* Source MAC Table index for smac */
353 struct l2t_entry *l2t; /* Layer Two Table entry for dmac */
355 struct t4_filter_specification fs;
358 static int map_bars_0_and_4(struct adapter *);
359 static int map_bar_2(struct adapter *);
360 static void setup_memwin(struct adapter *);
361 static int validate_mem_range(struct adapter *, uint32_t, int);
362 static int fwmtype_to_hwmtype(int);
363 static int validate_mt_off_len(struct adapter *, int, uint32_t, int,
365 static void memwin_info(struct adapter *, int, uint32_t *, uint32_t *);
366 static uint32_t position_memwin(struct adapter *, int, uint32_t);
367 static int cfg_itype_and_nqueues(struct adapter *, int, int,
368 struct intrs_and_queues *);
369 static int prep_firmware(struct adapter *);
370 static int partition_resources(struct adapter *, const struct firmware *,
372 static int get_params__pre_init(struct adapter *);
373 static int get_params__post_init(struct adapter *);
374 static int set_params__post_init(struct adapter *);
375 static void t4_set_desc(struct adapter *);
376 static void build_medialist(struct port_info *, struct ifmedia *);
377 static int cxgbe_init_synchronized(struct port_info *);
378 static int cxgbe_uninit_synchronized(struct port_info *);
379 static int setup_intr_handlers(struct adapter *);
380 static void quiesce_eq(struct adapter *, struct sge_eq *);
381 static void quiesce_iq(struct adapter *, struct sge_iq *);
382 static void quiesce_fl(struct adapter *, struct sge_fl *);
383 static int t4_alloc_irq(struct adapter *, struct irq *, int rid,
384 driver_intr_t *, void *, char *);
385 static int t4_free_irq(struct adapter *, struct irq *);
386 static void reg_block_dump(struct adapter *, uint8_t *, unsigned int,
388 static void t4_get_regs(struct adapter *, struct t4_regdump *, uint8_t *);
389 static void cxgbe_refresh_stats(struct adapter *, struct port_info *);
390 static void cxgbe_tick(void *);
391 static void cxgbe_vlan_config(void *, struct ifnet *, uint16_t);
392 static int cpl_not_handled(struct sge_iq *, const struct rss_header *,
394 static int an_not_handled(struct sge_iq *, const struct rsp_ctrl *);
395 static int fw_msg_not_handled(struct adapter *, const __be64 *);
396 static int t4_sysctls(struct adapter *);
397 static int cxgbe_sysctls(struct port_info *);
398 static int sysctl_int_array(SYSCTL_HANDLER_ARGS);
399 static int sysctl_bitfield(SYSCTL_HANDLER_ARGS);
400 static int sysctl_btphy(SYSCTL_HANDLER_ARGS);
401 static int sysctl_noflowq(SYSCTL_HANDLER_ARGS);
402 static int sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS);
403 static int sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS);
404 static int sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS);
405 static int sysctl_qsize_txq(SYSCTL_HANDLER_ARGS);
406 static int sysctl_pause_settings(SYSCTL_HANDLER_ARGS);
407 static int sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS);
408 static int sysctl_temperature(SYSCTL_HANDLER_ARGS);
410 static int sysctl_cctrl(SYSCTL_HANDLER_ARGS);
411 static int sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS);
412 static int sysctl_cim_la(SYSCTL_HANDLER_ARGS);
413 static int sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS);
414 static int sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS);
415 static int sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS);
416 static int sysctl_cpl_stats(SYSCTL_HANDLER_ARGS);
417 static int sysctl_ddp_stats(SYSCTL_HANDLER_ARGS);
418 static int sysctl_devlog(SYSCTL_HANDLER_ARGS);
419 static int sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS);
420 static int sysctl_hw_sched(SYSCTL_HANDLER_ARGS);
421 static int sysctl_lb_stats(SYSCTL_HANDLER_ARGS);
422 static int sysctl_linkdnrc(SYSCTL_HANDLER_ARGS);
423 static int sysctl_meminfo(SYSCTL_HANDLER_ARGS);
424 static int sysctl_mps_tcam(SYSCTL_HANDLER_ARGS);
425 static int sysctl_path_mtus(SYSCTL_HANDLER_ARGS);
426 static int sysctl_pm_stats(SYSCTL_HANDLER_ARGS);
427 static int sysctl_rdma_stats(SYSCTL_HANDLER_ARGS);
428 static int sysctl_tcp_stats(SYSCTL_HANDLER_ARGS);
429 static int sysctl_tids(SYSCTL_HANDLER_ARGS);
430 static int sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS);
431 static int sysctl_tp_la(SYSCTL_HANDLER_ARGS);
432 static int sysctl_tx_rate(SYSCTL_HANDLER_ARGS);
433 static int sysctl_ulprx_la(SYSCTL_HANDLER_ARGS);
434 static int sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS);
436 static inline void txq_start(struct ifnet *, struct sge_txq *);
437 static uint32_t fconf_to_mode(uint32_t);
438 static uint32_t mode_to_fconf(uint32_t);
439 static uint32_t fspec_to_fconf(struct t4_filter_specification *);
440 static int get_filter_mode(struct adapter *, uint32_t *);
441 static int set_filter_mode(struct adapter *, uint32_t);
442 static inline uint64_t get_filter_hits(struct adapter *, uint32_t);
443 static int get_filter(struct adapter *, struct t4_filter *);
444 static int set_filter(struct adapter *, struct t4_filter *);
445 static int del_filter(struct adapter *, struct t4_filter *);
446 static void clear_filter(struct filter_entry *);
447 static int set_filter_wr(struct adapter *, int);
448 static int del_filter_wr(struct adapter *, int);
449 static int get_sge_context(struct adapter *, struct t4_sge_context *);
450 static int load_fw(struct adapter *, struct t4_data *);
451 static int read_card_mem(struct adapter *, int, struct t4_mem_range *);
452 static int read_i2c(struct adapter *, struct t4_i2c_data *);
453 static int set_sched_class(struct adapter *, struct t4_sched_params *);
454 static int set_sched_queue(struct adapter *, struct t4_sched_queue *);
456 static int toe_capability(struct port_info *, int);
458 static int mod_event(module_t, int, void *);
464 {0xa000, "Chelsio Terminator 4 FPGA"},
465 {0x4400, "Chelsio T440-dbg"},
466 {0x4401, "Chelsio T420-CR"},
467 {0x4402, "Chelsio T422-CR"},
468 {0x4403, "Chelsio T440-CR"},
469 {0x4404, "Chelsio T420-BCH"},
470 {0x4405, "Chelsio T440-BCH"},
471 {0x4406, "Chelsio T440-CH"},
472 {0x4407, "Chelsio T420-SO"},
473 {0x4408, "Chelsio T420-CX"},
474 {0x4409, "Chelsio T420-BT"},
475 {0x440a, "Chelsio T404-BT"},
476 {0x440e, "Chelsio T440-LP-CR"},
478 {0xb000, "Chelsio Terminator 5 FPGA"},
479 {0x5400, "Chelsio T580-dbg"},
480 {0x5401, "Chelsio T520-CR"}, /* 2 x 10G */
481 {0x5402, "Chelsio T522-CR"}, /* 2 x 10G, 2 X 1G */
482 {0x5403, "Chelsio T540-CR"}, /* 4 x 10G */
483 {0x5407, "Chelsio T520-SO"}, /* 2 x 10G, nomem */
484 {0x5409, "Chelsio T520-BT"}, /* 2 x 10GBaseT */
485 {0x540a, "Chelsio T504-BT"}, /* 4 x 1G */
486 {0x540d, "Chelsio T580-CR"}, /* 2 x 40G */
487 {0x540e, "Chelsio T540-LP-CR"}, /* 4 x 10G */
488 {0x5410, "Chelsio T580-LP-CR"}, /* 2 x 40G */
489 {0x5411, "Chelsio T520-LL-CR"}, /* 2 x 10G */
490 {0x5412, "Chelsio T560-CR"}, /* 1 x 40G, 2 x 10G */
491 {0x5414, "Chelsio T580-LP-SO-CR"}, /* 2 x 40G, nomem */
492 {0x5415, "Chelsio T502-BT"}, /* 2 x 1G */
494 {0x5404, "Chelsio T520-BCH"},
495 {0x5405, "Chelsio T540-BCH"},
496 {0x5406, "Chelsio T540-CH"},
497 {0x5408, "Chelsio T520-CX"},
498 {0x540b, "Chelsio B520-SR"},
499 {0x540c, "Chelsio B504-BT"},
500 {0x540f, "Chelsio Amsterdam"},
501 {0x5413, "Chelsio T580-CHR"},
507 * service_iq() has an iq and needs the fl. Offset of fl from the iq should be
508 * exactly the same for both rxq and ofld_rxq.
510 CTASSERT(offsetof(struct sge_ofld_rxq, iq) == offsetof(struct sge_rxq, iq));
511 CTASSERT(offsetof(struct sge_ofld_rxq, fl) == offsetof(struct sge_rxq, fl));
514 /* No easy way to include t4_msg.h before adapter.h so we check this way */
515 CTASSERT(nitems(((struct adapter *)0)->cpl_handler) == NUM_CPL_CMDS);
516 CTASSERT(nitems(((struct adapter *)0)->fw_msg_handler) == NUM_FW6_TYPES);
518 CTASSERT(sizeof(struct cluster_metadata) <= CL_METADATA_SIZE);
521 t4_probe(device_t dev)
524 uint16_t v = pci_get_vendor(dev);
525 uint16_t d = pci_get_device(dev);
526 uint8_t f = pci_get_function(dev);
528 if (v != PCI_VENDOR_ID_CHELSIO)
531 /* Attach only to PF0 of the FPGA */
532 if (d == 0xa000 && f != 0)
535 for (i = 0; i < nitems(t4_pciids); i++) {
536 if (d == t4_pciids[i].device) {
537 device_set_desc(dev, t4_pciids[i].desc);
538 return (BUS_PROBE_DEFAULT);
546 t5_probe(device_t dev)
549 uint16_t v = pci_get_vendor(dev);
550 uint16_t d = pci_get_device(dev);
551 uint8_t f = pci_get_function(dev);
553 if (v != PCI_VENDOR_ID_CHELSIO)
556 /* Attach only to PF0 of the FPGA */
557 if (d == 0xb000 && f != 0)
560 for (i = 0; i < nitems(t5_pciids); i++) {
561 if (d == t5_pciids[i].device) {
562 device_set_desc(dev, t5_pciids[i].desc);
563 return (BUS_PROBE_DEFAULT);
571 t4_attach(device_t dev)
574 int rc = 0, i, n10g, n1g, rqidx, tqidx;
575 struct intrs_and_queues iaq;
578 int ofld_rqidx, ofld_tqidx;
581 int nm_rqidx, nm_tqidx;
584 sc = device_get_softc(dev);
587 pci_enable_busmaster(dev);
588 if (pci_find_cap(dev, PCIY_EXPRESS, &i) == 0) {
591 pci_set_max_read_req(dev, 4096);
592 v = pci_read_config(dev, i + PCIER_DEVICE_CTL, 2);
593 v |= PCIEM_CTL_RELAXED_ORD_ENABLE;
594 pci_write_config(dev, i + PCIER_DEVICE_CTL, v, 2);
596 sc->params.pci.mps = 128 << ((v & PCIEM_CTL_MAX_PAYLOAD) >> 5);
600 mtx_init(&sc->ifp_lock, sc->ifp_lockname, 0, MTX_DEF);
601 snprintf(sc->ifp_lockname, sizeof(sc->ifp_lockname), "%s tracer",
602 device_get_nameunit(dev));
604 snprintf(sc->lockname, sizeof(sc->lockname), "%s",
605 device_get_nameunit(dev));
606 mtx_init(&sc->sc_lock, sc->lockname, 0, MTX_DEF);
607 sx_xlock(&t4_list_lock);
608 SLIST_INSERT_HEAD(&t4_list, sc, link);
609 sx_xunlock(&t4_list_lock);
611 mtx_init(&sc->sfl_lock, "starving freelists", 0, MTX_DEF);
612 TAILQ_INIT(&sc->sfl);
613 callout_init(&sc->sfl_callout, CALLOUT_MPSAFE);
615 mtx_init(&sc->regwin_lock, "register and memory window", 0, MTX_DEF);
617 rc = map_bars_0_and_4(sc);
619 goto done; /* error message displayed already */
622 * This is the real PF# to which we're attaching. Works from within PCI
623 * passthrough environments too, where pci_get_function() could return a
624 * different PF# depending on the passthrough configuration. We need to
625 * use the real PF# in all our communication with the firmware.
627 sc->pf = G_SOURCEPF(t4_read_reg(sc, A_PL_WHOAMI));
630 memset(sc->chan_map, 0xff, sizeof(sc->chan_map));
631 sc->an_handler = an_not_handled;
632 for (i = 0; i < nitems(sc->cpl_handler); i++)
633 sc->cpl_handler[i] = cpl_not_handled;
634 for (i = 0; i < nitems(sc->fw_msg_handler); i++)
635 sc->fw_msg_handler[i] = fw_msg_not_handled;
636 t4_register_cpl_handler(sc, CPL_SET_TCB_RPL, t4_filter_rpl);
637 t4_register_cpl_handler(sc, CPL_TRACE_PKT, t4_trace_pkt);
638 t4_register_cpl_handler(sc, CPL_TRACE_PKT_T5, t5_trace_pkt);
639 t4_init_sge_cpl_handlers(sc);
641 /* Prepare the adapter for operation */
642 rc = -t4_prep_adapter(sc);
644 device_printf(dev, "failed to prepare adapter: %d.\n", rc);
649 * Do this really early, with the memory windows set up even before the
650 * character device. The userland tool's register i/o and mem read
651 * will work even in "recovery mode".
654 sc->cdev = make_dev(is_t4(sc) ? &t4_cdevsw : &t5_cdevsw,
655 device_get_unit(dev), UID_ROOT, GID_WHEEL, 0600, "%s",
656 device_get_nameunit(dev));
657 if (sc->cdev == NULL)
658 device_printf(dev, "failed to create nexus char device.\n");
660 sc->cdev->si_drv1 = sc;
662 /* Go no further if recovery mode has been requested. */
663 if (TUNABLE_INT_FETCH("hw.cxgbe.sos", &i) && i != 0) {
664 device_printf(dev, "recovery mode.\n");
668 /* Prepare the firmware for operation */
669 rc = prep_firmware(sc);
671 goto done; /* error message displayed already */
673 rc = get_params__post_init(sc);
675 goto done; /* error message displayed already */
677 rc = set_params__post_init(sc);
679 goto done; /* error message displayed already */
683 goto done; /* error message displayed already */
685 rc = t4_create_dma_tag(sc);
687 goto done; /* error message displayed already */
690 * First pass over all the ports - allocate VIs and initialize some
691 * basic parameters like mac address, port type, etc. We also figure
692 * out whether a port is 10G or 1G and use that information when
693 * calculating how many interrupts to attempt to allocate.
696 for_each_port(sc, i) {
697 struct port_info *pi;
699 pi = malloc(sizeof(*pi), M_CXGBE, M_ZERO | M_WAITOK);
702 /* These must be set before t4_port_init */
706 /* Allocate the vi and initialize parameters like mac addr */
707 rc = -t4_port_init(pi, sc->mbox, sc->pf, 0);
709 device_printf(dev, "unable to initialize port %d: %d\n",
716 pi->link_cfg.requested_fc &= ~(PAUSE_TX | PAUSE_RX);
717 pi->link_cfg.requested_fc |= t4_pause_settings;
718 pi->link_cfg.fc &= ~(PAUSE_TX | PAUSE_RX);
719 pi->link_cfg.fc |= t4_pause_settings;
721 rc = -t4_link_start(sc, sc->mbox, pi->tx_chan, &pi->link_cfg);
723 device_printf(dev, "port %d l1cfg failed: %d\n", i, rc);
729 snprintf(pi->lockname, sizeof(pi->lockname), "%sp%d",
730 device_get_nameunit(dev), i);
731 mtx_init(&pi->pi_lock, pi->lockname, 0, MTX_DEF);
732 sc->chan_map[pi->tx_chan] = i;
734 if (is_10G_port(pi) || is_40G_port(pi)) {
736 pi->tmr_idx = t4_tmr_idx_10g;
737 pi->pktc_idx = t4_pktc_idx_10g;
740 pi->tmr_idx = t4_tmr_idx_1g;
741 pi->pktc_idx = t4_pktc_idx_1g;
744 pi->xact_addr_filt = -1;
747 pi->qsize_rxq = t4_qsize_rxq;
748 pi->qsize_txq = t4_qsize_txq;
750 pi->dev = device_add_child(dev, is_t4(sc) ? "cxgbe" : "cxl", -1);
751 if (pi->dev == NULL) {
753 "failed to add device for port %d.\n", i);
757 device_set_softc(pi->dev, pi);
761 * Interrupt type, # of interrupts, # of rx/tx queues, etc.
763 rc = cfg_itype_and_nqueues(sc, n10g, n1g, &iaq);
765 goto done; /* error message displayed already */
767 sc->intr_type = iaq.intr_type;
768 sc->intr_count = iaq.nirq;
771 s->nrxq = n10g * iaq.nrxq10g + n1g * iaq.nrxq1g;
772 s->ntxq = n10g * iaq.ntxq10g + n1g * iaq.ntxq1g;
773 s->neq = s->ntxq + s->nrxq; /* the free list in an rxq is an eq */
774 s->neq += sc->params.nports + 1;/* ctrl queues: 1 per port + 1 mgmt */
775 s->niq = s->nrxq + 1; /* 1 extra for firmware event queue */
777 if (is_offload(sc)) {
778 s->nofldrxq = n10g * iaq.nofldrxq10g + n1g * iaq.nofldrxq1g;
779 s->nofldtxq = n10g * iaq.nofldtxq10g + n1g * iaq.nofldtxq1g;
780 s->neq += s->nofldtxq + s->nofldrxq;
781 s->niq += s->nofldrxq;
783 s->ofld_rxq = malloc(s->nofldrxq * sizeof(struct sge_ofld_rxq),
784 M_CXGBE, M_ZERO | M_WAITOK);
785 s->ofld_txq = malloc(s->nofldtxq * sizeof(struct sge_wrq),
786 M_CXGBE, M_ZERO | M_WAITOK);
790 s->nnmrxq = n10g * iaq.nnmrxq10g + n1g * iaq.nnmrxq1g;
791 s->nnmtxq = n10g * iaq.nnmtxq10g + n1g * iaq.nnmtxq1g;
792 s->neq += s->nnmtxq + s->nnmrxq;
795 s->nm_rxq = malloc(s->nnmrxq * sizeof(struct sge_nm_rxq),
796 M_CXGBE, M_ZERO | M_WAITOK);
797 s->nm_txq = malloc(s->nnmtxq * sizeof(struct sge_nm_txq),
798 M_CXGBE, M_ZERO | M_WAITOK);
801 s->ctrlq = malloc(sc->params.nports * sizeof(struct sge_wrq), M_CXGBE,
803 s->rxq = malloc(s->nrxq * sizeof(struct sge_rxq), M_CXGBE,
805 s->txq = malloc(s->ntxq * sizeof(struct sge_txq), M_CXGBE,
807 s->iqmap = malloc(s->niq * sizeof(struct sge_iq *), M_CXGBE,
809 s->eqmap = malloc(s->neq * sizeof(struct sge_eq *), M_CXGBE,
812 sc->irq = malloc(sc->intr_count * sizeof(struct irq), M_CXGBE,
815 t4_init_l2t(sc, M_WAITOK);
818 * Second pass over the ports. This time we know the number of rx and
819 * tx queues that each port should get.
823 ofld_rqidx = ofld_tqidx = 0;
826 nm_rqidx = nm_tqidx = 0;
828 for_each_port(sc, i) {
829 struct port_info *pi = sc->port[i];
834 pi->first_rxq = rqidx;
835 pi->first_txq = tqidx;
836 if (is_10G_port(pi) || is_40G_port(pi)) {
837 pi->flags |= iaq.intr_flags_10g;
838 pi->nrxq = iaq.nrxq10g;
839 pi->ntxq = iaq.ntxq10g;
841 pi->flags |= iaq.intr_flags_1g;
842 pi->nrxq = iaq.nrxq1g;
843 pi->ntxq = iaq.ntxq1g;
847 pi->rsrv_noflowq = iaq.rsrv_noflowq ? 1 : 0;
849 pi->rsrv_noflowq = 0;
854 if (is_offload(sc)) {
855 pi->first_ofld_rxq = ofld_rqidx;
856 pi->first_ofld_txq = ofld_tqidx;
857 if (is_10G_port(pi) || is_40G_port(pi)) {
858 pi->nofldrxq = iaq.nofldrxq10g;
859 pi->nofldtxq = iaq.nofldtxq10g;
861 pi->nofldrxq = iaq.nofldrxq1g;
862 pi->nofldtxq = iaq.nofldtxq1g;
864 ofld_rqidx += pi->nofldrxq;
865 ofld_tqidx += pi->nofldtxq;
869 pi->first_nm_rxq = nm_rqidx;
870 pi->first_nm_txq = nm_tqidx;
871 if (is_10G_port(pi) || is_40G_port(pi)) {
872 pi->nnmrxq = iaq.nnmrxq10g;
873 pi->nnmtxq = iaq.nnmtxq10g;
875 pi->nnmrxq = iaq.nnmrxq1g;
876 pi->nnmtxq = iaq.nnmtxq1g;
878 nm_rqidx += pi->nnmrxq;
879 nm_tqidx += pi->nnmtxq;
883 rc = setup_intr_handlers(sc);
886 "failed to setup interrupt handlers: %d\n", rc);
890 rc = bus_generic_attach(dev);
893 "failed to attach all child ports: %d\n", rc);
898 "PCIe x%d, %d ports, %d %s interrupt%s, %d eq, %d iq\n",
899 sc->params.pci.width, sc->params.nports, sc->intr_count,
900 sc->intr_type == INTR_MSIX ? "MSI-X" :
901 (sc->intr_type == INTR_MSI ? "MSI" : "INTx"),
902 sc->intr_count > 1 ? "s" : "", sc->sge.neq, sc->sge.niq);
907 if (rc != 0 && sc->cdev) {
908 /* cdev was created and so cxgbetool works; recover that way. */
910 "error during attach, adapter is now in recovery mode.\n");
926 t4_detach(device_t dev)
929 struct port_info *pi;
932 sc = device_get_softc(dev);
934 if (sc->flags & FULL_INIT_DONE)
938 destroy_dev(sc->cdev);
942 rc = bus_generic_detach(dev);
945 "failed to detach child devices: %d\n", rc);
949 for (i = 0; i < sc->intr_count; i++)
950 t4_free_irq(sc, &sc->irq[i]);
952 for (i = 0; i < MAX_NPORTS; i++) {
955 t4_free_vi(sc, sc->mbox, sc->pf, 0, pi->viid);
957 device_delete_child(dev, pi->dev);
959 mtx_destroy(&pi->pi_lock);
964 if (sc->flags & FULL_INIT_DONE)
965 adapter_full_uninit(sc);
967 if (sc->flags & FW_OK)
968 t4_fw_bye(sc, sc->mbox);
970 if (sc->intr_type == INTR_MSI || sc->intr_type == INTR_MSIX)
971 pci_release_msi(dev);
974 bus_release_resource(dev, SYS_RES_MEMORY, sc->regs_rid,
978 bus_release_resource(dev, SYS_RES_MEMORY, sc->udbs_rid,
982 bus_release_resource(dev, SYS_RES_MEMORY, sc->msix_rid,
986 t4_free_l2t(sc->l2t);
989 free(sc->sge.ofld_rxq, M_CXGBE);
990 free(sc->sge.ofld_txq, M_CXGBE);
993 free(sc->sge.nm_rxq, M_CXGBE);
994 free(sc->sge.nm_txq, M_CXGBE);
996 free(sc->irq, M_CXGBE);
997 free(sc->sge.rxq, M_CXGBE);
998 free(sc->sge.txq, M_CXGBE);
999 free(sc->sge.ctrlq, M_CXGBE);
1000 free(sc->sge.iqmap, M_CXGBE);
1001 free(sc->sge.eqmap, M_CXGBE);
1002 free(sc->tids.ftid_tab, M_CXGBE);
1003 t4_destroy_dma_tag(sc);
1004 if (mtx_initialized(&sc->sc_lock)) {
1005 sx_xlock(&t4_list_lock);
1006 SLIST_REMOVE(&t4_list, sc, adapter, link);
1007 sx_xunlock(&t4_list_lock);
1008 mtx_destroy(&sc->sc_lock);
1011 if (mtx_initialized(&sc->tids.ftid_lock))
1012 mtx_destroy(&sc->tids.ftid_lock);
1013 if (mtx_initialized(&sc->sfl_lock))
1014 mtx_destroy(&sc->sfl_lock);
1015 if (mtx_initialized(&sc->ifp_lock))
1016 mtx_destroy(&sc->ifp_lock);
1017 if (mtx_initialized(&sc->regwin_lock))
1018 mtx_destroy(&sc->regwin_lock);
1020 bzero(sc, sizeof(*sc));
1026 cxgbe_probe(device_t dev)
1029 struct port_info *pi = device_get_softc(dev);
1031 snprintf(buf, sizeof(buf), "port %d", pi->port_id);
1032 device_set_desc_copy(dev, buf);
1034 return (BUS_PROBE_DEFAULT);
1037 #define T4_CAP (IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_HWCSUM | \
1038 IFCAP_VLAN_HWCSUM | IFCAP_TSO | IFCAP_JUMBO_MTU | IFCAP_LRO | \
1039 IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWCSUM_IPV6 | IFCAP_HWSTATS)
1040 #define T4_CAP_ENABLE (T4_CAP)
1043 cxgbe_attach(device_t dev)
1045 struct port_info *pi = device_get_softc(dev);
1050 /* Allocate an ifnet and set it up */
1051 ifp = if_alloc(IFT_ETHER);
1053 device_printf(dev, "Cannot allocate ifnet\n");
1059 callout_init(&pi->tick, CALLOUT_MPSAFE);
1061 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1062 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1064 ifp->if_init = cxgbe_init;
1065 ifp->if_ioctl = cxgbe_ioctl;
1066 ifp->if_transmit = cxgbe_transmit;
1067 ifp->if_qflush = cxgbe_qflush;
1069 ifp->if_capabilities = T4_CAP;
1071 if (is_offload(pi->adapter))
1072 ifp->if_capabilities |= IFCAP_TOE;
1074 ifp->if_capenable = T4_CAP_ENABLE;
1075 ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_IP | CSUM_TSO |
1076 CSUM_UDP_IPV6 | CSUM_TCP_IPV6;
1078 ifp->if_hw_tsomax = 65536 - (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
1079 ifp->if_hw_tsomaxsegcount = TX_SGL_SEGS;
1080 ifp->if_hw_tsomaxsegsize = 65536;
1082 /* Initialize ifmedia for this port */
1083 ifmedia_init(&pi->media, IFM_IMASK, cxgbe_media_change,
1084 cxgbe_media_status);
1085 build_medialist(pi, &pi->media);
1087 pi->vlan_c = EVENTHANDLER_REGISTER(vlan_config, cxgbe_vlan_config, ifp,
1088 EVENTHANDLER_PRI_ANY);
1090 ether_ifattach(ifp, pi->hw_addr);
1093 s = malloc(n, M_CXGBE, M_WAITOK);
1094 o = snprintf(s, n, "%d txq, %d rxq (NIC)", pi->ntxq, pi->nrxq);
1097 if (is_offload(pi->adapter)) {
1098 o += snprintf(s + o, n - o, "; %d txq, %d rxq (TOE)",
1099 pi->nofldtxq, pi->nofldrxq);
1104 o += snprintf(s + o, n - o, "; %d txq, %d rxq (netmap)", pi->nnmtxq,
1108 device_printf(dev, "%s\n", s);
1112 /* nm_media handled here to keep implementation private to this file */
1113 ifmedia_init(&pi->nm_media, IFM_IMASK, cxgbe_media_change,
1114 cxgbe_media_status);
1115 build_medialist(pi, &pi->nm_media);
1116 create_netmap_ifnet(pi); /* logs errors it something fails */
1124 cxgbe_detach(device_t dev)
1126 struct port_info *pi = device_get_softc(dev);
1127 struct adapter *sc = pi->adapter;
1128 struct ifnet *ifp = pi->ifp;
1130 /* Tell if_ioctl and if_init that the port is going away */
1135 mtx_sleep(&sc->flags, &sc->sc_lock, 0, "t4detach", 0);
1138 sc->last_op = "t4detach";
1139 sc->last_op_thr = curthread;
1143 if (pi->flags & HAS_TRACEQ) {
1144 sc->traceq = -1; /* cloner should not create ifnet */
1145 t4_tracer_port_detach(sc);
1149 EVENTHANDLER_DEREGISTER(vlan_config, pi->vlan_c);
1152 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1153 callout_stop(&pi->tick);
1155 callout_drain(&pi->tick);
1157 /* Let detach proceed even if these fail. */
1158 cxgbe_uninit_synchronized(pi);
1159 port_full_uninit(pi);
1161 ifmedia_removeall(&pi->media);
1162 ether_ifdetach(pi->ifp);
1166 /* XXXNM: equivalent of cxgbe_uninit_synchronized to ifdown nm_ifp */
1167 destroy_netmap_ifnet(pi);
1179 cxgbe_init(void *arg)
1181 struct port_info *pi = arg;
1182 struct adapter *sc = pi->adapter;
1184 if (begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4init") != 0)
1186 cxgbe_init_synchronized(pi);
1187 end_synchronized_op(sc, 0);
1191 cxgbe_ioctl(struct ifnet *ifp, unsigned long cmd, caddr_t data)
1193 int rc = 0, mtu, flags, can_sleep;
1194 struct port_info *pi = ifp->if_softc;
1195 struct adapter *sc = pi->adapter;
1196 struct ifreq *ifr = (struct ifreq *)data;
1202 if ((mtu < ETHERMIN) || (mtu > ETHERMTU_JUMBO))
1205 rc = begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4mtu");
1209 if (pi->flags & PORT_INIT_DONE) {
1210 t4_update_fl_bufsize(ifp);
1211 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1212 rc = update_mac_settings(ifp, XGMAC_MTU);
1214 end_synchronized_op(sc, 0);
1220 rc = begin_synchronized_op(sc, pi,
1221 can_sleep ? (SLEEP_OK | INTR_OK) : HOLD_LOCK, "t4flg");
1225 if (ifp->if_flags & IFF_UP) {
1226 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1227 flags = pi->if_flags;
1228 if ((ifp->if_flags ^ flags) &
1229 (IFF_PROMISC | IFF_ALLMULTI)) {
1230 if (can_sleep == 1) {
1231 end_synchronized_op(sc, 0);
1235 rc = update_mac_settings(ifp,
1236 XGMAC_PROMISC | XGMAC_ALLMULTI);
1239 if (can_sleep == 0) {
1240 end_synchronized_op(sc, LOCK_HELD);
1244 rc = cxgbe_init_synchronized(pi);
1246 pi->if_flags = ifp->if_flags;
1247 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1248 if (can_sleep == 0) {
1249 end_synchronized_op(sc, LOCK_HELD);
1253 rc = cxgbe_uninit_synchronized(pi);
1255 end_synchronized_op(sc, can_sleep ? 0 : LOCK_HELD);
1259 case SIOCDELMULTI: /* these two are called with a mutex held :-( */
1260 rc = begin_synchronized_op(sc, pi, HOLD_LOCK, "t4multi");
1263 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1264 rc = update_mac_settings(ifp, XGMAC_MCADDRS);
1265 end_synchronized_op(sc, LOCK_HELD);
1269 rc = begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4cap");
1273 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1274 if (mask & IFCAP_TXCSUM) {
1275 ifp->if_capenable ^= IFCAP_TXCSUM;
1276 ifp->if_hwassist ^= (CSUM_TCP | CSUM_UDP | CSUM_IP);
1278 if (IFCAP_TSO4 & ifp->if_capenable &&
1279 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1280 ifp->if_capenable &= ~IFCAP_TSO4;
1282 "tso4 disabled due to -txcsum.\n");
1285 if (mask & IFCAP_TXCSUM_IPV6) {
1286 ifp->if_capenable ^= IFCAP_TXCSUM_IPV6;
1287 ifp->if_hwassist ^= (CSUM_UDP_IPV6 | CSUM_TCP_IPV6);
1289 if (IFCAP_TSO6 & ifp->if_capenable &&
1290 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1291 ifp->if_capenable &= ~IFCAP_TSO6;
1293 "tso6 disabled due to -txcsum6.\n");
1296 if (mask & IFCAP_RXCSUM)
1297 ifp->if_capenable ^= IFCAP_RXCSUM;
1298 if (mask & IFCAP_RXCSUM_IPV6)
1299 ifp->if_capenable ^= IFCAP_RXCSUM_IPV6;
1302 * Note that we leave CSUM_TSO alone (it is always set). The
1303 * kernel takes both IFCAP_TSOx and CSUM_TSO into account before
1304 * sending a TSO request our way, so it's sufficient to toggle
1307 if (mask & IFCAP_TSO4) {
1308 if (!(IFCAP_TSO4 & ifp->if_capenable) &&
1309 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1310 if_printf(ifp, "enable txcsum first.\n");
1314 ifp->if_capenable ^= IFCAP_TSO4;
1316 if (mask & IFCAP_TSO6) {
1317 if (!(IFCAP_TSO6 & ifp->if_capenable) &&
1318 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1319 if_printf(ifp, "enable txcsum6 first.\n");
1323 ifp->if_capenable ^= IFCAP_TSO6;
1325 if (mask & IFCAP_LRO) {
1326 #if defined(INET) || defined(INET6)
1328 struct sge_rxq *rxq;
1330 ifp->if_capenable ^= IFCAP_LRO;
1331 for_each_rxq(pi, i, rxq) {
1332 if (ifp->if_capenable & IFCAP_LRO)
1333 rxq->iq.flags |= IQ_LRO_ENABLED;
1335 rxq->iq.flags &= ~IQ_LRO_ENABLED;
1340 if (mask & IFCAP_TOE) {
1341 int enable = (ifp->if_capenable ^ mask) & IFCAP_TOE;
1343 rc = toe_capability(pi, enable);
1347 ifp->if_capenable ^= mask;
1350 if (mask & IFCAP_VLAN_HWTAGGING) {
1351 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
1352 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1353 rc = update_mac_settings(ifp, XGMAC_VLANEX);
1355 if (mask & IFCAP_VLAN_MTU) {
1356 ifp->if_capenable ^= IFCAP_VLAN_MTU;
1358 /* Need to find out how to disable auto-mtu-inflation */
1360 if (mask & IFCAP_VLAN_HWTSO)
1361 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
1362 if (mask & IFCAP_VLAN_HWCSUM)
1363 ifp->if_capenable ^= IFCAP_VLAN_HWCSUM;
1365 #ifdef VLAN_CAPABILITIES
1366 VLAN_CAPABILITIES(ifp);
1369 end_synchronized_op(sc, 0);
1374 ifmedia_ioctl(ifp, ifr, &pi->media, cmd);
1378 rc = ether_ioctl(ifp, cmd, data);
1385 cxgbe_transmit(struct ifnet *ifp, struct mbuf *m)
1387 struct port_info *pi = ifp->if_softc;
1388 struct adapter *sc = pi->adapter;
1389 struct sge_txq *txq = &sc->sge.txq[pi->first_txq];
1390 struct buf_ring *br;
1395 if (__predict_false(pi->link_cfg.link_ok == 0)) {
1400 /* check if flowid is set */
1401 if (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE)
1402 txq += ((m->m_pkthdr.flowid % (pi->ntxq - pi->rsrv_noflowq))
1403 + pi->rsrv_noflowq);
1406 if (TXQ_TRYLOCK(txq) == 0) {
1407 struct sge_eq *eq = &txq->eq;
1410 * It is possible that t4_eth_tx finishes up and releases the
1411 * lock between the TRYLOCK above and the drbr_enqueue here. We
1412 * need to make sure that this mbuf doesn't just sit there in
1416 rc = drbr_enqueue(ifp, br, m);
1417 if (rc == 0 && callout_pending(&eq->tx_callout) == 0 &&
1418 !(eq->flags & EQ_DOOMED))
1419 callout_reset(&eq->tx_callout, 1, t4_tx_callout, eq);
1424 * txq->m is the mbuf that is held up due to a temporary shortage of
1425 * resources and it should be put on the wire first. Then what's in
1426 * drbr and finally the mbuf that was just passed in to us.
1428 * Return code should indicate the fate of the mbuf that was passed in
1432 TXQ_LOCK_ASSERT_OWNED(txq);
1433 if (drbr_needs_enqueue(ifp, br) || txq->m) {
1435 /* Queued for transmission. */
1437 rc = drbr_enqueue(ifp, br, m);
1438 m = txq->m ? txq->m : drbr_dequeue(ifp, br);
1439 (void) t4_eth_tx(ifp, txq, m);
1444 /* Direct transmission. */
1445 rc = t4_eth_tx(ifp, txq, m);
1446 if (rc != 0 && txq->m)
1447 rc = 0; /* held, will be transmitted soon (hopefully) */
1454 cxgbe_qflush(struct ifnet *ifp)
1456 struct port_info *pi = ifp->if_softc;
1457 struct sge_txq *txq;
1461 /* queues do not exist if !PORT_INIT_DONE. */
1462 if (pi->flags & PORT_INIT_DONE) {
1463 for_each_txq(pi, i, txq) {
1467 while ((m = buf_ring_dequeue_sc(txq->br)) != NULL)
1476 cxgbe_media_change(struct ifnet *ifp)
1478 struct port_info *pi = ifp->if_softc;
1480 device_printf(pi->dev, "%s unimplemented.\n", __func__);
1482 return (EOPNOTSUPP);
1486 cxgbe_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
1488 struct port_info *pi = ifp->if_softc;
1489 struct ifmedia *media = NULL;
1490 struct ifmedia_entry *cur;
1491 int speed = pi->link_cfg.speed;
1493 int data = (pi->port_type << 8) | pi->mod_type;
1499 else if (ifp == pi->nm_ifp)
1500 media = &pi->nm_media;
1502 MPASS(media != NULL);
1504 cur = media->ifm_cur;
1505 MPASS(cur->ifm_data == data);
1507 ifmr->ifm_status = IFM_AVALID;
1508 if (!pi->link_cfg.link_ok)
1511 ifmr->ifm_status |= IFM_ACTIVE;
1513 /* active and current will differ iff current media is autoselect. */
1514 if (IFM_SUBTYPE(cur->ifm_media) != IFM_AUTO)
1517 ifmr->ifm_active = IFM_ETHER | IFM_FDX;
1518 if (speed == SPEED_10000)
1519 ifmr->ifm_active |= IFM_10G_T;
1520 else if (speed == SPEED_1000)
1521 ifmr->ifm_active |= IFM_1000_T;
1522 else if (speed == SPEED_100)
1523 ifmr->ifm_active |= IFM_100_TX;
1524 else if (speed == SPEED_10)
1525 ifmr->ifm_active |= IFM_10_T;
1527 KASSERT(0, ("%s: link up but speed unknown (%u)", __func__,
1532 t4_fatal_err(struct adapter *sc)
1534 t4_set_reg_field(sc, A_SGE_CONTROL, F_GLOBALENABLE, 0);
1535 t4_intr_disable(sc);
1536 log(LOG_EMERG, "%s: encountered fatal error, adapter stopped.\n",
1537 device_get_nameunit(sc->dev));
1541 map_bars_0_and_4(struct adapter *sc)
1543 sc->regs_rid = PCIR_BAR(0);
1544 sc->regs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
1545 &sc->regs_rid, RF_ACTIVE);
1546 if (sc->regs_res == NULL) {
1547 device_printf(sc->dev, "cannot map registers.\n");
1550 sc->bt = rman_get_bustag(sc->regs_res);
1551 sc->bh = rman_get_bushandle(sc->regs_res);
1552 sc->mmio_len = rman_get_size(sc->regs_res);
1553 setbit(&sc->doorbells, DOORBELL_KDB);
1555 sc->msix_rid = PCIR_BAR(4);
1556 sc->msix_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
1557 &sc->msix_rid, RF_ACTIVE);
1558 if (sc->msix_res == NULL) {
1559 device_printf(sc->dev, "cannot map MSI-X BAR.\n");
1567 map_bar_2(struct adapter *sc)
1571 * T4: only iWARP driver uses the userspace doorbells. There is no need
1572 * to map it if RDMA is disabled.
1574 if (is_t4(sc) && sc->rdmacaps == 0)
1577 sc->udbs_rid = PCIR_BAR(2);
1578 sc->udbs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
1579 &sc->udbs_rid, RF_ACTIVE);
1580 if (sc->udbs_res == NULL) {
1581 device_printf(sc->dev, "cannot map doorbell BAR.\n");
1584 sc->udbs_base = rman_get_virtual(sc->udbs_res);
1587 setbit(&sc->doorbells, DOORBELL_UDB);
1588 #if defined(__i386__) || defined(__amd64__)
1589 if (t5_write_combine) {
1593 * Enable write combining on BAR2. This is the
1594 * userspace doorbell BAR and is split into 128B
1595 * (UDBS_SEG_SIZE) doorbell regions, each associated
1596 * with an egress queue. The first 64B has the doorbell
1597 * and the second 64B can be used to submit a tx work
1598 * request with an implicit doorbell.
1601 rc = pmap_change_attr((vm_offset_t)sc->udbs_base,
1602 rman_get_size(sc->udbs_res), PAT_WRITE_COMBINING);
1604 clrbit(&sc->doorbells, DOORBELL_UDB);
1605 setbit(&sc->doorbells, DOORBELL_WCWR);
1606 setbit(&sc->doorbells, DOORBELL_UDBWC);
1608 device_printf(sc->dev,
1609 "couldn't enable write combining: %d\n",
1613 t4_write_reg(sc, A_SGE_STAT_CFG,
1614 V_STATSOURCE_T5(7) | V_STATMODE(0));
1622 static const struct memwin t4_memwin[] = {
1623 { MEMWIN0_BASE, MEMWIN0_APERTURE },
1624 { MEMWIN1_BASE, MEMWIN1_APERTURE },
1625 { MEMWIN2_BASE_T4, MEMWIN2_APERTURE_T4 }
1628 static const struct memwin t5_memwin[] = {
1629 { MEMWIN0_BASE, MEMWIN0_APERTURE },
1630 { MEMWIN1_BASE, MEMWIN1_APERTURE },
1631 { MEMWIN2_BASE_T5, MEMWIN2_APERTURE_T5 },
1635 setup_memwin(struct adapter *sc)
1637 const struct memwin *mw;
1643 * Read low 32b of bar0 indirectly via the hardware backdoor
1644 * mechanism. Works from within PCI passthrough environments
1645 * too, where rman_get_start() can return a different value. We
1646 * need to program the T4 memory window decoders with the actual
1647 * addresses that will be coming across the PCIe link.
1649 bar0 = t4_hw_pci_read_cfg4(sc, PCIR_BAR(0));
1650 bar0 &= (uint32_t) PCIM_BAR_MEM_BASE;
1653 n = nitems(t4_memwin);
1655 /* T5 uses the relative offset inside the PCIe BAR */
1659 n = nitems(t5_memwin);
1662 for (i = 0; i < n; i++, mw++) {
1664 PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, i),
1665 (mw->base + bar0) | V_BIR(0) |
1666 V_WINDOW(ilog2(mw->aperture) - 10));
1670 t4_read_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 2));
1674 * Verify that the memory range specified by the addr/len pair is valid and lies
1675 * entirely within a single region (EDCx or MCx).
1678 validate_mem_range(struct adapter *sc, uint32_t addr, int len)
1680 uint32_t em, addr_len, maddr, mlen;
1682 /* Memory can only be accessed in naturally aligned 4 byte units */
1683 if (addr & 3 || len & 3 || len == 0)
1686 /* Enabled memories */
1687 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
1688 if (em & F_EDRAM0_ENABLE) {
1689 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
1690 maddr = G_EDRAM0_BASE(addr_len) << 20;
1691 mlen = G_EDRAM0_SIZE(addr_len) << 20;
1692 if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1693 addr + len <= maddr + mlen)
1696 if (em & F_EDRAM1_ENABLE) {
1697 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
1698 maddr = G_EDRAM1_BASE(addr_len) << 20;
1699 mlen = G_EDRAM1_SIZE(addr_len) << 20;
1700 if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1701 addr + len <= maddr + mlen)
1704 if (em & F_EXT_MEM_ENABLE) {
1705 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
1706 maddr = G_EXT_MEM_BASE(addr_len) << 20;
1707 mlen = G_EXT_MEM_SIZE(addr_len) << 20;
1708 if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1709 addr + len <= maddr + mlen)
1712 if (!is_t4(sc) && em & F_EXT_MEM1_ENABLE) {
1713 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
1714 maddr = G_EXT_MEM1_BASE(addr_len) << 20;
1715 mlen = G_EXT_MEM1_SIZE(addr_len) << 20;
1716 if (mlen > 0 && addr >= maddr && addr < maddr + mlen &&
1717 addr + len <= maddr + mlen)
1725 fwmtype_to_hwmtype(int mtype)
1729 case FW_MEMTYPE_EDC0:
1731 case FW_MEMTYPE_EDC1:
1733 case FW_MEMTYPE_EXTMEM:
1735 case FW_MEMTYPE_EXTMEM1:
1738 panic("%s: cannot translate fw mtype %d.", __func__, mtype);
1743 * Verify that the memory range specified by the memtype/offset/len pair is
1744 * valid and lies entirely within the memtype specified. The global address of
1745 * the start of the range is returned in addr.
1748 validate_mt_off_len(struct adapter *sc, int mtype, uint32_t off, int len,
1751 uint32_t em, addr_len, maddr, mlen;
1753 /* Memory can only be accessed in naturally aligned 4 byte units */
1754 if (off & 3 || len & 3 || len == 0)
1757 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
1758 switch (fwmtype_to_hwmtype(mtype)) {
1760 if (!(em & F_EDRAM0_ENABLE))
1762 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
1763 maddr = G_EDRAM0_BASE(addr_len) << 20;
1764 mlen = G_EDRAM0_SIZE(addr_len) << 20;
1767 if (!(em & F_EDRAM1_ENABLE))
1769 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
1770 maddr = G_EDRAM1_BASE(addr_len) << 20;
1771 mlen = G_EDRAM1_SIZE(addr_len) << 20;
1774 if (!(em & F_EXT_MEM_ENABLE))
1776 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
1777 maddr = G_EXT_MEM_BASE(addr_len) << 20;
1778 mlen = G_EXT_MEM_SIZE(addr_len) << 20;
1781 if (is_t4(sc) || !(em & F_EXT_MEM1_ENABLE))
1783 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
1784 maddr = G_EXT_MEM1_BASE(addr_len) << 20;
1785 mlen = G_EXT_MEM1_SIZE(addr_len) << 20;
1791 if (mlen > 0 && off < mlen && off + len <= mlen) {
1792 *addr = maddr + off; /* global address */
1800 memwin_info(struct adapter *sc, int win, uint32_t *base, uint32_t *aperture)
1802 const struct memwin *mw;
1805 KASSERT(win >= 0 && win < nitems(t4_memwin),
1806 ("%s: incorrect memwin# (%d)", __func__, win));
1807 mw = &t4_memwin[win];
1809 KASSERT(win >= 0 && win < nitems(t5_memwin),
1810 ("%s: incorrect memwin# (%d)", __func__, win));
1811 mw = &t5_memwin[win];
1816 if (aperture != NULL)
1817 *aperture = mw->aperture;
1821 * Positions the memory window such that it can be used to access the specified
1822 * address in the chip's address space. The return value is the offset of addr
1823 * from the start of the window.
1826 position_memwin(struct adapter *sc, int n, uint32_t addr)
1831 KASSERT(n >= 0 && n <= 3,
1832 ("%s: invalid window %d.", __func__, n));
1833 KASSERT((addr & 3) == 0,
1834 ("%s: addr (0x%x) is not at a 4B boundary.", __func__, addr));
1838 start = addr & ~0xf; /* start must be 16B aligned */
1840 pf = V_PFNUM(sc->pf);
1841 start = addr & ~0x7f; /* start must be 128B aligned */
1843 reg = PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, n);
1845 t4_write_reg(sc, reg, start | pf);
1846 t4_read_reg(sc, reg);
1848 return (addr - start);
1852 cfg_itype_and_nqueues(struct adapter *sc, int n10g, int n1g,
1853 struct intrs_and_queues *iaq)
1855 int rc, itype, navail, nrxq10g, nrxq1g, n;
1856 int nofldrxq10g = 0, nofldrxq1g = 0;
1857 int nnmrxq10g = 0, nnmrxq1g = 0;
1859 bzero(iaq, sizeof(*iaq));
1861 iaq->ntxq10g = t4_ntxq10g;
1862 iaq->ntxq1g = t4_ntxq1g;
1863 iaq->nrxq10g = nrxq10g = t4_nrxq10g;
1864 iaq->nrxq1g = nrxq1g = t4_nrxq1g;
1865 iaq->rsrv_noflowq = t4_rsrv_noflowq;
1867 if (is_offload(sc)) {
1868 iaq->nofldtxq10g = t4_nofldtxq10g;
1869 iaq->nofldtxq1g = t4_nofldtxq1g;
1870 iaq->nofldrxq10g = nofldrxq10g = t4_nofldrxq10g;
1871 iaq->nofldrxq1g = nofldrxq1g = t4_nofldrxq1g;
1875 iaq->nnmtxq10g = t4_nnmtxq10g;
1876 iaq->nnmtxq1g = t4_nnmtxq1g;
1877 iaq->nnmrxq10g = nnmrxq10g = t4_nnmrxq10g;
1878 iaq->nnmrxq1g = nnmrxq1g = t4_nnmrxq1g;
1881 for (itype = INTR_MSIX; itype; itype >>= 1) {
1883 if ((itype & t4_intr_types) == 0)
1884 continue; /* not allowed */
1886 if (itype == INTR_MSIX)
1887 navail = pci_msix_count(sc->dev);
1888 else if (itype == INTR_MSI)
1889 navail = pci_msi_count(sc->dev);
1896 iaq->intr_type = itype;
1897 iaq->intr_flags_10g = 0;
1898 iaq->intr_flags_1g = 0;
1901 * Best option: an interrupt vector for errors, one for the
1902 * firmware event queue, and one for every rxq (NIC, TOE, and
1905 iaq->nirq = T4_EXTRA_INTR;
1906 iaq->nirq += n10g * (nrxq10g + nofldrxq10g + nnmrxq10g);
1907 iaq->nirq += n1g * (nrxq1g + nofldrxq1g + nnmrxq1g);
1908 if (iaq->nirq <= navail &&
1909 (itype != INTR_MSI || powerof2(iaq->nirq))) {
1910 iaq->intr_flags_10g = INTR_ALL;
1911 iaq->intr_flags_1g = INTR_ALL;
1916 * Second best option: a vector for errors, one for the firmware
1917 * event queue, and vectors for either all the NIC rx queues or
1918 * all the TOE rx queues. The queues that don't get vectors
1919 * will forward their interrupts to those that do.
1921 * Note: netmap rx queues cannot be created early and so they
1922 * can't be setup to receive forwarded interrupts for others.
1924 iaq->nirq = T4_EXTRA_INTR;
1925 if (nrxq10g >= nofldrxq10g) {
1926 iaq->intr_flags_10g = INTR_RXQ;
1927 iaq->nirq += n10g * nrxq10g;
1929 iaq->nnmrxq10g = min(nnmrxq10g, nrxq10g);
1932 iaq->intr_flags_10g = INTR_OFLD_RXQ;
1933 iaq->nirq += n10g * nofldrxq10g;
1935 iaq->nnmrxq10g = min(nnmrxq10g, nofldrxq10g);
1938 if (nrxq1g >= nofldrxq1g) {
1939 iaq->intr_flags_1g = INTR_RXQ;
1940 iaq->nirq += n1g * nrxq1g;
1942 iaq->nnmrxq1g = min(nnmrxq1g, nrxq1g);
1945 iaq->intr_flags_1g = INTR_OFLD_RXQ;
1946 iaq->nirq += n1g * nofldrxq1g;
1948 iaq->nnmrxq1g = min(nnmrxq1g, nofldrxq1g);
1951 if (iaq->nirq <= navail &&
1952 (itype != INTR_MSI || powerof2(iaq->nirq)))
1956 * Next best option: an interrupt vector for errors, one for the
1957 * firmware event queue, and at least one per port. At this
1958 * point we know we'll have to downsize nrxq and/or nofldrxq
1959 * and/or nnmrxq to fit what's available to us.
1961 iaq->nirq = T4_EXTRA_INTR;
1962 iaq->nirq += n10g + n1g;
1963 if (iaq->nirq <= navail) {
1964 int leftover = navail - iaq->nirq;
1967 int target = max(nrxq10g, nofldrxq10g);
1969 iaq->intr_flags_10g = nrxq10g >= nofldrxq10g ?
1970 INTR_RXQ : INTR_OFLD_RXQ;
1973 while (n < target && leftover >= n10g) {
1978 iaq->nrxq10g = min(n, nrxq10g);
1980 iaq->nofldrxq10g = min(n, nofldrxq10g);
1983 iaq->nnmrxq10g = min(n, nnmrxq10g);
1988 int target = max(nrxq1g, nofldrxq1g);
1990 iaq->intr_flags_1g = nrxq1g >= nofldrxq1g ?
1991 INTR_RXQ : INTR_OFLD_RXQ;
1994 while (n < target && leftover >= n1g) {
1999 iaq->nrxq1g = min(n, nrxq1g);
2001 iaq->nofldrxq1g = min(n, nofldrxq1g);
2004 iaq->nnmrxq1g = min(n, nnmrxq1g);
2008 if (itype != INTR_MSI || powerof2(iaq->nirq))
2013 * Least desirable option: one interrupt vector for everything.
2015 iaq->nirq = iaq->nrxq10g = iaq->nrxq1g = 1;
2016 iaq->intr_flags_10g = iaq->intr_flags_1g = 0;
2019 iaq->nofldrxq10g = iaq->nofldrxq1g = 1;
2022 iaq->nnmrxq10g = iaq->nnmrxq1g = 1;
2028 if (itype == INTR_MSIX)
2029 rc = pci_alloc_msix(sc->dev, &navail);
2030 else if (itype == INTR_MSI)
2031 rc = pci_alloc_msi(sc->dev, &navail);
2034 if (navail == iaq->nirq)
2038 * Didn't get the number requested. Use whatever number
2039 * the kernel is willing to allocate (it's in navail).
2041 device_printf(sc->dev, "fewer vectors than requested, "
2042 "type=%d, req=%d, rcvd=%d; will downshift req.\n",
2043 itype, iaq->nirq, navail);
2044 pci_release_msi(sc->dev);
2048 device_printf(sc->dev,
2049 "failed to allocate vectors:%d, type=%d, req=%d, rcvd=%d\n",
2050 itype, rc, iaq->nirq, navail);
2053 device_printf(sc->dev,
2054 "failed to find a usable interrupt type. "
2055 "allowed=%d, msi-x=%d, msi=%d, intx=1", t4_intr_types,
2056 pci_msix_count(sc->dev), pci_msi_count(sc->dev));
2061 #define FW_VERSION(chip) ( \
2062 V_FW_HDR_FW_VER_MAJOR(chip##FW_VERSION_MAJOR) | \
2063 V_FW_HDR_FW_VER_MINOR(chip##FW_VERSION_MINOR) | \
2064 V_FW_HDR_FW_VER_MICRO(chip##FW_VERSION_MICRO) | \
2065 V_FW_HDR_FW_VER_BUILD(chip##FW_VERSION_BUILD))
2066 #define FW_INTFVER(chip, intf) (chip##FW_HDR_INTFVER_##intf)
2072 struct fw_hdr fw_hdr; /* XXX: waste of space, need a sparse struct */
2076 .kld_name = "t4fw_cfg",
2077 .fw_mod_name = "t4fw",
2079 .chip = FW_HDR_CHIP_T4,
2080 .fw_ver = htobe32_const(FW_VERSION(T4)),
2081 .intfver_nic = FW_INTFVER(T4, NIC),
2082 .intfver_vnic = FW_INTFVER(T4, VNIC),
2083 .intfver_ofld = FW_INTFVER(T4, OFLD),
2084 .intfver_ri = FW_INTFVER(T4, RI),
2085 .intfver_iscsipdu = FW_INTFVER(T4, ISCSIPDU),
2086 .intfver_iscsi = FW_INTFVER(T4, ISCSI),
2087 .intfver_fcoepdu = FW_INTFVER(T4, FCOEPDU),
2088 .intfver_fcoe = FW_INTFVER(T4, FCOE),
2092 .kld_name = "t5fw_cfg",
2093 .fw_mod_name = "t5fw",
2095 .chip = FW_HDR_CHIP_T5,
2096 .fw_ver = htobe32_const(FW_VERSION(T5)),
2097 .intfver_nic = FW_INTFVER(T5, NIC),
2098 .intfver_vnic = FW_INTFVER(T5, VNIC),
2099 .intfver_ofld = FW_INTFVER(T5, OFLD),
2100 .intfver_ri = FW_INTFVER(T5, RI),
2101 .intfver_iscsipdu = FW_INTFVER(T5, ISCSIPDU),
2102 .intfver_iscsi = FW_INTFVER(T5, ISCSI),
2103 .intfver_fcoepdu = FW_INTFVER(T5, FCOEPDU),
2104 .intfver_fcoe = FW_INTFVER(T5, FCOE),
2109 static struct fw_info *
2110 find_fw_info(int chip)
2114 for (i = 0; i < nitems(fw_info); i++) {
2115 if (fw_info[i].chip == chip)
2116 return (&fw_info[i]);
2122 * Is the given firmware API compatible with the one the driver was compiled
2126 fw_compatible(const struct fw_hdr *hdr1, const struct fw_hdr *hdr2)
2129 /* short circuit if it's the exact same firmware version */
2130 if (hdr1->chip == hdr2->chip && hdr1->fw_ver == hdr2->fw_ver)
2134 * XXX: Is this too conservative? Perhaps I should limit this to the
2135 * features that are supported in the driver.
2137 #define SAME_INTF(x) (hdr1->intfver_##x == hdr2->intfver_##x)
2138 if (hdr1->chip == hdr2->chip && SAME_INTF(nic) && SAME_INTF(vnic) &&
2139 SAME_INTF(ofld) && SAME_INTF(ri) && SAME_INTF(iscsipdu) &&
2140 SAME_INTF(iscsi) && SAME_INTF(fcoepdu) && SAME_INTF(fcoe))
2148 * The firmware in the KLD is usable, but should it be installed? This routine
2149 * explains itself in detail if it indicates the KLD firmware should be
2153 should_install_kld_fw(struct adapter *sc, int card_fw_usable, int k, int c)
2157 if (!card_fw_usable) {
2158 reason = "incompatible or unusable";
2163 reason = "older than the version bundled with this driver";
2167 if (t4_fw_install == 2 && k != c) {
2168 reason = "different than the version bundled with this driver";
2175 if (t4_fw_install == 0) {
2176 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
2177 "but the driver is prohibited from installing a different "
2178 "firmware on the card.\n",
2179 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
2180 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason);
2185 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
2186 "installing firmware %u.%u.%u.%u on card.\n",
2187 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
2188 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason,
2189 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
2190 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
2195 * Establish contact with the firmware and determine if we are the master driver
2196 * or not, and whether we are responsible for chip initialization.
2199 prep_firmware(struct adapter *sc)
2201 const struct firmware *fw = NULL, *default_cfg;
2202 int rc, pf, card_fw_usable, kld_fw_usable, need_fw_reset = 1;
2203 enum dev_state state;
2204 struct fw_info *fw_info;
2205 struct fw_hdr *card_fw; /* fw on the card */
2206 const struct fw_hdr *kld_fw; /* fw in the KLD */
2207 const struct fw_hdr *drv_fw; /* fw header the driver was compiled
2210 /* Contact firmware. */
2211 rc = t4_fw_hello(sc, sc->mbox, sc->mbox, MASTER_MAY, &state);
2212 if (rc < 0 || state == DEV_STATE_ERR) {
2214 device_printf(sc->dev,
2215 "failed to connect to the firmware: %d, %d.\n", rc, state);
2220 sc->flags |= MASTER_PF;
2221 else if (state == DEV_STATE_UNINIT) {
2223 * We didn't get to be the master so we definitely won't be
2224 * configuring the chip. It's a bug if someone else hasn't
2225 * configured it already.
2227 device_printf(sc->dev, "couldn't be master(%d), "
2228 "device not already initialized either(%d).\n", rc, state);
2232 /* This is the firmware whose headers the driver was compiled against */
2233 fw_info = find_fw_info(chip_id(sc));
2234 if (fw_info == NULL) {
2235 device_printf(sc->dev,
2236 "unable to look up firmware information for chip %d.\n",
2240 drv_fw = &fw_info->fw_hdr;
2243 * The firmware KLD contains many modules. The KLD name is also the
2244 * name of the module that contains the default config file.
2246 default_cfg = firmware_get(fw_info->kld_name);
2248 /* Read the header of the firmware on the card */
2249 card_fw = malloc(sizeof(*card_fw), M_CXGBE, M_ZERO | M_WAITOK);
2250 rc = -t4_read_flash(sc, FLASH_FW_START,
2251 sizeof (*card_fw) / sizeof (uint32_t), (uint32_t *)card_fw, 1);
2253 card_fw_usable = fw_compatible(drv_fw, (const void*)card_fw);
2255 device_printf(sc->dev,
2256 "Unable to read card's firmware header: %d\n", rc);
2260 /* This is the firmware in the KLD */
2261 fw = firmware_get(fw_info->fw_mod_name);
2263 kld_fw = (const void *)fw->data;
2264 kld_fw_usable = fw_compatible(drv_fw, kld_fw);
2270 if (card_fw_usable && card_fw->fw_ver == drv_fw->fw_ver &&
2271 (!kld_fw_usable || kld_fw->fw_ver == drv_fw->fw_ver)) {
2273 * Common case: the firmware on the card is an exact match and
2274 * the KLD is an exact match too, or the KLD is
2275 * absent/incompatible. Note that t4_fw_install = 2 is ignored
2276 * here -- use cxgbetool loadfw if you want to reinstall the
2277 * same firmware as the one on the card.
2279 } else if (kld_fw_usable && state == DEV_STATE_UNINIT &&
2280 should_install_kld_fw(sc, card_fw_usable, be32toh(kld_fw->fw_ver),
2281 be32toh(card_fw->fw_ver))) {
2283 rc = -t4_fw_upgrade(sc, sc->mbox, fw->data, fw->datasize, 0);
2285 device_printf(sc->dev,
2286 "failed to install firmware: %d\n", rc);
2290 /* Installed successfully, update the cached header too. */
2291 memcpy(card_fw, kld_fw, sizeof(*card_fw));
2293 need_fw_reset = 0; /* already reset as part of load_fw */
2296 if (!card_fw_usable) {
2299 d = ntohl(drv_fw->fw_ver);
2300 c = ntohl(card_fw->fw_ver);
2301 k = kld_fw ? ntohl(kld_fw->fw_ver) : 0;
2303 device_printf(sc->dev, "Cannot find a usable firmware: "
2304 "fw_install %d, chip state %d, "
2305 "driver compiled with %d.%d.%d.%d, "
2306 "card has %d.%d.%d.%d, KLD has %d.%d.%d.%d\n",
2307 t4_fw_install, state,
2308 G_FW_HDR_FW_VER_MAJOR(d), G_FW_HDR_FW_VER_MINOR(d),
2309 G_FW_HDR_FW_VER_MICRO(d), G_FW_HDR_FW_VER_BUILD(d),
2310 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
2311 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c),
2312 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
2313 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
2318 /* We're using whatever's on the card and it's known to be good. */
2319 sc->params.fw_vers = ntohl(card_fw->fw_ver);
2320 snprintf(sc->fw_version, sizeof(sc->fw_version), "%u.%u.%u.%u",
2321 G_FW_HDR_FW_VER_MAJOR(sc->params.fw_vers),
2322 G_FW_HDR_FW_VER_MINOR(sc->params.fw_vers),
2323 G_FW_HDR_FW_VER_MICRO(sc->params.fw_vers),
2324 G_FW_HDR_FW_VER_BUILD(sc->params.fw_vers));
2325 t4_get_tp_version(sc, &sc->params.tp_vers);
2328 if (need_fw_reset &&
2329 (rc = -t4_fw_reset(sc, sc->mbox, F_PIORSTMODE | F_PIORST)) != 0) {
2330 device_printf(sc->dev, "firmware reset failed: %d.\n", rc);
2331 if (rc != ETIMEDOUT && rc != EIO)
2332 t4_fw_bye(sc, sc->mbox);
2337 rc = get_params__pre_init(sc);
2339 goto done; /* error message displayed already */
2341 /* Partition adapter resources as specified in the config file. */
2342 if (state == DEV_STATE_UNINIT) {
2344 KASSERT(sc->flags & MASTER_PF,
2345 ("%s: trying to change chip settings when not master.",
2348 rc = partition_resources(sc, default_cfg, fw_info->kld_name);
2350 goto done; /* error message displayed already */
2352 t4_tweak_chip_settings(sc);
2354 /* get basic stuff going */
2355 rc = -t4_fw_initialize(sc, sc->mbox);
2357 device_printf(sc->dev, "fw init failed: %d.\n", rc);
2361 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "pf%d", pf);
2366 free(card_fw, M_CXGBE);
2368 firmware_put(fw, FIRMWARE_UNLOAD);
2369 if (default_cfg != NULL)
2370 firmware_put(default_cfg, FIRMWARE_UNLOAD);
2375 #define FW_PARAM_DEV(param) \
2376 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
2377 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
2378 #define FW_PARAM_PFVF(param) \
2379 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
2380 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param))
2383 * Partition chip resources for use between various PFs, VFs, etc.
2386 partition_resources(struct adapter *sc, const struct firmware *default_cfg,
2387 const char *name_prefix)
2389 const struct firmware *cfg = NULL;
2391 struct fw_caps_config_cmd caps;
2392 uint32_t mtype, moff, finicsum, cfcsum;
2395 * Figure out what configuration file to use. Pick the default config
2396 * file for the card if the user hasn't specified one explicitly.
2398 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", t4_cfg_file);
2399 if (strncmp(t4_cfg_file, DEFAULT_CF, sizeof(t4_cfg_file)) == 0) {
2400 /* Card specific overrides go here. */
2401 if (pci_get_device(sc->dev) == 0x440a)
2402 snprintf(sc->cfg_file, sizeof(sc->cfg_file), UWIRE_CF);
2404 snprintf(sc->cfg_file, sizeof(sc->cfg_file), FPGA_CF);
2408 * We need to load another module if the profile is anything except
2409 * "default" or "flash".
2411 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) != 0 &&
2412 strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
2415 snprintf(s, sizeof(s), "%s_%s", name_prefix, sc->cfg_file);
2416 cfg = firmware_get(s);
2418 if (default_cfg != NULL) {
2419 device_printf(sc->dev,
2420 "unable to load module \"%s\" for "
2421 "configuration profile \"%s\", will use "
2422 "the default config file instead.\n",
2424 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
2427 device_printf(sc->dev,
2428 "unable to load module \"%s\" for "
2429 "configuration profile \"%s\", will use "
2430 "the config file on the card's flash "
2431 "instead.\n", s, sc->cfg_file);
2432 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
2438 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) == 0 &&
2439 default_cfg == NULL) {
2440 device_printf(sc->dev,
2441 "default config file not available, will use the config "
2442 "file on the card's flash instead.\n");
2443 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", FLASH_CF);
2446 if (strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
2448 const uint32_t *cfdata;
2449 uint32_t param, val, addr, off, mw_base, mw_aperture;
2451 KASSERT(cfg != NULL || default_cfg != NULL,
2452 ("%s: no config to upload", __func__));
2455 * Ask the firmware where it wants us to upload the config file.
2457 param = FW_PARAM_DEV(CF);
2458 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
2460 /* No support for config file? Shouldn't happen. */
2461 device_printf(sc->dev,
2462 "failed to query config file location: %d.\n", rc);
2465 mtype = G_FW_PARAMS_PARAM_Y(val);
2466 moff = G_FW_PARAMS_PARAM_Z(val) << 16;
2469 * XXX: sheer laziness. We deliberately added 4 bytes of
2470 * useless stuffing/comments at the end of the config file so
2471 * it's ok to simply throw away the last remaining bytes when
2472 * the config file is not an exact multiple of 4. This also
2473 * helps with the validate_mt_off_len check.
2476 cflen = cfg->datasize & ~3;
2479 cflen = default_cfg->datasize & ~3;
2480 cfdata = default_cfg->data;
2483 if (cflen > FLASH_CFG_MAX_SIZE) {
2484 device_printf(sc->dev,
2485 "config file too long (%d, max allowed is %d). "
2486 "Will try to use the config on the card, if any.\n",
2487 cflen, FLASH_CFG_MAX_SIZE);
2488 goto use_config_on_flash;
2491 rc = validate_mt_off_len(sc, mtype, moff, cflen, &addr);
2493 device_printf(sc->dev,
2494 "%s: addr (%d/0x%x) or len %d is not valid: %d. "
2495 "Will try to use the config on the card, if any.\n",
2496 __func__, mtype, moff, cflen, rc);
2497 goto use_config_on_flash;
2500 memwin_info(sc, 2, &mw_base, &mw_aperture);
2502 off = position_memwin(sc, 2, addr);
2503 n = min(cflen, mw_aperture - off);
2504 for (i = 0; i < n; i += 4)
2505 t4_write_reg(sc, mw_base + off + i, *cfdata++);
2510 use_config_on_flash:
2511 mtype = FW_MEMTYPE_FLASH;
2512 moff = t4_flash_cfg_addr(sc);
2515 bzero(&caps, sizeof(caps));
2516 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
2517 F_FW_CMD_REQUEST | F_FW_CMD_READ);
2518 caps.cfvalid_to_len16 = htobe32(F_FW_CAPS_CONFIG_CMD_CFVALID |
2519 V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
2520 V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(moff >> 16) | FW_LEN16(caps));
2521 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
2523 device_printf(sc->dev,
2524 "failed to pre-process config file: %d "
2525 "(mtype %d, moff 0x%x).\n", rc, mtype, moff);
2529 finicsum = be32toh(caps.finicsum);
2530 cfcsum = be32toh(caps.cfcsum);
2531 if (finicsum != cfcsum) {
2532 device_printf(sc->dev,
2533 "WARNING: config file checksum mismatch: %08x %08x\n",
2536 sc->cfcsum = cfcsum;
2538 #define LIMIT_CAPS(x) do { \
2539 caps.x &= htobe16(t4_##x##_allowed); \
2543 * Let the firmware know what features will (not) be used so it can tune
2544 * things accordingly.
2546 LIMIT_CAPS(linkcaps);
2547 LIMIT_CAPS(niccaps);
2548 LIMIT_CAPS(toecaps);
2549 LIMIT_CAPS(rdmacaps);
2550 LIMIT_CAPS(iscsicaps);
2551 LIMIT_CAPS(fcoecaps);
2554 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
2555 F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
2556 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
2557 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), NULL);
2559 device_printf(sc->dev,
2560 "failed to process config file: %d.\n", rc);
2564 firmware_put(cfg, FIRMWARE_UNLOAD);
2569 * Retrieve parameters that are needed (or nice to have) very early.
2572 get_params__pre_init(struct adapter *sc)
2575 uint32_t param[2], val[2];
2576 struct fw_devlog_cmd cmd;
2577 struct devlog_params *dlog = &sc->params.devlog;
2579 param[0] = FW_PARAM_DEV(PORTVEC);
2580 param[1] = FW_PARAM_DEV(CCLK);
2581 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
2583 device_printf(sc->dev,
2584 "failed to query parameters (pre_init): %d.\n", rc);
2588 sc->params.portvec = val[0];
2589 sc->params.nports = bitcount32(val[0]);
2590 sc->params.vpd.cclk = val[1];
2592 /* Read device log parameters. */
2593 bzero(&cmd, sizeof(cmd));
2594 cmd.op_to_write = htobe32(V_FW_CMD_OP(FW_DEVLOG_CMD) |
2595 F_FW_CMD_REQUEST | F_FW_CMD_READ);
2596 cmd.retval_len16 = htobe32(FW_LEN16(cmd));
2597 rc = -t4_wr_mbox(sc, sc->mbox, &cmd, sizeof(cmd), &cmd);
2599 device_printf(sc->dev,
2600 "failed to get devlog parameters: %d.\n", rc);
2601 bzero(dlog, sizeof (*dlog));
2602 rc = 0; /* devlog isn't critical for device operation */
2604 val[0] = be32toh(cmd.memtype_devlog_memaddr16_devlog);
2605 dlog->memtype = G_FW_DEVLOG_CMD_MEMTYPE_DEVLOG(val[0]);
2606 dlog->start = G_FW_DEVLOG_CMD_MEMADDR16_DEVLOG(val[0]) << 4;
2607 dlog->size = be32toh(cmd.memsize_devlog);
2614 * Retrieve various parameters that are of interest to the driver. The device
2615 * has been initialized by the firmware at this point.
2618 get_params__post_init(struct adapter *sc)
2621 uint32_t param[7], val[7];
2622 struct fw_caps_config_cmd caps;
2624 param[0] = FW_PARAM_PFVF(IQFLINT_START);
2625 param[1] = FW_PARAM_PFVF(EQ_START);
2626 param[2] = FW_PARAM_PFVF(FILTER_START);
2627 param[3] = FW_PARAM_PFVF(FILTER_END);
2628 param[4] = FW_PARAM_PFVF(L2T_START);
2629 param[5] = FW_PARAM_PFVF(L2T_END);
2630 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
2632 device_printf(sc->dev,
2633 "failed to query parameters (post_init): %d.\n", rc);
2637 sc->sge.iq_start = val[0];
2638 sc->sge.eq_start = val[1];
2639 sc->tids.ftid_base = val[2];
2640 sc->tids.nftids = val[3] - val[2] + 1;
2641 sc->params.ftid_min = val[2];
2642 sc->params.ftid_max = val[3];
2643 sc->vres.l2t.start = val[4];
2644 sc->vres.l2t.size = val[5] - val[4] + 1;
2645 KASSERT(sc->vres.l2t.size <= L2T_SIZE,
2646 ("%s: L2 table size (%u) larger than expected (%u)",
2647 __func__, sc->vres.l2t.size, L2T_SIZE));
2649 /* get capabilites */
2650 bzero(&caps, sizeof(caps));
2651 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
2652 F_FW_CMD_REQUEST | F_FW_CMD_READ);
2653 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
2654 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
2656 device_printf(sc->dev,
2657 "failed to get card capabilities: %d.\n", rc);
2661 #define READ_CAPS(x) do { \
2662 sc->x = htobe16(caps.x); \
2664 READ_CAPS(linkcaps);
2667 READ_CAPS(rdmacaps);
2668 READ_CAPS(iscsicaps);
2669 READ_CAPS(fcoecaps);
2671 if (sc->niccaps & FW_CAPS_CONFIG_NIC_ETHOFLD) {
2672 param[0] = FW_PARAM_PFVF(ETHOFLD_START);
2673 param[1] = FW_PARAM_PFVF(ETHOFLD_END);
2674 param[2] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
2675 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 3, param, val);
2677 device_printf(sc->dev,
2678 "failed to query NIC parameters: %d.\n", rc);
2681 sc->tids.etid_base = val[0];
2682 sc->params.etid_min = val[0];
2683 sc->tids.netids = val[1] - val[0] + 1;
2684 sc->params.netids = sc->tids.netids;
2685 sc->params.eo_wr_cred = val[2];
2686 sc->params.ethoffload = 1;
2690 /* query offload-related parameters */
2691 param[0] = FW_PARAM_DEV(NTID);
2692 param[1] = FW_PARAM_PFVF(SERVER_START);
2693 param[2] = FW_PARAM_PFVF(SERVER_END);
2694 param[3] = FW_PARAM_PFVF(TDDP_START);
2695 param[4] = FW_PARAM_PFVF(TDDP_END);
2696 param[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
2697 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
2699 device_printf(sc->dev,
2700 "failed to query TOE parameters: %d.\n", rc);
2703 sc->tids.ntids = val[0];
2704 sc->tids.natids = min(sc->tids.ntids / 2, MAX_ATIDS);
2705 sc->tids.stid_base = val[1];
2706 sc->tids.nstids = val[2] - val[1] + 1;
2707 sc->vres.ddp.start = val[3];
2708 sc->vres.ddp.size = val[4] - val[3] + 1;
2709 sc->params.ofldq_wr_cred = val[5];
2710 sc->params.offload = 1;
2713 param[0] = FW_PARAM_PFVF(STAG_START);
2714 param[1] = FW_PARAM_PFVF(STAG_END);
2715 param[2] = FW_PARAM_PFVF(RQ_START);
2716 param[3] = FW_PARAM_PFVF(RQ_END);
2717 param[4] = FW_PARAM_PFVF(PBL_START);
2718 param[5] = FW_PARAM_PFVF(PBL_END);
2719 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
2721 device_printf(sc->dev,
2722 "failed to query RDMA parameters(1): %d.\n", rc);
2725 sc->vres.stag.start = val[0];
2726 sc->vres.stag.size = val[1] - val[0] + 1;
2727 sc->vres.rq.start = val[2];
2728 sc->vres.rq.size = val[3] - val[2] + 1;
2729 sc->vres.pbl.start = val[4];
2730 sc->vres.pbl.size = val[5] - val[4] + 1;
2732 param[0] = FW_PARAM_PFVF(SQRQ_START);
2733 param[1] = FW_PARAM_PFVF(SQRQ_END);
2734 param[2] = FW_PARAM_PFVF(CQ_START);
2735 param[3] = FW_PARAM_PFVF(CQ_END);
2736 param[4] = FW_PARAM_PFVF(OCQ_START);
2737 param[5] = FW_PARAM_PFVF(OCQ_END);
2738 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
2740 device_printf(sc->dev,
2741 "failed to query RDMA parameters(2): %d.\n", rc);
2744 sc->vres.qp.start = val[0];
2745 sc->vres.qp.size = val[1] - val[0] + 1;
2746 sc->vres.cq.start = val[2];
2747 sc->vres.cq.size = val[3] - val[2] + 1;
2748 sc->vres.ocq.start = val[4];
2749 sc->vres.ocq.size = val[5] - val[4] + 1;
2751 if (sc->iscsicaps) {
2752 param[0] = FW_PARAM_PFVF(ISCSI_START);
2753 param[1] = FW_PARAM_PFVF(ISCSI_END);
2754 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
2756 device_printf(sc->dev,
2757 "failed to query iSCSI parameters: %d.\n", rc);
2760 sc->vres.iscsi.start = val[0];
2761 sc->vres.iscsi.size = val[1] - val[0] + 1;
2765 * We've got the params we wanted to query via the firmware. Now grab
2766 * some others directly from the chip.
2768 rc = t4_read_chip_settings(sc);
2774 set_params__post_init(struct adapter *sc)
2776 uint32_t param, val;
2778 /* ask for encapsulated CPLs */
2779 param = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
2781 (void)t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
2786 #undef FW_PARAM_PFVF
2790 t4_set_desc(struct adapter *sc)
2793 struct adapter_params *p = &sc->params;
2795 snprintf(buf, sizeof(buf), "Chelsio %s %sNIC (rev %d), S/N:%s, "
2796 "P/N:%s, E/C:%s", p->vpd.id, is_offload(sc) ? "R" : "",
2797 chip_rev(sc), p->vpd.sn, p->vpd.pn, p->vpd.ec);
2799 device_set_desc_copy(sc->dev, buf);
2803 build_medialist(struct port_info *pi, struct ifmedia *media)
2809 ifmedia_removeall(media);
2811 m = IFM_ETHER | IFM_FDX;
2812 data = (pi->port_type << 8) | pi->mod_type;
2814 switch(pi->port_type) {
2815 case FW_PORT_TYPE_BT_XFI:
2816 case FW_PORT_TYPE_BT_XAUI:
2817 ifmedia_add(media, m | IFM_10G_T, data, NULL);
2820 case FW_PORT_TYPE_BT_SGMII:
2821 ifmedia_add(media, m | IFM_1000_T, data, NULL);
2822 ifmedia_add(media, m | IFM_100_TX, data, NULL);
2823 ifmedia_add(media, IFM_ETHER | IFM_AUTO, data, NULL);
2824 ifmedia_set(media, IFM_ETHER | IFM_AUTO);
2827 case FW_PORT_TYPE_CX4:
2828 ifmedia_add(media, m | IFM_10G_CX4, data, NULL);
2829 ifmedia_set(media, m | IFM_10G_CX4);
2832 case FW_PORT_TYPE_QSFP_10G:
2833 case FW_PORT_TYPE_SFP:
2834 case FW_PORT_TYPE_FIBER_XFI:
2835 case FW_PORT_TYPE_FIBER_XAUI:
2836 switch (pi->mod_type) {
2838 case FW_PORT_MOD_TYPE_LR:
2839 ifmedia_add(media, m | IFM_10G_LR, data, NULL);
2840 ifmedia_set(media, m | IFM_10G_LR);
2843 case FW_PORT_MOD_TYPE_SR:
2844 ifmedia_add(media, m | IFM_10G_SR, data, NULL);
2845 ifmedia_set(media, m | IFM_10G_SR);
2848 case FW_PORT_MOD_TYPE_LRM:
2849 ifmedia_add(media, m | IFM_10G_LRM, data, NULL);
2850 ifmedia_set(media, m | IFM_10G_LRM);
2853 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
2854 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
2855 ifmedia_add(media, m | IFM_10G_TWINAX, data, NULL);
2856 ifmedia_set(media, m | IFM_10G_TWINAX);
2859 case FW_PORT_MOD_TYPE_NONE:
2861 ifmedia_add(media, m | IFM_NONE, data, NULL);
2862 ifmedia_set(media, m | IFM_NONE);
2865 case FW_PORT_MOD_TYPE_NA:
2866 case FW_PORT_MOD_TYPE_ER:
2868 device_printf(pi->dev,
2869 "unknown port_type (%d), mod_type (%d)\n",
2870 pi->port_type, pi->mod_type);
2871 ifmedia_add(media, m | IFM_UNKNOWN, data, NULL);
2872 ifmedia_set(media, m | IFM_UNKNOWN);
2877 case FW_PORT_TYPE_QSFP:
2878 switch (pi->mod_type) {
2880 case FW_PORT_MOD_TYPE_LR:
2881 ifmedia_add(media, m | IFM_40G_LR4, data, NULL);
2882 ifmedia_set(media, m | IFM_40G_LR4);
2885 case FW_PORT_MOD_TYPE_SR:
2886 ifmedia_add(media, m | IFM_40G_SR4, data, NULL);
2887 ifmedia_set(media, m | IFM_40G_SR4);
2890 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
2891 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
2892 ifmedia_add(media, m | IFM_40G_CR4, data, NULL);
2893 ifmedia_set(media, m | IFM_40G_CR4);
2896 case FW_PORT_MOD_TYPE_NONE:
2898 ifmedia_add(media, m | IFM_NONE, data, NULL);
2899 ifmedia_set(media, m | IFM_NONE);
2903 device_printf(pi->dev,
2904 "unknown port_type (%d), mod_type (%d)\n",
2905 pi->port_type, pi->mod_type);
2906 ifmedia_add(media, m | IFM_UNKNOWN, data, NULL);
2907 ifmedia_set(media, m | IFM_UNKNOWN);
2913 device_printf(pi->dev,
2914 "unknown port_type (%d), mod_type (%d)\n", pi->port_type,
2916 ifmedia_add(media, m | IFM_UNKNOWN, data, NULL);
2917 ifmedia_set(media, m | IFM_UNKNOWN);
2924 #define FW_MAC_EXACT_CHUNK 7
2927 * Program the port's XGMAC based on parameters in ifnet. The caller also
2928 * indicates which parameters should be programmed (the rest are left alone).
2931 update_mac_settings(struct ifnet *ifp, int flags)
2934 struct port_info *pi = ifp->if_softc;
2935 struct adapter *sc = pi->adapter;
2936 int mtu = -1, promisc = -1, allmulti = -1, vlanex = -1;
2937 uint16_t viid = 0xffff;
2938 int16_t *xact_addr_filt = NULL;
2940 ASSERT_SYNCHRONIZED_OP(sc);
2941 KASSERT(flags, ("%s: not told what to update.", __func__));
2943 if (ifp == pi->ifp) {
2945 xact_addr_filt = &pi->xact_addr_filt;
2948 else if (ifp == pi->nm_ifp) {
2950 xact_addr_filt = &pi->nm_xact_addr_filt;
2953 if (flags & XGMAC_MTU)
2956 if (flags & XGMAC_PROMISC)
2957 promisc = ifp->if_flags & IFF_PROMISC ? 1 : 0;
2959 if (flags & XGMAC_ALLMULTI)
2960 allmulti = ifp->if_flags & IFF_ALLMULTI ? 1 : 0;
2962 if (flags & XGMAC_VLANEX)
2963 vlanex = ifp->if_capenable & IFCAP_VLAN_HWTAGGING ? 1 : 0;
2965 if (flags & (XGMAC_MTU|XGMAC_PROMISC|XGMAC_ALLMULTI|XGMAC_VLANEX)) {
2966 rc = -t4_set_rxmode(sc, sc->mbox, viid, mtu, promisc, allmulti,
2969 if_printf(ifp, "set_rxmode (%x) failed: %d\n", flags,
2975 if (flags & XGMAC_UCADDR) {
2976 uint8_t ucaddr[ETHER_ADDR_LEN];
2978 bcopy(IF_LLADDR(ifp), ucaddr, sizeof(ucaddr));
2979 rc = t4_change_mac(sc, sc->mbox, viid, *xact_addr_filt, ucaddr,
2983 if_printf(ifp, "change_mac failed: %d\n", rc);
2986 *xact_addr_filt = rc;
2991 if (flags & XGMAC_MCADDRS) {
2992 const uint8_t *mcaddr[FW_MAC_EXACT_CHUNK];
2995 struct ifmultiaddr *ifma;
2998 if_maddr_rlock(ifp);
2999 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
3000 if (ifma->ifma_addr->sa_family != AF_LINK)
3003 LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
3004 MPASS(ETHER_IS_MULTICAST(mcaddr[i]));
3007 if (i == FW_MAC_EXACT_CHUNK) {
3008 rc = t4_alloc_mac_filt(sc, sc->mbox, viid, del,
3009 i, mcaddr, NULL, &hash, 0);
3012 for (j = 0; j < i; j++) {
3014 "failed to add mc address"
3016 "%02x:%02x:%02x rc=%d\n",
3017 mcaddr[j][0], mcaddr[j][1],
3018 mcaddr[j][2], mcaddr[j][3],
3019 mcaddr[j][4], mcaddr[j][5],
3029 rc = t4_alloc_mac_filt(sc, sc->mbox, viid, del, i,
3030 mcaddr, NULL, &hash, 0);
3033 for (j = 0; j < i; j++) {
3035 "failed to add mc address"
3037 "%02x:%02x:%02x rc=%d\n",
3038 mcaddr[j][0], mcaddr[j][1],
3039 mcaddr[j][2], mcaddr[j][3],
3040 mcaddr[j][4], mcaddr[j][5],
3047 rc = -t4_set_addr_hash(sc, sc->mbox, viid, 0, hash, 0);
3049 if_printf(ifp, "failed to set mc address hash: %d", rc);
3051 if_maddr_runlock(ifp);
3058 * {begin|end}_synchronized_op must be called from the same thread.
3061 begin_synchronized_op(struct adapter *sc, struct port_info *pi, int flags,
3067 /* the caller thinks it's ok to sleep, but is it really? */
3068 if (flags & SLEEP_OK)
3069 pause("t4slptst", 1);
3080 if (pi && IS_DOOMED(pi)) {
3090 if (!(flags & SLEEP_OK)) {
3095 if (mtx_sleep(&sc->flags, &sc->sc_lock, pri, wmesg, 0)) {
3101 KASSERT(!IS_BUSY(sc), ("%s: controller busy.", __func__));
3104 sc->last_op = wmesg;
3105 sc->last_op_thr = curthread;
3109 if (!(flags & HOLD_LOCK) || rc)
3116 * {begin|end}_synchronized_op must be called from the same thread.
3119 end_synchronized_op(struct adapter *sc, int flags)
3122 if (flags & LOCK_HELD)
3123 ADAPTER_LOCK_ASSERT_OWNED(sc);
3127 KASSERT(IS_BUSY(sc), ("%s: controller not busy.", __func__));
3134 cxgbe_init_synchronized(struct port_info *pi)
3136 struct adapter *sc = pi->adapter;
3137 struct ifnet *ifp = pi->ifp;
3140 ASSERT_SYNCHRONIZED_OP(sc);
3142 if (isset(&sc->open_device_map, pi->port_id)) {
3143 KASSERT(ifp->if_drv_flags & IFF_DRV_RUNNING,
3144 ("mismatch between open_device_map and if_drv_flags"));
3145 return (0); /* already running */
3148 if (!(sc->flags & FULL_INIT_DONE) &&
3149 ((rc = adapter_full_init(sc)) != 0))
3150 return (rc); /* error message displayed already */
3152 if (!(pi->flags & PORT_INIT_DONE) &&
3153 ((rc = port_full_init(pi)) != 0))
3154 return (rc); /* error message displayed already */
3156 rc = update_mac_settings(ifp, XGMAC_ALL);
3158 goto done; /* error message displayed already */
3160 rc = -t4_enable_vi(sc, sc->mbox, pi->viid, true, true);
3162 if_printf(ifp, "enable_vi failed: %d\n", rc);
3167 * The first iq of the first port to come up is used for tracing.
3169 if (sc->traceq < 0) {
3170 sc->traceq = sc->sge.rxq[pi->first_rxq].iq.abs_id;
3171 t4_write_reg(sc, is_t4(sc) ? A_MPS_TRC_RSS_CONTROL :
3172 A_MPS_T5_TRC_RSS_CONTROL, V_RSSCONTROL(pi->tx_chan) |
3173 V_QUEUENUMBER(sc->traceq));
3174 pi->flags |= HAS_TRACEQ;
3178 setbit(&sc->open_device_map, pi->port_id);
3180 ifp->if_drv_flags |= IFF_DRV_RUNNING;
3183 callout_reset(&pi->tick, hz, cxgbe_tick, pi);
3186 cxgbe_uninit_synchronized(pi);
3195 cxgbe_uninit_synchronized(struct port_info *pi)
3197 struct adapter *sc = pi->adapter;
3198 struct ifnet *ifp = pi->ifp;
3201 ASSERT_SYNCHRONIZED_OP(sc);
3204 * Disable the VI so that all its data in either direction is discarded
3205 * by the MPS. Leave everything else (the queues, interrupts, and 1Hz
3206 * tick) intact as the TP can deliver negative advice or data that it's
3207 * holding in its RAM (for an offloaded connection) even after the VI is
3210 rc = -t4_enable_vi(sc, sc->mbox, pi->viid, false, false);
3212 if_printf(ifp, "disable_vi failed: %d\n", rc);
3216 clrbit(&sc->open_device_map, pi->port_id);
3218 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
3221 pi->link_cfg.link_ok = 0;
3222 pi->link_cfg.speed = 0;
3224 t4_os_link_changed(sc, pi->port_id, 0, -1);
3230 * It is ok for this function to fail midway and return right away. t4_detach
3231 * will walk the entire sc->irq list and clean up whatever is valid.
3234 setup_intr_handlers(struct adapter *sc)
3239 struct port_info *pi;
3240 struct sge_rxq *rxq;
3242 struct sge_ofld_rxq *ofld_rxq;
3245 struct sge_nm_rxq *nm_rxq;
3252 rid = sc->intr_type == INTR_INTX ? 0 : 1;
3253 if (sc->intr_count == 1)
3254 return (t4_alloc_irq(sc, irq, rid, t4_intr_all, sc, "all"));
3256 /* Multiple interrupts. */
3257 KASSERT(sc->intr_count >= T4_EXTRA_INTR + sc->params.nports,
3258 ("%s: too few intr.", __func__));
3260 /* The first one is always error intr */
3261 rc = t4_alloc_irq(sc, irq, rid, t4_intr_err, sc, "err");
3267 /* The second one is always the firmware event queue */
3268 rc = t4_alloc_irq(sc, irq, rid, t4_intr_evt, &sc->sge.fwq, "evt");
3274 for_each_port(sc, p) {
3277 if (pi->flags & INTR_RXQ) {
3278 for_each_rxq(pi, q, rxq) {
3279 snprintf(s, sizeof(s), "%d.%d", p, q);
3280 rc = t4_alloc_irq(sc, irq, rid, t4_intr, rxq,
3289 if (pi->flags & INTR_OFLD_RXQ) {
3290 for_each_ofld_rxq(pi, q, ofld_rxq) {
3291 snprintf(s, sizeof(s), "%d,%d", p, q);
3292 rc = t4_alloc_irq(sc, irq, rid, t4_intr,
3302 if (pi->flags & INTR_NM_RXQ) {
3303 for_each_nm_rxq(pi, q, nm_rxq) {
3304 snprintf(s, sizeof(s), "%d-%d", p, q);
3305 rc = t4_alloc_irq(sc, irq, rid, t4_nm_intr,
3315 MPASS(irq == &sc->irq[sc->intr_count]);
3321 adapter_full_init(struct adapter *sc)
3325 ASSERT_SYNCHRONIZED_OP(sc);
3326 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
3327 KASSERT((sc->flags & FULL_INIT_DONE) == 0,
3328 ("%s: FULL_INIT_DONE already", __func__));
3331 * queues that belong to the adapter (not any particular port).
3333 rc = t4_setup_adapter_queues(sc);
3337 for (i = 0; i < nitems(sc->tq); i++) {
3338 sc->tq[i] = taskqueue_create("t4 taskq", M_NOWAIT,
3339 taskqueue_thread_enqueue, &sc->tq[i]);
3340 if (sc->tq[i] == NULL) {
3341 device_printf(sc->dev,
3342 "failed to allocate task queue %d\n", i);
3346 taskqueue_start_threads(&sc->tq[i], 1, PI_NET, "%s tq%d",
3347 device_get_nameunit(sc->dev), i);
3351 sc->flags |= FULL_INIT_DONE;
3354 adapter_full_uninit(sc);
3360 adapter_full_uninit(struct adapter *sc)
3364 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
3366 t4_teardown_adapter_queues(sc);
3368 for (i = 0; i < nitems(sc->tq) && sc->tq[i]; i++) {
3369 taskqueue_free(sc->tq[i]);
3373 sc->flags &= ~FULL_INIT_DONE;
3379 port_full_init(struct port_info *pi)
3381 struct adapter *sc = pi->adapter;
3382 struct ifnet *ifp = pi->ifp;
3384 struct sge_rxq *rxq;
3387 ASSERT_SYNCHRONIZED_OP(sc);
3388 KASSERT((pi->flags & PORT_INIT_DONE) == 0,
3389 ("%s: PORT_INIT_DONE already", __func__));
3391 sysctl_ctx_init(&pi->ctx);
3392 pi->flags |= PORT_SYSCTL_CTX;
3395 * Allocate tx/rx/fl queues for this port.
3397 rc = t4_setup_port_queues(pi);
3399 goto done; /* error message displayed already */
3402 * Setup RSS for this port. Save a copy of the RSS table for later use.
3404 rss = malloc(pi->rss_size * sizeof (*rss), M_CXGBE, M_ZERO | M_WAITOK);
3405 for (i = 0; i < pi->rss_size;) {
3406 for_each_rxq(pi, j, rxq) {
3407 rss[i++] = rxq->iq.abs_id;
3408 if (i == pi->rss_size)
3413 rc = -t4_config_rss_range(sc, sc->mbox, pi->viid, 0, pi->rss_size, rss,
3416 if_printf(ifp, "rss_config failed: %d\n", rc);
3421 pi->flags |= PORT_INIT_DONE;
3424 port_full_uninit(pi);
3433 port_full_uninit(struct port_info *pi)
3435 struct adapter *sc = pi->adapter;
3437 struct sge_rxq *rxq;
3438 struct sge_txq *txq;
3440 struct sge_ofld_rxq *ofld_rxq;
3441 struct sge_wrq *ofld_txq;
3444 if (pi->flags & PORT_INIT_DONE) {
3446 /* Need to quiesce queues. XXX: ctrl queues? */
3448 for_each_txq(pi, i, txq) {
3449 quiesce_eq(sc, &txq->eq);
3453 for_each_ofld_txq(pi, i, ofld_txq) {
3454 quiesce_eq(sc, &ofld_txq->eq);
3458 for_each_rxq(pi, i, rxq) {
3459 quiesce_iq(sc, &rxq->iq);
3460 quiesce_fl(sc, &rxq->fl);
3464 for_each_ofld_rxq(pi, i, ofld_rxq) {
3465 quiesce_iq(sc, &ofld_rxq->iq);
3466 quiesce_fl(sc, &ofld_rxq->fl);
3469 free(pi->rss, M_CXGBE);
3472 t4_teardown_port_queues(pi);
3473 pi->flags &= ~PORT_INIT_DONE;
3479 quiesce_eq(struct adapter *sc, struct sge_eq *eq)
3482 eq->flags |= EQ_DOOMED;
3485 * Wait for the response to a credit flush if one's
3488 while (eq->flags & EQ_CRFLUSHED)
3489 mtx_sleep(eq, &eq->eq_lock, 0, "crflush", 0);
3492 callout_drain(&eq->tx_callout); /* XXX: iffy */
3493 pause("callout", 10); /* Still iffy */
3495 taskqueue_drain(sc->tq[eq->tx_chan], &eq->tx_task);
3499 quiesce_iq(struct adapter *sc, struct sge_iq *iq)
3501 (void) sc; /* unused */
3503 /* Synchronize with the interrupt handler */
3504 while (!atomic_cmpset_int(&iq->state, IQS_IDLE, IQS_DISABLED))
3509 quiesce_fl(struct adapter *sc, struct sge_fl *fl)
3511 mtx_lock(&sc->sfl_lock);
3513 fl->flags |= FL_DOOMED;
3515 mtx_unlock(&sc->sfl_lock);
3517 callout_drain(&sc->sfl_callout);
3518 KASSERT((fl->flags & FL_STARVING) == 0,
3519 ("%s: still starving", __func__));
3523 t4_alloc_irq(struct adapter *sc, struct irq *irq, int rid,
3524 driver_intr_t *handler, void *arg, char *name)
3529 irq->res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &irq->rid,
3530 RF_SHAREABLE | RF_ACTIVE);
3531 if (irq->res == NULL) {
3532 device_printf(sc->dev,
3533 "failed to allocate IRQ for rid %d, name %s.\n", rid, name);
3537 rc = bus_setup_intr(sc->dev, irq->res, INTR_MPSAFE | INTR_TYPE_NET,
3538 NULL, handler, arg, &irq->tag);
3540 device_printf(sc->dev,
3541 "failed to setup interrupt for rid %d, name %s: %d\n",
3544 bus_describe_intr(sc->dev, irq->res, irq->tag, name);
3550 t4_free_irq(struct adapter *sc, struct irq *irq)
3553 bus_teardown_intr(sc->dev, irq->res, irq->tag);
3555 bus_release_resource(sc->dev, SYS_RES_IRQ, irq->rid, irq->res);
3557 bzero(irq, sizeof(*irq));
3563 reg_block_dump(struct adapter *sc, uint8_t *buf, unsigned int start,
3566 uint32_t *p = (uint32_t *)(buf + start);
3568 for ( ; start <= end; start += sizeof(uint32_t))
3569 *p++ = t4_read_reg(sc, start);
3573 t4_get_regs(struct adapter *sc, struct t4_regdump *regs, uint8_t *buf)
3576 const unsigned int *reg_ranges;
3577 static const unsigned int t4_reg_ranges[] = {
3797 static const unsigned int t5_reg_ranges[] = {
4238 reg_ranges = &t4_reg_ranges[0];
4239 n = nitems(t4_reg_ranges);
4241 reg_ranges = &t5_reg_ranges[0];
4242 n = nitems(t5_reg_ranges);
4245 regs->version = chip_id(sc) | chip_rev(sc) << 10;
4246 for (i = 0; i < n; i += 2)
4247 reg_block_dump(sc, buf, reg_ranges[i], reg_ranges[i + 1]);
4251 cxgbe_refresh_stats(struct adapter *sc, struct port_info *pi)
4253 struct ifnet *ifp = pi->ifp;
4254 struct sge_txq *txq;
4256 struct port_stats *s = &pi->stats;
4258 const struct timeval interval = {0, 250000}; /* 250ms */
4261 timevalsub(&tv, &interval);
4262 if (timevalcmp(&tv, &pi->last_refreshed, <))
4265 t4_get_port_stats(sc, pi->tx_chan, s);
4267 ifp->if_opackets = s->tx_frames - s->tx_pause;
4268 ifp->if_ipackets = s->rx_frames - s->rx_pause;
4269 ifp->if_obytes = s->tx_octets - s->tx_pause * 64;
4270 ifp->if_ibytes = s->rx_octets - s->rx_pause * 64;
4271 ifp->if_omcasts = s->tx_mcast_frames - s->tx_pause;
4272 ifp->if_imcasts = s->rx_mcast_frames - s->rx_pause;
4273 ifp->if_iqdrops = s->rx_ovflow0 + s->rx_ovflow1 + s->rx_ovflow2 +
4274 s->rx_ovflow3 + s->rx_trunc0 + s->rx_trunc1 + s->rx_trunc2 +
4276 for (i = 0; i < NCHAN; i++) {
4277 if (pi->rx_chan_map & (1 << i)) {
4280 mtx_lock(&sc->regwin_lock);
4281 t4_read_indirect(sc, A_TP_MIB_INDEX, A_TP_MIB_DATA, &v,
4282 1, A_TP_MIB_TNL_CNG_DROP_0 + i);
4283 mtx_unlock(&sc->regwin_lock);
4284 ifp->if_iqdrops += v;
4289 for_each_txq(pi, i, txq)
4290 drops += txq->br->br_drops;
4291 ifp->if_snd.ifq_drops = drops;
4293 ifp->if_oerrors = s->tx_error_frames;
4294 ifp->if_ierrors = s->rx_jabber + s->rx_runt + s->rx_too_long +
4295 s->rx_fcs_err + s->rx_len_err;
4297 getmicrotime(&pi->last_refreshed);
4301 cxgbe_tick(void *arg)
4303 struct port_info *pi = arg;
4304 struct adapter *sc = pi->adapter;
4305 struct ifnet *ifp = pi->ifp;
4308 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
4310 return; /* without scheduling another callout */
4313 cxgbe_refresh_stats(sc, pi);
4315 callout_schedule(&pi->tick, hz);
4320 cxgbe_vlan_config(void *arg, struct ifnet *ifp, uint16_t vid)
4324 if (arg != ifp || ifp->if_type != IFT_ETHER)
4327 vlan = VLAN_DEVAT(ifp, vid);
4328 VLAN_SETCOOKIE(vlan, ifp);
4332 cpl_not_handled(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
4336 panic("%s: opcode 0x%02x on iq %p with payload %p",
4337 __func__, rss->opcode, iq, m);
4339 log(LOG_ERR, "%s: opcode 0x%02x on iq %p with payload %p\n",
4340 __func__, rss->opcode, iq, m);
4347 t4_register_cpl_handler(struct adapter *sc, int opcode, cpl_handler_t h)
4349 uintptr_t *loc, new;
4351 if (opcode >= nitems(sc->cpl_handler))
4354 new = h ? (uintptr_t)h : (uintptr_t)cpl_not_handled;
4355 loc = (uintptr_t *) &sc->cpl_handler[opcode];
4356 atomic_store_rel_ptr(loc, new);
4362 an_not_handled(struct sge_iq *iq, const struct rsp_ctrl *ctrl)
4366 panic("%s: async notification on iq %p (ctrl %p)", __func__, iq, ctrl);
4368 log(LOG_ERR, "%s: async notification on iq %p (ctrl %p)\n",
4369 __func__, iq, ctrl);
4375 t4_register_an_handler(struct adapter *sc, an_handler_t h)
4377 uintptr_t *loc, new;
4379 new = h ? (uintptr_t)h : (uintptr_t)an_not_handled;
4380 loc = (uintptr_t *) &sc->an_handler;
4381 atomic_store_rel_ptr(loc, new);
4387 fw_msg_not_handled(struct adapter *sc, const __be64 *rpl)
4389 const struct cpl_fw6_msg *cpl =
4390 __containerof(rpl, struct cpl_fw6_msg, data[0]);
4393 panic("%s: fw_msg type %d", __func__, cpl->type);
4395 log(LOG_ERR, "%s: fw_msg type %d\n", __func__, cpl->type);
4401 t4_register_fw_msg_handler(struct adapter *sc, int type, fw_msg_handler_t h)
4403 uintptr_t *loc, new;
4405 if (type >= nitems(sc->fw_msg_handler))
4409 * These are dispatched by the handler for FW{4|6}_CPL_MSG using the CPL
4410 * handler dispatch table. Reject any attempt to install a handler for
4413 if (type == FW_TYPE_RSSCPL || type == FW6_TYPE_RSSCPL)
4416 new = h ? (uintptr_t)h : (uintptr_t)fw_msg_not_handled;
4417 loc = (uintptr_t *) &sc->fw_msg_handler[type];
4418 atomic_store_rel_ptr(loc, new);
4424 t4_sysctls(struct adapter *sc)
4426 struct sysctl_ctx_list *ctx;
4427 struct sysctl_oid *oid;
4428 struct sysctl_oid_list *children, *c0;
4429 static char *caps[] = {
4430 "\20\1PPP\2QFC\3DCBX", /* caps[0] linkcaps */
4431 "\20\1NIC\2VM\3IDS\4UM\5UM_ISGL" /* caps[1] niccaps */
4432 "\6HASHFILTER\7ETHOFLD",
4433 "\20\1TOE", /* caps[2] toecaps */
4434 "\20\1RDDP\2RDMAC", /* caps[3] rdmacaps */
4435 "\20\1INITIATOR_PDU\2TARGET_PDU" /* caps[4] iscsicaps */
4436 "\3INITIATOR_CNXOFLD\4TARGET_CNXOFLD"
4437 "\5INITIATOR_SSNOFLD\6TARGET_SSNOFLD",
4438 "\20\1INITIATOR\2TARGET\3CTRL_OFLD" /* caps[5] fcoecaps */
4439 "\4PO_INITIAOR\5PO_TARGET"
4441 static char *doorbells = {"\20\1UDB\2WCWR\3UDBWC\4KDB"};
4443 ctx = device_get_sysctl_ctx(sc->dev);
4448 oid = device_get_sysctl_tree(sc->dev);
4449 c0 = children = SYSCTL_CHILDREN(oid);
4451 sc->sc_do_rxcopy = 1;
4452 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "do_rx_copy", CTLFLAG_RW,
4453 &sc->sc_do_rxcopy, 1, "Do RX copy of small frames");
4455 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nports", CTLFLAG_RD, NULL,
4456 sc->params.nports, "# of ports");
4458 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "hw_revision", CTLFLAG_RD,
4459 NULL, chip_rev(sc), "chip hardware revision");
4461 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "firmware_version",
4462 CTLFLAG_RD, sc->fw_version, 0, "firmware version");
4464 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "cf",
4465 CTLFLAG_RD, sc->cfg_file, 0, "configuration file");
4467 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "cfcsum", CTLFLAG_RD, NULL,
4468 sc->cfcsum, "config file checksum");
4470 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "doorbells",
4471 CTLTYPE_STRING | CTLFLAG_RD, doorbells, sc->doorbells,
4472 sysctl_bitfield, "A", "available doorbells");
4474 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "linkcaps",
4475 CTLTYPE_STRING | CTLFLAG_RD, caps[0], sc->linkcaps,
4476 sysctl_bitfield, "A", "available link capabilities");
4478 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "niccaps",
4479 CTLTYPE_STRING | CTLFLAG_RD, caps[1], sc->niccaps,
4480 sysctl_bitfield, "A", "available NIC capabilities");
4482 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "toecaps",
4483 CTLTYPE_STRING | CTLFLAG_RD, caps[2], sc->toecaps,
4484 sysctl_bitfield, "A", "available TCP offload capabilities");
4486 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rdmacaps",
4487 CTLTYPE_STRING | CTLFLAG_RD, caps[3], sc->rdmacaps,
4488 sysctl_bitfield, "A", "available RDMA capabilities");
4490 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "iscsicaps",
4491 CTLTYPE_STRING | CTLFLAG_RD, caps[4], sc->iscsicaps,
4492 sysctl_bitfield, "A", "available iSCSI capabilities");
4494 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fcoecaps",
4495 CTLTYPE_STRING | CTLFLAG_RD, caps[5], sc->fcoecaps,
4496 sysctl_bitfield, "A", "available FCoE capabilities");
4498 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "core_clock", CTLFLAG_RD, NULL,
4499 sc->params.vpd.cclk, "core clock frequency (in KHz)");
4501 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_timers",
4502 CTLTYPE_STRING | CTLFLAG_RD, sc->sge.timer_val,
4503 sizeof(sc->sge.timer_val), sysctl_int_array, "A",
4504 "interrupt holdoff timer values (us)");
4506 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pkt_counts",
4507 CTLTYPE_STRING | CTLFLAG_RD, sc->sge.counter_val,
4508 sizeof(sc->sge.counter_val), sysctl_int_array, "A",
4509 "interrupt holdoff packet counter values");
4511 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nfilters", CTLFLAG_RD,
4512 NULL, sc->tids.nftids, "number of filters");
4514 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature", CTLTYPE_INT |
4515 CTLFLAG_RD, sc, 0, sysctl_temperature, "I",
4516 "chip temperature (in Celsius)");
4518 t4_sge_sysctls(sc, ctx, children);
4520 sc->lro_timeout = 100;
4521 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "lro_timeout", CTLFLAG_RW,
4522 &sc->lro_timeout, 0, "lro inactive-flush timeout (in us)");
4526 * dev.t4nex.X.misc. Marked CTLFLAG_SKIP to avoid information overload.
4528 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "misc",
4529 CTLFLAG_RD | CTLFLAG_SKIP, NULL,
4530 "logs and miscellaneous information");
4531 children = SYSCTL_CHILDREN(oid);
4533 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cctrl",
4534 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4535 sysctl_cctrl, "A", "congestion control");
4537 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp0",
4538 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4539 sysctl_cim_ibq_obq, "A", "CIM IBQ 0 (TP0)");
4541 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp1",
4542 CTLTYPE_STRING | CTLFLAG_RD, sc, 1,
4543 sysctl_cim_ibq_obq, "A", "CIM IBQ 1 (TP1)");
4545 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ulp",
4546 CTLTYPE_STRING | CTLFLAG_RD, sc, 2,
4547 sysctl_cim_ibq_obq, "A", "CIM IBQ 2 (ULP)");
4549 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge0",
4550 CTLTYPE_STRING | CTLFLAG_RD, sc, 3,
4551 sysctl_cim_ibq_obq, "A", "CIM IBQ 3 (SGE0)");
4553 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge1",
4554 CTLTYPE_STRING | CTLFLAG_RD, sc, 4,
4555 sysctl_cim_ibq_obq, "A", "CIM IBQ 4 (SGE1)");
4557 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ncsi",
4558 CTLTYPE_STRING | CTLFLAG_RD, sc, 5,
4559 sysctl_cim_ibq_obq, "A", "CIM IBQ 5 (NCSI)");
4561 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_la",
4562 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4563 sysctl_cim_la, "A", "CIM logic analyzer");
4565 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ma_la",
4566 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4567 sysctl_cim_ma_la, "A", "CIM MA logic analyzer");
4569 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp0",
4570 CTLTYPE_STRING | CTLFLAG_RD, sc, 0 + CIM_NUM_IBQ,
4571 sysctl_cim_ibq_obq, "A", "CIM OBQ 0 (ULP0)");
4573 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp1",
4574 CTLTYPE_STRING | CTLFLAG_RD, sc, 1 + CIM_NUM_IBQ,
4575 sysctl_cim_ibq_obq, "A", "CIM OBQ 1 (ULP1)");
4577 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp2",
4578 CTLTYPE_STRING | CTLFLAG_RD, sc, 2 + CIM_NUM_IBQ,
4579 sysctl_cim_ibq_obq, "A", "CIM OBQ 2 (ULP2)");
4581 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp3",
4582 CTLTYPE_STRING | CTLFLAG_RD, sc, 3 + CIM_NUM_IBQ,
4583 sysctl_cim_ibq_obq, "A", "CIM OBQ 3 (ULP3)");
4585 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge",
4586 CTLTYPE_STRING | CTLFLAG_RD, sc, 4 + CIM_NUM_IBQ,
4587 sysctl_cim_ibq_obq, "A", "CIM OBQ 4 (SGE)");
4589 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ncsi",
4590 CTLTYPE_STRING | CTLFLAG_RD, sc, 5 + CIM_NUM_IBQ,
4591 sysctl_cim_ibq_obq, "A", "CIM OBQ 5 (NCSI)");
4594 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge0_rx",
4595 CTLTYPE_STRING | CTLFLAG_RD, sc, 6 + CIM_NUM_IBQ,
4596 sysctl_cim_ibq_obq, "A", "CIM OBQ 6 (SGE0-RX)");
4598 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge1_rx",
4599 CTLTYPE_STRING | CTLFLAG_RD, sc, 7 + CIM_NUM_IBQ,
4600 sysctl_cim_ibq_obq, "A", "CIM OBQ 7 (SGE1-RX)");
4603 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_pif_la",
4604 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4605 sysctl_cim_pif_la, "A", "CIM PIF logic analyzer");
4607 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_qcfg",
4608 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4609 sysctl_cim_qcfg, "A", "CIM queue configuration");
4611 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cpl_stats",
4612 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4613 sysctl_cpl_stats, "A", "CPL statistics");
4615 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ddp_stats",
4616 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4617 sysctl_ddp_stats, "A", "non-TCP DDP statistics");
4619 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "devlog",
4620 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4621 sysctl_devlog, "A", "firmware's device log");
4623 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fcoe_stats",
4624 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4625 sysctl_fcoe_stats, "A", "FCoE statistics");
4627 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "hw_sched",
4628 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4629 sysctl_hw_sched, "A", "hardware scheduler ");
4631 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "l2t",
4632 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4633 sysctl_l2t, "A", "hardware L2 table");
4635 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "lb_stats",
4636 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4637 sysctl_lb_stats, "A", "loopback statistics");
4639 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "meminfo",
4640 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4641 sysctl_meminfo, "A", "memory regions");
4643 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "mps_tcam",
4644 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4645 sysctl_mps_tcam, "A", "MPS TCAM entries");
4647 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "path_mtus",
4648 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4649 sysctl_path_mtus, "A", "path MTUs");
4651 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pm_stats",
4652 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4653 sysctl_pm_stats, "A", "PM statistics");
4655 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rdma_stats",
4656 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4657 sysctl_rdma_stats, "A", "RDMA statistics");
4659 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tcp_stats",
4660 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4661 sysctl_tcp_stats, "A", "TCP statistics");
4663 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tids",
4664 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4665 sysctl_tids, "A", "TID information");
4667 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_err_stats",
4668 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4669 sysctl_tp_err_stats, "A", "TP error statistics");
4671 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_la",
4672 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4673 sysctl_tp_la, "A", "TP logic analyzer");
4675 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_rate",
4676 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4677 sysctl_tx_rate, "A", "Tx rate");
4679 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ulprx_la",
4680 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4681 sysctl_ulprx_la, "A", "ULPRX logic analyzer");
4684 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "wcwr_stats",
4685 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
4686 sysctl_wcwr_stats, "A", "write combined work requests");
4691 if (is_offload(sc)) {
4695 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "toe", CTLFLAG_RD,
4696 NULL, "TOE parameters");
4697 children = SYSCTL_CHILDREN(oid);
4699 sc->tt.sndbuf = 256 * 1024;
4700 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "sndbuf", CTLFLAG_RW,
4701 &sc->tt.sndbuf, 0, "max hardware send buffer size");
4704 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ddp", CTLFLAG_RW,
4705 &sc->tt.ddp, 0, "DDP allowed");
4707 sc->tt.indsz = G_INDICATESIZE(t4_read_reg(sc, A_TP_PARA_REG5));
4708 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "indsz", CTLFLAG_RW,
4709 &sc->tt.indsz, 0, "DDP max indicate size allowed");
4712 G_RXCOALESCESIZE(t4_read_reg(sc, A_TP_PARA_REG2));
4713 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ddp_thres", CTLFLAG_RW,
4714 &sc->tt.ddp_thres, 0, "DDP threshold");
4716 sc->tt.rx_coalesce = 1;
4717 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_coalesce",
4718 CTLFLAG_RW, &sc->tt.rx_coalesce, 0, "receive coalescing");
4720 sc->tt.tx_align = 1;
4721 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_align",
4722 CTLFLAG_RW, &sc->tt.tx_align, 0, "chop and align payload");
4731 cxgbe_sysctls(struct port_info *pi)
4733 struct sysctl_ctx_list *ctx;
4734 struct sysctl_oid *oid;
4735 struct sysctl_oid_list *children;
4736 struct adapter *sc = pi->adapter;
4738 ctx = device_get_sysctl_ctx(pi->dev);
4743 oid = device_get_sysctl_tree(pi->dev);
4744 children = SYSCTL_CHILDREN(oid);
4746 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "linkdnrc", CTLTYPE_STRING |
4747 CTLFLAG_RD, pi, 0, sysctl_linkdnrc, "A", "reason why link is down");
4748 if (pi->port_type == FW_PORT_TYPE_BT_XAUI) {
4749 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature",
4750 CTLTYPE_INT | CTLFLAG_RD, pi, 0, sysctl_btphy, "I",
4751 "PHY temperature (in Celsius)");
4752 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fw_version",
4753 CTLTYPE_INT | CTLFLAG_RD, pi, 1, sysctl_btphy, "I",
4754 "PHY firmware version");
4756 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nrxq", CTLFLAG_RD,
4757 &pi->nrxq, 0, "# of rx queues");
4758 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ntxq", CTLFLAG_RD,
4759 &pi->ntxq, 0, "# of tx queues");
4760 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_rxq", CTLFLAG_RD,
4761 &pi->first_rxq, 0, "index of first rx queue");
4762 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_txq", CTLFLAG_RD,
4763 &pi->first_txq, 0, "index of first tx queue");
4764 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rsrv_noflowq", CTLTYPE_INT |
4765 CTLFLAG_RW, pi, 0, sysctl_noflowq, "IU",
4766 "Reserve queue 0 for non-flowid packets");
4769 if (is_offload(sc)) {
4770 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldrxq", CTLFLAG_RD,
4772 "# of rx queues for offloaded TCP connections");
4773 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldtxq", CTLFLAG_RD,
4775 "# of tx queues for offloaded TCP connections");
4776 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_rxq",
4777 CTLFLAG_RD, &pi->first_ofld_rxq, 0,
4778 "index of first TOE rx queue");
4779 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_txq",
4780 CTLFLAG_RD, &pi->first_ofld_txq, 0,
4781 "index of first TOE tx queue");
4785 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmrxq", CTLFLAG_RD,
4786 &pi->nnmrxq, 0, "# of rx queues for netmap");
4787 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmtxq", CTLFLAG_RD,
4788 &pi->nnmtxq, 0, "# of tx queues for netmap");
4789 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_rxq",
4790 CTLFLAG_RD, &pi->first_nm_rxq, 0,
4791 "index of first netmap rx queue");
4792 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_txq",
4793 CTLFLAG_RD, &pi->first_nm_txq, 0,
4794 "index of first netmap tx queue");
4797 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx",
4798 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_holdoff_tmr_idx, "I",
4799 "holdoff timer index");
4800 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx",
4801 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_holdoff_pktc_idx, "I",
4802 "holdoff packet counter index");
4804 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_rxq",
4805 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_qsize_rxq, "I",
4807 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_txq",
4808 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_qsize_txq, "I",
4811 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pause_settings",
4812 CTLTYPE_STRING | CTLFLAG_RW, pi, PAUSE_TX, sysctl_pause_settings,
4813 "A", "PAUSE settings (bit 0 = rx_pause, bit 1 = tx_pause)");
4816 * dev.cxgbe.X.stats.
4818 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats", CTLFLAG_RD,
4819 NULL, "port statistics");
4820 children = SYSCTL_CHILDREN(oid);
4822 #define SYSCTL_ADD_T4_REG64(pi, name, desc, reg) \
4823 SYSCTL_ADD_OID(ctx, children, OID_AUTO, name, \
4824 CTLTYPE_U64 | CTLFLAG_RD, sc, reg, \
4825 sysctl_handle_t4_reg64, "QU", desc)
4827 SYSCTL_ADD_T4_REG64(pi, "tx_octets", "# of octets in good frames",
4828 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BYTES_L));
4829 SYSCTL_ADD_T4_REG64(pi, "tx_frames", "total # of good frames",
4830 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_FRAMES_L));
4831 SYSCTL_ADD_T4_REG64(pi, "tx_bcast_frames", "# of broadcast frames",
4832 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BCAST_L));
4833 SYSCTL_ADD_T4_REG64(pi, "tx_mcast_frames", "# of multicast frames",
4834 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_MCAST_L));
4835 SYSCTL_ADD_T4_REG64(pi, "tx_ucast_frames", "# of unicast frames",
4836 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_UCAST_L));
4837 SYSCTL_ADD_T4_REG64(pi, "tx_error_frames", "# of error frames",
4838 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_ERROR_L));
4839 SYSCTL_ADD_T4_REG64(pi, "tx_frames_64",
4840 "# of tx frames in this range",
4841 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_64B_L));
4842 SYSCTL_ADD_T4_REG64(pi, "tx_frames_65_127",
4843 "# of tx frames in this range",
4844 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_65B_127B_L));
4845 SYSCTL_ADD_T4_REG64(pi, "tx_frames_128_255",
4846 "# of tx frames in this range",
4847 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_128B_255B_L));
4848 SYSCTL_ADD_T4_REG64(pi, "tx_frames_256_511",
4849 "# of tx frames in this range",
4850 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_256B_511B_L));
4851 SYSCTL_ADD_T4_REG64(pi, "tx_frames_512_1023",
4852 "# of tx frames in this range",
4853 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_512B_1023B_L));
4854 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1024_1518",
4855 "# of tx frames in this range",
4856 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1024B_1518B_L));
4857 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1519_max",
4858 "# of tx frames in this range",
4859 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1519B_MAX_L));
4860 SYSCTL_ADD_T4_REG64(pi, "tx_drop", "# of dropped tx frames",
4861 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_DROP_L));
4862 SYSCTL_ADD_T4_REG64(pi, "tx_pause", "# of pause frames transmitted",
4863 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PAUSE_L));
4864 SYSCTL_ADD_T4_REG64(pi, "tx_ppp0", "# of PPP prio 0 frames transmitted",
4865 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP0_L));
4866 SYSCTL_ADD_T4_REG64(pi, "tx_ppp1", "# of PPP prio 1 frames transmitted",
4867 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP1_L));
4868 SYSCTL_ADD_T4_REG64(pi, "tx_ppp2", "# of PPP prio 2 frames transmitted",
4869 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP2_L));
4870 SYSCTL_ADD_T4_REG64(pi, "tx_ppp3", "# of PPP prio 3 frames transmitted",
4871 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP3_L));
4872 SYSCTL_ADD_T4_REG64(pi, "tx_ppp4", "# of PPP prio 4 frames transmitted",
4873 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP4_L));
4874 SYSCTL_ADD_T4_REG64(pi, "tx_ppp5", "# of PPP prio 5 frames transmitted",
4875 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP5_L));
4876 SYSCTL_ADD_T4_REG64(pi, "tx_ppp6", "# of PPP prio 6 frames transmitted",
4877 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP6_L));
4878 SYSCTL_ADD_T4_REG64(pi, "tx_ppp7", "# of PPP prio 7 frames transmitted",
4879 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP7_L));
4881 SYSCTL_ADD_T4_REG64(pi, "rx_octets", "# of octets in good frames",
4882 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BYTES_L));
4883 SYSCTL_ADD_T4_REG64(pi, "rx_frames", "total # of good frames",
4884 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_FRAMES_L));
4885 SYSCTL_ADD_T4_REG64(pi, "rx_bcast_frames", "# of broadcast frames",
4886 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BCAST_L));
4887 SYSCTL_ADD_T4_REG64(pi, "rx_mcast_frames", "# of multicast frames",
4888 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MCAST_L));
4889 SYSCTL_ADD_T4_REG64(pi, "rx_ucast_frames", "# of unicast frames",
4890 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_UCAST_L));
4891 SYSCTL_ADD_T4_REG64(pi, "rx_too_long", "# of frames exceeding MTU",
4892 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_ERROR_L));
4893 SYSCTL_ADD_T4_REG64(pi, "rx_jabber", "# of jabber frames",
4894 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_CRC_ERROR_L));
4895 SYSCTL_ADD_T4_REG64(pi, "rx_fcs_err",
4896 "# of frames received with bad FCS",
4897 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_CRC_ERROR_L));
4898 SYSCTL_ADD_T4_REG64(pi, "rx_len_err",
4899 "# of frames received with length error",
4900 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LEN_ERROR_L));
4901 SYSCTL_ADD_T4_REG64(pi, "rx_symbol_err", "symbol errors",
4902 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_SYM_ERROR_L));
4903 SYSCTL_ADD_T4_REG64(pi, "rx_runt", "# of short frames received",
4904 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LESS_64B_L));
4905 SYSCTL_ADD_T4_REG64(pi, "rx_frames_64",
4906 "# of rx frames in this range",
4907 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_64B_L));
4908 SYSCTL_ADD_T4_REG64(pi, "rx_frames_65_127",
4909 "# of rx frames in this range",
4910 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_65B_127B_L));
4911 SYSCTL_ADD_T4_REG64(pi, "rx_frames_128_255",
4912 "# of rx frames in this range",
4913 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_128B_255B_L));
4914 SYSCTL_ADD_T4_REG64(pi, "rx_frames_256_511",
4915 "# of rx frames in this range",
4916 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_256B_511B_L));
4917 SYSCTL_ADD_T4_REG64(pi, "rx_frames_512_1023",
4918 "# of rx frames in this range",
4919 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_512B_1023B_L));
4920 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1024_1518",
4921 "# of rx frames in this range",
4922 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1024B_1518B_L));
4923 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1519_max",
4924 "# of rx frames in this range",
4925 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1519B_MAX_L));
4926 SYSCTL_ADD_T4_REG64(pi, "rx_pause", "# of pause frames received",
4927 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PAUSE_L));
4928 SYSCTL_ADD_T4_REG64(pi, "rx_ppp0", "# of PPP prio 0 frames received",
4929 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP0_L));
4930 SYSCTL_ADD_T4_REG64(pi, "rx_ppp1", "# of PPP prio 1 frames received",
4931 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP1_L));
4932 SYSCTL_ADD_T4_REG64(pi, "rx_ppp2", "# of PPP prio 2 frames received",
4933 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP2_L));
4934 SYSCTL_ADD_T4_REG64(pi, "rx_ppp3", "# of PPP prio 3 frames received",
4935 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP3_L));
4936 SYSCTL_ADD_T4_REG64(pi, "rx_ppp4", "# of PPP prio 4 frames received",
4937 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP4_L));
4938 SYSCTL_ADD_T4_REG64(pi, "rx_ppp5", "# of PPP prio 5 frames received",
4939 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP5_L));
4940 SYSCTL_ADD_T4_REG64(pi, "rx_ppp6", "# of PPP prio 6 frames received",
4941 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP6_L));
4942 SYSCTL_ADD_T4_REG64(pi, "rx_ppp7", "# of PPP prio 7 frames received",
4943 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP7_L));
4945 #undef SYSCTL_ADD_T4_REG64
4947 #define SYSCTL_ADD_T4_PORTSTAT(name, desc) \
4948 SYSCTL_ADD_UQUAD(ctx, children, OID_AUTO, #name, CTLFLAG_RD, \
4949 &pi->stats.name, desc)
4951 /* We get these from port_stats and they may be stale by upto 1s */
4952 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow0,
4953 "# drops due to buffer-group 0 overflows");
4954 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow1,
4955 "# drops due to buffer-group 1 overflows");
4956 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow2,
4957 "# drops due to buffer-group 2 overflows");
4958 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow3,
4959 "# drops due to buffer-group 3 overflows");
4960 SYSCTL_ADD_T4_PORTSTAT(rx_trunc0,
4961 "# of buffer-group 0 truncated packets");
4962 SYSCTL_ADD_T4_PORTSTAT(rx_trunc1,
4963 "# of buffer-group 1 truncated packets");
4964 SYSCTL_ADD_T4_PORTSTAT(rx_trunc2,
4965 "# of buffer-group 2 truncated packets");
4966 SYSCTL_ADD_T4_PORTSTAT(rx_trunc3,
4967 "# of buffer-group 3 truncated packets");
4969 #undef SYSCTL_ADD_T4_PORTSTAT
4975 sysctl_int_array(SYSCTL_HANDLER_ARGS)
4977 int rc, *i, space = 0;
4980 sbuf_new(&sb, NULL, 32, SBUF_AUTOEXTEND);
4981 for (i = arg1; arg2; arg2 -= sizeof(int), i++) {
4983 sbuf_printf(&sb, " ");
4984 sbuf_printf(&sb, "%d", *i);
4988 rc = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
4994 sysctl_bitfield(SYSCTL_HANDLER_ARGS)
4999 rc = sysctl_wire_old_buffer(req, 0);
5003 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
5007 sbuf_printf(sb, "%b", (int)arg2, (char *)arg1);
5008 rc = sbuf_finish(sb);
5015 sysctl_btphy(SYSCTL_HANDLER_ARGS)
5017 struct port_info *pi = arg1;
5019 struct adapter *sc = pi->adapter;
5023 rc = begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4btt");
5026 /* XXX: magic numbers */
5027 rc = -t4_mdio_rd(sc, sc->mbox, pi->mdio_addr, 0x1e, op ? 0x20 : 0xc820,
5029 end_synchronized_op(sc, 0);
5035 rc = sysctl_handle_int(oidp, &v, 0, req);
5040 sysctl_noflowq(SYSCTL_HANDLER_ARGS)
5042 struct port_info *pi = arg1;
5045 val = pi->rsrv_noflowq;
5046 rc = sysctl_handle_int(oidp, &val, 0, req);
5047 if (rc != 0 || req->newptr == NULL)
5050 if ((val >= 1) && (pi->ntxq > 1))
5051 pi->rsrv_noflowq = 1;
5053 pi->rsrv_noflowq = 0;
5059 sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS)
5061 struct port_info *pi = arg1;
5062 struct adapter *sc = pi->adapter;
5064 struct sge_rxq *rxq;
5066 struct sge_ofld_rxq *ofld_rxq;
5072 rc = sysctl_handle_int(oidp, &idx, 0, req);
5073 if (rc != 0 || req->newptr == NULL)
5076 if (idx < 0 || idx >= SGE_NTIMERS)
5079 rc = begin_synchronized_op(sc, pi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5084 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(pi->pktc_idx != -1);
5085 for_each_rxq(pi, i, rxq) {
5086 #ifdef atomic_store_rel_8
5087 atomic_store_rel_8(&rxq->iq.intr_params, v);
5089 rxq->iq.intr_params = v;
5093 for_each_ofld_rxq(pi, i, ofld_rxq) {
5094 #ifdef atomic_store_rel_8
5095 atomic_store_rel_8(&ofld_rxq->iq.intr_params, v);
5097 ofld_rxq->iq.intr_params = v;
5103 end_synchronized_op(sc, LOCK_HELD);
5108 sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS)
5110 struct port_info *pi = arg1;
5111 struct adapter *sc = pi->adapter;
5116 rc = sysctl_handle_int(oidp, &idx, 0, req);
5117 if (rc != 0 || req->newptr == NULL)
5120 if (idx < -1 || idx >= SGE_NCOUNTERS)
5123 rc = begin_synchronized_op(sc, pi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5128 if (pi->flags & PORT_INIT_DONE)
5129 rc = EBUSY; /* cannot be changed once the queues are created */
5133 end_synchronized_op(sc, LOCK_HELD);
5138 sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS)
5140 struct port_info *pi = arg1;
5141 struct adapter *sc = pi->adapter;
5144 qsize = pi->qsize_rxq;
5146 rc = sysctl_handle_int(oidp, &qsize, 0, req);
5147 if (rc != 0 || req->newptr == NULL)
5150 if (qsize < 128 || (qsize & 7))
5153 rc = begin_synchronized_op(sc, pi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5158 if (pi->flags & PORT_INIT_DONE)
5159 rc = EBUSY; /* cannot be changed once the queues are created */
5161 pi->qsize_rxq = qsize;
5163 end_synchronized_op(sc, LOCK_HELD);
5168 sysctl_qsize_txq(SYSCTL_HANDLER_ARGS)
5170 struct port_info *pi = arg1;
5171 struct adapter *sc = pi->adapter;
5174 qsize = pi->qsize_txq;
5176 rc = sysctl_handle_int(oidp, &qsize, 0, req);
5177 if (rc != 0 || req->newptr == NULL)
5180 /* bufring size must be powerof2 */
5181 if (qsize < 128 || !powerof2(qsize))
5184 rc = begin_synchronized_op(sc, pi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5189 if (pi->flags & PORT_INIT_DONE)
5190 rc = EBUSY; /* cannot be changed once the queues are created */
5192 pi->qsize_txq = qsize;
5194 end_synchronized_op(sc, LOCK_HELD);
5199 sysctl_pause_settings(SYSCTL_HANDLER_ARGS)
5201 struct port_info *pi = arg1;
5202 struct adapter *sc = pi->adapter;
5203 struct link_config *lc = &pi->link_cfg;
5206 if (req->newptr == NULL) {
5208 static char *bits = "\20\1PAUSE_RX\2PAUSE_TX";
5210 rc = sysctl_wire_old_buffer(req, 0);
5214 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
5218 sbuf_printf(sb, "%b", lc->fc & (PAUSE_TX | PAUSE_RX), bits);
5219 rc = sbuf_finish(sb);
5225 s[0] = '0' + (lc->requested_fc & (PAUSE_TX | PAUSE_RX));
5228 rc = sysctl_handle_string(oidp, s, sizeof(s), req);
5234 if (s[0] < '0' || s[0] > '9')
5235 return (EINVAL); /* not a number */
5237 if (n & ~(PAUSE_TX | PAUSE_RX))
5238 return (EINVAL); /* some other bit is set too */
5240 rc = begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4PAUSE");
5243 if ((lc->requested_fc & (PAUSE_TX | PAUSE_RX)) != n) {
5244 int link_ok = lc->link_ok;
5246 lc->requested_fc &= ~(PAUSE_TX | PAUSE_RX);
5247 lc->requested_fc |= n;
5248 rc = -t4_link_start(sc, sc->mbox, pi->tx_chan, lc);
5249 lc->link_ok = link_ok; /* restore */
5251 end_synchronized_op(sc, 0);
5258 sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS)
5260 struct adapter *sc = arg1;
5264 val = t4_read_reg64(sc, reg);
5266 return (sysctl_handle_64(oidp, &val, 0, req));
5270 sysctl_temperature(SYSCTL_HANDLER_ARGS)
5272 struct adapter *sc = arg1;
5274 uint32_t param, val;
5276 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4temp");
5279 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
5280 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) |
5281 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_TMP);
5282 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
5283 end_synchronized_op(sc, 0);
5287 /* unknown is returned as 0 but we display -1 in that case */
5288 t = val == 0 ? -1 : val;
5290 rc = sysctl_handle_int(oidp, &t, 0, req);
5296 sysctl_cctrl(SYSCTL_HANDLER_ARGS)
5298 struct adapter *sc = arg1;
5301 uint16_t incr[NMTUS][NCCTRL_WIN];
5302 static const char *dec_fac[] = {
5303 "0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
5307 rc = sysctl_wire_old_buffer(req, 0);
5311 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
5315 t4_read_cong_tbl(sc, incr);
5317 for (i = 0; i < NCCTRL_WIN; ++i) {
5318 sbuf_printf(sb, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
5319 incr[0][i], incr[1][i], incr[2][i], incr[3][i], incr[4][i],
5320 incr[5][i], incr[6][i], incr[7][i]);
5321 sbuf_printf(sb, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
5322 incr[8][i], incr[9][i], incr[10][i], incr[11][i],
5323 incr[12][i], incr[13][i], incr[14][i], incr[15][i],
5324 sc->params.a_wnd[i], dec_fac[sc->params.b_wnd[i]]);
5327 rc = sbuf_finish(sb);
5333 static const char *qname[CIM_NUM_IBQ + CIM_NUM_OBQ_T5] = {
5334 "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI", /* ibq's */
5335 "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI", /* obq's */
5336 "SGE0-RX", "SGE1-RX" /* additional obq's (T5 onwards) */
5340 sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS)
5342 struct adapter *sc = arg1;
5344 int rc, i, n, qid = arg2;
5347 u_int cim_num_obq = is_t4(sc) ? CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
5349 KASSERT(qid >= 0 && qid < CIM_NUM_IBQ + cim_num_obq,
5350 ("%s: bad qid %d\n", __func__, qid));
5352 if (qid < CIM_NUM_IBQ) {
5355 n = 4 * CIM_IBQ_SIZE;
5356 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
5357 rc = t4_read_cim_ibq(sc, qid, buf, n);
5359 /* outbound queue */
5362 n = 4 * cim_num_obq * CIM_OBQ_SIZE;
5363 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
5364 rc = t4_read_cim_obq(sc, qid, buf, n);
5371 n = rc * sizeof(uint32_t); /* rc has # of words actually read */
5373 rc = sysctl_wire_old_buffer(req, 0);
5377 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
5383 sbuf_printf(sb, "%s%d %s", qtype , qid, qname[arg2]);
5384 for (i = 0, p = buf; i < n; i += 16, p += 4)
5385 sbuf_printf(sb, "\n%#06x: %08x %08x %08x %08x", i, p[0], p[1],
5388 rc = sbuf_finish(sb);
5396 sysctl_cim_la(SYSCTL_HANDLER_ARGS)
5398 struct adapter *sc = arg1;
5404 rc = -t4_cim_read(sc, A_UP_UP_DBG_LA_CFG, 1, &cfg);
5408 rc = sysctl_wire_old_buffer(req, 0);
5412 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
5416 buf = malloc(sc->params.cim_la_size * sizeof(uint32_t), M_CXGBE,
5419 rc = -t4_cim_read_la(sc, buf, NULL);
5423 sbuf_printf(sb, "Status Data PC%s",
5424 cfg & F_UPDBGLACAPTPCONLY ? "" :
5425 " LS0Stat LS0Addr LS0Data");
5427 KASSERT((sc->params.cim_la_size & 7) == 0,
5428 ("%s: p will walk off the end of buf", __func__));
5430 for (p = buf; p < &buf[sc->params.cim_la_size]; p += 8) {
5431 if (cfg & F_UPDBGLACAPTPCONLY) {
5432 sbuf_printf(sb, "\n %02x %08x %08x", p[5] & 0xff,
5434 sbuf_printf(sb, "\n %02x %02x%06x %02x%06x",
5435 (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8,
5436 p[4] & 0xff, p[5] >> 8);
5437 sbuf_printf(sb, "\n %02x %x%07x %x%07x",
5438 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
5439 p[1] & 0xf, p[2] >> 4);
5442 "\n %02x %x%07x %x%07x %08x %08x "
5444 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
5445 p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5],
5450 rc = sbuf_finish(sb);
5458 sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS)
5460 struct adapter *sc = arg1;
5466 rc = sysctl_wire_old_buffer(req, 0);
5470 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
5474 buf = malloc(2 * CIM_MALA_SIZE * 5 * sizeof(uint32_t), M_CXGBE,
5477 t4_cim_read_ma_la(sc, buf, buf + 5 * CIM_MALA_SIZE);
5480 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
5481 sbuf_printf(sb, "\n%02x%08x%08x%08x%08x", p[4], p[3], p[2],
5485 sbuf_printf(sb, "\n\nCnt ID Tag UE Data RDY VLD");
5486 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
5487 sbuf_printf(sb, "\n%3u %2u %x %u %08x%08x %u %u",
5488 (p[2] >> 10) & 0xff, (p[2] >> 7) & 7,
5489 (p[2] >> 3) & 0xf, (p[2] >> 2) & 1,
5490 (p[1] >> 2) | ((p[2] & 3) << 30),
5491 (p[0] >> 2) | ((p[1] & 3) << 30), (p[0] >> 1) & 1,
5495 rc = sbuf_finish(sb);
5502 sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS)
5504 struct adapter *sc = arg1;
5510 rc = sysctl_wire_old_buffer(req, 0);
5514 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
5518 buf = malloc(2 * CIM_PIFLA_SIZE * 6 * sizeof(uint32_t), M_CXGBE,
5521 t4_cim_read_pif_la(sc, buf, buf + 6 * CIM_PIFLA_SIZE, NULL, NULL);
5524 sbuf_printf(sb, "Cntl ID DataBE Addr Data");
5525 for (i = 0; i < CIM_MALA_SIZE; i++, p += 6) {
5526 sbuf_printf(sb, "\n %02x %02x %04x %08x %08x%08x%08x%08x",
5527 (p[5] >> 22) & 0xff, (p[5] >> 16) & 0x3f, p[5] & 0xffff,
5528 p[4], p[3], p[2], p[1], p[0]);
5531 sbuf_printf(sb, "\n\nCntl ID Data");
5532 for (i = 0; i < CIM_MALA_SIZE; i++, p += 6) {
5533 sbuf_printf(sb, "\n %02x %02x %08x%08x%08x%08x",
5534 (p[4] >> 6) & 0xff, p[4] & 0x3f, p[3], p[2], p[1], p[0]);
5537 rc = sbuf_finish(sb);
5544 sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS)
5546 struct adapter *sc = arg1;
5549 uint16_t base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
5550 uint16_t size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
5551 uint16_t thres[CIM_NUM_IBQ];
5552 uint32_t obq_wr[2 * CIM_NUM_OBQ_T5], *wr = obq_wr;
5553 uint32_t stat[4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5)], *p = stat;
5554 u_int cim_num_obq, ibq_rdaddr, obq_rdaddr, nq;
5557 cim_num_obq = CIM_NUM_OBQ;
5558 ibq_rdaddr = A_UP_IBQ_0_RDADDR;
5559 obq_rdaddr = A_UP_OBQ_0_REALADDR;
5561 cim_num_obq = CIM_NUM_OBQ_T5;
5562 ibq_rdaddr = A_UP_IBQ_0_SHADOW_RDADDR;
5563 obq_rdaddr = A_UP_OBQ_0_SHADOW_REALADDR;
5565 nq = CIM_NUM_IBQ + cim_num_obq;
5567 rc = -t4_cim_read(sc, ibq_rdaddr, 4 * nq, stat);
5569 rc = -t4_cim_read(sc, obq_rdaddr, 2 * cim_num_obq, obq_wr);
5573 t4_read_cimq_cfg(sc, base, size, thres);
5575 rc = sysctl_wire_old_buffer(req, 0);
5579 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
5583 sbuf_printf(sb, "Queue Base Size Thres RdPtr WrPtr SOP EOP Avail");
5585 for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
5586 sbuf_printf(sb, "\n%7s %5x %5u %5u %6x %4x %4u %4u %5u",
5587 qname[i], base[i], size[i], thres[i], G_IBQRDADDR(p[0]),
5588 G_IBQWRADDR(p[1]), G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
5589 G_QUEREMFLITS(p[2]) * 16);
5590 for ( ; i < nq; i++, p += 4, wr += 2)
5591 sbuf_printf(sb, "\n%7s %5x %5u %12x %4x %4u %4u %5u", qname[i],
5592 base[i], size[i], G_QUERDADDR(p[0]) & 0x3fff,
5593 wr[0] - base[i], G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
5594 G_QUEREMFLITS(p[2]) * 16);
5596 rc = sbuf_finish(sb);
5603 sysctl_cpl_stats(SYSCTL_HANDLER_ARGS)
5605 struct adapter *sc = arg1;
5608 struct tp_cpl_stats stats;
5610 rc = sysctl_wire_old_buffer(req, 0);
5614 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
5618 t4_tp_get_cpl_stats(sc, &stats);
5620 sbuf_printf(sb, " channel 0 channel 1 channel 2 "
5622 sbuf_printf(sb, "CPL requests: %10u %10u %10u %10u\n",
5623 stats.req[0], stats.req[1], stats.req[2], stats.req[3]);
5624 sbuf_printf(sb, "CPL responses: %10u %10u %10u %10u",
5625 stats.rsp[0], stats.rsp[1], stats.rsp[2], stats.rsp[3]);
5627 rc = sbuf_finish(sb);
5634 sysctl_ddp_stats(SYSCTL_HANDLER_ARGS)
5636 struct adapter *sc = arg1;
5639 struct tp_usm_stats stats;
5641 rc = sysctl_wire_old_buffer(req, 0);
5645 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
5649 t4_get_usm_stats(sc, &stats);
5651 sbuf_printf(sb, "Frames: %u\n", stats.frames);
5652 sbuf_printf(sb, "Octets: %ju\n", stats.octets);
5653 sbuf_printf(sb, "Drops: %u", stats.drops);
5655 rc = sbuf_finish(sb);
5661 const char *devlog_level_strings[] = {
5662 [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
5663 [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
5664 [FW_DEVLOG_LEVEL_ERR] = "ERR",
5665 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
5666 [FW_DEVLOG_LEVEL_INFO] = "INFO",
5667 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
5670 const char *devlog_facility_strings[] = {
5671 [FW_DEVLOG_FACILITY_CORE] = "CORE",
5672 [FW_DEVLOG_FACILITY_CF] = "CF",
5673 [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
5674 [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
5675 [FW_DEVLOG_FACILITY_RES] = "RES",
5676 [FW_DEVLOG_FACILITY_HW] = "HW",
5677 [FW_DEVLOG_FACILITY_FLR] = "FLR",
5678 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
5679 [FW_DEVLOG_FACILITY_PHY] = "PHY",
5680 [FW_DEVLOG_FACILITY_MAC] = "MAC",
5681 [FW_DEVLOG_FACILITY_PORT] = "PORT",
5682 [FW_DEVLOG_FACILITY_VI] = "VI",
5683 [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
5684 [FW_DEVLOG_FACILITY_ACL] = "ACL",
5685 [FW_DEVLOG_FACILITY_TM] = "TM",
5686 [FW_DEVLOG_FACILITY_QFC] = "QFC",
5687 [FW_DEVLOG_FACILITY_DCB] = "DCB",
5688 [FW_DEVLOG_FACILITY_ETH] = "ETH",
5689 [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
5690 [FW_DEVLOG_FACILITY_RI] = "RI",
5691 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
5692 [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
5693 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
5694 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE"
5698 sysctl_devlog(SYSCTL_HANDLER_ARGS)
5700 struct adapter *sc = arg1;
5701 struct devlog_params *dparams = &sc->params.devlog;
5702 struct fw_devlog_e *buf, *e;
5703 int i, j, rc, nentries, first = 0, m;
5705 uint64_t ftstamp = UINT64_MAX;
5707 if (dparams->start == 0) {
5708 dparams->memtype = FW_MEMTYPE_EDC0;
5709 dparams->start = 0x84000;
5710 dparams->size = 32768;
5713 nentries = dparams->size / sizeof(struct fw_devlog_e);
5715 buf = malloc(dparams->size, M_CXGBE, M_NOWAIT);
5719 m = fwmtype_to_hwmtype(dparams->memtype);
5720 rc = -t4_mem_read(sc, m, dparams->start, dparams->size, (void *)buf);
5724 for (i = 0; i < nentries; i++) {
5727 if (e->timestamp == 0)
5730 e->timestamp = be64toh(e->timestamp);
5731 e->seqno = be32toh(e->seqno);
5732 for (j = 0; j < 8; j++)
5733 e->params[j] = be32toh(e->params[j]);
5735 if (e->timestamp < ftstamp) {
5736 ftstamp = e->timestamp;
5741 if (buf[first].timestamp == 0)
5742 goto done; /* nothing in the log */
5744 rc = sysctl_wire_old_buffer(req, 0);
5748 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
5753 sbuf_printf(sb, "%10s %15s %8s %8s %s\n",
5754 "Seq#", "Tstamp", "Level", "Facility", "Message");
5759 if (e->timestamp == 0)
5762 sbuf_printf(sb, "%10d %15ju %8s %8s ",
5763 e->seqno, e->timestamp,
5764 (e->level < nitems(devlog_level_strings) ?
5765 devlog_level_strings[e->level] : "UNKNOWN"),
5766 (e->facility < nitems(devlog_facility_strings) ?
5767 devlog_facility_strings[e->facility] : "UNKNOWN"));
5768 sbuf_printf(sb, e->fmt, e->params[0], e->params[1],
5769 e->params[2], e->params[3], e->params[4],
5770 e->params[5], e->params[6], e->params[7]);
5772 if (++i == nentries)
5774 } while (i != first);
5776 rc = sbuf_finish(sb);
5784 sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS)
5786 struct adapter *sc = arg1;
5789 struct tp_fcoe_stats stats[4];
5791 rc = sysctl_wire_old_buffer(req, 0);
5795 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
5799 t4_get_fcoe_stats(sc, 0, &stats[0]);
5800 t4_get_fcoe_stats(sc, 1, &stats[1]);
5801 t4_get_fcoe_stats(sc, 2, &stats[2]);
5802 t4_get_fcoe_stats(sc, 3, &stats[3]);
5804 sbuf_printf(sb, " channel 0 channel 1 "
5805 "channel 2 channel 3\n");
5806 sbuf_printf(sb, "octetsDDP: %16ju %16ju %16ju %16ju\n",
5807 stats[0].octetsDDP, stats[1].octetsDDP, stats[2].octetsDDP,
5808 stats[3].octetsDDP);
5809 sbuf_printf(sb, "framesDDP: %16u %16u %16u %16u\n", stats[0].framesDDP,
5810 stats[1].framesDDP, stats[2].framesDDP, stats[3].framesDDP);
5811 sbuf_printf(sb, "framesDrop: %16u %16u %16u %16u",
5812 stats[0].framesDrop, stats[1].framesDrop, stats[2].framesDrop,
5813 stats[3].framesDrop);
5815 rc = sbuf_finish(sb);
5822 sysctl_hw_sched(SYSCTL_HANDLER_ARGS)
5824 struct adapter *sc = arg1;
5827 unsigned int map, kbps, ipg, mode;
5828 unsigned int pace_tab[NTX_SCHED];
5830 rc = sysctl_wire_old_buffer(req, 0);
5834 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
5838 map = t4_read_reg(sc, A_TP_TX_MOD_QUEUE_REQ_MAP);
5839 mode = G_TIMERMODE(t4_read_reg(sc, A_TP_MOD_CONFIG));
5840 t4_read_pace_tbl(sc, pace_tab);
5842 sbuf_printf(sb, "Scheduler Mode Channel Rate (Kbps) "
5843 "Class IPG (0.1 ns) Flow IPG (us)");
5845 for (i = 0; i < NTX_SCHED; ++i, map >>= 2) {
5846 t4_get_tx_sched(sc, i, &kbps, &ipg);
5847 sbuf_printf(sb, "\n %u %-5s %u ", i,
5848 (mode & (1 << i)) ? "flow" : "class", map & 3);
5850 sbuf_printf(sb, "%9u ", kbps);
5852 sbuf_printf(sb, " disabled ");
5855 sbuf_printf(sb, "%13u ", ipg);
5857 sbuf_printf(sb, " disabled ");
5860 sbuf_printf(sb, "%10u", pace_tab[i]);
5862 sbuf_printf(sb, " disabled");
5865 rc = sbuf_finish(sb);
5872 sysctl_lb_stats(SYSCTL_HANDLER_ARGS)
5874 struct adapter *sc = arg1;
5878 struct lb_port_stats s[2];
5879 static const char *stat_name[] = {
5880 "OctetsOK:", "FramesOK:", "BcastFrames:", "McastFrames:",
5881 "UcastFrames:", "ErrorFrames:", "Frames64:", "Frames65To127:",
5882 "Frames128To255:", "Frames256To511:", "Frames512To1023:",
5883 "Frames1024To1518:", "Frames1519ToMax:", "FramesDropped:",
5884 "BG0FramesDropped:", "BG1FramesDropped:", "BG2FramesDropped:",
5885 "BG3FramesDropped:", "BG0FramesTrunc:", "BG1FramesTrunc:",
5886 "BG2FramesTrunc:", "BG3FramesTrunc:"
5889 rc = sysctl_wire_old_buffer(req, 0);
5893 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
5897 memset(s, 0, sizeof(s));
5899 for (i = 0; i < 4; i += 2) {
5900 t4_get_lb_stats(sc, i, &s[0]);
5901 t4_get_lb_stats(sc, i + 1, &s[1]);
5905 sbuf_printf(sb, "%s Loopback %u"
5906 " Loopback %u", i == 0 ? "" : "\n", i, i + 1);
5908 for (j = 0; j < nitems(stat_name); j++)
5909 sbuf_printf(sb, "\n%-17s %20ju %20ju", stat_name[j],
5913 rc = sbuf_finish(sb);
5920 sysctl_linkdnrc(SYSCTL_HANDLER_ARGS)
5923 struct port_info *pi = arg1;
5925 static const char *linkdnreasons[] = {
5926 "non-specific", "remote fault", "autoneg failed", "reserved3",
5927 "PHY overheated", "unknown", "rx los", "reserved7"
5930 rc = sysctl_wire_old_buffer(req, 0);
5933 sb = sbuf_new_for_sysctl(NULL, NULL, 64, req);
5937 if (pi->linkdnrc < 0)
5938 sbuf_printf(sb, "n/a");
5939 else if (pi->linkdnrc < nitems(linkdnreasons))
5940 sbuf_printf(sb, "%s", linkdnreasons[pi->linkdnrc]);
5942 sbuf_printf(sb, "%d", pi->linkdnrc);
5944 rc = sbuf_finish(sb);
5957 mem_desc_cmp(const void *a, const void *b)
5959 return ((const struct mem_desc *)a)->base -
5960 ((const struct mem_desc *)b)->base;
5964 mem_region_show(struct sbuf *sb, const char *name, unsigned int from,
5969 size = to - from + 1;
5973 /* XXX: need humanize_number(3) in libkern for a more readable 'size' */
5974 sbuf_printf(sb, "%-15s %#x-%#x [%u]\n", name, from, to, size);
5978 sysctl_meminfo(SYSCTL_HANDLER_ARGS)
5980 struct adapter *sc = arg1;
5983 uint32_t lo, hi, used, alloc;
5984 static const char *memory[] = {"EDC0:", "EDC1:", "MC:", "MC0:", "MC1:"};
5985 static const char *region[] = {
5986 "DBQ contexts:", "IMSG contexts:", "FLM cache:", "TCBs:",
5987 "Pstructs:", "Timers:", "Rx FL:", "Tx FL:", "Pstruct FL:",
5988 "Tx payload:", "Rx payload:", "LE hash:", "iSCSI region:",
5989 "TDDP region:", "TPT region:", "STAG region:", "RQ region:",
5990 "RQUDP region:", "PBL region:", "TXPBL region:",
5991 "DBVFIFO region:", "ULPRX state:", "ULPTX state:",
5994 struct mem_desc avail[4];
5995 struct mem_desc mem[nitems(region) + 3]; /* up to 3 holes */
5996 struct mem_desc *md = mem;
5998 rc = sysctl_wire_old_buffer(req, 0);
6002 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6006 for (i = 0; i < nitems(mem); i++) {
6011 /* Find and sort the populated memory ranges */
6013 lo = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
6014 if (lo & F_EDRAM0_ENABLE) {
6015 hi = t4_read_reg(sc, A_MA_EDRAM0_BAR);
6016 avail[i].base = G_EDRAM0_BASE(hi) << 20;
6017 avail[i].limit = avail[i].base + (G_EDRAM0_SIZE(hi) << 20);
6021 if (lo & F_EDRAM1_ENABLE) {
6022 hi = t4_read_reg(sc, A_MA_EDRAM1_BAR);
6023 avail[i].base = G_EDRAM1_BASE(hi) << 20;
6024 avail[i].limit = avail[i].base + (G_EDRAM1_SIZE(hi) << 20);
6028 if (lo & F_EXT_MEM_ENABLE) {
6029 hi = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
6030 avail[i].base = G_EXT_MEM_BASE(hi) << 20;
6031 avail[i].limit = avail[i].base +
6032 (G_EXT_MEM_SIZE(hi) << 20);
6033 avail[i].idx = is_t4(sc) ? 2 : 3; /* Call it MC for T4 */
6036 if (!is_t4(sc) && lo & F_EXT_MEM1_ENABLE) {
6037 hi = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
6038 avail[i].base = G_EXT_MEM1_BASE(hi) << 20;
6039 avail[i].limit = avail[i].base +
6040 (G_EXT_MEM1_SIZE(hi) << 20);
6044 if (!i) /* no memory available */
6046 qsort(avail, i, sizeof(struct mem_desc), mem_desc_cmp);
6048 (md++)->base = t4_read_reg(sc, A_SGE_DBQ_CTXT_BADDR);
6049 (md++)->base = t4_read_reg(sc, A_SGE_IMSG_CTXT_BADDR);
6050 (md++)->base = t4_read_reg(sc, A_SGE_FLM_CACHE_BADDR);
6051 (md++)->base = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
6052 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_BASE);
6053 (md++)->base = t4_read_reg(sc, A_TP_CMM_TIMER_BASE);
6054 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_RX_FLST_BASE);
6055 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_TX_FLST_BASE);
6056 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_PS_FLST_BASE);
6058 /* the next few have explicit upper bounds */
6059 md->base = t4_read_reg(sc, A_TP_PMM_TX_BASE);
6060 md->limit = md->base - 1 +
6061 t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE) *
6062 G_PMTXMAXPAGE(t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE));
6065 md->base = t4_read_reg(sc, A_TP_PMM_RX_BASE);
6066 md->limit = md->base - 1 +
6067 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) *
6068 G_PMRXMAXPAGE(t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE));
6071 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
6072 hi = t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4;
6073 md->base = t4_read_reg(sc, A_LE_DB_HASH_TID_BASE);
6074 md->limit = (sc->tids.ntids - hi) * 16 + md->base - 1;
6077 md->idx = nitems(region); /* hide it */
6081 #define ulp_region(reg) \
6082 md->base = t4_read_reg(sc, A_ULP_ ## reg ## _LLIMIT);\
6083 (md++)->limit = t4_read_reg(sc, A_ULP_ ## reg ## _ULIMIT)
6085 ulp_region(RX_ISCSI);
6086 ulp_region(RX_TDDP);
6088 ulp_region(RX_STAG);
6090 ulp_region(RX_RQUDP);
6096 md->idx = nitems(region);
6097 if (!is_t4(sc) && t4_read_reg(sc, A_SGE_CONTROL2) & F_VFIFO_ENABLE) {
6098 md->base = G_BASEADDR(t4_read_reg(sc, A_SGE_DBVFIFO_BADDR));
6099 md->limit = md->base + (G_DBVFIFO_SIZE((t4_read_reg(sc,
6100 A_SGE_DBVFIFO_SIZE))) << 2) - 1;
6104 md->base = t4_read_reg(sc, A_ULP_RX_CTX_BASE);
6105 md->limit = md->base + sc->tids.ntids - 1;
6107 md->base = t4_read_reg(sc, A_ULP_TX_ERR_TABLE_BASE);
6108 md->limit = md->base + sc->tids.ntids - 1;
6111 md->base = sc->vres.ocq.start;
6112 if (sc->vres.ocq.size)
6113 md->limit = md->base + sc->vres.ocq.size - 1;
6115 md->idx = nitems(region); /* hide it */
6118 /* add any address-space holes, there can be up to 3 */
6119 for (n = 0; n < i - 1; n++)
6120 if (avail[n].limit < avail[n + 1].base)
6121 (md++)->base = avail[n].limit;
6123 (md++)->base = avail[n].limit;
6126 qsort(mem, n, sizeof(struct mem_desc), mem_desc_cmp);
6128 for (lo = 0; lo < i; lo++)
6129 mem_region_show(sb, memory[avail[lo].idx], avail[lo].base,
6130 avail[lo].limit - 1);
6132 sbuf_printf(sb, "\n");
6133 for (i = 0; i < n; i++) {
6134 if (mem[i].idx >= nitems(region))
6135 continue; /* skip holes */
6137 mem[i].limit = i < n - 1 ? mem[i + 1].base - 1 : ~0;
6138 mem_region_show(sb, region[mem[i].idx], mem[i].base,
6142 sbuf_printf(sb, "\n");
6143 lo = t4_read_reg(sc, A_CIM_SDRAM_BASE_ADDR);
6144 hi = t4_read_reg(sc, A_CIM_SDRAM_ADDR_SIZE) + lo - 1;
6145 mem_region_show(sb, "uP RAM:", lo, hi);
6147 lo = t4_read_reg(sc, A_CIM_EXTMEM2_BASE_ADDR);
6148 hi = t4_read_reg(sc, A_CIM_EXTMEM2_ADDR_SIZE) + lo - 1;
6149 mem_region_show(sb, "uP Extmem2:", lo, hi);
6151 lo = t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE);
6152 sbuf_printf(sb, "\n%u Rx pages of size %uKiB for %u channels\n",
6154 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) >> 10,
6155 (lo & F_PMRXNUMCHN) ? 2 : 1);
6157 lo = t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE);
6158 hi = t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE);
6159 sbuf_printf(sb, "%u Tx pages of size %u%ciB for %u channels\n",
6161 hi >= (1 << 20) ? (hi >> 20) : (hi >> 10),
6162 hi >= (1 << 20) ? 'M' : 'K', 1 << G_PMTXNUMCHN(lo));
6163 sbuf_printf(sb, "%u p-structs\n",
6164 t4_read_reg(sc, A_TP_CMM_MM_MAX_PSTRUCT));
6166 for (i = 0; i < 4; i++) {
6167 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV0 + i * 4);
6170 alloc = G_ALLOC(lo);
6172 used = G_T5_USED(lo);
6173 alloc = G_T5_ALLOC(lo);
6175 sbuf_printf(sb, "\nPort %d using %u pages out of %u allocated",
6178 for (i = 0; i < 4; i++) {
6179 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV4 + i * 4);
6182 alloc = G_ALLOC(lo);
6184 used = G_T5_USED(lo);
6185 alloc = G_T5_ALLOC(lo);
6188 "\nLoopback %d using %u pages out of %u allocated",
6192 rc = sbuf_finish(sb);
6199 tcamxy2valmask(uint64_t x, uint64_t y, uint8_t *addr, uint64_t *mask)
6203 memcpy(addr, (char *)&y + 2, ETHER_ADDR_LEN);
6207 sysctl_mps_tcam(SYSCTL_HANDLER_ARGS)
6209 struct adapter *sc = arg1;
6213 rc = sysctl_wire_old_buffer(req, 0);
6217 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6222 "Idx Ethernet address Mask Vld Ports PF"
6223 " VF Replication P0 P1 P2 P3 ML");
6224 n = is_t4(sc) ? NUM_MPS_CLS_SRAM_L_INSTANCES :
6225 NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
6226 for (i = 0; i < n; i++) {
6227 uint64_t tcamx, tcamy, mask;
6228 uint32_t cls_lo, cls_hi;
6229 uint8_t addr[ETHER_ADDR_LEN];
6231 tcamy = t4_read_reg64(sc, MPS_CLS_TCAM_Y_L(i));
6232 tcamx = t4_read_reg64(sc, MPS_CLS_TCAM_X_L(i));
6233 cls_lo = t4_read_reg(sc, MPS_CLS_SRAM_L(i));
6234 cls_hi = t4_read_reg(sc, MPS_CLS_SRAM_H(i));
6239 tcamxy2valmask(tcamx, tcamy, addr, &mask);
6240 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x %012jx"
6241 " %c %#x%4u%4d", i, addr[0], addr[1], addr[2],
6242 addr[3], addr[4], addr[5], (uintmax_t)mask,
6243 (cls_lo & F_SRAM_VLD) ? 'Y' : 'N',
6244 G_PORTMAP(cls_hi), G_PF(cls_lo),
6245 (cls_lo & F_VF_VALID) ? G_VF(cls_lo) : -1);
6247 if (cls_lo & F_REPLICATE) {
6248 struct fw_ldst_cmd ldst_cmd;
6250 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
6251 ldst_cmd.op_to_addrspace =
6252 htobe32(V_FW_CMD_OP(FW_LDST_CMD) |
6253 F_FW_CMD_REQUEST | F_FW_CMD_READ |
6254 V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MPS));
6255 ldst_cmd.cycles_to_len16 = htobe32(FW_LEN16(ldst_cmd));
6256 ldst_cmd.u.mps.fid_ctl =
6257 htobe16(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) |
6258 V_FW_LDST_CMD_CTL(i));
6260 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK,
6264 rc = -t4_wr_mbox(sc, sc->mbox, &ldst_cmd,
6265 sizeof(ldst_cmd), &ldst_cmd);
6266 end_synchronized_op(sc, 0);
6270 " ------------ error %3u ------------", rc);
6273 sbuf_printf(sb, " %08x %08x %08x %08x",
6274 be32toh(ldst_cmd.u.mps.rplc127_96),
6275 be32toh(ldst_cmd.u.mps.rplc95_64),
6276 be32toh(ldst_cmd.u.mps.rplc63_32),
6277 be32toh(ldst_cmd.u.mps.rplc31_0));
6280 sbuf_printf(sb, "%36s", "");
6282 sbuf_printf(sb, "%4u%3u%3u%3u %#3x", G_SRAM_PRIO0(cls_lo),
6283 G_SRAM_PRIO1(cls_lo), G_SRAM_PRIO2(cls_lo),
6284 G_SRAM_PRIO3(cls_lo), (cls_lo >> S_MULTILISTEN0) & 0xf);
6288 (void) sbuf_finish(sb);
6290 rc = sbuf_finish(sb);
6297 sysctl_path_mtus(SYSCTL_HANDLER_ARGS)
6299 struct adapter *sc = arg1;
6302 uint16_t mtus[NMTUS];
6304 rc = sysctl_wire_old_buffer(req, 0);
6308 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6312 t4_read_mtu_tbl(sc, mtus, NULL);
6314 sbuf_printf(sb, "%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u",
6315 mtus[0], mtus[1], mtus[2], mtus[3], mtus[4], mtus[5], mtus[6],
6316 mtus[7], mtus[8], mtus[9], mtus[10], mtus[11], mtus[12], mtus[13],
6317 mtus[14], mtus[15]);
6319 rc = sbuf_finish(sb);
6326 sysctl_pm_stats(SYSCTL_HANDLER_ARGS)
6328 struct adapter *sc = arg1;
6331 uint32_t cnt[PM_NSTATS];
6332 uint64_t cyc[PM_NSTATS];
6333 static const char *rx_stats[] = {
6334 "Read:", "Write bypass:", "Write mem:", "Flush:"
6336 static const char *tx_stats[] = {
6337 "Read:", "Write bypass:", "Write mem:", "Bypass + mem:"
6340 rc = sysctl_wire_old_buffer(req, 0);
6344 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6348 t4_pmtx_get_stats(sc, cnt, cyc);
6349 sbuf_printf(sb, " Tx pcmds Tx bytes");
6350 for (i = 0; i < ARRAY_SIZE(tx_stats); i++)
6351 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], cnt[i],
6354 t4_pmrx_get_stats(sc, cnt, cyc);
6355 sbuf_printf(sb, "\n Rx pcmds Rx bytes");
6356 for (i = 0; i < ARRAY_SIZE(rx_stats); i++)
6357 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], cnt[i],
6360 rc = sbuf_finish(sb);
6367 sysctl_rdma_stats(SYSCTL_HANDLER_ARGS)
6369 struct adapter *sc = arg1;
6372 struct tp_rdma_stats stats;
6374 rc = sysctl_wire_old_buffer(req, 0);
6378 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6382 t4_tp_get_rdma_stats(sc, &stats);
6383 sbuf_printf(sb, "NoRQEModDefferals: %u\n", stats.rqe_dfr_mod);
6384 sbuf_printf(sb, "NoRQEPktDefferals: %u", stats.rqe_dfr_pkt);
6386 rc = sbuf_finish(sb);
6393 sysctl_tcp_stats(SYSCTL_HANDLER_ARGS)
6395 struct adapter *sc = arg1;
6398 struct tp_tcp_stats v4, v6;
6400 rc = sysctl_wire_old_buffer(req, 0);
6404 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6408 t4_tp_get_tcp_stats(sc, &v4, &v6);
6411 sbuf_printf(sb, "OutRsts: %20u %20u\n",
6412 v4.tcpOutRsts, v6.tcpOutRsts);
6413 sbuf_printf(sb, "InSegs: %20ju %20ju\n",
6414 v4.tcpInSegs, v6.tcpInSegs);
6415 sbuf_printf(sb, "OutSegs: %20ju %20ju\n",
6416 v4.tcpOutSegs, v6.tcpOutSegs);
6417 sbuf_printf(sb, "RetransSegs: %20ju %20ju",
6418 v4.tcpRetransSegs, v6.tcpRetransSegs);
6420 rc = sbuf_finish(sb);
6427 sysctl_tids(SYSCTL_HANDLER_ARGS)
6429 struct adapter *sc = arg1;
6432 struct tid_info *t = &sc->tids;
6434 rc = sysctl_wire_old_buffer(req, 0);
6438 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6443 sbuf_printf(sb, "ATID range: 0-%u, in use: %u\n", t->natids - 1,
6448 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
6449 uint32_t b = t4_read_reg(sc, A_LE_DB_SERVER_INDEX) / 4;
6452 sbuf_printf(sb, "TID range: 0-%u, %u-%u", b - 1,
6453 t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4,
6456 sbuf_printf(sb, "TID range: %u-%u",
6457 t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4,
6461 sbuf_printf(sb, "TID range: 0-%u", t->ntids - 1);
6462 sbuf_printf(sb, ", in use: %u\n",
6463 atomic_load_acq_int(&t->tids_in_use));
6467 sbuf_printf(sb, "STID range: %u-%u, in use: %u\n", t->stid_base,
6468 t->stid_base + t->nstids - 1, t->stids_in_use);
6472 sbuf_printf(sb, "FTID range: %u-%u\n", t->ftid_base,
6473 t->ftid_base + t->nftids - 1);
6477 sbuf_printf(sb, "ETID range: %u-%u\n", t->etid_base,
6478 t->etid_base + t->netids - 1);
6481 sbuf_printf(sb, "HW TID usage: %u IP users, %u IPv6 users",
6482 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV4),
6483 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV6));
6485 rc = sbuf_finish(sb);
6492 sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS)
6494 struct adapter *sc = arg1;
6497 struct tp_err_stats stats;
6499 rc = sysctl_wire_old_buffer(req, 0);
6503 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6507 t4_tp_get_err_stats(sc, &stats);
6509 sbuf_printf(sb, " channel 0 channel 1 channel 2 "
6511 sbuf_printf(sb, "macInErrs: %10u %10u %10u %10u\n",
6512 stats.macInErrs[0], stats.macInErrs[1], stats.macInErrs[2],
6513 stats.macInErrs[3]);
6514 sbuf_printf(sb, "hdrInErrs: %10u %10u %10u %10u\n",
6515 stats.hdrInErrs[0], stats.hdrInErrs[1], stats.hdrInErrs[2],
6516 stats.hdrInErrs[3]);
6517 sbuf_printf(sb, "tcpInErrs: %10u %10u %10u %10u\n",
6518 stats.tcpInErrs[0], stats.tcpInErrs[1], stats.tcpInErrs[2],
6519 stats.tcpInErrs[3]);
6520 sbuf_printf(sb, "tcp6InErrs: %10u %10u %10u %10u\n",
6521 stats.tcp6InErrs[0], stats.tcp6InErrs[1], stats.tcp6InErrs[2],
6522 stats.tcp6InErrs[3]);
6523 sbuf_printf(sb, "tnlCongDrops: %10u %10u %10u %10u\n",
6524 stats.tnlCongDrops[0], stats.tnlCongDrops[1], stats.tnlCongDrops[2],
6525 stats.tnlCongDrops[3]);
6526 sbuf_printf(sb, "tnlTxDrops: %10u %10u %10u %10u\n",
6527 stats.tnlTxDrops[0], stats.tnlTxDrops[1], stats.tnlTxDrops[2],
6528 stats.tnlTxDrops[3]);
6529 sbuf_printf(sb, "ofldVlanDrops: %10u %10u %10u %10u\n",
6530 stats.ofldVlanDrops[0], stats.ofldVlanDrops[1],
6531 stats.ofldVlanDrops[2], stats.ofldVlanDrops[3]);
6532 sbuf_printf(sb, "ofldChanDrops: %10u %10u %10u %10u\n\n",
6533 stats.ofldChanDrops[0], stats.ofldChanDrops[1],
6534 stats.ofldChanDrops[2], stats.ofldChanDrops[3]);
6535 sbuf_printf(sb, "ofldNoNeigh: %u\nofldCongDefer: %u",
6536 stats.ofldNoNeigh, stats.ofldCongDefer);
6538 rc = sbuf_finish(sb);
6551 field_desc_show(struct sbuf *sb, uint64_t v, const struct field_desc *f)
6557 uint64_t mask = (1ULL << f->width) - 1;
6558 int len = snprintf(buf, sizeof(buf), "%s: %ju", f->name,
6559 ((uintmax_t)v >> f->start) & mask);
6561 if (line_size + len >= 79) {
6563 sbuf_printf(sb, "\n ");
6565 sbuf_printf(sb, "%s ", buf);
6566 line_size += len + 1;
6569 sbuf_printf(sb, "\n");
6572 static struct field_desc tp_la0[] = {
6573 { "RcfOpCodeOut", 60, 4 },
6575 { "WcfState", 52, 4 },
6576 { "RcfOpcSrcOut", 50, 2 },
6577 { "CRxError", 49, 1 },
6578 { "ERxError", 48, 1 },
6579 { "SanityFailed", 47, 1 },
6580 { "SpuriousMsg", 46, 1 },
6581 { "FlushInputMsg", 45, 1 },
6582 { "FlushInputCpl", 44, 1 },
6583 { "RssUpBit", 43, 1 },
6584 { "RssFilterHit", 42, 1 },
6586 { "InitTcb", 31, 1 },
6587 { "LineNumber", 24, 7 },
6589 { "EdataOut", 22, 1 },
6591 { "CdataOut", 20, 1 },
6592 { "EreadPdu", 19, 1 },
6593 { "CreadPdu", 18, 1 },
6594 { "TunnelPkt", 17, 1 },
6595 { "RcfPeerFin", 16, 1 },
6596 { "RcfReasonOut", 12, 4 },
6597 { "TxCchannel", 10, 2 },
6598 { "RcfTxChannel", 8, 2 },
6599 { "RxEchannel", 6, 2 },
6600 { "RcfRxChannel", 5, 1 },
6601 { "RcfDataOutSrdy", 4, 1 },
6603 { "RxOoDvld", 2, 1 },
6604 { "RxCongestion", 1, 1 },
6605 { "TxCongestion", 0, 1 },
6609 static struct field_desc tp_la1[] = {
6610 { "CplCmdIn", 56, 8 },
6611 { "CplCmdOut", 48, 8 },
6612 { "ESynOut", 47, 1 },
6613 { "EAckOut", 46, 1 },
6614 { "EFinOut", 45, 1 },
6615 { "ERstOut", 44, 1 },
6620 { "DataIn", 39, 1 },
6621 { "DataInVld", 38, 1 },
6623 { "RxBufEmpty", 36, 1 },
6625 { "RxFbCongestion", 34, 1 },
6626 { "TxFbCongestion", 33, 1 },
6627 { "TxPktSumSrdy", 32, 1 },
6628 { "RcfUlpType", 28, 4 },
6630 { "Ebypass", 26, 1 },
6632 { "Static0", 24, 1 },
6634 { "Cbypass", 22, 1 },
6636 { "CPktOut", 20, 1 },
6637 { "RxPagePoolFull", 18, 2 },
6638 { "RxLpbkPkt", 17, 1 },
6639 { "TxLpbkPkt", 16, 1 },
6640 { "RxVfValid", 15, 1 },
6641 { "SynLearned", 14, 1 },
6642 { "SetDelEntry", 13, 1 },
6643 { "SetInvEntry", 12, 1 },
6644 { "CpcmdDvld", 11, 1 },
6645 { "CpcmdSave", 10, 1 },
6646 { "RxPstructsFull", 8, 2 },
6647 { "EpcmdDvld", 7, 1 },
6648 { "EpcmdFlush", 6, 1 },
6649 { "EpcmdTrimPrefix", 5, 1 },
6650 { "EpcmdTrimPostfix", 4, 1 },
6651 { "ERssIp4Pkt", 3, 1 },
6652 { "ERssIp6Pkt", 2, 1 },
6653 { "ERssTcpUdpPkt", 1, 1 },
6654 { "ERssFceFipPkt", 0, 1 },
6658 static struct field_desc tp_la2[] = {
6659 { "CplCmdIn", 56, 8 },
6660 { "MpsVfVld", 55, 1 },
6667 { "DataIn", 39, 1 },
6668 { "DataInVld", 38, 1 },
6670 { "RxBufEmpty", 36, 1 },
6672 { "RxFbCongestion", 34, 1 },
6673 { "TxFbCongestion", 33, 1 },
6674 { "TxPktSumSrdy", 32, 1 },
6675 { "RcfUlpType", 28, 4 },
6677 { "Ebypass", 26, 1 },
6679 { "Static0", 24, 1 },
6681 { "Cbypass", 22, 1 },
6683 { "CPktOut", 20, 1 },
6684 { "RxPagePoolFull", 18, 2 },
6685 { "RxLpbkPkt", 17, 1 },
6686 { "TxLpbkPkt", 16, 1 },
6687 { "RxVfValid", 15, 1 },
6688 { "SynLearned", 14, 1 },
6689 { "SetDelEntry", 13, 1 },
6690 { "SetInvEntry", 12, 1 },
6691 { "CpcmdDvld", 11, 1 },
6692 { "CpcmdSave", 10, 1 },
6693 { "RxPstructsFull", 8, 2 },
6694 { "EpcmdDvld", 7, 1 },
6695 { "EpcmdFlush", 6, 1 },
6696 { "EpcmdTrimPrefix", 5, 1 },
6697 { "EpcmdTrimPostfix", 4, 1 },
6698 { "ERssIp4Pkt", 3, 1 },
6699 { "ERssIp6Pkt", 2, 1 },
6700 { "ERssTcpUdpPkt", 1, 1 },
6701 { "ERssFceFipPkt", 0, 1 },
6706 tp_la_show(struct sbuf *sb, uint64_t *p, int idx)
6709 field_desc_show(sb, *p, tp_la0);
6713 tp_la_show2(struct sbuf *sb, uint64_t *p, int idx)
6717 sbuf_printf(sb, "\n");
6718 field_desc_show(sb, p[0], tp_la0);
6719 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
6720 field_desc_show(sb, p[1], tp_la0);
6724 tp_la_show3(struct sbuf *sb, uint64_t *p, int idx)
6728 sbuf_printf(sb, "\n");
6729 field_desc_show(sb, p[0], tp_la0);
6730 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
6731 field_desc_show(sb, p[1], (p[0] & (1 << 17)) ? tp_la2 : tp_la1);
6735 sysctl_tp_la(SYSCTL_HANDLER_ARGS)
6737 struct adapter *sc = arg1;
6742 void (*show_func)(struct sbuf *, uint64_t *, int);
6744 rc = sysctl_wire_old_buffer(req, 0);
6748 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6752 buf = malloc(TPLA_SIZE * sizeof(uint64_t), M_CXGBE, M_ZERO | M_WAITOK);
6754 t4_tp_read_la(sc, buf, NULL);
6757 switch (G_DBGLAMODE(t4_read_reg(sc, A_TP_DBG_LA_CONFIG))) {
6760 show_func = tp_la_show2;
6764 show_func = tp_la_show3;
6768 show_func = tp_la_show;
6771 for (i = 0; i < TPLA_SIZE / inc; i++, p += inc)
6772 (*show_func)(sb, p, i);
6774 rc = sbuf_finish(sb);
6781 sysctl_tx_rate(SYSCTL_HANDLER_ARGS)
6783 struct adapter *sc = arg1;
6786 u64 nrate[NCHAN], orate[NCHAN];
6788 rc = sysctl_wire_old_buffer(req, 0);
6792 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6796 t4_get_chan_txrate(sc, nrate, orate);
6797 sbuf_printf(sb, " channel 0 channel 1 channel 2 "
6799 sbuf_printf(sb, "NIC B/s: %10ju %10ju %10ju %10ju\n",
6800 nrate[0], nrate[1], nrate[2], nrate[3]);
6801 sbuf_printf(sb, "Offload B/s: %10ju %10ju %10ju %10ju",
6802 orate[0], orate[1], orate[2], orate[3]);
6804 rc = sbuf_finish(sb);
6811 sysctl_ulprx_la(SYSCTL_HANDLER_ARGS)
6813 struct adapter *sc = arg1;
6818 rc = sysctl_wire_old_buffer(req, 0);
6822 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6826 buf = malloc(ULPRX_LA_SIZE * 8 * sizeof(uint32_t), M_CXGBE,
6829 t4_ulprx_read_la(sc, buf);
6832 sbuf_printf(sb, " Pcmd Type Message"
6834 for (i = 0; i < ULPRX_LA_SIZE; i++, p += 8) {
6835 sbuf_printf(sb, "\n%08x%08x %4x %08x %08x%08x%08x%08x",
6836 p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
6839 rc = sbuf_finish(sb);
6846 sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS)
6848 struct adapter *sc = arg1;
6852 rc = sysctl_wire_old_buffer(req, 0);
6856 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6860 v = t4_read_reg(sc, A_SGE_STAT_CFG);
6861 if (G_STATSOURCE_T5(v) == 7) {
6862 if (G_STATMODE(v) == 0) {
6863 sbuf_printf(sb, "total %d, incomplete %d",
6864 t4_read_reg(sc, A_SGE_STAT_TOTAL),
6865 t4_read_reg(sc, A_SGE_STAT_MATCH));
6866 } else if (G_STATMODE(v) == 1) {
6867 sbuf_printf(sb, "total %d, data overflow %d",
6868 t4_read_reg(sc, A_SGE_STAT_TOTAL),
6869 t4_read_reg(sc, A_SGE_STAT_MATCH));
6872 rc = sbuf_finish(sb);
6880 txq_start(struct ifnet *ifp, struct sge_txq *txq)
6882 struct buf_ring *br;
6885 TXQ_LOCK_ASSERT_OWNED(txq);
6888 m = txq->m ? txq->m : drbr_dequeue(ifp, br);
6890 t4_eth_tx(ifp, txq, m);
6894 t4_tx_callout(void *arg)
6896 struct sge_eq *eq = arg;
6899 if (EQ_TRYLOCK(eq) == 0)
6902 if (eq->flags & EQ_STALLED && !can_resume_tx(eq)) {
6905 if (__predict_true(!(eq->flags && EQ_DOOMED)))
6906 callout_schedule(&eq->tx_callout, 1);
6910 EQ_LOCK_ASSERT_OWNED(eq);
6912 if (__predict_true((eq->flags & EQ_DOOMED) == 0)) {
6914 if ((eq->flags & EQ_TYPEMASK) == EQ_ETH) {
6915 struct sge_txq *txq = arg;
6916 struct port_info *pi = txq->ifp->if_softc;
6920 struct sge_wrq *wrq = arg;
6925 taskqueue_enqueue(sc->tq[eq->tx_chan], &eq->tx_task);
6932 t4_tx_task(void *arg, int count)
6934 struct sge_eq *eq = arg;
6937 if ((eq->flags & EQ_TYPEMASK) == EQ_ETH) {
6938 struct sge_txq *txq = arg;
6939 txq_start(txq->ifp, txq);
6941 struct sge_wrq *wrq = arg;
6942 t4_wrq_tx_locked(wrq->adapter, wrq, NULL);
6948 fconf_to_mode(uint32_t fconf)
6952 mode = T4_FILTER_IPv4 | T4_FILTER_IPv6 | T4_FILTER_IP_SADDR |
6953 T4_FILTER_IP_DADDR | T4_FILTER_IP_SPORT | T4_FILTER_IP_DPORT;
6955 if (fconf & F_FRAGMENTATION)
6956 mode |= T4_FILTER_IP_FRAGMENT;
6958 if (fconf & F_MPSHITTYPE)
6959 mode |= T4_FILTER_MPS_HIT_TYPE;
6961 if (fconf & F_MACMATCH)
6962 mode |= T4_FILTER_MAC_IDX;
6964 if (fconf & F_ETHERTYPE)
6965 mode |= T4_FILTER_ETH_TYPE;
6967 if (fconf & F_PROTOCOL)
6968 mode |= T4_FILTER_IP_PROTO;
6971 mode |= T4_FILTER_IP_TOS;
6974 mode |= T4_FILTER_VLAN;
6976 if (fconf & F_VNIC_ID)
6977 mode |= T4_FILTER_VNIC;
6980 mode |= T4_FILTER_PORT;
6983 mode |= T4_FILTER_FCoE;
6989 mode_to_fconf(uint32_t mode)
6993 if (mode & T4_FILTER_IP_FRAGMENT)
6994 fconf |= F_FRAGMENTATION;
6996 if (mode & T4_FILTER_MPS_HIT_TYPE)
6997 fconf |= F_MPSHITTYPE;
6999 if (mode & T4_FILTER_MAC_IDX)
7000 fconf |= F_MACMATCH;
7002 if (mode & T4_FILTER_ETH_TYPE)
7003 fconf |= F_ETHERTYPE;
7005 if (mode & T4_FILTER_IP_PROTO)
7006 fconf |= F_PROTOCOL;
7008 if (mode & T4_FILTER_IP_TOS)
7011 if (mode & T4_FILTER_VLAN)
7014 if (mode & T4_FILTER_VNIC)
7017 if (mode & T4_FILTER_PORT)
7020 if (mode & T4_FILTER_FCoE)
7027 fspec_to_fconf(struct t4_filter_specification *fs)
7031 if (fs->val.frag || fs->mask.frag)
7032 fconf |= F_FRAGMENTATION;
7034 if (fs->val.matchtype || fs->mask.matchtype)
7035 fconf |= F_MPSHITTYPE;
7037 if (fs->val.macidx || fs->mask.macidx)
7038 fconf |= F_MACMATCH;
7040 if (fs->val.ethtype || fs->mask.ethtype)
7041 fconf |= F_ETHERTYPE;
7043 if (fs->val.proto || fs->mask.proto)
7044 fconf |= F_PROTOCOL;
7046 if (fs->val.tos || fs->mask.tos)
7049 if (fs->val.vlan_vld || fs->mask.vlan_vld)
7052 if (fs->val.vnic_vld || fs->mask.vnic_vld)
7055 if (fs->val.iport || fs->mask.iport)
7058 if (fs->val.fcoe || fs->mask.fcoe)
7065 get_filter_mode(struct adapter *sc, uint32_t *mode)
7070 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
7075 t4_read_indirect(sc, A_TP_PIO_ADDR, A_TP_PIO_DATA, &fconf, 1,
7078 if (sc->params.tp.vlan_pri_map != fconf) {
7079 log(LOG_WARNING, "%s: cached filter mode out of sync %x %x.\n",
7080 device_get_nameunit(sc->dev), sc->params.tp.vlan_pri_map,
7084 *mode = fconf_to_mode(fconf);
7086 end_synchronized_op(sc, LOCK_HELD);
7091 set_filter_mode(struct adapter *sc, uint32_t mode)
7096 fconf = mode_to_fconf(mode);
7098 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
7103 if (sc->tids.ftids_in_use > 0) {
7109 if (sc->offload_map) {
7115 rc = -t4_set_filter_mode(sc, fconf);
7117 end_synchronized_op(sc, LOCK_HELD);
7121 static inline uint64_t
7122 get_filter_hits(struct adapter *sc, uint32_t fid)
7124 uint32_t mw_base, off, tcb_base = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
7127 memwin_info(sc, 0, &mw_base, NULL);
7128 off = position_memwin(sc, 0,
7129 tcb_base + (fid + sc->tids.ftid_base) * TCB_SIZE);
7131 hits = t4_read_reg64(sc, mw_base + off + 16);
7132 hits = be64toh(hits);
7134 hits = t4_read_reg(sc, mw_base + off + 24);
7135 hits = be32toh(hits);
7142 get_filter(struct adapter *sc, struct t4_filter *t)
7144 int i, rc, nfilters = sc->tids.nftids;
7145 struct filter_entry *f;
7147 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
7152 if (sc->tids.ftids_in_use == 0 || sc->tids.ftid_tab == NULL ||
7153 t->idx >= nfilters) {
7154 t->idx = 0xffffffff;
7158 f = &sc->tids.ftid_tab[t->idx];
7159 for (i = t->idx; i < nfilters; i++, f++) {
7162 t->l2tidx = f->l2t ? f->l2t->idx : 0;
7163 t->smtidx = f->smtidx;
7165 t->hits = get_filter_hits(sc, t->idx);
7167 t->hits = UINT64_MAX;
7174 t->idx = 0xffffffff;
7176 end_synchronized_op(sc, LOCK_HELD);
7181 set_filter(struct adapter *sc, struct t4_filter *t)
7183 unsigned int nfilters, nports;
7184 struct filter_entry *f;
7187 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setf");
7191 nfilters = sc->tids.nftids;
7192 nports = sc->params.nports;
7194 if (nfilters == 0) {
7199 if (!(sc->flags & FULL_INIT_DONE)) {
7204 if (t->idx >= nfilters) {
7209 /* Validate against the global filter mode */
7210 if ((sc->params.tp.vlan_pri_map | fspec_to_fconf(&t->fs)) !=
7211 sc->params.tp.vlan_pri_map) {
7216 if (t->fs.action == FILTER_SWITCH && t->fs.eport >= nports) {
7221 if (t->fs.val.iport >= nports) {
7226 /* Can't specify an iq if not steering to it */
7227 if (!t->fs.dirsteer && t->fs.iq) {
7232 /* IPv6 filter idx must be 4 aligned */
7233 if (t->fs.type == 1 &&
7234 ((t->idx & 0x3) || t->idx + 4 >= nfilters)) {
7239 if (sc->tids.ftid_tab == NULL) {
7240 KASSERT(sc->tids.ftids_in_use == 0,
7241 ("%s: no memory allocated but filters_in_use > 0",
7244 sc->tids.ftid_tab = malloc(sizeof (struct filter_entry) *
7245 nfilters, M_CXGBE, M_NOWAIT | M_ZERO);
7246 if (sc->tids.ftid_tab == NULL) {
7250 mtx_init(&sc->tids.ftid_lock, "T4 filters", 0, MTX_DEF);
7253 for (i = 0; i < 4; i++) {
7254 f = &sc->tids.ftid_tab[t->idx + i];
7256 if (f->pending || f->valid) {
7265 if (t->fs.type == 0)
7269 f = &sc->tids.ftid_tab[t->idx];
7272 rc = set_filter_wr(sc, t->idx);
7274 end_synchronized_op(sc, 0);
7277 mtx_lock(&sc->tids.ftid_lock);
7279 if (f->pending == 0) {
7280 rc = f->valid ? 0 : EIO;
7284 if (mtx_sleep(&sc->tids.ftid_tab, &sc->tids.ftid_lock,
7285 PCATCH, "t4setfw", 0)) {
7290 mtx_unlock(&sc->tids.ftid_lock);
7296 del_filter(struct adapter *sc, struct t4_filter *t)
7298 unsigned int nfilters;
7299 struct filter_entry *f;
7302 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4delf");
7306 nfilters = sc->tids.nftids;
7308 if (nfilters == 0) {
7313 if (sc->tids.ftid_tab == NULL || sc->tids.ftids_in_use == 0 ||
7314 t->idx >= nfilters) {
7319 if (!(sc->flags & FULL_INIT_DONE)) {
7324 f = &sc->tids.ftid_tab[t->idx];
7336 t->fs = f->fs; /* extra info for the caller */
7337 rc = del_filter_wr(sc, t->idx);
7341 end_synchronized_op(sc, 0);
7344 mtx_lock(&sc->tids.ftid_lock);
7346 if (f->pending == 0) {
7347 rc = f->valid ? EIO : 0;
7351 if (mtx_sleep(&sc->tids.ftid_tab, &sc->tids.ftid_lock,
7352 PCATCH, "t4delfw", 0)) {
7357 mtx_unlock(&sc->tids.ftid_lock);
7364 clear_filter(struct filter_entry *f)
7367 t4_l2t_release(f->l2t);
7369 bzero(f, sizeof (*f));
7373 set_filter_wr(struct adapter *sc, int fidx)
7375 struct filter_entry *f = &sc->tids.ftid_tab[fidx];
7377 struct fw_filter_wr *fwr;
7380 ASSERT_SYNCHRONIZED_OP(sc);
7382 if (f->fs.newdmac || f->fs.newvlan) {
7383 /* This filter needs an L2T entry; allocate one. */
7384 f->l2t = t4_l2t_alloc_switching(sc->l2t);
7387 if (t4_l2t_set_switching(sc, f->l2t, f->fs.vlan, f->fs.eport,
7389 t4_l2t_release(f->l2t);
7395 ftid = sc->tids.ftid_base + fidx;
7397 wr = alloc_wrqe(sizeof(*fwr), &sc->sge.mgmtq);
7402 bzero(fwr, sizeof (*fwr));
7404 fwr->op_pkd = htobe32(V_FW_WR_OP(FW_FILTER_WR));
7405 fwr->len16_pkd = htobe32(FW_LEN16(*fwr));
7407 htobe32(V_FW_FILTER_WR_TID(ftid) |
7408 V_FW_FILTER_WR_RQTYPE(f->fs.type) |
7409 V_FW_FILTER_WR_NOREPLY(0) |
7410 V_FW_FILTER_WR_IQ(f->fs.iq));
7411 fwr->del_filter_to_l2tix =
7412 htobe32(V_FW_FILTER_WR_RPTTID(f->fs.rpttid) |
7413 V_FW_FILTER_WR_DROP(f->fs.action == FILTER_DROP) |
7414 V_FW_FILTER_WR_DIRSTEER(f->fs.dirsteer) |
7415 V_FW_FILTER_WR_MASKHASH(f->fs.maskhash) |
7416 V_FW_FILTER_WR_DIRSTEERHASH(f->fs.dirsteerhash) |
7417 V_FW_FILTER_WR_LPBK(f->fs.action == FILTER_SWITCH) |
7418 V_FW_FILTER_WR_DMAC(f->fs.newdmac) |
7419 V_FW_FILTER_WR_SMAC(f->fs.newsmac) |
7420 V_FW_FILTER_WR_INSVLAN(f->fs.newvlan == VLAN_INSERT ||
7421 f->fs.newvlan == VLAN_REWRITE) |
7422 V_FW_FILTER_WR_RMVLAN(f->fs.newvlan == VLAN_REMOVE ||
7423 f->fs.newvlan == VLAN_REWRITE) |
7424 V_FW_FILTER_WR_HITCNTS(f->fs.hitcnts) |
7425 V_FW_FILTER_WR_TXCHAN(f->fs.eport) |
7426 V_FW_FILTER_WR_PRIO(f->fs.prio) |
7427 V_FW_FILTER_WR_L2TIX(f->l2t ? f->l2t->idx : 0));
7428 fwr->ethtype = htobe16(f->fs.val.ethtype);
7429 fwr->ethtypem = htobe16(f->fs.mask.ethtype);
7430 fwr->frag_to_ovlan_vldm =
7431 (V_FW_FILTER_WR_FRAG(f->fs.val.frag) |
7432 V_FW_FILTER_WR_FRAGM(f->fs.mask.frag) |
7433 V_FW_FILTER_WR_IVLAN_VLD(f->fs.val.vlan_vld) |
7434 V_FW_FILTER_WR_OVLAN_VLD(f->fs.val.vnic_vld) |
7435 V_FW_FILTER_WR_IVLAN_VLDM(f->fs.mask.vlan_vld) |
7436 V_FW_FILTER_WR_OVLAN_VLDM(f->fs.mask.vnic_vld));
7438 fwr->rx_chan_rx_rpl_iq = htobe16(V_FW_FILTER_WR_RX_CHAN(0) |
7439 V_FW_FILTER_WR_RX_RPL_IQ(sc->sge.fwq.abs_id));
7440 fwr->maci_to_matchtypem =
7441 htobe32(V_FW_FILTER_WR_MACI(f->fs.val.macidx) |
7442 V_FW_FILTER_WR_MACIM(f->fs.mask.macidx) |
7443 V_FW_FILTER_WR_FCOE(f->fs.val.fcoe) |
7444 V_FW_FILTER_WR_FCOEM(f->fs.mask.fcoe) |
7445 V_FW_FILTER_WR_PORT(f->fs.val.iport) |
7446 V_FW_FILTER_WR_PORTM(f->fs.mask.iport) |
7447 V_FW_FILTER_WR_MATCHTYPE(f->fs.val.matchtype) |
7448 V_FW_FILTER_WR_MATCHTYPEM(f->fs.mask.matchtype));
7449 fwr->ptcl = f->fs.val.proto;
7450 fwr->ptclm = f->fs.mask.proto;
7451 fwr->ttyp = f->fs.val.tos;
7452 fwr->ttypm = f->fs.mask.tos;
7453 fwr->ivlan = htobe16(f->fs.val.vlan);
7454 fwr->ivlanm = htobe16(f->fs.mask.vlan);
7455 fwr->ovlan = htobe16(f->fs.val.vnic);
7456 fwr->ovlanm = htobe16(f->fs.mask.vnic);
7457 bcopy(f->fs.val.dip, fwr->lip, sizeof (fwr->lip));
7458 bcopy(f->fs.mask.dip, fwr->lipm, sizeof (fwr->lipm));
7459 bcopy(f->fs.val.sip, fwr->fip, sizeof (fwr->fip));
7460 bcopy(f->fs.mask.sip, fwr->fipm, sizeof (fwr->fipm));
7461 fwr->lp = htobe16(f->fs.val.dport);
7462 fwr->lpm = htobe16(f->fs.mask.dport);
7463 fwr->fp = htobe16(f->fs.val.sport);
7464 fwr->fpm = htobe16(f->fs.mask.sport);
7466 bcopy(f->fs.smac, fwr->sma, sizeof (fwr->sma));
7469 sc->tids.ftids_in_use++;
7476 del_filter_wr(struct adapter *sc, int fidx)
7478 struct filter_entry *f = &sc->tids.ftid_tab[fidx];
7480 struct fw_filter_wr *fwr;
7483 ftid = sc->tids.ftid_base + fidx;
7485 wr = alloc_wrqe(sizeof(*fwr), &sc->sge.mgmtq);
7489 bzero(fwr, sizeof (*fwr));
7491 t4_mk_filtdelwr(ftid, fwr, sc->sge.fwq.abs_id);
7499 t4_filter_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
7501 struct adapter *sc = iq->adapter;
7502 const struct cpl_set_tcb_rpl *rpl = (const void *)(rss + 1);
7503 unsigned int idx = GET_TID(rpl);
7505 struct filter_entry *f;
7507 KASSERT(m == NULL, ("%s: payload with opcode %02x", __func__,
7510 if (is_ftid(sc, idx)) {
7512 idx -= sc->tids.ftid_base;
7513 f = &sc->tids.ftid_tab[idx];
7514 rc = G_COOKIE(rpl->cookie);
7516 mtx_lock(&sc->tids.ftid_lock);
7517 if (rc == FW_FILTER_WR_FLT_ADDED) {
7518 KASSERT(f->pending, ("%s: filter[%u] isn't pending.",
7520 f->smtidx = (be64toh(rpl->oldval) >> 24) & 0xff;
7521 f->pending = 0; /* asynchronous setup completed */
7524 if (rc != FW_FILTER_WR_FLT_DELETED) {
7525 /* Add or delete failed, display an error */
7527 "filter %u setup failed with error %u\n",
7532 sc->tids.ftids_in_use--;
7534 wakeup(&sc->tids.ftid_tab);
7535 mtx_unlock(&sc->tids.ftid_lock);
7542 get_sge_context(struct adapter *sc, struct t4_sge_context *cntxt)
7546 if (cntxt->cid > M_CTXTQID)
7549 if (cntxt->mem_id != CTXT_EGRESS && cntxt->mem_id != CTXT_INGRESS &&
7550 cntxt->mem_id != CTXT_FLM && cntxt->mem_id != CTXT_CNM)
7553 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ctxt");
7557 if (sc->flags & FW_OK) {
7558 rc = -t4_sge_ctxt_rd(sc, sc->mbox, cntxt->cid, cntxt->mem_id,
7565 * Read via firmware failed or wasn't even attempted. Read directly via
7568 rc = -t4_sge_ctxt_rd_bd(sc, cntxt->cid, cntxt->mem_id, &cntxt->data[0]);
7570 end_synchronized_op(sc, 0);
7575 load_fw(struct adapter *sc, struct t4_data *fw)
7580 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldfw");
7584 if (sc->flags & FULL_INIT_DONE) {
7589 fw_data = malloc(fw->len, M_CXGBE, M_WAITOK);
7590 if (fw_data == NULL) {
7595 rc = copyin(fw->data, fw_data, fw->len);
7597 rc = -t4_load_fw(sc, fw_data, fw->len);
7599 free(fw_data, M_CXGBE);
7601 end_synchronized_op(sc, 0);
7606 read_card_mem(struct adapter *sc, int win, struct t4_mem_range *mr)
7608 uint32_t addr, off, remaining, i, n;
7610 uint32_t mw_base, mw_aperture;
7614 rc = validate_mem_range(sc, mr->addr, mr->len);
7618 memwin_info(sc, win, &mw_base, &mw_aperture);
7619 buf = b = malloc(min(mr->len, mw_aperture), M_CXGBE, M_WAITOK);
7621 remaining = mr->len;
7622 dst = (void *)mr->data;
7625 off = position_memwin(sc, win, addr);
7627 /* number of bytes that we'll copy in the inner loop */
7628 n = min(remaining, mw_aperture - off);
7629 for (i = 0; i < n; i += 4)
7630 *b++ = t4_read_reg(sc, mw_base + off + i);
7632 rc = copyout(buf, dst, n);
7647 read_i2c(struct adapter *sc, struct t4_i2c_data *i2cd)
7651 if (i2cd->len == 0 || i2cd->port_id >= sc->params.nports)
7654 if (i2cd->len > sizeof(i2cd->data))
7657 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4i2crd");
7660 rc = -t4_i2c_rd(sc, sc->mbox, i2cd->port_id, i2cd->dev_addr,
7661 i2cd->offset, i2cd->len, &i2cd->data[0]);
7662 end_synchronized_op(sc, 0);
7668 in_range(int val, int lo, int hi)
7671 return (val < 0 || (val <= hi && val >= lo));
7675 set_sched_class(struct adapter *sc, struct t4_sched_params *p)
7677 int fw_subcmd, fw_type, rc;
7679 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setsc");
7683 if (!(sc->flags & FULL_INIT_DONE)) {
7689 * Translate the cxgbetool parameters into T4 firmware parameters. (The
7690 * sub-command and type are in common locations.)
7692 if (p->subcmd == SCHED_CLASS_SUBCMD_CONFIG)
7693 fw_subcmd = FW_SCHED_SC_CONFIG;
7694 else if (p->subcmd == SCHED_CLASS_SUBCMD_PARAMS)
7695 fw_subcmd = FW_SCHED_SC_PARAMS;
7700 if (p->type == SCHED_CLASS_TYPE_PACKET)
7701 fw_type = FW_SCHED_TYPE_PKTSCHED;
7707 if (fw_subcmd == FW_SCHED_SC_CONFIG) {
7708 /* Vet our parameters ..*/
7709 if (p->u.config.minmax < 0) {
7714 /* And pass the request to the firmware ...*/
7715 rc = -t4_sched_config(sc, fw_type, p->u.config.minmax, 1);
7719 if (fw_subcmd == FW_SCHED_SC_PARAMS) {
7725 if (p->u.params.level == SCHED_CLASS_LEVEL_CL_RL)
7726 fw_level = FW_SCHED_PARAMS_LEVEL_CL_RL;
7727 else if (p->u.params.level == SCHED_CLASS_LEVEL_CL_WRR)
7728 fw_level = FW_SCHED_PARAMS_LEVEL_CL_WRR;
7729 else if (p->u.params.level == SCHED_CLASS_LEVEL_CH_RL)
7730 fw_level = FW_SCHED_PARAMS_LEVEL_CH_RL;
7736 if (p->u.params.mode == SCHED_CLASS_MODE_CLASS)
7737 fw_mode = FW_SCHED_PARAMS_MODE_CLASS;
7738 else if (p->u.params.mode == SCHED_CLASS_MODE_FLOW)
7739 fw_mode = FW_SCHED_PARAMS_MODE_FLOW;
7745 if (p->u.params.rateunit == SCHED_CLASS_RATEUNIT_BITS)
7746 fw_rateunit = FW_SCHED_PARAMS_UNIT_BITRATE;
7747 else if (p->u.params.rateunit == SCHED_CLASS_RATEUNIT_PKTS)
7748 fw_rateunit = FW_SCHED_PARAMS_UNIT_PKTRATE;
7754 if (p->u.params.ratemode == SCHED_CLASS_RATEMODE_REL)
7755 fw_ratemode = FW_SCHED_PARAMS_RATE_REL;
7756 else if (p->u.params.ratemode == SCHED_CLASS_RATEMODE_ABS)
7757 fw_ratemode = FW_SCHED_PARAMS_RATE_ABS;
7763 /* Vet our parameters ... */
7764 if (!in_range(p->u.params.channel, 0, 3) ||
7765 !in_range(p->u.params.cl, 0, is_t4(sc) ? 15 : 16) ||
7766 !in_range(p->u.params.minrate, 0, 10000000) ||
7767 !in_range(p->u.params.maxrate, 0, 10000000) ||
7768 !in_range(p->u.params.weight, 0, 100)) {
7774 * Translate any unset parameters into the firmware's
7775 * nomenclature and/or fail the call if the parameters
7778 if (p->u.params.rateunit < 0 || p->u.params.ratemode < 0 ||
7779 p->u.params.channel < 0 || p->u.params.cl < 0) {
7783 if (p->u.params.minrate < 0)
7784 p->u.params.minrate = 0;
7785 if (p->u.params.maxrate < 0) {
7786 if (p->u.params.level == SCHED_CLASS_LEVEL_CL_RL ||
7787 p->u.params.level == SCHED_CLASS_LEVEL_CH_RL) {
7791 p->u.params.maxrate = 0;
7793 if (p->u.params.weight < 0) {
7794 if (p->u.params.level == SCHED_CLASS_LEVEL_CL_WRR) {
7798 p->u.params.weight = 0;
7800 if (p->u.params.pktsize < 0) {
7801 if (p->u.params.level == SCHED_CLASS_LEVEL_CL_RL ||
7802 p->u.params.level == SCHED_CLASS_LEVEL_CH_RL) {
7806 p->u.params.pktsize = 0;
7809 /* See what the firmware thinks of the request ... */
7810 rc = -t4_sched_params(sc, fw_type, fw_level, fw_mode,
7811 fw_rateunit, fw_ratemode, p->u.params.channel,
7812 p->u.params.cl, p->u.params.minrate, p->u.params.maxrate,
7813 p->u.params.weight, p->u.params.pktsize, 1);
7819 end_synchronized_op(sc, 0);
7824 set_sched_queue(struct adapter *sc, struct t4_sched_queue *p)
7826 struct port_info *pi = NULL;
7827 struct sge_txq *txq;
7828 uint32_t fw_mnem, fw_queue, fw_class;
7831 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setsq");
7835 if (!(sc->flags & FULL_INIT_DONE)) {
7840 if (p->port >= sc->params.nports) {
7845 pi = sc->port[p->port];
7846 if (!in_range(p->queue, 0, pi->ntxq - 1) || !in_range(p->cl, 0, 7)) {
7852 * Create a template for the FW_PARAMS_CMD mnemonic and value (TX
7853 * Scheduling Class in this case).
7855 fw_mnem = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DMAQ) |
7856 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DMAQ_EQ_SCHEDCLASS_ETH));
7857 fw_class = p->cl < 0 ? 0xffffffff : p->cl;
7860 * If op.queue is non-negative, then we're only changing the scheduling
7861 * on a single specified TX queue.
7863 if (p->queue >= 0) {
7864 txq = &sc->sge.txq[pi->first_txq + p->queue];
7865 fw_queue = (fw_mnem | V_FW_PARAMS_PARAM_YZ(txq->eq.cntxt_id));
7866 rc = -t4_set_params(sc, sc->mbox, sc->pf, 0, 1, &fw_queue,
7872 * Change the scheduling on all the TX queues for the
7875 for_each_txq(pi, i, txq) {
7876 fw_queue = (fw_mnem | V_FW_PARAMS_PARAM_YZ(txq->eq.cntxt_id));
7877 rc = -t4_set_params(sc, sc->mbox, sc->pf, 0, 1, &fw_queue,
7885 end_synchronized_op(sc, 0);
7890 t4_os_find_pci_capability(struct adapter *sc, int cap)
7894 return (pci_find_cap(sc->dev, cap, &i) == 0 ? i : 0);
7898 t4_os_pci_save_state(struct adapter *sc)
7901 struct pci_devinfo *dinfo;
7904 dinfo = device_get_ivars(dev);
7906 pci_cfg_save(dev, dinfo, 0);
7911 t4_os_pci_restore_state(struct adapter *sc)
7914 struct pci_devinfo *dinfo;
7917 dinfo = device_get_ivars(dev);
7919 pci_cfg_restore(dev, dinfo);
7924 t4_os_portmod_changed(const struct adapter *sc, int idx)
7926 struct port_info *pi = sc->port[idx];
7927 static const char *mod_str[] = {
7928 NULL, "LR", "SR", "ER", "TWINAX", "active TWINAX", "LRM"
7931 build_medialist(pi, &pi->media);
7933 build_medialist(pi, &pi->nm_media);
7936 if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
7937 if_printf(pi->ifp, "transceiver unplugged.\n");
7938 else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
7939 if_printf(pi->ifp, "unknown transceiver inserted.\n");
7940 else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
7941 if_printf(pi->ifp, "unsupported transceiver inserted.\n");
7942 else if (pi->mod_type > 0 && pi->mod_type < nitems(mod_str)) {
7943 if_printf(pi->ifp, "%s transceiver inserted.\n",
7944 mod_str[pi->mod_type]);
7946 if_printf(pi->ifp, "transceiver (type %d) inserted.\n",
7952 t4_os_link_changed(struct adapter *sc, int idx, int link_stat, int reason)
7954 struct port_info *pi = sc->port[idx];
7955 struct ifnet *ifp = pi->ifp;
7959 ifp->if_baudrate = IF_Mbps(pi->link_cfg.speed);
7960 if_link_state_change(ifp, LINK_STATE_UP);
7963 pi->linkdnrc = reason;
7964 if_link_state_change(ifp, LINK_STATE_DOWN);
7969 t4_iterate(void (*func)(struct adapter *, void *), void *arg)
7973 sx_slock(&t4_list_lock);
7974 SLIST_FOREACH(sc, &t4_list, link) {
7976 * func should not make any assumptions about what state sc is
7977 * in - the only guarantee is that sc->sc_lock is a valid lock.
7981 sx_sunlock(&t4_list_lock);
7985 t4_open(struct cdev *dev, int flags, int type, struct thread *td)
7991 t4_close(struct cdev *dev, int flags, int type, struct thread *td)
7997 t4_ioctl(struct cdev *dev, unsigned long cmd, caddr_t data, int fflag,
8001 struct adapter *sc = dev->si_drv1;
8003 rc = priv_check(td, PRIV_DRIVER);
8008 case CHELSIO_T4_GETREG: {
8009 struct t4_reg *edata = (struct t4_reg *)data;
8011 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
8014 if (edata->size == 4)
8015 edata->val = t4_read_reg(sc, edata->addr);
8016 else if (edata->size == 8)
8017 edata->val = t4_read_reg64(sc, edata->addr);
8023 case CHELSIO_T4_SETREG: {
8024 struct t4_reg *edata = (struct t4_reg *)data;
8026 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
8029 if (edata->size == 4) {
8030 if (edata->val & 0xffffffff00000000)
8032 t4_write_reg(sc, edata->addr, (uint32_t) edata->val);
8033 } else if (edata->size == 8)
8034 t4_write_reg64(sc, edata->addr, edata->val);
8039 case CHELSIO_T4_REGDUMP: {
8040 struct t4_regdump *regs = (struct t4_regdump *)data;
8041 int reglen = is_t4(sc) ? T4_REGDUMP_SIZE : T5_REGDUMP_SIZE;
8044 if (regs->len < reglen) {
8045 regs->len = reglen; /* hint to the caller */
8050 buf = malloc(reglen, M_CXGBE, M_WAITOK | M_ZERO);
8051 t4_get_regs(sc, regs, buf);
8052 rc = copyout(buf, regs->data, reglen);
8056 case CHELSIO_T4_GET_FILTER_MODE:
8057 rc = get_filter_mode(sc, (uint32_t *)data);
8059 case CHELSIO_T4_SET_FILTER_MODE:
8060 rc = set_filter_mode(sc, *(uint32_t *)data);
8062 case CHELSIO_T4_GET_FILTER:
8063 rc = get_filter(sc, (struct t4_filter *)data);
8065 case CHELSIO_T4_SET_FILTER:
8066 rc = set_filter(sc, (struct t4_filter *)data);
8068 case CHELSIO_T4_DEL_FILTER:
8069 rc = del_filter(sc, (struct t4_filter *)data);
8071 case CHELSIO_T4_GET_SGE_CONTEXT:
8072 rc = get_sge_context(sc, (struct t4_sge_context *)data);
8074 case CHELSIO_T4_LOAD_FW:
8075 rc = load_fw(sc, (struct t4_data *)data);
8077 case CHELSIO_T4_GET_MEM:
8078 rc = read_card_mem(sc, 2, (struct t4_mem_range *)data);
8080 case CHELSIO_T4_GET_I2C:
8081 rc = read_i2c(sc, (struct t4_i2c_data *)data);
8083 case CHELSIO_T4_CLEAR_STATS: {
8085 u_int port_id = *(uint32_t *)data;
8086 struct port_info *pi;
8088 if (port_id >= sc->params.nports)
8090 pi = sc->port[port_id];
8093 t4_clr_port_stats(sc, pi->tx_chan);
8095 if (pi->flags & PORT_INIT_DONE) {
8096 struct sge_rxq *rxq;
8097 struct sge_txq *txq;
8098 struct sge_wrq *wrq;
8100 for_each_rxq(pi, i, rxq) {
8101 #if defined(INET) || defined(INET6)
8102 rxq->lro.lro_queued = 0;
8103 rxq->lro.lro_flushed = 0;
8106 rxq->vlan_extraction = 0;
8109 for_each_txq(pi, i, txq) {
8112 txq->vlan_insertion = 0;
8116 txq->txpkts_wrs = 0;
8117 txq->txpkts_pkts = 0;
8118 txq->br->br_drops = 0;
8124 /* nothing to clear for each ofld_rxq */
8126 for_each_ofld_txq(pi, i, wrq) {
8131 wrq = &sc->sge.ctrlq[pi->port_id];
8137 case CHELSIO_T4_SCHED_CLASS:
8138 rc = set_sched_class(sc, (struct t4_sched_params *)data);
8140 case CHELSIO_T4_SCHED_QUEUE:
8141 rc = set_sched_queue(sc, (struct t4_sched_queue *)data);
8143 case CHELSIO_T4_GET_TRACER:
8144 rc = t4_get_tracer(sc, (struct t4_tracer *)data);
8146 case CHELSIO_T4_SET_TRACER:
8147 rc = t4_set_tracer(sc, (struct t4_tracer *)data);
8158 t4_iscsi_init(struct ifnet *ifp, unsigned int tag_mask,
8159 const unsigned int *pgsz_order)
8161 struct port_info *pi = ifp->if_softc;
8162 struct adapter *sc = pi->adapter;
8164 t4_write_reg(sc, A_ULP_RX_ISCSI_TAGMASK, tag_mask);
8165 t4_write_reg(sc, A_ULP_RX_ISCSI_PSZ, V_HPZ0(pgsz_order[0]) |
8166 V_HPZ1(pgsz_order[1]) | V_HPZ2(pgsz_order[2]) |
8167 V_HPZ3(pgsz_order[3]));
8171 toe_capability(struct port_info *pi, int enable)
8174 struct adapter *sc = pi->adapter;
8176 ASSERT_SYNCHRONIZED_OP(sc);
8178 if (!is_offload(sc))
8183 * We need the port's queues around so that we're able to send
8184 * and receive CPLs to/from the TOE even if the ifnet for this
8185 * port has never been UP'd administratively.
8187 if (!(pi->flags & PORT_INIT_DONE)) {
8188 rc = cxgbe_init_synchronized(pi);
8193 if (isset(&sc->offload_map, pi->port_id))
8196 if (!(sc->flags & TOM_INIT_DONE)) {
8197 rc = t4_activate_uld(sc, ULD_TOM);
8200 "You must kldload t4_tom.ko before trying "
8201 "to enable TOE on a cxgbe interface.\n");
8205 KASSERT(sc->tom_softc != NULL,
8206 ("%s: TOM activated but softc NULL", __func__));
8207 KASSERT(sc->flags & TOM_INIT_DONE,
8208 ("%s: TOM activated but flag not set", __func__));
8211 setbit(&sc->offload_map, pi->port_id);
8213 if (!isset(&sc->offload_map, pi->port_id))
8216 KASSERT(sc->flags & TOM_INIT_DONE,
8217 ("%s: TOM never initialized?", __func__));
8218 clrbit(&sc->offload_map, pi->port_id);
8225 * Add an upper layer driver to the global list.
8228 t4_register_uld(struct uld_info *ui)
8233 sx_xlock(&t4_uld_list_lock);
8234 SLIST_FOREACH(u, &t4_uld_list, link) {
8235 if (u->uld_id == ui->uld_id) {
8241 SLIST_INSERT_HEAD(&t4_uld_list, ui, link);
8244 sx_xunlock(&t4_uld_list_lock);
8249 t4_unregister_uld(struct uld_info *ui)
8254 sx_xlock(&t4_uld_list_lock);
8256 SLIST_FOREACH(u, &t4_uld_list, link) {
8258 if (ui->refcount > 0) {
8263 SLIST_REMOVE(&t4_uld_list, ui, uld_info, link);
8269 sx_xunlock(&t4_uld_list_lock);
8274 t4_activate_uld(struct adapter *sc, int id)
8277 struct uld_info *ui;
8279 ASSERT_SYNCHRONIZED_OP(sc);
8281 sx_slock(&t4_uld_list_lock);
8283 SLIST_FOREACH(ui, &t4_uld_list, link) {
8284 if (ui->uld_id == id) {
8285 if (!(sc->flags & FULL_INIT_DONE)) {
8286 rc = adapter_full_init(sc);
8291 rc = ui->activate(sc);
8298 sx_sunlock(&t4_uld_list_lock);
8304 t4_deactivate_uld(struct adapter *sc, int id)
8307 struct uld_info *ui;
8309 ASSERT_SYNCHRONIZED_OP(sc);
8311 sx_slock(&t4_uld_list_lock);
8313 SLIST_FOREACH(ui, &t4_uld_list, link) {
8314 if (ui->uld_id == id) {
8315 rc = ui->deactivate(sc);
8322 sx_sunlock(&t4_uld_list_lock);
8329 * Come up with reasonable defaults for some of the tunables, provided they're
8330 * not set by the user (in which case we'll use the values as is).
8333 tweak_tunables(void)
8335 int nc = mp_ncpus; /* our snapshot of the number of CPUs */
8338 t4_ntxq10g = min(nc, NTXQ_10G);
8341 t4_ntxq1g = min(nc, NTXQ_1G);
8344 t4_nrxq10g = min(nc, NRXQ_10G);
8347 t4_nrxq1g = min(nc, NRXQ_1G);
8350 if (t4_nofldtxq10g < 1)
8351 t4_nofldtxq10g = min(nc, NOFLDTXQ_10G);
8353 if (t4_nofldtxq1g < 1)
8354 t4_nofldtxq1g = min(nc, NOFLDTXQ_1G);
8356 if (t4_nofldrxq10g < 1)
8357 t4_nofldrxq10g = min(nc, NOFLDRXQ_10G);
8359 if (t4_nofldrxq1g < 1)
8360 t4_nofldrxq1g = min(nc, NOFLDRXQ_1G);
8362 if (t4_toecaps_allowed == -1)
8363 t4_toecaps_allowed = FW_CAPS_CONFIG_TOE;
8365 if (t4_toecaps_allowed == -1)
8366 t4_toecaps_allowed = 0;
8370 if (t4_nnmtxq10g < 1)
8371 t4_nnmtxq10g = min(nc, NNMTXQ_10G);
8373 if (t4_nnmtxq1g < 1)
8374 t4_nnmtxq1g = min(nc, NNMTXQ_1G);
8376 if (t4_nnmrxq10g < 1)
8377 t4_nnmrxq10g = min(nc, NNMRXQ_10G);
8379 if (t4_nnmrxq1g < 1)
8380 t4_nnmrxq1g = min(nc, NNMRXQ_1G);
8383 if (t4_tmr_idx_10g < 0 || t4_tmr_idx_10g >= SGE_NTIMERS)
8384 t4_tmr_idx_10g = TMR_IDX_10G;
8386 if (t4_pktc_idx_10g < -1 || t4_pktc_idx_10g >= SGE_NCOUNTERS)
8387 t4_pktc_idx_10g = PKTC_IDX_10G;
8389 if (t4_tmr_idx_1g < 0 || t4_tmr_idx_1g >= SGE_NTIMERS)
8390 t4_tmr_idx_1g = TMR_IDX_1G;
8392 if (t4_pktc_idx_1g < -1 || t4_pktc_idx_1g >= SGE_NCOUNTERS)
8393 t4_pktc_idx_1g = PKTC_IDX_1G;
8395 if (t4_qsize_txq < 128)
8398 if (t4_qsize_rxq < 128)
8400 while (t4_qsize_rxq & 7)
8403 t4_intr_types &= INTR_MSIX | INTR_MSI | INTR_INTX;
8406 static struct sx mlu; /* mod load unload */
8407 SX_SYSINIT(cxgbe_mlu, &mlu, "cxgbe mod load/unload");
8410 mod_event(module_t mod, int cmd, void *arg)
8413 static int loaded = 0;
8418 if (loaded++ == 0) {
8420 sx_init(&t4_list_lock, "T4/T5 adapters");
8421 SLIST_INIT(&t4_list);
8423 sx_init(&t4_uld_list_lock, "T4/T5 ULDs");
8424 SLIST_INIT(&t4_uld_list);
8426 t4_tracer_modload();
8434 if (--loaded == 0) {
8437 sx_slock(&t4_list_lock);
8438 if (!SLIST_EMPTY(&t4_list)) {
8440 sx_sunlock(&t4_list_lock);
8444 sx_slock(&t4_uld_list_lock);
8445 if (!SLIST_EMPTY(&t4_uld_list)) {
8447 sx_sunlock(&t4_uld_list_lock);
8448 sx_sunlock(&t4_list_lock);
8453 while (tries++ < 5 && t4_sge_extfree_refs() != 0) {
8454 uprintf("%ju clusters with custom free routine "
8455 "still is use.\n", t4_sge_extfree_refs());
8456 pause("t4unload", 2 * hz);
8459 sx_sunlock(&t4_uld_list_lock);
8461 sx_sunlock(&t4_list_lock);
8463 if (t4_sge_extfree_refs() == 0) {
8464 t4_tracer_modunload();
8466 sx_destroy(&t4_uld_list_lock);
8468 sx_destroy(&t4_list_lock);
8473 loaded++; /* undo earlier decrement */
8484 static devclass_t t4_devclass, t5_devclass;
8485 static devclass_t cxgbe_devclass, cxl_devclass;
8487 DRIVER_MODULE(t4nex, pci, t4_driver, t4_devclass, mod_event, 0);
8488 MODULE_VERSION(t4nex, 1);
8489 MODULE_DEPEND(t4nex, firmware, 1, 1, 1);
8491 DRIVER_MODULE(t5nex, pci, t5_driver, t5_devclass, mod_event, 0);
8492 MODULE_VERSION(t5nex, 1);
8493 MODULE_DEPEND(t5nex, firmware, 1, 1, 1);
8495 DRIVER_MODULE(cxgbe, t4nex, cxgbe_driver, cxgbe_devclass, 0, 0);
8496 MODULE_VERSION(cxgbe, 1);
8498 DRIVER_MODULE(cxl, t5nex, cxl_driver, cxl_devclass, 0, 0);
8499 MODULE_VERSION(cxl, 1);