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>
59 #include "common/common.h"
60 #include "common/t4_msg.h"
61 #include "common/t4_regs.h"
62 #include "common/t4_regs_values.h"
66 /* T4 bus driver interface */
67 static int t4_probe(device_t);
68 static int t4_attach(device_t);
69 static int t4_detach(device_t);
70 static device_method_t t4_methods[] = {
71 DEVMETHOD(device_probe, t4_probe),
72 DEVMETHOD(device_attach, t4_attach),
73 DEVMETHOD(device_detach, t4_detach),
77 static driver_t t4_driver = {
80 sizeof(struct adapter)
84 /* T4 port (cxgbe) interface */
85 static int cxgbe_probe(device_t);
86 static int cxgbe_attach(device_t);
87 static int cxgbe_detach(device_t);
88 static device_method_t cxgbe_methods[] = {
89 DEVMETHOD(device_probe, cxgbe_probe),
90 DEVMETHOD(device_attach, cxgbe_attach),
91 DEVMETHOD(device_detach, cxgbe_detach),
94 static driver_t cxgbe_driver = {
97 sizeof(struct port_info)
100 static d_ioctl_t t4_ioctl;
101 static d_open_t t4_open;
102 static d_close_t t4_close;
104 static struct cdevsw t4_cdevsw = {
105 .d_version = D_VERSION,
113 /* ifnet + media interface */
114 static void cxgbe_init(void *);
115 static int cxgbe_ioctl(struct ifnet *, unsigned long, caddr_t);
116 static int cxgbe_transmit(struct ifnet *, struct mbuf *);
117 static void cxgbe_qflush(struct ifnet *);
118 static int cxgbe_media_change(struct ifnet *);
119 static void cxgbe_media_status(struct ifnet *, struct ifmediareq *);
121 MALLOC_DEFINE(M_CXGBE, "cxgbe", "Chelsio T4 Ethernet driver and services");
124 * Correct lock order when you need to acquire multiple locks is t4_list_lock,
125 * then ADAPTER_LOCK, then t4_uld_list_lock.
127 static struct mtx t4_list_lock;
128 static SLIST_HEAD(, adapter) t4_list;
130 static struct mtx t4_uld_list_lock;
131 static SLIST_HEAD(, uld_info) t4_uld_list;
135 * Tunables. See tweak_tunables() too.
139 * Number of queues for tx and rx, 10G and 1G, NIC and offload.
142 static int t4_ntxq10g = -1;
143 TUNABLE_INT("hw.cxgbe.ntxq10g", &t4_ntxq10g);
146 static int t4_nrxq10g = -1;
147 TUNABLE_INT("hw.cxgbe.nrxq10g", &t4_nrxq10g);
150 static int t4_ntxq1g = -1;
151 TUNABLE_INT("hw.cxgbe.ntxq1g", &t4_ntxq1g);
154 static int t4_nrxq1g = -1;
155 TUNABLE_INT("hw.cxgbe.nrxq1g", &t4_nrxq1g);
158 #define NOFLDTXQ_10G 8
159 static int t4_nofldtxq10g = -1;
160 TUNABLE_INT("hw.cxgbe.nofldtxq10g", &t4_nofldtxq10g);
162 #define NOFLDRXQ_10G 2
163 static int t4_nofldrxq10g = -1;
164 TUNABLE_INT("hw.cxgbe.nofldrxq10g", &t4_nofldrxq10g);
166 #define NOFLDTXQ_1G 2
167 static int t4_nofldtxq1g = -1;
168 TUNABLE_INT("hw.cxgbe.nofldtxq1g", &t4_nofldtxq1g);
170 #define NOFLDRXQ_1G 1
171 static int t4_nofldrxq1g = -1;
172 TUNABLE_INT("hw.cxgbe.nofldrxq1g", &t4_nofldrxq1g);
176 * Holdoff parameters for 10G and 1G ports.
178 #define TMR_IDX_10G 1
179 static int t4_tmr_idx_10g = TMR_IDX_10G;
180 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_10G", &t4_tmr_idx_10g);
182 #define PKTC_IDX_10G (-1)
183 static int t4_pktc_idx_10g = PKTC_IDX_10G;
184 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_10G", &t4_pktc_idx_10g);
187 static int t4_tmr_idx_1g = TMR_IDX_1G;
188 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_1G", &t4_tmr_idx_1g);
190 #define PKTC_IDX_1G (-1)
191 static int t4_pktc_idx_1g = PKTC_IDX_1G;
192 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_1G", &t4_pktc_idx_1g);
195 * Size (# of entries) of each tx and rx queue.
197 static unsigned int t4_qsize_txq = TX_EQ_QSIZE;
198 TUNABLE_INT("hw.cxgbe.qsize_txq", &t4_qsize_txq);
200 static unsigned int t4_qsize_rxq = RX_IQ_QSIZE;
201 TUNABLE_INT("hw.cxgbe.qsize_rxq", &t4_qsize_rxq);
204 * Interrupt types allowed (bits 0, 1, 2 = INTx, MSI, MSI-X respectively).
206 static int t4_intr_types = INTR_MSIX | INTR_MSI | INTR_INTX;
207 TUNABLE_INT("hw.cxgbe.interrupt_types", &t4_intr_types);
210 * Configuration file.
212 static char t4_cfg_file[32] = "default";
213 TUNABLE_STR("hw.cxgbe.config_file", t4_cfg_file, sizeof(t4_cfg_file));
216 * ASIC features that will be used. Disable the ones you don't want so that the
217 * chip resources aren't wasted on features that will not be used.
219 static int t4_linkcaps_allowed = 0; /* No DCBX, PPP, etc. by default */
220 TUNABLE_INT("hw.cxgbe.linkcaps_allowed", &t4_linkcaps_allowed);
222 static int t4_niccaps_allowed = FW_CAPS_CONFIG_NIC;
223 TUNABLE_INT("hw.cxgbe.niccaps_allowed", &t4_niccaps_allowed);
225 static int t4_toecaps_allowed = -1;
226 TUNABLE_INT("hw.cxgbe.toecaps_allowed", &t4_toecaps_allowed);
228 static int t4_rdmacaps_allowed = 0;
229 TUNABLE_INT("hw.cxgbe.rdmacaps_allowed", &t4_rdmacaps_allowed);
231 static int t4_iscsicaps_allowed = 0;
232 TUNABLE_INT("hw.cxgbe.iscsicaps_allowed", &t4_iscsicaps_allowed);
234 static int t4_fcoecaps_allowed = 0;
235 TUNABLE_INT("hw.cxgbe.fcoecaps_allowed", &t4_fcoecaps_allowed);
237 struct intrs_and_queues {
238 int intr_type; /* INTx, MSI, or MSI-X */
239 int nirq; /* Number of vectors */
241 int ntxq10g; /* # of NIC txq's for each 10G port */
242 int nrxq10g; /* # of NIC rxq's for each 10G port */
243 int ntxq1g; /* # of NIC txq's for each 1G port */
244 int nrxq1g; /* # of NIC rxq's for each 1G port */
246 int nofldtxq10g; /* # of TOE txq's for each 10G port */
247 int nofldrxq10g; /* # of TOE rxq's for each 10G port */
248 int nofldtxq1g; /* # of TOE txq's for each 1G port */
249 int nofldrxq1g; /* # of TOE rxq's for each 1G port */
253 struct filter_entry {
254 uint32_t valid:1; /* filter allocated and valid */
255 uint32_t locked:1; /* filter is administratively locked */
256 uint32_t pending:1; /* filter action is pending firmware reply */
257 uint32_t smtidx:8; /* Source MAC Table index for smac */
258 struct l2t_entry *l2t; /* Layer Two Table entry for dmac */
260 struct t4_filter_specification fs;
264 XGMAC_MTU = (1 << 0),
265 XGMAC_PROMISC = (1 << 1),
266 XGMAC_ALLMULTI = (1 << 2),
267 XGMAC_VLANEX = (1 << 3),
268 XGMAC_UCADDR = (1 << 4),
269 XGMAC_MCADDRS = (1 << 5),
274 static int map_bars(struct adapter *);
275 static void setup_memwin(struct adapter *);
276 static int cfg_itype_and_nqueues(struct adapter *, int, int,
277 struct intrs_and_queues *);
278 static int prep_firmware(struct adapter *);
279 static int upload_config_file(struct adapter *, const struct firmware *,
280 uint32_t *, uint32_t *);
281 static int partition_resources(struct adapter *, const struct firmware *);
282 static int get_params__pre_init(struct adapter *);
283 static int get_params__post_init(struct adapter *);
284 static void t4_set_desc(struct adapter *);
285 static void build_medialist(struct port_info *);
286 static int update_mac_settings(struct port_info *, int);
287 static int cxgbe_init_synchronized(struct port_info *);
288 static int cxgbe_uninit_synchronized(struct port_info *);
289 static int setup_intr_handlers(struct adapter *);
290 static int adapter_full_init(struct adapter *);
291 static int adapter_full_uninit(struct adapter *);
292 static int port_full_init(struct port_info *);
293 static int port_full_uninit(struct port_info *);
294 static void quiesce_eq(struct adapter *, struct sge_eq *);
295 static void quiesce_iq(struct adapter *, struct sge_iq *);
296 static void quiesce_fl(struct adapter *, struct sge_fl *);
297 static int t4_alloc_irq(struct adapter *, struct irq *, int rid,
298 driver_intr_t *, void *, char *);
299 static int t4_free_irq(struct adapter *, struct irq *);
300 static void reg_block_dump(struct adapter *, uint8_t *, unsigned int,
302 static void t4_get_regs(struct adapter *, struct t4_regdump *, uint8_t *);
303 static void cxgbe_tick(void *);
304 static void cxgbe_vlan_config(void *, struct ifnet *, uint16_t);
305 static int cpl_not_handled(struct sge_iq *, const struct rss_header *,
307 static int an_not_handled(struct sge_iq *, const struct rsp_ctrl *);
308 static int fw_msg_not_handled(struct adapter *, const __be64 *);
309 static int t4_sysctls(struct adapter *);
310 static int cxgbe_sysctls(struct port_info *);
311 static int sysctl_int_array(SYSCTL_HANDLER_ARGS);
312 static int sysctl_bitfield(SYSCTL_HANDLER_ARGS);
313 static int sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS);
314 static int sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS);
315 static int sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS);
316 static int sysctl_qsize_txq(SYSCTL_HANDLER_ARGS);
317 static int sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS);
319 static int sysctl_cctrl(SYSCTL_HANDLER_ARGS);
320 static int sysctl_cpl_stats(SYSCTL_HANDLER_ARGS);
321 static int sysctl_ddp_stats(SYSCTL_HANDLER_ARGS);
322 static int sysctl_devlog(SYSCTL_HANDLER_ARGS);
323 static int sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS);
324 static int sysctl_hw_sched(SYSCTL_HANDLER_ARGS);
325 static int sysctl_lb_stats(SYSCTL_HANDLER_ARGS);
326 static int sysctl_meminfo(SYSCTL_HANDLER_ARGS);
327 static int sysctl_path_mtus(SYSCTL_HANDLER_ARGS);
328 static int sysctl_pm_stats(SYSCTL_HANDLER_ARGS);
329 static int sysctl_rdma_stats(SYSCTL_HANDLER_ARGS);
330 static int sysctl_tcp_stats(SYSCTL_HANDLER_ARGS);
331 static int sysctl_tids(SYSCTL_HANDLER_ARGS);
332 static int sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS);
333 static int sysctl_tx_rate(SYSCTL_HANDLER_ARGS);
335 static inline void txq_start(struct ifnet *, struct sge_txq *);
336 static uint32_t fconf_to_mode(uint32_t);
337 static uint32_t mode_to_fconf(uint32_t);
338 static uint32_t fspec_to_fconf(struct t4_filter_specification *);
339 static int get_filter_mode(struct adapter *, uint32_t *);
340 static int set_filter_mode(struct adapter *, uint32_t);
341 static inline uint64_t get_filter_hits(struct adapter *, uint32_t);
342 static int get_filter(struct adapter *, struct t4_filter *);
343 static int set_filter(struct adapter *, struct t4_filter *);
344 static int del_filter(struct adapter *, struct t4_filter *);
345 static void clear_filter(struct filter_entry *);
346 static int set_filter_wr(struct adapter *, int);
347 static int del_filter_wr(struct adapter *, int);
348 static int get_sge_context(struct adapter *, struct t4_sge_context *);
349 static int load_fw(struct adapter *, struct t4_data *);
350 static int read_card_mem(struct adapter *, struct t4_mem_range *);
351 static int read_i2c(struct adapter *, struct t4_i2c_data *);
353 static int toe_capability(struct port_info *, int);
355 static int t4_mod_event(module_t, int, void *);
361 {0xa000, "Chelsio Terminator 4 FPGA"},
362 {0x4400, "Chelsio T440-dbg"},
363 {0x4401, "Chelsio T420-CR"},
364 {0x4402, "Chelsio T422-CR"},
365 {0x4403, "Chelsio T440-CR"},
366 {0x4404, "Chelsio T420-BCH"},
367 {0x4405, "Chelsio T440-BCH"},
368 {0x4406, "Chelsio T440-CH"},
369 {0x4407, "Chelsio T420-SO"},
370 {0x4408, "Chelsio T420-CX"},
371 {0x4409, "Chelsio T420-BT"},
372 {0x440a, "Chelsio T404-BT"},
373 {0x440e, "Chelsio T440-LP-CR"},
378 * service_iq() has an iq and needs the fl. Offset of fl from the iq should be
379 * exactly the same for both rxq and ofld_rxq.
381 CTASSERT(offsetof(struct sge_ofld_rxq, iq) == offsetof(struct sge_rxq, iq));
382 CTASSERT(offsetof(struct sge_ofld_rxq, fl) == offsetof(struct sge_rxq, fl));
385 /* No easy way to include t4_msg.h before adapter.h so we check this way */
386 CTASSERT(nitems(((struct adapter *)0)->cpl_handler) == NUM_CPL_CMDS);
387 CTASSERT(nitems(((struct adapter *)0)->fw_msg_handler) == NUM_FW6_TYPES);
390 t4_probe(device_t dev)
393 uint16_t v = pci_get_vendor(dev);
394 uint16_t d = pci_get_device(dev);
395 uint8_t f = pci_get_function(dev);
397 if (v != PCI_VENDOR_ID_CHELSIO)
400 /* Attach only to PF0 of the FPGA */
401 if (d == 0xa000 && f != 0)
404 for (i = 0; i < nitems(t4_pciids); i++) {
405 if (d == t4_pciids[i].device) {
406 device_set_desc(dev, t4_pciids[i].desc);
407 return (BUS_PROBE_DEFAULT);
415 t4_attach(device_t dev)
418 int rc = 0, i, n10g, n1g, rqidx, tqidx;
419 struct intrs_and_queues iaq;
422 int ofld_rqidx, ofld_tqidx;
425 sc = device_get_softc(dev);
428 pci_enable_busmaster(dev);
429 if (pci_find_cap(dev, PCIY_EXPRESS, &i) == 0) {
432 pci_set_max_read_req(dev, 4096);
433 v = pci_read_config(dev, i + PCIER_DEVICE_CTL, 2);
434 v |= PCIEM_CTL_RELAXED_ORD_ENABLE;
435 pci_write_config(dev, i + PCIER_DEVICE_CTL, v, 2);
438 snprintf(sc->lockname, sizeof(sc->lockname), "%s",
439 device_get_nameunit(dev));
440 mtx_init(&sc->sc_lock, sc->lockname, 0, MTX_DEF);
441 mtx_lock(&t4_list_lock);
442 SLIST_INSERT_HEAD(&t4_list, sc, link);
443 mtx_unlock(&t4_list_lock);
445 mtx_init(&sc->sfl_lock, "starving freelists", 0, MTX_DEF);
446 TAILQ_INIT(&sc->sfl);
447 callout_init(&sc->sfl_callout, CALLOUT_MPSAFE);
451 goto done; /* error message displayed already */
454 * This is the real PF# to which we're attaching. Works from within PCI
455 * passthrough environments too, where pci_get_function() could return a
456 * different PF# depending on the passthrough configuration. We need to
457 * use the real PF# in all our communication with the firmware.
459 sc->pf = G_SOURCEPF(t4_read_reg(sc, A_PL_WHOAMI));
462 memset(sc->chan_map, 0xff, sizeof(sc->chan_map));
463 sc->an_handler = an_not_handled;
464 for (i = 0; i < nitems(sc->cpl_handler); i++)
465 sc->cpl_handler[i] = cpl_not_handled;
466 for (i = 0; i < nitems(sc->fw_msg_handler); i++)
467 sc->fw_msg_handler[i] = fw_msg_not_handled;
468 t4_register_cpl_handler(sc, CPL_SET_TCB_RPL, t4_filter_rpl);
470 /* Prepare the adapter for operation */
471 rc = -t4_prep_adapter(sc);
473 device_printf(dev, "failed to prepare adapter: %d.\n", rc);
478 * Do this really early, with the memory windows set up even before the
479 * character device. The userland tool's register i/o and mem read
480 * will work even in "recovery mode".
483 sc->cdev = make_dev(&t4_cdevsw, device_get_unit(dev), UID_ROOT,
484 GID_WHEEL, 0600, "%s", device_get_nameunit(dev));
485 sc->cdev->si_drv1 = sc;
487 /* Go no further if recovery mode has been requested. */
488 if (TUNABLE_INT_FETCH("hw.cxgbe.sos", &i) && i != 0) {
489 device_printf(dev, "recovery mode.\n");
493 /* Prepare the firmware for operation */
494 rc = prep_firmware(sc);
496 goto done; /* error message displayed already */
498 rc = get_params__pre_init(sc);
500 goto done; /* error message displayed already */
502 rc = t4_sge_init(sc);
504 goto done; /* error message displayed already */
506 if (sc->flags & MASTER_PF) {
507 /* get basic stuff going */
508 rc = -t4_fw_initialize(sc, sc->mbox);
510 device_printf(dev, "early init failed: %d.\n", rc);
515 rc = get_params__post_init(sc);
517 goto done; /* error message displayed already */
519 if (sc->flags & MASTER_PF) {
520 uint16_t indsz = min(RX_COPY_THRESHOLD - 1, M_INDICATESIZE);
522 /* final tweaks to some settings */
524 t4_load_mtus(sc, sc->params.mtus, sc->params.a_wnd,
526 /* 4K, 16K, 64K, 256K DDP "page sizes" */
527 t4_write_reg(sc, A_ULP_RX_TDDP_PSZ, V_HPZ0(0) | V_HPZ1(2) |
528 V_HPZ2(4) | V_HPZ3(6));
529 t4_set_reg_field(sc, A_ULP_RX_CTL, F_TDDPTAGTCB, F_TDDPTAGTCB);
530 t4_set_reg_field(sc, A_TP_PARA_REG5,
531 V_INDICATESIZE(M_INDICATESIZE) |
532 F_REARMDDPOFFSET | F_RESETDDPOFFSET,
533 V_INDICATESIZE(indsz) |
534 F_REARMDDPOFFSET | F_RESETDDPOFFSET);
537 * XXX: Verify that we can live with whatever the master driver
538 * has done so far, and hope that it doesn't change any global
539 * setting from underneath us in the future.
543 t4_read_indirect(sc, A_TP_PIO_ADDR, A_TP_PIO_DATA, &sc->filter_mode, 1,
546 for (i = 0; i < NCHAN; i++)
547 sc->params.tp.tx_modq[i] = i;
549 rc = t4_create_dma_tag(sc);
551 goto done; /* error message displayed already */
554 * First pass over all the ports - allocate VIs and initialize some
555 * basic parameters like mac address, port type, etc. We also figure
556 * out whether a port is 10G or 1G and use that information when
557 * calculating how many interrupts to attempt to allocate.
560 for_each_port(sc, i) {
561 struct port_info *pi;
563 pi = malloc(sizeof(*pi), M_CXGBE, M_ZERO | M_WAITOK);
566 /* These must be set before t4_port_init */
570 /* Allocate the vi and initialize parameters like mac addr */
571 rc = -t4_port_init(pi, sc->mbox, sc->pf, 0);
573 device_printf(dev, "unable to initialize port %d: %d\n",
580 snprintf(pi->lockname, sizeof(pi->lockname), "%sp%d",
581 device_get_nameunit(dev), i);
582 mtx_init(&pi->pi_lock, pi->lockname, 0, MTX_DEF);
584 if (is_10G_port(pi)) {
586 pi->tmr_idx = t4_tmr_idx_10g;
587 pi->pktc_idx = t4_pktc_idx_10g;
590 pi->tmr_idx = t4_tmr_idx_1g;
591 pi->pktc_idx = t4_pktc_idx_1g;
594 pi->xact_addr_filt = -1;
596 pi->qsize_rxq = t4_qsize_rxq;
597 pi->qsize_txq = t4_qsize_txq;
599 pi->dev = device_add_child(dev, "cxgbe", -1);
600 if (pi->dev == NULL) {
602 "failed to add device for port %d.\n", i);
606 device_set_softc(pi->dev, pi);
610 * Interrupt type, # of interrupts, # of rx/tx queues, etc.
612 rc = cfg_itype_and_nqueues(sc, n10g, n1g, &iaq);
614 goto done; /* error message displayed already */
616 sc->intr_type = iaq.intr_type;
617 sc->intr_count = iaq.nirq;
618 sc->flags |= iaq.intr_flags;
621 s->nrxq = n10g * iaq.nrxq10g + n1g * iaq.nrxq1g;
622 s->ntxq = n10g * iaq.ntxq10g + n1g * iaq.ntxq1g;
623 s->neq = s->ntxq + s->nrxq; /* the free list in an rxq is an eq */
624 s->neq += sc->params.nports + 1;/* ctrl queues: 1 per port + 1 mgmt */
625 s->niq = s->nrxq + 1; /* 1 extra for firmware event queue */
628 if (is_offload(sc)) {
630 s->nofldrxq = n10g * iaq.nofldrxq10g + n1g * iaq.nofldrxq1g;
631 s->nofldtxq = n10g * iaq.nofldtxq10g + n1g * iaq.nofldtxq1g;
632 s->neq += s->nofldtxq + s->nofldrxq;
633 s->niq += s->nofldrxq;
635 s->ofld_rxq = malloc(s->nofldrxq * sizeof(struct sge_ofld_rxq),
636 M_CXGBE, M_ZERO | M_WAITOK);
637 s->ofld_txq = malloc(s->nofldtxq * sizeof(struct sge_wrq),
638 M_CXGBE, M_ZERO | M_WAITOK);
642 s->ctrlq = malloc(sc->params.nports * sizeof(struct sge_wrq), M_CXGBE,
644 s->rxq = malloc(s->nrxq * sizeof(struct sge_rxq), M_CXGBE,
646 s->txq = malloc(s->ntxq * sizeof(struct sge_txq), M_CXGBE,
648 s->iqmap = malloc(s->niq * sizeof(struct sge_iq *), M_CXGBE,
650 s->eqmap = malloc(s->neq * sizeof(struct sge_eq *), M_CXGBE,
653 sc->irq = malloc(sc->intr_count * sizeof(struct irq), M_CXGBE,
656 t4_init_l2t(sc, M_WAITOK);
659 * Second pass over the ports. This time we know the number of rx and
660 * tx queues that each port should get.
664 ofld_rqidx = ofld_tqidx = 0;
666 for_each_port(sc, i) {
667 struct port_info *pi = sc->port[i];
672 pi->first_rxq = rqidx;
673 pi->first_txq = tqidx;
674 if (is_10G_port(pi)) {
675 pi->nrxq = iaq.nrxq10g;
676 pi->ntxq = iaq.ntxq10g;
678 pi->nrxq = iaq.nrxq1g;
679 pi->ntxq = iaq.ntxq1g;
686 if (is_offload(sc)) {
687 pi->first_ofld_rxq = ofld_rqidx;
688 pi->first_ofld_txq = ofld_tqidx;
689 if (is_10G_port(pi)) {
690 pi->nofldrxq = iaq.nofldrxq10g;
691 pi->nofldtxq = iaq.nofldtxq10g;
693 pi->nofldrxq = iaq.nofldrxq1g;
694 pi->nofldtxq = iaq.nofldtxq1g;
696 ofld_rqidx += pi->nofldrxq;
697 ofld_tqidx += pi->nofldtxq;
702 rc = setup_intr_handlers(sc);
705 "failed to setup interrupt handlers: %d\n", rc);
709 rc = bus_generic_attach(dev);
712 "failed to attach all child ports: %d\n", rc);
717 "PCIe x%d, %d ports, %d %s interrupt%s, %d eq, %d iq\n",
718 sc->params.pci.width, sc->params.nports, sc->intr_count,
719 sc->intr_type == INTR_MSIX ? "MSI-X" :
720 (sc->intr_type == INTR_MSI ? "MSI" : "INTx"),
721 sc->intr_count > 1 ? "s" : "", sc->sge.neq, sc->sge.niq);
726 if (rc != 0 && sc->cdev) {
727 /* cdev was created and so cxgbetool works; recover that way. */
729 "error during attach, adapter is now in recovery mode.\n");
745 t4_detach(device_t dev)
748 struct port_info *pi;
751 sc = device_get_softc(dev);
753 if (sc->flags & FULL_INIT_DONE)
757 destroy_dev(sc->cdev);
761 rc = bus_generic_detach(dev);
764 "failed to detach child devices: %d\n", rc);
768 for (i = 0; i < sc->intr_count; i++)
769 t4_free_irq(sc, &sc->irq[i]);
771 for (i = 0; i < MAX_NPORTS; i++) {
774 t4_free_vi(pi->adapter, sc->mbox, sc->pf, 0, pi->viid);
776 device_delete_child(dev, pi->dev);
778 mtx_destroy(&pi->pi_lock);
783 if (sc->flags & FULL_INIT_DONE)
784 adapter_full_uninit(sc);
786 if (sc->flags & FW_OK)
787 t4_fw_bye(sc, sc->mbox);
789 if (sc->intr_type == INTR_MSI || sc->intr_type == INTR_MSIX)
790 pci_release_msi(dev);
793 bus_release_resource(dev, SYS_RES_MEMORY, sc->regs_rid,
797 bus_release_resource(dev, SYS_RES_MEMORY, sc->msix_rid,
801 t4_free_l2t(sc->l2t);
804 free(sc->sge.ofld_rxq, M_CXGBE);
805 free(sc->sge.ofld_txq, M_CXGBE);
807 free(sc->irq, M_CXGBE);
808 free(sc->sge.rxq, M_CXGBE);
809 free(sc->sge.txq, M_CXGBE);
810 free(sc->sge.ctrlq, M_CXGBE);
811 free(sc->sge.iqmap, M_CXGBE);
812 free(sc->sge.eqmap, M_CXGBE);
813 free(sc->tids.ftid_tab, M_CXGBE);
814 t4_destroy_dma_tag(sc);
815 if (mtx_initialized(&sc->sc_lock)) {
816 mtx_lock(&t4_list_lock);
817 SLIST_REMOVE(&t4_list, sc, adapter, link);
818 mtx_unlock(&t4_list_lock);
819 mtx_destroy(&sc->sc_lock);
822 if (mtx_initialized(&sc->tids.ftid_lock))
823 mtx_destroy(&sc->tids.ftid_lock);
824 if (mtx_initialized(&sc->sfl_lock))
825 mtx_destroy(&sc->sfl_lock);
827 bzero(sc, sizeof(*sc));
834 cxgbe_probe(device_t dev)
837 struct port_info *pi = device_get_softc(dev);
839 snprintf(buf, sizeof(buf), "port %d", pi->port_id);
840 device_set_desc_copy(dev, buf);
842 return (BUS_PROBE_DEFAULT);
845 #define T4_CAP (IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_HWCSUM | \
846 IFCAP_VLAN_HWCSUM | IFCAP_TSO | IFCAP_JUMBO_MTU | IFCAP_LRO | \
847 IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWCSUM_IPV6)
848 #define T4_CAP_ENABLE (T4_CAP)
851 cxgbe_attach(device_t dev)
853 struct port_info *pi = device_get_softc(dev);
856 /* Allocate an ifnet and set it up */
857 ifp = if_alloc(IFT_ETHER);
859 device_printf(dev, "Cannot allocate ifnet\n");
865 callout_init(&pi->tick, CALLOUT_MPSAFE);
867 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
868 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
870 ifp->if_init = cxgbe_init;
871 ifp->if_ioctl = cxgbe_ioctl;
872 ifp->if_transmit = cxgbe_transmit;
873 ifp->if_qflush = cxgbe_qflush;
875 ifp->if_capabilities = T4_CAP;
877 if (is_offload(pi->adapter))
878 ifp->if_capabilities |= IFCAP_TOE;
880 ifp->if_capenable = T4_CAP_ENABLE;
881 ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_IP | CSUM_TSO |
882 CSUM_UDP_IPV6 | CSUM_TCP_IPV6;
884 /* Initialize ifmedia for this port */
885 ifmedia_init(&pi->media, IFM_IMASK, cxgbe_media_change,
889 pi->vlan_c = EVENTHANDLER_REGISTER(vlan_config, cxgbe_vlan_config, ifp,
890 EVENTHANDLER_PRI_ANY);
892 ether_ifattach(ifp, pi->hw_addr);
895 if (is_offload(pi->adapter)) {
897 "%d txq, %d rxq (NIC); %d txq, %d rxq (TOE)\n",
898 pi->ntxq, pi->nrxq, pi->nofldtxq, pi->nofldrxq);
901 device_printf(dev, "%d txq, %d rxq\n", pi->ntxq, pi->nrxq);
909 cxgbe_detach(device_t dev)
911 struct port_info *pi = device_get_softc(dev);
912 struct adapter *sc = pi->adapter;
913 struct ifnet *ifp = pi->ifp;
915 /* Tell if_ioctl and if_init that the port is going away */
920 mtx_sleep(&sc->flags, &sc->sc_lock, 0, "t4detach", 0);
923 sc->last_op = "t4detach";
924 sc->last_op_thr = curthread;
929 EVENTHANDLER_DEREGISTER(vlan_config, pi->vlan_c);
932 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
933 callout_stop(&pi->tick);
935 callout_drain(&pi->tick);
937 /* Let detach proceed even if these fail. */
938 cxgbe_uninit_synchronized(pi);
939 port_full_uninit(pi);
941 ifmedia_removeall(&pi->media);
942 ether_ifdetach(pi->ifp);
954 cxgbe_init(void *arg)
956 struct port_info *pi = arg;
957 struct adapter *sc = pi->adapter;
959 if (begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4init") != 0)
961 cxgbe_init_synchronized(pi);
962 end_synchronized_op(sc, 0);
966 cxgbe_ioctl(struct ifnet *ifp, unsigned long cmd, caddr_t data)
968 int rc = 0, mtu, flags;
969 struct port_info *pi = ifp->if_softc;
970 struct adapter *sc = pi->adapter;
971 struct ifreq *ifr = (struct ifreq *)data;
977 if ((mtu < ETHERMIN) || (mtu > ETHERMTU_JUMBO))
980 rc = begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4mtu");
984 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
985 t4_update_fl_bufsize(ifp);
986 rc = update_mac_settings(pi, XGMAC_MTU);
988 end_synchronized_op(sc, 0);
992 rc = begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4flg");
996 if (ifp->if_flags & IFF_UP) {
997 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
998 flags = pi->if_flags;
999 if ((ifp->if_flags ^ flags) &
1000 (IFF_PROMISC | IFF_ALLMULTI)) {
1001 rc = update_mac_settings(pi,
1002 XGMAC_PROMISC | XGMAC_ALLMULTI);
1005 rc = cxgbe_init_synchronized(pi);
1006 pi->if_flags = ifp->if_flags;
1007 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1008 rc = cxgbe_uninit_synchronized(pi);
1009 end_synchronized_op(sc, 0);
1013 case SIOCDELMULTI: /* these two are called with a mutex held :-( */
1014 rc = begin_synchronized_op(sc, pi, HOLD_LOCK, "t4multi");
1017 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1018 rc = update_mac_settings(pi, XGMAC_MCADDRS);
1019 end_synchronized_op(sc, LOCK_HELD);
1023 rc = begin_synchronized_op(sc, pi, SLEEP_OK | INTR_OK, "t4cap");
1027 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1028 if (mask & IFCAP_TXCSUM) {
1029 ifp->if_capenable ^= IFCAP_TXCSUM;
1030 ifp->if_hwassist ^= (CSUM_TCP | CSUM_UDP | CSUM_IP);
1032 if (IFCAP_TSO4 & ifp->if_capenable &&
1033 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1034 ifp->if_capenable &= ~IFCAP_TSO4;
1036 "tso4 disabled due to -txcsum.\n");
1039 if (mask & IFCAP_TXCSUM_IPV6) {
1040 ifp->if_capenable ^= IFCAP_TXCSUM_IPV6;
1041 ifp->if_hwassist ^= (CSUM_UDP_IPV6 | CSUM_TCP_IPV6);
1043 if (IFCAP_TSO6 & ifp->if_capenable &&
1044 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1045 ifp->if_capenable &= ~IFCAP_TSO6;
1047 "tso6 disabled due to -txcsum6.\n");
1050 if (mask & IFCAP_RXCSUM)
1051 ifp->if_capenable ^= IFCAP_RXCSUM;
1052 if (mask & IFCAP_RXCSUM_IPV6)
1053 ifp->if_capenable ^= IFCAP_RXCSUM_IPV6;
1056 * Note that we leave CSUM_TSO alone (it is always set). The
1057 * kernel takes both IFCAP_TSOx and CSUM_TSO into account before
1058 * sending a TSO request our way, so it's sufficient to toggle
1061 if (mask & IFCAP_TSO4) {
1062 if (!(IFCAP_TSO4 & ifp->if_capenable) &&
1063 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1064 if_printf(ifp, "enable txcsum first.\n");
1068 ifp->if_capenable ^= IFCAP_TSO4;
1070 if (mask & IFCAP_TSO6) {
1071 if (!(IFCAP_TSO6 & ifp->if_capenable) &&
1072 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1073 if_printf(ifp, "enable txcsum6 first.\n");
1077 ifp->if_capenable ^= IFCAP_TSO6;
1079 if (mask & IFCAP_LRO) {
1080 #if defined(INET) || defined(INET6)
1082 struct sge_rxq *rxq;
1084 ifp->if_capenable ^= IFCAP_LRO;
1085 for_each_rxq(pi, i, rxq) {
1086 if (ifp->if_capenable & IFCAP_LRO)
1087 rxq->iq.flags |= IQ_LRO_ENABLED;
1089 rxq->iq.flags &= ~IQ_LRO_ENABLED;
1094 if (mask & IFCAP_TOE) {
1095 int enable = (ifp->if_capenable ^ mask) & IFCAP_TOE;
1097 rc = toe_capability(pi, enable);
1101 ifp->if_capenable ^= mask;
1104 if (mask & IFCAP_VLAN_HWTAGGING) {
1105 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
1106 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1107 rc = update_mac_settings(pi, XGMAC_VLANEX);
1109 if (mask & IFCAP_VLAN_MTU) {
1110 ifp->if_capenable ^= IFCAP_VLAN_MTU;
1112 /* Need to find out how to disable auto-mtu-inflation */
1114 if (mask & IFCAP_VLAN_HWTSO)
1115 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
1116 if (mask & IFCAP_VLAN_HWCSUM)
1117 ifp->if_capenable ^= IFCAP_VLAN_HWCSUM;
1119 #ifdef VLAN_CAPABILITIES
1120 VLAN_CAPABILITIES(ifp);
1123 end_synchronized_op(sc, 0);
1128 ifmedia_ioctl(ifp, ifr, &pi->media, cmd);
1132 rc = ether_ioctl(ifp, cmd, data);
1139 cxgbe_transmit(struct ifnet *ifp, struct mbuf *m)
1141 struct port_info *pi = ifp->if_softc;
1142 struct adapter *sc = pi->adapter;
1143 struct sge_txq *txq = &sc->sge.txq[pi->first_txq];
1144 struct buf_ring *br;
1149 if (__predict_false(pi->link_cfg.link_ok == 0)) {
1154 if (m->m_flags & M_FLOWID)
1155 txq += (m->m_pkthdr.flowid % pi->ntxq);
1158 if (TXQ_TRYLOCK(txq) == 0) {
1159 struct sge_eq *eq = &txq->eq;
1162 * It is possible that t4_eth_tx finishes up and releases the
1163 * lock between the TRYLOCK above and the drbr_enqueue here. We
1164 * need to make sure that this mbuf doesn't just sit there in
1168 rc = drbr_enqueue(ifp, br, m);
1169 if (rc == 0 && callout_pending(&eq->tx_callout) == 0 &&
1170 !(eq->flags & EQ_DOOMED))
1171 callout_reset(&eq->tx_callout, 1, t4_tx_callout, eq);
1176 * txq->m is the mbuf that is held up due to a temporary shortage of
1177 * resources and it should be put on the wire first. Then what's in
1178 * drbr and finally the mbuf that was just passed in to us.
1180 * Return code should indicate the fate of the mbuf that was passed in
1184 TXQ_LOCK_ASSERT_OWNED(txq);
1185 if (drbr_needs_enqueue(ifp, br) || txq->m) {
1187 /* Queued for transmission. */
1189 rc = drbr_enqueue(ifp, br, m);
1190 m = txq->m ? txq->m : drbr_dequeue(ifp, br);
1191 (void) t4_eth_tx(ifp, txq, m);
1196 /* Direct transmission. */
1197 rc = t4_eth_tx(ifp, txq, m);
1198 if (rc != 0 && txq->m)
1199 rc = 0; /* held, will be transmitted soon (hopefully) */
1206 cxgbe_qflush(struct ifnet *ifp)
1208 struct port_info *pi = ifp->if_softc;
1209 struct sge_txq *txq;
1213 /* queues do not exist if !PORT_INIT_DONE. */
1214 if (pi->flags & PORT_INIT_DONE) {
1215 for_each_txq(pi, i, txq) {
1219 while ((m = buf_ring_dequeue_sc(txq->br)) != NULL)
1228 cxgbe_media_change(struct ifnet *ifp)
1230 struct port_info *pi = ifp->if_softc;
1232 device_printf(pi->dev, "%s unimplemented.\n", __func__);
1234 return (EOPNOTSUPP);
1238 cxgbe_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
1240 struct port_info *pi = ifp->if_softc;
1241 struct ifmedia_entry *cur = pi->media.ifm_cur;
1242 int speed = pi->link_cfg.speed;
1243 int data = (pi->port_type << 8) | pi->mod_type;
1245 if (cur->ifm_data != data) {
1246 build_medialist(pi);
1247 cur = pi->media.ifm_cur;
1250 ifmr->ifm_status = IFM_AVALID;
1251 if (!pi->link_cfg.link_ok)
1254 ifmr->ifm_status |= IFM_ACTIVE;
1256 /* active and current will differ iff current media is autoselect. */
1257 if (IFM_SUBTYPE(cur->ifm_media) != IFM_AUTO)
1260 ifmr->ifm_active = IFM_ETHER | IFM_FDX;
1261 if (speed == SPEED_10000)
1262 ifmr->ifm_active |= IFM_10G_T;
1263 else if (speed == SPEED_1000)
1264 ifmr->ifm_active |= IFM_1000_T;
1265 else if (speed == SPEED_100)
1266 ifmr->ifm_active |= IFM_100_TX;
1267 else if (speed == SPEED_10)
1268 ifmr->ifm_active |= IFM_10_T;
1270 KASSERT(0, ("%s: link up but speed unknown (%u)", __func__,
1275 t4_fatal_err(struct adapter *sc)
1277 t4_set_reg_field(sc, A_SGE_CONTROL, F_GLOBALENABLE, 0);
1278 t4_intr_disable(sc);
1279 log(LOG_EMERG, "%s: encountered fatal error, adapter stopped.\n",
1280 device_get_nameunit(sc->dev));
1284 map_bars(struct adapter *sc)
1286 sc->regs_rid = PCIR_BAR(0);
1287 sc->regs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
1288 &sc->regs_rid, RF_ACTIVE);
1289 if (sc->regs_res == NULL) {
1290 device_printf(sc->dev, "cannot map registers.\n");
1293 sc->bt = rman_get_bustag(sc->regs_res);
1294 sc->bh = rman_get_bushandle(sc->regs_res);
1295 sc->mmio_len = rman_get_size(sc->regs_res);
1297 sc->msix_rid = PCIR_BAR(4);
1298 sc->msix_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
1299 &sc->msix_rid, RF_ACTIVE);
1300 if (sc->msix_res == NULL) {
1301 device_printf(sc->dev, "cannot map MSI-X BAR.\n");
1309 setup_memwin(struct adapter *sc)
1314 * Read low 32b of bar0 indirectly via the hardware backdoor mechanism.
1315 * Works from within PCI passthrough environments too, where
1316 * rman_get_start() can return a different value. We need to program
1317 * the memory window decoders with the actual addresses that will be
1318 * coming across the PCIe link.
1320 bar0 = t4_hw_pci_read_cfg4(sc, PCIR_BAR(0));
1321 bar0 &= (uint32_t) PCIM_BAR_MEM_BASE;
1323 t4_write_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 0),
1324 (bar0 + MEMWIN0_BASE) | V_BIR(0) |
1325 V_WINDOW(ilog2(MEMWIN0_APERTURE) - 10));
1327 t4_write_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 1),
1328 (bar0 + MEMWIN1_BASE) | V_BIR(0) |
1329 V_WINDOW(ilog2(MEMWIN1_APERTURE) - 10));
1331 t4_write_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 2),
1332 (bar0 + MEMWIN2_BASE) | V_BIR(0) |
1333 V_WINDOW(ilog2(MEMWIN2_APERTURE) - 10));
1336 t4_read_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 2));
1340 cfg_itype_and_nqueues(struct adapter *sc, int n10g, int n1g,
1341 struct intrs_and_queues *iaq)
1343 int rc, itype, navail, nrxq10g, nrxq1g, n;
1344 int nofldrxq10g = 0, nofldrxq1g = 0;
1346 bzero(iaq, sizeof(*iaq));
1348 iaq->ntxq10g = t4_ntxq10g;
1349 iaq->ntxq1g = t4_ntxq1g;
1350 iaq->nrxq10g = nrxq10g = t4_nrxq10g;
1351 iaq->nrxq1g = nrxq1g = t4_nrxq1g;
1353 if (is_offload(sc)) {
1354 iaq->nofldtxq10g = t4_nofldtxq10g;
1355 iaq->nofldtxq1g = t4_nofldtxq1g;
1356 iaq->nofldrxq10g = nofldrxq10g = t4_nofldrxq10g;
1357 iaq->nofldrxq1g = nofldrxq1g = t4_nofldrxq1g;
1361 for (itype = INTR_MSIX; itype; itype >>= 1) {
1363 if ((itype & t4_intr_types) == 0)
1364 continue; /* not allowed */
1366 if (itype == INTR_MSIX)
1367 navail = pci_msix_count(sc->dev);
1368 else if (itype == INTR_MSI)
1369 navail = pci_msi_count(sc->dev);
1376 iaq->intr_type = itype;
1377 iaq->intr_flags = 0;
1380 * Best option: an interrupt vector for errors, one for the
1381 * firmware event queue, and one each for each rxq (NIC as well
1384 iaq->nirq = T4_EXTRA_INTR;
1385 iaq->nirq += n10g * (nrxq10g + nofldrxq10g);
1386 iaq->nirq += n1g * (nrxq1g + nofldrxq1g);
1387 if (iaq->nirq <= navail &&
1388 (itype != INTR_MSI || powerof2(iaq->nirq))) {
1389 iaq->intr_flags |= INTR_DIRECT;
1394 * Second best option: an interrupt vector for errors, one for
1395 * the firmware event queue, and one each for either NIC or
1398 iaq->nirq = T4_EXTRA_INTR;
1399 iaq->nirq += n10g * max(nrxq10g, nofldrxq10g);
1400 iaq->nirq += n1g * max(nrxq1g, nofldrxq1g);
1401 if (iaq->nirq <= navail &&
1402 (itype != INTR_MSI || powerof2(iaq->nirq)))
1406 * Next best option: an interrupt vector for errors, one for the
1407 * firmware event queue, and at least one per port. At this
1408 * point we know we'll have to downsize nrxq or nofldrxq to fit
1409 * what's available to us.
1411 iaq->nirq = T4_EXTRA_INTR;
1412 iaq->nirq += n10g + n1g;
1413 if (iaq->nirq <= navail) {
1414 int leftover = navail - iaq->nirq;
1417 int target = max(nrxq10g, nofldrxq10g);
1420 while (n < target && leftover >= n10g) {
1425 iaq->nrxq10g = min(n, nrxq10g);
1428 iaq->nofldrxq10g = min(n, nofldrxq10g);
1433 int target = max(nrxq1g, nofldrxq1g);
1436 while (n < target && leftover >= n1g) {
1441 iaq->nrxq1g = min(n, nrxq1g);
1444 iaq->nofldrxq1g = min(n, nofldrxq1g);
1448 if (itype != INTR_MSI || powerof2(iaq->nirq))
1453 * Least desirable option: one interrupt vector for everything.
1455 iaq->nirq = iaq->nrxq10g = iaq->nrxq1g = 1;
1458 iaq->nofldrxq10g = iaq->nofldrxq1g = 1;
1464 if (itype == INTR_MSIX)
1465 rc = pci_alloc_msix(sc->dev, &navail);
1466 else if (itype == INTR_MSI)
1467 rc = pci_alloc_msi(sc->dev, &navail);
1470 if (navail == iaq->nirq)
1474 * Didn't get the number requested. Use whatever number
1475 * the kernel is willing to allocate (it's in navail).
1477 device_printf(sc->dev, "fewer vectors than requested, "
1478 "type=%d, req=%d, rcvd=%d; will downshift req.\n",
1479 itype, iaq->nirq, navail);
1480 pci_release_msi(sc->dev);
1484 device_printf(sc->dev,
1485 "failed to allocate vectors:%d, type=%d, req=%d, rcvd=%d\n",
1486 itype, rc, iaq->nirq, navail);
1489 device_printf(sc->dev,
1490 "failed to find a usable interrupt type. "
1491 "allowed=%d, msi-x=%d, msi=%d, intx=1", t4_intr_types,
1492 pci_msix_count(sc->dev), pci_msi_count(sc->dev));
1498 * Install a compatible firmware (if required), establish contact with it (by
1499 * saying hello), and reset the device. If we end up as the master driver,
1500 * partition adapter resources by providing a configuration file to the
1504 prep_firmware(struct adapter *sc)
1506 const struct firmware *fw = NULL, *cfg = NULL, *default_cfg;
1508 enum dev_state state;
1510 default_cfg = firmware_get(T4_CFGNAME);
1512 /* Check firmware version and install a different one if necessary */
1513 rc = t4_check_fw_version(sc);
1514 snprintf(sc->fw_version, sizeof(sc->fw_version), "%u.%u.%u.%u",
1515 G_FW_HDR_FW_VER_MAJOR(sc->params.fw_vers),
1516 G_FW_HDR_FW_VER_MINOR(sc->params.fw_vers),
1517 G_FW_HDR_FW_VER_MICRO(sc->params.fw_vers),
1518 G_FW_HDR_FW_VER_BUILD(sc->params.fw_vers));
1522 fw = firmware_get(T4_FWNAME);
1524 const struct fw_hdr *hdr = (const void *)fw->data;
1526 v = ntohl(hdr->fw_ver);
1529 * The firmware module will not be used if it isn't the
1530 * same major version as what the driver was compiled
1533 if (G_FW_HDR_FW_VER_MAJOR(v) != FW_VERSION_MAJOR) {
1534 device_printf(sc->dev,
1535 "Found firmware image but version %d "
1536 "can not be used with this driver (%d)\n",
1537 G_FW_HDR_FW_VER_MAJOR(v), FW_VERSION_MAJOR);
1539 firmware_put(fw, FIRMWARE_UNLOAD);
1544 if (fw == NULL && rc < 0) {
1545 device_printf(sc->dev, "No usable firmware. "
1546 "card has %d.%d.%d, driver compiled with %d.%d.%d",
1547 G_FW_HDR_FW_VER_MAJOR(sc->params.fw_vers),
1548 G_FW_HDR_FW_VER_MINOR(sc->params.fw_vers),
1549 G_FW_HDR_FW_VER_MICRO(sc->params.fw_vers),
1550 FW_VERSION_MAJOR, FW_VERSION_MINOR,
1557 * Always upgrade, even for minor/micro/build mismatches.
1558 * Downgrade only for a major version mismatch or if
1559 * force_firmware_install was specified.
1561 if (fw != NULL && (rc < 0 || v > sc->params.fw_vers)) {
1562 device_printf(sc->dev,
1563 "installing firmware %d.%d.%d.%d on card.\n",
1564 G_FW_HDR_FW_VER_MAJOR(v), G_FW_HDR_FW_VER_MINOR(v),
1565 G_FW_HDR_FW_VER_MICRO(v), G_FW_HDR_FW_VER_BUILD(v));
1567 rc = -t4_load_fw(sc, fw->data, fw->datasize);
1569 device_printf(sc->dev,
1570 "failed to install firmware: %d\n", rc);
1574 (void) t4_check_fw_version(sc);
1575 snprintf(sc->fw_version,
1576 sizeof(sc->fw_version), "%u.%u.%u.%u",
1577 G_FW_HDR_FW_VER_MAJOR(sc->params.fw_vers),
1578 G_FW_HDR_FW_VER_MINOR(sc->params.fw_vers),
1579 G_FW_HDR_FW_VER_MICRO(sc->params.fw_vers),
1580 G_FW_HDR_FW_VER_BUILD(sc->params.fw_vers));
1585 /* Contact firmware. */
1586 rc = t4_fw_hello(sc, sc->mbox, sc->mbox, MASTER_MAY, &state);
1589 device_printf(sc->dev,
1590 "failed to connect to the firmware: %d.\n", rc);
1594 sc->flags |= MASTER_PF;
1597 rc = -t4_fw_reset(sc, sc->mbox, F_PIORSTMODE | F_PIORST);
1599 device_printf(sc->dev, "firmware reset failed: %d.\n", rc);
1600 if (rc != ETIMEDOUT && rc != EIO)
1601 t4_fw_bye(sc, sc->mbox);
1605 /* Partition adapter resources as specified in the config file. */
1606 if (sc->flags & MASTER_PF) {
1607 if (strncmp(t4_cfg_file, "default", sizeof(t4_cfg_file))) {
1610 snprintf(s, sizeof(s), "t4fw_cfg_%s", t4_cfg_file);
1611 cfg = firmware_get(s);
1613 device_printf(sc->dev,
1614 "unable to locate %s module, "
1615 "will use default config file.\n", s);
1619 rc = partition_resources(sc, cfg ? cfg : default_cfg);
1621 goto done; /* error message displayed already */
1628 firmware_put(fw, FIRMWARE_UNLOAD);
1630 firmware_put(cfg, FIRMWARE_UNLOAD);
1631 if (default_cfg != NULL)
1632 firmware_put(default_cfg, FIRMWARE_UNLOAD);
1637 #define FW_PARAM_DEV(param) \
1638 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
1639 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
1640 #define FW_PARAM_PFVF(param) \
1641 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
1642 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param))
1645 * Upload configuration file to card's memory.
1648 upload_config_file(struct adapter *sc, const struct firmware *fw, uint32_t *mt,
1652 uint32_t param, val, mtype, maddr, bar, off, win, remaining;
1655 /* Figure out where the firmware wants us to upload it. */
1656 param = FW_PARAM_DEV(CF);
1657 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
1659 /* Firmwares without config file support will fail this way */
1660 device_printf(sc->dev,
1661 "failed to query config file location: %d.\n", rc);
1664 *mt = mtype = G_FW_PARAMS_PARAM_Y(val);
1665 *ma = maddr = G_FW_PARAMS_PARAM_Z(val) << 16;
1668 device_printf(sc->dev,
1669 "cannot upload config file (type %u, addr %x).\n",
1674 /* Translate mtype/maddr to an address suitable for the PCIe window */
1675 val = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
1676 val &= F_EDRAM0_ENABLE | F_EDRAM1_ENABLE | F_EXT_MEM_ENABLE;
1678 case FW_MEMTYPE_CF_EDC0:
1679 if (!(val & F_EDRAM0_ENABLE))
1681 bar = t4_read_reg(sc, A_MA_EDRAM0_BAR);
1682 maddr += G_EDRAM0_BASE(bar) << 20;
1685 case FW_MEMTYPE_CF_EDC1:
1686 if (!(val & F_EDRAM1_ENABLE))
1688 bar = t4_read_reg(sc, A_MA_EDRAM1_BAR);
1689 maddr += G_EDRAM1_BASE(bar) << 20;
1692 case FW_MEMTYPE_CF_EXTMEM:
1693 if (!(val & F_EXT_MEM_ENABLE))
1695 bar = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
1696 maddr += G_EXT_MEM_BASE(bar) << 20;
1701 device_printf(sc->dev,
1702 "cannot upload config file (type %u, enabled %u).\n",
1708 * Position the PCIe window (we use memwin2) to the 16B aligned area
1709 * just at/before the upload location.
1712 off = maddr - win; /* offset from the start of the window. */
1713 t4_write_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, 2), win);
1714 t4_read_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, 2));
1716 remaining = fw->datasize;
1717 if (remaining > FLASH_CFG_MAX_SIZE ||
1718 remaining > MEMWIN2_APERTURE - off) {
1719 device_printf(sc->dev, "cannot upload config file all at once "
1720 "(size %u, max %u, room %u).\n",
1721 remaining, FLASH_CFG_MAX_SIZE, MEMWIN2_APERTURE - off);
1726 * XXX: sheer laziness. We deliberately added 4 bytes of useless
1727 * stuffing/comments at the end of the config file so it's ok to simply
1728 * throw away the last remaining bytes when the config file is not an
1729 * exact multiple of 4.
1732 for (i = 0; remaining >= 4; i += 4, remaining -= 4)
1733 t4_write_reg(sc, MEMWIN2_BASE + off + i, *b++);
1739 * Partition chip resources for use between various PFs, VFs, etc. This is done
1740 * by uploading the firmware configuration file to the adapter and instructing
1741 * the firmware to process it.
1744 partition_resources(struct adapter *sc, const struct firmware *cfg)
1747 struct fw_caps_config_cmd caps;
1748 uint32_t mtype, maddr, finicsum, cfcsum;
1750 rc = cfg ? upload_config_file(sc, cfg, &mtype, &maddr) : ENOENT;
1752 mtype = FW_MEMTYPE_CF_FLASH;
1753 maddr = t4_flash_cfg_addr(sc);
1756 bzero(&caps, sizeof(caps));
1757 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
1758 F_FW_CMD_REQUEST | F_FW_CMD_READ);
1759 caps.cfvalid_to_len16 = htobe32(F_FW_CAPS_CONFIG_CMD_CFVALID |
1760 V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
1761 V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(maddr >> 16) | FW_LEN16(caps));
1762 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
1764 device_printf(sc->dev,
1765 "failed to pre-process config file: %d.\n", rc);
1769 finicsum = be32toh(caps.finicsum);
1770 cfcsum = be32toh(caps.cfcsum);
1771 if (finicsum != cfcsum) {
1772 device_printf(sc->dev,
1773 "WARNING: config file checksum mismatch: %08x %08x\n",
1776 sc->cfcsum = cfcsum;
1778 #define LIMIT_CAPS(x) do { \
1779 caps.x &= htobe16(t4_##x##_allowed); \
1780 sc->x = htobe16(caps.x); \
1784 * Let the firmware know what features will (not) be used so it can tune
1785 * things accordingly.
1787 LIMIT_CAPS(linkcaps);
1788 LIMIT_CAPS(niccaps);
1789 LIMIT_CAPS(toecaps);
1790 LIMIT_CAPS(rdmacaps);
1791 LIMIT_CAPS(iscsicaps);
1792 LIMIT_CAPS(fcoecaps);
1795 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
1796 F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
1797 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
1798 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), NULL);
1800 device_printf(sc->dev,
1801 "failed to process config file: %d.\n", rc);
1809 * Retrieve parameters that are needed (or nice to have) prior to calling
1810 * t4_sge_init and t4_fw_initialize.
1813 get_params__pre_init(struct adapter *sc)
1816 uint32_t param[2], val[2];
1817 struct fw_devlog_cmd cmd;
1818 struct devlog_params *dlog = &sc->params.devlog;
1820 param[0] = FW_PARAM_DEV(PORTVEC);
1821 param[1] = FW_PARAM_DEV(CCLK);
1822 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
1824 device_printf(sc->dev,
1825 "failed to query parameters (pre_init): %d.\n", rc);
1829 sc->params.portvec = val[0];
1830 sc->params.nports = bitcount32(val[0]);
1831 sc->params.vpd.cclk = val[1];
1833 /* Read device log parameters. */
1834 bzero(&cmd, sizeof(cmd));
1835 cmd.op_to_write = htobe32(V_FW_CMD_OP(FW_DEVLOG_CMD) |
1836 F_FW_CMD_REQUEST | F_FW_CMD_READ);
1837 cmd.retval_len16 = htobe32(FW_LEN16(cmd));
1838 rc = -t4_wr_mbox(sc, sc->mbox, &cmd, sizeof(cmd), &cmd);
1840 device_printf(sc->dev,
1841 "failed to get devlog parameters: %d.\n", rc);
1842 bzero(dlog, sizeof (*dlog));
1843 rc = 0; /* devlog isn't critical for device operation */
1845 val[0] = be32toh(cmd.memtype_devlog_memaddr16_devlog);
1846 dlog->memtype = G_FW_DEVLOG_CMD_MEMTYPE_DEVLOG(val[0]);
1847 dlog->start = G_FW_DEVLOG_CMD_MEMADDR16_DEVLOG(val[0]) << 4;
1848 dlog->size = be32toh(cmd.memsize_devlog);
1855 * Retrieve various parameters that are of interest to the driver. The device
1856 * has been initialized by the firmware at this point.
1859 get_params__post_init(struct adapter *sc)
1862 uint32_t param[7], val[7];
1863 struct fw_caps_config_cmd caps;
1865 param[0] = FW_PARAM_PFVF(IQFLINT_START);
1866 param[1] = FW_PARAM_PFVF(EQ_START);
1867 param[2] = FW_PARAM_PFVF(FILTER_START);
1868 param[3] = FW_PARAM_PFVF(FILTER_END);
1869 param[4] = FW_PARAM_PFVF(L2T_START);
1870 param[5] = FW_PARAM_PFVF(L2T_END);
1871 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
1873 device_printf(sc->dev,
1874 "failed to query parameters (post_init): %d.\n", rc);
1878 sc->sge.iq_start = val[0];
1879 sc->sge.eq_start = val[1];
1880 sc->tids.ftid_base = val[2];
1881 sc->tids.nftids = val[3] - val[2] + 1;
1882 sc->vres.l2t.start = val[4];
1883 sc->vres.l2t.size = val[5] - val[4] + 1;
1884 KASSERT(sc->vres.l2t.size <= L2T_SIZE,
1885 ("%s: L2 table size (%u) larger than expected (%u)",
1886 __func__, sc->vres.l2t.size, L2T_SIZE));
1888 /* get capabilites */
1889 bzero(&caps, sizeof(caps));
1890 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
1891 F_FW_CMD_REQUEST | F_FW_CMD_READ);
1892 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
1893 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
1895 device_printf(sc->dev,
1896 "failed to get card capabilities: %d.\n", rc);
1901 /* query offload-related parameters */
1902 param[0] = FW_PARAM_DEV(NTID);
1903 param[1] = FW_PARAM_PFVF(SERVER_START);
1904 param[2] = FW_PARAM_PFVF(SERVER_END);
1905 param[3] = FW_PARAM_PFVF(TDDP_START);
1906 param[4] = FW_PARAM_PFVF(TDDP_END);
1907 param[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
1908 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
1910 device_printf(sc->dev,
1911 "failed to query TOE parameters: %d.\n", rc);
1914 sc->tids.ntids = val[0];
1915 sc->tids.natids = min(sc->tids.ntids / 2, MAX_ATIDS);
1916 sc->tids.stid_base = val[1];
1917 sc->tids.nstids = val[2] - val[1] + 1;
1918 sc->vres.ddp.start = val[3];
1919 sc->vres.ddp.size = val[4] - val[3] + 1;
1920 sc->params.ofldq_wr_cred = val[5];
1921 sc->params.offload = 1;
1923 if (caps.rdmacaps) {
1924 param[0] = FW_PARAM_PFVF(STAG_START);
1925 param[1] = FW_PARAM_PFVF(STAG_END);
1926 param[2] = FW_PARAM_PFVF(RQ_START);
1927 param[3] = FW_PARAM_PFVF(RQ_END);
1928 param[4] = FW_PARAM_PFVF(PBL_START);
1929 param[5] = FW_PARAM_PFVF(PBL_END);
1930 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
1932 device_printf(sc->dev,
1933 "failed to query RDMA parameters(1): %d.\n", rc);
1936 sc->vres.stag.start = val[0];
1937 sc->vres.stag.size = val[1] - val[0] + 1;
1938 sc->vres.rq.start = val[2];
1939 sc->vres.rq.size = val[3] - val[2] + 1;
1940 sc->vres.pbl.start = val[4];
1941 sc->vres.pbl.size = val[5] - val[4] + 1;
1943 param[0] = FW_PARAM_PFVF(SQRQ_START);
1944 param[1] = FW_PARAM_PFVF(SQRQ_END);
1945 param[2] = FW_PARAM_PFVF(CQ_START);
1946 param[3] = FW_PARAM_PFVF(CQ_END);
1947 param[4] = FW_PARAM_PFVF(OCQ_START);
1948 param[5] = FW_PARAM_PFVF(OCQ_END);
1949 rc = -t4_query_params(sc, 0, 0, 0, 6, param, val);
1951 device_printf(sc->dev,
1952 "failed to query RDMA parameters(2): %d.\n", rc);
1955 sc->vres.qp.start = val[0];
1956 sc->vres.qp.size = val[1] - val[0] + 1;
1957 sc->vres.cq.start = val[2];
1958 sc->vres.cq.size = val[3] - val[2] + 1;
1959 sc->vres.ocq.start = val[4];
1960 sc->vres.ocq.size = val[5] - val[4] + 1;
1962 if (caps.iscsicaps) {
1963 param[0] = FW_PARAM_PFVF(ISCSI_START);
1964 param[1] = FW_PARAM_PFVF(ISCSI_END);
1965 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
1967 device_printf(sc->dev,
1968 "failed to query iSCSI parameters: %d.\n", rc);
1971 sc->vres.iscsi.start = val[0];
1972 sc->vres.iscsi.size = val[1] - val[0] + 1;
1975 /* These are finalized by FW initialization, load their values now */
1976 val[0] = t4_read_reg(sc, A_TP_TIMER_RESOLUTION);
1977 sc->params.tp.tre = G_TIMERRESOLUTION(val[0]);
1978 sc->params.tp.dack_re = G_DELAYEDACKRESOLUTION(val[0]);
1979 t4_read_mtu_tbl(sc, sc->params.mtus, NULL);
1984 #undef FW_PARAM_PFVF
1988 t4_set_desc(struct adapter *sc)
1991 struct adapter_params *p = &sc->params;
1993 snprintf(buf, sizeof(buf), "Chelsio %s %sNIC (rev %d), S/N:%s, E/C:%s",
1994 p->vpd.id, is_offload(sc) ? "R" : "", p->rev, p->vpd.sn, p->vpd.ec);
1996 device_set_desc_copy(sc->dev, buf);
2000 build_medialist(struct port_info *pi)
2002 struct ifmedia *media = &pi->media;
2007 ifmedia_removeall(media);
2009 m = IFM_ETHER | IFM_FDX;
2010 data = (pi->port_type << 8) | pi->mod_type;
2012 switch(pi->port_type) {
2013 case FW_PORT_TYPE_BT_XFI:
2014 ifmedia_add(media, m | IFM_10G_T, data, NULL);
2017 case FW_PORT_TYPE_BT_XAUI:
2018 ifmedia_add(media, m | IFM_10G_T, data, NULL);
2021 case FW_PORT_TYPE_BT_SGMII:
2022 ifmedia_add(media, m | IFM_1000_T, data, NULL);
2023 ifmedia_add(media, m | IFM_100_TX, data, NULL);
2024 ifmedia_add(media, IFM_ETHER | IFM_AUTO, data, NULL);
2025 ifmedia_set(media, IFM_ETHER | IFM_AUTO);
2028 case FW_PORT_TYPE_CX4:
2029 ifmedia_add(media, m | IFM_10G_CX4, data, NULL);
2030 ifmedia_set(media, m | IFM_10G_CX4);
2033 case FW_PORT_TYPE_SFP:
2034 case FW_PORT_TYPE_FIBER_XFI:
2035 case FW_PORT_TYPE_FIBER_XAUI:
2036 switch (pi->mod_type) {
2038 case FW_PORT_MOD_TYPE_LR:
2039 ifmedia_add(media, m | IFM_10G_LR, data, NULL);
2040 ifmedia_set(media, m | IFM_10G_LR);
2043 case FW_PORT_MOD_TYPE_SR:
2044 ifmedia_add(media, m | IFM_10G_SR, data, NULL);
2045 ifmedia_set(media, m | IFM_10G_SR);
2048 case FW_PORT_MOD_TYPE_LRM:
2049 ifmedia_add(media, m | IFM_10G_LRM, data, NULL);
2050 ifmedia_set(media, m | IFM_10G_LRM);
2053 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
2054 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
2055 ifmedia_add(media, m | IFM_10G_TWINAX, data, NULL);
2056 ifmedia_set(media, m | IFM_10G_TWINAX);
2059 case FW_PORT_MOD_TYPE_NONE:
2061 ifmedia_add(media, m | IFM_NONE, data, NULL);
2062 ifmedia_set(media, m | IFM_NONE);
2065 case FW_PORT_MOD_TYPE_NA:
2066 case FW_PORT_MOD_TYPE_ER:
2068 ifmedia_add(media, m | IFM_UNKNOWN, data, NULL);
2069 ifmedia_set(media, m | IFM_UNKNOWN);
2074 case FW_PORT_TYPE_KX4:
2075 case FW_PORT_TYPE_KX:
2076 case FW_PORT_TYPE_KR:
2078 ifmedia_add(media, m | IFM_UNKNOWN, data, NULL);
2079 ifmedia_set(media, m | IFM_UNKNOWN);
2086 #define FW_MAC_EXACT_CHUNK 7
2089 * Program the port's XGMAC based on parameters in ifnet. The caller also
2090 * indicates which parameters should be programmed (the rest are left alone).
2093 update_mac_settings(struct port_info *pi, int flags)
2096 struct ifnet *ifp = pi->ifp;
2097 struct adapter *sc = pi->adapter;
2098 int mtu = -1, promisc = -1, allmulti = -1, vlanex = -1;
2100 ASSERT_SYNCHRONIZED_OP(sc);
2101 KASSERT(flags, ("%s: not told what to update.", __func__));
2103 if (flags & XGMAC_MTU)
2106 if (flags & XGMAC_PROMISC)
2107 promisc = ifp->if_flags & IFF_PROMISC ? 1 : 0;
2109 if (flags & XGMAC_ALLMULTI)
2110 allmulti = ifp->if_flags & IFF_ALLMULTI ? 1 : 0;
2112 if (flags & XGMAC_VLANEX)
2113 vlanex = ifp->if_capenable & IFCAP_VLAN_HWTAGGING ? 1 : 0;
2115 rc = -t4_set_rxmode(sc, sc->mbox, pi->viid, mtu, promisc, allmulti, 1,
2118 if_printf(ifp, "set_rxmode (%x) failed: %d\n", flags, rc);
2122 if (flags & XGMAC_UCADDR) {
2123 uint8_t ucaddr[ETHER_ADDR_LEN];
2125 bcopy(IF_LLADDR(ifp), ucaddr, sizeof(ucaddr));
2126 rc = t4_change_mac(sc, sc->mbox, pi->viid, pi->xact_addr_filt,
2127 ucaddr, true, true);
2130 if_printf(ifp, "change_mac failed: %d\n", rc);
2133 pi->xact_addr_filt = rc;
2138 if (flags & XGMAC_MCADDRS) {
2139 const uint8_t *mcaddr[FW_MAC_EXACT_CHUNK];
2142 struct ifmultiaddr *ifma;
2145 if_maddr_rlock(ifp);
2146 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
2147 if (ifma->ifma_addr->sa_family != AF_LINK)
2150 LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
2152 if (i == FW_MAC_EXACT_CHUNK) {
2153 rc = t4_alloc_mac_filt(sc, sc->mbox, pi->viid,
2154 del, i, mcaddr, NULL, &hash, 0);
2157 for (j = 0; j < i; j++) {
2159 "failed to add mc address"
2161 "%02x:%02x:%02x rc=%d\n",
2162 mcaddr[j][0], mcaddr[j][1],
2163 mcaddr[j][2], mcaddr[j][3],
2164 mcaddr[j][4], mcaddr[j][5],
2174 rc = t4_alloc_mac_filt(sc, sc->mbox, pi->viid,
2175 del, i, mcaddr, NULL, &hash, 0);
2178 for (j = 0; j < i; j++) {
2180 "failed to add mc address"
2182 "%02x:%02x:%02x rc=%d\n",
2183 mcaddr[j][0], mcaddr[j][1],
2184 mcaddr[j][2], mcaddr[j][3],
2185 mcaddr[j][4], mcaddr[j][5],
2192 rc = -t4_set_addr_hash(sc, sc->mbox, pi->viid, 0, hash, 0);
2194 if_printf(ifp, "failed to set mc address hash: %d", rc);
2196 if_maddr_runlock(ifp);
2203 begin_synchronized_op(struct adapter *sc, struct port_info *pi, int flags,
2209 /* the caller thinks it's ok to sleep, but is it really? */
2210 if (flags & SLEEP_OK)
2211 pause("t4slptst", 1);
2222 if (pi && IS_DOOMED(pi)) {
2232 if (!(flags & SLEEP_OK)) {
2237 if (mtx_sleep(&sc->flags, &sc->sc_lock, pri, wmesg, 0)) {
2243 KASSERT(!IS_BUSY(sc), ("%s: controller busy.", __func__));
2246 sc->last_op = wmesg;
2247 sc->last_op_thr = curthread;
2251 if (!(flags & HOLD_LOCK) || rc)
2258 end_synchronized_op(struct adapter *sc, int flags)
2261 if (flags & LOCK_HELD)
2262 ADAPTER_LOCK_ASSERT_OWNED(sc);
2266 KASSERT(IS_BUSY(sc), ("%s: controller not busy.", __func__));
2273 cxgbe_init_synchronized(struct port_info *pi)
2275 struct adapter *sc = pi->adapter;
2276 struct ifnet *ifp = pi->ifp;
2279 ASSERT_SYNCHRONIZED_OP(sc);
2281 if (isset(&sc->open_device_map, pi->port_id)) {
2282 KASSERT(ifp->if_drv_flags & IFF_DRV_RUNNING,
2283 ("mismatch between open_device_map and if_drv_flags"));
2284 return (0); /* already running */
2287 if (!(sc->flags & FULL_INIT_DONE) &&
2288 ((rc = adapter_full_init(sc)) != 0))
2289 return (rc); /* error message displayed already */
2291 if (!(pi->flags & PORT_INIT_DONE) &&
2292 ((rc = port_full_init(pi)) != 0))
2293 return (rc); /* error message displayed already */
2295 rc = update_mac_settings(pi, XGMAC_ALL);
2297 goto done; /* error message displayed already */
2299 rc = -t4_link_start(sc, sc->mbox, pi->tx_chan, &pi->link_cfg);
2301 if_printf(ifp, "start_link failed: %d\n", rc);
2305 rc = -t4_enable_vi(sc, sc->mbox, pi->viid, true, true);
2307 if_printf(ifp, "enable_vi failed: %d\n", rc);
2312 setbit(&sc->open_device_map, pi->port_id);
2314 ifp->if_drv_flags |= IFF_DRV_RUNNING;
2317 callout_reset(&pi->tick, hz, cxgbe_tick, pi);
2320 cxgbe_uninit_synchronized(pi);
2329 cxgbe_uninit_synchronized(struct port_info *pi)
2331 struct adapter *sc = pi->adapter;
2332 struct ifnet *ifp = pi->ifp;
2335 ASSERT_SYNCHRONIZED_OP(sc);
2338 * Disable the VI so that all its data in either direction is discarded
2339 * by the MPS. Leave everything else (the queues, interrupts, and 1Hz
2340 * tick) intact as the TP can deliver negative advice or data that it's
2341 * holding in its RAM (for an offloaded connection) even after the VI is
2344 rc = -t4_enable_vi(sc, sc->mbox, pi->viid, false, false);
2346 if_printf(ifp, "disable_vi failed: %d\n", rc);
2350 clrbit(&sc->open_device_map, pi->port_id);
2352 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
2355 pi->link_cfg.link_ok = 0;
2356 pi->link_cfg.speed = 0;
2357 t4_os_link_changed(sc, pi->port_id, 0);
2363 * It is ok for this function to fail midway and return right away. t4_detach
2364 * will walk the entire sc->irq list and clean up whatever is valid.
2367 setup_intr_handlers(struct adapter *sc)
2372 struct port_info *pi;
2373 struct sge_rxq *rxq;
2375 struct sge_ofld_rxq *ofld_rxq;
2382 rid = sc->intr_type == INTR_INTX ? 0 : 1;
2383 if (sc->intr_count == 1) {
2384 KASSERT(!(sc->flags & INTR_DIRECT),
2385 ("%s: single interrupt && INTR_DIRECT?", __func__));
2387 rc = t4_alloc_irq(sc, irq, rid, t4_intr_all, sc, "all");
2391 /* Multiple interrupts. */
2392 KASSERT(sc->intr_count >= T4_EXTRA_INTR + sc->params.nports,
2393 ("%s: too few intr.", __func__));
2395 /* The first one is always error intr */
2396 rc = t4_alloc_irq(sc, irq, rid, t4_intr_err, sc, "err");
2402 /* The second one is always the firmware event queue */
2403 rc = t4_alloc_irq(sc, irq, rid, t4_intr_evt, &sc->sge.fwq,
2411 * Note that if INTR_DIRECT is not set then either the NIC rx
2412 * queues or (exclusive or) the TOE rx queueus will be taking
2413 * direct interrupts.
2415 * There is no need to check for is_offload(sc) as nofldrxq
2416 * will be 0 if offload is disabled.
2418 for_each_port(sc, p) {
2423 * Skip over the NIC queues if they aren't taking direct
2426 if (!(sc->flags & INTR_DIRECT) &&
2427 pi->nofldrxq > pi->nrxq)
2430 rxq = &sc->sge.rxq[pi->first_rxq];
2431 for (q = 0; q < pi->nrxq; q++, rxq++) {
2432 snprintf(s, sizeof(s), "%d.%d", p, q);
2433 rc = t4_alloc_irq(sc, irq, rid, t4_intr, rxq,
2443 * Skip over the offload queues if they aren't taking
2444 * direct interrupts.
2446 if (!(sc->flags & INTR_DIRECT))
2449 ofld_rxq = &sc->sge.ofld_rxq[pi->first_ofld_rxq];
2450 for (q = 0; q < pi->nofldrxq; q++, ofld_rxq++) {
2451 snprintf(s, sizeof(s), "%d,%d", p, q);
2452 rc = t4_alloc_irq(sc, irq, rid, t4_intr,
2467 adapter_full_init(struct adapter *sc)
2471 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
2472 KASSERT((sc->flags & FULL_INIT_DONE) == 0,
2473 ("%s: FULL_INIT_DONE already", __func__));
2476 * queues that belong to the adapter (not any particular port).
2478 rc = t4_setup_adapter_queues(sc);
2482 for (i = 0; i < nitems(sc->tq); i++) {
2483 sc->tq[i] = taskqueue_create("t4 taskq", M_NOWAIT,
2484 taskqueue_thread_enqueue, &sc->tq[i]);
2485 if (sc->tq[i] == NULL) {
2486 device_printf(sc->dev,
2487 "failed to allocate task queue %d\n", i);
2491 taskqueue_start_threads(&sc->tq[i], 1, PI_NET, "%s tq%d",
2492 device_get_nameunit(sc->dev), i);
2496 sc->flags |= FULL_INIT_DONE;
2499 adapter_full_uninit(sc);
2505 adapter_full_uninit(struct adapter *sc)
2509 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
2511 t4_teardown_adapter_queues(sc);
2513 for (i = 0; i < nitems(sc->tq) && sc->tq[i]; i++) {
2514 taskqueue_free(sc->tq[i]);
2518 sc->flags &= ~FULL_INIT_DONE;
2524 port_full_init(struct port_info *pi)
2526 struct adapter *sc = pi->adapter;
2527 struct ifnet *ifp = pi->ifp;
2529 struct sge_rxq *rxq;
2532 ASSERT_SYNCHRONIZED_OP(sc);
2533 KASSERT((pi->flags & PORT_INIT_DONE) == 0,
2534 ("%s: PORT_INIT_DONE already", __func__));
2536 sysctl_ctx_init(&pi->ctx);
2537 pi->flags |= PORT_SYSCTL_CTX;
2540 * Allocate tx/rx/fl queues for this port.
2542 rc = t4_setup_port_queues(pi);
2544 goto done; /* error message displayed already */
2547 * Setup RSS for this port.
2549 rss = malloc(pi->nrxq * sizeof (*rss), M_CXGBE,
2551 for_each_rxq(pi, i, rxq) {
2552 rss[i] = rxq->iq.abs_id;
2554 rc = -t4_config_rss_range(sc, sc->mbox, pi->viid, 0,
2555 pi->rss_size, rss, pi->nrxq);
2558 if_printf(ifp, "rss_config failed: %d\n", rc);
2562 pi->flags |= PORT_INIT_DONE;
2565 port_full_uninit(pi);
2574 port_full_uninit(struct port_info *pi)
2576 struct adapter *sc = pi->adapter;
2578 struct sge_rxq *rxq;
2579 struct sge_txq *txq;
2581 struct sge_ofld_rxq *ofld_rxq;
2582 struct sge_wrq *ofld_txq;
2585 if (pi->flags & PORT_INIT_DONE) {
2587 /* Need to quiesce queues. XXX: ctrl queues? */
2589 for_each_txq(pi, i, txq) {
2590 quiesce_eq(sc, &txq->eq);
2594 for_each_ofld_txq(pi, i, ofld_txq) {
2595 quiesce_eq(sc, &ofld_txq->eq);
2599 for_each_rxq(pi, i, rxq) {
2600 quiesce_iq(sc, &rxq->iq);
2601 quiesce_fl(sc, &rxq->fl);
2605 for_each_ofld_rxq(pi, i, ofld_rxq) {
2606 quiesce_iq(sc, &ofld_rxq->iq);
2607 quiesce_fl(sc, &ofld_rxq->fl);
2612 t4_teardown_port_queues(pi);
2613 pi->flags &= ~PORT_INIT_DONE;
2619 quiesce_eq(struct adapter *sc, struct sge_eq *eq)
2622 eq->flags |= EQ_DOOMED;
2625 * Wait for the response to a credit flush if one's
2628 while (eq->flags & EQ_CRFLUSHED)
2629 mtx_sleep(eq, &eq->eq_lock, 0, "crflush", 0);
2632 callout_drain(&eq->tx_callout); /* XXX: iffy */
2633 pause("callout", 10); /* Still iffy */
2635 taskqueue_drain(sc->tq[eq->tx_chan], &eq->tx_task);
2639 quiesce_iq(struct adapter *sc, struct sge_iq *iq)
2641 (void) sc; /* unused */
2643 /* Synchronize with the interrupt handler */
2644 while (!atomic_cmpset_int(&iq->state, IQS_IDLE, IQS_DISABLED))
2649 quiesce_fl(struct adapter *sc, struct sge_fl *fl)
2651 mtx_lock(&sc->sfl_lock);
2653 fl->flags |= FL_DOOMED;
2655 mtx_unlock(&sc->sfl_lock);
2657 callout_drain(&sc->sfl_callout);
2658 KASSERT((fl->flags & FL_STARVING) == 0,
2659 ("%s: still starving", __func__));
2663 t4_alloc_irq(struct adapter *sc, struct irq *irq, int rid,
2664 driver_intr_t *handler, void *arg, char *name)
2669 irq->res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &irq->rid,
2670 RF_SHAREABLE | RF_ACTIVE);
2671 if (irq->res == NULL) {
2672 device_printf(sc->dev,
2673 "failed to allocate IRQ for rid %d, name %s.\n", rid, name);
2677 rc = bus_setup_intr(sc->dev, irq->res, INTR_MPSAFE | INTR_TYPE_NET,
2678 NULL, handler, arg, &irq->tag);
2680 device_printf(sc->dev,
2681 "failed to setup interrupt for rid %d, name %s: %d\n",
2684 bus_describe_intr(sc->dev, irq->res, irq->tag, name);
2690 t4_free_irq(struct adapter *sc, struct irq *irq)
2693 bus_teardown_intr(sc->dev, irq->res, irq->tag);
2695 bus_release_resource(sc->dev, SYS_RES_IRQ, irq->rid, irq->res);
2697 bzero(irq, sizeof(*irq));
2703 reg_block_dump(struct adapter *sc, uint8_t *buf, unsigned int start,
2706 uint32_t *p = (uint32_t *)(buf + start);
2708 for ( ; start <= end; start += sizeof(uint32_t))
2709 *p++ = t4_read_reg(sc, start);
2713 t4_get_regs(struct adapter *sc, struct t4_regdump *regs, uint8_t *buf)
2716 static const unsigned int reg_ranges[] = {
2936 regs->version = 4 | (sc->params.rev << 10);
2937 for (i = 0; i < nitems(reg_ranges); i += 2)
2938 reg_block_dump(sc, buf, reg_ranges[i], reg_ranges[i + 1]);
2942 cxgbe_tick(void *arg)
2944 struct port_info *pi = arg;
2945 struct ifnet *ifp = pi->ifp;
2946 struct sge_txq *txq;
2948 struct port_stats *s = &pi->stats;
2951 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
2953 return; /* without scheduling another callout */
2956 t4_get_port_stats(pi->adapter, pi->tx_chan, s);
2958 ifp->if_opackets = s->tx_frames - s->tx_pause;
2959 ifp->if_ipackets = s->rx_frames - s->rx_pause;
2960 ifp->if_obytes = s->tx_octets - s->tx_pause * 64;
2961 ifp->if_ibytes = s->rx_octets - s->rx_pause * 64;
2962 ifp->if_omcasts = s->tx_mcast_frames - s->tx_pause;
2963 ifp->if_imcasts = s->rx_mcast_frames - s->rx_pause;
2964 ifp->if_iqdrops = s->rx_ovflow0 + s->rx_ovflow1 + s->rx_ovflow2 +
2965 s->rx_ovflow3 + s->rx_trunc0 + s->rx_trunc1 + s->rx_trunc2 +
2969 for_each_txq(pi, i, txq)
2970 drops += txq->br->br_drops;
2971 ifp->if_snd.ifq_drops = drops;
2973 ifp->if_oerrors = s->tx_error_frames;
2974 ifp->if_ierrors = s->rx_jabber + s->rx_runt + s->rx_too_long +
2975 s->rx_fcs_err + s->rx_len_err;
2977 callout_schedule(&pi->tick, hz);
2982 cxgbe_vlan_config(void *arg, struct ifnet *ifp, uint16_t vid)
2986 if (arg != ifp || ifp->if_type != IFT_ETHER)
2989 vlan = VLAN_DEVAT(ifp, vid);
2990 VLAN_SETCOOKIE(vlan, ifp);
2994 cpl_not_handled(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
2998 panic("%s: opcode 0x%02x on iq %p with payload %p",
2999 __func__, rss->opcode, iq, m);
3001 log(LOG_ERR, "%s: opcode 0x%02x on iq %p with payload %p\n",
3002 __func__, rss->opcode, iq, m);
3009 t4_register_cpl_handler(struct adapter *sc, int opcode, cpl_handler_t h)
3011 uintptr_t *loc, new;
3013 if (opcode >= nitems(sc->cpl_handler))
3016 new = h ? (uintptr_t)h : (uintptr_t)cpl_not_handled;
3017 loc = (uintptr_t *) &sc->cpl_handler[opcode];
3018 atomic_store_rel_ptr(loc, new);
3024 an_not_handled(struct sge_iq *iq, const struct rsp_ctrl *ctrl)
3028 panic("%s: async notification on iq %p (ctrl %p)", __func__, iq, ctrl);
3030 log(LOG_ERR, "%s: async notification on iq %p (ctrl %p)\n",
3031 __func__, iq, ctrl);
3037 t4_register_an_handler(struct adapter *sc, an_handler_t h)
3039 uintptr_t *loc, new;
3041 new = h ? (uintptr_t)h : (uintptr_t)an_not_handled;
3042 loc = (uintptr_t *) &sc->an_handler;
3043 atomic_store_rel_ptr(loc, new);
3049 fw_msg_not_handled(struct adapter *sc, const __be64 *rpl)
3051 const struct cpl_fw6_msg *cpl =
3052 __containerof(rpl, struct cpl_fw6_msg, data[0]);
3055 panic("%s: fw_msg type %d", __func__, cpl->type);
3057 log(LOG_ERR, "%s: fw_msg type %d\n", __func__, cpl->type);
3063 t4_register_fw_msg_handler(struct adapter *sc, int type, fw_msg_handler_t h)
3065 uintptr_t *loc, new;
3067 if (type >= nitems(sc->fw_msg_handler))
3070 new = h ? (uintptr_t)h : (uintptr_t)fw_msg_not_handled;
3071 loc = (uintptr_t *) &sc->fw_msg_handler[type];
3072 atomic_store_rel_ptr(loc, new);
3078 t4_sysctls(struct adapter *sc)
3080 struct sysctl_ctx_list *ctx;
3081 struct sysctl_oid *oid;
3082 struct sysctl_oid_list *children, *c0;
3083 static char *caps[] = {
3084 "\20\1PPP\2QFC\3DCBX", /* caps[0] linkcaps */
3085 "\20\1NIC\2VM\3IDS\4UM\5UM_ISGL", /* caps[1] niccaps */
3086 "\20\1TOE", /* caps[2] toecaps */
3087 "\20\1RDDP\2RDMAC", /* caps[3] rdmacaps */
3088 "\20\1INITIATOR_PDU\2TARGET_PDU" /* caps[4] iscsicaps */
3089 "\3INITIATOR_CNXOFLD\4TARGET_CNXOFLD"
3090 "\5INITIATOR_SSNOFLD\6TARGET_SSNOFLD",
3091 "\20\1INITIATOR\2TARGET\3CTRL_OFLD" /* caps[5] fcoecaps */
3094 ctx = device_get_sysctl_ctx(sc->dev);
3099 oid = device_get_sysctl_tree(sc->dev);
3100 c0 = children = SYSCTL_CHILDREN(oid);
3102 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nports", CTLFLAG_RD,
3103 &sc->params.nports, 0, "# of ports");
3105 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "hw_revision", CTLFLAG_RD,
3106 &sc->params.rev, 0, "chip hardware revision");
3108 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "firmware_version",
3109 CTLFLAG_RD, &sc->fw_version, 0, "firmware version");
3111 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "cf",
3112 CTLFLAG_RD, &t4_cfg_file, 0, "configuration file");
3114 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "cfcsum", CTLFLAG_RD,
3115 &sc->cfcsum, 0, "config file checksum");
3117 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "linkcaps",
3118 CTLTYPE_STRING | CTLFLAG_RD, caps[0], sc->linkcaps,
3119 sysctl_bitfield, "A", "available link capabilities");
3121 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "niccaps",
3122 CTLTYPE_STRING | CTLFLAG_RD, caps[1], sc->niccaps,
3123 sysctl_bitfield, "A", "available NIC capabilities");
3125 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "toecaps",
3126 CTLTYPE_STRING | CTLFLAG_RD, caps[2], sc->toecaps,
3127 sysctl_bitfield, "A", "available TCP offload capabilities");
3129 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rdmacaps",
3130 CTLTYPE_STRING | CTLFLAG_RD, caps[3], sc->rdmacaps,
3131 sysctl_bitfield, "A", "available RDMA capabilities");
3133 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "iscsicaps",
3134 CTLTYPE_STRING | CTLFLAG_RD, caps[4], sc->iscsicaps,
3135 sysctl_bitfield, "A", "available iSCSI capabilities");
3137 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fcoecaps",
3138 CTLTYPE_STRING | CTLFLAG_RD, caps[5], sc->fcoecaps,
3139 sysctl_bitfield, "A", "available FCoE capabilities");
3141 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "core_clock", CTLFLAG_RD,
3142 &sc->params.vpd.cclk, 0, "core clock frequency (in KHz)");
3144 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_timers",
3145 CTLTYPE_STRING | CTLFLAG_RD, sc->sge.timer_val,
3146 sizeof(sc->sge.timer_val), sysctl_int_array, "A",
3147 "interrupt holdoff timer values (us)");
3149 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pkt_counts",
3150 CTLTYPE_STRING | CTLFLAG_RD, sc->sge.counter_val,
3151 sizeof(sc->sge.counter_val), sysctl_int_array, "A",
3152 "interrupt holdoff packet counter values");
3156 * dev.t4nex.X.misc. Marked CTLFLAG_SKIP to avoid information overload.
3158 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "misc",
3159 CTLFLAG_RD | CTLFLAG_SKIP, NULL,
3160 "logs and miscellaneous information");
3161 children = SYSCTL_CHILDREN(oid);
3163 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cctrl",
3164 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3165 sysctl_cctrl, "A", "congestion control");
3167 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cpl_stats",
3168 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3169 sysctl_cpl_stats, "A", "CPL statistics");
3171 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ddp_stats",
3172 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3173 sysctl_ddp_stats, "A", "DDP statistics");
3175 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "devlog",
3176 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3177 sysctl_devlog, "A", "firmware's device log");
3179 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fcoe_stats",
3180 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3181 sysctl_fcoe_stats, "A", "FCoE statistics");
3183 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "hw_sched",
3184 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3185 sysctl_hw_sched, "A", "hardware scheduler ");
3187 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "l2t",
3188 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3189 sysctl_l2t, "A", "hardware L2 table");
3191 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "lb_stats",
3192 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3193 sysctl_lb_stats, "A", "loopback statistics");
3195 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "meminfo",
3196 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3197 sysctl_meminfo, "A", "memory regions");
3199 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "path_mtus",
3200 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3201 sysctl_path_mtus, "A", "path MTUs");
3203 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pm_stats",
3204 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3205 sysctl_pm_stats, "A", "PM statistics");
3207 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rdma_stats",
3208 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3209 sysctl_rdma_stats, "A", "RDMA statistics");
3211 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tcp_stats",
3212 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3213 sysctl_tcp_stats, "A", "TCP statistics");
3215 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tids",
3216 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3217 sysctl_tids, "A", "TID information");
3219 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_err_stats",
3220 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3221 sysctl_tp_err_stats, "A", "TP error statistics");
3223 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_rate",
3224 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
3225 sysctl_tx_rate, "A", "Tx rate");
3229 if (is_offload(sc)) {
3233 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "toe", CTLFLAG_RD,
3234 NULL, "TOE parameters");
3235 children = SYSCTL_CHILDREN(oid);
3237 sc->tt.sndbuf = 256 * 1024;
3238 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "sndbuf", CTLFLAG_RW,
3239 &sc->tt.sndbuf, 0, "max hardware send buffer size");
3242 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ddp", CTLFLAG_RW,
3243 &sc->tt.ddp, 0, "DDP allowed");
3245 sc->tt.indsz = G_INDICATESIZE(t4_read_reg(sc, A_TP_PARA_REG5));
3246 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "indsz", CTLFLAG_RW,
3247 &sc->tt.indsz, 0, "DDP max indicate size allowed");
3250 G_RXCOALESCESIZE(t4_read_reg(sc, A_TP_PARA_REG2));
3251 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ddp_thres", CTLFLAG_RW,
3252 &sc->tt.ddp_thres, 0, "DDP threshold");
3261 cxgbe_sysctls(struct port_info *pi)
3263 struct sysctl_ctx_list *ctx;
3264 struct sysctl_oid *oid;
3265 struct sysctl_oid_list *children;
3267 ctx = device_get_sysctl_ctx(pi->dev);
3272 oid = device_get_sysctl_tree(pi->dev);
3273 children = SYSCTL_CHILDREN(oid);
3275 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nrxq", CTLFLAG_RD,
3276 &pi->nrxq, 0, "# of rx queues");
3277 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ntxq", CTLFLAG_RD,
3278 &pi->ntxq, 0, "# of tx queues");
3279 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_rxq", CTLFLAG_RD,
3280 &pi->first_rxq, 0, "index of first rx queue");
3281 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_txq", CTLFLAG_RD,
3282 &pi->first_txq, 0, "index of first tx queue");
3285 if (is_offload(pi->adapter)) {
3286 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldrxq", CTLFLAG_RD,
3288 "# of rx queues for offloaded TCP connections");
3289 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldtxq", CTLFLAG_RD,
3291 "# of tx queues for offloaded TCP connections");
3292 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_rxq",
3293 CTLFLAG_RD, &pi->first_ofld_rxq, 0,
3294 "index of first TOE rx queue");
3295 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_txq",
3296 CTLFLAG_RD, &pi->first_ofld_txq, 0,
3297 "index of first TOE tx queue");
3301 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx",
3302 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_holdoff_tmr_idx, "I",
3303 "holdoff timer index");
3304 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx",
3305 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_holdoff_pktc_idx, "I",
3306 "holdoff packet counter index");
3308 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_rxq",
3309 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_qsize_rxq, "I",
3311 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_txq",
3312 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_qsize_txq, "I",
3316 * dev.cxgbe.X.stats.
3318 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats", CTLFLAG_RD,
3319 NULL, "port statistics");
3320 children = SYSCTL_CHILDREN(oid);
3322 #define SYSCTL_ADD_T4_REG64(pi, name, desc, reg) \
3323 SYSCTL_ADD_OID(ctx, children, OID_AUTO, name, \
3324 CTLTYPE_U64 | CTLFLAG_RD, pi->adapter, reg, \
3325 sysctl_handle_t4_reg64, "QU", desc)
3327 SYSCTL_ADD_T4_REG64(pi, "tx_octets", "# of octets in good frames",
3328 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BYTES_L));
3329 SYSCTL_ADD_T4_REG64(pi, "tx_frames", "total # of good frames",
3330 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_FRAMES_L));
3331 SYSCTL_ADD_T4_REG64(pi, "tx_bcast_frames", "# of broadcast frames",
3332 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BCAST_L));
3333 SYSCTL_ADD_T4_REG64(pi, "tx_mcast_frames", "# of multicast frames",
3334 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_MCAST_L));
3335 SYSCTL_ADD_T4_REG64(pi, "tx_ucast_frames", "# of unicast frames",
3336 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_UCAST_L));
3337 SYSCTL_ADD_T4_REG64(pi, "tx_error_frames", "# of error frames",
3338 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_ERROR_L));
3339 SYSCTL_ADD_T4_REG64(pi, "tx_frames_64",
3340 "# of tx frames in this range",
3341 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_64B_L));
3342 SYSCTL_ADD_T4_REG64(pi, "tx_frames_65_127",
3343 "# of tx frames in this range",
3344 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_65B_127B_L));
3345 SYSCTL_ADD_T4_REG64(pi, "tx_frames_128_255",
3346 "# of tx frames in this range",
3347 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_128B_255B_L));
3348 SYSCTL_ADD_T4_REG64(pi, "tx_frames_256_511",
3349 "# of tx frames in this range",
3350 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_256B_511B_L));
3351 SYSCTL_ADD_T4_REG64(pi, "tx_frames_512_1023",
3352 "# of tx frames in this range",
3353 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_512B_1023B_L));
3354 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1024_1518",
3355 "# of tx frames in this range",
3356 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1024B_1518B_L));
3357 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1519_max",
3358 "# of tx frames in this range",
3359 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1519B_MAX_L));
3360 SYSCTL_ADD_T4_REG64(pi, "tx_drop", "# of dropped tx frames",
3361 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_DROP_L));
3362 SYSCTL_ADD_T4_REG64(pi, "tx_pause", "# of pause frames transmitted",
3363 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PAUSE_L));
3364 SYSCTL_ADD_T4_REG64(pi, "tx_ppp0", "# of PPP prio 0 frames transmitted",
3365 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP0_L));
3366 SYSCTL_ADD_T4_REG64(pi, "tx_ppp1", "# of PPP prio 1 frames transmitted",
3367 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP1_L));
3368 SYSCTL_ADD_T4_REG64(pi, "tx_ppp2", "# of PPP prio 2 frames transmitted",
3369 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP2_L));
3370 SYSCTL_ADD_T4_REG64(pi, "tx_ppp3", "# of PPP prio 3 frames transmitted",
3371 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP3_L));
3372 SYSCTL_ADD_T4_REG64(pi, "tx_ppp4", "# of PPP prio 4 frames transmitted",
3373 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP4_L));
3374 SYSCTL_ADD_T4_REG64(pi, "tx_ppp5", "# of PPP prio 5 frames transmitted",
3375 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP5_L));
3376 SYSCTL_ADD_T4_REG64(pi, "tx_ppp6", "# of PPP prio 6 frames transmitted",
3377 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP6_L));
3378 SYSCTL_ADD_T4_REG64(pi, "tx_ppp7", "# of PPP prio 7 frames transmitted",
3379 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP7_L));
3381 SYSCTL_ADD_T4_REG64(pi, "rx_octets", "# of octets in good frames",
3382 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BYTES_L));
3383 SYSCTL_ADD_T4_REG64(pi, "rx_frames", "total # of good frames",
3384 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_FRAMES_L));
3385 SYSCTL_ADD_T4_REG64(pi, "rx_bcast_frames", "# of broadcast frames",
3386 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BCAST_L));
3387 SYSCTL_ADD_T4_REG64(pi, "rx_mcast_frames", "# of multicast frames",
3388 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MCAST_L));
3389 SYSCTL_ADD_T4_REG64(pi, "rx_ucast_frames", "# of unicast frames",
3390 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_UCAST_L));
3391 SYSCTL_ADD_T4_REG64(pi, "rx_too_long", "# of frames exceeding MTU",
3392 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_ERROR_L));
3393 SYSCTL_ADD_T4_REG64(pi, "rx_jabber", "# of jabber frames",
3394 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_CRC_ERROR_L));
3395 SYSCTL_ADD_T4_REG64(pi, "rx_fcs_err",
3396 "# of frames received with bad FCS",
3397 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_CRC_ERROR_L));
3398 SYSCTL_ADD_T4_REG64(pi, "rx_len_err",
3399 "# of frames received with length error",
3400 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LEN_ERROR_L));
3401 SYSCTL_ADD_T4_REG64(pi, "rx_symbol_err", "symbol errors",
3402 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_SYM_ERROR_L));
3403 SYSCTL_ADD_T4_REG64(pi, "rx_runt", "# of short frames received",
3404 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LESS_64B_L));
3405 SYSCTL_ADD_T4_REG64(pi, "rx_frames_64",
3406 "# of rx frames in this range",
3407 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_64B_L));
3408 SYSCTL_ADD_T4_REG64(pi, "rx_frames_65_127",
3409 "# of rx frames in this range",
3410 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_65B_127B_L));
3411 SYSCTL_ADD_T4_REG64(pi, "rx_frames_128_255",
3412 "# of rx frames in this range",
3413 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_128B_255B_L));
3414 SYSCTL_ADD_T4_REG64(pi, "rx_frames_256_511",
3415 "# of rx frames in this range",
3416 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_256B_511B_L));
3417 SYSCTL_ADD_T4_REG64(pi, "rx_frames_512_1023",
3418 "# of rx frames in this range",
3419 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_512B_1023B_L));
3420 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1024_1518",
3421 "# of rx frames in this range",
3422 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1024B_1518B_L));
3423 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1519_max",
3424 "# of rx frames in this range",
3425 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1519B_MAX_L));
3426 SYSCTL_ADD_T4_REG64(pi, "rx_pause", "# of pause frames received",
3427 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PAUSE_L));
3428 SYSCTL_ADD_T4_REG64(pi, "rx_ppp0", "# of PPP prio 0 frames received",
3429 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP0_L));
3430 SYSCTL_ADD_T4_REG64(pi, "rx_ppp1", "# of PPP prio 1 frames received",
3431 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP1_L));
3432 SYSCTL_ADD_T4_REG64(pi, "rx_ppp2", "# of PPP prio 2 frames received",
3433 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP2_L));
3434 SYSCTL_ADD_T4_REG64(pi, "rx_ppp3", "# of PPP prio 3 frames received",
3435 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP3_L));
3436 SYSCTL_ADD_T4_REG64(pi, "rx_ppp4", "# of PPP prio 4 frames received",
3437 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP4_L));
3438 SYSCTL_ADD_T4_REG64(pi, "rx_ppp5", "# of PPP prio 5 frames received",
3439 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP5_L));
3440 SYSCTL_ADD_T4_REG64(pi, "rx_ppp6", "# of PPP prio 6 frames received",
3441 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP6_L));
3442 SYSCTL_ADD_T4_REG64(pi, "rx_ppp7", "# of PPP prio 7 frames received",
3443 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP7_L));
3445 #undef SYSCTL_ADD_T4_REG64
3447 #define SYSCTL_ADD_T4_PORTSTAT(name, desc) \
3448 SYSCTL_ADD_UQUAD(ctx, children, OID_AUTO, #name, CTLFLAG_RD, \
3449 &pi->stats.name, desc)
3451 /* We get these from port_stats and they may be stale by upto 1s */
3452 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow0,
3453 "# drops due to buffer-group 0 overflows");
3454 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow1,
3455 "# drops due to buffer-group 1 overflows");
3456 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow2,
3457 "# drops due to buffer-group 2 overflows");
3458 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow3,
3459 "# drops due to buffer-group 3 overflows");
3460 SYSCTL_ADD_T4_PORTSTAT(rx_trunc0,
3461 "# of buffer-group 0 truncated packets");
3462 SYSCTL_ADD_T4_PORTSTAT(rx_trunc1,
3463 "# of buffer-group 1 truncated packets");
3464 SYSCTL_ADD_T4_PORTSTAT(rx_trunc2,
3465 "# of buffer-group 2 truncated packets");
3466 SYSCTL_ADD_T4_PORTSTAT(rx_trunc3,
3467 "# of buffer-group 3 truncated packets");
3469 #undef SYSCTL_ADD_T4_PORTSTAT
3475 sysctl_int_array(SYSCTL_HANDLER_ARGS)
3480 sbuf_new(&sb, NULL, 32, SBUF_AUTOEXTEND);
3481 for (i = arg1; arg2; arg2 -= sizeof(int), i++)
3482 sbuf_printf(&sb, "%d ", *i);
3485 rc = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
3491 sysctl_bitfield(SYSCTL_HANDLER_ARGS)
3496 rc = sysctl_wire_old_buffer(req, 0);
3500 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
3504 sbuf_printf(sb, "%b", (int)arg2, (char *)arg1);
3505 rc = sbuf_finish(sb);
3512 sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS)
3514 struct port_info *pi = arg1;
3515 struct adapter *sc = pi->adapter;
3517 struct sge_rxq *rxq;
3522 rc = sysctl_handle_int(oidp, &idx, 0, req);
3523 if (rc != 0 || req->newptr == NULL)
3526 if (idx < 0 || idx >= SGE_NTIMERS)
3529 rc = begin_synchronized_op(sc, pi, HOLD_LOCK | SLEEP_OK | INTR_OK,
3534 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(pi->pktc_idx != -1);
3535 for_each_rxq(pi, i, rxq) {
3536 #ifdef atomic_store_rel_8
3537 atomic_store_rel_8(&rxq->iq.intr_params, v);
3539 rxq->iq.intr_params = v;
3544 end_synchronized_op(sc, LOCK_HELD);
3549 sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS)
3551 struct port_info *pi = arg1;
3552 struct adapter *sc = pi->adapter;
3557 rc = sysctl_handle_int(oidp, &idx, 0, req);
3558 if (rc != 0 || req->newptr == NULL)
3561 if (idx < -1 || idx >= SGE_NCOUNTERS)
3564 rc = begin_synchronized_op(sc, pi, HOLD_LOCK | SLEEP_OK | INTR_OK,
3569 if (pi->flags & PORT_INIT_DONE)
3570 rc = EBUSY; /* cannot be changed once the queues are created */
3574 end_synchronized_op(sc, LOCK_HELD);
3579 sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS)
3581 struct port_info *pi = arg1;
3582 struct adapter *sc = pi->adapter;
3585 qsize = pi->qsize_rxq;
3587 rc = sysctl_handle_int(oidp, &qsize, 0, req);
3588 if (rc != 0 || req->newptr == NULL)
3591 if (qsize < 128 || (qsize & 7))
3594 rc = begin_synchronized_op(sc, pi, HOLD_LOCK | SLEEP_OK | INTR_OK,
3599 if (pi->flags & PORT_INIT_DONE)
3600 rc = EBUSY; /* cannot be changed once the queues are created */
3602 pi->qsize_rxq = qsize;
3604 end_synchronized_op(sc, LOCK_HELD);
3609 sysctl_qsize_txq(SYSCTL_HANDLER_ARGS)
3611 struct port_info *pi = arg1;
3612 struct adapter *sc = pi->adapter;
3615 qsize = pi->qsize_txq;
3617 rc = sysctl_handle_int(oidp, &qsize, 0, req);
3618 if (rc != 0 || req->newptr == NULL)
3621 /* bufring size must be powerof2 */
3622 if (qsize < 128 || !powerof2(qsize))
3625 rc = begin_synchronized_op(sc, pi, HOLD_LOCK | SLEEP_OK | INTR_OK,
3630 if (pi->flags & PORT_INIT_DONE)
3631 rc = EBUSY; /* cannot be changed once the queues are created */
3633 pi->qsize_txq = qsize;
3635 end_synchronized_op(sc, LOCK_HELD);
3640 sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS)
3642 struct adapter *sc = arg1;
3646 val = t4_read_reg64(sc, reg);
3648 return (sysctl_handle_64(oidp, &val, 0, req));
3653 sysctl_cctrl(SYSCTL_HANDLER_ARGS)
3655 struct adapter *sc = arg1;
3658 uint16_t incr[NMTUS][NCCTRL_WIN];
3659 static const char *dec_fac[] = {
3660 "0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
3664 rc = sysctl_wire_old_buffer(req, 0);
3668 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
3672 t4_read_cong_tbl(sc, incr);
3674 for (i = 0; i < NCCTRL_WIN; ++i) {
3675 sbuf_printf(sb, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
3676 incr[0][i], incr[1][i], incr[2][i], incr[3][i], incr[4][i],
3677 incr[5][i], incr[6][i], incr[7][i]);
3678 sbuf_printf(sb, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
3679 incr[8][i], incr[9][i], incr[10][i], incr[11][i],
3680 incr[12][i], incr[13][i], incr[14][i], incr[15][i],
3681 sc->params.a_wnd[i], dec_fac[sc->params.b_wnd[i]]);
3684 rc = sbuf_finish(sb);
3691 sysctl_cpl_stats(SYSCTL_HANDLER_ARGS)
3693 struct adapter *sc = arg1;
3696 struct tp_cpl_stats stats;
3698 rc = sysctl_wire_old_buffer(req, 0);
3702 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
3706 t4_tp_get_cpl_stats(sc, &stats);
3708 sbuf_printf(sb, " channel 0 channel 1 channel 2 "
3710 sbuf_printf(sb, "CPL requests: %10u %10u %10u %10u\n",
3711 stats.req[0], stats.req[1], stats.req[2], stats.req[3]);
3712 sbuf_printf(sb, "CPL responses: %10u %10u %10u %10u",
3713 stats.rsp[0], stats.rsp[1], stats.rsp[2], stats.rsp[3]);
3715 rc = sbuf_finish(sb);
3722 sysctl_ddp_stats(SYSCTL_HANDLER_ARGS)
3724 struct adapter *sc = arg1;
3727 struct tp_usm_stats stats;
3729 rc = sysctl_wire_old_buffer(req, 0);
3733 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
3737 t4_get_usm_stats(sc, &stats);
3739 sbuf_printf(sb, "Frames: %u\n", stats.frames);
3740 sbuf_printf(sb, "Octets: %ju\n", stats.octets);
3741 sbuf_printf(sb, "Drops: %u", stats.drops);
3743 rc = sbuf_finish(sb);
3749 const char *devlog_level_strings[] = {
3750 [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
3751 [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
3752 [FW_DEVLOG_LEVEL_ERR] = "ERR",
3753 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
3754 [FW_DEVLOG_LEVEL_INFO] = "INFO",
3755 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
3758 const char *devlog_facility_strings[] = {
3759 [FW_DEVLOG_FACILITY_CORE] = "CORE",
3760 [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
3761 [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
3762 [FW_DEVLOG_FACILITY_RES] = "RES",
3763 [FW_DEVLOG_FACILITY_HW] = "HW",
3764 [FW_DEVLOG_FACILITY_FLR] = "FLR",
3765 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
3766 [FW_DEVLOG_FACILITY_PHY] = "PHY",
3767 [FW_DEVLOG_FACILITY_MAC] = "MAC",
3768 [FW_DEVLOG_FACILITY_PORT] = "PORT",
3769 [FW_DEVLOG_FACILITY_VI] = "VI",
3770 [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
3771 [FW_DEVLOG_FACILITY_ACL] = "ACL",
3772 [FW_DEVLOG_FACILITY_TM] = "TM",
3773 [FW_DEVLOG_FACILITY_QFC] = "QFC",
3774 [FW_DEVLOG_FACILITY_DCB] = "DCB",
3775 [FW_DEVLOG_FACILITY_ETH] = "ETH",
3776 [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
3777 [FW_DEVLOG_FACILITY_RI] = "RI",
3778 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
3779 [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
3780 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
3781 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE"
3785 sysctl_devlog(SYSCTL_HANDLER_ARGS)
3787 struct adapter *sc = arg1;
3788 struct devlog_params *dparams = &sc->params.devlog;
3789 struct fw_devlog_e *buf, *e;
3790 int i, j, rc, nentries, first = 0;
3792 uint64_t ftstamp = UINT64_MAX;
3794 if (dparams->start == 0)
3797 nentries = dparams->size / sizeof(struct fw_devlog_e);
3799 buf = malloc(dparams->size, M_CXGBE, M_NOWAIT);
3803 rc = -t4_mem_read(sc, dparams->memtype, dparams->start, dparams->size,
3808 for (i = 0; i < nentries; i++) {
3811 if (e->timestamp == 0)
3814 e->timestamp = be64toh(e->timestamp);
3815 e->seqno = be32toh(e->seqno);
3816 for (j = 0; j < 8; j++)
3817 e->params[j] = be32toh(e->params[j]);
3819 if (e->timestamp < ftstamp) {
3820 ftstamp = e->timestamp;
3825 if (buf[first].timestamp == 0)
3826 goto done; /* nothing in the log */
3828 rc = sysctl_wire_old_buffer(req, 0);
3832 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
3837 sbuf_printf(sb, "%10s %15s %8s %8s %s\n",
3838 "Seq#", "Tstamp", "Level", "Facility", "Message");
3843 if (e->timestamp == 0)
3846 sbuf_printf(sb, "%10d %15ju %8s %8s ",
3847 e->seqno, e->timestamp,
3848 (e->level < nitems(devlog_level_strings) ?
3849 devlog_level_strings[e->level] : "UNKNOWN"),
3850 (e->facility < nitems(devlog_facility_strings) ?
3851 devlog_facility_strings[e->facility] : "UNKNOWN"));
3852 sbuf_printf(sb, e->fmt, e->params[0], e->params[1],
3853 e->params[2], e->params[3], e->params[4],
3854 e->params[5], e->params[6], e->params[7]);
3856 if (++i == nentries)
3858 } while (i != first);
3860 rc = sbuf_finish(sb);
3868 sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS)
3870 struct adapter *sc = arg1;
3873 struct tp_fcoe_stats stats[4];
3875 rc = sysctl_wire_old_buffer(req, 0);
3879 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
3883 t4_get_fcoe_stats(sc, 0, &stats[0]);
3884 t4_get_fcoe_stats(sc, 1, &stats[1]);
3885 t4_get_fcoe_stats(sc, 2, &stats[2]);
3886 t4_get_fcoe_stats(sc, 3, &stats[3]);
3888 sbuf_printf(sb, " channel 0 channel 1 "
3889 "channel 2 channel 3\n");
3890 sbuf_printf(sb, "octetsDDP: %16ju %16ju %16ju %16ju\n",
3891 stats[0].octetsDDP, stats[1].octetsDDP, stats[2].octetsDDP,
3892 stats[3].octetsDDP);
3893 sbuf_printf(sb, "framesDDP: %16u %16u %16u %16u\n", stats[0].framesDDP,
3894 stats[1].framesDDP, stats[2].framesDDP, stats[3].framesDDP);
3895 sbuf_printf(sb, "framesDrop: %16u %16u %16u %16u",
3896 stats[0].framesDrop, stats[1].framesDrop, stats[2].framesDrop,
3897 stats[3].framesDrop);
3899 rc = sbuf_finish(sb);
3906 sysctl_hw_sched(SYSCTL_HANDLER_ARGS)
3908 struct adapter *sc = arg1;
3911 unsigned int map, kbps, ipg, mode;
3912 unsigned int pace_tab[NTX_SCHED];
3914 rc = sysctl_wire_old_buffer(req, 0);
3918 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
3922 map = t4_read_reg(sc, A_TP_TX_MOD_QUEUE_REQ_MAP);
3923 mode = G_TIMERMODE(t4_read_reg(sc, A_TP_MOD_CONFIG));
3924 t4_read_pace_tbl(sc, pace_tab);
3926 sbuf_printf(sb, "Scheduler Mode Channel Rate (Kbps) "
3927 "Class IPG (0.1 ns) Flow IPG (us)");
3929 for (i = 0; i < NTX_SCHED; ++i, map >>= 2) {
3930 t4_get_tx_sched(sc, i, &kbps, &ipg);
3931 sbuf_printf(sb, "\n %u %-5s %u ", i,
3932 (mode & (1 << i)) ? "flow" : "class", map & 3);
3934 sbuf_printf(sb, "%9u ", kbps);
3936 sbuf_printf(sb, " disabled ");
3939 sbuf_printf(sb, "%13u ", ipg);
3941 sbuf_printf(sb, " disabled ");
3944 sbuf_printf(sb, "%10u", pace_tab[i]);
3946 sbuf_printf(sb, " disabled");
3949 rc = sbuf_finish(sb);
3956 sysctl_lb_stats(SYSCTL_HANDLER_ARGS)
3958 struct adapter *sc = arg1;
3962 struct lb_port_stats s[2];
3963 static const char *stat_name[] = {
3964 "OctetsOK:", "FramesOK:", "BcastFrames:", "McastFrames:",
3965 "UcastFrames:", "ErrorFrames:", "Frames64:", "Frames65To127:",
3966 "Frames128To255:", "Frames256To511:", "Frames512To1023:",
3967 "Frames1024To1518:", "Frames1519ToMax:", "FramesDropped:",
3968 "BG0FramesDropped:", "BG1FramesDropped:", "BG2FramesDropped:",
3969 "BG3FramesDropped:", "BG0FramesTrunc:", "BG1FramesTrunc:",
3970 "BG2FramesTrunc:", "BG3FramesTrunc:"
3973 rc = sysctl_wire_old_buffer(req, 0);
3977 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
3981 memset(s, 0, sizeof(s));
3983 for (i = 0; i < 4; i += 2) {
3984 t4_get_lb_stats(sc, i, &s[0]);
3985 t4_get_lb_stats(sc, i + 1, &s[1]);
3989 sbuf_printf(sb, "%s Loopback %u"
3990 " Loopback %u", i == 0 ? "" : "\n", i, i + 1);
3992 for (j = 0; j < nitems(stat_name); j++)
3993 sbuf_printf(sb, "\n%-17s %20ju %20ju", stat_name[j],
3997 rc = sbuf_finish(sb);
4010 mem_desc_cmp(const void *a, const void *b)
4012 return ((const struct mem_desc *)a)->base -
4013 ((const struct mem_desc *)b)->base;
4017 mem_region_show(struct sbuf *sb, const char *name, unsigned int from,
4022 size = to - from + 1;
4026 /* XXX: need humanize_number(3) in libkern for a more readable 'size' */
4027 sbuf_printf(sb, "%-15s %#x-%#x [%u]\n", name, from, to, size);
4031 sysctl_meminfo(SYSCTL_HANDLER_ARGS)
4033 struct adapter *sc = arg1;
4037 static const char *memory[] = { "EDC0:", "EDC1:", "MC:" };
4038 static const char *region[] = {
4039 "DBQ contexts:", "IMSG contexts:", "FLM cache:", "TCBs:",
4040 "Pstructs:", "Timers:", "Rx FL:", "Tx FL:", "Pstruct FL:",
4041 "Tx payload:", "Rx payload:", "LE hash:", "iSCSI region:",
4042 "TDDP region:", "TPT region:", "STAG region:", "RQ region:",
4043 "RQUDP region:", "PBL region:", "TXPBL region:", "ULPRX state:",
4044 "ULPTX state:", "On-chip queues:"
4046 struct mem_desc avail[3];
4047 struct mem_desc mem[nitems(region) + 3]; /* up to 3 holes */
4048 struct mem_desc *md = mem;
4050 rc = sysctl_wire_old_buffer(req, 0);
4054 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
4058 for (i = 0; i < nitems(mem); i++) {
4063 /* Find and sort the populated memory ranges */
4065 lo = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
4066 if (lo & F_EDRAM0_ENABLE) {
4067 hi = t4_read_reg(sc, A_MA_EDRAM0_BAR);
4068 avail[i].base = G_EDRAM0_BASE(hi) << 20;
4069 avail[i].limit = avail[i].base + (G_EDRAM0_SIZE(hi) << 20);
4073 if (lo & F_EDRAM1_ENABLE) {
4074 hi = t4_read_reg(sc, A_MA_EDRAM1_BAR);
4075 avail[i].base = G_EDRAM1_BASE(hi) << 20;
4076 avail[i].limit = avail[i].base + (G_EDRAM1_SIZE(hi) << 20);
4080 if (lo & F_EXT_MEM_ENABLE) {
4081 hi = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
4082 avail[i].base = G_EXT_MEM_BASE(hi) << 20;
4083 avail[i].limit = avail[i].base + (G_EXT_MEM_SIZE(hi) << 20);
4087 if (!i) /* no memory available */
4089 qsort(avail, i, sizeof(struct mem_desc), mem_desc_cmp);
4091 (md++)->base = t4_read_reg(sc, A_SGE_DBQ_CTXT_BADDR);
4092 (md++)->base = t4_read_reg(sc, A_SGE_IMSG_CTXT_BADDR);
4093 (md++)->base = t4_read_reg(sc, A_SGE_FLM_CACHE_BADDR);
4094 (md++)->base = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
4095 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_BASE);
4096 (md++)->base = t4_read_reg(sc, A_TP_CMM_TIMER_BASE);
4097 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_RX_FLST_BASE);
4098 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_TX_FLST_BASE);
4099 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_PS_FLST_BASE);
4101 /* the next few have explicit upper bounds */
4102 md->base = t4_read_reg(sc, A_TP_PMM_TX_BASE);
4103 md->limit = md->base - 1 +
4104 t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE) *
4105 G_PMTXMAXPAGE(t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE));
4108 md->base = t4_read_reg(sc, A_TP_PMM_RX_BASE);
4109 md->limit = md->base - 1 +
4110 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) *
4111 G_PMRXMAXPAGE(t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE));
4114 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
4115 hi = t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4;
4116 md->base = t4_read_reg(sc, A_LE_DB_HASH_TID_BASE);
4117 md->limit = (sc->tids.ntids - hi) * 16 + md->base - 1;
4120 md->idx = nitems(region); /* hide it */
4124 #define ulp_region(reg) \
4125 md->base = t4_read_reg(sc, A_ULP_ ## reg ## _LLIMIT);\
4126 (md++)->limit = t4_read_reg(sc, A_ULP_ ## reg ## _ULIMIT)
4128 ulp_region(RX_ISCSI);
4129 ulp_region(RX_TDDP);
4131 ulp_region(RX_STAG);
4133 ulp_region(RX_RQUDP);
4138 md->base = t4_read_reg(sc, A_ULP_RX_CTX_BASE);
4139 md->limit = md->base + sc->tids.ntids - 1;
4141 md->base = t4_read_reg(sc, A_ULP_TX_ERR_TABLE_BASE);
4142 md->limit = md->base + sc->tids.ntids - 1;
4145 md->base = sc->vres.ocq.start;
4146 if (sc->vres.ocq.size)
4147 md->limit = md->base + sc->vres.ocq.size - 1;
4149 md->idx = nitems(region); /* hide it */
4152 /* add any address-space holes, there can be up to 3 */
4153 for (n = 0; n < i - 1; n++)
4154 if (avail[n].limit < avail[n + 1].base)
4155 (md++)->base = avail[n].limit;
4157 (md++)->base = avail[n].limit;
4160 qsort(mem, n, sizeof(struct mem_desc), mem_desc_cmp);
4162 for (lo = 0; lo < i; lo++)
4163 mem_region_show(sb, memory[avail[lo].idx], avail[lo].base,
4164 avail[lo].limit - 1);
4166 sbuf_printf(sb, "\n");
4167 for (i = 0; i < n; i++) {
4168 if (mem[i].idx >= nitems(region))
4169 continue; /* skip holes */
4171 mem[i].limit = i < n - 1 ? mem[i + 1].base - 1 : ~0;
4172 mem_region_show(sb, region[mem[i].idx], mem[i].base,
4176 sbuf_printf(sb, "\n");
4177 lo = t4_read_reg(sc, A_CIM_SDRAM_BASE_ADDR);
4178 hi = t4_read_reg(sc, A_CIM_SDRAM_ADDR_SIZE) + lo - 1;
4179 mem_region_show(sb, "uP RAM:", lo, hi);
4181 lo = t4_read_reg(sc, A_CIM_EXTMEM2_BASE_ADDR);
4182 hi = t4_read_reg(sc, A_CIM_EXTMEM2_ADDR_SIZE) + lo - 1;
4183 mem_region_show(sb, "uP Extmem2:", lo, hi);
4185 lo = t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE);
4186 sbuf_printf(sb, "\n%u Rx pages of size %uKiB for %u channels\n",
4188 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) >> 10,
4189 (lo & F_PMRXNUMCHN) ? 2 : 1);
4191 lo = t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE);
4192 hi = t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE);
4193 sbuf_printf(sb, "%u Tx pages of size %u%ciB for %u channels\n",
4195 hi >= (1 << 20) ? (hi >> 20) : (hi >> 10),
4196 hi >= (1 << 20) ? 'M' : 'K', 1 << G_PMTXNUMCHN(lo));
4197 sbuf_printf(sb, "%u p-structs\n",
4198 t4_read_reg(sc, A_TP_CMM_MM_MAX_PSTRUCT));
4200 for (i = 0; i < 4; i++) {
4201 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV0 + i * 4);
4202 sbuf_printf(sb, "\nPort %d using %u pages out of %u allocated",
4203 i, G_USED(lo), G_ALLOC(lo));
4205 for (i = 0; i < 4; i++) {
4206 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV4 + i * 4);
4208 "\nLoopback %d using %u pages out of %u allocated",
4209 i, G_USED(lo), G_ALLOC(lo));
4212 rc = sbuf_finish(sb);
4219 sysctl_path_mtus(SYSCTL_HANDLER_ARGS)
4221 struct adapter *sc = arg1;
4224 uint16_t mtus[NMTUS];
4226 rc = sysctl_wire_old_buffer(req, 0);
4230 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
4234 t4_read_mtu_tbl(sc, mtus, NULL);
4236 sbuf_printf(sb, "%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u",
4237 mtus[0], mtus[1], mtus[2], mtus[3], mtus[4], mtus[5], mtus[6],
4238 mtus[7], mtus[8], mtus[9], mtus[10], mtus[11], mtus[12], mtus[13],
4239 mtus[14], mtus[15]);
4241 rc = sbuf_finish(sb);
4248 sysctl_pm_stats(SYSCTL_HANDLER_ARGS)
4250 struct adapter *sc = arg1;
4253 uint32_t tx_cnt[PM_NSTATS], rx_cnt[PM_NSTATS];
4254 uint64_t tx_cyc[PM_NSTATS], rx_cyc[PM_NSTATS];
4255 static const char *pm_stats[] = {
4256 "Read:", "Write bypass:", "Write mem:", "Flush:", "FIFO wait:"
4259 rc = sysctl_wire_old_buffer(req, 0);
4263 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
4267 t4_pmtx_get_stats(sc, tx_cnt, tx_cyc);
4268 t4_pmrx_get_stats(sc, rx_cnt, rx_cyc);
4270 sbuf_printf(sb, " Tx count Tx cycles "
4271 "Rx count Rx cycles");
4272 for (i = 0; i < PM_NSTATS; i++)
4273 sbuf_printf(sb, "\n%-13s %10u %20ju %10u %20ju",
4274 pm_stats[i], tx_cnt[i], tx_cyc[i], rx_cnt[i], rx_cyc[i]);
4276 rc = sbuf_finish(sb);
4283 sysctl_rdma_stats(SYSCTL_HANDLER_ARGS)
4285 struct adapter *sc = arg1;
4288 struct tp_rdma_stats stats;
4290 rc = sysctl_wire_old_buffer(req, 0);
4294 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
4298 t4_tp_get_rdma_stats(sc, &stats);
4299 sbuf_printf(sb, "NoRQEModDefferals: %u\n", stats.rqe_dfr_mod);
4300 sbuf_printf(sb, "NoRQEPktDefferals: %u", stats.rqe_dfr_pkt);
4302 rc = sbuf_finish(sb);
4309 sysctl_tcp_stats(SYSCTL_HANDLER_ARGS)
4311 struct adapter *sc = arg1;
4314 struct tp_tcp_stats v4, v6;
4316 rc = sysctl_wire_old_buffer(req, 0);
4320 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
4324 t4_tp_get_tcp_stats(sc, &v4, &v6);
4327 sbuf_printf(sb, "OutRsts: %20u %20u\n",
4328 v4.tcpOutRsts, v6.tcpOutRsts);
4329 sbuf_printf(sb, "InSegs: %20ju %20ju\n",
4330 v4.tcpInSegs, v6.tcpInSegs);
4331 sbuf_printf(sb, "OutSegs: %20ju %20ju\n",
4332 v4.tcpOutSegs, v6.tcpOutSegs);
4333 sbuf_printf(sb, "RetransSegs: %20ju %20ju",
4334 v4.tcpRetransSegs, v6.tcpRetransSegs);
4336 rc = sbuf_finish(sb);
4343 sysctl_tids(SYSCTL_HANDLER_ARGS)
4345 struct adapter *sc = arg1;
4348 struct tid_info *t = &sc->tids;
4350 rc = sysctl_wire_old_buffer(req, 0);
4354 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
4359 sbuf_printf(sb, "ATID range: 0-%u, in use: %u\n", t->natids - 1,
4364 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
4365 uint32_t b = t4_read_reg(sc, A_LE_DB_SERVER_INDEX) / 4;
4368 sbuf_printf(sb, "TID range: 0-%u, %u-%u", b - 1,
4369 t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4,
4372 sbuf_printf(sb, "TID range: %u-%u",
4373 t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4,
4377 sbuf_printf(sb, "TID range: 0-%u", t->ntids - 1);
4378 sbuf_printf(sb, ", in use: %u\n",
4379 atomic_load_acq_int(&t->tids_in_use));
4383 sbuf_printf(sb, "STID range: %u-%u, in use: %u\n", t->stid_base,
4384 t->stid_base + t->nstids - 1, t->stids_in_use);
4388 sbuf_printf(sb, "FTID range: %u-%u\n", t->ftid_base,
4389 t->ftid_base + t->nftids - 1);
4392 sbuf_printf(sb, "HW TID usage: %u IP users, %u IPv6 users",
4393 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV4),
4394 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV6));
4396 rc = sbuf_finish(sb);
4403 sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS)
4405 struct adapter *sc = arg1;
4408 struct tp_err_stats stats;
4410 rc = sysctl_wire_old_buffer(req, 0);
4414 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
4418 t4_tp_get_err_stats(sc, &stats);
4420 sbuf_printf(sb, " channel 0 channel 1 channel 2 "
4422 sbuf_printf(sb, "macInErrs: %10u %10u %10u %10u\n",
4423 stats.macInErrs[0], stats.macInErrs[1], stats.macInErrs[2],
4424 stats.macInErrs[3]);
4425 sbuf_printf(sb, "hdrInErrs: %10u %10u %10u %10u\n",
4426 stats.hdrInErrs[0], stats.hdrInErrs[1], stats.hdrInErrs[2],
4427 stats.hdrInErrs[3]);
4428 sbuf_printf(sb, "tcpInErrs: %10u %10u %10u %10u\n",
4429 stats.tcpInErrs[0], stats.tcpInErrs[1], stats.tcpInErrs[2],
4430 stats.tcpInErrs[3]);
4431 sbuf_printf(sb, "tcp6InErrs: %10u %10u %10u %10u\n",
4432 stats.tcp6InErrs[0], stats.tcp6InErrs[1], stats.tcp6InErrs[2],
4433 stats.tcp6InErrs[3]);
4434 sbuf_printf(sb, "tnlCongDrops: %10u %10u %10u %10u\n",
4435 stats.tnlCongDrops[0], stats.tnlCongDrops[1], stats.tnlCongDrops[2],
4436 stats.tnlCongDrops[3]);
4437 sbuf_printf(sb, "tnlTxDrops: %10u %10u %10u %10u\n",
4438 stats.tnlTxDrops[0], stats.tnlTxDrops[1], stats.tnlTxDrops[2],
4439 stats.tnlTxDrops[3]);
4440 sbuf_printf(sb, "ofldVlanDrops: %10u %10u %10u %10u\n",
4441 stats.ofldVlanDrops[0], stats.ofldVlanDrops[1],
4442 stats.ofldVlanDrops[2], stats.ofldVlanDrops[3]);
4443 sbuf_printf(sb, "ofldChanDrops: %10u %10u %10u %10u\n\n",
4444 stats.ofldChanDrops[0], stats.ofldChanDrops[1],
4445 stats.ofldChanDrops[2], stats.ofldChanDrops[3]);
4446 sbuf_printf(sb, "ofldNoNeigh: %u\nofldCongDefer: %u",
4447 stats.ofldNoNeigh, stats.ofldCongDefer);
4449 rc = sbuf_finish(sb);
4456 sysctl_tx_rate(SYSCTL_HANDLER_ARGS)
4458 struct adapter *sc = arg1;
4461 u64 nrate[NCHAN], orate[NCHAN];
4463 rc = sysctl_wire_old_buffer(req, 0);
4467 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
4471 t4_get_chan_txrate(sc, nrate, orate);
4472 sbuf_printf(sb, " channel 0 channel 1 channel 2 "
4474 sbuf_printf(sb, "NIC B/s: %10ju %10ju %10ju %10ju\n",
4475 nrate[0], nrate[1], nrate[2], nrate[3]);
4476 sbuf_printf(sb, "Offload B/s: %10ju %10ju %10ju %10ju",
4477 orate[0], orate[1], orate[2], orate[3]);
4479 rc = sbuf_finish(sb);
4487 txq_start(struct ifnet *ifp, struct sge_txq *txq)
4489 struct buf_ring *br;
4492 TXQ_LOCK_ASSERT_OWNED(txq);
4495 m = txq->m ? txq->m : drbr_dequeue(ifp, br);
4497 t4_eth_tx(ifp, txq, m);
4501 t4_tx_callout(void *arg)
4503 struct sge_eq *eq = arg;
4506 if (EQ_TRYLOCK(eq) == 0)
4509 if (eq->flags & EQ_STALLED && !can_resume_tx(eq)) {
4512 if (__predict_true(!(eq->flags && EQ_DOOMED)))
4513 callout_schedule(&eq->tx_callout, 1);
4517 EQ_LOCK_ASSERT_OWNED(eq);
4519 if (__predict_true((eq->flags & EQ_DOOMED) == 0)) {
4521 if ((eq->flags & EQ_TYPEMASK) == EQ_ETH) {
4522 struct sge_txq *txq = arg;
4523 struct port_info *pi = txq->ifp->if_softc;
4527 struct sge_wrq *wrq = arg;
4532 taskqueue_enqueue(sc->tq[eq->tx_chan], &eq->tx_task);
4539 t4_tx_task(void *arg, int count)
4541 struct sge_eq *eq = arg;
4544 if ((eq->flags & EQ_TYPEMASK) == EQ_ETH) {
4545 struct sge_txq *txq = arg;
4546 txq_start(txq->ifp, txq);
4548 struct sge_wrq *wrq = arg;
4549 t4_wrq_tx_locked(wrq->adapter, wrq, NULL);
4555 fconf_to_mode(uint32_t fconf)
4559 mode = T4_FILTER_IPv4 | T4_FILTER_IPv6 | T4_FILTER_IP_SADDR |
4560 T4_FILTER_IP_DADDR | T4_FILTER_IP_SPORT | T4_FILTER_IP_DPORT;
4562 if (fconf & F_FRAGMENTATION)
4563 mode |= T4_FILTER_IP_FRAGMENT;
4565 if (fconf & F_MPSHITTYPE)
4566 mode |= T4_FILTER_MPS_HIT_TYPE;
4568 if (fconf & F_MACMATCH)
4569 mode |= T4_FILTER_MAC_IDX;
4571 if (fconf & F_ETHERTYPE)
4572 mode |= T4_FILTER_ETH_TYPE;
4574 if (fconf & F_PROTOCOL)
4575 mode |= T4_FILTER_IP_PROTO;
4578 mode |= T4_FILTER_IP_TOS;
4581 mode |= T4_FILTER_VLAN;
4583 if (fconf & F_VNIC_ID)
4584 mode |= T4_FILTER_VNIC;
4587 mode |= T4_FILTER_PORT;
4590 mode |= T4_FILTER_FCoE;
4596 mode_to_fconf(uint32_t mode)
4600 if (mode & T4_FILTER_IP_FRAGMENT)
4601 fconf |= F_FRAGMENTATION;
4603 if (mode & T4_FILTER_MPS_HIT_TYPE)
4604 fconf |= F_MPSHITTYPE;
4606 if (mode & T4_FILTER_MAC_IDX)
4607 fconf |= F_MACMATCH;
4609 if (mode & T4_FILTER_ETH_TYPE)
4610 fconf |= F_ETHERTYPE;
4612 if (mode & T4_FILTER_IP_PROTO)
4613 fconf |= F_PROTOCOL;
4615 if (mode & T4_FILTER_IP_TOS)
4618 if (mode & T4_FILTER_VLAN)
4621 if (mode & T4_FILTER_VNIC)
4624 if (mode & T4_FILTER_PORT)
4627 if (mode & T4_FILTER_FCoE)
4634 fspec_to_fconf(struct t4_filter_specification *fs)
4638 if (fs->val.frag || fs->mask.frag)
4639 fconf |= F_FRAGMENTATION;
4641 if (fs->val.matchtype || fs->mask.matchtype)
4642 fconf |= F_MPSHITTYPE;
4644 if (fs->val.macidx || fs->mask.macidx)
4645 fconf |= F_MACMATCH;
4647 if (fs->val.ethtype || fs->mask.ethtype)
4648 fconf |= F_ETHERTYPE;
4650 if (fs->val.proto || fs->mask.proto)
4651 fconf |= F_PROTOCOL;
4653 if (fs->val.tos || fs->mask.tos)
4656 if (fs->val.vlan_vld || fs->mask.vlan_vld)
4659 if (fs->val.vnic_vld || fs->mask.vnic_vld)
4662 if (fs->val.iport || fs->mask.iport)
4665 if (fs->val.fcoe || fs->mask.fcoe)
4672 get_filter_mode(struct adapter *sc, uint32_t *mode)
4677 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
4682 t4_read_indirect(sc, A_TP_PIO_ADDR, A_TP_PIO_DATA, &fconf, 1,
4685 if (sc->filter_mode != fconf) {
4686 log(LOG_WARNING, "%s: cached filter mode out of sync %x %x.\n",
4687 device_get_nameunit(sc->dev), sc->filter_mode, fconf);
4688 sc->filter_mode = fconf;
4691 *mode = fconf_to_mode(sc->filter_mode);
4693 end_synchronized_op(sc, LOCK_HELD);
4698 set_filter_mode(struct adapter *sc, uint32_t mode)
4703 fconf = mode_to_fconf(mode);
4705 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
4710 if (sc->tids.ftids_in_use > 0) {
4716 if (sc->offload_map) {
4723 rc = -t4_set_filter_mode(sc, fconf);
4725 sc->filter_mode = fconf;
4731 end_synchronized_op(sc, LOCK_HELD);
4735 static inline uint64_t
4736 get_filter_hits(struct adapter *sc, uint32_t fid)
4738 uint32_t tcb_base = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
4741 t4_write_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, 0),
4742 tcb_base + (fid + sc->tids.ftid_base) * TCB_SIZE);
4743 t4_read_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, 0));
4744 hits = t4_read_reg64(sc, MEMWIN0_BASE + 16);
4746 return (be64toh(hits));
4750 get_filter(struct adapter *sc, struct t4_filter *t)
4752 int i, rc, nfilters = sc->tids.nftids;
4753 struct filter_entry *f;
4755 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
4760 if (sc->tids.ftids_in_use == 0 || sc->tids.ftid_tab == NULL ||
4761 t->idx >= nfilters) {
4762 t->idx = 0xffffffff;
4766 f = &sc->tids.ftid_tab[t->idx];
4767 for (i = t->idx; i < nfilters; i++, f++) {
4770 t->l2tidx = f->l2t ? f->l2t->idx : 0;
4771 t->smtidx = f->smtidx;
4773 t->hits = get_filter_hits(sc, t->idx);
4775 t->hits = UINT64_MAX;
4782 t->idx = 0xffffffff;
4784 end_synchronized_op(sc, LOCK_HELD);
4789 set_filter(struct adapter *sc, struct t4_filter *t)
4791 unsigned int nfilters, nports;
4792 struct filter_entry *f;
4795 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setf");
4799 nfilters = sc->tids.nftids;
4800 nports = sc->params.nports;
4802 if (nfilters == 0) {
4807 if (!(sc->flags & FULL_INIT_DONE)) {
4812 if (t->idx >= nfilters) {
4817 /* Validate against the global filter mode */
4818 if ((sc->filter_mode | fspec_to_fconf(&t->fs)) != sc->filter_mode) {
4823 if (t->fs.action == FILTER_SWITCH && t->fs.eport >= nports) {
4828 if (t->fs.val.iport >= nports) {
4833 /* Can't specify an iq if not steering to it */
4834 if (!t->fs.dirsteer && t->fs.iq) {
4839 /* IPv6 filter idx must be 4 aligned */
4840 if (t->fs.type == 1 &&
4841 ((t->idx & 0x3) || t->idx + 4 >= nfilters)) {
4846 if (sc->tids.ftid_tab == NULL) {
4847 KASSERT(sc->tids.ftids_in_use == 0,
4848 ("%s: no memory allocated but filters_in_use > 0",
4851 sc->tids.ftid_tab = malloc(sizeof (struct filter_entry) *
4852 nfilters, M_CXGBE, M_NOWAIT | M_ZERO);
4853 if (sc->tids.ftid_tab == NULL) {
4857 mtx_init(&sc->tids.ftid_lock, "T4 filters", 0, MTX_DEF);
4860 for (i = 0; i < 4; i++) {
4861 f = &sc->tids.ftid_tab[t->idx + i];
4863 if (f->pending || f->valid) {
4872 if (t->fs.type == 0)
4876 f = &sc->tids.ftid_tab[t->idx];
4879 rc = set_filter_wr(sc, t->idx);
4881 end_synchronized_op(sc, 0);
4884 mtx_lock(&sc->tids.ftid_lock);
4886 if (f->pending == 0) {
4887 rc = f->valid ? 0 : EIO;
4891 if (mtx_sleep(&sc->tids.ftid_tab, &sc->tids.ftid_lock,
4892 PCATCH, "t4setfw", 0)) {
4897 mtx_unlock(&sc->tids.ftid_lock);
4903 del_filter(struct adapter *sc, struct t4_filter *t)
4905 unsigned int nfilters;
4906 struct filter_entry *f;
4909 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4delf");
4913 nfilters = sc->tids.nftids;
4915 if (nfilters == 0) {
4920 if (sc->tids.ftid_tab == NULL || sc->tids.ftids_in_use == 0 ||
4921 t->idx >= nfilters) {
4926 if (!(sc->flags & FULL_INIT_DONE)) {
4931 f = &sc->tids.ftid_tab[t->idx];
4943 t->fs = f->fs; /* extra info for the caller */
4944 rc = del_filter_wr(sc, t->idx);
4948 end_synchronized_op(sc, 0);
4951 mtx_lock(&sc->tids.ftid_lock);
4953 if (f->pending == 0) {
4954 rc = f->valid ? EIO : 0;
4958 if (mtx_sleep(&sc->tids.ftid_tab, &sc->tids.ftid_lock,
4959 PCATCH, "t4delfw", 0)) {
4964 mtx_unlock(&sc->tids.ftid_lock);
4971 clear_filter(struct filter_entry *f)
4974 t4_l2t_release(f->l2t);
4976 bzero(f, sizeof (*f));
4980 set_filter_wr(struct adapter *sc, int fidx)
4982 struct filter_entry *f = &sc->tids.ftid_tab[fidx];
4984 struct fw_filter_wr *fwr;
4987 ASSERT_SYNCHRONIZED_OP(sc);
4989 if (f->fs.newdmac || f->fs.newvlan) {
4990 /* This filter needs an L2T entry; allocate one. */
4991 f->l2t = t4_l2t_alloc_switching(sc->l2t);
4994 if (t4_l2t_set_switching(sc, f->l2t, f->fs.vlan, f->fs.eport,
4996 t4_l2t_release(f->l2t);
5002 ftid = sc->tids.ftid_base + fidx;
5004 wr = alloc_wrqe(sizeof(*fwr), &sc->sge.mgmtq);
5009 bzero(fwr, sizeof (*fwr));
5011 fwr->op_pkd = htobe32(V_FW_WR_OP(FW_FILTER_WR));
5012 fwr->len16_pkd = htobe32(FW_LEN16(*fwr));
5014 htobe32(V_FW_FILTER_WR_TID(ftid) |
5015 V_FW_FILTER_WR_RQTYPE(f->fs.type) |
5016 V_FW_FILTER_WR_NOREPLY(0) |
5017 V_FW_FILTER_WR_IQ(f->fs.iq));
5018 fwr->del_filter_to_l2tix =
5019 htobe32(V_FW_FILTER_WR_RPTTID(f->fs.rpttid) |
5020 V_FW_FILTER_WR_DROP(f->fs.action == FILTER_DROP) |
5021 V_FW_FILTER_WR_DIRSTEER(f->fs.dirsteer) |
5022 V_FW_FILTER_WR_MASKHASH(f->fs.maskhash) |
5023 V_FW_FILTER_WR_DIRSTEERHASH(f->fs.dirsteerhash) |
5024 V_FW_FILTER_WR_LPBK(f->fs.action == FILTER_SWITCH) |
5025 V_FW_FILTER_WR_DMAC(f->fs.newdmac) |
5026 V_FW_FILTER_WR_SMAC(f->fs.newsmac) |
5027 V_FW_FILTER_WR_INSVLAN(f->fs.newvlan == VLAN_INSERT ||
5028 f->fs.newvlan == VLAN_REWRITE) |
5029 V_FW_FILTER_WR_RMVLAN(f->fs.newvlan == VLAN_REMOVE ||
5030 f->fs.newvlan == VLAN_REWRITE) |
5031 V_FW_FILTER_WR_HITCNTS(f->fs.hitcnts) |
5032 V_FW_FILTER_WR_TXCHAN(f->fs.eport) |
5033 V_FW_FILTER_WR_PRIO(f->fs.prio) |
5034 V_FW_FILTER_WR_L2TIX(f->l2t ? f->l2t->idx : 0));
5035 fwr->ethtype = htobe16(f->fs.val.ethtype);
5036 fwr->ethtypem = htobe16(f->fs.mask.ethtype);
5037 fwr->frag_to_ovlan_vldm =
5038 (V_FW_FILTER_WR_FRAG(f->fs.val.frag) |
5039 V_FW_FILTER_WR_FRAGM(f->fs.mask.frag) |
5040 V_FW_FILTER_WR_IVLAN_VLD(f->fs.val.vlan_vld) |
5041 V_FW_FILTER_WR_OVLAN_VLD(f->fs.val.vnic_vld) |
5042 V_FW_FILTER_WR_IVLAN_VLDM(f->fs.mask.vlan_vld) |
5043 V_FW_FILTER_WR_OVLAN_VLDM(f->fs.mask.vnic_vld));
5045 fwr->rx_chan_rx_rpl_iq = htobe16(V_FW_FILTER_WR_RX_CHAN(0) |
5046 V_FW_FILTER_WR_RX_RPL_IQ(sc->sge.fwq.abs_id));
5047 fwr->maci_to_matchtypem =
5048 htobe32(V_FW_FILTER_WR_MACI(f->fs.val.macidx) |
5049 V_FW_FILTER_WR_MACIM(f->fs.mask.macidx) |
5050 V_FW_FILTER_WR_FCOE(f->fs.val.fcoe) |
5051 V_FW_FILTER_WR_FCOEM(f->fs.mask.fcoe) |
5052 V_FW_FILTER_WR_PORT(f->fs.val.iport) |
5053 V_FW_FILTER_WR_PORTM(f->fs.mask.iport) |
5054 V_FW_FILTER_WR_MATCHTYPE(f->fs.val.matchtype) |
5055 V_FW_FILTER_WR_MATCHTYPEM(f->fs.mask.matchtype));
5056 fwr->ptcl = f->fs.val.proto;
5057 fwr->ptclm = f->fs.mask.proto;
5058 fwr->ttyp = f->fs.val.tos;
5059 fwr->ttypm = f->fs.mask.tos;
5060 fwr->ivlan = htobe16(f->fs.val.vlan);
5061 fwr->ivlanm = htobe16(f->fs.mask.vlan);
5062 fwr->ovlan = htobe16(f->fs.val.vnic);
5063 fwr->ovlanm = htobe16(f->fs.mask.vnic);
5064 bcopy(f->fs.val.dip, fwr->lip, sizeof (fwr->lip));
5065 bcopy(f->fs.mask.dip, fwr->lipm, sizeof (fwr->lipm));
5066 bcopy(f->fs.val.sip, fwr->fip, sizeof (fwr->fip));
5067 bcopy(f->fs.mask.sip, fwr->fipm, sizeof (fwr->fipm));
5068 fwr->lp = htobe16(f->fs.val.dport);
5069 fwr->lpm = htobe16(f->fs.mask.dport);
5070 fwr->fp = htobe16(f->fs.val.sport);
5071 fwr->fpm = htobe16(f->fs.mask.sport);
5073 bcopy(f->fs.smac, fwr->sma, sizeof (fwr->sma));
5076 sc->tids.ftids_in_use++;
5083 del_filter_wr(struct adapter *sc, int fidx)
5085 struct filter_entry *f = &sc->tids.ftid_tab[fidx];
5087 struct fw_filter_wr *fwr;
5090 ftid = sc->tids.ftid_base + fidx;
5092 wr = alloc_wrqe(sizeof(*fwr), &sc->sge.mgmtq);
5096 bzero(fwr, sizeof (*fwr));
5098 t4_mk_filtdelwr(ftid, fwr, sc->sge.fwq.abs_id);
5106 t4_filter_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
5108 struct adapter *sc = iq->adapter;
5109 const struct cpl_set_tcb_rpl *rpl = (const void *)(rss + 1);
5110 unsigned int idx = GET_TID(rpl);
5112 KASSERT(m == NULL, ("%s: payload with opcode %02x", __func__,
5115 if (idx >= sc->tids.ftid_base &&
5116 (idx -= sc->tids.ftid_base) < sc->tids.nftids) {
5117 unsigned int rc = G_COOKIE(rpl->cookie);
5118 struct filter_entry *f = &sc->tids.ftid_tab[idx];
5120 mtx_lock(&sc->tids.ftid_lock);
5121 if (rc == FW_FILTER_WR_FLT_ADDED) {
5122 KASSERT(f->pending, ("%s: filter[%u] isn't pending.",
5124 f->smtidx = (be64toh(rpl->oldval) >> 24) & 0xff;
5125 f->pending = 0; /* asynchronous setup completed */
5128 if (rc != FW_FILTER_WR_FLT_DELETED) {
5129 /* Add or delete failed, display an error */
5131 "filter %u setup failed with error %u\n",
5136 sc->tids.ftids_in_use--;
5138 wakeup(&sc->tids.ftid_tab);
5139 mtx_unlock(&sc->tids.ftid_lock);
5146 get_sge_context(struct adapter *sc, struct t4_sge_context *cntxt)
5150 if (cntxt->cid > M_CTXTQID)
5153 if (cntxt->mem_id != CTXT_EGRESS && cntxt->mem_id != CTXT_INGRESS &&
5154 cntxt->mem_id != CTXT_FLM && cntxt->mem_id != CTXT_CNM)
5157 if (sc->flags & FW_OK) {
5158 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK, "t4ctxt");
5160 rc = -t4_sge_ctxt_rd(sc, sc->mbox, cntxt->cid,
5161 cntxt->mem_id, &cntxt->data[0]);
5162 end_synchronized_op(sc, LOCK_HELD);
5169 * Read via firmware failed or wasn't even attempted. Read directly via
5172 rc = -t4_sge_ctxt_rd_bd(sc, cntxt->cid, cntxt->mem_id,
5178 load_fw(struct adapter *sc, struct t4_data *fw)
5183 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldfw");
5187 if (sc->flags & FULL_INIT_DONE) {
5192 fw_data = malloc(fw->len, M_CXGBE, M_WAITOK);
5193 if (fw_data == NULL) {
5198 rc = copyin(fw->data, fw_data, fw->len);
5200 rc = -t4_load_fw(sc, fw_data, fw->len);
5202 free(fw_data, M_CXGBE);
5204 end_synchronized_op(sc, 0);
5209 read_card_mem(struct adapter *sc, struct t4_mem_range *mr)
5211 uint32_t base, size, lo, hi, win, off, remaining, i, n;
5215 /* reads are in multiples of 32 bits */
5216 if (mr->addr & 3 || mr->len & 3 || mr->len == 0)
5220 * We don't want to deal with potential holes so we mandate that the
5221 * requested region must lie entirely within one of the 3 memories.
5223 lo = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
5224 if (lo & F_EDRAM0_ENABLE) {
5225 hi = t4_read_reg(sc, A_MA_EDRAM0_BAR);
5226 base = G_EDRAM0_BASE(hi) << 20;
5227 size = G_EDRAM0_SIZE(hi) << 20;
5229 mr->addr >= base && mr->addr < base + size &&
5230 mr->addr + mr->len <= base + size)
5233 if (lo & F_EDRAM1_ENABLE) {
5234 hi = t4_read_reg(sc, A_MA_EDRAM1_BAR);
5235 base = G_EDRAM1_BASE(hi) << 20;
5236 size = G_EDRAM1_SIZE(hi) << 20;
5238 mr->addr >= base && mr->addr < base + size &&
5239 mr->addr + mr->len <= base + size)
5242 if (lo & F_EXT_MEM_ENABLE) {
5243 hi = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
5244 base = G_EXT_MEM_BASE(hi) << 20;
5245 size = G_EXT_MEM_SIZE(hi) << 20;
5247 mr->addr >= base && mr->addr < base + size &&
5248 mr->addr + mr->len <= base + size)
5254 buf = b = malloc(mr->len, M_CXGBE, M_WAITOK);
5257 * Position the PCIe window (we use memwin2) to the 16B aligned area
5258 * just at/before the requested region.
5260 win = mr->addr & ~0xf;
5261 off = mr->addr - win; /* offset of the requested region in the win */
5262 remaining = mr->len;
5266 PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, 2), win);
5268 PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, 2));
5270 /* number of bytes that we'll copy in the inner loop */
5271 n = min(remaining, MEMWIN2_APERTURE - off);
5273 for (i = 0; i < n; i += 4, remaining -= 4)
5274 *b++ = t4_read_reg(sc, MEMWIN2_BASE + off + i);
5276 win += MEMWIN2_APERTURE;
5280 rc = copyout(buf, mr->data, mr->len);
5287 read_i2c(struct adapter *sc, struct t4_i2c_data *i2cd)
5291 if (i2cd->len == 0 || i2cd->port_id >= sc->params.nports)
5294 if (i2cd->len > 1) {
5295 /* XXX: need fw support for longer reads in one go */
5299 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4i2crd");
5302 rc = -t4_i2c_rd(sc, sc->mbox, i2cd->port_id, i2cd->dev_addr,
5303 i2cd->offset, &i2cd->data[0]);
5304 end_synchronized_op(sc, 0);
5310 t4_os_find_pci_capability(struct adapter *sc, int cap)
5314 return (pci_find_cap(sc->dev, cap, &i) == 0 ? i : 0);
5318 t4_os_pci_save_state(struct adapter *sc)
5321 struct pci_devinfo *dinfo;
5324 dinfo = device_get_ivars(dev);
5326 pci_cfg_save(dev, dinfo, 0);
5331 t4_os_pci_restore_state(struct adapter *sc)
5334 struct pci_devinfo *dinfo;
5337 dinfo = device_get_ivars(dev);
5339 pci_cfg_restore(dev, dinfo);
5344 t4_os_portmod_changed(const struct adapter *sc, int idx)
5346 struct port_info *pi = sc->port[idx];
5347 static const char *mod_str[] = {
5348 NULL, "LR", "SR", "ER", "TWINAX", "active TWINAX", "LRM"
5351 if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
5352 if_printf(pi->ifp, "transceiver unplugged.\n");
5353 else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
5354 if_printf(pi->ifp, "unknown transceiver inserted.\n");
5355 else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
5356 if_printf(pi->ifp, "unsupported transceiver inserted.\n");
5357 else if (pi->mod_type > 0 && pi->mod_type < nitems(mod_str)) {
5358 if_printf(pi->ifp, "%s transceiver inserted.\n",
5359 mod_str[pi->mod_type]);
5361 if_printf(pi->ifp, "transceiver (type %d) inserted.\n",
5367 t4_os_link_changed(struct adapter *sc, int idx, int link_stat)
5369 struct port_info *pi = sc->port[idx];
5370 struct ifnet *ifp = pi->ifp;
5373 ifp->if_baudrate = IF_Mbps(pi->link_cfg.speed);
5374 if_link_state_change(ifp, LINK_STATE_UP);
5376 if_link_state_change(ifp, LINK_STATE_DOWN);
5380 t4_iterate(void (*func)(struct adapter *, void *), void *arg)
5384 mtx_lock(&t4_list_lock);
5385 SLIST_FOREACH(sc, &t4_list, link) {
5387 * func should not make any assumptions about what state sc is
5388 * in - the only guarantee is that sc->sc_lock is a valid lock.
5392 mtx_unlock(&t4_list_lock);
5396 t4_open(struct cdev *dev, int flags, int type, struct thread *td)
5402 t4_close(struct cdev *dev, int flags, int type, struct thread *td)
5408 t4_ioctl(struct cdev *dev, unsigned long cmd, caddr_t data, int fflag,
5412 struct adapter *sc = dev->si_drv1;
5414 rc = priv_check(td, PRIV_DRIVER);
5419 case CHELSIO_T4_GETREG: {
5420 struct t4_reg *edata = (struct t4_reg *)data;
5422 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
5425 if (edata->size == 4)
5426 edata->val = t4_read_reg(sc, edata->addr);
5427 else if (edata->size == 8)
5428 edata->val = t4_read_reg64(sc, edata->addr);
5434 case CHELSIO_T4_SETREG: {
5435 struct t4_reg *edata = (struct t4_reg *)data;
5437 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
5440 if (edata->size == 4) {
5441 if (edata->val & 0xffffffff00000000)
5443 t4_write_reg(sc, edata->addr, (uint32_t) edata->val);
5444 } else if (edata->size == 8)
5445 t4_write_reg64(sc, edata->addr, edata->val);
5450 case CHELSIO_T4_REGDUMP: {
5451 struct t4_regdump *regs = (struct t4_regdump *)data;
5452 int reglen = T4_REGDUMP_SIZE;
5455 if (regs->len < reglen) {
5456 regs->len = reglen; /* hint to the caller */
5461 buf = malloc(reglen, M_CXGBE, M_WAITOK | M_ZERO);
5462 t4_get_regs(sc, regs, buf);
5463 rc = copyout(buf, regs->data, reglen);
5467 case CHELSIO_T4_GET_FILTER_MODE:
5468 rc = get_filter_mode(sc, (uint32_t *)data);
5470 case CHELSIO_T4_SET_FILTER_MODE:
5471 rc = set_filter_mode(sc, *(uint32_t *)data);
5473 case CHELSIO_T4_GET_FILTER:
5474 rc = get_filter(sc, (struct t4_filter *)data);
5476 case CHELSIO_T4_SET_FILTER:
5477 rc = set_filter(sc, (struct t4_filter *)data);
5479 case CHELSIO_T4_DEL_FILTER:
5480 rc = del_filter(sc, (struct t4_filter *)data);
5482 case CHELSIO_T4_GET_SGE_CONTEXT:
5483 rc = get_sge_context(sc, (struct t4_sge_context *)data);
5485 case CHELSIO_T4_LOAD_FW:
5486 rc = load_fw(sc, (struct t4_data *)data);
5488 case CHELSIO_T4_GET_MEM:
5489 rc = read_card_mem(sc, (struct t4_mem_range *)data);
5491 case CHELSIO_T4_GET_I2C:
5492 rc = read_i2c(sc, (struct t4_i2c_data *)data);
5494 case CHELSIO_T4_CLEAR_STATS: {
5496 u_int port_id = *(uint32_t *)data;
5497 struct port_info *pi;
5499 if (port_id >= sc->params.nports)
5503 t4_clr_port_stats(sc, port_id);
5505 pi = sc->port[port_id];
5506 if (pi->flags & PORT_INIT_DONE) {
5507 struct sge_rxq *rxq;
5508 struct sge_txq *txq;
5509 struct sge_wrq *wrq;
5511 for_each_rxq(pi, i, rxq) {
5512 #if defined(INET) || defined(INET6)
5513 rxq->lro.lro_queued = 0;
5514 rxq->lro.lro_flushed = 0;
5517 rxq->vlan_extraction = 0;
5520 for_each_txq(pi, i, txq) {
5523 txq->vlan_insertion = 0;
5527 txq->txpkts_wrs = 0;
5528 txq->txpkts_pkts = 0;
5534 /* nothing to clear for each ofld_rxq */
5536 for_each_ofld_txq(pi, i, wrq) {
5541 wrq = &sc->sge.ctrlq[pi->port_id];
5556 toe_capability(struct port_info *pi, int enable)
5559 struct adapter *sc = pi->adapter;
5561 ASSERT_SYNCHRONIZED_OP(sc);
5563 if (!is_offload(sc))
5567 if (!(sc->flags & FULL_INIT_DONE)) {
5568 rc = cxgbe_init_synchronized(pi);
5573 if (isset(&sc->offload_map, pi->port_id))
5576 if (!(sc->flags & TOM_INIT_DONE)) {
5577 rc = t4_activate_uld(sc, ULD_TOM);
5580 "You must kldload t4_tom.ko before trying "
5581 "to enable TOE on a cxgbe interface.\n");
5585 KASSERT(sc->tom_softc != NULL,
5586 ("%s: TOM activated but softc NULL", __func__));
5587 KASSERT(sc->flags & TOM_INIT_DONE,
5588 ("%s: TOM activated but flag not set", __func__));
5591 setbit(&sc->offload_map, pi->port_id);
5593 if (!isset(&sc->offload_map, pi->port_id))
5596 KASSERT(sc->flags & TOM_INIT_DONE,
5597 ("%s: TOM never initialized?", __func__));
5598 clrbit(&sc->offload_map, pi->port_id);
5605 * Add an upper layer driver to the global list.
5608 t4_register_uld(struct uld_info *ui)
5613 mtx_lock(&t4_uld_list_lock);
5614 SLIST_FOREACH(u, &t4_uld_list, link) {
5615 if (u->uld_id == ui->uld_id) {
5621 SLIST_INSERT_HEAD(&t4_uld_list, ui, link);
5624 mtx_unlock(&t4_uld_list_lock);
5629 t4_unregister_uld(struct uld_info *ui)
5634 mtx_lock(&t4_uld_list_lock);
5636 SLIST_FOREACH(u, &t4_uld_list, link) {
5638 if (ui->refcount > 0) {
5643 SLIST_REMOVE(&t4_uld_list, ui, uld_info, link);
5649 mtx_unlock(&t4_uld_list_lock);
5654 t4_activate_uld(struct adapter *sc, int id)
5657 struct uld_info *ui;
5659 ASSERT_SYNCHRONIZED_OP(sc);
5661 mtx_lock(&t4_uld_list_lock);
5663 SLIST_FOREACH(ui, &t4_uld_list, link) {
5664 if (ui->uld_id == id) {
5665 rc = ui->activate(sc);
5672 mtx_unlock(&t4_uld_list_lock);
5678 t4_deactivate_uld(struct adapter *sc, int id)
5681 struct uld_info *ui;
5683 ASSERT_SYNCHRONIZED_OP(sc);
5685 mtx_lock(&t4_uld_list_lock);
5687 SLIST_FOREACH(ui, &t4_uld_list, link) {
5688 if (ui->uld_id == id) {
5689 rc = ui->deactivate(sc);
5696 mtx_unlock(&t4_uld_list_lock);
5703 * Come up with reasonable defaults for some of the tunables, provided they're
5704 * not set by the user (in which case we'll use the values as is).
5707 tweak_tunables(void)
5709 int nc = mp_ncpus; /* our snapshot of the number of CPUs */
5712 t4_ntxq10g = min(nc, NTXQ_10G);
5715 t4_ntxq1g = min(nc, NTXQ_1G);
5718 t4_nrxq10g = min(nc, NRXQ_10G);
5721 t4_nrxq1g = min(nc, NRXQ_1G);
5724 if (t4_nofldtxq10g < 1)
5725 t4_nofldtxq10g = min(nc, NOFLDTXQ_10G);
5727 if (t4_nofldtxq1g < 1)
5728 t4_nofldtxq1g = min(nc, NOFLDTXQ_1G);
5730 if (t4_nofldrxq10g < 1)
5731 t4_nofldrxq10g = min(nc, NOFLDRXQ_10G);
5733 if (t4_nofldrxq1g < 1)
5734 t4_nofldrxq1g = min(nc, NOFLDRXQ_1G);
5736 if (t4_toecaps_allowed == -1)
5737 t4_toecaps_allowed = FW_CAPS_CONFIG_TOE;
5739 if (t4_toecaps_allowed == -1)
5740 t4_toecaps_allowed = 0;
5743 if (t4_tmr_idx_10g < 0 || t4_tmr_idx_10g >= SGE_NTIMERS)
5744 t4_tmr_idx_10g = TMR_IDX_10G;
5746 if (t4_pktc_idx_10g < -1 || t4_pktc_idx_10g >= SGE_NCOUNTERS)
5747 t4_pktc_idx_10g = PKTC_IDX_10G;
5749 if (t4_tmr_idx_1g < 0 || t4_tmr_idx_1g >= SGE_NTIMERS)
5750 t4_tmr_idx_1g = TMR_IDX_1G;
5752 if (t4_pktc_idx_1g < -1 || t4_pktc_idx_1g >= SGE_NCOUNTERS)
5753 t4_pktc_idx_1g = PKTC_IDX_1G;
5755 if (t4_qsize_txq < 128)
5758 if (t4_qsize_rxq < 128)
5760 while (t4_qsize_rxq & 7)
5763 t4_intr_types &= INTR_MSIX | INTR_MSI | INTR_INTX;
5767 t4_mod_event(module_t mod, int cmd, void *arg)
5774 mtx_init(&t4_list_lock, "T4 adapters", 0, MTX_DEF);
5775 SLIST_INIT(&t4_list);
5777 mtx_init(&t4_uld_list_lock, "T4 ULDs", 0, MTX_DEF);
5778 SLIST_INIT(&t4_uld_list);
5785 mtx_lock(&t4_uld_list_lock);
5786 if (!SLIST_EMPTY(&t4_uld_list)) {
5788 mtx_unlock(&t4_uld_list_lock);
5791 mtx_unlock(&t4_uld_list_lock);
5792 mtx_destroy(&t4_uld_list_lock);
5794 mtx_lock(&t4_list_lock);
5795 if (!SLIST_EMPTY(&t4_list)) {
5797 mtx_unlock(&t4_list_lock);
5800 mtx_unlock(&t4_list_lock);
5801 mtx_destroy(&t4_list_lock);
5808 static devclass_t t4_devclass;
5809 static devclass_t cxgbe_devclass;
5811 DRIVER_MODULE(t4nex, pci, t4_driver, t4_devclass, t4_mod_event, 0);
5812 MODULE_VERSION(t4nex, 1);
5814 DRIVER_MODULE(cxgbe, t4nex, cxgbe_driver, cxgbe_devclass, 0, 0);
5815 MODULE_VERSION(cxgbe, 1);