2 * Copyright (c) 2011 Chelsio Communications, Inc.
4 * Written by: Navdeep Parhar <np@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
33 #include "opt_inet6.h"
36 #include <sys/param.h>
39 #include <sys/kernel.h>
41 #include <sys/module.h>
42 #include <sys/malloc.h>
43 #include <sys/queue.h>
44 #include <sys/taskqueue.h>
45 #include <sys/pciio.h>
46 #include <dev/pci/pcireg.h>
47 #include <dev/pci/pcivar.h>
48 #include <dev/pci/pci_private.h>
49 #include <sys/firmware.h>
52 #include <sys/socket.h>
53 #include <sys/sockio.h>
54 #include <sys/sysctl.h>
55 #include <net/ethernet.h>
57 #include <net/if_types.h>
58 #include <net/if_dl.h>
59 #include <net/if_vlan_var.h>
61 #include <net/rss_config.h>
63 #if defined(__i386__) || defined(__amd64__)
69 #include <ddb/db_lex.h>
72 #include "common/common.h"
73 #include "common/t4_msg.h"
74 #include "common/t4_regs.h"
75 #include "common/t4_regs_values.h"
76 #include "cudbg/cudbg.h"
79 #include "t4_mp_ring.h"
82 /* T4 bus driver interface */
83 static int t4_probe(device_t);
84 static int t4_attach(device_t);
85 static int t4_detach(device_t);
86 static int t4_ready(device_t);
87 static int t4_read_port_device(device_t, int, device_t *);
88 static device_method_t t4_methods[] = {
89 DEVMETHOD(device_probe, t4_probe),
90 DEVMETHOD(device_attach, t4_attach),
91 DEVMETHOD(device_detach, t4_detach),
93 DEVMETHOD(t4_is_main_ready, t4_ready),
94 DEVMETHOD(t4_read_port_device, t4_read_port_device),
98 static driver_t t4_driver = {
101 sizeof(struct adapter)
105 /* T4 port (cxgbe) interface */
106 static int cxgbe_probe(device_t);
107 static int cxgbe_attach(device_t);
108 static int cxgbe_detach(device_t);
109 device_method_t cxgbe_methods[] = {
110 DEVMETHOD(device_probe, cxgbe_probe),
111 DEVMETHOD(device_attach, cxgbe_attach),
112 DEVMETHOD(device_detach, cxgbe_detach),
115 static driver_t cxgbe_driver = {
118 sizeof(struct port_info)
121 /* T4 VI (vcxgbe) interface */
122 static int vcxgbe_probe(device_t);
123 static int vcxgbe_attach(device_t);
124 static int vcxgbe_detach(device_t);
125 static device_method_t vcxgbe_methods[] = {
126 DEVMETHOD(device_probe, vcxgbe_probe),
127 DEVMETHOD(device_attach, vcxgbe_attach),
128 DEVMETHOD(device_detach, vcxgbe_detach),
131 static driver_t vcxgbe_driver = {
134 sizeof(struct vi_info)
137 static d_ioctl_t t4_ioctl;
139 static struct cdevsw t4_cdevsw = {
140 .d_version = D_VERSION,
145 /* T5 bus driver interface */
146 static int t5_probe(device_t);
147 static device_method_t t5_methods[] = {
148 DEVMETHOD(device_probe, t5_probe),
149 DEVMETHOD(device_attach, t4_attach),
150 DEVMETHOD(device_detach, t4_detach),
152 DEVMETHOD(t4_is_main_ready, t4_ready),
153 DEVMETHOD(t4_read_port_device, t4_read_port_device),
157 static driver_t t5_driver = {
160 sizeof(struct adapter)
164 /* T5 port (cxl) interface */
165 static driver_t cxl_driver = {
168 sizeof(struct port_info)
171 /* T5 VI (vcxl) interface */
172 static driver_t vcxl_driver = {
175 sizeof(struct vi_info)
178 /* T6 bus driver interface */
179 static int t6_probe(device_t);
180 static device_method_t t6_methods[] = {
181 DEVMETHOD(device_probe, t6_probe),
182 DEVMETHOD(device_attach, t4_attach),
183 DEVMETHOD(device_detach, t4_detach),
185 DEVMETHOD(t4_is_main_ready, t4_ready),
186 DEVMETHOD(t4_read_port_device, t4_read_port_device),
190 static driver_t t6_driver = {
193 sizeof(struct adapter)
197 /* T6 port (cc) interface */
198 static driver_t cc_driver = {
201 sizeof(struct port_info)
204 /* T6 VI (vcc) interface */
205 static driver_t vcc_driver = {
208 sizeof(struct vi_info)
211 /* ifnet + media interface */
212 static void cxgbe_init(void *);
213 static int cxgbe_ioctl(struct ifnet *, unsigned long, caddr_t);
214 static int cxgbe_transmit(struct ifnet *, struct mbuf *);
215 static void cxgbe_qflush(struct ifnet *);
216 static int cxgbe_media_change(struct ifnet *);
217 static void cxgbe_media_status(struct ifnet *, struct ifmediareq *);
219 MALLOC_DEFINE(M_CXGBE, "cxgbe", "Chelsio T4/T5 Ethernet driver and services");
222 * Correct lock order when you need to acquire multiple locks is t4_list_lock,
223 * then ADAPTER_LOCK, then t4_uld_list_lock.
225 static struct sx t4_list_lock;
226 SLIST_HEAD(, adapter) t4_list;
228 static struct sx t4_uld_list_lock;
229 SLIST_HEAD(, uld_info) t4_uld_list;
233 * Tunables. See tweak_tunables() too.
235 * Each tunable is set to a default value here if it's known at compile-time.
236 * Otherwise it is set to -n as an indication to tweak_tunables() that it should
237 * provide a reasonable default (upto n) when the driver is loaded.
239 * Tunables applicable to both T4 and T5 are under hw.cxgbe. Those specific to
240 * T5 are under hw.cxl.
244 * Number of queues for tx and rx, NIC and offload.
248 TUNABLE_INT("hw.cxgbe.ntxq", &t4_ntxq);
249 TUNABLE_INT("hw.cxgbe.ntxq10g", &t4_ntxq); /* Old name, undocumented */
253 TUNABLE_INT("hw.cxgbe.nrxq", &t4_nrxq);
254 TUNABLE_INT("hw.cxgbe.nrxq10g", &t4_nrxq); /* Old name, undocumented */
257 static int t4_ntxq_vi = -NTXQ_VI;
258 TUNABLE_INT("hw.cxgbe.ntxq_vi", &t4_ntxq_vi);
261 static int t4_nrxq_vi = -NRXQ_VI;
262 TUNABLE_INT("hw.cxgbe.nrxq_vi", &t4_nrxq_vi);
264 static int t4_rsrv_noflowq = 0;
265 TUNABLE_INT("hw.cxgbe.rsrv_noflowq", &t4_rsrv_noflowq);
269 static int t4_nofldtxq = -NOFLDTXQ;
270 TUNABLE_INT("hw.cxgbe.nofldtxq", &t4_nofldtxq);
273 static int t4_nofldrxq = -NOFLDRXQ;
274 TUNABLE_INT("hw.cxgbe.nofldrxq", &t4_nofldrxq);
276 #define NOFLDTXQ_VI 1
277 static int t4_nofldtxq_vi = -NOFLDTXQ_VI;
278 TUNABLE_INT("hw.cxgbe.nofldtxq_vi", &t4_nofldtxq_vi);
280 #define NOFLDRXQ_VI 1
281 static int t4_nofldrxq_vi = -NOFLDRXQ_VI;
282 TUNABLE_INT("hw.cxgbe.nofldrxq_vi", &t4_nofldrxq_vi);
284 #define TMR_IDX_OFLD 1
285 int t4_tmr_idx_ofld = TMR_IDX_OFLD;
286 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_ofld", &t4_tmr_idx_ofld);
288 #define PKTC_IDX_OFLD (-1)
289 int t4_pktc_idx_ofld = PKTC_IDX_OFLD;
290 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_ofld", &t4_pktc_idx_ofld);
292 /* 0 means chip/fw default, non-zero number is value in microseconds */
293 static u_long t4_toe_keepalive_idle = 0;
294 TUNABLE_ULONG("hw.cxgbe.toe.keepalive_idle", &t4_toe_keepalive_idle);
296 /* 0 means chip/fw default, non-zero number is value in microseconds */
297 static u_long t4_toe_keepalive_interval = 0;
298 TUNABLE_ULONG("hw.cxgbe.toe.keepalive_interval", &t4_toe_keepalive_interval);
300 /* 0 means chip/fw default, non-zero number is # of keepalives before abort */
301 static int t4_toe_keepalive_count = 0;
302 TUNABLE_INT("hw.cxgbe.toe.keepalive_count", &t4_toe_keepalive_count);
304 /* 0 means chip/fw default, non-zero number is value in microseconds */
305 static u_long t4_toe_rexmt_min = 0;
306 TUNABLE_ULONG("hw.cxgbe.toe.rexmt_min", &t4_toe_rexmt_min);
308 /* 0 means chip/fw default, non-zero number is value in microseconds */
309 static u_long t4_toe_rexmt_max = 0;
310 TUNABLE_ULONG("hw.cxgbe.toe.rexmt_max", &t4_toe_rexmt_max);
312 /* 0 means chip/fw default, non-zero number is # of rexmt before abort */
313 static int t4_toe_rexmt_count = 0;
314 TUNABLE_INT("hw.cxgbe.toe.rexmt_count", &t4_toe_rexmt_count);
316 /* -1 means chip/fw default, other values are raw backoff values to use */
317 static int t4_toe_rexmt_backoff[16] = {
318 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
320 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.0", &t4_toe_rexmt_backoff[0]);
321 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.1", &t4_toe_rexmt_backoff[1]);
322 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.2", &t4_toe_rexmt_backoff[2]);
323 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.3", &t4_toe_rexmt_backoff[3]);
324 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.4", &t4_toe_rexmt_backoff[4]);
325 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.5", &t4_toe_rexmt_backoff[5]);
326 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.6", &t4_toe_rexmt_backoff[6]);
327 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.7", &t4_toe_rexmt_backoff[7]);
328 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.8", &t4_toe_rexmt_backoff[8]);
329 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.9", &t4_toe_rexmt_backoff[9]);
330 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.10", &t4_toe_rexmt_backoff[10]);
331 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.11", &t4_toe_rexmt_backoff[11]);
332 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.12", &t4_toe_rexmt_backoff[12]);
333 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.13", &t4_toe_rexmt_backoff[13]);
334 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.14", &t4_toe_rexmt_backoff[14]);
335 TUNABLE_INT("hw.cxgbe.toe.rexmt_backoff.15", &t4_toe_rexmt_backoff[15]);
340 static int t4_nnmtxq_vi = -NNMTXQ_VI;
341 TUNABLE_INT("hw.cxgbe.nnmtxq_vi", &t4_nnmtxq_vi);
344 static int t4_nnmrxq_vi = -NNMRXQ_VI;
345 TUNABLE_INT("hw.cxgbe.nnmrxq_vi", &t4_nnmrxq_vi);
349 * Holdoff parameters for ports.
352 int t4_tmr_idx = TMR_IDX;
353 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx", &t4_tmr_idx);
355 #define PKTC_IDX (-1)
356 int t4_pktc_idx = PKTC_IDX;
357 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx", &t4_pktc_idx);
360 * Size (# of entries) of each tx and rx queue.
362 unsigned int t4_qsize_txq = TX_EQ_QSIZE;
363 TUNABLE_INT("hw.cxgbe.qsize_txq", &t4_qsize_txq);
365 unsigned int t4_qsize_rxq = RX_IQ_QSIZE;
366 TUNABLE_INT("hw.cxgbe.qsize_rxq", &t4_qsize_rxq);
369 * Interrupt types allowed (bits 0, 1, 2 = INTx, MSI, MSI-X respectively).
371 int t4_intr_types = INTR_MSIX | INTR_MSI | INTR_INTX;
372 TUNABLE_INT("hw.cxgbe.interrupt_types", &t4_intr_types);
375 * Configuration file.
377 #define DEFAULT_CF "default"
378 #define FLASH_CF "flash"
379 #define UWIRE_CF "uwire"
380 #define FPGA_CF "fpga"
381 static char t4_cfg_file[32] = DEFAULT_CF;
382 TUNABLE_STR("hw.cxgbe.config_file", t4_cfg_file, sizeof(t4_cfg_file));
385 * PAUSE settings (bit 0, 1 = rx_pause, tx_pause respectively).
386 * rx_pause = 1 to heed incoming PAUSE frames, 0 to ignore them.
387 * tx_pause = 1 to emit PAUSE frames when the rx FIFO reaches its high water
388 * mark or when signalled to do so, 0 to never emit PAUSE.
390 static int t4_pause_settings = PAUSE_TX | PAUSE_RX;
391 TUNABLE_INT("hw.cxgbe.pause_settings", &t4_pause_settings);
394 * Forward Error Correction settings (bit 0, 1, 2 = FEC_RS, FEC_BASER_RS,
395 * FEC_RESERVED respectively).
396 * -1 to run with the firmware default.
399 static int t4_fec = -1;
400 TUNABLE_INT("hw.cxgbe.fec", &t4_fec);
403 * Link autonegotiation.
404 * -1 to run with the firmware default.
408 static int t4_autoneg = -1;
409 TUNABLE_INT("hw.cxgbe.autoneg", &t4_autoneg);
412 * Firmware auto-install by driver during attach (0, 1, 2 = prohibited, allowed,
413 * encouraged respectively).
415 static unsigned int t4_fw_install = 1;
416 TUNABLE_INT("hw.cxgbe.fw_install", &t4_fw_install);
419 * ASIC features that will be used. Disable the ones you don't want so that the
420 * chip resources aren't wasted on features that will not be used.
422 static int t4_nbmcaps_allowed = 0;
423 TUNABLE_INT("hw.cxgbe.nbmcaps_allowed", &t4_nbmcaps_allowed);
425 static int t4_linkcaps_allowed = 0; /* No DCBX, PPP, etc. by default */
426 TUNABLE_INT("hw.cxgbe.linkcaps_allowed", &t4_linkcaps_allowed);
428 static int t4_switchcaps_allowed = FW_CAPS_CONFIG_SWITCH_INGRESS |
429 FW_CAPS_CONFIG_SWITCH_EGRESS;
430 TUNABLE_INT("hw.cxgbe.switchcaps_allowed", &t4_switchcaps_allowed);
432 static int t4_niccaps_allowed = FW_CAPS_CONFIG_NIC;
433 TUNABLE_INT("hw.cxgbe.niccaps_allowed", &t4_niccaps_allowed);
435 static int t4_toecaps_allowed = -1;
436 TUNABLE_INT("hw.cxgbe.toecaps_allowed", &t4_toecaps_allowed);
438 static int t4_rdmacaps_allowed = -1;
439 TUNABLE_INT("hw.cxgbe.rdmacaps_allowed", &t4_rdmacaps_allowed);
441 static int t4_cryptocaps_allowed = -1;
442 TUNABLE_INT("hw.cxgbe.cryptocaps_allowed", &t4_cryptocaps_allowed);
444 static int t4_iscsicaps_allowed = -1;
445 TUNABLE_INT("hw.cxgbe.iscsicaps_allowed", &t4_iscsicaps_allowed);
447 static int t4_fcoecaps_allowed = 0;
448 TUNABLE_INT("hw.cxgbe.fcoecaps_allowed", &t4_fcoecaps_allowed);
450 static int t5_write_combine = 1;
451 TUNABLE_INT("hw.cxl.write_combine", &t5_write_combine);
453 static int t4_num_vis = 1;
454 TUNABLE_INT("hw.cxgbe.num_vis", &t4_num_vis);
456 /* Functions used by VIs to obtain unique MAC addresses for each VI. */
457 static int vi_mac_funcs[] = {
461 FW_VI_FUNC_OPENISCSI,
467 struct intrs_and_queues {
468 uint16_t intr_type; /* INTx, MSI, or MSI-X */
469 uint16_t num_vis; /* number of VIs for each port */
470 uint16_t nirq; /* Total # of vectors */
471 uint16_t intr_flags; /* Interrupt flags for each port */
472 uint16_t ntxq; /* # of NIC txq's for each port */
473 uint16_t nrxq; /* # of NIC rxq's for each port */
474 uint16_t nofldtxq; /* # of TOE txq's for each port */
475 uint16_t nofldrxq; /* # of TOE rxq's for each port */
477 /* The vcxgbe/vcxl interfaces use these and not the ones above. */
478 uint16_t ntxq_vi; /* # of NIC txq's */
479 uint16_t nrxq_vi; /* # of NIC rxq's */
480 uint16_t nofldtxq_vi; /* # of TOE txq's */
481 uint16_t nofldrxq_vi; /* # of TOE rxq's */
482 uint16_t nnmtxq_vi; /* # of netmap txq's */
483 uint16_t nnmrxq_vi; /* # of netmap rxq's */
486 struct filter_entry {
487 uint32_t valid:1; /* filter allocated and valid */
488 uint32_t locked:1; /* filter is administratively locked */
489 uint32_t pending:1; /* filter action is pending firmware reply */
490 uint32_t smtidx:8; /* Source MAC Table index for smac */
491 struct l2t_entry *l2t; /* Layer Two Table entry for dmac */
493 struct t4_filter_specification fs;
496 static void setup_memwin(struct adapter *);
497 static void position_memwin(struct adapter *, int, uint32_t);
498 static int rw_via_memwin(struct adapter *, int, uint32_t, uint32_t *, int, int);
499 static inline int read_via_memwin(struct adapter *, int, uint32_t, uint32_t *,
501 static inline int write_via_memwin(struct adapter *, int, uint32_t,
502 const uint32_t *, int);
503 static int validate_mem_range(struct adapter *, uint32_t, int);
504 static int fwmtype_to_hwmtype(int);
505 static int validate_mt_off_len(struct adapter *, int, uint32_t, int,
507 static int fixup_devlog_params(struct adapter *);
508 static int cfg_itype_and_nqueues(struct adapter *, struct intrs_and_queues *);
509 static int prep_firmware(struct adapter *);
510 static int partition_resources(struct adapter *, const struct firmware *,
512 static int get_params__pre_init(struct adapter *);
513 static int get_params__post_init(struct adapter *);
514 static int set_params__post_init(struct adapter *);
515 static void t4_set_desc(struct adapter *);
516 static void build_medialist(struct port_info *, struct ifmedia *);
517 static void init_l1cfg(struct port_info *);
518 static int cxgbe_init_synchronized(struct vi_info *);
519 static int cxgbe_uninit_synchronized(struct vi_info *);
520 static void quiesce_txq(struct adapter *, struct sge_txq *);
521 static void quiesce_wrq(struct adapter *, struct sge_wrq *);
522 static void quiesce_iq(struct adapter *, struct sge_iq *);
523 static void quiesce_fl(struct adapter *, struct sge_fl *);
524 static int t4_alloc_irq(struct adapter *, struct irq *, int rid,
525 driver_intr_t *, void *, char *);
526 static int t4_free_irq(struct adapter *, struct irq *);
527 static void get_regs(struct adapter *, struct t4_regdump *, uint8_t *);
528 static void vi_refresh_stats(struct adapter *, struct vi_info *);
529 static void cxgbe_refresh_stats(struct adapter *, struct port_info *);
530 static void cxgbe_tick(void *);
531 static void cxgbe_vlan_config(void *, struct ifnet *, uint16_t);
532 static void cxgbe_sysctls(struct port_info *);
533 static int sysctl_int_array(SYSCTL_HANDLER_ARGS);
534 static int sysctl_bitfield(SYSCTL_HANDLER_ARGS);
535 static int sysctl_btphy(SYSCTL_HANDLER_ARGS);
536 static int sysctl_noflowq(SYSCTL_HANDLER_ARGS);
537 static int sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS);
538 static int sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS);
539 static int sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS);
540 static int sysctl_qsize_txq(SYSCTL_HANDLER_ARGS);
541 static int sysctl_pause_settings(SYSCTL_HANDLER_ARGS);
542 static int sysctl_fec(SYSCTL_HANDLER_ARGS);
543 static int sysctl_autoneg(SYSCTL_HANDLER_ARGS);
544 static int sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS);
545 static int sysctl_temperature(SYSCTL_HANDLER_ARGS);
547 static int sysctl_cctrl(SYSCTL_HANDLER_ARGS);
548 static int sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS);
549 static int sysctl_cim_la(SYSCTL_HANDLER_ARGS);
550 static int sysctl_cim_la_t6(SYSCTL_HANDLER_ARGS);
551 static int sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS);
552 static int sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS);
553 static int sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS);
554 static int sysctl_cpl_stats(SYSCTL_HANDLER_ARGS);
555 static int sysctl_ddp_stats(SYSCTL_HANDLER_ARGS);
556 static int sysctl_devlog(SYSCTL_HANDLER_ARGS);
557 static int sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS);
558 static int sysctl_hw_sched(SYSCTL_HANDLER_ARGS);
559 static int sysctl_lb_stats(SYSCTL_HANDLER_ARGS);
560 static int sysctl_linkdnrc(SYSCTL_HANDLER_ARGS);
561 static int sysctl_meminfo(SYSCTL_HANDLER_ARGS);
562 static int sysctl_mps_tcam(SYSCTL_HANDLER_ARGS);
563 static int sysctl_mps_tcam_t6(SYSCTL_HANDLER_ARGS);
564 static int sysctl_path_mtus(SYSCTL_HANDLER_ARGS);
565 static int sysctl_pm_stats(SYSCTL_HANDLER_ARGS);
566 static int sysctl_rdma_stats(SYSCTL_HANDLER_ARGS);
567 static int sysctl_tcp_stats(SYSCTL_HANDLER_ARGS);
568 static int sysctl_tids(SYSCTL_HANDLER_ARGS);
569 static int sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS);
570 static int sysctl_tp_la_mask(SYSCTL_HANDLER_ARGS);
571 static int sysctl_tp_la(SYSCTL_HANDLER_ARGS);
572 static int sysctl_tx_rate(SYSCTL_HANDLER_ARGS);
573 static int sysctl_ulprx_la(SYSCTL_HANDLER_ARGS);
574 static int sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS);
575 static int sysctl_tc_params(SYSCTL_HANDLER_ARGS);
578 static int sysctl_tp_tick(SYSCTL_HANDLER_ARGS);
579 static int sysctl_tp_dack_timer(SYSCTL_HANDLER_ARGS);
580 static int sysctl_tp_timer(SYSCTL_HANDLER_ARGS);
581 static int sysctl_tp_shift_cnt(SYSCTL_HANDLER_ARGS);
582 static int sysctl_tp_backoff(SYSCTL_HANDLER_ARGS);
583 static int sysctl_holdoff_tmr_idx_ofld(SYSCTL_HANDLER_ARGS);
584 static int sysctl_holdoff_pktc_idx_ofld(SYSCTL_HANDLER_ARGS);
586 static uint32_t fconf_iconf_to_mode(uint32_t, uint32_t);
587 static uint32_t mode_to_fconf(uint32_t);
588 static uint32_t mode_to_iconf(uint32_t);
589 static int check_fspec_against_fconf_iconf(struct adapter *,
590 struct t4_filter_specification *);
591 static int get_filter_mode(struct adapter *, uint32_t *);
592 static int set_filter_mode(struct adapter *, uint32_t);
593 static inline uint64_t get_filter_hits(struct adapter *, uint32_t);
594 static int get_filter(struct adapter *, struct t4_filter *);
595 static int set_filter(struct adapter *, struct t4_filter *);
596 static int del_filter(struct adapter *, struct t4_filter *);
597 static void clear_filter(struct filter_entry *);
598 static int set_filter_wr(struct adapter *, int);
599 static int del_filter_wr(struct adapter *, int);
600 static int set_tcb_rpl(struct sge_iq *, const struct rss_header *,
602 static int get_sge_context(struct adapter *, struct t4_sge_context *);
603 static int load_fw(struct adapter *, struct t4_data *);
604 static int load_cfg(struct adapter *, struct t4_data *);
605 static int load_boot(struct adapter *, struct t4_bootrom *);
606 static int load_bootcfg(struct adapter *, struct t4_data *);
607 static int cudbg_dump(struct adapter *, struct t4_cudbg_dump *);
608 static int read_card_mem(struct adapter *, int, struct t4_mem_range *);
609 static int read_i2c(struct adapter *, struct t4_i2c_data *);
611 static int toe_capability(struct vi_info *, int);
613 static int mod_event(module_t, int, void *);
614 static int notify_siblings(device_t, int);
620 {0xa000, "Chelsio Terminator 4 FPGA"},
621 {0x4400, "Chelsio T440-dbg"},
622 {0x4401, "Chelsio T420-CR"},
623 {0x4402, "Chelsio T422-CR"},
624 {0x4403, "Chelsio T440-CR"},
625 {0x4404, "Chelsio T420-BCH"},
626 {0x4405, "Chelsio T440-BCH"},
627 {0x4406, "Chelsio T440-CH"},
628 {0x4407, "Chelsio T420-SO"},
629 {0x4408, "Chelsio T420-CX"},
630 {0x4409, "Chelsio T420-BT"},
631 {0x440a, "Chelsio T404-BT"},
632 {0x440e, "Chelsio T440-LP-CR"},
634 {0xb000, "Chelsio Terminator 5 FPGA"},
635 {0x5400, "Chelsio T580-dbg"},
636 {0x5401, "Chelsio T520-CR"}, /* 2 x 10G */
637 {0x5402, "Chelsio T522-CR"}, /* 2 x 10G, 2 X 1G */
638 {0x5403, "Chelsio T540-CR"}, /* 4 x 10G */
639 {0x5407, "Chelsio T520-SO"}, /* 2 x 10G, nomem */
640 {0x5409, "Chelsio T520-BT"}, /* 2 x 10GBaseT */
641 {0x540a, "Chelsio T504-BT"}, /* 4 x 1G */
642 {0x540d, "Chelsio T580-CR"}, /* 2 x 40G */
643 {0x540e, "Chelsio T540-LP-CR"}, /* 4 x 10G */
644 {0x5410, "Chelsio T580-LP-CR"}, /* 2 x 40G */
645 {0x5411, "Chelsio T520-LL-CR"}, /* 2 x 10G */
646 {0x5412, "Chelsio T560-CR"}, /* 1 x 40G, 2 x 10G */
647 {0x5414, "Chelsio T580-LP-SO-CR"}, /* 2 x 40G, nomem */
648 {0x5415, "Chelsio T502-BT"}, /* 2 x 1G */
650 {0x5404, "Chelsio T520-BCH"},
651 {0x5405, "Chelsio T540-BCH"},
652 {0x5406, "Chelsio T540-CH"},
653 {0x5408, "Chelsio T520-CX"},
654 {0x540b, "Chelsio B520-SR"},
655 {0x540c, "Chelsio B504-BT"},
656 {0x540f, "Chelsio Amsterdam"},
657 {0x5413, "Chelsio T580-CHR"},
660 {0xc006, "Chelsio Terminator 6 FPGA"}, /* T6 PE10K6 FPGA (PF0) */
661 {0x6400, "Chelsio T6-DBG-25"}, /* 2 x 10/25G, debug */
662 {0x6401, "Chelsio T6225-CR"}, /* 2 x 10/25G */
663 {0x6402, "Chelsio T6225-SO-CR"}, /* 2 x 10/25G, nomem */
664 {0x6403, "Chelsio T6425-CR"}, /* 4 x 10/25G */
665 {0x6404, "Chelsio T6425-SO-CR"}, /* 4 x 10/25G, nomem */
666 {0x6405, "Chelsio T6225-OCP-SO"}, /* 2 x 10/25G, nomem */
667 {0x6406, "Chelsio T62100-OCP-SO"}, /* 2 x 40/50/100G, nomem */
668 {0x6407, "Chelsio T62100-LP-CR"}, /* 2 x 40/50/100G */
669 {0x6408, "Chelsio T62100-SO-CR"}, /* 2 x 40/50/100G, nomem */
670 {0x6409, "Chelsio T6210-BT"}, /* 2 x 10GBASE-T */
671 {0x640d, "Chelsio T62100-CR"}, /* 2 x 40/50/100G */
672 {0x6410, "Chelsio T6-DBG-100"}, /* 2 x 40/50/100G, debug */
673 {0x6411, "Chelsio T6225-LL-CR"}, /* 2 x 10/25G */
674 {0x6414, "Chelsio T61100-OCP-SO"}, /* 1 x 40/50/100G, nomem */
675 {0x6415, "Chelsio T6201-BT"}, /* 2 x 1000BASE-T */
678 {0x6480, "Chelsio T6225 80"},
679 {0x6481, "Chelsio T62100 81"},
680 {0x6484, "Chelsio T62100 84"},
685 * service_iq() has an iq and needs the fl. Offset of fl from the iq should be
686 * exactly the same for both rxq and ofld_rxq.
688 CTASSERT(offsetof(struct sge_ofld_rxq, iq) == offsetof(struct sge_rxq, iq));
689 CTASSERT(offsetof(struct sge_ofld_rxq, fl) == offsetof(struct sge_rxq, fl));
691 CTASSERT(sizeof(struct cluster_metadata) <= CL_METADATA_SIZE);
694 t4_probe(device_t dev)
697 uint16_t v = pci_get_vendor(dev);
698 uint16_t d = pci_get_device(dev);
699 uint8_t f = pci_get_function(dev);
701 if (v != PCI_VENDOR_ID_CHELSIO)
704 /* Attach only to PF0 of the FPGA */
705 if (d == 0xa000 && f != 0)
708 for (i = 0; i < nitems(t4_pciids); i++) {
709 if (d == t4_pciids[i].device) {
710 device_set_desc(dev, t4_pciids[i].desc);
711 return (BUS_PROBE_DEFAULT);
719 t5_probe(device_t dev)
722 uint16_t v = pci_get_vendor(dev);
723 uint16_t d = pci_get_device(dev);
724 uint8_t f = pci_get_function(dev);
726 if (v != PCI_VENDOR_ID_CHELSIO)
729 /* Attach only to PF0 of the FPGA */
730 if (d == 0xb000 && f != 0)
733 for (i = 0; i < nitems(t5_pciids); i++) {
734 if (d == t5_pciids[i].device) {
735 device_set_desc(dev, t5_pciids[i].desc);
736 return (BUS_PROBE_DEFAULT);
744 t6_probe(device_t dev)
747 uint16_t v = pci_get_vendor(dev);
748 uint16_t d = pci_get_device(dev);
750 if (v != PCI_VENDOR_ID_CHELSIO)
753 for (i = 0; i < nitems(t6_pciids); i++) {
754 if (d == t6_pciids[i].device) {
755 device_set_desc(dev, t6_pciids[i].desc);
756 return (BUS_PROBE_DEFAULT);
764 t5_attribute_workaround(device_t dev)
770 * The T5 chips do not properly echo the No Snoop and Relaxed
771 * Ordering attributes when replying to a TLP from a Root
772 * Port. As a workaround, find the parent Root Port and
773 * disable No Snoop and Relaxed Ordering. Note that this
774 * affects all devices under this root port.
776 root_port = pci_find_pcie_root_port(dev);
777 if (root_port == NULL) {
778 device_printf(dev, "Unable to find parent root port\n");
782 v = pcie_adjust_config(root_port, PCIER_DEVICE_CTL,
783 PCIEM_CTL_RELAXED_ORD_ENABLE | PCIEM_CTL_NOSNOOP_ENABLE, 0, 2);
784 if ((v & (PCIEM_CTL_RELAXED_ORD_ENABLE | PCIEM_CTL_NOSNOOP_ENABLE)) !=
786 device_printf(dev, "Disabled No Snoop/Relaxed Ordering on %s\n",
787 device_get_nameunit(root_port));
790 static const struct devnames devnames[] = {
792 .nexus_name = "t4nex",
793 .ifnet_name = "cxgbe",
794 .vi_ifnet_name = "vcxgbe",
795 .pf03_drv_name = "t4iov",
796 .vf_nexus_name = "t4vf",
797 .vf_ifnet_name = "cxgbev"
799 .nexus_name = "t5nex",
801 .vi_ifnet_name = "vcxl",
802 .pf03_drv_name = "t5iov",
803 .vf_nexus_name = "t5vf",
804 .vf_ifnet_name = "cxlv"
806 .nexus_name = "t6nex",
808 .vi_ifnet_name = "vcc",
809 .pf03_drv_name = "t6iov",
810 .vf_nexus_name = "t6vf",
811 .vf_ifnet_name = "ccv"
816 t4_init_devnames(struct adapter *sc)
821 if (id >= CHELSIO_T4 && id - CHELSIO_T4 < nitems(devnames))
822 sc->names = &devnames[id - CHELSIO_T4];
824 device_printf(sc->dev, "chip id %d is not supported.\n", id);
830 t4_attach(device_t dev)
833 int rc = 0, i, j, rqidx, tqidx, nports;
834 struct make_dev_args mda;
835 struct intrs_and_queues iaq;
839 int ofld_rqidx, ofld_tqidx;
842 int nm_rqidx, nm_tqidx;
846 sc = device_get_softc(dev);
848 TUNABLE_INT_FETCH("hw.cxgbe.dflags", &sc->debug_flags);
850 if ((pci_get_device(dev) & 0xff00) == 0x5400)
851 t5_attribute_workaround(dev);
852 pci_enable_busmaster(dev);
853 if (pci_find_cap(dev, PCIY_EXPRESS, &i) == 0) {
856 pci_set_max_read_req(dev, 4096);
857 v = pci_read_config(dev, i + PCIER_DEVICE_CTL, 2);
858 v |= PCIEM_CTL_RELAXED_ORD_ENABLE;
859 pci_write_config(dev, i + PCIER_DEVICE_CTL, v, 2);
861 sc->params.pci.mps = 128 << ((v & PCIEM_CTL_MAX_PAYLOAD) >> 5);
864 sc->sge_gts_reg = MYPF_REG(A_SGE_PF_GTS);
865 sc->sge_kdoorbell_reg = MYPF_REG(A_SGE_PF_KDOORBELL);
867 mtx_init(&sc->ifp_lock, sc->ifp_lockname, 0, MTX_DEF);
868 snprintf(sc->ifp_lockname, sizeof(sc->ifp_lockname), "%s tracer",
869 device_get_nameunit(dev));
871 snprintf(sc->lockname, sizeof(sc->lockname), "%s",
872 device_get_nameunit(dev));
873 mtx_init(&sc->sc_lock, sc->lockname, 0, MTX_DEF);
876 mtx_init(&sc->sfl_lock, "starving freelists", 0, MTX_DEF);
877 TAILQ_INIT(&sc->sfl);
878 callout_init_mtx(&sc->sfl_callout, &sc->sfl_lock, 0);
880 mtx_init(&sc->reg_lock, "indirect register access", 0, MTX_DEF);
882 rc = t4_map_bars_0_and_4(sc);
884 goto done; /* error message displayed already */
886 memset(sc->chan_map, 0xff, sizeof(sc->chan_map));
888 /* Prepare the adapter for operation. */
889 buf = malloc(PAGE_SIZE, M_CXGBE, M_ZERO | M_WAITOK);
890 rc = -t4_prep_adapter(sc, buf);
893 device_printf(dev, "failed to prepare adapter: %d.\n", rc);
898 * This is the real PF# to which we're attaching. Works from within PCI
899 * passthrough environments too, where pci_get_function() could return a
900 * different PF# depending on the passthrough configuration. We need to
901 * use the real PF# in all our communication with the firmware.
903 j = t4_read_reg(sc, A_PL_WHOAMI);
904 sc->pf = chip_id(sc) <= CHELSIO_T5 ? G_SOURCEPF(j) : G_T6_SOURCEPF(j);
907 t4_init_devnames(sc);
908 if (sc->names == NULL) {
910 goto done; /* error message displayed already */
914 * Do this really early, with the memory windows set up even before the
915 * character device. The userland tool's register i/o and mem read
916 * will work even in "recovery mode".
919 if (t4_init_devlog_params(sc, 0) == 0)
920 fixup_devlog_params(sc);
921 make_dev_args_init(&mda);
922 mda.mda_devsw = &t4_cdevsw;
923 mda.mda_uid = UID_ROOT;
924 mda.mda_gid = GID_WHEEL;
926 mda.mda_si_drv1 = sc;
927 rc = make_dev_s(&mda, &sc->cdev, "%s", device_get_nameunit(dev));
929 device_printf(dev, "failed to create nexus char device: %d.\n",
932 /* Go no further if recovery mode has been requested. */
933 if (TUNABLE_INT_FETCH("hw.cxgbe.sos", &i) && i != 0) {
934 device_printf(dev, "recovery mode.\n");
938 #if defined(__i386__)
939 if ((cpu_feature & CPUID_CX8) == 0) {
940 device_printf(dev, "64 bit atomics not available.\n");
946 /* Prepare the firmware for operation */
947 rc = prep_firmware(sc);
949 goto done; /* error message displayed already */
951 rc = get_params__post_init(sc);
953 goto done; /* error message displayed already */
955 rc = set_params__post_init(sc);
957 goto done; /* error message displayed already */
959 rc = t4_map_bar_2(sc);
961 goto done; /* error message displayed already */
963 rc = t4_create_dma_tag(sc);
965 goto done; /* error message displayed already */
968 * First pass over all the ports - allocate VIs and initialize some
969 * basic parameters like mac address, port type, etc.
971 for_each_port(sc, i) {
972 struct port_info *pi;
974 pi = malloc(sizeof(*pi), M_CXGBE, M_ZERO | M_WAITOK);
977 /* These must be set before t4_port_init */
981 * XXX: vi[0] is special so we can't delay this allocation until
982 * pi->nvi's final value is known.
984 pi->vi = malloc(sizeof(struct vi_info) * t4_num_vis, M_CXGBE,
988 * Allocate the "main" VI and initialize parameters
991 rc = -t4_port_init(sc, sc->mbox, sc->pf, 0, i);
993 device_printf(dev, "unable to initialize port %d: %d\n",
995 free(pi->vi, M_CXGBE);
1001 snprintf(pi->lockname, sizeof(pi->lockname), "%sp%d",
1002 device_get_nameunit(dev), i);
1003 mtx_init(&pi->pi_lock, pi->lockname, 0, MTX_DEF);
1004 sc->chan_map[pi->tx_chan] = i;
1006 /* All VIs on this port share this media. */
1007 ifmedia_init(&pi->media, IFM_IMASK, cxgbe_media_change,
1008 cxgbe_media_status);
1010 pi->dev = device_add_child(dev, sc->names->ifnet_name, -1);
1011 if (pi->dev == NULL) {
1013 "failed to add device for port %d.\n", i);
1017 pi->vi[0].dev = pi->dev;
1018 device_set_softc(pi->dev, pi);
1022 * Interrupt type, # of interrupts, # of rx/tx queues, etc.
1024 nports = sc->params.nports;
1025 rc = cfg_itype_and_nqueues(sc, &iaq);
1027 goto done; /* error message displayed already */
1029 num_vis = iaq.num_vis;
1030 sc->intr_type = iaq.intr_type;
1031 sc->intr_count = iaq.nirq;
1034 s->nrxq = nports * iaq.nrxq;
1035 s->ntxq = nports * iaq.ntxq;
1037 s->nrxq += nports * (num_vis - 1) * iaq.nrxq_vi;
1038 s->ntxq += nports * (num_vis - 1) * iaq.ntxq_vi;
1040 s->neq = s->ntxq + s->nrxq; /* the free list in an rxq is an eq */
1041 s->neq += nports + 1;/* ctrl queues: 1 per port + 1 mgmt */
1042 s->niq = s->nrxq + 1; /* 1 extra for firmware event queue */
1044 if (is_offload(sc)) {
1045 s->nofldrxq = nports * iaq.nofldrxq;
1046 s->nofldtxq = nports * iaq.nofldtxq;
1048 s->nofldrxq += nports * (num_vis - 1) * iaq.nofldrxq_vi;
1049 s->nofldtxq += nports * (num_vis - 1) * iaq.nofldtxq_vi;
1051 s->neq += s->nofldtxq + s->nofldrxq;
1052 s->niq += s->nofldrxq;
1054 s->ofld_rxq = malloc(s->nofldrxq * sizeof(struct sge_ofld_rxq),
1055 M_CXGBE, M_ZERO | M_WAITOK);
1056 s->ofld_txq = malloc(s->nofldtxq * sizeof(struct sge_wrq),
1057 M_CXGBE, M_ZERO | M_WAITOK);
1062 s->nnmrxq = nports * (num_vis - 1) * iaq.nnmrxq_vi;
1063 s->nnmtxq = nports * (num_vis - 1) * iaq.nnmtxq_vi;
1065 s->neq += s->nnmtxq + s->nnmrxq;
1066 s->niq += s->nnmrxq;
1068 s->nm_rxq = malloc(s->nnmrxq * sizeof(struct sge_nm_rxq),
1069 M_CXGBE, M_ZERO | M_WAITOK);
1070 s->nm_txq = malloc(s->nnmtxq * sizeof(struct sge_nm_txq),
1071 M_CXGBE, M_ZERO | M_WAITOK);
1074 s->ctrlq = malloc(nports * sizeof(struct sge_wrq), M_CXGBE,
1076 s->rxq = malloc(s->nrxq * sizeof(struct sge_rxq), M_CXGBE,
1078 s->txq = malloc(s->ntxq * sizeof(struct sge_txq), M_CXGBE,
1080 s->iqmap = malloc(s->niq * sizeof(struct sge_iq *), M_CXGBE,
1082 s->eqmap = malloc(s->neq * sizeof(struct sge_eq *), M_CXGBE,
1085 sc->irq = malloc(sc->intr_count * sizeof(struct irq), M_CXGBE,
1088 t4_init_l2t(sc, M_WAITOK);
1089 t4_init_tx_sched(sc);
1092 * Second pass over the ports. This time we know the number of rx and
1093 * tx queues that each port should get.
1097 ofld_rqidx = ofld_tqidx = 0;
1100 nm_rqidx = nm_tqidx = 0;
1102 for_each_port(sc, i) {
1103 struct port_info *pi = sc->port[i];
1110 for_each_vi(pi, j, vi) {
1112 vi->qsize_rxq = t4_qsize_rxq;
1113 vi->qsize_txq = t4_qsize_txq;
1115 vi->first_rxq = rqidx;
1116 vi->first_txq = tqidx;
1117 vi->tmr_idx = t4_tmr_idx;
1118 vi->pktc_idx = t4_pktc_idx;
1119 vi->flags |= iaq.intr_flags & INTR_RXQ;
1120 vi->nrxq = j == 0 ? iaq.nrxq : iaq.nrxq_vi;
1121 vi->ntxq = j == 0 ? iaq.ntxq : iaq.ntxq_vi;
1126 if (j == 0 && vi->ntxq > 1)
1127 vi->rsrv_noflowq = t4_rsrv_noflowq ? 1 : 0;
1129 vi->rsrv_noflowq = 0;
1132 vi->ofld_tmr_idx = t4_tmr_idx_ofld;
1133 vi->ofld_pktc_idx = t4_pktc_idx_ofld;
1134 vi->first_ofld_rxq = ofld_rqidx;
1135 vi->first_ofld_txq = ofld_tqidx;
1136 vi->flags |= iaq.intr_flags & INTR_OFLD_RXQ;
1137 vi->nofldrxq = j == 0 ? iaq.nofldrxq : iaq.nofldrxq_vi;
1138 vi->nofldtxq = j == 0 ? iaq.nofldtxq : iaq.nofldtxq_vi;
1140 ofld_rqidx += vi->nofldrxq;
1141 ofld_tqidx += vi->nofldtxq;
1145 vi->first_nm_rxq = nm_rqidx;
1146 vi->first_nm_txq = nm_tqidx;
1147 vi->nnmrxq = iaq.nnmrxq_vi;
1148 vi->nnmtxq = iaq.nnmtxq_vi;
1149 nm_rqidx += vi->nnmrxq;
1150 nm_tqidx += vi->nnmtxq;
1156 rc = t4_setup_intr_handlers(sc);
1159 "failed to setup interrupt handlers: %d\n", rc);
1163 rc = bus_generic_probe(dev);
1165 device_printf(dev, "failed to probe child drivers: %d\n", rc);
1170 * Ensure thread-safe mailbox access (in debug builds).
1172 * So far this was the only thread accessing the mailbox but various
1173 * ifnets and sysctls are about to be created and their handlers/ioctls
1174 * will access the mailbox from different threads.
1176 sc->flags |= CHK_MBOX_ACCESS;
1178 rc = bus_generic_attach(dev);
1181 "failed to attach all child ports: %d\n", rc);
1186 "PCIe gen%d x%d, %d ports, %d %s interrupt%s, %d eq, %d iq\n",
1187 sc->params.pci.speed, sc->params.pci.width, sc->params.nports,
1188 sc->intr_count, sc->intr_type == INTR_MSIX ? "MSI-X" :
1189 (sc->intr_type == INTR_MSI ? "MSI" : "INTx"),
1190 sc->intr_count > 1 ? "s" : "", sc->sge.neq, sc->sge.niq);
1194 notify_siblings(dev, 0);
1197 if (rc != 0 && sc->cdev) {
1198 /* cdev was created and so cxgbetool works; recover that way. */
1200 "error during attach, adapter is now in recovery mode.\n");
1205 t4_detach_common(dev);
1213 t4_ready(device_t dev)
1217 sc = device_get_softc(dev);
1218 if (sc->flags & FW_OK)
1224 t4_read_port_device(device_t dev, int port, device_t *child)
1227 struct port_info *pi;
1229 sc = device_get_softc(dev);
1230 if (port < 0 || port >= MAX_NPORTS)
1232 pi = sc->port[port];
1233 if (pi == NULL || pi->dev == NULL)
1240 notify_siblings(device_t dev, int detaching)
1246 for (i = 0; i < PCI_FUNCMAX; i++) {
1247 if (i == pci_get_function(dev))
1249 sibling = pci_find_dbsf(pci_get_domain(dev), pci_get_bus(dev),
1250 pci_get_slot(dev), i);
1251 if (sibling == NULL || !device_is_attached(sibling))
1254 error = T4_DETACH_CHILD(sibling);
1256 (void)T4_ATTACH_CHILD(sibling);
1267 t4_detach(device_t dev)
1272 sc = device_get_softc(dev);
1274 rc = notify_siblings(dev, 1);
1277 "failed to detach sibling devices: %d\n", rc);
1281 return (t4_detach_common(dev));
1285 t4_detach_common(device_t dev)
1288 struct port_info *pi;
1291 sc = device_get_softc(dev);
1293 sc->flags &= ~CHK_MBOX_ACCESS;
1294 if (sc->flags & FULL_INIT_DONE) {
1295 if (!(sc->flags & IS_VF))
1296 t4_intr_disable(sc);
1300 destroy_dev(sc->cdev);
1304 if (device_is_attached(dev)) {
1305 rc = bus_generic_detach(dev);
1308 "failed to detach child devices: %d\n", rc);
1313 for (i = 0; i < sc->intr_count; i++)
1314 t4_free_irq(sc, &sc->irq[i]);
1316 if ((sc->flags & (IS_VF | FW_OK)) == FW_OK)
1317 t4_free_tx_sched(sc);
1319 for (i = 0; i < MAX_NPORTS; i++) {
1322 t4_free_vi(sc, sc->mbox, sc->pf, 0, pi->vi[0].viid);
1324 device_delete_child(dev, pi->dev);
1326 mtx_destroy(&pi->pi_lock);
1327 free(pi->vi, M_CXGBE);
1332 device_delete_children(dev);
1334 if (sc->flags & FULL_INIT_DONE)
1335 adapter_full_uninit(sc);
1337 if ((sc->flags & (IS_VF | FW_OK)) == FW_OK)
1338 t4_fw_bye(sc, sc->mbox);
1340 if (sc->intr_type == INTR_MSI || sc->intr_type == INTR_MSIX)
1341 pci_release_msi(dev);
1344 bus_release_resource(dev, SYS_RES_MEMORY, sc->regs_rid,
1348 bus_release_resource(dev, SYS_RES_MEMORY, sc->udbs_rid,
1352 bus_release_resource(dev, SYS_RES_MEMORY, sc->msix_rid,
1356 t4_free_l2t(sc->l2t);
1359 free(sc->sge.ofld_rxq, M_CXGBE);
1360 free(sc->sge.ofld_txq, M_CXGBE);
1363 free(sc->sge.nm_rxq, M_CXGBE);
1364 free(sc->sge.nm_txq, M_CXGBE);
1366 free(sc->irq, M_CXGBE);
1367 free(sc->sge.rxq, M_CXGBE);
1368 free(sc->sge.txq, M_CXGBE);
1369 free(sc->sge.ctrlq, M_CXGBE);
1370 free(sc->sge.iqmap, M_CXGBE);
1371 free(sc->sge.eqmap, M_CXGBE);
1372 free(sc->tids.ftid_tab, M_CXGBE);
1373 t4_destroy_dma_tag(sc);
1374 if (mtx_initialized(&sc->sc_lock)) {
1375 sx_xlock(&t4_list_lock);
1376 SLIST_REMOVE(&t4_list, sc, adapter, link);
1377 sx_xunlock(&t4_list_lock);
1378 mtx_destroy(&sc->sc_lock);
1381 callout_drain(&sc->sfl_callout);
1382 if (mtx_initialized(&sc->tids.ftid_lock))
1383 mtx_destroy(&sc->tids.ftid_lock);
1384 if (mtx_initialized(&sc->sfl_lock))
1385 mtx_destroy(&sc->sfl_lock);
1386 if (mtx_initialized(&sc->ifp_lock))
1387 mtx_destroy(&sc->ifp_lock);
1388 if (mtx_initialized(&sc->reg_lock))
1389 mtx_destroy(&sc->reg_lock);
1391 for (i = 0; i < NUM_MEMWIN; i++) {
1392 struct memwin *mw = &sc->memwin[i];
1394 if (rw_initialized(&mw->mw_lock))
1395 rw_destroy(&mw->mw_lock);
1398 bzero(sc, sizeof(*sc));
1404 cxgbe_probe(device_t dev)
1407 struct port_info *pi = device_get_softc(dev);
1409 snprintf(buf, sizeof(buf), "port %d", pi->port_id);
1410 device_set_desc_copy(dev, buf);
1412 return (BUS_PROBE_DEFAULT);
1415 #define T4_CAP (IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_HWCSUM | \
1416 IFCAP_VLAN_HWCSUM | IFCAP_TSO | IFCAP_JUMBO_MTU | IFCAP_LRO | \
1417 IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWCSUM_IPV6 | IFCAP_HWSTATS)
1418 #define T4_CAP_ENABLE (T4_CAP)
1421 cxgbe_vi_attach(device_t dev, struct vi_info *vi)
1426 vi->xact_addr_filt = -1;
1427 callout_init(&vi->tick, 1);
1429 /* Allocate an ifnet and set it up */
1430 ifp = if_alloc(IFT_ETHER);
1432 device_printf(dev, "Cannot allocate ifnet\n");
1438 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1439 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1441 ifp->if_init = cxgbe_init;
1442 ifp->if_ioctl = cxgbe_ioctl;
1443 ifp->if_transmit = cxgbe_transmit;
1444 ifp->if_qflush = cxgbe_qflush;
1445 ifp->if_get_counter = cxgbe_get_counter;
1447 ifp->if_capabilities = T4_CAP;
1449 if (vi->nofldrxq != 0)
1450 ifp->if_capabilities |= IFCAP_TOE;
1453 if (vi->nnmrxq != 0)
1454 ifp->if_capabilities |= IFCAP_NETMAP;
1456 ifp->if_capenable = T4_CAP_ENABLE;
1457 ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_IP | CSUM_TSO |
1458 CSUM_UDP_IPV6 | CSUM_TCP_IPV6;
1460 ifp->if_hw_tsomax = 65536 - (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
1461 ifp->if_hw_tsomaxsegcount = TX_SGL_SEGS;
1462 ifp->if_hw_tsomaxsegsize = 65536;
1464 vi->vlan_c = EVENTHANDLER_REGISTER(vlan_config, cxgbe_vlan_config, ifp,
1465 EVENTHANDLER_PRI_ANY);
1467 ether_ifattach(ifp, vi->hw_addr);
1469 if (ifp->if_capabilities & IFCAP_NETMAP)
1470 cxgbe_nm_attach(vi);
1472 sb = sbuf_new_auto();
1473 sbuf_printf(sb, "%d txq, %d rxq (NIC)", vi->ntxq, vi->nrxq);
1475 if (ifp->if_capabilities & IFCAP_TOE)
1476 sbuf_printf(sb, "; %d txq, %d rxq (TOE)",
1477 vi->nofldtxq, vi->nofldrxq);
1480 if (ifp->if_capabilities & IFCAP_NETMAP)
1481 sbuf_printf(sb, "; %d txq, %d rxq (netmap)",
1482 vi->nnmtxq, vi->nnmrxq);
1485 device_printf(dev, "%s\n", sbuf_data(sb));
1494 cxgbe_attach(device_t dev)
1496 struct port_info *pi = device_get_softc(dev);
1497 struct adapter *sc = pi->adapter;
1501 callout_init_mtx(&pi->tick, &pi->pi_lock, 0);
1503 rc = cxgbe_vi_attach(dev, &pi->vi[0]);
1507 for_each_vi(pi, i, vi) {
1510 vi->dev = device_add_child(dev, sc->names->vi_ifnet_name, -1);
1511 if (vi->dev == NULL) {
1512 device_printf(dev, "failed to add VI %d\n", i);
1515 device_set_softc(vi->dev, vi);
1520 bus_generic_attach(dev);
1526 cxgbe_vi_detach(struct vi_info *vi)
1528 struct ifnet *ifp = vi->ifp;
1530 ether_ifdetach(ifp);
1533 EVENTHANDLER_DEREGISTER(vlan_config, vi->vlan_c);
1535 /* Let detach proceed even if these fail. */
1537 if (ifp->if_capabilities & IFCAP_NETMAP)
1538 cxgbe_nm_detach(vi);
1540 cxgbe_uninit_synchronized(vi);
1541 callout_drain(&vi->tick);
1549 cxgbe_detach(device_t dev)
1551 struct port_info *pi = device_get_softc(dev);
1552 struct adapter *sc = pi->adapter;
1555 /* Detach the extra VIs first. */
1556 rc = bus_generic_detach(dev);
1559 device_delete_children(dev);
1561 doom_vi(sc, &pi->vi[0]);
1563 if (pi->flags & HAS_TRACEQ) {
1564 sc->traceq = -1; /* cloner should not create ifnet */
1565 t4_tracer_port_detach(sc);
1568 cxgbe_vi_detach(&pi->vi[0]);
1569 callout_drain(&pi->tick);
1570 ifmedia_removeall(&pi->media);
1572 end_synchronized_op(sc, 0);
1578 cxgbe_init(void *arg)
1580 struct vi_info *vi = arg;
1581 struct adapter *sc = vi->pi->adapter;
1583 if (begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4init") != 0)
1585 cxgbe_init_synchronized(vi);
1586 end_synchronized_op(sc, 0);
1590 cxgbe_ioctl(struct ifnet *ifp, unsigned long cmd, caddr_t data)
1592 int rc = 0, mtu, flags, can_sleep;
1593 struct vi_info *vi = ifp->if_softc;
1594 struct port_info *pi = vi->pi;
1595 struct adapter *sc = pi->adapter;
1596 struct ifreq *ifr = (struct ifreq *)data;
1602 if (mtu < ETHERMIN || mtu > MAX_MTU)
1605 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4mtu");
1609 if (vi->flags & VI_INIT_DONE) {
1610 t4_update_fl_bufsize(ifp);
1611 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1612 rc = update_mac_settings(ifp, XGMAC_MTU);
1614 end_synchronized_op(sc, 0);
1620 rc = begin_synchronized_op(sc, vi,
1621 can_sleep ? (SLEEP_OK | INTR_OK) : HOLD_LOCK, "t4flg");
1625 if (ifp->if_flags & IFF_UP) {
1626 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1627 flags = vi->if_flags;
1628 if ((ifp->if_flags ^ flags) &
1629 (IFF_PROMISC | IFF_ALLMULTI)) {
1630 if (can_sleep == 1) {
1631 end_synchronized_op(sc, 0);
1635 rc = update_mac_settings(ifp,
1636 XGMAC_PROMISC | XGMAC_ALLMULTI);
1639 if (can_sleep == 0) {
1640 end_synchronized_op(sc, LOCK_HELD);
1644 rc = cxgbe_init_synchronized(vi);
1646 vi->if_flags = ifp->if_flags;
1647 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1648 if (can_sleep == 0) {
1649 end_synchronized_op(sc, LOCK_HELD);
1653 rc = cxgbe_uninit_synchronized(vi);
1655 end_synchronized_op(sc, can_sleep ? 0 : LOCK_HELD);
1659 case SIOCDELMULTI: /* these two are called with a mutex held :-( */
1660 rc = begin_synchronized_op(sc, vi, HOLD_LOCK, "t4multi");
1663 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1664 rc = update_mac_settings(ifp, XGMAC_MCADDRS);
1665 end_synchronized_op(sc, LOCK_HELD);
1669 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4cap");
1673 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1674 if (mask & IFCAP_TXCSUM) {
1675 ifp->if_capenable ^= IFCAP_TXCSUM;
1676 ifp->if_hwassist ^= (CSUM_TCP | CSUM_UDP | CSUM_IP);
1678 if (IFCAP_TSO4 & ifp->if_capenable &&
1679 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1680 ifp->if_capenable &= ~IFCAP_TSO4;
1682 "tso4 disabled due to -txcsum.\n");
1685 if (mask & IFCAP_TXCSUM_IPV6) {
1686 ifp->if_capenable ^= IFCAP_TXCSUM_IPV6;
1687 ifp->if_hwassist ^= (CSUM_UDP_IPV6 | CSUM_TCP_IPV6);
1689 if (IFCAP_TSO6 & ifp->if_capenable &&
1690 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1691 ifp->if_capenable &= ~IFCAP_TSO6;
1693 "tso6 disabled due to -txcsum6.\n");
1696 if (mask & IFCAP_RXCSUM)
1697 ifp->if_capenable ^= IFCAP_RXCSUM;
1698 if (mask & IFCAP_RXCSUM_IPV6)
1699 ifp->if_capenable ^= IFCAP_RXCSUM_IPV6;
1702 * Note that we leave CSUM_TSO alone (it is always set). The
1703 * kernel takes both IFCAP_TSOx and CSUM_TSO into account before
1704 * sending a TSO request our way, so it's sufficient to toggle
1707 if (mask & IFCAP_TSO4) {
1708 if (!(IFCAP_TSO4 & ifp->if_capenable) &&
1709 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1710 if_printf(ifp, "enable txcsum first.\n");
1714 ifp->if_capenable ^= IFCAP_TSO4;
1716 if (mask & IFCAP_TSO6) {
1717 if (!(IFCAP_TSO6 & ifp->if_capenable) &&
1718 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1719 if_printf(ifp, "enable txcsum6 first.\n");
1723 ifp->if_capenable ^= IFCAP_TSO6;
1725 if (mask & IFCAP_LRO) {
1726 #if defined(INET) || defined(INET6)
1728 struct sge_rxq *rxq;
1730 ifp->if_capenable ^= IFCAP_LRO;
1731 for_each_rxq(vi, i, rxq) {
1732 if (ifp->if_capenable & IFCAP_LRO)
1733 rxq->iq.flags |= IQ_LRO_ENABLED;
1735 rxq->iq.flags &= ~IQ_LRO_ENABLED;
1740 if (mask & IFCAP_TOE) {
1741 int enable = (ifp->if_capenable ^ mask) & IFCAP_TOE;
1743 rc = toe_capability(vi, enable);
1747 ifp->if_capenable ^= mask;
1750 if (mask & IFCAP_VLAN_HWTAGGING) {
1751 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
1752 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1753 rc = update_mac_settings(ifp, XGMAC_VLANEX);
1755 if (mask & IFCAP_VLAN_MTU) {
1756 ifp->if_capenable ^= IFCAP_VLAN_MTU;
1758 /* Need to find out how to disable auto-mtu-inflation */
1760 if (mask & IFCAP_VLAN_HWTSO)
1761 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
1762 if (mask & IFCAP_VLAN_HWCSUM)
1763 ifp->if_capenable ^= IFCAP_VLAN_HWCSUM;
1765 #ifdef VLAN_CAPABILITIES
1766 VLAN_CAPABILITIES(ifp);
1769 end_synchronized_op(sc, 0);
1775 ifmedia_ioctl(ifp, ifr, &pi->media, cmd);
1779 struct ifi2creq i2c;
1781 rc = copyin(ifr->ifr_data, &i2c, sizeof(i2c));
1784 if (i2c.dev_addr != 0xA0 && i2c.dev_addr != 0xA2) {
1788 if (i2c.len > sizeof(i2c.data)) {
1792 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4i2c");
1795 rc = -t4_i2c_rd(sc, sc->mbox, pi->port_id, i2c.dev_addr,
1796 i2c.offset, i2c.len, &i2c.data[0]);
1797 end_synchronized_op(sc, 0);
1799 rc = copyout(&i2c, ifr->ifr_data, sizeof(i2c));
1804 rc = ether_ioctl(ifp, cmd, data);
1811 cxgbe_transmit(struct ifnet *ifp, struct mbuf *m)
1813 struct vi_info *vi = ifp->if_softc;
1814 struct port_info *pi = vi->pi;
1815 struct adapter *sc = pi->adapter;
1816 struct sge_txq *txq;
1821 MPASS(m->m_nextpkt == NULL); /* not quite ready for this yet */
1823 if (__predict_false(pi->link_cfg.link_ok == 0)) {
1828 rc = parse_pkt(sc, &m);
1829 if (__predict_false(rc != 0)) {
1830 MPASS(m == NULL); /* was freed already */
1831 atomic_add_int(&pi->tx_parse_error, 1); /* rare, atomic is ok */
1836 txq = &sc->sge.txq[vi->first_txq];
1837 if (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE)
1838 txq += ((m->m_pkthdr.flowid % (vi->ntxq - vi->rsrv_noflowq)) +
1842 rc = mp_ring_enqueue(txq->r, items, 1, 4096);
1843 if (__predict_false(rc != 0))
1850 cxgbe_qflush(struct ifnet *ifp)
1852 struct vi_info *vi = ifp->if_softc;
1853 struct sge_txq *txq;
1856 /* queues do not exist if !VI_INIT_DONE. */
1857 if (vi->flags & VI_INIT_DONE) {
1858 for_each_txq(vi, i, txq) {
1860 txq->eq.flags |= EQ_QFLUSH;
1862 while (!mp_ring_is_idle(txq->r)) {
1863 mp_ring_check_drainage(txq->r, 0);
1867 txq->eq.flags &= ~EQ_QFLUSH;
1875 vi_get_counter(struct ifnet *ifp, ift_counter c)
1877 struct vi_info *vi = ifp->if_softc;
1878 struct fw_vi_stats_vf *s = &vi->stats;
1880 vi_refresh_stats(vi->pi->adapter, vi);
1883 case IFCOUNTER_IPACKETS:
1884 return (s->rx_bcast_frames + s->rx_mcast_frames +
1885 s->rx_ucast_frames);
1886 case IFCOUNTER_IERRORS:
1887 return (s->rx_err_frames);
1888 case IFCOUNTER_OPACKETS:
1889 return (s->tx_bcast_frames + s->tx_mcast_frames +
1890 s->tx_ucast_frames + s->tx_offload_frames);
1891 case IFCOUNTER_OERRORS:
1892 return (s->tx_drop_frames);
1893 case IFCOUNTER_IBYTES:
1894 return (s->rx_bcast_bytes + s->rx_mcast_bytes +
1896 case IFCOUNTER_OBYTES:
1897 return (s->tx_bcast_bytes + s->tx_mcast_bytes +
1898 s->tx_ucast_bytes + s->tx_offload_bytes);
1899 case IFCOUNTER_IMCASTS:
1900 return (s->rx_mcast_frames);
1901 case IFCOUNTER_OMCASTS:
1902 return (s->tx_mcast_frames);
1903 case IFCOUNTER_OQDROPS: {
1907 if (vi->flags & VI_INIT_DONE) {
1909 struct sge_txq *txq;
1911 for_each_txq(vi, i, txq)
1912 drops += counter_u64_fetch(txq->r->drops);
1920 return (if_get_counter_default(ifp, c));
1925 cxgbe_get_counter(struct ifnet *ifp, ift_counter c)
1927 struct vi_info *vi = ifp->if_softc;
1928 struct port_info *pi = vi->pi;
1929 struct adapter *sc = pi->adapter;
1930 struct port_stats *s = &pi->stats;
1932 if (pi->nvi > 1 || sc->flags & IS_VF)
1933 return (vi_get_counter(ifp, c));
1935 cxgbe_refresh_stats(sc, pi);
1938 case IFCOUNTER_IPACKETS:
1939 return (s->rx_frames);
1941 case IFCOUNTER_IERRORS:
1942 return (s->rx_jabber + s->rx_runt + s->rx_too_long +
1943 s->rx_fcs_err + s->rx_len_err);
1945 case IFCOUNTER_OPACKETS:
1946 return (s->tx_frames);
1948 case IFCOUNTER_OERRORS:
1949 return (s->tx_error_frames);
1951 case IFCOUNTER_IBYTES:
1952 return (s->rx_octets);
1954 case IFCOUNTER_OBYTES:
1955 return (s->tx_octets);
1957 case IFCOUNTER_IMCASTS:
1958 return (s->rx_mcast_frames);
1960 case IFCOUNTER_OMCASTS:
1961 return (s->tx_mcast_frames);
1963 case IFCOUNTER_IQDROPS:
1964 return (s->rx_ovflow0 + s->rx_ovflow1 + s->rx_ovflow2 +
1965 s->rx_ovflow3 + s->rx_trunc0 + s->rx_trunc1 + s->rx_trunc2 +
1966 s->rx_trunc3 + pi->tnl_cong_drops);
1968 case IFCOUNTER_OQDROPS: {
1972 if (vi->flags & VI_INIT_DONE) {
1974 struct sge_txq *txq;
1976 for_each_txq(vi, i, txq)
1977 drops += counter_u64_fetch(txq->r->drops);
1985 return (if_get_counter_default(ifp, c));
1990 cxgbe_media_change(struct ifnet *ifp)
1992 struct vi_info *vi = ifp->if_softc;
1994 device_printf(vi->dev, "%s unimplemented.\n", __func__);
1996 return (EOPNOTSUPP);
2000 cxgbe_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
2002 struct vi_info *vi = ifp->if_softc;
2003 struct port_info *pi = vi->pi;
2004 struct ifmedia_entry *cur;
2005 struct link_config *lc = &pi->link_cfg;
2008 * If all the interfaces are administratively down the firmware does not
2009 * report transceiver changes. Refresh port info here so that ifconfig
2010 * displays accurate information at all times.
2012 if (begin_synchronized_op(pi->adapter, NULL, SLEEP_OK | INTR_OK,
2015 if (pi->up_vis == 0) {
2016 t4_update_port_info(pi);
2017 build_medialist(pi, &pi->media);
2020 end_synchronized_op(pi->adapter, 0);
2023 ifmr->ifm_status = IFM_AVALID;
2024 if (lc->link_ok == 0)
2027 ifmr->ifm_status |= IFM_ACTIVE;
2028 ifmr->ifm_active &= ~(IFM_ETH_TXPAUSE | IFM_ETH_RXPAUSE);
2029 if (lc->fc & PAUSE_RX)
2030 ifmr->ifm_active |= IFM_ETH_RXPAUSE;
2031 if (lc->fc & PAUSE_TX)
2032 ifmr->ifm_active |= IFM_ETH_TXPAUSE;
2034 /* active and current will differ iff current media is autoselect. */
2035 cur = pi->media.ifm_cur;
2036 if (cur != NULL && IFM_SUBTYPE(cur->ifm_media) != IFM_AUTO)
2039 ifmr->ifm_active = IFM_ETHER | IFM_FDX;
2040 if (lc->fc & PAUSE_RX)
2041 ifmr->ifm_active |= IFM_ETH_RXPAUSE;
2042 if (lc->fc & PAUSE_TX)
2043 ifmr->ifm_active |= IFM_ETH_TXPAUSE;
2044 switch (lc->speed) {
2046 ifmr->ifm_active |= IFM_10G_T;
2049 ifmr->ifm_active |= IFM_1000_T;
2052 ifmr->ifm_active |= IFM_100_TX;
2055 ifmr->ifm_active |= IFM_10_T;
2058 device_printf(vi->dev, "link up but speed unknown (%u)\n",
2064 vcxgbe_probe(device_t dev)
2067 struct vi_info *vi = device_get_softc(dev);
2069 snprintf(buf, sizeof(buf), "port %d vi %td", vi->pi->port_id,
2071 device_set_desc_copy(dev, buf);
2073 return (BUS_PROBE_DEFAULT);
2077 alloc_extra_vi(struct adapter *sc, struct port_info *pi, struct vi_info *vi)
2079 int func, index, rc;
2080 uint32_t param, val;
2082 ASSERT_SYNCHRONIZED_OP(sc);
2084 index = vi - pi->vi;
2085 MPASS(index > 0); /* This function deals with _extra_ VIs only */
2086 KASSERT(index < nitems(vi_mac_funcs),
2087 ("%s: VI %s doesn't have a MAC func", __func__,
2088 device_get_nameunit(vi->dev)));
2089 func = vi_mac_funcs[index];
2090 rc = t4_alloc_vi_func(sc, sc->mbox, pi->tx_chan, sc->pf, 0, 1,
2091 vi->hw_addr, &vi->rss_size, func, 0);
2093 device_printf(vi->dev, "failed to allocate virtual interface %d"
2094 "for port %d: %d\n", index, pi->port_id, -rc);
2098 if (chip_id(sc) <= CHELSIO_T5)
2099 vi->smt_idx = (rc & 0x7f) << 1;
2101 vi->smt_idx = (rc & 0x7f);
2103 if (vi->rss_size == 1) {
2105 * This VI didn't get a slice of the RSS table. Reduce the
2106 * number of VIs being created (hw.cxgbe.num_vis) or modify the
2107 * configuration file (nvi, rssnvi for this PF) if this is a
2110 device_printf(vi->dev, "RSS table not available.\n");
2111 vi->rss_base = 0xffff;
2116 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
2117 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_RSSINFO) |
2118 V_FW_PARAMS_PARAM_YZ(vi->viid);
2119 rc = t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
2121 vi->rss_base = 0xffff;
2123 MPASS((val >> 16) == vi->rss_size);
2124 vi->rss_base = val & 0xffff;
2131 vcxgbe_attach(device_t dev)
2134 struct port_info *pi;
2138 vi = device_get_softc(dev);
2142 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4via");
2145 rc = alloc_extra_vi(sc, pi, vi);
2146 end_synchronized_op(sc, 0);
2150 rc = cxgbe_vi_attach(dev, vi);
2152 t4_free_vi(sc, sc->mbox, sc->pf, 0, vi->viid);
2159 vcxgbe_detach(device_t dev)
2164 vi = device_get_softc(dev);
2165 sc = vi->pi->adapter;
2169 cxgbe_vi_detach(vi);
2170 t4_free_vi(sc, sc->mbox, sc->pf, 0, vi->viid);
2172 end_synchronized_op(sc, 0);
2178 t4_fatal_err(struct adapter *sc)
2180 t4_set_reg_field(sc, A_SGE_CONTROL, F_GLOBALENABLE, 0);
2181 t4_intr_disable(sc);
2182 log(LOG_EMERG, "%s: encountered fatal error, adapter stopped.\n",
2183 device_get_nameunit(sc->dev));
2187 t4_add_adapter(struct adapter *sc)
2189 sx_xlock(&t4_list_lock);
2190 SLIST_INSERT_HEAD(&t4_list, sc, link);
2191 sx_xunlock(&t4_list_lock);
2195 t4_map_bars_0_and_4(struct adapter *sc)
2197 sc->regs_rid = PCIR_BAR(0);
2198 sc->regs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
2199 &sc->regs_rid, RF_ACTIVE);
2200 if (sc->regs_res == NULL) {
2201 device_printf(sc->dev, "cannot map registers.\n");
2204 sc->bt = rman_get_bustag(sc->regs_res);
2205 sc->bh = rman_get_bushandle(sc->regs_res);
2206 sc->mmio_len = rman_get_size(sc->regs_res);
2207 setbit(&sc->doorbells, DOORBELL_KDB);
2209 sc->msix_rid = PCIR_BAR(4);
2210 sc->msix_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
2211 &sc->msix_rid, RF_ACTIVE);
2212 if (sc->msix_res == NULL) {
2213 device_printf(sc->dev, "cannot map MSI-X BAR.\n");
2221 t4_map_bar_2(struct adapter *sc)
2225 * T4: only iWARP driver uses the userspace doorbells. There is no need
2226 * to map it if RDMA is disabled.
2228 if (is_t4(sc) && sc->rdmacaps == 0)
2231 sc->udbs_rid = PCIR_BAR(2);
2232 sc->udbs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
2233 &sc->udbs_rid, RF_ACTIVE);
2234 if (sc->udbs_res == NULL) {
2235 device_printf(sc->dev, "cannot map doorbell BAR.\n");
2238 sc->udbs_base = rman_get_virtual(sc->udbs_res);
2240 if (chip_id(sc) >= CHELSIO_T5) {
2241 setbit(&sc->doorbells, DOORBELL_UDB);
2242 #if defined(__i386__) || defined(__amd64__)
2243 if (t5_write_combine) {
2247 * Enable write combining on BAR2. This is the
2248 * userspace doorbell BAR and is split into 128B
2249 * (UDBS_SEG_SIZE) doorbell regions, each associated
2250 * with an egress queue. The first 64B has the doorbell
2251 * and the second 64B can be used to submit a tx work
2252 * request with an implicit doorbell.
2255 rc = pmap_change_attr((vm_offset_t)sc->udbs_base,
2256 rman_get_size(sc->udbs_res), PAT_WRITE_COMBINING);
2258 clrbit(&sc->doorbells, DOORBELL_UDB);
2259 setbit(&sc->doorbells, DOORBELL_WCWR);
2260 setbit(&sc->doorbells, DOORBELL_UDBWC);
2262 t5_write_combine = 0;
2263 device_printf(sc->dev,
2264 "couldn't enable write combining: %d\n",
2268 mode = is_t5(sc) ? V_STATMODE(0) : V_T6_STATMODE(0);
2269 t4_write_reg(sc, A_SGE_STAT_CFG,
2270 V_STATSOURCE_T5(7) | mode);
2273 t5_write_combine = 0;
2275 sc->iwt.wc_en = t5_write_combine;
2281 struct memwin_init {
2286 static const struct memwin_init t4_memwin[NUM_MEMWIN] = {
2287 { MEMWIN0_BASE, MEMWIN0_APERTURE },
2288 { MEMWIN1_BASE, MEMWIN1_APERTURE },
2289 { MEMWIN2_BASE_T4, MEMWIN2_APERTURE_T4 }
2292 static const struct memwin_init t5_memwin[NUM_MEMWIN] = {
2293 { MEMWIN0_BASE, MEMWIN0_APERTURE },
2294 { MEMWIN1_BASE, MEMWIN1_APERTURE },
2295 { MEMWIN2_BASE_T5, MEMWIN2_APERTURE_T5 },
2299 setup_memwin(struct adapter *sc)
2301 const struct memwin_init *mw_init;
2308 * Read low 32b of bar0 indirectly via the hardware backdoor
2309 * mechanism. Works from within PCI passthrough environments
2310 * too, where rman_get_start() can return a different value. We
2311 * need to program the T4 memory window decoders with the actual
2312 * addresses that will be coming across the PCIe link.
2314 bar0 = t4_hw_pci_read_cfg4(sc, PCIR_BAR(0));
2315 bar0 &= (uint32_t) PCIM_BAR_MEM_BASE;
2317 mw_init = &t4_memwin[0];
2319 /* T5+ use the relative offset inside the PCIe BAR */
2322 mw_init = &t5_memwin[0];
2325 for (i = 0, mw = &sc->memwin[0]; i < NUM_MEMWIN; i++, mw_init++, mw++) {
2326 rw_init(&mw->mw_lock, "memory window access");
2327 mw->mw_base = mw_init->base;
2328 mw->mw_aperture = mw_init->aperture;
2331 PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, i),
2332 (mw->mw_base + bar0) | V_BIR(0) |
2333 V_WINDOW(ilog2(mw->mw_aperture) - 10));
2334 rw_wlock(&mw->mw_lock);
2335 position_memwin(sc, i, 0);
2336 rw_wunlock(&mw->mw_lock);
2340 t4_read_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 2));
2344 * Positions the memory window at the given address in the card's address space.
2345 * There are some alignment requirements and the actual position may be at an
2346 * address prior to the requested address. mw->mw_curpos always has the actual
2347 * position of the window.
2350 position_memwin(struct adapter *sc, int idx, uint32_t addr)
2356 MPASS(idx >= 0 && idx < NUM_MEMWIN);
2357 mw = &sc->memwin[idx];
2358 rw_assert(&mw->mw_lock, RA_WLOCKED);
2362 mw->mw_curpos = addr & ~0xf; /* start must be 16B aligned */
2364 pf = V_PFNUM(sc->pf);
2365 mw->mw_curpos = addr & ~0x7f; /* start must be 128B aligned */
2367 reg = PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, idx);
2368 t4_write_reg(sc, reg, mw->mw_curpos | pf);
2369 t4_read_reg(sc, reg); /* flush */
2373 rw_via_memwin(struct adapter *sc, int idx, uint32_t addr, uint32_t *val,
2379 MPASS(idx >= 0 && idx < NUM_MEMWIN);
2381 /* Memory can only be accessed in naturally aligned 4 byte units */
2382 if (addr & 3 || len & 3 || len <= 0)
2385 mw = &sc->memwin[idx];
2387 rw_rlock(&mw->mw_lock);
2388 mw_end = mw->mw_curpos + mw->mw_aperture;
2389 if (addr >= mw_end || addr < mw->mw_curpos) {
2390 /* Will need to reposition the window */
2391 if (!rw_try_upgrade(&mw->mw_lock)) {
2392 rw_runlock(&mw->mw_lock);
2393 rw_wlock(&mw->mw_lock);
2395 rw_assert(&mw->mw_lock, RA_WLOCKED);
2396 position_memwin(sc, idx, addr);
2397 rw_downgrade(&mw->mw_lock);
2398 mw_end = mw->mw_curpos + mw->mw_aperture;
2400 rw_assert(&mw->mw_lock, RA_RLOCKED);
2401 while (addr < mw_end && len > 0) {
2403 v = t4_read_reg(sc, mw->mw_base + addr -
2405 *val++ = le32toh(v);
2408 t4_write_reg(sc, mw->mw_base + addr -
2409 mw->mw_curpos, htole32(v));
2414 rw_runlock(&mw->mw_lock);
2421 read_via_memwin(struct adapter *sc, int idx, uint32_t addr, uint32_t *val,
2425 return (rw_via_memwin(sc, idx, addr, val, len, 0));
2429 write_via_memwin(struct adapter *sc, int idx, uint32_t addr,
2430 const uint32_t *val, int len)
2433 return (rw_via_memwin(sc, idx, addr, (void *)(uintptr_t)val, len, 1));
2437 t4_range_cmp(const void *a, const void *b)
2439 return ((const struct t4_range *)a)->start -
2440 ((const struct t4_range *)b)->start;
2444 * Verify that the memory range specified by the addr/len pair is valid within
2445 * the card's address space.
2448 validate_mem_range(struct adapter *sc, uint32_t addr, int len)
2450 struct t4_range mem_ranges[4], *r, *next;
2451 uint32_t em, addr_len;
2452 int i, n, remaining;
2454 /* Memory can only be accessed in naturally aligned 4 byte units */
2455 if (addr & 3 || len & 3 || len <= 0)
2458 /* Enabled memories */
2459 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
2463 bzero(r, sizeof(mem_ranges));
2464 if (em & F_EDRAM0_ENABLE) {
2465 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
2466 r->size = G_EDRAM0_SIZE(addr_len) << 20;
2468 r->start = G_EDRAM0_BASE(addr_len) << 20;
2469 if (addr >= r->start &&
2470 addr + len <= r->start + r->size)
2476 if (em & F_EDRAM1_ENABLE) {
2477 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
2478 r->size = G_EDRAM1_SIZE(addr_len) << 20;
2480 r->start = G_EDRAM1_BASE(addr_len) << 20;
2481 if (addr >= r->start &&
2482 addr + len <= r->start + r->size)
2488 if (em & F_EXT_MEM_ENABLE) {
2489 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
2490 r->size = G_EXT_MEM_SIZE(addr_len) << 20;
2492 r->start = G_EXT_MEM_BASE(addr_len) << 20;
2493 if (addr >= r->start &&
2494 addr + len <= r->start + r->size)
2500 if (is_t5(sc) && em & F_EXT_MEM1_ENABLE) {
2501 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
2502 r->size = G_EXT_MEM1_SIZE(addr_len) << 20;
2504 r->start = G_EXT_MEM1_BASE(addr_len) << 20;
2505 if (addr >= r->start &&
2506 addr + len <= r->start + r->size)
2512 MPASS(n <= nitems(mem_ranges));
2515 /* Sort and merge the ranges. */
2516 qsort(mem_ranges, n, sizeof(struct t4_range), t4_range_cmp);
2518 /* Start from index 0 and examine the next n - 1 entries. */
2520 for (remaining = n - 1; remaining > 0; remaining--, r++) {
2522 MPASS(r->size > 0); /* r is a valid entry. */
2524 MPASS(next->size > 0); /* and so is the next one. */
2526 while (r->start + r->size >= next->start) {
2527 /* Merge the next one into the current entry. */
2528 r->size = max(r->start + r->size,
2529 next->start + next->size) - r->start;
2530 n--; /* One fewer entry in total. */
2531 if (--remaining == 0)
2532 goto done; /* short circuit */
2535 if (next != r + 1) {
2537 * Some entries were merged into r and next
2538 * points to the first valid entry that couldn't
2541 MPASS(next->size > 0); /* must be valid */
2542 memcpy(r + 1, next, remaining * sizeof(*r));
2545 * This so that the foo->size assertion in the
2546 * next iteration of the loop do the right
2547 * thing for entries that were pulled up and are
2550 MPASS(n < nitems(mem_ranges));
2551 bzero(&mem_ranges[n], (nitems(mem_ranges) - n) *
2552 sizeof(struct t4_range));
2557 /* Done merging the ranges. */
2560 for (i = 0; i < n; i++, r++) {
2561 if (addr >= r->start &&
2562 addr + len <= r->start + r->size)
2571 fwmtype_to_hwmtype(int mtype)
2575 case FW_MEMTYPE_EDC0:
2577 case FW_MEMTYPE_EDC1:
2579 case FW_MEMTYPE_EXTMEM:
2581 case FW_MEMTYPE_EXTMEM1:
2584 panic("%s: cannot translate fw mtype %d.", __func__, mtype);
2589 * Verify that the memory range specified by the memtype/offset/len pair is
2590 * valid and lies entirely within the memtype specified. The global address of
2591 * the start of the range is returned in addr.
2594 validate_mt_off_len(struct adapter *sc, int mtype, uint32_t off, int len,
2597 uint32_t em, addr_len, maddr;
2599 /* Memory can only be accessed in naturally aligned 4 byte units */
2600 if (off & 3 || len & 3 || len == 0)
2603 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
2604 switch (fwmtype_to_hwmtype(mtype)) {
2606 if (!(em & F_EDRAM0_ENABLE))
2608 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
2609 maddr = G_EDRAM0_BASE(addr_len) << 20;
2612 if (!(em & F_EDRAM1_ENABLE))
2614 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
2615 maddr = G_EDRAM1_BASE(addr_len) << 20;
2618 if (!(em & F_EXT_MEM_ENABLE))
2620 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
2621 maddr = G_EXT_MEM_BASE(addr_len) << 20;
2624 if (!is_t5(sc) || !(em & F_EXT_MEM1_ENABLE))
2626 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
2627 maddr = G_EXT_MEM1_BASE(addr_len) << 20;
2633 *addr = maddr + off; /* global address */
2634 return (validate_mem_range(sc, *addr, len));
2638 fixup_devlog_params(struct adapter *sc)
2640 struct devlog_params *dparams = &sc->params.devlog;
2643 rc = validate_mt_off_len(sc, dparams->memtype, dparams->start,
2644 dparams->size, &dparams->addr);
2650 cfg_itype_and_nqueues(struct adapter *sc, struct intrs_and_queues *iaq)
2652 int rc, itype, navail, nrxq, nports, n;
2655 nports = sc->params.nports;
2658 bzero(iaq, sizeof(*iaq));
2659 iaq->num_vis = t4_num_vis;
2660 iaq->ntxq = t4_ntxq;
2661 iaq->ntxq_vi = t4_ntxq_vi;
2662 iaq->nrxq = nrxq = t4_nrxq;
2663 iaq->nrxq_vi = t4_nrxq_vi;
2665 if (is_offload(sc)) {
2666 iaq->nofldtxq = t4_nofldtxq;
2667 iaq->nofldtxq_vi = t4_nofldtxq_vi;
2668 iaq->nofldrxq = nofldrxq = t4_nofldrxq;
2669 iaq->nofldrxq_vi = t4_nofldrxq_vi;
2673 iaq->nnmtxq_vi = t4_nnmtxq_vi;
2674 iaq->nnmrxq_vi = t4_nnmrxq_vi;
2677 for (itype = INTR_MSIX; itype; itype >>= 1) {
2679 if ((itype & t4_intr_types) == 0)
2680 continue; /* not allowed */
2682 if (itype == INTR_MSIX)
2683 navail = pci_msix_count(sc->dev);
2684 else if (itype == INTR_MSI)
2685 navail = pci_msi_count(sc->dev);
2692 iaq->intr_type = itype;
2693 iaq->intr_flags = 0;
2696 * Best option: an interrupt vector for errors, one for the
2697 * firmware event queue, and one for every rxq (NIC and TOE) of
2698 * every VI. The VIs that support netmap use the same
2699 * interrupts for the NIC rx queues and the netmap rx queues
2700 * because only one set of queues is active at a time.
2702 iaq->nirq = T4_EXTRA_INTR;
2703 iaq->nirq += nports * (nrxq + nofldrxq);
2704 iaq->nirq += nports * (iaq->num_vis - 1) *
2705 max(iaq->nrxq_vi, iaq->nnmrxq_vi); /* See comment above. */
2706 iaq->nirq += nports * (iaq->num_vis - 1) * iaq->nofldrxq_vi;
2707 if (iaq->nirq <= navail &&
2708 (itype != INTR_MSI || powerof2(iaq->nirq))) {
2709 iaq->intr_flags = INTR_ALL;
2713 /* Disable the VIs (and netmap) if there aren't enough intrs */
2714 if (iaq->num_vis > 1) {
2715 device_printf(sc->dev, "virtual interfaces disabled "
2716 "because num_vis=%u with current settings "
2717 "(nrxq=%u, nofldrxq=%u, nrxq_vi=%u nofldrxq_vi=%u, "
2718 "nnmrxq_vi=%u) would need %u interrupts but "
2719 "only %u are available.\n", iaq->num_vis, nrxq,
2720 nofldrxq, iaq->nrxq_vi, iaq->nofldrxq_vi,
2721 iaq->nnmrxq_vi, iaq->nirq, navail);
2723 iaq->ntxq_vi = iaq->nrxq_vi = 0;
2724 iaq->nofldtxq_vi = iaq->nofldrxq_vi = 0;
2725 iaq->nnmtxq_vi = iaq->nnmrxq_vi = 0;
2730 * Second best option: a vector for errors, one for the firmware
2731 * event queue, and vectors for either all the NIC rx queues or
2732 * all the TOE rx queues. The queues that don't get vectors
2733 * will forward their interrupts to those that do.
2735 iaq->nirq = T4_EXTRA_INTR;
2736 if (nrxq >= nofldrxq) {
2737 iaq->intr_flags = INTR_RXQ;
2738 iaq->nirq += nports * nrxq;
2740 iaq->intr_flags = INTR_OFLD_RXQ;
2741 iaq->nirq += nports * nofldrxq;
2743 if (iaq->nirq <= navail &&
2744 (itype != INTR_MSI || powerof2(iaq->nirq)))
2748 * Next best option: an interrupt vector for errors, one for the
2749 * firmware event queue, and at least one per main-VI. At this
2750 * point we know we'll have to downsize nrxq and/or nofldrxq to
2751 * fit what's available to us.
2753 iaq->nirq = T4_EXTRA_INTR;
2754 iaq->nirq += nports;
2755 if (iaq->nirq <= navail) {
2756 int leftover = navail - iaq->nirq;
2757 int target = max(nrxq, nofldrxq);
2759 iaq->intr_flags = nrxq >= nofldrxq ?
2760 INTR_RXQ : INTR_OFLD_RXQ;
2763 while (n < target && leftover >= nports) {
2765 iaq->nirq += nports;
2768 iaq->nrxq = min(n, nrxq);
2770 iaq->nofldrxq = min(n, nofldrxq);
2773 if (itype != INTR_MSI || powerof2(iaq->nirq))
2778 * Least desirable option: one interrupt vector for everything.
2780 iaq->nirq = iaq->nrxq = 1;
2781 iaq->intr_flags = 0;
2789 if (itype == INTR_MSIX)
2790 rc = pci_alloc_msix(sc->dev, &navail);
2791 else if (itype == INTR_MSI)
2792 rc = pci_alloc_msi(sc->dev, &navail);
2795 if (navail == iaq->nirq)
2799 * Didn't get the number requested. Use whatever number
2800 * the kernel is willing to allocate (it's in navail).
2802 device_printf(sc->dev, "fewer vectors than requested, "
2803 "type=%d, req=%d, rcvd=%d; will downshift req.\n",
2804 itype, iaq->nirq, navail);
2805 pci_release_msi(sc->dev);
2809 device_printf(sc->dev,
2810 "failed to allocate vectors:%d, type=%d, req=%d, rcvd=%d\n",
2811 itype, rc, iaq->nirq, navail);
2814 device_printf(sc->dev,
2815 "failed to find a usable interrupt type. "
2816 "allowed=%d, msi-x=%d, msi=%d, intx=1", t4_intr_types,
2817 pci_msix_count(sc->dev), pci_msi_count(sc->dev));
2822 #define FW_VERSION(chip) ( \
2823 V_FW_HDR_FW_VER_MAJOR(chip##FW_VERSION_MAJOR) | \
2824 V_FW_HDR_FW_VER_MINOR(chip##FW_VERSION_MINOR) | \
2825 V_FW_HDR_FW_VER_MICRO(chip##FW_VERSION_MICRO) | \
2826 V_FW_HDR_FW_VER_BUILD(chip##FW_VERSION_BUILD))
2827 #define FW_INTFVER(chip, intf) (chip##FW_HDR_INTFVER_##intf)
2833 struct fw_hdr fw_hdr; /* XXX: waste of space, need a sparse struct */
2837 .kld_name = "t4fw_cfg",
2838 .fw_mod_name = "t4fw",
2840 .chip = FW_HDR_CHIP_T4,
2841 .fw_ver = htobe32_const(FW_VERSION(T4)),
2842 .intfver_nic = FW_INTFVER(T4, NIC),
2843 .intfver_vnic = FW_INTFVER(T4, VNIC),
2844 .intfver_ofld = FW_INTFVER(T4, OFLD),
2845 .intfver_ri = FW_INTFVER(T4, RI),
2846 .intfver_iscsipdu = FW_INTFVER(T4, ISCSIPDU),
2847 .intfver_iscsi = FW_INTFVER(T4, ISCSI),
2848 .intfver_fcoepdu = FW_INTFVER(T4, FCOEPDU),
2849 .intfver_fcoe = FW_INTFVER(T4, FCOE),
2853 .kld_name = "t5fw_cfg",
2854 .fw_mod_name = "t5fw",
2856 .chip = FW_HDR_CHIP_T5,
2857 .fw_ver = htobe32_const(FW_VERSION(T5)),
2858 .intfver_nic = FW_INTFVER(T5, NIC),
2859 .intfver_vnic = FW_INTFVER(T5, VNIC),
2860 .intfver_ofld = FW_INTFVER(T5, OFLD),
2861 .intfver_ri = FW_INTFVER(T5, RI),
2862 .intfver_iscsipdu = FW_INTFVER(T5, ISCSIPDU),
2863 .intfver_iscsi = FW_INTFVER(T5, ISCSI),
2864 .intfver_fcoepdu = FW_INTFVER(T5, FCOEPDU),
2865 .intfver_fcoe = FW_INTFVER(T5, FCOE),
2869 .kld_name = "t6fw_cfg",
2870 .fw_mod_name = "t6fw",
2872 .chip = FW_HDR_CHIP_T6,
2873 .fw_ver = htobe32_const(FW_VERSION(T6)),
2874 .intfver_nic = FW_INTFVER(T6, NIC),
2875 .intfver_vnic = FW_INTFVER(T6, VNIC),
2876 .intfver_ofld = FW_INTFVER(T6, OFLD),
2877 .intfver_ri = FW_INTFVER(T6, RI),
2878 .intfver_iscsipdu = FW_INTFVER(T6, ISCSIPDU),
2879 .intfver_iscsi = FW_INTFVER(T6, ISCSI),
2880 .intfver_fcoepdu = FW_INTFVER(T6, FCOEPDU),
2881 .intfver_fcoe = FW_INTFVER(T6, FCOE),
2886 static struct fw_info *
2887 find_fw_info(int chip)
2891 for (i = 0; i < nitems(fw_info); i++) {
2892 if (fw_info[i].chip == chip)
2893 return (&fw_info[i]);
2899 * Is the given firmware API compatible with the one the driver was compiled
2903 fw_compatible(const struct fw_hdr *hdr1, const struct fw_hdr *hdr2)
2906 /* short circuit if it's the exact same firmware version */
2907 if (hdr1->chip == hdr2->chip && hdr1->fw_ver == hdr2->fw_ver)
2911 * XXX: Is this too conservative? Perhaps I should limit this to the
2912 * features that are supported in the driver.
2914 #define SAME_INTF(x) (hdr1->intfver_##x == hdr2->intfver_##x)
2915 if (hdr1->chip == hdr2->chip && SAME_INTF(nic) && SAME_INTF(vnic) &&
2916 SAME_INTF(ofld) && SAME_INTF(ri) && SAME_INTF(iscsipdu) &&
2917 SAME_INTF(iscsi) && SAME_INTF(fcoepdu) && SAME_INTF(fcoe))
2925 * The firmware in the KLD is usable, but should it be installed? This routine
2926 * explains itself in detail if it indicates the KLD firmware should be
2930 should_install_kld_fw(struct adapter *sc, int card_fw_usable, int k, int c)
2934 if (!card_fw_usable) {
2935 reason = "incompatible or unusable";
2940 reason = "older than the version bundled with this driver";
2944 if (t4_fw_install == 2 && k != c) {
2945 reason = "different than the version bundled with this driver";
2952 if (t4_fw_install == 0) {
2953 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
2954 "but the driver is prohibited from installing a different "
2955 "firmware on the card.\n",
2956 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
2957 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason);
2962 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
2963 "installing firmware %u.%u.%u.%u on card.\n",
2964 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
2965 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason,
2966 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
2967 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
2973 * Establish contact with the firmware and determine if we are the master driver
2974 * or not, and whether we are responsible for chip initialization.
2977 prep_firmware(struct adapter *sc)
2979 const struct firmware *fw = NULL, *default_cfg;
2980 int rc, pf, card_fw_usable, kld_fw_usable, need_fw_reset = 1;
2981 enum dev_state state;
2982 struct fw_info *fw_info;
2983 struct fw_hdr *card_fw; /* fw on the card */
2984 const struct fw_hdr *kld_fw; /* fw in the KLD */
2985 const struct fw_hdr *drv_fw; /* fw header the driver was compiled
2988 /* This is the firmware whose headers the driver was compiled against */
2989 fw_info = find_fw_info(chip_id(sc));
2990 if (fw_info == NULL) {
2991 device_printf(sc->dev,
2992 "unable to look up firmware information for chip %d.\n",
2996 drv_fw = &fw_info->fw_hdr;
2999 * The firmware KLD contains many modules. The KLD name is also the
3000 * name of the module that contains the default config file.
3002 default_cfg = firmware_get(fw_info->kld_name);
3004 /* This is the firmware in the KLD */
3005 fw = firmware_get(fw_info->fw_mod_name);
3007 kld_fw = (const void *)fw->data;
3008 kld_fw_usable = fw_compatible(drv_fw, kld_fw);
3014 /* Read the header of the firmware on the card */
3015 card_fw = malloc(sizeof(*card_fw), M_CXGBE, M_ZERO | M_WAITOK);
3016 rc = -t4_read_flash(sc, FLASH_FW_START,
3017 sizeof (*card_fw) / sizeof (uint32_t), (uint32_t *)card_fw, 1);
3019 card_fw_usable = fw_compatible(drv_fw, (const void*)card_fw);
3020 if (card_fw->fw_ver == be32toh(0xffffffff)) {
3021 uint32_t d = be32toh(kld_fw->fw_ver);
3023 if (!kld_fw_usable) {
3024 device_printf(sc->dev,
3025 "no firmware on the card and no usable "
3026 "firmware bundled with the driver.\n");
3029 } else if (t4_fw_install == 0) {
3030 device_printf(sc->dev,
3031 "no firmware on the card and the driver "
3032 "is prohibited from installing new "
3038 device_printf(sc->dev, "no firmware on the card, "
3039 "installing firmware %d.%d.%d.%d\n",
3040 G_FW_HDR_FW_VER_MAJOR(d), G_FW_HDR_FW_VER_MINOR(d),
3041 G_FW_HDR_FW_VER_MICRO(d), G_FW_HDR_FW_VER_BUILD(d));
3042 rc = t4_fw_forceinstall(sc, fw->data, fw->datasize);
3045 device_printf(sc->dev,
3046 "firmware install failed: %d.\n", rc);
3049 memcpy(card_fw, kld_fw, sizeof(*card_fw));
3054 device_printf(sc->dev,
3055 "Unable to read card's firmware header: %d\n", rc);
3059 /* Contact firmware. */
3060 rc = t4_fw_hello(sc, sc->mbox, sc->mbox, MASTER_MAY, &state);
3061 if (rc < 0 || state == DEV_STATE_ERR) {
3063 device_printf(sc->dev,
3064 "failed to connect to the firmware: %d, %d.\n", rc, state);
3069 sc->flags |= MASTER_PF;
3070 else if (state == DEV_STATE_UNINIT) {
3072 * We didn't get to be the master so we definitely won't be
3073 * configuring the chip. It's a bug if someone else hasn't
3074 * configured it already.
3076 device_printf(sc->dev, "couldn't be master(%d), "
3077 "device not already initialized either(%d).\n", rc, state);
3082 if (card_fw_usable && card_fw->fw_ver == drv_fw->fw_ver &&
3083 (!kld_fw_usable || kld_fw->fw_ver == drv_fw->fw_ver)) {
3085 * Common case: the firmware on the card is an exact match and
3086 * the KLD is an exact match too, or the KLD is
3087 * absent/incompatible. Note that t4_fw_install = 2 is ignored
3088 * here -- use cxgbetool loadfw if you want to reinstall the
3089 * same firmware as the one on the card.
3091 } else if (kld_fw_usable && state == DEV_STATE_UNINIT &&
3092 should_install_kld_fw(sc, card_fw_usable, be32toh(kld_fw->fw_ver),
3093 be32toh(card_fw->fw_ver))) {
3095 rc = -t4_fw_upgrade(sc, sc->mbox, fw->data, fw->datasize, 0);
3097 device_printf(sc->dev,
3098 "failed to install firmware: %d\n", rc);
3102 /* Installed successfully, update the cached header too. */
3103 memcpy(card_fw, kld_fw, sizeof(*card_fw));
3105 need_fw_reset = 0; /* already reset as part of load_fw */
3108 if (!card_fw_usable) {
3111 d = ntohl(drv_fw->fw_ver);
3112 c = ntohl(card_fw->fw_ver);
3113 k = kld_fw ? ntohl(kld_fw->fw_ver) : 0;
3115 device_printf(sc->dev, "Cannot find a usable firmware: "
3116 "fw_install %d, chip state %d, "
3117 "driver compiled with %d.%d.%d.%d, "
3118 "card has %d.%d.%d.%d, KLD has %d.%d.%d.%d\n",
3119 t4_fw_install, state,
3120 G_FW_HDR_FW_VER_MAJOR(d), G_FW_HDR_FW_VER_MINOR(d),
3121 G_FW_HDR_FW_VER_MICRO(d), G_FW_HDR_FW_VER_BUILD(d),
3122 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
3123 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c),
3124 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
3125 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
3131 if (need_fw_reset &&
3132 (rc = -t4_fw_reset(sc, sc->mbox, F_PIORSTMODE | F_PIORST)) != 0) {
3133 device_printf(sc->dev, "firmware reset failed: %d.\n", rc);
3134 if (rc != ETIMEDOUT && rc != EIO)
3135 t4_fw_bye(sc, sc->mbox);
3140 rc = get_params__pre_init(sc);
3142 goto done; /* error message displayed already */
3144 /* Partition adapter resources as specified in the config file. */
3145 if (state == DEV_STATE_UNINIT) {
3147 KASSERT(sc->flags & MASTER_PF,
3148 ("%s: trying to change chip settings when not master.",
3151 rc = partition_resources(sc, default_cfg, fw_info->kld_name);
3153 goto done; /* error message displayed already */
3155 t4_tweak_chip_settings(sc);
3157 /* get basic stuff going */
3158 rc = -t4_fw_initialize(sc, sc->mbox);
3160 device_printf(sc->dev, "fw init failed: %d.\n", rc);
3164 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "pf%d", pf);
3169 free(card_fw, M_CXGBE);
3171 firmware_put(fw, FIRMWARE_UNLOAD);
3172 if (default_cfg != NULL)
3173 firmware_put(default_cfg, FIRMWARE_UNLOAD);
3178 #define FW_PARAM_DEV(param) \
3179 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
3180 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
3181 #define FW_PARAM_PFVF(param) \
3182 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
3183 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param))
3186 * Partition chip resources for use between various PFs, VFs, etc.
3189 partition_resources(struct adapter *sc, const struct firmware *default_cfg,
3190 const char *name_prefix)
3192 const struct firmware *cfg = NULL;
3194 struct fw_caps_config_cmd caps;
3195 uint32_t mtype, moff, finicsum, cfcsum;
3198 * Figure out what configuration file to use. Pick the default config
3199 * file for the card if the user hasn't specified one explicitly.
3201 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", t4_cfg_file);
3202 if (strncmp(t4_cfg_file, DEFAULT_CF, sizeof(t4_cfg_file)) == 0) {
3203 /* Card specific overrides go here. */
3204 if (pci_get_device(sc->dev) == 0x440a)
3205 snprintf(sc->cfg_file, sizeof(sc->cfg_file), UWIRE_CF);
3207 snprintf(sc->cfg_file, sizeof(sc->cfg_file), FPGA_CF);
3211 * We need to load another module if the profile is anything except
3212 * "default" or "flash".
3214 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) != 0 &&
3215 strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
3218 snprintf(s, sizeof(s), "%s_%s", name_prefix, sc->cfg_file);
3219 cfg = firmware_get(s);
3221 if (default_cfg != NULL) {
3222 device_printf(sc->dev,
3223 "unable to load module \"%s\" for "
3224 "configuration profile \"%s\", will use "
3225 "the default config file instead.\n",
3227 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
3230 device_printf(sc->dev,
3231 "unable to load module \"%s\" for "
3232 "configuration profile \"%s\", will use "
3233 "the config file on the card's flash "
3234 "instead.\n", s, sc->cfg_file);
3235 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
3241 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) == 0 &&
3242 default_cfg == NULL) {
3243 device_printf(sc->dev,
3244 "default config file not available, will use the config "
3245 "file on the card's flash instead.\n");
3246 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", FLASH_CF);
3249 if (strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
3251 const uint32_t *cfdata;
3252 uint32_t param, val, addr;
3254 KASSERT(cfg != NULL || default_cfg != NULL,
3255 ("%s: no config to upload", __func__));
3258 * Ask the firmware where it wants us to upload the config file.
3260 param = FW_PARAM_DEV(CF);
3261 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
3263 /* No support for config file? Shouldn't happen. */
3264 device_printf(sc->dev,
3265 "failed to query config file location: %d.\n", rc);
3268 mtype = G_FW_PARAMS_PARAM_Y(val);
3269 moff = G_FW_PARAMS_PARAM_Z(val) << 16;
3272 * XXX: sheer laziness. We deliberately added 4 bytes of
3273 * useless stuffing/comments at the end of the config file so
3274 * it's ok to simply throw away the last remaining bytes when
3275 * the config file is not an exact multiple of 4. This also
3276 * helps with the validate_mt_off_len check.
3279 cflen = cfg->datasize & ~3;
3282 cflen = default_cfg->datasize & ~3;
3283 cfdata = default_cfg->data;
3286 if (cflen > FLASH_CFG_MAX_SIZE) {
3287 device_printf(sc->dev,
3288 "config file too long (%d, max allowed is %d). "
3289 "Will try to use the config on the card, if any.\n",
3290 cflen, FLASH_CFG_MAX_SIZE);
3291 goto use_config_on_flash;
3294 rc = validate_mt_off_len(sc, mtype, moff, cflen, &addr);
3296 device_printf(sc->dev,
3297 "%s: addr (%d/0x%x) or len %d is not valid: %d. "
3298 "Will try to use the config on the card, if any.\n",
3299 __func__, mtype, moff, cflen, rc);
3300 goto use_config_on_flash;
3302 write_via_memwin(sc, 2, addr, cfdata, cflen);
3304 use_config_on_flash:
3305 mtype = FW_MEMTYPE_FLASH;
3306 moff = t4_flash_cfg_addr(sc);
3309 bzero(&caps, sizeof(caps));
3310 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3311 F_FW_CMD_REQUEST | F_FW_CMD_READ);
3312 caps.cfvalid_to_len16 = htobe32(F_FW_CAPS_CONFIG_CMD_CFVALID |
3313 V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
3314 V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(moff >> 16) | FW_LEN16(caps));
3315 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
3317 device_printf(sc->dev,
3318 "failed to pre-process config file: %d "
3319 "(mtype %d, moff 0x%x).\n", rc, mtype, moff);
3323 finicsum = be32toh(caps.finicsum);
3324 cfcsum = be32toh(caps.cfcsum);
3325 if (finicsum != cfcsum) {
3326 device_printf(sc->dev,
3327 "WARNING: config file checksum mismatch: %08x %08x\n",
3330 sc->cfcsum = cfcsum;
3332 #define LIMIT_CAPS(x) do { \
3333 caps.x &= htobe16(t4_##x##_allowed); \
3337 * Let the firmware know what features will (not) be used so it can tune
3338 * things accordingly.
3340 LIMIT_CAPS(nbmcaps);
3341 LIMIT_CAPS(linkcaps);
3342 LIMIT_CAPS(switchcaps);
3343 LIMIT_CAPS(niccaps);
3344 LIMIT_CAPS(toecaps);
3345 LIMIT_CAPS(rdmacaps);
3346 LIMIT_CAPS(cryptocaps);
3347 LIMIT_CAPS(iscsicaps);
3348 LIMIT_CAPS(fcoecaps);
3351 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3352 F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
3353 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
3354 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), NULL);
3356 device_printf(sc->dev,
3357 "failed to process config file: %d.\n", rc);
3361 firmware_put(cfg, FIRMWARE_UNLOAD);
3366 * Retrieve parameters that are needed (or nice to have) very early.
3369 get_params__pre_init(struct adapter *sc)
3372 uint32_t param[2], val[2];
3374 t4_get_version_info(sc);
3376 snprintf(sc->fw_version, sizeof(sc->fw_version), "%u.%u.%u.%u",
3377 G_FW_HDR_FW_VER_MAJOR(sc->params.fw_vers),
3378 G_FW_HDR_FW_VER_MINOR(sc->params.fw_vers),
3379 G_FW_HDR_FW_VER_MICRO(sc->params.fw_vers),
3380 G_FW_HDR_FW_VER_BUILD(sc->params.fw_vers));
3382 snprintf(sc->bs_version, sizeof(sc->bs_version), "%u.%u.%u.%u",
3383 G_FW_HDR_FW_VER_MAJOR(sc->params.bs_vers),
3384 G_FW_HDR_FW_VER_MINOR(sc->params.bs_vers),
3385 G_FW_HDR_FW_VER_MICRO(sc->params.bs_vers),
3386 G_FW_HDR_FW_VER_BUILD(sc->params.bs_vers));
3388 snprintf(sc->tp_version, sizeof(sc->tp_version), "%u.%u.%u.%u",
3389 G_FW_HDR_FW_VER_MAJOR(sc->params.tp_vers),
3390 G_FW_HDR_FW_VER_MINOR(sc->params.tp_vers),
3391 G_FW_HDR_FW_VER_MICRO(sc->params.tp_vers),
3392 G_FW_HDR_FW_VER_BUILD(sc->params.tp_vers));
3394 snprintf(sc->er_version, sizeof(sc->er_version), "%u.%u.%u.%u",
3395 G_FW_HDR_FW_VER_MAJOR(sc->params.er_vers),
3396 G_FW_HDR_FW_VER_MINOR(sc->params.er_vers),
3397 G_FW_HDR_FW_VER_MICRO(sc->params.er_vers),
3398 G_FW_HDR_FW_VER_BUILD(sc->params.er_vers));
3400 param[0] = FW_PARAM_DEV(PORTVEC);
3401 param[1] = FW_PARAM_DEV(CCLK);
3402 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
3404 device_printf(sc->dev,
3405 "failed to query parameters (pre_init): %d.\n", rc);
3409 sc->params.portvec = val[0];
3410 sc->params.nports = bitcount32(val[0]);
3411 sc->params.vpd.cclk = val[1];
3413 /* Read device log parameters. */
3414 rc = -t4_init_devlog_params(sc, 1);
3416 fixup_devlog_params(sc);
3418 device_printf(sc->dev,
3419 "failed to get devlog parameters: %d.\n", rc);
3420 rc = 0; /* devlog isn't critical for device operation */
3427 * Retrieve various parameters that are of interest to the driver. The device
3428 * has been initialized by the firmware at this point.
3431 get_params__post_init(struct adapter *sc)
3434 uint32_t param[7], val[7];
3435 struct fw_caps_config_cmd caps;
3437 param[0] = FW_PARAM_PFVF(IQFLINT_START);
3438 param[1] = FW_PARAM_PFVF(EQ_START);
3439 param[2] = FW_PARAM_PFVF(FILTER_START);
3440 param[3] = FW_PARAM_PFVF(FILTER_END);
3441 param[4] = FW_PARAM_PFVF(L2T_START);
3442 param[5] = FW_PARAM_PFVF(L2T_END);
3443 param[6] = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
3444 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) |
3445 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_VDD);
3446 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 7, param, val);
3448 device_printf(sc->dev,
3449 "failed to query parameters (post_init): %d.\n", rc);
3453 sc->sge.iq_start = val[0];
3454 sc->sge.eq_start = val[1];
3455 sc->tids.ftid_base = val[2];
3456 sc->tids.nftids = val[3] - val[2] + 1;
3457 sc->params.ftid_min = val[2];
3458 sc->params.ftid_max = val[3];
3459 sc->vres.l2t.start = val[4];
3460 sc->vres.l2t.size = val[5] - val[4] + 1;
3461 KASSERT(sc->vres.l2t.size <= L2T_SIZE,
3462 ("%s: L2 table size (%u) larger than expected (%u)",
3463 __func__, sc->vres.l2t.size, L2T_SIZE));
3464 sc->params.core_vdd = val[6];
3467 * MPSBGMAP is queried separately because only recent firmwares support
3468 * it as a parameter and we don't want the compound query above to fail
3469 * on older firmwares.
3471 param[0] = FW_PARAM_DEV(MPSBGMAP);
3473 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val);
3475 sc->params.mps_bg_map = val[0];
3477 sc->params.mps_bg_map = 0;
3479 /* get capabilites */
3480 bzero(&caps, sizeof(caps));
3481 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3482 F_FW_CMD_REQUEST | F_FW_CMD_READ);
3483 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
3484 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
3486 device_printf(sc->dev,
3487 "failed to get card capabilities: %d.\n", rc);
3491 #define READ_CAPS(x) do { \
3492 sc->x = htobe16(caps.x); \
3495 READ_CAPS(linkcaps);
3496 READ_CAPS(switchcaps);
3499 READ_CAPS(rdmacaps);
3500 READ_CAPS(cryptocaps);
3501 READ_CAPS(iscsicaps);
3502 READ_CAPS(fcoecaps);
3505 * The firmware attempts memfree TOE configuration for -SO cards and
3506 * will report toecaps=0 if it runs out of resources (this depends on
3507 * the config file). It may not report 0 for other capabilities
3508 * dependent on the TOE in this case. Set them to 0 here so that the
3509 * driver doesn't bother tracking resources that will never be used.
3511 if (sc->toecaps == 0) {
3516 if (sc->niccaps & FW_CAPS_CONFIG_NIC_ETHOFLD) {
3517 param[0] = FW_PARAM_PFVF(ETHOFLD_START);
3518 param[1] = FW_PARAM_PFVF(ETHOFLD_END);
3519 param[2] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
3520 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 3, param, val);
3522 device_printf(sc->dev,
3523 "failed to query NIC parameters: %d.\n", rc);
3526 sc->tids.etid_base = val[0];
3527 sc->params.etid_min = val[0];
3528 sc->tids.netids = val[1] - val[0] + 1;
3529 sc->params.netids = sc->tids.netids;
3530 sc->params.eo_wr_cred = val[2];
3531 sc->params.ethoffload = 1;
3535 /* query offload-related parameters */
3536 param[0] = FW_PARAM_DEV(NTID);
3537 param[1] = FW_PARAM_PFVF(SERVER_START);
3538 param[2] = FW_PARAM_PFVF(SERVER_END);
3539 param[3] = FW_PARAM_PFVF(TDDP_START);
3540 param[4] = FW_PARAM_PFVF(TDDP_END);
3541 param[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
3542 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
3544 device_printf(sc->dev,
3545 "failed to query TOE parameters: %d.\n", rc);
3548 sc->tids.ntids = val[0];
3549 sc->tids.natids = min(sc->tids.ntids / 2, MAX_ATIDS);
3550 sc->tids.stid_base = val[1];
3551 sc->tids.nstids = val[2] - val[1] + 1;
3552 sc->vres.ddp.start = val[3];
3553 sc->vres.ddp.size = val[4] - val[3] + 1;
3554 sc->params.ofldq_wr_cred = val[5];
3555 sc->params.offload = 1;
3558 param[0] = FW_PARAM_PFVF(STAG_START);
3559 param[1] = FW_PARAM_PFVF(STAG_END);
3560 param[2] = FW_PARAM_PFVF(RQ_START);
3561 param[3] = FW_PARAM_PFVF(RQ_END);
3562 param[4] = FW_PARAM_PFVF(PBL_START);
3563 param[5] = FW_PARAM_PFVF(PBL_END);
3564 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
3566 device_printf(sc->dev,
3567 "failed to query RDMA parameters(1): %d.\n", rc);
3570 sc->vres.stag.start = val[0];
3571 sc->vres.stag.size = val[1] - val[0] + 1;
3572 sc->vres.rq.start = val[2];
3573 sc->vres.rq.size = val[3] - val[2] + 1;
3574 sc->vres.pbl.start = val[4];
3575 sc->vres.pbl.size = val[5] - val[4] + 1;
3577 param[0] = FW_PARAM_PFVF(SQRQ_START);
3578 param[1] = FW_PARAM_PFVF(SQRQ_END);
3579 param[2] = FW_PARAM_PFVF(CQ_START);
3580 param[3] = FW_PARAM_PFVF(CQ_END);
3581 param[4] = FW_PARAM_PFVF(OCQ_START);
3582 param[5] = FW_PARAM_PFVF(OCQ_END);
3583 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
3585 device_printf(sc->dev,
3586 "failed to query RDMA parameters(2): %d.\n", rc);
3589 sc->vres.qp.start = val[0];
3590 sc->vres.qp.size = val[1] - val[0] + 1;
3591 sc->vres.cq.start = val[2];
3592 sc->vres.cq.size = val[3] - val[2] + 1;
3593 sc->vres.ocq.start = val[4];
3594 sc->vres.ocq.size = val[5] - val[4] + 1;
3596 param[0] = FW_PARAM_PFVF(SRQ_START);
3597 param[1] = FW_PARAM_PFVF(SRQ_END);
3598 param[2] = FW_PARAM_DEV(MAXORDIRD_QP);
3599 param[3] = FW_PARAM_DEV(MAXIRD_ADAPTER);
3600 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 4, param, val);
3602 device_printf(sc->dev,
3603 "failed to query RDMA parameters(3): %d.\n", rc);
3606 sc->vres.srq.start = val[0];
3607 sc->vres.srq.size = val[1] - val[0] + 1;
3608 sc->params.max_ordird_qp = val[2];
3609 sc->params.max_ird_adapter = val[3];
3611 if (sc->iscsicaps) {
3612 param[0] = FW_PARAM_PFVF(ISCSI_START);
3613 param[1] = FW_PARAM_PFVF(ISCSI_END);
3614 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
3616 device_printf(sc->dev,
3617 "failed to query iSCSI parameters: %d.\n", rc);
3620 sc->vres.iscsi.start = val[0];
3621 sc->vres.iscsi.size = val[1] - val[0] + 1;
3624 t4_init_sge_params(sc);
3627 * We've got the params we wanted to query via the firmware. Now grab
3628 * some others directly from the chip.
3630 rc = t4_read_chip_settings(sc);
3636 set_params__post_init(struct adapter *sc)
3638 uint32_t param, val;
3643 /* ask for encapsulated CPLs */
3644 param = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
3646 (void)t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
3650 * Override the TOE timers with user provided tunables. This is not the
3651 * recommended way to change the timers (the firmware config file is) so
3652 * these tunables are not documented.
3654 * All the timer tunables are in microseconds.
3656 if (t4_toe_keepalive_idle != 0) {
3657 v = us_to_tcp_ticks(sc, t4_toe_keepalive_idle);
3658 v &= M_KEEPALIVEIDLE;
3659 t4_set_reg_field(sc, A_TP_KEEP_IDLE,
3660 V_KEEPALIVEIDLE(M_KEEPALIVEIDLE), V_KEEPALIVEIDLE(v));
3662 if (t4_toe_keepalive_interval != 0) {
3663 v = us_to_tcp_ticks(sc, t4_toe_keepalive_interval);
3664 v &= M_KEEPALIVEINTVL;
3665 t4_set_reg_field(sc, A_TP_KEEP_INTVL,
3666 V_KEEPALIVEINTVL(M_KEEPALIVEINTVL), V_KEEPALIVEINTVL(v));
3668 if (t4_toe_keepalive_count != 0) {
3669 v = t4_toe_keepalive_count & M_KEEPALIVEMAXR2;
3670 t4_set_reg_field(sc, A_TP_SHIFT_CNT,
3671 V_KEEPALIVEMAXR1(M_KEEPALIVEMAXR1) |
3672 V_KEEPALIVEMAXR2(M_KEEPALIVEMAXR2),
3673 V_KEEPALIVEMAXR1(1) | V_KEEPALIVEMAXR2(v));
3675 if (t4_toe_rexmt_min != 0) {
3676 v = us_to_tcp_ticks(sc, t4_toe_rexmt_min);
3678 t4_set_reg_field(sc, A_TP_RXT_MIN,
3679 V_RXTMIN(M_RXTMIN), V_RXTMIN(v));
3681 if (t4_toe_rexmt_max != 0) {
3682 v = us_to_tcp_ticks(sc, t4_toe_rexmt_max);
3684 t4_set_reg_field(sc, A_TP_RXT_MAX,
3685 V_RXTMAX(M_RXTMAX), V_RXTMAX(v));
3687 if (t4_toe_rexmt_count != 0) {
3688 v = t4_toe_rexmt_count & M_RXTSHIFTMAXR2;
3689 t4_set_reg_field(sc, A_TP_SHIFT_CNT,
3690 V_RXTSHIFTMAXR1(M_RXTSHIFTMAXR1) |
3691 V_RXTSHIFTMAXR2(M_RXTSHIFTMAXR2),
3692 V_RXTSHIFTMAXR1(1) | V_RXTSHIFTMAXR2(v));
3694 for (i = 0; i < nitems(t4_toe_rexmt_backoff); i++) {
3695 if (t4_toe_rexmt_backoff[i] != -1) {
3696 v = t4_toe_rexmt_backoff[i] & M_TIMERBACKOFFINDEX0;
3697 shift = (i & 3) << 3;
3698 t4_set_reg_field(sc, A_TP_TCP_BACKOFF_REG0 + (i & ~3),
3699 M_TIMERBACKOFFINDEX0 << shift, v << shift);
3706 #undef FW_PARAM_PFVF
3710 t4_set_desc(struct adapter *sc)
3713 struct adapter_params *p = &sc->params;
3715 snprintf(buf, sizeof(buf), "Chelsio %s", p->vpd.id);
3717 device_set_desc_copy(sc->dev, buf);
3721 build_medialist(struct port_info *pi, struct ifmedia *media)
3725 PORT_LOCK_ASSERT_OWNED(pi);
3727 ifmedia_removeall(media);
3730 * XXX: Would it be better to ifmedia_add all 4 combinations of pause
3731 * settings for every speed instead of just txpause|rxpause? ifconfig
3732 * media display looks much better if autoselect is the only case where
3733 * ifm_current is different from ifm_active. If the user picks anything
3734 * except txpause|rxpause the display is ugly.
3736 m = IFM_ETHER | IFM_FDX | IFM_ETH_TXPAUSE | IFM_ETH_RXPAUSE;
3738 switch(pi->port_type) {
3739 case FW_PORT_TYPE_BT_XFI:
3740 case FW_PORT_TYPE_BT_XAUI:
3741 ifmedia_add(media, m | IFM_10G_T, 0, NULL);
3744 case FW_PORT_TYPE_BT_SGMII:
3745 ifmedia_add(media, m | IFM_1000_T, 0, NULL);
3746 ifmedia_add(media, m | IFM_100_TX, 0, NULL);
3747 ifmedia_add(media, IFM_ETHER | IFM_AUTO, 0, NULL);
3748 ifmedia_set(media, IFM_ETHER | IFM_AUTO);
3751 case FW_PORT_TYPE_CX4:
3752 ifmedia_add(media, m | IFM_10G_CX4, 0, NULL);
3753 ifmedia_set(media, m | IFM_10G_CX4);
3756 case FW_PORT_TYPE_QSFP_10G:
3757 case FW_PORT_TYPE_SFP:
3758 case FW_PORT_TYPE_FIBER_XFI:
3759 case FW_PORT_TYPE_FIBER_XAUI:
3760 switch (pi->mod_type) {
3762 case FW_PORT_MOD_TYPE_LR:
3763 ifmedia_add(media, m | IFM_10G_LR, 0, NULL);
3764 ifmedia_set(media, m | IFM_10G_LR);
3767 case FW_PORT_MOD_TYPE_SR:
3768 ifmedia_add(media, m | IFM_10G_SR, 0, NULL);
3769 ifmedia_set(media, m | IFM_10G_SR);
3772 case FW_PORT_MOD_TYPE_LRM:
3773 ifmedia_add(media, m | IFM_10G_LRM, 0, NULL);
3774 ifmedia_set(media, m | IFM_10G_LRM);
3777 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
3778 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
3779 ifmedia_add(media, m | IFM_10G_TWINAX, 0, NULL);
3780 ifmedia_set(media, m | IFM_10G_TWINAX);
3783 case FW_PORT_MOD_TYPE_NONE:
3785 ifmedia_add(media, m | IFM_NONE, 0, NULL);
3786 ifmedia_set(media, m | IFM_NONE);
3789 case FW_PORT_MOD_TYPE_NA:
3790 case FW_PORT_MOD_TYPE_ER:
3792 device_printf(pi->dev,
3793 "unknown port_type (%d), mod_type (%d)\n",
3794 pi->port_type, pi->mod_type);
3795 ifmedia_add(media, m | IFM_UNKNOWN, 0, NULL);
3796 ifmedia_set(media, m | IFM_UNKNOWN);
3801 case FW_PORT_TYPE_CR_QSFP:
3802 case FW_PORT_TYPE_SFP28:
3803 case FW_PORT_TYPE_KR_SFP28:
3804 switch (pi->mod_type) {
3806 case FW_PORT_MOD_TYPE_SR:
3807 ifmedia_add(media, m | IFM_25G_SR, 0, NULL);
3808 ifmedia_set(media, m | IFM_25G_SR);
3811 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
3812 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
3813 ifmedia_add(media, m | IFM_25G_CR, 0, NULL);
3814 ifmedia_set(media, m | IFM_25G_CR);
3817 case FW_PORT_MOD_TYPE_NONE:
3819 ifmedia_add(media, m | IFM_NONE, 0, NULL);
3820 ifmedia_set(media, m | IFM_NONE);
3824 device_printf(pi->dev,
3825 "unknown port_type (%d), mod_type (%d)\n",
3826 pi->port_type, pi->mod_type);
3827 ifmedia_add(media, m | IFM_UNKNOWN, 0, NULL);
3828 ifmedia_set(media, m | IFM_UNKNOWN);
3833 case FW_PORT_TYPE_QSFP:
3834 switch (pi->mod_type) {
3836 case FW_PORT_MOD_TYPE_LR:
3837 ifmedia_add(media, m | IFM_40G_LR4, 0, NULL);
3838 ifmedia_set(media, m | IFM_40G_LR4);
3841 case FW_PORT_MOD_TYPE_SR:
3842 ifmedia_add(media, m | IFM_40G_SR4, 0, NULL);
3843 ifmedia_set(media, m | IFM_40G_SR4);
3846 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
3847 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
3848 ifmedia_add(media, m | IFM_40G_CR4, 0, NULL);
3849 ifmedia_set(media, m | IFM_40G_CR4);
3852 case FW_PORT_MOD_TYPE_NONE:
3854 ifmedia_add(media, m | IFM_NONE, 0, NULL);
3855 ifmedia_set(media, m | IFM_NONE);
3859 device_printf(pi->dev,
3860 "unknown port_type (%d), mod_type (%d)\n",
3861 pi->port_type, pi->mod_type);
3862 ifmedia_add(media, m | IFM_UNKNOWN, 0, NULL);
3863 ifmedia_set(media, m | IFM_UNKNOWN);
3868 case FW_PORT_TYPE_KR4_100G:
3869 case FW_PORT_TYPE_CR4_QSFP:
3870 switch (pi->mod_type) {
3872 case FW_PORT_MOD_TYPE_LR:
3873 ifmedia_add(media, m | IFM_100G_LR4, 0, NULL);
3874 ifmedia_set(media, m | IFM_100G_LR4);
3877 case FW_PORT_MOD_TYPE_SR:
3878 ifmedia_add(media, m | IFM_100G_SR4, 0, NULL);
3879 ifmedia_set(media, m | IFM_100G_SR4);
3882 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
3883 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
3884 ifmedia_add(media, m | IFM_100G_CR4, 0, NULL);
3885 ifmedia_set(media, m | IFM_100G_CR4);
3888 case FW_PORT_MOD_TYPE_NONE:
3890 ifmedia_add(media, m | IFM_NONE, 0, NULL);
3891 ifmedia_set(media, m | IFM_NONE);
3895 device_printf(pi->dev,
3896 "unknown port_type (%d), mod_type (%d)\n",
3897 pi->port_type, pi->mod_type);
3898 ifmedia_add(media, m | IFM_UNKNOWN, 0, NULL);
3899 ifmedia_set(media, m | IFM_UNKNOWN);
3905 device_printf(pi->dev,
3906 "unknown port_type (%d), mod_type (%d)\n", pi->port_type,
3908 ifmedia_add(media, m | IFM_UNKNOWN, 0, NULL);
3909 ifmedia_set(media, m | IFM_UNKNOWN);
3915 * Update all the requested_* fields in the link config and then send a mailbox
3916 * command to apply the settings.
3919 init_l1cfg(struct port_info *pi)
3921 struct adapter *sc = pi->adapter;
3922 struct link_config *lc = &pi->link_cfg;
3925 ASSERT_SYNCHRONIZED_OP(sc);
3927 if (t4_autoneg != 0 && lc->supported & FW_PORT_CAP_ANEG) {
3928 lc->requested_aneg = AUTONEG_ENABLE;
3929 lc->requested_speed = 0;
3931 lc->requested_aneg = AUTONEG_DISABLE;
3932 lc->requested_speed = port_top_speed(pi); /* in Gbps */
3935 lc->requested_fc = t4_pause_settings & (PAUSE_TX | PAUSE_RX);
3938 lc->requested_fec = t4_fec & (FEC_RS | FEC_BASER_RS |
3941 /* Use the suggested value provided by the firmware in acaps */
3942 if (lc->advertising & FW_PORT_CAP_FEC_RS)
3943 lc->requested_fec = FEC_RS;
3944 else if (lc->advertising & FW_PORT_CAP_FEC_BASER_RS)
3945 lc->requested_fec = FEC_BASER_RS;
3946 else if (lc->advertising & FW_PORT_CAP_FEC_RESERVED)
3947 lc->requested_fec = FEC_RESERVED;
3949 lc->requested_fec = 0;
3952 rc = -t4_link_l1cfg(sc, sc->mbox, pi->tx_chan, lc);
3954 device_printf(pi->dev, "l1cfg failed: %d\n", rc);
3956 lc->fc = lc->requested_fc;
3957 lc->fec = lc->requested_fec;
3961 #define FW_MAC_EXACT_CHUNK 7
3964 * Program the port's XGMAC based on parameters in ifnet. The caller also
3965 * indicates which parameters should be programmed (the rest are left alone).
3968 update_mac_settings(struct ifnet *ifp, int flags)
3971 struct vi_info *vi = ifp->if_softc;
3972 struct port_info *pi = vi->pi;
3973 struct adapter *sc = pi->adapter;
3974 int mtu = -1, promisc = -1, allmulti = -1, vlanex = -1;
3976 ASSERT_SYNCHRONIZED_OP(sc);
3977 KASSERT(flags, ("%s: not told what to update.", __func__));
3979 if (flags & XGMAC_MTU)
3982 if (flags & XGMAC_PROMISC)
3983 promisc = ifp->if_flags & IFF_PROMISC ? 1 : 0;
3985 if (flags & XGMAC_ALLMULTI)
3986 allmulti = ifp->if_flags & IFF_ALLMULTI ? 1 : 0;
3988 if (flags & XGMAC_VLANEX)
3989 vlanex = ifp->if_capenable & IFCAP_VLAN_HWTAGGING ? 1 : 0;
3991 if (flags & (XGMAC_MTU|XGMAC_PROMISC|XGMAC_ALLMULTI|XGMAC_VLANEX)) {
3992 rc = -t4_set_rxmode(sc, sc->mbox, vi->viid, mtu, promisc,
3993 allmulti, 1, vlanex, false);
3995 if_printf(ifp, "set_rxmode (%x) failed: %d\n", flags,
4001 if (flags & XGMAC_UCADDR) {
4002 uint8_t ucaddr[ETHER_ADDR_LEN];
4004 bcopy(IF_LLADDR(ifp), ucaddr, sizeof(ucaddr));
4005 rc = t4_change_mac(sc, sc->mbox, vi->viid, vi->xact_addr_filt,
4006 ucaddr, true, true);
4009 if_printf(ifp, "change_mac failed: %d\n", rc);
4012 vi->xact_addr_filt = rc;
4017 if (flags & XGMAC_MCADDRS) {
4018 const uint8_t *mcaddr[FW_MAC_EXACT_CHUNK];
4021 struct ifmultiaddr *ifma;
4024 if_maddr_rlock(ifp);
4025 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
4026 if (ifma->ifma_addr->sa_family != AF_LINK)
4029 LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
4030 MPASS(ETHER_IS_MULTICAST(mcaddr[i]));
4033 if (i == FW_MAC_EXACT_CHUNK) {
4034 rc = t4_alloc_mac_filt(sc, sc->mbox, vi->viid,
4035 del, i, mcaddr, NULL, &hash, 0);
4038 for (j = 0; j < i; j++) {
4040 "failed to add mc address"
4042 "%02x:%02x:%02x rc=%d\n",
4043 mcaddr[j][0], mcaddr[j][1],
4044 mcaddr[j][2], mcaddr[j][3],
4045 mcaddr[j][4], mcaddr[j][5],
4055 rc = t4_alloc_mac_filt(sc, sc->mbox, vi->viid, del, i,
4056 mcaddr, NULL, &hash, 0);
4059 for (j = 0; j < i; j++) {
4061 "failed to add mc address"
4063 "%02x:%02x:%02x rc=%d\n",
4064 mcaddr[j][0], mcaddr[j][1],
4065 mcaddr[j][2], mcaddr[j][3],
4066 mcaddr[j][4], mcaddr[j][5],
4073 rc = -t4_set_addr_hash(sc, sc->mbox, vi->viid, 0, hash, 0);
4075 if_printf(ifp, "failed to set mc address hash: %d", rc);
4077 if_maddr_runlock(ifp);
4084 * {begin|end}_synchronized_op must be called from the same thread.
4087 begin_synchronized_op(struct adapter *sc, struct vi_info *vi, int flags,
4093 /* the caller thinks it's ok to sleep, but is it really? */
4094 if (flags & SLEEP_OK)
4095 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
4096 "begin_synchronized_op");
4107 if (vi && IS_DOOMED(vi)) {
4117 if (!(flags & SLEEP_OK)) {
4122 if (mtx_sleep(&sc->flags, &sc->sc_lock, pri, wmesg, 0)) {
4128 KASSERT(!IS_BUSY(sc), ("%s: controller busy.", __func__));
4131 sc->last_op = wmesg;
4132 sc->last_op_thr = curthread;
4133 sc->last_op_flags = flags;
4137 if (!(flags & HOLD_LOCK) || rc)
4144 * Tell if_ioctl and if_init that the VI is going away. This is
4145 * special variant of begin_synchronized_op and must be paired with a
4146 * call to end_synchronized_op.
4149 doom_vi(struct adapter *sc, struct vi_info *vi)
4156 mtx_sleep(&sc->flags, &sc->sc_lock, 0, "t4detach", 0);
4159 sc->last_op = "t4detach";
4160 sc->last_op_thr = curthread;
4161 sc->last_op_flags = 0;
4167 * {begin|end}_synchronized_op must be called from the same thread.
4170 end_synchronized_op(struct adapter *sc, int flags)
4173 if (flags & LOCK_HELD)
4174 ADAPTER_LOCK_ASSERT_OWNED(sc);
4178 KASSERT(IS_BUSY(sc), ("%s: controller not busy.", __func__));
4185 cxgbe_init_synchronized(struct vi_info *vi)
4187 struct port_info *pi = vi->pi;
4188 struct adapter *sc = pi->adapter;
4189 struct ifnet *ifp = vi->ifp;
4191 struct sge_txq *txq;
4193 ASSERT_SYNCHRONIZED_OP(sc);
4195 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
4196 return (0); /* already running */
4198 if (!(sc->flags & FULL_INIT_DONE) &&
4199 ((rc = adapter_full_init(sc)) != 0))
4200 return (rc); /* error message displayed already */
4202 if (!(vi->flags & VI_INIT_DONE) &&
4203 ((rc = vi_full_init(vi)) != 0))
4204 return (rc); /* error message displayed already */
4206 rc = update_mac_settings(ifp, XGMAC_ALL);
4208 goto done; /* error message displayed already */
4210 rc = -t4_enable_vi(sc, sc->mbox, vi->viid, true, true);
4212 if_printf(ifp, "enable_vi failed: %d\n", rc);
4217 * Can't fail from this point onwards. Review cxgbe_uninit_synchronized
4221 for_each_txq(vi, i, txq) {
4223 txq->eq.flags |= EQ_ENABLED;
4228 * The first iq of the first port to come up is used for tracing.
4230 if (sc->traceq < 0 && IS_MAIN_VI(vi)) {
4231 sc->traceq = sc->sge.rxq[vi->first_rxq].iq.abs_id;
4232 t4_write_reg(sc, is_t4(sc) ? A_MPS_TRC_RSS_CONTROL :
4233 A_MPS_T5_TRC_RSS_CONTROL, V_RSSCONTROL(pi->tx_chan) |
4234 V_QUEUENUMBER(sc->traceq));
4235 pi->flags |= HAS_TRACEQ;
4240 if (pi->up_vis++ == 0) {
4241 t4_update_port_info(pi);
4242 build_medialist(pi, &pi->media);
4245 ifp->if_drv_flags |= IFF_DRV_RUNNING;
4247 if (pi->nvi > 1 || sc->flags & IS_VF)
4248 callout_reset(&vi->tick, hz, vi_tick, vi);
4250 callout_reset(&pi->tick, hz, cxgbe_tick, pi);
4254 cxgbe_uninit_synchronized(vi);
4263 cxgbe_uninit_synchronized(struct vi_info *vi)
4265 struct port_info *pi = vi->pi;
4266 struct adapter *sc = pi->adapter;
4267 struct ifnet *ifp = vi->ifp;
4269 struct sge_txq *txq;
4271 ASSERT_SYNCHRONIZED_OP(sc);
4273 if (!(vi->flags & VI_INIT_DONE)) {
4274 KASSERT(!(ifp->if_drv_flags & IFF_DRV_RUNNING),
4275 ("uninited VI is running"));
4280 * Disable the VI so that all its data in either direction is discarded
4281 * by the MPS. Leave everything else (the queues, interrupts, and 1Hz
4282 * tick) intact as the TP can deliver negative advice or data that it's
4283 * holding in its RAM (for an offloaded connection) even after the VI is
4286 rc = -t4_enable_vi(sc, sc->mbox, vi->viid, false, false);
4288 if_printf(ifp, "disable_vi failed: %d\n", rc);
4292 for_each_txq(vi, i, txq) {
4294 txq->eq.flags &= ~EQ_ENABLED;
4299 if (pi->nvi > 1 || sc->flags & IS_VF)
4300 callout_stop(&vi->tick);
4302 callout_stop(&pi->tick);
4303 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
4307 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
4309 if (pi->up_vis > 0) {
4315 pi->link_cfg.link_ok = 0;
4316 pi->link_cfg.speed = 0;
4317 pi->link_cfg.link_down_rc = 255;
4318 t4_os_link_changed(pi);
4319 pi->old_link_cfg = pi->link_cfg;
4325 * It is ok for this function to fail midway and return right away. t4_detach
4326 * will walk the entire sc->irq list and clean up whatever is valid.
4329 t4_setup_intr_handlers(struct adapter *sc)
4331 int rc, rid, p, q, v;
4334 struct port_info *pi;
4336 struct sge *sge = &sc->sge;
4337 struct sge_rxq *rxq;
4339 struct sge_ofld_rxq *ofld_rxq;
4342 struct sge_nm_rxq *nm_rxq;
4345 int nbuckets = rss_getnumbuckets();
4352 rid = sc->intr_type == INTR_INTX ? 0 : 1;
4353 if (sc->intr_count == 1)
4354 return (t4_alloc_irq(sc, irq, rid, t4_intr_all, sc, "all"));
4356 /* Multiple interrupts. */
4357 if (sc->flags & IS_VF)
4358 KASSERT(sc->intr_count >= T4VF_EXTRA_INTR + sc->params.nports,
4359 ("%s: too few intr.", __func__));
4361 KASSERT(sc->intr_count >= T4_EXTRA_INTR + sc->params.nports,
4362 ("%s: too few intr.", __func__));
4364 /* The first one is always error intr on PFs */
4365 if (!(sc->flags & IS_VF)) {
4366 rc = t4_alloc_irq(sc, irq, rid, t4_intr_err, sc, "err");
4373 /* The second one is always the firmware event queue (first on VFs) */
4374 rc = t4_alloc_irq(sc, irq, rid, t4_intr_evt, &sge->fwq, "evt");
4380 for_each_port(sc, p) {
4382 for_each_vi(pi, v, vi) {
4383 vi->first_intr = rid - 1;
4385 if (vi->nnmrxq > 0) {
4386 int n = max(vi->nrxq, vi->nnmrxq);
4388 MPASS(vi->flags & INTR_RXQ);
4390 rxq = &sge->rxq[vi->first_rxq];
4392 nm_rxq = &sge->nm_rxq[vi->first_nm_rxq];
4394 for (q = 0; q < n; q++) {
4395 snprintf(s, sizeof(s), "%x%c%x", p,
4401 irq->nm_rxq = nm_rxq++;
4403 rc = t4_alloc_irq(sc, irq, rid,
4404 t4_vi_intr, irq, s);
4411 } else if (vi->flags & INTR_RXQ) {
4412 for_each_rxq(vi, q, rxq) {
4413 snprintf(s, sizeof(s), "%x%c%x", p,
4415 rc = t4_alloc_irq(sc, irq, rid,
4420 bus_bind_intr(sc->dev, irq->res,
4421 rss_getcpu(q % nbuckets));
4429 if (vi->flags & INTR_OFLD_RXQ) {
4430 for_each_ofld_rxq(vi, q, ofld_rxq) {
4431 snprintf(s, sizeof(s), "%x%c%x", p,
4433 rc = t4_alloc_irq(sc, irq, rid,
4434 t4_intr, ofld_rxq, s);
4445 MPASS(irq == &sc->irq[sc->intr_count]);
4451 adapter_full_init(struct adapter *sc)
4455 uint32_t raw_rss_key[RSS_KEYSIZE / sizeof(uint32_t)];
4456 uint32_t rss_key[RSS_KEYSIZE / sizeof(uint32_t)];
4459 ASSERT_SYNCHRONIZED_OP(sc);
4460 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
4461 KASSERT((sc->flags & FULL_INIT_DONE) == 0,
4462 ("%s: FULL_INIT_DONE already", __func__));
4465 * queues that belong to the adapter (not any particular port).
4467 rc = t4_setup_adapter_queues(sc);
4471 for (i = 0; i < nitems(sc->tq); i++) {
4472 sc->tq[i] = taskqueue_create("t4 taskq", M_NOWAIT,
4473 taskqueue_thread_enqueue, &sc->tq[i]);
4474 if (sc->tq[i] == NULL) {
4475 device_printf(sc->dev,
4476 "failed to allocate task queue %d\n", i);
4480 taskqueue_start_threads(&sc->tq[i], 1, PI_NET, "%s tq%d",
4481 device_get_nameunit(sc->dev), i);
4484 MPASS(RSS_KEYSIZE == 40);
4485 rss_getkey((void *)&raw_rss_key[0]);
4486 for (i = 0; i < nitems(rss_key); i++) {
4487 rss_key[i] = htobe32(raw_rss_key[nitems(rss_key) - 1 - i]);
4489 t4_write_rss_key(sc, &rss_key[0], -1, 1);
4492 if (!(sc->flags & IS_VF))
4494 sc->flags |= FULL_INIT_DONE;
4497 adapter_full_uninit(sc);
4503 adapter_full_uninit(struct adapter *sc)
4507 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
4509 t4_teardown_adapter_queues(sc);
4511 for (i = 0; i < nitems(sc->tq) && sc->tq[i]; i++) {
4512 taskqueue_free(sc->tq[i]);
4516 sc->flags &= ~FULL_INIT_DONE;
4522 #define SUPPORTED_RSS_HASHTYPES (RSS_HASHTYPE_RSS_IPV4 | \
4523 RSS_HASHTYPE_RSS_TCP_IPV4 | RSS_HASHTYPE_RSS_IPV6 | \
4524 RSS_HASHTYPE_RSS_TCP_IPV6 | RSS_HASHTYPE_RSS_UDP_IPV4 | \
4525 RSS_HASHTYPE_RSS_UDP_IPV6)
4527 /* Translates kernel hash types to hardware. */
4529 hashconfig_to_hashen(int hashconfig)
4533 if (hashconfig & RSS_HASHTYPE_RSS_IPV4)
4534 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN;
4535 if (hashconfig & RSS_HASHTYPE_RSS_IPV6)
4536 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN;
4537 if (hashconfig & RSS_HASHTYPE_RSS_UDP_IPV4) {
4538 hashen |= F_FW_RSS_VI_CONFIG_CMD_UDPEN |
4539 F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
4541 if (hashconfig & RSS_HASHTYPE_RSS_UDP_IPV6) {
4542 hashen |= F_FW_RSS_VI_CONFIG_CMD_UDPEN |
4543 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
4545 if (hashconfig & RSS_HASHTYPE_RSS_TCP_IPV4)
4546 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
4547 if (hashconfig & RSS_HASHTYPE_RSS_TCP_IPV6)
4548 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
4553 /* Translates hardware hash types to kernel. */
4555 hashen_to_hashconfig(int hashen)
4559 if (hashen & F_FW_RSS_VI_CONFIG_CMD_UDPEN) {
4561 * If UDP hashing was enabled it must have been enabled for
4562 * either IPv4 or IPv6 (inclusive or). Enabling UDP without
4563 * enabling any 4-tuple hash is nonsense configuration.
4565 MPASS(hashen & (F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN |
4566 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN));
4568 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN)
4569 hashconfig |= RSS_HASHTYPE_RSS_UDP_IPV4;
4570 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN)
4571 hashconfig |= RSS_HASHTYPE_RSS_UDP_IPV6;
4573 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN)
4574 hashconfig |= RSS_HASHTYPE_RSS_TCP_IPV4;
4575 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN)
4576 hashconfig |= RSS_HASHTYPE_RSS_TCP_IPV6;
4577 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN)
4578 hashconfig |= RSS_HASHTYPE_RSS_IPV4;
4579 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN)
4580 hashconfig |= RSS_HASHTYPE_RSS_IPV6;
4582 return (hashconfig);
4587 vi_full_init(struct vi_info *vi)
4589 struct adapter *sc = vi->pi->adapter;
4590 struct ifnet *ifp = vi->ifp;
4592 struct sge_rxq *rxq;
4593 int rc, i, j, hashen;
4595 int nbuckets = rss_getnumbuckets();
4596 int hashconfig = rss_gethashconfig();
4600 ASSERT_SYNCHRONIZED_OP(sc);
4601 KASSERT((vi->flags & VI_INIT_DONE) == 0,
4602 ("%s: VI_INIT_DONE already", __func__));
4604 sysctl_ctx_init(&vi->ctx);
4605 vi->flags |= VI_SYSCTL_CTX;
4608 * Allocate tx/rx/fl queues for this VI.
4610 rc = t4_setup_vi_queues(vi);
4612 goto done; /* error message displayed already */
4615 * Setup RSS for this VI. Save a copy of the RSS table for later use.
4617 if (vi->nrxq > vi->rss_size) {
4618 if_printf(ifp, "nrxq (%d) > hw RSS table size (%d); "
4619 "some queues will never receive traffic.\n", vi->nrxq,
4621 } else if (vi->rss_size % vi->nrxq) {
4622 if_printf(ifp, "nrxq (%d), hw RSS table size (%d); "
4623 "expect uneven traffic distribution.\n", vi->nrxq,
4627 if (vi->nrxq != nbuckets) {
4628 if_printf(ifp, "nrxq (%d) != kernel RSS buckets (%d);"
4629 "performance will be impacted.\n", vi->nrxq, nbuckets);
4632 rss = malloc(vi->rss_size * sizeof (*rss), M_CXGBE, M_ZERO | M_WAITOK);
4633 for (i = 0; i < vi->rss_size;) {
4635 j = rss_get_indirection_to_bucket(i);
4637 rxq = &sc->sge.rxq[vi->first_rxq + j];
4638 rss[i++] = rxq->iq.abs_id;
4640 for_each_rxq(vi, j, rxq) {
4641 rss[i++] = rxq->iq.abs_id;
4642 if (i == vi->rss_size)
4648 rc = -t4_config_rss_range(sc, sc->mbox, vi->viid, 0, vi->rss_size, rss,
4651 if_printf(ifp, "rss_config failed: %d\n", rc);
4656 hashen = hashconfig_to_hashen(hashconfig);
4659 * We may have had to enable some hashes even though the global config
4660 * wants them disabled. This is a potential problem that must be
4661 * reported to the user.
4663 extra = hashen_to_hashconfig(hashen) ^ hashconfig;
4666 * If we consider only the supported hash types, then the enabled hashes
4667 * are a superset of the requested hashes. In other words, there cannot
4668 * be any supported hash that was requested but not enabled, but there
4669 * can be hashes that were not requested but had to be enabled.
4671 extra &= SUPPORTED_RSS_HASHTYPES;
4672 MPASS((extra & hashconfig) == 0);
4676 "global RSS config (0x%x) cannot be accommodated.\n",
4679 if (extra & RSS_HASHTYPE_RSS_IPV4)
4680 if_printf(ifp, "IPv4 2-tuple hashing forced on.\n");
4681 if (extra & RSS_HASHTYPE_RSS_TCP_IPV4)
4682 if_printf(ifp, "TCP/IPv4 4-tuple hashing forced on.\n");
4683 if (extra & RSS_HASHTYPE_RSS_IPV6)
4684 if_printf(ifp, "IPv6 2-tuple hashing forced on.\n");
4685 if (extra & RSS_HASHTYPE_RSS_TCP_IPV6)
4686 if_printf(ifp, "TCP/IPv6 4-tuple hashing forced on.\n");
4687 if (extra & RSS_HASHTYPE_RSS_UDP_IPV4)
4688 if_printf(ifp, "UDP/IPv4 4-tuple hashing forced on.\n");
4689 if (extra & RSS_HASHTYPE_RSS_UDP_IPV6)
4690 if_printf(ifp, "UDP/IPv6 4-tuple hashing forced on.\n");
4692 hashen = F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN |
4693 F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN |
4694 F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN |
4695 F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN | F_FW_RSS_VI_CONFIG_CMD_UDPEN;
4697 rc = -t4_config_vi_rss(sc, sc->mbox, vi->viid, hashen, rss[0], 0, 0);
4699 if_printf(ifp, "rss hash/defaultq config failed: %d\n", rc);
4704 vi->flags |= VI_INIT_DONE;
4716 vi_full_uninit(struct vi_info *vi)
4718 struct port_info *pi = vi->pi;
4719 struct adapter *sc = pi->adapter;
4721 struct sge_rxq *rxq;
4722 struct sge_txq *txq;
4724 struct sge_ofld_rxq *ofld_rxq;
4725 struct sge_wrq *ofld_txq;
4728 if (vi->flags & VI_INIT_DONE) {
4730 /* Need to quiesce queues. */
4732 /* XXX: Only for the first VI? */
4733 if (IS_MAIN_VI(vi) && !(sc->flags & IS_VF))
4734 quiesce_wrq(sc, &sc->sge.ctrlq[pi->port_id]);
4736 for_each_txq(vi, i, txq) {
4737 quiesce_txq(sc, txq);
4741 for_each_ofld_txq(vi, i, ofld_txq) {
4742 quiesce_wrq(sc, ofld_txq);
4746 for_each_rxq(vi, i, rxq) {
4747 quiesce_iq(sc, &rxq->iq);
4748 quiesce_fl(sc, &rxq->fl);
4752 for_each_ofld_rxq(vi, i, ofld_rxq) {
4753 quiesce_iq(sc, &ofld_rxq->iq);
4754 quiesce_fl(sc, &ofld_rxq->fl);
4757 free(vi->rss, M_CXGBE);
4758 free(vi->nm_rss, M_CXGBE);
4761 t4_teardown_vi_queues(vi);
4762 vi->flags &= ~VI_INIT_DONE;
4768 quiesce_txq(struct adapter *sc, struct sge_txq *txq)
4770 struct sge_eq *eq = &txq->eq;
4771 struct sge_qstat *spg = (void *)&eq->desc[eq->sidx];
4773 (void) sc; /* unused */
4777 MPASS((eq->flags & EQ_ENABLED) == 0);
4781 /* Wait for the mp_ring to empty. */
4782 while (!mp_ring_is_idle(txq->r)) {
4783 mp_ring_check_drainage(txq->r, 0);
4784 pause("rquiesce", 1);
4787 /* Then wait for the hardware to finish. */
4788 while (spg->cidx != htobe16(eq->pidx))
4789 pause("equiesce", 1);
4791 /* Finally, wait for the driver to reclaim all descriptors. */
4792 while (eq->cidx != eq->pidx)
4793 pause("dquiesce", 1);
4797 quiesce_wrq(struct adapter *sc, struct sge_wrq *wrq)
4804 quiesce_iq(struct adapter *sc, struct sge_iq *iq)
4806 (void) sc; /* unused */
4808 /* Synchronize with the interrupt handler */
4809 while (!atomic_cmpset_int(&iq->state, IQS_IDLE, IQS_DISABLED))
4814 quiesce_fl(struct adapter *sc, struct sge_fl *fl)
4816 mtx_lock(&sc->sfl_lock);
4818 fl->flags |= FL_DOOMED;
4820 callout_stop(&sc->sfl_callout);
4821 mtx_unlock(&sc->sfl_lock);
4823 KASSERT((fl->flags & FL_STARVING) == 0,
4824 ("%s: still starving", __func__));
4828 t4_alloc_irq(struct adapter *sc, struct irq *irq, int rid,
4829 driver_intr_t *handler, void *arg, char *name)
4834 irq->res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &irq->rid,
4835 RF_SHAREABLE | RF_ACTIVE);
4836 if (irq->res == NULL) {
4837 device_printf(sc->dev,
4838 "failed to allocate IRQ for rid %d, name %s.\n", rid, name);
4842 rc = bus_setup_intr(sc->dev, irq->res, INTR_MPSAFE | INTR_TYPE_NET,
4843 NULL, handler, arg, &irq->tag);
4845 device_printf(sc->dev,
4846 "failed to setup interrupt for rid %d, name %s: %d\n",
4849 bus_describe_intr(sc->dev, irq->res, irq->tag, "%s", name);
4855 t4_free_irq(struct adapter *sc, struct irq *irq)
4858 bus_teardown_intr(sc->dev, irq->res, irq->tag);
4860 bus_release_resource(sc->dev, SYS_RES_IRQ, irq->rid, irq->res);
4862 bzero(irq, sizeof(*irq));
4868 get_regs(struct adapter *sc, struct t4_regdump *regs, uint8_t *buf)
4871 regs->version = chip_id(sc) | chip_rev(sc) << 10;
4872 t4_get_regs(sc, buf, regs->len);
4875 #define A_PL_INDIR_CMD 0x1f8
4877 #define S_PL_AUTOINC 31
4878 #define M_PL_AUTOINC 0x1U
4879 #define V_PL_AUTOINC(x) ((x) << S_PL_AUTOINC)
4880 #define G_PL_AUTOINC(x) (((x) >> S_PL_AUTOINC) & M_PL_AUTOINC)
4882 #define S_PL_VFID 20
4883 #define M_PL_VFID 0xffU
4884 #define V_PL_VFID(x) ((x) << S_PL_VFID)
4885 #define G_PL_VFID(x) (((x) >> S_PL_VFID) & M_PL_VFID)
4888 #define M_PL_ADDR 0xfffffU
4889 #define V_PL_ADDR(x) ((x) << S_PL_ADDR)
4890 #define G_PL_ADDR(x) (((x) >> S_PL_ADDR) & M_PL_ADDR)
4892 #define A_PL_INDIR_DATA 0x1fc
4895 read_vf_stat(struct adapter *sc, unsigned int viid, int reg)
4899 mtx_assert(&sc->reg_lock, MA_OWNED);
4900 if (sc->flags & IS_VF) {
4901 stats[0] = t4_read_reg(sc, VF_MPS_REG(reg));
4902 stats[1] = t4_read_reg(sc, VF_MPS_REG(reg + 4));
4904 t4_write_reg(sc, A_PL_INDIR_CMD, V_PL_AUTOINC(1) |
4905 V_PL_VFID(G_FW_VIID_VIN(viid)) |
4906 V_PL_ADDR(VF_MPS_REG(reg)));
4907 stats[0] = t4_read_reg(sc, A_PL_INDIR_DATA);
4908 stats[1] = t4_read_reg(sc, A_PL_INDIR_DATA);
4910 return (((uint64_t)stats[1]) << 32 | stats[0]);
4914 t4_get_vi_stats(struct adapter *sc, unsigned int viid,
4915 struct fw_vi_stats_vf *stats)
4918 #define GET_STAT(name) \
4919 read_vf_stat(sc, viid, A_MPS_VF_STAT_##name##_L)
4921 stats->tx_bcast_bytes = GET_STAT(TX_VF_BCAST_BYTES);
4922 stats->tx_bcast_frames = GET_STAT(TX_VF_BCAST_FRAMES);
4923 stats->tx_mcast_bytes = GET_STAT(TX_VF_MCAST_BYTES);
4924 stats->tx_mcast_frames = GET_STAT(TX_VF_MCAST_FRAMES);
4925 stats->tx_ucast_bytes = GET_STAT(TX_VF_UCAST_BYTES);
4926 stats->tx_ucast_frames = GET_STAT(TX_VF_UCAST_FRAMES);
4927 stats->tx_drop_frames = GET_STAT(TX_VF_DROP_FRAMES);
4928 stats->tx_offload_bytes = GET_STAT(TX_VF_OFFLOAD_BYTES);
4929 stats->tx_offload_frames = GET_STAT(TX_VF_OFFLOAD_FRAMES);
4930 stats->rx_bcast_bytes = GET_STAT(RX_VF_BCAST_BYTES);
4931 stats->rx_bcast_frames = GET_STAT(RX_VF_BCAST_FRAMES);
4932 stats->rx_mcast_bytes = GET_STAT(RX_VF_MCAST_BYTES);
4933 stats->rx_mcast_frames = GET_STAT(RX_VF_MCAST_FRAMES);
4934 stats->rx_ucast_bytes = GET_STAT(RX_VF_UCAST_BYTES);
4935 stats->rx_ucast_frames = GET_STAT(RX_VF_UCAST_FRAMES);
4936 stats->rx_err_frames = GET_STAT(RX_VF_ERR_FRAMES);
4942 t4_clr_vi_stats(struct adapter *sc, unsigned int viid)
4946 t4_write_reg(sc, A_PL_INDIR_CMD, V_PL_AUTOINC(1) |
4947 V_PL_VFID(G_FW_VIID_VIN(viid)) |
4948 V_PL_ADDR(VF_MPS_REG(A_MPS_VF_STAT_TX_VF_BCAST_BYTES_L)));
4949 for (reg = A_MPS_VF_STAT_TX_VF_BCAST_BYTES_L;
4950 reg <= A_MPS_VF_STAT_RX_VF_ERR_FRAMES_H; reg += 4)
4951 t4_write_reg(sc, A_PL_INDIR_DATA, 0);
4955 vi_refresh_stats(struct adapter *sc, struct vi_info *vi)
4958 const struct timeval interval = {0, 250000}; /* 250ms */
4960 if (!(vi->flags & VI_INIT_DONE))
4964 timevalsub(&tv, &interval);
4965 if (timevalcmp(&tv, &vi->last_refreshed, <))
4968 mtx_lock(&sc->reg_lock);
4969 t4_get_vi_stats(sc, vi->viid, &vi->stats);
4970 getmicrotime(&vi->last_refreshed);
4971 mtx_unlock(&sc->reg_lock);
4975 cxgbe_refresh_stats(struct adapter *sc, struct port_info *pi)
4977 u_int i, v, tnl_cong_drops, bg_map;
4979 const struct timeval interval = {0, 250000}; /* 250ms */
4982 timevalsub(&tv, &interval);
4983 if (timevalcmp(&tv, &pi->last_refreshed, <))
4987 t4_get_port_stats(sc, pi->tx_chan, &pi->stats);
4988 bg_map = pi->mps_bg_map;
4990 i = ffs(bg_map) - 1;
4991 mtx_lock(&sc->reg_lock);
4992 t4_read_indirect(sc, A_TP_MIB_INDEX, A_TP_MIB_DATA, &v, 1,
4993 A_TP_MIB_TNL_CNG_DROP_0 + i);
4994 mtx_unlock(&sc->reg_lock);
4995 tnl_cong_drops += v;
4996 bg_map &= ~(1 << i);
4998 pi->tnl_cong_drops = tnl_cong_drops;
4999 getmicrotime(&pi->last_refreshed);
5003 cxgbe_tick(void *arg)
5005 struct port_info *pi = arg;
5006 struct adapter *sc = pi->adapter;
5008 PORT_LOCK_ASSERT_OWNED(pi);
5009 cxgbe_refresh_stats(sc, pi);
5011 callout_schedule(&pi->tick, hz);
5017 struct vi_info *vi = arg;
5018 struct adapter *sc = vi->pi->adapter;
5020 vi_refresh_stats(sc, vi);
5022 callout_schedule(&vi->tick, hz);
5026 cxgbe_vlan_config(void *arg, struct ifnet *ifp, uint16_t vid)
5030 if (arg != ifp || ifp->if_type != IFT_ETHER)
5033 vlan = VLAN_DEVAT(ifp, vid);
5034 VLAN_SETCOOKIE(vlan, ifp);
5038 * Should match fw_caps_config_<foo> enums in t4fw_interface.h
5040 static char *caps_decoder[] = {
5041 "\20\001IPMI\002NCSI", /* 0: NBM */
5042 "\20\001PPP\002QFC\003DCBX", /* 1: link */
5043 "\20\001INGRESS\002EGRESS", /* 2: switch */
5044 "\20\001NIC\002VM\003IDS\004UM\005UM_ISGL" /* 3: NIC */
5045 "\006HASHFILTER\007ETHOFLD",
5046 "\20\001TOE", /* 4: TOE */
5047 "\20\001RDDP\002RDMAC", /* 5: RDMA */
5048 "\20\001INITIATOR_PDU\002TARGET_PDU" /* 6: iSCSI */
5049 "\003INITIATOR_CNXOFLD\004TARGET_CNXOFLD"
5050 "\005INITIATOR_SSNOFLD\006TARGET_SSNOFLD"
5052 "\010INITIATOR_CMDOFLD\011TARGET_CMDOFLD",
5053 "\20\001LOOKASIDE\002TLSKEYS", /* 7: Crypto */
5054 "\20\001INITIATOR\002TARGET\003CTRL_OFLD" /* 8: FCoE */
5055 "\004PO_INITIATOR\005PO_TARGET",
5059 t4_sysctls(struct adapter *sc)
5061 struct sysctl_ctx_list *ctx;
5062 struct sysctl_oid *oid;
5063 struct sysctl_oid_list *children, *c0;
5064 static char *doorbells = {"\20\1UDB\2WCWR\3UDBWC\4KDB"};
5066 ctx = device_get_sysctl_ctx(sc->dev);
5071 oid = device_get_sysctl_tree(sc->dev);
5072 c0 = children = SYSCTL_CHILDREN(oid);
5074 sc->sc_do_rxcopy = 1;
5075 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "do_rx_copy", CTLFLAG_RW,
5076 &sc->sc_do_rxcopy, 1, "Do RX copy of small frames");
5078 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nports", CTLFLAG_RD, NULL,
5079 sc->params.nports, "# of ports");
5081 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "doorbells",
5082 CTLTYPE_STRING | CTLFLAG_RD, doorbells, sc->doorbells,
5083 sysctl_bitfield, "A", "available doorbells");
5085 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "core_clock", CTLFLAG_RD, NULL,
5086 sc->params.vpd.cclk, "core clock frequency (in KHz)");
5088 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_timers",
5089 CTLTYPE_STRING | CTLFLAG_RD, sc->params.sge.timer_val,
5090 sizeof(sc->params.sge.timer_val), sysctl_int_array, "A",
5091 "interrupt holdoff timer values (us)");
5093 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pkt_counts",
5094 CTLTYPE_STRING | CTLFLAG_RD, sc->params.sge.counter_val,
5095 sizeof(sc->params.sge.counter_val), sysctl_int_array, "A",
5096 "interrupt holdoff packet counter values");
5098 t4_sge_sysctls(sc, ctx, children);
5100 sc->lro_timeout = 100;
5101 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "lro_timeout", CTLFLAG_RW,
5102 &sc->lro_timeout, 0, "lro inactive-flush timeout (in us)");
5104 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "dflags", CTLFLAG_RW,
5105 &sc->debug_flags, 0, "flags to enable runtime debugging");
5107 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "tp_version",
5108 CTLFLAG_RD, sc->tp_version, 0, "TP microcode version");
5110 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "firmware_version",
5111 CTLFLAG_RD, sc->fw_version, 0, "firmware version");
5113 if (sc->flags & IS_VF)
5116 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "hw_revision", CTLFLAG_RD,
5117 NULL, chip_rev(sc), "chip hardware revision");
5119 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "sn",
5120 CTLFLAG_RD, sc->params.vpd.sn, 0, "serial number");
5122 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "pn",
5123 CTLFLAG_RD, sc->params.vpd.pn, 0, "part number");
5125 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "ec",
5126 CTLFLAG_RD, sc->params.vpd.ec, 0, "engineering change");
5128 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "na",
5129 CTLFLAG_RD, sc->params.vpd.na, 0, "network address");
5131 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "er_version", CTLFLAG_RD,
5132 sc->er_version, 0, "expansion ROM version");
5134 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "bs_version", CTLFLAG_RD,
5135 sc->bs_version, 0, "bootstrap firmware version");
5137 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "scfg_version", CTLFLAG_RD,
5138 NULL, sc->params.scfg_vers, "serial config version");
5140 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "vpd_version", CTLFLAG_RD,
5141 NULL, sc->params.vpd_vers, "VPD version");
5143 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "cf",
5144 CTLFLAG_RD, sc->cfg_file, 0, "configuration file");
5146 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "cfcsum", CTLFLAG_RD, NULL,
5147 sc->cfcsum, "config file checksum");
5149 #define SYSCTL_CAP(name, n, text) \
5150 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, #name, \
5151 CTLTYPE_STRING | CTLFLAG_RD, caps_decoder[n], sc->name, \
5152 sysctl_bitfield, "A", "available " text " capabilities")
5154 SYSCTL_CAP(nbmcaps, 0, "NBM");
5155 SYSCTL_CAP(linkcaps, 1, "link");
5156 SYSCTL_CAP(switchcaps, 2, "switch");
5157 SYSCTL_CAP(niccaps, 3, "NIC");
5158 SYSCTL_CAP(toecaps, 4, "TCP offload");
5159 SYSCTL_CAP(rdmacaps, 5, "RDMA");
5160 SYSCTL_CAP(iscsicaps, 6, "iSCSI");
5161 SYSCTL_CAP(cryptocaps, 7, "crypto");
5162 SYSCTL_CAP(fcoecaps, 8, "FCoE");
5165 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nfilters", CTLFLAG_RD,
5166 NULL, sc->tids.nftids, "number of filters");
5168 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature", CTLTYPE_INT |
5169 CTLFLAG_RD, sc, 0, sysctl_temperature, "I",
5170 "chip temperature (in Celsius)");
5172 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "core_vdd", CTLFLAG_RD,
5173 &sc->params.core_vdd, 0, "core Vdd (in mV)");
5177 * dev.t4nex.X.misc. Marked CTLFLAG_SKIP to avoid information overload.
5179 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "misc",
5180 CTLFLAG_RD | CTLFLAG_SKIP, NULL,
5181 "logs and miscellaneous information");
5182 children = SYSCTL_CHILDREN(oid);
5184 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cctrl",
5185 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5186 sysctl_cctrl, "A", "congestion control");
5188 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp0",
5189 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5190 sysctl_cim_ibq_obq, "A", "CIM IBQ 0 (TP0)");
5192 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp1",
5193 CTLTYPE_STRING | CTLFLAG_RD, sc, 1,
5194 sysctl_cim_ibq_obq, "A", "CIM IBQ 1 (TP1)");
5196 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ulp",
5197 CTLTYPE_STRING | CTLFLAG_RD, sc, 2,
5198 sysctl_cim_ibq_obq, "A", "CIM IBQ 2 (ULP)");
5200 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge0",
5201 CTLTYPE_STRING | CTLFLAG_RD, sc, 3,
5202 sysctl_cim_ibq_obq, "A", "CIM IBQ 3 (SGE0)");
5204 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge1",
5205 CTLTYPE_STRING | CTLFLAG_RD, sc, 4,
5206 sysctl_cim_ibq_obq, "A", "CIM IBQ 4 (SGE1)");
5208 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ncsi",
5209 CTLTYPE_STRING | CTLFLAG_RD, sc, 5,
5210 sysctl_cim_ibq_obq, "A", "CIM IBQ 5 (NCSI)");
5212 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_la",
5213 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5214 chip_id(sc) <= CHELSIO_T5 ? sysctl_cim_la : sysctl_cim_la_t6,
5215 "A", "CIM logic analyzer");
5217 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ma_la",
5218 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5219 sysctl_cim_ma_la, "A", "CIM MA logic analyzer");
5221 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp0",
5222 CTLTYPE_STRING | CTLFLAG_RD, sc, 0 + CIM_NUM_IBQ,
5223 sysctl_cim_ibq_obq, "A", "CIM OBQ 0 (ULP0)");
5225 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp1",
5226 CTLTYPE_STRING | CTLFLAG_RD, sc, 1 + CIM_NUM_IBQ,
5227 sysctl_cim_ibq_obq, "A", "CIM OBQ 1 (ULP1)");
5229 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp2",
5230 CTLTYPE_STRING | CTLFLAG_RD, sc, 2 + CIM_NUM_IBQ,
5231 sysctl_cim_ibq_obq, "A", "CIM OBQ 2 (ULP2)");
5233 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp3",
5234 CTLTYPE_STRING | CTLFLAG_RD, sc, 3 + CIM_NUM_IBQ,
5235 sysctl_cim_ibq_obq, "A", "CIM OBQ 3 (ULP3)");
5237 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge",
5238 CTLTYPE_STRING | CTLFLAG_RD, sc, 4 + CIM_NUM_IBQ,
5239 sysctl_cim_ibq_obq, "A", "CIM OBQ 4 (SGE)");
5241 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ncsi",
5242 CTLTYPE_STRING | CTLFLAG_RD, sc, 5 + CIM_NUM_IBQ,
5243 sysctl_cim_ibq_obq, "A", "CIM OBQ 5 (NCSI)");
5245 if (chip_id(sc) > CHELSIO_T4) {
5246 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge0_rx",
5247 CTLTYPE_STRING | CTLFLAG_RD, sc, 6 + CIM_NUM_IBQ,
5248 sysctl_cim_ibq_obq, "A", "CIM OBQ 6 (SGE0-RX)");
5250 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge1_rx",
5251 CTLTYPE_STRING | CTLFLAG_RD, sc, 7 + CIM_NUM_IBQ,
5252 sysctl_cim_ibq_obq, "A", "CIM OBQ 7 (SGE1-RX)");
5255 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_pif_la",
5256 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5257 sysctl_cim_pif_la, "A", "CIM PIF logic analyzer");
5259 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_qcfg",
5260 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5261 sysctl_cim_qcfg, "A", "CIM queue configuration");
5263 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cpl_stats",
5264 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5265 sysctl_cpl_stats, "A", "CPL statistics");
5267 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ddp_stats",
5268 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5269 sysctl_ddp_stats, "A", "non-TCP DDP statistics");
5271 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "devlog",
5272 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5273 sysctl_devlog, "A", "firmware's device log");
5275 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fcoe_stats",
5276 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5277 sysctl_fcoe_stats, "A", "FCoE statistics");
5279 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "hw_sched",
5280 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5281 sysctl_hw_sched, "A", "hardware scheduler ");
5283 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "l2t",
5284 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5285 sysctl_l2t, "A", "hardware L2 table");
5287 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "lb_stats",
5288 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5289 sysctl_lb_stats, "A", "loopback statistics");
5291 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "meminfo",
5292 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5293 sysctl_meminfo, "A", "memory regions");
5295 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "mps_tcam",
5296 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5297 chip_id(sc) <= CHELSIO_T5 ? sysctl_mps_tcam : sysctl_mps_tcam_t6,
5298 "A", "MPS TCAM entries");
5300 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "path_mtus",
5301 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5302 sysctl_path_mtus, "A", "path MTUs");
5304 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pm_stats",
5305 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5306 sysctl_pm_stats, "A", "PM statistics");
5308 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rdma_stats",
5309 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5310 sysctl_rdma_stats, "A", "RDMA statistics");
5312 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tcp_stats",
5313 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5314 sysctl_tcp_stats, "A", "TCP statistics");
5316 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tids",
5317 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5318 sysctl_tids, "A", "TID information");
5320 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_err_stats",
5321 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5322 sysctl_tp_err_stats, "A", "TP error statistics");
5324 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_la_mask",
5325 CTLTYPE_INT | CTLFLAG_RW, sc, 0, sysctl_tp_la_mask, "I",
5326 "TP logic analyzer event capture mask");
5328 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_la",
5329 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5330 sysctl_tp_la, "A", "TP logic analyzer");
5332 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_rate",
5333 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5334 sysctl_tx_rate, "A", "Tx rate");
5336 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ulprx_la",
5337 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5338 sysctl_ulprx_la, "A", "ULPRX logic analyzer");
5340 if (chip_id(sc) >= CHELSIO_T5) {
5341 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "wcwr_stats",
5342 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5343 sysctl_wcwr_stats, "A", "write combined work requests");
5348 if (is_offload(sc)) {
5355 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "toe", CTLFLAG_RD,
5356 NULL, "TOE parameters");
5357 children = SYSCTL_CHILDREN(oid);
5359 sc->tt.cong_algorithm = -1;
5360 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "cong_algorithm",
5361 CTLFLAG_RW, &sc->tt.cong_algorithm, 0, "congestion control "
5362 "(-1 = default, 0 = reno, 1 = tahoe, 2 = newreno, "
5365 sc->tt.sndbuf = 256 * 1024;
5366 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "sndbuf", CTLFLAG_RW,
5367 &sc->tt.sndbuf, 0, "max hardware send buffer size");
5370 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ddp", CTLFLAG_RW,
5371 &sc->tt.ddp, 0, "DDP allowed");
5373 sc->tt.rx_coalesce = 1;
5374 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_coalesce",
5375 CTLFLAG_RW, &sc->tt.rx_coalesce, 0, "receive coalescing");
5377 sc->tt.tx_align = 1;
5378 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_align",
5379 CTLFLAG_RW, &sc->tt.tx_align, 0, "chop and align payload");
5381 sc->tt.tx_zcopy = 0;
5382 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_zcopy",
5383 CTLFLAG_RW, &sc->tt.tx_zcopy, 0,
5384 "Enable zero-copy aio_write(2)");
5386 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "timer_tick",
5387 CTLTYPE_STRING | CTLFLAG_RD, sc, 0, sysctl_tp_tick, "A",
5388 "TP timer tick (us)");
5390 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "timestamp_tick",
5391 CTLTYPE_STRING | CTLFLAG_RD, sc, 1, sysctl_tp_tick, "A",
5392 "TCP timestamp tick (us)");
5394 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "dack_tick",
5395 CTLTYPE_STRING | CTLFLAG_RD, sc, 2, sysctl_tp_tick, "A",
5398 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "dack_timer",
5399 CTLTYPE_UINT | CTLFLAG_RD, sc, 0, sysctl_tp_dack_timer,
5400 "IU", "DACK timer (us)");
5402 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_min",
5403 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_RXT_MIN,
5404 sysctl_tp_timer, "LU", "Minimum retransmit interval (us)");
5406 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_max",
5407 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_RXT_MAX,
5408 sysctl_tp_timer, "LU", "Maximum retransmit interval (us)");
5410 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "persist_min",
5411 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_PERS_MIN,
5412 sysctl_tp_timer, "LU", "Persist timer min (us)");
5414 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "persist_max",
5415 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_PERS_MAX,
5416 sysctl_tp_timer, "LU", "Persist timer max (us)");
5418 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_idle",
5419 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_KEEP_IDLE,
5420 sysctl_tp_timer, "LU", "Keepalive idle timer (us)");
5422 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_interval",
5423 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_KEEP_INTVL,
5424 sysctl_tp_timer, "LU", "Keepalive interval timer (us)");
5426 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "initial_srtt",
5427 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_INIT_SRTT,
5428 sysctl_tp_timer, "LU", "Initial SRTT (us)");
5430 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "finwait2_timer",
5431 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_FINWAIT2_TIMER,
5432 sysctl_tp_timer, "LU", "FINWAIT2 timer (us)");
5434 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "syn_rexmt_count",
5435 CTLTYPE_UINT | CTLFLAG_RD, sc, S_SYNSHIFTMAX,
5436 sysctl_tp_shift_cnt, "IU",
5437 "Number of SYN retransmissions before abort");
5439 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_count",
5440 CTLTYPE_UINT | CTLFLAG_RD, sc, S_RXTSHIFTMAXR2,
5441 sysctl_tp_shift_cnt, "IU",
5442 "Number of retransmissions before abort");
5444 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_count",
5445 CTLTYPE_UINT | CTLFLAG_RD, sc, S_KEEPALIVEMAXR2,
5446 sysctl_tp_shift_cnt, "IU",
5447 "Number of keepalive probes before abort");
5449 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "rexmt_backoff",
5450 CTLFLAG_RD, NULL, "TOE retransmit backoffs");
5451 children = SYSCTL_CHILDREN(oid);
5452 for (i = 0; i < 16; i++) {
5453 snprintf(s, sizeof(s), "%u", i);
5454 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, s,
5455 CTLTYPE_UINT | CTLFLAG_RD, sc, i, sysctl_tp_backoff,
5456 "IU", "TOE retransmit backoff");
5463 vi_sysctls(struct vi_info *vi)
5465 struct sysctl_ctx_list *ctx;
5466 struct sysctl_oid *oid;
5467 struct sysctl_oid_list *children;
5469 ctx = device_get_sysctl_ctx(vi->dev);
5472 * dev.v?(cxgbe|cxl).X.
5474 oid = device_get_sysctl_tree(vi->dev);
5475 children = SYSCTL_CHILDREN(oid);
5477 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "viid", CTLFLAG_RD, NULL,
5478 vi->viid, "VI identifer");
5479 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nrxq", CTLFLAG_RD,
5480 &vi->nrxq, 0, "# of rx queues");
5481 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ntxq", CTLFLAG_RD,
5482 &vi->ntxq, 0, "# of tx queues");
5483 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_rxq", CTLFLAG_RD,
5484 &vi->first_rxq, 0, "index of first rx queue");
5485 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_txq", CTLFLAG_RD,
5486 &vi->first_txq, 0, "index of first tx queue");
5487 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "rss_size", CTLFLAG_RD, NULL,
5488 vi->rss_size, "size of RSS indirection table");
5490 if (IS_MAIN_VI(vi)) {
5491 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rsrv_noflowq",
5492 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_noflowq, "IU",
5493 "Reserve queue 0 for non-flowid packets");
5497 if (vi->nofldrxq != 0) {
5498 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldrxq", CTLFLAG_RD,
5500 "# of rx queues for offloaded TCP connections");
5501 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldtxq", CTLFLAG_RD,
5503 "# of tx queues for offloaded TCP connections");
5504 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_rxq",
5505 CTLFLAG_RD, &vi->first_ofld_rxq, 0,
5506 "index of first TOE rx queue");
5507 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_txq",
5508 CTLFLAG_RD, &vi->first_ofld_txq, 0,
5509 "index of first TOE tx queue");
5510 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx_ofld",
5511 CTLTYPE_INT | CTLFLAG_RW, vi, 0,
5512 sysctl_holdoff_tmr_idx_ofld, "I",
5513 "holdoff timer index for TOE queues");
5514 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx_ofld",
5515 CTLTYPE_INT | CTLFLAG_RW, vi, 0,
5516 sysctl_holdoff_pktc_idx_ofld, "I",
5517 "holdoff packet counter index for TOE queues");
5521 if (vi->nnmrxq != 0) {
5522 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmrxq", CTLFLAG_RD,
5523 &vi->nnmrxq, 0, "# of netmap rx queues");
5524 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmtxq", CTLFLAG_RD,
5525 &vi->nnmtxq, 0, "# of netmap tx queues");
5526 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_rxq",
5527 CTLFLAG_RD, &vi->first_nm_rxq, 0,
5528 "index of first netmap rx queue");
5529 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_txq",
5530 CTLFLAG_RD, &vi->first_nm_txq, 0,
5531 "index of first netmap tx queue");
5535 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx",
5536 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_holdoff_tmr_idx, "I",
5537 "holdoff timer index");
5538 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx",
5539 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_holdoff_pktc_idx, "I",
5540 "holdoff packet counter index");
5542 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_rxq",
5543 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_qsize_rxq, "I",
5545 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_txq",
5546 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_qsize_txq, "I",
5551 cxgbe_sysctls(struct port_info *pi)
5553 struct sysctl_ctx_list *ctx;
5554 struct sysctl_oid *oid;
5555 struct sysctl_oid_list *children, *children2;
5556 struct adapter *sc = pi->adapter;
5560 ctx = device_get_sysctl_ctx(pi->dev);
5565 oid = device_get_sysctl_tree(pi->dev);
5566 children = SYSCTL_CHILDREN(oid);
5568 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "linkdnrc", CTLTYPE_STRING |
5569 CTLFLAG_RD, pi, 0, sysctl_linkdnrc, "A", "reason why link is down");
5570 if (pi->port_type == FW_PORT_TYPE_BT_XAUI) {
5571 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature",
5572 CTLTYPE_INT | CTLFLAG_RD, pi, 0, sysctl_btphy, "I",
5573 "PHY temperature (in Celsius)");
5574 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fw_version",
5575 CTLTYPE_INT | CTLFLAG_RD, pi, 1, sysctl_btphy, "I",
5576 "PHY firmware version");
5579 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pause_settings",
5580 CTLTYPE_STRING | CTLFLAG_RW, pi, 0, sysctl_pause_settings, "A",
5581 "PAUSE settings (bit 0 = rx_pause, bit 1 = tx_pause)");
5582 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fec",
5583 CTLTYPE_STRING | CTLFLAG_RW, pi, 0, sysctl_fec, "A",
5584 "Forward Error Correction (bit 0 = RS, bit 1 = BASER_RS)");
5585 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "autoneg",
5586 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_autoneg, "I",
5587 "autonegotiation (-1 = not supported)");
5589 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "max_speed", CTLFLAG_RD, NULL,
5590 port_top_speed(pi), "max speed (in Gbps)");
5591 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "mps_bg_map", CTLFLAG_RD, NULL,
5592 pi->mps_bg_map, "MPS buffer group map");
5593 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_e_chan_map", CTLFLAG_RD,
5594 NULL, pi->rx_e_chan_map, "TP rx e-channel map");
5596 if (sc->flags & IS_VF)
5600 * dev.(cxgbe|cxl).X.tc.
5602 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "tc", CTLFLAG_RD, NULL,
5603 "Tx scheduler traffic classes (cl_rl)");
5604 for (i = 0; i < sc->chip_params->nsched_cls; i++) {
5605 struct tx_cl_rl_params *tc = &pi->sched_params->cl_rl[i];
5607 snprintf(name, sizeof(name), "%d", i);
5608 children2 = SYSCTL_CHILDREN(SYSCTL_ADD_NODE(ctx,
5609 SYSCTL_CHILDREN(oid), OID_AUTO, name, CTLFLAG_RD, NULL,
5611 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "flags", CTLFLAG_RD,
5612 &tc->flags, 0, "flags");
5613 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "refcount",
5614 CTLFLAG_RD, &tc->refcount, 0, "references to this class");
5616 SYSCTL_ADD_PROC(ctx, children2, OID_AUTO, "params",
5617 CTLTYPE_STRING | CTLFLAG_RD, sc, (pi->port_id << 16) | i,
5618 sysctl_tc_params, "A", "traffic class parameters");
5623 * dev.cxgbe.X.stats.
5625 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats", CTLFLAG_RD,
5626 NULL, "port statistics");
5627 children = SYSCTL_CHILDREN(oid);
5628 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "tx_parse_error", CTLFLAG_RD,
5629 &pi->tx_parse_error, 0,
5630 "# of tx packets with invalid length or # of segments");
5632 #define SYSCTL_ADD_T4_REG64(pi, name, desc, reg) \
5633 SYSCTL_ADD_OID(ctx, children, OID_AUTO, name, \
5634 CTLTYPE_U64 | CTLFLAG_RD, sc, reg, \
5635 sysctl_handle_t4_reg64, "QU", desc)
5637 SYSCTL_ADD_T4_REG64(pi, "tx_octets", "# of octets in good frames",
5638 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BYTES_L));
5639 SYSCTL_ADD_T4_REG64(pi, "tx_frames", "total # of good frames",
5640 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_FRAMES_L));
5641 SYSCTL_ADD_T4_REG64(pi, "tx_bcast_frames", "# of broadcast frames",
5642 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BCAST_L));
5643 SYSCTL_ADD_T4_REG64(pi, "tx_mcast_frames", "# of multicast frames",
5644 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_MCAST_L));
5645 SYSCTL_ADD_T4_REG64(pi, "tx_ucast_frames", "# of unicast frames",
5646 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_UCAST_L));
5647 SYSCTL_ADD_T4_REG64(pi, "tx_error_frames", "# of error frames",
5648 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_ERROR_L));
5649 SYSCTL_ADD_T4_REG64(pi, "tx_frames_64",
5650 "# of tx frames in this range",
5651 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_64B_L));
5652 SYSCTL_ADD_T4_REG64(pi, "tx_frames_65_127",
5653 "# of tx frames in this range",
5654 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_65B_127B_L));
5655 SYSCTL_ADD_T4_REG64(pi, "tx_frames_128_255",
5656 "# of tx frames in this range",
5657 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_128B_255B_L));
5658 SYSCTL_ADD_T4_REG64(pi, "tx_frames_256_511",
5659 "# of tx frames in this range",
5660 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_256B_511B_L));
5661 SYSCTL_ADD_T4_REG64(pi, "tx_frames_512_1023",
5662 "# of tx frames in this range",
5663 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_512B_1023B_L));
5664 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1024_1518",
5665 "# of tx frames in this range",
5666 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1024B_1518B_L));
5667 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1519_max",
5668 "# of tx frames in this range",
5669 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1519B_MAX_L));
5670 SYSCTL_ADD_T4_REG64(pi, "tx_drop", "# of dropped tx frames",
5671 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_DROP_L));
5672 SYSCTL_ADD_T4_REG64(pi, "tx_pause", "# of pause frames transmitted",
5673 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PAUSE_L));
5674 SYSCTL_ADD_T4_REG64(pi, "tx_ppp0", "# of PPP prio 0 frames transmitted",
5675 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP0_L));
5676 SYSCTL_ADD_T4_REG64(pi, "tx_ppp1", "# of PPP prio 1 frames transmitted",
5677 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP1_L));
5678 SYSCTL_ADD_T4_REG64(pi, "tx_ppp2", "# of PPP prio 2 frames transmitted",
5679 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP2_L));
5680 SYSCTL_ADD_T4_REG64(pi, "tx_ppp3", "# of PPP prio 3 frames transmitted",
5681 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP3_L));
5682 SYSCTL_ADD_T4_REG64(pi, "tx_ppp4", "# of PPP prio 4 frames transmitted",
5683 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP4_L));
5684 SYSCTL_ADD_T4_REG64(pi, "tx_ppp5", "# of PPP prio 5 frames transmitted",
5685 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP5_L));
5686 SYSCTL_ADD_T4_REG64(pi, "tx_ppp6", "# of PPP prio 6 frames transmitted",
5687 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP6_L));
5688 SYSCTL_ADD_T4_REG64(pi, "tx_ppp7", "# of PPP prio 7 frames transmitted",
5689 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP7_L));
5691 SYSCTL_ADD_T4_REG64(pi, "rx_octets", "# of octets in good frames",
5692 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BYTES_L));
5693 SYSCTL_ADD_T4_REG64(pi, "rx_frames", "total # of good frames",
5694 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_FRAMES_L));
5695 SYSCTL_ADD_T4_REG64(pi, "rx_bcast_frames", "# of broadcast frames",
5696 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BCAST_L));
5697 SYSCTL_ADD_T4_REG64(pi, "rx_mcast_frames", "# of multicast frames",
5698 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MCAST_L));
5699 SYSCTL_ADD_T4_REG64(pi, "rx_ucast_frames", "# of unicast frames",
5700 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_UCAST_L));
5701 SYSCTL_ADD_T4_REG64(pi, "rx_too_long", "# of frames exceeding MTU",
5702 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_ERROR_L));
5703 SYSCTL_ADD_T4_REG64(pi, "rx_jabber", "# of jabber frames",
5704 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_CRC_ERROR_L));
5705 SYSCTL_ADD_T4_REG64(pi, "rx_fcs_err",
5706 "# of frames received with bad FCS",
5707 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_CRC_ERROR_L));
5708 SYSCTL_ADD_T4_REG64(pi, "rx_len_err",
5709 "# of frames received with length error",
5710 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LEN_ERROR_L));
5711 SYSCTL_ADD_T4_REG64(pi, "rx_symbol_err", "symbol errors",
5712 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_SYM_ERROR_L));
5713 SYSCTL_ADD_T4_REG64(pi, "rx_runt", "# of short frames received",
5714 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LESS_64B_L));
5715 SYSCTL_ADD_T4_REG64(pi, "rx_frames_64",
5716 "# of rx frames in this range",
5717 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_64B_L));
5718 SYSCTL_ADD_T4_REG64(pi, "rx_frames_65_127",
5719 "# of rx frames in this range",
5720 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_65B_127B_L));
5721 SYSCTL_ADD_T4_REG64(pi, "rx_frames_128_255",
5722 "# of rx frames in this range",
5723 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_128B_255B_L));
5724 SYSCTL_ADD_T4_REG64(pi, "rx_frames_256_511",
5725 "# of rx frames in this range",
5726 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_256B_511B_L));
5727 SYSCTL_ADD_T4_REG64(pi, "rx_frames_512_1023",
5728 "# of rx frames in this range",
5729 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_512B_1023B_L));
5730 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1024_1518",
5731 "# of rx frames in this range",
5732 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1024B_1518B_L));
5733 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1519_max",
5734 "# of rx frames in this range",
5735 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1519B_MAX_L));
5736 SYSCTL_ADD_T4_REG64(pi, "rx_pause", "# of pause frames received",
5737 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PAUSE_L));
5738 SYSCTL_ADD_T4_REG64(pi, "rx_ppp0", "# of PPP prio 0 frames received",
5739 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP0_L));
5740 SYSCTL_ADD_T4_REG64(pi, "rx_ppp1", "# of PPP prio 1 frames received",
5741 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP1_L));
5742 SYSCTL_ADD_T4_REG64(pi, "rx_ppp2", "# of PPP prio 2 frames received",
5743 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP2_L));
5744 SYSCTL_ADD_T4_REG64(pi, "rx_ppp3", "# of PPP prio 3 frames received",
5745 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP3_L));
5746 SYSCTL_ADD_T4_REG64(pi, "rx_ppp4", "# of PPP prio 4 frames received",
5747 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP4_L));
5748 SYSCTL_ADD_T4_REG64(pi, "rx_ppp5", "# of PPP prio 5 frames received",
5749 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP5_L));
5750 SYSCTL_ADD_T4_REG64(pi, "rx_ppp6", "# of PPP prio 6 frames received",
5751 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP6_L));
5752 SYSCTL_ADD_T4_REG64(pi, "rx_ppp7", "# of PPP prio 7 frames received",
5753 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP7_L));
5755 #undef SYSCTL_ADD_T4_REG64
5757 #define SYSCTL_ADD_T4_PORTSTAT(name, desc) \
5758 SYSCTL_ADD_UQUAD(ctx, children, OID_AUTO, #name, CTLFLAG_RD, \
5759 &pi->stats.name, desc)
5761 /* We get these from port_stats and they may be stale by up to 1s */
5762 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow0,
5763 "# drops due to buffer-group 0 overflows");
5764 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow1,
5765 "# drops due to buffer-group 1 overflows");
5766 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow2,
5767 "# drops due to buffer-group 2 overflows");
5768 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow3,
5769 "# drops due to buffer-group 3 overflows");
5770 SYSCTL_ADD_T4_PORTSTAT(rx_trunc0,
5771 "# of buffer-group 0 truncated packets");
5772 SYSCTL_ADD_T4_PORTSTAT(rx_trunc1,
5773 "# of buffer-group 1 truncated packets");
5774 SYSCTL_ADD_T4_PORTSTAT(rx_trunc2,
5775 "# of buffer-group 2 truncated packets");
5776 SYSCTL_ADD_T4_PORTSTAT(rx_trunc3,
5777 "# of buffer-group 3 truncated packets");
5779 #undef SYSCTL_ADD_T4_PORTSTAT
5783 sysctl_int_array(SYSCTL_HANDLER_ARGS)
5785 int rc, *i, space = 0;
5788 sbuf_new_for_sysctl(&sb, NULL, 64, req);
5789 for (i = arg1; arg2; arg2 -= sizeof(int), i++) {
5791 sbuf_printf(&sb, " ");
5792 sbuf_printf(&sb, "%d", *i);
5795 rc = sbuf_finish(&sb);
5801 sysctl_bitfield(SYSCTL_HANDLER_ARGS)
5806 rc = sysctl_wire_old_buffer(req, 0);
5810 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
5814 sbuf_printf(sb, "%b", (int)arg2, (char *)arg1);
5815 rc = sbuf_finish(sb);
5822 sysctl_btphy(SYSCTL_HANDLER_ARGS)
5824 struct port_info *pi = arg1;
5826 struct adapter *sc = pi->adapter;
5830 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK, "t4btt");
5833 /* XXX: magic numbers */
5834 rc = -t4_mdio_rd(sc, sc->mbox, pi->mdio_addr, 0x1e, op ? 0x20 : 0xc820,
5836 end_synchronized_op(sc, 0);
5842 rc = sysctl_handle_int(oidp, &v, 0, req);
5847 sysctl_noflowq(SYSCTL_HANDLER_ARGS)
5849 struct vi_info *vi = arg1;
5852 val = vi->rsrv_noflowq;
5853 rc = sysctl_handle_int(oidp, &val, 0, req);
5854 if (rc != 0 || req->newptr == NULL)
5857 if ((val >= 1) && (vi->ntxq > 1))
5858 vi->rsrv_noflowq = 1;
5860 vi->rsrv_noflowq = 0;
5866 sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS)
5868 struct vi_info *vi = arg1;
5869 struct adapter *sc = vi->pi->adapter;
5871 struct sge_rxq *rxq;
5876 rc = sysctl_handle_int(oidp, &idx, 0, req);
5877 if (rc != 0 || req->newptr == NULL)
5880 if (idx < 0 || idx >= SGE_NTIMERS)
5883 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5888 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(vi->pktc_idx != -1);
5889 for_each_rxq(vi, i, rxq) {
5890 #ifdef atomic_store_rel_8
5891 atomic_store_rel_8(&rxq->iq.intr_params, v);
5893 rxq->iq.intr_params = v;
5898 end_synchronized_op(sc, LOCK_HELD);
5903 sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS)
5905 struct vi_info *vi = arg1;
5906 struct adapter *sc = vi->pi->adapter;
5911 rc = sysctl_handle_int(oidp, &idx, 0, req);
5912 if (rc != 0 || req->newptr == NULL)
5915 if (idx < -1 || idx >= SGE_NCOUNTERS)
5918 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5923 if (vi->flags & VI_INIT_DONE)
5924 rc = EBUSY; /* cannot be changed once the queues are created */
5928 end_synchronized_op(sc, LOCK_HELD);
5933 sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS)
5935 struct vi_info *vi = arg1;
5936 struct adapter *sc = vi->pi->adapter;
5939 qsize = vi->qsize_rxq;
5941 rc = sysctl_handle_int(oidp, &qsize, 0, req);
5942 if (rc != 0 || req->newptr == NULL)
5945 if (qsize < 128 || (qsize & 7))
5948 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5953 if (vi->flags & VI_INIT_DONE)
5954 rc = EBUSY; /* cannot be changed once the queues are created */
5956 vi->qsize_rxq = qsize;
5958 end_synchronized_op(sc, LOCK_HELD);
5963 sysctl_qsize_txq(SYSCTL_HANDLER_ARGS)
5965 struct vi_info *vi = arg1;
5966 struct adapter *sc = vi->pi->adapter;
5969 qsize = vi->qsize_txq;
5971 rc = sysctl_handle_int(oidp, &qsize, 0, req);
5972 if (rc != 0 || req->newptr == NULL)
5975 if (qsize < 128 || qsize > 65536)
5978 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
5983 if (vi->flags & VI_INIT_DONE)
5984 rc = EBUSY; /* cannot be changed once the queues are created */
5986 vi->qsize_txq = qsize;
5988 end_synchronized_op(sc, LOCK_HELD);
5993 sysctl_pause_settings(SYSCTL_HANDLER_ARGS)
5995 struct port_info *pi = arg1;
5996 struct adapter *sc = pi->adapter;
5997 struct link_config *lc = &pi->link_cfg;
6000 if (req->newptr == NULL) {
6002 static char *bits = "\20\1PAUSE_RX\2PAUSE_TX";
6004 rc = sysctl_wire_old_buffer(req, 0);
6008 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
6012 sbuf_printf(sb, "%b", lc->fc & (PAUSE_TX | PAUSE_RX), bits);
6013 rc = sbuf_finish(sb);
6019 s[0] = '0' + (lc->requested_fc & (PAUSE_TX | PAUSE_RX));
6022 rc = sysctl_handle_string(oidp, s, sizeof(s), req);
6028 if (s[0] < '0' || s[0] > '9')
6029 return (EINVAL); /* not a number */
6031 if (n & ~(PAUSE_TX | PAUSE_RX))
6032 return (EINVAL); /* some other bit is set too */
6034 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK,
6038 if ((lc->requested_fc & (PAUSE_TX | PAUSE_RX)) != n) {
6039 lc->requested_fc &= ~(PAUSE_TX | PAUSE_RX);
6040 lc->requested_fc |= n;
6041 rc = -t4_link_l1cfg(sc, sc->mbox, pi->tx_chan, lc);
6043 lc->fc = lc->requested_fc;
6046 end_synchronized_op(sc, 0);
6053 sysctl_fec(SYSCTL_HANDLER_ARGS)
6055 struct port_info *pi = arg1;
6056 struct adapter *sc = pi->adapter;
6057 struct link_config *lc = &pi->link_cfg;
6060 if (req->newptr == NULL) {
6062 static char *bits = "\20\1RS\2BASER_RS\3RESERVED";
6064 rc = sysctl_wire_old_buffer(req, 0);
6068 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
6072 sbuf_printf(sb, "%b", lc->fec & M_FW_PORT_CAP_FEC, bits);
6073 rc = sbuf_finish(sb);
6079 s[0] = '0' + (lc->requested_fec & M_FW_PORT_CAP_FEC);
6082 rc = sysctl_handle_string(oidp, s, sizeof(s), req);
6088 if (s[0] < '0' || s[0] > '9')
6089 return (EINVAL); /* not a number */
6091 if (n & ~M_FW_PORT_CAP_FEC)
6092 return (EINVAL); /* some other bit is set too */
6094 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK,
6098 if ((lc->requested_fec & M_FW_PORT_CAP_FEC) != n) {
6099 lc->requested_fec = n &
6100 G_FW_PORT_CAP_FEC(lc->supported);
6101 rc = -t4_link_l1cfg(sc, sc->mbox, pi->tx_chan, lc);
6103 lc->fec = lc->requested_fec;
6106 end_synchronized_op(sc, 0);
6113 sysctl_autoneg(SYSCTL_HANDLER_ARGS)
6115 struct port_info *pi = arg1;
6116 struct adapter *sc = pi->adapter;
6117 struct link_config *lc = &pi->link_cfg;
6120 if (lc->supported & FW_PORT_CAP_ANEG)
6121 val = lc->requested_aneg == AUTONEG_ENABLE ? 1 : 0;
6124 rc = sysctl_handle_int(oidp, &val, 0, req);
6125 if (rc != 0 || req->newptr == NULL)
6127 if ((lc->supported & FW_PORT_CAP_ANEG) == 0)
6131 val = AUTONEG_DISABLE;
6133 val = AUTONEG_ENABLE;
6136 if (lc->requested_aneg == val)
6137 return (0); /* no change */
6139 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK,
6143 old = lc->requested_aneg;
6144 lc->requested_aneg = val;
6145 rc = -t4_link_l1cfg(sc, sc->mbox, pi->tx_chan, lc);
6147 lc->requested_aneg = old;
6148 end_synchronized_op(sc, 0);
6153 sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS)
6155 struct adapter *sc = arg1;
6159 val = t4_read_reg64(sc, reg);
6161 return (sysctl_handle_64(oidp, &val, 0, req));
6165 sysctl_temperature(SYSCTL_HANDLER_ARGS)
6167 struct adapter *sc = arg1;
6169 uint32_t param, val;
6171 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4temp");
6174 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
6175 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) |
6176 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_TMP);
6177 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
6178 end_synchronized_op(sc, 0);
6182 /* unknown is returned as 0 but we display -1 in that case */
6183 t = val == 0 ? -1 : val;
6185 rc = sysctl_handle_int(oidp, &t, 0, req);
6191 sysctl_cctrl(SYSCTL_HANDLER_ARGS)
6193 struct adapter *sc = arg1;
6196 uint16_t incr[NMTUS][NCCTRL_WIN];
6197 static const char *dec_fac[] = {
6198 "0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
6202 rc = sysctl_wire_old_buffer(req, 0);
6206 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6210 t4_read_cong_tbl(sc, incr);
6212 for (i = 0; i < NCCTRL_WIN; ++i) {
6213 sbuf_printf(sb, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
6214 incr[0][i], incr[1][i], incr[2][i], incr[3][i], incr[4][i],
6215 incr[5][i], incr[6][i], incr[7][i]);
6216 sbuf_printf(sb, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
6217 incr[8][i], incr[9][i], incr[10][i], incr[11][i],
6218 incr[12][i], incr[13][i], incr[14][i], incr[15][i],
6219 sc->params.a_wnd[i], dec_fac[sc->params.b_wnd[i]]);
6222 rc = sbuf_finish(sb);
6228 static const char *qname[CIM_NUM_IBQ + CIM_NUM_OBQ_T5] = {
6229 "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI", /* ibq's */
6230 "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI", /* obq's */
6231 "SGE0-RX", "SGE1-RX" /* additional obq's (T5 onwards) */
6235 sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS)
6237 struct adapter *sc = arg1;
6239 int rc, i, n, qid = arg2;
6242 u_int cim_num_obq = sc->chip_params->cim_num_obq;
6244 KASSERT(qid >= 0 && qid < CIM_NUM_IBQ + cim_num_obq,
6245 ("%s: bad qid %d\n", __func__, qid));
6247 if (qid < CIM_NUM_IBQ) {
6250 n = 4 * CIM_IBQ_SIZE;
6251 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
6252 rc = t4_read_cim_ibq(sc, qid, buf, n);
6254 /* outbound queue */
6257 n = 4 * cim_num_obq * CIM_OBQ_SIZE;
6258 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
6259 rc = t4_read_cim_obq(sc, qid, buf, n);
6266 n = rc * sizeof(uint32_t); /* rc has # of words actually read */
6268 rc = sysctl_wire_old_buffer(req, 0);
6272 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
6278 sbuf_printf(sb, "%s%d %s", qtype , qid, qname[arg2]);
6279 for (i = 0, p = buf; i < n; i += 16, p += 4)
6280 sbuf_printf(sb, "\n%#06x: %08x %08x %08x %08x", i, p[0], p[1],
6283 rc = sbuf_finish(sb);
6291 sysctl_cim_la(SYSCTL_HANDLER_ARGS)
6293 struct adapter *sc = arg1;
6299 MPASS(chip_id(sc) <= CHELSIO_T5);
6301 rc = -t4_cim_read(sc, A_UP_UP_DBG_LA_CFG, 1, &cfg);
6305 rc = sysctl_wire_old_buffer(req, 0);
6309 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6313 buf = malloc(sc->params.cim_la_size * sizeof(uint32_t), M_CXGBE,
6316 rc = -t4_cim_read_la(sc, buf, NULL);
6320 sbuf_printf(sb, "Status Data PC%s",
6321 cfg & F_UPDBGLACAPTPCONLY ? "" :
6322 " LS0Stat LS0Addr LS0Data");
6324 for (p = buf; p <= &buf[sc->params.cim_la_size - 8]; p += 8) {
6325 if (cfg & F_UPDBGLACAPTPCONLY) {
6326 sbuf_printf(sb, "\n %02x %08x %08x", p[5] & 0xff,
6328 sbuf_printf(sb, "\n %02x %02x%06x %02x%06x",
6329 (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8,
6330 p[4] & 0xff, p[5] >> 8);
6331 sbuf_printf(sb, "\n %02x %x%07x %x%07x",
6332 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
6333 p[1] & 0xf, p[2] >> 4);
6336 "\n %02x %x%07x %x%07x %08x %08x "
6338 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
6339 p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5],
6344 rc = sbuf_finish(sb);
6352 sysctl_cim_la_t6(SYSCTL_HANDLER_ARGS)
6354 struct adapter *sc = arg1;
6360 MPASS(chip_id(sc) > CHELSIO_T5);
6362 rc = -t4_cim_read(sc, A_UP_UP_DBG_LA_CFG, 1, &cfg);
6366 rc = sysctl_wire_old_buffer(req, 0);
6370 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6374 buf = malloc(sc->params.cim_la_size * sizeof(uint32_t), M_CXGBE,
6377 rc = -t4_cim_read_la(sc, buf, NULL);
6381 sbuf_printf(sb, "Status Inst Data PC%s",
6382 cfg & F_UPDBGLACAPTPCONLY ? "" :
6383 " LS0Stat LS0Addr LS0Data LS1Stat LS1Addr LS1Data");
6385 for (p = buf; p <= &buf[sc->params.cim_la_size - 10]; p += 10) {
6386 if (cfg & F_UPDBGLACAPTPCONLY) {
6387 sbuf_printf(sb, "\n %02x %08x %08x %08x",
6388 p[3] & 0xff, p[2], p[1], p[0]);
6389 sbuf_printf(sb, "\n %02x %02x%06x %02x%06x %02x%06x",
6390 (p[6] >> 8) & 0xff, p[6] & 0xff, p[5] >> 8,
6391 p[5] & 0xff, p[4] >> 8, p[4] & 0xff, p[3] >> 8);
6392 sbuf_printf(sb, "\n %02x %04x%04x %04x%04x %04x%04x",
6393 (p[9] >> 16) & 0xff, p[9] & 0xffff, p[8] >> 16,
6394 p[8] & 0xffff, p[7] >> 16, p[7] & 0xffff,
6397 sbuf_printf(sb, "\n %02x %04x%04x %04x%04x %04x%04x "
6398 "%08x %08x %08x %08x %08x %08x",
6399 (p[9] >> 16) & 0xff,
6400 p[9] & 0xffff, p[8] >> 16,
6401 p[8] & 0xffff, p[7] >> 16,
6402 p[7] & 0xffff, p[6] >> 16,
6403 p[2], p[1], p[0], p[5], p[4], p[3]);
6407 rc = sbuf_finish(sb);
6415 sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS)
6417 struct adapter *sc = arg1;
6423 rc = sysctl_wire_old_buffer(req, 0);
6427 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6431 buf = malloc(2 * CIM_MALA_SIZE * 5 * sizeof(uint32_t), M_CXGBE,
6434 t4_cim_read_ma_la(sc, buf, buf + 5 * CIM_MALA_SIZE);
6437 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
6438 sbuf_printf(sb, "\n%02x%08x%08x%08x%08x", p[4], p[3], p[2],
6442 sbuf_printf(sb, "\n\nCnt ID Tag UE Data RDY VLD");
6443 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
6444 sbuf_printf(sb, "\n%3u %2u %x %u %08x%08x %u %u",
6445 (p[2] >> 10) & 0xff, (p[2] >> 7) & 7,
6446 (p[2] >> 3) & 0xf, (p[2] >> 2) & 1,
6447 (p[1] >> 2) | ((p[2] & 3) << 30),
6448 (p[0] >> 2) | ((p[1] & 3) << 30), (p[0] >> 1) & 1,
6452 rc = sbuf_finish(sb);
6459 sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS)
6461 struct adapter *sc = arg1;
6467 rc = sysctl_wire_old_buffer(req, 0);
6471 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6475 buf = malloc(2 * CIM_PIFLA_SIZE * 6 * sizeof(uint32_t), M_CXGBE,
6478 t4_cim_read_pif_la(sc, buf, buf + 6 * CIM_PIFLA_SIZE, NULL, NULL);
6481 sbuf_printf(sb, "Cntl ID DataBE Addr Data");
6482 for (i = 0; i < CIM_PIFLA_SIZE; i++, p += 6) {
6483 sbuf_printf(sb, "\n %02x %02x %04x %08x %08x%08x%08x%08x",
6484 (p[5] >> 22) & 0xff, (p[5] >> 16) & 0x3f, p[5] & 0xffff,
6485 p[4], p[3], p[2], p[1], p[0]);
6488 sbuf_printf(sb, "\n\nCntl ID Data");
6489 for (i = 0; i < CIM_PIFLA_SIZE; i++, p += 6) {
6490 sbuf_printf(sb, "\n %02x %02x %08x%08x%08x%08x",
6491 (p[4] >> 6) & 0xff, p[4] & 0x3f, p[3], p[2], p[1], p[0]);
6494 rc = sbuf_finish(sb);
6501 sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS)
6503 struct adapter *sc = arg1;
6506 uint16_t base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
6507 uint16_t size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
6508 uint16_t thres[CIM_NUM_IBQ];
6509 uint32_t obq_wr[2 * CIM_NUM_OBQ_T5], *wr = obq_wr;
6510 uint32_t stat[4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5)], *p = stat;
6511 u_int cim_num_obq, ibq_rdaddr, obq_rdaddr, nq;
6513 cim_num_obq = sc->chip_params->cim_num_obq;
6515 ibq_rdaddr = A_UP_IBQ_0_RDADDR;
6516 obq_rdaddr = A_UP_OBQ_0_REALADDR;
6518 ibq_rdaddr = A_UP_IBQ_0_SHADOW_RDADDR;
6519 obq_rdaddr = A_UP_OBQ_0_SHADOW_REALADDR;
6521 nq = CIM_NUM_IBQ + cim_num_obq;
6523 rc = -t4_cim_read(sc, ibq_rdaddr, 4 * nq, stat);
6525 rc = -t4_cim_read(sc, obq_rdaddr, 2 * cim_num_obq, obq_wr);
6529 t4_read_cimq_cfg(sc, base, size, thres);
6531 rc = sysctl_wire_old_buffer(req, 0);
6535 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
6540 " Queue Base Size Thres RdPtr WrPtr SOP EOP Avail");
6542 for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
6543 sbuf_printf(sb, "\n%7s %5x %5u %5u %6x %4x %4u %4u %5u",
6544 qname[i], base[i], size[i], thres[i], G_IBQRDADDR(p[0]),
6545 G_IBQWRADDR(p[1]), G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
6546 G_QUEREMFLITS(p[2]) * 16);
6547 for ( ; i < nq; i++, p += 4, wr += 2)
6548 sbuf_printf(sb, "\n%7s %5x %5u %12x %4x %4u %4u %5u", qname[i],
6549 base[i], size[i], G_QUERDADDR(p[0]) & 0x3fff,
6550 wr[0] - base[i], G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
6551 G_QUEREMFLITS(p[2]) * 16);
6553 rc = sbuf_finish(sb);
6560 sysctl_cpl_stats(SYSCTL_HANDLER_ARGS)
6562 struct adapter *sc = arg1;
6565 struct tp_cpl_stats stats;
6567 rc = sysctl_wire_old_buffer(req, 0);
6571 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6575 mtx_lock(&sc->reg_lock);
6576 t4_tp_get_cpl_stats(sc, &stats, 0);
6577 mtx_unlock(&sc->reg_lock);
6579 if (sc->chip_params->nchan > 2) {
6580 sbuf_printf(sb, " channel 0 channel 1"
6581 " channel 2 channel 3");
6582 sbuf_printf(sb, "\nCPL requests: %10u %10u %10u %10u",
6583 stats.req[0], stats.req[1], stats.req[2], stats.req[3]);
6584 sbuf_printf(sb, "\nCPL responses: %10u %10u %10u %10u",
6585 stats.rsp[0], stats.rsp[1], stats.rsp[2], stats.rsp[3]);
6587 sbuf_printf(sb, " channel 0 channel 1");
6588 sbuf_printf(sb, "\nCPL requests: %10u %10u",
6589 stats.req[0], stats.req[1]);
6590 sbuf_printf(sb, "\nCPL responses: %10u %10u",
6591 stats.rsp[0], stats.rsp[1]);
6594 rc = sbuf_finish(sb);
6601 sysctl_ddp_stats(SYSCTL_HANDLER_ARGS)
6603 struct adapter *sc = arg1;
6606 struct tp_usm_stats stats;
6608 rc = sysctl_wire_old_buffer(req, 0);
6612 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6616 t4_get_usm_stats(sc, &stats, 1);
6618 sbuf_printf(sb, "Frames: %u\n", stats.frames);
6619 sbuf_printf(sb, "Octets: %ju\n", stats.octets);
6620 sbuf_printf(sb, "Drops: %u", stats.drops);
6622 rc = sbuf_finish(sb);
6628 static const char * const devlog_level_strings[] = {
6629 [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
6630 [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
6631 [FW_DEVLOG_LEVEL_ERR] = "ERR",
6632 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
6633 [FW_DEVLOG_LEVEL_INFO] = "INFO",
6634 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
6637 static const char * const devlog_facility_strings[] = {
6638 [FW_DEVLOG_FACILITY_CORE] = "CORE",
6639 [FW_DEVLOG_FACILITY_CF] = "CF",
6640 [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
6641 [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
6642 [FW_DEVLOG_FACILITY_RES] = "RES",
6643 [FW_DEVLOG_FACILITY_HW] = "HW",
6644 [FW_DEVLOG_FACILITY_FLR] = "FLR",
6645 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
6646 [FW_DEVLOG_FACILITY_PHY] = "PHY",
6647 [FW_DEVLOG_FACILITY_MAC] = "MAC",
6648 [FW_DEVLOG_FACILITY_PORT] = "PORT",
6649 [FW_DEVLOG_FACILITY_VI] = "VI",
6650 [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
6651 [FW_DEVLOG_FACILITY_ACL] = "ACL",
6652 [FW_DEVLOG_FACILITY_TM] = "TM",
6653 [FW_DEVLOG_FACILITY_QFC] = "QFC",
6654 [FW_DEVLOG_FACILITY_DCB] = "DCB",
6655 [FW_DEVLOG_FACILITY_ETH] = "ETH",
6656 [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
6657 [FW_DEVLOG_FACILITY_RI] = "RI",
6658 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
6659 [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
6660 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
6661 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE",
6662 [FW_DEVLOG_FACILITY_CHNET] = "CHNET",
6666 sysctl_devlog(SYSCTL_HANDLER_ARGS)
6668 struct adapter *sc = arg1;
6669 struct devlog_params *dparams = &sc->params.devlog;
6670 struct fw_devlog_e *buf, *e;
6671 int i, j, rc, nentries, first = 0;
6673 uint64_t ftstamp = UINT64_MAX;
6675 if (dparams->addr == 0)
6678 buf = malloc(dparams->size, M_CXGBE, M_NOWAIT);
6682 rc = read_via_memwin(sc, 1, dparams->addr, (void *)buf, dparams->size);
6686 nentries = dparams->size / sizeof(struct fw_devlog_e);
6687 for (i = 0; i < nentries; i++) {
6690 if (e->timestamp == 0)
6693 e->timestamp = be64toh(e->timestamp);
6694 e->seqno = be32toh(e->seqno);
6695 for (j = 0; j < 8; j++)
6696 e->params[j] = be32toh(e->params[j]);
6698 if (e->timestamp < ftstamp) {
6699 ftstamp = e->timestamp;
6704 if (buf[first].timestamp == 0)
6705 goto done; /* nothing in the log */
6707 rc = sysctl_wire_old_buffer(req, 0);
6711 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6716 sbuf_printf(sb, "%10s %15s %8s %8s %s\n",
6717 "Seq#", "Tstamp", "Level", "Facility", "Message");
6722 if (e->timestamp == 0)
6725 sbuf_printf(sb, "%10d %15ju %8s %8s ",
6726 e->seqno, e->timestamp,
6727 (e->level < nitems(devlog_level_strings) ?
6728 devlog_level_strings[e->level] : "UNKNOWN"),
6729 (e->facility < nitems(devlog_facility_strings) ?
6730 devlog_facility_strings[e->facility] : "UNKNOWN"));
6731 sbuf_printf(sb, e->fmt, e->params[0], e->params[1],
6732 e->params[2], e->params[3], e->params[4],
6733 e->params[5], e->params[6], e->params[7]);
6735 if (++i == nentries)
6737 } while (i != first);
6739 rc = sbuf_finish(sb);
6747 sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS)
6749 struct adapter *sc = arg1;
6752 struct tp_fcoe_stats stats[MAX_NCHAN];
6753 int i, nchan = sc->chip_params->nchan;
6755 rc = sysctl_wire_old_buffer(req, 0);
6759 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6763 for (i = 0; i < nchan; i++)
6764 t4_get_fcoe_stats(sc, i, &stats[i], 1);
6767 sbuf_printf(sb, " channel 0 channel 1"
6768 " channel 2 channel 3");
6769 sbuf_printf(sb, "\noctetsDDP: %16ju %16ju %16ju %16ju",
6770 stats[0].octets_ddp, stats[1].octets_ddp,
6771 stats[2].octets_ddp, stats[3].octets_ddp);
6772 sbuf_printf(sb, "\nframesDDP: %16u %16u %16u %16u",
6773 stats[0].frames_ddp, stats[1].frames_ddp,
6774 stats[2].frames_ddp, stats[3].frames_ddp);
6775 sbuf_printf(sb, "\nframesDrop: %16u %16u %16u %16u",
6776 stats[0].frames_drop, stats[1].frames_drop,
6777 stats[2].frames_drop, stats[3].frames_drop);
6779 sbuf_printf(sb, " channel 0 channel 1");
6780 sbuf_printf(sb, "\noctetsDDP: %16ju %16ju",
6781 stats[0].octets_ddp, stats[1].octets_ddp);
6782 sbuf_printf(sb, "\nframesDDP: %16u %16u",
6783 stats[0].frames_ddp, stats[1].frames_ddp);
6784 sbuf_printf(sb, "\nframesDrop: %16u %16u",
6785 stats[0].frames_drop, stats[1].frames_drop);
6788 rc = sbuf_finish(sb);
6795 sysctl_hw_sched(SYSCTL_HANDLER_ARGS)
6797 struct adapter *sc = arg1;
6800 unsigned int map, kbps, ipg, mode;
6801 unsigned int pace_tab[NTX_SCHED];
6803 rc = sysctl_wire_old_buffer(req, 0);
6807 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
6811 map = t4_read_reg(sc, A_TP_TX_MOD_QUEUE_REQ_MAP);
6812 mode = G_TIMERMODE(t4_read_reg(sc, A_TP_MOD_CONFIG));
6813 t4_read_pace_tbl(sc, pace_tab);
6815 sbuf_printf(sb, "Scheduler Mode Channel Rate (Kbps) "
6816 "Class IPG (0.1 ns) Flow IPG (us)");
6818 for (i = 0; i < NTX_SCHED; ++i, map >>= 2) {
6819 t4_get_tx_sched(sc, i, &kbps, &ipg, 1);
6820 sbuf_printf(sb, "\n %u %-5s %u ", i,
6821 (mode & (1 << i)) ? "flow" : "class", map & 3);
6823 sbuf_printf(sb, "%9u ", kbps);
6825 sbuf_printf(sb, " disabled ");
6828 sbuf_printf(sb, "%13u ", ipg);
6830 sbuf_printf(sb, " disabled ");
6833 sbuf_printf(sb, "%10u", pace_tab[i]);
6835 sbuf_printf(sb, " disabled");
6838 rc = sbuf_finish(sb);
6845 sysctl_lb_stats(SYSCTL_HANDLER_ARGS)
6847 struct adapter *sc = arg1;
6851 struct lb_port_stats s[2];
6852 static const char *stat_name[] = {
6853 "OctetsOK:", "FramesOK:", "BcastFrames:", "McastFrames:",
6854 "UcastFrames:", "ErrorFrames:", "Frames64:", "Frames65To127:",
6855 "Frames128To255:", "Frames256To511:", "Frames512To1023:",
6856 "Frames1024To1518:", "Frames1519ToMax:", "FramesDropped:",
6857 "BG0FramesDropped:", "BG1FramesDropped:", "BG2FramesDropped:",
6858 "BG3FramesDropped:", "BG0FramesTrunc:", "BG1FramesTrunc:",
6859 "BG2FramesTrunc:", "BG3FramesTrunc:"
6862 rc = sysctl_wire_old_buffer(req, 0);
6866 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6870 memset(s, 0, sizeof(s));
6872 for (i = 0; i < sc->chip_params->nchan; i += 2) {
6873 t4_get_lb_stats(sc, i, &s[0]);
6874 t4_get_lb_stats(sc, i + 1, &s[1]);
6878 sbuf_printf(sb, "%s Loopback %u"
6879 " Loopback %u", i == 0 ? "" : "\n", i, i + 1);
6881 for (j = 0; j < nitems(stat_name); j++)
6882 sbuf_printf(sb, "\n%-17s %20ju %20ju", stat_name[j],
6886 rc = sbuf_finish(sb);
6893 sysctl_linkdnrc(SYSCTL_HANDLER_ARGS)
6896 struct port_info *pi = arg1;
6897 struct link_config *lc = &pi->link_cfg;
6900 rc = sysctl_wire_old_buffer(req, 0);
6903 sb = sbuf_new_for_sysctl(NULL, NULL, 64, req);
6907 if (lc->link_ok || lc->link_down_rc == 255)
6908 sbuf_printf(sb, "n/a");
6910 sbuf_printf(sb, "%s", t4_link_down_rc_str(lc->link_down_rc));
6912 rc = sbuf_finish(sb);
6925 mem_desc_cmp(const void *a, const void *b)
6927 return ((const struct mem_desc *)a)->base -
6928 ((const struct mem_desc *)b)->base;
6932 mem_region_show(struct sbuf *sb, const char *name, unsigned int from,
6940 size = to - from + 1;
6944 /* XXX: need humanize_number(3) in libkern for a more readable 'size' */
6945 sbuf_printf(sb, "%-15s %#x-%#x [%u]\n", name, from, to, size);
6949 sysctl_meminfo(SYSCTL_HANDLER_ARGS)
6951 struct adapter *sc = arg1;
6954 uint32_t lo, hi, used, alloc;
6955 static const char *memory[] = {"EDC0:", "EDC1:", "MC:", "MC0:", "MC1:"};
6956 static const char *region[] = {
6957 "DBQ contexts:", "IMSG contexts:", "FLM cache:", "TCBs:",
6958 "Pstructs:", "Timers:", "Rx FL:", "Tx FL:", "Pstruct FL:",
6959 "Tx payload:", "Rx payload:", "LE hash:", "iSCSI region:",
6960 "TDDP region:", "TPT region:", "STAG region:", "RQ region:",
6961 "RQUDP region:", "PBL region:", "TXPBL region:",
6962 "DBVFIFO region:", "ULPRX state:", "ULPTX state:",
6965 struct mem_desc avail[4];
6966 struct mem_desc mem[nitems(region) + 3]; /* up to 3 holes */
6967 struct mem_desc *md = mem;
6969 rc = sysctl_wire_old_buffer(req, 0);
6973 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6977 for (i = 0; i < nitems(mem); i++) {
6982 /* Find and sort the populated memory ranges */
6984 lo = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
6985 if (lo & F_EDRAM0_ENABLE) {
6986 hi = t4_read_reg(sc, A_MA_EDRAM0_BAR);
6987 avail[i].base = G_EDRAM0_BASE(hi) << 20;
6988 avail[i].limit = avail[i].base + (G_EDRAM0_SIZE(hi) << 20);
6992 if (lo & F_EDRAM1_ENABLE) {
6993 hi = t4_read_reg(sc, A_MA_EDRAM1_BAR);
6994 avail[i].base = G_EDRAM1_BASE(hi) << 20;
6995 avail[i].limit = avail[i].base + (G_EDRAM1_SIZE(hi) << 20);
6999 if (lo & F_EXT_MEM_ENABLE) {
7000 hi = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
7001 avail[i].base = G_EXT_MEM_BASE(hi) << 20;
7002 avail[i].limit = avail[i].base +
7003 (G_EXT_MEM_SIZE(hi) << 20);
7004 avail[i].idx = is_t5(sc) ? 3 : 2; /* Call it MC0 for T5 */
7007 if (is_t5(sc) && lo & F_EXT_MEM1_ENABLE) {
7008 hi = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
7009 avail[i].base = G_EXT_MEM1_BASE(hi) << 20;
7010 avail[i].limit = avail[i].base +
7011 (G_EXT_MEM1_SIZE(hi) << 20);
7015 if (!i) /* no memory available */
7017 qsort(avail, i, sizeof(struct mem_desc), mem_desc_cmp);
7019 (md++)->base = t4_read_reg(sc, A_SGE_DBQ_CTXT_BADDR);
7020 (md++)->base = t4_read_reg(sc, A_SGE_IMSG_CTXT_BADDR);
7021 (md++)->base = t4_read_reg(sc, A_SGE_FLM_CACHE_BADDR);
7022 (md++)->base = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
7023 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_BASE);
7024 (md++)->base = t4_read_reg(sc, A_TP_CMM_TIMER_BASE);
7025 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_RX_FLST_BASE);
7026 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_TX_FLST_BASE);
7027 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_PS_FLST_BASE);
7029 /* the next few have explicit upper bounds */
7030 md->base = t4_read_reg(sc, A_TP_PMM_TX_BASE);
7031 md->limit = md->base - 1 +
7032 t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE) *
7033 G_PMTXMAXPAGE(t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE));
7036 md->base = t4_read_reg(sc, A_TP_PMM_RX_BASE);
7037 md->limit = md->base - 1 +
7038 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) *
7039 G_PMRXMAXPAGE(t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE));
7042 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
7043 if (chip_id(sc) <= CHELSIO_T5)
7044 md->base = t4_read_reg(sc, A_LE_DB_HASH_TID_BASE);
7046 md->base = t4_read_reg(sc, A_LE_DB_HASH_TBL_BASE_ADDR);
7050 md->idx = nitems(region); /* hide it */
7054 #define ulp_region(reg) \
7055 md->base = t4_read_reg(sc, A_ULP_ ## reg ## _LLIMIT);\
7056 (md++)->limit = t4_read_reg(sc, A_ULP_ ## reg ## _ULIMIT)
7058 ulp_region(RX_ISCSI);
7059 ulp_region(RX_TDDP);
7061 ulp_region(RX_STAG);
7063 ulp_region(RX_RQUDP);
7069 md->idx = nitems(region);
7072 uint32_t sge_ctrl = t4_read_reg(sc, A_SGE_CONTROL2);
7073 uint32_t fifo_size = t4_read_reg(sc, A_SGE_DBVFIFO_SIZE);
7076 if (sge_ctrl & F_VFIFO_ENABLE)
7077 size = G_DBVFIFO_SIZE(fifo_size);
7079 size = G_T6_DBVFIFO_SIZE(fifo_size);
7082 md->base = G_BASEADDR(t4_read_reg(sc,
7083 A_SGE_DBVFIFO_BADDR));
7084 md->limit = md->base + (size << 2) - 1;
7089 md->base = t4_read_reg(sc, A_ULP_RX_CTX_BASE);
7092 md->base = t4_read_reg(sc, A_ULP_TX_ERR_TABLE_BASE);
7096 md->base = sc->vres.ocq.start;
7097 if (sc->vres.ocq.size)
7098 md->limit = md->base + sc->vres.ocq.size - 1;
7100 md->idx = nitems(region); /* hide it */
7103 /* add any address-space holes, there can be up to 3 */
7104 for (n = 0; n < i - 1; n++)
7105 if (avail[n].limit < avail[n + 1].base)
7106 (md++)->base = avail[n].limit;
7108 (md++)->base = avail[n].limit;
7111 qsort(mem, n, sizeof(struct mem_desc), mem_desc_cmp);
7113 for (lo = 0; lo < i; lo++)
7114 mem_region_show(sb, memory[avail[lo].idx], avail[lo].base,
7115 avail[lo].limit - 1);
7117 sbuf_printf(sb, "\n");
7118 for (i = 0; i < n; i++) {
7119 if (mem[i].idx >= nitems(region))
7120 continue; /* skip holes */
7122 mem[i].limit = i < n - 1 ? mem[i + 1].base - 1 : ~0;
7123 mem_region_show(sb, region[mem[i].idx], mem[i].base,
7127 sbuf_printf(sb, "\n");
7128 lo = t4_read_reg(sc, A_CIM_SDRAM_BASE_ADDR);
7129 hi = t4_read_reg(sc, A_CIM_SDRAM_ADDR_SIZE) + lo - 1;
7130 mem_region_show(sb, "uP RAM:", lo, hi);
7132 lo = t4_read_reg(sc, A_CIM_EXTMEM2_BASE_ADDR);
7133 hi = t4_read_reg(sc, A_CIM_EXTMEM2_ADDR_SIZE) + lo - 1;
7134 mem_region_show(sb, "uP Extmem2:", lo, hi);
7136 lo = t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE);
7137 sbuf_printf(sb, "\n%u Rx pages of size %uKiB for %u channels\n",
7139 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) >> 10,
7140 (lo & F_PMRXNUMCHN) ? 2 : 1);
7142 lo = t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE);
7143 hi = t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE);
7144 sbuf_printf(sb, "%u Tx pages of size %u%ciB for %u channels\n",
7146 hi >= (1 << 20) ? (hi >> 20) : (hi >> 10),
7147 hi >= (1 << 20) ? 'M' : 'K', 1 << G_PMTXNUMCHN(lo));
7148 sbuf_printf(sb, "%u p-structs\n",
7149 t4_read_reg(sc, A_TP_CMM_MM_MAX_PSTRUCT));
7151 for (i = 0; i < 4; i++) {
7152 if (chip_id(sc) > CHELSIO_T5)
7153 lo = t4_read_reg(sc, A_MPS_RX_MAC_BG_PG_CNT0 + i * 4);
7155 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV0 + i * 4);
7157 used = G_T5_USED(lo);
7158 alloc = G_T5_ALLOC(lo);
7161 alloc = G_ALLOC(lo);
7163 /* For T6 these are MAC buffer groups */
7164 sbuf_printf(sb, "\nPort %d using %u pages out of %u allocated",
7167 for (i = 0; i < sc->chip_params->nchan; i++) {
7168 if (chip_id(sc) > CHELSIO_T5)
7169 lo = t4_read_reg(sc, A_MPS_RX_LPBK_BG_PG_CNT0 + i * 4);
7171 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV4 + i * 4);
7173 used = G_T5_USED(lo);
7174 alloc = G_T5_ALLOC(lo);
7177 alloc = G_ALLOC(lo);
7179 /* For T6 these are MAC buffer groups */
7181 "\nLoopback %d using %u pages out of %u allocated",
7185 rc = sbuf_finish(sb);
7192 tcamxy2valmask(uint64_t x, uint64_t y, uint8_t *addr, uint64_t *mask)
7196 memcpy(addr, (char *)&y + 2, ETHER_ADDR_LEN);
7200 sysctl_mps_tcam(SYSCTL_HANDLER_ARGS)
7202 struct adapter *sc = arg1;
7206 MPASS(chip_id(sc) <= CHELSIO_T5);
7208 rc = sysctl_wire_old_buffer(req, 0);
7212 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7217 "Idx Ethernet address Mask Vld Ports PF"
7218 " VF Replication P0 P1 P2 P3 ML");
7219 for (i = 0; i < sc->chip_params->mps_tcam_size; i++) {
7220 uint64_t tcamx, tcamy, mask;
7221 uint32_t cls_lo, cls_hi;
7222 uint8_t addr[ETHER_ADDR_LEN];
7224 tcamy = t4_read_reg64(sc, MPS_CLS_TCAM_Y_L(i));
7225 tcamx = t4_read_reg64(sc, MPS_CLS_TCAM_X_L(i));
7228 tcamxy2valmask(tcamx, tcamy, addr, &mask);
7229 cls_lo = t4_read_reg(sc, MPS_CLS_SRAM_L(i));
7230 cls_hi = t4_read_reg(sc, MPS_CLS_SRAM_H(i));
7231 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x %012jx"
7232 " %c %#x%4u%4d", i, addr[0], addr[1], addr[2],
7233 addr[3], addr[4], addr[5], (uintmax_t)mask,
7234 (cls_lo & F_SRAM_VLD) ? 'Y' : 'N',
7235 G_PORTMAP(cls_hi), G_PF(cls_lo),
7236 (cls_lo & F_VF_VALID) ? G_VF(cls_lo) : -1);
7238 if (cls_lo & F_REPLICATE) {
7239 struct fw_ldst_cmd ldst_cmd;
7241 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
7242 ldst_cmd.op_to_addrspace =
7243 htobe32(V_FW_CMD_OP(FW_LDST_CMD) |
7244 F_FW_CMD_REQUEST | F_FW_CMD_READ |
7245 V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MPS));
7246 ldst_cmd.cycles_to_len16 = htobe32(FW_LEN16(ldst_cmd));
7247 ldst_cmd.u.mps.rplc.fid_idx =
7248 htobe16(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) |
7249 V_FW_LDST_CMD_IDX(i));
7251 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK,
7255 rc = -t4_wr_mbox(sc, sc->mbox, &ldst_cmd,
7256 sizeof(ldst_cmd), &ldst_cmd);
7257 end_synchronized_op(sc, 0);
7260 sbuf_printf(sb, "%36d", rc);
7263 sbuf_printf(sb, " %08x %08x %08x %08x",
7264 be32toh(ldst_cmd.u.mps.rplc.rplc127_96),
7265 be32toh(ldst_cmd.u.mps.rplc.rplc95_64),
7266 be32toh(ldst_cmd.u.mps.rplc.rplc63_32),
7267 be32toh(ldst_cmd.u.mps.rplc.rplc31_0));
7270 sbuf_printf(sb, "%36s", "");
7272 sbuf_printf(sb, "%4u%3u%3u%3u %#3x", G_SRAM_PRIO0(cls_lo),
7273 G_SRAM_PRIO1(cls_lo), G_SRAM_PRIO2(cls_lo),
7274 G_SRAM_PRIO3(cls_lo), (cls_lo >> S_MULTILISTEN0) & 0xf);
7278 (void) sbuf_finish(sb);
7280 rc = sbuf_finish(sb);
7287 sysctl_mps_tcam_t6(SYSCTL_HANDLER_ARGS)
7289 struct adapter *sc = arg1;
7293 MPASS(chip_id(sc) > CHELSIO_T5);
7295 rc = sysctl_wire_old_buffer(req, 0);
7299 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7303 sbuf_printf(sb, "Idx Ethernet address Mask VNI Mask"
7304 " IVLAN Vld DIP_Hit Lookup Port Vld Ports PF VF"
7306 " P0 P1 P2 P3 ML\n");
7308 for (i = 0; i < sc->chip_params->mps_tcam_size; i++) {
7309 uint8_t dip_hit, vlan_vld, lookup_type, port_num;
7311 uint64_t tcamx, tcamy, val, mask;
7312 uint32_t cls_lo, cls_hi, ctl, data2, vnix, vniy;
7313 uint8_t addr[ETHER_ADDR_LEN];
7315 ctl = V_CTLREQID(1) | V_CTLCMDTYPE(0) | V_CTLXYBITSEL(0);
7317 ctl |= V_CTLTCAMINDEX(i) | V_CTLTCAMSEL(0);
7319 ctl |= V_CTLTCAMINDEX(i - 256) | V_CTLTCAMSEL(1);
7320 t4_write_reg(sc, A_MPS_CLS_TCAM_DATA2_CTL, ctl);
7321 val = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA1_REQ_ID1);
7322 tcamy = G_DMACH(val) << 32;
7323 tcamy |= t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA0_REQ_ID1);
7324 data2 = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA2_REQ_ID1);
7325 lookup_type = G_DATALKPTYPE(data2);
7326 port_num = G_DATAPORTNUM(data2);
7327 if (lookup_type && lookup_type != M_DATALKPTYPE) {
7328 /* Inner header VNI */
7329 vniy = ((data2 & F_DATAVIDH2) << 23) |
7330 (G_DATAVIDH1(data2) << 16) | G_VIDL(val);
7331 dip_hit = data2 & F_DATADIPHIT;
7336 vlan_vld = data2 & F_DATAVIDH2;
7337 ivlan = G_VIDL(val);
7340 ctl |= V_CTLXYBITSEL(1);
7341 t4_write_reg(sc, A_MPS_CLS_TCAM_DATA2_CTL, ctl);
7342 val = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA1_REQ_ID1);
7343 tcamx = G_DMACH(val) << 32;
7344 tcamx |= t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA0_REQ_ID1);
7345 data2 = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA2_REQ_ID1);
7346 if (lookup_type && lookup_type != M_DATALKPTYPE) {
7347 /* Inner header VNI mask */
7348 vnix = ((data2 & F_DATAVIDH2) << 23) |
7349 (G_DATAVIDH1(data2) << 16) | G_VIDL(val);
7355 tcamxy2valmask(tcamx, tcamy, addr, &mask);
7357 cls_lo = t4_read_reg(sc, MPS_CLS_SRAM_L(i));
7358 cls_hi = t4_read_reg(sc, MPS_CLS_SRAM_H(i));
7360 if (lookup_type && lookup_type != M_DATALKPTYPE) {
7361 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x "
7362 "%012jx %06x %06x - - %3c"
7363 " 'I' %4x %3c %#x%4u%4d", i, addr[0],
7364 addr[1], addr[2], addr[3], addr[4], addr[5],
7365 (uintmax_t)mask, vniy, vnix, dip_hit ? 'Y' : 'N',
7366 port_num, cls_lo & F_T6_SRAM_VLD ? 'Y' : 'N',
7367 G_PORTMAP(cls_hi), G_T6_PF(cls_lo),
7368 cls_lo & F_T6_VF_VALID ? G_T6_VF(cls_lo) : -1);
7370 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x "
7371 "%012jx - - ", i, addr[0], addr[1],
7372 addr[2], addr[3], addr[4], addr[5],
7376 sbuf_printf(sb, "%4u Y ", ivlan);
7378 sbuf_printf(sb, " - N ");
7380 sbuf_printf(sb, "- %3c %4x %3c %#x%4u%4d",
7381 lookup_type ? 'I' : 'O', port_num,
7382 cls_lo & F_T6_SRAM_VLD ? 'Y' : 'N',
7383 G_PORTMAP(cls_hi), G_T6_PF(cls_lo),
7384 cls_lo & F_T6_VF_VALID ? G_T6_VF(cls_lo) : -1);
7388 if (cls_lo & F_T6_REPLICATE) {
7389 struct fw_ldst_cmd ldst_cmd;
7391 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
7392 ldst_cmd.op_to_addrspace =
7393 htobe32(V_FW_CMD_OP(FW_LDST_CMD) |
7394 F_FW_CMD_REQUEST | F_FW_CMD_READ |
7395 V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MPS));
7396 ldst_cmd.cycles_to_len16 = htobe32(FW_LEN16(ldst_cmd));
7397 ldst_cmd.u.mps.rplc.fid_idx =
7398 htobe16(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) |
7399 V_FW_LDST_CMD_IDX(i));
7401 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK,
7405 rc = -t4_wr_mbox(sc, sc->mbox, &ldst_cmd,
7406 sizeof(ldst_cmd), &ldst_cmd);
7407 end_synchronized_op(sc, 0);
7410 sbuf_printf(sb, "%72d", rc);
7413 sbuf_printf(sb, " %08x %08x %08x %08x"
7414 " %08x %08x %08x %08x",
7415 be32toh(ldst_cmd.u.mps.rplc.rplc255_224),
7416 be32toh(ldst_cmd.u.mps.rplc.rplc223_192),
7417 be32toh(ldst_cmd.u.mps.rplc.rplc191_160),
7418 be32toh(ldst_cmd.u.mps.rplc.rplc159_128),
7419 be32toh(ldst_cmd.u.mps.rplc.rplc127_96),
7420 be32toh(ldst_cmd.u.mps.rplc.rplc95_64),
7421 be32toh(ldst_cmd.u.mps.rplc.rplc63_32),
7422 be32toh(ldst_cmd.u.mps.rplc.rplc31_0));
7425 sbuf_printf(sb, "%72s", "");
7427 sbuf_printf(sb, "%4u%3u%3u%3u %#x",
7428 G_T6_SRAM_PRIO0(cls_lo), G_T6_SRAM_PRIO1(cls_lo),
7429 G_T6_SRAM_PRIO2(cls_lo), G_T6_SRAM_PRIO3(cls_lo),
7430 (cls_lo >> S_T6_MULTILISTEN0) & 0xf);
7434 (void) sbuf_finish(sb);
7436 rc = sbuf_finish(sb);
7443 sysctl_path_mtus(SYSCTL_HANDLER_ARGS)
7445 struct adapter *sc = arg1;
7448 uint16_t mtus[NMTUS];
7450 rc = sysctl_wire_old_buffer(req, 0);
7454 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7458 t4_read_mtu_tbl(sc, mtus, NULL);
7460 sbuf_printf(sb, "%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u",
7461 mtus[0], mtus[1], mtus[2], mtus[3], mtus[4], mtus[5], mtus[6],
7462 mtus[7], mtus[8], mtus[9], mtus[10], mtus[11], mtus[12], mtus[13],
7463 mtus[14], mtus[15]);
7465 rc = sbuf_finish(sb);
7472 sysctl_pm_stats(SYSCTL_HANDLER_ARGS)
7474 struct adapter *sc = arg1;
7477 uint32_t tx_cnt[MAX_PM_NSTATS], rx_cnt[MAX_PM_NSTATS];
7478 uint64_t tx_cyc[MAX_PM_NSTATS], rx_cyc[MAX_PM_NSTATS];
7479 static const char *tx_stats[MAX_PM_NSTATS] = {
7480 "Read:", "Write bypass:", "Write mem:", "Bypass + mem:",
7481 "Tx FIFO wait", NULL, "Tx latency"
7483 static const char *rx_stats[MAX_PM_NSTATS] = {
7484 "Read:", "Write bypass:", "Write mem:", "Flush:",
7485 "Rx FIFO wait", NULL, "Rx latency"
7488 rc = sysctl_wire_old_buffer(req, 0);
7492 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7496 t4_pmtx_get_stats(sc, tx_cnt, tx_cyc);
7497 t4_pmrx_get_stats(sc, rx_cnt, rx_cyc);
7499 sbuf_printf(sb, " Tx pcmds Tx bytes");
7500 for (i = 0; i < 4; i++) {
7501 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i],
7505 sbuf_printf(sb, "\n Rx pcmds Rx bytes");
7506 for (i = 0; i < 4; i++) {
7507 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i],
7511 if (chip_id(sc) > CHELSIO_T5) {
7513 "\n Total wait Total occupancy");
7514 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i],
7516 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i],
7520 MPASS(i < nitems(tx_stats));
7523 "\n Reads Total wait");
7524 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i],
7526 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i],
7530 rc = sbuf_finish(sb);
7537 sysctl_rdma_stats(SYSCTL_HANDLER_ARGS)
7539 struct adapter *sc = arg1;
7542 struct tp_rdma_stats stats;
7544 rc = sysctl_wire_old_buffer(req, 0);
7548 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7552 mtx_lock(&sc->reg_lock);
7553 t4_tp_get_rdma_stats(sc, &stats, 0);
7554 mtx_unlock(&sc->reg_lock);
7556 sbuf_printf(sb, "NoRQEModDefferals: %u\n", stats.rqe_dfr_mod);
7557 sbuf_printf(sb, "NoRQEPktDefferals: %u", stats.rqe_dfr_pkt);
7559 rc = sbuf_finish(sb);
7566 sysctl_tcp_stats(SYSCTL_HANDLER_ARGS)
7568 struct adapter *sc = arg1;
7571 struct tp_tcp_stats v4, v6;
7573 rc = sysctl_wire_old_buffer(req, 0);
7577 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7581 mtx_lock(&sc->reg_lock);
7582 t4_tp_get_tcp_stats(sc, &v4, &v6, 0);
7583 mtx_unlock(&sc->reg_lock);
7587 sbuf_printf(sb, "OutRsts: %20u %20u\n",
7588 v4.tcp_out_rsts, v6.tcp_out_rsts);
7589 sbuf_printf(sb, "InSegs: %20ju %20ju\n",
7590 v4.tcp_in_segs, v6.tcp_in_segs);
7591 sbuf_printf(sb, "OutSegs: %20ju %20ju\n",
7592 v4.tcp_out_segs, v6.tcp_out_segs);
7593 sbuf_printf(sb, "RetransSegs: %20ju %20ju",
7594 v4.tcp_retrans_segs, v6.tcp_retrans_segs);
7596 rc = sbuf_finish(sb);
7603 sysctl_tids(SYSCTL_HANDLER_ARGS)
7605 struct adapter *sc = arg1;
7608 struct tid_info *t = &sc->tids;
7610 rc = sysctl_wire_old_buffer(req, 0);
7614 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7619 sbuf_printf(sb, "ATID range: 0-%u, in use: %u\n", t->natids - 1,
7624 sbuf_printf(sb, "TID range: ");
7625 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
7628 if (chip_id(sc) <= CHELSIO_T5) {
7629 b = t4_read_reg(sc, A_LE_DB_SERVER_INDEX) / 4;
7630 hb = t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4;
7632 b = t4_read_reg(sc, A_LE_DB_SRVR_START_INDEX);
7633 hb = t4_read_reg(sc, A_T6_LE_DB_HASH_TID_BASE);
7637 sbuf_printf(sb, "0-%u, ", b - 1);
7638 sbuf_printf(sb, "%u-%u", hb, t->ntids - 1);
7640 sbuf_printf(sb, "0-%u", t->ntids - 1);
7641 sbuf_printf(sb, ", in use: %u\n",
7642 atomic_load_acq_int(&t->tids_in_use));
7646 sbuf_printf(sb, "STID range: %u-%u, in use: %u\n", t->stid_base,
7647 t->stid_base + t->nstids - 1, t->stids_in_use);
7651 sbuf_printf(sb, "FTID range: %u-%u\n", t->ftid_base,
7652 t->ftid_base + t->nftids - 1);
7656 sbuf_printf(sb, "ETID range: %u-%u\n", t->etid_base,
7657 t->etid_base + t->netids - 1);
7660 sbuf_printf(sb, "HW TID usage: %u IP users, %u IPv6 users",
7661 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV4),
7662 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV6));
7664 rc = sbuf_finish(sb);
7671 sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS)
7673 struct adapter *sc = arg1;
7676 struct tp_err_stats stats;
7678 rc = sysctl_wire_old_buffer(req, 0);
7682 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7686 mtx_lock(&sc->reg_lock);
7687 t4_tp_get_err_stats(sc, &stats, 0);
7688 mtx_unlock(&sc->reg_lock);
7690 if (sc->chip_params->nchan > 2) {
7691 sbuf_printf(sb, " channel 0 channel 1"
7692 " channel 2 channel 3\n");
7693 sbuf_printf(sb, "macInErrs: %10u %10u %10u %10u\n",
7694 stats.mac_in_errs[0], stats.mac_in_errs[1],
7695 stats.mac_in_errs[2], stats.mac_in_errs[3]);
7696 sbuf_printf(sb, "hdrInErrs: %10u %10u %10u %10u\n",
7697 stats.hdr_in_errs[0], stats.hdr_in_errs[1],
7698 stats.hdr_in_errs[2], stats.hdr_in_errs[3]);
7699 sbuf_printf(sb, "tcpInErrs: %10u %10u %10u %10u\n",
7700 stats.tcp_in_errs[0], stats.tcp_in_errs[1],
7701 stats.tcp_in_errs[2], stats.tcp_in_errs[3]);
7702 sbuf_printf(sb, "tcp6InErrs: %10u %10u %10u %10u\n",
7703 stats.tcp6_in_errs[0], stats.tcp6_in_errs[1],
7704 stats.tcp6_in_errs[2], stats.tcp6_in_errs[3]);
7705 sbuf_printf(sb, "tnlCongDrops: %10u %10u %10u %10u\n",
7706 stats.tnl_cong_drops[0], stats.tnl_cong_drops[1],
7707 stats.tnl_cong_drops[2], stats.tnl_cong_drops[3]);
7708 sbuf_printf(sb, "tnlTxDrops: %10u %10u %10u %10u\n",
7709 stats.tnl_tx_drops[0], stats.tnl_tx_drops[1],
7710 stats.tnl_tx_drops[2], stats.tnl_tx_drops[3]);
7711 sbuf_printf(sb, "ofldVlanDrops: %10u %10u %10u %10u\n",
7712 stats.ofld_vlan_drops[0], stats.ofld_vlan_drops[1],
7713 stats.ofld_vlan_drops[2], stats.ofld_vlan_drops[3]);
7714 sbuf_printf(sb, "ofldChanDrops: %10u %10u %10u %10u\n\n",
7715 stats.ofld_chan_drops[0], stats.ofld_chan_drops[1],
7716 stats.ofld_chan_drops[2], stats.ofld_chan_drops[3]);
7718 sbuf_printf(sb, " channel 0 channel 1\n");
7719 sbuf_printf(sb, "macInErrs: %10u %10u\n",
7720 stats.mac_in_errs[0], stats.mac_in_errs[1]);
7721 sbuf_printf(sb, "hdrInErrs: %10u %10u\n",
7722 stats.hdr_in_errs[0], stats.hdr_in_errs[1]);
7723 sbuf_printf(sb, "tcpInErrs: %10u %10u\n",
7724 stats.tcp_in_errs[0], stats.tcp_in_errs[1]);
7725 sbuf_printf(sb, "tcp6InErrs: %10u %10u\n",
7726 stats.tcp6_in_errs[0], stats.tcp6_in_errs[1]);
7727 sbuf_printf(sb, "tnlCongDrops: %10u %10u\n",
7728 stats.tnl_cong_drops[0], stats.tnl_cong_drops[1]);
7729 sbuf_printf(sb, "tnlTxDrops: %10u %10u\n",
7730 stats.tnl_tx_drops[0], stats.tnl_tx_drops[1]);
7731 sbuf_printf(sb, "ofldVlanDrops: %10u %10u\n",
7732 stats.ofld_vlan_drops[0], stats.ofld_vlan_drops[1]);
7733 sbuf_printf(sb, "ofldChanDrops: %10u %10u\n\n",
7734 stats.ofld_chan_drops[0], stats.ofld_chan_drops[1]);
7737 sbuf_printf(sb, "ofldNoNeigh: %u\nofldCongDefer: %u",
7738 stats.ofld_no_neigh, stats.ofld_cong_defer);
7740 rc = sbuf_finish(sb);
7747 sysctl_tp_la_mask(SYSCTL_HANDLER_ARGS)
7749 struct adapter *sc = arg1;
7750 struct tp_params *tpp = &sc->params.tp;
7754 mask = tpp->la_mask >> 16;
7755 rc = sysctl_handle_int(oidp, &mask, 0, req);
7756 if (rc != 0 || req->newptr == NULL)
7760 tpp->la_mask = mask << 16;
7761 t4_set_reg_field(sc, A_TP_DBG_LA_CONFIG, 0xffff0000U, tpp->la_mask);
7773 field_desc_show(struct sbuf *sb, uint64_t v, const struct field_desc *f)
7779 uint64_t mask = (1ULL << f->width) - 1;
7780 int len = snprintf(buf, sizeof(buf), "%s: %ju", f->name,
7781 ((uintmax_t)v >> f->start) & mask);
7783 if (line_size + len >= 79) {
7785 sbuf_printf(sb, "\n ");
7787 sbuf_printf(sb, "%s ", buf);
7788 line_size += len + 1;
7791 sbuf_printf(sb, "\n");
7794 static const struct field_desc tp_la0[] = {
7795 { "RcfOpCodeOut", 60, 4 },
7797 { "WcfState", 52, 4 },
7798 { "RcfOpcSrcOut", 50, 2 },
7799 { "CRxError", 49, 1 },
7800 { "ERxError", 48, 1 },
7801 { "SanityFailed", 47, 1 },
7802 { "SpuriousMsg", 46, 1 },
7803 { "FlushInputMsg", 45, 1 },
7804 { "FlushInputCpl", 44, 1 },
7805 { "RssUpBit", 43, 1 },
7806 { "RssFilterHit", 42, 1 },
7808 { "InitTcb", 31, 1 },
7809 { "LineNumber", 24, 7 },
7811 { "EdataOut", 22, 1 },
7813 { "CdataOut", 20, 1 },
7814 { "EreadPdu", 19, 1 },
7815 { "CreadPdu", 18, 1 },
7816 { "TunnelPkt", 17, 1 },
7817 { "RcfPeerFin", 16, 1 },
7818 { "RcfReasonOut", 12, 4 },
7819 { "TxCchannel", 10, 2 },
7820 { "RcfTxChannel", 8, 2 },
7821 { "RxEchannel", 6, 2 },
7822 { "RcfRxChannel", 5, 1 },
7823 { "RcfDataOutSrdy", 4, 1 },
7825 { "RxOoDvld", 2, 1 },
7826 { "RxCongestion", 1, 1 },
7827 { "TxCongestion", 0, 1 },
7831 static const struct field_desc tp_la1[] = {
7832 { "CplCmdIn", 56, 8 },
7833 { "CplCmdOut", 48, 8 },
7834 { "ESynOut", 47, 1 },
7835 { "EAckOut", 46, 1 },
7836 { "EFinOut", 45, 1 },
7837 { "ERstOut", 44, 1 },
7842 { "DataIn", 39, 1 },
7843 { "DataInVld", 38, 1 },
7845 { "RxBufEmpty", 36, 1 },
7847 { "RxFbCongestion", 34, 1 },
7848 { "TxFbCongestion", 33, 1 },
7849 { "TxPktSumSrdy", 32, 1 },
7850 { "RcfUlpType", 28, 4 },
7852 { "Ebypass", 26, 1 },
7854 { "Static0", 24, 1 },
7856 { "Cbypass", 22, 1 },
7858 { "CPktOut", 20, 1 },
7859 { "RxPagePoolFull", 18, 2 },
7860 { "RxLpbkPkt", 17, 1 },
7861 { "TxLpbkPkt", 16, 1 },
7862 { "RxVfValid", 15, 1 },
7863 { "SynLearned", 14, 1 },
7864 { "SetDelEntry", 13, 1 },
7865 { "SetInvEntry", 12, 1 },
7866 { "CpcmdDvld", 11, 1 },
7867 { "CpcmdSave", 10, 1 },
7868 { "RxPstructsFull", 8, 2 },
7869 { "EpcmdDvld", 7, 1 },
7870 { "EpcmdFlush", 6, 1 },
7871 { "EpcmdTrimPrefix", 5, 1 },
7872 { "EpcmdTrimPostfix", 4, 1 },
7873 { "ERssIp4Pkt", 3, 1 },
7874 { "ERssIp6Pkt", 2, 1 },
7875 { "ERssTcpUdpPkt", 1, 1 },
7876 { "ERssFceFipPkt", 0, 1 },
7880 static const struct field_desc tp_la2[] = {
7881 { "CplCmdIn", 56, 8 },
7882 { "MpsVfVld", 55, 1 },
7889 { "DataIn", 39, 1 },
7890 { "DataInVld", 38, 1 },
7892 { "RxBufEmpty", 36, 1 },
7894 { "RxFbCongestion", 34, 1 },
7895 { "TxFbCongestion", 33, 1 },
7896 { "TxPktSumSrdy", 32, 1 },
7897 { "RcfUlpType", 28, 4 },
7899 { "Ebypass", 26, 1 },
7901 { "Static0", 24, 1 },
7903 { "Cbypass", 22, 1 },
7905 { "CPktOut", 20, 1 },
7906 { "RxPagePoolFull", 18, 2 },
7907 { "RxLpbkPkt", 17, 1 },
7908 { "TxLpbkPkt", 16, 1 },
7909 { "RxVfValid", 15, 1 },
7910 { "SynLearned", 14, 1 },
7911 { "SetDelEntry", 13, 1 },
7912 { "SetInvEntry", 12, 1 },
7913 { "CpcmdDvld", 11, 1 },
7914 { "CpcmdSave", 10, 1 },
7915 { "RxPstructsFull", 8, 2 },
7916 { "EpcmdDvld", 7, 1 },
7917 { "EpcmdFlush", 6, 1 },
7918 { "EpcmdTrimPrefix", 5, 1 },
7919 { "EpcmdTrimPostfix", 4, 1 },
7920 { "ERssIp4Pkt", 3, 1 },
7921 { "ERssIp6Pkt", 2, 1 },
7922 { "ERssTcpUdpPkt", 1, 1 },
7923 { "ERssFceFipPkt", 0, 1 },
7928 tp_la_show(struct sbuf *sb, uint64_t *p, int idx)
7931 field_desc_show(sb, *p, tp_la0);
7935 tp_la_show2(struct sbuf *sb, uint64_t *p, int idx)
7939 sbuf_printf(sb, "\n");
7940 field_desc_show(sb, p[0], tp_la0);
7941 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
7942 field_desc_show(sb, p[1], tp_la0);
7946 tp_la_show3(struct sbuf *sb, uint64_t *p, int idx)
7950 sbuf_printf(sb, "\n");
7951 field_desc_show(sb, p[0], tp_la0);
7952 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
7953 field_desc_show(sb, p[1], (p[0] & (1 << 17)) ? tp_la2 : tp_la1);
7957 sysctl_tp_la(SYSCTL_HANDLER_ARGS)
7959 struct adapter *sc = arg1;
7964 void (*show_func)(struct sbuf *, uint64_t *, int);
7966 rc = sysctl_wire_old_buffer(req, 0);
7970 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7974 buf = malloc(TPLA_SIZE * sizeof(uint64_t), M_CXGBE, M_ZERO | M_WAITOK);
7976 t4_tp_read_la(sc, buf, NULL);
7979 switch (G_DBGLAMODE(t4_read_reg(sc, A_TP_DBG_LA_CONFIG))) {
7982 show_func = tp_la_show2;
7986 show_func = tp_la_show3;
7990 show_func = tp_la_show;
7993 for (i = 0; i < TPLA_SIZE / inc; i++, p += inc)
7994 (*show_func)(sb, p, i);
7996 rc = sbuf_finish(sb);
8003 sysctl_tx_rate(SYSCTL_HANDLER_ARGS)
8005 struct adapter *sc = arg1;
8008 u64 nrate[MAX_NCHAN], orate[MAX_NCHAN];
8010 rc = sysctl_wire_old_buffer(req, 0);
8014 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8018 t4_get_chan_txrate(sc, nrate, orate);
8020 if (sc->chip_params->nchan > 2) {
8021 sbuf_printf(sb, " channel 0 channel 1"
8022 " channel 2 channel 3\n");
8023 sbuf_printf(sb, "NIC B/s: %10ju %10ju %10ju %10ju\n",
8024 nrate[0], nrate[1], nrate[2], nrate[3]);
8025 sbuf_printf(sb, "Offload B/s: %10ju %10ju %10ju %10ju",
8026 orate[0], orate[1], orate[2], orate[3]);
8028 sbuf_printf(sb, " channel 0 channel 1\n");
8029 sbuf_printf(sb, "NIC B/s: %10ju %10ju\n",
8030 nrate[0], nrate[1]);
8031 sbuf_printf(sb, "Offload B/s: %10ju %10ju",
8032 orate[0], orate[1]);
8035 rc = sbuf_finish(sb);
8042 sysctl_ulprx_la(SYSCTL_HANDLER_ARGS)
8044 struct adapter *sc = arg1;
8049 rc = sysctl_wire_old_buffer(req, 0);
8053 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8057 buf = malloc(ULPRX_LA_SIZE * 8 * sizeof(uint32_t), M_CXGBE,
8060 t4_ulprx_read_la(sc, buf);
8063 sbuf_printf(sb, " Pcmd Type Message"
8065 for (i = 0; i < ULPRX_LA_SIZE; i++, p += 8) {
8066 sbuf_printf(sb, "\n%08x%08x %4x %08x %08x%08x%08x%08x",
8067 p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
8070 rc = sbuf_finish(sb);
8077 sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS)
8079 struct adapter *sc = arg1;
8083 MPASS(chip_id(sc) >= CHELSIO_T5);
8085 rc = sysctl_wire_old_buffer(req, 0);
8089 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8093 v = t4_read_reg(sc, A_SGE_STAT_CFG);
8094 if (G_STATSOURCE_T5(v) == 7) {
8097 mode = is_t5(sc) ? G_STATMODE(v) : G_T6_STATMODE(v);
8099 sbuf_printf(sb, "total %d, incomplete %d",
8100 t4_read_reg(sc, A_SGE_STAT_TOTAL),
8101 t4_read_reg(sc, A_SGE_STAT_MATCH));
8102 } else if (mode == 1) {
8103 sbuf_printf(sb, "total %d, data overflow %d",
8104 t4_read_reg(sc, A_SGE_STAT_TOTAL),
8105 t4_read_reg(sc, A_SGE_STAT_MATCH));
8107 sbuf_printf(sb, "unknown mode %d", mode);
8110 rc = sbuf_finish(sb);
8117 sysctl_tc_params(SYSCTL_HANDLER_ARGS)
8119 struct adapter *sc = arg1;
8120 struct tx_cl_rl_params tc;
8122 int i, rc, port_id, mbps, gbps;
8124 rc = sysctl_wire_old_buffer(req, 0);
8128 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8132 port_id = arg2 >> 16;
8133 MPASS(port_id < sc->params.nports);
8134 MPASS(sc->port[port_id] != NULL);
8136 MPASS(i < sc->chip_params->nsched_cls);
8138 mtx_lock(&sc->tc_lock);
8139 tc = sc->port[port_id]->sched_params->cl_rl[i];
8140 mtx_unlock(&sc->tc_lock);
8142 if (tc.flags & TX_CLRL_ERROR) {
8143 sbuf_printf(sb, "error");
8147 if (tc.ratemode == SCHED_CLASS_RATEMODE_REL) {
8148 /* XXX: top speed or actual link speed? */
8149 gbps = port_top_speed(sc->port[port_id]);
8150 sbuf_printf(sb, " %u%% of %uGbps", tc.maxrate, gbps);
8151 } else if (tc.ratemode == SCHED_CLASS_RATEMODE_ABS) {
8152 switch (tc.rateunit) {
8153 case SCHED_CLASS_RATEUNIT_BITS:
8154 mbps = tc.maxrate / 1000;
8155 gbps = tc.maxrate / 1000000;
8156 if (tc.maxrate == gbps * 1000000)
8157 sbuf_printf(sb, " %uGbps", gbps);
8158 else if (tc.maxrate == mbps * 1000)
8159 sbuf_printf(sb, " %uMbps", mbps);
8161 sbuf_printf(sb, " %uKbps", tc.maxrate);
8163 case SCHED_CLASS_RATEUNIT_PKTS:
8164 sbuf_printf(sb, " %upps", tc.maxrate);
8173 case SCHED_CLASS_MODE_CLASS:
8174 sbuf_printf(sb, " aggregate");
8176 case SCHED_CLASS_MODE_FLOW:
8177 sbuf_printf(sb, " per-flow");
8186 rc = sbuf_finish(sb);
8195 unit_conv(char *buf, size_t len, u_int val, u_int factor)
8197 u_int rem = val % factor;
8200 snprintf(buf, len, "%u", val / factor);
8202 while (rem % 10 == 0)
8204 snprintf(buf, len, "%u.%u", val / factor, rem);
8209 sysctl_tp_tick(SYSCTL_HANDLER_ARGS)
8211 struct adapter *sc = arg1;
8214 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk;
8216 res = t4_read_reg(sc, A_TP_TIMER_RESOLUTION);
8220 re = G_TIMERRESOLUTION(res);
8223 /* TCP timestamp tick */
8224 re = G_TIMESTAMPRESOLUTION(res);
8228 re = G_DELAYEDACKRESOLUTION(res);
8234 unit_conv(buf, sizeof(buf), (cclk_ps << re), 1000000);
8236 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
8240 sysctl_tp_dack_timer(SYSCTL_HANDLER_ARGS)
8242 struct adapter *sc = arg1;
8243 u_int res, dack_re, v;
8244 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk;
8246 res = t4_read_reg(sc, A_TP_TIMER_RESOLUTION);
8247 dack_re = G_DELAYEDACKRESOLUTION(res);
8248 v = ((cclk_ps << dack_re) / 1000000) * t4_read_reg(sc, A_TP_DACK_TIMER);
8250 return (sysctl_handle_int(oidp, &v, 0, req));
8254 sysctl_tp_timer(SYSCTL_HANDLER_ARGS)
8256 struct adapter *sc = arg1;
8259 u_long tp_tick_us, v;
8260 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk;
8262 MPASS(reg == A_TP_RXT_MIN || reg == A_TP_RXT_MAX ||
8263 reg == A_TP_PERS_MIN || reg == A_TP_PERS_MAX ||
8264 reg == A_TP_KEEP_IDLE || reg == A_TP_KEEP_INTVL ||
8265 reg == A_TP_INIT_SRTT || reg == A_TP_FINWAIT2_TIMER);
8267 tre = G_TIMERRESOLUTION(t4_read_reg(sc, A_TP_TIMER_RESOLUTION));
8268 tp_tick_us = (cclk_ps << tre) / 1000000;
8270 if (reg == A_TP_INIT_SRTT)
8271 v = tp_tick_us * G_INITSRTT(t4_read_reg(sc, reg));
8273 v = tp_tick_us * t4_read_reg(sc, reg);
8275 return (sysctl_handle_long(oidp, &v, 0, req));
8279 * All fields in TP_SHIFT_CNT are 4b and the starting location of the field is
8280 * passed to this function.
8283 sysctl_tp_shift_cnt(SYSCTL_HANDLER_ARGS)
8285 struct adapter *sc = arg1;
8289 MPASS(idx >= 0 && idx <= 24);
8291 v = (t4_read_reg(sc, A_TP_SHIFT_CNT) >> idx) & 0xf;
8293 return (sysctl_handle_int(oidp, &v, 0, req));
8297 sysctl_tp_backoff(SYSCTL_HANDLER_ARGS)
8299 struct adapter *sc = arg1;
8303 MPASS(idx >= 0 && idx < 16);
8305 r = A_TP_TCP_BACKOFF_REG0 + (idx & ~3);
8306 shift = (idx & 3) << 3;
8307 v = (t4_read_reg(sc, r) >> shift) & M_TIMERBACKOFFINDEX0;
8309 return (sysctl_handle_int(oidp, &v, 0, req));
8313 sysctl_holdoff_tmr_idx_ofld(SYSCTL_HANDLER_ARGS)
8315 struct vi_info *vi = arg1;
8316 struct adapter *sc = vi->pi->adapter;
8318 struct sge_ofld_rxq *ofld_rxq;
8321 idx = vi->ofld_tmr_idx;
8323 rc = sysctl_handle_int(oidp, &idx, 0, req);
8324 if (rc != 0 || req->newptr == NULL)
8327 if (idx < 0 || idx >= SGE_NTIMERS)
8330 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
8335 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(vi->ofld_pktc_idx != -1);
8336 for_each_ofld_rxq(vi, i, ofld_rxq) {
8337 #ifdef atomic_store_rel_8
8338 atomic_store_rel_8(&ofld_rxq->iq.intr_params, v);
8340 ofld_rxq->iq.intr_params = v;
8343 vi->ofld_tmr_idx = idx;
8345 end_synchronized_op(sc, LOCK_HELD);
8350 sysctl_holdoff_pktc_idx_ofld(SYSCTL_HANDLER_ARGS)
8352 struct vi_info *vi = arg1;
8353 struct adapter *sc = vi->pi->adapter;
8356 idx = vi->ofld_pktc_idx;
8358 rc = sysctl_handle_int(oidp, &idx, 0, req);
8359 if (rc != 0 || req->newptr == NULL)
8362 if (idx < -1 || idx >= SGE_NCOUNTERS)
8365 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
8370 if (vi->flags & VI_INIT_DONE)
8371 rc = EBUSY; /* cannot be changed once the queues are created */
8373 vi->ofld_pktc_idx = idx;
8375 end_synchronized_op(sc, LOCK_HELD);
8381 fconf_iconf_to_mode(uint32_t fconf, uint32_t iconf)
8385 mode = T4_FILTER_IPv4 | T4_FILTER_IPv6 | T4_FILTER_IP_SADDR |
8386 T4_FILTER_IP_DADDR | T4_FILTER_IP_SPORT | T4_FILTER_IP_DPORT;
8388 if (fconf & F_FRAGMENTATION)
8389 mode |= T4_FILTER_IP_FRAGMENT;
8391 if (fconf & F_MPSHITTYPE)
8392 mode |= T4_FILTER_MPS_HIT_TYPE;
8394 if (fconf & F_MACMATCH)
8395 mode |= T4_FILTER_MAC_IDX;
8397 if (fconf & F_ETHERTYPE)
8398 mode |= T4_FILTER_ETH_TYPE;
8400 if (fconf & F_PROTOCOL)
8401 mode |= T4_FILTER_IP_PROTO;
8404 mode |= T4_FILTER_IP_TOS;
8407 mode |= T4_FILTER_VLAN;
8409 if (fconf & F_VNIC_ID) {
8410 mode |= T4_FILTER_VNIC;
8412 mode |= T4_FILTER_IC_VNIC;
8416 mode |= T4_FILTER_PORT;
8419 mode |= T4_FILTER_FCoE;
8425 mode_to_fconf(uint32_t mode)
8429 if (mode & T4_FILTER_IP_FRAGMENT)
8430 fconf |= F_FRAGMENTATION;
8432 if (mode & T4_FILTER_MPS_HIT_TYPE)
8433 fconf |= F_MPSHITTYPE;
8435 if (mode & T4_FILTER_MAC_IDX)
8436 fconf |= F_MACMATCH;
8438 if (mode & T4_FILTER_ETH_TYPE)
8439 fconf |= F_ETHERTYPE;
8441 if (mode & T4_FILTER_IP_PROTO)
8442 fconf |= F_PROTOCOL;
8444 if (mode & T4_FILTER_IP_TOS)
8447 if (mode & T4_FILTER_VLAN)
8450 if (mode & T4_FILTER_VNIC)
8453 if (mode & T4_FILTER_PORT)
8456 if (mode & T4_FILTER_FCoE)
8463 mode_to_iconf(uint32_t mode)
8466 if (mode & T4_FILTER_IC_VNIC)
8471 static int check_fspec_against_fconf_iconf(struct adapter *sc,
8472 struct t4_filter_specification *fs)
8474 struct tp_params *tpp = &sc->params.tp;
8477 if (fs->val.frag || fs->mask.frag)
8478 fconf |= F_FRAGMENTATION;
8480 if (fs->val.matchtype || fs->mask.matchtype)
8481 fconf |= F_MPSHITTYPE;
8483 if (fs->val.macidx || fs->mask.macidx)
8484 fconf |= F_MACMATCH;
8486 if (fs->val.ethtype || fs->mask.ethtype)
8487 fconf |= F_ETHERTYPE;
8489 if (fs->val.proto || fs->mask.proto)
8490 fconf |= F_PROTOCOL;
8492 if (fs->val.tos || fs->mask.tos)
8495 if (fs->val.vlan_vld || fs->mask.vlan_vld)
8498 if (fs->val.ovlan_vld || fs->mask.ovlan_vld) {
8500 if (tpp->ingress_config & F_VNIC)
8504 if (fs->val.pfvf_vld || fs->mask.pfvf_vld) {
8506 if ((tpp->ingress_config & F_VNIC) == 0)
8510 if (fs->val.iport || fs->mask.iport)
8513 if (fs->val.fcoe || fs->mask.fcoe)
8516 if ((tpp->vlan_pri_map | fconf) != tpp->vlan_pri_map)
8523 get_filter_mode(struct adapter *sc, uint32_t *mode)
8525 struct tp_params *tpp = &sc->params.tp;
8528 * We trust the cached values of the relevant TP registers. This means
8529 * things work reliably only if writes to those registers are always via
8530 * t4_set_filter_mode.
8532 *mode = fconf_iconf_to_mode(tpp->vlan_pri_map, tpp->ingress_config);
8538 set_filter_mode(struct adapter *sc, uint32_t mode)
8540 struct tp_params *tpp = &sc->params.tp;
8541 uint32_t fconf, iconf;
8544 iconf = mode_to_iconf(mode);
8545 if ((iconf ^ tpp->ingress_config) & F_VNIC) {
8547 * For now we just complain if A_TP_INGRESS_CONFIG is not
8548 * already set to the correct value for the requested filter
8549 * mode. It's not clear if it's safe to write to this register
8550 * on the fly. (And we trust the cached value of the register).
8555 fconf = mode_to_fconf(mode);
8557 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
8562 if (sc->tids.ftids_in_use > 0) {
8568 if (uld_active(sc, ULD_TOM)) {
8574 rc = -t4_set_filter_mode(sc, fconf, true);
8576 end_synchronized_op(sc, LOCK_HELD);
8580 static inline uint64_t
8581 get_filter_hits(struct adapter *sc, uint32_t fid)
8585 tcb_addr = t4_read_reg(sc, A_TP_CMM_TCB_BASE) +
8586 (fid + sc->tids.ftid_base) * TCB_SIZE;
8591 read_via_memwin(sc, 0, tcb_addr + 16, (uint32_t *)&hits, 8);
8592 return (be64toh(hits));
8596 read_via_memwin(sc, 0, tcb_addr + 24, &hits, 4);
8597 return (be32toh(hits));
8602 get_filter(struct adapter *sc, struct t4_filter *t)
8604 int i, rc, nfilters = sc->tids.nftids;
8605 struct filter_entry *f;
8607 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
8612 if (sc->tids.ftids_in_use == 0 || sc->tids.ftid_tab == NULL ||
8613 t->idx >= nfilters) {
8614 t->idx = 0xffffffff;
8618 f = &sc->tids.ftid_tab[t->idx];
8619 for (i = t->idx; i < nfilters; i++, f++) {
8622 t->l2tidx = f->l2t ? f->l2t->idx : 0;
8623 t->smtidx = f->smtidx;
8625 t->hits = get_filter_hits(sc, t->idx);
8627 t->hits = UINT64_MAX;
8634 t->idx = 0xffffffff;
8636 end_synchronized_op(sc, LOCK_HELD);
8641 set_filter(struct adapter *sc, struct t4_filter *t)
8643 unsigned int nfilters, nports;
8644 struct filter_entry *f;
8647 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setf");
8651 nfilters = sc->tids.nftids;
8652 nports = sc->params.nports;
8654 if (nfilters == 0) {
8659 if (t->idx >= nfilters) {
8664 /* Validate against the global filter mode and ingress config */
8665 rc = check_fspec_against_fconf_iconf(sc, &t->fs);
8669 if (t->fs.action == FILTER_SWITCH && t->fs.eport >= nports) {
8674 if (t->fs.val.iport >= nports) {
8679 /* Can't specify an iq if not steering to it */
8680 if (!t->fs.dirsteer && t->fs.iq) {
8685 /* IPv6 filter idx must be 4 aligned */
8686 if (t->fs.type == 1 &&
8687 ((t->idx & 0x3) || t->idx + 4 >= nfilters)) {
8692 if (!(sc->flags & FULL_INIT_DONE) &&
8693 ((rc = adapter_full_init(sc)) != 0))
8696 if (sc->tids.ftid_tab == NULL) {
8697 KASSERT(sc->tids.ftids_in_use == 0,
8698 ("%s: no memory allocated but filters_in_use > 0",
8701 sc->tids.ftid_tab = malloc(sizeof (struct filter_entry) *
8702 nfilters, M_CXGBE, M_NOWAIT | M_ZERO);
8703 if (sc->tids.ftid_tab == NULL) {
8707 mtx_init(&sc->tids.ftid_lock, "T4 filters", 0, MTX_DEF);
8710 for (i = 0; i < 4; i++) {
8711 f = &sc->tids.ftid_tab[t->idx + i];
8713 if (f->pending || f->valid) {
8722 if (t->fs.type == 0)
8726 f = &sc->tids.ftid_tab[t->idx];
8729 rc = set_filter_wr(sc, t->idx);
8731 end_synchronized_op(sc, 0);
8734 mtx_lock(&sc->tids.ftid_lock);
8736 if (f->pending == 0) {
8737 rc = f->valid ? 0 : EIO;
8741 if (mtx_sleep(&sc->tids.ftid_tab, &sc->tids.ftid_lock,
8742 PCATCH, "t4setfw", 0)) {
8747 mtx_unlock(&sc->tids.ftid_lock);
8753 del_filter(struct adapter *sc, struct t4_filter *t)
8755 unsigned int nfilters;
8756 struct filter_entry *f;
8759 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4delf");
8763 nfilters = sc->tids.nftids;
8765 if (nfilters == 0) {
8770 if (sc->tids.ftid_tab == NULL || sc->tids.ftids_in_use == 0 ||
8771 t->idx >= nfilters) {
8776 if (!(sc->flags & FULL_INIT_DONE)) {
8781 f = &sc->tids.ftid_tab[t->idx];
8793 t->fs = f->fs; /* extra info for the caller */
8794 rc = del_filter_wr(sc, t->idx);
8798 end_synchronized_op(sc, 0);
8801 mtx_lock(&sc->tids.ftid_lock);
8803 if (f->pending == 0) {
8804 rc = f->valid ? EIO : 0;
8808 if (mtx_sleep(&sc->tids.ftid_tab, &sc->tids.ftid_lock,
8809 PCATCH, "t4delfw", 0)) {
8814 mtx_unlock(&sc->tids.ftid_lock);
8821 clear_filter(struct filter_entry *f)
8824 t4_l2t_release(f->l2t);
8826 bzero(f, sizeof (*f));
8830 set_filter_wr(struct adapter *sc, int fidx)
8832 struct filter_entry *f = &sc->tids.ftid_tab[fidx];
8833 struct fw_filter_wr *fwr;
8834 unsigned int ftid, vnic_vld, vnic_vld_mask;
8835 struct wrq_cookie cookie;
8837 ASSERT_SYNCHRONIZED_OP(sc);
8839 if (f->fs.newdmac || f->fs.newvlan) {
8840 /* This filter needs an L2T entry; allocate one. */
8841 f->l2t = t4_l2t_alloc_switching(sc->l2t);
8844 if (t4_l2t_set_switching(sc, f->l2t, f->fs.vlan, f->fs.eport,
8846 t4_l2t_release(f->l2t);
8852 /* Already validated against fconf, iconf */
8853 MPASS((f->fs.val.pfvf_vld & f->fs.val.ovlan_vld) == 0);
8854 MPASS((f->fs.mask.pfvf_vld & f->fs.mask.ovlan_vld) == 0);
8855 if (f->fs.val.pfvf_vld || f->fs.val.ovlan_vld)
8859 if (f->fs.mask.pfvf_vld || f->fs.mask.ovlan_vld)
8864 ftid = sc->tids.ftid_base + fidx;
8866 fwr = start_wrq_wr(&sc->sge.mgmtq, howmany(sizeof(*fwr), 16), &cookie);
8869 bzero(fwr, sizeof(*fwr));
8871 fwr->op_pkd = htobe32(V_FW_WR_OP(FW_FILTER_WR));
8872 fwr->len16_pkd = htobe32(FW_LEN16(*fwr));
8874 htobe32(V_FW_FILTER_WR_TID(ftid) |
8875 V_FW_FILTER_WR_RQTYPE(f->fs.type) |
8876 V_FW_FILTER_WR_NOREPLY(0) |
8877 V_FW_FILTER_WR_IQ(f->fs.iq));
8878 fwr->del_filter_to_l2tix =
8879 htobe32(V_FW_FILTER_WR_RPTTID(f->fs.rpttid) |
8880 V_FW_FILTER_WR_DROP(f->fs.action == FILTER_DROP) |
8881 V_FW_FILTER_WR_DIRSTEER(f->fs.dirsteer) |
8882 V_FW_FILTER_WR_MASKHASH(f->fs.maskhash) |
8883 V_FW_FILTER_WR_DIRSTEERHASH(f->fs.dirsteerhash) |
8884 V_FW_FILTER_WR_LPBK(f->fs.action == FILTER_SWITCH) |
8885 V_FW_FILTER_WR_DMAC(f->fs.newdmac) |
8886 V_FW_FILTER_WR_SMAC(f->fs.newsmac) |
8887 V_FW_FILTER_WR_INSVLAN(f->fs.newvlan == VLAN_INSERT ||
8888 f->fs.newvlan == VLAN_REWRITE) |
8889 V_FW_FILTER_WR_RMVLAN(f->fs.newvlan == VLAN_REMOVE ||
8890 f->fs.newvlan == VLAN_REWRITE) |
8891 V_FW_FILTER_WR_HITCNTS(f->fs.hitcnts) |
8892 V_FW_FILTER_WR_TXCHAN(f->fs.eport) |
8893 V_FW_FILTER_WR_PRIO(f->fs.prio) |
8894 V_FW_FILTER_WR_L2TIX(f->l2t ? f->l2t->idx : 0));
8895 fwr->ethtype = htobe16(f->fs.val.ethtype);
8896 fwr->ethtypem = htobe16(f->fs.mask.ethtype);
8897 fwr->frag_to_ovlan_vldm =
8898 (V_FW_FILTER_WR_FRAG(f->fs.val.frag) |
8899 V_FW_FILTER_WR_FRAGM(f->fs.mask.frag) |
8900 V_FW_FILTER_WR_IVLAN_VLD(f->fs.val.vlan_vld) |
8901 V_FW_FILTER_WR_OVLAN_VLD(vnic_vld) |
8902 V_FW_FILTER_WR_IVLAN_VLDM(f->fs.mask.vlan_vld) |
8903 V_FW_FILTER_WR_OVLAN_VLDM(vnic_vld_mask));
8905 fwr->rx_chan_rx_rpl_iq = htobe16(V_FW_FILTER_WR_RX_CHAN(0) |
8906 V_FW_FILTER_WR_RX_RPL_IQ(sc->sge.fwq.abs_id));
8907 fwr->maci_to_matchtypem =
8908 htobe32(V_FW_FILTER_WR_MACI(f->fs.val.macidx) |
8909 V_FW_FILTER_WR_MACIM(f->fs.mask.macidx) |
8910 V_FW_FILTER_WR_FCOE(f->fs.val.fcoe) |
8911 V_FW_FILTER_WR_FCOEM(f->fs.mask.fcoe) |
8912 V_FW_FILTER_WR_PORT(f->fs.val.iport) |
8913 V_FW_FILTER_WR_PORTM(f->fs.mask.iport) |
8914 V_FW_FILTER_WR_MATCHTYPE(f->fs.val.matchtype) |
8915 V_FW_FILTER_WR_MATCHTYPEM(f->fs.mask.matchtype));
8916 fwr->ptcl = f->fs.val.proto;
8917 fwr->ptclm = f->fs.mask.proto;
8918 fwr->ttyp = f->fs.val.tos;
8919 fwr->ttypm = f->fs.mask.tos;
8920 fwr->ivlan = htobe16(f->fs.val.vlan);
8921 fwr->ivlanm = htobe16(f->fs.mask.vlan);
8922 fwr->ovlan = htobe16(f->fs.val.vnic);
8923 fwr->ovlanm = htobe16(f->fs.mask.vnic);
8924 bcopy(f->fs.val.dip, fwr->lip, sizeof (fwr->lip));
8925 bcopy(f->fs.mask.dip, fwr->lipm, sizeof (fwr->lipm));
8926 bcopy(f->fs.val.sip, fwr->fip, sizeof (fwr->fip));
8927 bcopy(f->fs.mask.sip, fwr->fipm, sizeof (fwr->fipm));
8928 fwr->lp = htobe16(f->fs.val.dport);
8929 fwr->lpm = htobe16(f->fs.mask.dport);
8930 fwr->fp = htobe16(f->fs.val.sport);
8931 fwr->fpm = htobe16(f->fs.mask.sport);
8933 bcopy(f->fs.smac, fwr->sma, sizeof (fwr->sma));
8936 sc->tids.ftids_in_use++;
8938 commit_wrq_wr(&sc->sge.mgmtq, fwr, &cookie);
8943 del_filter_wr(struct adapter *sc, int fidx)
8945 struct filter_entry *f = &sc->tids.ftid_tab[fidx];
8946 struct fw_filter_wr *fwr;
8948 struct wrq_cookie cookie;
8950 ftid = sc->tids.ftid_base + fidx;
8952 fwr = start_wrq_wr(&sc->sge.mgmtq, howmany(sizeof(*fwr), 16), &cookie);
8955 bzero(fwr, sizeof (*fwr));
8957 t4_mk_filtdelwr(ftid, fwr, sc->sge.fwq.abs_id);
8960 commit_wrq_wr(&sc->sge.mgmtq, fwr, &cookie);
8965 t4_filter_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
8967 struct adapter *sc = iq->adapter;
8968 const struct cpl_set_tcb_rpl *rpl = (const void *)(rss + 1);
8969 unsigned int idx = GET_TID(rpl);
8971 struct filter_entry *f;
8973 KASSERT(m == NULL, ("%s: payload with opcode %02x", __func__,
8975 MPASS(iq == &sc->sge.fwq);
8976 MPASS(is_ftid(sc, idx));
8978 idx -= sc->tids.ftid_base;
8979 f = &sc->tids.ftid_tab[idx];
8980 rc = G_COOKIE(rpl->cookie);
8982 mtx_lock(&sc->tids.ftid_lock);
8983 if (rc == FW_FILTER_WR_FLT_ADDED) {
8984 KASSERT(f->pending, ("%s: filter[%u] isn't pending.",
8986 f->smtidx = (be64toh(rpl->oldval) >> 24) & 0xff;
8987 f->pending = 0; /* asynchronous setup completed */
8990 if (rc != FW_FILTER_WR_FLT_DELETED) {
8991 /* Add or delete failed, display an error */
8993 "filter %u setup failed with error %u\n",
8998 sc->tids.ftids_in_use--;
9000 wakeup(&sc->tids.ftid_tab);
9001 mtx_unlock(&sc->tids.ftid_lock);
9007 set_tcb_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
9010 MPASS(iq->set_tcb_rpl != NULL);
9011 return (iq->set_tcb_rpl(iq, rss, m));
9015 l2t_write_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
9018 MPASS(iq->l2t_write_rpl != NULL);
9019 return (iq->l2t_write_rpl(iq, rss, m));
9023 get_sge_context(struct adapter *sc, struct t4_sge_context *cntxt)
9027 if (cntxt->cid > M_CTXTQID)
9030 if (cntxt->mem_id != CTXT_EGRESS && cntxt->mem_id != CTXT_INGRESS &&
9031 cntxt->mem_id != CTXT_FLM && cntxt->mem_id != CTXT_CNM)
9034 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ctxt");
9038 if (sc->flags & FW_OK) {
9039 rc = -t4_sge_ctxt_rd(sc, sc->mbox, cntxt->cid, cntxt->mem_id,
9046 * Read via firmware failed or wasn't even attempted. Read directly via
9049 rc = -t4_sge_ctxt_rd_bd(sc, cntxt->cid, cntxt->mem_id, &cntxt->data[0]);
9051 end_synchronized_op(sc, 0);
9056 load_fw(struct adapter *sc, struct t4_data *fw)
9061 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldfw");
9066 * The firmware, with the sole exception of the memory parity error
9067 * handler, runs from memory and not flash. It is almost always safe to
9068 * install a new firmware on a running system. Just set bit 1 in
9069 * hw.cxgbe.dflags or dev.<nexus>.<n>.dflags first.
9071 if (sc->flags & FULL_INIT_DONE &&
9072 (sc->debug_flags & DF_LOAD_FW_ANYTIME) == 0) {
9077 fw_data = malloc(fw->len, M_CXGBE, M_WAITOK);
9078 if (fw_data == NULL) {
9083 rc = copyin(fw->data, fw_data, fw->len);
9085 rc = -t4_load_fw(sc, fw_data, fw->len);
9087 free(fw_data, M_CXGBE);
9089 end_synchronized_op(sc, 0);
9094 load_cfg(struct adapter *sc, struct t4_data *cfg)
9097 uint8_t *cfg_data = NULL;
9099 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldcf");
9103 if (cfg->len == 0) {
9105 rc = -t4_load_cfg(sc, NULL, 0);
9109 cfg_data = malloc(cfg->len, M_CXGBE, M_WAITOK);
9110 if (cfg_data == NULL) {
9115 rc = copyin(cfg->data, cfg_data, cfg->len);
9117 rc = -t4_load_cfg(sc, cfg_data, cfg->len);
9119 free(cfg_data, M_CXGBE);
9121 end_synchronized_op(sc, 0);
9126 load_boot(struct adapter *sc, struct t4_bootrom *br)
9129 uint8_t *br_data = NULL;
9132 if (br->len > 1024 * 1024)
9135 if (br->pf_offset == 0) {
9137 if (br->pfidx_addr > 7)
9139 offset = G_OFFSET(t4_read_reg(sc, PF_REG(br->pfidx_addr,
9140 A_PCIE_PF_EXPROM_OFST)));
9141 } else if (br->pf_offset == 1) {
9143 offset = G_OFFSET(br->pfidx_addr);
9148 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldbr");
9154 rc = -t4_load_boot(sc, NULL, offset, 0);
9158 br_data = malloc(br->len, M_CXGBE, M_WAITOK);
9159 if (br_data == NULL) {
9164 rc = copyin(br->data, br_data, br->len);
9166 rc = -t4_load_boot(sc, br_data, offset, br->len);
9168 free(br_data, M_CXGBE);
9170 end_synchronized_op(sc, 0);
9175 load_bootcfg(struct adapter *sc, struct t4_data *bc)
9178 uint8_t *bc_data = NULL;
9180 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldcf");
9186 rc = -t4_load_bootcfg(sc, NULL, 0);
9190 bc_data = malloc(bc->len, M_CXGBE, M_WAITOK);
9191 if (bc_data == NULL) {
9196 rc = copyin(bc->data, bc_data, bc->len);
9198 rc = -t4_load_bootcfg(sc, bc_data, bc->len);
9200 free(bc_data, M_CXGBE);
9202 end_synchronized_op(sc, 0);
9207 cudbg_dump(struct adapter *sc, struct t4_cudbg_dump *dump)
9210 struct cudbg_init *cudbg;
9213 /* buf is large, don't block if no memory is available */
9214 buf = malloc(dump->len, M_CXGBE, M_NOWAIT | M_ZERO);
9218 handle = cudbg_alloc_handle();
9219 if (handle == NULL) {
9224 cudbg = cudbg_get_init(handle);
9226 cudbg->print = (cudbg_print_cb)printf;
9229 device_printf(sc->dev, "%s: wr_flash %u, len %u, data %p.\n",
9230 __func__, dump->wr_flash, dump->len, dump->data);
9234 cudbg->use_flash = 1;
9235 MPASS(sizeof(cudbg->dbg_bitmap) == sizeof(dump->bitmap));
9236 memcpy(cudbg->dbg_bitmap, dump->bitmap, sizeof(cudbg->dbg_bitmap));
9238 rc = cudbg_collect(handle, buf, &dump->len);
9242 rc = copyout(buf, dump->data, dump->len);
9244 cudbg_free_handle(handle);
9249 #define MAX_READ_BUF_SIZE (128 * 1024)
9251 read_card_mem(struct adapter *sc, int win, struct t4_mem_range *mr)
9253 uint32_t addr, remaining, n;
9258 rc = validate_mem_range(sc, mr->addr, mr->len);
9262 buf = malloc(min(mr->len, MAX_READ_BUF_SIZE), M_CXGBE, M_WAITOK);
9264 remaining = mr->len;
9265 dst = (void *)mr->data;
9268 n = min(remaining, MAX_READ_BUF_SIZE);
9269 read_via_memwin(sc, 2, addr, buf, n);
9271 rc = copyout(buf, dst, n);
9283 #undef MAX_READ_BUF_SIZE
9286 read_i2c(struct adapter *sc, struct t4_i2c_data *i2cd)
9290 if (i2cd->len == 0 || i2cd->port_id >= sc->params.nports)
9293 if (i2cd->len > sizeof(i2cd->data))
9296 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4i2crd");
9299 rc = -t4_i2c_rd(sc, sc->mbox, i2cd->port_id, i2cd->dev_addr,
9300 i2cd->offset, i2cd->len, &i2cd->data[0]);
9301 end_synchronized_op(sc, 0);
9307 t4_os_find_pci_capability(struct adapter *sc, int cap)
9311 return (pci_find_cap(sc->dev, cap, &i) == 0 ? i : 0);
9315 t4_os_pci_save_state(struct adapter *sc)
9318 struct pci_devinfo *dinfo;
9321 dinfo = device_get_ivars(dev);
9323 pci_cfg_save(dev, dinfo, 0);
9328 t4_os_pci_restore_state(struct adapter *sc)
9331 struct pci_devinfo *dinfo;
9334 dinfo = device_get_ivars(dev);
9336 pci_cfg_restore(dev, dinfo);
9341 t4_os_portmod_changed(struct port_info *pi)
9343 struct adapter *sc = pi->adapter;
9346 static const char *mod_str[] = {
9347 NULL, "LR", "SR", "ER", "TWINAX", "active TWINAX", "LRM"
9351 build_medialist(pi, &pi->media);
9354 if (begin_synchronized_op(sc, vi, HOLD_LOCK, "t4mod") == 0) {
9356 end_synchronized_op(sc, LOCK_HELD);
9360 if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
9361 if_printf(ifp, "transceiver unplugged.\n");
9362 else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
9363 if_printf(ifp, "unknown transceiver inserted.\n");
9364 else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
9365 if_printf(ifp, "unsupported transceiver inserted.\n");
9366 else if (pi->mod_type > 0 && pi->mod_type < nitems(mod_str)) {
9367 if_printf(ifp, "%dGbps %s transceiver inserted.\n",
9368 port_top_speed(pi), mod_str[pi->mod_type]);
9370 if_printf(ifp, "transceiver (type %d) inserted.\n",
9376 t4_os_link_changed(struct port_info *pi)
9380 struct link_config *lc;
9383 for_each_vi(pi, v, vi) {
9390 ifp->if_baudrate = IF_Mbps(lc->speed);
9391 if_link_state_change(ifp, LINK_STATE_UP);
9393 if_link_state_change(ifp, LINK_STATE_DOWN);
9399 t4_iterate(void (*func)(struct adapter *, void *), void *arg)
9403 sx_slock(&t4_list_lock);
9404 SLIST_FOREACH(sc, &t4_list, link) {
9406 * func should not make any assumptions about what state sc is
9407 * in - the only guarantee is that sc->sc_lock is a valid lock.
9411 sx_sunlock(&t4_list_lock);
9415 t4_ioctl(struct cdev *dev, unsigned long cmd, caddr_t data, int fflag,
9419 struct adapter *sc = dev->si_drv1;
9421 rc = priv_check(td, PRIV_DRIVER);
9426 case CHELSIO_T4_GETREG: {
9427 struct t4_reg *edata = (struct t4_reg *)data;
9429 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
9432 if (edata->size == 4)
9433 edata->val = t4_read_reg(sc, edata->addr);
9434 else if (edata->size == 8)
9435 edata->val = t4_read_reg64(sc, edata->addr);
9441 case CHELSIO_T4_SETREG: {
9442 struct t4_reg *edata = (struct t4_reg *)data;
9444 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
9447 if (edata->size == 4) {
9448 if (edata->val & 0xffffffff00000000)
9450 t4_write_reg(sc, edata->addr, (uint32_t) edata->val);
9451 } else if (edata->size == 8)
9452 t4_write_reg64(sc, edata->addr, edata->val);
9457 case CHELSIO_T4_REGDUMP: {
9458 struct t4_regdump *regs = (struct t4_regdump *)data;
9459 int reglen = t4_get_regs_len(sc);
9462 if (regs->len < reglen) {
9463 regs->len = reglen; /* hint to the caller */
9468 buf = malloc(reglen, M_CXGBE, M_WAITOK | M_ZERO);
9469 get_regs(sc, regs, buf);
9470 rc = copyout(buf, regs->data, reglen);
9474 case CHELSIO_T4_GET_FILTER_MODE:
9475 rc = get_filter_mode(sc, (uint32_t *)data);
9477 case CHELSIO_T4_SET_FILTER_MODE:
9478 rc = set_filter_mode(sc, *(uint32_t *)data);
9480 case CHELSIO_T4_GET_FILTER:
9481 rc = get_filter(sc, (struct t4_filter *)data);
9483 case CHELSIO_T4_SET_FILTER:
9484 rc = set_filter(sc, (struct t4_filter *)data);
9486 case CHELSIO_T4_DEL_FILTER:
9487 rc = del_filter(sc, (struct t4_filter *)data);
9489 case CHELSIO_T4_GET_SGE_CONTEXT:
9490 rc = get_sge_context(sc, (struct t4_sge_context *)data);
9492 case CHELSIO_T4_LOAD_FW:
9493 rc = load_fw(sc, (struct t4_data *)data);
9495 case CHELSIO_T4_GET_MEM:
9496 rc = read_card_mem(sc, 2, (struct t4_mem_range *)data);
9498 case CHELSIO_T4_GET_I2C:
9499 rc = read_i2c(sc, (struct t4_i2c_data *)data);
9501 case CHELSIO_T4_CLEAR_STATS: {
9503 u_int port_id = *(uint32_t *)data;
9504 struct port_info *pi;
9507 if (port_id >= sc->params.nports)
9509 pi = sc->port[port_id];
9514 t4_clr_port_stats(sc, pi->tx_chan);
9515 pi->tx_parse_error = 0;
9516 mtx_lock(&sc->reg_lock);
9517 for_each_vi(pi, v, vi) {
9518 if (vi->flags & VI_INIT_DONE)
9519 t4_clr_vi_stats(sc, vi->viid);
9521 mtx_unlock(&sc->reg_lock);
9524 * Since this command accepts a port, clear stats for
9525 * all VIs on this port.
9527 for_each_vi(pi, v, vi) {
9528 if (vi->flags & VI_INIT_DONE) {
9529 struct sge_rxq *rxq;
9530 struct sge_txq *txq;
9531 struct sge_wrq *wrq;
9533 for_each_rxq(vi, i, rxq) {
9534 #if defined(INET) || defined(INET6)
9535 rxq->lro.lro_queued = 0;
9536 rxq->lro.lro_flushed = 0;
9539 rxq->vlan_extraction = 0;
9542 for_each_txq(vi, i, txq) {
9545 txq->vlan_insertion = 0;
9549 txq->txpkts0_wrs = 0;
9550 txq->txpkts1_wrs = 0;
9551 txq->txpkts0_pkts = 0;
9552 txq->txpkts1_pkts = 0;
9553 mp_ring_reset_stats(txq->r);
9557 /* nothing to clear for each ofld_rxq */
9559 for_each_ofld_txq(vi, i, wrq) {
9560 wrq->tx_wrs_direct = 0;
9561 wrq->tx_wrs_copied = 0;
9565 if (IS_MAIN_VI(vi)) {
9566 wrq = &sc->sge.ctrlq[pi->port_id];
9567 wrq->tx_wrs_direct = 0;
9568 wrq->tx_wrs_copied = 0;
9574 case CHELSIO_T4_SCHED_CLASS:
9575 rc = t4_set_sched_class(sc, (struct t4_sched_params *)data);
9577 case CHELSIO_T4_SCHED_QUEUE:
9578 rc = t4_set_sched_queue(sc, (struct t4_sched_queue *)data);
9580 case CHELSIO_T4_GET_TRACER:
9581 rc = t4_get_tracer(sc, (struct t4_tracer *)data);
9583 case CHELSIO_T4_SET_TRACER:
9584 rc = t4_set_tracer(sc, (struct t4_tracer *)data);
9586 case CHELSIO_T4_LOAD_CFG:
9587 rc = load_cfg(sc, (struct t4_data *)data);
9589 case CHELSIO_T4_LOAD_BOOT:
9590 rc = load_boot(sc, (struct t4_bootrom *)data);
9592 case CHELSIO_T4_LOAD_BOOTCFG:
9593 rc = load_bootcfg(sc, (struct t4_data *)data);
9595 case CHELSIO_T4_CUDBG_DUMP:
9596 rc = cudbg_dump(sc, (struct t4_cudbg_dump *)data);
9606 t4_db_full(struct adapter *sc)
9609 CXGBE_UNIMPLEMENTED(__func__);
9613 t4_db_dropped(struct adapter *sc)
9616 CXGBE_UNIMPLEMENTED(__func__);
9621 toe_capability(struct vi_info *vi, int enable)
9624 struct port_info *pi = vi->pi;
9625 struct adapter *sc = pi->adapter;
9627 ASSERT_SYNCHRONIZED_OP(sc);
9629 if (!is_offload(sc))
9633 if ((vi->ifp->if_capenable & IFCAP_TOE) != 0) {
9634 /* TOE is already enabled. */
9639 * We need the port's queues around so that we're able to send
9640 * and receive CPLs to/from the TOE even if the ifnet for this
9641 * port has never been UP'd administratively.
9643 if (!(vi->flags & VI_INIT_DONE)) {
9644 rc = vi_full_init(vi);
9648 if (!(pi->vi[0].flags & VI_INIT_DONE)) {
9649 rc = vi_full_init(&pi->vi[0]);
9654 if (isset(&sc->offload_map, pi->port_id)) {
9655 /* TOE is enabled on another VI of this port. */
9660 if (!uld_active(sc, ULD_TOM)) {
9661 rc = t4_activate_uld(sc, ULD_TOM);
9664 "You must kldload t4_tom.ko before trying "
9665 "to enable TOE on a cxgbe interface.\n");
9669 KASSERT(sc->tom_softc != NULL,
9670 ("%s: TOM activated but softc NULL", __func__));
9671 KASSERT(uld_active(sc, ULD_TOM),
9672 ("%s: TOM activated but flag not set", __func__));
9675 /* Activate iWARP and iSCSI too, if the modules are loaded. */
9676 if (!uld_active(sc, ULD_IWARP))
9677 (void) t4_activate_uld(sc, ULD_IWARP);
9678 if (!uld_active(sc, ULD_ISCSI))
9679 (void) t4_activate_uld(sc, ULD_ISCSI);
9682 setbit(&sc->offload_map, pi->port_id);
9686 if (!isset(&sc->offload_map, pi->port_id) || pi->uld_vis > 0)
9689 KASSERT(uld_active(sc, ULD_TOM),
9690 ("%s: TOM never initialized?", __func__));
9691 clrbit(&sc->offload_map, pi->port_id);
9698 * Add an upper layer driver to the global list.
9701 t4_register_uld(struct uld_info *ui)
9706 sx_xlock(&t4_uld_list_lock);
9707 SLIST_FOREACH(u, &t4_uld_list, link) {
9708 if (u->uld_id == ui->uld_id) {
9714 SLIST_INSERT_HEAD(&t4_uld_list, ui, link);
9717 sx_xunlock(&t4_uld_list_lock);
9722 t4_unregister_uld(struct uld_info *ui)
9727 sx_xlock(&t4_uld_list_lock);
9729 SLIST_FOREACH(u, &t4_uld_list, link) {
9731 if (ui->refcount > 0) {
9736 SLIST_REMOVE(&t4_uld_list, ui, uld_info, link);
9742 sx_xunlock(&t4_uld_list_lock);
9747 t4_activate_uld(struct adapter *sc, int id)
9750 struct uld_info *ui;
9752 ASSERT_SYNCHRONIZED_OP(sc);
9754 if (id < 0 || id > ULD_MAX)
9756 rc = EAGAIN; /* kldoad the module with this ULD and try again. */
9758 sx_slock(&t4_uld_list_lock);
9760 SLIST_FOREACH(ui, &t4_uld_list, link) {
9761 if (ui->uld_id == id) {
9762 if (!(sc->flags & FULL_INIT_DONE)) {
9763 rc = adapter_full_init(sc);
9768 rc = ui->activate(sc);
9770 setbit(&sc->active_ulds, id);
9777 sx_sunlock(&t4_uld_list_lock);
9783 t4_deactivate_uld(struct adapter *sc, int id)
9786 struct uld_info *ui;
9788 ASSERT_SYNCHRONIZED_OP(sc);
9790 if (id < 0 || id > ULD_MAX)
9794 sx_slock(&t4_uld_list_lock);
9796 SLIST_FOREACH(ui, &t4_uld_list, link) {
9797 if (ui->uld_id == id) {
9798 rc = ui->deactivate(sc);
9800 clrbit(&sc->active_ulds, id);
9807 sx_sunlock(&t4_uld_list_lock);
9813 uld_active(struct adapter *sc, int uld_id)
9816 MPASS(uld_id >= 0 && uld_id <= ULD_MAX);
9818 return (isset(&sc->active_ulds, uld_id));
9823 * t = ptr to tunable.
9824 * nc = number of CPUs.
9825 * c = compiled in default for that tunable.
9828 calculate_nqueues(int *t, int nc, const int c)
9834 nq = *t < 0 ? -*t : c;
9839 * Come up with reasonable defaults for some of the tunables, provided they're
9840 * not set by the user (in which case we'll use the values as is).
9843 tweak_tunables(void)
9845 int nc = mp_ncpus; /* our snapshot of the number of CPUs */
9849 t4_ntxq = rss_getnumbuckets();
9851 calculate_nqueues(&t4_ntxq, nc, NTXQ);
9855 calculate_nqueues(&t4_ntxq_vi, nc, NTXQ_VI);
9859 t4_nrxq = rss_getnumbuckets();
9861 calculate_nqueues(&t4_nrxq, nc, NRXQ);
9865 calculate_nqueues(&t4_nrxq_vi, nc, NRXQ_VI);
9868 calculate_nqueues(&t4_nofldtxq, nc, NOFLDTXQ);
9869 calculate_nqueues(&t4_nofldtxq_vi, nc, NOFLDTXQ_VI);
9870 calculate_nqueues(&t4_nofldrxq, nc, NOFLDRXQ);
9871 calculate_nqueues(&t4_nofldrxq_vi, nc, NOFLDRXQ_VI);
9873 if (t4_toecaps_allowed == -1)
9874 t4_toecaps_allowed = FW_CAPS_CONFIG_TOE;
9876 if (t4_rdmacaps_allowed == -1) {
9877 t4_rdmacaps_allowed = FW_CAPS_CONFIG_RDMA_RDDP |
9878 FW_CAPS_CONFIG_RDMA_RDMAC;
9881 if (t4_iscsicaps_allowed == -1) {
9882 t4_iscsicaps_allowed = FW_CAPS_CONFIG_ISCSI_INITIATOR_PDU |
9883 FW_CAPS_CONFIG_ISCSI_TARGET_PDU |
9884 FW_CAPS_CONFIG_ISCSI_T10DIF;
9887 if (t4_tmr_idx_ofld < 0 || t4_tmr_idx_ofld >= SGE_NTIMERS)
9888 t4_tmr_idx_ofld = TMR_IDX_OFLD;
9890 if (t4_pktc_idx_ofld < -1 || t4_pktc_idx_ofld >= SGE_NCOUNTERS)
9891 t4_pktc_idx_ofld = PKTC_IDX_OFLD;
9893 if (t4_toecaps_allowed == -1)
9894 t4_toecaps_allowed = 0;
9896 if (t4_rdmacaps_allowed == -1)
9897 t4_rdmacaps_allowed = 0;
9899 if (t4_iscsicaps_allowed == -1)
9900 t4_iscsicaps_allowed = 0;
9904 calculate_nqueues(&t4_nnmtxq_vi, nc, NNMTXQ_VI);
9905 calculate_nqueues(&t4_nnmrxq_vi, nc, NNMRXQ_VI);
9908 if (t4_tmr_idx < 0 || t4_tmr_idx >= SGE_NTIMERS)
9909 t4_tmr_idx = TMR_IDX;
9911 if (t4_pktc_idx < -1 || t4_pktc_idx >= SGE_NCOUNTERS)
9912 t4_pktc_idx = PKTC_IDX;
9914 if (t4_qsize_txq < 128)
9917 if (t4_qsize_rxq < 128)
9919 while (t4_qsize_rxq & 7)
9922 t4_intr_types &= INTR_MSIX | INTR_MSI | INTR_INTX;
9925 * Number of VIs to create per-port. The first VI is the "main" regular
9926 * VI for the port. The rest are additional virtual interfaces on the
9927 * same physical port. Note that the main VI does not have native
9928 * netmap support but the extra VIs do.
9930 * Limit the number of VIs per port to the number of available
9931 * MAC addresses per port.
9935 if (t4_num_vis > nitems(vi_mac_funcs)) {
9936 t4_num_vis = nitems(vi_mac_funcs);
9937 printf("cxgbe: number of VIs limited to %d\n", t4_num_vis);
9943 t4_dump_tcb(struct adapter *sc, int tid)
9945 uint32_t base, i, j, off, pf, reg, save, tcb_addr, win_pos;
9947 reg = PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, 2);
9948 save = t4_read_reg(sc, reg);
9949 base = sc->memwin[2].mw_base;
9951 /* Dump TCB for the tid */
9952 tcb_addr = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
9953 tcb_addr += tid * TCB_SIZE;
9957 win_pos = tcb_addr & ~0xf; /* start must be 16B aligned */
9959 pf = V_PFNUM(sc->pf);
9960 win_pos = tcb_addr & ~0x7f; /* start must be 128B aligned */
9962 t4_write_reg(sc, reg, win_pos | pf);
9963 t4_read_reg(sc, reg);
9965 off = tcb_addr - win_pos;
9966 for (i = 0; i < 4; i++) {
9968 for (j = 0; j < 8; j++, off += 4)
9969 buf[j] = htonl(t4_read_reg(sc, base + off));
9971 db_printf("%08x %08x %08x %08x %08x %08x %08x %08x\n",
9972 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
9976 t4_write_reg(sc, reg, save);
9977 t4_read_reg(sc, reg);
9981 t4_dump_devlog(struct adapter *sc)
9983 struct devlog_params *dparams = &sc->params.devlog;
9984 struct fw_devlog_e e;
9985 int i, first, j, m, nentries, rc;
9986 uint64_t ftstamp = UINT64_MAX;
9988 if (dparams->start == 0) {
9989 db_printf("devlog params not valid\n");
9993 nentries = dparams->size / sizeof(struct fw_devlog_e);
9994 m = fwmtype_to_hwmtype(dparams->memtype);
9996 /* Find the first entry. */
9998 for (i = 0; i < nentries && !db_pager_quit; i++) {
9999 rc = -t4_mem_read(sc, m, dparams->start + i * sizeof(e),
10000 sizeof(e), (void *)&e);
10004 if (e.timestamp == 0)
10007 e.timestamp = be64toh(e.timestamp);
10008 if (e.timestamp < ftstamp) {
10009 ftstamp = e.timestamp;
10019 rc = -t4_mem_read(sc, m, dparams->start + i * sizeof(e),
10020 sizeof(e), (void *)&e);
10024 if (e.timestamp == 0)
10027 e.timestamp = be64toh(e.timestamp);
10028 e.seqno = be32toh(e.seqno);
10029 for (j = 0; j < 8; j++)
10030 e.params[j] = be32toh(e.params[j]);
10032 db_printf("%10d %15ju %8s %8s ",
10033 e.seqno, e.timestamp,
10034 (e.level < nitems(devlog_level_strings) ?
10035 devlog_level_strings[e.level] : "UNKNOWN"),
10036 (e.facility < nitems(devlog_facility_strings) ?
10037 devlog_facility_strings[e.facility] : "UNKNOWN"));
10038 db_printf(e.fmt, e.params[0], e.params[1], e.params[2],
10039 e.params[3], e.params[4], e.params[5], e.params[6],
10042 if (++i == nentries)
10044 } while (i != first && !db_pager_quit);
10047 static struct command_table db_t4_table = LIST_HEAD_INITIALIZER(db_t4_table);
10048 _DB_SET(_show, t4, NULL, db_show_table, 0, &db_t4_table);
10050 DB_FUNC(devlog, db_show_devlog, db_t4_table, CS_OWN, NULL)
10057 t = db_read_token();
10059 dev = device_lookup_by_name(db_tok_string);
10064 db_printf("usage: show t4 devlog <nexus>\n");
10069 db_printf("device not found\n");
10073 t4_dump_devlog(device_get_softc(dev));
10076 DB_FUNC(tcb, db_show_t4tcb, db_t4_table, CS_OWN, NULL)
10085 t = db_read_token();
10087 dev = device_lookup_by_name(db_tok_string);
10088 t = db_read_token();
10089 if (t == tNUMBER) {
10090 tid = db_tok_number;
10097 db_printf("usage: show t4 tcb <nexus> <tid>\n");
10102 db_printf("device not found\n");
10106 db_printf("invalid tid\n");
10110 t4_dump_tcb(device_get_softc(dev), tid);
10114 static struct sx mlu; /* mod load unload */
10115 SX_SYSINIT(cxgbe_mlu, &mlu, "cxgbe mod load/unload");
10118 mod_event(module_t mod, int cmd, void *arg)
10121 static int loaded = 0;
10126 if (loaded++ == 0) {
10128 t4_register_cpl_handler(CPL_SET_TCB_RPL, set_tcb_rpl);
10129 t4_register_cpl_handler(CPL_L2T_WRITE_RPL, l2t_write_rpl);
10130 t4_register_cpl_handler(CPL_TRACE_PKT, t4_trace_pkt);
10131 t4_register_cpl_handler(CPL_T5_TRACE_PKT, t5_trace_pkt);
10132 sx_init(&t4_list_lock, "T4/T5 adapters");
10133 SLIST_INIT(&t4_list);
10135 sx_init(&t4_uld_list_lock, "T4/T5 ULDs");
10136 SLIST_INIT(&t4_uld_list);
10138 t4_tracer_modload();
10146 if (--loaded == 0) {
10149 sx_slock(&t4_list_lock);
10150 if (!SLIST_EMPTY(&t4_list)) {
10152 sx_sunlock(&t4_list_lock);
10156 sx_slock(&t4_uld_list_lock);
10157 if (!SLIST_EMPTY(&t4_uld_list)) {
10159 sx_sunlock(&t4_uld_list_lock);
10160 sx_sunlock(&t4_list_lock);
10165 while (tries++ < 5 && t4_sge_extfree_refs() != 0) {
10166 uprintf("%ju clusters with custom free routine "
10167 "still is use.\n", t4_sge_extfree_refs());
10168 pause("t4unload", 2 * hz);
10171 sx_sunlock(&t4_uld_list_lock);
10173 sx_sunlock(&t4_list_lock);
10175 if (t4_sge_extfree_refs() == 0) {
10176 t4_tracer_modunload();
10178 sx_destroy(&t4_uld_list_lock);
10180 sx_destroy(&t4_list_lock);
10181 t4_sge_modunload();
10185 loaded++; /* undo earlier decrement */
10196 static devclass_t t4_devclass, t5_devclass, t6_devclass;
10197 static devclass_t cxgbe_devclass, cxl_devclass, cc_devclass;
10198 static devclass_t vcxgbe_devclass, vcxl_devclass, vcc_devclass;
10200 DRIVER_MODULE(t4nex, pci, t4_driver, t4_devclass, mod_event, 0);
10201 MODULE_VERSION(t4nex, 1);
10202 MODULE_DEPEND(t4nex, firmware, 1, 1, 1);
10204 MODULE_DEPEND(t4nex, netmap, 1, 1, 1);
10205 #endif /* DEV_NETMAP */
10207 DRIVER_MODULE(t5nex, pci, t5_driver, t5_devclass, mod_event, 0);
10208 MODULE_VERSION(t5nex, 1);
10209 MODULE_DEPEND(t5nex, firmware, 1, 1, 1);
10211 MODULE_DEPEND(t5nex, netmap, 1, 1, 1);
10212 #endif /* DEV_NETMAP */
10214 DRIVER_MODULE(t6nex, pci, t6_driver, t6_devclass, mod_event, 0);
10215 MODULE_VERSION(t6nex, 1);
10216 MODULE_DEPEND(t6nex, firmware, 1, 1, 1);
10218 MODULE_DEPEND(t6nex, netmap, 1, 1, 1);
10219 #endif /* DEV_NETMAP */
10221 DRIVER_MODULE(cxgbe, t4nex, cxgbe_driver, cxgbe_devclass, 0, 0);
10222 MODULE_VERSION(cxgbe, 1);
10224 DRIVER_MODULE(cxl, t5nex, cxl_driver, cxl_devclass, 0, 0);
10225 MODULE_VERSION(cxl, 1);
10227 DRIVER_MODULE(cc, t6nex, cc_driver, cc_devclass, 0, 0);
10228 MODULE_VERSION(cc, 1);
10230 DRIVER_MODULE(vcxgbe, cxgbe, vcxgbe_driver, vcxgbe_devclass, 0, 0);
10231 MODULE_VERSION(vcxgbe, 1);
10233 DRIVER_MODULE(vcxl, cxl, vcxl_driver, vcxl_devclass, 0, 0);
10234 MODULE_VERSION(vcxl, 1);
10236 DRIVER_MODULE(vcc, cc, vcc_driver, vcc_devclass, 0, 0);
10237 MODULE_VERSION(vcc, 1);