2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2011 Chelsio Communications, Inc.
6 * Written by: Navdeep Parhar <np@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
35 #include "opt_inet6.h"
36 #include "opt_ratelimit.h"
39 #include <sys/param.h>
42 #include <sys/kernel.h>
44 #include <sys/module.h>
45 #include <sys/malloc.h>
46 #include <sys/queue.h>
47 #include <sys/taskqueue.h>
48 #include <sys/pciio.h>
49 #include <dev/pci/pcireg.h>
50 #include <dev/pci/pcivar.h>
51 #include <dev/pci/pci_private.h>
52 #include <sys/firmware.h>
55 #include <sys/socket.h>
56 #include <sys/sockio.h>
57 #include <sys/sysctl.h>
58 #include <net/ethernet.h>
60 #include <net/if_types.h>
61 #include <net/if_dl.h>
62 #include <net/if_vlan_var.h>
64 #include <net/rss_config.h>
66 #if defined(__i386__) || defined(__amd64__)
67 #include <machine/md_var.h>
68 #include <machine/cputypes.h>
72 #include <crypto/rijndael/rijndael.h>
75 #include <ddb/db_lex.h>
78 #include "common/common.h"
79 #include "common/t4_msg.h"
80 #include "common/t4_regs.h"
81 #include "common/t4_regs_values.h"
82 #include "cudbg/cudbg.h"
85 #include "t4_mp_ring.h"
89 /* T4 bus driver interface */
90 static int t4_probe(device_t);
91 static int t4_attach(device_t);
92 static int t4_detach(device_t);
93 static int t4_child_location_str(device_t, device_t, char *, size_t);
94 static int t4_ready(device_t);
95 static int t4_read_port_device(device_t, int, device_t *);
96 static device_method_t t4_methods[] = {
97 DEVMETHOD(device_probe, t4_probe),
98 DEVMETHOD(device_attach, t4_attach),
99 DEVMETHOD(device_detach, t4_detach),
101 DEVMETHOD(bus_child_location_str, t4_child_location_str),
103 DEVMETHOD(t4_is_main_ready, t4_ready),
104 DEVMETHOD(t4_read_port_device, t4_read_port_device),
108 static driver_t t4_driver = {
111 sizeof(struct adapter)
115 /* T4 port (cxgbe) interface */
116 static int cxgbe_probe(device_t);
117 static int cxgbe_attach(device_t);
118 static int cxgbe_detach(device_t);
119 device_method_t cxgbe_methods[] = {
120 DEVMETHOD(device_probe, cxgbe_probe),
121 DEVMETHOD(device_attach, cxgbe_attach),
122 DEVMETHOD(device_detach, cxgbe_detach),
125 static driver_t cxgbe_driver = {
128 sizeof(struct port_info)
131 /* T4 VI (vcxgbe) interface */
132 static int vcxgbe_probe(device_t);
133 static int vcxgbe_attach(device_t);
134 static int vcxgbe_detach(device_t);
135 static device_method_t vcxgbe_methods[] = {
136 DEVMETHOD(device_probe, vcxgbe_probe),
137 DEVMETHOD(device_attach, vcxgbe_attach),
138 DEVMETHOD(device_detach, vcxgbe_detach),
141 static driver_t vcxgbe_driver = {
144 sizeof(struct vi_info)
147 static d_ioctl_t t4_ioctl;
149 static struct cdevsw t4_cdevsw = {
150 .d_version = D_VERSION,
155 /* T5 bus driver interface */
156 static int t5_probe(device_t);
157 static device_method_t t5_methods[] = {
158 DEVMETHOD(device_probe, t5_probe),
159 DEVMETHOD(device_attach, t4_attach),
160 DEVMETHOD(device_detach, t4_detach),
162 DEVMETHOD(bus_child_location_str, t4_child_location_str),
164 DEVMETHOD(t4_is_main_ready, t4_ready),
165 DEVMETHOD(t4_read_port_device, t4_read_port_device),
169 static driver_t t5_driver = {
172 sizeof(struct adapter)
176 /* T5 port (cxl) interface */
177 static driver_t cxl_driver = {
180 sizeof(struct port_info)
183 /* T5 VI (vcxl) interface */
184 static driver_t vcxl_driver = {
187 sizeof(struct vi_info)
190 /* T6 bus driver interface */
191 static int t6_probe(device_t);
192 static device_method_t t6_methods[] = {
193 DEVMETHOD(device_probe, t6_probe),
194 DEVMETHOD(device_attach, t4_attach),
195 DEVMETHOD(device_detach, t4_detach),
197 DEVMETHOD(bus_child_location_str, t4_child_location_str),
199 DEVMETHOD(t4_is_main_ready, t4_ready),
200 DEVMETHOD(t4_read_port_device, t4_read_port_device),
204 static driver_t t6_driver = {
207 sizeof(struct adapter)
211 /* T6 port (cc) interface */
212 static driver_t cc_driver = {
215 sizeof(struct port_info)
218 /* T6 VI (vcc) interface */
219 static driver_t vcc_driver = {
222 sizeof(struct vi_info)
225 /* ifnet interface */
226 static void cxgbe_init(void *);
227 static int cxgbe_ioctl(struct ifnet *, unsigned long, caddr_t);
228 static int cxgbe_transmit(struct ifnet *, struct mbuf *);
229 static void cxgbe_qflush(struct ifnet *);
231 MALLOC_DEFINE(M_CXGBE, "cxgbe", "Chelsio T4/T5 Ethernet driver and services");
234 * Correct lock order when you need to acquire multiple locks is t4_list_lock,
235 * then ADAPTER_LOCK, then t4_uld_list_lock.
237 static struct sx t4_list_lock;
238 SLIST_HEAD(, adapter) t4_list;
240 static struct sx t4_uld_list_lock;
241 SLIST_HEAD(, uld_info) t4_uld_list;
245 * Tunables. See tweak_tunables() too.
247 * Each tunable is set to a default value here if it's known at compile-time.
248 * Otherwise it is set to -n as an indication to tweak_tunables() that it should
249 * provide a reasonable default (upto n) when the driver is loaded.
251 * Tunables applicable to both T4 and T5 are under hw.cxgbe. Those specific to
252 * T5 are under hw.cxl.
256 * Number of queues for tx and rx, NIC and offload.
260 TUNABLE_INT("hw.cxgbe.ntxq", &t4_ntxq);
261 TUNABLE_INT("hw.cxgbe.ntxq10g", &t4_ntxq); /* Old name, undocumented */
265 TUNABLE_INT("hw.cxgbe.nrxq", &t4_nrxq);
266 TUNABLE_INT("hw.cxgbe.nrxq10g", &t4_nrxq); /* Old name, undocumented */
269 static int t4_ntxq_vi = -NTXQ_VI;
270 TUNABLE_INT("hw.cxgbe.ntxq_vi", &t4_ntxq_vi);
273 static int t4_nrxq_vi = -NRXQ_VI;
274 TUNABLE_INT("hw.cxgbe.nrxq_vi", &t4_nrxq_vi);
276 static int t4_rsrv_noflowq = 0;
277 TUNABLE_INT("hw.cxgbe.rsrv_noflowq", &t4_rsrv_noflowq);
279 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
281 static int t4_nofldtxq = -NOFLDTXQ;
282 TUNABLE_INT("hw.cxgbe.nofldtxq", &t4_nofldtxq);
285 static int t4_nofldrxq = -NOFLDRXQ;
286 TUNABLE_INT("hw.cxgbe.nofldrxq", &t4_nofldrxq);
288 #define NOFLDTXQ_VI 1
289 static int t4_nofldtxq_vi = -NOFLDTXQ_VI;
290 TUNABLE_INT("hw.cxgbe.nofldtxq_vi", &t4_nofldtxq_vi);
292 #define NOFLDRXQ_VI 1
293 static int t4_nofldrxq_vi = -NOFLDRXQ_VI;
294 TUNABLE_INT("hw.cxgbe.nofldrxq_vi", &t4_nofldrxq_vi);
296 #define TMR_IDX_OFLD 1
297 int t4_tmr_idx_ofld = TMR_IDX_OFLD;
298 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_ofld", &t4_tmr_idx_ofld);
300 #define PKTC_IDX_OFLD (-1)
301 int t4_pktc_idx_ofld = PKTC_IDX_OFLD;
302 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_ofld", &t4_pktc_idx_ofld);
304 /* 0 means chip/fw default, non-zero number is value in microseconds */
305 static u_long t4_toe_keepalive_idle = 0;
306 TUNABLE_ULONG("hw.cxgbe.toe.keepalive_idle", &t4_toe_keepalive_idle);
308 /* 0 means chip/fw default, non-zero number is value in microseconds */
309 static u_long t4_toe_keepalive_interval = 0;
310 TUNABLE_ULONG("hw.cxgbe.toe.keepalive_interval", &t4_toe_keepalive_interval);
312 /* 0 means chip/fw default, non-zero number is # of keepalives before abort */
313 static int t4_toe_keepalive_count = 0;
314 TUNABLE_INT("hw.cxgbe.toe.keepalive_count", &t4_toe_keepalive_count);
316 /* 0 means chip/fw default, non-zero number is value in microseconds */
317 static u_long t4_toe_rexmt_min = 0;
318 TUNABLE_ULONG("hw.cxgbe.toe.rexmt_min", &t4_toe_rexmt_min);
320 /* 0 means chip/fw default, non-zero number is value in microseconds */
321 static u_long t4_toe_rexmt_max = 0;
322 TUNABLE_ULONG("hw.cxgbe.toe.rexmt_max", &t4_toe_rexmt_max);
324 /* 0 means chip/fw default, non-zero number is # of rexmt before abort */
325 static int t4_toe_rexmt_count = 0;
326 TUNABLE_INT("hw.cxgbe.toe.rexmt_count", &t4_toe_rexmt_count);
328 /* -1 means chip/fw default, other values are raw backoff values to use */
329 static int t4_toe_rexmt_backoff[16] = {
330 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
332 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.0", &t4_toe_rexmt_backoff[0]);
333 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.1", &t4_toe_rexmt_backoff[1]);
334 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.2", &t4_toe_rexmt_backoff[2]);
335 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.3", &t4_toe_rexmt_backoff[3]);
336 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.4", &t4_toe_rexmt_backoff[4]);
337 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.5", &t4_toe_rexmt_backoff[5]);
338 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.6", &t4_toe_rexmt_backoff[6]);
339 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.7", &t4_toe_rexmt_backoff[7]);
340 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.8", &t4_toe_rexmt_backoff[8]);
341 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.9", &t4_toe_rexmt_backoff[9]);
342 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.10", &t4_toe_rexmt_backoff[10]);
343 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.11", &t4_toe_rexmt_backoff[11]);
344 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.12", &t4_toe_rexmt_backoff[12]);
345 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.13", &t4_toe_rexmt_backoff[13]);
346 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.14", &t4_toe_rexmt_backoff[14]);
347 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.15", &t4_toe_rexmt_backoff[15]);
352 static int t4_nnmtxq_vi = -NNMTXQ_VI;
353 TUNABLE_INT("hw.cxgbe.nnmtxq_vi", &t4_nnmtxq_vi);
356 static int t4_nnmrxq_vi = -NNMRXQ_VI;
357 TUNABLE_INT("hw.cxgbe.nnmrxq_vi", &t4_nnmrxq_vi);
361 * Holdoff parameters for ports.
364 int t4_tmr_idx = TMR_IDX;
365 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx", &t4_tmr_idx);
366 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_10G", &t4_tmr_idx); /* Old name */
368 #define PKTC_IDX (-1)
369 int t4_pktc_idx = PKTC_IDX;
370 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx", &t4_pktc_idx);
371 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_10G", &t4_pktc_idx); /* Old name */
374 * Size (# of entries) of each tx and rx queue.
376 unsigned int t4_qsize_txq = TX_EQ_QSIZE;
377 TUNABLE_INT("hw.cxgbe.qsize_txq", &t4_qsize_txq);
379 unsigned int t4_qsize_rxq = RX_IQ_QSIZE;
380 TUNABLE_INT("hw.cxgbe.qsize_rxq", &t4_qsize_rxq);
383 * Interrupt types allowed (bits 0, 1, 2 = INTx, MSI, MSI-X respectively).
385 int t4_intr_types = INTR_MSIX | INTR_MSI | INTR_INTX;
386 TUNABLE_INT("hw.cxgbe.interrupt_types", &t4_intr_types);
389 * Configuration file. All the _CF names here are special.
391 #define DEFAULT_CF "default"
392 #define BUILTIN_CF "built-in"
393 #define FLASH_CF "flash"
394 #define UWIRE_CF "uwire"
395 #define FPGA_CF "fpga"
396 static char t4_cfg_file[32] = DEFAULT_CF;
397 TUNABLE_STR("hw.cxgbe.config_file", t4_cfg_file, sizeof(t4_cfg_file));
400 * PAUSE settings (bit 0, 1, 2 = rx_pause, tx_pause, pause_autoneg respectively).
401 * rx_pause = 1 to heed incoming PAUSE frames, 0 to ignore them.
402 * tx_pause = 1 to emit PAUSE frames when the rx FIFO reaches its high water
403 * mark or when signalled to do so, 0 to never emit PAUSE.
404 * pause_autoneg = 1 means PAUSE will be negotiated if possible and the
405 * negotiated settings will override rx_pause/tx_pause.
406 * Otherwise rx_pause/tx_pause are applied forcibly.
408 static int t4_pause_settings = PAUSE_RX | PAUSE_TX | PAUSE_AUTONEG;
409 TUNABLE_INT("hw.cxgbe.pause_settings", &t4_pause_settings);
412 * Forward Error Correction settings (bit 0, 1 = RS, BASER respectively).
413 * -1 to run with the firmware default. Same as FEC_AUTO (bit 5)
416 static int t4_fec = -1;
417 TUNABLE_INT("hw.cxgbe.fec", &t4_fec);
420 * Link autonegotiation.
421 * -1 to run with the firmware default.
425 static int t4_autoneg = -1;
426 TUNABLE_INT("hw.cxgbe.autoneg", &t4_autoneg);
429 * Firmware auto-install by driver during attach (0, 1, 2 = prohibited, allowed,
430 * encouraged respectively).
432 static unsigned int t4_fw_install = 1;
433 TUNABLE_INT("hw.cxgbe.fw_install", &t4_fw_install);
436 * ASIC features that will be used. Disable the ones you don't want so that the
437 * chip resources aren't wasted on features that will not be used.
439 static int t4_nbmcaps_allowed = 0;
440 TUNABLE_INT("hw.cxgbe.nbmcaps_allowed", &t4_nbmcaps_allowed);
442 static int t4_linkcaps_allowed = 0; /* No DCBX, PPP, etc. by default */
443 TUNABLE_INT("hw.cxgbe.linkcaps_allowed", &t4_linkcaps_allowed);
445 static int t4_switchcaps_allowed = FW_CAPS_CONFIG_SWITCH_INGRESS |
446 FW_CAPS_CONFIG_SWITCH_EGRESS;
447 TUNABLE_INT("hw.cxgbe.switchcaps_allowed", &t4_switchcaps_allowed);
450 static int t4_niccaps_allowed = FW_CAPS_CONFIG_NIC |
451 FW_CAPS_CONFIG_NIC_HASHFILTER | FW_CAPS_CONFIG_NIC_ETHOFLD;
453 static int t4_niccaps_allowed = FW_CAPS_CONFIG_NIC |
454 FW_CAPS_CONFIG_NIC_HASHFILTER;
456 TUNABLE_INT("hw.cxgbe.niccaps_allowed", &t4_niccaps_allowed);
458 static int t4_toecaps_allowed = -1;
459 TUNABLE_INT("hw.cxgbe.toecaps_allowed", &t4_toecaps_allowed);
461 static int t4_rdmacaps_allowed = -1;
462 TUNABLE_INT("hw.cxgbe.rdmacaps_allowed", &t4_rdmacaps_allowed);
464 static int t4_cryptocaps_allowed = -1;
465 TUNABLE_INT("hw.cxgbe.cryptocaps_allowed", &t4_cryptocaps_allowed);
467 static int t4_iscsicaps_allowed = -1;
468 TUNABLE_INT("hw.cxgbe.iscsicaps_allowed", &t4_iscsicaps_allowed);
470 static int t4_fcoecaps_allowed = 0;
471 TUNABLE_INT("hw.cxgbe.fcoecaps_allowed", &t4_fcoecaps_allowed);
473 static int t5_write_combine = 0;
474 TUNABLE_INT("hw.cxl.write_combine", &t5_write_combine);
476 static int t4_num_vis = 1;
477 TUNABLE_INT("hw.cxgbe.num_vis", &t4_num_vis);
479 * PCIe Relaxed Ordering.
480 * -1: driver should figure out a good value.
485 static int pcie_relaxed_ordering = -1;
486 TUNABLE_INT("hw.cxgbe.pcie_relaxed_ordering", &pcie_relaxed_ordering);
488 static int t4_panic_on_fatal_err = 0;
489 TUNABLE_INT("hw.cxgbe.panic_on_fatal_err", &t4_panic_on_fatal_err);
495 static int t4_cop_managed_offloading = 0;
496 TUNABLE_INT("hw.cxgbe.cop_managed_offloading", &t4_cop_managed_offloading);
499 /* Functions used by VIs to obtain unique MAC addresses for each VI. */
500 static int vi_mac_funcs[] = {
504 FW_VI_FUNC_OPENISCSI,
510 struct intrs_and_queues {
511 uint16_t intr_type; /* INTx, MSI, or MSI-X */
512 uint16_t num_vis; /* number of VIs for each port */
513 uint16_t nirq; /* Total # of vectors */
514 uint16_t ntxq; /* # of NIC txq's for each port */
515 uint16_t nrxq; /* # of NIC rxq's for each port */
516 uint16_t nofldtxq; /* # of TOE/ETHOFLD txq's for each port */
517 uint16_t nofldrxq; /* # of TOE rxq's for each port */
519 /* The vcxgbe/vcxl interfaces use these and not the ones above. */
520 uint16_t ntxq_vi; /* # of NIC txq's */
521 uint16_t nrxq_vi; /* # of NIC rxq's */
522 uint16_t nofldtxq_vi; /* # of TOE txq's */
523 uint16_t nofldrxq_vi; /* # of TOE rxq's */
524 uint16_t nnmtxq_vi; /* # of netmap txq's */
525 uint16_t nnmrxq_vi; /* # of netmap rxq's */
528 static void setup_memwin(struct adapter *);
529 static void position_memwin(struct adapter *, int, uint32_t);
530 static int validate_mem_range(struct adapter *, uint32_t, uint32_t);
531 static int fwmtype_to_hwmtype(int);
532 static int validate_mt_off_len(struct adapter *, int, uint32_t, uint32_t,
534 static int fixup_devlog_params(struct adapter *);
535 static int cfg_itype_and_nqueues(struct adapter *, struct intrs_and_queues *);
536 static int prep_firmware(struct adapter *);
537 static int partition_resources(struct adapter *, const struct firmware *,
539 static int get_params__pre_init(struct adapter *);
540 static int get_params__post_init(struct adapter *);
541 static int set_params__post_init(struct adapter *);
542 static void t4_set_desc(struct adapter *);
543 static bool fixed_ifmedia(struct port_info *);
544 static void build_medialist(struct port_info *);
545 static void init_link_config(struct port_info *);
546 static int fixup_link_config(struct port_info *);
547 static int apply_link_config(struct port_info *);
548 static int cxgbe_init_synchronized(struct vi_info *);
549 static int cxgbe_uninit_synchronized(struct vi_info *);
550 static void quiesce_txq(struct adapter *, struct sge_txq *);
551 static void quiesce_wrq(struct adapter *, struct sge_wrq *);
552 static void quiesce_iq(struct adapter *, struct sge_iq *);
553 static void quiesce_fl(struct adapter *, struct sge_fl *);
554 static int t4_alloc_irq(struct adapter *, struct irq *, int rid,
555 driver_intr_t *, void *, char *);
556 static int t4_free_irq(struct adapter *, struct irq *);
557 static void get_regs(struct adapter *, struct t4_regdump *, uint8_t *);
558 static void vi_refresh_stats(struct adapter *, struct vi_info *);
559 static void cxgbe_refresh_stats(struct adapter *, struct port_info *);
560 static void cxgbe_tick(void *);
561 static void cxgbe_sysctls(struct port_info *);
562 static int sysctl_int_array(SYSCTL_HANDLER_ARGS);
563 static int sysctl_bitfield_8b(SYSCTL_HANDLER_ARGS);
564 static int sysctl_bitfield_16b(SYSCTL_HANDLER_ARGS);
565 static int sysctl_btphy(SYSCTL_HANDLER_ARGS);
566 static int sysctl_noflowq(SYSCTL_HANDLER_ARGS);
567 static int sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS);
568 static int sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS);
569 static int sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS);
570 static int sysctl_qsize_txq(SYSCTL_HANDLER_ARGS);
571 static int sysctl_pause_settings(SYSCTL_HANDLER_ARGS);
572 static int sysctl_fec(SYSCTL_HANDLER_ARGS);
573 static int sysctl_autoneg(SYSCTL_HANDLER_ARGS);
574 static int sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS);
575 static int sysctl_temperature(SYSCTL_HANDLER_ARGS);
576 static int sysctl_loadavg(SYSCTL_HANDLER_ARGS);
577 static int sysctl_cctrl(SYSCTL_HANDLER_ARGS);
578 static int sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS);
579 static int sysctl_cim_la(SYSCTL_HANDLER_ARGS);
580 static int sysctl_cim_la_t6(SYSCTL_HANDLER_ARGS);
581 static int sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS);
582 static int sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS);
583 static int sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS);
584 static int sysctl_cpl_stats(SYSCTL_HANDLER_ARGS);
585 static int sysctl_ddp_stats(SYSCTL_HANDLER_ARGS);
586 static int sysctl_devlog(SYSCTL_HANDLER_ARGS);
587 static int sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS);
588 static int sysctl_hw_sched(SYSCTL_HANDLER_ARGS);
589 static int sysctl_lb_stats(SYSCTL_HANDLER_ARGS);
590 static int sysctl_linkdnrc(SYSCTL_HANDLER_ARGS);
591 static int sysctl_meminfo(SYSCTL_HANDLER_ARGS);
592 static int sysctl_mps_tcam(SYSCTL_HANDLER_ARGS);
593 static int sysctl_mps_tcam_t6(SYSCTL_HANDLER_ARGS);
594 static int sysctl_path_mtus(SYSCTL_HANDLER_ARGS);
595 static int sysctl_pm_stats(SYSCTL_HANDLER_ARGS);
596 static int sysctl_rdma_stats(SYSCTL_HANDLER_ARGS);
597 static int sysctl_tcp_stats(SYSCTL_HANDLER_ARGS);
598 static int sysctl_tids(SYSCTL_HANDLER_ARGS);
599 static int sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS);
600 static int sysctl_tp_la_mask(SYSCTL_HANDLER_ARGS);
601 static int sysctl_tp_la(SYSCTL_HANDLER_ARGS);
602 static int sysctl_tx_rate(SYSCTL_HANDLER_ARGS);
603 static int sysctl_ulprx_la(SYSCTL_HANDLER_ARGS);
604 static int sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS);
605 static int sysctl_cpus(SYSCTL_HANDLER_ARGS);
607 static int sysctl_tls_rx_ports(SYSCTL_HANDLER_ARGS);
608 static int sysctl_tp_tick(SYSCTL_HANDLER_ARGS);
609 static int sysctl_tp_dack_timer(SYSCTL_HANDLER_ARGS);
610 static int sysctl_tp_timer(SYSCTL_HANDLER_ARGS);
611 static int sysctl_tp_shift_cnt(SYSCTL_HANDLER_ARGS);
612 static int sysctl_tp_backoff(SYSCTL_HANDLER_ARGS);
613 static int sysctl_holdoff_tmr_idx_ofld(SYSCTL_HANDLER_ARGS);
614 static int sysctl_holdoff_pktc_idx_ofld(SYSCTL_HANDLER_ARGS);
616 static int get_sge_context(struct adapter *, struct t4_sge_context *);
617 static int load_fw(struct adapter *, struct t4_data *);
618 static int load_cfg(struct adapter *, struct t4_data *);
619 static int load_boot(struct adapter *, struct t4_bootrom *);
620 static int load_bootcfg(struct adapter *, struct t4_data *);
621 static int cudbg_dump(struct adapter *, struct t4_cudbg_dump *);
622 static void free_offload_policy(struct t4_offload_policy *);
623 static int set_offload_policy(struct adapter *, struct t4_offload_policy *);
624 static int read_card_mem(struct adapter *, int, struct t4_mem_range *);
625 static int read_i2c(struct adapter *, struct t4_i2c_data *);
627 static int toe_capability(struct vi_info *, int);
629 static int mod_event(module_t, int, void *);
630 static int notify_siblings(device_t, int);
636 {0xa000, "Chelsio Terminator 4 FPGA"},
637 {0x4400, "Chelsio T440-dbg"},
638 {0x4401, "Chelsio T420-CR"},
639 {0x4402, "Chelsio T422-CR"},
640 {0x4403, "Chelsio T440-CR"},
641 {0x4404, "Chelsio T420-BCH"},
642 {0x4405, "Chelsio T440-BCH"},
643 {0x4406, "Chelsio T440-CH"},
644 {0x4407, "Chelsio T420-SO"},
645 {0x4408, "Chelsio T420-CX"},
646 {0x4409, "Chelsio T420-BT"},
647 {0x440a, "Chelsio T404-BT"},
648 {0x440e, "Chelsio T440-LP-CR"},
650 {0xb000, "Chelsio Terminator 5 FPGA"},
651 {0x5400, "Chelsio T580-dbg"},
652 {0x5401, "Chelsio T520-CR"}, /* 2 x 10G */
653 {0x5402, "Chelsio T522-CR"}, /* 2 x 10G, 2 X 1G */
654 {0x5403, "Chelsio T540-CR"}, /* 4 x 10G */
655 {0x5407, "Chelsio T520-SO"}, /* 2 x 10G, nomem */
656 {0x5409, "Chelsio T520-BT"}, /* 2 x 10GBaseT */
657 {0x540a, "Chelsio T504-BT"}, /* 4 x 1G */
658 {0x540d, "Chelsio T580-CR"}, /* 2 x 40G */
659 {0x540e, "Chelsio T540-LP-CR"}, /* 4 x 10G */
660 {0x5410, "Chelsio T580-LP-CR"}, /* 2 x 40G */
661 {0x5411, "Chelsio T520-LL-CR"}, /* 2 x 10G */
662 {0x5412, "Chelsio T560-CR"}, /* 1 x 40G, 2 x 10G */
663 {0x5414, "Chelsio T580-LP-SO-CR"}, /* 2 x 40G, nomem */
664 {0x5415, "Chelsio T502-BT"}, /* 2 x 1G */
665 {0x5418, "Chelsio T540-BT"}, /* 4 x 10GBaseT */
666 {0x5419, "Chelsio T540-LP-BT"}, /* 4 x 10GBaseT */
667 {0x541a, "Chelsio T540-SO-BT"}, /* 4 x 10GBaseT, nomem */
668 {0x541b, "Chelsio T540-SO-CR"}, /* 4 x 10G, nomem */
670 {0xc006, "Chelsio Terminator 6 FPGA"}, /* T6 PE10K6 FPGA (PF0) */
671 {0x6400, "Chelsio T6-DBG-25"}, /* 2 x 10/25G, debug */
672 {0x6401, "Chelsio T6225-CR"}, /* 2 x 10/25G */
673 {0x6402, "Chelsio T6225-SO-CR"}, /* 2 x 10/25G, nomem */
674 {0x6403, "Chelsio T6425-CR"}, /* 4 x 10/25G */
675 {0x6404, "Chelsio T6425-SO-CR"}, /* 4 x 10/25G, nomem */
676 {0x6405, "Chelsio T6225-OCP-SO"}, /* 2 x 10/25G, nomem */
677 {0x6406, "Chelsio T62100-OCP-SO"}, /* 2 x 40/50/100G, nomem */
678 {0x6407, "Chelsio T62100-LP-CR"}, /* 2 x 40/50/100G */
679 {0x6408, "Chelsio T62100-SO-CR"}, /* 2 x 40/50/100G, nomem */
680 {0x6409, "Chelsio T6210-BT"}, /* 2 x 10GBASE-T */
681 {0x640d, "Chelsio T62100-CR"}, /* 2 x 40/50/100G */
682 {0x6410, "Chelsio T6-DBG-100"}, /* 2 x 40/50/100G, debug */
683 {0x6411, "Chelsio T6225-LL-CR"}, /* 2 x 10/25G */
684 {0x6414, "Chelsio T61100-OCP-SO"}, /* 1 x 40/50/100G, nomem */
685 {0x6415, "Chelsio T6201-BT"}, /* 2 x 1000BASE-T */
688 {0x6480, "Custom T6225-CR"},
689 {0x6481, "Custom T62100-CR"},
690 {0x6482, "Custom T6225-CR"},
691 {0x6483, "Custom T62100-CR"},
692 {0x6484, "Custom T64100-CR"},
693 {0x6485, "Custom T6240-SO"},
694 {0x6486, "Custom T6225-SO-CR"},
695 {0x6487, "Custom T6225-CR"},
700 * service_iq_fl() has an iq and needs the fl. Offset of fl from the iq should
701 * be exactly the same for both rxq and ofld_rxq.
703 CTASSERT(offsetof(struct sge_ofld_rxq, iq) == offsetof(struct sge_rxq, iq));
704 CTASSERT(offsetof(struct sge_ofld_rxq, fl) == offsetof(struct sge_rxq, fl));
706 CTASSERT(sizeof(struct cluster_metadata) <= CL_METADATA_SIZE);
709 t4_probe(device_t dev)
712 uint16_t v = pci_get_vendor(dev);
713 uint16_t d = pci_get_device(dev);
714 uint8_t f = pci_get_function(dev);
716 if (v != PCI_VENDOR_ID_CHELSIO)
719 /* Attach only to PF0 of the FPGA */
720 if (d == 0xa000 && f != 0)
723 for (i = 0; i < nitems(t4_pciids); i++) {
724 if (d == t4_pciids[i].device) {
725 device_set_desc(dev, t4_pciids[i].desc);
726 return (BUS_PROBE_DEFAULT);
734 t5_probe(device_t dev)
737 uint16_t v = pci_get_vendor(dev);
738 uint16_t d = pci_get_device(dev);
739 uint8_t f = pci_get_function(dev);
741 if (v != PCI_VENDOR_ID_CHELSIO)
744 /* Attach only to PF0 of the FPGA */
745 if (d == 0xb000 && f != 0)
748 for (i = 0; i < nitems(t5_pciids); i++) {
749 if (d == t5_pciids[i].device) {
750 device_set_desc(dev, t5_pciids[i].desc);
751 return (BUS_PROBE_DEFAULT);
759 t6_probe(device_t dev)
762 uint16_t v = pci_get_vendor(dev);
763 uint16_t d = pci_get_device(dev);
765 if (v != PCI_VENDOR_ID_CHELSIO)
768 for (i = 0; i < nitems(t6_pciids); i++) {
769 if (d == t6_pciids[i].device) {
770 device_set_desc(dev, t6_pciids[i].desc);
771 return (BUS_PROBE_DEFAULT);
779 t5_attribute_workaround(device_t dev)
785 * The T5 chips do not properly echo the No Snoop and Relaxed
786 * Ordering attributes when replying to a TLP from a Root
787 * Port. As a workaround, find the parent Root Port and
788 * disable No Snoop and Relaxed Ordering. Note that this
789 * affects all devices under this root port.
791 root_port = pci_find_pcie_root_port(dev);
792 if (root_port == NULL) {
793 device_printf(dev, "Unable to find parent root port\n");
797 v = pcie_adjust_config(root_port, PCIER_DEVICE_CTL,
798 PCIEM_CTL_RELAXED_ORD_ENABLE | PCIEM_CTL_NOSNOOP_ENABLE, 0, 2);
799 if ((v & (PCIEM_CTL_RELAXED_ORD_ENABLE | PCIEM_CTL_NOSNOOP_ENABLE)) !=
801 device_printf(dev, "Disabled No Snoop/Relaxed Ordering on %s\n",
802 device_get_nameunit(root_port));
805 static const struct devnames devnames[] = {
807 .nexus_name = "t4nex",
808 .ifnet_name = "cxgbe",
809 .vi_ifnet_name = "vcxgbe",
810 .pf03_drv_name = "t4iov",
811 .vf_nexus_name = "t4vf",
812 .vf_ifnet_name = "cxgbev"
814 .nexus_name = "t5nex",
816 .vi_ifnet_name = "vcxl",
817 .pf03_drv_name = "t5iov",
818 .vf_nexus_name = "t5vf",
819 .vf_ifnet_name = "cxlv"
821 .nexus_name = "t6nex",
823 .vi_ifnet_name = "vcc",
824 .pf03_drv_name = "t6iov",
825 .vf_nexus_name = "t6vf",
826 .vf_ifnet_name = "ccv"
831 t4_init_devnames(struct adapter *sc)
836 if (id >= CHELSIO_T4 && id - CHELSIO_T4 < nitems(devnames))
837 sc->names = &devnames[id - CHELSIO_T4];
839 device_printf(sc->dev, "chip id %d is not supported.\n", id);
845 t4_ifnet_unit(struct adapter *sc, struct port_info *pi)
847 const char *parent, *name;
852 parent = device_get_nameunit(sc->dev);
853 name = sc->names->ifnet_name;
854 while (resource_find_dev(&line, name, &unit, "at", parent) == 0) {
855 if (resource_long_value(name, unit, "port", &value) == 0 &&
856 value == pi->port_id)
863 t4_attach(device_t dev)
866 int rc = 0, i, j, rqidx, tqidx, nports;
867 struct make_dev_args mda;
868 struct intrs_and_queues iaq;
871 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
878 int nm_rqidx, nm_tqidx;
882 sc = device_get_softc(dev);
884 TUNABLE_INT_FETCH("hw.cxgbe.dflags", &sc->debug_flags);
886 if ((pci_get_device(dev) & 0xff00) == 0x5400)
887 t5_attribute_workaround(dev);
888 pci_enable_busmaster(dev);
889 if (pci_find_cap(dev, PCIY_EXPRESS, &i) == 0) {
892 pci_set_max_read_req(dev, 4096);
893 v = pci_read_config(dev, i + PCIER_DEVICE_CTL, 2);
894 sc->params.pci.mps = 128 << ((v & PCIEM_CTL_MAX_PAYLOAD) >> 5);
895 if (pcie_relaxed_ordering == 0 &&
896 (v & PCIEM_CTL_RELAXED_ORD_ENABLE) != 0) {
897 v &= ~PCIEM_CTL_RELAXED_ORD_ENABLE;
898 pci_write_config(dev, i + PCIER_DEVICE_CTL, v, 2);
899 } else if (pcie_relaxed_ordering == 1 &&
900 (v & PCIEM_CTL_RELAXED_ORD_ENABLE) == 0) {
901 v |= PCIEM_CTL_RELAXED_ORD_ENABLE;
902 pci_write_config(dev, i + PCIER_DEVICE_CTL, v, 2);
906 sc->sge_gts_reg = MYPF_REG(A_SGE_PF_GTS);
907 sc->sge_kdoorbell_reg = MYPF_REG(A_SGE_PF_KDOORBELL);
909 mtx_init(&sc->ifp_lock, sc->ifp_lockname, 0, MTX_DEF);
910 snprintf(sc->ifp_lockname, sizeof(sc->ifp_lockname), "%s tracer",
911 device_get_nameunit(dev));
913 snprintf(sc->lockname, sizeof(sc->lockname), "%s",
914 device_get_nameunit(dev));
915 mtx_init(&sc->sc_lock, sc->lockname, 0, MTX_DEF);
918 mtx_init(&sc->sfl_lock, "starving freelists", 0, MTX_DEF);
919 TAILQ_INIT(&sc->sfl);
920 callout_init_mtx(&sc->sfl_callout, &sc->sfl_lock, 0);
922 mtx_init(&sc->reg_lock, "indirect register access", 0, MTX_DEF);
925 rw_init(&sc->policy_lock, "connection offload policy");
927 rc = t4_map_bars_0_and_4(sc);
929 goto done; /* error message displayed already */
931 memset(sc->chan_map, 0xff, sizeof(sc->chan_map));
933 /* Prepare the adapter for operation. */
934 buf = malloc(PAGE_SIZE, M_CXGBE, M_ZERO | M_WAITOK);
935 rc = -t4_prep_adapter(sc, buf);
938 device_printf(dev, "failed to prepare adapter: %d.\n", rc);
943 * This is the real PF# to which we're attaching. Works from within PCI
944 * passthrough environments too, where pci_get_function() could return a
945 * different PF# depending on the passthrough configuration. We need to
946 * use the real PF# in all our communication with the firmware.
948 j = t4_read_reg(sc, A_PL_WHOAMI);
949 sc->pf = chip_id(sc) <= CHELSIO_T5 ? G_SOURCEPF(j) : G_T6_SOURCEPF(j);
952 t4_init_devnames(sc);
953 if (sc->names == NULL) {
955 goto done; /* error message displayed already */
959 * Do this really early, with the memory windows set up even before the
960 * character device. The userland tool's register i/o and mem read
961 * will work even in "recovery mode".
964 if (t4_init_devlog_params(sc, 0) == 0)
965 fixup_devlog_params(sc);
966 make_dev_args_init(&mda);
967 mda.mda_devsw = &t4_cdevsw;
968 mda.mda_uid = UID_ROOT;
969 mda.mda_gid = GID_WHEEL;
971 mda.mda_si_drv1 = sc;
972 rc = make_dev_s(&mda, &sc->cdev, "%s", device_get_nameunit(dev));
974 device_printf(dev, "failed to create nexus char device: %d.\n",
977 /* Go no further if recovery mode has been requested. */
978 if (TUNABLE_INT_FETCH("hw.cxgbe.sos", &i) && i != 0) {
979 device_printf(dev, "recovery mode.\n");
983 #if defined(__i386__)
984 if ((cpu_feature & CPUID_CX8) == 0) {
985 device_printf(dev, "64 bit atomics not available.\n");
991 /* Prepare the firmware for operation */
992 rc = prep_firmware(sc);
994 goto done; /* error message displayed already */
996 rc = get_params__post_init(sc);
998 goto done; /* error message displayed already */
1000 rc = set_params__post_init(sc);
1002 goto done; /* error message displayed already */
1004 rc = t4_map_bar_2(sc);
1006 goto done; /* error message displayed already */
1008 rc = t4_create_dma_tag(sc);
1010 goto done; /* error message displayed already */
1013 * First pass over all the ports - allocate VIs and initialize some
1014 * basic parameters like mac address, port type, etc.
1016 for_each_port(sc, i) {
1017 struct port_info *pi;
1019 pi = malloc(sizeof(*pi), M_CXGBE, M_ZERO | M_WAITOK);
1022 /* These must be set before t4_port_init */
1026 * XXX: vi[0] is special so we can't delay this allocation until
1027 * pi->nvi's final value is known.
1029 pi->vi = malloc(sizeof(struct vi_info) * t4_num_vis, M_CXGBE,
1033 * Allocate the "main" VI and initialize parameters
1036 rc = -t4_port_init(sc, sc->mbox, sc->pf, 0, i);
1038 device_printf(dev, "unable to initialize port %d: %d\n",
1040 free(pi->vi, M_CXGBE);
1046 snprintf(pi->lockname, sizeof(pi->lockname), "%sp%d",
1047 device_get_nameunit(dev), i);
1048 mtx_init(&pi->pi_lock, pi->lockname, 0, MTX_DEF);
1049 sc->chan_map[pi->tx_chan] = i;
1051 /* All VIs on this port share this media. */
1052 ifmedia_init(&pi->media, IFM_IMASK, cxgbe_media_change,
1053 cxgbe_media_status);
1056 init_link_config(pi);
1057 fixup_link_config(pi);
1058 build_medialist(pi);
1059 if (fixed_ifmedia(pi))
1060 pi->flags |= FIXED_IFMEDIA;
1063 pi->dev = device_add_child(dev, sc->names->ifnet_name,
1064 t4_ifnet_unit(sc, pi));
1065 if (pi->dev == NULL) {
1067 "failed to add device for port %d.\n", i);
1071 pi->vi[0].dev = pi->dev;
1072 device_set_softc(pi->dev, pi);
1076 * Interrupt type, # of interrupts, # of rx/tx queues, etc.
1078 nports = sc->params.nports;
1079 rc = cfg_itype_and_nqueues(sc, &iaq);
1081 goto done; /* error message displayed already */
1083 num_vis = iaq.num_vis;
1084 sc->intr_type = iaq.intr_type;
1085 sc->intr_count = iaq.nirq;
1088 s->nrxq = nports * iaq.nrxq;
1089 s->ntxq = nports * iaq.ntxq;
1091 s->nrxq += nports * (num_vis - 1) * iaq.nrxq_vi;
1092 s->ntxq += nports * (num_vis - 1) * iaq.ntxq_vi;
1094 s->neq = s->ntxq + s->nrxq; /* the free list in an rxq is an eq */
1095 s->neq += nports; /* ctrl queues: 1 per port */
1096 s->niq = s->nrxq + 1; /* 1 extra for firmware event queue */
1097 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
1098 if (is_offload(sc) || is_ethoffload(sc)) {
1099 s->nofldtxq = nports * iaq.nofldtxq;
1101 s->nofldtxq += nports * (num_vis - 1) * iaq.nofldtxq_vi;
1102 s->neq += s->nofldtxq;
1104 s->ofld_txq = malloc(s->nofldtxq * sizeof(struct sge_wrq),
1105 M_CXGBE, M_ZERO | M_WAITOK);
1109 if (is_offload(sc)) {
1110 s->nofldrxq = nports * iaq.nofldrxq;
1112 s->nofldrxq += nports * (num_vis - 1) * iaq.nofldrxq_vi;
1113 s->neq += s->nofldrxq; /* free list */
1114 s->niq += s->nofldrxq;
1116 s->ofld_rxq = malloc(s->nofldrxq * sizeof(struct sge_ofld_rxq),
1117 M_CXGBE, M_ZERO | M_WAITOK);
1122 s->nnmrxq = nports * (num_vis - 1) * iaq.nnmrxq_vi;
1123 s->nnmtxq = nports * (num_vis - 1) * iaq.nnmtxq_vi;
1125 s->neq += s->nnmtxq + s->nnmrxq;
1126 s->niq += s->nnmrxq;
1128 s->nm_rxq = malloc(s->nnmrxq * sizeof(struct sge_nm_rxq),
1129 M_CXGBE, M_ZERO | M_WAITOK);
1130 s->nm_txq = malloc(s->nnmtxq * sizeof(struct sge_nm_txq),
1131 M_CXGBE, M_ZERO | M_WAITOK);
1134 s->ctrlq = malloc(nports * sizeof(struct sge_wrq), M_CXGBE,
1136 s->rxq = malloc(s->nrxq * sizeof(struct sge_rxq), M_CXGBE,
1138 s->txq = malloc(s->ntxq * sizeof(struct sge_txq), M_CXGBE,
1140 s->iqmap = malloc(s->niq * sizeof(struct sge_iq *), M_CXGBE,
1142 s->eqmap = malloc(s->neq * sizeof(struct sge_eq *), M_CXGBE,
1145 sc->irq = malloc(sc->intr_count * sizeof(struct irq), M_CXGBE,
1148 t4_init_l2t(sc, M_WAITOK);
1149 t4_init_smt(sc, M_WAITOK);
1150 t4_init_tx_sched(sc);
1152 t4_init_etid_table(sc);
1156 * Second pass over the ports. This time we know the number of rx and
1157 * tx queues that each port should get.
1160 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
1167 nm_rqidx = nm_tqidx = 0;
1169 for_each_port(sc, i) {
1170 struct port_info *pi = sc->port[i];
1177 for_each_vi(pi, j, vi) {
1179 vi->qsize_rxq = t4_qsize_rxq;
1180 vi->qsize_txq = t4_qsize_txq;
1182 vi->first_rxq = rqidx;
1183 vi->first_txq = tqidx;
1184 vi->tmr_idx = t4_tmr_idx;
1185 vi->pktc_idx = t4_pktc_idx;
1186 vi->nrxq = j == 0 ? iaq.nrxq : iaq.nrxq_vi;
1187 vi->ntxq = j == 0 ? iaq.ntxq : iaq.ntxq_vi;
1192 if (j == 0 && vi->ntxq > 1)
1193 vi->rsrv_noflowq = t4_rsrv_noflowq ? 1 : 0;
1195 vi->rsrv_noflowq = 0;
1197 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
1198 vi->first_ofld_txq = ofld_tqidx;
1199 vi->nofldtxq = j == 0 ? iaq.nofldtxq : iaq.nofldtxq_vi;
1200 ofld_tqidx += vi->nofldtxq;
1203 vi->ofld_tmr_idx = t4_tmr_idx_ofld;
1204 vi->ofld_pktc_idx = t4_pktc_idx_ofld;
1205 vi->first_ofld_rxq = ofld_rqidx;
1206 vi->nofldrxq = j == 0 ? iaq.nofldrxq : iaq.nofldrxq_vi;
1208 ofld_rqidx += vi->nofldrxq;
1212 vi->first_nm_rxq = nm_rqidx;
1213 vi->first_nm_txq = nm_tqidx;
1214 vi->nnmrxq = iaq.nnmrxq_vi;
1215 vi->nnmtxq = iaq.nnmtxq_vi;
1216 nm_rqidx += vi->nnmrxq;
1217 nm_tqidx += vi->nnmtxq;
1223 rc = t4_setup_intr_handlers(sc);
1226 "failed to setup interrupt handlers: %d\n", rc);
1230 rc = bus_generic_probe(dev);
1232 device_printf(dev, "failed to probe child drivers: %d\n", rc);
1237 * Ensure thread-safe mailbox access (in debug builds).
1239 * So far this was the only thread accessing the mailbox but various
1240 * ifnets and sysctls are about to be created and their handlers/ioctls
1241 * will access the mailbox from different threads.
1243 sc->flags |= CHK_MBOX_ACCESS;
1245 rc = bus_generic_attach(dev);
1248 "failed to attach all child ports: %d\n", rc);
1253 "PCIe gen%d x%d, %d ports, %d %s interrupt%s, %d eq, %d iq\n",
1254 sc->params.pci.speed, sc->params.pci.width, sc->params.nports,
1255 sc->intr_count, sc->intr_type == INTR_MSIX ? "MSI-X" :
1256 (sc->intr_type == INTR_MSI ? "MSI" : "INTx"),
1257 sc->intr_count > 1 ? "s" : "", sc->sge.neq, sc->sge.niq);
1261 notify_siblings(dev, 0);
1264 if (rc != 0 && sc->cdev) {
1265 /* cdev was created and so cxgbetool works; recover that way. */
1267 "error during attach, adapter is now in recovery mode.\n");
1272 t4_detach_common(dev);
1280 t4_child_location_str(device_t bus, device_t dev, char *buf, size_t buflen)
1282 struct port_info *pi;
1284 pi = device_get_softc(dev);
1285 snprintf(buf, buflen, "port=%d", pi->port_id);
1290 t4_ready(device_t dev)
1294 sc = device_get_softc(dev);
1295 if (sc->flags & FW_OK)
1301 t4_read_port_device(device_t dev, int port, device_t *child)
1304 struct port_info *pi;
1306 sc = device_get_softc(dev);
1307 if (port < 0 || port >= MAX_NPORTS)
1309 pi = sc->port[port];
1310 if (pi == NULL || pi->dev == NULL)
1317 notify_siblings(device_t dev, int detaching)
1323 for (i = 0; i < PCI_FUNCMAX; i++) {
1324 if (i == pci_get_function(dev))
1326 sibling = pci_find_dbsf(pci_get_domain(dev), pci_get_bus(dev),
1327 pci_get_slot(dev), i);
1328 if (sibling == NULL || !device_is_attached(sibling))
1331 error = T4_DETACH_CHILD(sibling);
1333 (void)T4_ATTACH_CHILD(sibling);
1344 t4_detach(device_t dev)
1349 sc = device_get_softc(dev);
1351 rc = notify_siblings(dev, 1);
1354 "failed to detach sibling devices: %d\n", rc);
1358 return (t4_detach_common(dev));
1362 t4_detach_common(device_t dev)
1365 struct port_info *pi;
1368 sc = device_get_softc(dev);
1371 destroy_dev(sc->cdev);
1375 sc->flags &= ~CHK_MBOX_ACCESS;
1376 if (sc->flags & FULL_INIT_DONE) {
1377 if (!(sc->flags & IS_VF))
1378 t4_intr_disable(sc);
1381 if (device_is_attached(dev)) {
1382 rc = bus_generic_detach(dev);
1385 "failed to detach child devices: %d\n", rc);
1390 for (i = 0; i < sc->intr_count; i++)
1391 t4_free_irq(sc, &sc->irq[i]);
1393 if ((sc->flags & (IS_VF | FW_OK)) == FW_OK)
1394 t4_free_tx_sched(sc);
1396 for (i = 0; i < MAX_NPORTS; i++) {
1399 t4_free_vi(sc, sc->mbox, sc->pf, 0, pi->vi[0].viid);
1401 device_delete_child(dev, pi->dev);
1403 mtx_destroy(&pi->pi_lock);
1404 free(pi->vi, M_CXGBE);
1409 device_delete_children(dev);
1411 if (sc->flags & FULL_INIT_DONE)
1412 adapter_full_uninit(sc);
1414 if ((sc->flags & (IS_VF | FW_OK)) == FW_OK)
1415 t4_fw_bye(sc, sc->mbox);
1417 if (sc->intr_type == INTR_MSI || sc->intr_type == INTR_MSIX)
1418 pci_release_msi(dev);
1421 bus_release_resource(dev, SYS_RES_MEMORY, sc->regs_rid,
1425 bus_release_resource(dev, SYS_RES_MEMORY, sc->udbs_rid,
1429 bus_release_resource(dev, SYS_RES_MEMORY, sc->msix_rid,
1433 t4_free_l2t(sc->l2t);
1435 t4_free_smt(sc->smt);
1437 t4_free_etid_table(sc);
1440 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
1441 free(sc->sge.ofld_txq, M_CXGBE);
1444 free(sc->sge.ofld_rxq, M_CXGBE);
1447 free(sc->sge.nm_rxq, M_CXGBE);
1448 free(sc->sge.nm_txq, M_CXGBE);
1450 free(sc->irq, M_CXGBE);
1451 free(sc->sge.rxq, M_CXGBE);
1452 free(sc->sge.txq, M_CXGBE);
1453 free(sc->sge.ctrlq, M_CXGBE);
1454 free(sc->sge.iqmap, M_CXGBE);
1455 free(sc->sge.eqmap, M_CXGBE);
1456 free(sc->tids.ftid_tab, M_CXGBE);
1457 free(sc->tids.hpftid_tab, M_CXGBE);
1458 free_hftid_hash(&sc->tids);
1459 free(sc->tids.atid_tab, M_CXGBE);
1460 free(sc->tids.tid_tab, M_CXGBE);
1461 free(sc->tt.tls_rx_ports, M_CXGBE);
1462 t4_destroy_dma_tag(sc);
1463 if (mtx_initialized(&sc->sc_lock)) {
1464 sx_xlock(&t4_list_lock);
1465 SLIST_REMOVE(&t4_list, sc, adapter, link);
1466 sx_xunlock(&t4_list_lock);
1467 mtx_destroy(&sc->sc_lock);
1470 callout_drain(&sc->sfl_callout);
1471 if (mtx_initialized(&sc->tids.ftid_lock)) {
1472 mtx_destroy(&sc->tids.ftid_lock);
1473 cv_destroy(&sc->tids.ftid_cv);
1475 if (mtx_initialized(&sc->tids.atid_lock))
1476 mtx_destroy(&sc->tids.atid_lock);
1477 if (mtx_initialized(&sc->sfl_lock))
1478 mtx_destroy(&sc->sfl_lock);
1479 if (mtx_initialized(&sc->ifp_lock))
1480 mtx_destroy(&sc->ifp_lock);
1481 if (mtx_initialized(&sc->reg_lock))
1482 mtx_destroy(&sc->reg_lock);
1484 if (rw_initialized(&sc->policy_lock)) {
1485 rw_destroy(&sc->policy_lock);
1487 if (sc->policy != NULL)
1488 free_offload_policy(sc->policy);
1492 for (i = 0; i < NUM_MEMWIN; i++) {
1493 struct memwin *mw = &sc->memwin[i];
1495 if (rw_initialized(&mw->mw_lock))
1496 rw_destroy(&mw->mw_lock);
1499 bzero(sc, sizeof(*sc));
1505 cxgbe_probe(device_t dev)
1508 struct port_info *pi = device_get_softc(dev);
1510 snprintf(buf, sizeof(buf), "port %d", pi->port_id);
1511 device_set_desc_copy(dev, buf);
1513 return (BUS_PROBE_DEFAULT);
1516 #define T4_CAP (IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_HWCSUM | \
1517 IFCAP_VLAN_HWCSUM | IFCAP_TSO | IFCAP_JUMBO_MTU | IFCAP_LRO | \
1518 IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWCSUM_IPV6 | IFCAP_HWSTATS | \
1520 #define T4_CAP_ENABLE (T4_CAP)
1523 cxgbe_vi_attach(device_t dev, struct vi_info *vi)
1528 vi->xact_addr_filt = -1;
1529 callout_init(&vi->tick, 1);
1531 /* Allocate an ifnet and set it up */
1532 ifp = if_alloc(IFT_ETHER);
1534 device_printf(dev, "Cannot allocate ifnet\n");
1540 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1541 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1543 ifp->if_init = cxgbe_init;
1544 ifp->if_ioctl = cxgbe_ioctl;
1545 ifp->if_transmit = cxgbe_transmit;
1546 ifp->if_qflush = cxgbe_qflush;
1547 ifp->if_get_counter = cxgbe_get_counter;
1549 ifp->if_snd_tag_alloc = cxgbe_snd_tag_alloc;
1550 ifp->if_snd_tag_modify = cxgbe_snd_tag_modify;
1551 ifp->if_snd_tag_query = cxgbe_snd_tag_query;
1552 ifp->if_snd_tag_free = cxgbe_snd_tag_free;
1555 ifp->if_capabilities = T4_CAP;
1556 ifp->if_capenable = T4_CAP_ENABLE;
1558 if (vi->nofldrxq != 0)
1559 ifp->if_capabilities |= IFCAP_TOE;
1562 if (is_ethoffload(vi->pi->adapter) && vi->nofldtxq != 0) {
1563 ifp->if_capabilities |= IFCAP_TXRTLMT;
1564 ifp->if_capenable |= IFCAP_TXRTLMT;
1567 ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_IP | CSUM_TSO |
1568 CSUM_UDP_IPV6 | CSUM_TCP_IPV6;
1570 ifp->if_hw_tsomax = 65536 - (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
1571 ifp->if_hw_tsomaxsegcount = TX_SGL_SEGS;
1572 ifp->if_hw_tsomaxsegsize = 65536;
1574 ether_ifattach(ifp, vi->hw_addr);
1576 if (vi->nnmrxq != 0)
1577 cxgbe_nm_attach(vi);
1579 sb = sbuf_new_auto();
1580 sbuf_printf(sb, "%d txq, %d rxq (NIC)", vi->ntxq, vi->nrxq);
1581 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
1582 switch (ifp->if_capabilities & (IFCAP_TOE | IFCAP_TXRTLMT)) {
1584 sbuf_printf(sb, "; %d txq (TOE)", vi->nofldtxq);
1586 case IFCAP_TOE | IFCAP_TXRTLMT:
1587 sbuf_printf(sb, "; %d txq (TOE/ETHOFLD)", vi->nofldtxq);
1590 sbuf_printf(sb, "; %d txq (ETHOFLD)", vi->nofldtxq);
1595 if (ifp->if_capabilities & IFCAP_TOE)
1596 sbuf_printf(sb, ", %d rxq (TOE)", vi->nofldrxq);
1599 if (ifp->if_capabilities & IFCAP_NETMAP)
1600 sbuf_printf(sb, "; %d txq, %d rxq (netmap)",
1601 vi->nnmtxq, vi->nnmrxq);
1604 device_printf(dev, "%s\n", sbuf_data(sb));
1613 cxgbe_attach(device_t dev)
1615 struct port_info *pi = device_get_softc(dev);
1616 struct adapter *sc = pi->adapter;
1620 callout_init_mtx(&pi->tick, &pi->pi_lock, 0);
1622 rc = cxgbe_vi_attach(dev, &pi->vi[0]);
1626 for_each_vi(pi, i, vi) {
1629 vi->dev = device_add_child(dev, sc->names->vi_ifnet_name, -1);
1630 if (vi->dev == NULL) {
1631 device_printf(dev, "failed to add VI %d\n", i);
1634 device_set_softc(vi->dev, vi);
1639 bus_generic_attach(dev);
1645 cxgbe_vi_detach(struct vi_info *vi)
1647 struct ifnet *ifp = vi->ifp;
1649 ether_ifdetach(ifp);
1651 /* Let detach proceed even if these fail. */
1653 if (ifp->if_capabilities & IFCAP_NETMAP)
1654 cxgbe_nm_detach(vi);
1656 cxgbe_uninit_synchronized(vi);
1657 callout_drain(&vi->tick);
1665 cxgbe_detach(device_t dev)
1667 struct port_info *pi = device_get_softc(dev);
1668 struct adapter *sc = pi->adapter;
1671 /* Detach the extra VIs first. */
1672 rc = bus_generic_detach(dev);
1675 device_delete_children(dev);
1677 doom_vi(sc, &pi->vi[0]);
1679 if (pi->flags & HAS_TRACEQ) {
1680 sc->traceq = -1; /* cloner should not create ifnet */
1681 t4_tracer_port_detach(sc);
1684 cxgbe_vi_detach(&pi->vi[0]);
1685 callout_drain(&pi->tick);
1686 ifmedia_removeall(&pi->media);
1688 end_synchronized_op(sc, 0);
1694 cxgbe_init(void *arg)
1696 struct vi_info *vi = arg;
1697 struct adapter *sc = vi->pi->adapter;
1699 if (begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4init") != 0)
1701 cxgbe_init_synchronized(vi);
1702 end_synchronized_op(sc, 0);
1706 cxgbe_ioctl(struct ifnet *ifp, unsigned long cmd, caddr_t data)
1708 int rc = 0, mtu, flags;
1709 struct vi_info *vi = ifp->if_softc;
1710 struct port_info *pi = vi->pi;
1711 struct adapter *sc = pi->adapter;
1712 struct ifreq *ifr = (struct ifreq *)data;
1718 if (mtu < ETHERMIN || mtu > MAX_MTU)
1721 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4mtu");
1725 if (vi->flags & VI_INIT_DONE) {
1726 t4_update_fl_bufsize(ifp);
1727 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1728 rc = update_mac_settings(ifp, XGMAC_MTU);
1730 end_synchronized_op(sc, 0);
1734 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4flg");
1738 if (ifp->if_flags & IFF_UP) {
1739 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1740 flags = vi->if_flags;
1741 if ((ifp->if_flags ^ flags) &
1742 (IFF_PROMISC | IFF_ALLMULTI)) {
1743 rc = update_mac_settings(ifp,
1744 XGMAC_PROMISC | XGMAC_ALLMULTI);
1747 rc = cxgbe_init_synchronized(vi);
1749 vi->if_flags = ifp->if_flags;
1750 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1751 rc = cxgbe_uninit_synchronized(vi);
1753 end_synchronized_op(sc, 0);
1758 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4multi");
1761 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1762 rc = update_mac_settings(ifp, XGMAC_MCADDRS);
1763 end_synchronized_op(sc, 0);
1767 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4cap");
1771 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1772 if (mask & IFCAP_TXCSUM) {
1773 ifp->if_capenable ^= IFCAP_TXCSUM;
1774 ifp->if_hwassist ^= (CSUM_TCP | CSUM_UDP | CSUM_IP);
1776 if (IFCAP_TSO4 & ifp->if_capenable &&
1777 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1778 ifp->if_capenable &= ~IFCAP_TSO4;
1780 "tso4 disabled due to -txcsum.\n");
1783 if (mask & IFCAP_TXCSUM_IPV6) {
1784 ifp->if_capenable ^= IFCAP_TXCSUM_IPV6;
1785 ifp->if_hwassist ^= (CSUM_UDP_IPV6 | CSUM_TCP_IPV6);
1787 if (IFCAP_TSO6 & ifp->if_capenable &&
1788 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1789 ifp->if_capenable &= ~IFCAP_TSO6;
1791 "tso6 disabled due to -txcsum6.\n");
1794 if (mask & IFCAP_RXCSUM)
1795 ifp->if_capenable ^= IFCAP_RXCSUM;
1796 if (mask & IFCAP_RXCSUM_IPV6)
1797 ifp->if_capenable ^= IFCAP_RXCSUM_IPV6;
1800 * Note that we leave CSUM_TSO alone (it is always set). The
1801 * kernel takes both IFCAP_TSOx and CSUM_TSO into account before
1802 * sending a TSO request our way, so it's sufficient to toggle
1805 if (mask & IFCAP_TSO4) {
1806 if (!(IFCAP_TSO4 & ifp->if_capenable) &&
1807 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1808 if_printf(ifp, "enable txcsum first.\n");
1812 ifp->if_capenable ^= IFCAP_TSO4;
1814 if (mask & IFCAP_TSO6) {
1815 if (!(IFCAP_TSO6 & ifp->if_capenable) &&
1816 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1817 if_printf(ifp, "enable txcsum6 first.\n");
1821 ifp->if_capenable ^= IFCAP_TSO6;
1823 if (mask & IFCAP_LRO) {
1824 #if defined(INET) || defined(INET6)
1826 struct sge_rxq *rxq;
1828 ifp->if_capenable ^= IFCAP_LRO;
1829 for_each_rxq(vi, i, rxq) {
1830 if (ifp->if_capenable & IFCAP_LRO)
1831 rxq->iq.flags |= IQ_LRO_ENABLED;
1833 rxq->iq.flags &= ~IQ_LRO_ENABLED;
1838 if (mask & IFCAP_TOE) {
1839 int enable = (ifp->if_capenable ^ mask) & IFCAP_TOE;
1841 rc = toe_capability(vi, enable);
1845 ifp->if_capenable ^= mask;
1848 if (mask & IFCAP_VLAN_HWTAGGING) {
1849 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
1850 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1851 rc = update_mac_settings(ifp, XGMAC_VLANEX);
1853 if (mask & IFCAP_VLAN_MTU) {
1854 ifp->if_capenable ^= IFCAP_VLAN_MTU;
1856 /* Need to find out how to disable auto-mtu-inflation */
1858 if (mask & IFCAP_VLAN_HWTSO)
1859 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
1860 if (mask & IFCAP_VLAN_HWCSUM)
1861 ifp->if_capenable ^= IFCAP_VLAN_HWCSUM;
1863 if (mask & IFCAP_TXRTLMT)
1864 ifp->if_capenable ^= IFCAP_TXRTLMT;
1866 if (mask & IFCAP_HWRXTSTMP) {
1868 struct sge_rxq *rxq;
1870 ifp->if_capenable ^= IFCAP_HWRXTSTMP;
1871 for_each_rxq(vi, i, rxq) {
1872 if (ifp->if_capenable & IFCAP_HWRXTSTMP)
1873 rxq->iq.flags |= IQ_RX_TIMESTAMP;
1875 rxq->iq.flags &= ~IQ_RX_TIMESTAMP;
1879 #ifdef VLAN_CAPABILITIES
1880 VLAN_CAPABILITIES(ifp);
1883 end_synchronized_op(sc, 0);
1889 ifmedia_ioctl(ifp, ifr, &pi->media, cmd);
1893 struct ifi2creq i2c;
1895 rc = copyin(ifr_data_get_ptr(ifr), &i2c, sizeof(i2c));
1898 if (i2c.dev_addr != 0xA0 && i2c.dev_addr != 0xA2) {
1902 if (i2c.len > sizeof(i2c.data)) {
1906 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4i2c");
1909 rc = -t4_i2c_rd(sc, sc->mbox, pi->port_id, i2c.dev_addr,
1910 i2c.offset, i2c.len, &i2c.data[0]);
1911 end_synchronized_op(sc, 0);
1913 rc = copyout(&i2c, ifr_data_get_ptr(ifr), sizeof(i2c));
1918 rc = ether_ioctl(ifp, cmd, data);
1925 cxgbe_transmit(struct ifnet *ifp, struct mbuf *m)
1927 struct vi_info *vi = ifp->if_softc;
1928 struct port_info *pi = vi->pi;
1929 struct adapter *sc = pi->adapter;
1930 struct sge_txq *txq;
1935 MPASS(m->m_nextpkt == NULL); /* not quite ready for this yet */
1937 if (__predict_false(pi->link_cfg.link_ok == false)) {
1942 rc = parse_pkt(sc, &m);
1943 if (__predict_false(rc != 0)) {
1944 MPASS(m == NULL); /* was freed already */
1945 atomic_add_int(&pi->tx_parse_error, 1); /* rare, atomic is ok */
1949 if (m->m_pkthdr.snd_tag != NULL) {
1950 /* EAGAIN tells the stack we are not the correct interface. */
1951 if (__predict_false(ifp != m->m_pkthdr.snd_tag->ifp)) {
1956 return (ethofld_transmit(ifp, m));
1961 txq = &sc->sge.txq[vi->first_txq];
1962 if (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE)
1963 txq += ((m->m_pkthdr.flowid % (vi->ntxq - vi->rsrv_noflowq)) +
1967 rc = mp_ring_enqueue(txq->r, items, 1, 4096);
1968 if (__predict_false(rc != 0))
1975 cxgbe_qflush(struct ifnet *ifp)
1977 struct vi_info *vi = ifp->if_softc;
1978 struct sge_txq *txq;
1981 /* queues do not exist if !VI_INIT_DONE. */
1982 if (vi->flags & VI_INIT_DONE) {
1983 for_each_txq(vi, i, txq) {
1985 txq->eq.flags |= EQ_QFLUSH;
1987 while (!mp_ring_is_idle(txq->r)) {
1988 mp_ring_check_drainage(txq->r, 0);
1992 txq->eq.flags &= ~EQ_QFLUSH;
2000 vi_get_counter(struct ifnet *ifp, ift_counter c)
2002 struct vi_info *vi = ifp->if_softc;
2003 struct fw_vi_stats_vf *s = &vi->stats;
2005 vi_refresh_stats(vi->pi->adapter, vi);
2008 case IFCOUNTER_IPACKETS:
2009 return (s->rx_bcast_frames + s->rx_mcast_frames +
2010 s->rx_ucast_frames);
2011 case IFCOUNTER_IERRORS:
2012 return (s->rx_err_frames);
2013 case IFCOUNTER_OPACKETS:
2014 return (s->tx_bcast_frames + s->tx_mcast_frames +
2015 s->tx_ucast_frames + s->tx_offload_frames);
2016 case IFCOUNTER_OERRORS:
2017 return (s->tx_drop_frames);
2018 case IFCOUNTER_IBYTES:
2019 return (s->rx_bcast_bytes + s->rx_mcast_bytes +
2021 case IFCOUNTER_OBYTES:
2022 return (s->tx_bcast_bytes + s->tx_mcast_bytes +
2023 s->tx_ucast_bytes + s->tx_offload_bytes);
2024 case IFCOUNTER_IMCASTS:
2025 return (s->rx_mcast_frames);
2026 case IFCOUNTER_OMCASTS:
2027 return (s->tx_mcast_frames);
2028 case IFCOUNTER_OQDROPS: {
2032 if (vi->flags & VI_INIT_DONE) {
2034 struct sge_txq *txq;
2036 for_each_txq(vi, i, txq)
2037 drops += counter_u64_fetch(txq->r->drops);
2045 return (if_get_counter_default(ifp, c));
2050 cxgbe_get_counter(struct ifnet *ifp, ift_counter c)
2052 struct vi_info *vi = ifp->if_softc;
2053 struct port_info *pi = vi->pi;
2054 struct adapter *sc = pi->adapter;
2055 struct port_stats *s = &pi->stats;
2057 if (pi->nvi > 1 || sc->flags & IS_VF)
2058 return (vi_get_counter(ifp, c));
2060 cxgbe_refresh_stats(sc, pi);
2063 case IFCOUNTER_IPACKETS:
2064 return (s->rx_frames);
2066 case IFCOUNTER_IERRORS:
2067 return (s->rx_jabber + s->rx_runt + s->rx_too_long +
2068 s->rx_fcs_err + s->rx_len_err);
2070 case IFCOUNTER_OPACKETS:
2071 return (s->tx_frames);
2073 case IFCOUNTER_OERRORS:
2074 return (s->tx_error_frames);
2076 case IFCOUNTER_IBYTES:
2077 return (s->rx_octets);
2079 case IFCOUNTER_OBYTES:
2080 return (s->tx_octets);
2082 case IFCOUNTER_IMCASTS:
2083 return (s->rx_mcast_frames);
2085 case IFCOUNTER_OMCASTS:
2086 return (s->tx_mcast_frames);
2088 case IFCOUNTER_IQDROPS:
2089 return (s->rx_ovflow0 + s->rx_ovflow1 + s->rx_ovflow2 +
2090 s->rx_ovflow3 + s->rx_trunc0 + s->rx_trunc1 + s->rx_trunc2 +
2091 s->rx_trunc3 + pi->tnl_cong_drops);
2093 case IFCOUNTER_OQDROPS: {
2097 if (vi->flags & VI_INIT_DONE) {
2099 struct sge_txq *txq;
2101 for_each_txq(vi, i, txq)
2102 drops += counter_u64_fetch(txq->r->drops);
2110 return (if_get_counter_default(ifp, c));
2115 * The kernel picks a media from the list we had provided but we still validate
2119 cxgbe_media_change(struct ifnet *ifp)
2121 struct vi_info *vi = ifp->if_softc;
2122 struct port_info *pi = vi->pi;
2123 struct ifmedia *ifm = &pi->media;
2124 struct link_config *lc = &pi->link_cfg;
2125 struct adapter *sc = pi->adapter;
2128 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4mec");
2132 if (IFM_SUBTYPE(ifm->ifm_media) == IFM_AUTO) {
2133 /* ifconfig .. media autoselect */
2134 if (!(lc->supported & FW_PORT_CAP32_ANEG)) {
2135 rc = ENOTSUP; /* AN not supported by transceiver */
2138 lc->requested_aneg = AUTONEG_ENABLE;
2139 lc->requested_speed = 0;
2140 lc->requested_fc |= PAUSE_AUTONEG;
2142 lc->requested_aneg = AUTONEG_DISABLE;
2143 lc->requested_speed =
2144 ifmedia_baudrate(ifm->ifm_media) / 1000000;
2145 lc->requested_fc = 0;
2146 if (IFM_OPTIONS(ifm->ifm_media) & IFM_ETH_RXPAUSE)
2147 lc->requested_fc |= PAUSE_RX;
2148 if (IFM_OPTIONS(ifm->ifm_media) & IFM_ETH_TXPAUSE)
2149 lc->requested_fc |= PAUSE_TX;
2151 if (pi->up_vis > 0) {
2152 fixup_link_config(pi);
2153 rc = apply_link_config(pi);
2157 end_synchronized_op(sc, 0);
2162 * Base media word (without ETHER, pause, link active, etc.) for the port at the
2166 port_mword(struct port_info *pi, uint32_t speed)
2169 MPASS(speed & M_FW_PORT_CAP32_SPEED);
2170 MPASS(powerof2(speed));
2172 switch(pi->port_type) {
2173 case FW_PORT_TYPE_BT_SGMII:
2174 case FW_PORT_TYPE_BT_XFI:
2175 case FW_PORT_TYPE_BT_XAUI:
2178 case FW_PORT_CAP32_SPEED_100M:
2180 case FW_PORT_CAP32_SPEED_1G:
2181 return (IFM_1000_T);
2182 case FW_PORT_CAP32_SPEED_10G:
2186 case FW_PORT_TYPE_KX4:
2187 if (speed == FW_PORT_CAP32_SPEED_10G)
2188 return (IFM_10G_KX4);
2190 case FW_PORT_TYPE_CX4:
2191 if (speed == FW_PORT_CAP32_SPEED_10G)
2192 return (IFM_10G_CX4);
2194 case FW_PORT_TYPE_KX:
2195 if (speed == FW_PORT_CAP32_SPEED_1G)
2196 return (IFM_1000_KX);
2198 case FW_PORT_TYPE_KR:
2199 case FW_PORT_TYPE_BP_AP:
2200 case FW_PORT_TYPE_BP4_AP:
2201 case FW_PORT_TYPE_BP40_BA:
2202 case FW_PORT_TYPE_KR4_100G:
2203 case FW_PORT_TYPE_KR_SFP28:
2204 case FW_PORT_TYPE_KR_XLAUI:
2206 case FW_PORT_CAP32_SPEED_1G:
2207 return (IFM_1000_KX);
2208 case FW_PORT_CAP32_SPEED_10G:
2209 return (IFM_10G_KR);
2210 case FW_PORT_CAP32_SPEED_25G:
2211 return (IFM_25G_KR);
2212 case FW_PORT_CAP32_SPEED_40G:
2213 return (IFM_40G_KR4);
2214 case FW_PORT_CAP32_SPEED_50G:
2215 return (IFM_50G_KR2);
2216 case FW_PORT_CAP32_SPEED_100G:
2217 return (IFM_100G_KR4);
2220 case FW_PORT_TYPE_FIBER_XFI:
2221 case FW_PORT_TYPE_FIBER_XAUI:
2222 case FW_PORT_TYPE_SFP:
2223 case FW_PORT_TYPE_QSFP_10G:
2224 case FW_PORT_TYPE_QSA:
2225 case FW_PORT_TYPE_QSFP:
2226 case FW_PORT_TYPE_CR4_QSFP:
2227 case FW_PORT_TYPE_CR_QSFP:
2228 case FW_PORT_TYPE_CR2_QSFP:
2229 case FW_PORT_TYPE_SFP28:
2230 /* Pluggable transceiver */
2231 switch (pi->mod_type) {
2232 case FW_PORT_MOD_TYPE_LR:
2234 case FW_PORT_CAP32_SPEED_1G:
2235 return (IFM_1000_LX);
2236 case FW_PORT_CAP32_SPEED_10G:
2237 return (IFM_10G_LR);
2238 case FW_PORT_CAP32_SPEED_25G:
2239 return (IFM_25G_LR);
2240 case FW_PORT_CAP32_SPEED_40G:
2241 return (IFM_40G_LR4);
2242 case FW_PORT_CAP32_SPEED_50G:
2243 return (IFM_50G_LR2);
2244 case FW_PORT_CAP32_SPEED_100G:
2245 return (IFM_100G_LR4);
2248 case FW_PORT_MOD_TYPE_SR:
2250 case FW_PORT_CAP32_SPEED_1G:
2251 return (IFM_1000_SX);
2252 case FW_PORT_CAP32_SPEED_10G:
2253 return (IFM_10G_SR);
2254 case FW_PORT_CAP32_SPEED_25G:
2255 return (IFM_25G_SR);
2256 case FW_PORT_CAP32_SPEED_40G:
2257 return (IFM_40G_SR4);
2258 case FW_PORT_CAP32_SPEED_50G:
2259 return (IFM_50G_SR2);
2260 case FW_PORT_CAP32_SPEED_100G:
2261 return (IFM_100G_SR4);
2264 case FW_PORT_MOD_TYPE_ER:
2265 if (speed == FW_PORT_CAP32_SPEED_10G)
2266 return (IFM_10G_ER);
2268 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
2269 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
2271 case FW_PORT_CAP32_SPEED_1G:
2272 return (IFM_1000_CX);
2273 case FW_PORT_CAP32_SPEED_10G:
2274 return (IFM_10G_TWINAX);
2275 case FW_PORT_CAP32_SPEED_25G:
2276 return (IFM_25G_CR);
2277 case FW_PORT_CAP32_SPEED_40G:
2278 return (IFM_40G_CR4);
2279 case FW_PORT_CAP32_SPEED_50G:
2280 return (IFM_50G_CR2);
2281 case FW_PORT_CAP32_SPEED_100G:
2282 return (IFM_100G_CR4);
2285 case FW_PORT_MOD_TYPE_LRM:
2286 if (speed == FW_PORT_CAP32_SPEED_10G)
2287 return (IFM_10G_LRM);
2289 case FW_PORT_MOD_TYPE_NA:
2290 MPASS(0); /* Not pluggable? */
2292 case FW_PORT_MOD_TYPE_ERROR:
2293 case FW_PORT_MOD_TYPE_UNKNOWN:
2294 case FW_PORT_MOD_TYPE_NOTSUPPORTED:
2296 case FW_PORT_MOD_TYPE_NONE:
2300 case FW_PORT_TYPE_NONE:
2304 return (IFM_UNKNOWN);
2308 cxgbe_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
2310 struct vi_info *vi = ifp->if_softc;
2311 struct port_info *pi = vi->pi;
2312 struct adapter *sc = pi->adapter;
2313 struct link_config *lc = &pi->link_cfg;
2315 if (begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4med") != 0)
2319 if (pi->up_vis == 0) {
2321 * If all the interfaces are administratively down the firmware
2322 * does not report transceiver changes. Refresh port info here
2323 * so that ifconfig displays accurate ifmedia at all times.
2324 * This is the only reason we have a synchronized op in this
2325 * function. Just PORT_LOCK would have been enough otherwise.
2327 t4_update_port_info(pi);
2328 build_medialist(pi);
2332 ifmr->ifm_status = IFM_AVALID;
2333 if (lc->link_ok == false)
2335 ifmr->ifm_status |= IFM_ACTIVE;
2338 ifmr->ifm_active = IFM_ETHER | IFM_FDX;
2339 ifmr->ifm_active &= ~(IFM_ETH_TXPAUSE | IFM_ETH_RXPAUSE);
2340 if (lc->fc & PAUSE_RX)
2341 ifmr->ifm_active |= IFM_ETH_RXPAUSE;
2342 if (lc->fc & PAUSE_TX)
2343 ifmr->ifm_active |= IFM_ETH_TXPAUSE;
2344 ifmr->ifm_active |= port_mword(pi, speed_to_fwcap(lc->speed));
2347 end_synchronized_op(sc, 0);
2351 vcxgbe_probe(device_t dev)
2354 struct vi_info *vi = device_get_softc(dev);
2356 snprintf(buf, sizeof(buf), "port %d vi %td", vi->pi->port_id,
2358 device_set_desc_copy(dev, buf);
2360 return (BUS_PROBE_DEFAULT);
2364 alloc_extra_vi(struct adapter *sc, struct port_info *pi, struct vi_info *vi)
2366 int func, index, rc;
2367 uint32_t param, val;
2369 ASSERT_SYNCHRONIZED_OP(sc);
2371 index = vi - pi->vi;
2372 MPASS(index > 0); /* This function deals with _extra_ VIs only */
2373 KASSERT(index < nitems(vi_mac_funcs),
2374 ("%s: VI %s doesn't have a MAC func", __func__,
2375 device_get_nameunit(vi->dev)));
2376 func = vi_mac_funcs[index];
2377 rc = t4_alloc_vi_func(sc, sc->mbox, pi->tx_chan, sc->pf, 0, 1,
2378 vi->hw_addr, &vi->rss_size, func, 0);
2380 device_printf(vi->dev, "failed to allocate virtual interface %d"
2381 "for port %d: %d\n", index, pi->port_id, -rc);
2385 if (chip_id(sc) <= CHELSIO_T5)
2386 vi->smt_idx = (rc & 0x7f) << 1;
2388 vi->smt_idx = (rc & 0x7f);
2390 if (vi->rss_size == 1) {
2392 * This VI didn't get a slice of the RSS table. Reduce the
2393 * number of VIs being created (hw.cxgbe.num_vis) or modify the
2394 * configuration file (nvi, rssnvi for this PF) if this is a
2397 device_printf(vi->dev, "RSS table not available.\n");
2398 vi->rss_base = 0xffff;
2403 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
2404 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_RSSINFO) |
2405 V_FW_PARAMS_PARAM_YZ(vi->viid);
2406 rc = t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
2408 vi->rss_base = 0xffff;
2410 MPASS((val >> 16) == vi->rss_size);
2411 vi->rss_base = val & 0xffff;
2418 vcxgbe_attach(device_t dev)
2421 struct port_info *pi;
2425 vi = device_get_softc(dev);
2429 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4via");
2432 rc = alloc_extra_vi(sc, pi, vi);
2433 end_synchronized_op(sc, 0);
2437 rc = cxgbe_vi_attach(dev, vi);
2439 t4_free_vi(sc, sc->mbox, sc->pf, 0, vi->viid);
2446 vcxgbe_detach(device_t dev)
2451 vi = device_get_softc(dev);
2452 sc = vi->pi->adapter;
2456 cxgbe_vi_detach(vi);
2457 t4_free_vi(sc, sc->mbox, sc->pf, 0, vi->viid);
2459 end_synchronized_op(sc, 0);
2465 t4_fatal_err(struct adapter *sc)
2467 t4_set_reg_field(sc, A_SGE_CONTROL, F_GLOBALENABLE, 0);
2468 t4_intr_disable(sc);
2469 log(LOG_EMERG, "%s: encountered fatal error, adapter stopped.\n",
2470 device_get_nameunit(sc->dev));
2471 if (t4_panic_on_fatal_err)
2472 panic("panic requested on fatal error");
2476 t4_add_adapter(struct adapter *sc)
2478 sx_xlock(&t4_list_lock);
2479 SLIST_INSERT_HEAD(&t4_list, sc, link);
2480 sx_xunlock(&t4_list_lock);
2484 t4_map_bars_0_and_4(struct adapter *sc)
2486 sc->regs_rid = PCIR_BAR(0);
2487 sc->regs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
2488 &sc->regs_rid, RF_ACTIVE);
2489 if (sc->regs_res == NULL) {
2490 device_printf(sc->dev, "cannot map registers.\n");
2493 sc->bt = rman_get_bustag(sc->regs_res);
2494 sc->bh = rman_get_bushandle(sc->regs_res);
2495 sc->mmio_len = rman_get_size(sc->regs_res);
2496 setbit(&sc->doorbells, DOORBELL_KDB);
2498 sc->msix_rid = PCIR_BAR(4);
2499 sc->msix_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
2500 &sc->msix_rid, RF_ACTIVE);
2501 if (sc->msix_res == NULL) {
2502 device_printf(sc->dev, "cannot map MSI-X BAR.\n");
2510 t4_map_bar_2(struct adapter *sc)
2514 * T4: only iWARP driver uses the userspace doorbells. There is no need
2515 * to map it if RDMA is disabled.
2517 if (is_t4(sc) && sc->rdmacaps == 0)
2520 sc->udbs_rid = PCIR_BAR(2);
2521 sc->udbs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
2522 &sc->udbs_rid, RF_ACTIVE);
2523 if (sc->udbs_res == NULL) {
2524 device_printf(sc->dev, "cannot map doorbell BAR.\n");
2527 sc->udbs_base = rman_get_virtual(sc->udbs_res);
2529 if (chip_id(sc) >= CHELSIO_T5) {
2530 setbit(&sc->doorbells, DOORBELL_UDB);
2531 #if defined(__i386__) || defined(__amd64__)
2532 if (t5_write_combine) {
2536 * Enable write combining on BAR2. This is the
2537 * userspace doorbell BAR and is split into 128B
2538 * (UDBS_SEG_SIZE) doorbell regions, each associated
2539 * with an egress queue. The first 64B has the doorbell
2540 * and the second 64B can be used to submit a tx work
2541 * request with an implicit doorbell.
2544 rc = pmap_change_attr((vm_offset_t)sc->udbs_base,
2545 rman_get_size(sc->udbs_res), PAT_WRITE_COMBINING);
2547 clrbit(&sc->doorbells, DOORBELL_UDB);
2548 setbit(&sc->doorbells, DOORBELL_WCWR);
2549 setbit(&sc->doorbells, DOORBELL_UDBWC);
2551 device_printf(sc->dev,
2552 "couldn't enable write combining: %d\n",
2556 mode = is_t5(sc) ? V_STATMODE(0) : V_T6_STATMODE(0);
2557 t4_write_reg(sc, A_SGE_STAT_CFG,
2558 V_STATSOURCE_T5(7) | mode);
2562 sc->iwt.wc_en = isset(&sc->doorbells, DOORBELL_UDBWC) ? 1 : 0;
2567 struct memwin_init {
2572 static const struct memwin_init t4_memwin[NUM_MEMWIN] = {
2573 { MEMWIN0_BASE, MEMWIN0_APERTURE },
2574 { MEMWIN1_BASE, MEMWIN1_APERTURE },
2575 { MEMWIN2_BASE_T4, MEMWIN2_APERTURE_T4 }
2578 static const struct memwin_init t5_memwin[NUM_MEMWIN] = {
2579 { MEMWIN0_BASE, MEMWIN0_APERTURE },
2580 { MEMWIN1_BASE, MEMWIN1_APERTURE },
2581 { MEMWIN2_BASE_T5, MEMWIN2_APERTURE_T5 },
2585 setup_memwin(struct adapter *sc)
2587 const struct memwin_init *mw_init;
2594 * Read low 32b of bar0 indirectly via the hardware backdoor
2595 * mechanism. Works from within PCI passthrough environments
2596 * too, where rman_get_start() can return a different value. We
2597 * need to program the T4 memory window decoders with the actual
2598 * addresses that will be coming across the PCIe link.
2600 bar0 = t4_hw_pci_read_cfg4(sc, PCIR_BAR(0));
2601 bar0 &= (uint32_t) PCIM_BAR_MEM_BASE;
2603 mw_init = &t4_memwin[0];
2605 /* T5+ use the relative offset inside the PCIe BAR */
2608 mw_init = &t5_memwin[0];
2611 for (i = 0, mw = &sc->memwin[0]; i < NUM_MEMWIN; i++, mw_init++, mw++) {
2612 rw_init(&mw->mw_lock, "memory window access");
2613 mw->mw_base = mw_init->base;
2614 mw->mw_aperture = mw_init->aperture;
2617 PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, i),
2618 (mw->mw_base + bar0) | V_BIR(0) |
2619 V_WINDOW(ilog2(mw->mw_aperture) - 10));
2620 rw_wlock(&mw->mw_lock);
2621 position_memwin(sc, i, 0);
2622 rw_wunlock(&mw->mw_lock);
2626 t4_read_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 2));
2630 * Positions the memory window at the given address in the card's address space.
2631 * There are some alignment requirements and the actual position may be at an
2632 * address prior to the requested address. mw->mw_curpos always has the actual
2633 * position of the window.
2636 position_memwin(struct adapter *sc, int idx, uint32_t addr)
2642 MPASS(idx >= 0 && idx < NUM_MEMWIN);
2643 mw = &sc->memwin[idx];
2644 rw_assert(&mw->mw_lock, RA_WLOCKED);
2648 mw->mw_curpos = addr & ~0xf; /* start must be 16B aligned */
2650 pf = V_PFNUM(sc->pf);
2651 mw->mw_curpos = addr & ~0x7f; /* start must be 128B aligned */
2653 reg = PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, idx);
2654 t4_write_reg(sc, reg, mw->mw_curpos | pf);
2655 t4_read_reg(sc, reg); /* flush */
2659 rw_via_memwin(struct adapter *sc, int idx, uint32_t addr, uint32_t *val,
2665 MPASS(idx >= 0 && idx < NUM_MEMWIN);
2667 /* Memory can only be accessed in naturally aligned 4 byte units */
2668 if (addr & 3 || len & 3 || len <= 0)
2671 mw = &sc->memwin[idx];
2673 rw_rlock(&mw->mw_lock);
2674 mw_end = mw->mw_curpos + mw->mw_aperture;
2675 if (addr >= mw_end || addr < mw->mw_curpos) {
2676 /* Will need to reposition the window */
2677 if (!rw_try_upgrade(&mw->mw_lock)) {
2678 rw_runlock(&mw->mw_lock);
2679 rw_wlock(&mw->mw_lock);
2681 rw_assert(&mw->mw_lock, RA_WLOCKED);
2682 position_memwin(sc, idx, addr);
2683 rw_downgrade(&mw->mw_lock);
2684 mw_end = mw->mw_curpos + mw->mw_aperture;
2686 rw_assert(&mw->mw_lock, RA_RLOCKED);
2687 while (addr < mw_end && len > 0) {
2689 v = t4_read_reg(sc, mw->mw_base + addr -
2691 *val++ = le32toh(v);
2694 t4_write_reg(sc, mw->mw_base + addr -
2695 mw->mw_curpos, htole32(v));
2700 rw_runlock(&mw->mw_lock);
2707 alloc_atid_tab(struct tid_info *t, int flags)
2711 MPASS(t->natids > 0);
2712 MPASS(t->atid_tab == NULL);
2714 t->atid_tab = malloc(t->natids * sizeof(*t->atid_tab), M_CXGBE,
2716 if (t->atid_tab == NULL)
2718 mtx_init(&t->atid_lock, "atid lock", NULL, MTX_DEF);
2719 t->afree = t->atid_tab;
2720 t->atids_in_use = 0;
2721 for (i = 1; i < t->natids; i++)
2722 t->atid_tab[i - 1].next = &t->atid_tab[i];
2723 t->atid_tab[t->natids - 1].next = NULL;
2729 free_atid_tab(struct tid_info *t)
2732 KASSERT(t->atids_in_use == 0,
2733 ("%s: %d atids still in use.", __func__, t->atids_in_use));
2735 if (mtx_initialized(&t->atid_lock))
2736 mtx_destroy(&t->atid_lock);
2737 free(t->atid_tab, M_CXGBE);
2742 alloc_atid(struct adapter *sc, void *ctx)
2744 struct tid_info *t = &sc->tids;
2747 mtx_lock(&t->atid_lock);
2749 union aopen_entry *p = t->afree;
2751 atid = p - t->atid_tab;
2752 MPASS(atid <= M_TID_TID);
2757 mtx_unlock(&t->atid_lock);
2762 lookup_atid(struct adapter *sc, int atid)
2764 struct tid_info *t = &sc->tids;
2766 return (t->atid_tab[atid].data);
2770 free_atid(struct adapter *sc, int atid)
2772 struct tid_info *t = &sc->tids;
2773 union aopen_entry *p = &t->atid_tab[atid];
2775 mtx_lock(&t->atid_lock);
2779 mtx_unlock(&t->atid_lock);
2783 queue_tid_release(struct adapter *sc, int tid)
2786 CXGBE_UNIMPLEMENTED("deferred tid release");
2790 release_tid(struct adapter *sc, int tid, struct sge_wrq *ctrlq)
2793 struct cpl_tid_release *req;
2795 wr = alloc_wrqe(sizeof(*req), ctrlq);
2797 queue_tid_release(sc, tid); /* defer */
2802 INIT_TP_WR_MIT_CPL(req, CPL_TID_RELEASE, tid);
2808 t4_range_cmp(const void *a, const void *b)
2810 return ((const struct t4_range *)a)->start -
2811 ((const struct t4_range *)b)->start;
2815 * Verify that the memory range specified by the addr/len pair is valid within
2816 * the card's address space.
2819 validate_mem_range(struct adapter *sc, uint32_t addr, uint32_t len)
2821 struct t4_range mem_ranges[4], *r, *next;
2822 uint32_t em, addr_len;
2823 int i, n, remaining;
2825 /* Memory can only be accessed in naturally aligned 4 byte units */
2826 if (addr & 3 || len & 3 || len == 0)
2829 /* Enabled memories */
2830 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
2834 bzero(r, sizeof(mem_ranges));
2835 if (em & F_EDRAM0_ENABLE) {
2836 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
2837 r->size = G_EDRAM0_SIZE(addr_len) << 20;
2839 r->start = G_EDRAM0_BASE(addr_len) << 20;
2840 if (addr >= r->start &&
2841 addr + len <= r->start + r->size)
2847 if (em & F_EDRAM1_ENABLE) {
2848 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
2849 r->size = G_EDRAM1_SIZE(addr_len) << 20;
2851 r->start = G_EDRAM1_BASE(addr_len) << 20;
2852 if (addr >= r->start &&
2853 addr + len <= r->start + r->size)
2859 if (em & F_EXT_MEM_ENABLE) {
2860 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
2861 r->size = G_EXT_MEM_SIZE(addr_len) << 20;
2863 r->start = G_EXT_MEM_BASE(addr_len) << 20;
2864 if (addr >= r->start &&
2865 addr + len <= r->start + r->size)
2871 if (is_t5(sc) && em & F_EXT_MEM1_ENABLE) {
2872 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
2873 r->size = G_EXT_MEM1_SIZE(addr_len) << 20;
2875 r->start = G_EXT_MEM1_BASE(addr_len) << 20;
2876 if (addr >= r->start &&
2877 addr + len <= r->start + r->size)
2883 MPASS(n <= nitems(mem_ranges));
2886 /* Sort and merge the ranges. */
2887 qsort(mem_ranges, n, sizeof(struct t4_range), t4_range_cmp);
2889 /* Start from index 0 and examine the next n - 1 entries. */
2891 for (remaining = n - 1; remaining > 0; remaining--, r++) {
2893 MPASS(r->size > 0); /* r is a valid entry. */
2895 MPASS(next->size > 0); /* and so is the next one. */
2897 while (r->start + r->size >= next->start) {
2898 /* Merge the next one into the current entry. */
2899 r->size = max(r->start + r->size,
2900 next->start + next->size) - r->start;
2901 n--; /* One fewer entry in total. */
2902 if (--remaining == 0)
2903 goto done; /* short circuit */
2906 if (next != r + 1) {
2908 * Some entries were merged into r and next
2909 * points to the first valid entry that couldn't
2912 MPASS(next->size > 0); /* must be valid */
2913 memcpy(r + 1, next, remaining * sizeof(*r));
2916 * This so that the foo->size assertion in the
2917 * next iteration of the loop do the right
2918 * thing for entries that were pulled up and are
2921 MPASS(n < nitems(mem_ranges));
2922 bzero(&mem_ranges[n], (nitems(mem_ranges) - n) *
2923 sizeof(struct t4_range));
2928 /* Done merging the ranges. */
2931 for (i = 0; i < n; i++, r++) {
2932 if (addr >= r->start &&
2933 addr + len <= r->start + r->size)
2942 fwmtype_to_hwmtype(int mtype)
2946 case FW_MEMTYPE_EDC0:
2948 case FW_MEMTYPE_EDC1:
2950 case FW_MEMTYPE_EXTMEM:
2952 case FW_MEMTYPE_EXTMEM1:
2955 panic("%s: cannot translate fw mtype %d.", __func__, mtype);
2960 * Verify that the memory range specified by the memtype/offset/len pair is
2961 * valid and lies entirely within the memtype specified. The global address of
2962 * the start of the range is returned in addr.
2965 validate_mt_off_len(struct adapter *sc, int mtype, uint32_t off, uint32_t len,
2968 uint32_t em, addr_len, maddr;
2970 /* Memory can only be accessed in naturally aligned 4 byte units */
2971 if (off & 3 || len & 3 || len == 0)
2974 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
2975 switch (fwmtype_to_hwmtype(mtype)) {
2977 if (!(em & F_EDRAM0_ENABLE))
2979 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
2980 maddr = G_EDRAM0_BASE(addr_len) << 20;
2983 if (!(em & F_EDRAM1_ENABLE))
2985 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
2986 maddr = G_EDRAM1_BASE(addr_len) << 20;
2989 if (!(em & F_EXT_MEM_ENABLE))
2991 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
2992 maddr = G_EXT_MEM_BASE(addr_len) << 20;
2995 if (!is_t5(sc) || !(em & F_EXT_MEM1_ENABLE))
2997 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
2998 maddr = G_EXT_MEM1_BASE(addr_len) << 20;
3004 *addr = maddr + off; /* global address */
3005 return (validate_mem_range(sc, *addr, len));
3009 fixup_devlog_params(struct adapter *sc)
3011 struct devlog_params *dparams = &sc->params.devlog;
3014 rc = validate_mt_off_len(sc, dparams->memtype, dparams->start,
3015 dparams->size, &dparams->addr);
3021 update_nirq(struct intrs_and_queues *iaq, int nports)
3023 int extra = T4_EXTRA_INTR;
3026 iaq->nirq += nports * (iaq->nrxq + iaq->nofldrxq);
3027 iaq->nirq += nports * (iaq->num_vis - 1) *
3028 max(iaq->nrxq_vi, iaq->nnmrxq_vi);
3029 iaq->nirq += nports * (iaq->num_vis - 1) * iaq->nofldrxq_vi;
3033 * Adjust requirements to fit the number of interrupts available.
3036 calculate_iaq(struct adapter *sc, struct intrs_and_queues *iaq, int itype,
3040 const int nports = sc->params.nports;
3045 bzero(iaq, sizeof(*iaq));
3046 iaq->intr_type = itype;
3047 iaq->num_vis = t4_num_vis;
3048 iaq->ntxq = t4_ntxq;
3049 iaq->ntxq_vi = t4_ntxq_vi;
3050 iaq->nrxq = t4_nrxq;
3051 iaq->nrxq_vi = t4_nrxq_vi;
3052 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
3053 if (is_offload(sc) || is_ethoffload(sc)) {
3054 iaq->nofldtxq = t4_nofldtxq;
3055 iaq->nofldtxq_vi = t4_nofldtxq_vi;
3059 if (is_offload(sc)) {
3060 iaq->nofldrxq = t4_nofldrxq;
3061 iaq->nofldrxq_vi = t4_nofldrxq_vi;
3065 iaq->nnmtxq_vi = t4_nnmtxq_vi;
3066 iaq->nnmrxq_vi = t4_nnmrxq_vi;
3069 update_nirq(iaq, nports);
3070 if (iaq->nirq <= navail &&
3071 (itype != INTR_MSI || powerof2(iaq->nirq))) {
3073 * This is the normal case -- there are enough interrupts for
3080 * If extra VIs have been configured try reducing their count and see if
3083 while (iaq->num_vis > 1) {
3085 update_nirq(iaq, nports);
3086 if (iaq->nirq <= navail &&
3087 (itype != INTR_MSI || powerof2(iaq->nirq))) {
3088 device_printf(sc->dev, "virtual interfaces per port "
3089 "reduced to %d from %d. nrxq=%u, nofldrxq=%u, "
3090 "nrxq_vi=%u nofldrxq_vi=%u, nnmrxq_vi=%u. "
3091 "itype %d, navail %u, nirq %d.\n",
3092 iaq->num_vis, t4_num_vis, iaq->nrxq, iaq->nofldrxq,
3093 iaq->nrxq_vi, iaq->nofldrxq_vi, iaq->nnmrxq_vi,
3094 itype, navail, iaq->nirq);
3100 * Extra VIs will not be created. Log a message if they were requested.
3102 MPASS(iaq->num_vis == 1);
3103 iaq->ntxq_vi = iaq->nrxq_vi = 0;
3104 iaq->nofldtxq_vi = iaq->nofldrxq_vi = 0;
3105 iaq->nnmtxq_vi = iaq->nnmrxq_vi = 0;
3106 if (iaq->num_vis != t4_num_vis) {
3107 device_printf(sc->dev, "extra virtual interfaces disabled. "
3108 "nrxq=%u, nofldrxq=%u, nrxq_vi=%u nofldrxq_vi=%u, "
3109 "nnmrxq_vi=%u. itype %d, navail %u, nirq %d.\n",
3110 iaq->nrxq, iaq->nofldrxq, iaq->nrxq_vi, iaq->nofldrxq_vi,
3111 iaq->nnmrxq_vi, itype, navail, iaq->nirq);
3115 * Keep reducing the number of NIC rx queues to the next lower power of
3116 * 2 (for even RSS distribution) and halving the TOE rx queues and see
3120 if (iaq->nrxq > 1) {
3123 } while (!powerof2(iaq->nrxq));
3125 if (iaq->nofldrxq > 1)
3126 iaq->nofldrxq >>= 1;
3128 old_nirq = iaq->nirq;
3129 update_nirq(iaq, nports);
3130 if (iaq->nirq <= navail &&
3131 (itype != INTR_MSI || powerof2(iaq->nirq))) {
3132 device_printf(sc->dev, "running with reduced number of "
3133 "rx queues because of shortage of interrupts. "
3134 "nrxq=%u, nofldrxq=%u. "
3135 "itype %d, navail %u, nirq %d.\n", iaq->nrxq,
3136 iaq->nofldrxq, itype, navail, iaq->nirq);
3139 } while (old_nirq != iaq->nirq);
3141 /* One interrupt for everything. Ugh. */
3142 device_printf(sc->dev, "running with minimal number of queues. "
3143 "itype %d, navail %u.\n", itype, navail);
3145 MPASS(iaq->nrxq == 1);
3147 if (iaq->nofldrxq > 1)
3150 MPASS(iaq->num_vis > 0);
3151 if (iaq->num_vis > 1) {
3152 MPASS(iaq->nrxq_vi > 0);
3153 MPASS(iaq->ntxq_vi > 0);
3155 MPASS(iaq->nirq > 0);
3156 MPASS(iaq->nrxq > 0);
3157 MPASS(iaq->ntxq > 0);
3158 if (itype == INTR_MSI) {
3159 MPASS(powerof2(iaq->nirq));
3164 cfg_itype_and_nqueues(struct adapter *sc, struct intrs_and_queues *iaq)
3166 int rc, itype, navail, nalloc;
3168 for (itype = INTR_MSIX; itype; itype >>= 1) {
3170 if ((itype & t4_intr_types) == 0)
3171 continue; /* not allowed */
3173 if (itype == INTR_MSIX)
3174 navail = pci_msix_count(sc->dev);
3175 else if (itype == INTR_MSI)
3176 navail = pci_msi_count(sc->dev);
3183 calculate_iaq(sc, iaq, itype, navail);
3186 if (itype == INTR_MSIX)
3187 rc = pci_alloc_msix(sc->dev, &nalloc);
3188 else if (itype == INTR_MSI)
3189 rc = pci_alloc_msi(sc->dev, &nalloc);
3191 if (rc == 0 && nalloc > 0) {
3192 if (nalloc == iaq->nirq)
3196 * Didn't get the number requested. Use whatever number
3197 * the kernel is willing to allocate.
3199 device_printf(sc->dev, "fewer vectors than requested, "
3200 "type=%d, req=%d, rcvd=%d; will downshift req.\n",
3201 itype, iaq->nirq, nalloc);
3202 pci_release_msi(sc->dev);
3207 device_printf(sc->dev,
3208 "failed to allocate vectors:%d, type=%d, req=%d, rcvd=%d\n",
3209 itype, rc, iaq->nirq, nalloc);
3212 device_printf(sc->dev,
3213 "failed to find a usable interrupt type. "
3214 "allowed=%d, msi-x=%d, msi=%d, intx=1", t4_intr_types,
3215 pci_msix_count(sc->dev), pci_msi_count(sc->dev));
3220 #define FW_VERSION(chip) ( \
3221 V_FW_HDR_FW_VER_MAJOR(chip##FW_VERSION_MAJOR) | \
3222 V_FW_HDR_FW_VER_MINOR(chip##FW_VERSION_MINOR) | \
3223 V_FW_HDR_FW_VER_MICRO(chip##FW_VERSION_MICRO) | \
3224 V_FW_HDR_FW_VER_BUILD(chip##FW_VERSION_BUILD))
3225 #define FW_INTFVER(chip, intf) (chip##FW_HDR_INTFVER_##intf)
3231 struct fw_hdr fw_hdr; /* XXX: waste of space, need a sparse struct */
3235 .kld_name = "t4fw_cfg",
3236 .fw_mod_name = "t4fw",
3238 .chip = FW_HDR_CHIP_T4,
3239 .fw_ver = htobe32(FW_VERSION(T4)),
3240 .intfver_nic = FW_INTFVER(T4, NIC),
3241 .intfver_vnic = FW_INTFVER(T4, VNIC),
3242 .intfver_ofld = FW_INTFVER(T4, OFLD),
3243 .intfver_ri = FW_INTFVER(T4, RI),
3244 .intfver_iscsipdu = FW_INTFVER(T4, ISCSIPDU),
3245 .intfver_iscsi = FW_INTFVER(T4, ISCSI),
3246 .intfver_fcoepdu = FW_INTFVER(T4, FCOEPDU),
3247 .intfver_fcoe = FW_INTFVER(T4, FCOE),
3251 .kld_name = "t5fw_cfg",
3252 .fw_mod_name = "t5fw",
3254 .chip = FW_HDR_CHIP_T5,
3255 .fw_ver = htobe32(FW_VERSION(T5)),
3256 .intfver_nic = FW_INTFVER(T5, NIC),
3257 .intfver_vnic = FW_INTFVER(T5, VNIC),
3258 .intfver_ofld = FW_INTFVER(T5, OFLD),
3259 .intfver_ri = FW_INTFVER(T5, RI),
3260 .intfver_iscsipdu = FW_INTFVER(T5, ISCSIPDU),
3261 .intfver_iscsi = FW_INTFVER(T5, ISCSI),
3262 .intfver_fcoepdu = FW_INTFVER(T5, FCOEPDU),
3263 .intfver_fcoe = FW_INTFVER(T5, FCOE),
3267 .kld_name = "t6fw_cfg",
3268 .fw_mod_name = "t6fw",
3270 .chip = FW_HDR_CHIP_T6,
3271 .fw_ver = htobe32(FW_VERSION(T6)),
3272 .intfver_nic = FW_INTFVER(T6, NIC),
3273 .intfver_vnic = FW_INTFVER(T6, VNIC),
3274 .intfver_ofld = FW_INTFVER(T6, OFLD),
3275 .intfver_ri = FW_INTFVER(T6, RI),
3276 .intfver_iscsipdu = FW_INTFVER(T6, ISCSIPDU),
3277 .intfver_iscsi = FW_INTFVER(T6, ISCSI),
3278 .intfver_fcoepdu = FW_INTFVER(T6, FCOEPDU),
3279 .intfver_fcoe = FW_INTFVER(T6, FCOE),
3284 static struct fw_info *
3285 find_fw_info(int chip)
3289 for (i = 0; i < nitems(fw_info); i++) {
3290 if (fw_info[i].chip == chip)
3291 return (&fw_info[i]);
3297 * Is the given firmware API compatible with the one the driver was compiled
3301 fw_compatible(const struct fw_hdr *hdr1, const struct fw_hdr *hdr2)
3304 /* short circuit if it's the exact same firmware version */
3305 if (hdr1->chip == hdr2->chip && hdr1->fw_ver == hdr2->fw_ver)
3309 * XXX: Is this too conservative? Perhaps I should limit this to the
3310 * features that are supported in the driver.
3312 #define SAME_INTF(x) (hdr1->intfver_##x == hdr2->intfver_##x)
3313 if (hdr1->chip == hdr2->chip && SAME_INTF(nic) && SAME_INTF(vnic) &&
3314 SAME_INTF(ofld) && SAME_INTF(ri) && SAME_INTF(iscsipdu) &&
3315 SAME_INTF(iscsi) && SAME_INTF(fcoepdu) && SAME_INTF(fcoe))
3323 * The firmware in the KLD is usable, but should it be installed? This routine
3324 * explains itself in detail if it indicates the KLD firmware should be
3328 should_install_kld_fw(struct adapter *sc, int card_fw_usable, int k, int c)
3332 if (!card_fw_usable) {
3333 reason = "incompatible or unusable";
3338 reason = "older than the version bundled with this driver";
3342 if (t4_fw_install == 2 && k != c) {
3343 reason = "different than the version bundled with this driver";
3350 if (t4_fw_install == 0) {
3351 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
3352 "but the driver is prohibited from installing a different "
3353 "firmware on the card.\n",
3354 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
3355 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason);
3360 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
3361 "installing firmware %u.%u.%u.%u on card.\n",
3362 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
3363 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason,
3364 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
3365 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
3371 * Establish contact with the firmware and determine if we are the master driver
3372 * or not, and whether we are responsible for chip initialization.
3375 prep_firmware(struct adapter *sc)
3377 const struct firmware *fw = NULL, *default_cfg;
3378 int rc, pf, card_fw_usable, kld_fw_usable, need_fw_reset = 1;
3379 enum dev_state state;
3380 struct fw_info *fw_info;
3381 struct fw_hdr *card_fw; /* fw on the card */
3382 const struct fw_hdr *kld_fw; /* fw in the KLD */
3383 const struct fw_hdr *drv_fw; /* fw header the driver was compiled
3386 /* This is the firmware whose headers the driver was compiled against */
3387 fw_info = find_fw_info(chip_id(sc));
3388 if (fw_info == NULL) {
3389 device_printf(sc->dev,
3390 "unable to look up firmware information for chip %d.\n",
3394 drv_fw = &fw_info->fw_hdr;
3397 * The firmware KLD contains many modules. The KLD name is also the
3398 * name of the module that contains the default config file.
3400 default_cfg = firmware_get(fw_info->kld_name);
3402 /* This is the firmware in the KLD */
3403 fw = firmware_get(fw_info->fw_mod_name);
3405 kld_fw = (const void *)fw->data;
3406 kld_fw_usable = fw_compatible(drv_fw, kld_fw);
3412 /* Read the header of the firmware on the card */
3413 card_fw = malloc(sizeof(*card_fw), M_CXGBE, M_ZERO | M_WAITOK);
3414 rc = -t4_read_flash(sc, FLASH_FW_START,
3415 sizeof (*card_fw) / sizeof (uint32_t), (uint32_t *)card_fw, 1);
3417 card_fw_usable = fw_compatible(drv_fw, (const void*)card_fw);
3418 if (card_fw->fw_ver == be32toh(0xffffffff)) {
3419 uint32_t d = be32toh(kld_fw->fw_ver);
3421 if (!kld_fw_usable) {
3422 device_printf(sc->dev,
3423 "no firmware on the card and no usable "
3424 "firmware bundled with the driver.\n");
3427 } else if (t4_fw_install == 0) {
3428 device_printf(sc->dev,
3429 "no firmware on the card and the driver "
3430 "is prohibited from installing new "
3436 device_printf(sc->dev, "no firmware on the card, "
3437 "installing firmware %d.%d.%d.%d\n",
3438 G_FW_HDR_FW_VER_MAJOR(d), G_FW_HDR_FW_VER_MINOR(d),
3439 G_FW_HDR_FW_VER_MICRO(d), G_FW_HDR_FW_VER_BUILD(d));
3440 rc = t4_fw_forceinstall(sc, fw->data, fw->datasize);
3443 device_printf(sc->dev,
3444 "firmware install failed: %d.\n", rc);
3447 memcpy(card_fw, kld_fw, sizeof(*card_fw));
3452 device_printf(sc->dev,
3453 "Unable to read card's firmware header: %d\n", rc);
3457 /* Contact firmware. */
3458 rc = t4_fw_hello(sc, sc->mbox, sc->mbox, MASTER_MAY, &state);
3459 if (rc < 0 || state == DEV_STATE_ERR) {
3461 device_printf(sc->dev,
3462 "failed to connect to the firmware: %d, %d.\n", rc, state);
3467 sc->flags |= MASTER_PF;
3468 else if (state == DEV_STATE_UNINIT) {
3470 * We didn't get to be the master so we definitely won't be
3471 * configuring the chip. It's a bug if someone else hasn't
3472 * configured it already.
3474 device_printf(sc->dev, "couldn't be master(%d), "
3475 "device not already initialized either(%d).\n", rc, state);
3480 if (card_fw_usable && card_fw->fw_ver == drv_fw->fw_ver &&
3481 (!kld_fw_usable || kld_fw->fw_ver == drv_fw->fw_ver)) {
3483 * Common case: the firmware on the card is an exact match and
3484 * the KLD is an exact match too, or the KLD is
3485 * absent/incompatible. Note that t4_fw_install = 2 is ignored
3486 * here -- use cxgbetool loadfw if you want to reinstall the
3487 * same firmware as the one on the card.
3489 } else if (kld_fw_usable && state == DEV_STATE_UNINIT &&
3490 should_install_kld_fw(sc, card_fw_usable, be32toh(kld_fw->fw_ver),
3491 be32toh(card_fw->fw_ver))) {
3493 rc = -t4_fw_upgrade(sc, sc->mbox, fw->data, fw->datasize, 0);
3495 device_printf(sc->dev,
3496 "failed to install firmware: %d\n", rc);
3500 /* Installed successfully, update the cached header too. */
3501 memcpy(card_fw, kld_fw, sizeof(*card_fw));
3503 need_fw_reset = 0; /* already reset as part of load_fw */
3506 if (!card_fw_usable) {
3509 d = ntohl(drv_fw->fw_ver);
3510 c = ntohl(card_fw->fw_ver);
3511 k = kld_fw ? ntohl(kld_fw->fw_ver) : 0;
3513 device_printf(sc->dev, "Cannot find a usable firmware: "
3514 "fw_install %d, chip state %d, "
3515 "driver compiled with %d.%d.%d.%d, "
3516 "card has %d.%d.%d.%d, KLD has %d.%d.%d.%d\n",
3517 t4_fw_install, state,
3518 G_FW_HDR_FW_VER_MAJOR(d), G_FW_HDR_FW_VER_MINOR(d),
3519 G_FW_HDR_FW_VER_MICRO(d), G_FW_HDR_FW_VER_BUILD(d),
3520 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
3521 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c),
3522 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
3523 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
3529 if (need_fw_reset &&
3530 (rc = -t4_fw_reset(sc, sc->mbox, F_PIORSTMODE | F_PIORST)) != 0) {
3531 device_printf(sc->dev, "firmware reset failed: %d.\n", rc);
3532 if (rc != ETIMEDOUT && rc != EIO)
3533 t4_fw_bye(sc, sc->mbox);
3538 rc = get_params__pre_init(sc);
3540 goto done; /* error message displayed already */
3542 /* Partition adapter resources as specified in the config file. */
3543 if (state == DEV_STATE_UNINIT) {
3545 KASSERT(sc->flags & MASTER_PF,
3546 ("%s: trying to change chip settings when not master.",
3549 rc = partition_resources(sc, default_cfg, fw_info->kld_name);
3551 goto done; /* error message displayed already */
3553 t4_tweak_chip_settings(sc);
3555 /* get basic stuff going */
3556 rc = -t4_fw_initialize(sc, sc->mbox);
3558 device_printf(sc->dev, "fw init failed: %d.\n", rc);
3562 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "pf%d", pf);
3567 free(card_fw, M_CXGBE);
3569 firmware_put(fw, FIRMWARE_UNLOAD);
3570 if (default_cfg != NULL)
3571 firmware_put(default_cfg, FIRMWARE_UNLOAD);
3576 #define FW_PARAM_DEV(param) \
3577 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
3578 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
3579 #define FW_PARAM_PFVF(param) \
3580 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
3581 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param))
3584 * Partition chip resources for use between various PFs, VFs, etc.
3587 partition_resources(struct adapter *sc, const struct firmware *default_cfg,
3588 const char *name_prefix)
3590 const struct firmware *cfg = NULL;
3592 struct fw_caps_config_cmd caps;
3593 uint32_t mtype, moff, finicsum, cfcsum;
3596 * Figure out what configuration file to use. Pick the default config
3597 * file for the card if the user hasn't specified one explicitly.
3599 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", t4_cfg_file);
3600 if (strncmp(t4_cfg_file, DEFAULT_CF, sizeof(t4_cfg_file)) == 0) {
3601 /* Card specific overrides go here. */
3602 if (pci_get_device(sc->dev) == 0x440a)
3603 snprintf(sc->cfg_file, sizeof(sc->cfg_file), UWIRE_CF);
3605 snprintf(sc->cfg_file, sizeof(sc->cfg_file), FPGA_CF);
3606 } else if (strncmp(t4_cfg_file, BUILTIN_CF, sizeof(t4_cfg_file)) == 0)
3607 goto use_built_in_config; /* go straight to config. */
3610 * We need to load another module if the profile is anything except
3611 * "default" or "flash".
3613 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) != 0 &&
3614 strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
3617 snprintf(s, sizeof(s), "%s_%s", name_prefix, sc->cfg_file);
3618 cfg = firmware_get(s);
3620 if (default_cfg != NULL) {
3621 device_printf(sc->dev,
3622 "unable to load module \"%s\" for "
3623 "configuration profile \"%s\", will use "
3624 "the default config file instead.\n",
3626 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
3629 device_printf(sc->dev,
3630 "unable to load module \"%s\" for "
3631 "configuration profile \"%s\", will use "
3632 "the config file on the card's flash "
3633 "instead.\n", s, sc->cfg_file);
3634 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
3640 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) == 0 &&
3641 default_cfg == NULL) {
3642 device_printf(sc->dev,
3643 "default config file not available, will use the config "
3644 "file on the card's flash instead.\n");
3645 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", FLASH_CF);
3648 if (strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
3650 const uint32_t *cfdata;
3651 uint32_t param, val, addr;
3653 KASSERT(cfg != NULL || default_cfg != NULL,
3654 ("%s: no config to upload", __func__));
3657 * Ask the firmware where it wants us to upload the config file.
3659 param = FW_PARAM_DEV(CF);
3660 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
3662 /* No support for config file? Shouldn't happen. */
3663 device_printf(sc->dev,
3664 "failed to query config file location: %d.\n", rc);
3667 mtype = G_FW_PARAMS_PARAM_Y(val);
3668 moff = G_FW_PARAMS_PARAM_Z(val) << 16;
3671 * XXX: sheer laziness. We deliberately added 4 bytes of
3672 * useless stuffing/comments at the end of the config file so
3673 * it's ok to simply throw away the last remaining bytes when
3674 * the config file is not an exact multiple of 4. This also
3675 * helps with the validate_mt_off_len check.
3678 cflen = cfg->datasize & ~3;
3681 cflen = default_cfg->datasize & ~3;
3682 cfdata = default_cfg->data;
3685 if (cflen > FLASH_CFG_MAX_SIZE) {
3686 device_printf(sc->dev,
3687 "config file too long (%d, max allowed is %d). "
3688 "Will try to use the config on the card, if any.\n",
3689 cflen, FLASH_CFG_MAX_SIZE);
3690 goto use_config_on_flash;
3693 rc = validate_mt_off_len(sc, mtype, moff, cflen, &addr);
3695 device_printf(sc->dev,
3696 "%s: addr (%d/0x%x) or len %d is not valid: %d. "
3697 "Will try to use the config on the card, if any.\n",
3698 __func__, mtype, moff, cflen, rc);
3699 goto use_config_on_flash;
3701 write_via_memwin(sc, 2, addr, cfdata, cflen);
3703 use_config_on_flash:
3704 mtype = FW_MEMTYPE_FLASH;
3705 moff = t4_flash_cfg_addr(sc);
3708 bzero(&caps, sizeof(caps));
3709 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3710 F_FW_CMD_REQUEST | F_FW_CMD_READ);
3711 caps.cfvalid_to_len16 = htobe32(F_FW_CAPS_CONFIG_CMD_CFVALID |
3712 V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
3713 V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(moff >> 16) | FW_LEN16(caps));
3714 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
3716 device_printf(sc->dev,
3717 "failed to pre-process config file: %d "
3718 "(mtype %d, moff 0x%x). Will reset the firmware and retry "
3719 "with the built-in configuration.\n", rc, mtype, moff);
3721 rc = -t4_fw_reset(sc, sc->mbox, F_PIORSTMODE | F_PIORST);
3723 device_printf(sc->dev,
3724 "firmware reset failed: %d.\n", rc);
3725 if (rc != ETIMEDOUT && rc != EIO) {
3726 t4_fw_bye(sc, sc->mbox);
3727 sc->flags &= ~FW_OK;
3731 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", "built-in");
3732 use_built_in_config:
3733 bzero(&caps, sizeof(caps));
3734 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3735 F_FW_CMD_REQUEST | F_FW_CMD_READ);
3736 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
3737 rc = t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
3739 device_printf(sc->dev,
3740 "built-in configuration failed: %d.\n", rc);
3745 finicsum = be32toh(caps.finicsum);
3746 cfcsum = be32toh(caps.cfcsum);
3747 if (finicsum != cfcsum) {
3748 device_printf(sc->dev,
3749 "WARNING: config file checksum mismatch: %08x %08x\n",
3752 sc->cfcsum = cfcsum;
3754 #define LIMIT_CAPS(x) do { \
3755 caps.x &= htobe16(t4_##x##_allowed); \
3759 * Let the firmware know what features will (not) be used so it can tune
3760 * things accordingly.
3762 LIMIT_CAPS(nbmcaps);
3763 LIMIT_CAPS(linkcaps);
3764 LIMIT_CAPS(switchcaps);
3765 LIMIT_CAPS(niccaps);
3766 LIMIT_CAPS(toecaps);
3767 LIMIT_CAPS(rdmacaps);
3768 LIMIT_CAPS(cryptocaps);
3769 LIMIT_CAPS(iscsicaps);
3770 LIMIT_CAPS(fcoecaps);
3773 if (caps.niccaps & htobe16(FW_CAPS_CONFIG_NIC_HASHFILTER)) {
3775 * TOE and hashfilters are mutually exclusive. It is a config
3776 * file or firmware bug if both are reported as available. Try
3777 * to cope with the situation in non-debug builds by disabling
3780 MPASS(caps.toecaps == 0);
3787 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3788 F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
3789 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
3790 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), NULL);
3792 device_printf(sc->dev,
3793 "failed to process config file: %d.\n", rc);
3797 firmware_put(cfg, FIRMWARE_UNLOAD);
3802 * Retrieve parameters that are needed (or nice to have) very early.
3805 get_params__pre_init(struct adapter *sc)
3808 uint32_t param[2], val[2];
3810 t4_get_version_info(sc);
3812 snprintf(sc->fw_version, sizeof(sc->fw_version), "%u.%u.%u.%u",
3813 G_FW_HDR_FW_VER_MAJOR(sc->params.fw_vers),
3814 G_FW_HDR_FW_VER_MINOR(sc->params.fw_vers),
3815 G_FW_HDR_FW_VER_MICRO(sc->params.fw_vers),
3816 G_FW_HDR_FW_VER_BUILD(sc->params.fw_vers));
3818 snprintf(sc->bs_version, sizeof(sc->bs_version), "%u.%u.%u.%u",
3819 G_FW_HDR_FW_VER_MAJOR(sc->params.bs_vers),
3820 G_FW_HDR_FW_VER_MINOR(sc->params.bs_vers),
3821 G_FW_HDR_FW_VER_MICRO(sc->params.bs_vers),
3822 G_FW_HDR_FW_VER_BUILD(sc->params.bs_vers));
3824 snprintf(sc->tp_version, sizeof(sc->tp_version), "%u.%u.%u.%u",
3825 G_FW_HDR_FW_VER_MAJOR(sc->params.tp_vers),
3826 G_FW_HDR_FW_VER_MINOR(sc->params.tp_vers),
3827 G_FW_HDR_FW_VER_MICRO(sc->params.tp_vers),
3828 G_FW_HDR_FW_VER_BUILD(sc->params.tp_vers));
3830 snprintf(sc->er_version, sizeof(sc->er_version), "%u.%u.%u.%u",
3831 G_FW_HDR_FW_VER_MAJOR(sc->params.er_vers),
3832 G_FW_HDR_FW_VER_MINOR(sc->params.er_vers),
3833 G_FW_HDR_FW_VER_MICRO(sc->params.er_vers),
3834 G_FW_HDR_FW_VER_BUILD(sc->params.er_vers));
3836 param[0] = FW_PARAM_DEV(PORTVEC);
3837 param[1] = FW_PARAM_DEV(CCLK);
3838 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
3840 device_printf(sc->dev,
3841 "failed to query parameters (pre_init): %d.\n", rc);
3845 sc->params.portvec = val[0];
3846 sc->params.nports = bitcount32(val[0]);
3847 sc->params.vpd.cclk = val[1];
3849 /* Read device log parameters. */
3850 rc = -t4_init_devlog_params(sc, 1);
3852 fixup_devlog_params(sc);
3854 device_printf(sc->dev,
3855 "failed to get devlog parameters: %d.\n", rc);
3856 rc = 0; /* devlog isn't critical for device operation */
3863 * Retrieve various parameters that are of interest to the driver. The device
3864 * has been initialized by the firmware at this point.
3867 get_params__post_init(struct adapter *sc)
3870 uint32_t param[7], val[7];
3871 struct fw_caps_config_cmd caps;
3873 param[0] = FW_PARAM_PFVF(IQFLINT_START);
3874 param[1] = FW_PARAM_PFVF(EQ_START);
3875 param[2] = FW_PARAM_PFVF(FILTER_START);
3876 param[3] = FW_PARAM_PFVF(FILTER_END);
3877 param[4] = FW_PARAM_PFVF(L2T_START);
3878 param[5] = FW_PARAM_PFVF(L2T_END);
3879 param[6] = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
3880 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) |
3881 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_VDD);
3882 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 7, param, val);
3884 device_printf(sc->dev,
3885 "failed to query parameters (post_init): %d.\n", rc);
3889 sc->sge.iq_start = val[0];
3890 sc->sge.eq_start = val[1];
3891 if ((int)val[3] > (int)val[2]) {
3892 sc->tids.ftid_base = val[2];
3893 sc->tids.ftid_end = val[3];
3894 sc->tids.nftids = val[3] - val[2] + 1;
3896 sc->vres.l2t.start = val[4];
3897 sc->vres.l2t.size = val[5] - val[4] + 1;
3898 KASSERT(sc->vres.l2t.size <= L2T_SIZE,
3899 ("%s: L2 table size (%u) larger than expected (%u)",
3900 __func__, sc->vres.l2t.size, L2T_SIZE));
3901 sc->params.core_vdd = val[6];
3903 if (chip_id(sc) >= CHELSIO_T6) {
3906 if (sc->params.fw_vers >=
3907 (V_FW_HDR_FW_VER_MAJOR(1) | V_FW_HDR_FW_VER_MINOR(20) |
3908 V_FW_HDR_FW_VER_MICRO(1) | V_FW_HDR_FW_VER_BUILD(0))) {
3910 * Note that the code to enable the region should run
3911 * before t4_fw_initialize and not here. This is just a
3912 * reminder to add said code.
3914 device_printf(sc->dev,
3915 "hpfilter region not enabled.\n");
3919 sc->tids.tid_base = t4_read_reg(sc,
3920 A_LE_DB_ACTIVE_TABLE_START_INDEX);
3922 param[0] = FW_PARAM_PFVF(HPFILTER_START);
3923 param[1] = FW_PARAM_PFVF(HPFILTER_END);
3924 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
3926 device_printf(sc->dev,
3927 "failed to query hpfilter parameters: %d.\n", rc);
3930 if ((int)val[1] > (int)val[0]) {
3931 sc->tids.hpftid_base = val[0];
3932 sc->tids.hpftid_end = val[1];
3933 sc->tids.nhpftids = val[1] - val[0] + 1;
3936 * These should go off if the layout changes and the
3937 * driver needs to catch up.
3939 MPASS(sc->tids.hpftid_base == 0);
3940 MPASS(sc->tids.tid_base == sc->tids.nhpftids);
3945 * MPSBGMAP is queried separately because only recent firmwares support
3946 * it as a parameter and we don't want the compound query above to fail
3947 * on older firmwares.
3949 param[0] = FW_PARAM_DEV(MPSBGMAP);
3951 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val);
3953 sc->params.mps_bg_map = val[0];
3955 sc->params.mps_bg_map = 0;
3958 * Determine whether the firmware supports the filter2 work request.
3959 * This is queried separately for the same reason as MPSBGMAP above.
3961 param[0] = FW_PARAM_DEV(FILTER2_WR);
3963 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val);
3965 sc->params.filter2_wr_support = val[0] != 0;
3967 sc->params.filter2_wr_support = 0;
3969 /* get capabilites */
3970 bzero(&caps, sizeof(caps));
3971 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3972 F_FW_CMD_REQUEST | F_FW_CMD_READ);
3973 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
3974 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
3976 device_printf(sc->dev,
3977 "failed to get card capabilities: %d.\n", rc);
3981 #define READ_CAPS(x) do { \
3982 sc->x = htobe16(caps.x); \
3985 READ_CAPS(linkcaps);
3986 READ_CAPS(switchcaps);
3989 READ_CAPS(rdmacaps);
3990 READ_CAPS(cryptocaps);
3991 READ_CAPS(iscsicaps);
3992 READ_CAPS(fcoecaps);
3994 if (sc->niccaps & FW_CAPS_CONFIG_NIC_HASHFILTER) {
3995 MPASS(chip_id(sc) > CHELSIO_T4);
3996 MPASS(sc->toecaps == 0);
3999 param[0] = FW_PARAM_DEV(NTID);
4000 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val);
4002 device_printf(sc->dev,
4003 "failed to query HASHFILTER parameters: %d.\n", rc);
4006 sc->tids.ntids = val[0];
4007 if (sc->params.fw_vers <
4008 (V_FW_HDR_FW_VER_MAJOR(1) | V_FW_HDR_FW_VER_MINOR(20) |
4009 V_FW_HDR_FW_VER_MICRO(5) | V_FW_HDR_FW_VER_BUILD(0))) {
4010 MPASS(sc->tids.ntids >= sc->tids.nhpftids);
4011 sc->tids.ntids -= sc->tids.nhpftids;
4013 sc->tids.natids = min(sc->tids.ntids / 2, MAX_ATIDS);
4014 sc->params.hash_filter = 1;
4016 if (sc->niccaps & FW_CAPS_CONFIG_NIC_ETHOFLD) {
4017 param[0] = FW_PARAM_PFVF(ETHOFLD_START);
4018 param[1] = FW_PARAM_PFVF(ETHOFLD_END);
4019 param[2] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
4020 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 3, param, val);
4022 device_printf(sc->dev,
4023 "failed to query NIC parameters: %d.\n", rc);
4026 if ((int)val[1] > (int)val[0]) {
4027 sc->tids.etid_base = val[0];
4028 sc->tids.etid_end = val[1];
4029 sc->tids.netids = val[1] - val[0] + 1;
4030 sc->params.eo_wr_cred = val[2];
4031 sc->params.ethoffload = 1;
4035 /* query offload-related parameters */
4036 param[0] = FW_PARAM_DEV(NTID);
4037 param[1] = FW_PARAM_PFVF(SERVER_START);
4038 param[2] = FW_PARAM_PFVF(SERVER_END);
4039 param[3] = FW_PARAM_PFVF(TDDP_START);
4040 param[4] = FW_PARAM_PFVF(TDDP_END);
4041 param[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
4042 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
4044 device_printf(sc->dev,
4045 "failed to query TOE parameters: %d.\n", rc);
4048 sc->tids.ntids = val[0];
4049 if (sc->params.fw_vers <
4050 (V_FW_HDR_FW_VER_MAJOR(1) | V_FW_HDR_FW_VER_MINOR(20) |
4051 V_FW_HDR_FW_VER_MICRO(5) | V_FW_HDR_FW_VER_BUILD(0))) {
4052 MPASS(sc->tids.ntids >= sc->tids.nhpftids);
4053 sc->tids.ntids -= sc->tids.nhpftids;
4055 sc->tids.natids = min(sc->tids.ntids / 2, MAX_ATIDS);
4056 if ((int)val[2] > (int)val[1]) {
4057 sc->tids.stid_base = val[1];
4058 sc->tids.nstids = val[2] - val[1] + 1;
4060 sc->vres.ddp.start = val[3];
4061 sc->vres.ddp.size = val[4] - val[3] + 1;
4062 sc->params.ofldq_wr_cred = val[5];
4063 sc->params.offload = 1;
4066 * The firmware attempts memfree TOE configuration for -SO cards
4067 * and will report toecaps=0 if it runs out of resources (this
4068 * depends on the config file). It may not report 0 for other
4069 * capabilities dependent on the TOE in this case. Set them to
4070 * 0 here so that the driver doesn't bother tracking resources
4071 * that will never be used.
4077 param[0] = FW_PARAM_PFVF(STAG_START);
4078 param[1] = FW_PARAM_PFVF(STAG_END);
4079 param[2] = FW_PARAM_PFVF(RQ_START);
4080 param[3] = FW_PARAM_PFVF(RQ_END);
4081 param[4] = FW_PARAM_PFVF(PBL_START);
4082 param[5] = FW_PARAM_PFVF(PBL_END);
4083 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
4085 device_printf(sc->dev,
4086 "failed to query RDMA parameters(1): %d.\n", rc);
4089 sc->vres.stag.start = val[0];
4090 sc->vres.stag.size = val[1] - val[0] + 1;
4091 sc->vres.rq.start = val[2];
4092 sc->vres.rq.size = val[3] - val[2] + 1;
4093 sc->vres.pbl.start = val[4];
4094 sc->vres.pbl.size = val[5] - val[4] + 1;
4096 param[0] = FW_PARAM_PFVF(SQRQ_START);
4097 param[1] = FW_PARAM_PFVF(SQRQ_END);
4098 param[2] = FW_PARAM_PFVF(CQ_START);
4099 param[3] = FW_PARAM_PFVF(CQ_END);
4100 param[4] = FW_PARAM_PFVF(OCQ_START);
4101 param[5] = FW_PARAM_PFVF(OCQ_END);
4102 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
4104 device_printf(sc->dev,
4105 "failed to query RDMA parameters(2): %d.\n", rc);
4108 sc->vres.qp.start = val[0];
4109 sc->vres.qp.size = val[1] - val[0] + 1;
4110 sc->vres.cq.start = val[2];
4111 sc->vres.cq.size = val[3] - val[2] + 1;
4112 sc->vres.ocq.start = val[4];
4113 sc->vres.ocq.size = val[5] - val[4] + 1;
4115 param[0] = FW_PARAM_PFVF(SRQ_START);
4116 param[1] = FW_PARAM_PFVF(SRQ_END);
4117 param[2] = FW_PARAM_DEV(MAXORDIRD_QP);
4118 param[3] = FW_PARAM_DEV(MAXIRD_ADAPTER);
4119 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 4, param, val);
4121 device_printf(sc->dev,
4122 "failed to query RDMA parameters(3): %d.\n", rc);
4125 sc->vres.srq.start = val[0];
4126 sc->vres.srq.size = val[1] - val[0] + 1;
4127 sc->params.max_ordird_qp = val[2];
4128 sc->params.max_ird_adapter = val[3];
4130 if (sc->iscsicaps) {
4131 param[0] = FW_PARAM_PFVF(ISCSI_START);
4132 param[1] = FW_PARAM_PFVF(ISCSI_END);
4133 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
4135 device_printf(sc->dev,
4136 "failed to query iSCSI parameters: %d.\n", rc);
4139 sc->vres.iscsi.start = val[0];
4140 sc->vres.iscsi.size = val[1] - val[0] + 1;
4142 if (sc->cryptocaps & FW_CAPS_CONFIG_TLSKEYS) {
4143 param[0] = FW_PARAM_PFVF(TLS_START);
4144 param[1] = FW_PARAM_PFVF(TLS_END);
4145 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
4147 device_printf(sc->dev,
4148 "failed to query TLS parameters: %d.\n", rc);
4151 sc->vres.key.start = val[0];
4152 sc->vres.key.size = val[1] - val[0] + 1;
4155 t4_init_sge_params(sc);
4158 * We've got the params we wanted to query via the firmware. Now grab
4159 * some others directly from the chip.
4161 rc = t4_read_chip_settings(sc);
4167 set_params__post_init(struct adapter *sc)
4169 uint32_t param, val;
4174 /* ask for encapsulated CPLs */
4175 param = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
4177 (void)t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
4179 /* Enable 32b port caps if the firmware supports it. */
4180 param = FW_PARAM_PFVF(PORT_CAPS32);
4182 if (t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val) == 0)
4183 sc->params.port_caps32 = 1;
4187 * Override the TOE timers with user provided tunables. This is not the
4188 * recommended way to change the timers (the firmware config file is) so
4189 * these tunables are not documented.
4191 * All the timer tunables are in microseconds.
4193 if (t4_toe_keepalive_idle != 0) {
4194 v = us_to_tcp_ticks(sc, t4_toe_keepalive_idle);
4195 v &= M_KEEPALIVEIDLE;
4196 t4_set_reg_field(sc, A_TP_KEEP_IDLE,
4197 V_KEEPALIVEIDLE(M_KEEPALIVEIDLE), V_KEEPALIVEIDLE(v));
4199 if (t4_toe_keepalive_interval != 0) {
4200 v = us_to_tcp_ticks(sc, t4_toe_keepalive_interval);
4201 v &= M_KEEPALIVEINTVL;
4202 t4_set_reg_field(sc, A_TP_KEEP_INTVL,
4203 V_KEEPALIVEINTVL(M_KEEPALIVEINTVL), V_KEEPALIVEINTVL(v));
4205 if (t4_toe_keepalive_count != 0) {
4206 v = t4_toe_keepalive_count & M_KEEPALIVEMAXR2;
4207 t4_set_reg_field(sc, A_TP_SHIFT_CNT,
4208 V_KEEPALIVEMAXR1(M_KEEPALIVEMAXR1) |
4209 V_KEEPALIVEMAXR2(M_KEEPALIVEMAXR2),
4210 V_KEEPALIVEMAXR1(1) | V_KEEPALIVEMAXR2(v));
4212 if (t4_toe_rexmt_min != 0) {
4213 v = us_to_tcp_ticks(sc, t4_toe_rexmt_min);
4215 t4_set_reg_field(sc, A_TP_RXT_MIN,
4216 V_RXTMIN(M_RXTMIN), V_RXTMIN(v));
4218 if (t4_toe_rexmt_max != 0) {
4219 v = us_to_tcp_ticks(sc, t4_toe_rexmt_max);
4221 t4_set_reg_field(sc, A_TP_RXT_MAX,
4222 V_RXTMAX(M_RXTMAX), V_RXTMAX(v));
4224 if (t4_toe_rexmt_count != 0) {
4225 v = t4_toe_rexmt_count & M_RXTSHIFTMAXR2;
4226 t4_set_reg_field(sc, A_TP_SHIFT_CNT,
4227 V_RXTSHIFTMAXR1(M_RXTSHIFTMAXR1) |
4228 V_RXTSHIFTMAXR2(M_RXTSHIFTMAXR2),
4229 V_RXTSHIFTMAXR1(1) | V_RXTSHIFTMAXR2(v));
4231 for (i = 0; i < nitems(t4_toe_rexmt_backoff); i++) {
4232 if (t4_toe_rexmt_backoff[i] != -1) {
4233 v = t4_toe_rexmt_backoff[i] & M_TIMERBACKOFFINDEX0;
4234 shift = (i & 3) << 3;
4235 t4_set_reg_field(sc, A_TP_TCP_BACKOFF_REG0 + (i & ~3),
4236 M_TIMERBACKOFFINDEX0 << shift, v << shift);
4243 #undef FW_PARAM_PFVF
4247 t4_set_desc(struct adapter *sc)
4250 struct adapter_params *p = &sc->params;
4252 snprintf(buf, sizeof(buf), "Chelsio %s", p->vpd.id);
4254 device_set_desc_copy(sc->dev, buf);
4258 ifmedia_add4(struct ifmedia *ifm, int m)
4261 ifmedia_add(ifm, m, 0, NULL);
4262 ifmedia_add(ifm, m | IFM_ETH_TXPAUSE, 0, NULL);
4263 ifmedia_add(ifm, m | IFM_ETH_RXPAUSE, 0, NULL);
4264 ifmedia_add(ifm, m | IFM_ETH_TXPAUSE | IFM_ETH_RXPAUSE, 0, NULL);
4268 * This is the selected media, which is not quite the same as the active media.
4269 * The media line in ifconfig is "media: Ethernet selected (active)" if selected
4270 * and active are not the same, and "media: Ethernet selected" otherwise.
4273 set_current_media(struct port_info *pi)
4275 struct link_config *lc;
4276 struct ifmedia *ifm;
4280 PORT_LOCK_ASSERT_OWNED(pi);
4282 /* Leave current media alone if it's already set to IFM_NONE. */
4284 if (ifm->ifm_cur != NULL &&
4285 IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_NONE)
4289 if (lc->requested_aneg != AUTONEG_DISABLE &&
4290 lc->supported & FW_PORT_CAP32_ANEG) {
4291 ifmedia_set(ifm, IFM_ETHER | IFM_AUTO);
4294 mword = IFM_ETHER | IFM_FDX;
4295 if (lc->requested_fc & PAUSE_TX)
4296 mword |= IFM_ETH_TXPAUSE;
4297 if (lc->requested_fc & PAUSE_RX)
4298 mword |= IFM_ETH_RXPAUSE;
4299 if (lc->requested_speed == 0)
4300 speed = port_top_speed(pi) * 1000; /* Gbps -> Mbps */
4302 speed = lc->requested_speed;
4303 mword |= port_mword(pi, speed_to_fwcap(speed));
4304 ifmedia_set(ifm, mword);
4308 * Returns true if the ifmedia list for the port cannot change.
4311 fixed_ifmedia(struct port_info *pi)
4314 return (pi->port_type == FW_PORT_TYPE_BT_SGMII ||
4315 pi->port_type == FW_PORT_TYPE_BT_XFI ||
4316 pi->port_type == FW_PORT_TYPE_BT_XAUI ||
4317 pi->port_type == FW_PORT_TYPE_KX4 ||
4318 pi->port_type == FW_PORT_TYPE_KX ||
4319 pi->port_type == FW_PORT_TYPE_KR ||
4320 pi->port_type == FW_PORT_TYPE_BP_AP ||
4321 pi->port_type == FW_PORT_TYPE_BP4_AP ||
4322 pi->port_type == FW_PORT_TYPE_BP40_BA ||
4323 pi->port_type == FW_PORT_TYPE_KR4_100G ||
4324 pi->port_type == FW_PORT_TYPE_KR_SFP28 ||
4325 pi->port_type == FW_PORT_TYPE_KR_XLAUI);
4329 build_medialist(struct port_info *pi)
4332 int unknown, mword, bit;
4333 struct link_config *lc;
4334 struct ifmedia *ifm;
4336 PORT_LOCK_ASSERT_OWNED(pi);
4338 if (pi->flags & FIXED_IFMEDIA)
4342 * Rebuild the ifmedia list.
4345 ifmedia_removeall(ifm);
4347 ss = G_FW_PORT_CAP32_SPEED(lc->supported); /* Supported Speeds */
4348 if (__predict_false(ss == 0)) { /* not supposed to happen. */
4351 MPASS(LIST_EMPTY(&ifm->ifm_list));
4352 ifmedia_add(ifm, IFM_ETHER | IFM_NONE, 0, NULL);
4353 ifmedia_set(ifm, IFM_ETHER | IFM_NONE);
4358 for (bit = S_FW_PORT_CAP32_SPEED; bit < fls(ss); bit++) {
4360 MPASS(speed & M_FW_PORT_CAP32_SPEED);
4362 mword = port_mword(pi, speed);
4363 if (mword == IFM_NONE) {
4365 } else if (mword == IFM_UNKNOWN)
4368 ifmedia_add4(ifm, IFM_ETHER | IFM_FDX | mword);
4371 if (unknown > 0) /* Add one unknown for all unknown media types. */
4372 ifmedia_add4(ifm, IFM_ETHER | IFM_FDX | IFM_UNKNOWN);
4373 if (lc->supported & FW_PORT_CAP32_ANEG)
4374 ifmedia_add(ifm, IFM_ETHER | IFM_AUTO, 0, NULL);
4376 set_current_media(pi);
4380 * Initialize the requested fields in the link config based on driver tunables.
4383 init_link_config(struct port_info *pi)
4385 struct link_config *lc = &pi->link_cfg;
4387 PORT_LOCK_ASSERT_OWNED(pi);
4389 lc->requested_speed = 0;
4391 if (t4_autoneg == 0)
4392 lc->requested_aneg = AUTONEG_DISABLE;
4393 else if (t4_autoneg == 1)
4394 lc->requested_aneg = AUTONEG_ENABLE;
4396 lc->requested_aneg = AUTONEG_AUTO;
4398 lc->requested_fc = t4_pause_settings & (PAUSE_TX | PAUSE_RX |
4401 if (t4_fec == -1 || t4_fec & FEC_AUTO)
4402 lc->requested_fec = FEC_AUTO;
4404 lc->requested_fec = FEC_NONE;
4405 if (t4_fec & FEC_RS)
4406 lc->requested_fec |= FEC_RS;
4407 if (t4_fec & FEC_BASER_RS)
4408 lc->requested_fec |= FEC_BASER_RS;
4413 * Makes sure that all requested settings comply with what's supported by the
4414 * port. Returns the number of settings that were invalid and had to be fixed.
4417 fixup_link_config(struct port_info *pi)
4420 struct link_config *lc = &pi->link_cfg;
4423 PORT_LOCK_ASSERT_OWNED(pi);
4425 /* Speed (when not autonegotiating) */
4426 if (lc->requested_speed != 0) {
4427 fwspeed = speed_to_fwcap(lc->requested_speed);
4428 if ((fwspeed & lc->supported) == 0) {
4430 lc->requested_speed = 0;
4434 /* Link autonegotiation */
4435 MPASS(lc->requested_aneg == AUTONEG_ENABLE ||
4436 lc->requested_aneg == AUTONEG_DISABLE ||
4437 lc->requested_aneg == AUTONEG_AUTO);
4438 if (lc->requested_aneg == AUTONEG_ENABLE &&
4439 !(lc->supported & FW_PORT_CAP32_ANEG)) {
4441 lc->requested_aneg = AUTONEG_AUTO;
4445 MPASS((lc->requested_fc & ~(PAUSE_TX | PAUSE_RX | PAUSE_AUTONEG)) == 0);
4446 if (lc->requested_fc & PAUSE_TX &&
4447 !(lc->supported & FW_PORT_CAP32_FC_TX)) {
4449 lc->requested_fc &= ~PAUSE_TX;
4451 if (lc->requested_fc & PAUSE_RX &&
4452 !(lc->supported & FW_PORT_CAP32_FC_RX)) {
4454 lc->requested_fc &= ~PAUSE_RX;
4456 if (!(lc->requested_fc & PAUSE_AUTONEG) &&
4457 !(lc->supported & FW_PORT_CAP32_FORCE_PAUSE)) {
4459 lc->requested_fc |= PAUSE_AUTONEG;
4463 if ((lc->requested_fec & FEC_RS &&
4464 !(lc->supported & FW_PORT_CAP32_FEC_RS)) ||
4465 (lc->requested_fec & FEC_BASER_RS &&
4466 !(lc->supported & FW_PORT_CAP32_FEC_BASER_RS))) {
4468 lc->requested_fec = FEC_AUTO;
4475 * Apply the requested L1 settings, which are expected to be valid, to the
4479 apply_link_config(struct port_info *pi)
4481 struct adapter *sc = pi->adapter;
4482 struct link_config *lc = &pi->link_cfg;
4486 ASSERT_SYNCHRONIZED_OP(sc);
4487 PORT_LOCK_ASSERT_OWNED(pi);
4489 if (lc->requested_aneg == AUTONEG_ENABLE)
4490 MPASS(lc->supported & FW_PORT_CAP32_ANEG);
4491 if (!(lc->requested_fc & PAUSE_AUTONEG))
4492 MPASS(lc->supported & FW_PORT_CAP32_FORCE_PAUSE);
4493 if (lc->requested_fc & PAUSE_TX)
4494 MPASS(lc->supported & FW_PORT_CAP32_FC_TX);
4495 if (lc->requested_fc & PAUSE_RX)
4496 MPASS(lc->supported & FW_PORT_CAP32_FC_RX);
4497 if (lc->requested_fec & FEC_RS)
4498 MPASS(lc->supported & FW_PORT_CAP32_FEC_RS);
4499 if (lc->requested_fec & FEC_BASER_RS)
4500 MPASS(lc->supported & FW_PORT_CAP32_FEC_BASER_RS);
4502 rc = -t4_link_l1cfg(sc, sc->mbox, pi->tx_chan, lc);
4504 /* Don't complain if the VF driver gets back an EPERM. */
4505 if (!(sc->flags & IS_VF) || rc != FW_EPERM)
4506 device_printf(pi->dev, "l1cfg failed: %d\n", rc);
4509 * An L1_CFG will almost always result in a link-change event if
4510 * the link is up, and the driver will refresh the actual
4511 * fec/fc/etc. when the notification is processed. If the link
4512 * is down then the actual settings are meaningless.
4514 * This takes care of the case where a change in the L1 settings
4515 * may not result in a notification.
4517 if (lc->link_ok && !(lc->requested_fc & PAUSE_AUTONEG))
4518 lc->fc = lc->requested_fc & (PAUSE_TX | PAUSE_RX);
4523 #define FW_MAC_EXACT_CHUNK 7
4526 * Program the port's XGMAC based on parameters in ifnet. The caller also
4527 * indicates which parameters should be programmed (the rest are left alone).
4530 update_mac_settings(struct ifnet *ifp, int flags)
4533 struct vi_info *vi = ifp->if_softc;
4534 struct port_info *pi = vi->pi;
4535 struct adapter *sc = pi->adapter;
4536 int mtu = -1, promisc = -1, allmulti = -1, vlanex = -1;
4538 ASSERT_SYNCHRONIZED_OP(sc);
4539 KASSERT(flags, ("%s: not told what to update.", __func__));
4541 if (flags & XGMAC_MTU)
4544 if (flags & XGMAC_PROMISC)
4545 promisc = ifp->if_flags & IFF_PROMISC ? 1 : 0;
4547 if (flags & XGMAC_ALLMULTI)
4548 allmulti = ifp->if_flags & IFF_ALLMULTI ? 1 : 0;
4550 if (flags & XGMAC_VLANEX)
4551 vlanex = ifp->if_capenable & IFCAP_VLAN_HWTAGGING ? 1 : 0;
4553 if (flags & (XGMAC_MTU|XGMAC_PROMISC|XGMAC_ALLMULTI|XGMAC_VLANEX)) {
4554 rc = -t4_set_rxmode(sc, sc->mbox, vi->viid, mtu, promisc,
4555 allmulti, 1, vlanex, false);
4557 if_printf(ifp, "set_rxmode (%x) failed: %d\n", flags,
4563 if (flags & XGMAC_UCADDR) {
4564 uint8_t ucaddr[ETHER_ADDR_LEN];
4566 bcopy(IF_LLADDR(ifp), ucaddr, sizeof(ucaddr));
4567 rc = t4_change_mac(sc, sc->mbox, vi->viid, vi->xact_addr_filt,
4568 ucaddr, true, true);
4571 if_printf(ifp, "change_mac failed: %d\n", rc);
4574 vi->xact_addr_filt = rc;
4579 if (flags & XGMAC_MCADDRS) {
4580 const uint8_t *mcaddr[FW_MAC_EXACT_CHUNK];
4583 struct ifmultiaddr *ifma;
4586 if_maddr_rlock(ifp);
4587 CK_STAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
4588 if (ifma->ifma_addr->sa_family != AF_LINK)
4591 LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
4592 MPASS(ETHER_IS_MULTICAST(mcaddr[i]));
4595 if (i == FW_MAC_EXACT_CHUNK) {
4596 rc = t4_alloc_mac_filt(sc, sc->mbox, vi->viid,
4597 del, i, mcaddr, NULL, &hash, 0);
4600 for (j = 0; j < i; j++) {
4602 "failed to add mc address"
4604 "%02x:%02x:%02x rc=%d\n",
4605 mcaddr[j][0], mcaddr[j][1],
4606 mcaddr[j][2], mcaddr[j][3],
4607 mcaddr[j][4], mcaddr[j][5],
4617 rc = t4_alloc_mac_filt(sc, sc->mbox, vi->viid, del, i,
4618 mcaddr, NULL, &hash, 0);
4621 for (j = 0; j < i; j++) {
4623 "failed to add mc address"
4625 "%02x:%02x:%02x rc=%d\n",
4626 mcaddr[j][0], mcaddr[j][1],
4627 mcaddr[j][2], mcaddr[j][3],
4628 mcaddr[j][4], mcaddr[j][5],
4635 rc = -t4_set_addr_hash(sc, sc->mbox, vi->viid, 0, hash, 0);
4637 if_printf(ifp, "failed to set mc address hash: %d", rc);
4639 if_maddr_runlock(ifp);
4646 * {begin|end}_synchronized_op must be called from the same thread.
4649 begin_synchronized_op(struct adapter *sc, struct vi_info *vi, int flags,
4655 /* the caller thinks it's ok to sleep, but is it really? */
4656 if (flags & SLEEP_OK)
4657 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
4658 "begin_synchronized_op");
4669 if (vi && IS_DOOMED(vi)) {
4679 if (!(flags & SLEEP_OK)) {
4684 if (mtx_sleep(&sc->flags, &sc->sc_lock, pri, wmesg, 0)) {
4690 KASSERT(!IS_BUSY(sc), ("%s: controller busy.", __func__));
4693 sc->last_op = wmesg;
4694 sc->last_op_thr = curthread;
4695 sc->last_op_flags = flags;
4699 if (!(flags & HOLD_LOCK) || rc)
4706 * Tell if_ioctl and if_init that the VI is going away. This is
4707 * special variant of begin_synchronized_op and must be paired with a
4708 * call to end_synchronized_op.
4711 doom_vi(struct adapter *sc, struct vi_info *vi)
4718 mtx_sleep(&sc->flags, &sc->sc_lock, 0, "t4detach", 0);
4721 sc->last_op = "t4detach";
4722 sc->last_op_thr = curthread;
4723 sc->last_op_flags = 0;
4729 * {begin|end}_synchronized_op must be called from the same thread.
4732 end_synchronized_op(struct adapter *sc, int flags)
4735 if (flags & LOCK_HELD)
4736 ADAPTER_LOCK_ASSERT_OWNED(sc);
4740 KASSERT(IS_BUSY(sc), ("%s: controller not busy.", __func__));
4747 cxgbe_init_synchronized(struct vi_info *vi)
4749 struct port_info *pi = vi->pi;
4750 struct adapter *sc = pi->adapter;
4751 struct ifnet *ifp = vi->ifp;
4753 struct sge_txq *txq;
4755 ASSERT_SYNCHRONIZED_OP(sc);
4757 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
4758 return (0); /* already running */
4760 if (!(sc->flags & FULL_INIT_DONE) &&
4761 ((rc = adapter_full_init(sc)) != 0))
4762 return (rc); /* error message displayed already */
4764 if (!(vi->flags & VI_INIT_DONE) &&
4765 ((rc = vi_full_init(vi)) != 0))
4766 return (rc); /* error message displayed already */
4768 rc = update_mac_settings(ifp, XGMAC_ALL);
4770 goto done; /* error message displayed already */
4773 if (pi->up_vis == 0) {
4774 t4_update_port_info(pi);
4775 fixup_link_config(pi);
4776 build_medialist(pi);
4777 apply_link_config(pi);
4780 rc = -t4_enable_vi(sc, sc->mbox, vi->viid, true, true);
4782 if_printf(ifp, "enable_vi failed: %d\n", rc);
4788 * Can't fail from this point onwards. Review cxgbe_uninit_synchronized
4792 for_each_txq(vi, i, txq) {
4794 txq->eq.flags |= EQ_ENABLED;
4799 * The first iq of the first port to come up is used for tracing.
4801 if (sc->traceq < 0 && IS_MAIN_VI(vi)) {
4802 sc->traceq = sc->sge.rxq[vi->first_rxq].iq.abs_id;
4803 t4_write_reg(sc, is_t4(sc) ? A_MPS_TRC_RSS_CONTROL :
4804 A_MPS_T5_TRC_RSS_CONTROL, V_RSSCONTROL(pi->tx_chan) |
4805 V_QUEUENUMBER(sc->traceq));
4806 pi->flags |= HAS_TRACEQ;
4811 ifp->if_drv_flags |= IFF_DRV_RUNNING;
4813 if (pi->nvi > 1 || sc->flags & IS_VF)
4814 callout_reset(&vi->tick, hz, vi_tick, vi);
4816 callout_reset(&pi->tick, hz, cxgbe_tick, pi);
4820 cxgbe_uninit_synchronized(vi);
4829 cxgbe_uninit_synchronized(struct vi_info *vi)
4831 struct port_info *pi = vi->pi;
4832 struct adapter *sc = pi->adapter;
4833 struct ifnet *ifp = vi->ifp;
4835 struct sge_txq *txq;
4837 ASSERT_SYNCHRONIZED_OP(sc);
4839 if (!(vi->flags & VI_INIT_DONE)) {
4840 if (__predict_false(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
4841 KASSERT(0, ("uninited VI is running"));
4842 if_printf(ifp, "uninited VI with running ifnet. "
4843 "vi->flags 0x%016lx, if_flags 0x%08x, "
4844 "if_drv_flags 0x%08x\n", vi->flags, ifp->if_flags,
4851 * Disable the VI so that all its data in either direction is discarded
4852 * by the MPS. Leave everything else (the queues, interrupts, and 1Hz
4853 * tick) intact as the TP can deliver negative advice or data that it's
4854 * holding in its RAM (for an offloaded connection) even after the VI is
4857 rc = -t4_enable_vi(sc, sc->mbox, vi->viid, false, false);
4859 if_printf(ifp, "disable_vi failed: %d\n", rc);
4863 for_each_txq(vi, i, txq) {
4865 txq->eq.flags &= ~EQ_ENABLED;
4870 if (pi->nvi > 1 || sc->flags & IS_VF)
4871 callout_stop(&vi->tick);
4873 callout_stop(&pi->tick);
4874 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
4878 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
4880 if (pi->up_vis > 0) {
4885 pi->link_cfg.link_ok = false;
4886 pi->link_cfg.speed = 0;
4887 pi->link_cfg.link_down_rc = 255;
4888 t4_os_link_changed(pi);
4895 * It is ok for this function to fail midway and return right away. t4_detach
4896 * will walk the entire sc->irq list and clean up whatever is valid.
4899 t4_setup_intr_handlers(struct adapter *sc)
4901 int rc, rid, p, q, v;
4904 struct port_info *pi;
4906 struct sge *sge = &sc->sge;
4907 struct sge_rxq *rxq;
4909 struct sge_ofld_rxq *ofld_rxq;
4912 struct sge_nm_rxq *nm_rxq;
4915 int nbuckets = rss_getnumbuckets();
4922 rid = sc->intr_type == INTR_INTX ? 0 : 1;
4923 if (forwarding_intr_to_fwq(sc))
4924 return (t4_alloc_irq(sc, irq, rid, t4_intr_all, sc, "all"));
4926 /* Multiple interrupts. */
4927 if (sc->flags & IS_VF)
4928 KASSERT(sc->intr_count >= T4VF_EXTRA_INTR + sc->params.nports,
4929 ("%s: too few intr.", __func__));
4931 KASSERT(sc->intr_count >= T4_EXTRA_INTR + sc->params.nports,
4932 ("%s: too few intr.", __func__));
4934 /* The first one is always error intr on PFs */
4935 if (!(sc->flags & IS_VF)) {
4936 rc = t4_alloc_irq(sc, irq, rid, t4_intr_err, sc, "err");
4943 /* The second one is always the firmware event queue (first on VFs) */
4944 rc = t4_alloc_irq(sc, irq, rid, t4_intr_evt, &sge->fwq, "evt");
4950 for_each_port(sc, p) {
4952 for_each_vi(pi, v, vi) {
4953 vi->first_intr = rid - 1;
4955 if (vi->nnmrxq > 0) {
4956 int n = max(vi->nrxq, vi->nnmrxq);
4958 rxq = &sge->rxq[vi->first_rxq];
4960 nm_rxq = &sge->nm_rxq[vi->first_nm_rxq];
4962 for (q = 0; q < n; q++) {
4963 snprintf(s, sizeof(s), "%x%c%x", p,
4969 irq->nm_rxq = nm_rxq++;
4971 if (irq->nm_rxq != NULL &&
4973 /* Netmap rx only */
4974 rc = t4_alloc_irq(sc, irq, rid,
4975 t4_nm_intr, irq->nm_rxq, s);
4977 if (irq->nm_rxq != NULL &&
4979 /* NIC and Netmap rx */
4980 rc = t4_alloc_irq(sc, irq, rid,
4981 t4_vi_intr, irq, s);
4984 if (irq->rxq != NULL &&
4985 irq->nm_rxq == NULL) {
4987 rc = t4_alloc_irq(sc, irq, rid,
4988 t4_intr, irq->rxq, s);
4994 bus_bind_intr(sc->dev, irq->res,
4995 rss_getcpu(q % nbuckets));
5003 for_each_rxq(vi, q, rxq) {
5004 snprintf(s, sizeof(s), "%x%c%x", p,
5006 rc = t4_alloc_irq(sc, irq, rid,
5011 bus_bind_intr(sc->dev, irq->res,
5012 rss_getcpu(q % nbuckets));
5020 for_each_ofld_rxq(vi, q, ofld_rxq) {
5021 snprintf(s, sizeof(s), "%x%c%x", p, 'A' + v, q);
5022 rc = t4_alloc_irq(sc, irq, rid, t4_intr,
5033 MPASS(irq == &sc->irq[sc->intr_count]);
5039 adapter_full_init(struct adapter *sc)
5043 uint32_t raw_rss_key[RSS_KEYSIZE / sizeof(uint32_t)];
5044 uint32_t rss_key[RSS_KEYSIZE / sizeof(uint32_t)];
5047 ASSERT_SYNCHRONIZED_OP(sc);
5048 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
5049 KASSERT((sc->flags & FULL_INIT_DONE) == 0,
5050 ("%s: FULL_INIT_DONE already", __func__));
5053 * queues that belong to the adapter (not any particular port).
5055 rc = t4_setup_adapter_queues(sc);
5059 for (i = 0; i < nitems(sc->tq); i++) {
5060 sc->tq[i] = taskqueue_create("t4 taskq", M_NOWAIT,
5061 taskqueue_thread_enqueue, &sc->tq[i]);
5062 if (sc->tq[i] == NULL) {
5063 device_printf(sc->dev,
5064 "failed to allocate task queue %d\n", i);
5068 taskqueue_start_threads(&sc->tq[i], 1, PI_NET, "%s tq%d",
5069 device_get_nameunit(sc->dev), i);
5072 MPASS(RSS_KEYSIZE == 40);
5073 rss_getkey((void *)&raw_rss_key[0]);
5074 for (i = 0; i < nitems(rss_key); i++) {
5075 rss_key[i] = htobe32(raw_rss_key[nitems(rss_key) - 1 - i]);
5077 t4_write_rss_key(sc, &rss_key[0], -1, 1);
5080 if (!(sc->flags & IS_VF))
5082 sc->flags |= FULL_INIT_DONE;
5085 adapter_full_uninit(sc);
5091 adapter_full_uninit(struct adapter *sc)
5095 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
5097 t4_teardown_adapter_queues(sc);
5099 for (i = 0; i < nitems(sc->tq) && sc->tq[i]; i++) {
5100 taskqueue_free(sc->tq[i]);
5104 sc->flags &= ~FULL_INIT_DONE;
5110 #define SUPPORTED_RSS_HASHTYPES (RSS_HASHTYPE_RSS_IPV4 | \
5111 RSS_HASHTYPE_RSS_TCP_IPV4 | RSS_HASHTYPE_RSS_IPV6 | \
5112 RSS_HASHTYPE_RSS_TCP_IPV6 | RSS_HASHTYPE_RSS_UDP_IPV4 | \
5113 RSS_HASHTYPE_RSS_UDP_IPV6)
5115 /* Translates kernel hash types to hardware. */
5117 hashconfig_to_hashen(int hashconfig)
5121 if (hashconfig & RSS_HASHTYPE_RSS_IPV4)
5122 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN;
5123 if (hashconfig & RSS_HASHTYPE_RSS_IPV6)
5124 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN;
5125 if (hashconfig & RSS_HASHTYPE_RSS_UDP_IPV4) {
5126 hashen |= F_FW_RSS_VI_CONFIG_CMD_UDPEN |
5127 F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
5129 if (hashconfig & RSS_HASHTYPE_RSS_UDP_IPV6) {
5130 hashen |= F_FW_RSS_VI_CONFIG_CMD_UDPEN |
5131 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
5133 if (hashconfig & RSS_HASHTYPE_RSS_TCP_IPV4)
5134 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
5135 if (hashconfig & RSS_HASHTYPE_RSS_TCP_IPV6)
5136 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
5141 /* Translates hardware hash types to kernel. */
5143 hashen_to_hashconfig(int hashen)
5147 if (hashen & F_FW_RSS_VI_CONFIG_CMD_UDPEN) {
5149 * If UDP hashing was enabled it must have been enabled for
5150 * either IPv4 or IPv6 (inclusive or). Enabling UDP without
5151 * enabling any 4-tuple hash is nonsense configuration.
5153 MPASS(hashen & (F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN |
5154 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN));
5156 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN)
5157 hashconfig |= RSS_HASHTYPE_RSS_UDP_IPV4;
5158 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN)
5159 hashconfig |= RSS_HASHTYPE_RSS_UDP_IPV6;
5161 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN)
5162 hashconfig |= RSS_HASHTYPE_RSS_TCP_IPV4;
5163 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN)
5164 hashconfig |= RSS_HASHTYPE_RSS_TCP_IPV6;
5165 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN)
5166 hashconfig |= RSS_HASHTYPE_RSS_IPV4;
5167 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN)
5168 hashconfig |= RSS_HASHTYPE_RSS_IPV6;
5170 return (hashconfig);
5175 vi_full_init(struct vi_info *vi)
5177 struct adapter *sc = vi->pi->adapter;
5178 struct ifnet *ifp = vi->ifp;
5180 struct sge_rxq *rxq;
5181 int rc, i, j, hashen;
5183 int nbuckets = rss_getnumbuckets();
5184 int hashconfig = rss_gethashconfig();
5188 ASSERT_SYNCHRONIZED_OP(sc);
5189 KASSERT((vi->flags & VI_INIT_DONE) == 0,
5190 ("%s: VI_INIT_DONE already", __func__));
5192 sysctl_ctx_init(&vi->ctx);
5193 vi->flags |= VI_SYSCTL_CTX;
5196 * Allocate tx/rx/fl queues for this VI.
5198 rc = t4_setup_vi_queues(vi);
5200 goto done; /* error message displayed already */
5203 * Setup RSS for this VI. Save a copy of the RSS table for later use.
5205 if (vi->nrxq > vi->rss_size) {
5206 if_printf(ifp, "nrxq (%d) > hw RSS table size (%d); "
5207 "some queues will never receive traffic.\n", vi->nrxq,
5209 } else if (vi->rss_size % vi->nrxq) {
5210 if_printf(ifp, "nrxq (%d), hw RSS table size (%d); "
5211 "expect uneven traffic distribution.\n", vi->nrxq,
5215 if (vi->nrxq != nbuckets) {
5216 if_printf(ifp, "nrxq (%d) != kernel RSS buckets (%d);"
5217 "performance will be impacted.\n", vi->nrxq, nbuckets);
5220 rss = malloc(vi->rss_size * sizeof (*rss), M_CXGBE, M_ZERO | M_WAITOK);
5221 for (i = 0; i < vi->rss_size;) {
5223 j = rss_get_indirection_to_bucket(i);
5225 rxq = &sc->sge.rxq[vi->first_rxq + j];
5226 rss[i++] = rxq->iq.abs_id;
5228 for_each_rxq(vi, j, rxq) {
5229 rss[i++] = rxq->iq.abs_id;
5230 if (i == vi->rss_size)
5236 rc = -t4_config_rss_range(sc, sc->mbox, vi->viid, 0, vi->rss_size, rss,
5240 if_printf(ifp, "rss_config failed: %d\n", rc);
5245 hashen = hashconfig_to_hashen(hashconfig);
5248 * We may have had to enable some hashes even though the global config
5249 * wants them disabled. This is a potential problem that must be
5250 * reported to the user.
5252 extra = hashen_to_hashconfig(hashen) ^ hashconfig;
5255 * If we consider only the supported hash types, then the enabled hashes
5256 * are a superset of the requested hashes. In other words, there cannot
5257 * be any supported hash that was requested but not enabled, but there
5258 * can be hashes that were not requested but had to be enabled.
5260 extra &= SUPPORTED_RSS_HASHTYPES;
5261 MPASS((extra & hashconfig) == 0);
5265 "global RSS config (0x%x) cannot be accommodated.\n",
5268 if (extra & RSS_HASHTYPE_RSS_IPV4)
5269 if_printf(ifp, "IPv4 2-tuple hashing forced on.\n");
5270 if (extra & RSS_HASHTYPE_RSS_TCP_IPV4)
5271 if_printf(ifp, "TCP/IPv4 4-tuple hashing forced on.\n");
5272 if (extra & RSS_HASHTYPE_RSS_IPV6)
5273 if_printf(ifp, "IPv6 2-tuple hashing forced on.\n");
5274 if (extra & RSS_HASHTYPE_RSS_TCP_IPV6)
5275 if_printf(ifp, "TCP/IPv6 4-tuple hashing forced on.\n");
5276 if (extra & RSS_HASHTYPE_RSS_UDP_IPV4)
5277 if_printf(ifp, "UDP/IPv4 4-tuple hashing forced on.\n");
5278 if (extra & RSS_HASHTYPE_RSS_UDP_IPV6)
5279 if_printf(ifp, "UDP/IPv6 4-tuple hashing forced on.\n");
5281 hashen = F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN |
5282 F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN |
5283 F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN |
5284 F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN | F_FW_RSS_VI_CONFIG_CMD_UDPEN;
5286 rc = -t4_config_vi_rss(sc, sc->mbox, vi->viid, hashen, rss[0], 0, 0);
5289 if_printf(ifp, "rss hash/defaultq config failed: %d\n", rc);
5294 vi->flags |= VI_INIT_DONE;
5306 vi_full_uninit(struct vi_info *vi)
5308 struct port_info *pi = vi->pi;
5309 struct adapter *sc = pi->adapter;
5311 struct sge_rxq *rxq;
5312 struct sge_txq *txq;
5314 struct sge_ofld_rxq *ofld_rxq;
5315 struct sge_wrq *ofld_txq;
5318 if (vi->flags & VI_INIT_DONE) {
5320 /* Need to quiesce queues. */
5322 /* XXX: Only for the first VI? */
5323 if (IS_MAIN_VI(vi) && !(sc->flags & IS_VF))
5324 quiesce_wrq(sc, &sc->sge.ctrlq[pi->port_id]);
5326 for_each_txq(vi, i, txq) {
5327 quiesce_txq(sc, txq);
5331 for_each_ofld_txq(vi, i, ofld_txq) {
5332 quiesce_wrq(sc, ofld_txq);
5336 for_each_rxq(vi, i, rxq) {
5337 quiesce_iq(sc, &rxq->iq);
5338 quiesce_fl(sc, &rxq->fl);
5342 for_each_ofld_rxq(vi, i, ofld_rxq) {
5343 quiesce_iq(sc, &ofld_rxq->iq);
5344 quiesce_fl(sc, &ofld_rxq->fl);
5347 free(vi->rss, M_CXGBE);
5348 free(vi->nm_rss, M_CXGBE);
5351 t4_teardown_vi_queues(vi);
5352 vi->flags &= ~VI_INIT_DONE;
5358 quiesce_txq(struct adapter *sc, struct sge_txq *txq)
5360 struct sge_eq *eq = &txq->eq;
5361 struct sge_qstat *spg = (void *)&eq->desc[eq->sidx];
5363 (void) sc; /* unused */
5367 MPASS((eq->flags & EQ_ENABLED) == 0);
5371 /* Wait for the mp_ring to empty. */
5372 while (!mp_ring_is_idle(txq->r)) {
5373 mp_ring_check_drainage(txq->r, 0);
5374 pause("rquiesce", 1);
5377 /* Then wait for the hardware to finish. */
5378 while (spg->cidx != htobe16(eq->pidx))
5379 pause("equiesce", 1);
5381 /* Finally, wait for the driver to reclaim all descriptors. */
5382 while (eq->cidx != eq->pidx)
5383 pause("dquiesce", 1);
5387 quiesce_wrq(struct adapter *sc, struct sge_wrq *wrq)
5394 quiesce_iq(struct adapter *sc, struct sge_iq *iq)
5396 (void) sc; /* unused */
5398 /* Synchronize with the interrupt handler */
5399 while (!atomic_cmpset_int(&iq->state, IQS_IDLE, IQS_DISABLED))
5404 quiesce_fl(struct adapter *sc, struct sge_fl *fl)
5406 mtx_lock(&sc->sfl_lock);
5408 fl->flags |= FL_DOOMED;
5410 callout_stop(&sc->sfl_callout);
5411 mtx_unlock(&sc->sfl_lock);
5413 KASSERT((fl->flags & FL_STARVING) == 0,
5414 ("%s: still starving", __func__));
5418 t4_alloc_irq(struct adapter *sc, struct irq *irq, int rid,
5419 driver_intr_t *handler, void *arg, char *name)
5424 irq->res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &irq->rid,
5425 RF_SHAREABLE | RF_ACTIVE);
5426 if (irq->res == NULL) {
5427 device_printf(sc->dev,
5428 "failed to allocate IRQ for rid %d, name %s.\n", rid, name);
5432 rc = bus_setup_intr(sc->dev, irq->res, INTR_MPSAFE | INTR_TYPE_NET,
5433 NULL, handler, arg, &irq->tag);
5435 device_printf(sc->dev,
5436 "failed to setup interrupt for rid %d, name %s: %d\n",
5439 bus_describe_intr(sc->dev, irq->res, irq->tag, "%s", name);
5445 t4_free_irq(struct adapter *sc, struct irq *irq)
5448 bus_teardown_intr(sc->dev, irq->res, irq->tag);
5450 bus_release_resource(sc->dev, SYS_RES_IRQ, irq->rid, irq->res);
5452 bzero(irq, sizeof(*irq));
5458 get_regs(struct adapter *sc, struct t4_regdump *regs, uint8_t *buf)
5461 regs->version = chip_id(sc) | chip_rev(sc) << 10;
5462 t4_get_regs(sc, buf, regs->len);
5465 #define A_PL_INDIR_CMD 0x1f8
5467 #define S_PL_AUTOINC 31
5468 #define M_PL_AUTOINC 0x1U
5469 #define V_PL_AUTOINC(x) ((x) << S_PL_AUTOINC)
5470 #define G_PL_AUTOINC(x) (((x) >> S_PL_AUTOINC) & M_PL_AUTOINC)
5472 #define S_PL_VFID 20
5473 #define M_PL_VFID 0xffU
5474 #define V_PL_VFID(x) ((x) << S_PL_VFID)
5475 #define G_PL_VFID(x) (((x) >> S_PL_VFID) & M_PL_VFID)
5478 #define M_PL_ADDR 0xfffffU
5479 #define V_PL_ADDR(x) ((x) << S_PL_ADDR)
5480 #define G_PL_ADDR(x) (((x) >> S_PL_ADDR) & M_PL_ADDR)
5482 #define A_PL_INDIR_DATA 0x1fc
5485 read_vf_stat(struct adapter *sc, unsigned int viid, int reg)
5489 mtx_assert(&sc->reg_lock, MA_OWNED);
5490 if (sc->flags & IS_VF) {
5491 stats[0] = t4_read_reg(sc, VF_MPS_REG(reg));
5492 stats[1] = t4_read_reg(sc, VF_MPS_REG(reg + 4));
5494 t4_write_reg(sc, A_PL_INDIR_CMD, V_PL_AUTOINC(1) |
5495 V_PL_VFID(G_FW_VIID_VIN(viid)) |
5496 V_PL_ADDR(VF_MPS_REG(reg)));
5497 stats[0] = t4_read_reg(sc, A_PL_INDIR_DATA);
5498 stats[1] = t4_read_reg(sc, A_PL_INDIR_DATA);
5500 return (((uint64_t)stats[1]) << 32 | stats[0]);
5504 t4_get_vi_stats(struct adapter *sc, unsigned int viid,
5505 struct fw_vi_stats_vf *stats)
5508 #define GET_STAT(name) \
5509 read_vf_stat(sc, viid, A_MPS_VF_STAT_##name##_L)
5511 stats->tx_bcast_bytes = GET_STAT(TX_VF_BCAST_BYTES);
5512 stats->tx_bcast_frames = GET_STAT(TX_VF_BCAST_FRAMES);
5513 stats->tx_mcast_bytes = GET_STAT(TX_VF_MCAST_BYTES);
5514 stats->tx_mcast_frames = GET_STAT(TX_VF_MCAST_FRAMES);
5515 stats->tx_ucast_bytes = GET_STAT(TX_VF_UCAST_BYTES);
5516 stats->tx_ucast_frames = GET_STAT(TX_VF_UCAST_FRAMES);
5517 stats->tx_drop_frames = GET_STAT(TX_VF_DROP_FRAMES);
5518 stats->tx_offload_bytes = GET_STAT(TX_VF_OFFLOAD_BYTES);
5519 stats->tx_offload_frames = GET_STAT(TX_VF_OFFLOAD_FRAMES);
5520 stats->rx_bcast_bytes = GET_STAT(RX_VF_BCAST_BYTES);
5521 stats->rx_bcast_frames = GET_STAT(RX_VF_BCAST_FRAMES);
5522 stats->rx_mcast_bytes = GET_STAT(RX_VF_MCAST_BYTES);
5523 stats->rx_mcast_frames = GET_STAT(RX_VF_MCAST_FRAMES);
5524 stats->rx_ucast_bytes = GET_STAT(RX_VF_UCAST_BYTES);
5525 stats->rx_ucast_frames = GET_STAT(RX_VF_UCAST_FRAMES);
5526 stats->rx_err_frames = GET_STAT(RX_VF_ERR_FRAMES);
5532 t4_clr_vi_stats(struct adapter *sc, unsigned int viid)
5536 t4_write_reg(sc, A_PL_INDIR_CMD, V_PL_AUTOINC(1) |
5537 V_PL_VFID(G_FW_VIID_VIN(viid)) |
5538 V_PL_ADDR(VF_MPS_REG(A_MPS_VF_STAT_TX_VF_BCAST_BYTES_L)));
5539 for (reg = A_MPS_VF_STAT_TX_VF_BCAST_BYTES_L;
5540 reg <= A_MPS_VF_STAT_RX_VF_ERR_FRAMES_H; reg += 4)
5541 t4_write_reg(sc, A_PL_INDIR_DATA, 0);
5545 vi_refresh_stats(struct adapter *sc, struct vi_info *vi)
5548 const struct timeval interval = {0, 250000}; /* 250ms */
5550 if (!(vi->flags & VI_INIT_DONE))
5554 timevalsub(&tv, &interval);
5555 if (timevalcmp(&tv, &vi->last_refreshed, <))
5558 mtx_lock(&sc->reg_lock);
5559 t4_get_vi_stats(sc, vi->viid, &vi->stats);
5560 getmicrotime(&vi->last_refreshed);
5561 mtx_unlock(&sc->reg_lock);
5565 cxgbe_refresh_stats(struct adapter *sc, struct port_info *pi)
5567 u_int i, v, tnl_cong_drops, bg_map;
5569 const struct timeval interval = {0, 250000}; /* 250ms */
5572 timevalsub(&tv, &interval);
5573 if (timevalcmp(&tv, &pi->last_refreshed, <))
5577 t4_get_port_stats(sc, pi->tx_chan, &pi->stats);
5578 bg_map = pi->mps_bg_map;
5580 i = ffs(bg_map) - 1;
5581 mtx_lock(&sc->reg_lock);
5582 t4_read_indirect(sc, A_TP_MIB_INDEX, A_TP_MIB_DATA, &v, 1,
5583 A_TP_MIB_TNL_CNG_DROP_0 + i);
5584 mtx_unlock(&sc->reg_lock);
5585 tnl_cong_drops += v;
5586 bg_map &= ~(1 << i);
5588 pi->tnl_cong_drops = tnl_cong_drops;
5589 getmicrotime(&pi->last_refreshed);
5593 cxgbe_tick(void *arg)
5595 struct port_info *pi = arg;
5596 struct adapter *sc = pi->adapter;
5598 PORT_LOCK_ASSERT_OWNED(pi);
5599 cxgbe_refresh_stats(sc, pi);
5601 callout_schedule(&pi->tick, hz);
5607 struct vi_info *vi = arg;
5608 struct adapter *sc = vi->pi->adapter;
5610 vi_refresh_stats(sc, vi);
5612 callout_schedule(&vi->tick, hz);
5616 * Should match fw_caps_config_<foo> enums in t4fw_interface.h
5618 static char *caps_decoder[] = {
5619 "\20\001IPMI\002NCSI", /* 0: NBM */
5620 "\20\001PPP\002QFC\003DCBX", /* 1: link */
5621 "\20\001INGRESS\002EGRESS", /* 2: switch */
5622 "\20\001NIC\002VM\003IDS\004UM\005UM_ISGL" /* 3: NIC */
5623 "\006HASHFILTER\007ETHOFLD",
5624 "\20\001TOE", /* 4: TOE */
5625 "\20\001RDDP\002RDMAC", /* 5: RDMA */
5626 "\20\001INITIATOR_PDU\002TARGET_PDU" /* 6: iSCSI */
5627 "\003INITIATOR_CNXOFLD\004TARGET_CNXOFLD"
5628 "\005INITIATOR_SSNOFLD\006TARGET_SSNOFLD"
5630 "\010INITIATOR_CMDOFLD\011TARGET_CMDOFLD",
5631 "\20\001LOOKASIDE\002TLSKEYS", /* 7: Crypto */
5632 "\20\001INITIATOR\002TARGET\003CTRL_OFLD" /* 8: FCoE */
5633 "\004PO_INITIATOR\005PO_TARGET",
5637 t4_sysctls(struct adapter *sc)
5639 struct sysctl_ctx_list *ctx;
5640 struct sysctl_oid *oid;
5641 struct sysctl_oid_list *children, *c0;
5642 static char *doorbells = {"\20\1UDB\2WCWR\3UDBWC\4KDB"};
5644 ctx = device_get_sysctl_ctx(sc->dev);
5649 oid = device_get_sysctl_tree(sc->dev);
5650 c0 = children = SYSCTL_CHILDREN(oid);
5652 sc->sc_do_rxcopy = 1;
5653 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "do_rx_copy", CTLFLAG_RW,
5654 &sc->sc_do_rxcopy, 1, "Do RX copy of small frames");
5656 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nports", CTLFLAG_RD, NULL,
5657 sc->params.nports, "# of ports");
5659 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "doorbells",
5660 CTLTYPE_STRING | CTLFLAG_RD, doorbells, (uintptr_t)&sc->doorbells,
5661 sysctl_bitfield_8b, "A", "available doorbells");
5663 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "core_clock", CTLFLAG_RD, NULL,
5664 sc->params.vpd.cclk, "core clock frequency (in KHz)");
5666 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_timers",
5667 CTLTYPE_STRING | CTLFLAG_RD, sc->params.sge.timer_val,
5668 sizeof(sc->params.sge.timer_val), sysctl_int_array, "A",
5669 "interrupt holdoff timer values (us)");
5671 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pkt_counts",
5672 CTLTYPE_STRING | CTLFLAG_RD, sc->params.sge.counter_val,
5673 sizeof(sc->params.sge.counter_val), sysctl_int_array, "A",
5674 "interrupt holdoff packet counter values");
5676 t4_sge_sysctls(sc, ctx, children);
5678 sc->lro_timeout = 100;
5679 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "lro_timeout", CTLFLAG_RW,
5680 &sc->lro_timeout, 0, "lro inactive-flush timeout (in us)");
5682 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "dflags", CTLFLAG_RW,
5683 &sc->debug_flags, 0, "flags to enable runtime debugging");
5685 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "tp_version",
5686 CTLFLAG_RD, sc->tp_version, 0, "TP microcode version");
5688 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "firmware_version",
5689 CTLFLAG_RD, sc->fw_version, 0, "firmware version");
5691 if (sc->flags & IS_VF)
5694 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "hw_revision", CTLFLAG_RD,
5695 NULL, chip_rev(sc), "chip hardware revision");
5697 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "sn",
5698 CTLFLAG_RD, sc->params.vpd.sn, 0, "serial number");
5700 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "pn",
5701 CTLFLAG_RD, sc->params.vpd.pn, 0, "part number");
5703 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "ec",
5704 CTLFLAG_RD, sc->params.vpd.ec, 0, "engineering change");
5706 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "md_version",
5707 CTLFLAG_RD, sc->params.vpd.md, 0, "manufacturing diags version");
5709 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "na",
5710 CTLFLAG_RD, sc->params.vpd.na, 0, "network address");
5712 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "er_version", CTLFLAG_RD,
5713 sc->er_version, 0, "expansion ROM version");
5715 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "bs_version", CTLFLAG_RD,
5716 sc->bs_version, 0, "bootstrap firmware version");
5718 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "scfg_version", CTLFLAG_RD,
5719 NULL, sc->params.scfg_vers, "serial config version");
5721 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "vpd_version", CTLFLAG_RD,
5722 NULL, sc->params.vpd_vers, "VPD version");
5724 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "cf",
5725 CTLFLAG_RD, sc->cfg_file, 0, "configuration file");
5727 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "cfcsum", CTLFLAG_RD, NULL,
5728 sc->cfcsum, "config file checksum");
5730 #define SYSCTL_CAP(name, n, text) \
5731 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, #name, \
5732 CTLTYPE_STRING | CTLFLAG_RD, caps_decoder[n], (uintptr_t)&sc->name, \
5733 sysctl_bitfield_16b, "A", "available " text " capabilities")
5735 SYSCTL_CAP(nbmcaps, 0, "NBM");
5736 SYSCTL_CAP(linkcaps, 1, "link");
5737 SYSCTL_CAP(switchcaps, 2, "switch");
5738 SYSCTL_CAP(niccaps, 3, "NIC");
5739 SYSCTL_CAP(toecaps, 4, "TCP offload");
5740 SYSCTL_CAP(rdmacaps, 5, "RDMA");
5741 SYSCTL_CAP(iscsicaps, 6, "iSCSI");
5742 SYSCTL_CAP(cryptocaps, 7, "crypto");
5743 SYSCTL_CAP(fcoecaps, 8, "FCoE");
5746 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nfilters", CTLFLAG_RD,
5747 NULL, sc->tids.nftids, "number of filters");
5749 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature", CTLTYPE_INT |
5750 CTLFLAG_RD, sc, 0, sysctl_temperature, "I",
5751 "chip temperature (in Celsius)");
5753 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "loadavg", CTLTYPE_STRING |
5754 CTLFLAG_RD, sc, 0, sysctl_loadavg, "A",
5755 "microprocessor load averages (debug firmwares only)");
5757 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "core_vdd", CTLFLAG_RD,
5758 &sc->params.core_vdd, 0, "core Vdd (in mV)");
5760 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "local_cpus",
5761 CTLTYPE_STRING | CTLFLAG_RD, sc, LOCAL_CPUS,
5762 sysctl_cpus, "A", "local CPUs");
5764 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_cpus",
5765 CTLTYPE_STRING | CTLFLAG_RD, sc, INTR_CPUS,
5766 sysctl_cpus, "A", "preferred CPUs for interrupts");
5769 * dev.t4nex.X.misc. Marked CTLFLAG_SKIP to avoid information overload.
5771 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "misc",
5772 CTLFLAG_RD | CTLFLAG_SKIP, NULL,
5773 "logs and miscellaneous information");
5774 children = SYSCTL_CHILDREN(oid);
5776 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cctrl",
5777 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5778 sysctl_cctrl, "A", "congestion control");
5780 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp0",
5781 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5782 sysctl_cim_ibq_obq, "A", "CIM IBQ 0 (TP0)");
5784 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp1",
5785 CTLTYPE_STRING | CTLFLAG_RD, sc, 1,
5786 sysctl_cim_ibq_obq, "A", "CIM IBQ 1 (TP1)");
5788 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ulp",
5789 CTLTYPE_STRING | CTLFLAG_RD, sc, 2,
5790 sysctl_cim_ibq_obq, "A", "CIM IBQ 2 (ULP)");
5792 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge0",
5793 CTLTYPE_STRING | CTLFLAG_RD, sc, 3,
5794 sysctl_cim_ibq_obq, "A", "CIM IBQ 3 (SGE0)");
5796 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge1",
5797 CTLTYPE_STRING | CTLFLAG_RD, sc, 4,
5798 sysctl_cim_ibq_obq, "A", "CIM IBQ 4 (SGE1)");
5800 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ncsi",
5801 CTLTYPE_STRING | CTLFLAG_RD, sc, 5,
5802 sysctl_cim_ibq_obq, "A", "CIM IBQ 5 (NCSI)");
5804 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_la",
5805 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5806 chip_id(sc) <= CHELSIO_T5 ? sysctl_cim_la : sysctl_cim_la_t6,
5807 "A", "CIM logic analyzer");
5809 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ma_la",
5810 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5811 sysctl_cim_ma_la, "A", "CIM MA logic analyzer");
5813 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp0",
5814 CTLTYPE_STRING | CTLFLAG_RD, sc, 0 + CIM_NUM_IBQ,
5815 sysctl_cim_ibq_obq, "A", "CIM OBQ 0 (ULP0)");
5817 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp1",
5818 CTLTYPE_STRING | CTLFLAG_RD, sc, 1 + CIM_NUM_IBQ,
5819 sysctl_cim_ibq_obq, "A", "CIM OBQ 1 (ULP1)");
5821 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp2",
5822 CTLTYPE_STRING | CTLFLAG_RD, sc, 2 + CIM_NUM_IBQ,
5823 sysctl_cim_ibq_obq, "A", "CIM OBQ 2 (ULP2)");
5825 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp3",
5826 CTLTYPE_STRING | CTLFLAG_RD, sc, 3 + CIM_NUM_IBQ,
5827 sysctl_cim_ibq_obq, "A", "CIM OBQ 3 (ULP3)");
5829 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge",
5830 CTLTYPE_STRING | CTLFLAG_RD, sc, 4 + CIM_NUM_IBQ,
5831 sysctl_cim_ibq_obq, "A", "CIM OBQ 4 (SGE)");
5833 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ncsi",
5834 CTLTYPE_STRING | CTLFLAG_RD, sc, 5 + CIM_NUM_IBQ,
5835 sysctl_cim_ibq_obq, "A", "CIM OBQ 5 (NCSI)");
5837 if (chip_id(sc) > CHELSIO_T4) {
5838 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge0_rx",
5839 CTLTYPE_STRING | CTLFLAG_RD, sc, 6 + CIM_NUM_IBQ,
5840 sysctl_cim_ibq_obq, "A", "CIM OBQ 6 (SGE0-RX)");
5842 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge1_rx",
5843 CTLTYPE_STRING | CTLFLAG_RD, sc, 7 + CIM_NUM_IBQ,
5844 sysctl_cim_ibq_obq, "A", "CIM OBQ 7 (SGE1-RX)");
5847 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_pif_la",
5848 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5849 sysctl_cim_pif_la, "A", "CIM PIF logic analyzer");
5851 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_qcfg",
5852 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5853 sysctl_cim_qcfg, "A", "CIM queue configuration");
5855 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cpl_stats",
5856 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5857 sysctl_cpl_stats, "A", "CPL statistics");
5859 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ddp_stats",
5860 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5861 sysctl_ddp_stats, "A", "non-TCP DDP statistics");
5863 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "devlog",
5864 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5865 sysctl_devlog, "A", "firmware's device log");
5867 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fcoe_stats",
5868 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5869 sysctl_fcoe_stats, "A", "FCoE statistics");
5871 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "hw_sched",
5872 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5873 sysctl_hw_sched, "A", "hardware scheduler ");
5875 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "l2t",
5876 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5877 sysctl_l2t, "A", "hardware L2 table");
5879 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "smt",
5880 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5881 sysctl_smt, "A", "hardware source MAC table");
5883 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "lb_stats",
5884 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5885 sysctl_lb_stats, "A", "loopback statistics");
5887 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "meminfo",
5888 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5889 sysctl_meminfo, "A", "memory regions");
5891 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "mps_tcam",
5892 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5893 chip_id(sc) <= CHELSIO_T5 ? sysctl_mps_tcam : sysctl_mps_tcam_t6,
5894 "A", "MPS TCAM entries");
5896 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "path_mtus",
5897 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5898 sysctl_path_mtus, "A", "path MTUs");
5900 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pm_stats",
5901 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5902 sysctl_pm_stats, "A", "PM statistics");
5904 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rdma_stats",
5905 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5906 sysctl_rdma_stats, "A", "RDMA statistics");
5908 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tcp_stats",
5909 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5910 sysctl_tcp_stats, "A", "TCP statistics");
5912 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tids",
5913 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5914 sysctl_tids, "A", "TID information");
5916 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_err_stats",
5917 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5918 sysctl_tp_err_stats, "A", "TP error statistics");
5920 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_la_mask",
5921 CTLTYPE_INT | CTLFLAG_RW, sc, 0, sysctl_tp_la_mask, "I",
5922 "TP logic analyzer event capture mask");
5924 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_la",
5925 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5926 sysctl_tp_la, "A", "TP logic analyzer");
5928 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_rate",
5929 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5930 sysctl_tx_rate, "A", "Tx rate");
5932 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ulprx_la",
5933 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5934 sysctl_ulprx_la, "A", "ULPRX logic analyzer");
5936 if (chip_id(sc) >= CHELSIO_T5) {
5937 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "wcwr_stats",
5938 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5939 sysctl_wcwr_stats, "A", "write combined work requests");
5943 if (is_offload(sc)) {
5950 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "toe", CTLFLAG_RD,
5951 NULL, "TOE parameters");
5952 children = SYSCTL_CHILDREN(oid);
5954 sc->tt.cong_algorithm = -1;
5955 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "cong_algorithm",
5956 CTLFLAG_RW, &sc->tt.cong_algorithm, 0, "congestion control "
5957 "(-1 = default, 0 = reno, 1 = tahoe, 2 = newreno, "
5960 sc->tt.sndbuf = 256 * 1024;
5961 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "sndbuf", CTLFLAG_RW,
5962 &sc->tt.sndbuf, 0, "max hardware send buffer size");
5965 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ddp", CTLFLAG_RW,
5966 &sc->tt.ddp, 0, "DDP allowed");
5968 sc->tt.rx_coalesce = 1;
5969 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_coalesce",
5970 CTLFLAG_RW, &sc->tt.rx_coalesce, 0, "receive coalescing");
5973 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tls", CTLFLAG_RW,
5974 &sc->tt.tls, 0, "Inline TLS allowed");
5976 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tls_rx_ports",
5977 CTLTYPE_INT | CTLFLAG_RW, sc, 0, sysctl_tls_rx_ports,
5978 "I", "TCP ports that use inline TLS+TOE RX");
5980 sc->tt.tx_align = 1;
5981 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_align",
5982 CTLFLAG_RW, &sc->tt.tx_align, 0, "chop and align payload");
5984 sc->tt.tx_zcopy = 0;
5985 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_zcopy",
5986 CTLFLAG_RW, &sc->tt.tx_zcopy, 0,
5987 "Enable zero-copy aio_write(2)");
5989 sc->tt.cop_managed_offloading = !!t4_cop_managed_offloading;
5990 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5991 "cop_managed_offloading", CTLFLAG_RW,
5992 &sc->tt.cop_managed_offloading, 0,
5993 "COP (Connection Offload Policy) controls all TOE offload");
5995 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "timer_tick",
5996 CTLTYPE_STRING | CTLFLAG_RD, sc, 0, sysctl_tp_tick, "A",
5997 "TP timer tick (us)");
5999 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "timestamp_tick",
6000 CTLTYPE_STRING | CTLFLAG_RD, sc, 1, sysctl_tp_tick, "A",
6001 "TCP timestamp tick (us)");
6003 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "dack_tick",
6004 CTLTYPE_STRING | CTLFLAG_RD, sc, 2, sysctl_tp_tick, "A",
6007 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "dack_timer",
6008 CTLTYPE_UINT | CTLFLAG_RD, sc, 0, sysctl_tp_dack_timer,
6009 "IU", "DACK timer (us)");
6011 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_min",
6012 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_RXT_MIN,
6013 sysctl_tp_timer, "LU", "Minimum retransmit interval (us)");
6015 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_max",
6016 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_RXT_MAX,
6017 sysctl_tp_timer, "LU", "Maximum retransmit interval (us)");
6019 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "persist_min",
6020 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_PERS_MIN,
6021 sysctl_tp_timer, "LU", "Persist timer min (us)");
6023 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "persist_max",
6024 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_PERS_MAX,
6025 sysctl_tp_timer, "LU", "Persist timer max (us)");
6027 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_idle",
6028 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_KEEP_IDLE,
6029 sysctl_tp_timer, "LU", "Keepalive idle timer (us)");
6031 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_interval",
6032 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_KEEP_INTVL,
6033 sysctl_tp_timer, "LU", "Keepalive interval timer (us)");
6035 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "initial_srtt",
6036 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_INIT_SRTT,
6037 sysctl_tp_timer, "LU", "Initial SRTT (us)");
6039 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "finwait2_timer",
6040 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_FINWAIT2_TIMER,
6041 sysctl_tp_timer, "LU", "FINWAIT2 timer (us)");
6043 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "syn_rexmt_count",
6044 CTLTYPE_UINT | CTLFLAG_RD, sc, S_SYNSHIFTMAX,
6045 sysctl_tp_shift_cnt, "IU",
6046 "Number of SYN retransmissions before abort");
6048 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_count",
6049 CTLTYPE_UINT | CTLFLAG_RD, sc, S_RXTSHIFTMAXR2,
6050 sysctl_tp_shift_cnt, "IU",
6051 "Number of retransmissions before abort");
6053 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_count",
6054 CTLTYPE_UINT | CTLFLAG_RD, sc, S_KEEPALIVEMAXR2,
6055 sysctl_tp_shift_cnt, "IU",
6056 "Number of keepalive probes before abort");
6058 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "rexmt_backoff",
6059 CTLFLAG_RD, NULL, "TOE retransmit backoffs");
6060 children = SYSCTL_CHILDREN(oid);
6061 for (i = 0; i < 16; i++) {
6062 snprintf(s, sizeof(s), "%u", i);
6063 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, s,
6064 CTLTYPE_UINT | CTLFLAG_RD, sc, i, sysctl_tp_backoff,
6065 "IU", "TOE retransmit backoff");
6072 vi_sysctls(struct vi_info *vi)
6074 struct sysctl_ctx_list *ctx;
6075 struct sysctl_oid *oid;
6076 struct sysctl_oid_list *children;
6078 ctx = device_get_sysctl_ctx(vi->dev);
6081 * dev.v?(cxgbe|cxl).X.
6083 oid = device_get_sysctl_tree(vi->dev);
6084 children = SYSCTL_CHILDREN(oid);
6086 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "viid", CTLFLAG_RD, NULL,
6087 vi->viid, "VI identifer");
6088 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nrxq", CTLFLAG_RD,
6089 &vi->nrxq, 0, "# of rx queues");
6090 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ntxq", CTLFLAG_RD,
6091 &vi->ntxq, 0, "# of tx queues");
6092 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_rxq", CTLFLAG_RD,
6093 &vi->first_rxq, 0, "index of first rx queue");
6094 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_txq", CTLFLAG_RD,
6095 &vi->first_txq, 0, "index of first tx queue");
6096 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "rss_size", CTLFLAG_RD, NULL,
6097 vi->rss_size, "size of RSS indirection table");
6099 if (IS_MAIN_VI(vi)) {
6100 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rsrv_noflowq",
6101 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_noflowq, "IU",
6102 "Reserve queue 0 for non-flowid packets");
6106 if (vi->nofldrxq != 0) {
6107 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldrxq", CTLFLAG_RD,
6109 "# of rx queues for offloaded TCP connections");
6110 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldtxq", CTLFLAG_RD,
6112 "# of tx queues for offloaded TCP connections");
6113 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_rxq",
6114 CTLFLAG_RD, &vi->first_ofld_rxq, 0,
6115 "index of first TOE rx queue");
6116 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_txq",
6117 CTLFLAG_RD, &vi->first_ofld_txq, 0,
6118 "index of first TOE tx queue");
6119 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx_ofld",
6120 CTLTYPE_INT | CTLFLAG_RW, vi, 0,
6121 sysctl_holdoff_tmr_idx_ofld, "I",
6122 "holdoff timer index for TOE queues");
6123 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx_ofld",
6124 CTLTYPE_INT | CTLFLAG_RW, vi, 0,
6125 sysctl_holdoff_pktc_idx_ofld, "I",
6126 "holdoff packet counter index for TOE queues");
6130 if (vi->nnmrxq != 0) {
6131 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmrxq", CTLFLAG_RD,
6132 &vi->nnmrxq, 0, "# of netmap rx queues");
6133 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmtxq", CTLFLAG_RD,
6134 &vi->nnmtxq, 0, "# of netmap tx queues");
6135 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_rxq",
6136 CTLFLAG_RD, &vi->first_nm_rxq, 0,
6137 "index of first netmap rx queue");
6138 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_txq",
6139 CTLFLAG_RD, &vi->first_nm_txq, 0,
6140 "index of first netmap tx queue");
6144 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx",
6145 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_holdoff_tmr_idx, "I",
6146 "holdoff timer index");
6147 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx",
6148 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_holdoff_pktc_idx, "I",
6149 "holdoff packet counter index");
6151 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_rxq",
6152 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_qsize_rxq, "I",
6154 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_txq",
6155 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_qsize_txq, "I",
6160 cxgbe_sysctls(struct port_info *pi)
6162 struct sysctl_ctx_list *ctx;
6163 struct sysctl_oid *oid;
6164 struct sysctl_oid_list *children, *children2;
6165 struct adapter *sc = pi->adapter;
6168 static char *tc_flags = {"\20\1USER\2SYNC\3ASYNC\4ERR"};
6170 ctx = device_get_sysctl_ctx(pi->dev);
6175 oid = device_get_sysctl_tree(pi->dev);
6176 children = SYSCTL_CHILDREN(oid);
6178 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "linkdnrc", CTLTYPE_STRING |
6179 CTLFLAG_RD, pi, 0, sysctl_linkdnrc, "A", "reason why link is down");
6180 if (pi->port_type == FW_PORT_TYPE_BT_XAUI) {
6181 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature",
6182 CTLTYPE_INT | CTLFLAG_RD, pi, 0, sysctl_btphy, "I",
6183 "PHY temperature (in Celsius)");
6184 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fw_version",
6185 CTLTYPE_INT | CTLFLAG_RD, pi, 1, sysctl_btphy, "I",
6186 "PHY firmware version");
6189 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pause_settings",
6190 CTLTYPE_STRING | CTLFLAG_RW, pi, 0, sysctl_pause_settings, "A",
6191 "PAUSE settings (bit 0 = rx_pause, bit 1 = tx_pause)");
6192 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fec",
6193 CTLTYPE_STRING | CTLFLAG_RW, pi, 0, sysctl_fec, "A",
6194 "Forward Error Correction (bit 0 = RS, bit 1 = BASER_RS)");
6195 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "autoneg",
6196 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_autoneg, "I",
6197 "autonegotiation (-1 = not supported)");
6199 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "max_speed", CTLFLAG_RD, NULL,
6200 port_top_speed(pi), "max speed (in Gbps)");
6201 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "mps_bg_map", CTLFLAG_RD, NULL,
6202 pi->mps_bg_map, "MPS buffer group map");
6203 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_e_chan_map", CTLFLAG_RD,
6204 NULL, pi->rx_e_chan_map, "TP rx e-channel map");
6206 if (sc->flags & IS_VF)
6210 * dev.(cxgbe|cxl).X.tc.
6212 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "tc", CTLFLAG_RD, NULL,
6213 "Tx scheduler traffic classes (cl_rl)");
6214 children2 = SYSCTL_CHILDREN(oid);
6215 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "pktsize",
6216 CTLFLAG_RW, &pi->sched_params->pktsize, 0,
6217 "pktsize for per-flow cl-rl (0 means up to the driver )");
6218 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "burstsize",
6219 CTLFLAG_RW, &pi->sched_params->burstsize, 0,
6220 "burstsize for per-flow cl-rl (0 means up to the driver)");
6221 for (i = 0; i < sc->chip_params->nsched_cls; i++) {
6222 struct tx_cl_rl_params *tc = &pi->sched_params->cl_rl[i];
6224 snprintf(name, sizeof(name), "%d", i);
6225 children2 = SYSCTL_CHILDREN(SYSCTL_ADD_NODE(ctx,
6226 SYSCTL_CHILDREN(oid), OID_AUTO, name, CTLFLAG_RD, NULL,
6228 SYSCTL_ADD_PROC(ctx, children2, OID_AUTO, "flags",
6229 CTLTYPE_STRING | CTLFLAG_RD, tc_flags, (uintptr_t)&tc->flags,
6230 sysctl_bitfield_8b, "A", "flags");
6231 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "refcount",
6232 CTLFLAG_RD, &tc->refcount, 0, "references to this class");
6233 SYSCTL_ADD_PROC(ctx, children2, OID_AUTO, "params",
6234 CTLTYPE_STRING | CTLFLAG_RD, sc, (pi->port_id << 16) | i,
6235 sysctl_tc_params, "A", "traffic class parameters");
6239 * dev.cxgbe.X.stats.
6241 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats", CTLFLAG_RD,
6242 NULL, "port statistics");
6243 children = SYSCTL_CHILDREN(oid);
6244 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "tx_parse_error", CTLFLAG_RD,
6245 &pi->tx_parse_error, 0,
6246 "# of tx packets with invalid length or # of segments");
6248 #define SYSCTL_ADD_T4_REG64(pi, name, desc, reg) \
6249 SYSCTL_ADD_OID(ctx, children, OID_AUTO, name, \
6250 CTLTYPE_U64 | CTLFLAG_RD, sc, reg, \
6251 sysctl_handle_t4_reg64, "QU", desc)
6253 SYSCTL_ADD_T4_REG64(pi, "tx_octets", "# of octets in good frames",
6254 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BYTES_L));
6255 SYSCTL_ADD_T4_REG64(pi, "tx_frames", "total # of good frames",
6256 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_FRAMES_L));
6257 SYSCTL_ADD_T4_REG64(pi, "tx_bcast_frames", "# of broadcast frames",
6258 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BCAST_L));
6259 SYSCTL_ADD_T4_REG64(pi, "tx_mcast_frames", "# of multicast frames",
6260 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_MCAST_L));
6261 SYSCTL_ADD_T4_REG64(pi, "tx_ucast_frames", "# of unicast frames",
6262 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_UCAST_L));
6263 SYSCTL_ADD_T4_REG64(pi, "tx_error_frames", "# of error frames",
6264 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_ERROR_L));
6265 SYSCTL_ADD_T4_REG64(pi, "tx_frames_64",
6266 "# of tx frames in this range",
6267 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_64B_L));
6268 SYSCTL_ADD_T4_REG64(pi, "tx_frames_65_127",
6269 "# of tx frames in this range",
6270 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_65B_127B_L));
6271 SYSCTL_ADD_T4_REG64(pi, "tx_frames_128_255",
6272 "# of tx frames in this range",
6273 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_128B_255B_L));
6274 SYSCTL_ADD_T4_REG64(pi, "tx_frames_256_511",
6275 "# of tx frames in this range",
6276 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_256B_511B_L));
6277 SYSCTL_ADD_T4_REG64(pi, "tx_frames_512_1023",
6278 "# of tx frames in this range",
6279 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_512B_1023B_L));
6280 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1024_1518",
6281 "# of tx frames in this range",
6282 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1024B_1518B_L));
6283 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1519_max",
6284 "# of tx frames in this range",
6285 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1519B_MAX_L));
6286 SYSCTL_ADD_T4_REG64(pi, "tx_drop", "# of dropped tx frames",
6287 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_DROP_L));
6288 SYSCTL_ADD_T4_REG64(pi, "tx_pause", "# of pause frames transmitted",
6289 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PAUSE_L));
6290 SYSCTL_ADD_T4_REG64(pi, "tx_ppp0", "# of PPP prio 0 frames transmitted",
6291 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP0_L));
6292 SYSCTL_ADD_T4_REG64(pi, "tx_ppp1", "# of PPP prio 1 frames transmitted",
6293 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP1_L));
6294 SYSCTL_ADD_T4_REG64(pi, "tx_ppp2", "# of PPP prio 2 frames transmitted",
6295 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP2_L));
6296 SYSCTL_ADD_T4_REG64(pi, "tx_ppp3", "# of PPP prio 3 frames transmitted",
6297 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP3_L));
6298 SYSCTL_ADD_T4_REG64(pi, "tx_ppp4", "# of PPP prio 4 frames transmitted",
6299 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP4_L));
6300 SYSCTL_ADD_T4_REG64(pi, "tx_ppp5", "# of PPP prio 5 frames transmitted",
6301 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP5_L));
6302 SYSCTL_ADD_T4_REG64(pi, "tx_ppp6", "# of PPP prio 6 frames transmitted",
6303 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP6_L));
6304 SYSCTL_ADD_T4_REG64(pi, "tx_ppp7", "# of PPP prio 7 frames transmitted",
6305 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP7_L));
6307 SYSCTL_ADD_T4_REG64(pi, "rx_octets", "# of octets in good frames",
6308 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BYTES_L));
6309 SYSCTL_ADD_T4_REG64(pi, "rx_frames", "total # of good frames",
6310 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_FRAMES_L));
6311 SYSCTL_ADD_T4_REG64(pi, "rx_bcast_frames", "# of broadcast frames",
6312 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BCAST_L));
6313 SYSCTL_ADD_T4_REG64(pi, "rx_mcast_frames", "# of multicast frames",
6314 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MCAST_L));
6315 SYSCTL_ADD_T4_REG64(pi, "rx_ucast_frames", "# of unicast frames",
6316 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_UCAST_L));
6317 SYSCTL_ADD_T4_REG64(pi, "rx_too_long", "# of frames exceeding MTU",
6318 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_ERROR_L));
6319 SYSCTL_ADD_T4_REG64(pi, "rx_jabber", "# of jabber frames",
6320 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_CRC_ERROR_L));
6321 SYSCTL_ADD_T4_REG64(pi, "rx_fcs_err",
6322 "# of frames received with bad FCS",
6323 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_CRC_ERROR_L));
6324 SYSCTL_ADD_T4_REG64(pi, "rx_len_err",
6325 "# of frames received with length error",
6326 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LEN_ERROR_L));
6327 SYSCTL_ADD_T4_REG64(pi, "rx_symbol_err", "symbol errors",
6328 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_SYM_ERROR_L));
6329 SYSCTL_ADD_T4_REG64(pi, "rx_runt", "# of short frames received",
6330 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LESS_64B_L));
6331 SYSCTL_ADD_T4_REG64(pi, "rx_frames_64",
6332 "# of rx frames in this range",
6333 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_64B_L));
6334 SYSCTL_ADD_T4_REG64(pi, "rx_frames_65_127",
6335 "# of rx frames in this range",
6336 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_65B_127B_L));
6337 SYSCTL_ADD_T4_REG64(pi, "rx_frames_128_255",
6338 "# of rx frames in this range",
6339 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_128B_255B_L));
6340 SYSCTL_ADD_T4_REG64(pi, "rx_frames_256_511",
6341 "# of rx frames in this range",
6342 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_256B_511B_L));
6343 SYSCTL_ADD_T4_REG64(pi, "rx_frames_512_1023",
6344 "# of rx frames in this range",
6345 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_512B_1023B_L));
6346 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1024_1518",
6347 "# of rx frames in this range",
6348 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1024B_1518B_L));
6349 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1519_max",
6350 "# of rx frames in this range",
6351 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1519B_MAX_L));
6352 SYSCTL_ADD_T4_REG64(pi, "rx_pause", "# of pause frames received",
6353 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PAUSE_L));
6354 SYSCTL_ADD_T4_REG64(pi, "rx_ppp0", "# of PPP prio 0 frames received",
6355 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP0_L));
6356 SYSCTL_ADD_T4_REG64(pi, "rx_ppp1", "# of PPP prio 1 frames received",
6357 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP1_L));
6358 SYSCTL_ADD_T4_REG64(pi, "rx_ppp2", "# of PPP prio 2 frames received",
6359 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP2_L));
6360 SYSCTL_ADD_T4_REG64(pi, "rx_ppp3", "# of PPP prio 3 frames received",
6361 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP3_L));
6362 SYSCTL_ADD_T4_REG64(pi, "rx_ppp4", "# of PPP prio 4 frames received",
6363 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP4_L));
6364 SYSCTL_ADD_T4_REG64(pi, "rx_ppp5", "# of PPP prio 5 frames received",
6365 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP5_L));
6366 SYSCTL_ADD_T4_REG64(pi, "rx_ppp6", "# of PPP prio 6 frames received",
6367 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP6_L));
6368 SYSCTL_ADD_T4_REG64(pi, "rx_ppp7", "# of PPP prio 7 frames received",
6369 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP7_L));
6371 #undef SYSCTL_ADD_T4_REG64
6373 #define SYSCTL_ADD_T4_PORTSTAT(name, desc) \
6374 SYSCTL_ADD_UQUAD(ctx, children, OID_AUTO, #name, CTLFLAG_RD, \
6375 &pi->stats.name, desc)
6377 /* We get these from port_stats and they may be stale by up to 1s */
6378 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow0,
6379 "# drops due to buffer-group 0 overflows");
6380 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow1,
6381 "# drops due to buffer-group 1 overflows");
6382 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow2,
6383 "# drops due to buffer-group 2 overflows");
6384 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow3,
6385 "# drops due to buffer-group 3 overflows");
6386 SYSCTL_ADD_T4_PORTSTAT(rx_trunc0,
6387 "# of buffer-group 0 truncated packets");
6388 SYSCTL_ADD_T4_PORTSTAT(rx_trunc1,
6389 "# of buffer-group 1 truncated packets");
6390 SYSCTL_ADD_T4_PORTSTAT(rx_trunc2,
6391 "# of buffer-group 2 truncated packets");
6392 SYSCTL_ADD_T4_PORTSTAT(rx_trunc3,
6393 "# of buffer-group 3 truncated packets");
6395 #undef SYSCTL_ADD_T4_PORTSTAT
6397 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "tx_tls_records",
6398 CTLFLAG_RD, &pi->tx_tls_records,
6399 "# of TLS records transmitted");
6400 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "tx_tls_octets",
6401 CTLFLAG_RD, &pi->tx_tls_octets,
6402 "# of payload octets in transmitted TLS records");
6403 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "rx_tls_records",
6404 CTLFLAG_RD, &pi->rx_tls_records,
6405 "# of TLS records received");
6406 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "rx_tls_octets",
6407 CTLFLAG_RD, &pi->rx_tls_octets,
6408 "# of payload octets in received TLS records");
6412 sysctl_int_array(SYSCTL_HANDLER_ARGS)
6414 int rc, *i, space = 0;
6417 sbuf_new_for_sysctl(&sb, NULL, 64, req);
6418 for (i = arg1; arg2; arg2 -= sizeof(int), i++) {
6420 sbuf_printf(&sb, " ");
6421 sbuf_printf(&sb, "%d", *i);
6424 rc = sbuf_finish(&sb);
6430 sysctl_bitfield_8b(SYSCTL_HANDLER_ARGS)
6435 rc = sysctl_wire_old_buffer(req, 0);
6439 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
6443 sbuf_printf(sb, "%b", *(uint8_t *)(uintptr_t)arg2, (char *)arg1);
6444 rc = sbuf_finish(sb);
6451 sysctl_bitfield_16b(SYSCTL_HANDLER_ARGS)
6456 rc = sysctl_wire_old_buffer(req, 0);
6460 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
6464 sbuf_printf(sb, "%b", *(uint16_t *)(uintptr_t)arg2, (char *)arg1);
6465 rc = sbuf_finish(sb);
6472 sysctl_btphy(SYSCTL_HANDLER_ARGS)
6474 struct port_info *pi = arg1;
6476 struct adapter *sc = pi->adapter;
6480 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK, "t4btt");
6483 /* XXX: magic numbers */
6484 rc = -t4_mdio_rd(sc, sc->mbox, pi->mdio_addr, 0x1e, op ? 0x20 : 0xc820,
6486 end_synchronized_op(sc, 0);
6492 rc = sysctl_handle_int(oidp, &v, 0, req);
6497 sysctl_noflowq(SYSCTL_HANDLER_ARGS)
6499 struct vi_info *vi = arg1;
6502 val = vi->rsrv_noflowq;
6503 rc = sysctl_handle_int(oidp, &val, 0, req);
6504 if (rc != 0 || req->newptr == NULL)
6507 if ((val >= 1) && (vi->ntxq > 1))
6508 vi->rsrv_noflowq = 1;
6510 vi->rsrv_noflowq = 0;
6516 sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS)
6518 struct vi_info *vi = arg1;
6519 struct adapter *sc = vi->pi->adapter;
6521 struct sge_rxq *rxq;
6526 rc = sysctl_handle_int(oidp, &idx, 0, req);
6527 if (rc != 0 || req->newptr == NULL)
6530 if (idx < 0 || idx >= SGE_NTIMERS)
6533 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
6538 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(vi->pktc_idx != -1);
6539 for_each_rxq(vi, i, rxq) {
6540 #ifdef atomic_store_rel_8
6541 atomic_store_rel_8(&rxq->iq.intr_params, v);
6543 rxq->iq.intr_params = v;
6548 end_synchronized_op(sc, LOCK_HELD);
6553 sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS)
6555 struct vi_info *vi = arg1;
6556 struct adapter *sc = vi->pi->adapter;
6561 rc = sysctl_handle_int(oidp, &idx, 0, req);
6562 if (rc != 0 || req->newptr == NULL)
6565 if (idx < -1 || idx >= SGE_NCOUNTERS)
6568 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
6573 if (vi->flags & VI_INIT_DONE)
6574 rc = EBUSY; /* cannot be changed once the queues are created */
6578 end_synchronized_op(sc, LOCK_HELD);
6583 sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS)
6585 struct vi_info *vi = arg1;
6586 struct adapter *sc = vi->pi->adapter;
6589 qsize = vi->qsize_rxq;
6591 rc = sysctl_handle_int(oidp, &qsize, 0, req);
6592 if (rc != 0 || req->newptr == NULL)
6595 if (qsize < 128 || (qsize & 7))
6598 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
6603 if (vi->flags & VI_INIT_DONE)
6604 rc = EBUSY; /* cannot be changed once the queues are created */
6606 vi->qsize_rxq = qsize;
6608 end_synchronized_op(sc, LOCK_HELD);
6613 sysctl_qsize_txq(SYSCTL_HANDLER_ARGS)
6615 struct vi_info *vi = arg1;
6616 struct adapter *sc = vi->pi->adapter;
6619 qsize = vi->qsize_txq;
6621 rc = sysctl_handle_int(oidp, &qsize, 0, req);
6622 if (rc != 0 || req->newptr == NULL)
6625 if (qsize < 128 || qsize > 65536)
6628 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
6633 if (vi->flags & VI_INIT_DONE)
6634 rc = EBUSY; /* cannot be changed once the queues are created */
6636 vi->qsize_txq = qsize;
6638 end_synchronized_op(sc, LOCK_HELD);
6643 sysctl_pause_settings(SYSCTL_HANDLER_ARGS)
6645 struct port_info *pi = arg1;
6646 struct adapter *sc = pi->adapter;
6647 struct link_config *lc = &pi->link_cfg;
6650 if (req->newptr == NULL) {
6652 static char *bits = "\20\1RX\2TX\3AUTO";
6654 rc = sysctl_wire_old_buffer(req, 0);
6658 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
6663 sbuf_printf(sb, "%b", (lc->fc & (PAUSE_TX | PAUSE_RX)) |
6664 (lc->requested_fc & PAUSE_AUTONEG), bits);
6666 sbuf_printf(sb, "%b", lc->requested_fc & (PAUSE_TX |
6667 PAUSE_RX | PAUSE_AUTONEG), bits);
6669 rc = sbuf_finish(sb);
6675 s[0] = '0' + (lc->requested_fc & (PAUSE_TX | PAUSE_RX |
6679 rc = sysctl_handle_string(oidp, s, sizeof(s), req);
6685 if (s[0] < '0' || s[0] > '9')
6686 return (EINVAL); /* not a number */
6688 if (n & ~(PAUSE_TX | PAUSE_RX | PAUSE_AUTONEG))
6689 return (EINVAL); /* some other bit is set too */
6691 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK,
6696 lc->requested_fc = n;
6697 fixup_link_config(pi);
6699 rc = apply_link_config(pi);
6700 set_current_media(pi);
6702 end_synchronized_op(sc, 0);
6709 sysctl_fec(SYSCTL_HANDLER_ARGS)
6711 struct port_info *pi = arg1;
6712 struct adapter *sc = pi->adapter;
6713 struct link_config *lc = &pi->link_cfg;
6717 if (req->newptr == NULL) {
6719 static char *bits = "\20\1RS\2BASE-R\3RSVD1\4RSVD2\5RSVD3\6AUTO";
6721 rc = sysctl_wire_old_buffer(req, 0);
6725 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
6730 * Display the requested_fec when the link is down -- the actual
6731 * FEC makes sense only when the link is up.
6734 sbuf_printf(sb, "%b", (lc->fec & M_FW_PORT_CAP32_FEC) |
6735 (lc->requested_fec & FEC_AUTO), bits);
6737 sbuf_printf(sb, "%b", lc->requested_fec, bits);
6739 rc = sbuf_finish(sb);
6745 snprintf(s, sizeof(s), "%d",
6746 lc->requested_fec == FEC_AUTO ? -1 :
6747 lc->requested_fec & M_FW_PORT_CAP32_FEC);
6749 rc = sysctl_handle_string(oidp, s, sizeof(s), req);
6753 n = strtol(&s[0], NULL, 0);
6754 if (n < 0 || n & FEC_AUTO)
6757 if (n & ~M_FW_PORT_CAP32_FEC)
6758 return (EINVAL);/* some other bit is set too */
6760 return (EINVAL);/* one bit can be set at most */
6763 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK,
6768 old = lc->requested_fec;
6770 lc->requested_fec = FEC_AUTO;
6772 lc->requested_fec = FEC_NONE;
6774 if ((lc->supported | V_FW_PORT_CAP32_FEC(n)) !=
6779 lc->requested_fec = n;
6781 fixup_link_config(pi);
6782 if (pi->up_vis > 0) {
6783 rc = apply_link_config(pi);
6785 lc->requested_fec = old;
6786 if (rc == FW_EPROTO)
6792 end_synchronized_op(sc, 0);
6799 sysctl_autoneg(SYSCTL_HANDLER_ARGS)
6801 struct port_info *pi = arg1;
6802 struct adapter *sc = pi->adapter;
6803 struct link_config *lc = &pi->link_cfg;
6806 if (lc->supported & FW_PORT_CAP32_ANEG)
6807 val = lc->requested_aneg == AUTONEG_DISABLE ? 0 : 1;
6810 rc = sysctl_handle_int(oidp, &val, 0, req);
6811 if (rc != 0 || req->newptr == NULL)
6814 val = AUTONEG_DISABLE;
6816 val = AUTONEG_ENABLE;
6820 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK,
6825 if (val == AUTONEG_ENABLE && !(lc->supported & FW_PORT_CAP32_ANEG)) {
6829 lc->requested_aneg = val;
6830 fixup_link_config(pi);
6832 rc = apply_link_config(pi);
6833 set_current_media(pi);
6836 end_synchronized_op(sc, 0);
6841 sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS)
6843 struct adapter *sc = arg1;
6847 val = t4_read_reg64(sc, reg);
6849 return (sysctl_handle_64(oidp, &val, 0, req));
6853 sysctl_temperature(SYSCTL_HANDLER_ARGS)
6855 struct adapter *sc = arg1;
6857 uint32_t param, val;
6859 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4temp");
6862 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
6863 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) |
6864 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_TMP);
6865 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
6866 end_synchronized_op(sc, 0);
6870 /* unknown is returned as 0 but we display -1 in that case */
6871 t = val == 0 ? -1 : val;
6873 rc = sysctl_handle_int(oidp, &t, 0, req);
6878 sysctl_loadavg(SYSCTL_HANDLER_ARGS)
6880 struct adapter *sc = arg1;
6883 uint32_t param, val;
6885 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4lavg");
6888 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
6889 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_LOAD);
6890 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
6891 end_synchronized_op(sc, 0);
6895 rc = sysctl_wire_old_buffer(req, 0);
6899 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6903 if (val == 0xffffffff) {
6904 /* Only debug and custom firmwares report load averages. */
6905 sbuf_printf(sb, "not available");
6907 sbuf_printf(sb, "%d %d %d", val & 0xff, (val >> 8) & 0xff,
6908 (val >> 16) & 0xff);
6910 rc = sbuf_finish(sb);
6917 sysctl_cctrl(SYSCTL_HANDLER_ARGS)
6919 struct adapter *sc = arg1;
6922 uint16_t incr[NMTUS][NCCTRL_WIN];
6923 static const char *dec_fac[] = {
6924 "0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
6928 rc = sysctl_wire_old_buffer(req, 0);
6932 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6936 t4_read_cong_tbl(sc, incr);
6938 for (i = 0; i < NCCTRL_WIN; ++i) {
6939 sbuf_printf(sb, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
6940 incr[0][i], incr[1][i], incr[2][i], incr[3][i], incr[4][i],
6941 incr[5][i], incr[6][i], incr[7][i]);
6942 sbuf_printf(sb, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
6943 incr[8][i], incr[9][i], incr[10][i], incr[11][i],
6944 incr[12][i], incr[13][i], incr[14][i], incr[15][i],
6945 sc->params.a_wnd[i], dec_fac[sc->params.b_wnd[i]]);
6948 rc = sbuf_finish(sb);
6954 static const char *qname[CIM_NUM_IBQ + CIM_NUM_OBQ_T5] = {
6955 "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI", /* ibq's */
6956 "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI", /* obq's */
6957 "SGE0-RX", "SGE1-RX" /* additional obq's (T5 onwards) */
6961 sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS)
6963 struct adapter *sc = arg1;
6965 int rc, i, n, qid = arg2;
6968 u_int cim_num_obq = sc->chip_params->cim_num_obq;
6970 KASSERT(qid >= 0 && qid < CIM_NUM_IBQ + cim_num_obq,
6971 ("%s: bad qid %d\n", __func__, qid));
6973 if (qid < CIM_NUM_IBQ) {
6976 n = 4 * CIM_IBQ_SIZE;
6977 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
6978 rc = t4_read_cim_ibq(sc, qid, buf, n);
6980 /* outbound queue */
6983 n = 4 * cim_num_obq * CIM_OBQ_SIZE;
6984 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
6985 rc = t4_read_cim_obq(sc, qid, buf, n);
6992 n = rc * sizeof(uint32_t); /* rc has # of words actually read */
6994 rc = sysctl_wire_old_buffer(req, 0);
6998 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
7004 sbuf_printf(sb, "%s%d %s", qtype , qid, qname[arg2]);
7005 for (i = 0, p = buf; i < n; i += 16, p += 4)
7006 sbuf_printf(sb, "\n%#06x: %08x %08x %08x %08x", i, p[0], p[1],
7009 rc = sbuf_finish(sb);
7017 sysctl_cim_la(SYSCTL_HANDLER_ARGS)
7019 struct adapter *sc = arg1;
7025 MPASS(chip_id(sc) <= CHELSIO_T5);
7027 rc = -t4_cim_read(sc, A_UP_UP_DBG_LA_CFG, 1, &cfg);
7031 rc = sysctl_wire_old_buffer(req, 0);
7035 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7039 buf = malloc(sc->params.cim_la_size * sizeof(uint32_t), M_CXGBE,
7042 rc = -t4_cim_read_la(sc, buf, NULL);
7046 sbuf_printf(sb, "Status Data PC%s",
7047 cfg & F_UPDBGLACAPTPCONLY ? "" :
7048 " LS0Stat LS0Addr LS0Data");
7050 for (p = buf; p <= &buf[sc->params.cim_la_size - 8]; p += 8) {
7051 if (cfg & F_UPDBGLACAPTPCONLY) {
7052 sbuf_printf(sb, "\n %02x %08x %08x", p[5] & 0xff,
7054 sbuf_printf(sb, "\n %02x %02x%06x %02x%06x",
7055 (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8,
7056 p[4] & 0xff, p[5] >> 8);
7057 sbuf_printf(sb, "\n %02x %x%07x %x%07x",
7058 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
7059 p[1] & 0xf, p[2] >> 4);
7062 "\n %02x %x%07x %x%07x %08x %08x "
7064 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
7065 p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5],
7070 rc = sbuf_finish(sb);
7078 sysctl_cim_la_t6(SYSCTL_HANDLER_ARGS)
7080 struct adapter *sc = arg1;
7086 MPASS(chip_id(sc) > CHELSIO_T5);
7088 rc = -t4_cim_read(sc, A_UP_UP_DBG_LA_CFG, 1, &cfg);
7092 rc = sysctl_wire_old_buffer(req, 0);
7096 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7100 buf = malloc(sc->params.cim_la_size * sizeof(uint32_t), M_CXGBE,
7103 rc = -t4_cim_read_la(sc, buf, NULL);
7107 sbuf_printf(sb, "Status Inst Data PC%s",
7108 cfg & F_UPDBGLACAPTPCONLY ? "" :
7109 " LS0Stat LS0Addr LS0Data LS1Stat LS1Addr LS1Data");
7111 for (p = buf; p <= &buf[sc->params.cim_la_size - 10]; p += 10) {
7112 if (cfg & F_UPDBGLACAPTPCONLY) {
7113 sbuf_printf(sb, "\n %02x %08x %08x %08x",
7114 p[3] & 0xff, p[2], p[1], p[0]);
7115 sbuf_printf(sb, "\n %02x %02x%06x %02x%06x %02x%06x",
7116 (p[6] >> 8) & 0xff, p[6] & 0xff, p[5] >> 8,
7117 p[5] & 0xff, p[4] >> 8, p[4] & 0xff, p[3] >> 8);
7118 sbuf_printf(sb, "\n %02x %04x%04x %04x%04x %04x%04x",
7119 (p[9] >> 16) & 0xff, p[9] & 0xffff, p[8] >> 16,
7120 p[8] & 0xffff, p[7] >> 16, p[7] & 0xffff,
7123 sbuf_printf(sb, "\n %02x %04x%04x %04x%04x %04x%04x "
7124 "%08x %08x %08x %08x %08x %08x",
7125 (p[9] >> 16) & 0xff,
7126 p[9] & 0xffff, p[8] >> 16,
7127 p[8] & 0xffff, p[7] >> 16,
7128 p[7] & 0xffff, p[6] >> 16,
7129 p[2], p[1], p[0], p[5], p[4], p[3]);
7133 rc = sbuf_finish(sb);
7141 sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS)
7143 struct adapter *sc = arg1;
7149 rc = sysctl_wire_old_buffer(req, 0);
7153 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7157 buf = malloc(2 * CIM_MALA_SIZE * 5 * sizeof(uint32_t), M_CXGBE,
7160 t4_cim_read_ma_la(sc, buf, buf + 5 * CIM_MALA_SIZE);
7163 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
7164 sbuf_printf(sb, "\n%02x%08x%08x%08x%08x", p[4], p[3], p[2],
7168 sbuf_printf(sb, "\n\nCnt ID Tag UE Data RDY VLD");
7169 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
7170 sbuf_printf(sb, "\n%3u %2u %x %u %08x%08x %u %u",
7171 (p[2] >> 10) & 0xff, (p[2] >> 7) & 7,
7172 (p[2] >> 3) & 0xf, (p[2] >> 2) & 1,
7173 (p[1] >> 2) | ((p[2] & 3) << 30),
7174 (p[0] >> 2) | ((p[1] & 3) << 30), (p[0] >> 1) & 1,
7178 rc = sbuf_finish(sb);
7185 sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS)
7187 struct adapter *sc = arg1;
7193 rc = sysctl_wire_old_buffer(req, 0);
7197 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7201 buf = malloc(2 * CIM_PIFLA_SIZE * 6 * sizeof(uint32_t), M_CXGBE,
7204 t4_cim_read_pif_la(sc, buf, buf + 6 * CIM_PIFLA_SIZE, NULL, NULL);
7207 sbuf_printf(sb, "Cntl ID DataBE Addr Data");
7208 for (i = 0; i < CIM_PIFLA_SIZE; i++, p += 6) {
7209 sbuf_printf(sb, "\n %02x %02x %04x %08x %08x%08x%08x%08x",
7210 (p[5] >> 22) & 0xff, (p[5] >> 16) & 0x3f, p[5] & 0xffff,
7211 p[4], p[3], p[2], p[1], p[0]);
7214 sbuf_printf(sb, "\n\nCntl ID Data");
7215 for (i = 0; i < CIM_PIFLA_SIZE; i++, p += 6) {
7216 sbuf_printf(sb, "\n %02x %02x %08x%08x%08x%08x",
7217 (p[4] >> 6) & 0xff, p[4] & 0x3f, p[3], p[2], p[1], p[0]);
7220 rc = sbuf_finish(sb);
7227 sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS)
7229 struct adapter *sc = arg1;
7232 uint16_t base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
7233 uint16_t size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
7234 uint16_t thres[CIM_NUM_IBQ];
7235 uint32_t obq_wr[2 * CIM_NUM_OBQ_T5], *wr = obq_wr;
7236 uint32_t stat[4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5)], *p = stat;
7237 u_int cim_num_obq, ibq_rdaddr, obq_rdaddr, nq;
7239 cim_num_obq = sc->chip_params->cim_num_obq;
7241 ibq_rdaddr = A_UP_IBQ_0_RDADDR;
7242 obq_rdaddr = A_UP_OBQ_0_REALADDR;
7244 ibq_rdaddr = A_UP_IBQ_0_SHADOW_RDADDR;
7245 obq_rdaddr = A_UP_OBQ_0_SHADOW_REALADDR;
7247 nq = CIM_NUM_IBQ + cim_num_obq;
7249 rc = -t4_cim_read(sc, ibq_rdaddr, 4 * nq, stat);
7251 rc = -t4_cim_read(sc, obq_rdaddr, 2 * cim_num_obq, obq_wr);
7255 t4_read_cimq_cfg(sc, base, size, thres);
7257 rc = sysctl_wire_old_buffer(req, 0);
7261 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
7266 " Queue Base Size Thres RdPtr WrPtr SOP EOP Avail");
7268 for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
7269 sbuf_printf(sb, "\n%7s %5x %5u %5u %6x %4x %4u %4u %5u",
7270 qname[i], base[i], size[i], thres[i], G_IBQRDADDR(p[0]),
7271 G_IBQWRADDR(p[1]), G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
7272 G_QUEREMFLITS(p[2]) * 16);
7273 for ( ; i < nq; i++, p += 4, wr += 2)
7274 sbuf_printf(sb, "\n%7s %5x %5u %12x %4x %4u %4u %5u", qname[i],
7275 base[i], size[i], G_QUERDADDR(p[0]) & 0x3fff,
7276 wr[0] - base[i], G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
7277 G_QUEREMFLITS(p[2]) * 16);
7279 rc = sbuf_finish(sb);
7286 sysctl_cpl_stats(SYSCTL_HANDLER_ARGS)
7288 struct adapter *sc = arg1;
7291 struct tp_cpl_stats stats;
7293 rc = sysctl_wire_old_buffer(req, 0);
7297 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7301 mtx_lock(&sc->reg_lock);
7302 t4_tp_get_cpl_stats(sc, &stats, 0);
7303 mtx_unlock(&sc->reg_lock);
7305 if (sc->chip_params->nchan > 2) {
7306 sbuf_printf(sb, " channel 0 channel 1"
7307 " channel 2 channel 3");
7308 sbuf_printf(sb, "\nCPL requests: %10u %10u %10u %10u",
7309 stats.req[0], stats.req[1], stats.req[2], stats.req[3]);
7310 sbuf_printf(sb, "\nCPL responses: %10u %10u %10u %10u",
7311 stats.rsp[0], stats.rsp[1], stats.rsp[2], stats.rsp[3]);
7313 sbuf_printf(sb, " channel 0 channel 1");
7314 sbuf_printf(sb, "\nCPL requests: %10u %10u",
7315 stats.req[0], stats.req[1]);
7316 sbuf_printf(sb, "\nCPL responses: %10u %10u",
7317 stats.rsp[0], stats.rsp[1]);
7320 rc = sbuf_finish(sb);
7327 sysctl_ddp_stats(SYSCTL_HANDLER_ARGS)
7329 struct adapter *sc = arg1;
7332 struct tp_usm_stats stats;
7334 rc = sysctl_wire_old_buffer(req, 0);
7338 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7342 t4_get_usm_stats(sc, &stats, 1);
7344 sbuf_printf(sb, "Frames: %u\n", stats.frames);
7345 sbuf_printf(sb, "Octets: %ju\n", stats.octets);
7346 sbuf_printf(sb, "Drops: %u", stats.drops);
7348 rc = sbuf_finish(sb);
7354 static const char * const devlog_level_strings[] = {
7355 [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
7356 [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
7357 [FW_DEVLOG_LEVEL_ERR] = "ERR",
7358 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
7359 [FW_DEVLOG_LEVEL_INFO] = "INFO",
7360 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
7363 static const char * const devlog_facility_strings[] = {
7364 [FW_DEVLOG_FACILITY_CORE] = "CORE",
7365 [FW_DEVLOG_FACILITY_CF] = "CF",
7366 [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
7367 [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
7368 [FW_DEVLOG_FACILITY_RES] = "RES",
7369 [FW_DEVLOG_FACILITY_HW] = "HW",
7370 [FW_DEVLOG_FACILITY_FLR] = "FLR",
7371 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
7372 [FW_DEVLOG_FACILITY_PHY] = "PHY",
7373 [FW_DEVLOG_FACILITY_MAC] = "MAC",
7374 [FW_DEVLOG_FACILITY_PORT] = "PORT",
7375 [FW_DEVLOG_FACILITY_VI] = "VI",
7376 [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
7377 [FW_DEVLOG_FACILITY_ACL] = "ACL",
7378 [FW_DEVLOG_FACILITY_TM] = "TM",
7379 [FW_DEVLOG_FACILITY_QFC] = "QFC",
7380 [FW_DEVLOG_FACILITY_DCB] = "DCB",
7381 [FW_DEVLOG_FACILITY_ETH] = "ETH",
7382 [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
7383 [FW_DEVLOG_FACILITY_RI] = "RI",
7384 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
7385 [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
7386 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
7387 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE",
7388 [FW_DEVLOG_FACILITY_CHNET] = "CHNET",
7392 sysctl_devlog(SYSCTL_HANDLER_ARGS)
7394 struct adapter *sc = arg1;
7395 struct devlog_params *dparams = &sc->params.devlog;
7396 struct fw_devlog_e *buf, *e;
7397 int i, j, rc, nentries, first = 0;
7399 uint64_t ftstamp = UINT64_MAX;
7401 if (dparams->addr == 0)
7404 buf = malloc(dparams->size, M_CXGBE, M_NOWAIT);
7408 rc = read_via_memwin(sc, 1, dparams->addr, (void *)buf, dparams->size);
7412 nentries = dparams->size / sizeof(struct fw_devlog_e);
7413 for (i = 0; i < nentries; i++) {
7416 if (e->timestamp == 0)
7419 e->timestamp = be64toh(e->timestamp);
7420 e->seqno = be32toh(e->seqno);
7421 for (j = 0; j < 8; j++)
7422 e->params[j] = be32toh(e->params[j]);
7424 if (e->timestamp < ftstamp) {
7425 ftstamp = e->timestamp;
7430 if (buf[first].timestamp == 0)
7431 goto done; /* nothing in the log */
7433 rc = sysctl_wire_old_buffer(req, 0);
7437 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7442 sbuf_printf(sb, "%10s %15s %8s %8s %s\n",
7443 "Seq#", "Tstamp", "Level", "Facility", "Message");
7448 if (e->timestamp == 0)
7451 sbuf_printf(sb, "%10d %15ju %8s %8s ",
7452 e->seqno, e->timestamp,
7453 (e->level < nitems(devlog_level_strings) ?
7454 devlog_level_strings[e->level] : "UNKNOWN"),
7455 (e->facility < nitems(devlog_facility_strings) ?
7456 devlog_facility_strings[e->facility] : "UNKNOWN"));
7457 sbuf_printf(sb, e->fmt, e->params[0], e->params[1],
7458 e->params[2], e->params[3], e->params[4],
7459 e->params[5], e->params[6], e->params[7]);
7461 if (++i == nentries)
7463 } while (i != first);
7465 rc = sbuf_finish(sb);
7473 sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS)
7475 struct adapter *sc = arg1;
7478 struct tp_fcoe_stats stats[MAX_NCHAN];
7479 int i, nchan = sc->chip_params->nchan;
7481 rc = sysctl_wire_old_buffer(req, 0);
7485 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7489 for (i = 0; i < nchan; i++)
7490 t4_get_fcoe_stats(sc, i, &stats[i], 1);
7493 sbuf_printf(sb, " channel 0 channel 1"
7494 " channel 2 channel 3");
7495 sbuf_printf(sb, "\noctetsDDP: %16ju %16ju %16ju %16ju",
7496 stats[0].octets_ddp, stats[1].octets_ddp,
7497 stats[2].octets_ddp, stats[3].octets_ddp);
7498 sbuf_printf(sb, "\nframesDDP: %16u %16u %16u %16u",
7499 stats[0].frames_ddp, stats[1].frames_ddp,
7500 stats[2].frames_ddp, stats[3].frames_ddp);
7501 sbuf_printf(sb, "\nframesDrop: %16u %16u %16u %16u",
7502 stats[0].frames_drop, stats[1].frames_drop,
7503 stats[2].frames_drop, stats[3].frames_drop);
7505 sbuf_printf(sb, " channel 0 channel 1");
7506 sbuf_printf(sb, "\noctetsDDP: %16ju %16ju",
7507 stats[0].octets_ddp, stats[1].octets_ddp);
7508 sbuf_printf(sb, "\nframesDDP: %16u %16u",
7509 stats[0].frames_ddp, stats[1].frames_ddp);
7510 sbuf_printf(sb, "\nframesDrop: %16u %16u",
7511 stats[0].frames_drop, stats[1].frames_drop);
7514 rc = sbuf_finish(sb);
7521 sysctl_hw_sched(SYSCTL_HANDLER_ARGS)
7523 struct adapter *sc = arg1;
7526 unsigned int map, kbps, ipg, mode;
7527 unsigned int pace_tab[NTX_SCHED];
7529 rc = sysctl_wire_old_buffer(req, 0);
7533 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7537 map = t4_read_reg(sc, A_TP_TX_MOD_QUEUE_REQ_MAP);
7538 mode = G_TIMERMODE(t4_read_reg(sc, A_TP_MOD_CONFIG));
7539 t4_read_pace_tbl(sc, pace_tab);
7541 sbuf_printf(sb, "Scheduler Mode Channel Rate (Kbps) "
7542 "Class IPG (0.1 ns) Flow IPG (us)");
7544 for (i = 0; i < NTX_SCHED; ++i, map >>= 2) {
7545 t4_get_tx_sched(sc, i, &kbps, &ipg, 1);
7546 sbuf_printf(sb, "\n %u %-5s %u ", i,
7547 (mode & (1 << i)) ? "flow" : "class", map & 3);
7549 sbuf_printf(sb, "%9u ", kbps);
7551 sbuf_printf(sb, " disabled ");
7554 sbuf_printf(sb, "%13u ", ipg);
7556 sbuf_printf(sb, " disabled ");
7559 sbuf_printf(sb, "%10u", pace_tab[i]);
7561 sbuf_printf(sb, " disabled");
7564 rc = sbuf_finish(sb);
7571 sysctl_lb_stats(SYSCTL_HANDLER_ARGS)
7573 struct adapter *sc = arg1;
7577 struct lb_port_stats s[2];
7578 static const char *stat_name[] = {
7579 "OctetsOK:", "FramesOK:", "BcastFrames:", "McastFrames:",
7580 "UcastFrames:", "ErrorFrames:", "Frames64:", "Frames65To127:",
7581 "Frames128To255:", "Frames256To511:", "Frames512To1023:",
7582 "Frames1024To1518:", "Frames1519ToMax:", "FramesDropped:",
7583 "BG0FramesDropped:", "BG1FramesDropped:", "BG2FramesDropped:",
7584 "BG3FramesDropped:", "BG0FramesTrunc:", "BG1FramesTrunc:",
7585 "BG2FramesTrunc:", "BG3FramesTrunc:"
7588 rc = sysctl_wire_old_buffer(req, 0);
7592 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7596 memset(s, 0, sizeof(s));
7598 for (i = 0; i < sc->chip_params->nchan; i += 2) {
7599 t4_get_lb_stats(sc, i, &s[0]);
7600 t4_get_lb_stats(sc, i + 1, &s[1]);
7604 sbuf_printf(sb, "%s Loopback %u"
7605 " Loopback %u", i == 0 ? "" : "\n", i, i + 1);
7607 for (j = 0; j < nitems(stat_name); j++)
7608 sbuf_printf(sb, "\n%-17s %20ju %20ju", stat_name[j],
7612 rc = sbuf_finish(sb);
7619 sysctl_linkdnrc(SYSCTL_HANDLER_ARGS)
7622 struct port_info *pi = arg1;
7623 struct link_config *lc = &pi->link_cfg;
7626 rc = sysctl_wire_old_buffer(req, 0);
7629 sb = sbuf_new_for_sysctl(NULL, NULL, 64, req);
7633 if (lc->link_ok || lc->link_down_rc == 255)
7634 sbuf_printf(sb, "n/a");
7636 sbuf_printf(sb, "%s", t4_link_down_rc_str(lc->link_down_rc));
7638 rc = sbuf_finish(sb);
7651 mem_desc_cmp(const void *a, const void *b)
7653 return ((const struct mem_desc *)a)->base -
7654 ((const struct mem_desc *)b)->base;
7658 mem_region_show(struct sbuf *sb, const char *name, unsigned int from,
7666 size = to - from + 1;
7670 /* XXX: need humanize_number(3) in libkern for a more readable 'size' */
7671 sbuf_printf(sb, "%-15s %#x-%#x [%u]\n", name, from, to, size);
7675 sysctl_meminfo(SYSCTL_HANDLER_ARGS)
7677 struct adapter *sc = arg1;
7680 uint32_t lo, hi, used, alloc;
7681 static const char *memory[] = {"EDC0:", "EDC1:", "MC:", "MC0:", "MC1:"};
7682 static const char *region[] = {
7683 "DBQ contexts:", "IMSG contexts:", "FLM cache:", "TCBs:",
7684 "Pstructs:", "Timers:", "Rx FL:", "Tx FL:", "Pstruct FL:",
7685 "Tx payload:", "Rx payload:", "LE hash:", "iSCSI region:",
7686 "TDDP region:", "TPT region:", "STAG region:", "RQ region:",
7687 "RQUDP region:", "PBL region:", "TXPBL region:",
7688 "DBVFIFO region:", "ULPRX state:", "ULPTX state:",
7689 "On-chip queues:", "TLS keys:",
7691 struct mem_desc avail[4];
7692 struct mem_desc mem[nitems(region) + 3]; /* up to 3 holes */
7693 struct mem_desc *md = mem;
7695 rc = sysctl_wire_old_buffer(req, 0);
7699 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7703 for (i = 0; i < nitems(mem); i++) {
7708 /* Find and sort the populated memory ranges */
7710 lo = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
7711 if (lo & F_EDRAM0_ENABLE) {
7712 hi = t4_read_reg(sc, A_MA_EDRAM0_BAR);
7713 avail[i].base = G_EDRAM0_BASE(hi) << 20;
7714 avail[i].limit = avail[i].base + (G_EDRAM0_SIZE(hi) << 20);
7718 if (lo & F_EDRAM1_ENABLE) {
7719 hi = t4_read_reg(sc, A_MA_EDRAM1_BAR);
7720 avail[i].base = G_EDRAM1_BASE(hi) << 20;
7721 avail[i].limit = avail[i].base + (G_EDRAM1_SIZE(hi) << 20);
7725 if (lo & F_EXT_MEM_ENABLE) {
7726 hi = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
7727 avail[i].base = G_EXT_MEM_BASE(hi) << 20;
7728 avail[i].limit = avail[i].base +
7729 (G_EXT_MEM_SIZE(hi) << 20);
7730 avail[i].idx = is_t5(sc) ? 3 : 2; /* Call it MC0 for T5 */
7733 if (is_t5(sc) && lo & F_EXT_MEM1_ENABLE) {
7734 hi = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
7735 avail[i].base = G_EXT_MEM1_BASE(hi) << 20;
7736 avail[i].limit = avail[i].base +
7737 (G_EXT_MEM1_SIZE(hi) << 20);
7741 if (!i) /* no memory available */
7743 qsort(avail, i, sizeof(struct mem_desc), mem_desc_cmp);
7745 (md++)->base = t4_read_reg(sc, A_SGE_DBQ_CTXT_BADDR);
7746 (md++)->base = t4_read_reg(sc, A_SGE_IMSG_CTXT_BADDR);
7747 (md++)->base = t4_read_reg(sc, A_SGE_FLM_CACHE_BADDR);
7748 (md++)->base = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
7749 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_BASE);
7750 (md++)->base = t4_read_reg(sc, A_TP_CMM_TIMER_BASE);
7751 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_RX_FLST_BASE);
7752 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_TX_FLST_BASE);
7753 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_PS_FLST_BASE);
7755 /* the next few have explicit upper bounds */
7756 md->base = t4_read_reg(sc, A_TP_PMM_TX_BASE);
7757 md->limit = md->base - 1 +
7758 t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE) *
7759 G_PMTXMAXPAGE(t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE));
7762 md->base = t4_read_reg(sc, A_TP_PMM_RX_BASE);
7763 md->limit = md->base - 1 +
7764 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) *
7765 G_PMRXMAXPAGE(t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE));
7768 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
7769 if (chip_id(sc) <= CHELSIO_T5)
7770 md->base = t4_read_reg(sc, A_LE_DB_HASH_TID_BASE);
7772 md->base = t4_read_reg(sc, A_LE_DB_HASH_TBL_BASE_ADDR);
7776 md->idx = nitems(region); /* hide it */
7780 #define ulp_region(reg) \
7781 md->base = t4_read_reg(sc, A_ULP_ ## reg ## _LLIMIT);\
7782 (md++)->limit = t4_read_reg(sc, A_ULP_ ## reg ## _ULIMIT)
7784 ulp_region(RX_ISCSI);
7785 ulp_region(RX_TDDP);
7787 ulp_region(RX_STAG);
7789 ulp_region(RX_RQUDP);
7795 md->idx = nitems(region);
7798 uint32_t sge_ctrl = t4_read_reg(sc, A_SGE_CONTROL2);
7799 uint32_t fifo_size = t4_read_reg(sc, A_SGE_DBVFIFO_SIZE);
7802 if (sge_ctrl & F_VFIFO_ENABLE)
7803 size = G_DBVFIFO_SIZE(fifo_size);
7805 size = G_T6_DBVFIFO_SIZE(fifo_size);
7808 md->base = G_BASEADDR(t4_read_reg(sc,
7809 A_SGE_DBVFIFO_BADDR));
7810 md->limit = md->base + (size << 2) - 1;
7815 md->base = t4_read_reg(sc, A_ULP_RX_CTX_BASE);
7818 md->base = t4_read_reg(sc, A_ULP_TX_ERR_TABLE_BASE);
7822 md->base = sc->vres.ocq.start;
7823 if (sc->vres.ocq.size)
7824 md->limit = md->base + sc->vres.ocq.size - 1;
7826 md->idx = nitems(region); /* hide it */
7829 md->base = sc->vres.key.start;
7830 if (sc->vres.key.size)
7831 md->limit = md->base + sc->vres.key.size - 1;
7833 md->idx = nitems(region); /* hide it */
7836 /* add any address-space holes, there can be up to 3 */
7837 for (n = 0; n < i - 1; n++)
7838 if (avail[n].limit < avail[n + 1].base)
7839 (md++)->base = avail[n].limit;
7841 (md++)->base = avail[n].limit;
7844 qsort(mem, n, sizeof(struct mem_desc), mem_desc_cmp);
7846 for (lo = 0; lo < i; lo++)
7847 mem_region_show(sb, memory[avail[lo].idx], avail[lo].base,
7848 avail[lo].limit - 1);
7850 sbuf_printf(sb, "\n");
7851 for (i = 0; i < n; i++) {
7852 if (mem[i].idx >= nitems(region))
7853 continue; /* skip holes */
7855 mem[i].limit = i < n - 1 ? mem[i + 1].base - 1 : ~0;
7856 mem_region_show(sb, region[mem[i].idx], mem[i].base,
7860 sbuf_printf(sb, "\n");
7861 lo = t4_read_reg(sc, A_CIM_SDRAM_BASE_ADDR);
7862 hi = t4_read_reg(sc, A_CIM_SDRAM_ADDR_SIZE) + lo - 1;
7863 mem_region_show(sb, "uP RAM:", lo, hi);
7865 lo = t4_read_reg(sc, A_CIM_EXTMEM2_BASE_ADDR);
7866 hi = t4_read_reg(sc, A_CIM_EXTMEM2_ADDR_SIZE) + lo - 1;
7867 mem_region_show(sb, "uP Extmem2:", lo, hi);
7869 lo = t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE);
7870 sbuf_printf(sb, "\n%u Rx pages of size %uKiB for %u channels\n",
7872 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) >> 10,
7873 (lo & F_PMRXNUMCHN) ? 2 : 1);
7875 lo = t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE);
7876 hi = t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE);
7877 sbuf_printf(sb, "%u Tx pages of size %u%ciB for %u channels\n",
7879 hi >= (1 << 20) ? (hi >> 20) : (hi >> 10),
7880 hi >= (1 << 20) ? 'M' : 'K', 1 << G_PMTXNUMCHN(lo));
7881 sbuf_printf(sb, "%u p-structs\n",
7882 t4_read_reg(sc, A_TP_CMM_MM_MAX_PSTRUCT));
7884 for (i = 0; i < 4; i++) {
7885 if (chip_id(sc) > CHELSIO_T5)
7886 lo = t4_read_reg(sc, A_MPS_RX_MAC_BG_PG_CNT0 + i * 4);
7888 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV0 + i * 4);
7890 used = G_T5_USED(lo);
7891 alloc = G_T5_ALLOC(lo);
7894 alloc = G_ALLOC(lo);
7896 /* For T6 these are MAC buffer groups */
7897 sbuf_printf(sb, "\nPort %d using %u pages out of %u allocated",
7900 for (i = 0; i < sc->chip_params->nchan; i++) {
7901 if (chip_id(sc) > CHELSIO_T5)
7902 lo = t4_read_reg(sc, A_MPS_RX_LPBK_BG_PG_CNT0 + i * 4);
7904 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV4 + i * 4);
7906 used = G_T5_USED(lo);
7907 alloc = G_T5_ALLOC(lo);
7910 alloc = G_ALLOC(lo);
7912 /* For T6 these are MAC buffer groups */
7914 "\nLoopback %d using %u pages out of %u allocated",
7918 rc = sbuf_finish(sb);
7925 tcamxy2valmask(uint64_t x, uint64_t y, uint8_t *addr, uint64_t *mask)
7929 memcpy(addr, (char *)&y + 2, ETHER_ADDR_LEN);
7933 sysctl_mps_tcam(SYSCTL_HANDLER_ARGS)
7935 struct adapter *sc = arg1;
7939 MPASS(chip_id(sc) <= CHELSIO_T5);
7941 rc = sysctl_wire_old_buffer(req, 0);
7945 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7950 "Idx Ethernet address Mask Vld Ports PF"
7951 " VF Replication P0 P1 P2 P3 ML");
7952 for (i = 0; i < sc->chip_params->mps_tcam_size; i++) {
7953 uint64_t tcamx, tcamy, mask;
7954 uint32_t cls_lo, cls_hi;
7955 uint8_t addr[ETHER_ADDR_LEN];
7957 tcamy = t4_read_reg64(sc, MPS_CLS_TCAM_Y_L(i));
7958 tcamx = t4_read_reg64(sc, MPS_CLS_TCAM_X_L(i));
7961 tcamxy2valmask(tcamx, tcamy, addr, &mask);
7962 cls_lo = t4_read_reg(sc, MPS_CLS_SRAM_L(i));
7963 cls_hi = t4_read_reg(sc, MPS_CLS_SRAM_H(i));
7964 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x %012jx"
7965 " %c %#x%4u%4d", i, addr[0], addr[1], addr[2],
7966 addr[3], addr[4], addr[5], (uintmax_t)mask,
7967 (cls_lo & F_SRAM_VLD) ? 'Y' : 'N',
7968 G_PORTMAP(cls_hi), G_PF(cls_lo),
7969 (cls_lo & F_VF_VALID) ? G_VF(cls_lo) : -1);
7971 if (cls_lo & F_REPLICATE) {
7972 struct fw_ldst_cmd ldst_cmd;
7974 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
7975 ldst_cmd.op_to_addrspace =
7976 htobe32(V_FW_CMD_OP(FW_LDST_CMD) |
7977 F_FW_CMD_REQUEST | F_FW_CMD_READ |
7978 V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MPS));
7979 ldst_cmd.cycles_to_len16 = htobe32(FW_LEN16(ldst_cmd));
7980 ldst_cmd.u.mps.rplc.fid_idx =
7981 htobe16(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) |
7982 V_FW_LDST_CMD_IDX(i));
7984 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK,
7988 rc = -t4_wr_mbox(sc, sc->mbox, &ldst_cmd,
7989 sizeof(ldst_cmd), &ldst_cmd);
7990 end_synchronized_op(sc, 0);
7993 sbuf_printf(sb, "%36d", rc);
7996 sbuf_printf(sb, " %08x %08x %08x %08x",
7997 be32toh(ldst_cmd.u.mps.rplc.rplc127_96),
7998 be32toh(ldst_cmd.u.mps.rplc.rplc95_64),
7999 be32toh(ldst_cmd.u.mps.rplc.rplc63_32),
8000 be32toh(ldst_cmd.u.mps.rplc.rplc31_0));
8003 sbuf_printf(sb, "%36s", "");
8005 sbuf_printf(sb, "%4u%3u%3u%3u %#3x", G_SRAM_PRIO0(cls_lo),
8006 G_SRAM_PRIO1(cls_lo), G_SRAM_PRIO2(cls_lo),
8007 G_SRAM_PRIO3(cls_lo), (cls_lo >> S_MULTILISTEN0) & 0xf);
8011 (void) sbuf_finish(sb);
8013 rc = sbuf_finish(sb);
8020 sysctl_mps_tcam_t6(SYSCTL_HANDLER_ARGS)
8022 struct adapter *sc = arg1;
8026 MPASS(chip_id(sc) > CHELSIO_T5);
8028 rc = sysctl_wire_old_buffer(req, 0);
8032 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8036 sbuf_printf(sb, "Idx Ethernet address Mask VNI Mask"
8037 " IVLAN Vld DIP_Hit Lookup Port Vld Ports PF VF"
8039 " P0 P1 P2 P3 ML\n");
8041 for (i = 0; i < sc->chip_params->mps_tcam_size; i++) {
8042 uint8_t dip_hit, vlan_vld, lookup_type, port_num;
8044 uint64_t tcamx, tcamy, val, mask;
8045 uint32_t cls_lo, cls_hi, ctl, data2, vnix, vniy;
8046 uint8_t addr[ETHER_ADDR_LEN];
8048 ctl = V_CTLREQID(1) | V_CTLCMDTYPE(0) | V_CTLXYBITSEL(0);
8050 ctl |= V_CTLTCAMINDEX(i) | V_CTLTCAMSEL(0);
8052 ctl |= V_CTLTCAMINDEX(i - 256) | V_CTLTCAMSEL(1);
8053 t4_write_reg(sc, A_MPS_CLS_TCAM_DATA2_CTL, ctl);
8054 val = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA1_REQ_ID1);
8055 tcamy = G_DMACH(val) << 32;
8056 tcamy |= t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA0_REQ_ID1);
8057 data2 = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA2_REQ_ID1);
8058 lookup_type = G_DATALKPTYPE(data2);
8059 port_num = G_DATAPORTNUM(data2);
8060 if (lookup_type && lookup_type != M_DATALKPTYPE) {
8061 /* Inner header VNI */
8062 vniy = ((data2 & F_DATAVIDH2) << 23) |
8063 (G_DATAVIDH1(data2) << 16) | G_VIDL(val);
8064 dip_hit = data2 & F_DATADIPHIT;
8069 vlan_vld = data2 & F_DATAVIDH2;
8070 ivlan = G_VIDL(val);
8073 ctl |= V_CTLXYBITSEL(1);
8074 t4_write_reg(sc, A_MPS_CLS_TCAM_DATA2_CTL, ctl);
8075 val = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA1_REQ_ID1);
8076 tcamx = G_DMACH(val) << 32;
8077 tcamx |= t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA0_REQ_ID1);
8078 data2 = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA2_REQ_ID1);
8079 if (lookup_type && lookup_type != M_DATALKPTYPE) {
8080 /* Inner header VNI mask */
8081 vnix = ((data2 & F_DATAVIDH2) << 23) |
8082 (G_DATAVIDH1(data2) << 16) | G_VIDL(val);
8088 tcamxy2valmask(tcamx, tcamy, addr, &mask);
8090 cls_lo = t4_read_reg(sc, MPS_CLS_SRAM_L(i));
8091 cls_hi = t4_read_reg(sc, MPS_CLS_SRAM_H(i));
8093 if (lookup_type && lookup_type != M_DATALKPTYPE) {
8094 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x "
8095 "%012jx %06x %06x - - %3c"
8096 " 'I' %4x %3c %#x%4u%4d", i, addr[0],
8097 addr[1], addr[2], addr[3], addr[4], addr[5],
8098 (uintmax_t)mask, vniy, vnix, dip_hit ? 'Y' : 'N',
8099 port_num, cls_lo & F_T6_SRAM_VLD ? 'Y' : 'N',
8100 G_PORTMAP(cls_hi), G_T6_PF(cls_lo),
8101 cls_lo & F_T6_VF_VALID ? G_T6_VF(cls_lo) : -1);
8103 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x "
8104 "%012jx - - ", i, addr[0], addr[1],
8105 addr[2], addr[3], addr[4], addr[5],
8109 sbuf_printf(sb, "%4u Y ", ivlan);
8111 sbuf_printf(sb, " - N ");
8113 sbuf_printf(sb, "- %3c %4x %3c %#x%4u%4d",
8114 lookup_type ? 'I' : 'O', port_num,
8115 cls_lo & F_T6_SRAM_VLD ? 'Y' : 'N',
8116 G_PORTMAP(cls_hi), G_T6_PF(cls_lo),
8117 cls_lo & F_T6_VF_VALID ? G_T6_VF(cls_lo) : -1);
8121 if (cls_lo & F_T6_REPLICATE) {
8122 struct fw_ldst_cmd ldst_cmd;
8124 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
8125 ldst_cmd.op_to_addrspace =
8126 htobe32(V_FW_CMD_OP(FW_LDST_CMD) |
8127 F_FW_CMD_REQUEST | F_FW_CMD_READ |
8128 V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MPS));
8129 ldst_cmd.cycles_to_len16 = htobe32(FW_LEN16(ldst_cmd));
8130 ldst_cmd.u.mps.rplc.fid_idx =
8131 htobe16(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) |
8132 V_FW_LDST_CMD_IDX(i));
8134 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK,
8138 rc = -t4_wr_mbox(sc, sc->mbox, &ldst_cmd,
8139 sizeof(ldst_cmd), &ldst_cmd);
8140 end_synchronized_op(sc, 0);
8143 sbuf_printf(sb, "%72d", rc);
8146 sbuf_printf(sb, " %08x %08x %08x %08x"
8147 " %08x %08x %08x %08x",
8148 be32toh(ldst_cmd.u.mps.rplc.rplc255_224),
8149 be32toh(ldst_cmd.u.mps.rplc.rplc223_192),
8150 be32toh(ldst_cmd.u.mps.rplc.rplc191_160),
8151 be32toh(ldst_cmd.u.mps.rplc.rplc159_128),
8152 be32toh(ldst_cmd.u.mps.rplc.rplc127_96),
8153 be32toh(ldst_cmd.u.mps.rplc.rplc95_64),
8154 be32toh(ldst_cmd.u.mps.rplc.rplc63_32),
8155 be32toh(ldst_cmd.u.mps.rplc.rplc31_0));
8158 sbuf_printf(sb, "%72s", "");
8160 sbuf_printf(sb, "%4u%3u%3u%3u %#x",
8161 G_T6_SRAM_PRIO0(cls_lo), G_T6_SRAM_PRIO1(cls_lo),
8162 G_T6_SRAM_PRIO2(cls_lo), G_T6_SRAM_PRIO3(cls_lo),
8163 (cls_lo >> S_T6_MULTILISTEN0) & 0xf);
8167 (void) sbuf_finish(sb);
8169 rc = sbuf_finish(sb);
8176 sysctl_path_mtus(SYSCTL_HANDLER_ARGS)
8178 struct adapter *sc = arg1;
8181 uint16_t mtus[NMTUS];
8183 rc = sysctl_wire_old_buffer(req, 0);
8187 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8191 t4_read_mtu_tbl(sc, mtus, NULL);
8193 sbuf_printf(sb, "%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u",
8194 mtus[0], mtus[1], mtus[2], mtus[3], mtus[4], mtus[5], mtus[6],
8195 mtus[7], mtus[8], mtus[9], mtus[10], mtus[11], mtus[12], mtus[13],
8196 mtus[14], mtus[15]);
8198 rc = sbuf_finish(sb);
8205 sysctl_pm_stats(SYSCTL_HANDLER_ARGS)
8207 struct adapter *sc = arg1;
8210 uint32_t tx_cnt[MAX_PM_NSTATS], rx_cnt[MAX_PM_NSTATS];
8211 uint64_t tx_cyc[MAX_PM_NSTATS], rx_cyc[MAX_PM_NSTATS];
8212 static const char *tx_stats[MAX_PM_NSTATS] = {
8213 "Read:", "Write bypass:", "Write mem:", "Bypass + mem:",
8214 "Tx FIFO wait", NULL, "Tx latency"
8216 static const char *rx_stats[MAX_PM_NSTATS] = {
8217 "Read:", "Write bypass:", "Write mem:", "Flush:",
8218 "Rx FIFO wait", NULL, "Rx latency"
8221 rc = sysctl_wire_old_buffer(req, 0);
8225 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8229 t4_pmtx_get_stats(sc, tx_cnt, tx_cyc);
8230 t4_pmrx_get_stats(sc, rx_cnt, rx_cyc);
8232 sbuf_printf(sb, " Tx pcmds Tx bytes");
8233 for (i = 0; i < 4; i++) {
8234 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i],
8238 sbuf_printf(sb, "\n Rx pcmds Rx bytes");
8239 for (i = 0; i < 4; i++) {
8240 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i],
8244 if (chip_id(sc) > CHELSIO_T5) {
8246 "\n Total wait Total occupancy");
8247 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i],
8249 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i],
8253 MPASS(i < nitems(tx_stats));
8256 "\n Reads Total wait");
8257 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i],
8259 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i],
8263 rc = sbuf_finish(sb);
8270 sysctl_rdma_stats(SYSCTL_HANDLER_ARGS)
8272 struct adapter *sc = arg1;
8275 struct tp_rdma_stats stats;
8277 rc = sysctl_wire_old_buffer(req, 0);
8281 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8285 mtx_lock(&sc->reg_lock);
8286 t4_tp_get_rdma_stats(sc, &stats, 0);
8287 mtx_unlock(&sc->reg_lock);
8289 sbuf_printf(sb, "NoRQEModDefferals: %u\n", stats.rqe_dfr_mod);
8290 sbuf_printf(sb, "NoRQEPktDefferals: %u", stats.rqe_dfr_pkt);
8292 rc = sbuf_finish(sb);
8299 sysctl_tcp_stats(SYSCTL_HANDLER_ARGS)
8301 struct adapter *sc = arg1;
8304 struct tp_tcp_stats v4, v6;
8306 rc = sysctl_wire_old_buffer(req, 0);
8310 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8314 mtx_lock(&sc->reg_lock);
8315 t4_tp_get_tcp_stats(sc, &v4, &v6, 0);
8316 mtx_unlock(&sc->reg_lock);
8320 sbuf_printf(sb, "OutRsts: %20u %20u\n",
8321 v4.tcp_out_rsts, v6.tcp_out_rsts);
8322 sbuf_printf(sb, "InSegs: %20ju %20ju\n",
8323 v4.tcp_in_segs, v6.tcp_in_segs);
8324 sbuf_printf(sb, "OutSegs: %20ju %20ju\n",
8325 v4.tcp_out_segs, v6.tcp_out_segs);
8326 sbuf_printf(sb, "RetransSegs: %20ju %20ju",
8327 v4.tcp_retrans_segs, v6.tcp_retrans_segs);
8329 rc = sbuf_finish(sb);
8336 sysctl_tids(SYSCTL_HANDLER_ARGS)
8338 struct adapter *sc = arg1;
8341 struct tid_info *t = &sc->tids;
8343 rc = sysctl_wire_old_buffer(req, 0);
8347 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8352 sbuf_printf(sb, "ATID range: 0-%u, in use: %u\n", t->natids - 1,
8357 sbuf_printf(sb, "HPFTID range: %u-%u, in use: %u\n",
8358 t->hpftid_base, t->hpftid_end, t->hpftids_in_use);
8362 sbuf_printf(sb, "TID range: ");
8363 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
8366 if (chip_id(sc) <= CHELSIO_T5) {
8367 b = t4_read_reg(sc, A_LE_DB_SERVER_INDEX) / 4;
8368 hb = t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4;
8370 b = t4_read_reg(sc, A_LE_DB_SRVR_START_INDEX);
8371 hb = t4_read_reg(sc, A_T6_LE_DB_HASH_TID_BASE);
8375 sbuf_printf(sb, "%u-%u, ", t->tid_base, b - 1);
8376 sbuf_printf(sb, "%u-%u", hb, t->ntids - 1);
8378 sbuf_printf(sb, "%u-%u", t->tid_base, t->ntids - 1);
8379 sbuf_printf(sb, ", in use: %u\n",
8380 atomic_load_acq_int(&t->tids_in_use));
8384 sbuf_printf(sb, "STID range: %u-%u, in use: %u\n", t->stid_base,
8385 t->stid_base + t->nstids - 1, t->stids_in_use);
8389 sbuf_printf(sb, "FTID range: %u-%u, in use: %u\n", t->ftid_base,
8390 t->ftid_end, t->ftids_in_use);
8394 sbuf_printf(sb, "ETID range: %u-%u, in use: %u\n", t->etid_base,
8395 t->etid_base + t->netids - 1, t->etids_in_use);
8398 sbuf_printf(sb, "HW TID usage: %u IP users, %u IPv6 users",
8399 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV4),
8400 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV6));
8402 rc = sbuf_finish(sb);
8409 sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS)
8411 struct adapter *sc = arg1;
8414 struct tp_err_stats stats;
8416 rc = sysctl_wire_old_buffer(req, 0);
8420 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8424 mtx_lock(&sc->reg_lock);
8425 t4_tp_get_err_stats(sc, &stats, 0);
8426 mtx_unlock(&sc->reg_lock);
8428 if (sc->chip_params->nchan > 2) {
8429 sbuf_printf(sb, " channel 0 channel 1"
8430 " channel 2 channel 3\n");
8431 sbuf_printf(sb, "macInErrs: %10u %10u %10u %10u\n",
8432 stats.mac_in_errs[0], stats.mac_in_errs[1],
8433 stats.mac_in_errs[2], stats.mac_in_errs[3]);
8434 sbuf_printf(sb, "hdrInErrs: %10u %10u %10u %10u\n",
8435 stats.hdr_in_errs[0], stats.hdr_in_errs[1],
8436 stats.hdr_in_errs[2], stats.hdr_in_errs[3]);
8437 sbuf_printf(sb, "tcpInErrs: %10u %10u %10u %10u\n",
8438 stats.tcp_in_errs[0], stats.tcp_in_errs[1],
8439 stats.tcp_in_errs[2], stats.tcp_in_errs[3]);
8440 sbuf_printf(sb, "tcp6InErrs: %10u %10u %10u %10u\n",
8441 stats.tcp6_in_errs[0], stats.tcp6_in_errs[1],
8442 stats.tcp6_in_errs[2], stats.tcp6_in_errs[3]);
8443 sbuf_printf(sb, "tnlCongDrops: %10u %10u %10u %10u\n",
8444 stats.tnl_cong_drops[0], stats.tnl_cong_drops[1],
8445 stats.tnl_cong_drops[2], stats.tnl_cong_drops[3]);
8446 sbuf_printf(sb, "tnlTxDrops: %10u %10u %10u %10u\n",
8447 stats.tnl_tx_drops[0], stats.tnl_tx_drops[1],
8448 stats.tnl_tx_drops[2], stats.tnl_tx_drops[3]);
8449 sbuf_printf(sb, "ofldVlanDrops: %10u %10u %10u %10u\n",
8450 stats.ofld_vlan_drops[0], stats.ofld_vlan_drops[1],
8451 stats.ofld_vlan_drops[2], stats.ofld_vlan_drops[3]);
8452 sbuf_printf(sb, "ofldChanDrops: %10u %10u %10u %10u\n\n",
8453 stats.ofld_chan_drops[0], stats.ofld_chan_drops[1],
8454 stats.ofld_chan_drops[2], stats.ofld_chan_drops[3]);
8456 sbuf_printf(sb, " channel 0 channel 1\n");
8457 sbuf_printf(sb, "macInErrs: %10u %10u\n",
8458 stats.mac_in_errs[0], stats.mac_in_errs[1]);
8459 sbuf_printf(sb, "hdrInErrs: %10u %10u\n",
8460 stats.hdr_in_errs[0], stats.hdr_in_errs[1]);
8461 sbuf_printf(sb, "tcpInErrs: %10u %10u\n",
8462 stats.tcp_in_errs[0], stats.tcp_in_errs[1]);
8463 sbuf_printf(sb, "tcp6InErrs: %10u %10u\n",
8464 stats.tcp6_in_errs[0], stats.tcp6_in_errs[1]);
8465 sbuf_printf(sb, "tnlCongDrops: %10u %10u\n",
8466 stats.tnl_cong_drops[0], stats.tnl_cong_drops[1]);
8467 sbuf_printf(sb, "tnlTxDrops: %10u %10u\n",
8468 stats.tnl_tx_drops[0], stats.tnl_tx_drops[1]);
8469 sbuf_printf(sb, "ofldVlanDrops: %10u %10u\n",
8470 stats.ofld_vlan_drops[0], stats.ofld_vlan_drops[1]);
8471 sbuf_printf(sb, "ofldChanDrops: %10u %10u\n\n",
8472 stats.ofld_chan_drops[0], stats.ofld_chan_drops[1]);
8475 sbuf_printf(sb, "ofldNoNeigh: %u\nofldCongDefer: %u",
8476 stats.ofld_no_neigh, stats.ofld_cong_defer);
8478 rc = sbuf_finish(sb);
8485 sysctl_tp_la_mask(SYSCTL_HANDLER_ARGS)
8487 struct adapter *sc = arg1;
8488 struct tp_params *tpp = &sc->params.tp;
8492 mask = tpp->la_mask >> 16;
8493 rc = sysctl_handle_int(oidp, &mask, 0, req);
8494 if (rc != 0 || req->newptr == NULL)
8498 tpp->la_mask = mask << 16;
8499 t4_set_reg_field(sc, A_TP_DBG_LA_CONFIG, 0xffff0000U, tpp->la_mask);
8511 field_desc_show(struct sbuf *sb, uint64_t v, const struct field_desc *f)
8517 uint64_t mask = (1ULL << f->width) - 1;
8518 int len = snprintf(buf, sizeof(buf), "%s: %ju", f->name,
8519 ((uintmax_t)v >> f->start) & mask);
8521 if (line_size + len >= 79) {
8523 sbuf_printf(sb, "\n ");
8525 sbuf_printf(sb, "%s ", buf);
8526 line_size += len + 1;
8529 sbuf_printf(sb, "\n");
8532 static const struct field_desc tp_la0[] = {
8533 { "RcfOpCodeOut", 60, 4 },
8535 { "WcfState", 52, 4 },
8536 { "RcfOpcSrcOut", 50, 2 },
8537 { "CRxError", 49, 1 },
8538 { "ERxError", 48, 1 },
8539 { "SanityFailed", 47, 1 },
8540 { "SpuriousMsg", 46, 1 },
8541 { "FlushInputMsg", 45, 1 },
8542 { "FlushInputCpl", 44, 1 },
8543 { "RssUpBit", 43, 1 },
8544 { "RssFilterHit", 42, 1 },
8546 { "InitTcb", 31, 1 },
8547 { "LineNumber", 24, 7 },
8549 { "EdataOut", 22, 1 },
8551 { "CdataOut", 20, 1 },
8552 { "EreadPdu", 19, 1 },
8553 { "CreadPdu", 18, 1 },
8554 { "TunnelPkt", 17, 1 },
8555 { "RcfPeerFin", 16, 1 },
8556 { "RcfReasonOut", 12, 4 },
8557 { "TxCchannel", 10, 2 },
8558 { "RcfTxChannel", 8, 2 },
8559 { "RxEchannel", 6, 2 },
8560 { "RcfRxChannel", 5, 1 },
8561 { "RcfDataOutSrdy", 4, 1 },
8563 { "RxOoDvld", 2, 1 },
8564 { "RxCongestion", 1, 1 },
8565 { "TxCongestion", 0, 1 },
8569 static const struct field_desc tp_la1[] = {
8570 { "CplCmdIn", 56, 8 },
8571 { "CplCmdOut", 48, 8 },
8572 { "ESynOut", 47, 1 },
8573 { "EAckOut", 46, 1 },
8574 { "EFinOut", 45, 1 },
8575 { "ERstOut", 44, 1 },
8580 { "DataIn", 39, 1 },
8581 { "DataInVld", 38, 1 },
8583 { "RxBufEmpty", 36, 1 },
8585 { "RxFbCongestion", 34, 1 },
8586 { "TxFbCongestion", 33, 1 },
8587 { "TxPktSumSrdy", 32, 1 },
8588 { "RcfUlpType", 28, 4 },
8590 { "Ebypass", 26, 1 },
8592 { "Static0", 24, 1 },
8594 { "Cbypass", 22, 1 },
8596 { "CPktOut", 20, 1 },
8597 { "RxPagePoolFull", 18, 2 },
8598 { "RxLpbkPkt", 17, 1 },
8599 { "TxLpbkPkt", 16, 1 },
8600 { "RxVfValid", 15, 1 },
8601 { "SynLearned", 14, 1 },
8602 { "SetDelEntry", 13, 1 },
8603 { "SetInvEntry", 12, 1 },
8604 { "CpcmdDvld", 11, 1 },
8605 { "CpcmdSave", 10, 1 },
8606 { "RxPstructsFull", 8, 2 },
8607 { "EpcmdDvld", 7, 1 },
8608 { "EpcmdFlush", 6, 1 },
8609 { "EpcmdTrimPrefix", 5, 1 },
8610 { "EpcmdTrimPostfix", 4, 1 },
8611 { "ERssIp4Pkt", 3, 1 },
8612 { "ERssIp6Pkt", 2, 1 },
8613 { "ERssTcpUdpPkt", 1, 1 },
8614 { "ERssFceFipPkt", 0, 1 },
8618 static const struct field_desc tp_la2[] = {
8619 { "CplCmdIn", 56, 8 },
8620 { "MpsVfVld", 55, 1 },
8627 { "DataIn", 39, 1 },
8628 { "DataInVld", 38, 1 },
8630 { "RxBufEmpty", 36, 1 },
8632 { "RxFbCongestion", 34, 1 },
8633 { "TxFbCongestion", 33, 1 },
8634 { "TxPktSumSrdy", 32, 1 },
8635 { "RcfUlpType", 28, 4 },
8637 { "Ebypass", 26, 1 },
8639 { "Static0", 24, 1 },
8641 { "Cbypass", 22, 1 },
8643 { "CPktOut", 20, 1 },
8644 { "RxPagePoolFull", 18, 2 },
8645 { "RxLpbkPkt", 17, 1 },
8646 { "TxLpbkPkt", 16, 1 },
8647 { "RxVfValid", 15, 1 },
8648 { "SynLearned", 14, 1 },
8649 { "SetDelEntry", 13, 1 },
8650 { "SetInvEntry", 12, 1 },
8651 { "CpcmdDvld", 11, 1 },
8652 { "CpcmdSave", 10, 1 },
8653 { "RxPstructsFull", 8, 2 },
8654 { "EpcmdDvld", 7, 1 },
8655 { "EpcmdFlush", 6, 1 },
8656 { "EpcmdTrimPrefix", 5, 1 },
8657 { "EpcmdTrimPostfix", 4, 1 },
8658 { "ERssIp4Pkt", 3, 1 },
8659 { "ERssIp6Pkt", 2, 1 },
8660 { "ERssTcpUdpPkt", 1, 1 },
8661 { "ERssFceFipPkt", 0, 1 },
8666 tp_la_show(struct sbuf *sb, uint64_t *p, int idx)
8669 field_desc_show(sb, *p, tp_la0);
8673 tp_la_show2(struct sbuf *sb, uint64_t *p, int idx)
8677 sbuf_printf(sb, "\n");
8678 field_desc_show(sb, p[0], tp_la0);
8679 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
8680 field_desc_show(sb, p[1], tp_la0);
8684 tp_la_show3(struct sbuf *sb, uint64_t *p, int idx)
8688 sbuf_printf(sb, "\n");
8689 field_desc_show(sb, p[0], tp_la0);
8690 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
8691 field_desc_show(sb, p[1], (p[0] & (1 << 17)) ? tp_la2 : tp_la1);
8695 sysctl_tp_la(SYSCTL_HANDLER_ARGS)
8697 struct adapter *sc = arg1;
8702 void (*show_func)(struct sbuf *, uint64_t *, int);
8704 rc = sysctl_wire_old_buffer(req, 0);
8708 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8712 buf = malloc(TPLA_SIZE * sizeof(uint64_t), M_CXGBE, M_ZERO | M_WAITOK);
8714 t4_tp_read_la(sc, buf, NULL);
8717 switch (G_DBGLAMODE(t4_read_reg(sc, A_TP_DBG_LA_CONFIG))) {
8720 show_func = tp_la_show2;
8724 show_func = tp_la_show3;
8728 show_func = tp_la_show;
8731 for (i = 0; i < TPLA_SIZE / inc; i++, p += inc)
8732 (*show_func)(sb, p, i);
8734 rc = sbuf_finish(sb);
8741 sysctl_tx_rate(SYSCTL_HANDLER_ARGS)
8743 struct adapter *sc = arg1;
8746 u64 nrate[MAX_NCHAN], orate[MAX_NCHAN];
8748 rc = sysctl_wire_old_buffer(req, 0);
8752 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8756 t4_get_chan_txrate(sc, nrate, orate);
8758 if (sc->chip_params->nchan > 2) {
8759 sbuf_printf(sb, " channel 0 channel 1"
8760 " channel 2 channel 3\n");
8761 sbuf_printf(sb, "NIC B/s: %10ju %10ju %10ju %10ju\n",
8762 nrate[0], nrate[1], nrate[2], nrate[3]);
8763 sbuf_printf(sb, "Offload B/s: %10ju %10ju %10ju %10ju",
8764 orate[0], orate[1], orate[2], orate[3]);
8766 sbuf_printf(sb, " channel 0 channel 1\n");
8767 sbuf_printf(sb, "NIC B/s: %10ju %10ju\n",
8768 nrate[0], nrate[1]);
8769 sbuf_printf(sb, "Offload B/s: %10ju %10ju",
8770 orate[0], orate[1]);
8773 rc = sbuf_finish(sb);
8780 sysctl_ulprx_la(SYSCTL_HANDLER_ARGS)
8782 struct adapter *sc = arg1;
8787 rc = sysctl_wire_old_buffer(req, 0);
8791 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8795 buf = malloc(ULPRX_LA_SIZE * 8 * sizeof(uint32_t), M_CXGBE,
8798 t4_ulprx_read_la(sc, buf);
8801 sbuf_printf(sb, " Pcmd Type Message"
8803 for (i = 0; i < ULPRX_LA_SIZE; i++, p += 8) {
8804 sbuf_printf(sb, "\n%08x%08x %4x %08x %08x%08x%08x%08x",
8805 p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
8808 rc = sbuf_finish(sb);
8815 sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS)
8817 struct adapter *sc = arg1;
8821 MPASS(chip_id(sc) >= CHELSIO_T5);
8823 rc = sysctl_wire_old_buffer(req, 0);
8827 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8831 v = t4_read_reg(sc, A_SGE_STAT_CFG);
8832 if (G_STATSOURCE_T5(v) == 7) {
8835 mode = is_t5(sc) ? G_STATMODE(v) : G_T6_STATMODE(v);
8837 sbuf_printf(sb, "total %d, incomplete %d",
8838 t4_read_reg(sc, A_SGE_STAT_TOTAL),
8839 t4_read_reg(sc, A_SGE_STAT_MATCH));
8840 } else if (mode == 1) {
8841 sbuf_printf(sb, "total %d, data overflow %d",
8842 t4_read_reg(sc, A_SGE_STAT_TOTAL),
8843 t4_read_reg(sc, A_SGE_STAT_MATCH));
8845 sbuf_printf(sb, "unknown mode %d", mode);
8848 rc = sbuf_finish(sb);
8855 sysctl_cpus(SYSCTL_HANDLER_ARGS)
8857 struct adapter *sc = arg1;
8858 enum cpu_sets op = arg2;
8863 MPASS(op == LOCAL_CPUS || op == INTR_CPUS);
8866 rc = bus_get_cpus(sc->dev, op, sizeof(cpuset), &cpuset);
8870 rc = sysctl_wire_old_buffer(req, 0);
8874 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8879 sbuf_printf(sb, "%d ", i);
8880 rc = sbuf_finish(sb);
8888 sysctl_tls_rx_ports(SYSCTL_HANDLER_ARGS)
8890 struct adapter *sc = arg1;
8891 int *old_ports, *new_ports;
8892 int i, new_count, rc;
8894 if (req->newptr == NULL && req->oldptr == NULL)
8895 return (SYSCTL_OUT(req, NULL, imax(sc->tt.num_tls_rx_ports, 1) *
8896 sizeof(sc->tt.tls_rx_ports[0])));
8898 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4tlsrx");
8902 if (sc->tt.num_tls_rx_ports == 0) {
8904 rc = SYSCTL_OUT(req, &i, sizeof(i));
8906 rc = SYSCTL_OUT(req, sc->tt.tls_rx_ports,
8907 sc->tt.num_tls_rx_ports * sizeof(sc->tt.tls_rx_ports[0]));
8908 if (rc == 0 && req->newptr != NULL) {
8909 new_count = req->newlen / sizeof(new_ports[0]);
8910 new_ports = malloc(new_count * sizeof(new_ports[0]), M_CXGBE,
8912 rc = SYSCTL_IN(req, new_ports, new_count *
8913 sizeof(new_ports[0]));
8917 /* Allow setting to a single '-1' to clear the list. */
8918 if (new_count == 1 && new_ports[0] == -1) {
8920 old_ports = sc->tt.tls_rx_ports;
8921 sc->tt.tls_rx_ports = NULL;
8922 sc->tt.num_tls_rx_ports = 0;
8924 free(old_ports, M_CXGBE);
8926 for (i = 0; i < new_count; i++) {
8927 if (new_ports[i] < 1 ||
8928 new_ports[i] > IPPORT_MAX) {
8935 old_ports = sc->tt.tls_rx_ports;
8936 sc->tt.tls_rx_ports = new_ports;
8937 sc->tt.num_tls_rx_ports = new_count;
8939 free(old_ports, M_CXGBE);
8943 free(new_ports, M_CXGBE);
8945 end_synchronized_op(sc, 0);
8950 unit_conv(char *buf, size_t len, u_int val, u_int factor)
8952 u_int rem = val % factor;
8955 snprintf(buf, len, "%u", val / factor);
8957 while (rem % 10 == 0)
8959 snprintf(buf, len, "%u.%u", val / factor, rem);
8964 sysctl_tp_tick(SYSCTL_HANDLER_ARGS)
8966 struct adapter *sc = arg1;
8969 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk;
8971 res = t4_read_reg(sc, A_TP_TIMER_RESOLUTION);
8975 re = G_TIMERRESOLUTION(res);
8978 /* TCP timestamp tick */
8979 re = G_TIMESTAMPRESOLUTION(res);
8983 re = G_DELAYEDACKRESOLUTION(res);
8989 unit_conv(buf, sizeof(buf), (cclk_ps << re), 1000000);
8991 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
8995 sysctl_tp_dack_timer(SYSCTL_HANDLER_ARGS)
8997 struct adapter *sc = arg1;
8998 u_int res, dack_re, v;
8999 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk;
9001 res = t4_read_reg(sc, A_TP_TIMER_RESOLUTION);
9002 dack_re = G_DELAYEDACKRESOLUTION(res);
9003 v = ((cclk_ps << dack_re) / 1000000) * t4_read_reg(sc, A_TP_DACK_TIMER);
9005 return (sysctl_handle_int(oidp, &v, 0, req));
9009 sysctl_tp_timer(SYSCTL_HANDLER_ARGS)
9011 struct adapter *sc = arg1;
9014 u_long tp_tick_us, v;
9015 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk;
9017 MPASS(reg == A_TP_RXT_MIN || reg == A_TP_RXT_MAX ||
9018 reg == A_TP_PERS_MIN || reg == A_TP_PERS_MAX ||
9019 reg == A_TP_KEEP_IDLE || reg == A_TP_KEEP_INTVL ||
9020 reg == A_TP_INIT_SRTT || reg == A_TP_FINWAIT2_TIMER);
9022 tre = G_TIMERRESOLUTION(t4_read_reg(sc, A_TP_TIMER_RESOLUTION));
9023 tp_tick_us = (cclk_ps << tre) / 1000000;
9025 if (reg == A_TP_INIT_SRTT)
9026 v = tp_tick_us * G_INITSRTT(t4_read_reg(sc, reg));
9028 v = tp_tick_us * t4_read_reg(sc, reg);
9030 return (sysctl_handle_long(oidp, &v, 0, req));
9034 * All fields in TP_SHIFT_CNT are 4b and the starting location of the field is
9035 * passed to this function.
9038 sysctl_tp_shift_cnt(SYSCTL_HANDLER_ARGS)
9040 struct adapter *sc = arg1;
9044 MPASS(idx >= 0 && idx <= 24);
9046 v = (t4_read_reg(sc, A_TP_SHIFT_CNT) >> idx) & 0xf;
9048 return (sysctl_handle_int(oidp, &v, 0, req));
9052 sysctl_tp_backoff(SYSCTL_HANDLER_ARGS)
9054 struct adapter *sc = arg1;
9058 MPASS(idx >= 0 && idx < 16);
9060 r = A_TP_TCP_BACKOFF_REG0 + (idx & ~3);
9061 shift = (idx & 3) << 3;
9062 v = (t4_read_reg(sc, r) >> shift) & M_TIMERBACKOFFINDEX0;
9064 return (sysctl_handle_int(oidp, &v, 0, req));
9068 sysctl_holdoff_tmr_idx_ofld(SYSCTL_HANDLER_ARGS)
9070 struct vi_info *vi = arg1;
9071 struct adapter *sc = vi->pi->adapter;
9073 struct sge_ofld_rxq *ofld_rxq;
9076 idx = vi->ofld_tmr_idx;
9078 rc = sysctl_handle_int(oidp, &idx, 0, req);
9079 if (rc != 0 || req->newptr == NULL)
9082 if (idx < 0 || idx >= SGE_NTIMERS)
9085 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
9090 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(vi->ofld_pktc_idx != -1);
9091 for_each_ofld_rxq(vi, i, ofld_rxq) {
9092 #ifdef atomic_store_rel_8
9093 atomic_store_rel_8(&ofld_rxq->iq.intr_params, v);
9095 ofld_rxq->iq.intr_params = v;
9098 vi->ofld_tmr_idx = idx;
9100 end_synchronized_op(sc, LOCK_HELD);
9105 sysctl_holdoff_pktc_idx_ofld(SYSCTL_HANDLER_ARGS)
9107 struct vi_info *vi = arg1;
9108 struct adapter *sc = vi->pi->adapter;
9111 idx = vi->ofld_pktc_idx;
9113 rc = sysctl_handle_int(oidp, &idx, 0, req);
9114 if (rc != 0 || req->newptr == NULL)
9117 if (idx < -1 || idx >= SGE_NCOUNTERS)
9120 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
9125 if (vi->flags & VI_INIT_DONE)
9126 rc = EBUSY; /* cannot be changed once the queues are created */
9128 vi->ofld_pktc_idx = idx;
9130 end_synchronized_op(sc, LOCK_HELD);
9136 get_sge_context(struct adapter *sc, struct t4_sge_context *cntxt)
9140 if (cntxt->cid > M_CTXTQID)
9143 if (cntxt->mem_id != CTXT_EGRESS && cntxt->mem_id != CTXT_INGRESS &&
9144 cntxt->mem_id != CTXT_FLM && cntxt->mem_id != CTXT_CNM)
9147 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ctxt");
9151 if (sc->flags & FW_OK) {
9152 rc = -t4_sge_ctxt_rd(sc, sc->mbox, cntxt->cid, cntxt->mem_id,
9159 * Read via firmware failed or wasn't even attempted. Read directly via
9162 rc = -t4_sge_ctxt_rd_bd(sc, cntxt->cid, cntxt->mem_id, &cntxt->data[0]);
9164 end_synchronized_op(sc, 0);
9169 load_fw(struct adapter *sc, struct t4_data *fw)
9174 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldfw");
9179 * The firmware, with the sole exception of the memory parity error
9180 * handler, runs from memory and not flash. It is almost always safe to
9181 * install a new firmware on a running system. Just set bit 1 in
9182 * hw.cxgbe.dflags or dev.<nexus>.<n>.dflags first.
9184 if (sc->flags & FULL_INIT_DONE &&
9185 (sc->debug_flags & DF_LOAD_FW_ANYTIME) == 0) {
9190 fw_data = malloc(fw->len, M_CXGBE, M_WAITOK);
9191 if (fw_data == NULL) {
9196 rc = copyin(fw->data, fw_data, fw->len);
9198 rc = -t4_load_fw(sc, fw_data, fw->len);
9200 free(fw_data, M_CXGBE);
9202 end_synchronized_op(sc, 0);
9207 load_cfg(struct adapter *sc, struct t4_data *cfg)
9210 uint8_t *cfg_data = NULL;
9212 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldcf");
9216 if (cfg->len == 0) {
9218 rc = -t4_load_cfg(sc, NULL, 0);
9222 cfg_data = malloc(cfg->len, M_CXGBE, M_WAITOK);
9223 if (cfg_data == NULL) {
9228 rc = copyin(cfg->data, cfg_data, cfg->len);
9230 rc = -t4_load_cfg(sc, cfg_data, cfg->len);
9232 free(cfg_data, M_CXGBE);
9234 end_synchronized_op(sc, 0);
9239 load_boot(struct adapter *sc, struct t4_bootrom *br)
9242 uint8_t *br_data = NULL;
9245 if (br->len > 1024 * 1024)
9248 if (br->pf_offset == 0) {
9250 if (br->pfidx_addr > 7)
9252 offset = G_OFFSET(t4_read_reg(sc, PF_REG(br->pfidx_addr,
9253 A_PCIE_PF_EXPROM_OFST)));
9254 } else if (br->pf_offset == 1) {
9256 offset = G_OFFSET(br->pfidx_addr);
9261 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldbr");
9267 rc = -t4_load_boot(sc, NULL, offset, 0);
9271 br_data = malloc(br->len, M_CXGBE, M_WAITOK);
9272 if (br_data == NULL) {
9277 rc = copyin(br->data, br_data, br->len);
9279 rc = -t4_load_boot(sc, br_data, offset, br->len);
9281 free(br_data, M_CXGBE);
9283 end_synchronized_op(sc, 0);
9288 load_bootcfg(struct adapter *sc, struct t4_data *bc)
9291 uint8_t *bc_data = NULL;
9293 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldcf");
9299 rc = -t4_load_bootcfg(sc, NULL, 0);
9303 bc_data = malloc(bc->len, M_CXGBE, M_WAITOK);
9304 if (bc_data == NULL) {
9309 rc = copyin(bc->data, bc_data, bc->len);
9311 rc = -t4_load_bootcfg(sc, bc_data, bc->len);
9313 free(bc_data, M_CXGBE);
9315 end_synchronized_op(sc, 0);
9320 cudbg_dump(struct adapter *sc, struct t4_cudbg_dump *dump)
9323 struct cudbg_init *cudbg;
9326 /* buf is large, don't block if no memory is available */
9327 buf = malloc(dump->len, M_CXGBE, M_NOWAIT | M_ZERO);
9331 handle = cudbg_alloc_handle();
9332 if (handle == NULL) {
9337 cudbg = cudbg_get_init(handle);
9339 cudbg->print = (cudbg_print_cb)printf;
9342 device_printf(sc->dev, "%s: wr_flash %u, len %u, data %p.\n",
9343 __func__, dump->wr_flash, dump->len, dump->data);
9347 cudbg->use_flash = 1;
9348 MPASS(sizeof(cudbg->dbg_bitmap) == sizeof(dump->bitmap));
9349 memcpy(cudbg->dbg_bitmap, dump->bitmap, sizeof(cudbg->dbg_bitmap));
9351 rc = cudbg_collect(handle, buf, &dump->len);
9355 rc = copyout(buf, dump->data, dump->len);
9357 cudbg_free_handle(handle);
9363 free_offload_policy(struct t4_offload_policy *op)
9365 struct offload_rule *r;
9372 for (i = 0; i < op->nrules; i++, r++) {
9373 free(r->bpf_prog.bf_insns, M_CXGBE);
9375 free(op->rule, M_CXGBE);
9380 set_offload_policy(struct adapter *sc, struct t4_offload_policy *uop)
9383 struct t4_offload_policy *op, *old;
9384 struct bpf_program *bf;
9385 const struct offload_settings *s;
9386 struct offload_rule *r;
9389 if (!is_offload(sc))
9392 if (uop->nrules == 0) {
9393 /* Delete installed policies. */
9396 } if (uop->nrules > 256) { /* arbitrary */
9400 /* Copy userspace offload policy to kernel */
9401 op = malloc(sizeof(*op), M_CXGBE, M_ZERO | M_WAITOK);
9402 op->nrules = uop->nrules;
9403 len = op->nrules * sizeof(struct offload_rule);
9404 op->rule = malloc(len, M_CXGBE, M_ZERO | M_WAITOK);
9405 rc = copyin(uop->rule, op->rule, len);
9407 free(op->rule, M_CXGBE);
9413 for (i = 0; i < op->nrules; i++, r++) {
9415 /* Validate open_type */
9416 if (r->open_type != OPEN_TYPE_LISTEN &&
9417 r->open_type != OPEN_TYPE_ACTIVE &&
9418 r->open_type != OPEN_TYPE_PASSIVE &&
9419 r->open_type != OPEN_TYPE_DONTCARE) {
9422 * Rules 0 to i have malloc'd filters that need to be
9423 * freed. Rules i+1 to nrules have userspace pointers
9424 * and should be left alone.
9427 free_offload_policy(op);
9431 /* Validate settings */
9433 if ((s->offload != 0 && s->offload != 1) ||
9434 s->cong_algo < -1 || s->cong_algo > CONG_ALG_HIGHSPEED ||
9435 s->sched_class < -1 ||
9436 s->sched_class >= sc->chip_params->nsched_cls) {
9442 u = bf->bf_insns; /* userspace ptr */
9443 bf->bf_insns = NULL;
9444 if (bf->bf_len == 0) {
9445 /* legal, matches everything */
9448 len = bf->bf_len * sizeof(*bf->bf_insns);
9449 bf->bf_insns = malloc(len, M_CXGBE, M_ZERO | M_WAITOK);
9450 rc = copyin(u, bf->bf_insns, len);
9454 if (!bpf_validate(bf->bf_insns, bf->bf_len)) {
9460 rw_wlock(&sc->policy_lock);
9463 rw_wunlock(&sc->policy_lock);
9464 free_offload_policy(old);
9469 #define MAX_READ_BUF_SIZE (128 * 1024)
9471 read_card_mem(struct adapter *sc, int win, struct t4_mem_range *mr)
9473 uint32_t addr, remaining, n;
9478 rc = validate_mem_range(sc, mr->addr, mr->len);
9482 buf = malloc(min(mr->len, MAX_READ_BUF_SIZE), M_CXGBE, M_WAITOK);
9484 remaining = mr->len;
9485 dst = (void *)mr->data;
9488 n = min(remaining, MAX_READ_BUF_SIZE);
9489 read_via_memwin(sc, 2, addr, buf, n);
9491 rc = copyout(buf, dst, n);
9503 #undef MAX_READ_BUF_SIZE
9506 read_i2c(struct adapter *sc, struct t4_i2c_data *i2cd)
9510 if (i2cd->len == 0 || i2cd->port_id >= sc->params.nports)
9513 if (i2cd->len > sizeof(i2cd->data))
9516 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4i2crd");
9519 rc = -t4_i2c_rd(sc, sc->mbox, i2cd->port_id, i2cd->dev_addr,
9520 i2cd->offset, i2cd->len, &i2cd->data[0]);
9521 end_synchronized_op(sc, 0);
9527 t4_os_find_pci_capability(struct adapter *sc, int cap)
9531 return (pci_find_cap(sc->dev, cap, &i) == 0 ? i : 0);
9535 t4_os_pci_save_state(struct adapter *sc)
9538 struct pci_devinfo *dinfo;
9541 dinfo = device_get_ivars(dev);
9543 pci_cfg_save(dev, dinfo, 0);
9548 t4_os_pci_restore_state(struct adapter *sc)
9551 struct pci_devinfo *dinfo;
9554 dinfo = device_get_ivars(dev);
9556 pci_cfg_restore(dev, dinfo);
9561 t4_os_portmod_changed(struct port_info *pi)
9563 struct adapter *sc = pi->adapter;
9566 static const char *mod_str[] = {
9567 NULL, "LR", "SR", "ER", "TWINAX", "active TWINAX", "LRM"
9570 KASSERT((pi->flags & FIXED_IFMEDIA) == 0,
9571 ("%s: port_type %u", __func__, pi->port_type));
9574 if (begin_synchronized_op(sc, vi, HOLD_LOCK, "t4mod") == 0) {
9576 build_medialist(pi);
9577 if (pi->mod_type != FW_PORT_MOD_TYPE_NONE) {
9578 fixup_link_config(pi);
9579 apply_link_config(pi);
9582 end_synchronized_op(sc, LOCK_HELD);
9586 if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
9587 if_printf(ifp, "transceiver unplugged.\n");
9588 else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
9589 if_printf(ifp, "unknown transceiver inserted.\n");
9590 else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
9591 if_printf(ifp, "unsupported transceiver inserted.\n");
9592 else if (pi->mod_type > 0 && pi->mod_type < nitems(mod_str)) {
9593 if_printf(ifp, "%dGbps %s transceiver inserted.\n",
9594 port_top_speed(pi), mod_str[pi->mod_type]);
9596 if_printf(ifp, "transceiver (type %d) inserted.\n",
9602 t4_os_link_changed(struct port_info *pi)
9606 struct link_config *lc;
9609 PORT_LOCK_ASSERT_OWNED(pi);
9611 for_each_vi(pi, v, vi) {
9618 ifp->if_baudrate = IF_Mbps(lc->speed);
9619 if_link_state_change(ifp, LINK_STATE_UP);
9621 if_link_state_change(ifp, LINK_STATE_DOWN);
9627 t4_iterate(void (*func)(struct adapter *, void *), void *arg)
9631 sx_slock(&t4_list_lock);
9632 SLIST_FOREACH(sc, &t4_list, link) {
9634 * func should not make any assumptions about what state sc is
9635 * in - the only guarantee is that sc->sc_lock is a valid lock.
9639 sx_sunlock(&t4_list_lock);
9643 t4_ioctl(struct cdev *dev, unsigned long cmd, caddr_t data, int fflag,
9647 struct adapter *sc = dev->si_drv1;
9649 rc = priv_check(td, PRIV_DRIVER);
9654 case CHELSIO_T4_GETREG: {
9655 struct t4_reg *edata = (struct t4_reg *)data;
9657 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
9660 if (edata->size == 4)
9661 edata->val = t4_read_reg(sc, edata->addr);
9662 else if (edata->size == 8)
9663 edata->val = t4_read_reg64(sc, edata->addr);
9669 case CHELSIO_T4_SETREG: {
9670 struct t4_reg *edata = (struct t4_reg *)data;
9672 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
9675 if (edata->size == 4) {
9676 if (edata->val & 0xffffffff00000000)
9678 t4_write_reg(sc, edata->addr, (uint32_t) edata->val);
9679 } else if (edata->size == 8)
9680 t4_write_reg64(sc, edata->addr, edata->val);
9685 case CHELSIO_T4_REGDUMP: {
9686 struct t4_regdump *regs = (struct t4_regdump *)data;
9687 int reglen = t4_get_regs_len(sc);
9690 if (regs->len < reglen) {
9691 regs->len = reglen; /* hint to the caller */
9696 buf = malloc(reglen, M_CXGBE, M_WAITOK | M_ZERO);
9697 get_regs(sc, regs, buf);
9698 rc = copyout(buf, regs->data, reglen);
9702 case CHELSIO_T4_GET_FILTER_MODE:
9703 rc = get_filter_mode(sc, (uint32_t *)data);
9705 case CHELSIO_T4_SET_FILTER_MODE:
9706 rc = set_filter_mode(sc, *(uint32_t *)data);
9708 case CHELSIO_T4_GET_FILTER:
9709 rc = get_filter(sc, (struct t4_filter *)data);
9711 case CHELSIO_T4_SET_FILTER:
9712 rc = set_filter(sc, (struct t4_filter *)data);
9714 case CHELSIO_T4_DEL_FILTER:
9715 rc = del_filter(sc, (struct t4_filter *)data);
9717 case CHELSIO_T4_GET_SGE_CONTEXT:
9718 rc = get_sge_context(sc, (struct t4_sge_context *)data);
9720 case CHELSIO_T4_LOAD_FW:
9721 rc = load_fw(sc, (struct t4_data *)data);
9723 case CHELSIO_T4_GET_MEM:
9724 rc = read_card_mem(sc, 2, (struct t4_mem_range *)data);
9726 case CHELSIO_T4_GET_I2C:
9727 rc = read_i2c(sc, (struct t4_i2c_data *)data);
9729 case CHELSIO_T4_CLEAR_STATS: {
9731 u_int port_id = *(uint32_t *)data;
9732 struct port_info *pi;
9735 if (port_id >= sc->params.nports)
9737 pi = sc->port[port_id];
9742 t4_clr_port_stats(sc, pi->tx_chan);
9743 pi->tx_parse_error = 0;
9744 pi->tnl_cong_drops = 0;
9745 mtx_lock(&sc->reg_lock);
9746 for_each_vi(pi, v, vi) {
9747 if (vi->flags & VI_INIT_DONE)
9748 t4_clr_vi_stats(sc, vi->viid);
9750 bg_map = pi->mps_bg_map;
9753 i = ffs(bg_map) - 1;
9754 t4_write_indirect(sc, A_TP_MIB_INDEX, A_TP_MIB_DATA, &v,
9755 1, A_TP_MIB_TNL_CNG_DROP_0 + i);
9756 bg_map &= ~(1 << i);
9758 mtx_unlock(&sc->reg_lock);
9761 * Since this command accepts a port, clear stats for
9762 * all VIs on this port.
9764 for_each_vi(pi, v, vi) {
9765 if (vi->flags & VI_INIT_DONE) {
9766 struct sge_rxq *rxq;
9767 struct sge_txq *txq;
9768 struct sge_wrq *wrq;
9770 for_each_rxq(vi, i, rxq) {
9771 #if defined(INET) || defined(INET6)
9772 rxq->lro.lro_queued = 0;
9773 rxq->lro.lro_flushed = 0;
9776 rxq->vlan_extraction = 0;
9779 for_each_txq(vi, i, txq) {
9782 txq->vlan_insertion = 0;
9786 txq->txpkts0_wrs = 0;
9787 txq->txpkts1_wrs = 0;
9788 txq->txpkts0_pkts = 0;
9789 txq->txpkts1_pkts = 0;
9790 mp_ring_reset_stats(txq->r);
9794 /* nothing to clear for each ofld_rxq */
9796 for_each_ofld_txq(vi, i, wrq) {
9797 wrq->tx_wrs_direct = 0;
9798 wrq->tx_wrs_copied = 0;
9802 if (IS_MAIN_VI(vi)) {
9803 wrq = &sc->sge.ctrlq[pi->port_id];
9804 wrq->tx_wrs_direct = 0;
9805 wrq->tx_wrs_copied = 0;
9811 case CHELSIO_T4_SCHED_CLASS:
9812 rc = t4_set_sched_class(sc, (struct t4_sched_params *)data);
9814 case CHELSIO_T4_SCHED_QUEUE:
9815 rc = t4_set_sched_queue(sc, (struct t4_sched_queue *)data);
9817 case CHELSIO_T4_GET_TRACER:
9818 rc = t4_get_tracer(sc, (struct t4_tracer *)data);
9820 case CHELSIO_T4_SET_TRACER:
9821 rc = t4_set_tracer(sc, (struct t4_tracer *)data);
9823 case CHELSIO_T4_LOAD_CFG:
9824 rc = load_cfg(sc, (struct t4_data *)data);
9826 case CHELSIO_T4_LOAD_BOOT:
9827 rc = load_boot(sc, (struct t4_bootrom *)data);
9829 case CHELSIO_T4_LOAD_BOOTCFG:
9830 rc = load_bootcfg(sc, (struct t4_data *)data);
9832 case CHELSIO_T4_CUDBG_DUMP:
9833 rc = cudbg_dump(sc, (struct t4_cudbg_dump *)data);
9835 case CHELSIO_T4_SET_OFLD_POLICY:
9836 rc = set_offload_policy(sc, (struct t4_offload_policy *)data);
9846 t4_db_full(struct adapter *sc)
9849 CXGBE_UNIMPLEMENTED(__func__);
9853 t4_db_dropped(struct adapter *sc)
9856 CXGBE_UNIMPLEMENTED(__func__);
9861 toe_capability(struct vi_info *vi, int enable)
9864 struct port_info *pi = vi->pi;
9865 struct adapter *sc = pi->adapter;
9867 ASSERT_SYNCHRONIZED_OP(sc);
9869 if (!is_offload(sc))
9873 if ((vi->ifp->if_capenable & IFCAP_TOE) != 0) {
9874 /* TOE is already enabled. */
9879 * We need the port's queues around so that we're able to send
9880 * and receive CPLs to/from the TOE even if the ifnet for this
9881 * port has never been UP'd administratively.
9883 if (!(vi->flags & VI_INIT_DONE)) {
9884 rc = vi_full_init(vi);
9888 if (!(pi->vi[0].flags & VI_INIT_DONE)) {
9889 rc = vi_full_init(&pi->vi[0]);
9894 if (isset(&sc->offload_map, pi->port_id)) {
9895 /* TOE is enabled on another VI of this port. */
9900 if (!uld_active(sc, ULD_TOM)) {
9901 rc = t4_activate_uld(sc, ULD_TOM);
9904 "You must kldload t4_tom.ko before trying "
9905 "to enable TOE on a cxgbe interface.\n");
9909 KASSERT(sc->tom_softc != NULL,
9910 ("%s: TOM activated but softc NULL", __func__));
9911 KASSERT(uld_active(sc, ULD_TOM),
9912 ("%s: TOM activated but flag not set", __func__));
9915 /* Activate iWARP and iSCSI too, if the modules are loaded. */
9916 if (!uld_active(sc, ULD_IWARP))
9917 (void) t4_activate_uld(sc, ULD_IWARP);
9918 if (!uld_active(sc, ULD_ISCSI))
9919 (void) t4_activate_uld(sc, ULD_ISCSI);
9922 setbit(&sc->offload_map, pi->port_id);
9926 if (!isset(&sc->offload_map, pi->port_id) || pi->uld_vis > 0)
9929 KASSERT(uld_active(sc, ULD_TOM),
9930 ("%s: TOM never initialized?", __func__));
9931 clrbit(&sc->offload_map, pi->port_id);
9938 * Add an upper layer driver to the global list.
9941 t4_register_uld(struct uld_info *ui)
9946 sx_xlock(&t4_uld_list_lock);
9947 SLIST_FOREACH(u, &t4_uld_list, link) {
9948 if (u->uld_id == ui->uld_id) {
9954 SLIST_INSERT_HEAD(&t4_uld_list, ui, link);
9957 sx_xunlock(&t4_uld_list_lock);
9962 t4_unregister_uld(struct uld_info *ui)
9967 sx_xlock(&t4_uld_list_lock);
9969 SLIST_FOREACH(u, &t4_uld_list, link) {
9971 if (ui->refcount > 0) {
9976 SLIST_REMOVE(&t4_uld_list, ui, uld_info, link);
9982 sx_xunlock(&t4_uld_list_lock);
9987 t4_activate_uld(struct adapter *sc, int id)
9990 struct uld_info *ui;
9992 ASSERT_SYNCHRONIZED_OP(sc);
9994 if (id < 0 || id > ULD_MAX)
9996 rc = EAGAIN; /* kldoad the module with this ULD and try again. */
9998 sx_slock(&t4_uld_list_lock);
10000 SLIST_FOREACH(ui, &t4_uld_list, link) {
10001 if (ui->uld_id == id) {
10002 if (!(sc->flags & FULL_INIT_DONE)) {
10003 rc = adapter_full_init(sc);
10008 rc = ui->activate(sc);
10010 setbit(&sc->active_ulds, id);
10017 sx_sunlock(&t4_uld_list_lock);
10023 t4_deactivate_uld(struct adapter *sc, int id)
10026 struct uld_info *ui;
10028 ASSERT_SYNCHRONIZED_OP(sc);
10030 if (id < 0 || id > ULD_MAX)
10034 sx_slock(&t4_uld_list_lock);
10036 SLIST_FOREACH(ui, &t4_uld_list, link) {
10037 if (ui->uld_id == id) {
10038 rc = ui->deactivate(sc);
10040 clrbit(&sc->active_ulds, id);
10047 sx_sunlock(&t4_uld_list_lock);
10053 uld_active(struct adapter *sc, int uld_id)
10056 MPASS(uld_id >= 0 && uld_id <= ULD_MAX);
10058 return (isset(&sc->active_ulds, uld_id));
10063 * t = ptr to tunable.
10064 * nc = number of CPUs.
10065 * c = compiled in default for that tunable.
10068 calculate_nqueues(int *t, int nc, const int c)
10074 nq = *t < 0 ? -*t : c;
10079 * Come up with reasonable defaults for some of the tunables, provided they're
10080 * not set by the user (in which case we'll use the values as is).
10083 tweak_tunables(void)
10085 int nc = mp_ncpus; /* our snapshot of the number of CPUs */
10089 t4_ntxq = rss_getnumbuckets();
10091 calculate_nqueues(&t4_ntxq, nc, NTXQ);
10095 calculate_nqueues(&t4_ntxq_vi, nc, NTXQ_VI);
10099 t4_nrxq = rss_getnumbuckets();
10101 calculate_nqueues(&t4_nrxq, nc, NRXQ);
10105 calculate_nqueues(&t4_nrxq_vi, nc, NRXQ_VI);
10107 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
10108 calculate_nqueues(&t4_nofldtxq, nc, NOFLDTXQ);
10109 calculate_nqueues(&t4_nofldtxq_vi, nc, NOFLDTXQ_VI);
10112 calculate_nqueues(&t4_nofldrxq, nc, NOFLDRXQ);
10113 calculate_nqueues(&t4_nofldrxq_vi, nc, NOFLDRXQ_VI);
10115 if (t4_toecaps_allowed == -1)
10116 t4_toecaps_allowed = FW_CAPS_CONFIG_TOE;
10118 if (t4_rdmacaps_allowed == -1) {
10119 t4_rdmacaps_allowed = FW_CAPS_CONFIG_RDMA_RDDP |
10120 FW_CAPS_CONFIG_RDMA_RDMAC;
10123 if (t4_iscsicaps_allowed == -1) {
10124 t4_iscsicaps_allowed = FW_CAPS_CONFIG_ISCSI_INITIATOR_PDU |
10125 FW_CAPS_CONFIG_ISCSI_TARGET_PDU |
10126 FW_CAPS_CONFIG_ISCSI_T10DIF;
10129 if (t4_tmr_idx_ofld < 0 || t4_tmr_idx_ofld >= SGE_NTIMERS)
10130 t4_tmr_idx_ofld = TMR_IDX_OFLD;
10132 if (t4_pktc_idx_ofld < -1 || t4_pktc_idx_ofld >= SGE_NCOUNTERS)
10133 t4_pktc_idx_ofld = PKTC_IDX_OFLD;
10135 if (t4_toecaps_allowed == -1)
10136 t4_toecaps_allowed = 0;
10138 if (t4_rdmacaps_allowed == -1)
10139 t4_rdmacaps_allowed = 0;
10141 if (t4_iscsicaps_allowed == -1)
10142 t4_iscsicaps_allowed = 0;
10146 calculate_nqueues(&t4_nnmtxq_vi, nc, NNMTXQ_VI);
10147 calculate_nqueues(&t4_nnmrxq_vi, nc, NNMRXQ_VI);
10150 if (t4_tmr_idx < 0 || t4_tmr_idx >= SGE_NTIMERS)
10151 t4_tmr_idx = TMR_IDX;
10153 if (t4_pktc_idx < -1 || t4_pktc_idx >= SGE_NCOUNTERS)
10154 t4_pktc_idx = PKTC_IDX;
10156 if (t4_qsize_txq < 128)
10157 t4_qsize_txq = 128;
10159 if (t4_qsize_rxq < 128)
10160 t4_qsize_rxq = 128;
10161 while (t4_qsize_rxq & 7)
10164 t4_intr_types &= INTR_MSIX | INTR_MSI | INTR_INTX;
10167 * Number of VIs to create per-port. The first VI is the "main" regular
10168 * VI for the port. The rest are additional virtual interfaces on the
10169 * same physical port. Note that the main VI does not have native
10170 * netmap support but the extra VIs do.
10172 * Limit the number of VIs per port to the number of available
10173 * MAC addresses per port.
10175 if (t4_num_vis < 1)
10177 if (t4_num_vis > nitems(vi_mac_funcs)) {
10178 t4_num_vis = nitems(vi_mac_funcs);
10179 printf("cxgbe: number of VIs limited to %d\n", t4_num_vis);
10182 if (pcie_relaxed_ordering < 0 || pcie_relaxed_ordering > 2) {
10183 pcie_relaxed_ordering = 1;
10184 #if defined(__i386__) || defined(__amd64__)
10185 if (cpu_vendor_id == CPU_VENDOR_INTEL)
10186 pcie_relaxed_ordering = 0;
10193 t4_dump_tcb(struct adapter *sc, int tid)
10195 uint32_t base, i, j, off, pf, reg, save, tcb_addr, win_pos;
10197 reg = PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, 2);
10198 save = t4_read_reg(sc, reg);
10199 base = sc->memwin[2].mw_base;
10201 /* Dump TCB for the tid */
10202 tcb_addr = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
10203 tcb_addr += tid * TCB_SIZE;
10207 win_pos = tcb_addr & ~0xf; /* start must be 16B aligned */
10209 pf = V_PFNUM(sc->pf);
10210 win_pos = tcb_addr & ~0x7f; /* start must be 128B aligned */
10212 t4_write_reg(sc, reg, win_pos | pf);
10213 t4_read_reg(sc, reg);
10215 off = tcb_addr - win_pos;
10216 for (i = 0; i < 4; i++) {
10218 for (j = 0; j < 8; j++, off += 4)
10219 buf[j] = htonl(t4_read_reg(sc, base + off));
10221 db_printf("%08x %08x %08x %08x %08x %08x %08x %08x\n",
10222 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
10226 t4_write_reg(sc, reg, save);
10227 t4_read_reg(sc, reg);
10231 t4_dump_devlog(struct adapter *sc)
10233 struct devlog_params *dparams = &sc->params.devlog;
10234 struct fw_devlog_e e;
10235 int i, first, j, m, nentries, rc;
10236 uint64_t ftstamp = UINT64_MAX;
10238 if (dparams->start == 0) {
10239 db_printf("devlog params not valid\n");
10243 nentries = dparams->size / sizeof(struct fw_devlog_e);
10244 m = fwmtype_to_hwmtype(dparams->memtype);
10246 /* Find the first entry. */
10248 for (i = 0; i < nentries && !db_pager_quit; i++) {
10249 rc = -t4_mem_read(sc, m, dparams->start + i * sizeof(e),
10250 sizeof(e), (void *)&e);
10254 if (e.timestamp == 0)
10257 e.timestamp = be64toh(e.timestamp);
10258 if (e.timestamp < ftstamp) {
10259 ftstamp = e.timestamp;
10269 rc = -t4_mem_read(sc, m, dparams->start + i * sizeof(e),
10270 sizeof(e), (void *)&e);
10274 if (e.timestamp == 0)
10277 e.timestamp = be64toh(e.timestamp);
10278 e.seqno = be32toh(e.seqno);
10279 for (j = 0; j < 8; j++)
10280 e.params[j] = be32toh(e.params[j]);
10282 db_printf("%10d %15ju %8s %8s ",
10283 e.seqno, e.timestamp,
10284 (e.level < nitems(devlog_level_strings) ?
10285 devlog_level_strings[e.level] : "UNKNOWN"),
10286 (e.facility < nitems(devlog_facility_strings) ?
10287 devlog_facility_strings[e.facility] : "UNKNOWN"));
10288 db_printf(e.fmt, e.params[0], e.params[1], e.params[2],
10289 e.params[3], e.params[4], e.params[5], e.params[6],
10292 if (++i == nentries)
10294 } while (i != first && !db_pager_quit);
10297 static struct command_table db_t4_table = LIST_HEAD_INITIALIZER(db_t4_table);
10298 _DB_SET(_show, t4, NULL, db_show_table, 0, &db_t4_table);
10300 DB_FUNC(devlog, db_show_devlog, db_t4_table, CS_OWN, NULL)
10307 t = db_read_token();
10309 dev = device_lookup_by_name(db_tok_string);
10314 db_printf("usage: show t4 devlog <nexus>\n");
10319 db_printf("device not found\n");
10323 t4_dump_devlog(device_get_softc(dev));
10326 DB_FUNC(tcb, db_show_t4tcb, db_t4_table, CS_OWN, NULL)
10335 t = db_read_token();
10337 dev = device_lookup_by_name(db_tok_string);
10338 t = db_read_token();
10339 if (t == tNUMBER) {
10340 tid = db_tok_number;
10347 db_printf("usage: show t4 tcb <nexus> <tid>\n");
10352 db_printf("device not found\n");
10356 db_printf("invalid tid\n");
10360 t4_dump_tcb(device_get_softc(dev), tid);
10365 * Borrowed from cesa_prep_aes_key().
10367 * NB: The crypto engine wants the words in the decryption key in reverse
10371 t4_aes_getdeckey(void *dec_key, const void *enc_key, unsigned int kbits)
10373 uint32_t ek[4 * (RIJNDAEL_MAXNR + 1)];
10377 rijndaelKeySetupEnc(ek, enc_key, kbits);
10379 dkey += (kbits / 8) / 4;
10383 for (i = 0; i < 4; i++)
10384 *--dkey = htobe32(ek[4 * 10 + i]);
10387 for (i = 0; i < 2; i++)
10388 *--dkey = htobe32(ek[4 * 11 + 2 + i]);
10389 for (i = 0; i < 4; i++)
10390 *--dkey = htobe32(ek[4 * 12 + i]);
10393 for (i = 0; i < 4; i++)
10394 *--dkey = htobe32(ek[4 * 13 + i]);
10395 for (i = 0; i < 4; i++)
10396 *--dkey = htobe32(ek[4 * 14 + i]);
10399 MPASS(dkey == dec_key);
10402 static struct sx mlu; /* mod load unload */
10403 SX_SYSINIT(cxgbe_mlu, &mlu, "cxgbe mod load/unload");
10406 mod_event(module_t mod, int cmd, void *arg)
10409 static int loaded = 0;
10414 if (loaded++ == 0) {
10416 t4_register_shared_cpl_handler(CPL_SET_TCB_RPL,
10417 t4_filter_rpl, CPL_COOKIE_FILTER);
10418 t4_register_shared_cpl_handler(CPL_L2T_WRITE_RPL,
10419 do_l2t_write_rpl, CPL_COOKIE_FILTER);
10420 t4_register_shared_cpl_handler(CPL_ACT_OPEN_RPL,
10421 t4_hashfilter_ao_rpl, CPL_COOKIE_HASHFILTER);
10422 t4_register_shared_cpl_handler(CPL_SET_TCB_RPL,
10423 t4_hashfilter_tcb_rpl, CPL_COOKIE_HASHFILTER);
10424 t4_register_shared_cpl_handler(CPL_ABORT_RPL_RSS,
10425 t4_del_hashfilter_rpl, CPL_COOKIE_HASHFILTER);
10426 t4_register_cpl_handler(CPL_TRACE_PKT, t4_trace_pkt);
10427 t4_register_cpl_handler(CPL_T5_TRACE_PKT, t5_trace_pkt);
10428 t4_register_cpl_handler(CPL_SMT_WRITE_RPL,
10430 sx_init(&t4_list_lock, "T4/T5 adapters");
10431 SLIST_INIT(&t4_list);
10433 sx_init(&t4_uld_list_lock, "T4/T5 ULDs");
10434 SLIST_INIT(&t4_uld_list);
10436 t4_tracer_modload();
10444 if (--loaded == 0) {
10447 sx_slock(&t4_list_lock);
10448 if (!SLIST_EMPTY(&t4_list)) {
10450 sx_sunlock(&t4_list_lock);
10454 sx_slock(&t4_uld_list_lock);
10455 if (!SLIST_EMPTY(&t4_uld_list)) {
10457 sx_sunlock(&t4_uld_list_lock);
10458 sx_sunlock(&t4_list_lock);
10463 while (tries++ < 5 && t4_sge_extfree_refs() != 0) {
10464 uprintf("%ju clusters with custom free routine "
10465 "still is use.\n", t4_sge_extfree_refs());
10466 pause("t4unload", 2 * hz);
10469 sx_sunlock(&t4_uld_list_lock);
10471 sx_sunlock(&t4_list_lock);
10473 if (t4_sge_extfree_refs() == 0) {
10474 t4_tracer_modunload();
10476 sx_destroy(&t4_uld_list_lock);
10478 sx_destroy(&t4_list_lock);
10479 t4_sge_modunload();
10483 loaded++; /* undo earlier decrement */
10494 static devclass_t t4_devclass, t5_devclass, t6_devclass;
10495 static devclass_t cxgbe_devclass, cxl_devclass, cc_devclass;
10496 static devclass_t vcxgbe_devclass, vcxl_devclass, vcc_devclass;
10498 DRIVER_MODULE(t4nex, pci, t4_driver, t4_devclass, mod_event, 0);
10499 MODULE_VERSION(t4nex, 1);
10500 MODULE_DEPEND(t4nex, firmware, 1, 1, 1);
10502 MODULE_DEPEND(t4nex, netmap, 1, 1, 1);
10503 #endif /* DEV_NETMAP */
10505 DRIVER_MODULE(t5nex, pci, t5_driver, t5_devclass, mod_event, 0);
10506 MODULE_VERSION(t5nex, 1);
10507 MODULE_DEPEND(t5nex, firmware, 1, 1, 1);
10509 MODULE_DEPEND(t5nex, netmap, 1, 1, 1);
10510 #endif /* DEV_NETMAP */
10512 DRIVER_MODULE(t6nex, pci, t6_driver, t6_devclass, mod_event, 0);
10513 MODULE_VERSION(t6nex, 1);
10514 MODULE_DEPEND(t6nex, firmware, 1, 1, 1);
10516 MODULE_DEPEND(t6nex, netmap, 1, 1, 1);
10517 #endif /* DEV_NETMAP */
10519 DRIVER_MODULE(cxgbe, t4nex, cxgbe_driver, cxgbe_devclass, 0, 0);
10520 MODULE_VERSION(cxgbe, 1);
10522 DRIVER_MODULE(cxl, t5nex, cxl_driver, cxl_devclass, 0, 0);
10523 MODULE_VERSION(cxl, 1);
10525 DRIVER_MODULE(cc, t6nex, cc_driver, cc_devclass, 0, 0);
10526 MODULE_VERSION(cc, 1);
10528 DRIVER_MODULE(vcxgbe, cxgbe, vcxgbe_driver, vcxgbe_devclass, 0, 0);
10529 MODULE_VERSION(vcxgbe, 1);
10531 DRIVER_MODULE(vcxl, cxl, vcxl_driver, vcxl_devclass, 0, 0);
10532 MODULE_VERSION(vcxl, 1);
10534 DRIVER_MODULE(vcc, cc, vcc_driver, vcc_devclass, 0, 0);
10535 MODULE_VERSION(vcc, 1);