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__)
64 #include <machine/md_var.h>
65 #include <machine/cputypes.h>
69 #include <crypto/rijndael/rijndael.h>
72 #include <ddb/db_lex.h>
75 #include "common/common.h"
76 #include "common/t4_msg.h"
77 #include "common/t4_regs.h"
78 #include "common/t4_regs_values.h"
79 #include "cudbg/cudbg.h"
82 #include "t4_mp_ring.h"
85 /* T4 bus driver interface */
86 static int t4_probe(device_t);
87 static int t4_attach(device_t);
88 static int t4_detach(device_t);
89 static int t4_child_location_str(device_t, device_t, char *, size_t);
90 static int t4_ready(device_t);
91 static int t4_read_port_device(device_t, int, device_t *);
92 static device_method_t t4_methods[] = {
93 DEVMETHOD(device_probe, t4_probe),
94 DEVMETHOD(device_attach, t4_attach),
95 DEVMETHOD(device_detach, t4_detach),
97 DEVMETHOD(bus_child_location_str, t4_child_location_str),
99 DEVMETHOD(t4_is_main_ready, t4_ready),
100 DEVMETHOD(t4_read_port_device, t4_read_port_device),
104 static driver_t t4_driver = {
107 sizeof(struct adapter)
111 /* T4 port (cxgbe) interface */
112 static int cxgbe_probe(device_t);
113 static int cxgbe_attach(device_t);
114 static int cxgbe_detach(device_t);
115 device_method_t cxgbe_methods[] = {
116 DEVMETHOD(device_probe, cxgbe_probe),
117 DEVMETHOD(device_attach, cxgbe_attach),
118 DEVMETHOD(device_detach, cxgbe_detach),
121 static driver_t cxgbe_driver = {
124 sizeof(struct port_info)
127 /* T4 VI (vcxgbe) interface */
128 static int vcxgbe_probe(device_t);
129 static int vcxgbe_attach(device_t);
130 static int vcxgbe_detach(device_t);
131 static device_method_t vcxgbe_methods[] = {
132 DEVMETHOD(device_probe, vcxgbe_probe),
133 DEVMETHOD(device_attach, vcxgbe_attach),
134 DEVMETHOD(device_detach, vcxgbe_detach),
137 static driver_t vcxgbe_driver = {
140 sizeof(struct vi_info)
143 static d_ioctl_t t4_ioctl;
145 static struct cdevsw t4_cdevsw = {
146 .d_version = D_VERSION,
151 /* T5 bus driver interface */
152 static int t5_probe(device_t);
153 static device_method_t t5_methods[] = {
154 DEVMETHOD(device_probe, t5_probe),
155 DEVMETHOD(device_attach, t4_attach),
156 DEVMETHOD(device_detach, t4_detach),
158 DEVMETHOD(bus_child_location_str, t4_child_location_str),
160 DEVMETHOD(t4_is_main_ready, t4_ready),
161 DEVMETHOD(t4_read_port_device, t4_read_port_device),
165 static driver_t t5_driver = {
168 sizeof(struct adapter)
172 /* T5 port (cxl) interface */
173 static driver_t cxl_driver = {
176 sizeof(struct port_info)
179 /* T5 VI (vcxl) interface */
180 static driver_t vcxl_driver = {
183 sizeof(struct vi_info)
186 /* T6 bus driver interface */
187 static int t6_probe(device_t);
188 static device_method_t t6_methods[] = {
189 DEVMETHOD(device_probe, t6_probe),
190 DEVMETHOD(device_attach, t4_attach),
191 DEVMETHOD(device_detach, t4_detach),
193 DEVMETHOD(bus_child_location_str, t4_child_location_str),
195 DEVMETHOD(t4_is_main_ready, t4_ready),
196 DEVMETHOD(t4_read_port_device, t4_read_port_device),
200 static driver_t t6_driver = {
203 sizeof(struct adapter)
207 /* T6 port (cc) interface */
208 static driver_t cc_driver = {
211 sizeof(struct port_info)
214 /* T6 VI (vcc) interface */
215 static driver_t vcc_driver = {
218 sizeof(struct vi_info)
221 /* ifnet + media interface */
222 static void cxgbe_init(void *);
223 static int cxgbe_ioctl(struct ifnet *, unsigned long, caddr_t);
224 static int cxgbe_transmit(struct ifnet *, struct mbuf *);
225 static void cxgbe_qflush(struct ifnet *);
226 static int cxgbe_media_change(struct ifnet *);
227 static void cxgbe_media_status(struct ifnet *, struct ifmediareq *);
229 MALLOC_DEFINE(M_CXGBE, "cxgbe", "Chelsio T4/T5 Ethernet driver and services");
232 * Correct lock order when you need to acquire multiple locks is t4_list_lock,
233 * then ADAPTER_LOCK, then t4_uld_list_lock.
235 static struct sx t4_list_lock;
236 SLIST_HEAD(, adapter) t4_list;
238 static struct sx t4_uld_list_lock;
239 SLIST_HEAD(, uld_info) t4_uld_list;
243 * Tunables. See tweak_tunables() too.
245 * Each tunable is set to a default value here if it's known at compile-time.
246 * Otherwise it is set to -n as an indication to tweak_tunables() that it should
247 * provide a reasonable default (upto n) when the driver is loaded.
249 * Tunables applicable to both T4 and T5 are under hw.cxgbe. Those specific to
250 * T5 are under hw.cxl.
252 SYSCTL_NODE(_hw, OID_AUTO, cxgbe, CTLFLAG_RD, 0, "cxgbe(4) parameters");
253 SYSCTL_NODE(_hw, OID_AUTO, cxl, CTLFLAG_RD, 0, "cxgbe(4) T5+ parameters");
254 SYSCTL_NODE(_hw_cxgbe, OID_AUTO, toe, CTLFLAG_RD, 0, "cxgbe(4) TOE parameters");
257 * Number of queues for tx and rx, NIC and offload.
261 SYSCTL_INT(_hw_cxgbe, OID_AUTO, ntxq, CTLFLAG_RDTUN, &t4_ntxq, 0,
262 "Number of TX queues per port");
263 TUNABLE_INT("hw.cxgbe.ntxq10g", &t4_ntxq); /* Old name, undocumented */
267 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nrxq, CTLFLAG_RDTUN, &t4_nrxq, 0,
268 "Number of RX queues per port");
269 TUNABLE_INT("hw.cxgbe.nrxq10g", &t4_nrxq); /* Old name, undocumented */
272 static int t4_ntxq_vi = -NTXQ_VI;
273 SYSCTL_INT(_hw_cxgbe, OID_AUTO, ntxq_vi, CTLFLAG_RDTUN, &t4_ntxq_vi, 0,
274 "Number of TX queues per VI");
277 static int t4_nrxq_vi = -NRXQ_VI;
278 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nrxq_vi, CTLFLAG_RDTUN, &t4_nrxq_vi, 0,
279 "Number of RX queues per VI");
281 static int t4_rsrv_noflowq = 0;
282 SYSCTL_INT(_hw_cxgbe, OID_AUTO, rsrv_noflowq, CTLFLAG_RDTUN, &t4_rsrv_noflowq,
283 0, "Reserve TX queue 0 of each VI for non-flowid packets");
287 static int t4_nofldtxq = -NOFLDTXQ;
288 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nofldtxq, CTLFLAG_RDTUN, &t4_nofldtxq, 0,
289 "Number of offload TX queues per port");
292 static int t4_nofldrxq = -NOFLDRXQ;
293 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nofldrxq, CTLFLAG_RDTUN, &t4_nofldrxq, 0,
294 "Number of offload RX queues per port");
296 #define NOFLDTXQ_VI 1
297 static int t4_nofldtxq_vi = -NOFLDTXQ_VI;
298 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nofldtxq_vi, CTLFLAG_RDTUN, &t4_nofldtxq_vi, 0,
299 "Number of offload TX queues per VI");
301 #define NOFLDRXQ_VI 1
302 static int t4_nofldrxq_vi = -NOFLDRXQ_VI;
303 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nofldrxq_vi, CTLFLAG_RDTUN, &t4_nofldrxq_vi, 0,
304 "Number of offload RX queues per VI");
306 #define TMR_IDX_OFLD 1
307 int t4_tmr_idx_ofld = TMR_IDX_OFLD;
308 SYSCTL_INT(_hw_cxgbe, OID_AUTO, holdoff_timer_idx_ofld, CTLFLAG_RDTUN,
309 &t4_tmr_idx_ofld, 0, "Holdoff timer index for offload queues");
311 #define PKTC_IDX_OFLD (-1)
312 int t4_pktc_idx_ofld = PKTC_IDX_OFLD;
313 SYSCTL_INT(_hw_cxgbe, OID_AUTO, holdoff_pktc_idx_ofld, CTLFLAG_RDTUN,
314 &t4_pktc_idx_ofld, 0, "holdoff packet counter index for offload queues");
316 /* 0 means chip/fw default, non-zero number is value in microseconds */
317 static u_long t4_toe_keepalive_idle = 0;
318 SYSCTL_ULONG(_hw_cxgbe_toe, OID_AUTO, keepalive_idle, CTLFLAG_RDTUN,
319 &t4_toe_keepalive_idle, 0, "TOE keepalive idle timer (us)");
321 /* 0 means chip/fw default, non-zero number is value in microseconds */
322 static u_long t4_toe_keepalive_interval = 0;
323 SYSCTL_ULONG(_hw_cxgbe_toe, OID_AUTO, keepalive_interval, CTLFLAG_RDTUN,
324 &t4_toe_keepalive_interval, 0, "TOE keepalive interval timer (us)");
326 /* 0 means chip/fw default, non-zero number is # of keepalives before abort */
327 static int t4_toe_keepalive_count = 0;
328 SYSCTL_INT(_hw_cxgbe_toe, OID_AUTO, keepalive_count, CTLFLAG_RDTUN,
329 &t4_toe_keepalive_count, 0, "Number of TOE keepalive probes before abort");
331 /* 0 means chip/fw default, non-zero number is value in microseconds */
332 static u_long t4_toe_rexmt_min = 0;
333 SYSCTL_ULONG(_hw_cxgbe_toe, OID_AUTO, rexmt_min, CTLFLAG_RDTUN,
334 &t4_toe_rexmt_min, 0, "Minimum TOE retransmit interval (us)");
336 /* 0 means chip/fw default, non-zero number is value in microseconds */
337 static u_long t4_toe_rexmt_max = 0;
338 SYSCTL_ULONG(_hw_cxgbe_toe, OID_AUTO, rexmt_max, CTLFLAG_RDTUN,
339 &t4_toe_rexmt_max, 0, "Maximum TOE retransmit interval (us)");
341 /* 0 means chip/fw default, non-zero number is # of rexmt before abort */
342 static int t4_toe_rexmt_count = 0;
343 SYSCTL_INT(_hw_cxgbe_toe, OID_AUTO, rexmt_count, CTLFLAG_RDTUN,
344 &t4_toe_rexmt_count, 0, "Number of TOE retransmissions before abort");
346 /* -1 means chip/fw default, other values are raw backoff values to use */
347 static int t4_toe_rexmt_backoff[16] = {
348 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
350 SYSCTL_NODE(_hw_cxgbe_toe, OID_AUTO, rexmt_backoff, CTLFLAG_RD, 0,
351 "cxgbe(4) TOE retransmit backoff values");
352 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 0, CTLFLAG_RDTUN,
353 &t4_toe_rexmt_backoff[0], 0, "");
354 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 1, CTLFLAG_RDTUN,
355 &t4_toe_rexmt_backoff[1], 0, "");
356 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 2, CTLFLAG_RDTUN,
357 &t4_toe_rexmt_backoff[2], 0, "");
358 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 3, CTLFLAG_RDTUN,
359 &t4_toe_rexmt_backoff[3], 0, "");
360 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 4, CTLFLAG_RDTUN,
361 &t4_toe_rexmt_backoff[4], 0, "");
362 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 5, CTLFLAG_RDTUN,
363 &t4_toe_rexmt_backoff[5], 0, "");
364 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 6, CTLFLAG_RDTUN,
365 &t4_toe_rexmt_backoff[6], 0, "");
366 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 7, CTLFLAG_RDTUN,
367 &t4_toe_rexmt_backoff[7], 0, "");
368 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 8, CTLFLAG_RDTUN,
369 &t4_toe_rexmt_backoff[8], 0, "");
370 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 9, CTLFLAG_RDTUN,
371 &t4_toe_rexmt_backoff[9], 0, "");
372 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 10, CTLFLAG_RDTUN,
373 &t4_toe_rexmt_backoff[10], 0, "");
374 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 11, CTLFLAG_RDTUN,
375 &t4_toe_rexmt_backoff[11], 0, "");
376 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 12, CTLFLAG_RDTUN,
377 &t4_toe_rexmt_backoff[12], 0, "");
378 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 13, CTLFLAG_RDTUN,
379 &t4_toe_rexmt_backoff[13], 0, "");
380 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 14, CTLFLAG_RDTUN,
381 &t4_toe_rexmt_backoff[14], 0, "");
382 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 15, CTLFLAG_RDTUN,
383 &t4_toe_rexmt_backoff[15], 0, "");
388 static int t4_nnmtxq_vi = -NNMTXQ_VI;
389 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nnmtxq_vi, CTLFLAG_RDTUN, &t4_nnmtxq_vi, 0,
390 "Number of netmap TX queues per VI");
393 static int t4_nnmrxq_vi = -NNMRXQ_VI;
394 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nnmrxq_vi, CTLFLAG_RDTUN, &t4_nnmrxq_vi, 0,
395 "Number of netmap RX queues per VI");
399 * Holdoff parameters for ports.
402 int t4_tmr_idx = TMR_IDX;
403 SYSCTL_INT(_hw_cxgbe, OID_AUTO, holdoff_timer_idx, CTLFLAG_RDTUN, &t4_tmr_idx,
404 0, "Holdoff timer index");
405 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_10G", &t4_tmr_idx); /* Old name */
407 #define PKTC_IDX (-1)
408 int t4_pktc_idx = PKTC_IDX;
409 SYSCTL_INT(_hw_cxgbe, OID_AUTO, holdoff_pktc_idx, CTLFLAG_RDTUN, &t4_pktc_idx,
410 0, "Holdoff packet counter index");
411 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_10G", &t4_pktc_idx); /* Old name */
414 * Size (# of entries) of each tx and rx queue.
416 unsigned int t4_qsize_txq = TX_EQ_QSIZE;
417 SYSCTL_INT(_hw_cxgbe, OID_AUTO, qsize_txq, CTLFLAG_RDTUN, &t4_qsize_txq, 0,
418 "Number of descriptors in each TX queue");
420 unsigned int t4_qsize_rxq = RX_IQ_QSIZE;
421 SYSCTL_INT(_hw_cxgbe, OID_AUTO, qsize_rxq, CTLFLAG_RDTUN, &t4_qsize_rxq, 0,
422 "Number of descriptors in each RX queue");
425 * Interrupt types allowed (bits 0, 1, 2 = INTx, MSI, MSI-X respectively).
427 int t4_intr_types = INTR_MSIX | INTR_MSI | INTR_INTX;
428 SYSCTL_INT(_hw_cxgbe, OID_AUTO, interrupt_types, CTLFLAG_RDTUN, &t4_intr_types,
429 0, "Interrupt types allowed (bit 0 = INTx, 1 = MSI, 2 = MSI-X)");
432 * Configuration file. All the _CF names here are special.
434 #define DEFAULT_CF "default"
435 #define BUILTIN_CF "built-in"
436 #define FLASH_CF "flash"
437 #define UWIRE_CF "uwire"
438 #define FPGA_CF "fpga"
439 static char t4_cfg_file[32] = DEFAULT_CF;
440 SYSCTL_STRING(_hw_cxgbe, OID_AUTO, config_file, CTLFLAG_RDTUN, t4_cfg_file,
441 sizeof(t4_cfg_file), "Firmware configuration file");
444 * PAUSE settings (bit 0, 1, 2 = rx_pause, tx_pause, pause_autoneg respectively).
445 * rx_pause = 1 to heed incoming PAUSE frames, 0 to ignore them.
446 * tx_pause = 1 to emit PAUSE frames when the rx FIFO reaches its high water
447 * mark or when signalled to do so, 0 to never emit PAUSE.
448 * pause_autoneg = 1 means PAUSE will be negotiated if possible and the
449 * negotiated settings will override rx_pause/tx_pause.
450 * Otherwise rx_pause/tx_pause are applied forcibly.
452 static int t4_pause_settings = PAUSE_RX | PAUSE_TX | PAUSE_AUTONEG;
453 SYSCTL_INT(_hw_cxgbe, OID_AUTO, pause_settings, CTLFLAG_RDTUN,
454 &t4_pause_settings, 0,
455 "PAUSE settings (bit 0 = rx_pause, 1 = tx_pause, 2 = pause_autoneg)");
458 * Forward Error Correction settings (bit 0, 1 = RS, BASER respectively).
459 * -1 to run with the firmware default. Same as FEC_AUTO (bit 5)
462 static int t4_fec = -1;
463 SYSCTL_INT(_hw_cxgbe, OID_AUTO, fec, CTLFLAG_RDTUN, &t4_fec, 0,
464 "Forward Error Correction (bit 0 = RS, bit 1 = BASER_RS)");
467 * Link autonegotiation.
468 * -1 to run with the firmware default.
472 static int t4_autoneg = -1;
473 SYSCTL_INT(_hw_cxgbe, OID_AUTO, autoneg, CTLFLAG_RDTUN, &t4_autoneg, 0,
474 "Link autonegotiation");
477 * Firmware auto-install by driver during attach (0, 1, 2 = prohibited, allowed,
478 * encouraged respectively).
480 static unsigned int t4_fw_install = 1;
481 SYSCTL_INT(_hw_cxgbe, OID_AUTO, fw_install, CTLFLAG_RDTUN, &t4_fw_install, 0,
482 "Firmware auto-install (0 = prohibited, 1 = allowed, 2 = encouraged)");
485 * ASIC features that will be used. Disable the ones you don't want so that the
486 * chip resources aren't wasted on features that will not be used.
488 static int t4_nbmcaps_allowed = 0;
489 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nbmcaps_allowed, CTLFLAG_RDTUN,
490 &t4_nbmcaps_allowed, 0, "Default NBM capabilities");
492 static int t4_linkcaps_allowed = 0; /* No DCBX, PPP, etc. by default */
493 SYSCTL_INT(_hw_cxgbe, OID_AUTO, linkcaps_allowed, CTLFLAG_RDTUN,
494 &t4_linkcaps_allowed, 0, "Default link capabilities");
496 static int t4_switchcaps_allowed = FW_CAPS_CONFIG_SWITCH_INGRESS |
497 FW_CAPS_CONFIG_SWITCH_EGRESS;
498 SYSCTL_INT(_hw_cxgbe, OID_AUTO, switchcaps_allowed, CTLFLAG_RDTUN,
499 &t4_switchcaps_allowed, 0, "Default switch capabilities");
501 static int t4_niccaps_allowed = FW_CAPS_CONFIG_NIC;
502 SYSCTL_INT(_hw_cxgbe, OID_AUTO, niccaps_allowed, CTLFLAG_RDTUN,
503 &t4_niccaps_allowed, 0, "Default NIC capabilities");
505 static int t4_toecaps_allowed = -1;
506 SYSCTL_INT(_hw_cxgbe, OID_AUTO, toecaps_allowed, CTLFLAG_RDTUN,
507 &t4_toecaps_allowed, 0, "Default TCP offload capabilities");
509 static int t4_rdmacaps_allowed = -1;
510 SYSCTL_INT(_hw_cxgbe, OID_AUTO, rdmacaps_allowed, CTLFLAG_RDTUN,
511 &t4_rdmacaps_allowed, 0, "Default RDMA capabilities");
513 static int t4_cryptocaps_allowed = -1;
514 SYSCTL_INT(_hw_cxgbe, OID_AUTO, cryptocaps_allowed, CTLFLAG_RDTUN,
515 &t4_cryptocaps_allowed, 0, "Default crypto capabilities");
517 static int t4_iscsicaps_allowed = -1;
518 SYSCTL_INT(_hw_cxgbe, OID_AUTO, iscsicaps_allowed, CTLFLAG_RDTUN,
519 &t4_iscsicaps_allowed, 0, "Default iSCSI capabilities");
521 static int t4_fcoecaps_allowed = 0;
522 SYSCTL_INT(_hw_cxgbe, OID_AUTO, fcoecaps_allowed, CTLFLAG_RDTUN,
523 &t4_fcoecaps_allowed, 0, "Default FCoE capabilities");
525 static int t5_write_combine = 0;
526 SYSCTL_INT(_hw_cxl, OID_AUTO, write_combine, CTLFLAG_RDTUN, &t5_write_combine,
527 0, "Use WC instead of UC for BAR2");
529 static int t4_num_vis = 1;
530 SYSCTL_INT(_hw_cxgbe, OID_AUTO, num_vis, CTLFLAG_RDTUN, &t4_num_vis, 0,
531 "Number of VIs per port");
534 * PCIe Relaxed Ordering.
535 * -1: driver should figure out a good value.
540 static int pcie_relaxed_ordering = -1;
541 SYSCTL_INT(_hw_cxgbe, OID_AUTO, pcie_relaxed_ordering, CTLFLAG_RDTUN,
542 &pcie_relaxed_ordering, 0,
543 "PCIe Relaxed Ordering: 0 = disable, 1 = enable, 2 = leave alone");
550 static int t4_cop_managed_offloading = 0;
551 TUNABLE_INT("hw.cxgbe.cop_managed_offloading", &t4_cop_managed_offloading);
554 /* Functions used by VIs to obtain unique MAC addresses for each VI. */
555 static int vi_mac_funcs[] = {
559 FW_VI_FUNC_OPENISCSI,
565 struct intrs_and_queues {
566 uint16_t intr_type; /* INTx, MSI, or MSI-X */
567 uint16_t num_vis; /* number of VIs for each port */
568 uint16_t nirq; /* Total # of vectors */
569 uint16_t ntxq; /* # of NIC txq's for each port */
570 uint16_t nrxq; /* # of NIC rxq's for each port */
571 uint16_t nofldtxq; /* # of TOE txq's for each port */
572 uint16_t nofldrxq; /* # of TOE rxq's for each port */
574 /* The vcxgbe/vcxl interfaces use these and not the ones above. */
575 uint16_t ntxq_vi; /* # of NIC txq's */
576 uint16_t nrxq_vi; /* # of NIC rxq's */
577 uint16_t nofldtxq_vi; /* # of TOE txq's */
578 uint16_t nofldrxq_vi; /* # of TOE rxq's */
579 uint16_t nnmtxq_vi; /* # of netmap txq's */
580 uint16_t nnmrxq_vi; /* # of netmap rxq's */
583 struct filter_entry {
584 uint32_t valid:1; /* filter allocated and valid */
585 uint32_t locked:1; /* filter is administratively locked */
586 uint32_t pending:1; /* filter action is pending firmware reply */
587 uint32_t smtidx:8; /* Source MAC Table index for smac */
588 struct l2t_entry *l2t; /* Layer Two Table entry for dmac */
590 struct t4_filter_specification fs;
593 static void setup_memwin(struct adapter *);
594 static void position_memwin(struct adapter *, int, uint32_t);
595 static int rw_via_memwin(struct adapter *, int, uint32_t, uint32_t *, int, int);
596 static inline int read_via_memwin(struct adapter *, int, uint32_t, uint32_t *,
598 static inline int write_via_memwin(struct adapter *, int, uint32_t,
599 const uint32_t *, int);
600 static int validate_mem_range(struct adapter *, uint32_t, uint32_t);
601 static int fwmtype_to_hwmtype(int);
602 static int validate_mt_off_len(struct adapter *, int, uint32_t, uint32_t,
604 static int fixup_devlog_params(struct adapter *);
605 static int cfg_itype_and_nqueues(struct adapter *, struct intrs_and_queues *);
606 static int prep_firmware(struct adapter *);
607 static int partition_resources(struct adapter *, const struct firmware *,
609 static int get_params__pre_init(struct adapter *);
610 static int get_params__post_init(struct adapter *);
611 static int set_params__post_init(struct adapter *);
612 static void t4_set_desc(struct adapter *);
613 static bool fixed_ifmedia(struct port_info *);
614 static void build_medialist(struct port_info *);
615 static void init_link_config(struct port_info *);
616 static int fixup_link_config(struct port_info *);
617 static int apply_link_config(struct port_info *);
618 static int cxgbe_init_synchronized(struct vi_info *);
619 static int cxgbe_uninit_synchronized(struct vi_info *);
620 static void quiesce_txq(struct adapter *, struct sge_txq *);
621 static void quiesce_wrq(struct adapter *, struct sge_wrq *);
622 static void quiesce_iq(struct adapter *, struct sge_iq *);
623 static void quiesce_fl(struct adapter *, struct sge_fl *);
624 static int t4_alloc_irq(struct adapter *, struct irq *, int rid,
625 driver_intr_t *, void *, char *);
626 static int t4_free_irq(struct adapter *, struct irq *);
627 static void get_regs(struct adapter *, struct t4_regdump *, uint8_t *);
628 static void vi_refresh_stats(struct adapter *, struct vi_info *);
629 static void cxgbe_refresh_stats(struct adapter *, struct port_info *);
630 static void cxgbe_tick(void *);
631 static void cxgbe_vlan_config(void *, struct ifnet *, uint16_t);
632 static void cxgbe_sysctls(struct port_info *);
633 static int sysctl_int_array(SYSCTL_HANDLER_ARGS);
634 static int sysctl_bitfield(SYSCTL_HANDLER_ARGS);
635 static int sysctl_btphy(SYSCTL_HANDLER_ARGS);
636 static int sysctl_noflowq(SYSCTL_HANDLER_ARGS);
637 static int sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS);
638 static int sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS);
639 static int sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS);
640 static int sysctl_qsize_txq(SYSCTL_HANDLER_ARGS);
641 static int sysctl_pause_settings(SYSCTL_HANDLER_ARGS);
642 static int sysctl_fec(SYSCTL_HANDLER_ARGS);
643 static int sysctl_autoneg(SYSCTL_HANDLER_ARGS);
644 static int sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS);
645 static int sysctl_temperature(SYSCTL_HANDLER_ARGS);
647 static int sysctl_loadavg(SYSCTL_HANDLER_ARGS);
648 static int sysctl_cctrl(SYSCTL_HANDLER_ARGS);
649 static int sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS);
650 static int sysctl_cim_la(SYSCTL_HANDLER_ARGS);
651 static int sysctl_cim_la_t6(SYSCTL_HANDLER_ARGS);
652 static int sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS);
653 static int sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS);
654 static int sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS);
655 static int sysctl_cpl_stats(SYSCTL_HANDLER_ARGS);
656 static int sysctl_ddp_stats(SYSCTL_HANDLER_ARGS);
657 static int sysctl_devlog(SYSCTL_HANDLER_ARGS);
658 static int sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS);
659 static int sysctl_hw_sched(SYSCTL_HANDLER_ARGS);
660 static int sysctl_lb_stats(SYSCTL_HANDLER_ARGS);
661 static int sysctl_linkdnrc(SYSCTL_HANDLER_ARGS);
662 static int sysctl_meminfo(SYSCTL_HANDLER_ARGS);
663 static int sysctl_mps_tcam(SYSCTL_HANDLER_ARGS);
664 static int sysctl_mps_tcam_t6(SYSCTL_HANDLER_ARGS);
665 static int sysctl_path_mtus(SYSCTL_HANDLER_ARGS);
666 static int sysctl_pm_stats(SYSCTL_HANDLER_ARGS);
667 static int sysctl_rdma_stats(SYSCTL_HANDLER_ARGS);
668 static int sysctl_tcp_stats(SYSCTL_HANDLER_ARGS);
669 static int sysctl_tids(SYSCTL_HANDLER_ARGS);
670 static int sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS);
671 static int sysctl_tp_la_mask(SYSCTL_HANDLER_ARGS);
672 static int sysctl_tp_la(SYSCTL_HANDLER_ARGS);
673 static int sysctl_tx_rate(SYSCTL_HANDLER_ARGS);
674 static int sysctl_ulprx_la(SYSCTL_HANDLER_ARGS);
675 static int sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS);
676 static int sysctl_tc_params(SYSCTL_HANDLER_ARGS);
679 static int sysctl_tls_rx_ports(SYSCTL_HANDLER_ARGS);
680 static int sysctl_tp_tick(SYSCTL_HANDLER_ARGS);
681 static int sysctl_tp_dack_timer(SYSCTL_HANDLER_ARGS);
682 static int sysctl_tp_timer(SYSCTL_HANDLER_ARGS);
683 static int sysctl_tp_shift_cnt(SYSCTL_HANDLER_ARGS);
684 static int sysctl_tp_backoff(SYSCTL_HANDLER_ARGS);
685 static int sysctl_holdoff_tmr_idx_ofld(SYSCTL_HANDLER_ARGS);
686 static int sysctl_holdoff_pktc_idx_ofld(SYSCTL_HANDLER_ARGS);
688 static uint32_t fconf_iconf_to_mode(uint32_t, uint32_t);
689 static uint32_t mode_to_fconf(uint32_t);
690 static uint32_t mode_to_iconf(uint32_t);
691 static int check_fspec_against_fconf_iconf(struct adapter *,
692 struct t4_filter_specification *);
693 static int get_filter_mode(struct adapter *, uint32_t *);
694 static int set_filter_mode(struct adapter *, uint32_t);
695 static inline uint64_t get_filter_hits(struct adapter *, uint32_t);
696 static int get_filter(struct adapter *, struct t4_filter *);
697 static int set_filter(struct adapter *, struct t4_filter *);
698 static int del_filter(struct adapter *, struct t4_filter *);
699 static void clear_filter(struct filter_entry *);
700 static int set_filter_wr(struct adapter *, int);
701 static int del_filter_wr(struct adapter *, int);
702 static int set_tcb_rpl(struct sge_iq *, const struct rss_header *,
704 static int get_sge_context(struct adapter *, struct t4_sge_context *);
705 static int load_fw(struct adapter *, struct t4_data *);
706 static int load_cfg(struct adapter *, struct t4_data *);
707 static int load_boot(struct adapter *, struct t4_bootrom *);
708 static int load_bootcfg(struct adapter *, struct t4_data *);
709 static int cudbg_dump(struct adapter *, struct t4_cudbg_dump *);
710 static void free_offload_policy(struct t4_offload_policy *);
711 static int set_offload_policy(struct adapter *, struct t4_offload_policy *);
712 static int read_card_mem(struct adapter *, int, struct t4_mem_range *);
713 static int read_i2c(struct adapter *, struct t4_i2c_data *);
715 static int toe_capability(struct vi_info *, int);
717 static int mod_event(module_t, int, void *);
718 static int notify_siblings(device_t, int);
724 {0xa000, "Chelsio Terminator 4 FPGA"},
725 {0x4400, "Chelsio T440-dbg"},
726 {0x4401, "Chelsio T420-CR"},
727 {0x4402, "Chelsio T422-CR"},
728 {0x4403, "Chelsio T440-CR"},
729 {0x4404, "Chelsio T420-BCH"},
730 {0x4405, "Chelsio T440-BCH"},
731 {0x4406, "Chelsio T440-CH"},
732 {0x4407, "Chelsio T420-SO"},
733 {0x4408, "Chelsio T420-CX"},
734 {0x4409, "Chelsio T420-BT"},
735 {0x440a, "Chelsio T404-BT"},
736 {0x440e, "Chelsio T440-LP-CR"},
738 {0xb000, "Chelsio Terminator 5 FPGA"},
739 {0x5400, "Chelsio T580-dbg"},
740 {0x5401, "Chelsio T520-CR"}, /* 2 x 10G */
741 {0x5402, "Chelsio T522-CR"}, /* 2 x 10G, 2 X 1G */
742 {0x5403, "Chelsio T540-CR"}, /* 4 x 10G */
743 {0x5407, "Chelsio T520-SO"}, /* 2 x 10G, nomem */
744 {0x5409, "Chelsio T520-BT"}, /* 2 x 10GBaseT */
745 {0x540a, "Chelsio T504-BT"}, /* 4 x 1G */
746 {0x540d, "Chelsio T580-CR"}, /* 2 x 40G */
747 {0x540e, "Chelsio T540-LP-CR"}, /* 4 x 10G */
748 {0x5410, "Chelsio T580-LP-CR"}, /* 2 x 40G */
749 {0x5411, "Chelsio T520-LL-CR"}, /* 2 x 10G */
750 {0x5412, "Chelsio T560-CR"}, /* 1 x 40G, 2 x 10G */
751 {0x5414, "Chelsio T580-LP-SO-CR"}, /* 2 x 40G, nomem */
752 {0x5415, "Chelsio T502-BT"}, /* 2 x 1G */
753 {0x5418, "Chelsio T540-BT"}, /* 4 x 10GBaseT */
754 {0x5419, "Chelsio T540-LP-BT"}, /* 4 x 10GBaseT */
755 {0x541a, "Chelsio T540-SO-BT"}, /* 4 x 10GBaseT, nomem */
756 {0x541b, "Chelsio T540-SO-CR"}, /* 4 x 10G, nomem */
759 {0x5483, "Custom T540-CR"},
760 {0x5484, "Custom T540-BT"},
762 {0xc006, "Chelsio Terminator 6 FPGA"}, /* T6 PE10K6 FPGA (PF0) */
763 {0x6400, "Chelsio T6-DBG-25"}, /* 2 x 10/25G, debug */
764 {0x6401, "Chelsio T6225-CR"}, /* 2 x 10/25G */
765 {0x6402, "Chelsio T6225-SO-CR"}, /* 2 x 10/25G, nomem */
766 {0x6403, "Chelsio T6425-CR"}, /* 4 x 10/25G */
767 {0x6404, "Chelsio T6425-SO-CR"}, /* 4 x 10/25G, nomem */
768 {0x6405, "Chelsio T6225-OCP-SO"}, /* 2 x 10/25G, nomem */
769 {0x6406, "Chelsio T62100-OCP-SO"}, /* 2 x 40/50/100G, nomem */
770 {0x6407, "Chelsio T62100-LP-CR"}, /* 2 x 40/50/100G */
771 {0x6408, "Chelsio T62100-SO-CR"}, /* 2 x 40/50/100G, nomem */
772 {0x6409, "Chelsio T6210-BT"}, /* 2 x 10GBASE-T */
773 {0x640d, "Chelsio T62100-CR"}, /* 2 x 40/50/100G */
774 {0x6410, "Chelsio T6-DBG-100"}, /* 2 x 40/50/100G, debug */
775 {0x6411, "Chelsio T6225-LL-CR"}, /* 2 x 10/25G */
776 {0x6414, "Chelsio T61100-OCP-SO"}, /* 1 x 40/50/100G, nomem */
777 {0x6415, "Chelsio T6201-BT"}, /* 2 x 1000BASE-T */
780 {0x6480, "Custom T6225-CR"},
781 {0x6481, "Custom T62100-CR"},
782 {0x6482, "Custom T6225-CR"},
783 {0x6483, "Custom T62100-CR"},
784 {0x6484, "Custom T64100-CR"},
785 {0x6485, "Custom T6240-SO"},
786 {0x6486, "Custom T6225-SO-CR"},
787 {0x6487, "Custom T6225-CR"},
792 * service_iq() has an iq and needs the fl. Offset of fl from the iq should be
793 * exactly the same for both rxq and ofld_rxq.
795 CTASSERT(offsetof(struct sge_ofld_rxq, iq) == offsetof(struct sge_rxq, iq));
796 CTASSERT(offsetof(struct sge_ofld_rxq, fl) == offsetof(struct sge_rxq, fl));
798 CTASSERT(sizeof(struct cluster_metadata) <= CL_METADATA_SIZE);
801 t4_probe(device_t dev)
804 uint16_t v = pci_get_vendor(dev);
805 uint16_t d = pci_get_device(dev);
806 uint8_t f = pci_get_function(dev);
808 if (v != PCI_VENDOR_ID_CHELSIO)
811 /* Attach only to PF0 of the FPGA */
812 if (d == 0xa000 && f != 0)
815 for (i = 0; i < nitems(t4_pciids); i++) {
816 if (d == t4_pciids[i].device) {
817 device_set_desc(dev, t4_pciids[i].desc);
818 return (BUS_PROBE_DEFAULT);
826 t5_probe(device_t dev)
829 uint16_t v = pci_get_vendor(dev);
830 uint16_t d = pci_get_device(dev);
831 uint8_t f = pci_get_function(dev);
833 if (v != PCI_VENDOR_ID_CHELSIO)
836 /* Attach only to PF0 of the FPGA */
837 if (d == 0xb000 && f != 0)
840 for (i = 0; i < nitems(t5_pciids); i++) {
841 if (d == t5_pciids[i].device) {
842 device_set_desc(dev, t5_pciids[i].desc);
843 return (BUS_PROBE_DEFAULT);
851 t6_probe(device_t dev)
854 uint16_t v = pci_get_vendor(dev);
855 uint16_t d = pci_get_device(dev);
857 if (v != PCI_VENDOR_ID_CHELSIO)
860 for (i = 0; i < nitems(t6_pciids); i++) {
861 if (d == t6_pciids[i].device) {
862 device_set_desc(dev, t6_pciids[i].desc);
863 return (BUS_PROBE_DEFAULT);
871 t5_attribute_workaround(device_t dev)
877 * The T5 chips do not properly echo the No Snoop and Relaxed
878 * Ordering attributes when replying to a TLP from a Root
879 * Port. As a workaround, find the parent Root Port and
880 * disable No Snoop and Relaxed Ordering. Note that this
881 * affects all devices under this root port.
883 root_port = pci_find_pcie_root_port(dev);
884 if (root_port == NULL) {
885 device_printf(dev, "Unable to find parent root port\n");
889 v = pcie_adjust_config(root_port, PCIER_DEVICE_CTL,
890 PCIEM_CTL_RELAXED_ORD_ENABLE | PCIEM_CTL_NOSNOOP_ENABLE, 0, 2);
891 if ((v & (PCIEM_CTL_RELAXED_ORD_ENABLE | PCIEM_CTL_NOSNOOP_ENABLE)) !=
893 device_printf(dev, "Disabled No Snoop/Relaxed Ordering on %s\n",
894 device_get_nameunit(root_port));
897 static const struct devnames devnames[] = {
899 .nexus_name = "t4nex",
900 .ifnet_name = "cxgbe",
901 .vi_ifnet_name = "vcxgbe",
902 .pf03_drv_name = "t4iov",
903 .vf_nexus_name = "t4vf",
904 .vf_ifnet_name = "cxgbev"
906 .nexus_name = "t5nex",
908 .vi_ifnet_name = "vcxl",
909 .pf03_drv_name = "t5iov",
910 .vf_nexus_name = "t5vf",
911 .vf_ifnet_name = "cxlv"
913 .nexus_name = "t6nex",
915 .vi_ifnet_name = "vcc",
916 .pf03_drv_name = "t6iov",
917 .vf_nexus_name = "t6vf",
918 .vf_ifnet_name = "ccv"
923 t4_init_devnames(struct adapter *sc)
928 if (id >= CHELSIO_T4 && id - CHELSIO_T4 < nitems(devnames))
929 sc->names = &devnames[id - CHELSIO_T4];
931 device_printf(sc->dev, "chip id %d is not supported.\n", id);
937 t4_ifnet_unit(struct adapter *sc, struct port_info *pi)
939 const char *parent, *name;
944 parent = device_get_nameunit(sc->dev);
945 name = sc->names->ifnet_name;
946 while (resource_find_dev(&line, name, &unit, "at", parent) == 0) {
947 if (resource_long_value(name, unit, "port", &value) == 0 &&
948 value == pi->port_id)
955 t4_attach(device_t dev)
958 int rc = 0, i, j, rqidx, tqidx, nports;
959 struct make_dev_args mda;
960 struct intrs_and_queues iaq;
964 int ofld_rqidx, ofld_tqidx;
967 int nm_rqidx, nm_tqidx;
971 sc = device_get_softc(dev);
973 TUNABLE_INT_FETCH("hw.cxgbe.dflags", &sc->debug_flags);
975 if ((pci_get_device(dev) & 0xff00) == 0x5400)
976 t5_attribute_workaround(dev);
977 pci_enable_busmaster(dev);
978 if (pci_find_cap(dev, PCIY_EXPRESS, &i) == 0) {
981 pci_set_max_read_req(dev, 4096);
982 v = pci_read_config(dev, i + PCIER_DEVICE_CTL, 2);
983 sc->params.pci.mps = 128 << ((v & PCIEM_CTL_MAX_PAYLOAD) >> 5);
984 if (pcie_relaxed_ordering == 0 &&
985 (v | PCIEM_CTL_RELAXED_ORD_ENABLE) != 0) {
986 v &= ~PCIEM_CTL_RELAXED_ORD_ENABLE;
987 pci_write_config(dev, i + PCIER_DEVICE_CTL, v, 2);
988 } else if (pcie_relaxed_ordering == 1 &&
989 (v & PCIEM_CTL_RELAXED_ORD_ENABLE) == 0) {
990 v |= PCIEM_CTL_RELAXED_ORD_ENABLE;
991 pci_write_config(dev, i + PCIER_DEVICE_CTL, v, 2);
995 sc->sge_gts_reg = MYPF_REG(A_SGE_PF_GTS);
996 sc->sge_kdoorbell_reg = MYPF_REG(A_SGE_PF_KDOORBELL);
998 mtx_init(&sc->ifp_lock, sc->ifp_lockname, 0, MTX_DEF);
999 snprintf(sc->ifp_lockname, sizeof(sc->ifp_lockname), "%s tracer",
1000 device_get_nameunit(dev));
1002 snprintf(sc->lockname, sizeof(sc->lockname), "%s",
1003 device_get_nameunit(dev));
1004 mtx_init(&sc->sc_lock, sc->lockname, 0, MTX_DEF);
1007 mtx_init(&sc->sfl_lock, "starving freelists", 0, MTX_DEF);
1008 TAILQ_INIT(&sc->sfl);
1009 callout_init_mtx(&sc->sfl_callout, &sc->sfl_lock, 0);
1011 mtx_init(&sc->reg_lock, "indirect register access", 0, MTX_DEF);
1014 rw_init(&sc->policy_lock, "connection offload policy");
1016 rc = t4_map_bars_0_and_4(sc);
1018 goto done; /* error message displayed already */
1020 memset(sc->chan_map, 0xff, sizeof(sc->chan_map));
1022 /* Prepare the adapter for operation. */
1023 buf = malloc(PAGE_SIZE, M_CXGBE, M_ZERO | M_WAITOK);
1024 rc = -t4_prep_adapter(sc, buf);
1027 device_printf(dev, "failed to prepare adapter: %d.\n", rc);
1032 * This is the real PF# to which we're attaching. Works from within PCI
1033 * passthrough environments too, where pci_get_function() could return a
1034 * different PF# depending on the passthrough configuration. We need to
1035 * use the real PF# in all our communication with the firmware.
1037 j = t4_read_reg(sc, A_PL_WHOAMI);
1038 sc->pf = chip_id(sc) <= CHELSIO_T5 ? G_SOURCEPF(j) : G_T6_SOURCEPF(j);
1041 t4_init_devnames(sc);
1042 if (sc->names == NULL) {
1044 goto done; /* error message displayed already */
1048 * Do this really early, with the memory windows set up even before the
1049 * character device. The userland tool's register i/o and mem read
1050 * will work even in "recovery mode".
1053 if (t4_init_devlog_params(sc, 0) == 0)
1054 fixup_devlog_params(sc);
1055 make_dev_args_init(&mda);
1056 mda.mda_devsw = &t4_cdevsw;
1057 mda.mda_uid = UID_ROOT;
1058 mda.mda_gid = GID_WHEEL;
1059 mda.mda_mode = 0600;
1060 mda.mda_si_drv1 = sc;
1061 rc = make_dev_s(&mda, &sc->cdev, "%s", device_get_nameunit(dev));
1063 device_printf(dev, "failed to create nexus char device: %d.\n",
1066 /* Go no further if recovery mode has been requested. */
1067 if (TUNABLE_INT_FETCH("hw.cxgbe.sos", &i) && i != 0) {
1068 device_printf(dev, "recovery mode.\n");
1072 #if defined(__i386__)
1073 if ((cpu_feature & CPUID_CX8) == 0) {
1074 device_printf(dev, "64 bit atomics not available.\n");
1080 /* Prepare the firmware for operation */
1081 rc = prep_firmware(sc);
1083 goto done; /* error message displayed already */
1085 rc = get_params__post_init(sc);
1087 goto done; /* error message displayed already */
1089 rc = set_params__post_init(sc);
1091 goto done; /* error message displayed already */
1093 rc = t4_map_bar_2(sc);
1095 goto done; /* error message displayed already */
1097 rc = t4_create_dma_tag(sc);
1099 goto done; /* error message displayed already */
1102 * First pass over all the ports - allocate VIs and initialize some
1103 * basic parameters like mac address, port type, etc.
1105 for_each_port(sc, i) {
1106 struct port_info *pi;
1108 pi = malloc(sizeof(*pi), M_CXGBE, M_ZERO | M_WAITOK);
1111 /* These must be set before t4_port_init */
1115 * XXX: vi[0] is special so we can't delay this allocation until
1116 * pi->nvi's final value is known.
1118 pi->vi = malloc(sizeof(struct vi_info) * t4_num_vis, M_CXGBE,
1122 * Allocate the "main" VI and initialize parameters
1125 rc = -t4_port_init(sc, sc->mbox, sc->pf, 0, i);
1127 device_printf(dev, "unable to initialize port %d: %d\n",
1129 free(pi->vi, M_CXGBE);
1135 snprintf(pi->lockname, sizeof(pi->lockname), "%sp%d",
1136 device_get_nameunit(dev), i);
1137 mtx_init(&pi->pi_lock, pi->lockname, 0, MTX_DEF);
1138 sc->chan_map[pi->tx_chan] = i;
1140 /* All VIs on this port share this media. */
1141 ifmedia_init(&pi->media, IFM_IMASK, cxgbe_media_change,
1142 cxgbe_media_status);
1145 init_link_config(pi);
1146 fixup_link_config(pi);
1147 build_medialist(pi);
1148 if (fixed_ifmedia(pi))
1149 pi->flags |= FIXED_IFMEDIA;
1152 pi->dev = device_add_child(dev, sc->names->ifnet_name,
1153 t4_ifnet_unit(sc, pi));
1154 if (pi->dev == NULL) {
1156 "failed to add device for port %d.\n", i);
1160 pi->vi[0].dev = pi->dev;
1161 device_set_softc(pi->dev, pi);
1165 * Interrupt type, # of interrupts, # of rx/tx queues, etc.
1167 nports = sc->params.nports;
1168 rc = cfg_itype_and_nqueues(sc, &iaq);
1170 goto done; /* error message displayed already */
1172 num_vis = iaq.num_vis;
1173 sc->intr_type = iaq.intr_type;
1174 sc->intr_count = iaq.nirq;
1177 s->nrxq = nports * iaq.nrxq;
1178 s->ntxq = nports * iaq.ntxq;
1180 s->nrxq += nports * (num_vis - 1) * iaq.nrxq_vi;
1181 s->ntxq += nports * (num_vis - 1) * iaq.ntxq_vi;
1183 s->neq = s->ntxq + s->nrxq; /* the free list in an rxq is an eq */
1184 s->neq += nports + 1;/* ctrl queues: 1 per port + 1 mgmt */
1185 s->niq = s->nrxq + 1; /* 1 extra for firmware event queue */
1187 if (is_offload(sc)) {
1188 s->nofldrxq = nports * iaq.nofldrxq;
1189 s->nofldtxq = nports * iaq.nofldtxq;
1191 s->nofldrxq += nports * (num_vis - 1) * iaq.nofldrxq_vi;
1192 s->nofldtxq += nports * (num_vis - 1) * iaq.nofldtxq_vi;
1194 s->neq += s->nofldtxq + s->nofldrxq;
1195 s->niq += s->nofldrxq;
1197 s->ofld_rxq = malloc(s->nofldrxq * sizeof(struct sge_ofld_rxq),
1198 M_CXGBE, M_ZERO | M_WAITOK);
1199 s->ofld_txq = malloc(s->nofldtxq * sizeof(struct sge_wrq),
1200 M_CXGBE, M_ZERO | M_WAITOK);
1205 s->nnmrxq = nports * (num_vis - 1) * iaq.nnmrxq_vi;
1206 s->nnmtxq = nports * (num_vis - 1) * iaq.nnmtxq_vi;
1208 s->neq += s->nnmtxq + s->nnmrxq;
1209 s->niq += s->nnmrxq;
1211 s->nm_rxq = malloc(s->nnmrxq * sizeof(struct sge_nm_rxq),
1212 M_CXGBE, M_ZERO | M_WAITOK);
1213 s->nm_txq = malloc(s->nnmtxq * sizeof(struct sge_nm_txq),
1214 M_CXGBE, M_ZERO | M_WAITOK);
1217 s->ctrlq = malloc(nports * sizeof(struct sge_wrq), M_CXGBE,
1219 s->rxq = malloc(s->nrxq * sizeof(struct sge_rxq), M_CXGBE,
1221 s->txq = malloc(s->ntxq * sizeof(struct sge_txq), M_CXGBE,
1223 s->iqmap = malloc(s->niq * sizeof(struct sge_iq *), M_CXGBE,
1225 s->eqmap = malloc(s->neq * sizeof(struct sge_eq *), M_CXGBE,
1228 sc->irq = malloc(sc->intr_count * sizeof(struct irq), M_CXGBE,
1231 t4_init_l2t(sc, M_WAITOK);
1232 t4_init_tx_sched(sc);
1233 if (sc->vres.key.size != 0)
1234 sc->key_map = vmem_create("T4TLS key map", sc->vres.key.start,
1235 sc->vres.key.size, 32, 0, M_FIRSTFIT | M_WAITOK);
1238 * Second pass over the ports. This time we know the number of rx and
1239 * tx queues that each port should get.
1243 ofld_rqidx = ofld_tqidx = 0;
1246 nm_rqidx = nm_tqidx = 0;
1248 for_each_port(sc, i) {
1249 struct port_info *pi = sc->port[i];
1256 for_each_vi(pi, j, vi) {
1258 vi->qsize_rxq = t4_qsize_rxq;
1259 vi->qsize_txq = t4_qsize_txq;
1261 vi->first_rxq = rqidx;
1262 vi->first_txq = tqidx;
1263 vi->tmr_idx = t4_tmr_idx;
1264 vi->pktc_idx = t4_pktc_idx;
1265 vi->nrxq = j == 0 ? iaq.nrxq : iaq.nrxq_vi;
1266 vi->ntxq = j == 0 ? iaq.ntxq : iaq.ntxq_vi;
1271 if (j == 0 && vi->ntxq > 1)
1272 vi->rsrv_noflowq = t4_rsrv_noflowq ? 1 : 0;
1274 vi->rsrv_noflowq = 0;
1277 vi->ofld_tmr_idx = t4_tmr_idx_ofld;
1278 vi->ofld_pktc_idx = t4_pktc_idx_ofld;
1279 vi->first_ofld_rxq = ofld_rqidx;
1280 vi->first_ofld_txq = ofld_tqidx;
1281 vi->nofldrxq = j == 0 ? iaq.nofldrxq : iaq.nofldrxq_vi;
1282 vi->nofldtxq = j == 0 ? iaq.nofldtxq : iaq.nofldtxq_vi;
1284 ofld_rqidx += vi->nofldrxq;
1285 ofld_tqidx += vi->nofldtxq;
1289 vi->first_nm_rxq = nm_rqidx;
1290 vi->first_nm_txq = nm_tqidx;
1291 vi->nnmrxq = iaq.nnmrxq_vi;
1292 vi->nnmtxq = iaq.nnmtxq_vi;
1293 nm_rqidx += vi->nnmrxq;
1294 nm_tqidx += vi->nnmtxq;
1300 rc = t4_setup_intr_handlers(sc);
1303 "failed to setup interrupt handlers: %d\n", rc);
1307 rc = bus_generic_probe(dev);
1309 device_printf(dev, "failed to probe child drivers: %d\n", rc);
1314 * Ensure thread-safe mailbox access (in debug builds).
1316 * So far this was the only thread accessing the mailbox but various
1317 * ifnets and sysctls are about to be created and their handlers/ioctls
1318 * will access the mailbox from different threads.
1320 sc->flags |= CHK_MBOX_ACCESS;
1322 rc = bus_generic_attach(dev);
1325 "failed to attach all child ports: %d\n", rc);
1330 "PCIe gen%d x%d, %d ports, %d %s interrupt%s, %d eq, %d iq\n",
1331 sc->params.pci.speed, sc->params.pci.width, sc->params.nports,
1332 sc->intr_count, sc->intr_type == INTR_MSIX ? "MSI-X" :
1333 (sc->intr_type == INTR_MSI ? "MSI" : "INTx"),
1334 sc->intr_count > 1 ? "s" : "", sc->sge.neq, sc->sge.niq);
1338 notify_siblings(dev, 0);
1341 if (rc != 0 && sc->cdev) {
1342 /* cdev was created and so cxgbetool works; recover that way. */
1344 "error during attach, adapter is now in recovery mode.\n");
1349 t4_detach_common(dev);
1357 t4_child_location_str(device_t bus, device_t dev, char *buf, size_t buflen)
1360 struct port_info *pi;
1363 sc = device_get_softc(bus);
1365 for_each_port(sc, i) {
1367 if (pi != NULL && pi->dev == dev) {
1368 snprintf(buf, buflen, "port=%d", pi->port_id);
1376 t4_ready(device_t dev)
1380 sc = device_get_softc(dev);
1381 if (sc->flags & FW_OK)
1387 t4_read_port_device(device_t dev, int port, device_t *child)
1390 struct port_info *pi;
1392 sc = device_get_softc(dev);
1393 if (port < 0 || port >= MAX_NPORTS)
1395 pi = sc->port[port];
1396 if (pi == NULL || pi->dev == NULL)
1403 notify_siblings(device_t dev, int detaching)
1409 for (i = 0; i < PCI_FUNCMAX; i++) {
1410 if (i == pci_get_function(dev))
1412 sibling = pci_find_dbsf(pci_get_domain(dev), pci_get_bus(dev),
1413 pci_get_slot(dev), i);
1414 if (sibling == NULL || !device_is_attached(sibling))
1417 error = T4_DETACH_CHILD(sibling);
1419 (void)T4_ATTACH_CHILD(sibling);
1430 t4_detach(device_t dev)
1435 sc = device_get_softc(dev);
1437 rc = notify_siblings(dev, 1);
1440 "failed to detach sibling devices: %d\n", rc);
1444 return (t4_detach_common(dev));
1448 t4_detach_common(device_t dev)
1451 struct port_info *pi;
1454 sc = device_get_softc(dev);
1457 destroy_dev(sc->cdev);
1461 sc->flags &= ~CHK_MBOX_ACCESS;
1462 if (sc->flags & FULL_INIT_DONE) {
1463 if (!(sc->flags & IS_VF))
1464 t4_intr_disable(sc);
1467 if (device_is_attached(dev)) {
1468 rc = bus_generic_detach(dev);
1471 "failed to detach child devices: %d\n", rc);
1476 for (i = 0; i < sc->intr_count; i++)
1477 t4_free_irq(sc, &sc->irq[i]);
1479 if ((sc->flags & (IS_VF | FW_OK)) == FW_OK)
1480 t4_free_tx_sched(sc);
1482 for (i = 0; i < MAX_NPORTS; i++) {
1485 t4_free_vi(sc, sc->mbox, sc->pf, 0, pi->vi[0].viid);
1487 device_delete_child(dev, pi->dev);
1489 mtx_destroy(&pi->pi_lock);
1490 free(pi->vi, M_CXGBE);
1495 device_delete_children(dev);
1497 if (sc->flags & FULL_INIT_DONE)
1498 adapter_full_uninit(sc);
1500 if ((sc->flags & (IS_VF | FW_OK)) == FW_OK)
1501 t4_fw_bye(sc, sc->mbox);
1503 if (sc->intr_type == INTR_MSI || sc->intr_type == INTR_MSIX)
1504 pci_release_msi(dev);
1507 bus_release_resource(dev, SYS_RES_MEMORY, sc->regs_rid,
1511 bus_release_resource(dev, SYS_RES_MEMORY, sc->udbs_rid,
1515 bus_release_resource(dev, SYS_RES_MEMORY, sc->msix_rid,
1519 t4_free_l2t(sc->l2t);
1521 vmem_destroy(sc->key_map);
1524 free(sc->sge.ofld_rxq, M_CXGBE);
1525 free(sc->sge.ofld_txq, M_CXGBE);
1528 free(sc->sge.nm_rxq, M_CXGBE);
1529 free(sc->sge.nm_txq, M_CXGBE);
1531 free(sc->irq, M_CXGBE);
1532 free(sc->sge.rxq, M_CXGBE);
1533 free(sc->sge.txq, M_CXGBE);
1534 free(sc->sge.ctrlq, M_CXGBE);
1535 free(sc->sge.iqmap, M_CXGBE);
1536 free(sc->sge.eqmap, M_CXGBE);
1537 free(sc->tids.ftid_tab, M_CXGBE);
1538 free(sc->tt.tls_rx_ports, M_CXGBE);
1539 t4_destroy_dma_tag(sc);
1540 if (mtx_initialized(&sc->sc_lock)) {
1541 sx_xlock(&t4_list_lock);
1542 SLIST_REMOVE(&t4_list, sc, adapter, link);
1543 sx_xunlock(&t4_list_lock);
1544 mtx_destroy(&sc->sc_lock);
1547 callout_drain(&sc->sfl_callout);
1548 if (mtx_initialized(&sc->tids.ftid_lock))
1549 mtx_destroy(&sc->tids.ftid_lock);
1550 if (mtx_initialized(&sc->sfl_lock))
1551 mtx_destroy(&sc->sfl_lock);
1552 if (mtx_initialized(&sc->ifp_lock))
1553 mtx_destroy(&sc->ifp_lock);
1554 if (mtx_initialized(&sc->reg_lock))
1555 mtx_destroy(&sc->reg_lock);
1557 if (rw_initialized(&sc->policy_lock)) {
1558 rw_destroy(&sc->policy_lock);
1560 if (sc->policy != NULL)
1561 free_offload_policy(sc->policy);
1565 for (i = 0; i < NUM_MEMWIN; i++) {
1566 struct memwin *mw = &sc->memwin[i];
1568 if (rw_initialized(&mw->mw_lock))
1569 rw_destroy(&mw->mw_lock);
1572 bzero(sc, sizeof(*sc));
1578 cxgbe_probe(device_t dev)
1581 struct port_info *pi = device_get_softc(dev);
1583 snprintf(buf, sizeof(buf), "port %d", pi->port_id);
1584 device_set_desc_copy(dev, buf);
1586 return (BUS_PROBE_DEFAULT);
1589 #define T4_CAP (IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_HWCSUM | \
1590 IFCAP_VLAN_HWCSUM | IFCAP_TSO | IFCAP_JUMBO_MTU | IFCAP_LRO | \
1591 IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWCSUM_IPV6 | IFCAP_HWSTATS)
1592 #define T4_CAP_ENABLE (T4_CAP)
1595 cxgbe_vi_attach(device_t dev, struct vi_info *vi)
1600 vi->xact_addr_filt = -1;
1601 callout_init(&vi->tick, 1);
1603 /* Allocate an ifnet and set it up */
1604 ifp = if_alloc(IFT_ETHER);
1606 device_printf(dev, "Cannot allocate ifnet\n");
1612 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1613 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1615 ifp->if_init = cxgbe_init;
1616 ifp->if_ioctl = cxgbe_ioctl;
1617 ifp->if_transmit = cxgbe_transmit;
1618 ifp->if_qflush = cxgbe_qflush;
1619 ifp->if_get_counter = cxgbe_get_counter;
1621 ifp->if_capabilities = T4_CAP;
1623 if (vi->nofldrxq != 0)
1624 ifp->if_capabilities |= IFCAP_TOE;
1626 ifp->if_capenable = T4_CAP_ENABLE;
1627 ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_IP | CSUM_TSO |
1628 CSUM_UDP_IPV6 | CSUM_TCP_IPV6;
1630 ifp->if_hw_tsomax = 65536 - (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
1631 ifp->if_hw_tsomaxsegcount = TX_SGL_SEGS;
1632 ifp->if_hw_tsomaxsegsize = 65536;
1634 vi->vlan_c = EVENTHANDLER_REGISTER(vlan_config, cxgbe_vlan_config, ifp,
1635 EVENTHANDLER_PRI_ANY);
1637 ether_ifattach(ifp, vi->hw_addr);
1639 if (vi->nnmrxq != 0)
1640 cxgbe_nm_attach(vi);
1642 sb = sbuf_new_auto();
1643 sbuf_printf(sb, "%d txq, %d rxq (NIC)", vi->ntxq, vi->nrxq);
1645 if (ifp->if_capabilities & IFCAP_TOE)
1646 sbuf_printf(sb, "; %d txq, %d rxq (TOE)",
1647 vi->nofldtxq, vi->nofldrxq);
1650 if (ifp->if_capabilities & IFCAP_NETMAP)
1651 sbuf_printf(sb, "; %d txq, %d rxq (netmap)",
1652 vi->nnmtxq, vi->nnmrxq);
1655 device_printf(dev, "%s\n", sbuf_data(sb));
1664 cxgbe_attach(device_t dev)
1666 struct port_info *pi = device_get_softc(dev);
1667 struct adapter *sc = pi->adapter;
1671 callout_init_mtx(&pi->tick, &pi->pi_lock, 0);
1673 rc = cxgbe_vi_attach(dev, &pi->vi[0]);
1677 for_each_vi(pi, i, vi) {
1680 vi->dev = device_add_child(dev, sc->names->vi_ifnet_name, -1);
1681 if (vi->dev == NULL) {
1682 device_printf(dev, "failed to add VI %d\n", i);
1685 device_set_softc(vi->dev, vi);
1690 bus_generic_attach(dev);
1696 cxgbe_vi_detach(struct vi_info *vi)
1698 struct ifnet *ifp = vi->ifp;
1700 ether_ifdetach(ifp);
1703 EVENTHANDLER_DEREGISTER(vlan_config, vi->vlan_c);
1705 /* Let detach proceed even if these fail. */
1707 if (ifp->if_capabilities & IFCAP_NETMAP)
1708 cxgbe_nm_detach(vi);
1710 cxgbe_uninit_synchronized(vi);
1711 callout_drain(&vi->tick);
1719 cxgbe_detach(device_t dev)
1721 struct port_info *pi = device_get_softc(dev);
1722 struct adapter *sc = pi->adapter;
1725 /* Detach the extra VIs first. */
1726 rc = bus_generic_detach(dev);
1729 device_delete_children(dev);
1731 doom_vi(sc, &pi->vi[0]);
1733 if (pi->flags & HAS_TRACEQ) {
1734 sc->traceq = -1; /* cloner should not create ifnet */
1735 t4_tracer_port_detach(sc);
1738 cxgbe_vi_detach(&pi->vi[0]);
1739 callout_drain(&pi->tick);
1740 ifmedia_removeall(&pi->media);
1742 end_synchronized_op(sc, 0);
1748 cxgbe_init(void *arg)
1750 struct vi_info *vi = arg;
1751 struct adapter *sc = vi->pi->adapter;
1753 if (begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4init") != 0)
1755 cxgbe_init_synchronized(vi);
1756 end_synchronized_op(sc, 0);
1760 cxgbe_ioctl(struct ifnet *ifp, unsigned long cmd, caddr_t data)
1762 int rc = 0, mtu, can_sleep, if_flags, if_drv_flags, vi_if_flags;
1763 struct vi_info *vi = ifp->if_softc;
1764 struct port_info *pi = vi->pi;
1765 struct adapter *sc = pi->adapter;
1766 struct ifreq *ifr = (struct ifreq *)data;
1772 if (mtu < ETHERMIN || mtu > MAX_MTU)
1775 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4mtu");
1779 if (vi->flags & VI_INIT_DONE) {
1780 t4_update_fl_bufsize(ifp);
1781 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1782 rc = update_mac_settings(ifp, XGMAC_MTU);
1784 end_synchronized_op(sc, 0);
1789 * Decide what to do, with the port lock held.
1792 if_flags = ifp->if_flags;
1793 if_drv_flags = ifp->if_drv_flags;
1794 vi_if_flags = vi->if_flags;
1795 if (if_flags & IFF_UP && if_drv_flags & IFF_DRV_RUNNING &&
1796 (vi_if_flags ^ if_flags) & (IFF_PROMISC | IFF_ALLMULTI)) {
1804 * ifp/vi flags may change here but we'll just do what our local
1805 * copy of the flags indicates and then update the driver owned
1806 * ifp/vi flags (in a synch-op and with the port lock held) to
1807 * reflect what we did.
1810 rc = begin_synchronized_op(sc, vi,
1811 can_sleep ? (SLEEP_OK | INTR_OK) : HOLD_LOCK, "t4flg");
1813 if_printf(ifp, "%ssleepable synch operation failed: %d."
1814 " if_flags 0x%08x, if_drv_flags 0x%08x\n",
1815 can_sleep ? "" : "non-", rc, if_flags,
1820 if (if_flags & IFF_UP) {
1821 if (if_drv_flags & IFF_DRV_RUNNING) {
1822 if ((if_flags ^ vi_if_flags) &
1823 (IFF_PROMISC | IFF_ALLMULTI)) {
1824 MPASS(can_sleep == 0);
1825 rc = update_mac_settings(ifp,
1826 XGMAC_PROMISC | XGMAC_ALLMULTI);
1829 MPASS(can_sleep == 1);
1830 rc = cxgbe_init_synchronized(vi);
1832 } else if (if_drv_flags & IFF_DRV_RUNNING) {
1833 MPASS(can_sleep == 1);
1834 rc = cxgbe_uninit_synchronized(vi);
1837 vi->if_flags = if_flags;
1839 end_synchronized_op(sc, can_sleep ? 0 : LOCK_HELD);
1843 case SIOCDELMULTI: /* these two are called with a mutex held :-( */
1844 rc = begin_synchronized_op(sc, vi, HOLD_LOCK, "t4multi");
1847 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1848 rc = update_mac_settings(ifp, XGMAC_MCADDRS);
1849 end_synchronized_op(sc, LOCK_HELD);
1853 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4cap");
1857 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1858 if (mask & IFCAP_TXCSUM) {
1859 ifp->if_capenable ^= IFCAP_TXCSUM;
1860 ifp->if_hwassist ^= (CSUM_TCP | CSUM_UDP | CSUM_IP);
1862 if (IFCAP_TSO4 & ifp->if_capenable &&
1863 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1864 ifp->if_capenable &= ~IFCAP_TSO4;
1866 "tso4 disabled due to -txcsum.\n");
1869 if (mask & IFCAP_TXCSUM_IPV6) {
1870 ifp->if_capenable ^= IFCAP_TXCSUM_IPV6;
1871 ifp->if_hwassist ^= (CSUM_UDP_IPV6 | CSUM_TCP_IPV6);
1873 if (IFCAP_TSO6 & ifp->if_capenable &&
1874 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1875 ifp->if_capenable &= ~IFCAP_TSO6;
1877 "tso6 disabled due to -txcsum6.\n");
1880 if (mask & IFCAP_RXCSUM)
1881 ifp->if_capenable ^= IFCAP_RXCSUM;
1882 if (mask & IFCAP_RXCSUM_IPV6)
1883 ifp->if_capenable ^= IFCAP_RXCSUM_IPV6;
1886 * Note that we leave CSUM_TSO alone (it is always set). The
1887 * kernel takes both IFCAP_TSOx and CSUM_TSO into account before
1888 * sending a TSO request our way, so it's sufficient to toggle
1891 if (mask & IFCAP_TSO4) {
1892 if (!(IFCAP_TSO4 & ifp->if_capenable) &&
1893 !(IFCAP_TXCSUM & ifp->if_capenable)) {
1894 if_printf(ifp, "enable txcsum first.\n");
1898 ifp->if_capenable ^= IFCAP_TSO4;
1900 if (mask & IFCAP_TSO6) {
1901 if (!(IFCAP_TSO6 & ifp->if_capenable) &&
1902 !(IFCAP_TXCSUM_IPV6 & ifp->if_capenable)) {
1903 if_printf(ifp, "enable txcsum6 first.\n");
1907 ifp->if_capenable ^= IFCAP_TSO6;
1909 if (mask & IFCAP_LRO) {
1910 #if defined(INET) || defined(INET6)
1912 struct sge_rxq *rxq;
1914 ifp->if_capenable ^= IFCAP_LRO;
1915 for_each_rxq(vi, i, rxq) {
1916 if (ifp->if_capenable & IFCAP_LRO)
1917 rxq->iq.flags |= IQ_LRO_ENABLED;
1919 rxq->iq.flags &= ~IQ_LRO_ENABLED;
1924 if (mask & IFCAP_TOE) {
1925 int enable = (ifp->if_capenable ^ mask) & IFCAP_TOE;
1927 rc = toe_capability(vi, enable);
1931 ifp->if_capenable ^= mask;
1934 if (mask & IFCAP_VLAN_HWTAGGING) {
1935 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
1936 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1937 rc = update_mac_settings(ifp, XGMAC_VLANEX);
1939 if (mask & IFCAP_VLAN_MTU) {
1940 ifp->if_capenable ^= IFCAP_VLAN_MTU;
1942 /* Need to find out how to disable auto-mtu-inflation */
1944 if (mask & IFCAP_VLAN_HWTSO)
1945 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
1946 if (mask & IFCAP_VLAN_HWCSUM)
1947 ifp->if_capenable ^= IFCAP_VLAN_HWCSUM;
1949 #ifdef VLAN_CAPABILITIES
1950 VLAN_CAPABILITIES(ifp);
1953 end_synchronized_op(sc, 0);
1959 ifmedia_ioctl(ifp, ifr, &pi->media, cmd);
1963 struct ifi2creq i2c;
1965 rc = copyin(ifr_data_get_ptr(ifr), &i2c, sizeof(i2c));
1968 if (i2c.dev_addr != 0xA0 && i2c.dev_addr != 0xA2) {
1972 if (i2c.len > sizeof(i2c.data)) {
1976 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4i2c");
1979 rc = -t4_i2c_rd(sc, sc->mbox, pi->port_id, i2c.dev_addr,
1980 i2c.offset, i2c.len, &i2c.data[0]);
1981 end_synchronized_op(sc, 0);
1983 rc = copyout(&i2c, ifr_data_get_ptr(ifr), sizeof(i2c));
1988 rc = ether_ioctl(ifp, cmd, data);
1995 cxgbe_transmit(struct ifnet *ifp, struct mbuf *m)
1997 struct vi_info *vi = ifp->if_softc;
1998 struct port_info *pi = vi->pi;
1999 struct adapter *sc = pi->adapter;
2000 struct sge_txq *txq;
2005 MPASS(m->m_nextpkt == NULL); /* not quite ready for this yet */
2007 if (__predict_false(pi->link_cfg.link_ok == false)) {
2012 rc = parse_pkt(sc, &m);
2013 if (__predict_false(rc != 0)) {
2014 MPASS(m == NULL); /* was freed already */
2015 atomic_add_int(&pi->tx_parse_error, 1); /* rare, atomic is ok */
2020 txq = &sc->sge.txq[vi->first_txq];
2021 if (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE)
2022 txq += ((m->m_pkthdr.flowid % (vi->ntxq - vi->rsrv_noflowq)) +
2026 rc = mp_ring_enqueue(txq->r, items, 1, 4096);
2027 if (__predict_false(rc != 0))
2034 cxgbe_qflush(struct ifnet *ifp)
2036 struct vi_info *vi = ifp->if_softc;
2037 struct sge_txq *txq;
2040 /* queues do not exist if !VI_INIT_DONE. */
2041 if (vi->flags & VI_INIT_DONE) {
2042 for_each_txq(vi, i, txq) {
2044 txq->eq.flags |= EQ_QFLUSH;
2046 while (!mp_ring_is_idle(txq->r)) {
2047 mp_ring_check_drainage(txq->r, 0);
2051 txq->eq.flags &= ~EQ_QFLUSH;
2059 vi_get_counter(struct ifnet *ifp, ift_counter c)
2061 struct vi_info *vi = ifp->if_softc;
2062 struct fw_vi_stats_vf *s = &vi->stats;
2064 vi_refresh_stats(vi->pi->adapter, vi);
2067 case IFCOUNTER_IPACKETS:
2068 return (s->rx_bcast_frames + s->rx_mcast_frames +
2069 s->rx_ucast_frames);
2070 case IFCOUNTER_IERRORS:
2071 return (s->rx_err_frames);
2072 case IFCOUNTER_OPACKETS:
2073 return (s->tx_bcast_frames + s->tx_mcast_frames +
2074 s->tx_ucast_frames + s->tx_offload_frames);
2075 case IFCOUNTER_OERRORS:
2076 return (s->tx_drop_frames);
2077 case IFCOUNTER_IBYTES:
2078 return (s->rx_bcast_bytes + s->rx_mcast_bytes +
2080 case IFCOUNTER_OBYTES:
2081 return (s->tx_bcast_bytes + s->tx_mcast_bytes +
2082 s->tx_ucast_bytes + s->tx_offload_bytes);
2083 case IFCOUNTER_IMCASTS:
2084 return (s->rx_mcast_frames);
2085 case IFCOUNTER_OMCASTS:
2086 return (s->tx_mcast_frames);
2087 case IFCOUNTER_OQDROPS: {
2091 if (vi->flags & VI_INIT_DONE) {
2093 struct sge_txq *txq;
2095 for_each_txq(vi, i, txq)
2096 drops += counter_u64_fetch(txq->r->drops);
2104 return (if_get_counter_default(ifp, c));
2109 cxgbe_get_counter(struct ifnet *ifp, ift_counter c)
2111 struct vi_info *vi = ifp->if_softc;
2112 struct port_info *pi = vi->pi;
2113 struct adapter *sc = pi->adapter;
2114 struct port_stats *s = &pi->stats;
2116 if (pi->nvi > 1 || sc->flags & IS_VF)
2117 return (vi_get_counter(ifp, c));
2119 cxgbe_refresh_stats(sc, pi);
2122 case IFCOUNTER_IPACKETS:
2123 return (s->rx_frames);
2125 case IFCOUNTER_IERRORS:
2126 return (s->rx_jabber + s->rx_runt + s->rx_too_long +
2127 s->rx_fcs_err + s->rx_len_err);
2129 case IFCOUNTER_OPACKETS:
2130 return (s->tx_frames);
2132 case IFCOUNTER_OERRORS:
2133 return (s->tx_error_frames);
2135 case IFCOUNTER_IBYTES:
2136 return (s->rx_octets);
2138 case IFCOUNTER_OBYTES:
2139 return (s->tx_octets);
2141 case IFCOUNTER_IMCASTS:
2142 return (s->rx_mcast_frames);
2144 case IFCOUNTER_OMCASTS:
2145 return (s->tx_mcast_frames);
2147 case IFCOUNTER_IQDROPS:
2148 return (s->rx_ovflow0 + s->rx_ovflow1 + s->rx_ovflow2 +
2149 s->rx_ovflow3 + s->rx_trunc0 + s->rx_trunc1 + s->rx_trunc2 +
2150 s->rx_trunc3 + pi->tnl_cong_drops);
2152 case IFCOUNTER_OQDROPS: {
2156 if (vi->flags & VI_INIT_DONE) {
2158 struct sge_txq *txq;
2160 for_each_txq(vi, i, txq)
2161 drops += counter_u64_fetch(txq->r->drops);
2169 return (if_get_counter_default(ifp, c));
2174 * The kernel picks a media from the list we had provided but we still validate
2178 cxgbe_media_change(struct ifnet *ifp)
2180 struct vi_info *vi = ifp->if_softc;
2181 struct port_info *pi = vi->pi;
2182 struct ifmedia *ifm = &pi->media;
2183 struct link_config *lc = &pi->link_cfg;
2184 struct adapter *sc = pi->adapter;
2187 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4mec");
2191 if (IFM_SUBTYPE(ifm->ifm_media) == IFM_AUTO) {
2192 /* ifconfig .. media autoselect */
2193 if (!(lc->supported & FW_PORT_CAP32_ANEG)) {
2194 rc = ENOTSUP; /* AN not supported by transceiver */
2197 lc->requested_aneg = AUTONEG_ENABLE;
2198 lc->requested_speed = 0;
2199 lc->requested_fc |= PAUSE_AUTONEG;
2201 lc->requested_aneg = AUTONEG_DISABLE;
2202 lc->requested_speed =
2203 ifmedia_baudrate(ifm->ifm_media) / 1000000;
2204 lc->requested_fc = 0;
2205 if (IFM_OPTIONS(ifm->ifm_media) & IFM_ETH_RXPAUSE)
2206 lc->requested_fc |= PAUSE_RX;
2207 if (IFM_OPTIONS(ifm->ifm_media) & IFM_ETH_TXPAUSE)
2208 lc->requested_fc |= PAUSE_TX;
2210 if (pi->up_vis > 0) {
2211 fixup_link_config(pi);
2212 rc = apply_link_config(pi);
2216 end_synchronized_op(sc, 0);
2221 * Base media word (without ETHER, pause, link active, etc.) for the port at the
2225 port_mword(struct port_info *pi, uint32_t speed)
2228 MPASS(speed & M_FW_PORT_CAP32_SPEED);
2229 MPASS(powerof2(speed));
2231 switch(pi->port_type) {
2232 case FW_PORT_TYPE_BT_SGMII:
2233 case FW_PORT_TYPE_BT_XFI:
2234 case FW_PORT_TYPE_BT_XAUI:
2237 case FW_PORT_CAP32_SPEED_100M:
2239 case FW_PORT_CAP32_SPEED_1G:
2240 return (IFM_1000_T);
2241 case FW_PORT_CAP32_SPEED_10G:
2245 case FW_PORT_TYPE_KX4:
2246 if (speed == FW_PORT_CAP32_SPEED_10G)
2247 return (IFM_10G_KX4);
2249 case FW_PORT_TYPE_CX4:
2250 if (speed == FW_PORT_CAP32_SPEED_10G)
2251 return (IFM_10G_CX4);
2253 case FW_PORT_TYPE_KX:
2254 if (speed == FW_PORT_CAP32_SPEED_1G)
2255 return (IFM_1000_KX);
2257 case FW_PORT_TYPE_KR:
2258 case FW_PORT_TYPE_BP_AP:
2259 case FW_PORT_TYPE_BP4_AP:
2260 case FW_PORT_TYPE_BP40_BA:
2261 case FW_PORT_TYPE_KR4_100G:
2262 case FW_PORT_TYPE_KR_SFP28:
2263 case FW_PORT_TYPE_KR_XLAUI:
2265 case FW_PORT_CAP32_SPEED_1G:
2266 return (IFM_1000_KX);
2267 case FW_PORT_CAP32_SPEED_10G:
2268 return (IFM_10G_KR);
2269 case FW_PORT_CAP32_SPEED_25G:
2270 return (IFM_25G_KR);
2271 case FW_PORT_CAP32_SPEED_40G:
2272 return (IFM_40G_KR4);
2273 case FW_PORT_CAP32_SPEED_50G:
2274 return (IFM_50G_KR2);
2275 case FW_PORT_CAP32_SPEED_100G:
2276 return (IFM_100G_KR4);
2279 case FW_PORT_TYPE_FIBER_XFI:
2280 case FW_PORT_TYPE_FIBER_XAUI:
2281 case FW_PORT_TYPE_SFP:
2282 case FW_PORT_TYPE_QSFP_10G:
2283 case FW_PORT_TYPE_QSA:
2284 case FW_PORT_TYPE_QSFP:
2285 case FW_PORT_TYPE_CR4_QSFP:
2286 case FW_PORT_TYPE_CR_QSFP:
2287 case FW_PORT_TYPE_CR2_QSFP:
2288 case FW_PORT_TYPE_SFP28:
2289 /* Pluggable transceiver */
2290 switch (pi->mod_type) {
2291 case FW_PORT_MOD_TYPE_LR:
2293 case FW_PORT_CAP32_SPEED_1G:
2294 return (IFM_1000_LX);
2295 case FW_PORT_CAP32_SPEED_10G:
2296 return (IFM_10G_LR);
2297 case FW_PORT_CAP32_SPEED_25G:
2298 return (IFM_25G_LR);
2299 case FW_PORT_CAP32_SPEED_40G:
2300 return (IFM_40G_LR4);
2301 case FW_PORT_CAP32_SPEED_50G:
2302 return (IFM_50G_LR2);
2303 case FW_PORT_CAP32_SPEED_100G:
2304 return (IFM_100G_LR4);
2307 case FW_PORT_MOD_TYPE_SR:
2309 case FW_PORT_CAP32_SPEED_1G:
2310 return (IFM_1000_SX);
2311 case FW_PORT_CAP32_SPEED_10G:
2312 return (IFM_10G_SR);
2313 case FW_PORT_CAP32_SPEED_25G:
2314 return (IFM_25G_SR);
2315 case FW_PORT_CAP32_SPEED_40G:
2316 return (IFM_40G_SR4);
2317 case FW_PORT_CAP32_SPEED_50G:
2318 return (IFM_50G_SR2);
2319 case FW_PORT_CAP32_SPEED_100G:
2320 return (IFM_100G_SR4);
2323 case FW_PORT_MOD_TYPE_ER:
2324 if (speed == FW_PORT_CAP32_SPEED_10G)
2325 return (IFM_10G_ER);
2327 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE:
2328 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE:
2330 case FW_PORT_CAP32_SPEED_1G:
2331 return (IFM_1000_CX);
2332 case FW_PORT_CAP32_SPEED_10G:
2333 return (IFM_10G_TWINAX);
2334 case FW_PORT_CAP32_SPEED_25G:
2335 return (IFM_25G_CR);
2336 case FW_PORT_CAP32_SPEED_40G:
2337 return (IFM_40G_CR4);
2338 case FW_PORT_CAP32_SPEED_50G:
2339 return (IFM_50G_CR2);
2340 case FW_PORT_CAP32_SPEED_100G:
2341 return (IFM_100G_CR4);
2344 case FW_PORT_MOD_TYPE_LRM:
2345 if (speed == FW_PORT_CAP32_SPEED_10G)
2346 return (IFM_10G_LRM);
2348 case FW_PORT_MOD_TYPE_NA:
2349 MPASS(0); /* Not pluggable? */
2351 case FW_PORT_MOD_TYPE_ERROR:
2352 case FW_PORT_MOD_TYPE_UNKNOWN:
2353 case FW_PORT_MOD_TYPE_NOTSUPPORTED:
2355 case FW_PORT_MOD_TYPE_NONE:
2359 case FW_PORT_TYPE_NONE:
2363 return (IFM_UNKNOWN);
2367 cxgbe_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
2369 struct vi_info *vi = ifp->if_softc;
2370 struct port_info *pi = vi->pi;
2371 struct adapter *sc = pi->adapter;
2372 struct link_config *lc = &pi->link_cfg;
2374 if (begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4med") != 0)
2378 if (pi->up_vis == 0) {
2380 * If all the interfaces are administratively down the firmware
2381 * does not report transceiver changes. Refresh port info here
2382 * so that ifconfig displays accurate ifmedia at all times.
2383 * This is the only reason we have a synchronized op in this
2384 * function. Just PORT_LOCK would have been enough otherwise.
2386 t4_update_port_info(pi);
2387 build_medialist(pi);
2391 ifmr->ifm_status = IFM_AVALID;
2392 if (lc->link_ok == false)
2394 ifmr->ifm_status |= IFM_ACTIVE;
2397 ifmr->ifm_active = IFM_ETHER | IFM_FDX;
2398 ifmr->ifm_active &= ~(IFM_ETH_TXPAUSE | IFM_ETH_RXPAUSE);
2399 if (lc->fc & PAUSE_RX)
2400 ifmr->ifm_active |= IFM_ETH_RXPAUSE;
2401 if (lc->fc & PAUSE_TX)
2402 ifmr->ifm_active |= IFM_ETH_TXPAUSE;
2403 ifmr->ifm_active |= port_mword(pi, speed_to_fwcap(lc->speed));
2406 end_synchronized_op(sc, 0);
2410 vcxgbe_probe(device_t dev)
2413 struct vi_info *vi = device_get_softc(dev);
2415 snprintf(buf, sizeof(buf), "port %d vi %td", vi->pi->port_id,
2417 device_set_desc_copy(dev, buf);
2419 return (BUS_PROBE_DEFAULT);
2423 alloc_extra_vi(struct adapter *sc, struct port_info *pi, struct vi_info *vi)
2425 int func, index, rc;
2426 uint32_t param, val;
2428 ASSERT_SYNCHRONIZED_OP(sc);
2430 index = vi - pi->vi;
2431 MPASS(index > 0); /* This function deals with _extra_ VIs only */
2432 KASSERT(index < nitems(vi_mac_funcs),
2433 ("%s: VI %s doesn't have a MAC func", __func__,
2434 device_get_nameunit(vi->dev)));
2435 func = vi_mac_funcs[index];
2436 rc = t4_alloc_vi_func(sc, sc->mbox, pi->tx_chan, sc->pf, 0, 1,
2437 vi->hw_addr, &vi->rss_size, func, 0);
2439 device_printf(vi->dev, "failed to allocate virtual interface %d"
2440 "for port %d: %d\n", index, pi->port_id, -rc);
2444 if (chip_id(sc) <= CHELSIO_T5)
2445 vi->smt_idx = (rc & 0x7f) << 1;
2447 vi->smt_idx = (rc & 0x7f);
2449 if (vi->rss_size == 1) {
2451 * This VI didn't get a slice of the RSS table. Reduce the
2452 * number of VIs being created (hw.cxgbe.num_vis) or modify the
2453 * configuration file (nvi, rssnvi for this PF) if this is a
2456 device_printf(vi->dev, "RSS table not available.\n");
2457 vi->rss_base = 0xffff;
2462 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
2463 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_RSSINFO) |
2464 V_FW_PARAMS_PARAM_YZ(vi->viid);
2465 rc = t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
2467 vi->rss_base = 0xffff;
2469 MPASS((val >> 16) == vi->rss_size);
2470 vi->rss_base = val & 0xffff;
2477 vcxgbe_attach(device_t dev)
2480 struct port_info *pi;
2484 vi = device_get_softc(dev);
2488 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4via");
2491 rc = alloc_extra_vi(sc, pi, vi);
2492 end_synchronized_op(sc, 0);
2496 rc = cxgbe_vi_attach(dev, vi);
2498 t4_free_vi(sc, sc->mbox, sc->pf, 0, vi->viid);
2505 vcxgbe_detach(device_t dev)
2510 vi = device_get_softc(dev);
2511 sc = vi->pi->adapter;
2515 cxgbe_vi_detach(vi);
2516 t4_free_vi(sc, sc->mbox, sc->pf, 0, vi->viid);
2518 end_synchronized_op(sc, 0);
2524 t4_fatal_err(struct adapter *sc)
2526 t4_set_reg_field(sc, A_SGE_CONTROL, F_GLOBALENABLE, 0);
2527 t4_intr_disable(sc);
2528 log(LOG_EMERG, "%s: encountered fatal error, adapter stopped.\n",
2529 device_get_nameunit(sc->dev));
2533 t4_add_adapter(struct adapter *sc)
2535 sx_xlock(&t4_list_lock);
2536 SLIST_INSERT_HEAD(&t4_list, sc, link);
2537 sx_xunlock(&t4_list_lock);
2541 t4_map_bars_0_and_4(struct adapter *sc)
2543 sc->regs_rid = PCIR_BAR(0);
2544 sc->regs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
2545 &sc->regs_rid, RF_ACTIVE);
2546 if (sc->regs_res == NULL) {
2547 device_printf(sc->dev, "cannot map registers.\n");
2550 sc->bt = rman_get_bustag(sc->regs_res);
2551 sc->bh = rman_get_bushandle(sc->regs_res);
2552 sc->mmio_len = rman_get_size(sc->regs_res);
2553 setbit(&sc->doorbells, DOORBELL_KDB);
2555 sc->msix_rid = PCIR_BAR(4);
2556 sc->msix_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
2557 &sc->msix_rid, RF_ACTIVE);
2558 if (sc->msix_res == NULL) {
2559 device_printf(sc->dev, "cannot map MSI-X BAR.\n");
2567 t4_map_bar_2(struct adapter *sc)
2571 * T4: only iWARP driver uses the userspace doorbells. There is no need
2572 * to map it if RDMA is disabled.
2574 if (is_t4(sc) && sc->rdmacaps == 0)
2577 sc->udbs_rid = PCIR_BAR(2);
2578 sc->udbs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
2579 &sc->udbs_rid, RF_ACTIVE);
2580 if (sc->udbs_res == NULL) {
2581 device_printf(sc->dev, "cannot map doorbell BAR.\n");
2584 sc->udbs_base = rman_get_virtual(sc->udbs_res);
2586 if (chip_id(sc) >= CHELSIO_T5) {
2587 setbit(&sc->doorbells, DOORBELL_UDB);
2588 #if defined(__i386__) || defined(__amd64__)
2589 if (t5_write_combine) {
2593 * Enable write combining on BAR2. This is the
2594 * userspace doorbell BAR and is split into 128B
2595 * (UDBS_SEG_SIZE) doorbell regions, each associated
2596 * with an egress queue. The first 64B has the doorbell
2597 * and the second 64B can be used to submit a tx work
2598 * request with an implicit doorbell.
2601 rc = pmap_change_attr((vm_offset_t)sc->udbs_base,
2602 rman_get_size(sc->udbs_res), PAT_WRITE_COMBINING);
2604 clrbit(&sc->doorbells, DOORBELL_UDB);
2605 setbit(&sc->doorbells, DOORBELL_WCWR);
2606 setbit(&sc->doorbells, DOORBELL_UDBWC);
2608 device_printf(sc->dev,
2609 "couldn't enable write combining: %d\n",
2613 mode = is_t5(sc) ? V_STATMODE(0) : V_T6_STATMODE(0);
2614 t4_write_reg(sc, A_SGE_STAT_CFG,
2615 V_STATSOURCE_T5(7) | mode);
2619 sc->iwt.wc_en = isset(&sc->doorbells, DOORBELL_UDBWC) ? 1 : 0;
2624 struct memwin_init {
2629 static const struct memwin_init t4_memwin[NUM_MEMWIN] = {
2630 { MEMWIN0_BASE, MEMWIN0_APERTURE },
2631 { MEMWIN1_BASE, MEMWIN1_APERTURE },
2632 { MEMWIN2_BASE_T4, MEMWIN2_APERTURE_T4 }
2635 static const struct memwin_init t5_memwin[NUM_MEMWIN] = {
2636 { MEMWIN0_BASE, MEMWIN0_APERTURE },
2637 { MEMWIN1_BASE, MEMWIN1_APERTURE },
2638 { MEMWIN2_BASE_T5, MEMWIN2_APERTURE_T5 },
2642 setup_memwin(struct adapter *sc)
2644 const struct memwin_init *mw_init;
2651 * Read low 32b of bar0 indirectly via the hardware backdoor
2652 * mechanism. Works from within PCI passthrough environments
2653 * too, where rman_get_start() can return a different value. We
2654 * need to program the T4 memory window decoders with the actual
2655 * addresses that will be coming across the PCIe link.
2657 bar0 = t4_hw_pci_read_cfg4(sc, PCIR_BAR(0));
2658 bar0 &= (uint32_t) PCIM_BAR_MEM_BASE;
2660 mw_init = &t4_memwin[0];
2662 /* T5+ use the relative offset inside the PCIe BAR */
2665 mw_init = &t5_memwin[0];
2668 for (i = 0, mw = &sc->memwin[0]; i < NUM_MEMWIN; i++, mw_init++, mw++) {
2669 rw_init(&mw->mw_lock, "memory window access");
2670 mw->mw_base = mw_init->base;
2671 mw->mw_aperture = mw_init->aperture;
2674 PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, i),
2675 (mw->mw_base + bar0) | V_BIR(0) |
2676 V_WINDOW(ilog2(mw->mw_aperture) - 10));
2677 rw_wlock(&mw->mw_lock);
2678 position_memwin(sc, i, 0);
2679 rw_wunlock(&mw->mw_lock);
2683 t4_read_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 2));
2687 * Positions the memory window at the given address in the card's address space.
2688 * There are some alignment requirements and the actual position may be at an
2689 * address prior to the requested address. mw->mw_curpos always has the actual
2690 * position of the window.
2693 position_memwin(struct adapter *sc, int idx, uint32_t addr)
2699 MPASS(idx >= 0 && idx < NUM_MEMWIN);
2700 mw = &sc->memwin[idx];
2701 rw_assert(&mw->mw_lock, RA_WLOCKED);
2705 mw->mw_curpos = addr & ~0xf; /* start must be 16B aligned */
2707 pf = V_PFNUM(sc->pf);
2708 mw->mw_curpos = addr & ~0x7f; /* start must be 128B aligned */
2710 reg = PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, idx);
2711 t4_write_reg(sc, reg, mw->mw_curpos | pf);
2712 t4_read_reg(sc, reg); /* flush */
2716 rw_via_memwin(struct adapter *sc, int idx, uint32_t addr, uint32_t *val,
2722 MPASS(idx >= 0 && idx < NUM_MEMWIN);
2724 /* Memory can only be accessed in naturally aligned 4 byte units */
2725 if (addr & 3 || len & 3 || len <= 0)
2728 mw = &sc->memwin[idx];
2730 rw_rlock(&mw->mw_lock);
2731 mw_end = mw->mw_curpos + mw->mw_aperture;
2732 if (addr >= mw_end || addr < mw->mw_curpos) {
2733 /* Will need to reposition the window */
2734 if (!rw_try_upgrade(&mw->mw_lock)) {
2735 rw_runlock(&mw->mw_lock);
2736 rw_wlock(&mw->mw_lock);
2738 rw_assert(&mw->mw_lock, RA_WLOCKED);
2739 position_memwin(sc, idx, addr);
2740 rw_downgrade(&mw->mw_lock);
2741 mw_end = mw->mw_curpos + mw->mw_aperture;
2743 rw_assert(&mw->mw_lock, RA_RLOCKED);
2744 while (addr < mw_end && len > 0) {
2746 v = t4_read_reg(sc, mw->mw_base + addr -
2748 *val++ = le32toh(v);
2751 t4_write_reg(sc, mw->mw_base + addr -
2752 mw->mw_curpos, htole32(v));
2757 rw_runlock(&mw->mw_lock);
2764 read_via_memwin(struct adapter *sc, int idx, uint32_t addr, uint32_t *val,
2768 return (rw_via_memwin(sc, idx, addr, val, len, 0));
2772 write_via_memwin(struct adapter *sc, int idx, uint32_t addr,
2773 const uint32_t *val, int len)
2776 return (rw_via_memwin(sc, idx, addr, (void *)(uintptr_t)val, len, 1));
2780 t4_range_cmp(const void *a, const void *b)
2782 return ((const struct t4_range *)a)->start -
2783 ((const struct t4_range *)b)->start;
2787 * Verify that the memory range specified by the addr/len pair is valid within
2788 * the card's address space.
2791 validate_mem_range(struct adapter *sc, uint32_t addr, uint32_t len)
2793 struct t4_range mem_ranges[4], *r, *next;
2794 uint32_t em, addr_len;
2795 int i, n, remaining;
2797 /* Memory can only be accessed in naturally aligned 4 byte units */
2798 if (addr & 3 || len & 3 || len == 0)
2801 /* Enabled memories */
2802 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
2806 bzero(r, sizeof(mem_ranges));
2807 if (em & F_EDRAM0_ENABLE) {
2808 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
2809 r->size = G_EDRAM0_SIZE(addr_len) << 20;
2811 r->start = G_EDRAM0_BASE(addr_len) << 20;
2812 if (addr >= r->start &&
2813 addr + len <= r->start + r->size)
2819 if (em & F_EDRAM1_ENABLE) {
2820 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
2821 r->size = G_EDRAM1_SIZE(addr_len) << 20;
2823 r->start = G_EDRAM1_BASE(addr_len) << 20;
2824 if (addr >= r->start &&
2825 addr + len <= r->start + r->size)
2831 if (em & F_EXT_MEM_ENABLE) {
2832 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
2833 r->size = G_EXT_MEM_SIZE(addr_len) << 20;
2835 r->start = G_EXT_MEM_BASE(addr_len) << 20;
2836 if (addr >= r->start &&
2837 addr + len <= r->start + r->size)
2843 if (is_t5(sc) && em & F_EXT_MEM1_ENABLE) {
2844 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
2845 r->size = G_EXT_MEM1_SIZE(addr_len) << 20;
2847 r->start = G_EXT_MEM1_BASE(addr_len) << 20;
2848 if (addr >= r->start &&
2849 addr + len <= r->start + r->size)
2855 MPASS(n <= nitems(mem_ranges));
2858 /* Sort and merge the ranges. */
2859 qsort(mem_ranges, n, sizeof(struct t4_range), t4_range_cmp);
2861 /* Start from index 0 and examine the next n - 1 entries. */
2863 for (remaining = n - 1; remaining > 0; remaining--, r++) {
2865 MPASS(r->size > 0); /* r is a valid entry. */
2867 MPASS(next->size > 0); /* and so is the next one. */
2869 while (r->start + r->size >= next->start) {
2870 /* Merge the next one into the current entry. */
2871 r->size = max(r->start + r->size,
2872 next->start + next->size) - r->start;
2873 n--; /* One fewer entry in total. */
2874 if (--remaining == 0)
2875 goto done; /* short circuit */
2878 if (next != r + 1) {
2880 * Some entries were merged into r and next
2881 * points to the first valid entry that couldn't
2884 MPASS(next->size > 0); /* must be valid */
2885 memcpy(r + 1, next, remaining * sizeof(*r));
2888 * This so that the foo->size assertion in the
2889 * next iteration of the loop do the right
2890 * thing for entries that were pulled up and are
2893 MPASS(n < nitems(mem_ranges));
2894 bzero(&mem_ranges[n], (nitems(mem_ranges) - n) *
2895 sizeof(struct t4_range));
2900 /* Done merging the ranges. */
2903 for (i = 0; i < n; i++, r++) {
2904 if (addr >= r->start &&
2905 addr + len <= r->start + r->size)
2914 fwmtype_to_hwmtype(int mtype)
2918 case FW_MEMTYPE_EDC0:
2920 case FW_MEMTYPE_EDC1:
2922 case FW_MEMTYPE_EXTMEM:
2924 case FW_MEMTYPE_EXTMEM1:
2927 panic("%s: cannot translate fw mtype %d.", __func__, mtype);
2932 * Verify that the memory range specified by the memtype/offset/len pair is
2933 * valid and lies entirely within the memtype specified. The global address of
2934 * the start of the range is returned in addr.
2937 validate_mt_off_len(struct adapter *sc, int mtype, uint32_t off, uint32_t len,
2940 uint32_t em, addr_len, maddr;
2942 /* Memory can only be accessed in naturally aligned 4 byte units */
2943 if (off & 3 || len & 3 || len == 0)
2946 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
2947 switch (fwmtype_to_hwmtype(mtype)) {
2949 if (!(em & F_EDRAM0_ENABLE))
2951 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR);
2952 maddr = G_EDRAM0_BASE(addr_len) << 20;
2955 if (!(em & F_EDRAM1_ENABLE))
2957 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR);
2958 maddr = G_EDRAM1_BASE(addr_len) << 20;
2961 if (!(em & F_EXT_MEM_ENABLE))
2963 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
2964 maddr = G_EXT_MEM_BASE(addr_len) << 20;
2967 if (!is_t5(sc) || !(em & F_EXT_MEM1_ENABLE))
2969 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
2970 maddr = G_EXT_MEM1_BASE(addr_len) << 20;
2976 *addr = maddr + off; /* global address */
2977 return (validate_mem_range(sc, *addr, len));
2981 fixup_devlog_params(struct adapter *sc)
2983 struct devlog_params *dparams = &sc->params.devlog;
2986 rc = validate_mt_off_len(sc, dparams->memtype, dparams->start,
2987 dparams->size, &dparams->addr);
2993 update_nirq(struct intrs_and_queues *iaq, int nports)
2995 int extra = T4_EXTRA_INTR;
2998 iaq->nirq += nports * (iaq->nrxq + iaq->nofldrxq);
2999 iaq->nirq += nports * (iaq->num_vis - 1) *
3000 max(iaq->nrxq_vi, iaq->nnmrxq_vi);
3001 iaq->nirq += nports * (iaq->num_vis - 1) * iaq->nofldrxq_vi;
3005 * Adjust requirements to fit the number of interrupts available.
3008 calculate_iaq(struct adapter *sc, struct intrs_and_queues *iaq, int itype,
3012 const int nports = sc->params.nports;
3017 bzero(iaq, sizeof(*iaq));
3018 iaq->intr_type = itype;
3019 iaq->num_vis = t4_num_vis;
3020 iaq->ntxq = t4_ntxq;
3021 iaq->ntxq_vi = t4_ntxq_vi;
3022 iaq->nrxq = t4_nrxq;
3023 iaq->nrxq_vi = t4_nrxq_vi;
3025 if (is_offload(sc)) {
3026 iaq->nofldtxq = t4_nofldtxq;
3027 iaq->nofldtxq_vi = t4_nofldtxq_vi;
3028 iaq->nofldrxq = t4_nofldrxq;
3029 iaq->nofldrxq_vi = t4_nofldrxq_vi;
3033 iaq->nnmtxq_vi = t4_nnmtxq_vi;
3034 iaq->nnmrxq_vi = t4_nnmrxq_vi;
3037 update_nirq(iaq, nports);
3038 if (iaq->nirq <= navail &&
3039 (itype != INTR_MSI || powerof2(iaq->nirq))) {
3041 * This is the normal case -- there are enough interrupts for
3048 * If extra VIs have been configured try reducing their count and see if
3051 while (iaq->num_vis > 1) {
3053 update_nirq(iaq, nports);
3054 if (iaq->nirq <= navail &&
3055 (itype != INTR_MSI || powerof2(iaq->nirq))) {
3056 device_printf(sc->dev, "virtual interfaces per port "
3057 "reduced to %d from %d. nrxq=%u, nofldrxq=%u, "
3058 "nrxq_vi=%u nofldrxq_vi=%u, nnmrxq_vi=%u. "
3059 "itype %d, navail %u, nirq %d.\n",
3060 iaq->num_vis, t4_num_vis, iaq->nrxq, iaq->nofldrxq,
3061 iaq->nrxq_vi, iaq->nofldrxq_vi, iaq->nnmrxq_vi,
3062 itype, navail, iaq->nirq);
3068 * Extra VIs will not be created. Log a message if they were requested.
3070 MPASS(iaq->num_vis == 1);
3071 iaq->ntxq_vi = iaq->nrxq_vi = 0;
3072 iaq->nofldtxq_vi = iaq->nofldrxq_vi = 0;
3073 iaq->nnmtxq_vi = iaq->nnmrxq_vi = 0;
3074 if (iaq->num_vis != t4_num_vis) {
3075 device_printf(sc->dev, "extra virtual interfaces disabled. "
3076 "nrxq=%u, nofldrxq=%u, nrxq_vi=%u nofldrxq_vi=%u, "
3077 "nnmrxq_vi=%u. itype %d, navail %u, nirq %d.\n",
3078 iaq->nrxq, iaq->nofldrxq, iaq->nrxq_vi, iaq->nofldrxq_vi,
3079 iaq->nnmrxq_vi, itype, navail, iaq->nirq);
3083 * Keep reducing the number of NIC rx queues to the next lower power of
3084 * 2 (for even RSS distribution) and halving the TOE rx queues and see
3088 if (iaq->nrxq > 1) {
3091 } while (!powerof2(iaq->nrxq));
3093 if (iaq->nofldrxq > 1)
3094 iaq->nofldrxq >>= 1;
3096 old_nirq = iaq->nirq;
3097 update_nirq(iaq, nports);
3098 if (iaq->nirq <= navail &&
3099 (itype != INTR_MSI || powerof2(iaq->nirq))) {
3100 device_printf(sc->dev, "running with reduced number of "
3101 "rx queues because of shortage of interrupts. "
3102 "nrxq=%u, nofldrxq=%u. "
3103 "itype %d, navail %u, nirq %d.\n", iaq->nrxq,
3104 iaq->nofldrxq, itype, navail, iaq->nirq);
3107 } while (old_nirq != iaq->nirq);
3109 /* One interrupt for everything. Ugh. */
3110 device_printf(sc->dev, "running with minimal number of queues. "
3111 "itype %d, navail %u.\n", itype, navail);
3113 MPASS(iaq->nrxq == 1);
3115 if (iaq->nofldrxq > 1)
3118 MPASS(iaq->num_vis > 0);
3119 if (iaq->num_vis > 1) {
3120 MPASS(iaq->nrxq_vi > 0);
3121 MPASS(iaq->ntxq_vi > 0);
3123 MPASS(iaq->nirq > 0);
3124 MPASS(iaq->nrxq > 0);
3125 MPASS(iaq->ntxq > 0);
3126 if (itype == INTR_MSI) {
3127 MPASS(powerof2(iaq->nirq));
3132 cfg_itype_and_nqueues(struct adapter *sc, struct intrs_and_queues *iaq)
3134 int rc, itype, navail, nalloc;
3136 for (itype = INTR_MSIX; itype; itype >>= 1) {
3138 if ((itype & t4_intr_types) == 0)
3139 continue; /* not allowed */
3141 if (itype == INTR_MSIX)
3142 navail = pci_msix_count(sc->dev);
3143 else if (itype == INTR_MSI)
3144 navail = pci_msi_count(sc->dev);
3151 calculate_iaq(sc, iaq, itype, navail);
3154 if (itype == INTR_MSIX)
3155 rc = pci_alloc_msix(sc->dev, &nalloc);
3156 else if (itype == INTR_MSI)
3157 rc = pci_alloc_msi(sc->dev, &nalloc);
3159 if (rc == 0 && nalloc > 0) {
3160 if (nalloc == iaq->nirq)
3164 * Didn't get the number requested. Use whatever number
3165 * the kernel is willing to allocate.
3167 device_printf(sc->dev, "fewer vectors than requested, "
3168 "type=%d, req=%d, rcvd=%d; will downshift req.\n",
3169 itype, iaq->nirq, nalloc);
3170 pci_release_msi(sc->dev);
3175 device_printf(sc->dev,
3176 "failed to allocate vectors:%d, type=%d, req=%d, rcvd=%d\n",
3177 itype, rc, iaq->nirq, nalloc);
3180 device_printf(sc->dev,
3181 "failed to find a usable interrupt type. "
3182 "allowed=%d, msi-x=%d, msi=%d, intx=1", t4_intr_types,
3183 pci_msix_count(sc->dev), pci_msi_count(sc->dev));
3188 #define FW_VERSION(chip) ( \
3189 V_FW_HDR_FW_VER_MAJOR(chip##FW_VERSION_MAJOR) | \
3190 V_FW_HDR_FW_VER_MINOR(chip##FW_VERSION_MINOR) | \
3191 V_FW_HDR_FW_VER_MICRO(chip##FW_VERSION_MICRO) | \
3192 V_FW_HDR_FW_VER_BUILD(chip##FW_VERSION_BUILD))
3193 #define FW_INTFVER(chip, intf) (chip##FW_HDR_INTFVER_##intf)
3199 struct fw_hdr fw_hdr; /* XXX: waste of space, need a sparse struct */
3203 .kld_name = "t4fw_cfg",
3204 .fw_mod_name = "t4fw",
3206 .chip = FW_HDR_CHIP_T4,
3207 .fw_ver = htobe32(FW_VERSION(T4)),
3208 .intfver_nic = FW_INTFVER(T4, NIC),
3209 .intfver_vnic = FW_INTFVER(T4, VNIC),
3210 .intfver_ofld = FW_INTFVER(T4, OFLD),
3211 .intfver_ri = FW_INTFVER(T4, RI),
3212 .intfver_iscsipdu = FW_INTFVER(T4, ISCSIPDU),
3213 .intfver_iscsi = FW_INTFVER(T4, ISCSI),
3214 .intfver_fcoepdu = FW_INTFVER(T4, FCOEPDU),
3215 .intfver_fcoe = FW_INTFVER(T4, FCOE),
3219 .kld_name = "t5fw_cfg",
3220 .fw_mod_name = "t5fw",
3222 .chip = FW_HDR_CHIP_T5,
3223 .fw_ver = htobe32(FW_VERSION(T5)),
3224 .intfver_nic = FW_INTFVER(T5, NIC),
3225 .intfver_vnic = FW_INTFVER(T5, VNIC),
3226 .intfver_ofld = FW_INTFVER(T5, OFLD),
3227 .intfver_ri = FW_INTFVER(T5, RI),
3228 .intfver_iscsipdu = FW_INTFVER(T5, ISCSIPDU),
3229 .intfver_iscsi = FW_INTFVER(T5, ISCSI),
3230 .intfver_fcoepdu = FW_INTFVER(T5, FCOEPDU),
3231 .intfver_fcoe = FW_INTFVER(T5, FCOE),
3235 .kld_name = "t6fw_cfg",
3236 .fw_mod_name = "t6fw",
3238 .chip = FW_HDR_CHIP_T6,
3239 .fw_ver = htobe32(FW_VERSION(T6)),
3240 .intfver_nic = FW_INTFVER(T6, NIC),
3241 .intfver_vnic = FW_INTFVER(T6, VNIC),
3242 .intfver_ofld = FW_INTFVER(T6, OFLD),
3243 .intfver_ri = FW_INTFVER(T6, RI),
3244 .intfver_iscsipdu = FW_INTFVER(T6, ISCSIPDU),
3245 .intfver_iscsi = FW_INTFVER(T6, ISCSI),
3246 .intfver_fcoepdu = FW_INTFVER(T6, FCOEPDU),
3247 .intfver_fcoe = FW_INTFVER(T6, FCOE),
3252 static struct fw_info *
3253 find_fw_info(int chip)
3257 for (i = 0; i < nitems(fw_info); i++) {
3258 if (fw_info[i].chip == chip)
3259 return (&fw_info[i]);
3265 * Is the given firmware API compatible with the one the driver was compiled
3269 fw_compatible(const struct fw_hdr *hdr1, const struct fw_hdr *hdr2)
3272 /* short circuit if it's the exact same firmware version */
3273 if (hdr1->chip == hdr2->chip && hdr1->fw_ver == hdr2->fw_ver)
3277 * XXX: Is this too conservative? Perhaps I should limit this to the
3278 * features that are supported in the driver.
3280 #define SAME_INTF(x) (hdr1->intfver_##x == hdr2->intfver_##x)
3281 if (hdr1->chip == hdr2->chip && SAME_INTF(nic) && SAME_INTF(vnic) &&
3282 SAME_INTF(ofld) && SAME_INTF(ri) && SAME_INTF(iscsipdu) &&
3283 SAME_INTF(iscsi) && SAME_INTF(fcoepdu) && SAME_INTF(fcoe))
3291 * The firmware in the KLD is usable, but should it be installed? This routine
3292 * explains itself in detail if it indicates the KLD firmware should be
3296 should_install_kld_fw(struct adapter *sc, int card_fw_usable, int k, int c)
3300 if (!card_fw_usable) {
3301 reason = "incompatible or unusable";
3306 reason = "older than the version bundled with this driver";
3310 if (t4_fw_install == 2 && k != c) {
3311 reason = "different than the version bundled with this driver";
3318 if (t4_fw_install == 0) {
3319 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
3320 "but the driver is prohibited from installing a different "
3321 "firmware on the card.\n",
3322 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
3323 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason);
3328 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, "
3329 "installing firmware %u.%u.%u.%u on card.\n",
3330 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
3331 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason,
3332 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
3333 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
3339 * Establish contact with the firmware and determine if we are the master driver
3340 * or not, and whether we are responsible for chip initialization.
3343 prep_firmware(struct adapter *sc)
3345 const struct firmware *fw = NULL, *default_cfg;
3346 int rc, pf, card_fw_usable, kld_fw_usable, need_fw_reset = 1;
3347 enum dev_state state;
3348 struct fw_info *fw_info;
3349 struct fw_hdr *card_fw; /* fw on the card */
3350 const struct fw_hdr *kld_fw; /* fw in the KLD */
3351 const struct fw_hdr *drv_fw; /* fw header the driver was compiled
3354 /* This is the firmware whose headers the driver was compiled against */
3355 fw_info = find_fw_info(chip_id(sc));
3356 if (fw_info == NULL) {
3357 device_printf(sc->dev,
3358 "unable to look up firmware information for chip %d.\n",
3362 drv_fw = &fw_info->fw_hdr;
3365 * The firmware KLD contains many modules. The KLD name is also the
3366 * name of the module that contains the default config file.
3368 default_cfg = firmware_get(fw_info->kld_name);
3370 /* This is the firmware in the KLD */
3371 fw = firmware_get(fw_info->fw_mod_name);
3373 kld_fw = (const void *)fw->data;
3374 kld_fw_usable = fw_compatible(drv_fw, kld_fw);
3380 /* Read the header of the firmware on the card */
3381 card_fw = malloc(sizeof(*card_fw), M_CXGBE, M_ZERO | M_WAITOK);
3382 rc = -t4_read_flash(sc, FLASH_FW_START,
3383 sizeof (*card_fw) / sizeof (uint32_t), (uint32_t *)card_fw, 1);
3385 card_fw_usable = fw_compatible(drv_fw, (const void*)card_fw);
3386 if (card_fw->fw_ver == be32toh(0xffffffff)) {
3387 uint32_t d = be32toh(kld_fw->fw_ver);
3389 if (!kld_fw_usable) {
3390 device_printf(sc->dev,
3391 "no firmware on the card and no usable "
3392 "firmware bundled with the driver.\n");
3395 } else if (t4_fw_install == 0) {
3396 device_printf(sc->dev,
3397 "no firmware on the card and the driver "
3398 "is prohibited from installing new "
3404 device_printf(sc->dev, "no firmware on the card, "
3405 "installing firmware %d.%d.%d.%d\n",
3406 G_FW_HDR_FW_VER_MAJOR(d), G_FW_HDR_FW_VER_MINOR(d),
3407 G_FW_HDR_FW_VER_MICRO(d), G_FW_HDR_FW_VER_BUILD(d));
3408 rc = t4_fw_forceinstall(sc, fw->data, fw->datasize);
3411 device_printf(sc->dev,
3412 "firmware install failed: %d.\n", rc);
3415 memcpy(card_fw, kld_fw, sizeof(*card_fw));
3420 device_printf(sc->dev,
3421 "Unable to read card's firmware header: %d\n", rc);
3425 /* Contact firmware. */
3426 rc = t4_fw_hello(sc, sc->mbox, sc->mbox, MASTER_MAY, &state);
3427 if (rc < 0 || state == DEV_STATE_ERR) {
3429 device_printf(sc->dev,
3430 "failed to connect to the firmware: %d, %d.\n", rc, state);
3435 sc->flags |= MASTER_PF;
3436 else if (state == DEV_STATE_UNINIT) {
3438 * We didn't get to be the master so we definitely won't be
3439 * configuring the chip. It's a bug if someone else hasn't
3440 * configured it already.
3442 device_printf(sc->dev, "couldn't be master(%d), "
3443 "device not already initialized either(%d).\n", rc, state);
3448 if (card_fw_usable && card_fw->fw_ver == drv_fw->fw_ver &&
3449 (!kld_fw_usable || kld_fw->fw_ver == drv_fw->fw_ver)) {
3451 * Common case: the firmware on the card is an exact match and
3452 * the KLD is an exact match too, or the KLD is
3453 * absent/incompatible. Note that t4_fw_install = 2 is ignored
3454 * here -- use cxgbetool loadfw if you want to reinstall the
3455 * same firmware as the one on the card.
3457 } else if (kld_fw_usable && state == DEV_STATE_UNINIT &&
3458 should_install_kld_fw(sc, card_fw_usable, be32toh(kld_fw->fw_ver),
3459 be32toh(card_fw->fw_ver))) {
3461 rc = -t4_fw_upgrade(sc, sc->mbox, fw->data, fw->datasize, 0);
3463 device_printf(sc->dev,
3464 "failed to install firmware: %d\n", rc);
3468 /* Installed successfully, update the cached header too. */
3469 memcpy(card_fw, kld_fw, sizeof(*card_fw));
3471 need_fw_reset = 0; /* already reset as part of load_fw */
3474 if (!card_fw_usable) {
3477 d = ntohl(drv_fw->fw_ver);
3478 c = ntohl(card_fw->fw_ver);
3479 k = kld_fw ? ntohl(kld_fw->fw_ver) : 0;
3481 device_printf(sc->dev, "Cannot find a usable firmware: "
3482 "fw_install %d, chip state %d, "
3483 "driver compiled with %d.%d.%d.%d, "
3484 "card has %d.%d.%d.%d, KLD has %d.%d.%d.%d\n",
3485 t4_fw_install, state,
3486 G_FW_HDR_FW_VER_MAJOR(d), G_FW_HDR_FW_VER_MINOR(d),
3487 G_FW_HDR_FW_VER_MICRO(d), G_FW_HDR_FW_VER_BUILD(d),
3488 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c),
3489 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c),
3490 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k),
3491 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k));
3497 if (need_fw_reset &&
3498 (rc = -t4_fw_reset(sc, sc->mbox, F_PIORSTMODE | F_PIORST)) != 0) {
3499 device_printf(sc->dev, "firmware reset failed: %d.\n", rc);
3500 if (rc != ETIMEDOUT && rc != EIO)
3501 t4_fw_bye(sc, sc->mbox);
3506 rc = get_params__pre_init(sc);
3508 goto done; /* error message displayed already */
3510 /* Partition adapter resources as specified in the config file. */
3511 if (state == DEV_STATE_UNINIT) {
3513 KASSERT(sc->flags & MASTER_PF,
3514 ("%s: trying to change chip settings when not master.",
3517 rc = partition_resources(sc, default_cfg, fw_info->kld_name);
3519 goto done; /* error message displayed already */
3521 t4_tweak_chip_settings(sc);
3523 /* get basic stuff going */
3524 rc = -t4_fw_initialize(sc, sc->mbox);
3526 device_printf(sc->dev, "fw init failed: %d.\n", rc);
3530 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "pf%d", pf);
3535 free(card_fw, M_CXGBE);
3537 firmware_put(fw, FIRMWARE_UNLOAD);
3538 if (default_cfg != NULL)
3539 firmware_put(default_cfg, FIRMWARE_UNLOAD);
3544 #define FW_PARAM_DEV(param) \
3545 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
3546 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
3547 #define FW_PARAM_PFVF(param) \
3548 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
3549 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param))
3552 * Partition chip resources for use between various PFs, VFs, etc.
3555 partition_resources(struct adapter *sc, const struct firmware *default_cfg,
3556 const char *name_prefix)
3558 const struct firmware *cfg = NULL;
3560 struct fw_caps_config_cmd caps;
3561 uint32_t mtype, moff, finicsum, cfcsum;
3564 * Figure out what configuration file to use. Pick the default config
3565 * file for the card if the user hasn't specified one explicitly.
3567 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", t4_cfg_file);
3568 if (strncmp(t4_cfg_file, DEFAULT_CF, sizeof(t4_cfg_file)) == 0) {
3569 /* Card specific overrides go here. */
3570 if (pci_get_device(sc->dev) == 0x440a)
3571 snprintf(sc->cfg_file, sizeof(sc->cfg_file), UWIRE_CF);
3573 snprintf(sc->cfg_file, sizeof(sc->cfg_file), FPGA_CF);
3574 } else if (strncmp(t4_cfg_file, BUILTIN_CF, sizeof(t4_cfg_file)) == 0)
3575 goto use_built_in_config; /* go straight to config. */
3578 * We need to load another module if the profile is anything except
3579 * "default" or "flash".
3581 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) != 0 &&
3582 strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
3585 snprintf(s, sizeof(s), "%s_%s", name_prefix, sc->cfg_file);
3586 cfg = firmware_get(s);
3588 if (default_cfg != NULL) {
3589 device_printf(sc->dev,
3590 "unable to load module \"%s\" for "
3591 "configuration profile \"%s\", will use "
3592 "the default config file instead.\n",
3594 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
3597 device_printf(sc->dev,
3598 "unable to load module \"%s\" for "
3599 "configuration profile \"%s\", will use "
3600 "the config file on the card's flash "
3601 "instead.\n", s, sc->cfg_file);
3602 snprintf(sc->cfg_file, sizeof(sc->cfg_file),
3608 if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) == 0 &&
3609 default_cfg == NULL) {
3610 device_printf(sc->dev,
3611 "default config file not available, will use the config "
3612 "file on the card's flash instead.\n");
3613 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", FLASH_CF);
3616 if (strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
3618 const uint32_t *cfdata;
3619 uint32_t param, val, addr;
3621 KASSERT(cfg != NULL || default_cfg != NULL,
3622 ("%s: no config to upload", __func__));
3625 * Ask the firmware where it wants us to upload the config file.
3627 param = FW_PARAM_DEV(CF);
3628 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
3630 /* No support for config file? Shouldn't happen. */
3631 device_printf(sc->dev,
3632 "failed to query config file location: %d.\n", rc);
3635 mtype = G_FW_PARAMS_PARAM_Y(val);
3636 moff = G_FW_PARAMS_PARAM_Z(val) << 16;
3639 * XXX: sheer laziness. We deliberately added 4 bytes of
3640 * useless stuffing/comments at the end of the config file so
3641 * it's ok to simply throw away the last remaining bytes when
3642 * the config file is not an exact multiple of 4. This also
3643 * helps with the validate_mt_off_len check.
3646 cflen = cfg->datasize & ~3;
3649 cflen = default_cfg->datasize & ~3;
3650 cfdata = default_cfg->data;
3653 if (cflen > FLASH_CFG_MAX_SIZE) {
3654 device_printf(sc->dev,
3655 "config file too long (%d, max allowed is %d). "
3656 "Will try to use the config on the card, if any.\n",
3657 cflen, FLASH_CFG_MAX_SIZE);
3658 goto use_config_on_flash;
3661 rc = validate_mt_off_len(sc, mtype, moff, cflen, &addr);
3663 device_printf(sc->dev,
3664 "%s: addr (%d/0x%x) or len %d is not valid: %d. "
3665 "Will try to use the config on the card, if any.\n",
3666 __func__, mtype, moff, cflen, rc);
3667 goto use_config_on_flash;
3669 write_via_memwin(sc, 2, addr, cfdata, cflen);
3671 use_config_on_flash:
3672 mtype = FW_MEMTYPE_FLASH;
3673 moff = t4_flash_cfg_addr(sc);
3676 bzero(&caps, sizeof(caps));
3677 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3678 F_FW_CMD_REQUEST | F_FW_CMD_READ);
3679 caps.cfvalid_to_len16 = htobe32(F_FW_CAPS_CONFIG_CMD_CFVALID |
3680 V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
3681 V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(moff >> 16) | FW_LEN16(caps));
3682 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
3684 device_printf(sc->dev,
3685 "failed to pre-process config file: %d "
3686 "(mtype %d, moff 0x%x). Will reset the firmware and retry "
3687 "with the built-in configuration.\n", rc, mtype, moff);
3689 rc = -t4_fw_reset(sc, sc->mbox, F_PIORSTMODE | F_PIORST);
3691 device_printf(sc->dev,
3692 "firmware reset failed: %d.\n", rc);
3693 if (rc != ETIMEDOUT && rc != EIO) {
3694 t4_fw_bye(sc, sc->mbox);
3695 sc->flags &= ~FW_OK;
3699 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", "built-in");
3700 use_built_in_config:
3701 bzero(&caps, sizeof(caps));
3702 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3703 F_FW_CMD_REQUEST | F_FW_CMD_READ);
3704 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
3705 rc = t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
3707 device_printf(sc->dev,
3708 "built-in configuration failed: %d.\n", rc);
3713 finicsum = be32toh(caps.finicsum);
3714 cfcsum = be32toh(caps.cfcsum);
3715 if (finicsum != cfcsum) {
3716 device_printf(sc->dev,
3717 "WARNING: config file checksum mismatch: %08x %08x\n",
3720 sc->cfcsum = cfcsum;
3722 #define LIMIT_CAPS(x) do { \
3723 caps.x &= htobe16(t4_##x##_allowed); \
3727 * Let the firmware know what features will (not) be used so it can tune
3728 * things accordingly.
3730 LIMIT_CAPS(nbmcaps);
3731 LIMIT_CAPS(linkcaps);
3732 LIMIT_CAPS(switchcaps);
3733 LIMIT_CAPS(niccaps);
3734 LIMIT_CAPS(toecaps);
3735 LIMIT_CAPS(rdmacaps);
3736 LIMIT_CAPS(cryptocaps);
3737 LIMIT_CAPS(iscsicaps);
3738 LIMIT_CAPS(fcoecaps);
3741 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3742 F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
3743 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
3744 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), NULL);
3746 device_printf(sc->dev,
3747 "failed to process config file: %d.\n", rc);
3751 firmware_put(cfg, FIRMWARE_UNLOAD);
3756 * Retrieve parameters that are needed (or nice to have) very early.
3759 get_params__pre_init(struct adapter *sc)
3762 uint32_t param[2], val[2];
3764 t4_get_version_info(sc);
3766 snprintf(sc->fw_version, sizeof(sc->fw_version), "%u.%u.%u.%u",
3767 G_FW_HDR_FW_VER_MAJOR(sc->params.fw_vers),
3768 G_FW_HDR_FW_VER_MINOR(sc->params.fw_vers),
3769 G_FW_HDR_FW_VER_MICRO(sc->params.fw_vers),
3770 G_FW_HDR_FW_VER_BUILD(sc->params.fw_vers));
3772 snprintf(sc->bs_version, sizeof(sc->bs_version), "%u.%u.%u.%u",
3773 G_FW_HDR_FW_VER_MAJOR(sc->params.bs_vers),
3774 G_FW_HDR_FW_VER_MINOR(sc->params.bs_vers),
3775 G_FW_HDR_FW_VER_MICRO(sc->params.bs_vers),
3776 G_FW_HDR_FW_VER_BUILD(sc->params.bs_vers));
3778 snprintf(sc->tp_version, sizeof(sc->tp_version), "%u.%u.%u.%u",
3779 G_FW_HDR_FW_VER_MAJOR(sc->params.tp_vers),
3780 G_FW_HDR_FW_VER_MINOR(sc->params.tp_vers),
3781 G_FW_HDR_FW_VER_MICRO(sc->params.tp_vers),
3782 G_FW_HDR_FW_VER_BUILD(sc->params.tp_vers));
3784 snprintf(sc->er_version, sizeof(sc->er_version), "%u.%u.%u.%u",
3785 G_FW_HDR_FW_VER_MAJOR(sc->params.er_vers),
3786 G_FW_HDR_FW_VER_MINOR(sc->params.er_vers),
3787 G_FW_HDR_FW_VER_MICRO(sc->params.er_vers),
3788 G_FW_HDR_FW_VER_BUILD(sc->params.er_vers));
3790 param[0] = FW_PARAM_DEV(PORTVEC);
3791 param[1] = FW_PARAM_DEV(CCLK);
3792 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
3794 device_printf(sc->dev,
3795 "failed to query parameters (pre_init): %d.\n", rc);
3799 sc->params.portvec = val[0];
3800 sc->params.nports = bitcount32(val[0]);
3801 sc->params.vpd.cclk = val[1];
3803 /* Read device log parameters. */
3804 rc = -t4_init_devlog_params(sc, 1);
3806 fixup_devlog_params(sc);
3808 device_printf(sc->dev,
3809 "failed to get devlog parameters: %d.\n", rc);
3810 rc = 0; /* devlog isn't critical for device operation */
3817 * Retrieve various parameters that are of interest to the driver. The device
3818 * has been initialized by the firmware at this point.
3821 get_params__post_init(struct adapter *sc)
3824 uint32_t param[7], val[7];
3825 struct fw_caps_config_cmd caps;
3827 param[0] = FW_PARAM_PFVF(IQFLINT_START);
3828 param[1] = FW_PARAM_PFVF(EQ_START);
3829 param[2] = FW_PARAM_PFVF(FILTER_START);
3830 param[3] = FW_PARAM_PFVF(FILTER_END);
3831 param[4] = FW_PARAM_PFVF(L2T_START);
3832 param[5] = FW_PARAM_PFVF(L2T_END);
3833 param[6] = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
3834 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) |
3835 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_VDD);
3836 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 7, param, val);
3838 device_printf(sc->dev,
3839 "failed to query parameters (post_init): %d.\n", rc);
3843 sc->sge.iq_start = val[0];
3844 sc->sge.eq_start = val[1];
3845 sc->tids.ftid_base = val[2];
3846 sc->tids.nftids = val[3] - val[2] + 1;
3847 sc->params.ftid_min = val[2];
3848 sc->params.ftid_max = val[3];
3849 sc->vres.l2t.start = val[4];
3850 sc->vres.l2t.size = val[5] - val[4] + 1;
3851 KASSERT(sc->vres.l2t.size <= L2T_SIZE,
3852 ("%s: L2 table size (%u) larger than expected (%u)",
3853 __func__, sc->vres.l2t.size, L2T_SIZE));
3854 sc->params.core_vdd = val[6];
3857 * MPSBGMAP is queried separately because only recent firmwares support
3858 * it as a parameter and we don't want the compound query above to fail
3859 * on older firmwares.
3861 param[0] = FW_PARAM_DEV(MPSBGMAP);
3863 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val);
3865 sc->params.mps_bg_map = val[0];
3867 sc->params.mps_bg_map = 0;
3869 /* get capabilites */
3870 bzero(&caps, sizeof(caps));
3871 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
3872 F_FW_CMD_REQUEST | F_FW_CMD_READ);
3873 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
3874 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
3876 device_printf(sc->dev,
3877 "failed to get card capabilities: %d.\n", rc);
3881 #define READ_CAPS(x) do { \
3882 sc->x = htobe16(caps.x); \
3885 READ_CAPS(linkcaps);
3886 READ_CAPS(switchcaps);
3889 READ_CAPS(rdmacaps);
3890 READ_CAPS(cryptocaps);
3891 READ_CAPS(iscsicaps);
3892 READ_CAPS(fcoecaps);
3895 * The firmware attempts memfree TOE configuration for -SO cards and
3896 * will report toecaps=0 if it runs out of resources (this depends on
3897 * the config file). It may not report 0 for other capabilities
3898 * dependent on the TOE in this case. Set them to 0 here so that the
3899 * driver doesn't bother tracking resources that will never be used.
3901 if (sc->toecaps == 0) {
3906 if (sc->niccaps & FW_CAPS_CONFIG_NIC_ETHOFLD) {
3907 param[0] = FW_PARAM_PFVF(ETHOFLD_START);
3908 param[1] = FW_PARAM_PFVF(ETHOFLD_END);
3909 param[2] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
3910 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 3, param, val);
3912 device_printf(sc->dev,
3913 "failed to query NIC parameters: %d.\n", rc);
3916 sc->tids.etid_base = val[0];
3917 sc->params.etid_min = val[0];
3918 sc->tids.netids = val[1] - val[0] + 1;
3919 sc->params.netids = sc->tids.netids;
3920 sc->params.eo_wr_cred = val[2];
3921 sc->params.ethoffload = 1;
3925 /* query offload-related parameters */
3926 param[0] = FW_PARAM_DEV(NTID);
3927 param[1] = FW_PARAM_PFVF(SERVER_START);
3928 param[2] = FW_PARAM_PFVF(SERVER_END);
3929 param[3] = FW_PARAM_PFVF(TDDP_START);
3930 param[4] = FW_PARAM_PFVF(TDDP_END);
3931 param[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
3932 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
3934 device_printf(sc->dev,
3935 "failed to query TOE parameters: %d.\n", rc);
3938 sc->tids.ntids = val[0];
3939 sc->tids.natids = min(sc->tids.ntids / 2, MAX_ATIDS);
3940 sc->tids.stid_base = val[1];
3941 sc->tids.nstids = val[2] - val[1] + 1;
3942 sc->vres.ddp.start = val[3];
3943 sc->vres.ddp.size = val[4] - val[3] + 1;
3944 sc->params.ofldq_wr_cred = val[5];
3945 sc->params.offload = 1;
3948 param[0] = FW_PARAM_PFVF(STAG_START);
3949 param[1] = FW_PARAM_PFVF(STAG_END);
3950 param[2] = FW_PARAM_PFVF(RQ_START);
3951 param[3] = FW_PARAM_PFVF(RQ_END);
3952 param[4] = FW_PARAM_PFVF(PBL_START);
3953 param[5] = FW_PARAM_PFVF(PBL_END);
3954 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
3956 device_printf(sc->dev,
3957 "failed to query RDMA parameters(1): %d.\n", rc);
3960 sc->vres.stag.start = val[0];
3961 sc->vres.stag.size = val[1] - val[0] + 1;
3962 sc->vres.rq.start = val[2];
3963 sc->vres.rq.size = val[3] - val[2] + 1;
3964 sc->vres.pbl.start = val[4];
3965 sc->vres.pbl.size = val[5] - val[4] + 1;
3967 param[0] = FW_PARAM_PFVF(SQRQ_START);
3968 param[1] = FW_PARAM_PFVF(SQRQ_END);
3969 param[2] = FW_PARAM_PFVF(CQ_START);
3970 param[3] = FW_PARAM_PFVF(CQ_END);
3971 param[4] = FW_PARAM_PFVF(OCQ_START);
3972 param[5] = FW_PARAM_PFVF(OCQ_END);
3973 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val);
3975 device_printf(sc->dev,
3976 "failed to query RDMA parameters(2): %d.\n", rc);
3979 sc->vres.qp.start = val[0];
3980 sc->vres.qp.size = val[1] - val[0] + 1;
3981 sc->vres.cq.start = val[2];
3982 sc->vres.cq.size = val[3] - val[2] + 1;
3983 sc->vres.ocq.start = val[4];
3984 sc->vres.ocq.size = val[5] - val[4] + 1;
3986 param[0] = FW_PARAM_PFVF(SRQ_START);
3987 param[1] = FW_PARAM_PFVF(SRQ_END);
3988 param[2] = FW_PARAM_DEV(MAXORDIRD_QP);
3989 param[3] = FW_PARAM_DEV(MAXIRD_ADAPTER);
3990 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 4, param, val);
3992 device_printf(sc->dev,
3993 "failed to query RDMA parameters(3): %d.\n", rc);
3996 sc->vres.srq.start = val[0];
3997 sc->vres.srq.size = val[1] - val[0] + 1;
3998 sc->params.max_ordird_qp = val[2];
3999 sc->params.max_ird_adapter = val[3];
4001 if (sc->iscsicaps) {
4002 param[0] = FW_PARAM_PFVF(ISCSI_START);
4003 param[1] = FW_PARAM_PFVF(ISCSI_END);
4004 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
4006 device_printf(sc->dev,
4007 "failed to query iSCSI parameters: %d.\n", rc);
4010 sc->vres.iscsi.start = val[0];
4011 sc->vres.iscsi.size = val[1] - val[0] + 1;
4013 if (sc->cryptocaps & FW_CAPS_CONFIG_TLSKEYS) {
4014 param[0] = FW_PARAM_PFVF(TLS_START);
4015 param[1] = FW_PARAM_PFVF(TLS_END);
4016 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val);
4018 device_printf(sc->dev,
4019 "failed to query TLS parameters: %d.\n", rc);
4022 sc->vres.key.start = val[0];
4023 sc->vres.key.size = val[1] - val[0] + 1;
4026 t4_init_sge_params(sc);
4029 * We've got the params we wanted to query via the firmware. Now grab
4030 * some others directly from the chip.
4032 rc = t4_read_chip_settings(sc);
4038 set_params__post_init(struct adapter *sc)
4040 uint32_t param, val;
4045 /* ask for encapsulated CPLs */
4046 param = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
4048 (void)t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
4050 /* Enable 32b port caps if the firmware supports it. */
4051 param = FW_PARAM_PFVF(PORT_CAPS32);
4053 if (t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val) == 0)
4054 sc->params.port_caps32 = 1;
4058 * Override the TOE timers with user provided tunables. This is not the
4059 * recommended way to change the timers (the firmware config file is) so
4060 * these tunables are not documented.
4062 * All the timer tunables are in microseconds.
4064 if (t4_toe_keepalive_idle != 0) {
4065 v = us_to_tcp_ticks(sc, t4_toe_keepalive_idle);
4066 v &= M_KEEPALIVEIDLE;
4067 t4_set_reg_field(sc, A_TP_KEEP_IDLE,
4068 V_KEEPALIVEIDLE(M_KEEPALIVEIDLE), V_KEEPALIVEIDLE(v));
4070 if (t4_toe_keepalive_interval != 0) {
4071 v = us_to_tcp_ticks(sc, t4_toe_keepalive_interval);
4072 v &= M_KEEPALIVEINTVL;
4073 t4_set_reg_field(sc, A_TP_KEEP_INTVL,
4074 V_KEEPALIVEINTVL(M_KEEPALIVEINTVL), V_KEEPALIVEINTVL(v));
4076 if (t4_toe_keepalive_count != 0) {
4077 v = t4_toe_keepalive_count & M_KEEPALIVEMAXR2;
4078 t4_set_reg_field(sc, A_TP_SHIFT_CNT,
4079 V_KEEPALIVEMAXR1(M_KEEPALIVEMAXR1) |
4080 V_KEEPALIVEMAXR2(M_KEEPALIVEMAXR2),
4081 V_KEEPALIVEMAXR1(1) | V_KEEPALIVEMAXR2(v));
4083 if (t4_toe_rexmt_min != 0) {
4084 v = us_to_tcp_ticks(sc, t4_toe_rexmt_min);
4086 t4_set_reg_field(sc, A_TP_RXT_MIN,
4087 V_RXTMIN(M_RXTMIN), V_RXTMIN(v));
4089 if (t4_toe_rexmt_max != 0) {
4090 v = us_to_tcp_ticks(sc, t4_toe_rexmt_max);
4092 t4_set_reg_field(sc, A_TP_RXT_MAX,
4093 V_RXTMAX(M_RXTMAX), V_RXTMAX(v));
4095 if (t4_toe_rexmt_count != 0) {
4096 v = t4_toe_rexmt_count & M_RXTSHIFTMAXR2;
4097 t4_set_reg_field(sc, A_TP_SHIFT_CNT,
4098 V_RXTSHIFTMAXR1(M_RXTSHIFTMAXR1) |
4099 V_RXTSHIFTMAXR2(M_RXTSHIFTMAXR2),
4100 V_RXTSHIFTMAXR1(1) | V_RXTSHIFTMAXR2(v));
4102 for (i = 0; i < nitems(t4_toe_rexmt_backoff); i++) {
4103 if (t4_toe_rexmt_backoff[i] != -1) {
4104 v = t4_toe_rexmt_backoff[i] & M_TIMERBACKOFFINDEX0;
4105 shift = (i & 3) << 3;
4106 t4_set_reg_field(sc, A_TP_TCP_BACKOFF_REG0 + (i & ~3),
4107 M_TIMERBACKOFFINDEX0 << shift, v << shift);
4114 #undef FW_PARAM_PFVF
4118 t4_set_desc(struct adapter *sc)
4121 struct adapter_params *p = &sc->params;
4123 snprintf(buf, sizeof(buf), "Chelsio %s", p->vpd.id);
4125 device_set_desc_copy(sc->dev, buf);
4129 ifmedia_add4(struct ifmedia *ifm, int m)
4132 ifmedia_add(ifm, m, 0, NULL);
4133 ifmedia_add(ifm, m | IFM_ETH_TXPAUSE, 0, NULL);
4134 ifmedia_add(ifm, m | IFM_ETH_RXPAUSE, 0, NULL);
4135 ifmedia_add(ifm, m | IFM_ETH_TXPAUSE | IFM_ETH_RXPAUSE, 0, NULL);
4139 * This is the selected media, which is not quite the same as the active media.
4140 * The media line in ifconfig is "media: Ethernet selected (active)" if selected
4141 * and active are not the same, and "media: Ethernet selected" otherwise.
4144 set_current_media(struct port_info *pi)
4146 struct link_config *lc;
4147 struct ifmedia *ifm;
4151 PORT_LOCK_ASSERT_OWNED(pi);
4153 /* Leave current media alone if it's already set to IFM_NONE. */
4155 if (ifm->ifm_cur != NULL &&
4156 IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_NONE)
4160 if (lc->requested_aneg != AUTONEG_DISABLE &&
4161 lc->supported & FW_PORT_CAP32_ANEG) {
4162 ifmedia_set(ifm, IFM_ETHER | IFM_AUTO);
4165 mword = IFM_ETHER | IFM_FDX;
4166 if (lc->requested_fc & PAUSE_TX)
4167 mword |= IFM_ETH_TXPAUSE;
4168 if (lc->requested_fc & PAUSE_RX)
4169 mword |= IFM_ETH_RXPAUSE;
4170 if (lc->requested_speed == 0)
4171 speed = port_top_speed(pi) * 1000; /* Gbps -> Mbps */
4173 speed = lc->requested_speed;
4174 mword |= port_mword(pi, speed_to_fwcap(speed));
4175 ifmedia_set(ifm, mword);
4179 * Returns true if the ifmedia list for the port cannot change.
4182 fixed_ifmedia(struct port_info *pi)
4185 return (pi->port_type == FW_PORT_TYPE_BT_SGMII ||
4186 pi->port_type == FW_PORT_TYPE_BT_XFI ||
4187 pi->port_type == FW_PORT_TYPE_BT_XAUI ||
4188 pi->port_type == FW_PORT_TYPE_KX4 ||
4189 pi->port_type == FW_PORT_TYPE_KX ||
4190 pi->port_type == FW_PORT_TYPE_KR ||
4191 pi->port_type == FW_PORT_TYPE_BP_AP ||
4192 pi->port_type == FW_PORT_TYPE_BP4_AP ||
4193 pi->port_type == FW_PORT_TYPE_BP40_BA ||
4194 pi->port_type == FW_PORT_TYPE_KR4_100G ||
4195 pi->port_type == FW_PORT_TYPE_KR_SFP28 ||
4196 pi->port_type == FW_PORT_TYPE_KR_XLAUI);
4200 build_medialist(struct port_info *pi)
4203 int unknown, mword, bit;
4204 struct link_config *lc;
4205 struct ifmedia *ifm;
4207 PORT_LOCK_ASSERT_OWNED(pi);
4209 if (pi->flags & FIXED_IFMEDIA)
4213 * Rebuild the ifmedia list.
4216 ifmedia_removeall(ifm);
4218 ss = G_FW_PORT_CAP32_SPEED(lc->supported); /* Supported Speeds */
4219 if (__predict_false(ss == 0)) { /* not supposed to happen. */
4222 MPASS(LIST_EMPTY(&ifm->ifm_list));
4223 ifmedia_add(ifm, IFM_ETHER | IFM_NONE, 0, NULL);
4224 ifmedia_set(ifm, IFM_ETHER | IFM_NONE);
4229 for (bit = S_FW_PORT_CAP32_SPEED; bit < fls(ss); bit++) {
4231 MPASS(speed & M_FW_PORT_CAP32_SPEED);
4233 mword = port_mword(pi, speed);
4234 if (mword == IFM_NONE) {
4236 } else if (mword == IFM_UNKNOWN)
4239 ifmedia_add4(ifm, IFM_ETHER | IFM_FDX | mword);
4242 if (unknown > 0) /* Add one unknown for all unknown media types. */
4243 ifmedia_add4(ifm, IFM_ETHER | IFM_FDX | IFM_UNKNOWN);
4244 if (lc->supported & FW_PORT_CAP32_ANEG)
4245 ifmedia_add(ifm, IFM_ETHER | IFM_AUTO, 0, NULL);
4247 set_current_media(pi);
4251 * Initialize the requested fields in the link config based on driver tunables.
4254 init_link_config(struct port_info *pi)
4256 struct link_config *lc = &pi->link_cfg;
4258 PORT_LOCK_ASSERT_OWNED(pi);
4260 lc->requested_speed = 0;
4262 if (t4_autoneg == 0)
4263 lc->requested_aneg = AUTONEG_DISABLE;
4264 else if (t4_autoneg == 1)
4265 lc->requested_aneg = AUTONEG_ENABLE;
4267 lc->requested_aneg = AUTONEG_AUTO;
4269 lc->requested_fc = t4_pause_settings & (PAUSE_TX | PAUSE_RX |
4272 if (t4_fec == -1 || t4_fec & FEC_AUTO)
4273 lc->requested_fec = FEC_AUTO;
4275 lc->requested_fec = FEC_NONE;
4276 if (t4_fec & FEC_RS)
4277 lc->requested_fec |= FEC_RS;
4278 if (t4_fec & FEC_BASER_RS)
4279 lc->requested_fec |= FEC_BASER_RS;
4284 * Makes sure that all requested settings comply with what's supported by the
4285 * port. Returns the number of settings that were invalid and had to be fixed.
4288 fixup_link_config(struct port_info *pi)
4291 struct link_config *lc = &pi->link_cfg;
4294 PORT_LOCK_ASSERT_OWNED(pi);
4296 /* Speed (when not autonegotiating) */
4297 if (lc->requested_speed != 0) {
4298 fwspeed = speed_to_fwcap(lc->requested_speed);
4299 if ((fwspeed & lc->supported) == 0) {
4301 lc->requested_speed = 0;
4305 /* Link autonegotiation */
4306 MPASS(lc->requested_aneg == AUTONEG_ENABLE ||
4307 lc->requested_aneg == AUTONEG_DISABLE ||
4308 lc->requested_aneg == AUTONEG_AUTO);
4309 if (lc->requested_aneg == AUTONEG_ENABLE &&
4310 !(lc->supported & FW_PORT_CAP32_ANEG)) {
4312 lc->requested_aneg = AUTONEG_AUTO;
4316 MPASS((lc->requested_fc & ~(PAUSE_TX | PAUSE_RX | PAUSE_AUTONEG)) == 0);
4317 if (lc->requested_fc & PAUSE_TX &&
4318 !(lc->supported & FW_PORT_CAP32_FC_TX)) {
4320 lc->requested_fc &= ~PAUSE_TX;
4322 if (lc->requested_fc & PAUSE_RX &&
4323 !(lc->supported & FW_PORT_CAP32_FC_RX)) {
4325 lc->requested_fc &= ~PAUSE_RX;
4327 if (!(lc->requested_fc & PAUSE_AUTONEG) &&
4328 !(lc->supported & FW_PORT_CAP32_FORCE_PAUSE)) {
4330 lc->requested_fc |= PAUSE_AUTONEG;
4334 if ((lc->requested_fec & FEC_RS &&
4335 !(lc->supported & FW_PORT_CAP32_FEC_RS)) ||
4336 (lc->requested_fec & FEC_BASER_RS &&
4337 !(lc->supported & FW_PORT_CAP32_FEC_BASER_RS))) {
4339 lc->requested_fec = FEC_AUTO;
4346 * Apply the requested L1 settings, which are expected to be valid, to the
4350 apply_link_config(struct port_info *pi)
4352 struct adapter *sc = pi->adapter;
4353 struct link_config *lc = &pi->link_cfg;
4357 ASSERT_SYNCHRONIZED_OP(sc);
4358 PORT_LOCK_ASSERT_OWNED(pi);
4360 if (lc->requested_aneg == AUTONEG_ENABLE)
4361 MPASS(lc->supported & FW_PORT_CAP32_ANEG);
4362 if (!(lc->requested_fc & PAUSE_AUTONEG))
4363 MPASS(lc->supported & FW_PORT_CAP32_FORCE_PAUSE);
4364 if (lc->requested_fc & PAUSE_TX)
4365 MPASS(lc->supported & FW_PORT_CAP32_FC_TX);
4366 if (lc->requested_fc & PAUSE_RX)
4367 MPASS(lc->supported & FW_PORT_CAP32_FC_RX);
4368 if (lc->requested_fec & FEC_RS)
4369 MPASS(lc->supported & FW_PORT_CAP32_FEC_RS);
4370 if (lc->requested_fec & FEC_BASER_RS)
4371 MPASS(lc->supported & FW_PORT_CAP32_FEC_BASER_RS);
4373 rc = -t4_link_l1cfg(sc, sc->mbox, pi->tx_chan, lc);
4375 device_printf(pi->dev, "l1cfg failed: %d\n", rc);
4378 * An L1_CFG will almost always result in a link-change event if
4379 * the link is up, and the driver will refresh the actual
4380 * fec/fc/etc. when the notification is processed. If the link
4381 * is down then the actual settings are meaningless.
4383 * This takes care of the case where a change in the L1 settings
4384 * may not result in a notification.
4386 if (lc->link_ok && !(lc->requested_fc & PAUSE_AUTONEG))
4387 lc->fc = lc->requested_fc & (PAUSE_TX | PAUSE_RX);
4392 #define FW_MAC_EXACT_CHUNK 7
4395 * Program the port's XGMAC based on parameters in ifnet. The caller also
4396 * indicates which parameters should be programmed (the rest are left alone).
4399 update_mac_settings(struct ifnet *ifp, int flags)
4402 struct vi_info *vi = ifp->if_softc;
4403 struct port_info *pi = vi->pi;
4404 struct adapter *sc = pi->adapter;
4405 int mtu = -1, promisc = -1, allmulti = -1, vlanex = -1;
4407 ASSERT_SYNCHRONIZED_OP(sc);
4408 KASSERT(flags, ("%s: not told what to update.", __func__));
4410 if (flags & XGMAC_MTU)
4413 if (flags & XGMAC_PROMISC)
4414 promisc = ifp->if_flags & IFF_PROMISC ? 1 : 0;
4416 if (flags & XGMAC_ALLMULTI)
4417 allmulti = ifp->if_flags & IFF_ALLMULTI ? 1 : 0;
4419 if (flags & XGMAC_VLANEX)
4420 vlanex = ifp->if_capenable & IFCAP_VLAN_HWTAGGING ? 1 : 0;
4422 if (flags & (XGMAC_MTU|XGMAC_PROMISC|XGMAC_ALLMULTI|XGMAC_VLANEX)) {
4423 rc = -t4_set_rxmode(sc, sc->mbox, vi->viid, mtu, promisc,
4424 allmulti, 1, vlanex, false);
4426 if_printf(ifp, "set_rxmode (%x) failed: %d\n", flags,
4432 if (flags & XGMAC_UCADDR) {
4433 uint8_t ucaddr[ETHER_ADDR_LEN];
4435 bcopy(IF_LLADDR(ifp), ucaddr, sizeof(ucaddr));
4436 rc = t4_change_mac(sc, sc->mbox, vi->viid, vi->xact_addr_filt,
4437 ucaddr, true, true);
4440 if_printf(ifp, "change_mac failed: %d\n", rc);
4443 vi->xact_addr_filt = rc;
4448 if (flags & XGMAC_MCADDRS) {
4449 const uint8_t *mcaddr[FW_MAC_EXACT_CHUNK];
4452 struct ifmultiaddr *ifma;
4455 if_maddr_rlock(ifp);
4456 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
4457 if (ifma->ifma_addr->sa_family != AF_LINK)
4460 LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
4461 MPASS(ETHER_IS_MULTICAST(mcaddr[i]));
4464 if (i == FW_MAC_EXACT_CHUNK) {
4465 rc = t4_alloc_mac_filt(sc, sc->mbox, vi->viid,
4466 del, i, mcaddr, NULL, &hash, 0);
4469 for (j = 0; j < i; j++) {
4471 "failed to add mc address"
4473 "%02x:%02x:%02x rc=%d\n",
4474 mcaddr[j][0], mcaddr[j][1],
4475 mcaddr[j][2], mcaddr[j][3],
4476 mcaddr[j][4], mcaddr[j][5],
4486 rc = t4_alloc_mac_filt(sc, sc->mbox, vi->viid, del, i,
4487 mcaddr, NULL, &hash, 0);
4490 for (j = 0; j < i; j++) {
4492 "failed to add mc address"
4494 "%02x:%02x:%02x rc=%d\n",
4495 mcaddr[j][0], mcaddr[j][1],
4496 mcaddr[j][2], mcaddr[j][3],
4497 mcaddr[j][4], mcaddr[j][5],
4504 rc = -t4_set_addr_hash(sc, sc->mbox, vi->viid, 0, hash, 0);
4506 if_printf(ifp, "failed to set mc address hash: %d", rc);
4508 if_maddr_runlock(ifp);
4515 * {begin|end}_synchronized_op must be called from the same thread.
4518 begin_synchronized_op(struct adapter *sc, struct vi_info *vi, int flags,
4524 /* the caller thinks it's ok to sleep, but is it really? */
4525 if (flags & SLEEP_OK)
4526 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
4527 "begin_synchronized_op");
4538 if (vi && IS_DOOMED(vi)) {
4548 if (!(flags & SLEEP_OK)) {
4553 if (mtx_sleep(&sc->flags, &sc->sc_lock, pri, wmesg, 0)) {
4559 KASSERT(!IS_BUSY(sc), ("%s: controller busy.", __func__));
4562 sc->last_op = wmesg;
4563 sc->last_op_thr = curthread;
4564 sc->last_op_flags = flags;
4568 if (!(flags & HOLD_LOCK) || rc)
4575 * Tell if_ioctl and if_init that the VI is going away. This is
4576 * special variant of begin_synchronized_op and must be paired with a
4577 * call to end_synchronized_op.
4580 doom_vi(struct adapter *sc, struct vi_info *vi)
4587 mtx_sleep(&sc->flags, &sc->sc_lock, 0, "t4detach", 0);
4590 sc->last_op = "t4detach";
4591 sc->last_op_thr = curthread;
4592 sc->last_op_flags = 0;
4598 * {begin|end}_synchronized_op must be called from the same thread.
4601 end_synchronized_op(struct adapter *sc, int flags)
4604 if (flags & LOCK_HELD)
4605 ADAPTER_LOCK_ASSERT_OWNED(sc);
4609 KASSERT(IS_BUSY(sc), ("%s: controller not busy.", __func__));
4616 cxgbe_init_synchronized(struct vi_info *vi)
4618 struct port_info *pi = vi->pi;
4619 struct adapter *sc = pi->adapter;
4620 struct ifnet *ifp = vi->ifp;
4622 struct sge_txq *txq;
4624 ASSERT_SYNCHRONIZED_OP(sc);
4626 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
4627 return (0); /* already running */
4629 if (!(sc->flags & FULL_INIT_DONE) &&
4630 ((rc = adapter_full_init(sc)) != 0))
4631 return (rc); /* error message displayed already */
4633 if (!(vi->flags & VI_INIT_DONE) &&
4634 ((rc = vi_full_init(vi)) != 0))
4635 return (rc); /* error message displayed already */
4637 rc = update_mac_settings(ifp, XGMAC_ALL);
4639 goto done; /* error message displayed already */
4642 if (pi->up_vis == 0) {
4643 t4_update_port_info(pi);
4644 fixup_link_config(pi);
4645 build_medialist(pi);
4646 apply_link_config(pi);
4649 rc = -t4_enable_vi(sc, sc->mbox, vi->viid, true, true);
4651 if_printf(ifp, "enable_vi failed: %d\n", rc);
4657 * Can't fail from this point onwards. Review cxgbe_uninit_synchronized
4661 for_each_txq(vi, i, txq) {
4663 txq->eq.flags |= EQ_ENABLED;
4668 * The first iq of the first port to come up is used for tracing.
4670 if (sc->traceq < 0 && IS_MAIN_VI(vi)) {
4671 sc->traceq = sc->sge.rxq[vi->first_rxq].iq.abs_id;
4672 t4_write_reg(sc, is_t4(sc) ? A_MPS_TRC_RSS_CONTROL :
4673 A_MPS_T5_TRC_RSS_CONTROL, V_RSSCONTROL(pi->tx_chan) |
4674 V_QUEUENUMBER(sc->traceq));
4675 pi->flags |= HAS_TRACEQ;
4680 ifp->if_drv_flags |= IFF_DRV_RUNNING;
4682 if (pi->nvi > 1 || sc->flags & IS_VF)
4683 callout_reset(&vi->tick, hz, vi_tick, vi);
4685 callout_reset(&pi->tick, hz, cxgbe_tick, pi);
4689 cxgbe_uninit_synchronized(vi);
4698 cxgbe_uninit_synchronized(struct vi_info *vi)
4700 struct port_info *pi = vi->pi;
4701 struct adapter *sc = pi->adapter;
4702 struct ifnet *ifp = vi->ifp;
4704 struct sge_txq *txq;
4706 ASSERT_SYNCHRONIZED_OP(sc);
4708 if (!(vi->flags & VI_INIT_DONE)) {
4709 if (__predict_false(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
4710 KASSERT(0, ("uninited VI is running"));
4711 if_printf(ifp, "uninited VI with running ifnet. "
4712 "vi->flags 0x%016lx, if_flags 0x%08x, "
4713 "if_drv_flags 0x%08x\n", vi->flags, ifp->if_flags,
4720 * Disable the VI so that all its data in either direction is discarded
4721 * by the MPS. Leave everything else (the queues, interrupts, and 1Hz
4722 * tick) intact as the TP can deliver negative advice or data that it's
4723 * holding in its RAM (for an offloaded connection) even after the VI is
4726 rc = -t4_enable_vi(sc, sc->mbox, vi->viid, false, false);
4728 if_printf(ifp, "disable_vi failed: %d\n", rc);
4732 for_each_txq(vi, i, txq) {
4734 txq->eq.flags &= ~EQ_ENABLED;
4739 if (pi->nvi > 1 || sc->flags & IS_VF)
4740 callout_stop(&vi->tick);
4742 callout_stop(&pi->tick);
4743 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
4747 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
4749 if (pi->up_vis > 0) {
4754 pi->link_cfg.link_ok = false;
4755 pi->link_cfg.speed = 0;
4756 pi->link_cfg.link_down_rc = 255;
4757 t4_os_link_changed(pi);
4764 * It is ok for this function to fail midway and return right away. t4_detach
4765 * will walk the entire sc->irq list and clean up whatever is valid.
4768 t4_setup_intr_handlers(struct adapter *sc)
4770 int rc, rid, p, q, v;
4773 struct port_info *pi;
4775 struct sge *sge = &sc->sge;
4776 struct sge_rxq *rxq;
4778 struct sge_ofld_rxq *ofld_rxq;
4781 struct sge_nm_rxq *nm_rxq;
4784 int nbuckets = rss_getnumbuckets();
4791 rid = sc->intr_type == INTR_INTX ? 0 : 1;
4792 if (forwarding_intr_to_fwq(sc))
4793 return (t4_alloc_irq(sc, irq, rid, t4_intr_all, sc, "all"));
4795 /* Multiple interrupts. */
4796 if (sc->flags & IS_VF)
4797 KASSERT(sc->intr_count >= T4VF_EXTRA_INTR + sc->params.nports,
4798 ("%s: too few intr.", __func__));
4800 KASSERT(sc->intr_count >= T4_EXTRA_INTR + sc->params.nports,
4801 ("%s: too few intr.", __func__));
4803 /* The first one is always error intr on PFs */
4804 if (!(sc->flags & IS_VF)) {
4805 rc = t4_alloc_irq(sc, irq, rid, t4_intr_err, sc, "err");
4812 /* The second one is always the firmware event queue (first on VFs) */
4813 rc = t4_alloc_irq(sc, irq, rid, t4_intr_evt, &sge->fwq, "evt");
4819 for_each_port(sc, p) {
4821 for_each_vi(pi, v, vi) {
4822 vi->first_intr = rid - 1;
4824 if (vi->nnmrxq > 0) {
4825 int n = max(vi->nrxq, vi->nnmrxq);
4827 rxq = &sge->rxq[vi->first_rxq];
4829 nm_rxq = &sge->nm_rxq[vi->first_nm_rxq];
4831 for (q = 0; q < n; q++) {
4832 snprintf(s, sizeof(s), "%x%c%x", p,
4838 irq->nm_rxq = nm_rxq++;
4840 rc = t4_alloc_irq(sc, irq, rid,
4841 t4_vi_intr, irq, s);
4846 bus_bind_intr(sc->dev, irq->res,
4847 rss_getcpu(q % nbuckets));
4855 for_each_rxq(vi, q, rxq) {
4856 snprintf(s, sizeof(s), "%x%c%x", p,
4858 rc = t4_alloc_irq(sc, irq, rid,
4863 bus_bind_intr(sc->dev, irq->res,
4864 rss_getcpu(q % nbuckets));
4872 for_each_ofld_rxq(vi, q, ofld_rxq) {
4873 snprintf(s, sizeof(s), "%x%c%x", p, 'A' + v, q);
4874 rc = t4_alloc_irq(sc, irq, rid, t4_intr,
4885 MPASS(irq == &sc->irq[sc->intr_count]);
4891 adapter_full_init(struct adapter *sc)
4895 uint32_t raw_rss_key[RSS_KEYSIZE / sizeof(uint32_t)];
4896 uint32_t rss_key[RSS_KEYSIZE / sizeof(uint32_t)];
4899 ASSERT_SYNCHRONIZED_OP(sc);
4900 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
4901 KASSERT((sc->flags & FULL_INIT_DONE) == 0,
4902 ("%s: FULL_INIT_DONE already", __func__));
4905 * queues that belong to the adapter (not any particular port).
4907 rc = t4_setup_adapter_queues(sc);
4911 for (i = 0; i < nitems(sc->tq); i++) {
4912 sc->tq[i] = taskqueue_create("t4 taskq", M_NOWAIT,
4913 taskqueue_thread_enqueue, &sc->tq[i]);
4914 if (sc->tq[i] == NULL) {
4915 device_printf(sc->dev,
4916 "failed to allocate task queue %d\n", i);
4920 taskqueue_start_threads(&sc->tq[i], 1, PI_NET, "%s tq%d",
4921 device_get_nameunit(sc->dev), i);
4924 MPASS(RSS_KEYSIZE == 40);
4925 rss_getkey((void *)&raw_rss_key[0]);
4926 for (i = 0; i < nitems(rss_key); i++) {
4927 rss_key[i] = htobe32(raw_rss_key[nitems(rss_key) - 1 - i]);
4929 t4_write_rss_key(sc, &rss_key[0], -1, 1);
4932 if (!(sc->flags & IS_VF))
4934 sc->flags |= FULL_INIT_DONE;
4937 adapter_full_uninit(sc);
4943 adapter_full_uninit(struct adapter *sc)
4947 ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
4949 t4_teardown_adapter_queues(sc);
4951 for (i = 0; i < nitems(sc->tq) && sc->tq[i]; i++) {
4952 taskqueue_free(sc->tq[i]);
4956 sc->flags &= ~FULL_INIT_DONE;
4962 #define SUPPORTED_RSS_HASHTYPES (RSS_HASHTYPE_RSS_IPV4 | \
4963 RSS_HASHTYPE_RSS_TCP_IPV4 | RSS_HASHTYPE_RSS_IPV6 | \
4964 RSS_HASHTYPE_RSS_TCP_IPV6 | RSS_HASHTYPE_RSS_UDP_IPV4 | \
4965 RSS_HASHTYPE_RSS_UDP_IPV6)
4967 /* Translates kernel hash types to hardware. */
4969 hashconfig_to_hashen(int hashconfig)
4973 if (hashconfig & RSS_HASHTYPE_RSS_IPV4)
4974 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN;
4975 if (hashconfig & RSS_HASHTYPE_RSS_IPV6)
4976 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN;
4977 if (hashconfig & RSS_HASHTYPE_RSS_UDP_IPV4) {
4978 hashen |= F_FW_RSS_VI_CONFIG_CMD_UDPEN |
4979 F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
4981 if (hashconfig & RSS_HASHTYPE_RSS_UDP_IPV6) {
4982 hashen |= F_FW_RSS_VI_CONFIG_CMD_UDPEN |
4983 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
4985 if (hashconfig & RSS_HASHTYPE_RSS_TCP_IPV4)
4986 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN;
4987 if (hashconfig & RSS_HASHTYPE_RSS_TCP_IPV6)
4988 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN;
4993 /* Translates hardware hash types to kernel. */
4995 hashen_to_hashconfig(int hashen)
4999 if (hashen & F_FW_RSS_VI_CONFIG_CMD_UDPEN) {
5001 * If UDP hashing was enabled it must have been enabled for
5002 * either IPv4 or IPv6 (inclusive or). Enabling UDP without
5003 * enabling any 4-tuple hash is nonsense configuration.
5005 MPASS(hashen & (F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN |
5006 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN));
5008 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN)
5009 hashconfig |= RSS_HASHTYPE_RSS_UDP_IPV4;
5010 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN)
5011 hashconfig |= RSS_HASHTYPE_RSS_UDP_IPV6;
5013 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN)
5014 hashconfig |= RSS_HASHTYPE_RSS_TCP_IPV4;
5015 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN)
5016 hashconfig |= RSS_HASHTYPE_RSS_TCP_IPV6;
5017 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN)
5018 hashconfig |= RSS_HASHTYPE_RSS_IPV4;
5019 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN)
5020 hashconfig |= RSS_HASHTYPE_RSS_IPV6;
5022 return (hashconfig);
5027 vi_full_init(struct vi_info *vi)
5029 struct adapter *sc = vi->pi->adapter;
5030 struct ifnet *ifp = vi->ifp;
5032 struct sge_rxq *rxq;
5033 int rc, i, j, hashen;
5035 int nbuckets = rss_getnumbuckets();
5036 int hashconfig = rss_gethashconfig();
5040 ASSERT_SYNCHRONIZED_OP(sc);
5041 KASSERT((vi->flags & VI_INIT_DONE) == 0,
5042 ("%s: VI_INIT_DONE already", __func__));
5044 sysctl_ctx_init(&vi->ctx);
5045 vi->flags |= VI_SYSCTL_CTX;
5048 * Allocate tx/rx/fl queues for this VI.
5050 rc = t4_setup_vi_queues(vi);
5052 goto done; /* error message displayed already */
5055 * Setup RSS for this VI. Save a copy of the RSS table for later use.
5057 if (vi->nrxq > vi->rss_size) {
5058 if_printf(ifp, "nrxq (%d) > hw RSS table size (%d); "
5059 "some queues will never receive traffic.\n", vi->nrxq,
5061 } else if (vi->rss_size % vi->nrxq) {
5062 if_printf(ifp, "nrxq (%d), hw RSS table size (%d); "
5063 "expect uneven traffic distribution.\n", vi->nrxq,
5067 if (vi->nrxq != nbuckets) {
5068 if_printf(ifp, "nrxq (%d) != kernel RSS buckets (%d);"
5069 "performance will be impacted.\n", vi->nrxq, nbuckets);
5072 rss = malloc(vi->rss_size * sizeof (*rss), M_CXGBE, M_ZERO | M_WAITOK);
5073 for (i = 0; i < vi->rss_size;) {
5075 j = rss_get_indirection_to_bucket(i);
5077 rxq = &sc->sge.rxq[vi->first_rxq + j];
5078 rss[i++] = rxq->iq.abs_id;
5080 for_each_rxq(vi, j, rxq) {
5081 rss[i++] = rxq->iq.abs_id;
5082 if (i == vi->rss_size)
5088 rc = -t4_config_rss_range(sc, sc->mbox, vi->viid, 0, vi->rss_size, rss,
5091 if_printf(ifp, "rss_config failed: %d\n", rc);
5096 hashen = hashconfig_to_hashen(hashconfig);
5099 * We may have had to enable some hashes even though the global config
5100 * wants them disabled. This is a potential problem that must be
5101 * reported to the user.
5103 extra = hashen_to_hashconfig(hashen) ^ hashconfig;
5106 * If we consider only the supported hash types, then the enabled hashes
5107 * are a superset of the requested hashes. In other words, there cannot
5108 * be any supported hash that was requested but not enabled, but there
5109 * can be hashes that were not requested but had to be enabled.
5111 extra &= SUPPORTED_RSS_HASHTYPES;
5112 MPASS((extra & hashconfig) == 0);
5116 "global RSS config (0x%x) cannot be accommodated.\n",
5119 if (extra & RSS_HASHTYPE_RSS_IPV4)
5120 if_printf(ifp, "IPv4 2-tuple hashing forced on.\n");
5121 if (extra & RSS_HASHTYPE_RSS_TCP_IPV4)
5122 if_printf(ifp, "TCP/IPv4 4-tuple hashing forced on.\n");
5123 if (extra & RSS_HASHTYPE_RSS_IPV6)
5124 if_printf(ifp, "IPv6 2-tuple hashing forced on.\n");
5125 if (extra & RSS_HASHTYPE_RSS_TCP_IPV6)
5126 if_printf(ifp, "TCP/IPv6 4-tuple hashing forced on.\n");
5127 if (extra & RSS_HASHTYPE_RSS_UDP_IPV4)
5128 if_printf(ifp, "UDP/IPv4 4-tuple hashing forced on.\n");
5129 if (extra & RSS_HASHTYPE_RSS_UDP_IPV6)
5130 if_printf(ifp, "UDP/IPv6 4-tuple hashing forced on.\n");
5132 hashen = F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN |
5133 F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN |
5134 F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN |
5135 F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN | F_FW_RSS_VI_CONFIG_CMD_UDPEN;
5137 rc = -t4_config_vi_rss(sc, sc->mbox, vi->viid, hashen, rss[0], 0, 0);
5139 if_printf(ifp, "rss hash/defaultq config failed: %d\n", rc);
5144 vi->flags |= VI_INIT_DONE;
5156 vi_full_uninit(struct vi_info *vi)
5158 struct port_info *pi = vi->pi;
5159 struct adapter *sc = pi->adapter;
5161 struct sge_rxq *rxq;
5162 struct sge_txq *txq;
5164 struct sge_ofld_rxq *ofld_rxq;
5165 struct sge_wrq *ofld_txq;
5168 if (vi->flags & VI_INIT_DONE) {
5170 /* Need to quiesce queues. */
5172 /* XXX: Only for the first VI? */
5173 if (IS_MAIN_VI(vi) && !(sc->flags & IS_VF))
5174 quiesce_wrq(sc, &sc->sge.ctrlq[pi->port_id]);
5176 for_each_txq(vi, i, txq) {
5177 quiesce_txq(sc, txq);
5181 for_each_ofld_txq(vi, i, ofld_txq) {
5182 quiesce_wrq(sc, ofld_txq);
5186 for_each_rxq(vi, i, rxq) {
5187 quiesce_iq(sc, &rxq->iq);
5188 quiesce_fl(sc, &rxq->fl);
5192 for_each_ofld_rxq(vi, i, ofld_rxq) {
5193 quiesce_iq(sc, &ofld_rxq->iq);
5194 quiesce_fl(sc, &ofld_rxq->fl);
5197 free(vi->rss, M_CXGBE);
5198 free(vi->nm_rss, M_CXGBE);
5201 t4_teardown_vi_queues(vi);
5202 vi->flags &= ~VI_INIT_DONE;
5208 quiesce_txq(struct adapter *sc, struct sge_txq *txq)
5210 struct sge_eq *eq = &txq->eq;
5211 struct sge_qstat *spg = (void *)&eq->desc[eq->sidx];
5213 (void) sc; /* unused */
5217 MPASS((eq->flags & EQ_ENABLED) == 0);
5221 /* Wait for the mp_ring to empty. */
5222 while (!mp_ring_is_idle(txq->r)) {
5223 mp_ring_check_drainage(txq->r, 0);
5224 pause("rquiesce", 1);
5227 /* Then wait for the hardware to finish. */
5228 while (spg->cidx != htobe16(eq->pidx))
5229 pause("equiesce", 1);
5231 /* Finally, wait for the driver to reclaim all descriptors. */
5232 while (eq->cidx != eq->pidx)
5233 pause("dquiesce", 1);
5237 quiesce_wrq(struct adapter *sc, struct sge_wrq *wrq)
5244 quiesce_iq(struct adapter *sc, struct sge_iq *iq)
5246 (void) sc; /* unused */
5248 /* Synchronize with the interrupt handler */
5249 while (!atomic_cmpset_int(&iq->state, IQS_IDLE, IQS_DISABLED))
5254 quiesce_fl(struct adapter *sc, struct sge_fl *fl)
5256 mtx_lock(&sc->sfl_lock);
5258 fl->flags |= FL_DOOMED;
5260 callout_stop(&sc->sfl_callout);
5261 mtx_unlock(&sc->sfl_lock);
5263 KASSERT((fl->flags & FL_STARVING) == 0,
5264 ("%s: still starving", __func__));
5268 t4_alloc_irq(struct adapter *sc, struct irq *irq, int rid,
5269 driver_intr_t *handler, void *arg, char *name)
5274 irq->res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &irq->rid,
5275 RF_SHAREABLE | RF_ACTIVE);
5276 if (irq->res == NULL) {
5277 device_printf(sc->dev,
5278 "failed to allocate IRQ for rid %d, name %s.\n", rid, name);
5282 rc = bus_setup_intr(sc->dev, irq->res, INTR_MPSAFE | INTR_TYPE_NET,
5283 NULL, handler, arg, &irq->tag);
5285 device_printf(sc->dev,
5286 "failed to setup interrupt for rid %d, name %s: %d\n",
5289 bus_describe_intr(sc->dev, irq->res, irq->tag, "%s", name);
5295 t4_free_irq(struct adapter *sc, struct irq *irq)
5298 bus_teardown_intr(sc->dev, irq->res, irq->tag);
5300 bus_release_resource(sc->dev, SYS_RES_IRQ, irq->rid, irq->res);
5302 bzero(irq, sizeof(*irq));
5308 get_regs(struct adapter *sc, struct t4_regdump *regs, uint8_t *buf)
5311 regs->version = chip_id(sc) | chip_rev(sc) << 10;
5312 t4_get_regs(sc, buf, regs->len);
5315 #define A_PL_INDIR_CMD 0x1f8
5317 #define S_PL_AUTOINC 31
5318 #define M_PL_AUTOINC 0x1U
5319 #define V_PL_AUTOINC(x) ((x) << S_PL_AUTOINC)
5320 #define G_PL_AUTOINC(x) (((x) >> S_PL_AUTOINC) & M_PL_AUTOINC)
5322 #define S_PL_VFID 20
5323 #define M_PL_VFID 0xffU
5324 #define V_PL_VFID(x) ((x) << S_PL_VFID)
5325 #define G_PL_VFID(x) (((x) >> S_PL_VFID) & M_PL_VFID)
5328 #define M_PL_ADDR 0xfffffU
5329 #define V_PL_ADDR(x) ((x) << S_PL_ADDR)
5330 #define G_PL_ADDR(x) (((x) >> S_PL_ADDR) & M_PL_ADDR)
5332 #define A_PL_INDIR_DATA 0x1fc
5335 read_vf_stat(struct adapter *sc, unsigned int viid, int reg)
5339 mtx_assert(&sc->reg_lock, MA_OWNED);
5340 if (sc->flags & IS_VF) {
5341 stats[0] = t4_read_reg(sc, VF_MPS_REG(reg));
5342 stats[1] = t4_read_reg(sc, VF_MPS_REG(reg + 4));
5344 t4_write_reg(sc, A_PL_INDIR_CMD, V_PL_AUTOINC(1) |
5345 V_PL_VFID(G_FW_VIID_VIN(viid)) |
5346 V_PL_ADDR(VF_MPS_REG(reg)));
5347 stats[0] = t4_read_reg(sc, A_PL_INDIR_DATA);
5348 stats[1] = t4_read_reg(sc, A_PL_INDIR_DATA);
5350 return (((uint64_t)stats[1]) << 32 | stats[0]);
5354 t4_get_vi_stats(struct adapter *sc, unsigned int viid,
5355 struct fw_vi_stats_vf *stats)
5358 #define GET_STAT(name) \
5359 read_vf_stat(sc, viid, A_MPS_VF_STAT_##name##_L)
5361 stats->tx_bcast_bytes = GET_STAT(TX_VF_BCAST_BYTES);
5362 stats->tx_bcast_frames = GET_STAT(TX_VF_BCAST_FRAMES);
5363 stats->tx_mcast_bytes = GET_STAT(TX_VF_MCAST_BYTES);
5364 stats->tx_mcast_frames = GET_STAT(TX_VF_MCAST_FRAMES);
5365 stats->tx_ucast_bytes = GET_STAT(TX_VF_UCAST_BYTES);
5366 stats->tx_ucast_frames = GET_STAT(TX_VF_UCAST_FRAMES);
5367 stats->tx_drop_frames = GET_STAT(TX_VF_DROP_FRAMES);
5368 stats->tx_offload_bytes = GET_STAT(TX_VF_OFFLOAD_BYTES);
5369 stats->tx_offload_frames = GET_STAT(TX_VF_OFFLOAD_FRAMES);
5370 stats->rx_bcast_bytes = GET_STAT(RX_VF_BCAST_BYTES);
5371 stats->rx_bcast_frames = GET_STAT(RX_VF_BCAST_FRAMES);
5372 stats->rx_mcast_bytes = GET_STAT(RX_VF_MCAST_BYTES);
5373 stats->rx_mcast_frames = GET_STAT(RX_VF_MCAST_FRAMES);
5374 stats->rx_ucast_bytes = GET_STAT(RX_VF_UCAST_BYTES);
5375 stats->rx_ucast_frames = GET_STAT(RX_VF_UCAST_FRAMES);
5376 stats->rx_err_frames = GET_STAT(RX_VF_ERR_FRAMES);
5382 t4_clr_vi_stats(struct adapter *sc, unsigned int viid)
5386 t4_write_reg(sc, A_PL_INDIR_CMD, V_PL_AUTOINC(1) |
5387 V_PL_VFID(G_FW_VIID_VIN(viid)) |
5388 V_PL_ADDR(VF_MPS_REG(A_MPS_VF_STAT_TX_VF_BCAST_BYTES_L)));
5389 for (reg = A_MPS_VF_STAT_TX_VF_BCAST_BYTES_L;
5390 reg <= A_MPS_VF_STAT_RX_VF_ERR_FRAMES_H; reg += 4)
5391 t4_write_reg(sc, A_PL_INDIR_DATA, 0);
5395 vi_refresh_stats(struct adapter *sc, struct vi_info *vi)
5398 const struct timeval interval = {0, 250000}; /* 250ms */
5400 if (!(vi->flags & VI_INIT_DONE))
5404 timevalsub(&tv, &interval);
5405 if (timevalcmp(&tv, &vi->last_refreshed, <))
5408 mtx_lock(&sc->reg_lock);
5409 t4_get_vi_stats(sc, vi->viid, &vi->stats);
5410 getmicrotime(&vi->last_refreshed);
5411 mtx_unlock(&sc->reg_lock);
5415 cxgbe_refresh_stats(struct adapter *sc, struct port_info *pi)
5417 u_int i, v, tnl_cong_drops, bg_map;
5419 const struct timeval interval = {0, 250000}; /* 250ms */
5422 timevalsub(&tv, &interval);
5423 if (timevalcmp(&tv, &pi->last_refreshed, <))
5427 t4_get_port_stats(sc, pi->tx_chan, &pi->stats);
5428 bg_map = pi->mps_bg_map;
5430 i = ffs(bg_map) - 1;
5431 mtx_lock(&sc->reg_lock);
5432 t4_read_indirect(sc, A_TP_MIB_INDEX, A_TP_MIB_DATA, &v, 1,
5433 A_TP_MIB_TNL_CNG_DROP_0 + i);
5434 mtx_unlock(&sc->reg_lock);
5435 tnl_cong_drops += v;
5436 bg_map &= ~(1 << i);
5438 pi->tnl_cong_drops = tnl_cong_drops;
5439 getmicrotime(&pi->last_refreshed);
5443 cxgbe_tick(void *arg)
5445 struct port_info *pi = arg;
5446 struct adapter *sc = pi->adapter;
5448 PORT_LOCK_ASSERT_OWNED(pi);
5449 cxgbe_refresh_stats(sc, pi);
5451 callout_schedule(&pi->tick, hz);
5457 struct vi_info *vi = arg;
5458 struct adapter *sc = vi->pi->adapter;
5460 vi_refresh_stats(sc, vi);
5462 callout_schedule(&vi->tick, hz);
5466 cxgbe_vlan_config(void *arg, struct ifnet *ifp, uint16_t vid)
5470 if (arg != ifp || ifp->if_type != IFT_ETHER)
5473 vlan = VLAN_DEVAT(ifp, vid);
5474 VLAN_SETCOOKIE(vlan, ifp);
5478 * Should match fw_caps_config_<foo> enums in t4fw_interface.h
5480 static char *caps_decoder[] = {
5481 "\20\001IPMI\002NCSI", /* 0: NBM */
5482 "\20\001PPP\002QFC\003DCBX", /* 1: link */
5483 "\20\001INGRESS\002EGRESS", /* 2: switch */
5484 "\20\001NIC\002VM\003IDS\004UM\005UM_ISGL" /* 3: NIC */
5485 "\006HASHFILTER\007ETHOFLD",
5486 "\20\001TOE", /* 4: TOE */
5487 "\20\001RDDP\002RDMAC", /* 5: RDMA */
5488 "\20\001INITIATOR_PDU\002TARGET_PDU" /* 6: iSCSI */
5489 "\003INITIATOR_CNXOFLD\004TARGET_CNXOFLD"
5490 "\005INITIATOR_SSNOFLD\006TARGET_SSNOFLD"
5492 "\010INITIATOR_CMDOFLD\011TARGET_CMDOFLD",
5493 "\20\001LOOKASIDE\002TLSKEYS", /* 7: Crypto */
5494 "\20\001INITIATOR\002TARGET\003CTRL_OFLD" /* 8: FCoE */
5495 "\004PO_INITIATOR\005PO_TARGET",
5499 t4_sysctls(struct adapter *sc)
5501 struct sysctl_ctx_list *ctx;
5502 struct sysctl_oid *oid;
5503 struct sysctl_oid_list *children, *c0;
5504 static char *doorbells = {"\20\1UDB\2WCWR\3UDBWC\4KDB"};
5506 ctx = device_get_sysctl_ctx(sc->dev);
5511 oid = device_get_sysctl_tree(sc->dev);
5512 c0 = children = SYSCTL_CHILDREN(oid);
5514 sc->sc_do_rxcopy = 1;
5515 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "do_rx_copy", CTLFLAG_RW,
5516 &sc->sc_do_rxcopy, 1, "Do RX copy of small frames");
5518 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nports", CTLFLAG_RD, NULL,
5519 sc->params.nports, "# of ports");
5521 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "doorbells",
5522 CTLTYPE_STRING | CTLFLAG_RD, doorbells, sc->doorbells,
5523 sysctl_bitfield, "A", "available doorbells");
5525 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "core_clock", CTLFLAG_RD, NULL,
5526 sc->params.vpd.cclk, "core clock frequency (in KHz)");
5528 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_timers",
5529 CTLTYPE_STRING | CTLFLAG_RD, sc->params.sge.timer_val,
5530 sizeof(sc->params.sge.timer_val), sysctl_int_array, "A",
5531 "interrupt holdoff timer values (us)");
5533 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pkt_counts",
5534 CTLTYPE_STRING | CTLFLAG_RD, sc->params.sge.counter_val,
5535 sizeof(sc->params.sge.counter_val), sysctl_int_array, "A",
5536 "interrupt holdoff packet counter values");
5538 t4_sge_sysctls(sc, ctx, children);
5540 sc->lro_timeout = 100;
5541 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "lro_timeout", CTLFLAG_RW,
5542 &sc->lro_timeout, 0, "lro inactive-flush timeout (in us)");
5544 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "dflags", CTLFLAG_RW,
5545 &sc->debug_flags, 0, "flags to enable runtime debugging");
5547 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "tp_version",
5548 CTLFLAG_RD, sc->tp_version, 0, "TP microcode version");
5550 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "firmware_version",
5551 CTLFLAG_RD, sc->fw_version, 0, "firmware version");
5553 if (sc->flags & IS_VF)
5556 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "hw_revision", CTLFLAG_RD,
5557 NULL, chip_rev(sc), "chip hardware revision");
5559 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "sn",
5560 CTLFLAG_RD, sc->params.vpd.sn, 0, "serial number");
5562 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "pn",
5563 CTLFLAG_RD, sc->params.vpd.pn, 0, "part number");
5565 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "ec",
5566 CTLFLAG_RD, sc->params.vpd.ec, 0, "engineering change");
5568 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "md_version",
5569 CTLFLAG_RD, sc->params.vpd.md, 0, "manufacturing diags version");
5571 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "na",
5572 CTLFLAG_RD, sc->params.vpd.na, 0, "network address");
5574 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "er_version", CTLFLAG_RD,
5575 sc->er_version, 0, "expansion ROM version");
5577 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "bs_version", CTLFLAG_RD,
5578 sc->bs_version, 0, "bootstrap firmware version");
5580 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "scfg_version", CTLFLAG_RD,
5581 NULL, sc->params.scfg_vers, "serial config version");
5583 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "vpd_version", CTLFLAG_RD,
5584 NULL, sc->params.vpd_vers, "VPD version");
5586 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "cf",
5587 CTLFLAG_RD, sc->cfg_file, 0, "configuration file");
5589 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "cfcsum", CTLFLAG_RD, NULL,
5590 sc->cfcsum, "config file checksum");
5592 #define SYSCTL_CAP(name, n, text) \
5593 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, #name, \
5594 CTLTYPE_STRING | CTLFLAG_RD, caps_decoder[n], sc->name, \
5595 sysctl_bitfield, "A", "available " text " capabilities")
5597 SYSCTL_CAP(nbmcaps, 0, "NBM");
5598 SYSCTL_CAP(linkcaps, 1, "link");
5599 SYSCTL_CAP(switchcaps, 2, "switch");
5600 SYSCTL_CAP(niccaps, 3, "NIC");
5601 SYSCTL_CAP(toecaps, 4, "TCP offload");
5602 SYSCTL_CAP(rdmacaps, 5, "RDMA");
5603 SYSCTL_CAP(iscsicaps, 6, "iSCSI");
5604 SYSCTL_CAP(cryptocaps, 7, "crypto");
5605 SYSCTL_CAP(fcoecaps, 8, "FCoE");
5608 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nfilters", CTLFLAG_RD,
5609 NULL, sc->tids.nftids, "number of filters");
5611 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature", CTLTYPE_INT |
5612 CTLFLAG_RD, sc, 0, sysctl_temperature, "I",
5613 "chip temperature (in Celsius)");
5615 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "loadavg", CTLTYPE_STRING |
5616 CTLFLAG_RD, sc, 0, sysctl_loadavg, "A",
5617 "microprocessor load averages (debug firmwares only)");
5619 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "core_vdd", CTLFLAG_RD,
5620 &sc->params.core_vdd, 0, "core Vdd (in mV)");
5624 * dev.t4nex.X.misc. Marked CTLFLAG_SKIP to avoid information overload.
5626 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "misc",
5627 CTLFLAG_RD | CTLFLAG_SKIP, NULL,
5628 "logs and miscellaneous information");
5629 children = SYSCTL_CHILDREN(oid);
5631 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cctrl",
5632 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5633 sysctl_cctrl, "A", "congestion control");
5635 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp0",
5636 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5637 sysctl_cim_ibq_obq, "A", "CIM IBQ 0 (TP0)");
5639 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp1",
5640 CTLTYPE_STRING | CTLFLAG_RD, sc, 1,
5641 sysctl_cim_ibq_obq, "A", "CIM IBQ 1 (TP1)");
5643 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ulp",
5644 CTLTYPE_STRING | CTLFLAG_RD, sc, 2,
5645 sysctl_cim_ibq_obq, "A", "CIM IBQ 2 (ULP)");
5647 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge0",
5648 CTLTYPE_STRING | CTLFLAG_RD, sc, 3,
5649 sysctl_cim_ibq_obq, "A", "CIM IBQ 3 (SGE0)");
5651 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge1",
5652 CTLTYPE_STRING | CTLFLAG_RD, sc, 4,
5653 sysctl_cim_ibq_obq, "A", "CIM IBQ 4 (SGE1)");
5655 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ncsi",
5656 CTLTYPE_STRING | CTLFLAG_RD, sc, 5,
5657 sysctl_cim_ibq_obq, "A", "CIM IBQ 5 (NCSI)");
5659 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_la",
5660 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5661 chip_id(sc) <= CHELSIO_T5 ? sysctl_cim_la : sysctl_cim_la_t6,
5662 "A", "CIM logic analyzer");
5664 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ma_la",
5665 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5666 sysctl_cim_ma_la, "A", "CIM MA logic analyzer");
5668 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp0",
5669 CTLTYPE_STRING | CTLFLAG_RD, sc, 0 + CIM_NUM_IBQ,
5670 sysctl_cim_ibq_obq, "A", "CIM OBQ 0 (ULP0)");
5672 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp1",
5673 CTLTYPE_STRING | CTLFLAG_RD, sc, 1 + CIM_NUM_IBQ,
5674 sysctl_cim_ibq_obq, "A", "CIM OBQ 1 (ULP1)");
5676 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp2",
5677 CTLTYPE_STRING | CTLFLAG_RD, sc, 2 + CIM_NUM_IBQ,
5678 sysctl_cim_ibq_obq, "A", "CIM OBQ 2 (ULP2)");
5680 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp3",
5681 CTLTYPE_STRING | CTLFLAG_RD, sc, 3 + CIM_NUM_IBQ,
5682 sysctl_cim_ibq_obq, "A", "CIM OBQ 3 (ULP3)");
5684 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge",
5685 CTLTYPE_STRING | CTLFLAG_RD, sc, 4 + CIM_NUM_IBQ,
5686 sysctl_cim_ibq_obq, "A", "CIM OBQ 4 (SGE)");
5688 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ncsi",
5689 CTLTYPE_STRING | CTLFLAG_RD, sc, 5 + CIM_NUM_IBQ,
5690 sysctl_cim_ibq_obq, "A", "CIM OBQ 5 (NCSI)");
5692 if (chip_id(sc) > CHELSIO_T4) {
5693 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge0_rx",
5694 CTLTYPE_STRING | CTLFLAG_RD, sc, 6 + CIM_NUM_IBQ,
5695 sysctl_cim_ibq_obq, "A", "CIM OBQ 6 (SGE0-RX)");
5697 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge1_rx",
5698 CTLTYPE_STRING | CTLFLAG_RD, sc, 7 + CIM_NUM_IBQ,
5699 sysctl_cim_ibq_obq, "A", "CIM OBQ 7 (SGE1-RX)");
5702 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_pif_la",
5703 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5704 sysctl_cim_pif_la, "A", "CIM PIF logic analyzer");
5706 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_qcfg",
5707 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5708 sysctl_cim_qcfg, "A", "CIM queue configuration");
5710 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cpl_stats",
5711 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5712 sysctl_cpl_stats, "A", "CPL statistics");
5714 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ddp_stats",
5715 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5716 sysctl_ddp_stats, "A", "non-TCP DDP statistics");
5718 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "devlog",
5719 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5720 sysctl_devlog, "A", "firmware's device log");
5722 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fcoe_stats",
5723 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5724 sysctl_fcoe_stats, "A", "FCoE statistics");
5726 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "hw_sched",
5727 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5728 sysctl_hw_sched, "A", "hardware scheduler ");
5730 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "l2t",
5731 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5732 sysctl_l2t, "A", "hardware L2 table");
5734 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "lb_stats",
5735 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5736 sysctl_lb_stats, "A", "loopback statistics");
5738 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "meminfo",
5739 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5740 sysctl_meminfo, "A", "memory regions");
5742 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "mps_tcam",
5743 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5744 chip_id(sc) <= CHELSIO_T5 ? sysctl_mps_tcam : sysctl_mps_tcam_t6,
5745 "A", "MPS TCAM entries");
5747 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "path_mtus",
5748 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5749 sysctl_path_mtus, "A", "path MTUs");
5751 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pm_stats",
5752 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5753 sysctl_pm_stats, "A", "PM statistics");
5755 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rdma_stats",
5756 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5757 sysctl_rdma_stats, "A", "RDMA statistics");
5759 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tcp_stats",
5760 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5761 sysctl_tcp_stats, "A", "TCP statistics");
5763 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tids",
5764 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5765 sysctl_tids, "A", "TID information");
5767 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_err_stats",
5768 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5769 sysctl_tp_err_stats, "A", "TP error statistics");
5771 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_la_mask",
5772 CTLTYPE_INT | CTLFLAG_RW, sc, 0, sysctl_tp_la_mask, "I",
5773 "TP logic analyzer event capture mask");
5775 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_la",
5776 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5777 sysctl_tp_la, "A", "TP logic analyzer");
5779 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_rate",
5780 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5781 sysctl_tx_rate, "A", "Tx rate");
5783 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ulprx_la",
5784 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5785 sysctl_ulprx_la, "A", "ULPRX logic analyzer");
5787 if (chip_id(sc) >= CHELSIO_T5) {
5788 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "wcwr_stats",
5789 CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
5790 sysctl_wcwr_stats, "A", "write combined work requests");
5795 if (is_offload(sc)) {
5802 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "toe", CTLFLAG_RD,
5803 NULL, "TOE parameters");
5804 children = SYSCTL_CHILDREN(oid);
5806 sc->tt.cong_algorithm = -1;
5807 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "cong_algorithm",
5808 CTLFLAG_RW, &sc->tt.cong_algorithm, 0, "congestion control "
5809 "(-1 = default, 0 = reno, 1 = tahoe, 2 = newreno, "
5812 sc->tt.sndbuf = 256 * 1024;
5813 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "sndbuf", CTLFLAG_RW,
5814 &sc->tt.sndbuf, 0, "max hardware send buffer size");
5817 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ddp", CTLFLAG_RW,
5818 &sc->tt.ddp, 0, "DDP allowed");
5820 sc->tt.rx_coalesce = 1;
5821 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_coalesce",
5822 CTLFLAG_RW, &sc->tt.rx_coalesce, 0, "receive coalescing");
5825 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tls", CTLFLAG_RW,
5826 &sc->tt.tls, 0, "Inline TLS allowed");
5828 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tls_rx_ports",
5829 CTLTYPE_INT | CTLFLAG_RW, sc, 0, sysctl_tls_rx_ports,
5830 "I", "TCP ports that use inline TLS+TOE RX");
5832 sc->tt.tx_align = 1;
5833 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_align",
5834 CTLFLAG_RW, &sc->tt.tx_align, 0, "chop and align payload");
5836 sc->tt.tx_zcopy = 0;
5837 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_zcopy",
5838 CTLFLAG_RW, &sc->tt.tx_zcopy, 0,
5839 "Enable zero-copy aio_write(2)");
5841 sc->tt.cop_managed_offloading = !!t4_cop_managed_offloading;
5842 SYSCTL_ADD_INT(ctx, children, OID_AUTO,
5843 "cop_managed_offloading", CTLFLAG_RW,
5844 &sc->tt.cop_managed_offloading, 0,
5845 "COP (Connection Offload Policy) controls all TOE offload");
5847 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "timer_tick",
5848 CTLTYPE_STRING | CTLFLAG_RD, sc, 0, sysctl_tp_tick, "A",
5849 "TP timer tick (us)");
5851 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "timestamp_tick",
5852 CTLTYPE_STRING | CTLFLAG_RD, sc, 1, sysctl_tp_tick, "A",
5853 "TCP timestamp tick (us)");
5855 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "dack_tick",
5856 CTLTYPE_STRING | CTLFLAG_RD, sc, 2, sysctl_tp_tick, "A",
5859 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "dack_timer",
5860 CTLTYPE_UINT | CTLFLAG_RD, sc, 0, sysctl_tp_dack_timer,
5861 "IU", "DACK timer (us)");
5863 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_min",
5864 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_RXT_MIN,
5865 sysctl_tp_timer, "LU", "Minimum retransmit interval (us)");
5867 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_max",
5868 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_RXT_MAX,
5869 sysctl_tp_timer, "LU", "Maximum retransmit interval (us)");
5871 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "persist_min",
5872 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_PERS_MIN,
5873 sysctl_tp_timer, "LU", "Persist timer min (us)");
5875 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "persist_max",
5876 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_PERS_MAX,
5877 sysctl_tp_timer, "LU", "Persist timer max (us)");
5879 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_idle",
5880 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_KEEP_IDLE,
5881 sysctl_tp_timer, "LU", "Keepalive idle timer (us)");
5883 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_interval",
5884 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_KEEP_INTVL,
5885 sysctl_tp_timer, "LU", "Keepalive interval timer (us)");
5887 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "initial_srtt",
5888 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_INIT_SRTT,
5889 sysctl_tp_timer, "LU", "Initial SRTT (us)");
5891 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "finwait2_timer",
5892 CTLTYPE_ULONG | CTLFLAG_RD, sc, A_TP_FINWAIT2_TIMER,
5893 sysctl_tp_timer, "LU", "FINWAIT2 timer (us)");
5895 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "syn_rexmt_count",
5896 CTLTYPE_UINT | CTLFLAG_RD, sc, S_SYNSHIFTMAX,
5897 sysctl_tp_shift_cnt, "IU",
5898 "Number of SYN retransmissions before abort");
5900 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_count",
5901 CTLTYPE_UINT | CTLFLAG_RD, sc, S_RXTSHIFTMAXR2,
5902 sysctl_tp_shift_cnt, "IU",
5903 "Number of retransmissions before abort");
5905 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_count",
5906 CTLTYPE_UINT | CTLFLAG_RD, sc, S_KEEPALIVEMAXR2,
5907 sysctl_tp_shift_cnt, "IU",
5908 "Number of keepalive probes before abort");
5910 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "rexmt_backoff",
5911 CTLFLAG_RD, NULL, "TOE retransmit backoffs");
5912 children = SYSCTL_CHILDREN(oid);
5913 for (i = 0; i < 16; i++) {
5914 snprintf(s, sizeof(s), "%u", i);
5915 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, s,
5916 CTLTYPE_UINT | CTLFLAG_RD, sc, i, sysctl_tp_backoff,
5917 "IU", "TOE retransmit backoff");
5924 vi_sysctls(struct vi_info *vi)
5926 struct sysctl_ctx_list *ctx;
5927 struct sysctl_oid *oid;
5928 struct sysctl_oid_list *children;
5930 ctx = device_get_sysctl_ctx(vi->dev);
5933 * dev.v?(cxgbe|cxl).X.
5935 oid = device_get_sysctl_tree(vi->dev);
5936 children = SYSCTL_CHILDREN(oid);
5938 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "viid", CTLFLAG_RD, NULL,
5939 vi->viid, "VI identifer");
5940 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nrxq", CTLFLAG_RD,
5941 &vi->nrxq, 0, "# of rx queues");
5942 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ntxq", CTLFLAG_RD,
5943 &vi->ntxq, 0, "# of tx queues");
5944 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_rxq", CTLFLAG_RD,
5945 &vi->first_rxq, 0, "index of first rx queue");
5946 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_txq", CTLFLAG_RD,
5947 &vi->first_txq, 0, "index of first tx queue");
5948 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "rss_size", CTLFLAG_RD, NULL,
5949 vi->rss_size, "size of RSS indirection table");
5951 if (IS_MAIN_VI(vi)) {
5952 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rsrv_noflowq",
5953 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_noflowq, "IU",
5954 "Reserve queue 0 for non-flowid packets");
5958 if (vi->nofldrxq != 0) {
5959 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldrxq", CTLFLAG_RD,
5961 "# of rx queues for offloaded TCP connections");
5962 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldtxq", CTLFLAG_RD,
5964 "# of tx queues for offloaded TCP connections");
5965 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_rxq",
5966 CTLFLAG_RD, &vi->first_ofld_rxq, 0,
5967 "index of first TOE rx queue");
5968 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_txq",
5969 CTLFLAG_RD, &vi->first_ofld_txq, 0,
5970 "index of first TOE tx queue");
5971 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx_ofld",
5972 CTLTYPE_INT | CTLFLAG_RW, vi, 0,
5973 sysctl_holdoff_tmr_idx_ofld, "I",
5974 "holdoff timer index for TOE queues");
5975 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx_ofld",
5976 CTLTYPE_INT | CTLFLAG_RW, vi, 0,
5977 sysctl_holdoff_pktc_idx_ofld, "I",
5978 "holdoff packet counter index for TOE queues");
5982 if (vi->nnmrxq != 0) {
5983 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmrxq", CTLFLAG_RD,
5984 &vi->nnmrxq, 0, "# of netmap rx queues");
5985 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmtxq", CTLFLAG_RD,
5986 &vi->nnmtxq, 0, "# of netmap tx queues");
5987 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_rxq",
5988 CTLFLAG_RD, &vi->first_nm_rxq, 0,
5989 "index of first netmap rx queue");
5990 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_txq",
5991 CTLFLAG_RD, &vi->first_nm_txq, 0,
5992 "index of first netmap tx queue");
5996 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx",
5997 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_holdoff_tmr_idx, "I",
5998 "holdoff timer index");
5999 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx",
6000 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_holdoff_pktc_idx, "I",
6001 "holdoff packet counter index");
6003 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_rxq",
6004 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_qsize_rxq, "I",
6006 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_txq",
6007 CTLTYPE_INT | CTLFLAG_RW, vi, 0, sysctl_qsize_txq, "I",
6012 cxgbe_sysctls(struct port_info *pi)
6014 struct sysctl_ctx_list *ctx;
6015 struct sysctl_oid *oid;
6016 struct sysctl_oid_list *children, *children2;
6017 struct adapter *sc = pi->adapter;
6021 ctx = device_get_sysctl_ctx(pi->dev);
6026 oid = device_get_sysctl_tree(pi->dev);
6027 children = SYSCTL_CHILDREN(oid);
6029 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "linkdnrc", CTLTYPE_STRING |
6030 CTLFLAG_RD, pi, 0, sysctl_linkdnrc, "A", "reason why link is down");
6031 if (pi->port_type == FW_PORT_TYPE_BT_XAUI) {
6032 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature",
6033 CTLTYPE_INT | CTLFLAG_RD, pi, 0, sysctl_btphy, "I",
6034 "PHY temperature (in Celsius)");
6035 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fw_version",
6036 CTLTYPE_INT | CTLFLAG_RD, pi, 1, sysctl_btphy, "I",
6037 "PHY firmware version");
6040 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pause_settings",
6041 CTLTYPE_STRING | CTLFLAG_RW, pi, 0, sysctl_pause_settings, "A",
6042 "PAUSE settings (bit 0 = rx_pause, 1 = tx_pause, 2 = pause_autoneg)");
6043 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fec",
6044 CTLTYPE_STRING | CTLFLAG_RW, pi, 0, sysctl_fec, "A",
6045 "Forward Error Correction (bit 0 = RS, bit 1 = BASER_RS)");
6046 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "autoneg",
6047 CTLTYPE_INT | CTLFLAG_RW, pi, 0, sysctl_autoneg, "I",
6048 "autonegotiation (-1 = not supported)");
6050 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "max_speed", CTLFLAG_RD, NULL,
6051 port_top_speed(pi), "max speed (in Gbps)");
6052 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "mps_bg_map", CTLFLAG_RD, NULL,
6053 pi->mps_bg_map, "MPS buffer group map");
6054 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_e_chan_map", CTLFLAG_RD,
6055 NULL, pi->rx_e_chan_map, "TP rx e-channel map");
6057 if (sc->flags & IS_VF)
6061 * dev.(cxgbe|cxl).X.tc.
6063 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "tc", CTLFLAG_RD, NULL,
6064 "Tx scheduler traffic classes (cl_rl)");
6065 for (i = 0; i < sc->chip_params->nsched_cls; i++) {
6066 struct tx_cl_rl_params *tc = &pi->sched_params->cl_rl[i];
6068 snprintf(name, sizeof(name), "%d", i);
6069 children2 = SYSCTL_CHILDREN(SYSCTL_ADD_NODE(ctx,
6070 SYSCTL_CHILDREN(oid), OID_AUTO, name, CTLFLAG_RD, NULL,
6072 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "flags", CTLFLAG_RD,
6073 &tc->flags, 0, "flags");
6074 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "refcount",
6075 CTLFLAG_RD, &tc->refcount, 0, "references to this class");
6077 SYSCTL_ADD_PROC(ctx, children2, OID_AUTO, "params",
6078 CTLTYPE_STRING | CTLFLAG_RD, sc, (pi->port_id << 16) | i,
6079 sysctl_tc_params, "A", "traffic class parameters");
6084 * dev.cxgbe.X.stats.
6086 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats", CTLFLAG_RD,
6087 NULL, "port statistics");
6088 children = SYSCTL_CHILDREN(oid);
6089 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "tx_parse_error", CTLFLAG_RD,
6090 &pi->tx_parse_error, 0,
6091 "# of tx packets with invalid length or # of segments");
6093 #define SYSCTL_ADD_T4_REG64(pi, name, desc, reg) \
6094 SYSCTL_ADD_OID(ctx, children, OID_AUTO, name, \
6095 CTLTYPE_U64 | CTLFLAG_RD, sc, reg, \
6096 sysctl_handle_t4_reg64, "QU", desc)
6098 SYSCTL_ADD_T4_REG64(pi, "tx_octets", "# of octets in good frames",
6099 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BYTES_L));
6100 SYSCTL_ADD_T4_REG64(pi, "tx_frames", "total # of good frames",
6101 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_FRAMES_L));
6102 SYSCTL_ADD_T4_REG64(pi, "tx_bcast_frames", "# of broadcast frames",
6103 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_BCAST_L));
6104 SYSCTL_ADD_T4_REG64(pi, "tx_mcast_frames", "# of multicast frames",
6105 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_MCAST_L));
6106 SYSCTL_ADD_T4_REG64(pi, "tx_ucast_frames", "# of unicast frames",
6107 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_UCAST_L));
6108 SYSCTL_ADD_T4_REG64(pi, "tx_error_frames", "# of error frames",
6109 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_ERROR_L));
6110 SYSCTL_ADD_T4_REG64(pi, "tx_frames_64",
6111 "# of tx frames in this range",
6112 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_64B_L));
6113 SYSCTL_ADD_T4_REG64(pi, "tx_frames_65_127",
6114 "# of tx frames in this range",
6115 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_65B_127B_L));
6116 SYSCTL_ADD_T4_REG64(pi, "tx_frames_128_255",
6117 "# of tx frames in this range",
6118 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_128B_255B_L));
6119 SYSCTL_ADD_T4_REG64(pi, "tx_frames_256_511",
6120 "# of tx frames in this range",
6121 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_256B_511B_L));
6122 SYSCTL_ADD_T4_REG64(pi, "tx_frames_512_1023",
6123 "# of tx frames in this range",
6124 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_512B_1023B_L));
6125 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1024_1518",
6126 "# of tx frames in this range",
6127 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1024B_1518B_L));
6128 SYSCTL_ADD_T4_REG64(pi, "tx_frames_1519_max",
6129 "# of tx frames in this range",
6130 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_1519B_MAX_L));
6131 SYSCTL_ADD_T4_REG64(pi, "tx_drop", "# of dropped tx frames",
6132 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_DROP_L));
6133 SYSCTL_ADD_T4_REG64(pi, "tx_pause", "# of pause frames transmitted",
6134 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PAUSE_L));
6135 SYSCTL_ADD_T4_REG64(pi, "tx_ppp0", "# of PPP prio 0 frames transmitted",
6136 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP0_L));
6137 SYSCTL_ADD_T4_REG64(pi, "tx_ppp1", "# of PPP prio 1 frames transmitted",
6138 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP1_L));
6139 SYSCTL_ADD_T4_REG64(pi, "tx_ppp2", "# of PPP prio 2 frames transmitted",
6140 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP2_L));
6141 SYSCTL_ADD_T4_REG64(pi, "tx_ppp3", "# of PPP prio 3 frames transmitted",
6142 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP3_L));
6143 SYSCTL_ADD_T4_REG64(pi, "tx_ppp4", "# of PPP prio 4 frames transmitted",
6144 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP4_L));
6145 SYSCTL_ADD_T4_REG64(pi, "tx_ppp5", "# of PPP prio 5 frames transmitted",
6146 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP5_L));
6147 SYSCTL_ADD_T4_REG64(pi, "tx_ppp6", "# of PPP prio 6 frames transmitted",
6148 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP6_L));
6149 SYSCTL_ADD_T4_REG64(pi, "tx_ppp7", "# of PPP prio 7 frames transmitted",
6150 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_TX_PORT_PPP7_L));
6152 SYSCTL_ADD_T4_REG64(pi, "rx_octets", "# of octets in good frames",
6153 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BYTES_L));
6154 SYSCTL_ADD_T4_REG64(pi, "rx_frames", "total # of good frames",
6155 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_FRAMES_L));
6156 SYSCTL_ADD_T4_REG64(pi, "rx_bcast_frames", "# of broadcast frames",
6157 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_BCAST_L));
6158 SYSCTL_ADD_T4_REG64(pi, "rx_mcast_frames", "# of multicast frames",
6159 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MCAST_L));
6160 SYSCTL_ADD_T4_REG64(pi, "rx_ucast_frames", "# of unicast frames",
6161 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_UCAST_L));
6162 SYSCTL_ADD_T4_REG64(pi, "rx_too_long", "# of frames exceeding MTU",
6163 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_ERROR_L));
6164 SYSCTL_ADD_T4_REG64(pi, "rx_jabber", "# of jabber frames",
6165 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_MTU_CRC_ERROR_L));
6166 SYSCTL_ADD_T4_REG64(pi, "rx_fcs_err",
6167 "# of frames received with bad FCS",
6168 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_CRC_ERROR_L));
6169 SYSCTL_ADD_T4_REG64(pi, "rx_len_err",
6170 "# of frames received with length error",
6171 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LEN_ERROR_L));
6172 SYSCTL_ADD_T4_REG64(pi, "rx_symbol_err", "symbol errors",
6173 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_SYM_ERROR_L));
6174 SYSCTL_ADD_T4_REG64(pi, "rx_runt", "# of short frames received",
6175 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_LESS_64B_L));
6176 SYSCTL_ADD_T4_REG64(pi, "rx_frames_64",
6177 "# of rx frames in this range",
6178 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_64B_L));
6179 SYSCTL_ADD_T4_REG64(pi, "rx_frames_65_127",
6180 "# of rx frames in this range",
6181 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_65B_127B_L));
6182 SYSCTL_ADD_T4_REG64(pi, "rx_frames_128_255",
6183 "# of rx frames in this range",
6184 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_128B_255B_L));
6185 SYSCTL_ADD_T4_REG64(pi, "rx_frames_256_511",
6186 "# of rx frames in this range",
6187 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_256B_511B_L));
6188 SYSCTL_ADD_T4_REG64(pi, "rx_frames_512_1023",
6189 "# of rx frames in this range",
6190 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_512B_1023B_L));
6191 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1024_1518",
6192 "# of rx frames in this range",
6193 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1024B_1518B_L));
6194 SYSCTL_ADD_T4_REG64(pi, "rx_frames_1519_max",
6195 "# of rx frames in this range",
6196 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_1519B_MAX_L));
6197 SYSCTL_ADD_T4_REG64(pi, "rx_pause", "# of pause frames received",
6198 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PAUSE_L));
6199 SYSCTL_ADD_T4_REG64(pi, "rx_ppp0", "# of PPP prio 0 frames received",
6200 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP0_L));
6201 SYSCTL_ADD_T4_REG64(pi, "rx_ppp1", "# of PPP prio 1 frames received",
6202 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP1_L));
6203 SYSCTL_ADD_T4_REG64(pi, "rx_ppp2", "# of PPP prio 2 frames received",
6204 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP2_L));
6205 SYSCTL_ADD_T4_REG64(pi, "rx_ppp3", "# of PPP prio 3 frames received",
6206 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP3_L));
6207 SYSCTL_ADD_T4_REG64(pi, "rx_ppp4", "# of PPP prio 4 frames received",
6208 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP4_L));
6209 SYSCTL_ADD_T4_REG64(pi, "rx_ppp5", "# of PPP prio 5 frames received",
6210 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP5_L));
6211 SYSCTL_ADD_T4_REG64(pi, "rx_ppp6", "# of PPP prio 6 frames received",
6212 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP6_L));
6213 SYSCTL_ADD_T4_REG64(pi, "rx_ppp7", "# of PPP prio 7 frames received",
6214 PORT_REG(pi->tx_chan, A_MPS_PORT_STAT_RX_PORT_PPP7_L));
6216 #undef SYSCTL_ADD_T4_REG64
6218 #define SYSCTL_ADD_T4_PORTSTAT(name, desc) \
6219 SYSCTL_ADD_UQUAD(ctx, children, OID_AUTO, #name, CTLFLAG_RD, \
6220 &pi->stats.name, desc)
6222 /* We get these from port_stats and they may be stale by up to 1s */
6223 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow0,
6224 "# drops due to buffer-group 0 overflows");
6225 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow1,
6226 "# drops due to buffer-group 1 overflows");
6227 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow2,
6228 "# drops due to buffer-group 2 overflows");
6229 SYSCTL_ADD_T4_PORTSTAT(rx_ovflow3,
6230 "# drops due to buffer-group 3 overflows");
6231 SYSCTL_ADD_T4_PORTSTAT(rx_trunc0,
6232 "# of buffer-group 0 truncated packets");
6233 SYSCTL_ADD_T4_PORTSTAT(rx_trunc1,
6234 "# of buffer-group 1 truncated packets");
6235 SYSCTL_ADD_T4_PORTSTAT(rx_trunc2,
6236 "# of buffer-group 2 truncated packets");
6237 SYSCTL_ADD_T4_PORTSTAT(rx_trunc3,
6238 "# of buffer-group 3 truncated packets");
6240 #undef SYSCTL_ADD_T4_PORTSTAT
6242 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "tx_tls_records",
6243 CTLFLAG_RD, &pi->tx_tls_records,
6244 "# of TLS records transmitted");
6245 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "tx_tls_octets",
6246 CTLFLAG_RD, &pi->tx_tls_octets,
6247 "# of payload octets in transmitted TLS records");
6248 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "rx_tls_records",
6249 CTLFLAG_RD, &pi->rx_tls_records,
6250 "# of TLS records received");
6251 SYSCTL_ADD_ULONG(ctx, children, OID_AUTO, "rx_tls_octets",
6252 CTLFLAG_RD, &pi->rx_tls_octets,
6253 "# of payload octets in received TLS records");
6257 sysctl_int_array(SYSCTL_HANDLER_ARGS)
6259 int rc, *i, space = 0;
6262 sbuf_new_for_sysctl(&sb, NULL, 64, req);
6263 for (i = arg1; arg2; arg2 -= sizeof(int), i++) {
6265 sbuf_printf(&sb, " ");
6266 sbuf_printf(&sb, "%d", *i);
6269 rc = sbuf_finish(&sb);
6275 sysctl_bitfield(SYSCTL_HANDLER_ARGS)
6280 rc = sysctl_wire_old_buffer(req, 0);
6284 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
6288 sbuf_printf(sb, "%b", (int)arg2, (char *)arg1);
6289 rc = sbuf_finish(sb);
6296 sysctl_btphy(SYSCTL_HANDLER_ARGS)
6298 struct port_info *pi = arg1;
6300 struct adapter *sc = pi->adapter;
6304 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK, "t4btt");
6307 /* XXX: magic numbers */
6308 rc = -t4_mdio_rd(sc, sc->mbox, pi->mdio_addr, 0x1e, op ? 0x20 : 0xc820,
6310 end_synchronized_op(sc, 0);
6316 rc = sysctl_handle_int(oidp, &v, 0, req);
6321 sysctl_noflowq(SYSCTL_HANDLER_ARGS)
6323 struct vi_info *vi = arg1;
6326 val = vi->rsrv_noflowq;
6327 rc = sysctl_handle_int(oidp, &val, 0, req);
6328 if (rc != 0 || req->newptr == NULL)
6331 if ((val >= 1) && (vi->ntxq > 1))
6332 vi->rsrv_noflowq = 1;
6334 vi->rsrv_noflowq = 0;
6340 sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS)
6342 struct vi_info *vi = arg1;
6343 struct adapter *sc = vi->pi->adapter;
6345 struct sge_rxq *rxq;
6350 rc = sysctl_handle_int(oidp, &idx, 0, req);
6351 if (rc != 0 || req->newptr == NULL)
6354 if (idx < 0 || idx >= SGE_NTIMERS)
6357 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
6362 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(vi->pktc_idx != -1);
6363 for_each_rxq(vi, i, rxq) {
6364 #ifdef atomic_store_rel_8
6365 atomic_store_rel_8(&rxq->iq.intr_params, v);
6367 rxq->iq.intr_params = v;
6372 end_synchronized_op(sc, LOCK_HELD);
6377 sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS)
6379 struct vi_info *vi = arg1;
6380 struct adapter *sc = vi->pi->adapter;
6385 rc = sysctl_handle_int(oidp, &idx, 0, req);
6386 if (rc != 0 || req->newptr == NULL)
6389 if (idx < -1 || idx >= SGE_NCOUNTERS)
6392 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
6397 if (vi->flags & VI_INIT_DONE)
6398 rc = EBUSY; /* cannot be changed once the queues are created */
6402 end_synchronized_op(sc, LOCK_HELD);
6407 sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS)
6409 struct vi_info *vi = arg1;
6410 struct adapter *sc = vi->pi->adapter;
6413 qsize = vi->qsize_rxq;
6415 rc = sysctl_handle_int(oidp, &qsize, 0, req);
6416 if (rc != 0 || req->newptr == NULL)
6419 if (qsize < 128 || (qsize & 7))
6422 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
6427 if (vi->flags & VI_INIT_DONE)
6428 rc = EBUSY; /* cannot be changed once the queues are created */
6430 vi->qsize_rxq = qsize;
6432 end_synchronized_op(sc, LOCK_HELD);
6437 sysctl_qsize_txq(SYSCTL_HANDLER_ARGS)
6439 struct vi_info *vi = arg1;
6440 struct adapter *sc = vi->pi->adapter;
6443 qsize = vi->qsize_txq;
6445 rc = sysctl_handle_int(oidp, &qsize, 0, req);
6446 if (rc != 0 || req->newptr == NULL)
6449 if (qsize < 128 || qsize > 65536)
6452 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
6457 if (vi->flags & VI_INIT_DONE)
6458 rc = EBUSY; /* cannot be changed once the queues are created */
6460 vi->qsize_txq = qsize;
6462 end_synchronized_op(sc, LOCK_HELD);
6467 sysctl_pause_settings(SYSCTL_HANDLER_ARGS)
6469 struct port_info *pi = arg1;
6470 struct adapter *sc = pi->adapter;
6471 struct link_config *lc = &pi->link_cfg;
6474 if (req->newptr == NULL) {
6476 static char *bits = "\20\1RX\2TX\3AUTO";
6478 rc = sysctl_wire_old_buffer(req, 0);
6482 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
6487 sbuf_printf(sb, "%b", (lc->fc & (PAUSE_TX | PAUSE_RX)) |
6488 (lc->requested_fc & PAUSE_AUTONEG), bits);
6490 sbuf_printf(sb, "%b", lc->requested_fc & (PAUSE_TX |
6491 PAUSE_RX | PAUSE_AUTONEG), bits);
6493 rc = sbuf_finish(sb);
6499 s[0] = '0' + (lc->requested_fc & (PAUSE_TX | PAUSE_RX |
6503 rc = sysctl_handle_string(oidp, s, sizeof(s), req);
6509 if (s[0] < '0' || s[0] > '9')
6510 return (EINVAL); /* not a number */
6512 if (n & ~(PAUSE_TX | PAUSE_RX | PAUSE_AUTONEG))
6513 return (EINVAL); /* some other bit is set too */
6515 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK,
6520 lc->requested_fc = n;
6521 fixup_link_config(pi);
6523 rc = apply_link_config(pi);
6524 set_current_media(pi);
6526 end_synchronized_op(sc, 0);
6533 sysctl_fec(SYSCTL_HANDLER_ARGS)
6535 struct port_info *pi = arg1;
6536 struct adapter *sc = pi->adapter;
6537 struct link_config *lc = &pi->link_cfg;
6541 if (req->newptr == NULL) {
6543 static char *bits = "\20\1RS\2BASE-R\3RSVD1\4RSVD2\5RSVD3\6AUTO";
6545 rc = sysctl_wire_old_buffer(req, 0);
6549 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req);
6554 * Display the requested_fec when the link is down -- the actual
6555 * FEC makes sense only when the link is up.
6558 sbuf_printf(sb, "%b", (lc->fec & M_FW_PORT_CAP32_FEC) |
6559 (lc->requested_fec & FEC_AUTO), bits);
6561 sbuf_printf(sb, "%b", lc->requested_fec, bits);
6563 rc = sbuf_finish(sb);
6569 snprintf(s, sizeof(s), "%d",
6570 lc->requested_fec == FEC_AUTO ? -1 :
6571 lc->requested_fec & M_FW_PORT_CAP32_FEC);
6573 rc = sysctl_handle_string(oidp, s, sizeof(s), req);
6577 n = strtol(&s[0], NULL, 0);
6578 if (n < 0 || n & FEC_AUTO)
6581 if (n & ~M_FW_PORT_CAP32_FEC)
6582 return (EINVAL);/* some other bit is set too */
6584 return (EINVAL);/* one bit can be set at most */
6587 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK,
6592 old = lc->requested_fec;
6594 lc->requested_fec = FEC_AUTO;
6596 lc->requested_fec = FEC_NONE;
6598 if ((lc->supported | V_FW_PORT_CAP32_FEC(n)) !=
6603 lc->requested_fec = n;
6605 fixup_link_config(pi);
6606 if (pi->up_vis > 0) {
6607 rc = apply_link_config(pi);
6609 lc->requested_fec = old;
6610 if (rc == FW_EPROTO)
6616 end_synchronized_op(sc, 0);
6623 sysctl_autoneg(SYSCTL_HANDLER_ARGS)
6625 struct port_info *pi = arg1;
6626 struct adapter *sc = pi->adapter;
6627 struct link_config *lc = &pi->link_cfg;
6630 if (lc->supported & FW_PORT_CAP32_ANEG)
6631 val = lc->requested_aneg == AUTONEG_DISABLE ? 0 : 1;
6634 rc = sysctl_handle_int(oidp, &val, 0, req);
6635 if (rc != 0 || req->newptr == NULL)
6638 val = AUTONEG_DISABLE;
6640 val = AUTONEG_ENABLE;
6644 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK,
6649 if (val == AUTONEG_ENABLE && !(lc->supported & FW_PORT_CAP32_ANEG)) {
6653 lc->requested_aneg = val;
6654 fixup_link_config(pi);
6656 rc = apply_link_config(pi);
6657 set_current_media(pi);
6660 end_synchronized_op(sc, 0);
6665 sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS)
6667 struct adapter *sc = arg1;
6671 val = t4_read_reg64(sc, reg);
6673 return (sysctl_handle_64(oidp, &val, 0, req));
6677 sysctl_temperature(SYSCTL_HANDLER_ARGS)
6679 struct adapter *sc = arg1;
6681 uint32_t param, val;
6683 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4temp");
6686 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
6687 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) |
6688 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_TMP);
6689 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
6690 end_synchronized_op(sc, 0);
6694 /* unknown is returned as 0 but we display -1 in that case */
6695 t = val == 0 ? -1 : val;
6697 rc = sysctl_handle_int(oidp, &t, 0, req);
6703 sysctl_loadavg(SYSCTL_HANDLER_ARGS)
6705 struct adapter *sc = arg1;
6708 uint32_t param, val;
6710 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4lavg");
6713 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) |
6714 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_LOAD);
6715 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
6716 end_synchronized_op(sc, 0);
6720 rc = sysctl_wire_old_buffer(req, 0);
6724 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6728 if (val == 0xffffffff) {
6729 /* Only debug and custom firmwares report load averages. */
6730 sbuf_printf(sb, "not available");
6732 sbuf_printf(sb, "%d %d %d", val & 0xff, (val >> 8) & 0xff,
6733 (val >> 16) & 0xff);
6735 rc = sbuf_finish(sb);
6742 sysctl_cctrl(SYSCTL_HANDLER_ARGS)
6744 struct adapter *sc = arg1;
6747 uint16_t incr[NMTUS][NCCTRL_WIN];
6748 static const char *dec_fac[] = {
6749 "0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
6753 rc = sysctl_wire_old_buffer(req, 0);
6757 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6761 t4_read_cong_tbl(sc, incr);
6763 for (i = 0; i < NCCTRL_WIN; ++i) {
6764 sbuf_printf(sb, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
6765 incr[0][i], incr[1][i], incr[2][i], incr[3][i], incr[4][i],
6766 incr[5][i], incr[6][i], incr[7][i]);
6767 sbuf_printf(sb, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
6768 incr[8][i], incr[9][i], incr[10][i], incr[11][i],
6769 incr[12][i], incr[13][i], incr[14][i], incr[15][i],
6770 sc->params.a_wnd[i], dec_fac[sc->params.b_wnd[i]]);
6773 rc = sbuf_finish(sb);
6779 static const char *qname[CIM_NUM_IBQ + CIM_NUM_OBQ_T5] = {
6780 "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI", /* ibq's */
6781 "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI", /* obq's */
6782 "SGE0-RX", "SGE1-RX" /* additional obq's (T5 onwards) */
6786 sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS)
6788 struct adapter *sc = arg1;
6790 int rc, i, n, qid = arg2;
6793 u_int cim_num_obq = sc->chip_params->cim_num_obq;
6795 KASSERT(qid >= 0 && qid < CIM_NUM_IBQ + cim_num_obq,
6796 ("%s: bad qid %d\n", __func__, qid));
6798 if (qid < CIM_NUM_IBQ) {
6801 n = 4 * CIM_IBQ_SIZE;
6802 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
6803 rc = t4_read_cim_ibq(sc, qid, buf, n);
6805 /* outbound queue */
6808 n = 4 * cim_num_obq * CIM_OBQ_SIZE;
6809 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK);
6810 rc = t4_read_cim_obq(sc, qid, buf, n);
6817 n = rc * sizeof(uint32_t); /* rc has # of words actually read */
6819 rc = sysctl_wire_old_buffer(req, 0);
6823 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
6829 sbuf_printf(sb, "%s%d %s", qtype , qid, qname[arg2]);
6830 for (i = 0, p = buf; i < n; i += 16, p += 4)
6831 sbuf_printf(sb, "\n%#06x: %08x %08x %08x %08x", i, p[0], p[1],
6834 rc = sbuf_finish(sb);
6842 sysctl_cim_la(SYSCTL_HANDLER_ARGS)
6844 struct adapter *sc = arg1;
6850 MPASS(chip_id(sc) <= CHELSIO_T5);
6852 rc = -t4_cim_read(sc, A_UP_UP_DBG_LA_CFG, 1, &cfg);
6856 rc = sysctl_wire_old_buffer(req, 0);
6860 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6864 buf = malloc(sc->params.cim_la_size * sizeof(uint32_t), M_CXGBE,
6867 rc = -t4_cim_read_la(sc, buf, NULL);
6871 sbuf_printf(sb, "Status Data PC%s",
6872 cfg & F_UPDBGLACAPTPCONLY ? "" :
6873 " LS0Stat LS0Addr LS0Data");
6875 for (p = buf; p <= &buf[sc->params.cim_la_size - 8]; p += 8) {
6876 if (cfg & F_UPDBGLACAPTPCONLY) {
6877 sbuf_printf(sb, "\n %02x %08x %08x", p[5] & 0xff,
6879 sbuf_printf(sb, "\n %02x %02x%06x %02x%06x",
6880 (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8,
6881 p[4] & 0xff, p[5] >> 8);
6882 sbuf_printf(sb, "\n %02x %x%07x %x%07x",
6883 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
6884 p[1] & 0xf, p[2] >> 4);
6887 "\n %02x %x%07x %x%07x %08x %08x "
6889 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
6890 p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5],
6895 rc = sbuf_finish(sb);
6903 sysctl_cim_la_t6(SYSCTL_HANDLER_ARGS)
6905 struct adapter *sc = arg1;
6911 MPASS(chip_id(sc) > CHELSIO_T5);
6913 rc = -t4_cim_read(sc, A_UP_UP_DBG_LA_CFG, 1, &cfg);
6917 rc = sysctl_wire_old_buffer(req, 0);
6921 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6925 buf = malloc(sc->params.cim_la_size * sizeof(uint32_t), M_CXGBE,
6928 rc = -t4_cim_read_la(sc, buf, NULL);
6932 sbuf_printf(sb, "Status Inst Data PC%s",
6933 cfg & F_UPDBGLACAPTPCONLY ? "" :
6934 " LS0Stat LS0Addr LS0Data LS1Stat LS1Addr LS1Data");
6936 for (p = buf; p <= &buf[sc->params.cim_la_size - 10]; p += 10) {
6937 if (cfg & F_UPDBGLACAPTPCONLY) {
6938 sbuf_printf(sb, "\n %02x %08x %08x %08x",
6939 p[3] & 0xff, p[2], p[1], p[0]);
6940 sbuf_printf(sb, "\n %02x %02x%06x %02x%06x %02x%06x",
6941 (p[6] >> 8) & 0xff, p[6] & 0xff, p[5] >> 8,
6942 p[5] & 0xff, p[4] >> 8, p[4] & 0xff, p[3] >> 8);
6943 sbuf_printf(sb, "\n %02x %04x%04x %04x%04x %04x%04x",
6944 (p[9] >> 16) & 0xff, p[9] & 0xffff, p[8] >> 16,
6945 p[8] & 0xffff, p[7] >> 16, p[7] & 0xffff,
6948 sbuf_printf(sb, "\n %02x %04x%04x %04x%04x %04x%04x "
6949 "%08x %08x %08x %08x %08x %08x",
6950 (p[9] >> 16) & 0xff,
6951 p[9] & 0xffff, p[8] >> 16,
6952 p[8] & 0xffff, p[7] >> 16,
6953 p[7] & 0xffff, p[6] >> 16,
6954 p[2], p[1], p[0], p[5], p[4], p[3]);
6958 rc = sbuf_finish(sb);
6966 sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS)
6968 struct adapter *sc = arg1;
6974 rc = sysctl_wire_old_buffer(req, 0);
6978 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
6982 buf = malloc(2 * CIM_MALA_SIZE * 5 * sizeof(uint32_t), M_CXGBE,
6985 t4_cim_read_ma_la(sc, buf, buf + 5 * CIM_MALA_SIZE);
6988 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
6989 sbuf_printf(sb, "\n%02x%08x%08x%08x%08x", p[4], p[3], p[2],
6993 sbuf_printf(sb, "\n\nCnt ID Tag UE Data RDY VLD");
6994 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) {
6995 sbuf_printf(sb, "\n%3u %2u %x %u %08x%08x %u %u",
6996 (p[2] >> 10) & 0xff, (p[2] >> 7) & 7,
6997 (p[2] >> 3) & 0xf, (p[2] >> 2) & 1,
6998 (p[1] >> 2) | ((p[2] & 3) << 30),
6999 (p[0] >> 2) | ((p[1] & 3) << 30), (p[0] >> 1) & 1,
7003 rc = sbuf_finish(sb);
7010 sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS)
7012 struct adapter *sc = arg1;
7018 rc = sysctl_wire_old_buffer(req, 0);
7022 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7026 buf = malloc(2 * CIM_PIFLA_SIZE * 6 * sizeof(uint32_t), M_CXGBE,
7029 t4_cim_read_pif_la(sc, buf, buf + 6 * CIM_PIFLA_SIZE, NULL, NULL);
7032 sbuf_printf(sb, "Cntl ID DataBE Addr Data");
7033 for (i = 0; i < CIM_PIFLA_SIZE; i++, p += 6) {
7034 sbuf_printf(sb, "\n %02x %02x %04x %08x %08x%08x%08x%08x",
7035 (p[5] >> 22) & 0xff, (p[5] >> 16) & 0x3f, p[5] & 0xffff,
7036 p[4], p[3], p[2], p[1], p[0]);
7039 sbuf_printf(sb, "\n\nCntl ID Data");
7040 for (i = 0; i < CIM_PIFLA_SIZE; i++, p += 6) {
7041 sbuf_printf(sb, "\n %02x %02x %08x%08x%08x%08x",
7042 (p[4] >> 6) & 0xff, p[4] & 0x3f, p[3], p[2], p[1], p[0]);
7045 rc = sbuf_finish(sb);
7052 sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS)
7054 struct adapter *sc = arg1;
7057 uint16_t base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
7058 uint16_t size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
7059 uint16_t thres[CIM_NUM_IBQ];
7060 uint32_t obq_wr[2 * CIM_NUM_OBQ_T5], *wr = obq_wr;
7061 uint32_t stat[4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5)], *p = stat;
7062 u_int cim_num_obq, ibq_rdaddr, obq_rdaddr, nq;
7064 cim_num_obq = sc->chip_params->cim_num_obq;
7066 ibq_rdaddr = A_UP_IBQ_0_RDADDR;
7067 obq_rdaddr = A_UP_OBQ_0_REALADDR;
7069 ibq_rdaddr = A_UP_IBQ_0_SHADOW_RDADDR;
7070 obq_rdaddr = A_UP_OBQ_0_SHADOW_REALADDR;
7072 nq = CIM_NUM_IBQ + cim_num_obq;
7074 rc = -t4_cim_read(sc, ibq_rdaddr, 4 * nq, stat);
7076 rc = -t4_cim_read(sc, obq_rdaddr, 2 * cim_num_obq, obq_wr);
7080 t4_read_cimq_cfg(sc, base, size, thres);
7082 rc = sysctl_wire_old_buffer(req, 0);
7086 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req);
7091 " Queue Base Size Thres RdPtr WrPtr SOP EOP Avail");
7093 for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
7094 sbuf_printf(sb, "\n%7s %5x %5u %5u %6x %4x %4u %4u %5u",
7095 qname[i], base[i], size[i], thres[i], G_IBQRDADDR(p[0]),
7096 G_IBQWRADDR(p[1]), G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
7097 G_QUEREMFLITS(p[2]) * 16);
7098 for ( ; i < nq; i++, p += 4, wr += 2)
7099 sbuf_printf(sb, "\n%7s %5x %5u %12x %4x %4u %4u %5u", qname[i],
7100 base[i], size[i], G_QUERDADDR(p[0]) & 0x3fff,
7101 wr[0] - base[i], G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]),
7102 G_QUEREMFLITS(p[2]) * 16);
7104 rc = sbuf_finish(sb);
7111 sysctl_cpl_stats(SYSCTL_HANDLER_ARGS)
7113 struct adapter *sc = arg1;
7116 struct tp_cpl_stats stats;
7118 rc = sysctl_wire_old_buffer(req, 0);
7122 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7126 mtx_lock(&sc->reg_lock);
7127 t4_tp_get_cpl_stats(sc, &stats, 0);
7128 mtx_unlock(&sc->reg_lock);
7130 if (sc->chip_params->nchan > 2) {
7131 sbuf_printf(sb, " channel 0 channel 1"
7132 " channel 2 channel 3");
7133 sbuf_printf(sb, "\nCPL requests: %10u %10u %10u %10u",
7134 stats.req[0], stats.req[1], stats.req[2], stats.req[3]);
7135 sbuf_printf(sb, "\nCPL responses: %10u %10u %10u %10u",
7136 stats.rsp[0], stats.rsp[1], stats.rsp[2], stats.rsp[3]);
7138 sbuf_printf(sb, " channel 0 channel 1");
7139 sbuf_printf(sb, "\nCPL requests: %10u %10u",
7140 stats.req[0], stats.req[1]);
7141 sbuf_printf(sb, "\nCPL responses: %10u %10u",
7142 stats.rsp[0], stats.rsp[1]);
7145 rc = sbuf_finish(sb);
7152 sysctl_ddp_stats(SYSCTL_HANDLER_ARGS)
7154 struct adapter *sc = arg1;
7157 struct tp_usm_stats stats;
7159 rc = sysctl_wire_old_buffer(req, 0);
7163 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7167 t4_get_usm_stats(sc, &stats, 1);
7169 sbuf_printf(sb, "Frames: %u\n", stats.frames);
7170 sbuf_printf(sb, "Octets: %ju\n", stats.octets);
7171 sbuf_printf(sb, "Drops: %u", stats.drops);
7173 rc = sbuf_finish(sb);
7179 static const char * const devlog_level_strings[] = {
7180 [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
7181 [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
7182 [FW_DEVLOG_LEVEL_ERR] = "ERR",
7183 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
7184 [FW_DEVLOG_LEVEL_INFO] = "INFO",
7185 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
7188 static const char * const devlog_facility_strings[] = {
7189 [FW_DEVLOG_FACILITY_CORE] = "CORE",
7190 [FW_DEVLOG_FACILITY_CF] = "CF",
7191 [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
7192 [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
7193 [FW_DEVLOG_FACILITY_RES] = "RES",
7194 [FW_DEVLOG_FACILITY_HW] = "HW",
7195 [FW_DEVLOG_FACILITY_FLR] = "FLR",
7196 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
7197 [FW_DEVLOG_FACILITY_PHY] = "PHY",
7198 [FW_DEVLOG_FACILITY_MAC] = "MAC",
7199 [FW_DEVLOG_FACILITY_PORT] = "PORT",
7200 [FW_DEVLOG_FACILITY_VI] = "VI",
7201 [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
7202 [FW_DEVLOG_FACILITY_ACL] = "ACL",
7203 [FW_DEVLOG_FACILITY_TM] = "TM",
7204 [FW_DEVLOG_FACILITY_QFC] = "QFC",
7205 [FW_DEVLOG_FACILITY_DCB] = "DCB",
7206 [FW_DEVLOG_FACILITY_ETH] = "ETH",
7207 [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
7208 [FW_DEVLOG_FACILITY_RI] = "RI",
7209 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
7210 [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
7211 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
7212 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE",
7213 [FW_DEVLOG_FACILITY_CHNET] = "CHNET",
7217 sysctl_devlog(SYSCTL_HANDLER_ARGS)
7219 struct adapter *sc = arg1;
7220 struct devlog_params *dparams = &sc->params.devlog;
7221 struct fw_devlog_e *buf, *e;
7222 int i, j, rc, nentries, first = 0;
7224 uint64_t ftstamp = UINT64_MAX;
7226 if (dparams->addr == 0)
7229 buf = malloc(dparams->size, M_CXGBE, M_NOWAIT);
7233 rc = read_via_memwin(sc, 1, dparams->addr, (void *)buf, dparams->size);
7237 nentries = dparams->size / sizeof(struct fw_devlog_e);
7238 for (i = 0; i < nentries; i++) {
7241 if (e->timestamp == 0)
7244 e->timestamp = be64toh(e->timestamp);
7245 e->seqno = be32toh(e->seqno);
7246 for (j = 0; j < 8; j++)
7247 e->params[j] = be32toh(e->params[j]);
7249 if (e->timestamp < ftstamp) {
7250 ftstamp = e->timestamp;
7255 if (buf[first].timestamp == 0)
7256 goto done; /* nothing in the log */
7258 rc = sysctl_wire_old_buffer(req, 0);
7262 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7267 sbuf_printf(sb, "%10s %15s %8s %8s %s\n",
7268 "Seq#", "Tstamp", "Level", "Facility", "Message");
7273 if (e->timestamp == 0)
7276 sbuf_printf(sb, "%10d %15ju %8s %8s ",
7277 e->seqno, e->timestamp,
7278 (e->level < nitems(devlog_level_strings) ?
7279 devlog_level_strings[e->level] : "UNKNOWN"),
7280 (e->facility < nitems(devlog_facility_strings) ?
7281 devlog_facility_strings[e->facility] : "UNKNOWN"));
7282 sbuf_printf(sb, e->fmt, e->params[0], e->params[1],
7283 e->params[2], e->params[3], e->params[4],
7284 e->params[5], e->params[6], e->params[7]);
7286 if (++i == nentries)
7288 } while (i != first);
7290 rc = sbuf_finish(sb);
7298 sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS)
7300 struct adapter *sc = arg1;
7303 struct tp_fcoe_stats stats[MAX_NCHAN];
7304 int i, nchan = sc->chip_params->nchan;
7306 rc = sysctl_wire_old_buffer(req, 0);
7310 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7314 for (i = 0; i < nchan; i++)
7315 t4_get_fcoe_stats(sc, i, &stats[i], 1);
7318 sbuf_printf(sb, " channel 0 channel 1"
7319 " channel 2 channel 3");
7320 sbuf_printf(sb, "\noctetsDDP: %16ju %16ju %16ju %16ju",
7321 stats[0].octets_ddp, stats[1].octets_ddp,
7322 stats[2].octets_ddp, stats[3].octets_ddp);
7323 sbuf_printf(sb, "\nframesDDP: %16u %16u %16u %16u",
7324 stats[0].frames_ddp, stats[1].frames_ddp,
7325 stats[2].frames_ddp, stats[3].frames_ddp);
7326 sbuf_printf(sb, "\nframesDrop: %16u %16u %16u %16u",
7327 stats[0].frames_drop, stats[1].frames_drop,
7328 stats[2].frames_drop, stats[3].frames_drop);
7330 sbuf_printf(sb, " channel 0 channel 1");
7331 sbuf_printf(sb, "\noctetsDDP: %16ju %16ju",
7332 stats[0].octets_ddp, stats[1].octets_ddp);
7333 sbuf_printf(sb, "\nframesDDP: %16u %16u",
7334 stats[0].frames_ddp, stats[1].frames_ddp);
7335 sbuf_printf(sb, "\nframesDrop: %16u %16u",
7336 stats[0].frames_drop, stats[1].frames_drop);
7339 rc = sbuf_finish(sb);
7346 sysctl_hw_sched(SYSCTL_HANDLER_ARGS)
7348 struct adapter *sc = arg1;
7351 unsigned int map, kbps, ipg, mode;
7352 unsigned int pace_tab[NTX_SCHED];
7354 rc = sysctl_wire_old_buffer(req, 0);
7358 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
7362 map = t4_read_reg(sc, A_TP_TX_MOD_QUEUE_REQ_MAP);
7363 mode = G_TIMERMODE(t4_read_reg(sc, A_TP_MOD_CONFIG));
7364 t4_read_pace_tbl(sc, pace_tab);
7366 sbuf_printf(sb, "Scheduler Mode Channel Rate (Kbps) "
7367 "Class IPG (0.1 ns) Flow IPG (us)");
7369 for (i = 0; i < NTX_SCHED; ++i, map >>= 2) {
7370 t4_get_tx_sched(sc, i, &kbps, &ipg, 1);
7371 sbuf_printf(sb, "\n %u %-5s %u ", i,
7372 (mode & (1 << i)) ? "flow" : "class", map & 3);
7374 sbuf_printf(sb, "%9u ", kbps);
7376 sbuf_printf(sb, " disabled ");
7379 sbuf_printf(sb, "%13u ", ipg);
7381 sbuf_printf(sb, " disabled ");
7384 sbuf_printf(sb, "%10u", pace_tab[i]);
7386 sbuf_printf(sb, " disabled");
7389 rc = sbuf_finish(sb);
7396 sysctl_lb_stats(SYSCTL_HANDLER_ARGS)
7398 struct adapter *sc = arg1;
7402 struct lb_port_stats s[2];
7403 static const char *stat_name[] = {
7404 "OctetsOK:", "FramesOK:", "BcastFrames:", "McastFrames:",
7405 "UcastFrames:", "ErrorFrames:", "Frames64:", "Frames65To127:",
7406 "Frames128To255:", "Frames256To511:", "Frames512To1023:",
7407 "Frames1024To1518:", "Frames1519ToMax:", "FramesDropped:",
7408 "BG0FramesDropped:", "BG1FramesDropped:", "BG2FramesDropped:",
7409 "BG3FramesDropped:", "BG0FramesTrunc:", "BG1FramesTrunc:",
7410 "BG2FramesTrunc:", "BG3FramesTrunc:"
7413 rc = sysctl_wire_old_buffer(req, 0);
7417 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7421 memset(s, 0, sizeof(s));
7423 for (i = 0; i < sc->chip_params->nchan; i += 2) {
7424 t4_get_lb_stats(sc, i, &s[0]);
7425 t4_get_lb_stats(sc, i + 1, &s[1]);
7429 sbuf_printf(sb, "%s Loopback %u"
7430 " Loopback %u", i == 0 ? "" : "\n", i, i + 1);
7432 for (j = 0; j < nitems(stat_name); j++)
7433 sbuf_printf(sb, "\n%-17s %20ju %20ju", stat_name[j],
7437 rc = sbuf_finish(sb);
7444 sysctl_linkdnrc(SYSCTL_HANDLER_ARGS)
7447 struct port_info *pi = arg1;
7448 struct link_config *lc = &pi->link_cfg;
7451 rc = sysctl_wire_old_buffer(req, 0);
7454 sb = sbuf_new_for_sysctl(NULL, NULL, 64, req);
7458 if (lc->link_ok || lc->link_down_rc == 255)
7459 sbuf_printf(sb, "n/a");
7461 sbuf_printf(sb, "%s", t4_link_down_rc_str(lc->link_down_rc));
7463 rc = sbuf_finish(sb);
7476 mem_desc_cmp(const void *a, const void *b)
7478 return ((const struct mem_desc *)a)->base -
7479 ((const struct mem_desc *)b)->base;
7483 mem_region_show(struct sbuf *sb, const char *name, unsigned int from,
7491 size = to - from + 1;
7495 /* XXX: need humanize_number(3) in libkern for a more readable 'size' */
7496 sbuf_printf(sb, "%-15s %#x-%#x [%u]\n", name, from, to, size);
7500 sysctl_meminfo(SYSCTL_HANDLER_ARGS)
7502 struct adapter *sc = arg1;
7505 uint32_t lo, hi, used, alloc;
7506 static const char *memory[] = {"EDC0:", "EDC1:", "MC:", "MC0:", "MC1:"};
7507 static const char *region[] = {
7508 "DBQ contexts:", "IMSG contexts:", "FLM cache:", "TCBs:",
7509 "Pstructs:", "Timers:", "Rx FL:", "Tx FL:", "Pstruct FL:",
7510 "Tx payload:", "Rx payload:", "LE hash:", "iSCSI region:",
7511 "TDDP region:", "TPT region:", "STAG region:", "RQ region:",
7512 "RQUDP region:", "PBL region:", "TXPBL region:",
7513 "DBVFIFO region:", "ULPRX state:", "ULPTX state:",
7514 "On-chip queues:", "TLS keys:",
7516 struct mem_desc avail[4];
7517 struct mem_desc mem[nitems(region) + 3]; /* up to 3 holes */
7518 struct mem_desc *md = mem;
7520 rc = sysctl_wire_old_buffer(req, 0);
7524 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7528 for (i = 0; i < nitems(mem); i++) {
7533 /* Find and sort the populated memory ranges */
7535 lo = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE);
7536 if (lo & F_EDRAM0_ENABLE) {
7537 hi = t4_read_reg(sc, A_MA_EDRAM0_BAR);
7538 avail[i].base = G_EDRAM0_BASE(hi) << 20;
7539 avail[i].limit = avail[i].base + (G_EDRAM0_SIZE(hi) << 20);
7543 if (lo & F_EDRAM1_ENABLE) {
7544 hi = t4_read_reg(sc, A_MA_EDRAM1_BAR);
7545 avail[i].base = G_EDRAM1_BASE(hi) << 20;
7546 avail[i].limit = avail[i].base + (G_EDRAM1_SIZE(hi) << 20);
7550 if (lo & F_EXT_MEM_ENABLE) {
7551 hi = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR);
7552 avail[i].base = G_EXT_MEM_BASE(hi) << 20;
7553 avail[i].limit = avail[i].base +
7554 (G_EXT_MEM_SIZE(hi) << 20);
7555 avail[i].idx = is_t5(sc) ? 3 : 2; /* Call it MC0 for T5 */
7558 if (is_t5(sc) && lo & F_EXT_MEM1_ENABLE) {
7559 hi = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR);
7560 avail[i].base = G_EXT_MEM1_BASE(hi) << 20;
7561 avail[i].limit = avail[i].base +
7562 (G_EXT_MEM1_SIZE(hi) << 20);
7566 if (!i) /* no memory available */
7568 qsort(avail, i, sizeof(struct mem_desc), mem_desc_cmp);
7570 (md++)->base = t4_read_reg(sc, A_SGE_DBQ_CTXT_BADDR);
7571 (md++)->base = t4_read_reg(sc, A_SGE_IMSG_CTXT_BADDR);
7572 (md++)->base = t4_read_reg(sc, A_SGE_FLM_CACHE_BADDR);
7573 (md++)->base = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
7574 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_BASE);
7575 (md++)->base = t4_read_reg(sc, A_TP_CMM_TIMER_BASE);
7576 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_RX_FLST_BASE);
7577 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_TX_FLST_BASE);
7578 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_PS_FLST_BASE);
7580 /* the next few have explicit upper bounds */
7581 md->base = t4_read_reg(sc, A_TP_PMM_TX_BASE);
7582 md->limit = md->base - 1 +
7583 t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE) *
7584 G_PMTXMAXPAGE(t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE));
7587 md->base = t4_read_reg(sc, A_TP_PMM_RX_BASE);
7588 md->limit = md->base - 1 +
7589 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) *
7590 G_PMRXMAXPAGE(t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE));
7593 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
7594 if (chip_id(sc) <= CHELSIO_T5)
7595 md->base = t4_read_reg(sc, A_LE_DB_HASH_TID_BASE);
7597 md->base = t4_read_reg(sc, A_LE_DB_HASH_TBL_BASE_ADDR);
7601 md->idx = nitems(region); /* hide it */
7605 #define ulp_region(reg) \
7606 md->base = t4_read_reg(sc, A_ULP_ ## reg ## _LLIMIT);\
7607 (md++)->limit = t4_read_reg(sc, A_ULP_ ## reg ## _ULIMIT)
7609 ulp_region(RX_ISCSI);
7610 ulp_region(RX_TDDP);
7612 ulp_region(RX_STAG);
7614 ulp_region(RX_RQUDP);
7620 md->idx = nitems(region);
7623 uint32_t sge_ctrl = t4_read_reg(sc, A_SGE_CONTROL2);
7624 uint32_t fifo_size = t4_read_reg(sc, A_SGE_DBVFIFO_SIZE);
7627 if (sge_ctrl & F_VFIFO_ENABLE)
7628 size = G_DBVFIFO_SIZE(fifo_size);
7630 size = G_T6_DBVFIFO_SIZE(fifo_size);
7633 md->base = G_BASEADDR(t4_read_reg(sc,
7634 A_SGE_DBVFIFO_BADDR));
7635 md->limit = md->base + (size << 2) - 1;
7640 md->base = t4_read_reg(sc, A_ULP_RX_CTX_BASE);
7643 md->base = t4_read_reg(sc, A_ULP_TX_ERR_TABLE_BASE);
7647 md->base = sc->vres.ocq.start;
7648 if (sc->vres.ocq.size)
7649 md->limit = md->base + sc->vres.ocq.size - 1;
7651 md->idx = nitems(region); /* hide it */
7654 md->base = sc->vres.key.start;
7655 if (sc->vres.key.size)
7656 md->limit = md->base + sc->vres.key.size - 1;
7658 md->idx = nitems(region); /* hide it */
7661 /* add any address-space holes, there can be up to 3 */
7662 for (n = 0; n < i - 1; n++)
7663 if (avail[n].limit < avail[n + 1].base)
7664 (md++)->base = avail[n].limit;
7666 (md++)->base = avail[n].limit;
7669 qsort(mem, n, sizeof(struct mem_desc), mem_desc_cmp);
7671 for (lo = 0; lo < i; lo++)
7672 mem_region_show(sb, memory[avail[lo].idx], avail[lo].base,
7673 avail[lo].limit - 1);
7675 sbuf_printf(sb, "\n");
7676 for (i = 0; i < n; i++) {
7677 if (mem[i].idx >= nitems(region))
7678 continue; /* skip holes */
7680 mem[i].limit = i < n - 1 ? mem[i + 1].base - 1 : ~0;
7681 mem_region_show(sb, region[mem[i].idx], mem[i].base,
7685 sbuf_printf(sb, "\n");
7686 lo = t4_read_reg(sc, A_CIM_SDRAM_BASE_ADDR);
7687 hi = t4_read_reg(sc, A_CIM_SDRAM_ADDR_SIZE) + lo - 1;
7688 mem_region_show(sb, "uP RAM:", lo, hi);
7690 lo = t4_read_reg(sc, A_CIM_EXTMEM2_BASE_ADDR);
7691 hi = t4_read_reg(sc, A_CIM_EXTMEM2_ADDR_SIZE) + lo - 1;
7692 mem_region_show(sb, "uP Extmem2:", lo, hi);
7694 lo = t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE);
7695 sbuf_printf(sb, "\n%u Rx pages of size %uKiB for %u channels\n",
7697 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) >> 10,
7698 (lo & F_PMRXNUMCHN) ? 2 : 1);
7700 lo = t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE);
7701 hi = t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE);
7702 sbuf_printf(sb, "%u Tx pages of size %u%ciB for %u channels\n",
7704 hi >= (1 << 20) ? (hi >> 20) : (hi >> 10),
7705 hi >= (1 << 20) ? 'M' : 'K', 1 << G_PMTXNUMCHN(lo));
7706 sbuf_printf(sb, "%u p-structs\n",
7707 t4_read_reg(sc, A_TP_CMM_MM_MAX_PSTRUCT));
7709 for (i = 0; i < 4; i++) {
7710 if (chip_id(sc) > CHELSIO_T5)
7711 lo = t4_read_reg(sc, A_MPS_RX_MAC_BG_PG_CNT0 + i * 4);
7713 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV0 + i * 4);
7715 used = G_T5_USED(lo);
7716 alloc = G_T5_ALLOC(lo);
7719 alloc = G_ALLOC(lo);
7721 /* For T6 these are MAC buffer groups */
7722 sbuf_printf(sb, "\nPort %d using %u pages out of %u allocated",
7725 for (i = 0; i < sc->chip_params->nchan; i++) {
7726 if (chip_id(sc) > CHELSIO_T5)
7727 lo = t4_read_reg(sc, A_MPS_RX_LPBK_BG_PG_CNT0 + i * 4);
7729 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV4 + i * 4);
7731 used = G_T5_USED(lo);
7732 alloc = G_T5_ALLOC(lo);
7735 alloc = G_ALLOC(lo);
7737 /* For T6 these are MAC buffer groups */
7739 "\nLoopback %d using %u pages out of %u allocated",
7743 rc = sbuf_finish(sb);
7750 tcamxy2valmask(uint64_t x, uint64_t y, uint8_t *addr, uint64_t *mask)
7754 memcpy(addr, (char *)&y + 2, ETHER_ADDR_LEN);
7758 sysctl_mps_tcam(SYSCTL_HANDLER_ARGS)
7760 struct adapter *sc = arg1;
7764 MPASS(chip_id(sc) <= CHELSIO_T5);
7766 rc = sysctl_wire_old_buffer(req, 0);
7770 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7775 "Idx Ethernet address Mask Vld Ports PF"
7776 " VF Replication P0 P1 P2 P3 ML");
7777 for (i = 0; i < sc->chip_params->mps_tcam_size; i++) {
7778 uint64_t tcamx, tcamy, mask;
7779 uint32_t cls_lo, cls_hi;
7780 uint8_t addr[ETHER_ADDR_LEN];
7782 tcamy = t4_read_reg64(sc, MPS_CLS_TCAM_Y_L(i));
7783 tcamx = t4_read_reg64(sc, MPS_CLS_TCAM_X_L(i));
7786 tcamxy2valmask(tcamx, tcamy, addr, &mask);
7787 cls_lo = t4_read_reg(sc, MPS_CLS_SRAM_L(i));
7788 cls_hi = t4_read_reg(sc, MPS_CLS_SRAM_H(i));
7789 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x %012jx"
7790 " %c %#x%4u%4d", i, addr[0], addr[1], addr[2],
7791 addr[3], addr[4], addr[5], (uintmax_t)mask,
7792 (cls_lo & F_SRAM_VLD) ? 'Y' : 'N',
7793 G_PORTMAP(cls_hi), G_PF(cls_lo),
7794 (cls_lo & F_VF_VALID) ? G_VF(cls_lo) : -1);
7796 if (cls_lo & F_REPLICATE) {
7797 struct fw_ldst_cmd ldst_cmd;
7799 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
7800 ldst_cmd.op_to_addrspace =
7801 htobe32(V_FW_CMD_OP(FW_LDST_CMD) |
7802 F_FW_CMD_REQUEST | F_FW_CMD_READ |
7803 V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MPS));
7804 ldst_cmd.cycles_to_len16 = htobe32(FW_LEN16(ldst_cmd));
7805 ldst_cmd.u.mps.rplc.fid_idx =
7806 htobe16(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) |
7807 V_FW_LDST_CMD_IDX(i));
7809 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK,
7813 rc = -t4_wr_mbox(sc, sc->mbox, &ldst_cmd,
7814 sizeof(ldst_cmd), &ldst_cmd);
7815 end_synchronized_op(sc, 0);
7818 sbuf_printf(sb, "%36d", rc);
7821 sbuf_printf(sb, " %08x %08x %08x %08x",
7822 be32toh(ldst_cmd.u.mps.rplc.rplc127_96),
7823 be32toh(ldst_cmd.u.mps.rplc.rplc95_64),
7824 be32toh(ldst_cmd.u.mps.rplc.rplc63_32),
7825 be32toh(ldst_cmd.u.mps.rplc.rplc31_0));
7828 sbuf_printf(sb, "%36s", "");
7830 sbuf_printf(sb, "%4u%3u%3u%3u %#3x", G_SRAM_PRIO0(cls_lo),
7831 G_SRAM_PRIO1(cls_lo), G_SRAM_PRIO2(cls_lo),
7832 G_SRAM_PRIO3(cls_lo), (cls_lo >> S_MULTILISTEN0) & 0xf);
7836 (void) sbuf_finish(sb);
7838 rc = sbuf_finish(sb);
7845 sysctl_mps_tcam_t6(SYSCTL_HANDLER_ARGS)
7847 struct adapter *sc = arg1;
7851 MPASS(chip_id(sc) > CHELSIO_T5);
7853 rc = sysctl_wire_old_buffer(req, 0);
7857 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
7861 sbuf_printf(sb, "Idx Ethernet address Mask VNI Mask"
7862 " IVLAN Vld DIP_Hit Lookup Port Vld Ports PF VF"
7864 " P0 P1 P2 P3 ML\n");
7866 for (i = 0; i < sc->chip_params->mps_tcam_size; i++) {
7867 uint8_t dip_hit, vlan_vld, lookup_type, port_num;
7869 uint64_t tcamx, tcamy, val, mask;
7870 uint32_t cls_lo, cls_hi, ctl, data2, vnix, vniy;
7871 uint8_t addr[ETHER_ADDR_LEN];
7873 ctl = V_CTLREQID(1) | V_CTLCMDTYPE(0) | V_CTLXYBITSEL(0);
7875 ctl |= V_CTLTCAMINDEX(i) | V_CTLTCAMSEL(0);
7877 ctl |= V_CTLTCAMINDEX(i - 256) | V_CTLTCAMSEL(1);
7878 t4_write_reg(sc, A_MPS_CLS_TCAM_DATA2_CTL, ctl);
7879 val = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA1_REQ_ID1);
7880 tcamy = G_DMACH(val) << 32;
7881 tcamy |= t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA0_REQ_ID1);
7882 data2 = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA2_REQ_ID1);
7883 lookup_type = G_DATALKPTYPE(data2);
7884 port_num = G_DATAPORTNUM(data2);
7885 if (lookup_type && lookup_type != M_DATALKPTYPE) {
7886 /* Inner header VNI */
7887 vniy = ((data2 & F_DATAVIDH2) << 23) |
7888 (G_DATAVIDH1(data2) << 16) | G_VIDL(val);
7889 dip_hit = data2 & F_DATADIPHIT;
7894 vlan_vld = data2 & F_DATAVIDH2;
7895 ivlan = G_VIDL(val);
7898 ctl |= V_CTLXYBITSEL(1);
7899 t4_write_reg(sc, A_MPS_CLS_TCAM_DATA2_CTL, ctl);
7900 val = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA1_REQ_ID1);
7901 tcamx = G_DMACH(val) << 32;
7902 tcamx |= t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA0_REQ_ID1);
7903 data2 = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA2_REQ_ID1);
7904 if (lookup_type && lookup_type != M_DATALKPTYPE) {
7905 /* Inner header VNI mask */
7906 vnix = ((data2 & F_DATAVIDH2) << 23) |
7907 (G_DATAVIDH1(data2) << 16) | G_VIDL(val);
7913 tcamxy2valmask(tcamx, tcamy, addr, &mask);
7915 cls_lo = t4_read_reg(sc, MPS_CLS_SRAM_L(i));
7916 cls_hi = t4_read_reg(sc, MPS_CLS_SRAM_H(i));
7918 if (lookup_type && lookup_type != M_DATALKPTYPE) {
7919 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x "
7920 "%012jx %06x %06x - - %3c"
7921 " 'I' %4x %3c %#x%4u%4d", i, addr[0],
7922 addr[1], addr[2], addr[3], addr[4], addr[5],
7923 (uintmax_t)mask, vniy, vnix, dip_hit ? 'Y' : 'N',
7924 port_num, cls_lo & F_T6_SRAM_VLD ? 'Y' : 'N',
7925 G_PORTMAP(cls_hi), G_T6_PF(cls_lo),
7926 cls_lo & F_T6_VF_VALID ? G_T6_VF(cls_lo) : -1);
7928 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x "
7929 "%012jx - - ", i, addr[0], addr[1],
7930 addr[2], addr[3], addr[4], addr[5],
7934 sbuf_printf(sb, "%4u Y ", ivlan);
7936 sbuf_printf(sb, " - N ");
7938 sbuf_printf(sb, "- %3c %4x %3c %#x%4u%4d",
7939 lookup_type ? 'I' : 'O', port_num,
7940 cls_lo & F_T6_SRAM_VLD ? 'Y' : 'N',
7941 G_PORTMAP(cls_hi), G_T6_PF(cls_lo),
7942 cls_lo & F_T6_VF_VALID ? G_T6_VF(cls_lo) : -1);
7946 if (cls_lo & F_T6_REPLICATE) {
7947 struct fw_ldst_cmd ldst_cmd;
7949 memset(&ldst_cmd, 0, sizeof(ldst_cmd));
7950 ldst_cmd.op_to_addrspace =
7951 htobe32(V_FW_CMD_OP(FW_LDST_CMD) |
7952 F_FW_CMD_REQUEST | F_FW_CMD_READ |
7953 V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MPS));
7954 ldst_cmd.cycles_to_len16 = htobe32(FW_LEN16(ldst_cmd));
7955 ldst_cmd.u.mps.rplc.fid_idx =
7956 htobe16(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) |
7957 V_FW_LDST_CMD_IDX(i));
7959 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK,
7963 rc = -t4_wr_mbox(sc, sc->mbox, &ldst_cmd,
7964 sizeof(ldst_cmd), &ldst_cmd);
7965 end_synchronized_op(sc, 0);
7968 sbuf_printf(sb, "%72d", rc);
7971 sbuf_printf(sb, " %08x %08x %08x %08x"
7972 " %08x %08x %08x %08x",
7973 be32toh(ldst_cmd.u.mps.rplc.rplc255_224),
7974 be32toh(ldst_cmd.u.mps.rplc.rplc223_192),
7975 be32toh(ldst_cmd.u.mps.rplc.rplc191_160),
7976 be32toh(ldst_cmd.u.mps.rplc.rplc159_128),
7977 be32toh(ldst_cmd.u.mps.rplc.rplc127_96),
7978 be32toh(ldst_cmd.u.mps.rplc.rplc95_64),
7979 be32toh(ldst_cmd.u.mps.rplc.rplc63_32),
7980 be32toh(ldst_cmd.u.mps.rplc.rplc31_0));
7983 sbuf_printf(sb, "%72s", "");
7985 sbuf_printf(sb, "%4u%3u%3u%3u %#x",
7986 G_T6_SRAM_PRIO0(cls_lo), G_T6_SRAM_PRIO1(cls_lo),
7987 G_T6_SRAM_PRIO2(cls_lo), G_T6_SRAM_PRIO3(cls_lo),
7988 (cls_lo >> S_T6_MULTILISTEN0) & 0xf);
7992 (void) sbuf_finish(sb);
7994 rc = sbuf_finish(sb);
8001 sysctl_path_mtus(SYSCTL_HANDLER_ARGS)
8003 struct adapter *sc = arg1;
8006 uint16_t mtus[NMTUS];
8008 rc = sysctl_wire_old_buffer(req, 0);
8012 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8016 t4_read_mtu_tbl(sc, mtus, NULL);
8018 sbuf_printf(sb, "%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u",
8019 mtus[0], mtus[1], mtus[2], mtus[3], mtus[4], mtus[5], mtus[6],
8020 mtus[7], mtus[8], mtus[9], mtus[10], mtus[11], mtus[12], mtus[13],
8021 mtus[14], mtus[15]);
8023 rc = sbuf_finish(sb);
8030 sysctl_pm_stats(SYSCTL_HANDLER_ARGS)
8032 struct adapter *sc = arg1;
8035 uint32_t tx_cnt[MAX_PM_NSTATS], rx_cnt[MAX_PM_NSTATS];
8036 uint64_t tx_cyc[MAX_PM_NSTATS], rx_cyc[MAX_PM_NSTATS];
8037 static const char *tx_stats[MAX_PM_NSTATS] = {
8038 "Read:", "Write bypass:", "Write mem:", "Bypass + mem:",
8039 "Tx FIFO wait", NULL, "Tx latency"
8041 static const char *rx_stats[MAX_PM_NSTATS] = {
8042 "Read:", "Write bypass:", "Write mem:", "Flush:",
8043 "Rx FIFO wait", NULL, "Rx latency"
8046 rc = sysctl_wire_old_buffer(req, 0);
8050 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8054 t4_pmtx_get_stats(sc, tx_cnt, tx_cyc);
8055 t4_pmrx_get_stats(sc, rx_cnt, rx_cyc);
8057 sbuf_printf(sb, " Tx pcmds Tx bytes");
8058 for (i = 0; i < 4; i++) {
8059 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i],
8063 sbuf_printf(sb, "\n Rx pcmds Rx bytes");
8064 for (i = 0; i < 4; i++) {
8065 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i],
8069 if (chip_id(sc) > CHELSIO_T5) {
8071 "\n Total wait Total occupancy");
8072 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i],
8074 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i],
8078 MPASS(i < nitems(tx_stats));
8081 "\n Reads Total wait");
8082 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i],
8084 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i],
8088 rc = sbuf_finish(sb);
8095 sysctl_rdma_stats(SYSCTL_HANDLER_ARGS)
8097 struct adapter *sc = arg1;
8100 struct tp_rdma_stats stats;
8102 rc = sysctl_wire_old_buffer(req, 0);
8106 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8110 mtx_lock(&sc->reg_lock);
8111 t4_tp_get_rdma_stats(sc, &stats, 0);
8112 mtx_unlock(&sc->reg_lock);
8114 sbuf_printf(sb, "NoRQEModDefferals: %u\n", stats.rqe_dfr_mod);
8115 sbuf_printf(sb, "NoRQEPktDefferals: %u", stats.rqe_dfr_pkt);
8117 rc = sbuf_finish(sb);
8124 sysctl_tcp_stats(SYSCTL_HANDLER_ARGS)
8126 struct adapter *sc = arg1;
8129 struct tp_tcp_stats v4, v6;
8131 rc = sysctl_wire_old_buffer(req, 0);
8135 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8139 mtx_lock(&sc->reg_lock);
8140 t4_tp_get_tcp_stats(sc, &v4, &v6, 0);
8141 mtx_unlock(&sc->reg_lock);
8145 sbuf_printf(sb, "OutRsts: %20u %20u\n",
8146 v4.tcp_out_rsts, v6.tcp_out_rsts);
8147 sbuf_printf(sb, "InSegs: %20ju %20ju\n",
8148 v4.tcp_in_segs, v6.tcp_in_segs);
8149 sbuf_printf(sb, "OutSegs: %20ju %20ju\n",
8150 v4.tcp_out_segs, v6.tcp_out_segs);
8151 sbuf_printf(sb, "RetransSegs: %20ju %20ju",
8152 v4.tcp_retrans_segs, v6.tcp_retrans_segs);
8154 rc = sbuf_finish(sb);
8161 sysctl_tids(SYSCTL_HANDLER_ARGS)
8163 struct adapter *sc = arg1;
8166 struct tid_info *t = &sc->tids;
8168 rc = sysctl_wire_old_buffer(req, 0);
8172 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8177 sbuf_printf(sb, "ATID range: 0-%u, in use: %u\n", t->natids - 1,
8182 sbuf_printf(sb, "TID range: ");
8183 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) {
8186 if (chip_id(sc) <= CHELSIO_T5) {
8187 b = t4_read_reg(sc, A_LE_DB_SERVER_INDEX) / 4;
8188 hb = t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4;
8190 b = t4_read_reg(sc, A_LE_DB_SRVR_START_INDEX);
8191 hb = t4_read_reg(sc, A_T6_LE_DB_HASH_TID_BASE);
8195 sbuf_printf(sb, "0-%u, ", b - 1);
8196 sbuf_printf(sb, "%u-%u", hb, t->ntids - 1);
8198 sbuf_printf(sb, "0-%u", t->ntids - 1);
8199 sbuf_printf(sb, ", in use: %u\n",
8200 atomic_load_acq_int(&t->tids_in_use));
8204 sbuf_printf(sb, "STID range: %u-%u, in use: %u\n", t->stid_base,
8205 t->stid_base + t->nstids - 1, t->stids_in_use);
8209 sbuf_printf(sb, "FTID range: %u-%u\n", t->ftid_base,
8210 t->ftid_base + t->nftids - 1);
8214 sbuf_printf(sb, "ETID range: %u-%u\n", t->etid_base,
8215 t->etid_base + t->netids - 1);
8218 sbuf_printf(sb, "HW TID usage: %u IP users, %u IPv6 users",
8219 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV4),
8220 t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV6));
8222 rc = sbuf_finish(sb);
8229 sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS)
8231 struct adapter *sc = arg1;
8234 struct tp_err_stats stats;
8236 rc = sysctl_wire_old_buffer(req, 0);
8240 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8244 mtx_lock(&sc->reg_lock);
8245 t4_tp_get_err_stats(sc, &stats, 0);
8246 mtx_unlock(&sc->reg_lock);
8248 if (sc->chip_params->nchan > 2) {
8249 sbuf_printf(sb, " channel 0 channel 1"
8250 " channel 2 channel 3\n");
8251 sbuf_printf(sb, "macInErrs: %10u %10u %10u %10u\n",
8252 stats.mac_in_errs[0], stats.mac_in_errs[1],
8253 stats.mac_in_errs[2], stats.mac_in_errs[3]);
8254 sbuf_printf(sb, "hdrInErrs: %10u %10u %10u %10u\n",
8255 stats.hdr_in_errs[0], stats.hdr_in_errs[1],
8256 stats.hdr_in_errs[2], stats.hdr_in_errs[3]);
8257 sbuf_printf(sb, "tcpInErrs: %10u %10u %10u %10u\n",
8258 stats.tcp_in_errs[0], stats.tcp_in_errs[1],
8259 stats.tcp_in_errs[2], stats.tcp_in_errs[3]);
8260 sbuf_printf(sb, "tcp6InErrs: %10u %10u %10u %10u\n",
8261 stats.tcp6_in_errs[0], stats.tcp6_in_errs[1],
8262 stats.tcp6_in_errs[2], stats.tcp6_in_errs[3]);
8263 sbuf_printf(sb, "tnlCongDrops: %10u %10u %10u %10u\n",
8264 stats.tnl_cong_drops[0], stats.tnl_cong_drops[1],
8265 stats.tnl_cong_drops[2], stats.tnl_cong_drops[3]);
8266 sbuf_printf(sb, "tnlTxDrops: %10u %10u %10u %10u\n",
8267 stats.tnl_tx_drops[0], stats.tnl_tx_drops[1],
8268 stats.tnl_tx_drops[2], stats.tnl_tx_drops[3]);
8269 sbuf_printf(sb, "ofldVlanDrops: %10u %10u %10u %10u\n",
8270 stats.ofld_vlan_drops[0], stats.ofld_vlan_drops[1],
8271 stats.ofld_vlan_drops[2], stats.ofld_vlan_drops[3]);
8272 sbuf_printf(sb, "ofldChanDrops: %10u %10u %10u %10u\n\n",
8273 stats.ofld_chan_drops[0], stats.ofld_chan_drops[1],
8274 stats.ofld_chan_drops[2], stats.ofld_chan_drops[3]);
8276 sbuf_printf(sb, " channel 0 channel 1\n");
8277 sbuf_printf(sb, "macInErrs: %10u %10u\n",
8278 stats.mac_in_errs[0], stats.mac_in_errs[1]);
8279 sbuf_printf(sb, "hdrInErrs: %10u %10u\n",
8280 stats.hdr_in_errs[0], stats.hdr_in_errs[1]);
8281 sbuf_printf(sb, "tcpInErrs: %10u %10u\n",
8282 stats.tcp_in_errs[0], stats.tcp_in_errs[1]);
8283 sbuf_printf(sb, "tcp6InErrs: %10u %10u\n",
8284 stats.tcp6_in_errs[0], stats.tcp6_in_errs[1]);
8285 sbuf_printf(sb, "tnlCongDrops: %10u %10u\n",
8286 stats.tnl_cong_drops[0], stats.tnl_cong_drops[1]);
8287 sbuf_printf(sb, "tnlTxDrops: %10u %10u\n",
8288 stats.tnl_tx_drops[0], stats.tnl_tx_drops[1]);
8289 sbuf_printf(sb, "ofldVlanDrops: %10u %10u\n",
8290 stats.ofld_vlan_drops[0], stats.ofld_vlan_drops[1]);
8291 sbuf_printf(sb, "ofldChanDrops: %10u %10u\n\n",
8292 stats.ofld_chan_drops[0], stats.ofld_chan_drops[1]);
8295 sbuf_printf(sb, "ofldNoNeigh: %u\nofldCongDefer: %u",
8296 stats.ofld_no_neigh, stats.ofld_cong_defer);
8298 rc = sbuf_finish(sb);
8305 sysctl_tp_la_mask(SYSCTL_HANDLER_ARGS)
8307 struct adapter *sc = arg1;
8308 struct tp_params *tpp = &sc->params.tp;
8312 mask = tpp->la_mask >> 16;
8313 rc = sysctl_handle_int(oidp, &mask, 0, req);
8314 if (rc != 0 || req->newptr == NULL)
8318 tpp->la_mask = mask << 16;
8319 t4_set_reg_field(sc, A_TP_DBG_LA_CONFIG, 0xffff0000U, tpp->la_mask);
8331 field_desc_show(struct sbuf *sb, uint64_t v, const struct field_desc *f)
8337 uint64_t mask = (1ULL << f->width) - 1;
8338 int len = snprintf(buf, sizeof(buf), "%s: %ju", f->name,
8339 ((uintmax_t)v >> f->start) & mask);
8341 if (line_size + len >= 79) {
8343 sbuf_printf(sb, "\n ");
8345 sbuf_printf(sb, "%s ", buf);
8346 line_size += len + 1;
8349 sbuf_printf(sb, "\n");
8352 static const struct field_desc tp_la0[] = {
8353 { "RcfOpCodeOut", 60, 4 },
8355 { "WcfState", 52, 4 },
8356 { "RcfOpcSrcOut", 50, 2 },
8357 { "CRxError", 49, 1 },
8358 { "ERxError", 48, 1 },
8359 { "SanityFailed", 47, 1 },
8360 { "SpuriousMsg", 46, 1 },
8361 { "FlushInputMsg", 45, 1 },
8362 { "FlushInputCpl", 44, 1 },
8363 { "RssUpBit", 43, 1 },
8364 { "RssFilterHit", 42, 1 },
8366 { "InitTcb", 31, 1 },
8367 { "LineNumber", 24, 7 },
8369 { "EdataOut", 22, 1 },
8371 { "CdataOut", 20, 1 },
8372 { "EreadPdu", 19, 1 },
8373 { "CreadPdu", 18, 1 },
8374 { "TunnelPkt", 17, 1 },
8375 { "RcfPeerFin", 16, 1 },
8376 { "RcfReasonOut", 12, 4 },
8377 { "TxCchannel", 10, 2 },
8378 { "RcfTxChannel", 8, 2 },
8379 { "RxEchannel", 6, 2 },
8380 { "RcfRxChannel", 5, 1 },
8381 { "RcfDataOutSrdy", 4, 1 },
8383 { "RxOoDvld", 2, 1 },
8384 { "RxCongestion", 1, 1 },
8385 { "TxCongestion", 0, 1 },
8389 static const struct field_desc tp_la1[] = {
8390 { "CplCmdIn", 56, 8 },
8391 { "CplCmdOut", 48, 8 },
8392 { "ESynOut", 47, 1 },
8393 { "EAckOut", 46, 1 },
8394 { "EFinOut", 45, 1 },
8395 { "ERstOut", 44, 1 },
8400 { "DataIn", 39, 1 },
8401 { "DataInVld", 38, 1 },
8403 { "RxBufEmpty", 36, 1 },
8405 { "RxFbCongestion", 34, 1 },
8406 { "TxFbCongestion", 33, 1 },
8407 { "TxPktSumSrdy", 32, 1 },
8408 { "RcfUlpType", 28, 4 },
8410 { "Ebypass", 26, 1 },
8412 { "Static0", 24, 1 },
8414 { "Cbypass", 22, 1 },
8416 { "CPktOut", 20, 1 },
8417 { "RxPagePoolFull", 18, 2 },
8418 { "RxLpbkPkt", 17, 1 },
8419 { "TxLpbkPkt", 16, 1 },
8420 { "RxVfValid", 15, 1 },
8421 { "SynLearned", 14, 1 },
8422 { "SetDelEntry", 13, 1 },
8423 { "SetInvEntry", 12, 1 },
8424 { "CpcmdDvld", 11, 1 },
8425 { "CpcmdSave", 10, 1 },
8426 { "RxPstructsFull", 8, 2 },
8427 { "EpcmdDvld", 7, 1 },
8428 { "EpcmdFlush", 6, 1 },
8429 { "EpcmdTrimPrefix", 5, 1 },
8430 { "EpcmdTrimPostfix", 4, 1 },
8431 { "ERssIp4Pkt", 3, 1 },
8432 { "ERssIp6Pkt", 2, 1 },
8433 { "ERssTcpUdpPkt", 1, 1 },
8434 { "ERssFceFipPkt", 0, 1 },
8438 static const struct field_desc tp_la2[] = {
8439 { "CplCmdIn", 56, 8 },
8440 { "MpsVfVld", 55, 1 },
8447 { "DataIn", 39, 1 },
8448 { "DataInVld", 38, 1 },
8450 { "RxBufEmpty", 36, 1 },
8452 { "RxFbCongestion", 34, 1 },
8453 { "TxFbCongestion", 33, 1 },
8454 { "TxPktSumSrdy", 32, 1 },
8455 { "RcfUlpType", 28, 4 },
8457 { "Ebypass", 26, 1 },
8459 { "Static0", 24, 1 },
8461 { "Cbypass", 22, 1 },
8463 { "CPktOut", 20, 1 },
8464 { "RxPagePoolFull", 18, 2 },
8465 { "RxLpbkPkt", 17, 1 },
8466 { "TxLpbkPkt", 16, 1 },
8467 { "RxVfValid", 15, 1 },
8468 { "SynLearned", 14, 1 },
8469 { "SetDelEntry", 13, 1 },
8470 { "SetInvEntry", 12, 1 },
8471 { "CpcmdDvld", 11, 1 },
8472 { "CpcmdSave", 10, 1 },
8473 { "RxPstructsFull", 8, 2 },
8474 { "EpcmdDvld", 7, 1 },
8475 { "EpcmdFlush", 6, 1 },
8476 { "EpcmdTrimPrefix", 5, 1 },
8477 { "EpcmdTrimPostfix", 4, 1 },
8478 { "ERssIp4Pkt", 3, 1 },
8479 { "ERssIp6Pkt", 2, 1 },
8480 { "ERssTcpUdpPkt", 1, 1 },
8481 { "ERssFceFipPkt", 0, 1 },
8486 tp_la_show(struct sbuf *sb, uint64_t *p, int idx)
8489 field_desc_show(sb, *p, tp_la0);
8493 tp_la_show2(struct sbuf *sb, uint64_t *p, int idx)
8497 sbuf_printf(sb, "\n");
8498 field_desc_show(sb, p[0], tp_la0);
8499 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
8500 field_desc_show(sb, p[1], tp_la0);
8504 tp_la_show3(struct sbuf *sb, uint64_t *p, int idx)
8508 sbuf_printf(sb, "\n");
8509 field_desc_show(sb, p[0], tp_la0);
8510 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
8511 field_desc_show(sb, p[1], (p[0] & (1 << 17)) ? tp_la2 : tp_la1);
8515 sysctl_tp_la(SYSCTL_HANDLER_ARGS)
8517 struct adapter *sc = arg1;
8522 void (*show_func)(struct sbuf *, uint64_t *, int);
8524 rc = sysctl_wire_old_buffer(req, 0);
8528 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8532 buf = malloc(TPLA_SIZE * sizeof(uint64_t), M_CXGBE, M_ZERO | M_WAITOK);
8534 t4_tp_read_la(sc, buf, NULL);
8537 switch (G_DBGLAMODE(t4_read_reg(sc, A_TP_DBG_LA_CONFIG))) {
8540 show_func = tp_la_show2;
8544 show_func = tp_la_show3;
8548 show_func = tp_la_show;
8551 for (i = 0; i < TPLA_SIZE / inc; i++, p += inc)
8552 (*show_func)(sb, p, i);
8554 rc = sbuf_finish(sb);
8561 sysctl_tx_rate(SYSCTL_HANDLER_ARGS)
8563 struct adapter *sc = arg1;
8566 u64 nrate[MAX_NCHAN], orate[MAX_NCHAN];
8568 rc = sysctl_wire_old_buffer(req, 0);
8572 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req);
8576 t4_get_chan_txrate(sc, nrate, orate);
8578 if (sc->chip_params->nchan > 2) {
8579 sbuf_printf(sb, " channel 0 channel 1"
8580 " channel 2 channel 3\n");
8581 sbuf_printf(sb, "NIC B/s: %10ju %10ju %10ju %10ju\n",
8582 nrate[0], nrate[1], nrate[2], nrate[3]);
8583 sbuf_printf(sb, "Offload B/s: %10ju %10ju %10ju %10ju",
8584 orate[0], orate[1], orate[2], orate[3]);
8586 sbuf_printf(sb, " channel 0 channel 1\n");
8587 sbuf_printf(sb, "NIC B/s: %10ju %10ju\n",
8588 nrate[0], nrate[1]);
8589 sbuf_printf(sb, "Offload B/s: %10ju %10ju",
8590 orate[0], orate[1]);
8593 rc = sbuf_finish(sb);
8600 sysctl_ulprx_la(SYSCTL_HANDLER_ARGS)
8602 struct adapter *sc = arg1;
8607 rc = sysctl_wire_old_buffer(req, 0);
8611 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8615 buf = malloc(ULPRX_LA_SIZE * 8 * sizeof(uint32_t), M_CXGBE,
8618 t4_ulprx_read_la(sc, buf);
8621 sbuf_printf(sb, " Pcmd Type Message"
8623 for (i = 0; i < ULPRX_LA_SIZE; i++, p += 8) {
8624 sbuf_printf(sb, "\n%08x%08x %4x %08x %08x%08x%08x%08x",
8625 p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
8628 rc = sbuf_finish(sb);
8635 sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS)
8637 struct adapter *sc = arg1;
8641 MPASS(chip_id(sc) >= CHELSIO_T5);
8643 rc = sysctl_wire_old_buffer(req, 0);
8647 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8651 v = t4_read_reg(sc, A_SGE_STAT_CFG);
8652 if (G_STATSOURCE_T5(v) == 7) {
8655 mode = is_t5(sc) ? G_STATMODE(v) : G_T6_STATMODE(v);
8657 sbuf_printf(sb, "total %d, incomplete %d",
8658 t4_read_reg(sc, A_SGE_STAT_TOTAL),
8659 t4_read_reg(sc, A_SGE_STAT_MATCH));
8660 } else if (mode == 1) {
8661 sbuf_printf(sb, "total %d, data overflow %d",
8662 t4_read_reg(sc, A_SGE_STAT_TOTAL),
8663 t4_read_reg(sc, A_SGE_STAT_MATCH));
8665 sbuf_printf(sb, "unknown mode %d", mode);
8668 rc = sbuf_finish(sb);
8675 sysctl_tc_params(SYSCTL_HANDLER_ARGS)
8677 struct adapter *sc = arg1;
8678 struct tx_cl_rl_params tc;
8680 int i, rc, port_id, mbps, gbps;
8682 rc = sysctl_wire_old_buffer(req, 0);
8686 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
8690 port_id = arg2 >> 16;
8691 MPASS(port_id < sc->params.nports);
8692 MPASS(sc->port[port_id] != NULL);
8694 MPASS(i < sc->chip_params->nsched_cls);
8696 mtx_lock(&sc->tc_lock);
8697 tc = sc->port[port_id]->sched_params->cl_rl[i];
8698 mtx_unlock(&sc->tc_lock);
8700 if (tc.flags & TX_CLRL_ERROR) {
8701 sbuf_printf(sb, "error");
8705 if (tc.ratemode == SCHED_CLASS_RATEMODE_REL) {
8706 /* XXX: top speed or actual link speed? */
8707 gbps = port_top_speed(sc->port[port_id]);
8708 sbuf_printf(sb, " %u%% of %uGbps", tc.maxrate, gbps);
8709 } else if (tc.ratemode == SCHED_CLASS_RATEMODE_ABS) {
8710 switch (tc.rateunit) {
8711 case SCHED_CLASS_RATEUNIT_BITS:
8712 mbps = tc.maxrate / 1000;
8713 gbps = tc.maxrate / 1000000;
8714 if (tc.maxrate == gbps * 1000000)
8715 sbuf_printf(sb, " %uGbps", gbps);
8716 else if (tc.maxrate == mbps * 1000)
8717 sbuf_printf(sb, " %uMbps", mbps);
8719 sbuf_printf(sb, " %uKbps", tc.maxrate);
8721 case SCHED_CLASS_RATEUNIT_PKTS:
8722 sbuf_printf(sb, " %upps", tc.maxrate);
8731 case SCHED_CLASS_MODE_CLASS:
8732 sbuf_printf(sb, " aggregate");
8734 case SCHED_CLASS_MODE_FLOW:
8735 sbuf_printf(sb, " per-flow");
8744 rc = sbuf_finish(sb);
8753 sysctl_tls_rx_ports(SYSCTL_HANDLER_ARGS)
8755 struct adapter *sc = arg1;
8756 int *old_ports, *new_ports;
8757 int i, new_count, rc;
8759 if (req->newptr == NULL && req->oldptr == NULL)
8760 return (SYSCTL_OUT(req, NULL, imax(sc->tt.num_tls_rx_ports, 1) *
8761 sizeof(sc->tt.tls_rx_ports[0])));
8763 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4tlsrx");
8767 if (sc->tt.num_tls_rx_ports == 0) {
8769 rc = SYSCTL_OUT(req, &i, sizeof(i));
8771 rc = SYSCTL_OUT(req, sc->tt.tls_rx_ports,
8772 sc->tt.num_tls_rx_ports * sizeof(sc->tt.tls_rx_ports[0]));
8773 if (rc == 0 && req->newptr != NULL) {
8774 new_count = req->newlen / sizeof(new_ports[0]);
8775 new_ports = malloc(new_count * sizeof(new_ports[0]), M_CXGBE,
8777 rc = SYSCTL_IN(req, new_ports, new_count *
8778 sizeof(new_ports[0]));
8782 /* Allow setting to a single '-1' to clear the list. */
8783 if (new_count == 1 && new_ports[0] == -1) {
8785 old_ports = sc->tt.tls_rx_ports;
8786 sc->tt.tls_rx_ports = NULL;
8787 sc->tt.num_tls_rx_ports = 0;
8789 free(old_ports, M_CXGBE);
8791 for (i = 0; i < new_count; i++) {
8792 if (new_ports[i] < 1 ||
8793 new_ports[i] > IPPORT_MAX) {
8800 old_ports = sc->tt.tls_rx_ports;
8801 sc->tt.tls_rx_ports = new_ports;
8802 sc->tt.num_tls_rx_ports = new_count;
8804 free(old_ports, M_CXGBE);
8808 free(new_ports, M_CXGBE);
8810 end_synchronized_op(sc, 0);
8815 unit_conv(char *buf, size_t len, u_int val, u_int factor)
8817 u_int rem = val % factor;
8820 snprintf(buf, len, "%u", val / factor);
8822 while (rem % 10 == 0)
8824 snprintf(buf, len, "%u.%u", val / factor, rem);
8829 sysctl_tp_tick(SYSCTL_HANDLER_ARGS)
8831 struct adapter *sc = arg1;
8834 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk;
8836 res = t4_read_reg(sc, A_TP_TIMER_RESOLUTION);
8840 re = G_TIMERRESOLUTION(res);
8843 /* TCP timestamp tick */
8844 re = G_TIMESTAMPRESOLUTION(res);
8848 re = G_DELAYEDACKRESOLUTION(res);
8854 unit_conv(buf, sizeof(buf), (cclk_ps << re), 1000000);
8856 return (sysctl_handle_string(oidp, buf, sizeof(buf), req));
8860 sysctl_tp_dack_timer(SYSCTL_HANDLER_ARGS)
8862 struct adapter *sc = arg1;
8863 u_int res, dack_re, v;
8864 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk;
8866 res = t4_read_reg(sc, A_TP_TIMER_RESOLUTION);
8867 dack_re = G_DELAYEDACKRESOLUTION(res);
8868 v = ((cclk_ps << dack_re) / 1000000) * t4_read_reg(sc, A_TP_DACK_TIMER);
8870 return (sysctl_handle_int(oidp, &v, 0, req));
8874 sysctl_tp_timer(SYSCTL_HANDLER_ARGS)
8876 struct adapter *sc = arg1;
8879 u_long tp_tick_us, v;
8880 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk;
8882 MPASS(reg == A_TP_RXT_MIN || reg == A_TP_RXT_MAX ||
8883 reg == A_TP_PERS_MIN || reg == A_TP_PERS_MAX ||
8884 reg == A_TP_KEEP_IDLE || reg == A_TP_KEEP_INTVL ||
8885 reg == A_TP_INIT_SRTT || reg == A_TP_FINWAIT2_TIMER);
8887 tre = G_TIMERRESOLUTION(t4_read_reg(sc, A_TP_TIMER_RESOLUTION));
8888 tp_tick_us = (cclk_ps << tre) / 1000000;
8890 if (reg == A_TP_INIT_SRTT)
8891 v = tp_tick_us * G_INITSRTT(t4_read_reg(sc, reg));
8893 v = tp_tick_us * t4_read_reg(sc, reg);
8895 return (sysctl_handle_long(oidp, &v, 0, req));
8899 * All fields in TP_SHIFT_CNT are 4b and the starting location of the field is
8900 * passed to this function.
8903 sysctl_tp_shift_cnt(SYSCTL_HANDLER_ARGS)
8905 struct adapter *sc = arg1;
8909 MPASS(idx >= 0 && idx <= 24);
8911 v = (t4_read_reg(sc, A_TP_SHIFT_CNT) >> idx) & 0xf;
8913 return (sysctl_handle_int(oidp, &v, 0, req));
8917 sysctl_tp_backoff(SYSCTL_HANDLER_ARGS)
8919 struct adapter *sc = arg1;
8923 MPASS(idx >= 0 && idx < 16);
8925 r = A_TP_TCP_BACKOFF_REG0 + (idx & ~3);
8926 shift = (idx & 3) << 3;
8927 v = (t4_read_reg(sc, r) >> shift) & M_TIMERBACKOFFINDEX0;
8929 return (sysctl_handle_int(oidp, &v, 0, req));
8933 sysctl_holdoff_tmr_idx_ofld(SYSCTL_HANDLER_ARGS)
8935 struct vi_info *vi = arg1;
8936 struct adapter *sc = vi->pi->adapter;
8938 struct sge_ofld_rxq *ofld_rxq;
8941 idx = vi->ofld_tmr_idx;
8943 rc = sysctl_handle_int(oidp, &idx, 0, req);
8944 if (rc != 0 || req->newptr == NULL)
8947 if (idx < 0 || idx >= SGE_NTIMERS)
8950 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
8955 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(vi->ofld_pktc_idx != -1);
8956 for_each_ofld_rxq(vi, i, ofld_rxq) {
8957 #ifdef atomic_store_rel_8
8958 atomic_store_rel_8(&ofld_rxq->iq.intr_params, v);
8960 ofld_rxq->iq.intr_params = v;
8963 vi->ofld_tmr_idx = idx;
8965 end_synchronized_op(sc, LOCK_HELD);
8970 sysctl_holdoff_pktc_idx_ofld(SYSCTL_HANDLER_ARGS)
8972 struct vi_info *vi = arg1;
8973 struct adapter *sc = vi->pi->adapter;
8976 idx = vi->ofld_pktc_idx;
8978 rc = sysctl_handle_int(oidp, &idx, 0, req);
8979 if (rc != 0 || req->newptr == NULL)
8982 if (idx < -1 || idx >= SGE_NCOUNTERS)
8985 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK,
8990 if (vi->flags & VI_INIT_DONE)
8991 rc = EBUSY; /* cannot be changed once the queues are created */
8993 vi->ofld_pktc_idx = idx;
8995 end_synchronized_op(sc, LOCK_HELD);
9001 fconf_iconf_to_mode(uint32_t fconf, uint32_t iconf)
9005 mode = T4_FILTER_IPv4 | T4_FILTER_IPv6 | T4_FILTER_IP_SADDR |
9006 T4_FILTER_IP_DADDR | T4_FILTER_IP_SPORT | T4_FILTER_IP_DPORT;
9008 if (fconf & F_FRAGMENTATION)
9009 mode |= T4_FILTER_IP_FRAGMENT;
9011 if (fconf & F_MPSHITTYPE)
9012 mode |= T4_FILTER_MPS_HIT_TYPE;
9014 if (fconf & F_MACMATCH)
9015 mode |= T4_FILTER_MAC_IDX;
9017 if (fconf & F_ETHERTYPE)
9018 mode |= T4_FILTER_ETH_TYPE;
9020 if (fconf & F_PROTOCOL)
9021 mode |= T4_FILTER_IP_PROTO;
9024 mode |= T4_FILTER_IP_TOS;
9027 mode |= T4_FILTER_VLAN;
9029 if (fconf & F_VNIC_ID) {
9030 mode |= T4_FILTER_VNIC;
9032 mode |= T4_FILTER_IC_VNIC;
9036 mode |= T4_FILTER_PORT;
9039 mode |= T4_FILTER_FCoE;
9045 mode_to_fconf(uint32_t mode)
9049 if (mode & T4_FILTER_IP_FRAGMENT)
9050 fconf |= F_FRAGMENTATION;
9052 if (mode & T4_FILTER_MPS_HIT_TYPE)
9053 fconf |= F_MPSHITTYPE;
9055 if (mode & T4_FILTER_MAC_IDX)
9056 fconf |= F_MACMATCH;
9058 if (mode & T4_FILTER_ETH_TYPE)
9059 fconf |= F_ETHERTYPE;
9061 if (mode & T4_FILTER_IP_PROTO)
9062 fconf |= F_PROTOCOL;
9064 if (mode & T4_FILTER_IP_TOS)
9067 if (mode & T4_FILTER_VLAN)
9070 if (mode & T4_FILTER_VNIC)
9073 if (mode & T4_FILTER_PORT)
9076 if (mode & T4_FILTER_FCoE)
9083 mode_to_iconf(uint32_t mode)
9086 if (mode & T4_FILTER_IC_VNIC)
9091 static int check_fspec_against_fconf_iconf(struct adapter *sc,
9092 struct t4_filter_specification *fs)
9094 struct tp_params *tpp = &sc->params.tp;
9097 if (fs->val.frag || fs->mask.frag)
9098 fconf |= F_FRAGMENTATION;
9100 if (fs->val.matchtype || fs->mask.matchtype)
9101 fconf |= F_MPSHITTYPE;
9103 if (fs->val.macidx || fs->mask.macidx)
9104 fconf |= F_MACMATCH;
9106 if (fs->val.ethtype || fs->mask.ethtype)
9107 fconf |= F_ETHERTYPE;
9109 if (fs->val.proto || fs->mask.proto)
9110 fconf |= F_PROTOCOL;
9112 if (fs->val.tos || fs->mask.tos)
9115 if (fs->val.vlan_vld || fs->mask.vlan_vld)
9118 if (fs->val.ovlan_vld || fs->mask.ovlan_vld) {
9120 if (tpp->ingress_config & F_VNIC)
9124 if (fs->val.pfvf_vld || fs->mask.pfvf_vld) {
9126 if ((tpp->ingress_config & F_VNIC) == 0)
9130 if (fs->val.iport || fs->mask.iport)
9133 if (fs->val.fcoe || fs->mask.fcoe)
9136 if ((tpp->vlan_pri_map | fconf) != tpp->vlan_pri_map)
9143 get_filter_mode(struct adapter *sc, uint32_t *mode)
9145 struct tp_params *tpp = &sc->params.tp;
9148 * We trust the cached values of the relevant TP registers. This means
9149 * things work reliably only if writes to those registers are always via
9150 * t4_set_filter_mode.
9152 *mode = fconf_iconf_to_mode(tpp->vlan_pri_map, tpp->ingress_config);
9158 set_filter_mode(struct adapter *sc, uint32_t mode)
9160 struct tp_params *tpp = &sc->params.tp;
9161 uint32_t fconf, iconf;
9164 iconf = mode_to_iconf(mode);
9165 if ((iconf ^ tpp->ingress_config) & F_VNIC) {
9167 * For now we just complain if A_TP_INGRESS_CONFIG is not
9168 * already set to the correct value for the requested filter
9169 * mode. It's not clear if it's safe to write to this register
9170 * on the fly. (And we trust the cached value of the register).
9175 fconf = mode_to_fconf(mode);
9177 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
9182 if (sc->tids.ftids_in_use > 0) {
9188 if (uld_active(sc, ULD_TOM)) {
9194 rc = -t4_set_filter_mode(sc, fconf, true);
9196 end_synchronized_op(sc, LOCK_HELD);
9200 static inline uint64_t
9201 get_filter_hits(struct adapter *sc, uint32_t fid)
9205 tcb_addr = t4_read_reg(sc, A_TP_CMM_TCB_BASE) +
9206 (fid + sc->tids.ftid_base) * TCB_SIZE;
9211 read_via_memwin(sc, 0, tcb_addr + 16, (uint32_t *)&hits, 8);
9212 return (be64toh(hits));
9216 read_via_memwin(sc, 0, tcb_addr + 24, &hits, 4);
9217 return (be32toh(hits));
9222 get_filter(struct adapter *sc, struct t4_filter *t)
9224 int i, rc, nfilters = sc->tids.nftids;
9225 struct filter_entry *f;
9227 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
9232 if (sc->tids.ftids_in_use == 0 || sc->tids.ftid_tab == NULL ||
9233 t->idx >= nfilters) {
9234 t->idx = 0xffffffff;
9238 f = &sc->tids.ftid_tab[t->idx];
9239 for (i = t->idx; i < nfilters; i++, f++) {
9242 t->l2tidx = f->l2t ? f->l2t->idx : 0;
9243 t->smtidx = f->smtidx;
9245 t->hits = get_filter_hits(sc, t->idx);
9247 t->hits = UINT64_MAX;
9254 t->idx = 0xffffffff;
9256 end_synchronized_op(sc, LOCK_HELD);
9261 set_filter(struct adapter *sc, struct t4_filter *t)
9263 unsigned int nfilters, nports;
9264 struct filter_entry *f;
9267 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setf");
9271 nfilters = sc->tids.nftids;
9272 nports = sc->params.nports;
9274 if (nfilters == 0) {
9279 if (t->idx >= nfilters) {
9284 /* Validate against the global filter mode and ingress config */
9285 rc = check_fspec_against_fconf_iconf(sc, &t->fs);
9289 if (t->fs.action == FILTER_SWITCH && t->fs.eport >= nports) {
9294 if (t->fs.val.iport >= nports) {
9299 /* Can't specify an iq if not steering to it */
9300 if (!t->fs.dirsteer && t->fs.iq) {
9305 /* IPv6 filter idx must be 4 aligned */
9306 if (t->fs.type == 1 &&
9307 ((t->idx & 0x3) || t->idx + 4 >= nfilters)) {
9312 if (!(sc->flags & FULL_INIT_DONE) &&
9313 ((rc = adapter_full_init(sc)) != 0))
9316 if (sc->tids.ftid_tab == NULL) {
9317 KASSERT(sc->tids.ftids_in_use == 0,
9318 ("%s: no memory allocated but filters_in_use > 0",
9321 sc->tids.ftid_tab = malloc(sizeof (struct filter_entry) *
9322 nfilters, M_CXGBE, M_NOWAIT | M_ZERO);
9323 if (sc->tids.ftid_tab == NULL) {
9327 mtx_init(&sc->tids.ftid_lock, "T4 filters", 0, MTX_DEF);
9330 for (i = 0; i < 4; i++) {
9331 f = &sc->tids.ftid_tab[t->idx + i];
9333 if (f->pending || f->valid) {
9342 if (t->fs.type == 0)
9346 f = &sc->tids.ftid_tab[t->idx];
9349 rc = set_filter_wr(sc, t->idx);
9351 end_synchronized_op(sc, 0);
9354 mtx_lock(&sc->tids.ftid_lock);
9356 if (f->pending == 0) {
9357 rc = f->valid ? 0 : EIO;
9361 if (mtx_sleep(&sc->tids.ftid_tab, &sc->tids.ftid_lock,
9362 PCATCH, "t4setfw", 0)) {
9367 mtx_unlock(&sc->tids.ftid_lock);
9373 del_filter(struct adapter *sc, struct t4_filter *t)
9375 unsigned int nfilters;
9376 struct filter_entry *f;
9379 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4delf");
9383 nfilters = sc->tids.nftids;
9385 if (nfilters == 0) {
9390 if (sc->tids.ftid_tab == NULL || sc->tids.ftids_in_use == 0 ||
9391 t->idx >= nfilters) {
9396 if (!(sc->flags & FULL_INIT_DONE)) {
9401 f = &sc->tids.ftid_tab[t->idx];
9413 t->fs = f->fs; /* extra info for the caller */
9414 rc = del_filter_wr(sc, t->idx);
9418 end_synchronized_op(sc, 0);
9421 mtx_lock(&sc->tids.ftid_lock);
9423 if (f->pending == 0) {
9424 rc = f->valid ? EIO : 0;
9428 if (mtx_sleep(&sc->tids.ftid_tab, &sc->tids.ftid_lock,
9429 PCATCH, "t4delfw", 0)) {
9434 mtx_unlock(&sc->tids.ftid_lock);
9441 clear_filter(struct filter_entry *f)
9444 t4_l2t_release(f->l2t);
9446 bzero(f, sizeof (*f));
9450 set_filter_wr(struct adapter *sc, int fidx)
9452 struct filter_entry *f = &sc->tids.ftid_tab[fidx];
9453 struct fw_filter_wr *fwr;
9454 unsigned int ftid, vnic_vld, vnic_vld_mask;
9455 struct wrq_cookie cookie;
9457 ASSERT_SYNCHRONIZED_OP(sc);
9459 if (f->fs.newdmac || f->fs.newvlan) {
9460 /* This filter needs an L2T entry; allocate one. */
9461 f->l2t = t4_l2t_alloc_switching(sc->l2t);
9464 if (t4_l2t_set_switching(sc, f->l2t, f->fs.vlan, f->fs.eport,
9466 t4_l2t_release(f->l2t);
9472 /* Already validated against fconf, iconf */
9473 MPASS((f->fs.val.pfvf_vld & f->fs.val.ovlan_vld) == 0);
9474 MPASS((f->fs.mask.pfvf_vld & f->fs.mask.ovlan_vld) == 0);
9475 if (f->fs.val.pfvf_vld || f->fs.val.ovlan_vld)
9479 if (f->fs.mask.pfvf_vld || f->fs.mask.ovlan_vld)
9484 ftid = sc->tids.ftid_base + fidx;
9486 fwr = start_wrq_wr(&sc->sge.mgmtq, howmany(sizeof(*fwr), 16), &cookie);
9489 bzero(fwr, sizeof(*fwr));
9491 fwr->op_pkd = htobe32(V_FW_WR_OP(FW_FILTER_WR));
9492 fwr->len16_pkd = htobe32(FW_LEN16(*fwr));
9494 htobe32(V_FW_FILTER_WR_TID(ftid) |
9495 V_FW_FILTER_WR_RQTYPE(f->fs.type) |
9496 V_FW_FILTER_WR_NOREPLY(0) |
9497 V_FW_FILTER_WR_IQ(f->fs.iq));
9498 fwr->del_filter_to_l2tix =
9499 htobe32(V_FW_FILTER_WR_RPTTID(f->fs.rpttid) |
9500 V_FW_FILTER_WR_DROP(f->fs.action == FILTER_DROP) |
9501 V_FW_FILTER_WR_DIRSTEER(f->fs.dirsteer) |
9502 V_FW_FILTER_WR_MASKHASH(f->fs.maskhash) |
9503 V_FW_FILTER_WR_DIRSTEERHASH(f->fs.dirsteerhash) |
9504 V_FW_FILTER_WR_LPBK(f->fs.action == FILTER_SWITCH) |
9505 V_FW_FILTER_WR_DMAC(f->fs.newdmac) |
9506 V_FW_FILTER_WR_SMAC(f->fs.newsmac) |
9507 V_FW_FILTER_WR_INSVLAN(f->fs.newvlan == VLAN_INSERT ||
9508 f->fs.newvlan == VLAN_REWRITE) |
9509 V_FW_FILTER_WR_RMVLAN(f->fs.newvlan == VLAN_REMOVE ||
9510 f->fs.newvlan == VLAN_REWRITE) |
9511 V_FW_FILTER_WR_HITCNTS(f->fs.hitcnts) |
9512 V_FW_FILTER_WR_TXCHAN(f->fs.eport) |
9513 V_FW_FILTER_WR_PRIO(f->fs.prio) |
9514 V_FW_FILTER_WR_L2TIX(f->l2t ? f->l2t->idx : 0));
9515 fwr->ethtype = htobe16(f->fs.val.ethtype);
9516 fwr->ethtypem = htobe16(f->fs.mask.ethtype);
9517 fwr->frag_to_ovlan_vldm =
9518 (V_FW_FILTER_WR_FRAG(f->fs.val.frag) |
9519 V_FW_FILTER_WR_FRAGM(f->fs.mask.frag) |
9520 V_FW_FILTER_WR_IVLAN_VLD(f->fs.val.vlan_vld) |
9521 V_FW_FILTER_WR_OVLAN_VLD(vnic_vld) |
9522 V_FW_FILTER_WR_IVLAN_VLDM(f->fs.mask.vlan_vld) |
9523 V_FW_FILTER_WR_OVLAN_VLDM(vnic_vld_mask));
9525 fwr->rx_chan_rx_rpl_iq = htobe16(V_FW_FILTER_WR_RX_CHAN(0) |
9526 V_FW_FILTER_WR_RX_RPL_IQ(sc->sge.fwq.abs_id));
9527 fwr->maci_to_matchtypem =
9528 htobe32(V_FW_FILTER_WR_MACI(f->fs.val.macidx) |
9529 V_FW_FILTER_WR_MACIM(f->fs.mask.macidx) |
9530 V_FW_FILTER_WR_FCOE(f->fs.val.fcoe) |
9531 V_FW_FILTER_WR_FCOEM(f->fs.mask.fcoe) |
9532 V_FW_FILTER_WR_PORT(f->fs.val.iport) |
9533 V_FW_FILTER_WR_PORTM(f->fs.mask.iport) |
9534 V_FW_FILTER_WR_MATCHTYPE(f->fs.val.matchtype) |
9535 V_FW_FILTER_WR_MATCHTYPEM(f->fs.mask.matchtype));
9536 fwr->ptcl = f->fs.val.proto;
9537 fwr->ptclm = f->fs.mask.proto;
9538 fwr->ttyp = f->fs.val.tos;
9539 fwr->ttypm = f->fs.mask.tos;
9540 fwr->ivlan = htobe16(f->fs.val.vlan);
9541 fwr->ivlanm = htobe16(f->fs.mask.vlan);
9542 fwr->ovlan = htobe16(f->fs.val.vnic);
9543 fwr->ovlanm = htobe16(f->fs.mask.vnic);
9544 bcopy(f->fs.val.dip, fwr->lip, sizeof (fwr->lip));
9545 bcopy(f->fs.mask.dip, fwr->lipm, sizeof (fwr->lipm));
9546 bcopy(f->fs.val.sip, fwr->fip, sizeof (fwr->fip));
9547 bcopy(f->fs.mask.sip, fwr->fipm, sizeof (fwr->fipm));
9548 fwr->lp = htobe16(f->fs.val.dport);
9549 fwr->lpm = htobe16(f->fs.mask.dport);
9550 fwr->fp = htobe16(f->fs.val.sport);
9551 fwr->fpm = htobe16(f->fs.mask.sport);
9553 bcopy(f->fs.smac, fwr->sma, sizeof (fwr->sma));
9556 sc->tids.ftids_in_use++;
9558 commit_wrq_wr(&sc->sge.mgmtq, fwr, &cookie);
9563 del_filter_wr(struct adapter *sc, int fidx)
9565 struct filter_entry *f = &sc->tids.ftid_tab[fidx];
9566 struct fw_filter_wr *fwr;
9568 struct wrq_cookie cookie;
9570 ftid = sc->tids.ftid_base + fidx;
9572 fwr = start_wrq_wr(&sc->sge.mgmtq, howmany(sizeof(*fwr), 16), &cookie);
9575 bzero(fwr, sizeof (*fwr));
9577 t4_mk_filtdelwr(ftid, fwr, sc->sge.fwq.abs_id);
9580 commit_wrq_wr(&sc->sge.mgmtq, fwr, &cookie);
9585 t4_filter_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
9587 struct adapter *sc = iq->adapter;
9588 const struct cpl_set_tcb_rpl *rpl = (const void *)(rss + 1);
9589 unsigned int idx = GET_TID(rpl);
9591 struct filter_entry *f;
9593 KASSERT(m == NULL, ("%s: payload with opcode %02x", __func__,
9595 MPASS(iq == &sc->sge.fwq);
9596 MPASS(is_ftid(sc, idx));
9598 idx -= sc->tids.ftid_base;
9599 f = &sc->tids.ftid_tab[idx];
9600 rc = G_COOKIE(rpl->cookie);
9602 mtx_lock(&sc->tids.ftid_lock);
9603 if (rc == FW_FILTER_WR_FLT_ADDED) {
9604 KASSERT(f->pending, ("%s: filter[%u] isn't pending.",
9606 f->smtidx = (be64toh(rpl->oldval) >> 24) & 0xff;
9607 f->pending = 0; /* asynchronous setup completed */
9610 if (rc != FW_FILTER_WR_FLT_DELETED) {
9611 /* Add or delete failed, display an error */
9613 "filter %u setup failed with error %u\n",
9618 sc->tids.ftids_in_use--;
9620 wakeup(&sc->tids.ftid_tab);
9621 mtx_unlock(&sc->tids.ftid_lock);
9627 set_tcb_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
9630 MPASS(iq->set_tcb_rpl != NULL);
9631 return (iq->set_tcb_rpl(iq, rss, m));
9635 l2t_write_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
9638 MPASS(iq->l2t_write_rpl != NULL);
9639 return (iq->l2t_write_rpl(iq, rss, m));
9643 get_sge_context(struct adapter *sc, struct t4_sge_context *cntxt)
9647 if (cntxt->cid > M_CTXTQID)
9650 if (cntxt->mem_id != CTXT_EGRESS && cntxt->mem_id != CTXT_INGRESS &&
9651 cntxt->mem_id != CTXT_FLM && cntxt->mem_id != CTXT_CNM)
9654 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ctxt");
9658 if (sc->flags & FW_OK) {
9659 rc = -t4_sge_ctxt_rd(sc, sc->mbox, cntxt->cid, cntxt->mem_id,
9666 * Read via firmware failed or wasn't even attempted. Read directly via
9669 rc = -t4_sge_ctxt_rd_bd(sc, cntxt->cid, cntxt->mem_id, &cntxt->data[0]);
9671 end_synchronized_op(sc, 0);
9676 load_fw(struct adapter *sc, struct t4_data *fw)
9681 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldfw");
9686 * The firmware, with the sole exception of the memory parity error
9687 * handler, runs from memory and not flash. It is almost always safe to
9688 * install a new firmware on a running system. Just set bit 1 in
9689 * hw.cxgbe.dflags or dev.<nexus>.<n>.dflags first.
9691 if (sc->flags & FULL_INIT_DONE &&
9692 (sc->debug_flags & DF_LOAD_FW_ANYTIME) == 0) {
9697 fw_data = malloc(fw->len, M_CXGBE, M_WAITOK);
9698 if (fw_data == NULL) {
9703 rc = copyin(fw->data, fw_data, fw->len);
9705 rc = -t4_load_fw(sc, fw_data, fw->len);
9707 free(fw_data, M_CXGBE);
9709 end_synchronized_op(sc, 0);
9714 load_cfg(struct adapter *sc, struct t4_data *cfg)
9717 uint8_t *cfg_data = NULL;
9719 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldcf");
9723 if (cfg->len == 0) {
9725 rc = -t4_load_cfg(sc, NULL, 0);
9729 cfg_data = malloc(cfg->len, M_CXGBE, M_WAITOK);
9730 if (cfg_data == NULL) {
9735 rc = copyin(cfg->data, cfg_data, cfg->len);
9737 rc = -t4_load_cfg(sc, cfg_data, cfg->len);
9739 free(cfg_data, M_CXGBE);
9741 end_synchronized_op(sc, 0);
9746 load_boot(struct adapter *sc, struct t4_bootrom *br)
9749 uint8_t *br_data = NULL;
9752 if (br->len > 1024 * 1024)
9755 if (br->pf_offset == 0) {
9757 if (br->pfidx_addr > 7)
9759 offset = G_OFFSET(t4_read_reg(sc, PF_REG(br->pfidx_addr,
9760 A_PCIE_PF_EXPROM_OFST)));
9761 } else if (br->pf_offset == 1) {
9763 offset = G_OFFSET(br->pfidx_addr);
9768 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldbr");
9774 rc = -t4_load_boot(sc, NULL, offset, 0);
9778 br_data = malloc(br->len, M_CXGBE, M_WAITOK);
9779 if (br_data == NULL) {
9784 rc = copyin(br->data, br_data, br->len);
9786 rc = -t4_load_boot(sc, br_data, offset, br->len);
9788 free(br_data, M_CXGBE);
9790 end_synchronized_op(sc, 0);
9795 load_bootcfg(struct adapter *sc, struct t4_data *bc)
9798 uint8_t *bc_data = NULL;
9800 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldcf");
9806 rc = -t4_load_bootcfg(sc, NULL, 0);
9810 bc_data = malloc(bc->len, M_CXGBE, M_WAITOK);
9811 if (bc_data == NULL) {
9816 rc = copyin(bc->data, bc_data, bc->len);
9818 rc = -t4_load_bootcfg(sc, bc_data, bc->len);
9820 free(bc_data, M_CXGBE);
9822 end_synchronized_op(sc, 0);
9827 cudbg_dump(struct adapter *sc, struct t4_cudbg_dump *dump)
9830 struct cudbg_init *cudbg;
9833 /* buf is large, don't block if no memory is available */
9834 buf = malloc(dump->len, M_CXGBE, M_NOWAIT | M_ZERO);
9838 handle = cudbg_alloc_handle();
9839 if (handle == NULL) {
9844 cudbg = cudbg_get_init(handle);
9846 cudbg->print = (cudbg_print_cb)printf;
9849 device_printf(sc->dev, "%s: wr_flash %u, len %u, data %p.\n",
9850 __func__, dump->wr_flash, dump->len, dump->data);
9854 cudbg->use_flash = 1;
9855 MPASS(sizeof(cudbg->dbg_bitmap) == sizeof(dump->bitmap));
9856 memcpy(cudbg->dbg_bitmap, dump->bitmap, sizeof(cudbg->dbg_bitmap));
9858 rc = cudbg_collect(handle, buf, &dump->len);
9862 rc = copyout(buf, dump->data, dump->len);
9864 cudbg_free_handle(handle);
9870 free_offload_policy(struct t4_offload_policy *op)
9872 struct offload_rule *r;
9879 for (i = 0; i < op->nrules; i++, r++) {
9880 free(r->bpf_prog.bf_insns, M_CXGBE);
9882 free(op->rule, M_CXGBE);
9887 set_offload_policy(struct adapter *sc, struct t4_offload_policy *uop)
9890 struct t4_offload_policy *op, *old;
9891 struct bpf_program *bf;
9892 const struct offload_settings *s;
9893 struct offload_rule *r;
9896 if (!is_offload(sc))
9899 if (uop->nrules == 0) {
9900 /* Delete installed policies. */
9903 } if (uop->nrules > 256) { /* arbitrary */
9907 /* Copy userspace offload policy to kernel */
9908 op = malloc(sizeof(*op), M_CXGBE, M_ZERO | M_WAITOK);
9909 op->nrules = uop->nrules;
9910 len = op->nrules * sizeof(struct offload_rule);
9911 op->rule = malloc(len, M_CXGBE, M_ZERO | M_WAITOK);
9912 rc = copyin(uop->rule, op->rule, len);
9914 free(op->rule, M_CXGBE);
9920 for (i = 0; i < op->nrules; i++, r++) {
9922 /* Validate open_type */
9923 if (r->open_type != OPEN_TYPE_LISTEN &&
9924 r->open_type != OPEN_TYPE_ACTIVE &&
9925 r->open_type != OPEN_TYPE_PASSIVE &&
9926 r->open_type != OPEN_TYPE_DONTCARE) {
9929 * Rules 0 to i have malloc'd filters that need to be
9930 * freed. Rules i+1 to nrules have userspace pointers
9931 * and should be left alone.
9934 free_offload_policy(op);
9938 /* Validate settings */
9940 if ((s->offload != 0 && s->offload != 1) ||
9941 s->cong_algo < -1 || s->cong_algo > CONG_ALG_HIGHSPEED ||
9942 s->sched_class < -1 ||
9943 s->sched_class >= sc->chip_params->nsched_cls) {
9949 u = bf->bf_insns; /* userspace ptr */
9950 bf->bf_insns = NULL;
9951 if (bf->bf_len == 0) {
9952 /* legal, matches everything */
9955 len = bf->bf_len * sizeof(*bf->bf_insns);
9956 bf->bf_insns = malloc(len, M_CXGBE, M_ZERO | M_WAITOK);
9957 rc = copyin(u, bf->bf_insns, len);
9961 if (!bpf_validate(bf->bf_insns, bf->bf_len)) {
9967 rw_wlock(&sc->policy_lock);
9970 rw_wunlock(&sc->policy_lock);
9971 free_offload_policy(old);
9976 #define MAX_READ_BUF_SIZE (128 * 1024)
9978 read_card_mem(struct adapter *sc, int win, struct t4_mem_range *mr)
9980 uint32_t addr, remaining, n;
9985 rc = validate_mem_range(sc, mr->addr, mr->len);
9989 buf = malloc(min(mr->len, MAX_READ_BUF_SIZE), M_CXGBE, M_WAITOK);
9991 remaining = mr->len;
9992 dst = (void *)mr->data;
9995 n = min(remaining, MAX_READ_BUF_SIZE);
9996 read_via_memwin(sc, 2, addr, buf, n);
9998 rc = copyout(buf, dst, n);
10007 free(buf, M_CXGBE);
10010 #undef MAX_READ_BUF_SIZE
10013 read_i2c(struct adapter *sc, struct t4_i2c_data *i2cd)
10017 if (i2cd->len == 0 || i2cd->port_id >= sc->params.nports)
10020 if (i2cd->len > sizeof(i2cd->data))
10023 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4i2crd");
10026 rc = -t4_i2c_rd(sc, sc->mbox, i2cd->port_id, i2cd->dev_addr,
10027 i2cd->offset, i2cd->len, &i2cd->data[0]);
10028 end_synchronized_op(sc, 0);
10034 t4_os_find_pci_capability(struct adapter *sc, int cap)
10038 return (pci_find_cap(sc->dev, cap, &i) == 0 ? i : 0);
10042 t4_os_pci_save_state(struct adapter *sc)
10045 struct pci_devinfo *dinfo;
10048 dinfo = device_get_ivars(dev);
10050 pci_cfg_save(dev, dinfo, 0);
10055 t4_os_pci_restore_state(struct adapter *sc)
10058 struct pci_devinfo *dinfo;
10061 dinfo = device_get_ivars(dev);
10063 pci_cfg_restore(dev, dinfo);
10068 t4_os_portmod_changed(struct port_info *pi)
10070 struct adapter *sc = pi->adapter;
10071 struct vi_info *vi;
10073 static const char *mod_str[] = {
10074 NULL, "LR", "SR", "ER", "TWINAX", "active TWINAX", "LRM"
10077 KASSERT((pi->flags & FIXED_IFMEDIA) == 0,
10078 ("%s: port_type %u", __func__, pi->port_type));
10081 if (begin_synchronized_op(sc, vi, HOLD_LOCK, "t4mod") == 0) {
10083 build_medialist(pi);
10084 if (pi->mod_type != FW_PORT_MOD_TYPE_NONE) {
10085 fixup_link_config(pi);
10086 apply_link_config(pi);
10089 end_synchronized_op(sc, LOCK_HELD);
10093 if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
10094 if_printf(ifp, "transceiver unplugged.\n");
10095 else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
10096 if_printf(ifp, "unknown transceiver inserted.\n");
10097 else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
10098 if_printf(ifp, "unsupported transceiver inserted.\n");
10099 else if (pi->mod_type > 0 && pi->mod_type < nitems(mod_str)) {
10100 if_printf(ifp, "%dGbps %s transceiver inserted.\n",
10101 port_top_speed(pi), mod_str[pi->mod_type]);
10103 if_printf(ifp, "transceiver (type %d) inserted.\n",
10109 t4_os_link_changed(struct port_info *pi)
10111 struct vi_info *vi;
10113 struct link_config *lc;
10116 PORT_LOCK_ASSERT_OWNED(pi);
10118 for_each_vi(pi, v, vi) {
10123 lc = &pi->link_cfg;
10125 ifp->if_baudrate = IF_Mbps(lc->speed);
10126 if_link_state_change(ifp, LINK_STATE_UP);
10128 if_link_state_change(ifp, LINK_STATE_DOWN);
10134 t4_iterate(void (*func)(struct adapter *, void *), void *arg)
10136 struct adapter *sc;
10138 sx_slock(&t4_list_lock);
10139 SLIST_FOREACH(sc, &t4_list, link) {
10141 * func should not make any assumptions about what state sc is
10142 * in - the only guarantee is that sc->sc_lock is a valid lock.
10146 sx_sunlock(&t4_list_lock);
10150 t4_ioctl(struct cdev *dev, unsigned long cmd, caddr_t data, int fflag,
10154 struct adapter *sc = dev->si_drv1;
10156 rc = priv_check(td, PRIV_DRIVER);
10161 case CHELSIO_T4_GETREG: {
10162 struct t4_reg *edata = (struct t4_reg *)data;
10164 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
10167 if (edata->size == 4)
10168 edata->val = t4_read_reg(sc, edata->addr);
10169 else if (edata->size == 8)
10170 edata->val = t4_read_reg64(sc, edata->addr);
10176 case CHELSIO_T4_SETREG: {
10177 struct t4_reg *edata = (struct t4_reg *)data;
10179 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len)
10182 if (edata->size == 4) {
10183 if (edata->val & 0xffffffff00000000)
10185 t4_write_reg(sc, edata->addr, (uint32_t) edata->val);
10186 } else if (edata->size == 8)
10187 t4_write_reg64(sc, edata->addr, edata->val);
10192 case CHELSIO_T4_REGDUMP: {
10193 struct t4_regdump *regs = (struct t4_regdump *)data;
10194 int reglen = t4_get_regs_len(sc);
10197 if (regs->len < reglen) {
10198 regs->len = reglen; /* hint to the caller */
10202 regs->len = reglen;
10203 buf = malloc(reglen, M_CXGBE, M_WAITOK | M_ZERO);
10204 get_regs(sc, regs, buf);
10205 rc = copyout(buf, regs->data, reglen);
10206 free(buf, M_CXGBE);
10209 case CHELSIO_T4_GET_FILTER_MODE:
10210 rc = get_filter_mode(sc, (uint32_t *)data);
10212 case CHELSIO_T4_SET_FILTER_MODE:
10213 rc = set_filter_mode(sc, *(uint32_t *)data);
10215 case CHELSIO_T4_GET_FILTER:
10216 rc = get_filter(sc, (struct t4_filter *)data);
10218 case CHELSIO_T4_SET_FILTER:
10219 rc = set_filter(sc, (struct t4_filter *)data);
10221 case CHELSIO_T4_DEL_FILTER:
10222 rc = del_filter(sc, (struct t4_filter *)data);
10224 case CHELSIO_T4_GET_SGE_CONTEXT:
10225 rc = get_sge_context(sc, (struct t4_sge_context *)data);
10227 case CHELSIO_T4_LOAD_FW:
10228 rc = load_fw(sc, (struct t4_data *)data);
10230 case CHELSIO_T4_GET_MEM:
10231 rc = read_card_mem(sc, 2, (struct t4_mem_range *)data);
10233 case CHELSIO_T4_GET_I2C:
10234 rc = read_i2c(sc, (struct t4_i2c_data *)data);
10236 case CHELSIO_T4_CLEAR_STATS: {
10238 u_int port_id = *(uint32_t *)data;
10239 struct port_info *pi;
10240 struct vi_info *vi;
10242 if (port_id >= sc->params.nports)
10244 pi = sc->port[port_id];
10249 t4_clr_port_stats(sc, pi->tx_chan);
10250 pi->tx_parse_error = 0;
10251 pi->tnl_cong_drops = 0;
10252 mtx_lock(&sc->reg_lock);
10253 for_each_vi(pi, v, vi) {
10254 if (vi->flags & VI_INIT_DONE)
10255 t4_clr_vi_stats(sc, vi->viid);
10257 bg_map = pi->mps_bg_map;
10260 i = ffs(bg_map) - 1;
10261 t4_write_indirect(sc, A_TP_MIB_INDEX, A_TP_MIB_DATA, &v,
10262 1, A_TP_MIB_TNL_CNG_DROP_0 + i);
10263 bg_map &= ~(1 << i);
10265 mtx_unlock(&sc->reg_lock);
10268 * Since this command accepts a port, clear stats for
10269 * all VIs on this port.
10271 for_each_vi(pi, v, vi) {
10272 if (vi->flags & VI_INIT_DONE) {
10273 struct sge_rxq *rxq;
10274 struct sge_txq *txq;
10275 struct sge_wrq *wrq;
10277 for_each_rxq(vi, i, rxq) {
10278 #if defined(INET) || defined(INET6)
10279 rxq->lro.lro_queued = 0;
10280 rxq->lro.lro_flushed = 0;
10283 rxq->vlan_extraction = 0;
10286 for_each_txq(vi, i, txq) {
10289 txq->vlan_insertion = 0;
10292 txq->txpkt_wrs = 0;
10293 txq->txpkts0_wrs = 0;
10294 txq->txpkts1_wrs = 0;
10295 txq->txpkts0_pkts = 0;
10296 txq->txpkts1_pkts = 0;
10297 mp_ring_reset_stats(txq->r);
10301 /* nothing to clear for each ofld_rxq */
10303 for_each_ofld_txq(vi, i, wrq) {
10304 wrq->tx_wrs_direct = 0;
10305 wrq->tx_wrs_copied = 0;
10309 if (IS_MAIN_VI(vi)) {
10310 wrq = &sc->sge.ctrlq[pi->port_id];
10311 wrq->tx_wrs_direct = 0;
10312 wrq->tx_wrs_copied = 0;
10318 case CHELSIO_T4_SCHED_CLASS:
10319 rc = t4_set_sched_class(sc, (struct t4_sched_params *)data);
10321 case CHELSIO_T4_SCHED_QUEUE:
10322 rc = t4_set_sched_queue(sc, (struct t4_sched_queue *)data);
10324 case CHELSIO_T4_GET_TRACER:
10325 rc = t4_get_tracer(sc, (struct t4_tracer *)data);
10327 case CHELSIO_T4_SET_TRACER:
10328 rc = t4_set_tracer(sc, (struct t4_tracer *)data);
10330 case CHELSIO_T4_LOAD_CFG:
10331 rc = load_cfg(sc, (struct t4_data *)data);
10333 case CHELSIO_T4_LOAD_BOOT:
10334 rc = load_boot(sc, (struct t4_bootrom *)data);
10336 case CHELSIO_T4_LOAD_BOOTCFG:
10337 rc = load_bootcfg(sc, (struct t4_data *)data);
10339 case CHELSIO_T4_CUDBG_DUMP:
10340 rc = cudbg_dump(sc, (struct t4_cudbg_dump *)data);
10342 case CHELSIO_T4_SET_OFLD_POLICY:
10343 rc = set_offload_policy(sc, (struct t4_offload_policy *)data);
10353 t4_db_full(struct adapter *sc)
10356 CXGBE_UNIMPLEMENTED(__func__);
10360 t4_db_dropped(struct adapter *sc)
10363 CXGBE_UNIMPLEMENTED(__func__);
10368 t4_iscsi_init(struct adapter *sc, u_int tag_mask, const u_int *pgsz_order)
10371 t4_write_reg(sc, A_ULP_RX_ISCSI_TAGMASK, tag_mask);
10372 t4_write_reg(sc, A_ULP_RX_ISCSI_PSZ, V_HPZ0(pgsz_order[0]) |
10373 V_HPZ1(pgsz_order[1]) | V_HPZ2(pgsz_order[2]) |
10374 V_HPZ3(pgsz_order[3]));
10378 toe_capability(struct vi_info *vi, int enable)
10381 struct port_info *pi = vi->pi;
10382 struct adapter *sc = pi->adapter;
10384 ASSERT_SYNCHRONIZED_OP(sc);
10386 if (!is_offload(sc))
10390 if ((vi->ifp->if_capenable & IFCAP_TOE) != 0) {
10391 /* TOE is already enabled. */
10396 * We need the port's queues around so that we're able to send
10397 * and receive CPLs to/from the TOE even if the ifnet for this
10398 * port has never been UP'd administratively.
10400 if (!(vi->flags & VI_INIT_DONE)) {
10401 rc = vi_full_init(vi);
10405 if (!(pi->vi[0].flags & VI_INIT_DONE)) {
10406 rc = vi_full_init(&pi->vi[0]);
10411 if (isset(&sc->offload_map, pi->port_id)) {
10412 /* TOE is enabled on another VI of this port. */
10417 if (!uld_active(sc, ULD_TOM)) {
10418 rc = t4_activate_uld(sc, ULD_TOM);
10419 if (rc == EAGAIN) {
10421 "You must kldload t4_tom.ko before trying "
10422 "to enable TOE on a cxgbe interface.\n");
10426 KASSERT(sc->tom_softc != NULL,
10427 ("%s: TOM activated but softc NULL", __func__));
10428 KASSERT(uld_active(sc, ULD_TOM),
10429 ("%s: TOM activated but flag not set", __func__));
10432 /* Activate iWARP and iSCSI too, if the modules are loaded. */
10433 if (!uld_active(sc, ULD_IWARP))
10434 (void) t4_activate_uld(sc, ULD_IWARP);
10435 if (!uld_active(sc, ULD_ISCSI))
10436 (void) t4_activate_uld(sc, ULD_ISCSI);
10439 setbit(&sc->offload_map, pi->port_id);
10443 if (!isset(&sc->offload_map, pi->port_id) || pi->uld_vis > 0)
10446 KASSERT(uld_active(sc, ULD_TOM),
10447 ("%s: TOM never initialized?", __func__));
10448 clrbit(&sc->offload_map, pi->port_id);
10455 * Add an upper layer driver to the global list.
10458 t4_register_uld(struct uld_info *ui)
10461 struct uld_info *u;
10463 sx_xlock(&t4_uld_list_lock);
10464 SLIST_FOREACH(u, &t4_uld_list, link) {
10465 if (u->uld_id == ui->uld_id) {
10471 SLIST_INSERT_HEAD(&t4_uld_list, ui, link);
10474 sx_xunlock(&t4_uld_list_lock);
10479 t4_unregister_uld(struct uld_info *ui)
10482 struct uld_info *u;
10484 sx_xlock(&t4_uld_list_lock);
10486 SLIST_FOREACH(u, &t4_uld_list, link) {
10488 if (ui->refcount > 0) {
10493 SLIST_REMOVE(&t4_uld_list, ui, uld_info, link);
10499 sx_xunlock(&t4_uld_list_lock);
10504 t4_activate_uld(struct adapter *sc, int id)
10507 struct uld_info *ui;
10509 ASSERT_SYNCHRONIZED_OP(sc);
10511 if (id < 0 || id > ULD_MAX)
10513 rc = EAGAIN; /* kldoad the module with this ULD and try again. */
10515 sx_slock(&t4_uld_list_lock);
10517 SLIST_FOREACH(ui, &t4_uld_list, link) {
10518 if (ui->uld_id == id) {
10519 if (!(sc->flags & FULL_INIT_DONE)) {
10520 rc = adapter_full_init(sc);
10525 rc = ui->activate(sc);
10527 setbit(&sc->active_ulds, id);
10534 sx_sunlock(&t4_uld_list_lock);
10540 t4_deactivate_uld(struct adapter *sc, int id)
10543 struct uld_info *ui;
10545 ASSERT_SYNCHRONIZED_OP(sc);
10547 if (id < 0 || id > ULD_MAX)
10551 sx_slock(&t4_uld_list_lock);
10553 SLIST_FOREACH(ui, &t4_uld_list, link) {
10554 if (ui->uld_id == id) {
10555 rc = ui->deactivate(sc);
10557 clrbit(&sc->active_ulds, id);
10564 sx_sunlock(&t4_uld_list_lock);
10570 uld_active(struct adapter *sc, int uld_id)
10573 MPASS(uld_id >= 0 && uld_id <= ULD_MAX);
10575 return (isset(&sc->active_ulds, uld_id));
10580 * t = ptr to tunable.
10581 * nc = number of CPUs.
10582 * c = compiled in default for that tunable.
10585 calculate_nqueues(int *t, int nc, const int c)
10591 nq = *t < 0 ? -*t : c;
10596 * Come up with reasonable defaults for some of the tunables, provided they're
10597 * not set by the user (in which case we'll use the values as is).
10600 tweak_tunables(void)
10602 int nc = mp_ncpus; /* our snapshot of the number of CPUs */
10606 t4_ntxq = rss_getnumbuckets();
10608 calculate_nqueues(&t4_ntxq, nc, NTXQ);
10612 calculate_nqueues(&t4_ntxq_vi, nc, NTXQ_VI);
10616 t4_nrxq = rss_getnumbuckets();
10618 calculate_nqueues(&t4_nrxq, nc, NRXQ);
10622 calculate_nqueues(&t4_nrxq_vi, nc, NRXQ_VI);
10625 calculate_nqueues(&t4_nofldtxq, nc, NOFLDTXQ);
10626 calculate_nqueues(&t4_nofldtxq_vi, nc, NOFLDTXQ_VI);
10627 calculate_nqueues(&t4_nofldrxq, nc, NOFLDRXQ);
10628 calculate_nqueues(&t4_nofldrxq_vi, nc, NOFLDRXQ_VI);
10630 if (t4_toecaps_allowed == -1)
10631 t4_toecaps_allowed = FW_CAPS_CONFIG_TOE;
10633 if (t4_rdmacaps_allowed == -1) {
10634 t4_rdmacaps_allowed = FW_CAPS_CONFIG_RDMA_RDDP |
10635 FW_CAPS_CONFIG_RDMA_RDMAC;
10638 if (t4_iscsicaps_allowed == -1) {
10639 t4_iscsicaps_allowed = FW_CAPS_CONFIG_ISCSI_INITIATOR_PDU |
10640 FW_CAPS_CONFIG_ISCSI_TARGET_PDU |
10641 FW_CAPS_CONFIG_ISCSI_T10DIF;
10644 if (t4_tmr_idx_ofld < 0 || t4_tmr_idx_ofld >= SGE_NTIMERS)
10645 t4_tmr_idx_ofld = TMR_IDX_OFLD;
10647 if (t4_pktc_idx_ofld < -1 || t4_pktc_idx_ofld >= SGE_NCOUNTERS)
10648 t4_pktc_idx_ofld = PKTC_IDX_OFLD;
10650 if (t4_toecaps_allowed == -1)
10651 t4_toecaps_allowed = 0;
10653 if (t4_rdmacaps_allowed == -1)
10654 t4_rdmacaps_allowed = 0;
10656 if (t4_iscsicaps_allowed == -1)
10657 t4_iscsicaps_allowed = 0;
10661 calculate_nqueues(&t4_nnmtxq_vi, nc, NNMTXQ_VI);
10662 calculate_nqueues(&t4_nnmrxq_vi, nc, NNMRXQ_VI);
10665 if (t4_tmr_idx < 0 || t4_tmr_idx >= SGE_NTIMERS)
10666 t4_tmr_idx = TMR_IDX;
10668 if (t4_pktc_idx < -1 || t4_pktc_idx >= SGE_NCOUNTERS)
10669 t4_pktc_idx = PKTC_IDX;
10671 if (t4_qsize_txq < 128)
10672 t4_qsize_txq = 128;
10674 if (t4_qsize_rxq < 128)
10675 t4_qsize_rxq = 128;
10676 while (t4_qsize_rxq & 7)
10679 t4_intr_types &= INTR_MSIX | INTR_MSI | INTR_INTX;
10682 * Number of VIs to create per-port. The first VI is the "main" regular
10683 * VI for the port. The rest are additional virtual interfaces on the
10684 * same physical port. Note that the main VI does not have native
10685 * netmap support but the extra VIs do.
10687 * Limit the number of VIs per port to the number of available
10688 * MAC addresses per port.
10690 if (t4_num_vis < 1)
10692 if (t4_num_vis > nitems(vi_mac_funcs)) {
10693 t4_num_vis = nitems(vi_mac_funcs);
10694 printf("cxgbe: number of VIs limited to %d\n", t4_num_vis);
10697 if (pcie_relaxed_ordering < 0 || pcie_relaxed_ordering > 2) {
10698 pcie_relaxed_ordering = 1;
10699 #if defined(__i386__) || defined(__amd64__)
10700 if (cpu_vendor_id == CPU_VENDOR_INTEL)
10701 pcie_relaxed_ordering = 0;
10708 t4_dump_tcb(struct adapter *sc, int tid)
10710 uint32_t base, i, j, off, pf, reg, save, tcb_addr, win_pos;
10712 reg = PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, 2);
10713 save = t4_read_reg(sc, reg);
10714 base = sc->memwin[2].mw_base;
10716 /* Dump TCB for the tid */
10717 tcb_addr = t4_read_reg(sc, A_TP_CMM_TCB_BASE);
10718 tcb_addr += tid * TCB_SIZE;
10722 win_pos = tcb_addr & ~0xf; /* start must be 16B aligned */
10724 pf = V_PFNUM(sc->pf);
10725 win_pos = tcb_addr & ~0x7f; /* start must be 128B aligned */
10727 t4_write_reg(sc, reg, win_pos | pf);
10728 t4_read_reg(sc, reg);
10730 off = tcb_addr - win_pos;
10731 for (i = 0; i < 4; i++) {
10733 for (j = 0; j < 8; j++, off += 4)
10734 buf[j] = htonl(t4_read_reg(sc, base + off));
10736 db_printf("%08x %08x %08x %08x %08x %08x %08x %08x\n",
10737 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6],
10741 t4_write_reg(sc, reg, save);
10742 t4_read_reg(sc, reg);
10746 t4_dump_devlog(struct adapter *sc)
10748 struct devlog_params *dparams = &sc->params.devlog;
10749 struct fw_devlog_e e;
10750 int i, first, j, m, nentries, rc;
10751 uint64_t ftstamp = UINT64_MAX;
10753 if (dparams->start == 0) {
10754 db_printf("devlog params not valid\n");
10758 nentries = dparams->size / sizeof(struct fw_devlog_e);
10759 m = fwmtype_to_hwmtype(dparams->memtype);
10761 /* Find the first entry. */
10763 for (i = 0; i < nentries && !db_pager_quit; i++) {
10764 rc = -t4_mem_read(sc, m, dparams->start + i * sizeof(e),
10765 sizeof(e), (void *)&e);
10769 if (e.timestamp == 0)
10772 e.timestamp = be64toh(e.timestamp);
10773 if (e.timestamp < ftstamp) {
10774 ftstamp = e.timestamp;
10784 rc = -t4_mem_read(sc, m, dparams->start + i * sizeof(e),
10785 sizeof(e), (void *)&e);
10789 if (e.timestamp == 0)
10792 e.timestamp = be64toh(e.timestamp);
10793 e.seqno = be32toh(e.seqno);
10794 for (j = 0; j < 8; j++)
10795 e.params[j] = be32toh(e.params[j]);
10797 db_printf("%10d %15ju %8s %8s ",
10798 e.seqno, e.timestamp,
10799 (e.level < nitems(devlog_level_strings) ?
10800 devlog_level_strings[e.level] : "UNKNOWN"),
10801 (e.facility < nitems(devlog_facility_strings) ?
10802 devlog_facility_strings[e.facility] : "UNKNOWN"));
10803 db_printf(e.fmt, e.params[0], e.params[1], e.params[2],
10804 e.params[3], e.params[4], e.params[5], e.params[6],
10807 if (++i == nentries)
10809 } while (i != first && !db_pager_quit);
10812 static struct command_table db_t4_table = LIST_HEAD_INITIALIZER(db_t4_table);
10813 _DB_SET(_show, t4, NULL, db_show_table, 0, &db_t4_table);
10815 DB_FUNC(devlog, db_show_devlog, db_t4_table, CS_OWN, NULL)
10822 t = db_read_token();
10824 dev = device_lookup_by_name(db_tok_string);
10829 db_printf("usage: show t4 devlog <nexus>\n");
10834 db_printf("device not found\n");
10838 t4_dump_devlog(device_get_softc(dev));
10841 DB_FUNC(tcb, db_show_t4tcb, db_t4_table, CS_OWN, NULL)
10850 t = db_read_token();
10852 dev = device_lookup_by_name(db_tok_string);
10853 t = db_read_token();
10854 if (t == tNUMBER) {
10855 tid = db_tok_number;
10862 db_printf("usage: show t4 tcb <nexus> <tid>\n");
10867 db_printf("device not found\n");
10871 db_printf("invalid tid\n");
10875 t4_dump_tcb(device_get_softc(dev), tid);
10880 * Borrowed from cesa_prep_aes_key().
10882 * NB: The crypto engine wants the words in the decryption key in reverse
10886 t4_aes_getdeckey(void *dec_key, const void *enc_key, unsigned int kbits)
10888 uint32_t ek[4 * (RIJNDAEL_MAXNR + 1)];
10892 rijndaelKeySetupEnc(ek, enc_key, kbits);
10894 dkey += (kbits / 8) / 4;
10898 for (i = 0; i < 4; i++)
10899 *--dkey = htobe32(ek[4 * 10 + i]);
10902 for (i = 0; i < 2; i++)
10903 *--dkey = htobe32(ek[4 * 11 + 2 + i]);
10904 for (i = 0; i < 4; i++)
10905 *--dkey = htobe32(ek[4 * 12 + i]);
10908 for (i = 0; i < 4; i++)
10909 *--dkey = htobe32(ek[4 * 13 + i]);
10910 for (i = 0; i < 4; i++)
10911 *--dkey = htobe32(ek[4 * 14 + i]);
10914 MPASS(dkey == dec_key);
10917 static struct sx mlu; /* mod load unload */
10918 SX_SYSINIT(cxgbe_mlu, &mlu, "cxgbe mod load/unload");
10921 mod_event(module_t mod, int cmd, void *arg)
10924 static int loaded = 0;
10929 if (loaded++ == 0) {
10931 t4_register_cpl_handler(CPL_SET_TCB_RPL, set_tcb_rpl);
10932 t4_register_cpl_handler(CPL_L2T_WRITE_RPL, l2t_write_rpl);
10933 t4_register_cpl_handler(CPL_TRACE_PKT, t4_trace_pkt);
10934 t4_register_cpl_handler(CPL_T5_TRACE_PKT, t5_trace_pkt);
10935 sx_init(&t4_list_lock, "T4/T5 adapters");
10936 SLIST_INIT(&t4_list);
10938 sx_init(&t4_uld_list_lock, "T4/T5 ULDs");
10939 SLIST_INIT(&t4_uld_list);
10941 t4_tracer_modload();
10949 if (--loaded == 0) {
10952 sx_slock(&t4_list_lock);
10953 if (!SLIST_EMPTY(&t4_list)) {
10955 sx_sunlock(&t4_list_lock);
10959 sx_slock(&t4_uld_list_lock);
10960 if (!SLIST_EMPTY(&t4_uld_list)) {
10962 sx_sunlock(&t4_uld_list_lock);
10963 sx_sunlock(&t4_list_lock);
10968 while (tries++ < 5 && t4_sge_extfree_refs() != 0) {
10969 uprintf("%ju clusters with custom free routine "
10970 "still is use.\n", t4_sge_extfree_refs());
10971 pause("t4unload", 2 * hz);
10974 sx_sunlock(&t4_uld_list_lock);
10976 sx_sunlock(&t4_list_lock);
10978 if (t4_sge_extfree_refs() == 0) {
10979 t4_tracer_modunload();
10981 sx_destroy(&t4_uld_list_lock);
10983 sx_destroy(&t4_list_lock);
10984 t4_sge_modunload();
10988 loaded++; /* undo earlier decrement */
10999 static devclass_t t4_devclass, t5_devclass, t6_devclass;
11000 static devclass_t cxgbe_devclass, cxl_devclass, cc_devclass;
11001 static devclass_t vcxgbe_devclass, vcxl_devclass, vcc_devclass;
11003 DRIVER_MODULE(t4nex, pci, t4_driver, t4_devclass, mod_event, 0);
11004 MODULE_VERSION(t4nex, 1);
11005 MODULE_DEPEND(t4nex, firmware, 1, 1, 1);
11007 MODULE_DEPEND(t4nex, netmap, 1, 1, 1);
11008 #endif /* DEV_NETMAP */
11010 DRIVER_MODULE(t5nex, pci, t5_driver, t5_devclass, mod_event, 0);
11011 MODULE_VERSION(t5nex, 1);
11012 MODULE_DEPEND(t5nex, firmware, 1, 1, 1);
11014 MODULE_DEPEND(t5nex, netmap, 1, 1, 1);
11015 #endif /* DEV_NETMAP */
11017 DRIVER_MODULE(t6nex, pci, t6_driver, t6_devclass, mod_event, 0);
11018 MODULE_VERSION(t6nex, 1);
11019 MODULE_DEPEND(t6nex, firmware, 1, 1, 1);
11021 MODULE_DEPEND(t6nex, netmap, 1, 1, 1);
11022 #endif /* DEV_NETMAP */
11024 DRIVER_MODULE(cxgbe, t4nex, cxgbe_driver, cxgbe_devclass, 0, 0);
11025 MODULE_VERSION(cxgbe, 1);
11027 DRIVER_MODULE(cxl, t5nex, cxl_driver, cxl_devclass, 0, 0);
11028 MODULE_VERSION(cxl, 1);
11030 DRIVER_MODULE(cc, t6nex, cc_driver, cc_devclass, 0, 0);
11031 MODULE_VERSION(cc, 1);
11033 DRIVER_MODULE(vcxgbe, cxgbe, vcxgbe_driver, vcxgbe_devclass, 0, 0);
11034 MODULE_VERSION(vcxgbe, 1);
11036 DRIVER_MODULE(vcxl, cxl, vcxl_driver, vcxl_devclass, 0, 0);
11037 MODULE_VERSION(vcxl, 1);
11039 DRIVER_MODULE(vcc, cc, vcc_driver, vcc_devclass, 0, 0);
11040 MODULE_VERSION(vcc, 1);