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 #include <netinet/in.h>
67 #include <netinet/ip.h>
68 #if defined(__i386__) || defined(__amd64__)
69 #include <machine/md_var.h>
70 #include <machine/cputypes.h>
74 #include <crypto/rijndael/rijndael.h>
77 #include <ddb/db_lex.h>
80 #include "common/common.h"
81 #include "common/t4_msg.h"
82 #include "common/t4_regs.h"
83 #include "common/t4_regs_values.h"
84 #include "cudbg/cudbg.h"
87 #include "t4_mp_ring.h"
91 /* T4 bus driver interface */
92 static int t4_probe(device_t);
93 static int t4_attach(device_t);
94 static int t4_detach(device_t);
95 static int t4_ready(device_t);
96 static int t4_read_port_device(device_t, int, device_t *);
97 static device_method_t t4_methods[] = {
98 DEVMETHOD(device_probe, t4_probe),
99 DEVMETHOD(device_attach, t4_attach),
100 DEVMETHOD(device_detach, t4_detach),
102 DEVMETHOD(t4_is_main_ready, t4_ready),
103 DEVMETHOD(t4_read_port_device, t4_read_port_device),
107 static driver_t t4_driver = {
110 sizeof(struct adapter)
114 /* T4 port (cxgbe) interface */
115 static int cxgbe_probe(device_t);
116 static int cxgbe_attach(device_t);
117 static int cxgbe_detach(device_t);
118 device_method_t cxgbe_methods[] = {
119 DEVMETHOD(device_probe, cxgbe_probe),
120 DEVMETHOD(device_attach, cxgbe_attach),
121 DEVMETHOD(device_detach, cxgbe_detach),
124 static driver_t cxgbe_driver = {
127 sizeof(struct port_info)
130 /* T4 VI (vcxgbe) interface */
131 static int vcxgbe_probe(device_t);
132 static int vcxgbe_attach(device_t);
133 static int vcxgbe_detach(device_t);
134 static device_method_t vcxgbe_methods[] = {
135 DEVMETHOD(device_probe, vcxgbe_probe),
136 DEVMETHOD(device_attach, vcxgbe_attach),
137 DEVMETHOD(device_detach, vcxgbe_detach),
140 static driver_t vcxgbe_driver = {
143 sizeof(struct vi_info)
146 static d_ioctl_t t4_ioctl;
148 static struct cdevsw t4_cdevsw = {
149 .d_version = D_VERSION,
154 /* T5 bus driver interface */
155 static int t5_probe(device_t);
156 static device_method_t t5_methods[] = {
157 DEVMETHOD(device_probe, t5_probe),
158 DEVMETHOD(device_attach, t4_attach),
159 DEVMETHOD(device_detach, t4_detach),
161 DEVMETHOD(t4_is_main_ready, t4_ready),
162 DEVMETHOD(t4_read_port_device, t4_read_port_device),
166 static driver_t t5_driver = {
169 sizeof(struct adapter)
173 /* T5 port (cxl) interface */
174 static driver_t cxl_driver = {
177 sizeof(struct port_info)
180 /* T5 VI (vcxl) interface */
181 static driver_t vcxl_driver = {
184 sizeof(struct vi_info)
187 /* T6 bus driver interface */
188 static int t6_probe(device_t);
189 static device_method_t t6_methods[] = {
190 DEVMETHOD(device_probe, t6_probe),
191 DEVMETHOD(device_attach, t4_attach),
192 DEVMETHOD(device_detach, t4_detach),
194 DEVMETHOD(t4_is_main_ready, t4_ready),
195 DEVMETHOD(t4_read_port_device, t4_read_port_device),
199 static driver_t t6_driver = {
202 sizeof(struct adapter)
206 /* T6 port (cc) interface */
207 static driver_t cc_driver = {
210 sizeof(struct port_info)
213 /* T6 VI (vcc) interface */
214 static driver_t vcc_driver = {
217 sizeof(struct vi_info)
220 /* ifnet interface */
221 static void cxgbe_init(void *);
222 static int cxgbe_ioctl(struct ifnet *, unsigned long, caddr_t);
223 static int cxgbe_transmit(struct ifnet *, struct mbuf *);
224 static void cxgbe_qflush(struct ifnet *);
226 MALLOC_DEFINE(M_CXGBE, "cxgbe", "Chelsio T4/T5 Ethernet driver and services");
229 * Correct lock order when you need to acquire multiple locks is t4_list_lock,
230 * then ADAPTER_LOCK, then t4_uld_list_lock.
232 static struct sx t4_list_lock;
233 SLIST_HEAD(, adapter) t4_list;
235 static struct sx t4_uld_list_lock;
236 SLIST_HEAD(, uld_info) t4_uld_list;
240 * Tunables. See tweak_tunables() too.
242 * Each tunable is set to a default value here if it's known at compile-time.
243 * Otherwise it is set to -n as an indication to tweak_tunables() that it should
244 * provide a reasonable default (upto n) when the driver is loaded.
246 * Tunables applicable to both T4 and T5 are under hw.cxgbe. Those specific to
247 * T5 are under hw.cxl.
251 * Number of queues for tx and rx, NIC and offload.
255 TUNABLE_INT("hw.cxgbe.ntxq", &t4_ntxq);
256 TUNABLE_INT("hw.cxgbe.ntxq10g", &t4_ntxq); /* Old name, undocumented */
260 TUNABLE_INT("hw.cxgbe.nrxq", &t4_nrxq);
261 TUNABLE_INT("hw.cxgbe.nrxq10g", &t4_nrxq); /* Old name, undocumented */
264 static int t4_ntxq_vi = -NTXQ_VI;
265 TUNABLE_INT("hw.cxgbe.ntxq_vi", &t4_ntxq_vi);
268 static int t4_nrxq_vi = -NRXQ_VI;
269 TUNABLE_INT("hw.cxgbe.nrxq_vi", &t4_nrxq_vi);
271 static int t4_rsrv_noflowq = 0;
272 TUNABLE_INT("hw.cxgbe.rsrv_noflowq", &t4_rsrv_noflowq);
274 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
276 static int t4_nofldtxq = -NOFLDTXQ;
277 TUNABLE_INT("hw.cxgbe.nofldtxq", &t4_nofldtxq);
280 static int t4_nofldrxq = -NOFLDRXQ;
281 TUNABLE_INT("hw.cxgbe.nofldrxq", &t4_nofldrxq);
283 #define NOFLDTXQ_VI 1
284 static int t4_nofldtxq_vi = -NOFLDTXQ_VI;
285 TUNABLE_INT("hw.cxgbe.nofldtxq_vi", &t4_nofldtxq_vi);
287 #define NOFLDRXQ_VI 1
288 static int t4_nofldrxq_vi = -NOFLDRXQ_VI;
289 TUNABLE_INT("hw.cxgbe.nofldrxq_vi", &t4_nofldrxq_vi);
291 #define TMR_IDX_OFLD 1
292 int t4_tmr_idx_ofld = TMR_IDX_OFLD;
293 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_ofld", &t4_tmr_idx_ofld);
295 #define PKTC_IDX_OFLD (-1)
296 int t4_pktc_idx_ofld = PKTC_IDX_OFLD;
297 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_ofld", &t4_pktc_idx_ofld);
299 /* 0 means chip/fw default, non-zero number is value in microseconds */
300 static u_long t4_toe_keepalive_idle = 0;
301 TUNABLE_ULONG("hw.cxgbe.toe.keepalive_idle", &t4_toe_keepalive_idle);
303 /* 0 means chip/fw default, non-zero number is value in microseconds */
304 static u_long t4_toe_keepalive_interval = 0;
305 TUNABLE_ULONG("hw.cxgbe.toe.keepalive_interval", &t4_toe_keepalive_interval);
307 /* 0 means chip/fw default, non-zero number is # of keepalives before abort */
308 static int t4_toe_keepalive_count = 0;
309 TUNABLE_INT("hw.cxgbe.toe.keepalive_count", &t4_toe_keepalive_count);
311 /* 0 means chip/fw default, non-zero number is value in microseconds */
312 static u_long t4_toe_rexmt_min = 0;
313 TUNABLE_ULONG("hw.cxgbe.toe.rexmt_min", &t4_toe_rexmt_min);
315 /* 0 means chip/fw default, non-zero number is value in microseconds */
316 static u_long t4_toe_rexmt_max = 0;
317 TUNABLE_ULONG("hw.cxgbe.toe.rexmt_max", &t4_toe_rexmt_max);
319 /* 0 means chip/fw default, non-zero number is # of rexmt before abort */
320 static int t4_toe_rexmt_count = 0;
321 TUNABLE_INT("hw.cxgbe.toe.rexmt_count", &t4_toe_rexmt_count);
323 /* -1 means chip/fw default, other values are raw backoff values to use */
324 static int t4_toe_rexmt_backoff[16] = {
325 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
327 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.0", &t4_toe_rexmt_backoff[0]);
328 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.1", &t4_toe_rexmt_backoff[1]);
329 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.2", &t4_toe_rexmt_backoff[2]);
330 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.3", &t4_toe_rexmt_backoff[3]);
331 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.4", &t4_toe_rexmt_backoff[4]);
332 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.5", &t4_toe_rexmt_backoff[5]);
333 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.6", &t4_toe_rexmt_backoff[6]);
334 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.7", &t4_toe_rexmt_backoff[7]);
335 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.8", &t4_toe_rexmt_backoff[8]);
336 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.9", &t4_toe_rexmt_backoff[9]);
337 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.10", &t4_toe_rexmt_backoff[10]);
338 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.11", &t4_toe_rexmt_backoff[11]);
339 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.12", &t4_toe_rexmt_backoff[12]);
340 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.13", &t4_toe_rexmt_backoff[13]);
341 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.14", &t4_toe_rexmt_backoff[14]);
342 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.15", &t4_toe_rexmt_backoff[15]);
347 static int t4_nnmtxq_vi = -NNMTXQ_VI;
348 TUNABLE_INT("hw.cxgbe.nnmtxq_vi", &t4_nnmtxq_vi);
351 static int t4_nnmrxq_vi = -NNMRXQ_VI;
352 TUNABLE_INT("hw.cxgbe.nnmrxq_vi", &t4_nnmrxq_vi);
356 * Holdoff parameters for ports.
359 int t4_tmr_idx = TMR_IDX;
360 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx", &t4_tmr_idx);
361 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_10G", &t4_tmr_idx); /* Old name */
363 #define PKTC_IDX (-1)
364 int t4_pktc_idx = PKTC_IDX;
365 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx", &t4_pktc_idx);
366 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_10G", &t4_pktc_idx); /* Old name */
369 * Size (# of entries) of each tx and rx queue.
371 unsigned int t4_qsize_txq = TX_EQ_QSIZE;
372 TUNABLE_INT("hw.cxgbe.qsize_txq", &t4_qsize_txq);
374 unsigned int t4_qsize_rxq = RX_IQ_QSIZE;
375 TUNABLE_INT("hw.cxgbe.qsize_rxq", &t4_qsize_rxq);
378 * Interrupt types allowed (bits 0, 1, 2 = INTx, MSI, MSI-X respectively).
380 int t4_intr_types = INTR_MSIX | INTR_MSI | INTR_INTX;
381 TUNABLE_INT("hw.cxgbe.interrupt_types", &t4_intr_types);
384 * Configuration file. All the _CF names here are special.
386 #define DEFAULT_CF "default"
387 #define BUILTIN_CF "built-in"
388 #define FLASH_CF "flash"
389 #define UWIRE_CF "uwire"
390 #define FPGA_CF "fpga"
391 static char t4_cfg_file[32] = DEFAULT_CF;
392 TUNABLE_STR("hw.cxgbe.config_file", t4_cfg_file, sizeof(t4_cfg_file));
395 * PAUSE settings (bit 0, 1, 2 = rx_pause, tx_pause, pause_autoneg respectively).
396 * rx_pause = 1 to heed incoming PAUSE frames, 0 to ignore them.
397 * tx_pause = 1 to emit PAUSE frames when the rx FIFO reaches its high water
398 * mark or when signalled to do so, 0 to never emit PAUSE.
399 * pause_autoneg = 1 means PAUSE will be negotiated if possible and the
400 * negotiated settings will override rx_pause/tx_pause.
401 * Otherwise rx_pause/tx_pause are applied forcibly.
403 static int t4_pause_settings = PAUSE_RX | PAUSE_TX | PAUSE_AUTONEG;
404 TUNABLE_INT("hw.cxgbe.pause_settings", &t4_pause_settings);
407 * Forward Error Correction settings (bit 0, 1 = RS, BASER respectively).
408 * -1 to run with the firmware default. Same as FEC_AUTO (bit 5)
411 static int t4_fec = -1;
412 TUNABLE_INT("hw.cxgbe.fec", &t4_fec);
415 * Link autonegotiation.
416 * -1 to run with the firmware default.
420 static int t4_autoneg = -1;
421 TUNABLE_INT("hw.cxgbe.autoneg", &t4_autoneg);
424 * Firmware auto-install by driver during attach (0, 1, 2 = prohibited, allowed,
425 * encouraged respectively).
427 static unsigned int t4_fw_install = 1;
428 TUNABLE_INT("hw.cxgbe.fw_install", &t4_fw_install);
431 * ASIC features that will be used. Disable the ones you don't want so that the
432 * chip resources aren't wasted on features that will not be used.
434 static int t4_nbmcaps_allowed = 0;
435 TUNABLE_INT("hw.cxgbe.nbmcaps_allowed", &t4_nbmcaps_allowed);
437 static int t4_linkcaps_allowed = 0; /* No DCBX, PPP, etc. by default */
438 TUNABLE_INT("hw.cxgbe.linkcaps_allowed", &t4_linkcaps_allowed);
440 static int t4_switchcaps_allowed = FW_CAPS_CONFIG_SWITCH_INGRESS |
441 FW_CAPS_CONFIG_SWITCH_EGRESS;
442 TUNABLE_INT("hw.cxgbe.switchcaps_allowed", &t4_switchcaps_allowed);
445 static int t4_niccaps_allowed = FW_CAPS_CONFIG_NIC |
446 FW_CAPS_CONFIG_NIC_HASHFILTER | FW_CAPS_CONFIG_NIC_ETHOFLD;
448 static int t4_niccaps_allowed = FW_CAPS_CONFIG_NIC |
449 FW_CAPS_CONFIG_NIC_HASHFILTER;
451 TUNABLE_INT("hw.cxgbe.niccaps_allowed", &t4_niccaps_allowed);
453 static int t4_toecaps_allowed = -1;
454 TUNABLE_INT("hw.cxgbe.toecaps_allowed", &t4_toecaps_allowed);
456 static int t4_rdmacaps_allowed = -1;
457 TUNABLE_INT("hw.cxgbe.rdmacaps_allowed", &t4_rdmacaps_allowed);
459 static int t4_cryptocaps_allowed = -1;
460 TUNABLE_INT("hw.cxgbe.cryptocaps_allowed", &t4_cryptocaps_allowed);
462 static int t4_iscsicaps_allowed = -1;
463 TUNABLE_INT("hw.cxgbe.iscsicaps_allowed", &t4_iscsicaps_allowed);
465 static int t4_fcoecaps_allowed = 0;
466 TUNABLE_INT("hw.cxgbe.fcoecaps_allowed", &t4_fcoecaps_allowed);
468 static int t5_write_combine = 0;
469 TUNABLE_INT("hw.cxl.write_combine", &t5_write_combine);
471 static int t4_num_vis = 1;
472 TUNABLE_INT("hw.cxgbe.num_vis", &t4_num_vis);
474 * PCIe Relaxed Ordering.
475 * -1: driver should figure out a good value.
480 static int pcie_relaxed_ordering = -1;
481 TUNABLE_INT("hw.cxgbe.pcie_relaxed_ordering", &pcie_relaxed_ordering);
483 static int t4_panic_on_fatal_err = 0;
484 TUNABLE_INT("hw.cxgbe.panic_on_fatal_err", &t4_panic_on_fatal_err);
490 static int t4_cop_managed_offloading = 0;
491 TUNABLE_INT("hw.cxgbe.cop_managed_offloading", &t4_cop_managed_offloading);
494 /* Functions used by VIs to obtain unique MAC addresses for each VI. */
495 static int vi_mac_funcs[] = {
499 FW_VI_FUNC_OPENISCSI,
505 struct intrs_and_queues {
506 uint16_t intr_type; /* INTx, MSI, or MSI-X */
507 uint16_t num_vis; /* number of VIs for each port */
508 uint16_t nirq; /* Total # of vectors */
509 uint16_t ntxq; /* # of NIC txq's for each port */
510 uint16_t nrxq; /* # of NIC rxq's for each port */
511 uint16_t nofldtxq; /* # of TOE/ETHOFLD txq's for each port */
512 uint16_t nofldrxq; /* # of TOE rxq's for each port */
514 /* The vcxgbe/vcxl interfaces use these and not the ones above. */
515 uint16_t ntxq_vi; /* # of NIC txq's */
516 uint16_t nrxq_vi; /* # of NIC rxq's */
517 uint16_t nofldtxq_vi; /* # of TOE txq's */
518 uint16_t nofldrxq_vi; /* # of TOE rxq's */
519 uint16_t nnmtxq_vi; /* # of netmap txq's */
520 uint16_t nnmrxq_vi; /* # of netmap rxq's */
523 static void setup_memwin(struct adapter *);
524 static void position_memwin(struct adapter *, int, uint32_t);
525 static int validate_mem_range(struct adapter *, uint32_t, int);
526 static int fwmtype_to_hwmtype(int);
527 static int validate_mt_off_len(struct adapter *, int, uint32_t, int,
529 static int fixup_devlog_params(struct adapter *);
530 static int cfg_itype_and_nqueues(struct adapter *, struct intrs_and_queues *);
531 static int prep_firmware(struct adapter *);
532 static int partition_resources(struct adapter *, const struct firmware *,
534 static int get_params__pre_init(struct adapter *);
535 static int get_params__post_init(struct adapter *);
536 static int set_params__post_init(struct adapter *);
537 static void t4_set_desc(struct adapter *);
538 static bool fixed_ifmedia(struct port_info *);
539 static void build_medialist(struct port_info *);
540 static void init_link_config(struct port_info *);
541 static int fixup_link_config(struct port_info *);
542 static int apply_link_config(struct port_info *);
543 static int cxgbe_init_synchronized(struct vi_info *);
544 static int cxgbe_uninit_synchronized(struct vi_info *);
545 static void quiesce_txq(struct adapter *, struct sge_txq *);
546 static void quiesce_wrq(struct adapter *, struct sge_wrq *);
547 static void quiesce_iq(struct adapter *, struct sge_iq *);
548 static void quiesce_fl(struct adapter *, struct sge_fl *);
549 static int t4_alloc_irq(struct adapter *, struct irq *, int rid,
550 driver_intr_t *, void *, char *);
551 static int t4_free_irq(struct adapter *, struct irq *);
552 static void get_regs(struct adapter *, struct t4_regdump *, uint8_t *);
553 static void vi_refresh_stats(struct adapter *, struct vi_info *);
554 static void cxgbe_refresh_stats(struct adapter *, struct port_info *);
555 static void cxgbe_tick(void *);
556 static void cxgbe_sysctls(struct port_info *);
557 static int sysctl_int_array(SYSCTL_HANDLER_ARGS);
558 static int sysctl_bitfield_8b(SYSCTL_HANDLER_ARGS);
559 static int sysctl_bitfield_16b(SYSCTL_HANDLER_ARGS);
560 static int sysctl_btphy(SYSCTL_HANDLER_ARGS);
561 static int sysctl_noflowq(SYSCTL_HANDLER_ARGS);
562 static int sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS);
563 static int sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS);
564 static int sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS);
565 static int sysctl_qsize_txq(SYSCTL_HANDLER_ARGS);
566 static int sysctl_pause_settings(SYSCTL_HANDLER_ARGS);
567 static int sysctl_fec(SYSCTL_HANDLER_ARGS);
568 static int sysctl_autoneg(SYSCTL_HANDLER_ARGS);
569 static int sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS);
570 static int sysctl_temperature(SYSCTL_HANDLER_ARGS);
571 static int sysctl_loadavg(SYSCTL_HANDLER_ARGS);
572 static int sysctl_cctrl(SYSCTL_HANDLER_ARGS);
573 static int sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS);
574 static int sysctl_cim_la(SYSCTL_HANDLER_ARGS);
575 static int sysctl_cim_la_t6(SYSCTL_HANDLER_ARGS);
576 static int sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS);
577 static int sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS);
578 static int sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS);
579 static int sysctl_cpl_stats(SYSCTL_HANDLER_ARGS);
580 static int sysctl_ddp_stats(SYSCTL_HANDLER_ARGS);
581 static int sysctl_devlog(SYSCTL_HANDLER_ARGS);
582 static int sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS);
583 static int sysctl_hw_sched(SYSCTL_HANDLER_ARGS);
584 static int sysctl_lb_stats(SYSCTL_HANDLER_ARGS);
585 static int sysctl_linkdnrc(SYSCTL_HANDLER_ARGS);
586 static int sysctl_meminfo(SYSCTL_HANDLER_ARGS);
587 static int sysctl_mps_tcam(SYSCTL_HANDLER_ARGS);
588 static int sysctl_mps_tcam_t6(SYSCTL_HANDLER_ARGS);
589 static int sysctl_path_mtus(SYSCTL_HANDLER_ARGS);
590 static int sysctl_pm_stats(SYSCTL_HANDLER_ARGS);
591 static int sysctl_rdma_stats(SYSCTL_HANDLER_ARGS);
592 static int sysctl_tcp_stats(SYSCTL_HANDLER_ARGS);
593 static int sysctl_tids(SYSCTL_HANDLER_ARGS);
594 static int sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS);
595 static int sysctl_tp_la_mask(SYSCTL_HANDLER_ARGS);
596 static int sysctl_tp_la(SYSCTL_HANDLER_ARGS);
597 static int sysctl_tx_rate(SYSCTL_HANDLER_ARGS);
598 static int sysctl_ulprx_la(SYSCTL_HANDLER_ARGS);
599 static int sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS);
600 static int sysctl_cpus(SYSCTL_HANDLER_ARGS);
602 static int sysctl_tls_rx_ports(SYSCTL_HANDLER_ARGS);
603 static int sysctl_tp_tick(SYSCTL_HANDLER_ARGS);
604 static int sysctl_tp_dack_timer(SYSCTL_HANDLER_ARGS);
605 static int sysctl_tp_timer(SYSCTL_HANDLER_ARGS);
606 static int sysctl_tp_shift_cnt(SYSCTL_HANDLER_ARGS);
607 static int sysctl_tp_backoff(SYSCTL_HANDLER_ARGS);
608 static int sysctl_holdoff_tmr_idx_ofld(SYSCTL_HANDLER_ARGS);
609 static int sysctl_holdoff_pktc_idx_ofld(SYSCTL_HANDLER_ARGS);
611 static int get_sge_context(struct adapter *, struct t4_sge_context *);
612 static int load_fw(struct adapter *, struct t4_data *);
613 static int load_cfg(struct adapter *, struct t4_data *);
614 static int load_boot(struct adapter *, struct t4_bootrom *);
615 static int load_bootcfg(struct adapter *, struct t4_data *);
616 static int cudbg_dump(struct adapter *, struct t4_cudbg_dump *);
617 static void free_offload_policy(struct t4_offload_policy *);
618 static int set_offload_policy(struct adapter *, struct t4_offload_policy *);
619 static int read_card_mem(struct adapter *, int, struct t4_mem_range *);
620 static int read_i2c(struct adapter *, struct t4_i2c_data *);
622 static int toe_capability(struct vi_info *, int);
624 static int mod_event(module_t, int, void *);
625 static int notify_siblings(device_t, int);
631 {0xa000, "Chelsio Terminator 4 FPGA"},
632 {0x4400, "Chelsio T440-dbg"},
633 {0x4401, "Chelsio T420-CR"},
634 {0x4402, "Chelsio T422-CR"},
635 {0x4403, "Chelsio T440-CR"},
636 {0x4404, "Chelsio T420-BCH"},
637 {0x4405, "Chelsio T440-BCH"},
638 {0x4406, "Chelsio T440-CH"},
639 {0x4407, "Chelsio T420-SO"},
640 {0x4408, "Chelsio T420-CX"},
641 {0x4409, "Chelsio T420-BT"},
642 {0x440a, "Chelsio T404-BT"},
643 {0x440e, "Chelsio T440-LP-CR"},
645 {0xb000, "Chelsio Terminator 5 FPGA"},
646 {0x5400, "Chelsio T580-dbg"},
647 {0x5401, "Chelsio T520-CR"}, /* 2 x 10G */
648 {0x5402, "Chelsio T522-CR"}, /* 2 x 10G, 2 X 1G */
649 {0x5403, "Chelsio T540-CR"}, /* 4 x 10G */
650 {0x5407, "Chelsio T520-SO"}, /* 2 x 10G, nomem */
651 {0x5409, "Chelsio T520-BT"}, /* 2 x 10GBaseT */
652 {0x540a, "Chelsio T504-BT"}, /* 4 x 1G */
653 {0x540d, "Chelsio T580-CR"}, /* 2 x 40G */
654 {0x540e, "Chelsio T540-LP-CR"}, /* 4 x 10G */
655 {0x5410, "Chelsio T580-LP-CR"}, /* 2 x 40G */
656 {0x5411, "Chelsio T520-LL-CR"}, /* 2 x 10G */
657 {0x5412, "Chelsio T560-CR"}, /* 1 x 40G, 2 x 10G */
658 {0x5414, "Chelsio T580-LP-SO-CR"}, /* 2 x 40G, nomem */
659 {0x5415, "Chelsio T502-BT"}, /* 2 x 1G */
660 {0x5418, "Chelsio T540-BT"}, /* 4 x 10GBaseT */
661 {0x5419, "Chelsio T540-LP-BT"}, /* 4 x 10GBaseT */
662 {0x541a, "Chelsio T540-SO-BT"}, /* 4 x 10GBaseT, nomem */
663 {0x541b, "Chelsio T540-SO-CR"}, /* 4 x 10G, nomem */
665 {0xc006, "Chelsio Terminator 6 FPGA"}, /* T6 PE10K6 FPGA (PF0) */
666 {0x6400, "Chelsio T6-DBG-25"}, /* 2 x 10/25G, debug */
667 {0x6401, "Chelsio T6225-CR"}, /* 2 x 10/25G */
668 {0x6402, "Chelsio T6225-SO-CR"}, /* 2 x 10/25G, nomem */
669 {0x6403, "Chelsio T6425-CR"}, /* 4 x 10/25G */
670 {0x6404, "Chelsio T6425-SO-CR"}, /* 4 x 10/25G, nomem */
671 {0x6405, "Chelsio T6225-OCP-SO"}, /* 2 x 10/25G, nomem */
672 {0x6406, "Chelsio T62100-OCP-SO"}, /* 2 x 40/50/100G, nomem */
673 {0x6407, "Chelsio T62100-LP-CR"}, /* 2 x 40/50/100G */
674 {0x6408, "Chelsio T62100-SO-CR"}, /* 2 x 40/50/100G, nomem */
675 {0x6409, "Chelsio T6210-BT"}, /* 2 x 10GBASE-T */
676 {0x640d, "Chelsio T62100-CR"}, /* 2 x 40/50/100G */
677 {0x6410, "Chelsio T6-DBG-100"}, /* 2 x 40/50/100G, debug */
678 {0x6411, "Chelsio T6225-LL-CR"}, /* 2 x 10/25G */
679 {0x6414, "Chelsio T61100-OCP-SO"}, /* 1 x 40/50/100G, nomem */
680 {0x6415, "Chelsio T6201-BT"}, /* 2 x 1000BASE-T */
683 {0x6480, "Custom T6225-CR"},
684 {0x6481, "Custom T62100-CR"},
685 {0x6482, "Custom T6225-CR"},
686 {0x6483, "Custom T62100-CR"},
687 {0x6484, "Custom T64100-CR"},
688 {0x6485, "Custom T6240-SO"},
689 {0x6486, "Custom T6225-SO-CR"},
690 {0x6487, "Custom T6225-CR"},
695 * service_iq_fl() has an iq and needs the fl. Offset of fl from the iq should
696 * be exactly the same for both rxq and ofld_rxq.
698 CTASSERT(offsetof(struct sge_ofld_rxq, iq) == offsetof(struct sge_rxq, iq));
699 CTASSERT(offsetof(struct sge_ofld_rxq, fl) == offsetof(struct sge_rxq, fl));
701 CTASSERT(sizeof(struct cluster_metadata) <= CL_METADATA_SIZE);
704 t4_probe(device_t dev)
707 uint16_t v = pci_get_vendor(dev);
708 uint16_t d = pci_get_device(dev);
709 uint8_t f = pci_get_function(dev);
711 if (v != PCI_VENDOR_ID_CHELSIO)
714 /* Attach only to PF0 of the FPGA */
715 if (d == 0xa000 && f != 0)
718 for (i = 0; i < nitems(t4_pciids); i++) {
719 if (d == t4_pciids[i].device) {
720 device_set_desc(dev, t4_pciids[i].desc);
721 return (BUS_PROBE_DEFAULT);
729 t5_probe(device_t dev)
732 uint16_t v = pci_get_vendor(dev);
733 uint16_t d = pci_get_device(dev);
734 uint8_t f = pci_get_function(dev);
736 if (v != PCI_VENDOR_ID_CHELSIO)
739 /* Attach only to PF0 of the FPGA */
740 if (d == 0xb000 && f != 0)
743 for (i = 0; i < nitems(t5_pciids); i++) {
744 if (d == t5_pciids[i].device) {
745 device_set_desc(dev, t5_pciids[i].desc);
746 return (BUS_PROBE_DEFAULT);
754 t6_probe(device_t dev)
757 uint16_t v = pci_get_vendor(dev);
758 uint16_t d = pci_get_device(dev);
760 if (v != PCI_VENDOR_ID_CHELSIO)
763 for (i = 0; i < nitems(t6_pciids); i++) {
764 if (d == t6_pciids[i].device) {
765 device_set_desc(dev, t6_pciids[i].desc);
766 return (BUS_PROBE_DEFAULT);
774 t5_attribute_workaround(device_t dev)
780 * The T5 chips do not properly echo the No Snoop and Relaxed
781 * Ordering attributes when replying to a TLP from a Root
782 * Port. As a workaround, find the parent Root Port and
783 * disable No Snoop and Relaxed Ordering. Note that this
784 * affects all devices under this root port.
786 root_port = pci_find_pcie_root_port(dev);
787 if (root_port == NULL) {
788 device_printf(dev, "Unable to find parent root port\n");
792 v = pcie_adjust_config(root_port, PCIER_DEVICE_CTL,
793 PCIEM_CTL_RELAXED_ORD_ENABLE | PCIEM_CTL_NOSNOOP_ENABLE, 0, 2);
794 if ((v & (PCIEM_CTL_RELAXED_ORD_ENABLE | PCIEM_CTL_NOSNOOP_ENABLE)) !=
796 device_printf(dev, "Disabled No Snoop/Relaxed Ordering on %s\n",
797 device_get_nameunit(root_port));
800 static const struct devnames devnames[] = {
802 .nexus_name = "t4nex",
803 .ifnet_name = "cxgbe",
804 .vi_ifnet_name = "vcxgbe",
805 .pf03_drv_name = "t4iov",
806 .vf_nexus_name = "t4vf",
807 .vf_ifnet_name = "cxgbev"
809 .nexus_name = "t5nex",
811 .vi_ifnet_name = "vcxl",
812 .pf03_drv_name = "t5iov",
813 .vf_nexus_name = "t5vf",
814 .vf_ifnet_name = "cxlv"
816 .nexus_name = "t6nex",
818 .vi_ifnet_name = "vcc",
819 .pf03_drv_name = "t6iov",
820 .vf_nexus_name = "t6vf",
821 .vf_ifnet_name = "ccv"
826 t4_init_devnames(struct adapter *sc)
831 if (id >= CHELSIO_T4 && id - CHELSIO_T4 < nitems(devnames))
832 sc->names = &devnames[id - CHELSIO_T4];
834 device_printf(sc->dev, "chip id %d is not supported.\n", id);
840 t4_attach(device_t dev)
843 int rc = 0, i, j, rqidx, tqidx, nports;
844 struct make_dev_args mda;
845 struct intrs_and_queues iaq;
848 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
855 int nm_rqidx, nm_tqidx;
859 sc = device_get_softc(dev);
861 TUNABLE_INT_FETCH("hw.cxgbe.dflags", &sc->debug_flags);
863 if ((pci_get_device(dev) & 0xff00) == 0x5400)
864 t5_attribute_workaround(dev);
865 pci_enable_busmaster(dev);
866 if (pci_find_cap(dev, PCIY_EXPRESS, &i) == 0) {
869 pci_set_max_read_req(dev, 4096);
870 v = pci_read_config(dev, i + PCIER_DEVICE_CTL, 2);
871 sc->params.pci.mps = 128 << ((v & PCIEM_CTL_MAX_PAYLOAD) >> 5);
872 if (pcie_relaxed_ordering == 0 &&
873 (v & PCIEM_CTL_RELAXED_ORD_ENABLE) != 0) {
874 v &= ~PCIEM_CTL_RELAXED_ORD_ENABLE;
875 pci_write_config(dev, i + PCIER_DEVICE_CTL, v, 2);
876 } else if (pcie_relaxed_ordering == 1 &&
877 (v & PCIEM_CTL_RELAXED_ORD_ENABLE) == 0) {
878 v |= PCIEM_CTL_RELAXED_ORD_ENABLE;
879 pci_write_config(dev, i + PCIER_DEVICE_CTL, v, 2);
883 sc->sge_gts_reg = MYPF_REG(A_SGE_PF_GTS);
884 sc->sge_kdoorbell_reg = MYPF_REG(A_SGE_PF_KDOORBELL);
886 mtx_init(&sc->ifp_lock, sc->ifp_lockname, 0, MTX_DEF);
887 snprintf(sc->ifp_lockname, sizeof(sc->ifp_lockname), "%s tracer",
888 device_get_nameunit(dev));
890 snprintf(sc->lockname, sizeof(sc->lockname), "%s",
891 device_get_nameunit(dev));
892 mtx_init(&sc->sc_lock, sc->lockname, 0, MTX_DEF);
895 mtx_init(&sc->sfl_lock, "starving freelists", 0, MTX_DEF);
896 TAILQ_INIT(&sc->sfl);
897 callout_init_mtx(&sc->sfl_callout, &sc->sfl_lock, 0);
899 mtx_init(&sc->reg_lock, "indirect register access", 0, MTX_DEF);
902 rw_init(&sc->policy_lock, "connection offload policy");
904 rc = t4_map_bars_0_and_4(sc);
906 goto done; /* error message displayed already */
908 memset(sc->chan_map, 0xff, sizeof(sc->chan_map));
910 /* Prepare the adapter for operation. */
911 buf = malloc(PAGE_SIZE, M_CXGBE, M_ZERO | M_WAITOK);
912 rc = -t4_prep_adapter(sc, buf);
915 device_printf(dev, "failed to prepare adapter: %d.\n", rc);
920 * This is the real PF# to which we're attaching. Works from within PCI
921 * passthrough environments too, where pci_get_function() could return a
922 * different PF# depending on the passthrough configuration. We need to
923 * use the real PF# in all our communication with the firmware.
925 j = t4_read_reg(sc, A_PL_WHOAMI);
926 sc->pf = chip_id(sc) <= CHELSIO_T5 ? G_SOURCEPF(j) : G_T6_SOURCEPF(j);
929 t4_init_devnames(sc);
930 if (sc->names == NULL) {
932 goto done; /* error message displayed already */
936 * Do this really early, with the memory windows set up even before the
937 * character device. The userland tool's register i/o and mem read
938 * will work even in "recovery mode".
941 if (t4_init_devlog_params(sc, 0) == 0)
942 fixup_devlog_params(sc);
943 make_dev_args_init(&mda);
944 mda.mda_devsw = &t4_cdevsw;
945 mda.mda_uid = UID_ROOT;
946 mda.mda_gid = GID_WHEEL;
948 mda.mda_si_drv1 = sc;
949 rc = make_dev_s(&mda, &sc->cdev, "%s", device_get_nameunit(dev));
951 device_printf(dev, "failed to create nexus char device: %d.\n",
954 /* Go no further if recovery mode has been requested. */
955 if (TUNABLE_INT_FETCH("hw.cxgbe.sos", &i) && i != 0) {
956 device_printf(dev, "recovery mode.\n");
960 #if defined(__i386__)
961 if ((cpu_feature & CPUID_CX8) == 0) {
962 device_printf(dev, "64 bit atomics not available.\n");
968 /* Prepare the firmware for operation */
969 rc = prep_firmware(sc);
971 goto done; /* error message displayed already */
973 rc = get_params__post_init(sc);
975 goto done; /* error message displayed already */
977 rc = set_params__post_init(sc);
979 goto done; /* error message displayed already */
981 rc = t4_map_bar_2(sc);
983 goto done; /* error message displayed already */
985 rc = t4_create_dma_tag(sc);
987 goto done; /* error message displayed already */
990 * First pass over all the ports - allocate VIs and initialize some
991 * basic parameters like mac address, port type, etc.
993 for_each_port(sc, i) {
994 struct port_info *pi;
996 pi = malloc(sizeof(*pi), M_CXGBE, M_ZERO | M_WAITOK);
999 /* These must be set before t4_port_init */
1003 * XXX: vi[0] is special so we can't delay this allocation until
1004 * pi->nvi's final value is known.
1006 pi->vi = malloc(sizeof(struct vi_info) * t4_num_vis, M_CXGBE,
1010 * Allocate the "main" VI and initialize parameters
1013 rc = -t4_port_init(sc, sc->mbox, sc->pf, 0, i);
1015 device_printf(dev, "unable to initialize port %d: %d\n",
1017 free(pi->vi, M_CXGBE);
1023 snprintf(pi->lockname, sizeof(pi->lockname), "%sp%d",
1024 device_get_nameunit(dev), i);
1025 mtx_init(&pi->pi_lock, pi->lockname, 0, MTX_DEF);
1026 sc->chan_map[pi->tx_chan] = i;
1028 /* All VIs on this port share this media. */
1029 ifmedia_init(&pi->media, IFM_IMASK, cxgbe_media_change,
1030 cxgbe_media_status);
1033 init_link_config(pi);
1034 fixup_link_config(pi);
1035 build_medialist(pi);
1036 if (fixed_ifmedia(pi))
1037 pi->flags |= FIXED_IFMEDIA;
1040 pi->dev = device_add_child(dev, sc->names->ifnet_name, -1);
1041 if (pi->dev == NULL) {
1043 "failed to add device for port %d.\n", i);
1047 pi->vi[0].dev = pi->dev;
1048 device_set_softc(pi->dev, pi);
1052 * Interrupt type, # of interrupts, # of rx/tx queues, etc.
1054 nports = sc->params.nports;
1055 rc = cfg_itype_and_nqueues(sc, &iaq);
1057 goto done; /* error message displayed already */
1059 num_vis = iaq.num_vis;
1060 sc->intr_type = iaq.intr_type;
1061 sc->intr_count = iaq.nirq;
1064 s->nrxq = nports * iaq.nrxq;
1065 s->ntxq = nports * iaq.ntxq;
1067 s->nrxq += nports * (num_vis - 1) * iaq.nrxq_vi;
1068 s->ntxq += nports * (num_vis - 1) * iaq.ntxq_vi;
1070 s->neq = s->ntxq + s->nrxq; /* the free list in an rxq is an eq */
1071 s->neq += nports; /* ctrl queues: 1 per port */
1072 s->niq = s->nrxq + 1; /* 1 extra for firmware event queue */
1073 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
1074 if (is_offload(sc) || is_ethoffload(sc)) {
1075 s->nofldtxq = nports * iaq.nofldtxq;
1077 s->nofldtxq += nports * (num_vis - 1) * iaq.nofldtxq_vi;
1078 s->neq += s->nofldtxq;
1080 s->ofld_txq = malloc(s->nofldtxq * sizeof(struct sge_wrq),
1081 M_CXGBE, M_ZERO | M_WAITOK);
1085 if (is_offload(sc)) {
1086 s->nofldrxq = nports * iaq.nofldrxq;
1088 s->nofldrxq += nports * (num_vis - 1) * iaq.nofldrxq_vi;
1089 s->neq += s->nofldrxq; /* free list */
1090 s->niq += s->nofldrxq;
1092 s->ofld_rxq = malloc(s->nofldrxq * sizeof(struct sge_ofld_rxq),
1093 M_CXGBE, M_ZERO | M_WAITOK);
1098 s->nnmrxq = nports * (num_vis - 1) * iaq.nnmrxq_vi;
1099 s->nnmtxq = nports * (num_vis - 1) * iaq.nnmtxq_vi;
1101 s->neq += s->nnmtxq + s->nnmrxq;
1102 s->niq += s->nnmrxq;
1104 s->nm_rxq = malloc(s->nnmrxq * sizeof(struct sge_nm_rxq),
1105 M_CXGBE, M_ZERO | M_WAITOK);
1106 s->nm_txq = malloc(s->nnmtxq * sizeof(struct sge_nm_txq),
1107 M_CXGBE, M_ZERO | M_WAITOK);
1110 s->ctrlq = malloc(nports * sizeof(struct sge_wrq), M_CXGBE,
1112 s->rxq = malloc(s->nrxq * sizeof(struct sge_rxq), M_CXGBE,
1114 s->txq = malloc(s->ntxq * sizeof(struct sge_txq), M_CXGBE,
1116 s->iqmap = malloc(s->niq * sizeof(struct sge_iq *), M_CXGBE,
1118 s->eqmap = malloc(s->neq * sizeof(struct sge_eq *), M_CXGBE,
1121 sc->irq = malloc(sc->intr_count * sizeof(struct irq), M_CXGBE,
1124 t4_init_l2t(sc, M_WAITOK);
1125 t4_init_smt(sc, M_WAITOK);
1126 t4_init_tx_sched(sc);
1128 t4_init_etid_table(sc);
1132 * Second pass over the ports. This time we know the number of rx and
1133 * tx queues that each port should get.
1136 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
1143 nm_rqidx = nm_tqidx = 0;
1145 for_each_port(sc, i) {
1146 struct port_info *pi = sc->port[i];
1153 for_each_vi(pi, j, vi) {
1155 vi->qsize_rxq = t4_qsize_rxq;
1156 vi->qsize_txq = t4_qsize_txq;
1158 vi->first_rxq = rqidx;
1159 vi->first_txq = tqidx;
1160 vi->tmr_idx = t4_tmr_idx;
1161 vi->pktc_idx = t4_pktc_idx;
1162 vi->nrxq = j == 0 ? iaq.nrxq : iaq.nrxq_vi;
1163 vi->ntxq = j == 0 ? iaq.ntxq : iaq.ntxq_vi;
1168 if (j == 0 && vi->ntxq > 1)
1169 vi->rsrv_noflowq = t4_rsrv_noflowq ? 1 : 0;
1171 vi->rsrv_noflowq = 0;
1173 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
1174 vi->first_ofld_txq = ofld_tqidx;
1175 vi->nofldtxq = j == 0 ? iaq.nofldtxq : iaq.nofldtxq_vi;
1176 ofld_tqidx += vi->nofldtxq;
1179 vi->ofld_tmr_idx = t4_tmr_idx_ofld;
1180 vi->ofld_pktc_idx = t4_pktc_idx_ofld;
1181 vi->first_ofld_rxq = ofld_rqidx;
1182 vi->nofldrxq = j == 0 ? iaq.nofldrxq : iaq.nofldrxq_vi;
1184 ofld_rqidx += vi->nofldrxq;
1188 vi->first_nm_rxq = nm_rqidx;
1189 vi->first_nm_txq = nm_tqidx;
1190 vi->nnmrxq = iaq.nnmrxq_vi;
1191 vi->nnmtxq = iaq.nnmtxq_vi;
1192 nm_rqidx += vi->nnmrxq;
1193 nm_tqidx += vi->nnmtxq;
1199 rc = t4_setup_intr_handlers(sc);
1202 "failed to setup interrupt handlers: %d\n", rc);
1206 rc = bus_generic_probe(dev);
1208 device_printf(dev, "failed to probe child drivers: %d\n", rc);
1213 * Ensure thread-safe mailbox access (in debug builds).
1215 * So far this was the only thread accessing the mailbox but various
1216 * ifnets and sysctls are about to be created and their handlers/ioctls
1217 * will access the mailbox from different threads.
1219 sc->flags |= CHK_MBOX_ACCESS;
1221 rc = bus_generic_attach(dev);
1224 "failed to attach all child ports: %d\n", rc);
1229 "PCIe gen%d x%d, %d ports, %d %s interrupt%s, %d eq, %d iq\n",
1230 sc->params.pci.speed, sc->params.pci.width, sc->params.nports,
1231 sc->intr_count, sc->intr_type == INTR_MSIX ? "MSI-X" :
1232 (sc->intr_type == INTR_MSI ? "MSI" : "INTx"),
1233 sc->intr_count > 1 ? "s" : "", sc->sge.neq, sc->sge.niq);
1237 notify_siblings(dev, 0);
1240 if (rc != 0 && sc->cdev) {
1241 /* cdev was created and so cxgbetool works; recover that way. */
1243 "error during attach, adapter is now in recovery mode.\n");
1248 t4_detach_common(dev);
1256 t4_ready(device_t dev)
1260 sc = device_get_softc(dev);
1261 if (sc->flags & FW_OK)
1267 t4_read_port_device(device_t dev, int port, device_t *child)
1270 struct port_info *pi;
1272 sc = device_get_softc(dev);
1273 if (port < 0 || port >= MAX_NPORTS)
1275 pi = sc->port[port];
1276 if (pi == NULL || pi->dev == NULL)
1283 notify_siblings(device_t dev, int detaching)
1289 for (i = 0; i < PCI_FUNCMAX; i++) {
1290 if (i == pci_get_function(dev))
1292 sibling = pci_find_dbsf(pci_get_domain(dev), pci_get_bus(dev),
1293 pci_get_slot(dev), i);
1294 if (sibling == NULL || !device_is_attached(sibling))
1297 error = T4_DETACH_CHILD(sibling);
1299 (void)T4_ATTACH_CHILD(sibling);
1310 t4_detach(device_t dev)
1315 sc = device_get_softc(dev);
1317 rc = notify_siblings(dev, 1);
1320 "failed to detach sibling devices: %d\n", rc);
1324 return (t4_detach_common(dev));
1328 t4_detach_common(device_t dev)
1331 struct port_info *pi;
1334 sc = device_get_softc(dev);
1337 destroy_dev(sc->cdev);
1341 sc->flags &= ~CHK_MBOX_ACCESS;
1342 if (sc->flags & FULL_INIT_DONE) {
1343 if (!(sc->flags & IS_VF))
1344 t4_intr_disable(sc);
1347 if (device_is_attached(dev)) {
1348 rc = bus_generic_detach(dev);
1351 "failed to detach child devices: %d\n", rc);
1356 for (i = 0; i < sc->intr_count; i++)
1357 t4_free_irq(sc, &sc->irq[i]);
1359 if ((sc->flags & (IS_VF | FW_OK)) == FW_OK)
1360 t4_free_tx_sched(sc);
1362 for (i = 0; i < MAX_NPORTS; i++) {
1365 t4_free_vi(sc, sc->mbox, sc->pf, 0, pi->vi[0].viid);
1367 device_delete_child(dev, pi->dev);
1369 mtx_destroy(&pi->pi_lock);
1370 free(pi->vi, M_CXGBE);
1375 device_delete_children(dev);
1377 if (sc->flags & FULL_INIT_DONE)
1378 adapter_full_uninit(sc);
1380 if ((sc->flags & (IS_VF | FW_OK)) == FW_OK)
1381 t4_fw_bye(sc, sc->mbox);
1383 if (sc->intr_type == INTR_MSI || sc->intr_type == INTR_MSIX)
1384 pci_release_msi(dev);
1387 bus_release_resource(dev, SYS_RES_MEMORY, sc->regs_rid,
1391 bus_release_resource(dev, SYS_RES_MEMORY, sc->udbs_rid,
1395 bus_release_resource(dev, SYS_RES_MEMORY, sc->msix_rid,
1399 t4_free_l2t(sc->l2t);
1401 t4_free_smt(sc->smt);
1403 t4_free_etid_table(sc);
1406 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
1407 free(sc->sge.ofld_txq, M_CXGBE);
1410 free(sc->sge.ofld_rxq, M_CXGBE);
1413 free(sc->sge.nm_rxq, M_CXGBE);
1414 free(sc->sge.nm_txq, M_CXGBE);
1416 free(sc->irq, M_CXGBE);
1417 free(sc->sge.rxq, M_CXGBE);
1418 free(sc->sge.txq, M_CXGBE);
1419 free(sc->sge.ctrlq, M_CXGBE);
1420 free(sc->sge.iqmap, M_CXGBE);
1421 free(sc->sge.eqmap, M_CXGBE);
1422 free(sc->tids.ftid_tab, M_CXGBE);
1423 free(sc->tids.hpftid_tab, M_CXGBE);
1424 free_hftid_hash(&sc->tids);
1425 free(sc->tids.atid_tab, M_CXGBE);
1426 free(sc->tids.tid_tab, M_CXGBE);
1427 free(sc->tt.tls_rx_ports, M_CXGBE);
1428 t4_destroy_dma_tag(sc);
1429 if (mtx_initialized(&sc->sc_lock)) {
1430 sx_xlock(&t4_list_lock);
1431 SLIST_REMOVE(&t4_list, sc, adapter, link);
1432 sx_xunlock(&t4_list_lock);
1433 mtx_destroy(&sc->sc_lock);
1436 callout_drain(&sc->sfl_callout);
1437 if (mtx_initialized(&sc->tids.ftid_lock)) {
1438 mtx_destroy(&sc->tids.ftid_lock);
1439 cv_destroy(&sc->tids.ftid_cv);
1441 if (mtx_initialized(&sc->tids.atid_lock))
1442 mtx_destroy(&sc->tids.atid_lock);
1443 if (mtx_initialized(&sc->sfl_lock))
1444 mtx_destroy(&sc->sfl_lock);
1445 if (mtx_initialized(&sc->ifp_lock))
1446 mtx_destroy(&sc->ifp_lock);
1447 if (mtx_initialized(&sc->reg_lock))
1448 mtx_destroy(&sc->reg_lock);
1450 if (rw_initialized(&sc->policy_lock)) {
1451 rw_destroy(&sc->policy_lock);
1453 if (sc->policy != NULL)
1454 free_offload_policy(sc->policy);
1458 for (i = 0; i < NUM_MEMWIN; i++) {
1459 struct memwin *mw = &sc->memwin[i];
1461 if (rw_initialized(&mw->mw_lock))
1462 rw_destroy(&mw->mw_lock);
1465 bzero(sc, sizeof(*sc));
1471 cxgbe_probe(device_t dev)
1474 struct port_info *pi = device_get_softc(dev);
1476 snprintf(buf, sizeof(buf), "port %d", pi->port_id);
1477 device_set_desc_copy(dev, buf);
1479 return (BUS_PROBE_DEFAULT);
1482 #define T4_CAP (IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_HWCSUM | \
1483 IFCAP_VLAN_HWCSUM | IFCAP_TSO | IFCAP_JUMBO_MTU | IFCAP_LRO | \
1484 IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWCSUM_IPV6 | IFCAP_HWSTATS | \
1486 #define T4_CAP_ENABLE (T4_CAP)
1489 cxgbe_vi_attach(device_t dev, struct vi_info *vi)
1494 vi->xact_addr_filt = -1;
1495 callout_init(&vi->tick, 1);
1497 /* Allocate an ifnet and set it up */
1498 ifp = if_alloc(IFT_ETHER);
1500 device_printf(dev, "Cannot allocate ifnet\n");
1506 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1507 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1509 ifp->if_init = cxgbe_init;
1510 ifp->if_ioctl = cxgbe_ioctl;
1511 ifp->if_transmit = cxgbe_transmit;
1512 ifp->if_qflush = cxgbe_qflush;
1513 ifp->if_get_counter = cxgbe_get_counter;
1515 ifp->if_snd_tag_alloc = cxgbe_snd_tag_alloc;
1516 ifp->if_snd_tag_modify = cxgbe_snd_tag_modify;
1517 ifp->if_snd_tag_query = cxgbe_snd_tag_query;
1518 ifp->if_snd_tag_free = cxgbe_snd_tag_free;
1521 ifp->if_capabilities = T4_CAP;
1522 ifp->if_capenable = T4_CAP_ENABLE;
1524 if (vi->nofldrxq != 0)
1525 ifp->if_capabilities |= IFCAP_TOE;
1528 if (vi->nnmrxq != 0)
1529 ifp->if_capabilities |= IFCAP_NETMAP;
1532 if (is_ethoffload(vi->pi->adapter) && vi->nofldtxq != 0) {
1533 ifp->if_capabilities |= IFCAP_TXRTLMT;
1534 ifp->if_capenable |= IFCAP_TXRTLMT;
1537 ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_IP | CSUM_TSO |
1538 CSUM_UDP_IPV6 | CSUM_TCP_IPV6;
1540 ifp->if_hw_tsomax = IP_MAXPACKET;
1541 ifp->if_hw_tsomaxsegcount = TX_SGL_SEGS_TSO;
1543 if (is_ethoffload(vi->pi->adapter) && vi->nofldtxq != 0)
1544 ifp->if_hw_tsomaxsegcount = TX_SGL_SEGS_EO_TSO;
1546 ifp->if_hw_tsomaxsegsize = 0;
1548 ether_ifattach(ifp, vi->hw_addr);
1550 if (ifp->if_capabilities & IFCAP_NETMAP)
1551 cxgbe_nm_attach(vi);
1553 sb = sbuf_new_auto();
1554 sbuf_printf(sb, "%d txq, %d rxq (NIC)", vi->ntxq, vi->nrxq);
1555 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
1556 switch (ifp->if_capabilities & (IFCAP_TOE | IFCAP_TXRTLMT)) {
1558 sbuf_printf(sb, "; %d txq (TOE)", vi->nofldtxq);
1560 case IFCAP_TOE | IFCAP_TXRTLMT:
1561 sbuf_printf(sb, "; %d txq (TOE/ETHOFLD)", vi->nofldtxq);
1564 sbuf_printf(sb, "; %d txq (ETHOFLD)", vi->nofldtxq);
1569 if (ifp->if_capabilities & IFCAP_TOE)
1570 sbuf_printf(sb, ", %d rxq (TOE)", vi->nofldrxq);
1573 if (ifp->if_capabilities & IFCAP_NETMAP)
1574 sbuf_printf(sb, "; %d txq, %d rxq (netmap)",
1575 vi->nnmtxq, vi->nnmrxq);
1578 device_printf(dev, "%s\n", sbuf_data(sb));
1587 cxgbe_attach(device_t dev)
1589 struct port_info *pi = device_get_softc(dev);
1590 struct adapter *sc = pi->adapter;
1594 callout_init_mtx(&pi->tick, &pi->pi_lock, 0);
1596 rc = cxgbe_vi_attach(dev, &pi->vi[0]);
1600 for_each_vi(pi, i, vi) {
1603 vi->dev = device_add_child(dev, sc->names->vi_ifnet_name, -1);
1604 if (vi->dev == NULL) {
1605 device_printf(dev, "failed to add VI %d\n", i);
1608 device_set_softc(vi->dev, vi);
1613 bus_generic_attach(dev);
1619 cxgbe_vi_detach(struct vi_info *vi)
1621 struct ifnet *ifp = vi->ifp;
1623 ether_ifdetach(ifp);
1625 /* Let detach proceed even if these fail. */
1627 if (ifp->if_capabilities & IFCAP_NETMAP)
1628 cxgbe_nm_detach(vi);
1630 cxgbe_uninit_synchronized(vi);
1631 callout_drain(&vi->tick);
1639 cxgbe_detach(device_t dev)
1641 struct port_info *pi = device_get_softc(dev);
1642 struct adapter *sc = pi->adapter;
1645 /* Detach the extra VIs first. */
1646 rc = bus_generic_detach(dev);
1649 device_delete_children(dev);
1651 doom_vi(sc, &pi->vi[0]);
1653 if (pi->flags & HAS_TRACEQ) {
1654 sc->traceq = -1; /* cloner should not create ifnet */
1655 t4_tracer_port_detach(sc);
1658 cxgbe_vi_detach(&pi->vi[0]);
1659 callout_drain(&pi->tick);
1660 ifmedia_removeall(&pi->media);
1662 end_synchronized_op(sc, 0);
1668 cxgbe_init(void *arg)
1670 struct vi_info *vi = arg;
1671 struct adapter *sc = vi->pi->adapter;
1673 if (begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4init") != 0)
1675 cxgbe_init_synchronized(vi);
1676 end_synchronized_op(sc, 0);
1680 cxgbe_ioctl(struct ifnet *ifp, unsigned long cmd, caddr_t data)
1682 int rc = 0, mtu, flags;
1683 struct vi_info *vi = ifp->if_softc;
1684 struct port_info *pi = vi->pi;
1685 struct adapter *sc = pi->adapter;
1686 struct ifreq *ifr = (struct ifreq *)data;
1692 if (mtu < ETHERMIN || mtu > MAX_MTU)
1695 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4mtu");
1699 if (vi->flags & VI_INIT_DONE) {
1700 t4_update_fl_bufsize(ifp);
1701 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1702 rc = update_mac_settings(ifp, XGMAC_MTU);
1704 end_synchronized_op(sc, 0);
1708 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4flg");
1712 if (ifp->if_flags & IFF_UP) {
1713 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1714 flags = vi->if_flags;
1715 if ((ifp->if_flags ^ flags) &
1716 (IFF_PROMISC | IFF_ALLMULTI)) {
1717 rc = update_mac_settings(ifp,
1718 XGMAC_PROMISC | XGMAC_ALLMULTI);
1721 rc = cxgbe_init_synchronized(vi);
1723 vi->if_flags = ifp->if_flags;
1724 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1725 rc = cxgbe_uninit_synchronized(vi);
1727 end_synchronized_op(sc, 0);
1732 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4multi");
1735 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1736 rc = update_mac_settings(ifp, XGMAC_MCADDRS);
1737 end_synchronized_op(sc, 0);
1741 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4cap");
1745 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1746 if (mask & IFCAP_TXCSUM) {
1747 ifp->if_capenable ^= IFCAP_TXCSUM;
1748 ifp->if_hwassist ^= (CSUM_TCP | CSUM_UDP | CSUM_IP);
1750 if (IFCAP_TSO4 & ifp->if_capenable &&
1751 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1752 ifp->if_capenable &= ~IFCAP_TSO4;
1754 "tso4 disabled due to -txcsum.\n");
1757 if (mask & IFCAP_TXCSUM_IPV6) {
1758 ifp->if_capenable ^= IFCAP_TXCSUM_IPV6;
1759 ifp->if_hwassist ^= (CSUM_UDP_IPV6 | CSUM_TCP_IPV6);
1761 if (IFCAP_TSO6 & ifp->if_capenable &&
1762 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1763 ifp->if_capenable &= ~IFCAP_TSO6;
1765 "tso6 disabled due to -txcsum6.\n");
1768 if (mask & IFCAP_RXCSUM)
1769 ifp->if_capenable ^= IFCAP_RXCSUM;
1770 if (mask & IFCAP_RXCSUM_IPV6)
1771 ifp->if_capenable ^= IFCAP_RXCSUM_IPV6;
1774 * Note that we leave CSUM_TSO alone (it is always set). The
1775 * kernel takes both IFCAP_TSOx and CSUM_TSO into account before
1776 * sending a TSO request our way, so it's sufficient to toggle
1779 if (mask & IFCAP_TSO4) {
1780 if (!(IFCAP_TSO4 & ifp->if_capenable) &&
1781 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1782 if_printf(ifp, "enable txcsum first.\n");
1786 ifp->if_capenable ^= IFCAP_TSO4;
1788 if (mask & IFCAP_TSO6) {
1789 if (!(IFCAP_TSO6 & ifp->if_capenable) &&
1790 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1791 if_printf(ifp, "enable txcsum6 first.\n");
1795 ifp->if_capenable ^= IFCAP_TSO6;
1797 if (mask & IFCAP_LRO) {
1798 #if defined(INET) || defined(INET6)
1800 struct sge_rxq *rxq;
1802 ifp->if_capenable ^= IFCAP_LRO;
1803 for_each_rxq(vi, i, rxq) {
1804 if (ifp->if_capenable & IFCAP_LRO)
1805 rxq->iq.flags |= IQ_LRO_ENABLED;
1807 rxq->iq.flags &= ~IQ_LRO_ENABLED;
1812 if (mask & IFCAP_TOE) {
1813 int enable = (ifp->if_capenable ^ mask) & IFCAP_TOE;
1815 rc = toe_capability(vi, enable);
1819 ifp->if_capenable ^= mask;
1822 if (mask & IFCAP_VLAN_HWTAGGING) {
1823 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
1824 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1825 rc = update_mac_settings(ifp, XGMAC_VLANEX);
1827 if (mask & IFCAP_VLAN_MTU) {
1828 ifp->if_capenable ^= IFCAP_VLAN_MTU;
1830 /* Need to find out how to disable auto-mtu-inflation */
1832 if (mask & IFCAP_VLAN_HWTSO)
1833 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
1834 if (mask & IFCAP_VLAN_HWCSUM)
1835 ifp->if_capenable ^= IFCAP_VLAN_HWCSUM;
1837 if (mask & IFCAP_TXRTLMT)
1838 ifp->if_capenable ^= IFCAP_TXRTLMT;
1840 if (mask & IFCAP_HWRXTSTMP) {
1842 struct sge_rxq *rxq;
1844 ifp->if_capenable ^= IFCAP_HWRXTSTMP;
1845 for_each_rxq(vi, i, rxq) {
1846 if (ifp->if_capenable & IFCAP_HWRXTSTMP)
1847 rxq->iq.flags |= IQ_RX_TIMESTAMP;
1849 rxq->iq.flags &= ~IQ_RX_TIMESTAMP;
1853 #ifdef VLAN_CAPABILITIES
1854 VLAN_CAPABILITIES(ifp);
1857 end_synchronized_op(sc, 0);
1863 ifmedia_ioctl(ifp, ifr, &pi->media, cmd);
1867 struct ifi2creq i2c;
1869 rc = copyin(ifr_data_get_ptr(ifr), &i2c, sizeof(i2c));
1872 if (i2c.dev_addr != 0xA0 && i2c.dev_addr != 0xA2) {
1876 if (i2c.len > sizeof(i2c.data)) {
1880 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4i2c");
1883 rc = -t4_i2c_rd(sc, sc->mbox, pi->port_id, i2c.dev_addr,
1884 i2c.offset, i2c.len, &i2c.data[0]);
1885 end_synchronized_op(sc, 0);
1887 rc = copyout(&i2c, ifr_data_get_ptr(ifr), sizeof(i2c));
1892 rc = ether_ioctl(ifp, cmd, data);
1899 cxgbe_transmit(struct ifnet *ifp, struct mbuf *m)
1901 struct vi_info *vi = ifp->if_softc;
1902 struct port_info *pi = vi->pi;
1903 struct adapter *sc = pi->adapter;
1904 struct sge_txq *txq;
1909 MPASS(m->m_nextpkt == NULL); /* not quite ready for this yet */
1911 if (__predict_false(pi->link_cfg.link_ok == false)) {
1916 rc = parse_pkt(sc, &m);
1917 if (__predict_false(rc != 0)) {
1918 MPASS(m == NULL); /* was freed already */
1919 atomic_add_int(&pi->tx_parse_error, 1); /* rare, atomic is ok */
1923 if (m->m_pkthdr.snd_tag != NULL) {
1924 /* EAGAIN tells the stack we are not the correct interface. */
1925 if (__predict_false(ifp != m->m_pkthdr.snd_tag->ifp)) {
1930 return (ethofld_transmit(ifp, m));
1935 txq = &sc->sge.txq[vi->first_txq];
1936 if (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE)
1937 txq += ((m->m_pkthdr.flowid % (vi->ntxq - vi->rsrv_noflowq)) +
1941 rc = mp_ring_enqueue(txq->r, items, 1, 4096);
1942 if (__predict_false(rc != 0))
1949 cxgbe_qflush(struct ifnet *ifp)
1951 struct vi_info *vi = ifp->if_softc;
1952 struct sge_txq *txq;
1955 /* queues do not exist if !VI_INIT_DONE. */
1956 if (vi->flags & VI_INIT_DONE) {
1957 for_each_txq(vi, i, txq) {
1959 txq->eq.flags |= EQ_QFLUSH;
1961 while (!mp_ring_is_idle(txq->r)) {
1962 mp_ring_check_drainage(txq->r, 0);
1966 txq->eq.flags &= ~EQ_QFLUSH;
1974 vi_get_counter(struct ifnet *ifp, ift_counter c)
1976 struct vi_info *vi = ifp->if_softc;
1977 struct fw_vi_stats_vf *s = &vi->stats;
1979 vi_refresh_stats(vi->pi->adapter, vi);
1982 case IFCOUNTER_IPACKETS:
1983 return (s->rx_bcast_frames + s->rx_mcast_frames +
1984 s->rx_ucast_frames);
1985 case IFCOUNTER_IERRORS:
1986 return (s->rx_err_frames);
1987 case IFCOUNTER_OPACKETS:
1988 return (s->tx_bcast_frames + s->tx_mcast_frames +
1989 s->tx_ucast_frames + s->tx_offload_frames);
1990 case IFCOUNTER_OERRORS:
1991 return (s->tx_drop_frames);
1992 case IFCOUNTER_IBYTES:
1993 return (s->rx_bcast_bytes + s->rx_mcast_bytes +
1995 case IFCOUNTER_OBYTES:
1996 return (s->tx_bcast_bytes + s->tx_mcast_bytes +
1997 s->tx_ucast_bytes + s->tx_offload_bytes);
1998 case IFCOUNTER_IMCASTS:
1999 return (s->rx_mcast_frames);
2000 case IFCOUNTER_OMCASTS:
2001 return (s->tx_mcast_frames);
2002 case IFCOUNTER_OQDROPS: {
2006 if (vi->flags & VI_INIT_DONE) {
2008 struct sge_txq *txq;
2010 for_each_txq(vi, i, txq)
2011 drops += counter_u64_fetch(txq->r->drops);
2019 return (if_get_counter_default(ifp, c));
2024 cxgbe_get_counter(struct ifnet *ifp, ift_counter c)
2026 struct vi_info *vi = ifp->if_softc;
2027 struct port_info *pi = vi->pi;
2028 struct adapter *sc = pi->adapter;
2029 struct port_stats *s = &pi->stats;
2031 if (pi->nvi > 1 || sc->flags & IS_VF)
2032 return (vi_get_counter(ifp, c));
2034 cxgbe_refresh_stats(sc, pi);
2037 case IFCOUNTER_IPACKETS:
2038 return (s->rx_frames);
2040 case IFCOUNTER_IERRORS:
2041 return (s->rx_jabber + s->rx_runt + s->rx_too_long +
2042 s->rx_fcs_err + s->rx_len_err);
2044 case IFCOUNTER_OPACKETS:
2045 return (s->tx_frames);
2047 case IFCOUNTER_OERRORS:
2048 return (s->tx_error_frames);
2050 case IFCOUNTER_IBYTES:
2051 return (s->rx_octets);
2053 case IFCOUNTER_OBYTES:
2054 return (s->tx_octets);
2056 case IFCOUNTER_IMCASTS:
2057 return (s->rx_mcast_frames);
2059 case IFCOUNTER_OMCASTS:
2060 return (s->tx_mcast_frames);
2062 case IFCOUNTER_IQDROPS:
2063 return (s->rx_ovflow0 + s->rx_ovflow1 + s->rx_ovflow2 +
2064 s->rx_ovflow3 + s->rx_trunc0 + s->rx_trunc1 + s->rx_trunc2 +
2065 s->rx_trunc3 + pi->tnl_cong_drops);
2067 case IFCOUNTER_OQDROPS: {
2071 if (vi->flags & VI_INIT_DONE) {
2073 struct sge_txq *txq;
2075 for_each_txq(vi, i, txq)
2076 drops += counter_u64_fetch(txq->r->drops);
2084 return (if_get_counter_default(ifp, c));
2089 * The kernel picks a media from the list we had provided but we still validate
2093 cxgbe_media_change(struct ifnet *ifp)
2095 struct vi_info *vi = ifp->if_softc;
2096 struct port_info *pi = vi->pi;
2097 struct ifmedia *ifm = &pi->media;
2098 struct link_config *lc = &pi->link_cfg;
2099 struct adapter *sc = pi->adapter;
2102 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4mec");
2106 if (IFM_SUBTYPE(ifm->ifm_media) == IFM_AUTO) {
2107 /* ifconfig .. media autoselect */
2108 if (!(lc->supported & FW_PORT_CAP32_ANEG)) {
2109 rc = ENOTSUP; /* AN not supported by transceiver */
2112 lc->requested_aneg = AUTONEG_ENABLE;
2113 lc->requested_speed = 0;
2114 lc->requested_fc |= PAUSE_AUTONEG;
2116 lc->requested_aneg = AUTONEG_DISABLE;
2117 lc->requested_speed =
2118 ifmedia_baudrate(ifm->ifm_media) / 1000000;
2119 lc->requested_fc = 0;
2120 if (IFM_OPTIONS(ifm->ifm_media) & IFM_ETH_RXPAUSE)
2121 lc->requested_fc |= PAUSE_RX;
2122 if (IFM_OPTIONS(ifm->ifm_media) & IFM_ETH_TXPAUSE)
2123 lc->requested_fc |= PAUSE_TX;
2125 if (pi->up_vis > 0) {
2126 fixup_link_config(pi);
2127 rc = apply_link_config(pi);
2131 end_synchronized_op(sc, 0);
2136 * Base media word (without ETHER, pause, link active, etc.) for the port at the
2140 port_mword(struct port_info *pi, uint32_t speed)
2143 MPASS(speed & M_FW_PORT_CAP32_SPEED);
2144 MPASS(powerof2(speed));
2146 switch(pi->port_type) {
2147 case FW_PORT_TYPE_BT_SGMII:
2148 case FW_PORT_TYPE_BT_XFI:
2149 case FW_PORT_TYPE_BT_XAUI:
2152 case FW_PORT_CAP32_SPEED_100M:
2154 case FW_PORT_CAP32_SPEED_1G:
2155 return (IFM_1000_T);
2156 case FW_PORT_CAP32_SPEED_10G:
2160 case FW_PORT_TYPE_KX4:
2161 if (speed == FW_PORT_CAP32_SPEED_10G)
2162 return (IFM_10G_KX4);
2164 case FW_PORT_TYPE_CX4:
2165 if (speed == FW_PORT_CAP32_SPEED_10G)
2166 return (IFM_10G_CX4);
2168 case FW_PORT_TYPE_KX:
2169 if (speed == FW_PORT_CAP32_SPEED_1G)
2170 return (IFM_1000_KX);
2172 case FW_PORT_TYPE_KR:
2173 case FW_PORT_TYPE_BP_AP:
2174 case FW_PORT_TYPE_BP4_AP:
2175 case FW_PORT_TYPE_BP40_BA:
2176 case FW_PORT_TYPE_KR4_100G:
2177 case FW_PORT_TYPE_KR_SFP28:
2178 case FW_PORT_TYPE_KR_XLAUI:
2180 case FW_PORT_CAP32_SPEED_1G:
2181 return (IFM_1000_KX);
2182 case FW_PORT_CAP32_SPEED_10G:
2183 return (IFM_10G_KR);
2184 case FW_PORT_CAP32_SPEED_25G:
2185 return (IFM_25G_KR);
2186 case FW_PORT_CAP32_SPEED_40G:
2187 return (IFM_40G_KR4);
2188 case FW_PORT_CAP32_SPEED_50G:
2189 return (IFM_50G_KR2);
2190 case FW_PORT_CAP32_SPEED_100G:
2191 return (IFM_100G_KR4);
2194 case FW_PORT_TYPE_FIBER_XFI:
2195 case FW_PORT_TYPE_FIBER_XAUI:
2196 case FW_PORT_TYPE_SFP:
2197 case FW_PORT_TYPE_QSFP_10G:
2198 case FW_PORT_TYPE_QSA:
2199 case FW_PORT_TYPE_QSFP:
2200 case FW_PORT_TYPE_CR4_QSFP:
2201 case FW_PORT_TYPE_CR_QSFP:
2202 case FW_PORT_TYPE_CR2_QSFP:
2203 case FW_PORT_TYPE_SFP28:
2204 /* Pluggable transceiver */
2205 switch (pi->mod_type) {
2206 case FW_PORT_MOD_TYPE_LR:
2208 case FW_PORT_CAP32_SPEED_1G:
2209 return (IFM_1000_LX);
2210 case FW_PORT_CAP32_SPEED_10G:
2211 return (IFM_10G_LR);
2212 case FW_PORT_CAP32_SPEED_25G:
2213 return (IFM_25G_LR);
2214 case FW_PORT_CAP32_SPEED_40G:
2215 return (IFM_40G_LR4);
2216 case FW_PORT_CAP32_SPEED_50G:
2217 return (IFM_50G_LR2);
2218 case FW_PORT_CAP32_SPEED_100G:
2219 return (IFM_100G_LR4);
2222 case FW_PORT_MOD_TYPE_SR:
2224 case FW_PORT_CAP32_SPEED_1G:
2225 return (IFM_1000_SX);
2226 case FW_PORT_CAP32_SPEED_10G:
2227 return (IFM_10G_SR);
2228 case FW_PORT_CAP32_SPEED_25G:
2229 return (IFM_25G_SR);
2230 case FW_PORT_CAP32_SPEED_40G:
2231 return (IFM_40G_SR4);
2232 case FW_PORT_CAP32_SPEED_50G:
2233 return (IFM_50G_SR2);
2234 case FW_PORT_CAP32_SPEED_100G:
2235 return (IFM_100G_SR4);
2238 case FW_PORT_MOD_TYPE_ER:
2239 if (speed == FW_PORT_CAP32_SPEED_10G)
2240 return (IFM_10G_ER);
2242 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
2243 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
2245 case FW_PORT_CAP32_SPEED_1G:
2246 return (IFM_1000_CX);
2247 case FW_PORT_CAP32_SPEED_10G:
2248 return (IFM_10G_TWINAX);
2249 case FW_PORT_CAP32_SPEED_25G:
2250 return (IFM_25G_CR);
2251 case FW_PORT_CAP32_SPEED_40G:
2252 return (IFM_40G_CR4);
2253 case FW_PORT_CAP32_SPEED_50G:
2254 return (IFM_50G_CR2);
2255 case FW_PORT_CAP32_SPEED_100G:
2256 return (IFM_100G_CR4);
2259 case FW_PORT_MOD_TYPE_LRM:
2260 if (speed == FW_PORT_CAP32_SPEED_10G)
2261 return (IFM_10G_LRM);
2263 case FW_PORT_MOD_TYPE_NA:
2264 MPASS(0); /* Not pluggable? */
2266 case FW_PORT_MOD_TYPE_ERROR:
2267 case FW_PORT_MOD_TYPE_UNKNOWN:
2268 case FW_PORT_MOD_TYPE_NOTSUPPORTED:
2270 case FW_PORT_MOD_TYPE_NONE:
2274 case FW_PORT_TYPE_NONE:
2278 return (IFM_UNKNOWN);
2282 cxgbe_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
2284 struct vi_info *vi = ifp->if_softc;
2285 struct port_info *pi = vi->pi;
2286 struct adapter *sc = pi->adapter;
2287 struct link_config *lc = &pi->link_cfg;
2289 if (begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4med") != 0)
2293 if (pi->up_vis == 0) {
2295 * If all the interfaces are administratively down the firmware
2296 * does not report transceiver changes. Refresh port info here
2297 * so that ifconfig displays accurate ifmedia at all times.
2298 * This is the only reason we have a synchronized op in this
2299 * function. Just PORT_LOCK would have been enough otherwise.
2301 t4_update_port_info(pi);
2302 build_medialist(pi);
2306 ifmr->ifm_status = IFM_AVALID;
2307 if (lc->link_ok == false)
2309 ifmr->ifm_status |= IFM_ACTIVE;
2312 ifmr->ifm_active = IFM_ETHER | IFM_FDX;
2313 ifmr->ifm_active &= ~(IFM_ETH_TXPAUSE | IFM_ETH_RXPAUSE);
2314 if (lc->fc & PAUSE_RX)
2315 ifmr->ifm_active |= IFM_ETH_RXPAUSE;
2316 if (lc->fc & PAUSE_TX)
2317 ifmr->ifm_active |= IFM_ETH_TXPAUSE;
2318 ifmr->ifm_active |= port_mword(pi, speed_to_fwcap(lc->speed));
2321 end_synchronized_op(sc, 0);
2325 vcxgbe_probe(device_t dev)
2328 struct vi_info *vi = device_get_softc(dev);
2330 snprintf(buf, sizeof(buf), "port %d vi %td", vi->pi->port_id,
2332 device_set_desc_copy(dev, buf);
2334 return (BUS_PROBE_DEFAULT);
2338 alloc_extra_vi(struct adapter *sc, struct port_info *pi, struct vi_info *vi)
2340 int func, index, rc;
2341 uint32_t param, val;
2343 ASSERT_SYNCHRONIZED_OP(sc);
2345 index = vi - pi->vi;
2346 MPASS(index > 0); /* This function deals with _extra_ VIs only */
2347 KASSERT(index < nitems(vi_mac_funcs),
2348 ("%s: VI %s doesn't have a MAC func", __func__,
2349 device_get_nameunit(vi->dev)));
2350 func = vi_mac_funcs[index];
2351 rc = t4_alloc_vi_func(sc, sc->mbox, pi->tx_chan, sc->pf, 0, 1,
2352 vi->hw_addr, &vi->rss_size, func, 0);
2354 device_printf(vi->dev, "failed to allocate virtual interface %d"
2355 "for port %d: %d\n", index, pi->port_id, -rc);
2359 if (chip_id(sc) <= CHELSIO_T5)
2360 vi->smt_idx = (rc & 0x7f) << 1;
2362 vi->smt_idx = (rc & 0x7f);
2364 if (vi->rss_size == 1) {
2366 * This VI didn't get a slice of the RSS table. Reduce the
2367 * number of VIs being created (hw.cxgbe.num_vis) or modify the
2368 * configuration file (nvi, rssnvi for this PF) if this is a
2371 device_printf(vi->dev, "RSS table not available.\n");
2372 vi->rss_base = 0xffff;
2377 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
2378 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_RSSINFO) |
2379 V_FW_PARAMS_PARAM_YZ(vi->viid);
2380 rc = t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
2382 vi->rss_base = 0xffff;
2384 MPASS((val >> 16) == vi->rss_size);
2385 vi->rss_base = val & 0xffff;
2392 vcxgbe_attach(device_t dev)
2395 struct port_info *pi;
2399 vi = device_get_softc(dev);
2403 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4via");
2406 rc = alloc_extra_vi(sc, pi, vi);
2407 end_synchronized_op(sc, 0);
2411 rc = cxgbe_vi_attach(dev, vi);
2413 t4_free_vi(sc, sc->mbox, sc->pf, 0, vi->viid);
2420 vcxgbe_detach(device_t dev)
2425 vi = device_get_softc(dev);
2426 sc = vi->pi->adapter;
2430 cxgbe_vi_detach(vi);
2431 t4_free_vi(sc, sc->mbox, sc->pf, 0, vi->viid);
2433 end_synchronized_op(sc, 0);
2439 t4_fatal_err(struct adapter *sc)
2441 t4_set_reg_field(sc, A_SGE_CONTROL, F_GLOBALENABLE, 0);
2442 t4_intr_disable(sc);
2443 log(LOG_EMERG, "%s: encountered fatal error, adapter stopped.\n",
2444 device_get_nameunit(sc->dev));
2445 if (t4_panic_on_fatal_err)
2446 panic("panic requested on fatal error");
2450 t4_add_adapter(struct adapter *sc)
2452 sx_xlock(&t4_list_lock);
2453 SLIST_INSERT_HEAD(&t4_list, sc, link);
2454 sx_xunlock(&t4_list_lock);
2458 t4_map_bars_0_and_4(struct adapter *sc)
2460 sc->regs_rid = PCIR_BAR(0);
2461 sc->regs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
2462 &sc->regs_rid, RF_ACTIVE);
2463 if (sc->regs_res == NULL) {
2464 device_printf(sc->dev, "cannot map registers.\n");
2467 sc->bt = rman_get_bustag(sc->regs_res);
2468 sc->bh = rman_get_bushandle(sc->regs_res);
2469 sc->mmio_len = rman_get_size(sc->regs_res);
2470 setbit(&sc->doorbells, DOORBELL_KDB);
2472 sc->msix_rid = PCIR_BAR(4);
2473 sc->msix_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
2474 &sc->msix_rid, RF_ACTIVE);
2475 if (sc->msix_res == NULL) {
2476 device_printf(sc->dev, "cannot map MSI-X BAR.\n");
2484 t4_map_bar_2(struct adapter *sc)
2488 * T4: only iWARP driver uses the userspace doorbells. There is no need
2489 * to map it if RDMA is disabled.
2491 if (is_t4(sc) && sc->rdmacaps == 0)
2494 sc->udbs_rid = PCIR_BAR(2);
2495 sc->udbs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
2496 &sc->udbs_rid, RF_ACTIVE);
2497 if (sc->udbs_res == NULL) {
2498 device_printf(sc->dev, "cannot map doorbell BAR.\n");
2501 sc->udbs_base = rman_get_virtual(sc->udbs_res);
2503 if (chip_id(sc) >= CHELSIO_T5) {
2504 setbit(&sc->doorbells, DOORBELL_UDB);
2505 #if defined(__i386__) || defined(__amd64__)
2506 if (t5_write_combine) {
2510 * Enable write combining on BAR2. This is the
2511 * userspace doorbell BAR and is split into 128B
2512 * (UDBS_SEG_SIZE) doorbell regions, each associated
2513 * with an egress queue. The first 64B has the doorbell
2514 * and the second 64B can be used to submit a tx work
2515 * request with an implicit doorbell.
2518 rc = pmap_change_attr((vm_offset_t)sc->udbs_base,
2519 rman_get_size(sc->udbs_res), PAT_WRITE_COMBINING);
2521 clrbit(&sc->doorbells, DOORBELL_UDB);
2522 setbit(&sc->doorbells, DOORBELL_WCWR);
2523 setbit(&sc->doorbells, DOORBELL_UDBWC);
2525 device_printf(sc->dev,
2526 "couldn't enable write combining: %d\n",
2530 mode = is_t5(sc) ? V_STATMODE(0) : V_T6_STATMODE(0);
2531 t4_write_reg(sc, A_SGE_STAT_CFG,
2532 V_STATSOURCE_T5(7) | mode);
2536 sc->iwt.wc_en = isset(&sc->doorbells, DOORBELL_UDBWC) ? 1 : 0;
2541 struct memwin_init {
2546 static const struct memwin_init t4_memwin[NUM_MEMWIN] = {
2547 { MEMWIN0_BASE, MEMWIN0_APERTURE },
2548 { MEMWIN1_BASE, MEMWIN1_APERTURE },
2549 { MEMWIN2_BASE_T4, MEMWIN2_APERTURE_T4 }
2552 static const struct memwin_init t5_memwin[NUM_MEMWIN] = {
2553 { MEMWIN0_BASE, MEMWIN0_APERTURE },
2554 { MEMWIN1_BASE, MEMWIN1_APERTURE },
2555 { MEMWIN2_BASE_T5, MEMWIN2_APERTURE_T5 },
2559 setup_memwin(struct adapter *sc)
2561 const struct memwin_init *mw_init;
2568 * Read low 32b of bar0 indirectly via the hardware backdoor
2569 * mechanism. Works from within PCI passthrough environments
2570 * too, where rman_get_start() can return a different value. We
2571 * need to program the T4 memory window decoders with the actual
2572 * addresses that will be coming across the PCIe link.
2574 bar0 = t4_hw_pci_read_cfg4(sc, PCIR_BAR(0));
2575 bar0 &= (uint32_t) PCIM_BAR_MEM_BASE;
2577 mw_init = &t4_memwin[0];
2579 /* T5+ use the relative offset inside the PCIe BAR */
2582 mw_init = &t5_memwin[0];
2585 for (i = 0, mw = &sc->memwin[0]; i < NUM_MEMWIN; i++, mw_init++, mw++) {
2586 rw_init(&mw->mw_lock, "memory window access");
2587 mw->mw_base = mw_init->base;
2588 mw->mw_aperture = mw_init->aperture;
2591 PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, i),
2592 (mw->mw_base + bar0) | V_BIR(0) |
2593 V_WINDOW(ilog2(mw->mw_aperture) - 10));
2594 rw_wlock(&mw->mw_lock);
2595 position_memwin(sc, i, 0);
2596 rw_wunlock(&mw->mw_lock);
2600 t4_read_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 2));
2604 * Positions the memory window at the given address in the card's address space.
2605 * There are some alignment requirements and the actual position may be at an
2606 * address prior to the requested address. mw->mw_curpos always has the actual
2607 * position of the window.
2610 position_memwin(struct adapter *sc, int idx, uint32_t addr)
2616 MPASS(idx >= 0 && idx < NUM_MEMWIN);
2617 mw = &sc->memwin[idx];
2618 rw_assert(&mw->mw_lock, RA_WLOCKED);
2622 mw->mw_curpos = addr & ~0xf; /* start must be 16B aligned */
2624 pf = V_PFNUM(sc->pf);
2625 mw->mw_curpos = addr & ~0x7f; /* start must be 128B aligned */
2627 reg = PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, idx);
2628 t4_write_reg(sc, reg, mw->mw_curpos | pf);
2629 t4_read_reg(sc, reg); /* flush */
2633 rw_via_memwin(struct adapter *sc, int idx, uint32_t addr, uint32_t *val,
2639 MPASS(idx >= 0 && idx < NUM_MEMWIN);
2641 /* Memory can only be accessed in naturally aligned 4 byte units */
2642 if (addr & 3 || len & 3 || len <= 0)
2645 mw = &sc->memwin[idx];
2647 rw_rlock(&mw->mw_lock);
2648 mw_end = mw->mw_curpos + mw->mw_aperture;
2649 if (addr >= mw_end || addr < mw->mw_curpos) {
2650 /* Will need to reposition the window */
2651 if (!rw_try_upgrade(&mw->mw_lock)) {
2652 rw_runlock(&mw->mw_lock);
2653 rw_wlock(&mw->mw_lock);
2655 rw_assert(&mw->mw_lock, RA_WLOCKED);
2656 position_memwin(sc, idx, addr);
2657 rw_downgrade(&mw->mw_lock);
2658 mw_end = mw->mw_curpos + mw->mw_aperture;
2660 rw_assert(&mw->mw_lock, RA_RLOCKED);
2661 while (addr < mw_end && len > 0) {
2663 v = t4_read_reg(sc, mw->mw_base + addr -
2665 *val++ = le32toh(v);
2668 t4_write_reg(sc, mw->mw_base + addr -
2669 mw->mw_curpos, htole32(v));
2674 rw_runlock(&mw->mw_lock);
2681 alloc_atid_tab(struct tid_info *t, int flags)
2685 MPASS(t->natids > 0);
2686 MPASS(t->atid_tab == NULL);
2688 t->atid_tab = malloc(t->natids * sizeof(*t->atid_tab), M_CXGBE,
2690 if (t->atid_tab == NULL)
2692 mtx_init(&t->atid_lock, "atid lock", NULL, MTX_DEF);
2693 t->afree = t->atid_tab;
2694 t->atids_in_use = 0;
2695 for (i = 1; i < t->natids; i++)
2696 t->atid_tab[i - 1].next = &t->atid_tab[i];
2697 t->atid_tab[t->natids - 1].next = NULL;
2703 free_atid_tab(struct tid_info *t)
2706 KASSERT(t->atids_in_use == 0,
2707 ("%s: %d atids still in use.", __func__, t->atids_in_use));
2709 if (mtx_initialized(&t->atid_lock))
2710 mtx_destroy(&t->atid_lock);
2711 free(t->atid_tab, M_CXGBE);
2716 alloc_atid(struct adapter *sc, void *ctx)
2718 struct tid_info *t = &sc->tids;
2721 mtx_lock(&t->atid_lock);
2723 union aopen_entry *p = t->afree;
2725 atid = p - t->atid_tab;
2726 MPASS(atid <= M_TID_TID);
2731 mtx_unlock(&t->atid_lock);
2736 lookup_atid(struct adapter *sc, int atid)
2738 struct tid_info *t = &sc->tids;
2740 return (t->atid_tab[atid].data);
2744 free_atid(struct adapter *sc, int atid)
2746 struct tid_info *t = &sc->tids;
2747 union aopen_entry *p = &t->atid_tab[atid];
2749 mtx_lock(&t->atid_lock);
2753 mtx_unlock(&t->atid_lock);
2757 queue_tid_release(struct adapter *sc, int tid)
2760 CXGBE_UNIMPLEMENTED("deferred tid release");
2764 release_tid(struct adapter *sc, int tid, struct sge_wrq *ctrlq)
2767 struct cpl_tid_release *req;
2769 wr = alloc_wrqe(sizeof(*req), ctrlq);
2771 queue_tid_release(sc, tid); /* defer */
2776 INIT_TP_WR_MIT_CPL(req, CPL_TID_RELEASE, tid);
2782 t4_range_cmp(const void *a, const void *b)
2784 return ((const struct t4_range *)a)->start -
2785 ((const struct t4_range *)b)->start;
2789 * Verify that the memory range specified by the addr/len pair is valid within
2790 * the card's address space.
2793 validate_mem_range(struct adapter *sc, uint32_t addr, int len)
2795 struct t4_range mem_ranges[4], *r, *next;
2796 uint32_t em, addr_len;
2797 int i, n, remaining;
2799 /* Memory can only be accessed in naturally aligned 4 byte units */
2800 if (addr & 3 || len & 3 || len <= 0)
2803 /* Enabled memories */
2804 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
2808 bzero(r, sizeof(mem_ranges));
2809 if (em & F_EDRAM0_ENABLE) {
2810 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
2811 r->size = G_EDRAM0_SIZE(addr_len) << 20;
2813 r->start = G_EDRAM0_BASE(addr_len) << 20;
2814 if (addr >= r->start &&
2815 addr + len <= r->start + r->size)
2821 if (em & F_EDRAM1_ENABLE) {
2822 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
2823 r->size = G_EDRAM1_SIZE(addr_len) << 20;
2825 r->start = G_EDRAM1_BASE(addr_len) << 20;
2826 if (addr >= r->start &&
2827 addr + len <= r->start + r->size)
2833 if (em & F_EXT_MEM_ENABLE) {
2834 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
2835 r->size = G_EXT_MEM_SIZE(addr_len) << 20;
2837 r->start = G_EXT_MEM_BASE(addr_len) << 20;
2838 if (addr >= r->start &&
2839 addr + len <= r->start + r->size)
2845 if (is_t5(sc) && em & F_EXT_MEM1_ENABLE) {
2846 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
2847 r->size = G_EXT_MEM1_SIZE(addr_len) << 20;
2849 r->start = G_EXT_MEM1_BASE(addr_len) << 20;
2850 if (addr >= r->start &&
2851 addr + len <= r->start + r->size)
2857 MPASS(n <= nitems(mem_ranges));
2860 /* Sort and merge the ranges. */
2861 qsort(mem_ranges, n, sizeof(struct t4_range), t4_range_cmp);
2863 /* Start from index 0 and examine the next n - 1 entries. */
2865 for (remaining = n - 1; remaining > 0; remaining--, r++) {
2867 MPASS(r->size > 0); /* r is a valid entry. */
2869 MPASS(next->size > 0); /* and so is the next one. */
2871 while (r->start + r->size >= next->start) {
2872 /* Merge the next one into the current entry. */
2873 r->size = max(r->start + r->size,
2874 next->start + next->size) - r->start;
2875 n--; /* One fewer entry in total. */
2876 if (--remaining == 0)
2877 goto done; /* short circuit */
2880 if (next != r + 1) {
2882 * Some entries were merged into r and next
2883 * points to the first valid entry that couldn't
2886 MPASS(next->size > 0); /* must be valid */
2887 memcpy(r + 1, next, remaining * sizeof(*r));
2890 * This so that the foo->size assertion in the
2891 * next iteration of the loop do the right
2892 * thing for entries that were pulled up and are
2895 MPASS(n < nitems(mem_ranges));
2896 bzero(&mem_ranges[n], (nitems(mem_ranges) - n) *
2897 sizeof(struct t4_range));
2902 /* Done merging the ranges. */
2905 for (i = 0; i < n; i++, r++) {
2906 if (addr >= r->start &&
2907 addr + len <= r->start + r->size)
2916 fwmtype_to_hwmtype(int mtype)
2920 case FW_MEMTYPE_EDC0:
2922 case FW_MEMTYPE_EDC1:
2924 case FW_MEMTYPE_EXTMEM:
2926 case FW_MEMTYPE_EXTMEM1:
2929 panic("%s: cannot translate fw mtype %d.", __func__, mtype);
2934 * Verify that the memory range specified by the memtype/offset/len pair is
2935 * valid and lies entirely within the memtype specified. The global address of
2936 * the start of the range is returned in addr.
2939 validate_mt_off_len(struct adapter *sc, int mtype, uint32_t off, int len,
2942 uint32_t em, addr_len, maddr;
2944 /* Memory can only be accessed in naturally aligned 4 byte units */
2945 if (off & 3 || len & 3 || len == 0)
2948 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
2949 switch (fwmtype_to_hwmtype(mtype)) {
2951 if (!(em & F_EDRAM0_ENABLE))
2953 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
2954 maddr = G_EDRAM0_BASE(addr_len) << 20;
2957 if (!(em & F_EDRAM1_ENABLE))
2959 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
2960 maddr = G_EDRAM1_BASE(addr_len) << 20;
2963 if (!(em & F_EXT_MEM_ENABLE))
2965 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
2966 maddr = G_EXT_MEM_BASE(addr_len) << 20;
2969 if (!is_t5(sc) || !(em & F_EXT_MEM1_ENABLE))
2971 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
2972 maddr = G_EXT_MEM1_BASE(addr_len) << 20;
2978 *addr = maddr + off; /* global address */
2979 return (validate_mem_range(sc, *addr, len));
2983 fixup_devlog_params(struct adapter *sc)
2985 struct devlog_params *dparams = &sc->params.devlog;
2988 rc = validate_mt_off_len(sc, dparams->memtype, dparams->start,
2989 dparams->size, &dparams->addr);
2995 update_nirq(struct intrs_and_queues *iaq, int nports)
2997 int extra = T4_EXTRA_INTR;
3000 iaq->nirq += nports * (iaq->nrxq + iaq->nofldrxq);
3001 iaq->nirq += nports * (iaq->num_vis - 1) *
3002 max(iaq->nrxq_vi, iaq->nnmrxq_vi);
3003 iaq->nirq += nports * (iaq->num_vis - 1) * iaq->nofldrxq_vi;
3007 * Adjust requirements to fit the number of interrupts available.
3010 calculate_iaq(struct adapter *sc, struct intrs_and_queues *iaq, int itype,
3014 const int nports = sc->params.nports;
3019 bzero(iaq, sizeof(*iaq));
3020 iaq->intr_type = itype;
3021 iaq->num_vis = t4_num_vis;
3022 iaq->ntxq = t4_ntxq;
3023 iaq->ntxq_vi = t4_ntxq_vi;
3024 iaq->nrxq = t4_nrxq;
3025 iaq->nrxq_vi = t4_nrxq_vi;
3026 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
3027 if (is_offload(sc) || is_ethoffload(sc)) {
3028 iaq->nofldtxq = t4_nofldtxq;
3029 iaq->nofldtxq_vi = t4_nofldtxq_vi;
3033 if (is_offload(sc)) {
3034 iaq->nofldrxq = t4_nofldrxq;
3035 iaq->nofldrxq_vi = t4_nofldrxq_vi;
3039 iaq->nnmtxq_vi = t4_nnmtxq_vi;
3040 iaq->nnmrxq_vi = t4_nnmrxq_vi;
3043 update_nirq(iaq, nports);
3044 if (iaq->nirq <= navail &&
3045 (itype != INTR_MSI || powerof2(iaq->nirq))) {
3047 * This is the normal case -- there are enough interrupts for
3054 * If extra VIs have been configured try reducing their count and see if
3057 while (iaq->num_vis > 1) {
3059 update_nirq(iaq, nports);
3060 if (iaq->nirq <= navail &&
3061 (itype != INTR_MSI || powerof2(iaq->nirq))) {
3062 device_printf(sc->dev, "virtual interfaces per port "
3063 "reduced to %d from %d. nrxq=%u, nofldrxq=%u, "
3064 "nrxq_vi=%u nofldrxq_vi=%u, nnmrxq_vi=%u. "
3065 "itype %d, navail %u, nirq %d.\n",
3066 iaq->num_vis, t4_num_vis, iaq->nrxq, iaq->nofldrxq,
3067 iaq->nrxq_vi, iaq->nofldrxq_vi, iaq->nnmrxq_vi,
3068 itype, navail, iaq->nirq);
3074 * Extra VIs will not be created. Log a message if they were requested.
3076 MPASS(iaq->num_vis == 1);
3077 iaq->ntxq_vi = iaq->nrxq_vi = 0;
3078 iaq->nofldtxq_vi = iaq->nofldrxq_vi = 0;
3079 iaq->nnmtxq_vi = iaq->nnmrxq_vi = 0;
3080 if (iaq->num_vis != t4_num_vis) {
3081 device_printf(sc->dev, "extra virtual interfaces disabled. "
3082 "nrxq=%u, nofldrxq=%u, nrxq_vi=%u nofldrxq_vi=%u, "
3083 "nnmrxq_vi=%u. itype %d, navail %u, nirq %d.\n",
3084 iaq->nrxq, iaq->nofldrxq, iaq->nrxq_vi, iaq->nofldrxq_vi,
3085 iaq->nnmrxq_vi, itype, navail, iaq->nirq);
3089 * Keep reducing the number of NIC rx queues to the next lower power of
3090 * 2 (for even RSS distribution) and halving the TOE rx queues and see
3094 if (iaq->nrxq > 1) {
3097 } while (!powerof2(iaq->nrxq));
3099 if (iaq->nofldrxq > 1)
3100 iaq->nofldrxq >>= 1;
3102 old_nirq = iaq->nirq;
3103 update_nirq(iaq, nports);
3104 if (iaq->nirq <= navail &&
3105 (itype != INTR_MSI || powerof2(iaq->nirq))) {
3106 device_printf(sc->dev, "running with reduced number of "
3107 "rx queues because of shortage of interrupts. "
3108 "nrxq=%u, nofldrxq=%u. "
3109 "itype %d, navail %u, nirq %d.\n", iaq->nrxq,
3110 iaq->nofldrxq, itype, navail, iaq->nirq);
3113 } while (old_nirq != iaq->nirq);
3115 /* One interrupt for everything. Ugh. */
3116 device_printf(sc->dev, "running with minimal number of queues. "
3117 "itype %d, navail %u.\n", itype, navail);
3119 MPASS(iaq->nrxq == 1);
3121 if (iaq->nofldrxq > 1)
3124 MPASS(iaq->num_vis > 0);
3125 if (iaq->num_vis > 1) {
3126 MPASS(iaq->nrxq_vi > 0);
3127 MPASS(iaq->ntxq_vi > 0);
3129 MPASS(iaq->nirq > 0);
3130 MPASS(iaq->nrxq > 0);
3131 MPASS(iaq->ntxq > 0);
3132 if (itype == INTR_MSI) {
3133 MPASS(powerof2(iaq->nirq));
3138 cfg_itype_and_nqueues(struct adapter *sc, struct intrs_and_queues *iaq)
3140 int rc, itype, navail, nalloc;
3142 for (itype = INTR_MSIX; itype; itype >>= 1) {
3144 if ((itype & t4_intr_types) == 0)
3145 continue; /* not allowed */
3147 if (itype == INTR_MSIX)
3148 navail = pci_msix_count(sc->dev);
3149 else if (itype == INTR_MSI)
3150 navail = pci_msi_count(sc->dev);
3157 calculate_iaq(sc, iaq, itype, navail);
3160 if (itype == INTR_MSIX)
3161 rc = pci_alloc_msix(sc->dev, &nalloc);
3162 else if (itype == INTR_MSI)
3163 rc = pci_alloc_msi(sc->dev, &nalloc);
3165 if (rc == 0 && nalloc > 0) {
3166 if (nalloc == iaq->nirq)
3170 * Didn't get the number requested. Use whatever number
3171 * the kernel is willing to allocate.
3173 device_printf(sc->dev, "fewer vectors than requested, "
3174 "type=%d, req=%d, rcvd=%d; will downshift req.\n",
3175 itype, iaq->nirq, nalloc);
3176 pci_release_msi(sc->dev);
3181 device_printf(sc->dev,
3182 "failed to allocate vectors:%d, type=%d, req=%d, rcvd=%d\n",
3183 itype, rc, iaq->nirq, nalloc);
3186 device_printf(sc->dev,
3187 "failed to find a usable interrupt type. "
3188 "allowed=%d, msi-x=%d, msi=%d, intx=1", t4_intr_types,
3189 pci_msix_count(sc->dev), pci_msi_count(sc->dev));
3194 #define FW_VERSION(chip) ( \
3195 V_FW_HDR_FW_VER_MAJOR(chip##FW_VERSION_MAJOR) | \
3196 V_FW_HDR_FW_VER_MINOR(chip##FW_VERSION_MINOR) | \
3197 V_FW_HDR_FW_VER_MICRO(chip##FW_VERSION_MICRO) | \
3198 V_FW_HDR_FW_VER_BUILD(chip##FW_VERSION_BUILD))
3199 #define FW_INTFVER(chip, intf) (chip##FW_HDR_INTFVER_##intf)
3205 struct fw_hdr fw_hdr; /* XXX: waste of space, need a sparse struct */
3209 .kld_name = "t4fw_cfg",
3210 .fw_mod_name = "t4fw",
3212 .chip = FW_HDR_CHIP_T4,
3213 .fw_ver = htobe32(FW_VERSION(T4)),
3214 .intfver_nic = FW_INTFVER(T4, NIC),
3215 .intfver_vnic = FW_INTFVER(T4, VNIC),
3216 .intfver_ofld = FW_INTFVER(T4, OFLD),
3217 .intfver_ri = FW_INTFVER(T4, RI),
3218 .intfver_iscsipdu = FW_INTFVER(T4, ISCSIPDU),
3219 .intfver_iscsi = FW_INTFVER(T4, ISCSI),
3220 .intfver_fcoepdu = FW_INTFVER(T4, FCOEPDU),
3221 .intfver_fcoe = FW_INTFVER(T4, FCOE),
3225 .kld_name = "t5fw_cfg",
3226 .fw_mod_name = "t5fw",
3228 .chip = FW_HDR_CHIP_T5,
3229 .fw_ver = htobe32(FW_VERSION(T5)),
3230 .intfver_nic = FW_INTFVER(T5, NIC),
3231 .intfver_vnic = FW_INTFVER(T5, VNIC),
3232 .intfver_ofld = FW_INTFVER(T5, OFLD),
3233 .intfver_ri = FW_INTFVER(T5, RI),
3234 .intfver_iscsipdu = FW_INTFVER(T5, ISCSIPDU),
3235 .intfver_iscsi = FW_INTFVER(T5, ISCSI),
3236 .intfver_fcoepdu = FW_INTFVER(T5, FCOEPDU),
3237 .intfver_fcoe = FW_INTFVER(T5, FCOE),
3241 .kld_name = "t6fw_cfg",
3242 .fw_mod_name = "t6fw",
3244 .chip = FW_HDR_CHIP_T6,
3245 .fw_ver = htobe32(FW_VERSION(T6)),
3246 .intfver_nic = FW_INTFVER(T6, NIC),
3247 .intfver_vnic = FW_INTFVER(T6, VNIC),
3248 .intfver_ofld = FW_INTFVER(T6, OFLD),
3249 .intfver_ri = FW_INTFVER(T6, RI),
3250 .intfver_iscsipdu = FW_INTFVER(T6, ISCSIPDU),
3251 .intfver_iscsi = FW_INTFVER(T6, ISCSI),
3252 .intfver_fcoepdu = FW_INTFVER(T6, FCOEPDU),
3253 .intfver_fcoe = FW_INTFVER(T6, FCOE),
3258 static struct fw_info *
3259 find_fw_info(int chip)
3263 for (i = 0; i < nitems(fw_info); i++) {
3264 if (fw_info[i].chip == chip)
3265 return (&fw_info[i]);
3271 * Is the given firmware API compatible with the one the driver was compiled
3275 fw_compatible(const struct fw_hdr *hdr1, const struct fw_hdr *hdr2)
3278 /* short circuit if it's the exact same firmware version */
3279 if (hdr1->chip == hdr2->chip && hdr1->fw_ver == hdr2->fw_ver)
3283 * XXX: Is this too conservative? Perhaps I should limit this to the
3284 * features that are supported in the driver.
3286 #define SAME_INTF(x) (hdr1->intfver_##x == hdr2->intfver_##x)
3287 if (hdr1->chip == hdr2->chip && SAME_INTF(nic) && SAME_INTF(vnic) &&
3288 SAME_INTF(ofld) && SAME_INTF(ri) && SAME_INTF(iscsipdu) &&
3289 SAME_INTF(iscsi) && SAME_INTF(fcoepdu) && SAME_INTF(fcoe))
3297 * The firmware in the KLD is usable, but should it be installed? This routine
3298 * explains itself in detail if it indicates the KLD firmware should be
3302 should_install_kld_fw(struct adapter *sc, int card_fw_usable, int k, int c)
3306 if (!card_fw_usable) {
3307 reason = "incompatible or unusable";
3312 reason = "older than the version bundled with this driver";
3316 if (t4_fw_install == 2 && k != c) {
3317 reason = "different than the version bundled with this driver";
3324 if (t4_fw_install == 0) {
3325 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
3326 "but the driver is prohibited from installing a different "
3327 "firmware on the card.\n",
3328 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
3329 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason);
3334 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
3335 "installing firmware %u.%u.%u.%u on card.\n",
3336 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
3337 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason,
3338 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
3339 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
3345 * Establish contact with the firmware and determine if we are the master driver
3346 * or not, and whether we are responsible for chip initialization.
3349 prep_firmware(struct adapter *sc)
3351 const struct firmware *fw = NULL, *default_cfg;
3352 int rc, pf, card_fw_usable, kld_fw_usable, need_fw_reset = 1;
3353 enum dev_state state;
3354 struct fw_info *fw_info;
3355 struct fw_hdr *card_fw; /* fw on the card */
3356 const struct fw_hdr *kld_fw; /* fw in the KLD */
3357 const struct fw_hdr *drv_fw; /* fw header the driver was compiled
3360 /* This is the firmware whose headers the driver was compiled against */
3361 fw_info = find_fw_info(chip_id(sc));
3362 if (fw_info == NULL) {
3363 device_printf(sc->dev,
3364 "unable to look up firmware information for chip %d.\n",
3368 drv_fw = &fw_info->fw_hdr;
3371 * The firmware KLD contains many modules. The KLD name is also the
3372 * name of the module that contains the default config file.
3374 default_cfg = firmware_get(fw_info->kld_name);
3376 /* This is the firmware in the KLD */
3377 fw = firmware_get(fw_info->fw_mod_name);
3379 kld_fw = (const void *)fw->data;
3380 kld_fw_usable = fw_compatible(drv_fw, kld_fw);
3386 /* Read the header of the firmware on the card */
3387 card_fw = malloc(sizeof(*card_fw), M_CXGBE, M_ZERO | M_WAITOK);
3388 rc = -t4_read_flash(sc, FLASH_FW_START,
3389 sizeof (*card_fw) / sizeof (uint32_t), (uint32_t *)card_fw, 1);
3391 card_fw_usable = fw_compatible(drv_fw, (const void*)card_fw);
3392 if (card_fw->fw_ver == be32toh(0xffffffff)) {
3393 uint32_t d = be32toh(kld_fw->fw_ver);
3395 if (!kld_fw_usable) {
3396 device_printf(sc->dev,
3397 "no firmware on the card and no usable "
3398 "firmware bundled with the driver.\n");
3401 } else if (t4_fw_install == 0) {
3402 device_printf(sc->dev,
3403 "no firmware on the card and the driver "
3404 "is prohibited from installing new "
3410 device_printf(sc->dev, "no firmware on the card, "
3411 "installing firmware %d.%d.%d.%d\n",
3412 G_FW_HDR_FW_VER_MAJOR(d), G_FW_HDR_FW_VER_MINOR(d),
3413 G_FW_HDR_FW_VER_MICRO(d), G_FW_HDR_FW_VER_BUILD(d));
3414 rc = t4_fw_forceinstall(sc, fw->data, fw->datasize);
3417 device_printf(sc->dev,
3418 "firmware install failed: %d.\n", rc);
3421 memcpy(card_fw, kld_fw, sizeof(*card_fw));
3426 device_printf(sc->dev,
3427 "Unable to read card's firmware header: %d\n", rc);
3431 /* Contact firmware. */
3432 rc = t4_fw_hello(sc, sc->mbox, sc->mbox, MASTER_MAY, &state);
3433 if (rc < 0 || state == DEV_STATE_ERR) {
3435 device_printf(sc->dev,
3436 "failed to connect to the firmware: %d, %d.\n", rc, state);
3441 sc->flags |= MASTER_PF;
3442 else if (state == DEV_STATE_UNINIT) {
3444 * We didn't get to be the master so we definitely won't be
3445 * configuring the chip. It's a bug if someone else hasn't
3446 * configured it already.
3448 device_printf(sc->dev, "couldn't be master(%d), "
3449 "device not already initialized either(%d).\n", rc, state);
3454 if (card_fw_usable && card_fw->fw_ver == drv_fw->fw_ver &&
3455 (!kld_fw_usable || kld_fw->fw_ver == drv_fw->fw_ver)) {
3457 * Common case: the firmware on the card is an exact match and
3458 * the KLD is an exact match too, or the KLD is
3459 * absent/incompatible. Note that t4_fw_install = 2 is ignored
3460 * here -- use cxgbetool loadfw if you want to reinstall the
3461 * same firmware as the one on the card.
3463 } else if (kld_fw_usable && state == DEV_STATE_UNINIT &&
3464 should_install_kld_fw(sc, card_fw_usable, be32toh(kld_fw->fw_ver),
3465 be32toh(card_fw->fw_ver))) {
3467 rc = -t4_fw_upgrade(sc, sc->mbox, fw->data, fw->datasize, 0);
3469 device_printf(sc->dev,
3470 "failed to install firmware: %d\n", rc);
3474 /* Installed successfully, update the cached header too. */
3475 memcpy(card_fw, kld_fw, sizeof(*card_fw));
3477 need_fw_reset = 0; /* already reset as part of load_fw */
3480 if (!card_fw_usable) {
3483 d = ntohl(drv_fw->fw_ver);
3484 c = ntohl(card_fw->fw_ver);
3485 k = kld_fw ? ntohl(kld_fw->fw_ver) : 0;
3487 device_printf(sc->dev, "Cannot find a usable firmware: "
3488 "fw_install %d, chip state %d, "
3489 "driver compiled with %d.%d.%d.%d, "
3490 "card has %d.%d.%d.%d, KLD has %d.%d.%d.%d\n",
3491 t4_fw_install, state,
3492 G_FW_HDR_FW_VER_MAJOR(d), G_FW_HDR_FW_VER_MINOR(d),
3493 G_FW_HDR_FW_VER_MICRO(d), G_FW_HDR_FW_VER_BUILD(d),
3494 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
3495 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c),
3496 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
3497 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
3503 if (need_fw_reset &&
3504 (rc = -t4_fw_reset(sc, sc->mbox, F_PIORSTMODE | F_PIORST)) != 0) {
3505 device_printf(sc->dev, "firmware reset failed: %d.\n", rc);
3506 if (rc != ETIMEDOUT && rc != EIO)
3507 t4_fw_bye(sc, sc->mbox);
3512 rc = get_params__pre_init(sc);
3514 goto done; /* error message displayed already */
3516 /* Partition adapter resources as specified in the config file. */
3517 if (state == DEV_STATE_UNINIT) {
3519 KASSERT(sc->flags & MASTER_PF,
3520 ("%s: trying to change chip settings when not master.",
3523 rc = partition_resources(sc, default_cfg, fw_info->kld_name);
3525 goto done; /* error message displayed already */
3527 t4_tweak_chip_settings(sc);
3529 /* get basic stuff going */
3530 rc = -t4_fw_initialize(sc, sc->mbox);
3532 device_printf(sc->dev, "fw init failed: %d.\n", rc);
3536 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "pf%d", pf);
3541 free(card_fw, M_CXGBE);
3543 firmware_put(fw, FIRMWARE_UNLOAD);
3544 if (default_cfg != NULL)
3545 firmware_put(default_cfg, FIRMWARE_UNLOAD);
3550 #define FW_PARAM_DEV(param) \
3551 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
3552 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
3553 #define FW_PARAM_PFVF(param) \
3554 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
3555 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param))
3558 * Partition chip resources for use between various PFs, VFs, etc.
3561 partition_resources(struct adapter *sc, const struct firmware *default_cfg,
3562 const char *name_prefix)
3564 const struct firmware *cfg = NULL;
3566 struct fw_caps_config_cmd caps;
3567 uint32_t mtype, moff, finicsum, cfcsum;
3570 * Figure out what configuration file to use. Pick the default config
3571 * file for the card if the user hasn't specified one explicitly.
3573 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", t4_cfg_file);
3574 if (strncmp(t4_cfg_file, DEFAULT_CF, sizeof(t4_cfg_file)) == 0) {
3575 /* Card specific overrides go here. */
3576 if (pci_get_device(sc->dev) == 0x440a)
3577 snprintf(sc->cfg_file, sizeof(sc->cfg_file), UWIRE_CF);
3579 snprintf(sc->cfg_file, sizeof(sc->cfg_file), FPGA_CF);
3580 } else if (strncmp(t4_cfg_file, BUILTIN_CF, sizeof(t4_cfg_file)) == 0)
3581 goto use_built_in_config; /* go straight to config. */
3584 * We need to load another module if the profile is anything except
3585 * "default" or "flash".
3587 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) != 0 &&
3588 strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
3591 snprintf(s, sizeof(s), "%s_%s", name_prefix, sc->cfg_file);
3592 cfg = firmware_get(s);
3594 if (default_cfg != NULL) {
3595 device_printf(sc->dev,
3596 "unable to load module \"%s\" for "
3597 "configuration profile \"%s\", will use "
3598 "the default config file instead.\n",
3600 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
3603 device_printf(sc->dev,
3604 "unable to load module \"%s\" for "
3605 "configuration profile \"%s\", will use "
3606 "the config file on the card's flash "
3607 "instead.\n", s, sc->cfg_file);
3608 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
3614 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) == 0 &&
3615 default_cfg == NULL) {
3616 device_printf(sc->dev,
3617 "default config file not available, will use the config "
3618 "file on the card's flash instead.\n");
3619 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", FLASH_CF);
3622 if (strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
3624 const uint32_t *cfdata;
3625 uint32_t param, val, addr;
3627 KASSERT(cfg != NULL || default_cfg != NULL,
3628 ("%s: no config to upload", __func__));
3631 * Ask the firmware where it wants us to upload the config file.
3633 param = FW_PARAM_DEV(CF);
3634 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
3636 /* No support for config file? Shouldn't happen. */
3637 device_printf(sc->dev,
3638 "failed to query config file location: %d.\n", rc);
3641 mtype = G_FW_PARAMS_PARAM_Y(val);
3642 moff = G_FW_PARAMS_PARAM_Z(val) << 16;
3645 * XXX: sheer laziness. We deliberately added 4 bytes of
3646 * useless stuffing/comments at the end of the config file so
3647 * it's ok to simply throw away the last remaining bytes when
3648 * the config file is not an exact multiple of 4. This also
3649 * helps with the validate_mt_off_len check.
3652 cflen = cfg->datasize & ~3;
3655 cflen = default_cfg->datasize & ~3;
3656 cfdata = default_cfg->data;
3659 if (cflen > FLASH_CFG_MAX_SIZE) {
3660 device_printf(sc->dev,
3661 "config file too long (%d, max allowed is %d). "
3662 "Will try to use the config on the card, if any.\n",
3663 cflen, FLASH_CFG_MAX_SIZE);
3664 goto use_config_on_flash;
3667 rc = validate_mt_off_len(sc, mtype, moff, cflen, &addr);
3669 device_printf(sc->dev,
3670 "%s: addr (%d/0x%x) or len %d is not valid: %d. "
3671 "Will try to use the config on the card, if any.\n",
3672 __func__, mtype, moff, cflen, rc);
3673 goto use_config_on_flash;
3675 write_via_memwin(sc, 2, addr, cfdata, cflen);
3677 use_config_on_flash:
3678 mtype = FW_MEMTYPE_FLASH;
3679 moff = t4_flash_cfg_addr(sc);
3682 bzero(&caps, sizeof(caps));
3683 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3684 F_FW_CMD_REQUEST | F_FW_CMD_READ);
3685 caps.cfvalid_to_len16 = htobe32(F_FW_CAPS_CONFIG_CMD_CFVALID |
3686 V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
3687 V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(moff >> 16) | FW_LEN16(caps));
3688 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
3690 device_printf(sc->dev,
3691 "failed to pre-process config file: %d "
3692 "(mtype %d, moff 0x%x). Will reset the firmware and retry "
3693 "with the built-in configuration.\n", rc, mtype, moff);
3695 rc = -t4_fw_reset(sc, sc->mbox, F_PIORSTMODE | F_PIORST);
3697 device_printf(sc->dev,
3698 "firmware reset failed: %d.\n", rc);
3699 if (rc != ETIMEDOUT && rc != EIO) {
3700 t4_fw_bye(sc, sc->mbox);
3701 sc->flags &= ~FW_OK;
3705 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", "built-in");
3706 use_built_in_config:
3707 bzero(&caps, sizeof(caps));
3708 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3709 F_FW_CMD_REQUEST | F_FW_CMD_READ);
3710 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
3711 rc = t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
3713 device_printf(sc->dev,
3714 "built-in configuration failed: %d.\n", rc);
3719 finicsum = be32toh(caps.finicsum);
3720 cfcsum = be32toh(caps.cfcsum);
3721 if (finicsum != cfcsum) {
3722 device_printf(sc->dev,
3723 "WARNING: config file checksum mismatch: %08x %08x\n",
3726 sc->cfcsum = cfcsum;
3728 #define LIMIT_CAPS(x) do { \
3729 caps.x &= htobe16(t4_##x##_allowed); \
3733 * Let the firmware know what features will (not) be used so it can tune
3734 * things accordingly.
3736 LIMIT_CAPS(nbmcaps);
3737 LIMIT_CAPS(linkcaps);
3738 LIMIT_CAPS(switchcaps);
3739 LIMIT_CAPS(niccaps);
3740 LIMIT_CAPS(toecaps);
3741 LIMIT_CAPS(rdmacaps);
3742 LIMIT_CAPS(cryptocaps);
3743 LIMIT_CAPS(iscsicaps);
3744 LIMIT_CAPS(fcoecaps);
3747 if (caps.niccaps & htobe16(FW_CAPS_CONFIG_NIC_HASHFILTER)) {
3749 * TOE and hashfilters are mutually exclusive. It is a config
3750 * file or firmware bug if both are reported as available. Try
3751 * to cope with the situation in non-debug builds by disabling
3754 MPASS(caps.toecaps == 0);
3761 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3762 F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
3763 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
3764 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), NULL);
3766 device_printf(sc->dev,
3767 "failed to process config file: %d.\n", rc);
3771 firmware_put(cfg, FIRMWARE_UNLOAD);
3776 * Retrieve parameters that are needed (or nice to have) very early.
3779 get_params__pre_init(struct adapter *sc)
3782 uint32_t param[2], val[2];
3784 t4_get_version_info(sc);
3786 snprintf(sc->fw_version, sizeof(sc->fw_version), "%u.%u.%u.%u",
3787 G_FW_HDR_FW_VER_MAJOR(sc->params.fw_vers),
3788 G_FW_HDR_FW_VER_MINOR(sc->params.fw_vers),
3789 G_FW_HDR_FW_VER_MICRO(sc->params.fw_vers),
3790 G_FW_HDR_FW_VER_BUILD(sc->params.fw_vers));
3792 snprintf(sc->bs_version, sizeof(sc->bs_version), "%u.%u.%u.%u",
3793 G_FW_HDR_FW_VER_MAJOR(sc->params.bs_vers),
3794 G_FW_HDR_FW_VER_MINOR(sc->params.bs_vers),
3795 G_FW_HDR_FW_VER_MICRO(sc->params.bs_vers),
3796 G_FW_HDR_FW_VER_BUILD(sc->params.bs_vers));
3798 snprintf(sc->tp_version, sizeof(sc->tp_version), "%u.%u.%u.%u",
3799 G_FW_HDR_FW_VER_MAJOR(sc->params.tp_vers),
3800 G_FW_HDR_FW_VER_MINOR(sc->params.tp_vers),
3801 G_FW_HDR_FW_VER_MICRO(sc->params.tp_vers),
3802 G_FW_HDR_FW_VER_BUILD(sc->params.tp_vers));
3804 snprintf(sc->er_version, sizeof(sc->er_version), "%u.%u.%u.%u",
3805 G_FW_HDR_FW_VER_MAJOR(sc->params.er_vers),
3806 G_FW_HDR_FW_VER_MINOR(sc->params.er_vers),
3807 G_FW_HDR_FW_VER_MICRO(sc->params.er_vers),
3808 G_FW_HDR_FW_VER_BUILD(sc->params.er_vers));
3810 param[0] = FW_PARAM_DEV(PORTVEC);
3811 param[1] = FW_PARAM_DEV(CCLK);
3812 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
3814 device_printf(sc->dev,
3815 "failed to query parameters (pre_init): %d.\n", rc);
3819 sc->params.portvec = val[0];
3820 sc->params.nports = bitcount32(val[0]);
3821 sc->params.vpd.cclk = val[1];
3823 /* Read device log parameters. */
3824 rc = -t4_init_devlog_params(sc, 1);
3826 fixup_devlog_params(sc);
3828 device_printf(sc->dev,
3829 "failed to get devlog parameters: %d.\n", rc);
3830 rc = 0; /* devlog isn't critical for device operation */
3837 * Retrieve various parameters that are of interest to the driver. The device
3838 * has been initialized by the firmware at this point.
3841 get_params__post_init(struct adapter *sc)
3844 uint32_t param[7], val[7];
3845 struct fw_caps_config_cmd caps;
3847 param[0] = FW_PARAM_PFVF(IQFLINT_START);
3848 param[1] = FW_PARAM_PFVF(EQ_START);
3849 param[2] = FW_PARAM_PFVF(FILTER_START);
3850 param[3] = FW_PARAM_PFVF(FILTER_END);
3851 param[4] = FW_PARAM_PFVF(L2T_START);
3852 param[5] = FW_PARAM_PFVF(L2T_END);
3853 param[6] = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
3854 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) |
3855 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_VDD);
3856 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 7, param, val);
3858 device_printf(sc->dev,
3859 "failed to query parameters (post_init): %d.\n", rc);
3863 sc->sge.iq_start = val[0];
3864 sc->sge.eq_start = val[1];
3865 if ((int)val[3] > (int)val[2]) {
3866 sc->tids.ftid_base = val[2];
3867 sc->tids.ftid_end = val[3];
3868 sc->tids.nftids = val[3] - val[2] + 1;
3870 sc->vres.l2t.start = val[4];
3871 sc->vres.l2t.size = val[5] - val[4] + 1;
3872 KASSERT(sc->vres.l2t.size <= L2T_SIZE,
3873 ("%s: L2 table size (%u) larger than expected (%u)",
3874 __func__, sc->vres.l2t.size, L2T_SIZE));
3875 sc->params.core_vdd = val[6];
3877 if (chip_id(sc) >= CHELSIO_T6) {
3880 if (sc->params.fw_vers >=
3881 (V_FW_HDR_FW_VER_MAJOR(1) | V_FW_HDR_FW_VER_MINOR(20) |
3882 V_FW_HDR_FW_VER_MICRO(1) | V_FW_HDR_FW_VER_BUILD(0))) {
3884 * Note that the code to enable the region should run
3885 * before t4_fw_initialize and not here. This is just a
3886 * reminder to add said code.
3888 device_printf(sc->dev,
3889 "hpfilter region not enabled.\n");
3893 sc->tids.tid_base = t4_read_reg(sc,
3894 A_LE_DB_ACTIVE_TABLE_START_INDEX);
3896 param[0] = FW_PARAM_PFVF(HPFILTER_START);
3897 param[1] = FW_PARAM_PFVF(HPFILTER_END);
3898 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
3900 device_printf(sc->dev,
3901 "failed to query hpfilter parameters: %d.\n", rc);
3904 if ((int)val[1] > (int)val[0]) {
3905 sc->tids.hpftid_base = val[0];
3906 sc->tids.hpftid_end = val[1];
3907 sc->tids.nhpftids = val[1] - val[0] + 1;
3910 * These should go off if the layout changes and the
3911 * driver needs to catch up.
3913 MPASS(sc->tids.hpftid_base == 0);
3914 MPASS(sc->tids.tid_base == sc->tids.nhpftids);
3919 * MPSBGMAP is queried separately because only recent firmwares support
3920 * it as a parameter and we don't want the compound query above to fail
3921 * on older firmwares.
3923 param[0] = FW_PARAM_DEV(MPSBGMAP);
3925 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val);
3927 sc->params.mps_bg_map = val[0];
3929 sc->params.mps_bg_map = 0;
3932 * Determine whether the firmware supports the filter2 work request.
3933 * This is queried separately for the same reason as MPSBGMAP above.
3935 param[0] = FW_PARAM_DEV(FILTER2_WR);
3937 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val);
3939 sc->params.filter2_wr_support = val[0] != 0;
3941 sc->params.filter2_wr_support = 0;
3943 /* get capabilites */
3944 bzero(&caps, sizeof(caps));
3945 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3946 F_FW_CMD_REQUEST | F_FW_CMD_READ);
3947 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
3948 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
3950 device_printf(sc->dev,
3951 "failed to get card capabilities: %d.\n", rc);
3955 #define READ_CAPS(x) do { \
3956 sc->x = htobe16(caps.x); \
3959 READ_CAPS(linkcaps);
3960 READ_CAPS(switchcaps);
3963 READ_CAPS(rdmacaps);
3964 READ_CAPS(cryptocaps);
3965 READ_CAPS(iscsicaps);
3966 READ_CAPS(fcoecaps);
3968 if (sc->niccaps & FW_CAPS_CONFIG_NIC_HASHFILTER) {
3969 MPASS(chip_id(sc) > CHELSIO_T4);
3970 MPASS(sc->toecaps == 0);
3973 param[0] = FW_PARAM_DEV(NTID);
3974 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val);
3976 device_printf(sc->dev,
3977 "failed to query HASHFILTER parameters: %d.\n", rc);
3980 sc->tids.ntids = val[0];
3981 if (sc->params.fw_vers <
3982 (V_FW_HDR_FW_VER_MAJOR(1) | V_FW_HDR_FW_VER_MINOR(20) |
3983 V_FW_HDR_FW_VER_MICRO(5) | V_FW_HDR_FW_VER_BUILD(0))) {
3984 MPASS(sc->tids.ntids >= sc->tids.nhpftids);
3985 sc->tids.ntids -= sc->tids.nhpftids;
3987 sc->tids.natids = min(sc->tids.ntids / 2, MAX_ATIDS);
3988 sc->params.hash_filter = 1;
3990 if (sc->niccaps & FW_CAPS_CONFIG_NIC_ETHOFLD) {
3991 param[0] = FW_PARAM_PFVF(ETHOFLD_START);
3992 param[1] = FW_PARAM_PFVF(ETHOFLD_END);
3993 param[2] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
3994 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 3, param, val);
3996 device_printf(sc->dev,
3997 "failed to query NIC parameters: %d.\n", rc);
4000 if ((int)val[1] > (int)val[0]) {
4001 sc->tids.etid_base = val[0];
4002 sc->tids.etid_end = val[1];
4003 sc->tids.netids = val[1] - val[0] + 1;
4004 sc->params.eo_wr_cred = val[2];
4005 sc->params.ethoffload = 1;
4009 /* query offload-related parameters */
4010 param[0] = FW_PARAM_DEV(NTID);
4011 param[1] = FW_PARAM_PFVF(SERVER_START);
4012 param[2] = FW_PARAM_PFVF(SERVER_END);
4013 param[3] = FW_PARAM_PFVF(TDDP_START);
4014 param[4] = FW_PARAM_PFVF(TDDP_END);
4015 param[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
4016 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
4018 device_printf(sc->dev,
4019 "failed to query TOE parameters: %d.\n", rc);
4022 sc->tids.ntids = val[0];
4023 if (sc->params.fw_vers <
4024 (V_FW_HDR_FW_VER_MAJOR(1) | V_FW_HDR_FW_VER_MINOR(20) |
4025 V_FW_HDR_FW_VER_MICRO(5) | V_FW_HDR_FW_VER_BUILD(0))) {
4026 MPASS(sc->tids.ntids >= sc->tids.nhpftids);
4027 sc->tids.ntids -= sc->tids.nhpftids;
4029 sc->tids.natids = min(sc->tids.ntids / 2, MAX_ATIDS);
4030 if ((int)val[2] > (int)val[1]) {
4031 sc->tids.stid_base = val[1];
4032 sc->tids.nstids = val[2] - val[1] + 1;
4034 sc->vres.ddp.start = val[3];
4035 sc->vres.ddp.size = val[4] - val[3] + 1;
4036 sc->params.ofldq_wr_cred = val[5];
4037 sc->params.offload = 1;
4040 * The firmware attempts memfree TOE configuration for -SO cards
4041 * and will report toecaps=0 if it runs out of resources (this
4042 * depends on the config file). It may not report 0 for other
4043 * capabilities dependent on the TOE in this case. Set them to
4044 * 0 here so that the driver doesn't bother tracking resources
4045 * that will never be used.
4051 param[0] = FW_PARAM_PFVF(STAG_START);
4052 param[1] = FW_PARAM_PFVF(STAG_END);
4053 param[2] = FW_PARAM_PFVF(RQ_START);
4054 param[3] = FW_PARAM_PFVF(RQ_END);
4055 param[4] = FW_PARAM_PFVF(PBL_START);
4056 param[5] = FW_PARAM_PFVF(PBL_END);
4057 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
4059 device_printf(sc->dev,
4060 "failed to query RDMA parameters(1): %d.\n", rc);
4063 sc->vres.stag.start = val[0];
4064 sc->vres.stag.size = val[1] - val[0] + 1;
4065 sc->vres.rq.start = val[2];
4066 sc->vres.rq.size = val[3] - val[2] + 1;
4067 sc->vres.pbl.start = val[4];
4068 sc->vres.pbl.size = val[5] - val[4] + 1;
4070 param[0] = FW_PARAM_PFVF(SQRQ_START);
4071 param[1] = FW_PARAM_PFVF(SQRQ_END);
4072 param[2] = FW_PARAM_PFVF(CQ_START);
4073 param[3] = FW_PARAM_PFVF(CQ_END);
4074 param[4] = FW_PARAM_PFVF(OCQ_START);
4075 param[5] = FW_PARAM_PFVF(OCQ_END);
4076 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
4078 device_printf(sc->dev,
4079 "failed to query RDMA parameters(2): %d.\n", rc);
4082 sc->vres.qp.start = val[0];
4083 sc->vres.qp.size = val[1] - val[0] + 1;
4084 sc->vres.cq.start = val[2];
4085 sc->vres.cq.size = val[3] - val[2] + 1;
4086 sc->vres.ocq.start = val[4];
4087 sc->vres.ocq.size = val[5] - val[4] + 1;
4089 param[0] = FW_PARAM_PFVF(SRQ_START);
4090 param[1] = FW_PARAM_PFVF(SRQ_END);
4091 param[2] = FW_PARAM_DEV(MAXORDIRD_QP);
4092 param[3] = FW_PARAM_DEV(MAXIRD_ADAPTER);
4093 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 4, param, val);
4095 device_printf(sc->dev,
4096 "failed to query RDMA parameters(3): %d.\n", rc);
4099 sc->vres.srq.start = val[0];
4100 sc->vres.srq.size = val[1] - val[0] + 1;
4101 sc->params.max_ordird_qp = val[2];
4102 sc->params.max_ird_adapter = val[3];
4104 if (sc->iscsicaps) {
4105 param[0] = FW_PARAM_PFVF(ISCSI_START);
4106 param[1] = FW_PARAM_PFVF(ISCSI_END);
4107 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
4109 device_printf(sc->dev,
4110 "failed to query iSCSI parameters: %d.\n", rc);
4113 sc->vres.iscsi.start = val[0];
4114 sc->vres.iscsi.size = val[1] - val[0] + 1;
4116 if (sc->cryptocaps & FW_CAPS_CONFIG_TLSKEYS) {
4117 param[0] = FW_PARAM_PFVF(TLS_START);
4118 param[1] = FW_PARAM_PFVF(TLS_END);
4119 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
4121 device_printf(sc->dev,
4122 "failed to query TLS parameters: %d.\n", rc);
4125 sc->vres.key.start = val[0];
4126 sc->vres.key.size = val[1] - val[0] + 1;
4129 t4_init_sge_params(sc);
4132 * We've got the params we wanted to query via the firmware. Now grab
4133 * some others directly from the chip.
4135 rc = t4_read_chip_settings(sc);
4141 set_params__post_init(struct adapter *sc)
4143 uint32_t param, val;
4148 /* ask for encapsulated CPLs */
4149 param = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
4151 (void)t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
4153 /* Enable 32b port caps if the firmware supports it. */
4154 param = FW_PARAM_PFVF(PORT_CAPS32);
4156 if (t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val) == 0)
4157 sc->params.port_caps32 = 1;
4159 /* Let filter + maskhash steer to a part of the VI's RSS region. */
4160 val = 1 << (G_MASKSIZE(t4_read_reg(sc, A_TP_RSS_CONFIG_TNL)) - 1);
4161 t4_set_reg_field(sc, A_TP_RSS_CONFIG_TNL, V_MASKFILTER(M_MASKFILTER),
4162 V_MASKFILTER(val - 1));
4166 * Override the TOE timers with user provided tunables. This is not the
4167 * recommended way to change the timers (the firmware config file is) so
4168 * these tunables are not documented.
4170 * All the timer tunables are in microseconds.
4172 if (t4_toe_keepalive_idle != 0) {
4173 v = us_to_tcp_ticks(sc, t4_toe_keepalive_idle);
4174 v &= M_KEEPALIVEIDLE;
4175 t4_set_reg_field(sc, A_TP_KEEP_IDLE,
4176 V_KEEPALIVEIDLE(M_KEEPALIVEIDLE), V_KEEPALIVEIDLE(v));
4178 if (t4_toe_keepalive_interval != 0) {
4179 v = us_to_tcp_ticks(sc, t4_toe_keepalive_interval);
4180 v &= M_KEEPALIVEINTVL;
4181 t4_set_reg_field(sc, A_TP_KEEP_INTVL,
4182 V_KEEPALIVEINTVL(M_KEEPALIVEINTVL), V_KEEPALIVEINTVL(v));
4184 if (t4_toe_keepalive_count != 0) {
4185 v = t4_toe_keepalive_count & M_KEEPALIVEMAXR2;
4186 t4_set_reg_field(sc, A_TP_SHIFT_CNT,
4187 V_KEEPALIVEMAXR1(M_KEEPALIVEMAXR1) |
4188 V_KEEPALIVEMAXR2(M_KEEPALIVEMAXR2),
4189 V_KEEPALIVEMAXR1(1) | V_KEEPALIVEMAXR2(v));
4191 if (t4_toe_rexmt_min != 0) {
4192 v = us_to_tcp_ticks(sc, t4_toe_rexmt_min);
4194 t4_set_reg_field(sc, A_TP_RXT_MIN,
4195 V_RXTMIN(M_RXTMIN), V_RXTMIN(v));
4197 if (t4_toe_rexmt_max != 0) {
4198 v = us_to_tcp_ticks(sc, t4_toe_rexmt_max);
4200 t4_set_reg_field(sc, A_TP_RXT_MAX,
4201 V_RXTMAX(M_RXTMAX), V_RXTMAX(v));
4203 if (t4_toe_rexmt_count != 0) {
4204 v = t4_toe_rexmt_count & M_RXTSHIFTMAXR2;
4205 t4_set_reg_field(sc, A_TP_SHIFT_CNT,
4206 V_RXTSHIFTMAXR1(M_RXTSHIFTMAXR1) |
4207 V_RXTSHIFTMAXR2(M_RXTSHIFTMAXR2),
4208 V_RXTSHIFTMAXR1(1) | V_RXTSHIFTMAXR2(v));
4210 for (i = 0; i < nitems(t4_toe_rexmt_backoff); i++) {
4211 if (t4_toe_rexmt_backoff[i] != -1) {
4212 v = t4_toe_rexmt_backoff[i] & M_TIMERBACKOFFINDEX0;
4213 shift = (i & 3) << 3;
4214 t4_set_reg_field(sc, A_TP_TCP_BACKOFF_REG0 + (i & ~3),
4215 M_TIMERBACKOFFINDEX0 << shift, v << shift);
4222 #undef FW_PARAM_PFVF
4226 t4_set_desc(struct adapter *sc)
4229 struct adapter_params *p = &sc->params;
4231 snprintf(buf, sizeof(buf), "Chelsio %s", p->vpd.id);
4233 device_set_desc_copy(sc->dev, buf);
4237 ifmedia_add4(struct ifmedia *ifm, int m)
4240 ifmedia_add(ifm, m, 0, NULL);
4241 ifmedia_add(ifm, m | IFM_ETH_TXPAUSE, 0, NULL);
4242 ifmedia_add(ifm, m | IFM_ETH_RXPAUSE, 0, NULL);
4243 ifmedia_add(ifm, m | IFM_ETH_TXPAUSE | IFM_ETH_RXPAUSE, 0, NULL);
4247 * This is the selected media, which is not quite the same as the active media.
4248 * The media line in ifconfig is "media: Ethernet selected (active)" if selected
4249 * and active are not the same, and "media: Ethernet selected" otherwise.
4252 set_current_media(struct port_info *pi)
4254 struct link_config *lc;
4255 struct ifmedia *ifm;
4259 PORT_LOCK_ASSERT_OWNED(pi);
4261 /* Leave current media alone if it's already set to IFM_NONE. */
4263 if (ifm->ifm_cur != NULL &&
4264 IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_NONE)
4268 if (lc->requested_aneg != AUTONEG_DISABLE &&
4269 lc->supported & FW_PORT_CAP32_ANEG) {
4270 ifmedia_set(ifm, IFM_ETHER | IFM_AUTO);
4273 mword = IFM_ETHER | IFM_FDX;
4274 if (lc->requested_fc & PAUSE_TX)
4275 mword |= IFM_ETH_TXPAUSE;
4276 if (lc->requested_fc & PAUSE_RX)
4277 mword |= IFM_ETH_RXPAUSE;
4278 if (lc->requested_speed == 0)
4279 speed = port_top_speed(pi) * 1000; /* Gbps -> Mbps */
4281 speed = lc->requested_speed;
4282 mword |= port_mword(pi, speed_to_fwcap(speed));
4283 ifmedia_set(ifm, mword);
4287 * Returns true if the ifmedia list for the port cannot change.
4290 fixed_ifmedia(struct port_info *pi)
4293 return (pi->port_type == FW_PORT_TYPE_BT_SGMII ||
4294 pi->port_type == FW_PORT_TYPE_BT_XFI ||
4295 pi->port_type == FW_PORT_TYPE_BT_XAUI ||
4296 pi->port_type == FW_PORT_TYPE_KX4 ||
4297 pi->port_type == FW_PORT_TYPE_KX ||
4298 pi->port_type == FW_PORT_TYPE_KR ||
4299 pi->port_type == FW_PORT_TYPE_BP_AP ||
4300 pi->port_type == FW_PORT_TYPE_BP4_AP ||
4301 pi->port_type == FW_PORT_TYPE_BP40_BA ||
4302 pi->port_type == FW_PORT_TYPE_KR4_100G ||
4303 pi->port_type == FW_PORT_TYPE_KR_SFP28 ||
4304 pi->port_type == FW_PORT_TYPE_KR_XLAUI);
4308 build_medialist(struct port_info *pi)
4311 int unknown, mword, bit;
4312 struct link_config *lc;
4313 struct ifmedia *ifm;
4315 PORT_LOCK_ASSERT_OWNED(pi);
4317 if (pi->flags & FIXED_IFMEDIA)
4321 * Rebuild the ifmedia list.
4324 ifmedia_removeall(ifm);
4326 ss = G_FW_PORT_CAP32_SPEED(lc->supported); /* Supported Speeds */
4327 if (__predict_false(ss == 0)) { /* not supposed to happen. */
4330 MPASS(LIST_EMPTY(&ifm->ifm_list));
4331 ifmedia_add(ifm, IFM_ETHER | IFM_NONE, 0, NULL);
4332 ifmedia_set(ifm, IFM_ETHER | IFM_NONE);
4337 for (bit = S_FW_PORT_CAP32_SPEED; bit < fls(ss); bit++) {
4339 MPASS(speed & M_FW_PORT_CAP32_SPEED);
4341 mword = port_mword(pi, speed);
4342 if (mword == IFM_NONE) {
4344 } else if (mword == IFM_UNKNOWN)
4347 ifmedia_add4(ifm, IFM_ETHER | IFM_FDX | mword);
4350 if (unknown > 0) /* Add one unknown for all unknown media types. */
4351 ifmedia_add4(ifm, IFM_ETHER | IFM_FDX | IFM_UNKNOWN);
4352 if (lc->supported & FW_PORT_CAP32_ANEG)
4353 ifmedia_add(ifm, IFM_ETHER | IFM_AUTO, 0, NULL);
4355 set_current_media(pi);
4359 * Initialize the requested fields in the link config based on driver tunables.
4362 init_link_config(struct port_info *pi)
4364 struct link_config *lc = &pi->link_cfg;
4366 PORT_LOCK_ASSERT_OWNED(pi);
4368 lc->requested_speed = 0;
4370 if (t4_autoneg == 0)
4371 lc->requested_aneg = AUTONEG_DISABLE;
4372 else if (t4_autoneg == 1)
4373 lc->requested_aneg = AUTONEG_ENABLE;
4375 lc->requested_aneg = AUTONEG_AUTO;
4377 lc->requested_fc = t4_pause_settings & (PAUSE_TX | PAUSE_RX |
4380 if (t4_fec == -1 || t4_fec & FEC_AUTO)
4381 lc->requested_fec = FEC_AUTO;
4383 lc->requested_fec = FEC_NONE;
4384 if (t4_fec & FEC_RS)
4385 lc->requested_fec |= FEC_RS;
4386 if (t4_fec & FEC_BASER_RS)
4387 lc->requested_fec |= FEC_BASER_RS;
4392 * Makes sure that all requested settings comply with what's supported by the
4393 * port. Returns the number of settings that were invalid and had to be fixed.
4396 fixup_link_config(struct port_info *pi)
4399 struct link_config *lc = &pi->link_cfg;
4402 PORT_LOCK_ASSERT_OWNED(pi);
4404 /* Speed (when not autonegotiating) */
4405 if (lc->requested_speed != 0) {
4406 fwspeed = speed_to_fwcap(lc->requested_speed);
4407 if ((fwspeed & lc->supported) == 0) {
4409 lc->requested_speed = 0;
4413 /* Link autonegotiation */
4414 MPASS(lc->requested_aneg == AUTONEG_ENABLE ||
4415 lc->requested_aneg == AUTONEG_DISABLE ||
4416 lc->requested_aneg == AUTONEG_AUTO);
4417 if (lc->requested_aneg == AUTONEG_ENABLE &&
4418 !(lc->supported & FW_PORT_CAP32_ANEG)) {
4420 lc->requested_aneg = AUTONEG_AUTO;
4424 MPASS((lc->requested_fc & ~(PAUSE_TX | PAUSE_RX | PAUSE_AUTONEG)) == 0);
4425 if (lc->requested_fc & PAUSE_TX &&
4426 !(lc->supported & FW_PORT_CAP32_FC_TX)) {
4428 lc->requested_fc &= ~PAUSE_TX;
4430 if (lc->requested_fc & PAUSE_RX &&
4431 !(lc->supported & FW_PORT_CAP32_FC_RX)) {
4433 lc->requested_fc &= ~PAUSE_RX;
4435 if (!(lc->requested_fc & PAUSE_AUTONEG) &&
4436 !(lc->supported & FW_PORT_CAP32_FORCE_PAUSE)) {
4438 lc->requested_fc |= PAUSE_AUTONEG;
4442 if ((lc->requested_fec & FEC_RS &&
4443 !(lc->supported & FW_PORT_CAP32_FEC_RS)) ||
4444 (lc->requested_fec & FEC_BASER_RS &&
4445 !(lc->supported & FW_PORT_CAP32_FEC_BASER_RS))) {
4447 lc->requested_fec = FEC_AUTO;
4454 * Apply the requested L1 settings, which are expected to be valid, to the
4458 apply_link_config(struct port_info *pi)
4460 struct adapter *sc = pi->adapter;
4461 struct link_config *lc = &pi->link_cfg;
4465 ASSERT_SYNCHRONIZED_OP(sc);
4466 PORT_LOCK_ASSERT_OWNED(pi);
4468 if (lc->requested_aneg == AUTONEG_ENABLE)
4469 MPASS(lc->supported & FW_PORT_CAP32_ANEG);
4470 if (!(lc->requested_fc & PAUSE_AUTONEG))
4471 MPASS(lc->supported & FW_PORT_CAP32_FORCE_PAUSE);
4472 if (lc->requested_fc & PAUSE_TX)
4473 MPASS(lc->supported & FW_PORT_CAP32_FC_TX);
4474 if (lc->requested_fc & PAUSE_RX)
4475 MPASS(lc->supported & FW_PORT_CAP32_FC_RX);
4476 if (lc->requested_fec & FEC_RS)
4477 MPASS(lc->supported & FW_PORT_CAP32_FEC_RS);
4478 if (lc->requested_fec & FEC_BASER_RS)
4479 MPASS(lc->supported & FW_PORT_CAP32_FEC_BASER_RS);
4481 rc = -t4_link_l1cfg(sc, sc->mbox, pi->tx_chan, lc);
4483 /* Don't complain if the VF driver gets back an EPERM. */
4484 if (!(sc->flags & IS_VF) || rc != FW_EPERM)
4485 device_printf(pi->dev, "l1cfg failed: %d\n", rc);
4488 * An L1_CFG will almost always result in a link-change event if
4489 * the link is up, and the driver will refresh the actual
4490 * fec/fc/etc. when the notification is processed. If the link
4491 * is down then the actual settings are meaningless.
4493 * This takes care of the case where a change in the L1 settings
4494 * may not result in a notification.
4496 if (lc->link_ok && !(lc->requested_fc & PAUSE_AUTONEG))
4497 lc->fc = lc->requested_fc & (PAUSE_TX | PAUSE_RX);
4502 #define FW_MAC_EXACT_CHUNK 7
4505 * Program the port's XGMAC based on parameters in ifnet. The caller also
4506 * indicates which parameters should be programmed (the rest are left alone).
4509 update_mac_settings(struct ifnet *ifp, int flags)
4512 struct vi_info *vi = ifp->if_softc;
4513 struct port_info *pi = vi->pi;
4514 struct adapter *sc = pi->adapter;
4515 int mtu = -1, promisc = -1, allmulti = -1, vlanex = -1;
4517 ASSERT_SYNCHRONIZED_OP(sc);
4518 KASSERT(flags, ("%s: not told what to update.", __func__));
4520 if (flags & XGMAC_MTU)
4523 if (flags & XGMAC_PROMISC)
4524 promisc = ifp->if_flags & IFF_PROMISC ? 1 : 0;
4526 if (flags & XGMAC_ALLMULTI)
4527 allmulti = ifp->if_flags & IFF_ALLMULTI ? 1 : 0;
4529 if (flags & XGMAC_VLANEX)
4530 vlanex = ifp->if_capenable & IFCAP_VLAN_HWTAGGING ? 1 : 0;
4532 if (flags & (XGMAC_MTU|XGMAC_PROMISC|XGMAC_ALLMULTI|XGMAC_VLANEX)) {
4533 rc = -t4_set_rxmode(sc, sc->mbox, vi->viid, mtu, promisc,
4534 allmulti, 1, vlanex, false);
4536 if_printf(ifp, "set_rxmode (%x) failed: %d\n", flags,
4542 if (flags & XGMAC_UCADDR) {
4543 uint8_t ucaddr[ETHER_ADDR_LEN];
4545 bcopy(IF_LLADDR(ifp), ucaddr, sizeof(ucaddr));
4546 rc = t4_change_mac(sc, sc->mbox, vi->viid, vi->xact_addr_filt,
4547 ucaddr, true, true);
4550 if_printf(ifp, "change_mac failed: %d\n", rc);
4553 vi->xact_addr_filt = rc;
4558 if (flags & XGMAC_MCADDRS) {
4559 const uint8_t *mcaddr[FW_MAC_EXACT_CHUNK];
4562 struct ifmultiaddr *ifma;
4565 if_maddr_rlock(ifp);
4566 CK_STAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
4567 if (ifma->ifma_addr->sa_family != AF_LINK)
4570 LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
4571 MPASS(ETHER_IS_MULTICAST(mcaddr[i]));
4574 if (i == FW_MAC_EXACT_CHUNK) {
4575 rc = t4_alloc_mac_filt(sc, sc->mbox, vi->viid,
4576 del, i, mcaddr, NULL, &hash, 0);
4579 for (j = 0; j < i; j++) {
4581 "failed to add mc address"
4583 "%02x:%02x:%02x rc=%d\n",
4584 mcaddr[j][0], mcaddr[j][1],
4585 mcaddr[j][2], mcaddr[j][3],
4586 mcaddr[j][4], mcaddr[j][5],
4596 rc = t4_alloc_mac_filt(sc, sc->mbox, vi->viid, del, i,
4597 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],
4614 rc = -t4_set_addr_hash(sc, sc->mbox, vi->viid, 0, hash, 0);
4616 if_printf(ifp, "failed to set mc address hash: %d", rc);
4618 if_maddr_runlock(ifp);
4625 * {begin|end}_synchronized_op must be called from the same thread.
4628 begin_synchronized_op(struct adapter *sc, struct vi_info *vi, int flags,
4634 /* the caller thinks it's ok to sleep, but is it really? */
4635 if (flags & SLEEP_OK)
4636 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
4637 "begin_synchronized_op");
4648 if (vi && IS_DOOMED(vi)) {
4658 if (!(flags & SLEEP_OK)) {
4663 if (mtx_sleep(&sc->flags, &sc->sc_lock, pri, wmesg, 0)) {
4669 KASSERT(!IS_BUSY(sc), ("%s: controller busy.", __func__));
4672 sc->last_op = wmesg;
4673 sc->last_op_thr = curthread;
4674 sc->last_op_flags = flags;
4678 if (!(flags & HOLD_LOCK) || rc)
4685 * Tell if_ioctl and if_init that the VI is going away. This is
4686 * special variant of begin_synchronized_op and must be paired with a
4687 * call to end_synchronized_op.
4690 doom_vi(struct adapter *sc, struct vi_info *vi)
4697 mtx_sleep(&sc->flags, &sc->sc_lock, 0, "t4detach", 0);
4700 sc->last_op = "t4detach";
4701 sc->last_op_thr = curthread;
4702 sc->last_op_flags = 0;
4708 * {begin|end}_synchronized_op must be called from the same thread.
4711 end_synchronized_op(struct adapter *sc, int flags)
4714 if (flags & LOCK_HELD)
4715 ADAPTER_LOCK_ASSERT_OWNED(sc);
4719 KASSERT(IS_BUSY(sc), ("%s: controller not busy.", __func__));
4726 cxgbe_init_synchronized(struct vi_info *vi)
4728 struct port_info *pi = vi->pi;
4729 struct adapter *sc = pi->adapter;
4730 struct ifnet *ifp = vi->ifp;
4732 struct sge_txq *txq;
4734 ASSERT_SYNCHRONIZED_OP(sc);
4736 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
4737 return (0); /* already running */
4739 if (!(sc->flags & FULL_INIT_DONE) &&
4740 ((rc = adapter_full_init(sc)) != 0))
4741 return (rc); /* error message displayed already */
4743 if (!(vi->flags & VI_INIT_DONE) &&
4744 ((rc = vi_full_init(vi)) != 0))
4745 return (rc); /* error message displayed already */
4747 rc = update_mac_settings(ifp, XGMAC_ALL);
4749 goto done; /* error message displayed already */
4752 if (pi->up_vis == 0) {
4753 t4_update_port_info(pi);
4754 fixup_link_config(pi);
4755 build_medialist(pi);
4756 apply_link_config(pi);
4759 rc = -t4_enable_vi(sc, sc->mbox, vi->viid, true, true);
4761 if_printf(ifp, "enable_vi failed: %d\n", rc);
4767 * Can't fail from this point onwards. Review cxgbe_uninit_synchronized
4771 for_each_txq(vi, i, txq) {
4773 txq->eq.flags |= EQ_ENABLED;
4778 * The first iq of the first port to come up is used for tracing.
4780 if (sc->traceq < 0 && IS_MAIN_VI(vi)) {
4781 sc->traceq = sc->sge.rxq[vi->first_rxq].iq.abs_id;
4782 t4_write_reg(sc, is_t4(sc) ? A_MPS_TRC_RSS_CONTROL :
4783 A_MPS_T5_TRC_RSS_CONTROL, V_RSSCONTROL(pi->tx_chan) |
4784 V_QUEUENUMBER(sc->traceq));
4785 pi->flags |= HAS_TRACEQ;
4790 ifp->if_drv_flags |= IFF_DRV_RUNNING;
4792 if (pi->nvi > 1 || sc->flags & IS_VF)
4793 callout_reset(&vi->tick, hz, vi_tick, vi);
4795 callout_reset(&pi->tick, hz, cxgbe_tick, pi);
4799 cxgbe_uninit_synchronized(vi);
4808 cxgbe_uninit_synchronized(struct vi_info *vi)
4810 struct port_info *pi = vi->pi;
4811 struct adapter *sc = pi->adapter;
4812 struct ifnet *ifp = vi->ifp;
4814 struct sge_txq *txq;
4816 ASSERT_SYNCHRONIZED_OP(sc);
4818 if (!(vi->flags & VI_INIT_DONE)) {
4819 if (__predict_false(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
4820 KASSERT(0, ("uninited VI is running"));
4821 if_printf(ifp, "uninited VI with running ifnet. "
4822 "vi->flags 0x%016lx, if_flags 0x%08x, "
4823 "if_drv_flags 0x%08x\n", vi->flags, ifp->if_flags,
4830 * Disable the VI so that all its data in either direction is discarded
4831 * by the MPS. Leave everything else (the queues, interrupts, and 1Hz
4832 * tick) intact as the TP can deliver negative advice or data that it's
4833 * holding in its RAM (for an offloaded connection) even after the VI is
4836 rc = -t4_enable_vi(sc, sc->mbox, vi->viid, false, false);
4838 if_printf(ifp, "disable_vi failed: %d\n", rc);
4842 for_each_txq(vi, i, txq) {
4844 txq->eq.flags &= ~EQ_ENABLED;
4849 if (pi->nvi > 1 || sc->flags & IS_VF)
4850 callout_stop(&vi->tick);
4852 callout_stop(&pi->tick);
4853 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
4857 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
4859 if (pi->up_vis > 0) {
4864 pi->link_cfg.link_ok = false;
4865 pi->link_cfg.speed = 0;
4866 pi->link_cfg.link_down_rc = 255;
4867 t4_os_link_changed(pi);
4874 * It is ok for this function to fail midway and return right away. t4_detach
4875 * will walk the entire sc->irq list and clean up whatever is valid.
4878 t4_setup_intr_handlers(struct adapter *sc)
4880 int rc, rid, p, q, v;
4883 struct port_info *pi;
4885 struct sge *sge = &sc->sge;
4886 struct sge_rxq *rxq;
4888 struct sge_ofld_rxq *ofld_rxq;
4891 struct sge_nm_rxq *nm_rxq;
4894 int nbuckets = rss_getnumbuckets();
4901 rid = sc->intr_type == INTR_INTX ? 0 : 1;
4902 if (forwarding_intr_to_fwq(sc))
4903 return (t4_alloc_irq(sc, irq, rid, t4_intr_all, sc, "all"));
4905 /* Multiple interrupts. */
4906 if (sc->flags & IS_VF)
4907 KASSERT(sc->intr_count >= T4VF_EXTRA_INTR + sc->params.nports,
4908 ("%s: too few intr.", __func__));
4910 KASSERT(sc->intr_count >= T4_EXTRA_INTR + sc->params.nports,
4911 ("%s: too few intr.", __func__));
4913 /* The first one is always error intr on PFs */
4914 if (!(sc->flags & IS_VF)) {
4915 rc = t4_alloc_irq(sc, irq, rid, t4_intr_err, sc, "err");
4922 /* The second one is always the firmware event queue (first on VFs) */
4923 rc = t4_alloc_irq(sc, irq, rid, t4_intr_evt, &sge->fwq, "evt");
4929 for_each_port(sc, p) {
4931 for_each_vi(pi, v, vi) {
4932 vi->first_intr = rid - 1;
4934 if (vi->nnmrxq > 0) {
4935 int n = max(vi->nrxq, vi->nnmrxq);
4937 rxq = &sge->rxq[vi->first_rxq];
4939 nm_rxq = &sge->nm_rxq[vi->first_nm_rxq];
4941 for (q = 0; q < n; q++) {
4942 snprintf(s, sizeof(s), "%x%c%x", p,
4948 irq->nm_rxq = nm_rxq++;
4950 if (irq->nm_rxq != NULL &&
4952 /* Netmap rx only */
4953 rc = t4_alloc_irq(sc, irq, rid,
4954 t4_nm_intr, irq->nm_rxq, s);
4956 if (irq->nm_rxq != NULL &&
4958 /* NIC and Netmap rx */
4959 rc = t4_alloc_irq(sc, irq, rid,
4960 t4_vi_intr, irq, s);
4963 if (irq->rxq != NULL &&
4964 irq->nm_rxq == NULL) {
4966 rc = t4_alloc_irq(sc, irq, rid,
4967 t4_intr, irq->rxq, s);
4973 bus_bind_intr(sc->dev, irq->res,
4974 rss_getcpu(q % nbuckets));
4982 for_each_rxq(vi, q, rxq) {
4983 snprintf(s, sizeof(s), "%x%c%x", p,
4985 rc = t4_alloc_irq(sc, irq, rid,
4990 bus_bind_intr(sc->dev, irq->res,
4991 rss_getcpu(q % nbuckets));
4999 for_each_ofld_rxq(vi, q, ofld_rxq) {
5000 snprintf(s, sizeof(s), "%x%c%x", p, 'A' + v, q);
5001 rc = t4_alloc_irq(sc, irq, rid, t4_intr,
5012 MPASS(irq == &sc->irq[sc->intr_count]);
5018 adapter_full_init(struct adapter *sc)
5022 uint32_t raw_rss_key[RSS_KEYSIZE / sizeof(uint32_t)];
5023 uint32_t rss_key[RSS_KEYSIZE / sizeof(uint32_t)];
5026 ASSERT_SYNCHRONIZED_OP(sc);
5027 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
5028 KASSERT((sc->flags & FULL_INIT_DONE) == 0,
5029 ("%s: FULL_INIT_DONE already", __func__));
5032 * queues that belong to the adapter (not any particular port).
5034 rc = t4_setup_adapter_queues(sc);
5038 for (i = 0; i < nitems(sc->tq); i++) {
5039 sc->tq[i] = taskqueue_create("t4 taskq", M_NOWAIT,
5040 taskqueue_thread_enqueue, &sc->tq[i]);
5041 if (sc->tq[i] == NULL) {
5042 device_printf(sc->dev,
5043 "failed to allocate task queue %d\n", i);
5047 taskqueue_start_threads(&sc->tq[i], 1, PI_NET, "%s tq%d",
5048 device_get_nameunit(sc->dev), i);
5051 MPASS(RSS_KEYSIZE == 40);
5052 rss_getkey((void *)&raw_rss_key[0]);
5053 for (i = 0; i < nitems(rss_key); i++) {
5054 rss_key[i] = htobe32(raw_rss_key[nitems(rss_key) - 1 - i]);
5056 t4_write_rss_key(sc, &rss_key[0], -1, 1);
5059 if (!(sc->flags & IS_VF))
5061 sc->flags |= FULL_INIT_DONE;
5064 adapter_full_uninit(sc);
5070 adapter_full_uninit(struct adapter *sc)
5074 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
5076 t4_teardown_adapter_queues(sc);
5078 for (i = 0; i < nitems(sc->tq) && sc->tq[i]; i++) {
5079 taskqueue_free(sc->tq[i]);
5083 sc->flags &= ~FULL_INIT_DONE;
5089 #define SUPPORTED_RSS_HASHTYPES (RSS_HASHTYPE_RSS_IPV4 | \
5090 RSS_HASHTYPE_RSS_TCP_IPV4 | RSS_HASHTYPE_RSS_IPV6 | \
5091 RSS_HASHTYPE_RSS_TCP_IPV6 | RSS_HASHTYPE_RSS_UDP_IPV4 | \
5092 RSS_HASHTYPE_RSS_UDP_IPV6)
5094 /* Translates kernel hash types to hardware. */
5096 hashconfig_to_hashen(int hashconfig)
5100 if (hashconfig & RSS_HASHTYPE_RSS_IPV4)
5101 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN;
5102 if (hashconfig & RSS_HASHTYPE_RSS_IPV6)
5103 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN;
5104 if (hashconfig & RSS_HASHTYPE_RSS_UDP_IPV4) {
5105 hashen |= F_FW_RSS_VI_CONFIG_CMD_UDPEN |
5106 F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
5108 if (hashconfig & RSS_HASHTYPE_RSS_UDP_IPV6) {
5109 hashen |= F_FW_RSS_VI_CONFIG_CMD_UDPEN |
5110 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
5112 if (hashconfig & RSS_HASHTYPE_RSS_TCP_IPV4)
5113 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
5114 if (hashconfig & RSS_HASHTYPE_RSS_TCP_IPV6)
5115 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
5120 /* Translates hardware hash types to kernel. */
5122 hashen_to_hashconfig(int hashen)
5126 if (hashen & F_FW_RSS_VI_CONFIG_CMD_UDPEN) {
5128 * If UDP hashing was enabled it must have been enabled for
5129 * either IPv4 or IPv6 (inclusive or). Enabling UDP without
5130 * enabling any 4-tuple hash is nonsense configuration.
5132 MPASS(hashen & (F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN |
5133 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN));
5135 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN)
5136 hashconfig |= RSS_HASHTYPE_RSS_UDP_IPV4;
5137 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN)
5138 hashconfig |= RSS_HASHTYPE_RSS_UDP_IPV6;
5140 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN)
5141 hashconfig |= RSS_HASHTYPE_RSS_TCP_IPV4;
5142 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN)
5143 hashconfig |= RSS_HASHTYPE_RSS_TCP_IPV6;
5144 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN)
5145 hashconfig |= RSS_HASHTYPE_RSS_IPV4;
5146 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN)
5147 hashconfig |= RSS_HASHTYPE_RSS_IPV6;
5149 return (hashconfig);
5154 vi_full_init(struct vi_info *vi)
5156 struct adapter *sc = vi->pi->adapter;
5157 struct ifnet *ifp = vi->ifp;
5159 struct sge_rxq *rxq;
5162 int nbuckets = rss_getnumbuckets();
5163 int hashconfig = rss_gethashconfig();
5167 ASSERT_SYNCHRONIZED_OP(sc);
5168 KASSERT((vi->flags & VI_INIT_DONE) == 0,
5169 ("%s: VI_INIT_DONE already", __func__));
5171 sysctl_ctx_init(&vi->ctx);
5172 vi->flags |= VI_SYSCTL_CTX;
5175 * Allocate tx/rx/fl queues for this VI.
5177 rc = t4_setup_vi_queues(vi);
5179 goto done; /* error message displayed already */
5182 * Setup RSS for this VI. Save a copy of the RSS table for later use.
5184 if (vi->nrxq > vi->rss_size) {
5185 if_printf(ifp, "nrxq (%d) > hw RSS table size (%d); "
5186 "some queues will never receive traffic.\n", vi->nrxq,
5188 } else if (vi->rss_size % vi->nrxq) {
5189 if_printf(ifp, "nrxq (%d), hw RSS table size (%d); "
5190 "expect uneven traffic distribution.\n", vi->nrxq,
5194 if (vi->nrxq != nbuckets) {
5195 if_printf(ifp, "nrxq (%d) != kernel RSS buckets (%d);"
5196 "performance will be impacted.\n", vi->nrxq, nbuckets);
5199 rss = malloc(vi->rss_size * sizeof (*rss), M_CXGBE, M_ZERO | M_WAITOK);
5200 for (i = 0; i < vi->rss_size;) {
5202 j = rss_get_indirection_to_bucket(i);
5204 rxq = &sc->sge.rxq[vi->first_rxq + j];
5205 rss[i++] = rxq->iq.abs_id;
5207 for_each_rxq(vi, j, rxq) {
5208 rss[i++] = rxq->iq.abs_id;
5209 if (i == vi->rss_size)
5215 rc = -t4_config_rss_range(sc, sc->mbox, vi->viid, 0, vi->rss_size, rss,
5219 if_printf(ifp, "rss_config failed: %d\n", rc);
5224 vi->hashen = hashconfig_to_hashen(hashconfig);
5227 * We may have had to enable some hashes even though the global config
5228 * wants them disabled. This is a potential problem that must be
5229 * reported to the user.
5231 extra = hashen_to_hashconfig(vi->hashen) ^ hashconfig;
5234 * If we consider only the supported hash types, then the enabled hashes
5235 * are a superset of the requested hashes. In other words, there cannot
5236 * be any supported hash that was requested but not enabled, but there
5237 * can be hashes that were not requested but had to be enabled.
5239 extra &= SUPPORTED_RSS_HASHTYPES;
5240 MPASS((extra & hashconfig) == 0);
5244 "global RSS config (0x%x) cannot be accommodated.\n",
5247 if (extra & RSS_HASHTYPE_RSS_IPV4)
5248 if_printf(ifp, "IPv4 2-tuple hashing forced on.\n");
5249 if (extra & RSS_HASHTYPE_RSS_TCP_IPV4)
5250 if_printf(ifp, "TCP/IPv4 4-tuple hashing forced on.\n");
5251 if (extra & RSS_HASHTYPE_RSS_IPV6)
5252 if_printf(ifp, "IPv6 2-tuple hashing forced on.\n");
5253 if (extra & RSS_HASHTYPE_RSS_TCP_IPV6)
5254 if_printf(ifp, "TCP/IPv6 4-tuple hashing forced on.\n");
5255 if (extra & RSS_HASHTYPE_RSS_UDP_IPV4)
5256 if_printf(ifp, "UDP/IPv4 4-tuple hashing forced on.\n");
5257 if (extra & RSS_HASHTYPE_RSS_UDP_IPV6)
5258 if_printf(ifp, "UDP/IPv6 4-tuple hashing forced on.\n");
5260 vi->hashen = F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN |
5261 F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN |
5262 F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN |
5263 F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN | F_FW_RSS_VI_CONFIG_CMD_UDPEN;
5265 rc = -t4_config_vi_rss(sc, sc->mbox, vi->viid, vi->hashen, rss[0], 0, 0);
5268 if_printf(ifp, "rss hash/defaultq config failed: %d\n", rc);
5273 vi->flags |= VI_INIT_DONE;
5285 vi_full_uninit(struct vi_info *vi)
5287 struct port_info *pi = vi->pi;
5288 struct adapter *sc = pi->adapter;
5290 struct sge_rxq *rxq;
5291 struct sge_txq *txq;
5293 struct sge_ofld_rxq *ofld_rxq;
5294 struct sge_wrq *ofld_txq;
5297 if (vi->flags & VI_INIT_DONE) {
5299 /* Need to quiesce queues. */
5301 /* XXX: Only for the first VI? */
5302 if (IS_MAIN_VI(vi) && !(sc->flags & IS_VF))
5303 quiesce_wrq(sc, &sc->sge.ctrlq[pi->port_id]);
5305 for_each_txq(vi, i, txq) {
5306 quiesce_txq(sc, txq);
5310 for_each_ofld_txq(vi, i, ofld_txq) {
5311 quiesce_wrq(sc, ofld_txq);
5315 for_each_rxq(vi, i, rxq) {
5316 quiesce_iq(sc, &rxq->iq);
5317 quiesce_fl(sc, &rxq->fl);
5321 for_each_ofld_rxq(vi, i, ofld_rxq) {
5322 quiesce_iq(sc, &ofld_rxq->iq);
5323 quiesce_fl(sc, &ofld_rxq->fl);
5326 free(vi->rss, M_CXGBE);
5327 free(vi->nm_rss, M_CXGBE);
5330 t4_teardown_vi_queues(vi);
5331 vi->flags &= ~VI_INIT_DONE;
5337 quiesce_txq(struct adapter *sc, struct sge_txq *txq)
5339 struct sge_eq *eq = &txq->eq;
5340 struct sge_qstat *spg = (void *)&eq->desc[eq->sidx];
5342 (void) sc; /* unused */
5346 MPASS((eq->flags & EQ_ENABLED) == 0);
5350 /* Wait for the mp_ring to empty. */
5351 while (!mp_ring_is_idle(txq->r)) {
5352 mp_ring_check_drainage(txq->r, 0);
5353 pause("rquiesce", 1);
5356 /* Then wait for the hardware to finish. */
5357 while (spg->cidx != htobe16(eq->pidx))
5358 pause("equiesce", 1);
5360 /* Finally, wait for the driver to reclaim all descriptors. */
5361 while (eq->cidx != eq->pidx)
5362 pause("dquiesce", 1);
5366 quiesce_wrq(struct adapter *sc, struct sge_wrq *wrq)
5373 quiesce_iq(struct adapter *sc, struct sge_iq *iq)
5375 (void) sc; /* unused */
5377 /* Synchronize with the interrupt handler */
5378 while (!atomic_cmpset_int(&iq->state, IQS_IDLE, IQS_DISABLED))
5383 quiesce_fl(struct adapter *sc, struct sge_fl *fl)
5385 mtx_lock(&sc->sfl_lock);
5387 fl->flags |= FL_DOOMED;
5389 callout_stop(&sc->sfl_callout);
5390 mtx_unlock(&sc->sfl_lock);
5392 KASSERT((fl->flags & FL_STARVING) == 0,
5393 ("%s: still starving", __func__));
5397 t4_alloc_irq(struct adapter *sc, struct irq *irq, int rid,
5398 driver_intr_t *handler, void *arg, char *name)
5403 irq->res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &irq->rid,
5404 RF_SHAREABLE | RF_ACTIVE);
5405 if (irq->res == NULL) {
5406 device_printf(sc->dev,
5407 "failed to allocate IRQ for rid %d, name %s.\n", rid, name);
5411 rc = bus_setup_intr(sc->dev, irq->res, INTR_MPSAFE | INTR_TYPE_NET,
5412 NULL, handler, arg, &irq->tag);
5414 device_printf(sc->dev,
5415 "failed to setup interrupt for rid %d, name %s: %d\n",
5418 bus_describe_intr(sc->dev, irq->res, irq->tag, "%s", name);
5424 t4_free_irq(struct adapter *sc, struct irq *irq)
5427 bus_teardown_intr(sc->dev, irq->res, irq->tag);
5429 bus_release_resource(sc->dev, SYS_RES_IRQ, irq->rid, irq->res);
5431 bzero(irq, sizeof(*irq));
5437 get_regs(struct adapter *sc, struct t4_regdump *regs, uint8_t *buf)
5440 regs->version = chip_id(sc) | chip_rev(sc) << 10;
5441 t4_get_regs(sc, buf, regs->len);
5444 #define A_PL_INDIR_CMD 0x1f8
5446 #define S_PL_AUTOINC 31
5447 #define M_PL_AUTOINC 0x1U
5448 #define V_PL_AUTOINC(x) ((x) << S_PL_AUTOINC)
5449 #define G_PL_AUTOINC(x) (((x) >> S_PL_AUTOINC) & M_PL_AUTOINC)
5451 #define S_PL_VFID 20
5452 #define M_PL_VFID 0xffU
5453 #define V_PL_VFID(x) ((x) << S_PL_VFID)
5454 #define G_PL_VFID(x) (((x) >> S_PL_VFID) & M_PL_VFID)
5457 #define M_PL_ADDR 0xfffffU
5458 #define V_PL_ADDR(x) ((x) << S_PL_ADDR)
5459 #define G_PL_ADDR(x) (((x) >> S_PL_ADDR) & M_PL_ADDR)
5461 #define A_PL_INDIR_DATA 0x1fc
5464 read_vf_stat(struct adapter *sc, unsigned int viid, int reg)
5468 mtx_assert(&sc->reg_lock, MA_OWNED);
5469 if (sc->flags & IS_VF) {
5470 stats[0] = t4_read_reg(sc, VF_MPS_REG(reg));
5471 stats[1] = t4_read_reg(sc, VF_MPS_REG(reg + 4));
5473 t4_write_reg(sc, A_PL_INDIR_CMD, V_PL_AUTOINC(1) |
5474 V_PL_VFID(G_FW_VIID_VIN(viid)) |
5475 V_PL_ADDR(VF_MPS_REG(reg)));
5476 stats[0] = t4_read_reg(sc, A_PL_INDIR_DATA);
5477 stats[1] = t4_read_reg(sc, A_PL_INDIR_DATA);
5479 return (((uint64_t)stats[1]) << 32 | stats[0]);
5483 t4_get_vi_stats(struct adapter *sc, unsigned int viid,
5484 struct fw_vi_stats_vf *stats)
5487 #define GET_STAT(name) \
5488 read_vf_stat(sc, viid, A_MPS_VF_STAT_##name##_L)
5490 stats->tx_bcast_bytes = GET_STAT(TX_VF_BCAST_BYTES);
5491 stats->tx_bcast_frames = GET_STAT(TX_VF_BCAST_FRAMES);
5492 stats->tx_mcast_bytes = GET_STAT(TX_VF_MCAST_BYTES);
5493 stats->tx_mcast_frames = GET_STAT(TX_VF_MCAST_FRAMES);
5494 stats->tx_ucast_bytes = GET_STAT(TX_VF_UCAST_BYTES);
5495 stats->tx_ucast_frames = GET_STAT(TX_VF_UCAST_FRAMES);
5496 stats->tx_drop_frames = GET_STAT(TX_VF_DROP_FRAMES);
5497 stats->tx_offload_bytes = GET_STAT(TX_VF_OFFLOAD_BYTES);
5498 stats->tx_offload_frames = GET_STAT(TX_VF_OFFLOAD_FRAMES);
5499 stats->rx_bcast_bytes = GET_STAT(RX_VF_BCAST_BYTES);
5500 stats->rx_bcast_frames = GET_STAT(RX_VF_BCAST_FRAMES);
5501 stats->rx_mcast_bytes = GET_STAT(RX_VF_MCAST_BYTES);
5502 stats->rx_mcast_frames = GET_STAT(RX_VF_MCAST_FRAMES);
5503 stats->rx_ucast_bytes = GET_STAT(RX_VF_UCAST_BYTES);
5504 stats->rx_ucast_frames = GET_STAT(RX_VF_UCAST_FRAMES);
5505 stats->rx_err_frames = GET_STAT(RX_VF_ERR_FRAMES);
5511 t4_clr_vi_stats(struct adapter *sc, unsigned int viid)
5515 t4_write_reg(sc, A_PL_INDIR_CMD, V_PL_AUTOINC(1) |
5516 V_PL_VFID(G_FW_VIID_VIN(viid)) |
5517 V_PL_ADDR(VF_MPS_REG(A_MPS_VF_STAT_TX_VF_BCAST_BYTES_L)));
5518 for (reg = A_MPS_VF_STAT_TX_VF_BCAST_BYTES_L;
5519 reg <= A_MPS_VF_STAT_RX_VF_ERR_FRAMES_H; reg += 4)
5520 t4_write_reg(sc, A_PL_INDIR_DATA, 0);
5524 vi_refresh_stats(struct adapter *sc, struct vi_info *vi)
5527 const struct timeval interval = {0, 250000}; /* 250ms */
5529 if (!(vi->flags & VI_INIT_DONE))
5533 timevalsub(&tv, &interval);
5534 if (timevalcmp(&tv, &vi->last_refreshed, <))
5537 mtx_lock(&sc->reg_lock);
5538 t4_get_vi_stats(sc, vi->viid, &vi->stats);
5539 getmicrotime(&vi->last_refreshed);
5540 mtx_unlock(&sc->reg_lock);
5544 cxgbe_refresh_stats(struct adapter *sc, struct port_info *pi)
5546 u_int i, v, tnl_cong_drops, bg_map;
5548 const struct timeval interval = {0, 250000}; /* 250ms */
5551 timevalsub(&tv, &interval);
5552 if (timevalcmp(&tv, &pi->last_refreshed, <))
5556 t4_get_port_stats(sc, pi->tx_chan, &pi->stats);
5557 bg_map = pi->mps_bg_map;
5559 i = ffs(bg_map) - 1;
5560 mtx_lock(&sc->reg_lock);
5561 t4_read_indirect(sc, A_TP_MIB_INDEX, A_TP_MIB_DATA, &v, 1,
5562 A_TP_MIB_TNL_CNG_DROP_0 + i);
5563 mtx_unlock(&sc->reg_lock);
5564 tnl_cong_drops += v;
5565 bg_map &= ~(1 << i);
5567 pi->tnl_cong_drops = tnl_cong_drops;
5568 getmicrotime(&pi->last_refreshed);
5572 cxgbe_tick(void *arg)
5574 struct port_info *pi = arg;
5575 struct adapter *sc = pi->adapter;
5577 PORT_LOCK_ASSERT_OWNED(pi);
5578 cxgbe_refresh_stats(sc, pi);
5580 callout_schedule(&pi->tick, hz);
5586 struct vi_info *vi = arg;
5587 struct adapter *sc = vi->pi->adapter;
5589 vi_refresh_stats(sc, vi);
5591 callout_schedule(&vi->tick, hz);
5595 * Should match fw_caps_config_<foo> enums in t4fw_interface.h
5597 static char *caps_decoder[] = {
5598 "\20\001IPMI\002NCSI", /* 0: NBM */
5599 "\20\001PPP\002QFC\003DCBX", /* 1: link */
5600 "\20\001INGRESS\002EGRESS", /* 2: switch */
5601 "\20\001NIC\002VM\003IDS\004UM\005UM_ISGL" /* 3: NIC */
5602 "\006HASHFILTER\007ETHOFLD",
5603 "\20\001TOE", /* 4: TOE */
5604 "\20\001RDDP\002RDMAC", /* 5: RDMA */
5605 "\20\001INITIATOR_PDU\002TARGET_PDU" /* 6: iSCSI */
5606 "\003INITIATOR_CNXOFLD\004TARGET_CNXOFLD"
5607 "\005INITIATOR_SSNOFLD\006TARGET_SSNOFLD"
5609 "\010INITIATOR_CMDOFLD\011TARGET_CMDOFLD",
5610 "\20\001LOOKASIDE\002TLSKEYS", /* 7: Crypto */
5611 "\20\001INITIATOR\002TARGET\003CTRL_OFLD" /* 8: FCoE */
5612 "\004PO_INITIATOR\005PO_TARGET",
5616 t4_sysctls(struct adapter *sc)
5618 struct sysctl_ctx_list *ctx;
5619 struct sysctl_oid *oid;
5620 struct sysctl_oid_list *children, *c0;
5621 static char *doorbells = {"\20\1UDB\2WCWR\3UDBWC\4KDB"};
5623 ctx = device_get_sysctl_ctx(sc->dev);
5628 oid = device_get_sysctl_tree(sc->dev);
5629 c0 = children = SYSCTL_CHILDREN(oid);
5631 sc->sc_do_rxcopy = 1;
5632 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "do_rx_copy", CTLFLAG_RW,
5633 &sc->sc_do_rxcopy, 1, "Do RX copy of small frames");
5635 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nports", CTLFLAG_RD, NULL,
5636 sc->params.nports, "# of ports");
5638 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "doorbells",
5639 CTLTYPE_STRING | CTLFLAG_RD, doorbells, (uintptr_t)&sc->doorbells,
5640 sysctl_bitfield_8b, "A", "available doorbells");
5642 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "core_clock", CTLFLAG_RD, NULL,
5643 sc->params.vpd.cclk, "core clock frequency (in KHz)");
5645 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_timers",
5646 CTLTYPE_STRING | CTLFLAG_RD, sc->params.sge.timer_val,
5647 sizeof(sc->params.sge.timer_val), sysctl_int_array, "A",
5648 "interrupt holdoff timer values (us)");
5650 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pkt_counts",
5651 CTLTYPE_STRING | CTLFLAG_RD, sc->params.sge.counter_val,
5652 sizeof(sc->params.sge.counter_val), sysctl_int_array, "A",
5653 "interrupt holdoff packet counter values");
5655 t4_sge_sysctls(sc, ctx, children);
5657 sc->lro_timeout = 100;
5658 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "lro_timeout", CTLFLAG_RW,
5659 &sc->lro_timeout, 0, "lro inactive-flush timeout (in us)");
5661 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "dflags", CTLFLAG_RW,
5662 &sc->debug_flags, 0, "flags to enable runtime debugging");
5664 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "tp_version",
5665 CTLFLAG_RD, sc->tp_version, 0, "TP microcode version");
5667 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "firmware_version",
5668 CTLFLAG_RD, sc->fw_version, 0, "firmware version");
5670 if (sc->flags & IS_VF)
5673 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "hw_revision", CTLFLAG_RD,
5674 NULL, chip_rev(sc), "chip hardware revision");
5676 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "sn",
5677 CTLFLAG_RD, sc->params.vpd.sn, 0, "serial number");
5679 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "pn",
5680 CTLFLAG_RD, sc->params.vpd.pn, 0, "part number");
5682 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "ec",
5683 CTLFLAG_RD, sc->params.vpd.ec, 0, "engineering change");
5685 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "md_version",
5686 CTLFLAG_RD, sc->params.vpd.md, 0, "manufacturing diags version");
5688 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "na",
5689 CTLFLAG_RD, sc->params.vpd.na, 0, "network address");
5691 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "er_version", CTLFLAG_RD,
5692 sc->er_version, 0, "expansion ROM version");
5694 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "bs_version", CTLFLAG_RD,
5695 sc->bs_version, 0, "bootstrap firmware version");
5697 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "scfg_version", CTLFLAG_RD,
5698 NULL, sc->params.scfg_vers, "serial config version");
5700 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "vpd_version", CTLFLAG_RD,
5701 NULL, sc->params.vpd_vers, "VPD version");
5703 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "cf",
5704 CTLFLAG_RD, sc->cfg_file, 0, "configuration file");
5706 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "cfcsum", CTLFLAG_RD, NULL,
5707 sc->cfcsum, "config file checksum");
5709 #define SYSCTL_CAP(name, n, text) \
5710 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, #name, \
5711 CTLTYPE_STRING | CTLFLAG_RD, caps_decoder[n], (uintptr_t)&sc->name, \
5712 sysctl_bitfield_16b, "A", "available " text " capabilities")
5714 SYSCTL_CAP(nbmcaps, 0, "NBM");
5715 SYSCTL_CAP(linkcaps, 1, "link");
5716 SYSCTL_CAP(switchcaps, 2, "switch");
5717 SYSCTL_CAP(niccaps, 3, "NIC");
5718 SYSCTL_CAP(toecaps, 4, "TCP offload");
5719 SYSCTL_CAP(rdmacaps, 5, "RDMA");
5720 SYSCTL_CAP(iscsicaps, 6, "iSCSI");
5721 SYSCTL_CAP(cryptocaps, 7, "crypto");
5722 SYSCTL_CAP(fcoecaps, 8, "FCoE");
5725 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nfilters", CTLFLAG_RD,
5726 NULL, sc->tids.nftids, "number of filters");
5728 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature", CTLTYPE_INT |
5729 CTLFLAG_RD, sc, 0, sysctl_temperature, "I",
5730 "chip temperature (in Celsius)");
5732 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "loadavg", CTLTYPE_STRING |
5733 CTLFLAG_RD, sc, 0, sysctl_loadavg, "A",
5734 "microprocessor load averages (debug firmwares only)");
5736 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "core_vdd", CTLFLAG_RD,
5737 &sc->params.core_vdd, 0, "core Vdd (in mV)");
5739 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "local_cpus",
5740 CTLTYPE_STRING | CTLFLAG_RD, sc, LOCAL_CPUS,
5741 sysctl_cpus, "A", "local CPUs");
5743 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_cpus",
5744 CTLTYPE_STRING | CTLFLAG_RD, sc, INTR_CPUS,
5745 sysctl_cpus, "A", "preferred CPUs for interrupts");
5748 * dev.t4nex.X.misc. Marked CTLFLAG_SKIP to avoid information overload.
5750 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "misc",
5751 CTLFLAG_RD | CTLFLAG_SKIP, NULL,
5752 "logs and miscellaneous information");
5753 children = SYSCTL_CHILDREN(oid);
5755 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cctrl",
5756 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5757 sysctl_cctrl, "A", "congestion control");
5759 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp0",
5760 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5761 sysctl_cim_ibq_obq, "A", "CIM IBQ 0 (TP0)");
5763 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp1",
5764 CTLTYPE_STRING | CTLFLAG_RD, sc, 1,
5765 sysctl_cim_ibq_obq, "A", "CIM IBQ 1 (TP1)");
5767 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ulp",
5768 CTLTYPE_STRING | CTLFLAG_RD, sc, 2,
5769 sysctl_cim_ibq_obq, "A", "CIM IBQ 2 (ULP)");
5771 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge0",
5772 CTLTYPE_STRING | CTLFLAG_RD, sc, 3,
5773 sysctl_cim_ibq_obq, "A", "CIM IBQ 3 (SGE0)");
5775 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge1",
5776 CTLTYPE_STRING | CTLFLAG_RD, sc, 4,
5777 sysctl_cim_ibq_obq, "A", "CIM IBQ 4 (SGE1)");
5779 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ncsi",
5780 CTLTYPE_STRING | CTLFLAG_RD, sc, 5,
5781 sysctl_cim_ibq_obq, "A", "CIM IBQ 5 (NCSI)");
5783 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_la",
5784 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5785 chip_id(sc) <= CHELSIO_T5 ? sysctl_cim_la : sysctl_cim_la_t6,
5786 "A", "CIM logic analyzer");
5788 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ma_la",
5789 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5790 sysctl_cim_ma_la, "A", "CIM MA logic analyzer");
5792 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp0",
5793 CTLTYPE_STRING | CTLFLAG_RD, sc, 0 + CIM_NUM_IBQ,
5794 sysctl_cim_ibq_obq, "A", "CIM OBQ 0 (ULP0)");
5796 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp1",
5797 CTLTYPE_STRING | CTLFLAG_RD, sc, 1 + CIM_NUM_IBQ,
5798 sysctl_cim_ibq_obq, "A", "CIM OBQ 1 (ULP1)");
5800 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp2",
5801 CTLTYPE_STRING | CTLFLAG_RD, sc, 2 + CIM_NUM_IBQ,
5802 sysctl_cim_ibq_obq, "A", "CIM OBQ 2 (ULP2)");
5804 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp3",
5805 CTLTYPE_STRING | CTLFLAG_RD, sc, 3 + CIM_NUM_IBQ,
5806 sysctl_cim_ibq_obq, "A", "CIM OBQ 3 (ULP3)");
5808 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge",
5809 CTLTYPE_STRING | CTLFLAG_RD, sc, 4 + CIM_NUM_IBQ,
5810 sysctl_cim_ibq_obq, "A", "CIM OBQ 4 (SGE)");
5812 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ncsi",
5813 CTLTYPE_STRING | CTLFLAG_RD, sc, 5 + CIM_NUM_IBQ,
5814 sysctl_cim_ibq_obq, "A", "CIM OBQ 5 (NCSI)");
5816 if (chip_id(sc) > CHELSIO_T4) {
5817 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge0_rx",
5818 CTLTYPE_STRING | CTLFLAG_RD, sc, 6 + CIM_NUM_IBQ,
5819 sysctl_cim_ibq_obq, "A", "CIM OBQ 6 (SGE0-RX)");
5821 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge1_rx",
5822 CTLTYPE_STRING | CTLFLAG_RD, sc, 7 + CIM_NUM_IBQ,
5823 sysctl_cim_ibq_obq, "A", "CIM OBQ 7 (SGE1-RX)");
5826 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_pif_la",
5827 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5828 sysctl_cim_pif_la, "A", "CIM PIF logic analyzer");
5830 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_qcfg",
5831 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5832 sysctl_cim_qcfg, "A", "CIM queue configuration");
5834 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cpl_stats",
5835 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5836 sysctl_cpl_stats, "A", "CPL statistics");
5838 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ddp_stats",
5839 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5840 sysctl_ddp_stats, "A", "non-TCP DDP statistics");
5842 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "devlog",
5843 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5844 sysctl_devlog, "A", "firmware's device log");
5846 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fcoe_stats",
5847 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5848 sysctl_fcoe_stats, "A", "FCoE statistics");
5850 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "hw_sched",
5851 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5852 sysctl_hw_sched, "A", "hardware scheduler ");
5854 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "l2t",
5855 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5856 sysctl_l2t, "A", "hardware L2 table");
5858 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "smt",
5859 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5860 sysctl_smt, "A", "hardware source MAC table");
5862 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "lb_stats",
5863 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5864 sysctl_lb_stats, "A", "loopback statistics");
5866 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "meminfo",
5867 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5868 sysctl_meminfo, "A", "memory regions");
5870 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "mps_tcam",
5871 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5872 chip_id(sc) <= CHELSIO_T5 ? sysctl_mps_tcam : sysctl_mps_tcam_t6,
5873 "A", "MPS TCAM entries");
5875 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "path_mtus",
5876 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5877 sysctl_path_mtus, "A", "path MTUs");
5879 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pm_stats",
5880 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5881 sysctl_pm_stats, "A", "PM statistics");
5883 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rdma_stats",
5884 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5885 sysctl_rdma_stats, "A", "RDMA statistics");
5887 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tcp_stats",
5888 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5889 sysctl_tcp_stats, "A", "TCP statistics");
5891 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tids",
5892 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5893 sysctl_tids, "A", "TID information");
5895 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_err_stats",
5896 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5897 sysctl_tp_err_stats, "A", "TP error statistics");
5899 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_la_mask",
5900 CTLTYPE_INT | CTLFLAG_RW, sc, 0, sysctl_tp_la_mask, "I",
5901 "TP logic analyzer event capture mask");
5903 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_la",
5904 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5905 sysctl_tp_la, "A", "TP logic analyzer");
5907 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_rate",
5908 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5909 sysctl_tx_rate, "A", "Tx rate");
5911 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ulprx_la",
5912 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5913 sysctl_ulprx_la, "A", "ULPRX logic analyzer");
5915 if (chip_id(sc) >= CHELSIO_T5) {
5916 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "wcwr_stats",
5917 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5918 sysctl_wcwr_stats, "A", "write combined work requests");
5922 if (is_offload(sc)) {
5929 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "toe", CTLFLAG_RD,
5930 NULL, "TOE parameters");
5931 children = SYSCTL_CHILDREN(oid);
5933 sc->tt.cong_algorithm = -1;
5934 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "cong_algorithm",
5935 CTLFLAG_RW, &sc->tt.cong_algorithm, 0, "congestion control "
5936 "(-1 = default, 0 = reno, 1 = tahoe, 2 = newreno, "
5939 sc->tt.sndbuf = 256 * 1024;
5940 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "sndbuf", CTLFLAG_RW,
5941 &sc->tt.sndbuf, 0, "max hardware send buffer size");
5944 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ddp", CTLFLAG_RW,
5945 &sc->tt.ddp, 0, "DDP allowed");
5947 sc->tt.rx_coalesce = 1;
5948 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_coalesce",
5949 CTLFLAG_RW, &sc->tt.rx_coalesce, 0, "receive coalescing");
5952 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tls", CTLFLAG_RW,
5953 &sc->tt.tls, 0, "Inline TLS allowed");
5955 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tls_rx_ports",
5956 CTLTYPE_INT | CTLFLAG_RW, sc, 0, sysctl_tls_rx_ports,
5957 "I", "TCP ports that use inline TLS+TOE RX");
5959 sc->tt.tx_align = 1;
5960 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_align",
5961 CTLFLAG_RW, &sc->tt.tx_align, 0, "chop and align payload");
5963 sc->tt.tx_zcopy = 0;
5964 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_zcopy",
5965 CTLFLAG_RW, &sc->tt.tx_zcopy, 0,
5966 "Enable zero-copy aio_write(2)");
5968 sc->tt.cop_managed_offloading = !!t4_cop_managed_offloading;
5969 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5970 "cop_managed_offloading", CTLFLAG_RW,
5971 &sc->tt.cop_managed_offloading, 0,
5972 "COP (Connection Offload Policy) controls all TOE offload");
5974 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "timer_tick",
5975 CTLTYPE_STRING | CTLFLAG_RD, sc, 0, sysctl_tp_tick, "A",
5976 "TP timer tick (us)");
5978 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "timestamp_tick",
5979 CTLTYPE_STRING | CTLFLAG_RD, sc, 1, sysctl_tp_tick, "A",
5980 "TCP timestamp tick (us)");
5982 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "dack_tick",
5983 CTLTYPE_STRING | CTLFLAG_RD, sc, 2, sysctl_tp_tick, "A",
5986 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "dack_timer",
5987 CTLTYPE_UINT | CTLFLAG_RD, sc, 0, sysctl_tp_dack_timer,
5988 "IU", "DACK timer (us)");
5990 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_min",
5991 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_RXT_MIN,
5992 sysctl_tp_timer, "LU", "Minimum retransmit interval (us)");
5994 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_max",
5995 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_RXT_MAX,
5996 sysctl_tp_timer, "LU", "Maximum retransmit interval (us)");
5998 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "persist_min",
5999 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_PERS_MIN,
6000 sysctl_tp_timer, "LU", "Persist timer min (us)");
6002 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "persist_max",
6003 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_PERS_MAX,
6004 sysctl_tp_timer, "LU", "Persist timer max (us)");
6006 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_idle",
6007 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_KEEP_IDLE,
6008 sysctl_tp_timer, "LU", "Keepalive idle timer (us)");
6010 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_interval",
6011 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_KEEP_INTVL,
6012 sysctl_tp_timer, "LU", "Keepalive interval timer (us)");
6014 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "initial_srtt",
6015 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_INIT_SRTT,
6016 sysctl_tp_timer, "LU", "Initial SRTT (us)");
6018 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "finwait2_timer",
6019 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_FINWAIT2_TIMER,
6020 sysctl_tp_timer, "LU", "FINWAIT2 timer (us)");
6022 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "syn_rexmt_count",
6023 CTLTYPE_UINT | CTLFLAG_RD, sc, S_SYNSHIFTMAX,
6024 sysctl_tp_shift_cnt, "IU",
6025 "Number of SYN retransmissions before abort");
6027 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_count",
6028 CTLTYPE_UINT | CTLFLAG_RD, sc, S_RXTSHIFTMAXR2,
6029 sysctl_tp_shift_cnt, "IU",
6030 "Number of retransmissions before abort");
6032 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_count",
6033 CTLTYPE_UINT | CTLFLAG_RD, sc, S_KEEPALIVEMAXR2,
6034 sysctl_tp_shift_cnt, "IU",
6035 "Number of keepalive probes before abort");
6037 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "rexmt_backoff",
6038 CTLFLAG_RD, NULL, "TOE retransmit backoffs");
6039 children = SYSCTL_CHILDREN(oid);
6040 for (i = 0; i < 16; i++) {
6041 snprintf(s, sizeof(s), "%u", i);
6042 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, s,
6043 CTLTYPE_UINT | CTLFLAG_RD, sc, i, sysctl_tp_backoff,
6044 "IU", "TOE retransmit backoff");
6051 vi_sysctls(struct vi_info *vi)
6053 struct sysctl_ctx_list *ctx;
6054 struct sysctl_oid *oid;
6055 struct sysctl_oid_list *children;
6057 ctx = device_get_sysctl_ctx(vi->dev);
6060 * dev.v?(cxgbe|cxl).X.
6062 oid = device_get_sysctl_tree(vi->dev);
6063 children = SYSCTL_CHILDREN(oid);
6065 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "viid", CTLFLAG_RD, NULL,
6066 vi->viid, "VI identifer");
6067 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nrxq", CTLFLAG_RD,
6068 &vi->nrxq, 0, "# of rx queues");
6069 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ntxq", CTLFLAG_RD,
6070 &vi->ntxq, 0, "# of tx queues");
6071 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_rxq", CTLFLAG_RD,
6072 &vi->first_rxq, 0, "index of first rx queue");
6073 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_txq", CTLFLAG_RD,
6074 &vi->first_txq, 0, "index of first tx queue");
6075 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "rss_base", CTLFLAG_RD, NULL,
6076 vi->rss_base, "start of RSS indirection table");
6077 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "rss_size", CTLFLAG_RD, NULL,
6078 vi->rss_size, "size of RSS indirection table");
6080 if (IS_MAIN_VI(vi)) {
6081 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rsrv_noflowq",
6082 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_noflowq, "IU",
6083 "Reserve queue 0 for non-flowid packets");
6087 if (vi->nofldrxq != 0) {
6088 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldrxq", CTLFLAG_RD,
6090 "# of rx queues for offloaded TCP connections");
6091 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldtxq", CTLFLAG_RD,
6093 "# of tx queues for offloaded TCP connections");
6094 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_rxq",
6095 CTLFLAG_RD, &vi->first_ofld_rxq, 0,
6096 "index of first TOE rx queue");
6097 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_txq",
6098 CTLFLAG_RD, &vi->first_ofld_txq, 0,
6099 "index of first TOE tx queue");
6100 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx_ofld",
6101 CTLTYPE_INT | CTLFLAG_RW, vi, 0,
6102 sysctl_holdoff_tmr_idx_ofld, "I",
6103 "holdoff timer index for TOE queues");
6104 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx_ofld",
6105 CTLTYPE_INT | CTLFLAG_RW, vi, 0,
6106 sysctl_holdoff_pktc_idx_ofld, "I",
6107 "holdoff packet counter index for TOE queues");
6111 if (vi->nnmrxq != 0) {
6112 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmrxq", CTLFLAG_RD,
6113 &vi->nnmrxq, 0, "# of netmap rx queues");
6114 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmtxq", CTLFLAG_RD,
6115 &vi->nnmtxq, 0, "# of netmap tx queues");
6116 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_rxq",
6117 CTLFLAG_RD, &vi->first_nm_rxq, 0,
6118 "index of first netmap rx queue");
6119 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_txq",
6120 CTLFLAG_RD, &vi->first_nm_txq, 0,
6121 "index of first netmap tx queue");
6125 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx",
6126 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_holdoff_tmr_idx, "I",
6127 "holdoff timer index");
6128 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx",
6129 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_holdoff_pktc_idx, "I",
6130 "holdoff packet counter index");
6132 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_rxq",
6133 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_qsize_rxq, "I",
6135 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_txq",
6136 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_qsize_txq, "I",
6141 cxgbe_sysctls(struct port_info *pi)
6143 struct sysctl_ctx_list *ctx;
6144 struct sysctl_oid *oid;
6145 struct sysctl_oid_list *children, *children2;
6146 struct adapter *sc = pi->adapter;
6149 static char *tc_flags = {"\20\1USER\2SYNC\3ASYNC\4ERR"};
6151 ctx = device_get_sysctl_ctx(pi->dev);
6156 oid = device_get_sysctl_tree(pi->dev);
6157 children = SYSCTL_CHILDREN(oid);
6159 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "linkdnrc", CTLTYPE_STRING |
6160 CTLFLAG_RD, pi, 0, sysctl_linkdnrc, "A", "reason why link is down");
6161 if (pi->port_type == FW_PORT_TYPE_BT_XAUI) {
6162 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature",
6163 CTLTYPE_INT | CTLFLAG_RD, pi, 0, sysctl_btphy, "I",
6164 "PHY temperature (in Celsius)");
6165 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fw_version",
6166 CTLTYPE_INT | CTLFLAG_RD, pi, 1, sysctl_btphy, "I",
6167 "PHY firmware version");
6170 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pause_settings",
6171 CTLTYPE_STRING | CTLFLAG_RW, pi, 0, sysctl_pause_settings, "A",
6172 "PAUSE settings (bit 0 = rx_pause, bit 1 = tx_pause)");
6173 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fec",
6174 CTLTYPE_STRING | CTLFLAG_RW, pi, 0, sysctl_fec, "A",
6175 "Forward Error Correction (bit 0 = RS, bit 1 = BASER_RS)");
6176 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "autoneg",
6177 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_autoneg, "I",
6178 "autonegotiation (-1 = not supported)");
6180 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "max_speed", CTLFLAG_RD, NULL,
6181 port_top_speed(pi), "max speed (in Gbps)");
6182 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "mps_bg_map", CTLFLAG_RD, NULL,
6183 pi->mps_bg_map, "MPS buffer group map");
6184 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_e_chan_map", CTLFLAG_RD,
6185 NULL, pi->rx_e_chan_map, "TP rx e-channel map");
6187 if (sc->flags & IS_VF)
6191 * dev.(cxgbe|cxl).X.tc.
6193 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "tc", CTLFLAG_RD, NULL,
6194 "Tx scheduler traffic classes (cl_rl)");
6195 children2 = SYSCTL_CHILDREN(oid);
6196 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "pktsize",
6197 CTLFLAG_RW, &pi->sched_params->pktsize, 0,
6198 "pktsize for per-flow cl-rl (0 means up to the driver )");
6199 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "burstsize",
6200 CTLFLAG_RW, &pi->sched_params->burstsize, 0,
6201 "burstsize for per-flow cl-rl (0 means up to the driver)");
6202 for (i = 0; i < sc->chip_params->nsched_cls; i++) {
6203 struct tx_cl_rl_params *tc = &pi->sched_params->cl_rl[i];
6205 snprintf(name, sizeof(name), "%d", i);
6206 children2 = SYSCTL_CHILDREN(SYSCTL_ADD_NODE(ctx,
6207 SYSCTL_CHILDREN(oid), OID_AUTO, name, CTLFLAG_RD, NULL,
6209 SYSCTL_ADD_PROC(ctx, children2, OID_AUTO, "flags",
6210 CTLTYPE_STRING | CTLFLAG_RD, tc_flags, (uintptr_t)&tc->flags,
6211 sysctl_bitfield_8b, "A", "flags");
6212 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "refcount",
6213 CTLFLAG_RD, &tc->refcount, 0, "references to this class");
6214 SYSCTL_ADD_PROC(ctx, children2, OID_AUTO, "params",
6215 CTLTYPE_STRING | CTLFLAG_RD, sc, (pi->port_id << 16) | i,
6216 sysctl_tc_params, "A", "traffic class parameters");
6220 * dev.cxgbe.X.stats.
6222 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats", CTLFLAG_RD,
6223 NULL, "port statistics");
6224 children = SYSCTL_CHILDREN(oid);
6225 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "tx_parse_error", CTLFLAG_RD,
6226 &pi->tx_parse_error, 0,
6227 "# of tx packets with invalid length or # of segments");
6229 #define SYSCTL_ADD_T4_REG64(pi, name, desc, reg) \
6230 SYSCTL_ADD_OID(ctx, children, OID_AUTO, name, \
6231 CTLTYPE_U64 | CTLFLAG_RD, sc, reg, \
6232 sysctl_handle_t4_reg64, "QU", desc)
6234 SYSCTL_ADD_T4_REG64(pi, "tx_octets", "# of octets in good frames",
6235 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BYTES_L));
6236 SYSCTL_ADD_T4_REG64(pi, "tx_frames", "total # of good frames",
6237 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_FRAMES_L));
6238 SYSCTL_ADD_T4_REG64(pi, "tx_bcast_frames", "# of broadcast frames",
6239 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BCAST_L));
6240 SYSCTL_ADD_T4_REG64(pi, "tx_mcast_frames", "# of multicast frames",
6241 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_MCAST_L));
6242 SYSCTL_ADD_T4_REG64(pi, "tx_ucast_frames", "# of unicast frames",
6243 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_UCAST_L));
6244 SYSCTL_ADD_T4_REG64(pi, "tx_error_frames", "# of error frames",
6245 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_ERROR_L));
6246 SYSCTL_ADD_T4_REG64(pi, "tx_frames_64",
6247 "# of tx frames in this range",
6248 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_64B_L));
6249 SYSCTL_ADD_T4_REG64(pi, "tx_frames_65_127",
6250 "# of tx frames in this range",
6251 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_65B_127B_L));
6252 SYSCTL_ADD_T4_REG64(pi, "tx_frames_128_255",
6253 "# of tx frames in this range",
6254 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_128B_255B_L));
6255 SYSCTL_ADD_T4_REG64(pi, "tx_frames_256_511",
6256 "# of tx frames in this range",
6257 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_256B_511B_L));
6258 SYSCTL_ADD_T4_REG64(pi, "tx_frames_512_1023",
6259 "# of tx frames in this range",
6260 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_512B_1023B_L));
6261 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1024_1518",
6262 "# of tx frames in this range",
6263 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1024B_1518B_L));
6264 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1519_max",
6265 "# of tx frames in this range",
6266 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1519B_MAX_L));
6267 SYSCTL_ADD_T4_REG64(pi, "tx_drop", "# of dropped tx frames",
6268 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_DROP_L));
6269 SYSCTL_ADD_T4_REG64(pi, "tx_pause", "# of pause frames transmitted",
6270 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PAUSE_L));
6271 SYSCTL_ADD_T4_REG64(pi, "tx_ppp0", "# of PPP prio 0 frames transmitted",
6272 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP0_L));
6273 SYSCTL_ADD_T4_REG64(pi, "tx_ppp1", "# of PPP prio 1 frames transmitted",
6274 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP1_L));
6275 SYSCTL_ADD_T4_REG64(pi, "tx_ppp2", "# of PPP prio 2 frames transmitted",
6276 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP2_L));
6277 SYSCTL_ADD_T4_REG64(pi, "tx_ppp3", "# of PPP prio 3 frames transmitted",
6278 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP3_L));
6279 SYSCTL_ADD_T4_REG64(pi, "tx_ppp4", "# of PPP prio 4 frames transmitted",
6280 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP4_L));
6281 SYSCTL_ADD_T4_REG64(pi, "tx_ppp5", "# of PPP prio 5 frames transmitted",
6282 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP5_L));
6283 SYSCTL_ADD_T4_REG64(pi, "tx_ppp6", "# of PPP prio 6 frames transmitted",
6284 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP6_L));
6285 SYSCTL_ADD_T4_REG64(pi, "tx_ppp7", "# of PPP prio 7 frames transmitted",
6286 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP7_L));
6288 SYSCTL_ADD_T4_REG64(pi, "rx_octets", "# of octets in good frames",
6289 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BYTES_L));
6290 SYSCTL_ADD_T4_REG64(pi, "rx_frames", "total # of good frames",
6291 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_FRAMES_L));
6292 SYSCTL_ADD_T4_REG64(pi, "rx_bcast_frames", "# of broadcast frames",
6293 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BCAST_L));
6294 SYSCTL_ADD_T4_REG64(pi, "rx_mcast_frames", "# of multicast frames",
6295 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MCAST_L));
6296 SYSCTL_ADD_T4_REG64(pi, "rx_ucast_frames", "# of unicast frames",
6297 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_UCAST_L));
6298 SYSCTL_ADD_T4_REG64(pi, "rx_too_long", "# of frames exceeding MTU",
6299 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_ERROR_L));
6300 SYSCTL_ADD_T4_REG64(pi, "rx_jabber", "# of jabber frames",
6301 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_CRC_ERROR_L));
6302 SYSCTL_ADD_T4_REG64(pi, "rx_fcs_err",
6303 "# of frames received with bad FCS",
6304 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_CRC_ERROR_L));
6305 SYSCTL_ADD_T4_REG64(pi, "rx_len_err",
6306 "# of frames received with length error",
6307 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LEN_ERROR_L));
6308 SYSCTL_ADD_T4_REG64(pi, "rx_symbol_err", "symbol errors",
6309 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_SYM_ERROR_L));
6310 SYSCTL_ADD_T4_REG64(pi, "rx_runt", "# of short frames received",
6311 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LESS_64B_L));
6312 SYSCTL_ADD_T4_REG64(pi, "rx_frames_64",
6313 "# of rx frames in this range",
6314 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_64B_L));
6315 SYSCTL_ADD_T4_REG64(pi, "rx_frames_65_127",
6316 "# of rx frames in this range",
6317 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_65B_127B_L));
6318 SYSCTL_ADD_T4_REG64(pi, "rx_frames_128_255",
6319 "# of rx frames in this range",
6320 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_128B_255B_L));
6321 SYSCTL_ADD_T4_REG64(pi, "rx_frames_256_511",
6322 "# of rx frames in this range",
6323 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_256B_511B_L));
6324 SYSCTL_ADD_T4_REG64(pi, "rx_frames_512_1023",
6325 "# of rx frames in this range",
6326 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_512B_1023B_L));
6327 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1024_1518",
6328 "# of rx frames in this range",
6329 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1024B_1518B_L));
6330 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1519_max",
6331 "# of rx frames in this range",
6332 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1519B_MAX_L));
6333 SYSCTL_ADD_T4_REG64(pi, "rx_pause", "# of pause frames received",
6334 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PAUSE_L));
6335 SYSCTL_ADD_T4_REG64(pi, "rx_ppp0", "# of PPP prio 0 frames received",
6336 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP0_L));
6337 SYSCTL_ADD_T4_REG64(pi, "rx_ppp1", "# of PPP prio 1 frames received",
6338 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP1_L));
6339 SYSCTL_ADD_T4_REG64(pi, "rx_ppp2", "# of PPP prio 2 frames received",
6340 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP2_L));
6341 SYSCTL_ADD_T4_REG64(pi, "rx_ppp3", "# of PPP prio 3 frames received",
6342 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP3_L));
6343 SYSCTL_ADD_T4_REG64(pi, "rx_ppp4", "# of PPP prio 4 frames received",
6344 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP4_L));
6345 SYSCTL_ADD_T4_REG64(pi, "rx_ppp5", "# of PPP prio 5 frames received",
6346 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP5_L));
6347 SYSCTL_ADD_T4_REG64(pi, "rx_ppp6", "# of PPP prio 6 frames received",
6348 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP6_L));
6349 SYSCTL_ADD_T4_REG64(pi, "rx_ppp7", "# of PPP prio 7 frames received",
6350 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP7_L));
6352 #undef SYSCTL_ADD_T4_REG64
6354 #define SYSCTL_ADD_T4_PORTSTAT(name, desc) \
6355 SYSCTL_ADD_UQUAD(ctx, children, OID_AUTO, #name, CTLFLAG_RD, \
6356 &pi->stats.name, desc)
6358 /* We get these from port_stats and they may be stale by up to 1s */
6359 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow0,
6360 "# drops due to buffer-group 0 overflows");
6361 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow1,
6362 "# drops due to buffer-group 1 overflows");
6363 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow2,
6364 "# drops due to buffer-group 2 overflows");
6365 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow3,
6366 "# drops due to buffer-group 3 overflows");
6367 SYSCTL_ADD_T4_PORTSTAT(rx_trunc0,
6368 "# of buffer-group 0 truncated packets");
6369 SYSCTL_ADD_T4_PORTSTAT(rx_trunc1,
6370 "# of buffer-group 1 truncated packets");
6371 SYSCTL_ADD_T4_PORTSTAT(rx_trunc2,
6372 "# of buffer-group 2 truncated packets");
6373 SYSCTL_ADD_T4_PORTSTAT(rx_trunc3,
6374 "# of buffer-group 3 truncated packets");
6376 #undef SYSCTL_ADD_T4_PORTSTAT
6378 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "tx_tls_records",
6379 CTLFLAG_RD, &pi->tx_tls_records,
6380 "# of TLS records transmitted");
6381 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "tx_tls_octets",
6382 CTLFLAG_RD, &pi->tx_tls_octets,
6383 "# of payload octets in transmitted TLS records");
6384 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "rx_tls_records",
6385 CTLFLAG_RD, &pi->rx_tls_records,
6386 "# of TLS records received");
6387 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "rx_tls_octets",
6388 CTLFLAG_RD, &pi->rx_tls_octets,
6389 "# of payload octets in received TLS records");
6393 sysctl_int_array(SYSCTL_HANDLER_ARGS)
6395 int rc, *i, space = 0;
6398 sbuf_new_for_sysctl(&sb, NULL, 64, req);
6399 for (i = arg1; arg2; arg2 -= sizeof(int), i++) {
6401 sbuf_printf(&sb, " ");
6402 sbuf_printf(&sb, "%d", *i);
6405 rc = sbuf_finish(&sb);
6411 sysctl_bitfield_8b(SYSCTL_HANDLER_ARGS)
6416 rc = sysctl_wire_old_buffer(req, 0);
6420 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
6424 sbuf_printf(sb, "%b", *(uint8_t *)(uintptr_t)arg2, (char *)arg1);
6425 rc = sbuf_finish(sb);
6432 sysctl_bitfield_16b(SYSCTL_HANDLER_ARGS)
6437 rc = sysctl_wire_old_buffer(req, 0);
6441 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
6445 sbuf_printf(sb, "%b", *(uint16_t *)(uintptr_t)arg2, (char *)arg1);
6446 rc = sbuf_finish(sb);
6453 sysctl_btphy(SYSCTL_HANDLER_ARGS)
6455 struct port_info *pi = arg1;
6457 struct adapter *sc = pi->adapter;
6461 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK, "t4btt");
6464 /* XXX: magic numbers */
6465 rc = -t4_mdio_rd(sc, sc->mbox, pi->mdio_addr, 0x1e, op ? 0x20 : 0xc820,
6467 end_synchronized_op(sc, 0);
6473 rc = sysctl_handle_int(oidp, &v, 0, req);
6478 sysctl_noflowq(SYSCTL_HANDLER_ARGS)
6480 struct vi_info *vi = arg1;
6483 val = vi->rsrv_noflowq;
6484 rc = sysctl_handle_int(oidp, &val, 0, req);
6485 if (rc != 0 || req->newptr == NULL)
6488 if ((val >= 1) && (vi->ntxq > 1))
6489 vi->rsrv_noflowq = 1;
6491 vi->rsrv_noflowq = 0;
6497 sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS)
6499 struct vi_info *vi = arg1;
6500 struct adapter *sc = vi->pi->adapter;
6502 struct sge_rxq *rxq;
6507 rc = sysctl_handle_int(oidp, &idx, 0, req);
6508 if (rc != 0 || req->newptr == NULL)
6511 if (idx < 0 || idx >= SGE_NTIMERS)
6514 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
6519 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(vi->pktc_idx != -1);
6520 for_each_rxq(vi, i, rxq) {
6521 #ifdef atomic_store_rel_8
6522 atomic_store_rel_8(&rxq->iq.intr_params, v);
6524 rxq->iq.intr_params = v;
6529 end_synchronized_op(sc, LOCK_HELD);
6534 sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS)
6536 struct vi_info *vi = arg1;
6537 struct adapter *sc = vi->pi->adapter;
6542 rc = sysctl_handle_int(oidp, &idx, 0, req);
6543 if (rc != 0 || req->newptr == NULL)
6546 if (idx < -1 || idx >= SGE_NCOUNTERS)
6549 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
6554 if (vi->flags & VI_INIT_DONE)
6555 rc = EBUSY; /* cannot be changed once the queues are created */
6559 end_synchronized_op(sc, LOCK_HELD);
6564 sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS)
6566 struct vi_info *vi = arg1;
6567 struct adapter *sc = vi->pi->adapter;
6570 qsize = vi->qsize_rxq;
6572 rc = sysctl_handle_int(oidp, &qsize, 0, req);
6573 if (rc != 0 || req->newptr == NULL)
6576 if (qsize < 128 || (qsize & 7))
6579 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
6584 if (vi->flags & VI_INIT_DONE)
6585 rc = EBUSY; /* cannot be changed once the queues are created */
6587 vi->qsize_rxq = qsize;
6589 end_synchronized_op(sc, LOCK_HELD);
6594 sysctl_qsize_txq(SYSCTL_HANDLER_ARGS)
6596 struct vi_info *vi = arg1;
6597 struct adapter *sc = vi->pi->adapter;
6600 qsize = vi->qsize_txq;
6602 rc = sysctl_handle_int(oidp, &qsize, 0, req);
6603 if (rc != 0 || req->newptr == NULL)
6606 if (qsize < 128 || qsize > 65536)
6609 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
6614 if (vi->flags & VI_INIT_DONE)
6615 rc = EBUSY; /* cannot be changed once the queues are created */
6617 vi->qsize_txq = qsize;
6619 end_synchronized_op(sc, LOCK_HELD);
6624 sysctl_pause_settings(SYSCTL_HANDLER_ARGS)
6626 struct port_info *pi = arg1;
6627 struct adapter *sc = pi->adapter;
6628 struct link_config *lc = &pi->link_cfg;
6631 if (req->newptr == NULL) {
6633 static char *bits = "\20\1RX\2TX\3AUTO";
6635 rc = sysctl_wire_old_buffer(req, 0);
6639 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
6644 sbuf_printf(sb, "%b", (lc->fc & (PAUSE_TX | PAUSE_RX)) |
6645 (lc->requested_fc & PAUSE_AUTONEG), bits);
6647 sbuf_printf(sb, "%b", lc->requested_fc & (PAUSE_TX |
6648 PAUSE_RX | PAUSE_AUTONEG), bits);
6650 rc = sbuf_finish(sb);
6656 s[0] = '0' + (lc->requested_fc & (PAUSE_TX | PAUSE_RX |
6660 rc = sysctl_handle_string(oidp, s, sizeof(s), req);
6666 if (s[0] < '0' || s[0] > '9')
6667 return (EINVAL); /* not a number */
6669 if (n & ~(PAUSE_TX | PAUSE_RX | PAUSE_AUTONEG))
6670 return (EINVAL); /* some other bit is set too */
6672 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK,
6677 lc->requested_fc = n;
6678 fixup_link_config(pi);
6680 rc = apply_link_config(pi);
6681 set_current_media(pi);
6683 end_synchronized_op(sc, 0);
6690 sysctl_fec(SYSCTL_HANDLER_ARGS)
6692 struct port_info *pi = arg1;
6693 struct adapter *sc = pi->adapter;
6694 struct link_config *lc = &pi->link_cfg;
6698 if (req->newptr == NULL) {
6700 static char *bits = "\20\1RS\2BASE-R\3RSVD1\4RSVD2\5RSVD3\6AUTO";
6702 rc = sysctl_wire_old_buffer(req, 0);
6706 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
6711 * Display the requested_fec when the link is down -- the actual
6712 * FEC makes sense only when the link is up.
6715 sbuf_printf(sb, "%b", (lc->fec & M_FW_PORT_CAP32_FEC) |
6716 (lc->requested_fec & FEC_AUTO), bits);
6718 sbuf_printf(sb, "%b", lc->requested_fec, bits);
6720 rc = sbuf_finish(sb);
6726 snprintf(s, sizeof(s), "%d",
6727 lc->requested_fec == FEC_AUTO ? -1 :
6728 lc->requested_fec & M_FW_PORT_CAP32_FEC);
6730 rc = sysctl_handle_string(oidp, s, sizeof(s), req);
6734 n = strtol(&s[0], NULL, 0);
6735 if (n < 0 || n & FEC_AUTO)
6738 if (n & ~M_FW_PORT_CAP32_FEC)
6739 return (EINVAL);/* some other bit is set too */
6741 return (EINVAL);/* one bit can be set at most */
6744 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK,
6749 old = lc->requested_fec;
6751 lc->requested_fec = FEC_AUTO;
6753 lc->requested_fec = FEC_NONE;
6755 if ((lc->supported | V_FW_PORT_CAP32_FEC(n)) !=
6760 lc->requested_fec = n;
6762 fixup_link_config(pi);
6763 if (pi->up_vis > 0) {
6764 rc = apply_link_config(pi);
6766 lc->requested_fec = old;
6767 if (rc == FW_EPROTO)
6773 end_synchronized_op(sc, 0);
6780 sysctl_autoneg(SYSCTL_HANDLER_ARGS)
6782 struct port_info *pi = arg1;
6783 struct adapter *sc = pi->adapter;
6784 struct link_config *lc = &pi->link_cfg;
6787 if (lc->supported & FW_PORT_CAP32_ANEG)
6788 val = lc->requested_aneg == AUTONEG_DISABLE ? 0 : 1;
6791 rc = sysctl_handle_int(oidp, &val, 0, req);
6792 if (rc != 0 || req->newptr == NULL)
6795 val = AUTONEG_DISABLE;
6797 val = AUTONEG_ENABLE;
6801 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK,
6806 if (val == AUTONEG_ENABLE && !(lc->supported & FW_PORT_CAP32_ANEG)) {
6810 lc->requested_aneg = val;
6811 fixup_link_config(pi);
6813 rc = apply_link_config(pi);
6814 set_current_media(pi);
6817 end_synchronized_op(sc, 0);
6822 sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS)
6824 struct adapter *sc = arg1;
6828 val = t4_read_reg64(sc, reg);
6830 return (sysctl_handle_64(oidp, &val, 0, req));
6834 sysctl_temperature(SYSCTL_HANDLER_ARGS)
6836 struct adapter *sc = arg1;
6838 uint32_t param, val;
6840 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4temp");
6843 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
6844 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) |
6845 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_TMP);
6846 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
6847 end_synchronized_op(sc, 0);
6851 /* unknown is returned as 0 but we display -1 in that case */
6852 t = val == 0 ? -1 : val;
6854 rc = sysctl_handle_int(oidp, &t, 0, req);
6859 sysctl_loadavg(SYSCTL_HANDLER_ARGS)
6861 struct adapter *sc = arg1;
6864 uint32_t param, val;
6866 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4lavg");
6869 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
6870 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_LOAD);
6871 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
6872 end_synchronized_op(sc, 0);
6876 rc = sysctl_wire_old_buffer(req, 0);
6880 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6884 if (val == 0xffffffff) {
6885 /* Only debug and custom firmwares report load averages. */
6886 sbuf_printf(sb, "not available");
6888 sbuf_printf(sb, "%d %d %d", val & 0xff, (val >> 8) & 0xff,
6889 (val >> 16) & 0xff);
6891 rc = sbuf_finish(sb);
6898 sysctl_cctrl(SYSCTL_HANDLER_ARGS)
6900 struct adapter *sc = arg1;
6903 uint16_t incr[NMTUS][NCCTRL_WIN];
6904 static const char *dec_fac[] = {
6905 "0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
6909 rc = sysctl_wire_old_buffer(req, 0);
6913 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6917 t4_read_cong_tbl(sc, incr);
6919 for (i = 0; i < NCCTRL_WIN; ++i) {
6920 sbuf_printf(sb, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
6921 incr[0][i], incr[1][i], incr[2][i], incr[3][i], incr[4][i],
6922 incr[5][i], incr[6][i], incr[7][i]);
6923 sbuf_printf(sb, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
6924 incr[8][i], incr[9][i], incr[10][i], incr[11][i],
6925 incr[12][i], incr[13][i], incr[14][i], incr[15][i],
6926 sc->params.a_wnd[i], dec_fac[sc->params.b_wnd[i]]);
6929 rc = sbuf_finish(sb);
6935 static const char *qname[CIM_NUM_IBQ + CIM_NUM_OBQ_T5] = {
6936 "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI", /* ibq's */
6937 "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI", /* obq's */
6938 "SGE0-RX", "SGE1-RX" /* additional obq's (T5 onwards) */
6942 sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS)
6944 struct adapter *sc = arg1;
6946 int rc, i, n, qid = arg2;
6949 u_int cim_num_obq = sc->chip_params->cim_num_obq;
6951 KASSERT(qid >= 0 && qid < CIM_NUM_IBQ + cim_num_obq,
6952 ("%s: bad qid %d\n", __func__, qid));
6954 if (qid < CIM_NUM_IBQ) {
6957 n = 4 * CIM_IBQ_SIZE;
6958 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
6959 rc = t4_read_cim_ibq(sc, qid, buf, n);
6961 /* outbound queue */
6964 n = 4 * cim_num_obq * CIM_OBQ_SIZE;
6965 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
6966 rc = t4_read_cim_obq(sc, qid, buf, n);
6973 n = rc * sizeof(uint32_t); /* rc has # of words actually read */
6975 rc = sysctl_wire_old_buffer(req, 0);
6979 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
6985 sbuf_printf(sb, "%s%d %s", qtype , qid, qname[arg2]);
6986 for (i = 0, p = buf; i < n; i += 16, p += 4)
6987 sbuf_printf(sb, "\n%#06x: %08x %08x %08x %08x", i, p[0], p[1],
6990 rc = sbuf_finish(sb);
6998 sysctl_cim_la(SYSCTL_HANDLER_ARGS)
7000 struct adapter *sc = arg1;
7006 MPASS(chip_id(sc) <= CHELSIO_T5);
7008 rc = -t4_cim_read(sc, A_UP_UP_DBG_LA_CFG, 1, &cfg);
7012 rc = sysctl_wire_old_buffer(req, 0);
7016 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7020 buf = malloc(sc->params.cim_la_size * sizeof(uint32_t), M_CXGBE,
7023 rc = -t4_cim_read_la(sc, buf, NULL);
7027 sbuf_printf(sb, "Status Data PC%s",
7028 cfg & F_UPDBGLACAPTPCONLY ? "" :
7029 " LS0Stat LS0Addr LS0Data");
7031 for (p = buf; p <= &buf[sc->params.cim_la_size - 8]; p += 8) {
7032 if (cfg & F_UPDBGLACAPTPCONLY) {
7033 sbuf_printf(sb, "\n %02x %08x %08x", p[5] & 0xff,
7035 sbuf_printf(sb, "\n %02x %02x%06x %02x%06x",
7036 (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8,
7037 p[4] & 0xff, p[5] >> 8);
7038 sbuf_printf(sb, "\n %02x %x%07x %x%07x",
7039 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
7040 p[1] & 0xf, p[2] >> 4);
7043 "\n %02x %x%07x %x%07x %08x %08x "
7045 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
7046 p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5],
7051 rc = sbuf_finish(sb);
7059 sysctl_cim_la_t6(SYSCTL_HANDLER_ARGS)
7061 struct adapter *sc = arg1;
7067 MPASS(chip_id(sc) > CHELSIO_T5);
7069 rc = -t4_cim_read(sc, A_UP_UP_DBG_LA_CFG, 1, &cfg);
7073 rc = sysctl_wire_old_buffer(req, 0);
7077 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7081 buf = malloc(sc->params.cim_la_size * sizeof(uint32_t), M_CXGBE,
7084 rc = -t4_cim_read_la(sc, buf, NULL);
7088 sbuf_printf(sb, "Status Inst Data PC%s",
7089 cfg & F_UPDBGLACAPTPCONLY ? "" :
7090 " LS0Stat LS0Addr LS0Data LS1Stat LS1Addr LS1Data");
7092 for (p = buf; p <= &buf[sc->params.cim_la_size - 10]; p += 10) {
7093 if (cfg & F_UPDBGLACAPTPCONLY) {
7094 sbuf_printf(sb, "\n %02x %08x %08x %08x",
7095 p[3] & 0xff, p[2], p[1], p[0]);
7096 sbuf_printf(sb, "\n %02x %02x%06x %02x%06x %02x%06x",
7097 (p[6] >> 8) & 0xff, p[6] & 0xff, p[5] >> 8,
7098 p[5] & 0xff, p[4] >> 8, p[4] & 0xff, p[3] >> 8);
7099 sbuf_printf(sb, "\n %02x %04x%04x %04x%04x %04x%04x",
7100 (p[9] >> 16) & 0xff, p[9] & 0xffff, p[8] >> 16,
7101 p[8] & 0xffff, p[7] >> 16, p[7] & 0xffff,
7104 sbuf_printf(sb, "\n %02x %04x%04x %04x%04x %04x%04x "
7105 "%08x %08x %08x %08x %08x %08x",
7106 (p[9] >> 16) & 0xff,
7107 p[9] & 0xffff, p[8] >> 16,
7108 p[8] & 0xffff, p[7] >> 16,
7109 p[7] & 0xffff, p[6] >> 16,
7110 p[2], p[1], p[0], p[5], p[4], p[3]);
7114 rc = sbuf_finish(sb);
7122 sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS)
7124 struct adapter *sc = arg1;
7130 rc = sysctl_wire_old_buffer(req, 0);
7134 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7138 buf = malloc(2 * CIM_MALA_SIZE * 5 * sizeof(uint32_t), M_CXGBE,
7141 t4_cim_read_ma_la(sc, buf, buf + 5 * CIM_MALA_SIZE);
7144 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
7145 sbuf_printf(sb, "\n%02x%08x%08x%08x%08x", p[4], p[3], p[2],
7149 sbuf_printf(sb, "\n\nCnt ID Tag UE Data RDY VLD");
7150 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
7151 sbuf_printf(sb, "\n%3u %2u %x %u %08x%08x %u %u",
7152 (p[2] >> 10) & 0xff, (p[2] >> 7) & 7,
7153 (p[2] >> 3) & 0xf, (p[2] >> 2) & 1,
7154 (p[1] >> 2) | ((p[2] & 3) << 30),
7155 (p[0] >> 2) | ((p[1] & 3) << 30), (p[0] >> 1) & 1,
7159 rc = sbuf_finish(sb);
7166 sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS)
7168 struct adapter *sc = arg1;
7174 rc = sysctl_wire_old_buffer(req, 0);
7178 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7182 buf = malloc(2 * CIM_PIFLA_SIZE * 6 * sizeof(uint32_t), M_CXGBE,
7185 t4_cim_read_pif_la(sc, buf, buf + 6 * CIM_PIFLA_SIZE, NULL, NULL);
7188 sbuf_printf(sb, "Cntl ID DataBE Addr Data");
7189 for (i = 0; i < CIM_PIFLA_SIZE; i++, p += 6) {
7190 sbuf_printf(sb, "\n %02x %02x %04x %08x %08x%08x%08x%08x",
7191 (p[5] >> 22) & 0xff, (p[5] >> 16) & 0x3f, p[5] & 0xffff,
7192 p[4], p[3], p[2], p[1], p[0]);
7195 sbuf_printf(sb, "\n\nCntl ID Data");
7196 for (i = 0; i < CIM_PIFLA_SIZE; i++, p += 6) {
7197 sbuf_printf(sb, "\n %02x %02x %08x%08x%08x%08x",
7198 (p[4] >> 6) & 0xff, p[4] & 0x3f, p[3], p[2], p[1], p[0]);
7201 rc = sbuf_finish(sb);
7208 sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS)
7210 struct adapter *sc = arg1;
7213 uint16_t base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
7214 uint16_t size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
7215 uint16_t thres[CIM_NUM_IBQ];
7216 uint32_t obq_wr[2 * CIM_NUM_OBQ_T5], *wr = obq_wr;
7217 uint32_t stat[4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5)], *p = stat;
7218 u_int cim_num_obq, ibq_rdaddr, obq_rdaddr, nq;
7220 cim_num_obq = sc->chip_params->cim_num_obq;
7222 ibq_rdaddr = A_UP_IBQ_0_RDADDR;
7223 obq_rdaddr = A_UP_OBQ_0_REALADDR;
7225 ibq_rdaddr = A_UP_IBQ_0_SHADOW_RDADDR;
7226 obq_rdaddr = A_UP_OBQ_0_SHADOW_REALADDR;
7228 nq = CIM_NUM_IBQ + cim_num_obq;
7230 rc = -t4_cim_read(sc, ibq_rdaddr, 4 * nq, stat);
7232 rc = -t4_cim_read(sc, obq_rdaddr, 2 * cim_num_obq, obq_wr);
7236 t4_read_cimq_cfg(sc, base, size, thres);
7238 rc = sysctl_wire_old_buffer(req, 0);
7242 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
7247 " Queue Base Size Thres RdPtr WrPtr SOP EOP Avail");
7249 for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
7250 sbuf_printf(sb, "\n%7s %5x %5u %5u %6x %4x %4u %4u %5u",
7251 qname[i], base[i], size[i], thres[i], G_IBQRDADDR(p[0]),
7252 G_IBQWRADDR(p[1]), G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
7253 G_QUEREMFLITS(p[2]) * 16);
7254 for ( ; i < nq; i++, p += 4, wr += 2)
7255 sbuf_printf(sb, "\n%7s %5x %5u %12x %4x %4u %4u %5u", qname[i],
7256 base[i], size[i], G_QUERDADDR(p[0]) & 0x3fff,
7257 wr[0] - base[i], G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
7258 G_QUEREMFLITS(p[2]) * 16);
7260 rc = sbuf_finish(sb);
7267 sysctl_cpl_stats(SYSCTL_HANDLER_ARGS)
7269 struct adapter *sc = arg1;
7272 struct tp_cpl_stats stats;
7274 rc = sysctl_wire_old_buffer(req, 0);
7278 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7282 mtx_lock(&sc->reg_lock);
7283 t4_tp_get_cpl_stats(sc, &stats, 0);
7284 mtx_unlock(&sc->reg_lock);
7286 if (sc->chip_params->nchan > 2) {
7287 sbuf_printf(sb, " channel 0 channel 1"
7288 " channel 2 channel 3");
7289 sbuf_printf(sb, "\nCPL requests: %10u %10u %10u %10u",
7290 stats.req[0], stats.req[1], stats.req[2], stats.req[3]);
7291 sbuf_printf(sb, "\nCPL responses: %10u %10u %10u %10u",
7292 stats.rsp[0], stats.rsp[1], stats.rsp[2], stats.rsp[3]);
7294 sbuf_printf(sb, " channel 0 channel 1");
7295 sbuf_printf(sb, "\nCPL requests: %10u %10u",
7296 stats.req[0], stats.req[1]);
7297 sbuf_printf(sb, "\nCPL responses: %10u %10u",
7298 stats.rsp[0], stats.rsp[1]);
7301 rc = sbuf_finish(sb);
7308 sysctl_ddp_stats(SYSCTL_HANDLER_ARGS)
7310 struct adapter *sc = arg1;
7313 struct tp_usm_stats stats;
7315 rc = sysctl_wire_old_buffer(req, 0);
7319 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7323 t4_get_usm_stats(sc, &stats, 1);
7325 sbuf_printf(sb, "Frames: %u\n", stats.frames);
7326 sbuf_printf(sb, "Octets: %ju\n", stats.octets);
7327 sbuf_printf(sb, "Drops: %u", stats.drops);
7329 rc = sbuf_finish(sb);
7335 static const char * const devlog_level_strings[] = {
7336 [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
7337 [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
7338 [FW_DEVLOG_LEVEL_ERR] = "ERR",
7339 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
7340 [FW_DEVLOG_LEVEL_INFO] = "INFO",
7341 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
7344 static const char * const devlog_facility_strings[] = {
7345 [FW_DEVLOG_FACILITY_CORE] = "CORE",
7346 [FW_DEVLOG_FACILITY_CF] = "CF",
7347 [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
7348 [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
7349 [FW_DEVLOG_FACILITY_RES] = "RES",
7350 [FW_DEVLOG_FACILITY_HW] = "HW",
7351 [FW_DEVLOG_FACILITY_FLR] = "FLR",
7352 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
7353 [FW_DEVLOG_FACILITY_PHY] = "PHY",
7354 [FW_DEVLOG_FACILITY_MAC] = "MAC",
7355 [FW_DEVLOG_FACILITY_PORT] = "PORT",
7356 [FW_DEVLOG_FACILITY_VI] = "VI",
7357 [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
7358 [FW_DEVLOG_FACILITY_ACL] = "ACL",
7359 [FW_DEVLOG_FACILITY_TM] = "TM",
7360 [FW_DEVLOG_FACILITY_QFC] = "QFC",
7361 [FW_DEVLOG_FACILITY_DCB] = "DCB",
7362 [FW_DEVLOG_FACILITY_ETH] = "ETH",
7363 [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
7364 [FW_DEVLOG_FACILITY_RI] = "RI",
7365 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
7366 [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
7367 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
7368 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE",
7369 [FW_DEVLOG_FACILITY_CHNET] = "CHNET",
7373 sysctl_devlog(SYSCTL_HANDLER_ARGS)
7375 struct adapter *sc = arg1;
7376 struct devlog_params *dparams = &sc->params.devlog;
7377 struct fw_devlog_e *buf, *e;
7378 int i, j, rc, nentries, first = 0;
7380 uint64_t ftstamp = UINT64_MAX;
7382 if (dparams->addr == 0)
7385 buf = malloc(dparams->size, M_CXGBE, M_NOWAIT);
7389 rc = read_via_memwin(sc, 1, dparams->addr, (void *)buf, dparams->size);
7393 nentries = dparams->size / sizeof(struct fw_devlog_e);
7394 for (i = 0; i < nentries; i++) {
7397 if (e->timestamp == 0)
7400 e->timestamp = be64toh(e->timestamp);
7401 e->seqno = be32toh(e->seqno);
7402 for (j = 0; j < 8; j++)
7403 e->params[j] = be32toh(e->params[j]);
7405 if (e->timestamp < ftstamp) {
7406 ftstamp = e->timestamp;
7411 if (buf[first].timestamp == 0)
7412 goto done; /* nothing in the log */
7414 rc = sysctl_wire_old_buffer(req, 0);
7418 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7423 sbuf_printf(sb, "%10s %15s %8s %8s %s\n",
7424 "Seq#", "Tstamp", "Level", "Facility", "Message");
7429 if (e->timestamp == 0)
7432 sbuf_printf(sb, "%10d %15ju %8s %8s ",
7433 e->seqno, e->timestamp,
7434 (e->level < nitems(devlog_level_strings) ?
7435 devlog_level_strings[e->level] : "UNKNOWN"),
7436 (e->facility < nitems(devlog_facility_strings) ?
7437 devlog_facility_strings[e->facility] : "UNKNOWN"));
7438 sbuf_printf(sb, e->fmt, e->params[0], e->params[1],
7439 e->params[2], e->params[3], e->params[4],
7440 e->params[5], e->params[6], e->params[7]);
7442 if (++i == nentries)
7444 } while (i != first);
7446 rc = sbuf_finish(sb);
7454 sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS)
7456 struct adapter *sc = arg1;
7459 struct tp_fcoe_stats stats[MAX_NCHAN];
7460 int i, nchan = sc->chip_params->nchan;
7462 rc = sysctl_wire_old_buffer(req, 0);
7466 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7470 for (i = 0; i < nchan; i++)
7471 t4_get_fcoe_stats(sc, i, &stats[i], 1);
7474 sbuf_printf(sb, " channel 0 channel 1"
7475 " channel 2 channel 3");
7476 sbuf_printf(sb, "\noctetsDDP: %16ju %16ju %16ju %16ju",
7477 stats[0].octets_ddp, stats[1].octets_ddp,
7478 stats[2].octets_ddp, stats[3].octets_ddp);
7479 sbuf_printf(sb, "\nframesDDP: %16u %16u %16u %16u",
7480 stats[0].frames_ddp, stats[1].frames_ddp,
7481 stats[2].frames_ddp, stats[3].frames_ddp);
7482 sbuf_printf(sb, "\nframesDrop: %16u %16u %16u %16u",
7483 stats[0].frames_drop, stats[1].frames_drop,
7484 stats[2].frames_drop, stats[3].frames_drop);
7486 sbuf_printf(sb, " channel 0 channel 1");
7487 sbuf_printf(sb, "\noctetsDDP: %16ju %16ju",
7488 stats[0].octets_ddp, stats[1].octets_ddp);
7489 sbuf_printf(sb, "\nframesDDP: %16u %16u",
7490 stats[0].frames_ddp, stats[1].frames_ddp);
7491 sbuf_printf(sb, "\nframesDrop: %16u %16u",
7492 stats[0].frames_drop, stats[1].frames_drop);
7495 rc = sbuf_finish(sb);
7502 sysctl_hw_sched(SYSCTL_HANDLER_ARGS)
7504 struct adapter *sc = arg1;
7507 unsigned int map, kbps, ipg, mode;
7508 unsigned int pace_tab[NTX_SCHED];
7510 rc = sysctl_wire_old_buffer(req, 0);
7514 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7518 map = t4_read_reg(sc, A_TP_TX_MOD_QUEUE_REQ_MAP);
7519 mode = G_TIMERMODE(t4_read_reg(sc, A_TP_MOD_CONFIG));
7520 t4_read_pace_tbl(sc, pace_tab);
7522 sbuf_printf(sb, "Scheduler Mode Channel Rate (Kbps) "
7523 "Class IPG (0.1 ns) Flow IPG (us)");
7525 for (i = 0; i < NTX_SCHED; ++i, map >>= 2) {
7526 t4_get_tx_sched(sc, i, &kbps, &ipg, 1);
7527 sbuf_printf(sb, "\n %u %-5s %u ", i,
7528 (mode & (1 << i)) ? "flow" : "class", map & 3);
7530 sbuf_printf(sb, "%9u ", kbps);
7532 sbuf_printf(sb, " disabled ");
7535 sbuf_printf(sb, "%13u ", ipg);
7537 sbuf_printf(sb, " disabled ");
7540 sbuf_printf(sb, "%10u", pace_tab[i]);
7542 sbuf_printf(sb, " disabled");
7545 rc = sbuf_finish(sb);
7552 sysctl_lb_stats(SYSCTL_HANDLER_ARGS)
7554 struct adapter *sc = arg1;
7558 struct lb_port_stats s[2];
7559 static const char *stat_name[] = {
7560 "OctetsOK:", "FramesOK:", "BcastFrames:", "McastFrames:",
7561 "UcastFrames:", "ErrorFrames:", "Frames64:", "Frames65To127:",
7562 "Frames128To255:", "Frames256To511:", "Frames512To1023:",
7563 "Frames1024To1518:", "Frames1519ToMax:", "FramesDropped:",
7564 "BG0FramesDropped:", "BG1FramesDropped:", "BG2FramesDropped:",
7565 "BG3FramesDropped:", "BG0FramesTrunc:", "BG1FramesTrunc:",
7566 "BG2FramesTrunc:", "BG3FramesTrunc:"
7569 rc = sysctl_wire_old_buffer(req, 0);
7573 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7577 memset(s, 0, sizeof(s));
7579 for (i = 0; i < sc->chip_params->nchan; i += 2) {
7580 t4_get_lb_stats(sc, i, &s[0]);
7581 t4_get_lb_stats(sc, i + 1, &s[1]);
7585 sbuf_printf(sb, "%s Loopback %u"
7586 " Loopback %u", i == 0 ? "" : "\n", i, i + 1);
7588 for (j = 0; j < nitems(stat_name); j++)
7589 sbuf_printf(sb, "\n%-17s %20ju %20ju", stat_name[j],
7593 rc = sbuf_finish(sb);
7600 sysctl_linkdnrc(SYSCTL_HANDLER_ARGS)
7603 struct port_info *pi = arg1;
7604 struct link_config *lc = &pi->link_cfg;
7607 rc = sysctl_wire_old_buffer(req, 0);
7610 sb = sbuf_new_for_sysctl(NULL, NULL, 64, req);
7614 if (lc->link_ok || lc->link_down_rc == 255)
7615 sbuf_printf(sb, "n/a");
7617 sbuf_printf(sb, "%s", t4_link_down_rc_str(lc->link_down_rc));
7619 rc = sbuf_finish(sb);
7632 mem_desc_cmp(const void *a, const void *b)
7634 return ((const struct mem_desc *)a)->base -
7635 ((const struct mem_desc *)b)->base;
7639 mem_region_show(struct sbuf *sb, const char *name, unsigned int from,
7647 size = to - from + 1;
7651 /* XXX: need humanize_number(3) in libkern for a more readable 'size' */
7652 sbuf_printf(sb, "%-15s %#x-%#x [%u]\n", name, from, to, size);
7656 sysctl_meminfo(SYSCTL_HANDLER_ARGS)
7658 struct adapter *sc = arg1;
7661 uint32_t lo, hi, used, alloc;
7662 static const char *memory[] = {"EDC0:", "EDC1:", "MC:", "MC0:", "MC1:"};
7663 static const char *region[] = {
7664 "DBQ contexts:", "IMSG contexts:", "FLM cache:", "TCBs:",
7665 "Pstructs:", "Timers:", "Rx FL:", "Tx FL:", "Pstruct FL:",
7666 "Tx payload:", "Rx payload:", "LE hash:", "iSCSI region:",
7667 "TDDP region:", "TPT region:", "STAG region:", "RQ region:",
7668 "RQUDP region:", "PBL region:", "TXPBL region:",
7669 "DBVFIFO region:", "ULPRX state:", "ULPTX state:",
7670 "On-chip queues:", "TLS keys:",
7672 struct mem_desc avail[4];
7673 struct mem_desc mem[nitems(region) + 3]; /* up to 3 holes */
7674 struct mem_desc *md = mem;
7676 rc = sysctl_wire_old_buffer(req, 0);
7680 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7684 for (i = 0; i < nitems(mem); i++) {
7689 /* Find and sort the populated memory ranges */
7691 lo = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
7692 if (lo & F_EDRAM0_ENABLE) {
7693 hi = t4_read_reg(sc, A_MA_EDRAM0_BAR);
7694 avail[i].base = G_EDRAM0_BASE(hi) << 20;
7695 avail[i].limit = avail[i].base + (G_EDRAM0_SIZE(hi) << 20);
7699 if (lo & F_EDRAM1_ENABLE) {
7700 hi = t4_read_reg(sc, A_MA_EDRAM1_BAR);
7701 avail[i].base = G_EDRAM1_BASE(hi) << 20;
7702 avail[i].limit = avail[i].base + (G_EDRAM1_SIZE(hi) << 20);
7706 if (lo & F_EXT_MEM_ENABLE) {
7707 hi = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
7708 avail[i].base = G_EXT_MEM_BASE(hi) << 20;
7709 avail[i].limit = avail[i].base +
7710 (G_EXT_MEM_SIZE(hi) << 20);
7711 avail[i].idx = is_t5(sc) ? 3 : 2; /* Call it MC0 for T5 */
7714 if (is_t5(sc) && lo & F_EXT_MEM1_ENABLE) {
7715 hi = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
7716 avail[i].base = G_EXT_MEM1_BASE(hi) << 20;
7717 avail[i].limit = avail[i].base +
7718 (G_EXT_MEM1_SIZE(hi) << 20);
7722 if (!i) /* no memory available */
7724 qsort(avail, i, sizeof(struct mem_desc), mem_desc_cmp);
7726 (md++)->base = t4_read_reg(sc, A_SGE_DBQ_CTXT_BADDR);
7727 (md++)->base = t4_read_reg(sc, A_SGE_IMSG_CTXT_BADDR);
7728 (md++)->base = t4_read_reg(sc, A_SGE_FLM_CACHE_BADDR);
7729 (md++)->base = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
7730 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_BASE);
7731 (md++)->base = t4_read_reg(sc, A_TP_CMM_TIMER_BASE);
7732 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_RX_FLST_BASE);
7733 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_TX_FLST_BASE);
7734 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_PS_FLST_BASE);
7736 /* the next few have explicit upper bounds */
7737 md->base = t4_read_reg(sc, A_TP_PMM_TX_BASE);
7738 md->limit = md->base - 1 +
7739 t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE) *
7740 G_PMTXMAXPAGE(t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE));
7743 md->base = t4_read_reg(sc, A_TP_PMM_RX_BASE);
7744 md->limit = md->base - 1 +
7745 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) *
7746 G_PMRXMAXPAGE(t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE));
7749 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
7750 if (chip_id(sc) <= CHELSIO_T5)
7751 md->base = t4_read_reg(sc, A_LE_DB_HASH_TID_BASE);
7753 md->base = t4_read_reg(sc, A_LE_DB_HASH_TBL_BASE_ADDR);
7757 md->idx = nitems(region); /* hide it */
7761 #define ulp_region(reg) \
7762 md->base = t4_read_reg(sc, A_ULP_ ## reg ## _LLIMIT);\
7763 (md++)->limit = t4_read_reg(sc, A_ULP_ ## reg ## _ULIMIT)
7765 ulp_region(RX_ISCSI);
7766 ulp_region(RX_TDDP);
7768 ulp_region(RX_STAG);
7770 ulp_region(RX_RQUDP);
7776 md->idx = nitems(region);
7779 uint32_t sge_ctrl = t4_read_reg(sc, A_SGE_CONTROL2);
7780 uint32_t fifo_size = t4_read_reg(sc, A_SGE_DBVFIFO_SIZE);
7783 if (sge_ctrl & F_VFIFO_ENABLE)
7784 size = G_DBVFIFO_SIZE(fifo_size);
7786 size = G_T6_DBVFIFO_SIZE(fifo_size);
7789 md->base = G_BASEADDR(t4_read_reg(sc,
7790 A_SGE_DBVFIFO_BADDR));
7791 md->limit = md->base + (size << 2) - 1;
7796 md->base = t4_read_reg(sc, A_ULP_RX_CTX_BASE);
7799 md->base = t4_read_reg(sc, A_ULP_TX_ERR_TABLE_BASE);
7803 md->base = sc->vres.ocq.start;
7804 if (sc->vres.ocq.size)
7805 md->limit = md->base + sc->vres.ocq.size - 1;
7807 md->idx = nitems(region); /* hide it */
7810 md->base = sc->vres.key.start;
7811 if (sc->vres.key.size)
7812 md->limit = md->base + sc->vres.key.size - 1;
7814 md->idx = nitems(region); /* hide it */
7817 /* add any address-space holes, there can be up to 3 */
7818 for (n = 0; n < i - 1; n++)
7819 if (avail[n].limit < avail[n + 1].base)
7820 (md++)->base = avail[n].limit;
7822 (md++)->base = avail[n].limit;
7825 qsort(mem, n, sizeof(struct mem_desc), mem_desc_cmp);
7827 for (lo = 0; lo < i; lo++)
7828 mem_region_show(sb, memory[avail[lo].idx], avail[lo].base,
7829 avail[lo].limit - 1);
7831 sbuf_printf(sb, "\n");
7832 for (i = 0; i < n; i++) {
7833 if (mem[i].idx >= nitems(region))
7834 continue; /* skip holes */
7836 mem[i].limit = i < n - 1 ? mem[i + 1].base - 1 : ~0;
7837 mem_region_show(sb, region[mem[i].idx], mem[i].base,
7841 sbuf_printf(sb, "\n");
7842 lo = t4_read_reg(sc, A_CIM_SDRAM_BASE_ADDR);
7843 hi = t4_read_reg(sc, A_CIM_SDRAM_ADDR_SIZE) + lo - 1;
7844 mem_region_show(sb, "uP RAM:", lo, hi);
7846 lo = t4_read_reg(sc, A_CIM_EXTMEM2_BASE_ADDR);
7847 hi = t4_read_reg(sc, A_CIM_EXTMEM2_ADDR_SIZE) + lo - 1;
7848 mem_region_show(sb, "uP Extmem2:", lo, hi);
7850 lo = t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE);
7851 sbuf_printf(sb, "\n%u Rx pages of size %uKiB for %u channels\n",
7853 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) >> 10,
7854 (lo & F_PMRXNUMCHN) ? 2 : 1);
7856 lo = t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE);
7857 hi = t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE);
7858 sbuf_printf(sb, "%u Tx pages of size %u%ciB for %u channels\n",
7860 hi >= (1 << 20) ? (hi >> 20) : (hi >> 10),
7861 hi >= (1 << 20) ? 'M' : 'K', 1 << G_PMTXNUMCHN(lo));
7862 sbuf_printf(sb, "%u p-structs\n",
7863 t4_read_reg(sc, A_TP_CMM_MM_MAX_PSTRUCT));
7865 for (i = 0; i < 4; i++) {
7866 if (chip_id(sc) > CHELSIO_T5)
7867 lo = t4_read_reg(sc, A_MPS_RX_MAC_BG_PG_CNT0 + i * 4);
7869 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV0 + i * 4);
7871 used = G_T5_USED(lo);
7872 alloc = G_T5_ALLOC(lo);
7875 alloc = G_ALLOC(lo);
7877 /* For T6 these are MAC buffer groups */
7878 sbuf_printf(sb, "\nPort %d using %u pages out of %u allocated",
7881 for (i = 0; i < sc->chip_params->nchan; i++) {
7882 if (chip_id(sc) > CHELSIO_T5)
7883 lo = t4_read_reg(sc, A_MPS_RX_LPBK_BG_PG_CNT0 + i * 4);
7885 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV4 + i * 4);
7887 used = G_T5_USED(lo);
7888 alloc = G_T5_ALLOC(lo);
7891 alloc = G_ALLOC(lo);
7893 /* For T6 these are MAC buffer groups */
7895 "\nLoopback %d using %u pages out of %u allocated",
7899 rc = sbuf_finish(sb);
7906 tcamxy2valmask(uint64_t x, uint64_t y, uint8_t *addr, uint64_t *mask)
7910 memcpy(addr, (char *)&y + 2, ETHER_ADDR_LEN);
7914 sysctl_mps_tcam(SYSCTL_HANDLER_ARGS)
7916 struct adapter *sc = arg1;
7920 MPASS(chip_id(sc) <= CHELSIO_T5);
7922 rc = sysctl_wire_old_buffer(req, 0);
7926 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7931 "Idx Ethernet address Mask Vld Ports PF"
7932 " VF Replication P0 P1 P2 P3 ML");
7933 for (i = 0; i < sc->chip_params->mps_tcam_size; i++) {
7934 uint64_t tcamx, tcamy, mask;
7935 uint32_t cls_lo, cls_hi;
7936 uint8_t addr[ETHER_ADDR_LEN];
7938 tcamy = t4_read_reg64(sc, MPS_CLS_TCAM_Y_L(i));
7939 tcamx = t4_read_reg64(sc, MPS_CLS_TCAM_X_L(i));
7942 tcamxy2valmask(tcamx, tcamy, addr, &mask);
7943 cls_lo = t4_read_reg(sc, MPS_CLS_SRAM_L(i));
7944 cls_hi = t4_read_reg(sc, MPS_CLS_SRAM_H(i));
7945 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x %012jx"
7946 " %c %#x%4u%4d", i, addr[0], addr[1], addr[2],
7947 addr[3], addr[4], addr[5], (uintmax_t)mask,
7948 (cls_lo & F_SRAM_VLD) ? 'Y' : 'N',
7949 G_PORTMAP(cls_hi), G_PF(cls_lo),
7950 (cls_lo & F_VF_VALID) ? G_VF(cls_lo) : -1);
7952 if (cls_lo & F_REPLICATE) {
7953 struct fw_ldst_cmd ldst_cmd;
7955 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
7956 ldst_cmd.op_to_addrspace =
7957 htobe32(V_FW_CMD_OP(FW_LDST_CMD) |
7958 F_FW_CMD_REQUEST | F_FW_CMD_READ |
7959 V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MPS));
7960 ldst_cmd.cycles_to_len16 = htobe32(FW_LEN16(ldst_cmd));
7961 ldst_cmd.u.mps.rplc.fid_idx =
7962 htobe16(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) |
7963 V_FW_LDST_CMD_IDX(i));
7965 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK,
7969 rc = -t4_wr_mbox(sc, sc->mbox, &ldst_cmd,
7970 sizeof(ldst_cmd), &ldst_cmd);
7971 end_synchronized_op(sc, 0);
7974 sbuf_printf(sb, "%36d", rc);
7977 sbuf_printf(sb, " %08x %08x %08x %08x",
7978 be32toh(ldst_cmd.u.mps.rplc.rplc127_96),
7979 be32toh(ldst_cmd.u.mps.rplc.rplc95_64),
7980 be32toh(ldst_cmd.u.mps.rplc.rplc63_32),
7981 be32toh(ldst_cmd.u.mps.rplc.rplc31_0));
7984 sbuf_printf(sb, "%36s", "");
7986 sbuf_printf(sb, "%4u%3u%3u%3u %#3x", G_SRAM_PRIO0(cls_lo),
7987 G_SRAM_PRIO1(cls_lo), G_SRAM_PRIO2(cls_lo),
7988 G_SRAM_PRIO3(cls_lo), (cls_lo >> S_MULTILISTEN0) & 0xf);
7992 (void) sbuf_finish(sb);
7994 rc = sbuf_finish(sb);
8001 sysctl_mps_tcam_t6(SYSCTL_HANDLER_ARGS)
8003 struct adapter *sc = arg1;
8007 MPASS(chip_id(sc) > CHELSIO_T5);
8009 rc = sysctl_wire_old_buffer(req, 0);
8013 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8017 sbuf_printf(sb, "Idx Ethernet address Mask VNI Mask"
8018 " IVLAN Vld DIP_Hit Lookup Port Vld Ports PF VF"
8020 " P0 P1 P2 P3 ML\n");
8022 for (i = 0; i < sc->chip_params->mps_tcam_size; i++) {
8023 uint8_t dip_hit, vlan_vld, lookup_type, port_num;
8025 uint64_t tcamx, tcamy, val, mask;
8026 uint32_t cls_lo, cls_hi, ctl, data2, vnix, vniy;
8027 uint8_t addr[ETHER_ADDR_LEN];
8029 ctl = V_CTLREQID(1) | V_CTLCMDTYPE(0) | V_CTLXYBITSEL(0);
8031 ctl |= V_CTLTCAMINDEX(i) | V_CTLTCAMSEL(0);
8033 ctl |= V_CTLTCAMINDEX(i - 256) | V_CTLTCAMSEL(1);
8034 t4_write_reg(sc, A_MPS_CLS_TCAM_DATA2_CTL, ctl);
8035 val = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA1_REQ_ID1);
8036 tcamy = G_DMACH(val) << 32;
8037 tcamy |= t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA0_REQ_ID1);
8038 data2 = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA2_REQ_ID1);
8039 lookup_type = G_DATALKPTYPE(data2);
8040 port_num = G_DATAPORTNUM(data2);
8041 if (lookup_type && lookup_type != M_DATALKPTYPE) {
8042 /* Inner header VNI */
8043 vniy = ((data2 & F_DATAVIDH2) << 23) |
8044 (G_DATAVIDH1(data2) << 16) | G_VIDL(val);
8045 dip_hit = data2 & F_DATADIPHIT;
8050 vlan_vld = data2 & F_DATAVIDH2;
8051 ivlan = G_VIDL(val);
8054 ctl |= V_CTLXYBITSEL(1);
8055 t4_write_reg(sc, A_MPS_CLS_TCAM_DATA2_CTL, ctl);
8056 val = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA1_REQ_ID1);
8057 tcamx = G_DMACH(val) << 32;
8058 tcamx |= t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA0_REQ_ID1);
8059 data2 = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA2_REQ_ID1);
8060 if (lookup_type && lookup_type != M_DATALKPTYPE) {
8061 /* Inner header VNI mask */
8062 vnix = ((data2 & F_DATAVIDH2) << 23) |
8063 (G_DATAVIDH1(data2) << 16) | G_VIDL(val);
8069 tcamxy2valmask(tcamx, tcamy, addr, &mask);
8071 cls_lo = t4_read_reg(sc, MPS_CLS_SRAM_L(i));
8072 cls_hi = t4_read_reg(sc, MPS_CLS_SRAM_H(i));
8074 if (lookup_type && lookup_type != M_DATALKPTYPE) {
8075 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x "
8076 "%012jx %06x %06x - - %3c"
8077 " 'I' %4x %3c %#x%4u%4d", i, addr[0],
8078 addr[1], addr[2], addr[3], addr[4], addr[5],
8079 (uintmax_t)mask, vniy, vnix, dip_hit ? 'Y' : 'N',
8080 port_num, cls_lo & F_T6_SRAM_VLD ? 'Y' : 'N',
8081 G_PORTMAP(cls_hi), G_T6_PF(cls_lo),
8082 cls_lo & F_T6_VF_VALID ? G_T6_VF(cls_lo) : -1);
8084 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x "
8085 "%012jx - - ", i, addr[0], addr[1],
8086 addr[2], addr[3], addr[4], addr[5],
8090 sbuf_printf(sb, "%4u Y ", ivlan);
8092 sbuf_printf(sb, " - N ");
8094 sbuf_printf(sb, "- %3c %4x %3c %#x%4u%4d",
8095 lookup_type ? 'I' : 'O', port_num,
8096 cls_lo & F_T6_SRAM_VLD ? 'Y' : 'N',
8097 G_PORTMAP(cls_hi), G_T6_PF(cls_lo),
8098 cls_lo & F_T6_VF_VALID ? G_T6_VF(cls_lo) : -1);
8102 if (cls_lo & F_T6_REPLICATE) {
8103 struct fw_ldst_cmd ldst_cmd;
8105 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
8106 ldst_cmd.op_to_addrspace =
8107 htobe32(V_FW_CMD_OP(FW_LDST_CMD) |
8108 F_FW_CMD_REQUEST | F_FW_CMD_READ |
8109 V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MPS));
8110 ldst_cmd.cycles_to_len16 = htobe32(FW_LEN16(ldst_cmd));
8111 ldst_cmd.u.mps.rplc.fid_idx =
8112 htobe16(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) |
8113 V_FW_LDST_CMD_IDX(i));
8115 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK,
8119 rc = -t4_wr_mbox(sc, sc->mbox, &ldst_cmd,
8120 sizeof(ldst_cmd), &ldst_cmd);
8121 end_synchronized_op(sc, 0);
8124 sbuf_printf(sb, "%72d", rc);
8127 sbuf_printf(sb, " %08x %08x %08x %08x"
8128 " %08x %08x %08x %08x",
8129 be32toh(ldst_cmd.u.mps.rplc.rplc255_224),
8130 be32toh(ldst_cmd.u.mps.rplc.rplc223_192),
8131 be32toh(ldst_cmd.u.mps.rplc.rplc191_160),
8132 be32toh(ldst_cmd.u.mps.rplc.rplc159_128),
8133 be32toh(ldst_cmd.u.mps.rplc.rplc127_96),
8134 be32toh(ldst_cmd.u.mps.rplc.rplc95_64),
8135 be32toh(ldst_cmd.u.mps.rplc.rplc63_32),
8136 be32toh(ldst_cmd.u.mps.rplc.rplc31_0));
8139 sbuf_printf(sb, "%72s", "");
8141 sbuf_printf(sb, "%4u%3u%3u%3u %#x",
8142 G_T6_SRAM_PRIO0(cls_lo), G_T6_SRAM_PRIO1(cls_lo),
8143 G_T6_SRAM_PRIO2(cls_lo), G_T6_SRAM_PRIO3(cls_lo),
8144 (cls_lo >> S_T6_MULTILISTEN0) & 0xf);
8148 (void) sbuf_finish(sb);
8150 rc = sbuf_finish(sb);
8157 sysctl_path_mtus(SYSCTL_HANDLER_ARGS)
8159 struct adapter *sc = arg1;
8162 uint16_t mtus[NMTUS];
8164 rc = sysctl_wire_old_buffer(req, 0);
8168 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8172 t4_read_mtu_tbl(sc, mtus, NULL);
8174 sbuf_printf(sb, "%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u",
8175 mtus[0], mtus[1], mtus[2], mtus[3], mtus[4], mtus[5], mtus[6],
8176 mtus[7], mtus[8], mtus[9], mtus[10], mtus[11], mtus[12], mtus[13],
8177 mtus[14], mtus[15]);
8179 rc = sbuf_finish(sb);
8186 sysctl_pm_stats(SYSCTL_HANDLER_ARGS)
8188 struct adapter *sc = arg1;
8191 uint32_t tx_cnt[MAX_PM_NSTATS], rx_cnt[MAX_PM_NSTATS];
8192 uint64_t tx_cyc[MAX_PM_NSTATS], rx_cyc[MAX_PM_NSTATS];
8193 static const char *tx_stats[MAX_PM_NSTATS] = {
8194 "Read:", "Write bypass:", "Write mem:", "Bypass + mem:",
8195 "Tx FIFO wait", NULL, "Tx latency"
8197 static const char *rx_stats[MAX_PM_NSTATS] = {
8198 "Read:", "Write bypass:", "Write mem:", "Flush:",
8199 "Rx FIFO wait", NULL, "Rx latency"
8202 rc = sysctl_wire_old_buffer(req, 0);
8206 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8210 t4_pmtx_get_stats(sc, tx_cnt, tx_cyc);
8211 t4_pmrx_get_stats(sc, rx_cnt, rx_cyc);
8213 sbuf_printf(sb, " Tx pcmds Tx bytes");
8214 for (i = 0; i < 4; i++) {
8215 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i],
8219 sbuf_printf(sb, "\n Rx pcmds Rx bytes");
8220 for (i = 0; i < 4; i++) {
8221 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i],
8225 if (chip_id(sc) > CHELSIO_T5) {
8227 "\n Total wait Total occupancy");
8228 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i],
8230 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i],
8234 MPASS(i < nitems(tx_stats));
8237 "\n Reads Total wait");
8238 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i],
8240 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i],
8244 rc = sbuf_finish(sb);
8251 sysctl_rdma_stats(SYSCTL_HANDLER_ARGS)
8253 struct adapter *sc = arg1;
8256 struct tp_rdma_stats stats;
8258 rc = sysctl_wire_old_buffer(req, 0);
8262 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8266 mtx_lock(&sc->reg_lock);
8267 t4_tp_get_rdma_stats(sc, &stats, 0);
8268 mtx_unlock(&sc->reg_lock);
8270 sbuf_printf(sb, "NoRQEModDefferals: %u\n", stats.rqe_dfr_mod);
8271 sbuf_printf(sb, "NoRQEPktDefferals: %u", stats.rqe_dfr_pkt);
8273 rc = sbuf_finish(sb);
8280 sysctl_tcp_stats(SYSCTL_HANDLER_ARGS)
8282 struct adapter *sc = arg1;
8285 struct tp_tcp_stats v4, v6;
8287 rc = sysctl_wire_old_buffer(req, 0);
8291 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8295 mtx_lock(&sc->reg_lock);
8296 t4_tp_get_tcp_stats(sc, &v4, &v6, 0);
8297 mtx_unlock(&sc->reg_lock);
8301 sbuf_printf(sb, "OutRsts: %20u %20u\n",
8302 v4.tcp_out_rsts, v6.tcp_out_rsts);
8303 sbuf_printf(sb, "InSegs: %20ju %20ju\n",
8304 v4.tcp_in_segs, v6.tcp_in_segs);
8305 sbuf_printf(sb, "OutSegs: %20ju %20ju\n",
8306 v4.tcp_out_segs, v6.tcp_out_segs);
8307 sbuf_printf(sb, "RetransSegs: %20ju %20ju",
8308 v4.tcp_retrans_segs, v6.tcp_retrans_segs);
8310 rc = sbuf_finish(sb);
8317 sysctl_tids(SYSCTL_HANDLER_ARGS)
8319 struct adapter *sc = arg1;
8322 struct tid_info *t = &sc->tids;
8324 rc = sysctl_wire_old_buffer(req, 0);
8328 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8333 sbuf_printf(sb, "ATID range: 0-%u, in use: %u\n", t->natids - 1,
8338 sbuf_printf(sb, "HPFTID range: %u-%u, in use: %u\n",
8339 t->hpftid_base, t->hpftid_end, t->hpftids_in_use);
8343 sbuf_printf(sb, "TID range: ");
8344 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
8347 if (chip_id(sc) <= CHELSIO_T5) {
8348 b = t4_read_reg(sc, A_LE_DB_SERVER_INDEX) / 4;
8349 hb = t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4;
8351 b = t4_read_reg(sc, A_LE_DB_SRVR_START_INDEX);
8352 hb = t4_read_reg(sc, A_T6_LE_DB_HASH_TID_BASE);
8356 sbuf_printf(sb, "%u-%u, ", t->tid_base, b - 1);
8357 sbuf_printf(sb, "%u-%u", hb, t->ntids - 1);
8359 sbuf_printf(sb, "%u-%u", t->tid_base, t->ntids - 1);
8360 sbuf_printf(sb, ", in use: %u\n",
8361 atomic_load_acq_int(&t->tids_in_use));
8365 sbuf_printf(sb, "STID range: %u-%u, in use: %u\n", t->stid_base,
8366 t->stid_base + t->nstids - 1, t->stids_in_use);
8370 sbuf_printf(sb, "FTID range: %u-%u, in use: %u\n", t->ftid_base,
8371 t->ftid_end, t->ftids_in_use);
8375 sbuf_printf(sb, "ETID range: %u-%u, in use: %u\n", t->etid_base,
8376 t->etid_base + t->netids - 1, t->etids_in_use);
8379 sbuf_printf(sb, "HW TID usage: %u IP users, %u IPv6 users",
8380 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV4),
8381 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV6));
8383 rc = sbuf_finish(sb);
8390 sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS)
8392 struct adapter *sc = arg1;
8395 struct tp_err_stats stats;
8397 rc = sysctl_wire_old_buffer(req, 0);
8401 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8405 mtx_lock(&sc->reg_lock);
8406 t4_tp_get_err_stats(sc, &stats, 0);
8407 mtx_unlock(&sc->reg_lock);
8409 if (sc->chip_params->nchan > 2) {
8410 sbuf_printf(sb, " channel 0 channel 1"
8411 " channel 2 channel 3\n");
8412 sbuf_printf(sb, "macInErrs: %10u %10u %10u %10u\n",
8413 stats.mac_in_errs[0], stats.mac_in_errs[1],
8414 stats.mac_in_errs[2], stats.mac_in_errs[3]);
8415 sbuf_printf(sb, "hdrInErrs: %10u %10u %10u %10u\n",
8416 stats.hdr_in_errs[0], stats.hdr_in_errs[1],
8417 stats.hdr_in_errs[2], stats.hdr_in_errs[3]);
8418 sbuf_printf(sb, "tcpInErrs: %10u %10u %10u %10u\n",
8419 stats.tcp_in_errs[0], stats.tcp_in_errs[1],
8420 stats.tcp_in_errs[2], stats.tcp_in_errs[3]);
8421 sbuf_printf(sb, "tcp6InErrs: %10u %10u %10u %10u\n",
8422 stats.tcp6_in_errs[0], stats.tcp6_in_errs[1],
8423 stats.tcp6_in_errs[2], stats.tcp6_in_errs[3]);
8424 sbuf_printf(sb, "tnlCongDrops: %10u %10u %10u %10u\n",
8425 stats.tnl_cong_drops[0], stats.tnl_cong_drops[1],
8426 stats.tnl_cong_drops[2], stats.tnl_cong_drops[3]);
8427 sbuf_printf(sb, "tnlTxDrops: %10u %10u %10u %10u\n",
8428 stats.tnl_tx_drops[0], stats.tnl_tx_drops[1],
8429 stats.tnl_tx_drops[2], stats.tnl_tx_drops[3]);
8430 sbuf_printf(sb, "ofldVlanDrops: %10u %10u %10u %10u\n",
8431 stats.ofld_vlan_drops[0], stats.ofld_vlan_drops[1],
8432 stats.ofld_vlan_drops[2], stats.ofld_vlan_drops[3]);
8433 sbuf_printf(sb, "ofldChanDrops: %10u %10u %10u %10u\n\n",
8434 stats.ofld_chan_drops[0], stats.ofld_chan_drops[1],
8435 stats.ofld_chan_drops[2], stats.ofld_chan_drops[3]);
8437 sbuf_printf(sb, " channel 0 channel 1\n");
8438 sbuf_printf(sb, "macInErrs: %10u %10u\n",
8439 stats.mac_in_errs[0], stats.mac_in_errs[1]);
8440 sbuf_printf(sb, "hdrInErrs: %10u %10u\n",
8441 stats.hdr_in_errs[0], stats.hdr_in_errs[1]);
8442 sbuf_printf(sb, "tcpInErrs: %10u %10u\n",
8443 stats.tcp_in_errs[0], stats.tcp_in_errs[1]);
8444 sbuf_printf(sb, "tcp6InErrs: %10u %10u\n",
8445 stats.tcp6_in_errs[0], stats.tcp6_in_errs[1]);
8446 sbuf_printf(sb, "tnlCongDrops: %10u %10u\n",
8447 stats.tnl_cong_drops[0], stats.tnl_cong_drops[1]);
8448 sbuf_printf(sb, "tnlTxDrops: %10u %10u\n",
8449 stats.tnl_tx_drops[0], stats.tnl_tx_drops[1]);
8450 sbuf_printf(sb, "ofldVlanDrops: %10u %10u\n",
8451 stats.ofld_vlan_drops[0], stats.ofld_vlan_drops[1]);
8452 sbuf_printf(sb, "ofldChanDrops: %10u %10u\n\n",
8453 stats.ofld_chan_drops[0], stats.ofld_chan_drops[1]);
8456 sbuf_printf(sb, "ofldNoNeigh: %u\nofldCongDefer: %u",
8457 stats.ofld_no_neigh, stats.ofld_cong_defer);
8459 rc = sbuf_finish(sb);
8466 sysctl_tp_la_mask(SYSCTL_HANDLER_ARGS)
8468 struct adapter *sc = arg1;
8469 struct tp_params *tpp = &sc->params.tp;
8473 mask = tpp->la_mask >> 16;
8474 rc = sysctl_handle_int(oidp, &mask, 0, req);
8475 if (rc != 0 || req->newptr == NULL)
8479 tpp->la_mask = mask << 16;
8480 t4_set_reg_field(sc, A_TP_DBG_LA_CONFIG, 0xffff0000U, tpp->la_mask);
8492 field_desc_show(struct sbuf *sb, uint64_t v, const struct field_desc *f)
8498 uint64_t mask = (1ULL << f->width) - 1;
8499 int len = snprintf(buf, sizeof(buf), "%s: %ju", f->name,
8500 ((uintmax_t)v >> f->start) & mask);
8502 if (line_size + len >= 79) {
8504 sbuf_printf(sb, "\n ");
8506 sbuf_printf(sb, "%s ", buf);
8507 line_size += len + 1;
8510 sbuf_printf(sb, "\n");
8513 static const struct field_desc tp_la0[] = {
8514 { "RcfOpCodeOut", 60, 4 },
8516 { "WcfState", 52, 4 },
8517 { "RcfOpcSrcOut", 50, 2 },
8518 { "CRxError", 49, 1 },
8519 { "ERxError", 48, 1 },
8520 { "SanityFailed", 47, 1 },
8521 { "SpuriousMsg", 46, 1 },
8522 { "FlushInputMsg", 45, 1 },
8523 { "FlushInputCpl", 44, 1 },
8524 { "RssUpBit", 43, 1 },
8525 { "RssFilterHit", 42, 1 },
8527 { "InitTcb", 31, 1 },
8528 { "LineNumber", 24, 7 },
8530 { "EdataOut", 22, 1 },
8532 { "CdataOut", 20, 1 },
8533 { "EreadPdu", 19, 1 },
8534 { "CreadPdu", 18, 1 },
8535 { "TunnelPkt", 17, 1 },
8536 { "RcfPeerFin", 16, 1 },
8537 { "RcfReasonOut", 12, 4 },
8538 { "TxCchannel", 10, 2 },
8539 { "RcfTxChannel", 8, 2 },
8540 { "RxEchannel", 6, 2 },
8541 { "RcfRxChannel", 5, 1 },
8542 { "RcfDataOutSrdy", 4, 1 },
8544 { "RxOoDvld", 2, 1 },
8545 { "RxCongestion", 1, 1 },
8546 { "TxCongestion", 0, 1 },
8550 static const struct field_desc tp_la1[] = {
8551 { "CplCmdIn", 56, 8 },
8552 { "CplCmdOut", 48, 8 },
8553 { "ESynOut", 47, 1 },
8554 { "EAckOut", 46, 1 },
8555 { "EFinOut", 45, 1 },
8556 { "ERstOut", 44, 1 },
8561 { "DataIn", 39, 1 },
8562 { "DataInVld", 38, 1 },
8564 { "RxBufEmpty", 36, 1 },
8566 { "RxFbCongestion", 34, 1 },
8567 { "TxFbCongestion", 33, 1 },
8568 { "TxPktSumSrdy", 32, 1 },
8569 { "RcfUlpType", 28, 4 },
8571 { "Ebypass", 26, 1 },
8573 { "Static0", 24, 1 },
8575 { "Cbypass", 22, 1 },
8577 { "CPktOut", 20, 1 },
8578 { "RxPagePoolFull", 18, 2 },
8579 { "RxLpbkPkt", 17, 1 },
8580 { "TxLpbkPkt", 16, 1 },
8581 { "RxVfValid", 15, 1 },
8582 { "SynLearned", 14, 1 },
8583 { "SetDelEntry", 13, 1 },
8584 { "SetInvEntry", 12, 1 },
8585 { "CpcmdDvld", 11, 1 },
8586 { "CpcmdSave", 10, 1 },
8587 { "RxPstructsFull", 8, 2 },
8588 { "EpcmdDvld", 7, 1 },
8589 { "EpcmdFlush", 6, 1 },
8590 { "EpcmdTrimPrefix", 5, 1 },
8591 { "EpcmdTrimPostfix", 4, 1 },
8592 { "ERssIp4Pkt", 3, 1 },
8593 { "ERssIp6Pkt", 2, 1 },
8594 { "ERssTcpUdpPkt", 1, 1 },
8595 { "ERssFceFipPkt", 0, 1 },
8599 static const struct field_desc tp_la2[] = {
8600 { "CplCmdIn", 56, 8 },
8601 { "MpsVfVld", 55, 1 },
8608 { "DataIn", 39, 1 },
8609 { "DataInVld", 38, 1 },
8611 { "RxBufEmpty", 36, 1 },
8613 { "RxFbCongestion", 34, 1 },
8614 { "TxFbCongestion", 33, 1 },
8615 { "TxPktSumSrdy", 32, 1 },
8616 { "RcfUlpType", 28, 4 },
8618 { "Ebypass", 26, 1 },
8620 { "Static0", 24, 1 },
8622 { "Cbypass", 22, 1 },
8624 { "CPktOut", 20, 1 },
8625 { "RxPagePoolFull", 18, 2 },
8626 { "RxLpbkPkt", 17, 1 },
8627 { "TxLpbkPkt", 16, 1 },
8628 { "RxVfValid", 15, 1 },
8629 { "SynLearned", 14, 1 },
8630 { "SetDelEntry", 13, 1 },
8631 { "SetInvEntry", 12, 1 },
8632 { "CpcmdDvld", 11, 1 },
8633 { "CpcmdSave", 10, 1 },
8634 { "RxPstructsFull", 8, 2 },
8635 { "EpcmdDvld", 7, 1 },
8636 { "EpcmdFlush", 6, 1 },
8637 { "EpcmdTrimPrefix", 5, 1 },
8638 { "EpcmdTrimPostfix", 4, 1 },
8639 { "ERssIp4Pkt", 3, 1 },
8640 { "ERssIp6Pkt", 2, 1 },
8641 { "ERssTcpUdpPkt", 1, 1 },
8642 { "ERssFceFipPkt", 0, 1 },
8647 tp_la_show(struct sbuf *sb, uint64_t *p, int idx)
8650 field_desc_show(sb, *p, tp_la0);
8654 tp_la_show2(struct sbuf *sb, uint64_t *p, int idx)
8658 sbuf_printf(sb, "\n");
8659 field_desc_show(sb, p[0], tp_la0);
8660 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
8661 field_desc_show(sb, p[1], tp_la0);
8665 tp_la_show3(struct sbuf *sb, uint64_t *p, int idx)
8669 sbuf_printf(sb, "\n");
8670 field_desc_show(sb, p[0], tp_la0);
8671 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
8672 field_desc_show(sb, p[1], (p[0] & (1 << 17)) ? tp_la2 : tp_la1);
8676 sysctl_tp_la(SYSCTL_HANDLER_ARGS)
8678 struct adapter *sc = arg1;
8683 void (*show_func)(struct sbuf *, uint64_t *, int);
8685 rc = sysctl_wire_old_buffer(req, 0);
8689 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8693 buf = malloc(TPLA_SIZE * sizeof(uint64_t), M_CXGBE, M_ZERO | M_WAITOK);
8695 t4_tp_read_la(sc, buf, NULL);
8698 switch (G_DBGLAMODE(t4_read_reg(sc, A_TP_DBG_LA_CONFIG))) {
8701 show_func = tp_la_show2;
8705 show_func = tp_la_show3;
8709 show_func = tp_la_show;
8712 for (i = 0; i < TPLA_SIZE / inc; i++, p += inc)
8713 (*show_func)(sb, p, i);
8715 rc = sbuf_finish(sb);
8722 sysctl_tx_rate(SYSCTL_HANDLER_ARGS)
8724 struct adapter *sc = arg1;
8727 u64 nrate[MAX_NCHAN], orate[MAX_NCHAN];
8729 rc = sysctl_wire_old_buffer(req, 0);
8733 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8737 t4_get_chan_txrate(sc, nrate, orate);
8739 if (sc->chip_params->nchan > 2) {
8740 sbuf_printf(sb, " channel 0 channel 1"
8741 " channel 2 channel 3\n");
8742 sbuf_printf(sb, "NIC B/s: %10ju %10ju %10ju %10ju\n",
8743 nrate[0], nrate[1], nrate[2], nrate[3]);
8744 sbuf_printf(sb, "Offload B/s: %10ju %10ju %10ju %10ju",
8745 orate[0], orate[1], orate[2], orate[3]);
8747 sbuf_printf(sb, " channel 0 channel 1\n");
8748 sbuf_printf(sb, "NIC B/s: %10ju %10ju\n",
8749 nrate[0], nrate[1]);
8750 sbuf_printf(sb, "Offload B/s: %10ju %10ju",
8751 orate[0], orate[1]);
8754 rc = sbuf_finish(sb);
8761 sysctl_ulprx_la(SYSCTL_HANDLER_ARGS)
8763 struct adapter *sc = arg1;
8768 rc = sysctl_wire_old_buffer(req, 0);
8772 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8776 buf = malloc(ULPRX_LA_SIZE * 8 * sizeof(uint32_t), M_CXGBE,
8779 t4_ulprx_read_la(sc, buf);
8782 sbuf_printf(sb, " Pcmd Type Message"
8784 for (i = 0; i < ULPRX_LA_SIZE; i++, p += 8) {
8785 sbuf_printf(sb, "\n%08x%08x %4x %08x %08x%08x%08x%08x",
8786 p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
8789 rc = sbuf_finish(sb);
8796 sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS)
8798 struct adapter *sc = arg1;
8802 MPASS(chip_id(sc) >= CHELSIO_T5);
8804 rc = sysctl_wire_old_buffer(req, 0);
8808 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8812 v = t4_read_reg(sc, A_SGE_STAT_CFG);
8813 if (G_STATSOURCE_T5(v) == 7) {
8816 mode = is_t5(sc) ? G_STATMODE(v) : G_T6_STATMODE(v);
8818 sbuf_printf(sb, "total %d, incomplete %d",
8819 t4_read_reg(sc, A_SGE_STAT_TOTAL),
8820 t4_read_reg(sc, A_SGE_STAT_MATCH));
8821 } else if (mode == 1) {
8822 sbuf_printf(sb, "total %d, data overflow %d",
8823 t4_read_reg(sc, A_SGE_STAT_TOTAL),
8824 t4_read_reg(sc, A_SGE_STAT_MATCH));
8826 sbuf_printf(sb, "unknown mode %d", mode);
8829 rc = sbuf_finish(sb);
8836 sysctl_cpus(SYSCTL_HANDLER_ARGS)
8838 struct adapter *sc = arg1;
8839 enum cpu_sets op = arg2;
8844 MPASS(op == LOCAL_CPUS || op == INTR_CPUS);
8847 rc = bus_get_cpus(sc->dev, op, sizeof(cpuset), &cpuset);
8851 rc = sysctl_wire_old_buffer(req, 0);
8855 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8860 sbuf_printf(sb, "%d ", i);
8861 rc = sbuf_finish(sb);
8869 sysctl_tls_rx_ports(SYSCTL_HANDLER_ARGS)
8871 struct adapter *sc = arg1;
8872 int *old_ports, *new_ports;
8873 int i, new_count, rc;
8875 if (req->newptr == NULL && req->oldptr == NULL)
8876 return (SYSCTL_OUT(req, NULL, imax(sc->tt.num_tls_rx_ports, 1) *
8877 sizeof(sc->tt.tls_rx_ports[0])));
8879 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4tlsrx");
8883 if (sc->tt.num_tls_rx_ports == 0) {
8885 rc = SYSCTL_OUT(req, &i, sizeof(i));
8887 rc = SYSCTL_OUT(req, sc->tt.tls_rx_ports,
8888 sc->tt.num_tls_rx_ports * sizeof(sc->tt.tls_rx_ports[0]));
8889 if (rc == 0 && req->newptr != NULL) {
8890 new_count = req->newlen / sizeof(new_ports[0]);
8891 new_ports = malloc(new_count * sizeof(new_ports[0]), M_CXGBE,
8893 rc = SYSCTL_IN(req, new_ports, new_count *
8894 sizeof(new_ports[0]));
8898 /* Allow setting to a single '-1' to clear the list. */
8899 if (new_count == 1 && new_ports[0] == -1) {
8901 old_ports = sc->tt.tls_rx_ports;
8902 sc->tt.tls_rx_ports = NULL;
8903 sc->tt.num_tls_rx_ports = 0;
8905 free(old_ports, M_CXGBE);
8907 for (i = 0; i < new_count; i++) {
8908 if (new_ports[i] < 1 ||
8909 new_ports[i] > IPPORT_MAX) {
8916 old_ports = sc->tt.tls_rx_ports;
8917 sc->tt.tls_rx_ports = new_ports;
8918 sc->tt.num_tls_rx_ports = new_count;
8920 free(old_ports, M_CXGBE);
8924 free(new_ports, M_CXGBE);
8926 end_synchronized_op(sc, 0);
8931 unit_conv(char *buf, size_t len, u_int val, u_int factor)
8933 u_int rem = val % factor;
8936 snprintf(buf, len, "%u", val / factor);
8938 while (rem % 10 == 0)
8940 snprintf(buf, len, "%u.%u", val / factor, rem);
8945 sysctl_tp_tick(SYSCTL_HANDLER_ARGS)
8947 struct adapter *sc = arg1;
8950 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk;
8952 res = t4_read_reg(sc, A_TP_TIMER_RESOLUTION);
8956 re = G_TIMERRESOLUTION(res);
8959 /* TCP timestamp tick */
8960 re = G_TIMESTAMPRESOLUTION(res);
8964 re = G_DELAYEDACKRESOLUTION(res);
8970 unit_conv(buf, sizeof(buf), (cclk_ps << re), 1000000);
8972 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
8976 sysctl_tp_dack_timer(SYSCTL_HANDLER_ARGS)
8978 struct adapter *sc = arg1;
8979 u_int res, dack_re, v;
8980 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk;
8982 res = t4_read_reg(sc, A_TP_TIMER_RESOLUTION);
8983 dack_re = G_DELAYEDACKRESOLUTION(res);
8984 v = ((cclk_ps << dack_re) / 1000000) * t4_read_reg(sc, A_TP_DACK_TIMER);
8986 return (sysctl_handle_int(oidp, &v, 0, req));
8990 sysctl_tp_timer(SYSCTL_HANDLER_ARGS)
8992 struct adapter *sc = arg1;
8995 u_long tp_tick_us, v;
8996 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk;
8998 MPASS(reg == A_TP_RXT_MIN || reg == A_TP_RXT_MAX ||
8999 reg == A_TP_PERS_MIN || reg == A_TP_PERS_MAX ||
9000 reg == A_TP_KEEP_IDLE || reg == A_TP_KEEP_INTVL ||
9001 reg == A_TP_INIT_SRTT || reg == A_TP_FINWAIT2_TIMER);
9003 tre = G_TIMERRESOLUTION(t4_read_reg(sc, A_TP_TIMER_RESOLUTION));
9004 tp_tick_us = (cclk_ps << tre) / 1000000;
9006 if (reg == A_TP_INIT_SRTT)
9007 v = tp_tick_us * G_INITSRTT(t4_read_reg(sc, reg));
9009 v = tp_tick_us * t4_read_reg(sc, reg);
9011 return (sysctl_handle_long(oidp, &v, 0, req));
9015 * All fields in TP_SHIFT_CNT are 4b and the starting location of the field is
9016 * passed to this function.
9019 sysctl_tp_shift_cnt(SYSCTL_HANDLER_ARGS)
9021 struct adapter *sc = arg1;
9025 MPASS(idx >= 0 && idx <= 24);
9027 v = (t4_read_reg(sc, A_TP_SHIFT_CNT) >> idx) & 0xf;
9029 return (sysctl_handle_int(oidp, &v, 0, req));
9033 sysctl_tp_backoff(SYSCTL_HANDLER_ARGS)
9035 struct adapter *sc = arg1;
9039 MPASS(idx >= 0 && idx < 16);
9041 r = A_TP_TCP_BACKOFF_REG0 + (idx & ~3);
9042 shift = (idx & 3) << 3;
9043 v = (t4_read_reg(sc, r) >> shift) & M_TIMERBACKOFFINDEX0;
9045 return (sysctl_handle_int(oidp, &v, 0, req));
9049 sysctl_holdoff_tmr_idx_ofld(SYSCTL_HANDLER_ARGS)
9051 struct vi_info *vi = arg1;
9052 struct adapter *sc = vi->pi->adapter;
9054 struct sge_ofld_rxq *ofld_rxq;
9057 idx = vi->ofld_tmr_idx;
9059 rc = sysctl_handle_int(oidp, &idx, 0, req);
9060 if (rc != 0 || req->newptr == NULL)
9063 if (idx < 0 || idx >= SGE_NTIMERS)
9066 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
9071 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(vi->ofld_pktc_idx != -1);
9072 for_each_ofld_rxq(vi, i, ofld_rxq) {
9073 #ifdef atomic_store_rel_8
9074 atomic_store_rel_8(&ofld_rxq->iq.intr_params, v);
9076 ofld_rxq->iq.intr_params = v;
9079 vi->ofld_tmr_idx = idx;
9081 end_synchronized_op(sc, LOCK_HELD);
9086 sysctl_holdoff_pktc_idx_ofld(SYSCTL_HANDLER_ARGS)
9088 struct vi_info *vi = arg1;
9089 struct adapter *sc = vi->pi->adapter;
9092 idx = vi->ofld_pktc_idx;
9094 rc = sysctl_handle_int(oidp, &idx, 0, req);
9095 if (rc != 0 || req->newptr == NULL)
9098 if (idx < -1 || idx >= SGE_NCOUNTERS)
9101 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
9106 if (vi->flags & VI_INIT_DONE)
9107 rc = EBUSY; /* cannot be changed once the queues are created */
9109 vi->ofld_pktc_idx = idx;
9111 end_synchronized_op(sc, LOCK_HELD);
9117 get_sge_context(struct adapter *sc, struct t4_sge_context *cntxt)
9121 if (cntxt->cid > M_CTXTQID)
9124 if (cntxt->mem_id != CTXT_EGRESS && cntxt->mem_id != CTXT_INGRESS &&
9125 cntxt->mem_id != CTXT_FLM && cntxt->mem_id != CTXT_CNM)
9128 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ctxt");
9132 if (sc->flags & FW_OK) {
9133 rc = -t4_sge_ctxt_rd(sc, sc->mbox, cntxt->cid, cntxt->mem_id,
9140 * Read via firmware failed or wasn't even attempted. Read directly via
9143 rc = -t4_sge_ctxt_rd_bd(sc, cntxt->cid, cntxt->mem_id, &cntxt->data[0]);
9145 end_synchronized_op(sc, 0);
9150 load_fw(struct adapter *sc, struct t4_data *fw)
9155 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldfw");
9160 * The firmware, with the sole exception of the memory parity error
9161 * handler, runs from memory and not flash. It is almost always safe to
9162 * install a new firmware on a running system. Just set bit 1 in
9163 * hw.cxgbe.dflags or dev.<nexus>.<n>.dflags first.
9165 if (sc->flags & FULL_INIT_DONE &&
9166 (sc->debug_flags & DF_LOAD_FW_ANYTIME) == 0) {
9171 fw_data = malloc(fw->len, M_CXGBE, M_WAITOK);
9172 if (fw_data == NULL) {
9177 rc = copyin(fw->data, fw_data, fw->len);
9179 rc = -t4_load_fw(sc, fw_data, fw->len);
9181 free(fw_data, M_CXGBE);
9183 end_synchronized_op(sc, 0);
9188 load_cfg(struct adapter *sc, struct t4_data *cfg)
9191 uint8_t *cfg_data = NULL;
9193 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldcf");
9197 if (cfg->len == 0) {
9199 rc = -t4_load_cfg(sc, NULL, 0);
9203 cfg_data = malloc(cfg->len, M_CXGBE, M_WAITOK);
9204 if (cfg_data == NULL) {
9209 rc = copyin(cfg->data, cfg_data, cfg->len);
9211 rc = -t4_load_cfg(sc, cfg_data, cfg->len);
9213 free(cfg_data, M_CXGBE);
9215 end_synchronized_op(sc, 0);
9220 load_boot(struct adapter *sc, struct t4_bootrom *br)
9223 uint8_t *br_data = NULL;
9226 if (br->len > 1024 * 1024)
9229 if (br->pf_offset == 0) {
9231 if (br->pfidx_addr > 7)
9233 offset = G_OFFSET(t4_read_reg(sc, PF_REG(br->pfidx_addr,
9234 A_PCIE_PF_EXPROM_OFST)));
9235 } else if (br->pf_offset == 1) {
9237 offset = G_OFFSET(br->pfidx_addr);
9242 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldbr");
9248 rc = -t4_load_boot(sc, NULL, offset, 0);
9252 br_data = malloc(br->len, M_CXGBE, M_WAITOK);
9253 if (br_data == NULL) {
9258 rc = copyin(br->data, br_data, br->len);
9260 rc = -t4_load_boot(sc, br_data, offset, br->len);
9262 free(br_data, M_CXGBE);
9264 end_synchronized_op(sc, 0);
9269 load_bootcfg(struct adapter *sc, struct t4_data *bc)
9272 uint8_t *bc_data = NULL;
9274 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldcf");
9280 rc = -t4_load_bootcfg(sc, NULL, 0);
9284 bc_data = malloc(bc->len, M_CXGBE, M_WAITOK);
9285 if (bc_data == NULL) {
9290 rc = copyin(bc->data, bc_data, bc->len);
9292 rc = -t4_load_bootcfg(sc, bc_data, bc->len);
9294 free(bc_data, M_CXGBE);
9296 end_synchronized_op(sc, 0);
9301 cudbg_dump(struct adapter *sc, struct t4_cudbg_dump *dump)
9304 struct cudbg_init *cudbg;
9307 /* buf is large, don't block if no memory is available */
9308 buf = malloc(dump->len, M_CXGBE, M_NOWAIT | M_ZERO);
9312 handle = cudbg_alloc_handle();
9313 if (handle == NULL) {
9318 cudbg = cudbg_get_init(handle);
9320 cudbg->print = (cudbg_print_cb)printf;
9323 device_printf(sc->dev, "%s: wr_flash %u, len %u, data %p.\n",
9324 __func__, dump->wr_flash, dump->len, dump->data);
9328 cudbg->use_flash = 1;
9329 MPASS(sizeof(cudbg->dbg_bitmap) == sizeof(dump->bitmap));
9330 memcpy(cudbg->dbg_bitmap, dump->bitmap, sizeof(cudbg->dbg_bitmap));
9332 rc = cudbg_collect(handle, buf, &dump->len);
9336 rc = copyout(buf, dump->data, dump->len);
9338 cudbg_free_handle(handle);
9344 free_offload_policy(struct t4_offload_policy *op)
9346 struct offload_rule *r;
9353 for (i = 0; i < op->nrules; i++, r++) {
9354 free(r->bpf_prog.bf_insns, M_CXGBE);
9356 free(op->rule, M_CXGBE);
9361 set_offload_policy(struct adapter *sc, struct t4_offload_policy *uop)
9364 struct t4_offload_policy *op, *old;
9365 struct bpf_program *bf;
9366 const struct offload_settings *s;
9367 struct offload_rule *r;
9370 if (!is_offload(sc))
9373 if (uop->nrules == 0) {
9374 /* Delete installed policies. */
9377 } if (uop->nrules > 256) { /* arbitrary */
9381 /* Copy userspace offload policy to kernel */
9382 op = malloc(sizeof(*op), M_CXGBE, M_ZERO | M_WAITOK);
9383 op->nrules = uop->nrules;
9384 len = op->nrules * sizeof(struct offload_rule);
9385 op->rule = malloc(len, M_CXGBE, M_ZERO | M_WAITOK);
9386 rc = copyin(uop->rule, op->rule, len);
9388 free(op->rule, M_CXGBE);
9394 for (i = 0; i < op->nrules; i++, r++) {
9396 /* Validate open_type */
9397 if (r->open_type != OPEN_TYPE_LISTEN &&
9398 r->open_type != OPEN_TYPE_ACTIVE &&
9399 r->open_type != OPEN_TYPE_PASSIVE &&
9400 r->open_type != OPEN_TYPE_DONTCARE) {
9403 * Rules 0 to i have malloc'd filters that need to be
9404 * freed. Rules i+1 to nrules have userspace pointers
9405 * and should be left alone.
9408 free_offload_policy(op);
9412 /* Validate settings */
9414 if ((s->offload != 0 && s->offload != 1) ||
9415 s->cong_algo < -1 || s->cong_algo > CONG_ALG_HIGHSPEED ||
9416 s->sched_class < -1 ||
9417 s->sched_class >= sc->chip_params->nsched_cls) {
9423 u = bf->bf_insns; /* userspace ptr */
9424 bf->bf_insns = NULL;
9425 if (bf->bf_len == 0) {
9426 /* legal, matches everything */
9429 len = bf->bf_len * sizeof(*bf->bf_insns);
9430 bf->bf_insns = malloc(len, M_CXGBE, M_ZERO | M_WAITOK);
9431 rc = copyin(u, bf->bf_insns, len);
9435 if (!bpf_validate(bf->bf_insns, bf->bf_len)) {
9441 rw_wlock(&sc->policy_lock);
9444 rw_wunlock(&sc->policy_lock);
9445 free_offload_policy(old);
9450 #define MAX_READ_BUF_SIZE (128 * 1024)
9452 read_card_mem(struct adapter *sc, int win, struct t4_mem_range *mr)
9454 uint32_t addr, remaining, n;
9459 rc = validate_mem_range(sc, mr->addr, mr->len);
9463 buf = malloc(min(mr->len, MAX_READ_BUF_SIZE), M_CXGBE, M_WAITOK);
9465 remaining = mr->len;
9466 dst = (void *)mr->data;
9469 n = min(remaining, MAX_READ_BUF_SIZE);
9470 read_via_memwin(sc, 2, addr, buf, n);
9472 rc = copyout(buf, dst, n);
9484 #undef MAX_READ_BUF_SIZE
9487 read_i2c(struct adapter *sc, struct t4_i2c_data *i2cd)
9491 if (i2cd->len == 0 || i2cd->port_id >= sc->params.nports)
9494 if (i2cd->len > sizeof(i2cd->data))
9497 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4i2crd");
9500 rc = -t4_i2c_rd(sc, sc->mbox, i2cd->port_id, i2cd->dev_addr,
9501 i2cd->offset, i2cd->len, &i2cd->data[0]);
9502 end_synchronized_op(sc, 0);
9508 t4_os_find_pci_capability(struct adapter *sc, int cap)
9512 return (pci_find_cap(sc->dev, cap, &i) == 0 ? i : 0);
9516 t4_os_pci_save_state(struct adapter *sc)
9519 struct pci_devinfo *dinfo;
9522 dinfo = device_get_ivars(dev);
9524 pci_cfg_save(dev, dinfo, 0);
9529 t4_os_pci_restore_state(struct adapter *sc)
9532 struct pci_devinfo *dinfo;
9535 dinfo = device_get_ivars(dev);
9537 pci_cfg_restore(dev, dinfo);
9542 t4_os_portmod_changed(struct port_info *pi)
9544 struct adapter *sc = pi->adapter;
9547 static const char *mod_str[] = {
9548 NULL, "LR", "SR", "ER", "TWINAX", "active TWINAX", "LRM"
9551 KASSERT((pi->flags & FIXED_IFMEDIA) == 0,
9552 ("%s: port_type %u", __func__, pi->port_type));
9555 if (begin_synchronized_op(sc, vi, HOLD_LOCK, "t4mod") == 0) {
9557 build_medialist(pi);
9558 if (pi->mod_type != FW_PORT_MOD_TYPE_NONE) {
9559 fixup_link_config(pi);
9560 apply_link_config(pi);
9563 end_synchronized_op(sc, LOCK_HELD);
9567 if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
9568 if_printf(ifp, "transceiver unplugged.\n");
9569 else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
9570 if_printf(ifp, "unknown transceiver inserted.\n");
9571 else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
9572 if_printf(ifp, "unsupported transceiver inserted.\n");
9573 else if (pi->mod_type > 0 && pi->mod_type < nitems(mod_str)) {
9574 if_printf(ifp, "%dGbps %s transceiver inserted.\n",
9575 port_top_speed(pi), mod_str[pi->mod_type]);
9577 if_printf(ifp, "transceiver (type %d) inserted.\n",
9583 t4_os_link_changed(struct port_info *pi)
9587 struct link_config *lc;
9590 PORT_LOCK_ASSERT_OWNED(pi);
9592 for_each_vi(pi, v, vi) {
9599 ifp->if_baudrate = IF_Mbps(lc->speed);
9600 if_link_state_change(ifp, LINK_STATE_UP);
9602 if_link_state_change(ifp, LINK_STATE_DOWN);
9608 t4_iterate(void (*func)(struct adapter *, void *), void *arg)
9612 sx_slock(&t4_list_lock);
9613 SLIST_FOREACH(sc, &t4_list, link) {
9615 * func should not make any assumptions about what state sc is
9616 * in - the only guarantee is that sc->sc_lock is a valid lock.
9620 sx_sunlock(&t4_list_lock);
9624 t4_ioctl(struct cdev *dev, unsigned long cmd, caddr_t data, int fflag,
9628 struct adapter *sc = dev->si_drv1;
9630 rc = priv_check(td, PRIV_DRIVER);
9635 case CHELSIO_T4_GETREG: {
9636 struct t4_reg *edata = (struct t4_reg *)data;
9638 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
9641 if (edata->size == 4)
9642 edata->val = t4_read_reg(sc, edata->addr);
9643 else if (edata->size == 8)
9644 edata->val = t4_read_reg64(sc, edata->addr);
9650 case CHELSIO_T4_SETREG: {
9651 struct t4_reg *edata = (struct t4_reg *)data;
9653 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
9656 if (edata->size == 4) {
9657 if (edata->val & 0xffffffff00000000)
9659 t4_write_reg(sc, edata->addr, (uint32_t) edata->val);
9660 } else if (edata->size == 8)
9661 t4_write_reg64(sc, edata->addr, edata->val);
9666 case CHELSIO_T4_REGDUMP: {
9667 struct t4_regdump *regs = (struct t4_regdump *)data;
9668 int reglen = t4_get_regs_len(sc);
9671 if (regs->len < reglen) {
9672 regs->len = reglen; /* hint to the caller */
9677 buf = malloc(reglen, M_CXGBE, M_WAITOK | M_ZERO);
9678 get_regs(sc, regs, buf);
9679 rc = copyout(buf, regs->data, reglen);
9683 case CHELSIO_T4_GET_FILTER_MODE:
9684 rc = get_filter_mode(sc, (uint32_t *)data);
9686 case CHELSIO_T4_SET_FILTER_MODE:
9687 rc = set_filter_mode(sc, *(uint32_t *)data);
9689 case CHELSIO_T4_GET_FILTER:
9690 rc = get_filter(sc, (struct t4_filter *)data);
9692 case CHELSIO_T4_SET_FILTER:
9693 rc = set_filter(sc, (struct t4_filter *)data);
9695 case CHELSIO_T4_DEL_FILTER:
9696 rc = del_filter(sc, (struct t4_filter *)data);
9698 case CHELSIO_T4_GET_SGE_CONTEXT:
9699 rc = get_sge_context(sc, (struct t4_sge_context *)data);
9701 case CHELSIO_T4_LOAD_FW:
9702 rc = load_fw(sc, (struct t4_data *)data);
9704 case CHELSIO_T4_GET_MEM:
9705 rc = read_card_mem(sc, 2, (struct t4_mem_range *)data);
9707 case CHELSIO_T4_GET_I2C:
9708 rc = read_i2c(sc, (struct t4_i2c_data *)data);
9710 case CHELSIO_T4_CLEAR_STATS: {
9712 u_int port_id = *(uint32_t *)data;
9713 struct port_info *pi;
9716 if (port_id >= sc->params.nports)
9718 pi = sc->port[port_id];
9723 t4_clr_port_stats(sc, pi->tx_chan);
9724 pi->tx_parse_error = 0;
9725 pi->tnl_cong_drops = 0;
9726 mtx_lock(&sc->reg_lock);
9727 for_each_vi(pi, v, vi) {
9728 if (vi->flags & VI_INIT_DONE)
9729 t4_clr_vi_stats(sc, vi->viid);
9731 bg_map = pi->mps_bg_map;
9734 i = ffs(bg_map) - 1;
9735 t4_write_indirect(sc, A_TP_MIB_INDEX, A_TP_MIB_DATA, &v,
9736 1, A_TP_MIB_TNL_CNG_DROP_0 + i);
9737 bg_map &= ~(1 << i);
9739 mtx_unlock(&sc->reg_lock);
9742 * Since this command accepts a port, clear stats for
9743 * all VIs on this port.
9745 for_each_vi(pi, v, vi) {
9746 if (vi->flags & VI_INIT_DONE) {
9747 struct sge_rxq *rxq;
9748 struct sge_txq *txq;
9749 struct sge_wrq *wrq;
9751 for_each_rxq(vi, i, rxq) {
9752 #if defined(INET) || defined(INET6)
9753 rxq->lro.lro_queued = 0;
9754 rxq->lro.lro_flushed = 0;
9757 rxq->vlan_extraction = 0;
9760 for_each_txq(vi, i, txq) {
9763 txq->vlan_insertion = 0;
9767 txq->txpkts0_wrs = 0;
9768 txq->txpkts1_wrs = 0;
9769 txq->txpkts0_pkts = 0;
9770 txq->txpkts1_pkts = 0;
9771 mp_ring_reset_stats(txq->r);
9775 /* nothing to clear for each ofld_rxq */
9777 for_each_ofld_txq(vi, i, wrq) {
9778 wrq->tx_wrs_direct = 0;
9779 wrq->tx_wrs_copied = 0;
9783 if (IS_MAIN_VI(vi)) {
9784 wrq = &sc->sge.ctrlq[pi->port_id];
9785 wrq->tx_wrs_direct = 0;
9786 wrq->tx_wrs_copied = 0;
9792 case CHELSIO_T4_SCHED_CLASS:
9793 rc = t4_set_sched_class(sc, (struct t4_sched_params *)data);
9795 case CHELSIO_T4_SCHED_QUEUE:
9796 rc = t4_set_sched_queue(sc, (struct t4_sched_queue *)data);
9798 case CHELSIO_T4_GET_TRACER:
9799 rc = t4_get_tracer(sc, (struct t4_tracer *)data);
9801 case CHELSIO_T4_SET_TRACER:
9802 rc = t4_set_tracer(sc, (struct t4_tracer *)data);
9804 case CHELSIO_T4_LOAD_CFG:
9805 rc = load_cfg(sc, (struct t4_data *)data);
9807 case CHELSIO_T4_LOAD_BOOT:
9808 rc = load_boot(sc, (struct t4_bootrom *)data);
9810 case CHELSIO_T4_LOAD_BOOTCFG:
9811 rc = load_bootcfg(sc, (struct t4_data *)data);
9813 case CHELSIO_T4_CUDBG_DUMP:
9814 rc = cudbg_dump(sc, (struct t4_cudbg_dump *)data);
9816 case CHELSIO_T4_SET_OFLD_POLICY:
9817 rc = set_offload_policy(sc, (struct t4_offload_policy *)data);
9827 t4_db_full(struct adapter *sc)
9830 CXGBE_UNIMPLEMENTED(__func__);
9834 t4_db_dropped(struct adapter *sc)
9837 CXGBE_UNIMPLEMENTED(__func__);
9842 toe_capability(struct vi_info *vi, int enable)
9845 struct port_info *pi = vi->pi;
9846 struct adapter *sc = pi->adapter;
9848 ASSERT_SYNCHRONIZED_OP(sc);
9850 if (!is_offload(sc))
9854 if ((vi->ifp->if_capenable & IFCAP_TOE) != 0) {
9855 /* TOE is already enabled. */
9860 * We need the port's queues around so that we're able to send
9861 * and receive CPLs to/from the TOE even if the ifnet for this
9862 * port has never been UP'd administratively.
9864 if (!(vi->flags & VI_INIT_DONE)) {
9865 rc = vi_full_init(vi);
9869 if (!(pi->vi[0].flags & VI_INIT_DONE)) {
9870 rc = vi_full_init(&pi->vi[0]);
9875 if (isset(&sc->offload_map, pi->port_id)) {
9876 /* TOE is enabled on another VI of this port. */
9881 if (!uld_active(sc, ULD_TOM)) {
9882 rc = t4_activate_uld(sc, ULD_TOM);
9885 "You must kldload t4_tom.ko before trying "
9886 "to enable TOE on a cxgbe interface.\n");
9890 KASSERT(sc->tom_softc != NULL,
9891 ("%s: TOM activated but softc NULL", __func__));
9892 KASSERT(uld_active(sc, ULD_TOM),
9893 ("%s: TOM activated but flag not set", __func__));
9896 /* Activate iWARP and iSCSI too, if the modules are loaded. */
9897 if (!uld_active(sc, ULD_IWARP))
9898 (void) t4_activate_uld(sc, ULD_IWARP);
9899 if (!uld_active(sc, ULD_ISCSI))
9900 (void) t4_activate_uld(sc, ULD_ISCSI);
9903 setbit(&sc->offload_map, pi->port_id);
9907 if (!isset(&sc->offload_map, pi->port_id) || pi->uld_vis > 0)
9910 KASSERT(uld_active(sc, ULD_TOM),
9911 ("%s: TOM never initialized?", __func__));
9912 clrbit(&sc->offload_map, pi->port_id);
9919 * Add an upper layer driver to the global list.
9922 t4_register_uld(struct uld_info *ui)
9927 sx_xlock(&t4_uld_list_lock);
9928 SLIST_FOREACH(u, &t4_uld_list, link) {
9929 if (u->uld_id == ui->uld_id) {
9935 SLIST_INSERT_HEAD(&t4_uld_list, ui, link);
9938 sx_xunlock(&t4_uld_list_lock);
9943 t4_unregister_uld(struct uld_info *ui)
9948 sx_xlock(&t4_uld_list_lock);
9950 SLIST_FOREACH(u, &t4_uld_list, link) {
9952 if (ui->refcount > 0) {
9957 SLIST_REMOVE(&t4_uld_list, ui, uld_info, link);
9963 sx_xunlock(&t4_uld_list_lock);
9968 t4_activate_uld(struct adapter *sc, int id)
9971 struct uld_info *ui;
9973 ASSERT_SYNCHRONIZED_OP(sc);
9975 if (id < 0 || id > ULD_MAX)
9977 rc = EAGAIN; /* kldoad the module with this ULD and try again. */
9979 sx_slock(&t4_uld_list_lock);
9981 SLIST_FOREACH(ui, &t4_uld_list, link) {
9982 if (ui->uld_id == id) {
9983 if (!(sc->flags & FULL_INIT_DONE)) {
9984 rc = adapter_full_init(sc);
9989 rc = ui->activate(sc);
9991 setbit(&sc->active_ulds, id);
9998 sx_sunlock(&t4_uld_list_lock);
10004 t4_deactivate_uld(struct adapter *sc, int id)
10007 struct uld_info *ui;
10009 ASSERT_SYNCHRONIZED_OP(sc);
10011 if (id < 0 || id > ULD_MAX)
10015 sx_slock(&t4_uld_list_lock);
10017 SLIST_FOREACH(ui, &t4_uld_list, link) {
10018 if (ui->uld_id == id) {
10019 rc = ui->deactivate(sc);
10021 clrbit(&sc->active_ulds, id);
10028 sx_sunlock(&t4_uld_list_lock);
10034 uld_active(struct adapter *sc, int uld_id)
10037 MPASS(uld_id >= 0 && uld_id <= ULD_MAX);
10039 return (isset(&sc->active_ulds, uld_id));
10044 * t = ptr to tunable.
10045 * nc = number of CPUs.
10046 * c = compiled in default for that tunable.
10049 calculate_nqueues(int *t, int nc, const int c)
10055 nq = *t < 0 ? -*t : c;
10060 * Come up with reasonable defaults for some of the tunables, provided they're
10061 * not set by the user (in which case we'll use the values as is).
10064 tweak_tunables(void)
10066 int nc = mp_ncpus; /* our snapshot of the number of CPUs */
10070 t4_ntxq = rss_getnumbuckets();
10072 calculate_nqueues(&t4_ntxq, nc, NTXQ);
10076 calculate_nqueues(&t4_ntxq_vi, nc, NTXQ_VI);
10080 t4_nrxq = rss_getnumbuckets();
10082 calculate_nqueues(&t4_nrxq, nc, NRXQ);
10086 calculate_nqueues(&t4_nrxq_vi, nc, NRXQ_VI);
10088 #if defined(TCP_OFFLOAD) || defined(RATELIMIT)
10089 calculate_nqueues(&t4_nofldtxq, nc, NOFLDTXQ);
10090 calculate_nqueues(&t4_nofldtxq_vi, nc, NOFLDTXQ_VI);
10093 calculate_nqueues(&t4_nofldrxq, nc, NOFLDRXQ);
10094 calculate_nqueues(&t4_nofldrxq_vi, nc, NOFLDRXQ_VI);
10096 if (t4_toecaps_allowed == -1)
10097 t4_toecaps_allowed = FW_CAPS_CONFIG_TOE;
10099 if (t4_rdmacaps_allowed == -1) {
10100 t4_rdmacaps_allowed = FW_CAPS_CONFIG_RDMA_RDDP |
10101 FW_CAPS_CONFIG_RDMA_RDMAC;
10104 if (t4_iscsicaps_allowed == -1) {
10105 t4_iscsicaps_allowed = FW_CAPS_CONFIG_ISCSI_INITIATOR_PDU |
10106 FW_CAPS_CONFIG_ISCSI_TARGET_PDU |
10107 FW_CAPS_CONFIG_ISCSI_T10DIF;
10110 if (t4_tmr_idx_ofld < 0 || t4_tmr_idx_ofld >= SGE_NTIMERS)
10111 t4_tmr_idx_ofld = TMR_IDX_OFLD;
10113 if (t4_pktc_idx_ofld < -1 || t4_pktc_idx_ofld >= SGE_NCOUNTERS)
10114 t4_pktc_idx_ofld = PKTC_IDX_OFLD;
10116 if (t4_toecaps_allowed == -1)
10117 t4_toecaps_allowed = 0;
10119 if (t4_rdmacaps_allowed == -1)
10120 t4_rdmacaps_allowed = 0;
10122 if (t4_iscsicaps_allowed == -1)
10123 t4_iscsicaps_allowed = 0;
10127 calculate_nqueues(&t4_nnmtxq_vi, nc, NNMTXQ_VI);
10128 calculate_nqueues(&t4_nnmrxq_vi, nc, NNMRXQ_VI);
10131 if (t4_tmr_idx < 0 || t4_tmr_idx >= SGE_NTIMERS)
10132 t4_tmr_idx = TMR_IDX;
10134 if (t4_pktc_idx < -1 || t4_pktc_idx >= SGE_NCOUNTERS)
10135 t4_pktc_idx = PKTC_IDX;
10137 if (t4_qsize_txq < 128)
10138 t4_qsize_txq = 128;
10140 if (t4_qsize_rxq < 128)
10141 t4_qsize_rxq = 128;
10142 while (t4_qsize_rxq & 7)
10145 t4_intr_types &= INTR_MSIX | INTR_MSI | INTR_INTX;
10148 * Number of VIs to create per-port. The first VI is the "main" regular
10149 * VI for the port. The rest are additional virtual interfaces on the
10150 * same physical port. Note that the main VI does not have native
10151 * netmap support but the extra VIs do.
10153 * Limit the number of VIs per port to the number of available
10154 * MAC addresses per port.
10156 if (t4_num_vis < 1)
10158 if (t4_num_vis > nitems(vi_mac_funcs)) {
10159 t4_num_vis = nitems(vi_mac_funcs);
10160 printf("cxgbe: number of VIs limited to %d\n", t4_num_vis);
10163 if (pcie_relaxed_ordering < 0 || pcie_relaxed_ordering > 2) {
10164 pcie_relaxed_ordering = 1;
10165 #if defined(__i386__) || defined(__amd64__)
10166 if (cpu_vendor_id == CPU_VENDOR_INTEL)
10167 pcie_relaxed_ordering = 0;
10174 t4_dump_tcb(struct adapter *sc, int tid)
10176 uint32_t base, i, j, off, pf, reg, save, tcb_addr, win_pos;
10178 reg = PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, 2);
10179 save = t4_read_reg(sc, reg);
10180 base = sc->memwin[2].mw_base;
10182 /* Dump TCB for the tid */
10183 tcb_addr = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
10184 tcb_addr += tid * TCB_SIZE;
10188 win_pos = tcb_addr & ~0xf; /* start must be 16B aligned */
10190 pf = V_PFNUM(sc->pf);
10191 win_pos = tcb_addr & ~0x7f; /* start must be 128B aligned */
10193 t4_write_reg(sc, reg, win_pos | pf);
10194 t4_read_reg(sc, reg);
10196 off = tcb_addr - win_pos;
10197 for (i = 0; i < 4; i++) {
10199 for (j = 0; j < 8; j++, off += 4)
10200 buf[j] = htonl(t4_read_reg(sc, base + off));
10202 db_printf("%08x %08x %08x %08x %08x %08x %08x %08x\n",
10203 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
10207 t4_write_reg(sc, reg, save);
10208 t4_read_reg(sc, reg);
10212 t4_dump_devlog(struct adapter *sc)
10214 struct devlog_params *dparams = &sc->params.devlog;
10215 struct fw_devlog_e e;
10216 int i, first, j, m, nentries, rc;
10217 uint64_t ftstamp = UINT64_MAX;
10219 if (dparams->start == 0) {
10220 db_printf("devlog params not valid\n");
10224 nentries = dparams->size / sizeof(struct fw_devlog_e);
10225 m = fwmtype_to_hwmtype(dparams->memtype);
10227 /* Find the first entry. */
10229 for (i = 0; i < nentries && !db_pager_quit; i++) {
10230 rc = -t4_mem_read(sc, m, dparams->start + i * sizeof(e),
10231 sizeof(e), (void *)&e);
10235 if (e.timestamp == 0)
10238 e.timestamp = be64toh(e.timestamp);
10239 if (e.timestamp < ftstamp) {
10240 ftstamp = e.timestamp;
10250 rc = -t4_mem_read(sc, m, dparams->start + i * sizeof(e),
10251 sizeof(e), (void *)&e);
10255 if (e.timestamp == 0)
10258 e.timestamp = be64toh(e.timestamp);
10259 e.seqno = be32toh(e.seqno);
10260 for (j = 0; j < 8; j++)
10261 e.params[j] = be32toh(e.params[j]);
10263 db_printf("%10d %15ju %8s %8s ",
10264 e.seqno, e.timestamp,
10265 (e.level < nitems(devlog_level_strings) ?
10266 devlog_level_strings[e.level] : "UNKNOWN"),
10267 (e.facility < nitems(devlog_facility_strings) ?
10268 devlog_facility_strings[e.facility] : "UNKNOWN"));
10269 db_printf(e.fmt, e.params[0], e.params[1], e.params[2],
10270 e.params[3], e.params[4], e.params[5], e.params[6],
10273 if (++i == nentries)
10275 } while (i != first && !db_pager_quit);
10278 static struct command_table db_t4_table = LIST_HEAD_INITIALIZER(db_t4_table);
10279 _DB_SET(_show, t4, NULL, db_show_table, 0, &db_t4_table);
10281 DB_FUNC(devlog, db_show_devlog, db_t4_table, CS_OWN, NULL)
10288 t = db_read_token();
10290 dev = device_lookup_by_name(db_tok_string);
10295 db_printf("usage: show t4 devlog <nexus>\n");
10300 db_printf("device not found\n");
10304 t4_dump_devlog(device_get_softc(dev));
10307 DB_FUNC(tcb, db_show_t4tcb, db_t4_table, CS_OWN, NULL)
10316 t = db_read_token();
10318 dev = device_lookup_by_name(db_tok_string);
10319 t = db_read_token();
10320 if (t == tNUMBER) {
10321 tid = db_tok_number;
10328 db_printf("usage: show t4 tcb <nexus> <tid>\n");
10333 db_printf("device not found\n");
10337 db_printf("invalid tid\n");
10341 t4_dump_tcb(device_get_softc(dev), tid);
10346 * Borrowed from cesa_prep_aes_key().
10348 * NB: The crypto engine wants the words in the decryption key in reverse
10352 t4_aes_getdeckey(void *dec_key, const void *enc_key, unsigned int kbits)
10354 uint32_t ek[4 * (RIJNDAEL_MAXNR + 1)];
10358 rijndaelKeySetupEnc(ek, enc_key, kbits);
10360 dkey += (kbits / 8) / 4;
10364 for (i = 0; i < 4; i++)
10365 *--dkey = htobe32(ek[4 * 10 + i]);
10368 for (i = 0; i < 2; i++)
10369 *--dkey = htobe32(ek[4 * 11 + 2 + i]);
10370 for (i = 0; i < 4; i++)
10371 *--dkey = htobe32(ek[4 * 12 + i]);
10374 for (i = 0; i < 4; i++)
10375 *--dkey = htobe32(ek[4 * 13 + i]);
10376 for (i = 0; i < 4; i++)
10377 *--dkey = htobe32(ek[4 * 14 + i]);
10380 MPASS(dkey == dec_key);
10383 static struct sx mlu; /* mod load unload */
10384 SX_SYSINIT(cxgbe_mlu, &mlu, "cxgbe mod load/unload");
10387 mod_event(module_t mod, int cmd, void *arg)
10390 static int loaded = 0;
10395 if (loaded++ == 0) {
10397 t4_register_shared_cpl_handler(CPL_SET_TCB_RPL,
10398 t4_filter_rpl, CPL_COOKIE_FILTER);
10399 t4_register_shared_cpl_handler(CPL_L2T_WRITE_RPL,
10400 do_l2t_write_rpl, CPL_COOKIE_FILTER);
10401 t4_register_shared_cpl_handler(CPL_ACT_OPEN_RPL,
10402 t4_hashfilter_ao_rpl, CPL_COOKIE_HASHFILTER);
10403 t4_register_shared_cpl_handler(CPL_SET_TCB_RPL,
10404 t4_hashfilter_tcb_rpl, CPL_COOKIE_HASHFILTER);
10405 t4_register_shared_cpl_handler(CPL_ABORT_RPL_RSS,
10406 t4_del_hashfilter_rpl, CPL_COOKIE_HASHFILTER);
10407 t4_register_cpl_handler(CPL_TRACE_PKT, t4_trace_pkt);
10408 t4_register_cpl_handler(CPL_T5_TRACE_PKT, t5_trace_pkt);
10409 t4_register_cpl_handler(CPL_SMT_WRITE_RPL,
10411 sx_init(&t4_list_lock, "T4/T5 adapters");
10412 SLIST_INIT(&t4_list);
10414 sx_init(&t4_uld_list_lock, "T4/T5 ULDs");
10415 SLIST_INIT(&t4_uld_list);
10417 t4_tracer_modload();
10425 if (--loaded == 0) {
10428 sx_slock(&t4_list_lock);
10429 if (!SLIST_EMPTY(&t4_list)) {
10431 sx_sunlock(&t4_list_lock);
10435 sx_slock(&t4_uld_list_lock);
10436 if (!SLIST_EMPTY(&t4_uld_list)) {
10438 sx_sunlock(&t4_uld_list_lock);
10439 sx_sunlock(&t4_list_lock);
10444 while (tries++ < 5 && t4_sge_extfree_refs() != 0) {
10445 uprintf("%ju clusters with custom free routine "
10446 "still is use.\n", t4_sge_extfree_refs());
10447 pause("t4unload", 2 * hz);
10450 sx_sunlock(&t4_uld_list_lock);
10452 sx_sunlock(&t4_list_lock);
10454 if (t4_sge_extfree_refs() == 0) {
10455 t4_tracer_modunload();
10457 sx_destroy(&t4_uld_list_lock);
10459 sx_destroy(&t4_list_lock);
10460 t4_sge_modunload();
10464 loaded++; /* undo earlier decrement */
10475 static devclass_t t4_devclass, t5_devclass, t6_devclass;
10476 static devclass_t cxgbe_devclass, cxl_devclass, cc_devclass;
10477 static devclass_t vcxgbe_devclass, vcxl_devclass, vcc_devclass;
10479 DRIVER_MODULE(t4nex, pci, t4_driver, t4_devclass, mod_event, 0);
10480 MODULE_VERSION(t4nex, 1);
10481 MODULE_DEPEND(t4nex, firmware, 1, 1, 1);
10483 MODULE_DEPEND(t4nex, netmap, 1, 1, 1);
10484 #endif /* DEV_NETMAP */
10486 DRIVER_MODULE(t5nex, pci, t5_driver, t5_devclass, mod_event, 0);
10487 MODULE_VERSION(t5nex, 1);
10488 MODULE_DEPEND(t5nex, firmware, 1, 1, 1);
10490 MODULE_DEPEND(t5nex, netmap, 1, 1, 1);
10491 #endif /* DEV_NETMAP */
10493 DRIVER_MODULE(t6nex, pci, t6_driver, t6_devclass, mod_event, 0);
10494 MODULE_VERSION(t6nex, 1);
10495 MODULE_DEPEND(t6nex, firmware, 1, 1, 1);
10497 MODULE_DEPEND(t6nex, netmap, 1, 1, 1);
10498 #endif /* DEV_NETMAP */
10500 DRIVER_MODULE(cxgbe, t4nex, cxgbe_driver, cxgbe_devclass, 0, 0);
10501 MODULE_VERSION(cxgbe, 1);
10503 DRIVER_MODULE(cxl, t5nex, cxl_driver, cxl_devclass, 0, 0);
10504 MODULE_VERSION(cxl, 1);
10506 DRIVER_MODULE(cc, t6nex, cc_driver, cc_devclass, 0, 0);
10507 MODULE_VERSION(cc, 1);
10509 DRIVER_MODULE(vcxgbe, cxgbe, vcxgbe_driver, vcxgbe_devclass, 0, 0);
10510 MODULE_VERSION(vcxgbe, 1);
10512 DRIVER_MODULE(vcxl, cxl, vcxl_driver, vcxl_devclass, 0, 0);
10513 MODULE_VERSION(vcxl, 1);
10515 DRIVER_MODULE(vcc, cc, vcc_driver, vcc_devclass, 0, 0);
10516 MODULE_VERSION(vcc, 1);