1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2011 Chelsio Communications, Inc. 5 * All rights reserved. 6 * Written by: Navdeep Parhar <np@FreeBSD.org> 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #include <sys/cdefs.h> 31 #include "opt_ddb.h" 32 #include "opt_inet.h" 33 #include "opt_inet6.h" 34 #include "opt_kern_tls.h" 35 #include "opt_ratelimit.h" 36 #include "opt_rss.h" 37 38 #include <sys/param.h> 39 #include <sys/conf.h> 40 #include <sys/priv.h> 41 #include <sys/kernel.h> 42 #include <sys/bus.h> 43 #include <sys/eventhandler.h> 44 #include <sys/module.h> 45 #include <sys/malloc.h> 46 #include <sys/queue.h> 47 #include <sys/taskqueue.h> 48 #include <sys/pciio.h> 49 #include <dev/pci/pcireg.h> 50 #include <dev/pci/pcivar.h> 51 #include <dev/pci/pci_private.h> 52 #include <sys/firmware.h> 53 #include <sys/sbuf.h> 54 #include <sys/smp.h> 55 #include <sys/socket.h> 56 #include <sys/sockio.h> 57 #include <sys/sysctl.h> 58 #include <net/ethernet.h> 59 #include <net/if.h> 60 #include <net/if_types.h> 61 #include <net/if_dl.h> 62 #include <net/if_vlan_var.h> 63 #ifdef RSS 64 #include <net/rss_config.h> 65 #endif 66 #include <netinet/in.h> 67 #include <netinet/ip.h> 68 #ifdef KERN_TLS 69 #include <netinet/tcp_seq.h> 70 #endif 71 #if defined(__i386__) || defined(__amd64__) 72 #include <machine/md_var.h> 73 #include <machine/cputypes.h> 74 #include <vm/vm.h> 75 #include <vm/pmap.h> 76 #endif 77 #ifdef DDB 78 #include <ddb/ddb.h> 79 #include <ddb/db_lex.h> 80 #endif 81 82 #include "common/common.h" 83 #include "common/t4_msg.h" 84 #include "common/t4_regs.h" 85 #include "common/t4_regs_values.h" 86 #include "cudbg/cudbg.h" 87 #include "t4_clip.h" 88 #include "t4_ioctl.h" 89 #include "t4_l2t.h" 90 #include "t4_mp_ring.h" 91 #include "t4_if.h" 92 #include "t4_smt.h" 93 94 /* T4 bus driver interface */ 95 static int t4_probe(device_t); 96 static int t4_attach(device_t); 97 static int t4_detach(device_t); 98 static int t4_child_location(device_t, device_t, struct sbuf *); 99 static int t4_ready(device_t); 100 static int t4_read_port_device(device_t, int, device_t *); 101 static int t4_suspend(device_t); 102 static int t4_resume(device_t); 103 static int t4_reset_prepare(device_t, device_t); 104 static int t4_reset_post(device_t, device_t); 105 static device_method_t t4_methods[] = { 106 DEVMETHOD(device_probe, t4_probe), 107 DEVMETHOD(device_attach, t4_attach), 108 DEVMETHOD(device_detach, t4_detach), 109 DEVMETHOD(device_suspend, t4_suspend), 110 DEVMETHOD(device_resume, t4_resume), 111 112 DEVMETHOD(bus_child_location, t4_child_location), 113 DEVMETHOD(bus_reset_prepare, t4_reset_prepare), 114 DEVMETHOD(bus_reset_post, t4_reset_post), 115 116 DEVMETHOD(t4_is_main_ready, t4_ready), 117 DEVMETHOD(t4_read_port_device, t4_read_port_device), 118 119 DEVMETHOD_END 120 }; 121 static driver_t t4_driver = { 122 "t4nex", 123 t4_methods, 124 sizeof(struct adapter) 125 }; 126 127 128 /* T4 port (cxgbe) interface */ 129 static int cxgbe_probe(device_t); 130 static int cxgbe_attach(device_t); 131 static int cxgbe_detach(device_t); 132 device_method_t cxgbe_methods[] = { 133 DEVMETHOD(device_probe, cxgbe_probe), 134 DEVMETHOD(device_attach, cxgbe_attach), 135 DEVMETHOD(device_detach, cxgbe_detach), 136 { 0, 0 } 137 }; 138 static driver_t cxgbe_driver = { 139 "cxgbe", 140 cxgbe_methods, 141 sizeof(struct port_info) 142 }; 143 144 /* T4 VI (vcxgbe) interface */ 145 static int vcxgbe_probe(device_t); 146 static int vcxgbe_attach(device_t); 147 static int vcxgbe_detach(device_t); 148 static device_method_t vcxgbe_methods[] = { 149 DEVMETHOD(device_probe, vcxgbe_probe), 150 DEVMETHOD(device_attach, vcxgbe_attach), 151 DEVMETHOD(device_detach, vcxgbe_detach), 152 { 0, 0 } 153 }; 154 static driver_t vcxgbe_driver = { 155 "vcxgbe", 156 vcxgbe_methods, 157 sizeof(struct vi_info) 158 }; 159 160 static d_ioctl_t t4_ioctl; 161 162 static struct cdevsw t4_cdevsw = { 163 .d_version = D_VERSION, 164 .d_ioctl = t4_ioctl, 165 .d_name = "t4nex", 166 }; 167 168 /* T5 bus driver interface */ 169 static int t5_probe(device_t); 170 static device_method_t t5_methods[] = { 171 DEVMETHOD(device_probe, t5_probe), 172 DEVMETHOD(device_attach, t4_attach), 173 DEVMETHOD(device_detach, t4_detach), 174 DEVMETHOD(device_suspend, t4_suspend), 175 DEVMETHOD(device_resume, t4_resume), 176 177 DEVMETHOD(bus_child_location, t4_child_location), 178 DEVMETHOD(bus_reset_prepare, t4_reset_prepare), 179 DEVMETHOD(bus_reset_post, t4_reset_post), 180 181 DEVMETHOD(t4_is_main_ready, t4_ready), 182 DEVMETHOD(t4_read_port_device, t4_read_port_device), 183 184 DEVMETHOD_END 185 }; 186 static driver_t t5_driver = { 187 "t5nex", 188 t5_methods, 189 sizeof(struct adapter) 190 }; 191 192 193 /* T5 port (cxl) interface */ 194 static driver_t cxl_driver = { 195 "cxl", 196 cxgbe_methods, 197 sizeof(struct port_info) 198 }; 199 200 /* T5 VI (vcxl) interface */ 201 static driver_t vcxl_driver = { 202 "vcxl", 203 vcxgbe_methods, 204 sizeof(struct vi_info) 205 }; 206 207 /* T6 bus driver interface */ 208 static int t6_probe(device_t); 209 static device_method_t t6_methods[] = { 210 DEVMETHOD(device_probe, t6_probe), 211 DEVMETHOD(device_attach, t4_attach), 212 DEVMETHOD(device_detach, t4_detach), 213 DEVMETHOD(device_suspend, t4_suspend), 214 DEVMETHOD(device_resume, t4_resume), 215 216 DEVMETHOD(bus_child_location, t4_child_location), 217 DEVMETHOD(bus_reset_prepare, t4_reset_prepare), 218 DEVMETHOD(bus_reset_post, t4_reset_post), 219 220 DEVMETHOD(t4_is_main_ready, t4_ready), 221 DEVMETHOD(t4_read_port_device, t4_read_port_device), 222 223 DEVMETHOD_END 224 }; 225 static driver_t t6_driver = { 226 "t6nex", 227 t6_methods, 228 sizeof(struct adapter) 229 }; 230 231 232 /* T6 port (cc) interface */ 233 static driver_t cc_driver = { 234 "cc", 235 cxgbe_methods, 236 sizeof(struct port_info) 237 }; 238 239 /* T6 VI (vcc) interface */ 240 static driver_t vcc_driver = { 241 "vcc", 242 vcxgbe_methods, 243 sizeof(struct vi_info) 244 }; 245 246 /* ifnet interface */ 247 static void cxgbe_init(void *); 248 static int cxgbe_ioctl(if_t, unsigned long, caddr_t); 249 static int cxgbe_transmit(if_t, struct mbuf *); 250 static void cxgbe_qflush(if_t); 251 #if defined(KERN_TLS) || defined(RATELIMIT) 252 static int cxgbe_snd_tag_alloc(if_t, union if_snd_tag_alloc_params *, 253 struct m_snd_tag **); 254 #endif 255 256 MALLOC_DEFINE(M_CXGBE, "cxgbe", "Chelsio T4/T5 Ethernet driver and services"); 257 258 /* 259 * Correct lock order when you need to acquire multiple locks is t4_list_lock, 260 * then ADAPTER_LOCK, then t4_uld_list_lock. 261 */ 262 static struct sx t4_list_lock; 263 SLIST_HEAD(, adapter) t4_list; 264 #ifdef TCP_OFFLOAD 265 static struct sx t4_uld_list_lock; 266 SLIST_HEAD(, uld_info) t4_uld_list; 267 #endif 268 269 /* 270 * Tunables. See tweak_tunables() too. 271 * 272 * Each tunable is set to a default value here if it's known at compile-time. 273 * Otherwise it is set to -n as an indication to tweak_tunables() that it should 274 * provide a reasonable default (upto n) when the driver is loaded. 275 * 276 * Tunables applicable to both T4 and T5 are under hw.cxgbe. Those specific to 277 * T5 are under hw.cxl. 278 */ 279 SYSCTL_NODE(_hw, OID_AUTO, cxgbe, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 280 "cxgbe(4) parameters"); 281 SYSCTL_NODE(_hw, OID_AUTO, cxl, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 282 "cxgbe(4) T5+ parameters"); 283 SYSCTL_NODE(_hw_cxgbe, OID_AUTO, toe, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 284 "cxgbe(4) TOE parameters"); 285 286 /* 287 * Number of queues for tx and rx, NIC and offload. 288 */ 289 #define NTXQ 16 290 int t4_ntxq = -NTXQ; 291 SYSCTL_INT(_hw_cxgbe, OID_AUTO, ntxq, CTLFLAG_RDTUN, &t4_ntxq, 0, 292 "Number of TX queues per port"); 293 TUNABLE_INT("hw.cxgbe.ntxq10g", &t4_ntxq); /* Old name, undocumented */ 294 295 #define NRXQ 8 296 int t4_nrxq = -NRXQ; 297 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nrxq, CTLFLAG_RDTUN, &t4_nrxq, 0, 298 "Number of RX queues per port"); 299 TUNABLE_INT("hw.cxgbe.nrxq10g", &t4_nrxq); /* Old name, undocumented */ 300 301 #define NTXQ_VI 1 302 static int t4_ntxq_vi = -NTXQ_VI; 303 SYSCTL_INT(_hw_cxgbe, OID_AUTO, ntxq_vi, CTLFLAG_RDTUN, &t4_ntxq_vi, 0, 304 "Number of TX queues per VI"); 305 306 #define NRXQ_VI 1 307 static int t4_nrxq_vi = -NRXQ_VI; 308 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nrxq_vi, CTLFLAG_RDTUN, &t4_nrxq_vi, 0, 309 "Number of RX queues per VI"); 310 311 static int t4_rsrv_noflowq = 0; 312 SYSCTL_INT(_hw_cxgbe, OID_AUTO, rsrv_noflowq, CTLFLAG_RDTUN, &t4_rsrv_noflowq, 313 0, "Reserve TX queue 0 of each VI for non-flowid packets"); 314 315 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 316 #define NOFLDTXQ 8 317 static int t4_nofldtxq = -NOFLDTXQ; 318 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nofldtxq, CTLFLAG_RDTUN, &t4_nofldtxq, 0, 319 "Number of offload TX queues per port"); 320 321 #define NOFLDRXQ 2 322 static int t4_nofldrxq = -NOFLDRXQ; 323 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nofldrxq, CTLFLAG_RDTUN, &t4_nofldrxq, 0, 324 "Number of offload RX queues per port"); 325 326 #define NOFLDTXQ_VI 1 327 static int t4_nofldtxq_vi = -NOFLDTXQ_VI; 328 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nofldtxq_vi, CTLFLAG_RDTUN, &t4_nofldtxq_vi, 0, 329 "Number of offload TX queues per VI"); 330 331 #define NOFLDRXQ_VI 1 332 static int t4_nofldrxq_vi = -NOFLDRXQ_VI; 333 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nofldrxq_vi, CTLFLAG_RDTUN, &t4_nofldrxq_vi, 0, 334 "Number of offload RX queues per VI"); 335 336 #define TMR_IDX_OFLD 1 337 int t4_tmr_idx_ofld = TMR_IDX_OFLD; 338 SYSCTL_INT(_hw_cxgbe, OID_AUTO, holdoff_timer_idx_ofld, CTLFLAG_RDTUN, 339 &t4_tmr_idx_ofld, 0, "Holdoff timer index for offload queues"); 340 341 #define PKTC_IDX_OFLD (-1) 342 int t4_pktc_idx_ofld = PKTC_IDX_OFLD; 343 SYSCTL_INT(_hw_cxgbe, OID_AUTO, holdoff_pktc_idx_ofld, CTLFLAG_RDTUN, 344 &t4_pktc_idx_ofld, 0, "holdoff packet counter index for offload queues"); 345 346 /* 0 means chip/fw default, non-zero number is value in microseconds */ 347 static u_long t4_toe_keepalive_idle = 0; 348 SYSCTL_ULONG(_hw_cxgbe_toe, OID_AUTO, keepalive_idle, CTLFLAG_RDTUN, 349 &t4_toe_keepalive_idle, 0, "TOE keepalive idle timer (us)"); 350 351 /* 0 means chip/fw default, non-zero number is value in microseconds */ 352 static u_long t4_toe_keepalive_interval = 0; 353 SYSCTL_ULONG(_hw_cxgbe_toe, OID_AUTO, keepalive_interval, CTLFLAG_RDTUN, 354 &t4_toe_keepalive_interval, 0, "TOE keepalive interval timer (us)"); 355 356 /* 0 means chip/fw default, non-zero number is # of keepalives before abort */ 357 static int t4_toe_keepalive_count = 0; 358 SYSCTL_INT(_hw_cxgbe_toe, OID_AUTO, keepalive_count, CTLFLAG_RDTUN, 359 &t4_toe_keepalive_count, 0, "Number of TOE keepalive probes before abort"); 360 361 /* 0 means chip/fw default, non-zero number is value in microseconds */ 362 static u_long t4_toe_rexmt_min = 0; 363 SYSCTL_ULONG(_hw_cxgbe_toe, OID_AUTO, rexmt_min, CTLFLAG_RDTUN, 364 &t4_toe_rexmt_min, 0, "Minimum TOE retransmit interval (us)"); 365 366 /* 0 means chip/fw default, non-zero number is value in microseconds */ 367 static u_long t4_toe_rexmt_max = 0; 368 SYSCTL_ULONG(_hw_cxgbe_toe, OID_AUTO, rexmt_max, CTLFLAG_RDTUN, 369 &t4_toe_rexmt_max, 0, "Maximum TOE retransmit interval (us)"); 370 371 /* 0 means chip/fw default, non-zero number is # of rexmt before abort */ 372 static int t4_toe_rexmt_count = 0; 373 SYSCTL_INT(_hw_cxgbe_toe, OID_AUTO, rexmt_count, CTLFLAG_RDTUN, 374 &t4_toe_rexmt_count, 0, "Number of TOE retransmissions before abort"); 375 376 /* -1 means chip/fw default, other values are raw backoff values to use */ 377 static int t4_toe_rexmt_backoff[16] = { 378 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 379 }; 380 SYSCTL_NODE(_hw_cxgbe_toe, OID_AUTO, rexmt_backoff, 381 CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 382 "cxgbe(4) TOE retransmit backoff values"); 383 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 0, CTLFLAG_RDTUN, 384 &t4_toe_rexmt_backoff[0], 0, ""); 385 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 1, CTLFLAG_RDTUN, 386 &t4_toe_rexmt_backoff[1], 0, ""); 387 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 2, CTLFLAG_RDTUN, 388 &t4_toe_rexmt_backoff[2], 0, ""); 389 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 3, CTLFLAG_RDTUN, 390 &t4_toe_rexmt_backoff[3], 0, ""); 391 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 4, CTLFLAG_RDTUN, 392 &t4_toe_rexmt_backoff[4], 0, ""); 393 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 5, CTLFLAG_RDTUN, 394 &t4_toe_rexmt_backoff[5], 0, ""); 395 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 6, CTLFLAG_RDTUN, 396 &t4_toe_rexmt_backoff[6], 0, ""); 397 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 7, CTLFLAG_RDTUN, 398 &t4_toe_rexmt_backoff[7], 0, ""); 399 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 8, CTLFLAG_RDTUN, 400 &t4_toe_rexmt_backoff[8], 0, ""); 401 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 9, CTLFLAG_RDTUN, 402 &t4_toe_rexmt_backoff[9], 0, ""); 403 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 10, CTLFLAG_RDTUN, 404 &t4_toe_rexmt_backoff[10], 0, ""); 405 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 11, CTLFLAG_RDTUN, 406 &t4_toe_rexmt_backoff[11], 0, ""); 407 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 12, CTLFLAG_RDTUN, 408 &t4_toe_rexmt_backoff[12], 0, ""); 409 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 13, CTLFLAG_RDTUN, 410 &t4_toe_rexmt_backoff[13], 0, ""); 411 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 14, CTLFLAG_RDTUN, 412 &t4_toe_rexmt_backoff[14], 0, ""); 413 SYSCTL_INT(_hw_cxgbe_toe_rexmt_backoff, OID_AUTO, 15, CTLFLAG_RDTUN, 414 &t4_toe_rexmt_backoff[15], 0, ""); 415 416 int t4_ddp_rcvbuf_len = 256 * 1024; 417 SYSCTL_INT(_hw_cxgbe_toe, OID_AUTO, ddp_rcvbuf_len, CTLFLAG_RWTUN, 418 &t4_ddp_rcvbuf_len, 0, "length of each DDP RX buffer"); 419 420 unsigned int t4_ddp_rcvbuf_cache = 4; 421 SYSCTL_UINT(_hw_cxgbe_toe, OID_AUTO, ddp_rcvbuf_cache, CTLFLAG_RWTUN, 422 &t4_ddp_rcvbuf_cache, 0, 423 "maximum number of free DDP RX buffers to cache per connection"); 424 #endif 425 426 #ifdef DEV_NETMAP 427 #define NN_MAIN_VI (1 << 0) /* Native netmap on the main VI */ 428 #define NN_EXTRA_VI (1 << 1) /* Native netmap on the extra VI(s) */ 429 static int t4_native_netmap = NN_EXTRA_VI; 430 SYSCTL_INT(_hw_cxgbe, OID_AUTO, native_netmap, CTLFLAG_RDTUN, &t4_native_netmap, 431 0, "Native netmap support. bit 0 = main VI, bit 1 = extra VIs"); 432 433 #define NNMTXQ 8 434 static int t4_nnmtxq = -NNMTXQ; 435 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nnmtxq, CTLFLAG_RDTUN, &t4_nnmtxq, 0, 436 "Number of netmap TX queues"); 437 438 #define NNMRXQ 8 439 static int t4_nnmrxq = -NNMRXQ; 440 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nnmrxq, CTLFLAG_RDTUN, &t4_nnmrxq, 0, 441 "Number of netmap RX queues"); 442 443 #define NNMTXQ_VI 2 444 static int t4_nnmtxq_vi = -NNMTXQ_VI; 445 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nnmtxq_vi, CTLFLAG_RDTUN, &t4_nnmtxq_vi, 0, 446 "Number of netmap TX queues per VI"); 447 448 #define NNMRXQ_VI 2 449 static int t4_nnmrxq_vi = -NNMRXQ_VI; 450 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nnmrxq_vi, CTLFLAG_RDTUN, &t4_nnmrxq_vi, 0, 451 "Number of netmap RX queues per VI"); 452 #endif 453 454 /* 455 * Holdoff parameters for ports. 456 */ 457 #define TMR_IDX 1 458 int t4_tmr_idx = TMR_IDX; 459 SYSCTL_INT(_hw_cxgbe, OID_AUTO, holdoff_timer_idx, CTLFLAG_RDTUN, &t4_tmr_idx, 460 0, "Holdoff timer index"); 461 TUNABLE_INT("hw.cxgbe.holdoff_timer_idx_10G", &t4_tmr_idx); /* Old name */ 462 463 #define PKTC_IDX (-1) 464 int t4_pktc_idx = PKTC_IDX; 465 SYSCTL_INT(_hw_cxgbe, OID_AUTO, holdoff_pktc_idx, CTLFLAG_RDTUN, &t4_pktc_idx, 466 0, "Holdoff packet counter index"); 467 TUNABLE_INT("hw.cxgbe.holdoff_pktc_idx_10G", &t4_pktc_idx); /* Old name */ 468 469 /* 470 * Size (# of entries) of each tx and rx queue. 471 */ 472 unsigned int t4_qsize_txq = TX_EQ_QSIZE; 473 SYSCTL_INT(_hw_cxgbe, OID_AUTO, qsize_txq, CTLFLAG_RDTUN, &t4_qsize_txq, 0, 474 "Number of descriptors in each TX queue"); 475 476 unsigned int t4_qsize_rxq = RX_IQ_QSIZE; 477 SYSCTL_INT(_hw_cxgbe, OID_AUTO, qsize_rxq, CTLFLAG_RDTUN, &t4_qsize_rxq, 0, 478 "Number of descriptors in each RX queue"); 479 480 /* 481 * Interrupt types allowed (bits 0, 1, 2 = INTx, MSI, MSI-X respectively). 482 */ 483 int t4_intr_types = INTR_MSIX | INTR_MSI | INTR_INTX; 484 SYSCTL_INT(_hw_cxgbe, OID_AUTO, interrupt_types, CTLFLAG_RDTUN, &t4_intr_types, 485 0, "Interrupt types allowed (bit 0 = INTx, 1 = MSI, 2 = MSI-X)"); 486 487 /* 488 * Configuration file. All the _CF names here are special. 489 */ 490 #define DEFAULT_CF "default" 491 #define BUILTIN_CF "built-in" 492 #define FLASH_CF "flash" 493 #define UWIRE_CF "uwire" 494 #define FPGA_CF "fpga" 495 static char t4_cfg_file[32] = DEFAULT_CF; 496 SYSCTL_STRING(_hw_cxgbe, OID_AUTO, config_file, CTLFLAG_RDTUN, t4_cfg_file, 497 sizeof(t4_cfg_file), "Firmware configuration file"); 498 499 /* 500 * PAUSE settings (bit 0, 1, 2 = rx_pause, tx_pause, pause_autoneg respectively). 501 * rx_pause = 1 to heed incoming PAUSE frames, 0 to ignore them. 502 * tx_pause = 1 to emit PAUSE frames when the rx FIFO reaches its high water 503 * mark or when signalled to do so, 0 to never emit PAUSE. 504 * pause_autoneg = 1 means PAUSE will be negotiated if possible and the 505 * negotiated settings will override rx_pause/tx_pause. 506 * Otherwise rx_pause/tx_pause are applied forcibly. 507 */ 508 static int t4_pause_settings = PAUSE_RX | PAUSE_TX | PAUSE_AUTONEG; 509 SYSCTL_INT(_hw_cxgbe, OID_AUTO, pause_settings, CTLFLAG_RDTUN, 510 &t4_pause_settings, 0, 511 "PAUSE settings (bit 0 = rx_pause, 1 = tx_pause, 2 = pause_autoneg)"); 512 513 /* 514 * Forward Error Correction settings (bit 0, 1 = RS, BASER respectively). 515 * -1 to run with the firmware default. Same as FEC_AUTO (bit 5) 516 * 0 to disable FEC. 517 */ 518 static int t4_fec = -1; 519 SYSCTL_INT(_hw_cxgbe, OID_AUTO, fec, CTLFLAG_RDTUN, &t4_fec, 0, 520 "Forward Error Correction (bit 0 = RS, bit 1 = BASER_RS)"); 521 522 /* 523 * Controls when the driver sets the FORCE_FEC bit in the L1_CFG32 that it 524 * issues to the firmware. If the firmware doesn't support FORCE_FEC then the 525 * driver runs as if this is set to 0. 526 * -1 to set FORCE_FEC iff requested_fec != AUTO. Multiple FEC bits are okay. 527 * 0 to never set FORCE_FEC. requested_fec = AUTO means use the hint from the 528 * transceiver. Multiple FEC bits may not be okay but will be passed on to 529 * the firmware anyway (may result in l1cfg errors with old firmwares). 530 * 1 to always set FORCE_FEC. Multiple FEC bits are okay. requested_fec = AUTO 531 * means set all FEC bits that are valid for the speed. 532 */ 533 static int t4_force_fec = -1; 534 SYSCTL_INT(_hw_cxgbe, OID_AUTO, force_fec, CTLFLAG_RDTUN, &t4_force_fec, 0, 535 "Controls the use of FORCE_FEC bit in L1 configuration."); 536 537 /* 538 * Link autonegotiation. 539 * -1 to run with the firmware default. 540 * 0 to disable. 541 * 1 to enable. 542 */ 543 static int t4_autoneg = -1; 544 SYSCTL_INT(_hw_cxgbe, OID_AUTO, autoneg, CTLFLAG_RDTUN, &t4_autoneg, 0, 545 "Link autonegotiation"); 546 547 /* 548 * Firmware auto-install by driver during attach (0, 1, 2 = prohibited, allowed, 549 * encouraged respectively). '-n' is the same as 'n' except the firmware 550 * version used in the checks is read from the firmware bundled with the driver. 551 */ 552 static int t4_fw_install = 1; 553 SYSCTL_INT(_hw_cxgbe, OID_AUTO, fw_install, CTLFLAG_RDTUN, &t4_fw_install, 0, 554 "Firmware auto-install (0 = prohibited, 1 = allowed, 2 = encouraged)"); 555 556 /* 557 * ASIC features that will be used. Disable the ones you don't want so that the 558 * chip resources aren't wasted on features that will not be used. 559 */ 560 static int t4_nbmcaps_allowed = 0; 561 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nbmcaps_allowed, CTLFLAG_RDTUN, 562 &t4_nbmcaps_allowed, 0, "Default NBM capabilities"); 563 564 static int t4_linkcaps_allowed = 0; /* No DCBX, PPP, etc. by default */ 565 SYSCTL_INT(_hw_cxgbe, OID_AUTO, linkcaps_allowed, CTLFLAG_RDTUN, 566 &t4_linkcaps_allowed, 0, "Default link capabilities"); 567 568 static int t4_switchcaps_allowed = FW_CAPS_CONFIG_SWITCH_INGRESS | 569 FW_CAPS_CONFIG_SWITCH_EGRESS; 570 SYSCTL_INT(_hw_cxgbe, OID_AUTO, switchcaps_allowed, CTLFLAG_RDTUN, 571 &t4_switchcaps_allowed, 0, "Default switch capabilities"); 572 573 #ifdef RATELIMIT 574 static int t4_niccaps_allowed = FW_CAPS_CONFIG_NIC | 575 FW_CAPS_CONFIG_NIC_HASHFILTER | FW_CAPS_CONFIG_NIC_ETHOFLD; 576 #else 577 static int t4_niccaps_allowed = FW_CAPS_CONFIG_NIC | 578 FW_CAPS_CONFIG_NIC_HASHFILTER; 579 #endif 580 SYSCTL_INT(_hw_cxgbe, OID_AUTO, niccaps_allowed, CTLFLAG_RDTUN, 581 &t4_niccaps_allowed, 0, "Default NIC capabilities"); 582 583 static int t4_toecaps_allowed = -1; 584 SYSCTL_INT(_hw_cxgbe, OID_AUTO, toecaps_allowed, CTLFLAG_RDTUN, 585 &t4_toecaps_allowed, 0, "Default TCP offload capabilities"); 586 587 static int t4_rdmacaps_allowed = -1; 588 SYSCTL_INT(_hw_cxgbe, OID_AUTO, rdmacaps_allowed, CTLFLAG_RDTUN, 589 &t4_rdmacaps_allowed, 0, "Default RDMA capabilities"); 590 591 static int t4_cryptocaps_allowed = -1; 592 SYSCTL_INT(_hw_cxgbe, OID_AUTO, cryptocaps_allowed, CTLFLAG_RDTUN, 593 &t4_cryptocaps_allowed, 0, "Default crypto capabilities"); 594 595 static int t4_iscsicaps_allowed = -1; 596 SYSCTL_INT(_hw_cxgbe, OID_AUTO, iscsicaps_allowed, CTLFLAG_RDTUN, 597 &t4_iscsicaps_allowed, 0, "Default iSCSI capabilities"); 598 599 static int t4_fcoecaps_allowed = 0; 600 SYSCTL_INT(_hw_cxgbe, OID_AUTO, fcoecaps_allowed, CTLFLAG_RDTUN, 601 &t4_fcoecaps_allowed, 0, "Default FCoE capabilities"); 602 603 static int t5_write_combine = 0; 604 SYSCTL_INT(_hw_cxl, OID_AUTO, write_combine, CTLFLAG_RDTUN, &t5_write_combine, 605 0, "Use WC instead of UC for BAR2"); 606 607 /* From t4_sysctls: doorbells = {"\20\1UDB\2WCWR\3UDBWC\4KDB"} */ 608 static int t4_doorbells_allowed = 0xf; 609 SYSCTL_INT(_hw_cxgbe, OID_AUTO, doorbells_allowed, CTLFLAG_RDTUN, 610 &t4_doorbells_allowed, 0, "Limit tx queues to these doorbells"); 611 612 static int t4_num_vis = 1; 613 SYSCTL_INT(_hw_cxgbe, OID_AUTO, num_vis, CTLFLAG_RDTUN, &t4_num_vis, 0, 614 "Number of VIs per port"); 615 616 /* 617 * PCIe Relaxed Ordering. 618 * -1: driver should figure out a good value. 619 * 0: disable RO. 620 * 1: enable RO. 621 * 2: leave RO alone. 622 */ 623 static int pcie_relaxed_ordering = -1; 624 SYSCTL_INT(_hw_cxgbe, OID_AUTO, pcie_relaxed_ordering, CTLFLAG_RDTUN, 625 &pcie_relaxed_ordering, 0, 626 "PCIe Relaxed Ordering: 0 = disable, 1 = enable, 2 = leave alone"); 627 628 static int t4_panic_on_fatal_err = 0; 629 SYSCTL_INT(_hw_cxgbe, OID_AUTO, panic_on_fatal_err, CTLFLAG_RWTUN, 630 &t4_panic_on_fatal_err, 0, "panic on fatal errors"); 631 632 static int t4_reset_on_fatal_err = 0; 633 SYSCTL_INT(_hw_cxgbe, OID_AUTO, reset_on_fatal_err, CTLFLAG_RWTUN, 634 &t4_reset_on_fatal_err, 0, "reset adapter on fatal errors"); 635 636 static int t4_clock_gate_on_suspend = 0; 637 SYSCTL_INT(_hw_cxgbe, OID_AUTO, clock_gate_on_suspend, CTLFLAG_RWTUN, 638 &t4_clock_gate_on_suspend, 0, "gate the clock on suspend"); 639 640 static int t4_tx_vm_wr = 0; 641 SYSCTL_INT(_hw_cxgbe, OID_AUTO, tx_vm_wr, CTLFLAG_RWTUN, &t4_tx_vm_wr, 0, 642 "Use VM work requests to transmit packets."); 643 644 /* 645 * Set to non-zero to enable the attack filter. A packet that matches any of 646 * these conditions will get dropped on ingress: 647 * 1) IP && source address == destination address. 648 * 2) TCP/IP && source address is not a unicast address. 649 * 3) TCP/IP && destination address is not a unicast address. 650 * 4) IP && source address is loopback (127.x.y.z). 651 * 5) IP && destination address is loopback (127.x.y.z). 652 * 6) IPv6 && source address == destination address. 653 * 7) IPv6 && source address is not a unicast address. 654 * 8) IPv6 && source address is loopback (::1/128). 655 * 9) IPv6 && destination address is loopback (::1/128). 656 * 10) IPv6 && source address is unspecified (::/128). 657 * 11) IPv6 && destination address is unspecified (::/128). 658 * 12) TCP/IPv6 && source address is multicast (ff00::/8). 659 * 13) TCP/IPv6 && destination address is multicast (ff00::/8). 660 */ 661 static int t4_attack_filter = 0; 662 SYSCTL_INT(_hw_cxgbe, OID_AUTO, attack_filter, CTLFLAG_RDTUN, 663 &t4_attack_filter, 0, "Drop suspicious traffic"); 664 665 static int t4_drop_ip_fragments = 0; 666 SYSCTL_INT(_hw_cxgbe, OID_AUTO, drop_ip_fragments, CTLFLAG_RDTUN, 667 &t4_drop_ip_fragments, 0, "Drop IP fragments"); 668 669 static int t4_drop_pkts_with_l2_errors = 1; 670 SYSCTL_INT(_hw_cxgbe, OID_AUTO, drop_pkts_with_l2_errors, CTLFLAG_RDTUN, 671 &t4_drop_pkts_with_l2_errors, 0, 672 "Drop all frames with Layer 2 length or checksum errors"); 673 674 static int t4_drop_pkts_with_l3_errors = 0; 675 SYSCTL_INT(_hw_cxgbe, OID_AUTO, drop_pkts_with_l3_errors, CTLFLAG_RDTUN, 676 &t4_drop_pkts_with_l3_errors, 0, 677 "Drop all frames with IP version, length, or checksum errors"); 678 679 static int t4_drop_pkts_with_l4_errors = 0; 680 SYSCTL_INT(_hw_cxgbe, OID_AUTO, drop_pkts_with_l4_errors, CTLFLAG_RDTUN, 681 &t4_drop_pkts_with_l4_errors, 0, 682 "Drop all frames with Layer 4 length, checksum, or other errors"); 683 684 #ifdef TCP_OFFLOAD 685 /* 686 * TOE tunables. 687 */ 688 static int t4_cop_managed_offloading = 0; 689 SYSCTL_INT(_hw_cxgbe, OID_AUTO, cop_managed_offloading, CTLFLAG_RDTUN, 690 &t4_cop_managed_offloading, 0, 691 "COP (Connection Offload Policy) controls all TOE offload"); 692 #endif 693 694 #ifdef KERN_TLS 695 /* 696 * This enables KERN_TLS for all adapters if set. 697 */ 698 static int t4_kern_tls = 0; 699 SYSCTL_INT(_hw_cxgbe, OID_AUTO, kern_tls, CTLFLAG_RDTUN, &t4_kern_tls, 0, 700 "Enable KERN_TLS mode for T6 adapters"); 701 702 SYSCTL_NODE(_hw_cxgbe, OID_AUTO, tls, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 703 "cxgbe(4) KERN_TLS parameters"); 704 705 static int t4_tls_inline_keys = 0; 706 SYSCTL_INT(_hw_cxgbe_tls, OID_AUTO, inline_keys, CTLFLAG_RDTUN, 707 &t4_tls_inline_keys, 0, 708 "Always pass TLS keys in work requests (1) or attempt to store TLS keys " 709 "in card memory."); 710 711 static int t4_tls_combo_wrs = 0; 712 SYSCTL_INT(_hw_cxgbe_tls, OID_AUTO, combo_wrs, CTLFLAG_RDTUN, &t4_tls_combo_wrs, 713 0, "Attempt to combine TCB field updates with TLS record work requests."); 714 #endif 715 716 /* Functions used by VIs to obtain unique MAC addresses for each VI. */ 717 static int vi_mac_funcs[] = { 718 FW_VI_FUNC_ETH, 719 FW_VI_FUNC_OFLD, 720 FW_VI_FUNC_IWARP, 721 FW_VI_FUNC_OPENISCSI, 722 FW_VI_FUNC_OPENFCOE, 723 FW_VI_FUNC_FOISCSI, 724 FW_VI_FUNC_FOFCOE, 725 }; 726 727 struct intrs_and_queues { 728 uint16_t intr_type; /* INTx, MSI, or MSI-X */ 729 uint16_t num_vis; /* number of VIs for each port */ 730 uint16_t nirq; /* Total # of vectors */ 731 uint16_t ntxq; /* # of NIC txq's for each port */ 732 uint16_t nrxq; /* # of NIC rxq's for each port */ 733 uint16_t nofldtxq; /* # of TOE/ETHOFLD txq's for each port */ 734 uint16_t nofldrxq; /* # of TOE rxq's for each port */ 735 uint16_t nnmtxq; /* # of netmap txq's */ 736 uint16_t nnmrxq; /* # of netmap rxq's */ 737 738 /* The vcxgbe/vcxl interfaces use these and not the ones above. */ 739 uint16_t ntxq_vi; /* # of NIC txq's */ 740 uint16_t nrxq_vi; /* # of NIC rxq's */ 741 uint16_t nofldtxq_vi; /* # of TOE txq's */ 742 uint16_t nofldrxq_vi; /* # of TOE rxq's */ 743 uint16_t nnmtxq_vi; /* # of netmap txq's */ 744 uint16_t nnmrxq_vi; /* # of netmap rxq's */ 745 }; 746 747 static void setup_memwin(struct adapter *); 748 static void position_memwin(struct adapter *, int, uint32_t); 749 static int validate_mem_range(struct adapter *, uint32_t, uint32_t); 750 static int fwmtype_to_hwmtype(int); 751 static int validate_mt_off_len(struct adapter *, int, uint32_t, uint32_t, 752 uint32_t *); 753 static int fixup_devlog_params(struct adapter *); 754 static int cfg_itype_and_nqueues(struct adapter *, struct intrs_and_queues *); 755 static int contact_firmware(struct adapter *); 756 static int partition_resources(struct adapter *); 757 static int get_params__pre_init(struct adapter *); 758 static int set_params__pre_init(struct adapter *); 759 static int get_params__post_init(struct adapter *); 760 static int set_params__post_init(struct adapter *); 761 static void t4_set_desc(struct adapter *); 762 static bool fixed_ifmedia(struct port_info *); 763 static void build_medialist(struct port_info *); 764 static void init_link_config(struct port_info *); 765 static int fixup_link_config(struct port_info *); 766 static int apply_link_config(struct port_info *); 767 static int cxgbe_init_synchronized(struct vi_info *); 768 static int cxgbe_uninit_synchronized(struct vi_info *); 769 static int adapter_full_init(struct adapter *); 770 static void adapter_full_uninit(struct adapter *); 771 static int vi_full_init(struct vi_info *); 772 static void vi_full_uninit(struct vi_info *); 773 static int alloc_extra_vi(struct adapter *, struct port_info *, struct vi_info *); 774 static void quiesce_txq(struct sge_txq *); 775 static void quiesce_wrq(struct sge_wrq *); 776 static void quiesce_iq_fl(struct adapter *, struct sge_iq *, struct sge_fl *); 777 static void quiesce_vi(struct vi_info *); 778 static int t4_alloc_irq(struct adapter *, struct irq *, int rid, 779 driver_intr_t *, void *, char *); 780 static int t4_free_irq(struct adapter *, struct irq *); 781 static void t4_init_atid_table(struct adapter *); 782 static void t4_free_atid_table(struct adapter *); 783 static void get_regs(struct adapter *, struct t4_regdump *, uint8_t *); 784 static void vi_refresh_stats(struct vi_info *); 785 static void cxgbe_refresh_stats(struct vi_info *); 786 static void cxgbe_tick(void *); 787 static void vi_tick(void *); 788 static void cxgbe_sysctls(struct port_info *); 789 static int sysctl_int_array(SYSCTL_HANDLER_ARGS); 790 static int sysctl_bitfield_8b(SYSCTL_HANDLER_ARGS); 791 static int sysctl_bitfield_16b(SYSCTL_HANDLER_ARGS); 792 static int sysctl_btphy(SYSCTL_HANDLER_ARGS); 793 static int sysctl_noflowq(SYSCTL_HANDLER_ARGS); 794 static int sysctl_tx_vm_wr(SYSCTL_HANDLER_ARGS); 795 static int sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS); 796 static int sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS); 797 static int sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS); 798 static int sysctl_qsize_txq(SYSCTL_HANDLER_ARGS); 799 static int sysctl_pause_settings(SYSCTL_HANDLER_ARGS); 800 static int sysctl_link_fec(SYSCTL_HANDLER_ARGS); 801 static int sysctl_requested_fec(SYSCTL_HANDLER_ARGS); 802 static int sysctl_module_fec(SYSCTL_HANDLER_ARGS); 803 static int sysctl_autoneg(SYSCTL_HANDLER_ARGS); 804 static int sysctl_force_fec(SYSCTL_HANDLER_ARGS); 805 static int sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS); 806 static int sysctl_temperature(SYSCTL_HANDLER_ARGS); 807 static int sysctl_vdd(SYSCTL_HANDLER_ARGS); 808 static int sysctl_reset_sensor(SYSCTL_HANDLER_ARGS); 809 static int sysctl_loadavg(SYSCTL_HANDLER_ARGS); 810 static int sysctl_cctrl(SYSCTL_HANDLER_ARGS); 811 static int sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS); 812 static int sysctl_cim_la(SYSCTL_HANDLER_ARGS); 813 static int sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS); 814 static int sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS); 815 static int sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS); 816 static int sysctl_cpl_stats(SYSCTL_HANDLER_ARGS); 817 static int sysctl_ddp_stats(SYSCTL_HANDLER_ARGS); 818 static int sysctl_tid_stats(SYSCTL_HANDLER_ARGS); 819 static int sysctl_devlog(SYSCTL_HANDLER_ARGS); 820 static int sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS); 821 static int sysctl_hw_sched(SYSCTL_HANDLER_ARGS); 822 static int sysctl_lb_stats(SYSCTL_HANDLER_ARGS); 823 static int sysctl_linkdnrc(SYSCTL_HANDLER_ARGS); 824 static int sysctl_meminfo(SYSCTL_HANDLER_ARGS); 825 static int sysctl_mps_tcam(SYSCTL_HANDLER_ARGS); 826 static int sysctl_mps_tcam_t6(SYSCTL_HANDLER_ARGS); 827 static int sysctl_path_mtus(SYSCTL_HANDLER_ARGS); 828 static int sysctl_pm_stats(SYSCTL_HANDLER_ARGS); 829 static int sysctl_rdma_stats(SYSCTL_HANDLER_ARGS); 830 static int sysctl_tcp_stats(SYSCTL_HANDLER_ARGS); 831 static int sysctl_tids(SYSCTL_HANDLER_ARGS); 832 static int sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS); 833 static int sysctl_tnl_stats(SYSCTL_HANDLER_ARGS); 834 static int sysctl_tp_la_mask(SYSCTL_HANDLER_ARGS); 835 static int sysctl_tp_la(SYSCTL_HANDLER_ARGS); 836 static int sysctl_tx_rate(SYSCTL_HANDLER_ARGS); 837 static int sysctl_ulprx_la(SYSCTL_HANDLER_ARGS); 838 static int sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS); 839 static int sysctl_cpus(SYSCTL_HANDLER_ARGS); 840 static int sysctl_reset(SYSCTL_HANDLER_ARGS); 841 #ifdef TCP_OFFLOAD 842 static int sysctl_tls(SYSCTL_HANDLER_ARGS); 843 static int sysctl_tp_tick(SYSCTL_HANDLER_ARGS); 844 static int sysctl_tp_dack_timer(SYSCTL_HANDLER_ARGS); 845 static int sysctl_tp_timer(SYSCTL_HANDLER_ARGS); 846 static int sysctl_tp_shift_cnt(SYSCTL_HANDLER_ARGS); 847 static int sysctl_tp_backoff(SYSCTL_HANDLER_ARGS); 848 static int sysctl_holdoff_tmr_idx_ofld(SYSCTL_HANDLER_ARGS); 849 static int sysctl_holdoff_pktc_idx_ofld(SYSCTL_HANDLER_ARGS); 850 #endif 851 static int get_sge_context(struct adapter *, struct t4_sge_context *); 852 static int load_fw(struct adapter *, struct t4_data *); 853 static int load_cfg(struct adapter *, struct t4_data *); 854 static int load_boot(struct adapter *, struct t4_bootrom *); 855 static int load_bootcfg(struct adapter *, struct t4_data *); 856 static int cudbg_dump(struct adapter *, struct t4_cudbg_dump *); 857 static void free_offload_policy(struct t4_offload_policy *); 858 static int set_offload_policy(struct adapter *, struct t4_offload_policy *); 859 static int read_card_mem(struct adapter *, int, struct t4_mem_range *); 860 static int read_i2c(struct adapter *, struct t4_i2c_data *); 861 static int clear_stats(struct adapter *, u_int); 862 static int hold_clip_addr(struct adapter *, struct t4_clip_addr *); 863 static int release_clip_addr(struct adapter *, struct t4_clip_addr *); 864 #ifdef TCP_OFFLOAD 865 static int toe_capability(struct vi_info *, bool); 866 static int t4_deactivate_all_uld(struct adapter *); 867 static void t4_async_event(struct adapter *); 868 #endif 869 #ifdef KERN_TLS 870 static int ktls_capability(struct adapter *, bool); 871 #endif 872 static int mod_event(module_t, int, void *); 873 static int notify_siblings(device_t, int); 874 static uint64_t vi_get_counter(if_t, ift_counter); 875 static uint64_t cxgbe_get_counter(if_t, ift_counter); 876 static void enable_vxlan_rx(struct adapter *); 877 static void reset_adapter_task(void *, int); 878 static void fatal_error_task(void *, int); 879 static void dump_devlog(struct adapter *); 880 static void dump_cim_regs(struct adapter *); 881 static void dump_cimla(struct adapter *); 882 883 struct { 884 uint16_t device; 885 char *desc; 886 } t4_pciids[] = { 887 {0xa000, "Chelsio Terminator 4 FPGA"}, 888 {0x4400, "Chelsio T440-dbg"}, 889 {0x4401, "Chelsio T420-CR"}, 890 {0x4402, "Chelsio T422-CR"}, 891 {0x4403, "Chelsio T440-CR"}, 892 {0x4404, "Chelsio T420-BCH"}, 893 {0x4405, "Chelsio T440-BCH"}, 894 {0x4406, "Chelsio T440-CH"}, 895 {0x4407, "Chelsio T420-SO"}, 896 {0x4408, "Chelsio T420-CX"}, 897 {0x4409, "Chelsio T420-BT"}, 898 {0x440a, "Chelsio T404-BT"}, 899 {0x440e, "Chelsio T440-LP-CR"}, 900 }, t5_pciids[] = { 901 {0xb000, "Chelsio Terminator 5 FPGA"}, 902 {0x5400, "Chelsio T580-dbg"}, 903 {0x5401, "Chelsio T520-CR"}, /* 2 x 10G */ 904 {0x5402, "Chelsio T522-CR"}, /* 2 x 10G, 2 X 1G */ 905 {0x5403, "Chelsio T540-CR"}, /* 4 x 10G */ 906 {0x5407, "Chelsio T520-SO"}, /* 2 x 10G, nomem */ 907 {0x5409, "Chelsio T520-BT"}, /* 2 x 10GBaseT */ 908 {0x540a, "Chelsio T504-BT"}, /* 4 x 1G */ 909 {0x540d, "Chelsio T580-CR"}, /* 2 x 40G */ 910 {0x540e, "Chelsio T540-LP-CR"}, /* 4 x 10G */ 911 {0x5410, "Chelsio T580-LP-CR"}, /* 2 x 40G */ 912 {0x5411, "Chelsio T520-LL-CR"}, /* 2 x 10G */ 913 {0x5412, "Chelsio T560-CR"}, /* 1 x 40G, 2 x 10G */ 914 {0x5414, "Chelsio T580-LP-SO-CR"}, /* 2 x 40G, nomem */ 915 {0x5415, "Chelsio T502-BT"}, /* 2 x 1G */ 916 {0x5418, "Chelsio T540-BT"}, /* 4 x 10GBaseT */ 917 {0x5419, "Chelsio T540-LP-BT"}, /* 4 x 10GBaseT */ 918 {0x541a, "Chelsio T540-SO-BT"}, /* 4 x 10GBaseT, nomem */ 919 {0x541b, "Chelsio T540-SO-CR"}, /* 4 x 10G, nomem */ 920 921 /* Custom */ 922 {0x5483, "Custom T540-CR"}, 923 {0x5484, "Custom T540-BT"}, 924 }, t6_pciids[] = { 925 {0xc006, "Chelsio Terminator 6 FPGA"}, /* T6 PE10K6 FPGA (PF0) */ 926 {0x6400, "Chelsio T6-DBG-25"}, /* 2 x 10/25G, debug */ 927 {0x6401, "Chelsio T6225-CR"}, /* 2 x 10/25G */ 928 {0x6402, "Chelsio T6225-SO-CR"}, /* 2 x 10/25G, nomem */ 929 {0x6403, "Chelsio T6425-CR"}, /* 4 x 10/25G */ 930 {0x6404, "Chelsio T6425-SO-CR"}, /* 4 x 10/25G, nomem */ 931 {0x6405, "Chelsio T6225-OCP-SO"}, /* 2 x 10/25G, nomem */ 932 {0x6406, "Chelsio T62100-OCP-SO"}, /* 2 x 40/50/100G, nomem */ 933 {0x6407, "Chelsio T62100-LP-CR"}, /* 2 x 40/50/100G */ 934 {0x6408, "Chelsio T62100-SO-CR"}, /* 2 x 40/50/100G, nomem */ 935 {0x6409, "Chelsio T6210-BT"}, /* 2 x 10GBASE-T */ 936 {0x640d, "Chelsio T62100-CR"}, /* 2 x 40/50/100G */ 937 {0x6410, "Chelsio T6-DBG-100"}, /* 2 x 40/50/100G, debug */ 938 {0x6411, "Chelsio T6225-LL-CR"}, /* 2 x 10/25G */ 939 {0x6414, "Chelsio T61100-OCP-SO"}, /* 1 x 40/50/100G, nomem */ 940 {0x6415, "Chelsio T6201-BT"}, /* 2 x 1000BASE-T */ 941 942 /* Custom */ 943 {0x6480, "Custom T6225-CR"}, 944 {0x6481, "Custom T62100-CR"}, 945 {0x6482, "Custom T6225-CR"}, 946 {0x6483, "Custom T62100-CR"}, 947 {0x6484, "Custom T64100-CR"}, 948 {0x6485, "Custom T6240-SO"}, 949 {0x6486, "Custom T6225-SO-CR"}, 950 {0x6487, "Custom T6225-CR"}, 951 }; 952 953 #ifdef TCP_OFFLOAD 954 /* 955 * service_iq_fl() has an iq and needs the fl. Offset of fl from the iq should 956 * be exactly the same for both rxq and ofld_rxq. 957 */ 958 CTASSERT(offsetof(struct sge_ofld_rxq, iq) == offsetof(struct sge_rxq, iq)); 959 CTASSERT(offsetof(struct sge_ofld_rxq, fl) == offsetof(struct sge_rxq, fl)); 960 #endif 961 CTASSERT(sizeof(struct cluster_metadata) <= CL_METADATA_SIZE); 962 963 static int 964 t4_probe(device_t dev) 965 { 966 int i; 967 uint16_t v = pci_get_vendor(dev); 968 uint16_t d = pci_get_device(dev); 969 uint8_t f = pci_get_function(dev); 970 971 if (v != PCI_VENDOR_ID_CHELSIO) 972 return (ENXIO); 973 974 /* Attach only to PF0 of the FPGA */ 975 if (d == 0xa000 && f != 0) 976 return (ENXIO); 977 978 for (i = 0; i < nitems(t4_pciids); i++) { 979 if (d == t4_pciids[i].device) { 980 device_set_desc(dev, t4_pciids[i].desc); 981 return (BUS_PROBE_DEFAULT); 982 } 983 } 984 985 return (ENXIO); 986 } 987 988 static int 989 t5_probe(device_t dev) 990 { 991 int i; 992 uint16_t v = pci_get_vendor(dev); 993 uint16_t d = pci_get_device(dev); 994 uint8_t f = pci_get_function(dev); 995 996 if (v != PCI_VENDOR_ID_CHELSIO) 997 return (ENXIO); 998 999 /* Attach only to PF0 of the FPGA */ 1000 if (d == 0xb000 && f != 0) 1001 return (ENXIO); 1002 1003 for (i = 0; i < nitems(t5_pciids); i++) { 1004 if (d == t5_pciids[i].device) { 1005 device_set_desc(dev, t5_pciids[i].desc); 1006 return (BUS_PROBE_DEFAULT); 1007 } 1008 } 1009 1010 return (ENXIO); 1011 } 1012 1013 static int 1014 t6_probe(device_t dev) 1015 { 1016 int i; 1017 uint16_t v = pci_get_vendor(dev); 1018 uint16_t d = pci_get_device(dev); 1019 1020 if (v != PCI_VENDOR_ID_CHELSIO) 1021 return (ENXIO); 1022 1023 for (i = 0; i < nitems(t6_pciids); i++) { 1024 if (d == t6_pciids[i].device) { 1025 device_set_desc(dev, t6_pciids[i].desc); 1026 return (BUS_PROBE_DEFAULT); 1027 } 1028 } 1029 1030 return (ENXIO); 1031 } 1032 1033 static void 1034 t5_attribute_workaround(device_t dev) 1035 { 1036 device_t root_port; 1037 uint32_t v; 1038 1039 /* 1040 * The T5 chips do not properly echo the No Snoop and Relaxed 1041 * Ordering attributes when replying to a TLP from a Root 1042 * Port. As a workaround, find the parent Root Port and 1043 * disable No Snoop and Relaxed Ordering. Note that this 1044 * affects all devices under this root port. 1045 */ 1046 root_port = pci_find_pcie_root_port(dev); 1047 if (root_port == NULL) { 1048 device_printf(dev, "Unable to find parent root port\n"); 1049 return; 1050 } 1051 1052 v = pcie_adjust_config(root_port, PCIER_DEVICE_CTL, 1053 PCIEM_CTL_RELAXED_ORD_ENABLE | PCIEM_CTL_NOSNOOP_ENABLE, 0, 2); 1054 if ((v & (PCIEM_CTL_RELAXED_ORD_ENABLE | PCIEM_CTL_NOSNOOP_ENABLE)) != 1055 0) 1056 device_printf(dev, "Disabled No Snoop/Relaxed Ordering on %s\n", 1057 device_get_nameunit(root_port)); 1058 } 1059 1060 static const struct devnames devnames[] = { 1061 { 1062 .nexus_name = "t4nex", 1063 .ifnet_name = "cxgbe", 1064 .vi_ifnet_name = "vcxgbe", 1065 .pf03_drv_name = "t4iov", 1066 .vf_nexus_name = "t4vf", 1067 .vf_ifnet_name = "cxgbev" 1068 }, { 1069 .nexus_name = "t5nex", 1070 .ifnet_name = "cxl", 1071 .vi_ifnet_name = "vcxl", 1072 .pf03_drv_name = "t5iov", 1073 .vf_nexus_name = "t5vf", 1074 .vf_ifnet_name = "cxlv" 1075 }, { 1076 .nexus_name = "t6nex", 1077 .ifnet_name = "cc", 1078 .vi_ifnet_name = "vcc", 1079 .pf03_drv_name = "t6iov", 1080 .vf_nexus_name = "t6vf", 1081 .vf_ifnet_name = "ccv" 1082 } 1083 }; 1084 1085 void 1086 t4_init_devnames(struct adapter *sc) 1087 { 1088 int id; 1089 1090 id = chip_id(sc); 1091 if (id >= CHELSIO_T4 && id - CHELSIO_T4 < nitems(devnames)) 1092 sc->names = &devnames[id - CHELSIO_T4]; 1093 else { 1094 device_printf(sc->dev, "chip id %d is not supported.\n", id); 1095 sc->names = NULL; 1096 } 1097 } 1098 1099 static int 1100 t4_ifnet_unit(struct adapter *sc, struct port_info *pi) 1101 { 1102 const char *parent, *name; 1103 long value; 1104 int line, unit; 1105 1106 line = 0; 1107 parent = device_get_nameunit(sc->dev); 1108 name = sc->names->ifnet_name; 1109 while (resource_find_dev(&line, name, &unit, "at", parent) == 0) { 1110 if (resource_long_value(name, unit, "port", &value) == 0 && 1111 value == pi->port_id) 1112 return (unit); 1113 } 1114 return (-1); 1115 } 1116 1117 static void 1118 t4_calibration(void *arg) 1119 { 1120 struct adapter *sc; 1121 struct clock_sync *cur, *nex; 1122 uint64_t hw; 1123 sbintime_t sbt; 1124 int next_up; 1125 1126 sc = (struct adapter *)arg; 1127 1128 KASSERT((hw_off_limits(sc) == 0), ("hw_off_limits at t4_calibration")); 1129 hw = t4_read_reg64(sc, A_SGE_TIMESTAMP_LO); 1130 sbt = sbinuptime(); 1131 1132 cur = &sc->cal_info[sc->cal_current]; 1133 next_up = (sc->cal_current + 1) % CNT_CAL_INFO; 1134 nex = &sc->cal_info[next_up]; 1135 if (__predict_false(sc->cal_count == 0)) { 1136 /* First time in, just get the values in */ 1137 cur->hw_cur = hw; 1138 cur->sbt_cur = sbt; 1139 sc->cal_count++; 1140 goto done; 1141 } 1142 1143 if (cur->hw_cur == hw) { 1144 /* The clock is not advancing? */ 1145 sc->cal_count = 0; 1146 atomic_store_rel_int(&cur->gen, 0); 1147 goto done; 1148 } 1149 1150 seqc_write_begin(&nex->gen); 1151 nex->hw_prev = cur->hw_cur; 1152 nex->sbt_prev = cur->sbt_cur; 1153 nex->hw_cur = hw; 1154 nex->sbt_cur = sbt; 1155 seqc_write_end(&nex->gen); 1156 sc->cal_current = next_up; 1157 done: 1158 callout_reset_sbt_curcpu(&sc->cal_callout, SBT_1S, 0, t4_calibration, 1159 sc, C_DIRECT_EXEC); 1160 } 1161 1162 static void 1163 t4_calibration_start(struct adapter *sc) 1164 { 1165 /* 1166 * Here if we have not done a calibration 1167 * then do so otherwise start the appropriate 1168 * timer. 1169 */ 1170 int i; 1171 1172 for (i = 0; i < CNT_CAL_INFO; i++) { 1173 sc->cal_info[i].gen = 0; 1174 } 1175 sc->cal_current = 0; 1176 sc->cal_count = 0; 1177 sc->cal_gen = 0; 1178 t4_calibration(sc); 1179 } 1180 1181 static int 1182 t4_attach(device_t dev) 1183 { 1184 struct adapter *sc; 1185 int rc = 0, i, j, rqidx, tqidx, nports; 1186 struct make_dev_args mda; 1187 struct intrs_and_queues iaq; 1188 struct sge *s; 1189 uint32_t *buf; 1190 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 1191 int ofld_tqidx; 1192 #endif 1193 #ifdef TCP_OFFLOAD 1194 int ofld_rqidx; 1195 #endif 1196 #ifdef DEV_NETMAP 1197 int nm_rqidx, nm_tqidx; 1198 #endif 1199 int num_vis; 1200 1201 sc = device_get_softc(dev); 1202 sc->dev = dev; 1203 sysctl_ctx_init(&sc->ctx); 1204 TUNABLE_INT_FETCH("hw.cxgbe.dflags", &sc->debug_flags); 1205 1206 if ((pci_get_device(dev) & 0xff00) == 0x5400) 1207 t5_attribute_workaround(dev); 1208 pci_enable_busmaster(dev); 1209 if (pci_find_cap(dev, PCIY_EXPRESS, &i) == 0) { 1210 uint32_t v; 1211 1212 pci_set_max_read_req(dev, 4096); 1213 v = pci_read_config(dev, i + PCIER_DEVICE_CTL, 2); 1214 sc->params.pci.mps = 128 << ((v & PCIEM_CTL_MAX_PAYLOAD) >> 5); 1215 if (pcie_relaxed_ordering == 0 && 1216 (v & PCIEM_CTL_RELAXED_ORD_ENABLE) != 0) { 1217 v &= ~PCIEM_CTL_RELAXED_ORD_ENABLE; 1218 pci_write_config(dev, i + PCIER_DEVICE_CTL, v, 2); 1219 } else if (pcie_relaxed_ordering == 1 && 1220 (v & PCIEM_CTL_RELAXED_ORD_ENABLE) == 0) { 1221 v |= PCIEM_CTL_RELAXED_ORD_ENABLE; 1222 pci_write_config(dev, i + PCIER_DEVICE_CTL, v, 2); 1223 } 1224 } 1225 1226 sc->sge_gts_reg = MYPF_REG(A_SGE_PF_GTS); 1227 sc->sge_kdoorbell_reg = MYPF_REG(A_SGE_PF_KDOORBELL); 1228 sc->traceq = -1; 1229 mtx_init(&sc->ifp_lock, sc->ifp_lockname, 0, MTX_DEF); 1230 snprintf(sc->ifp_lockname, sizeof(sc->ifp_lockname), "%s tracer", 1231 device_get_nameunit(dev)); 1232 1233 snprintf(sc->lockname, sizeof(sc->lockname), "%s", 1234 device_get_nameunit(dev)); 1235 mtx_init(&sc->sc_lock, sc->lockname, 0, MTX_DEF); 1236 t4_add_adapter(sc); 1237 1238 mtx_init(&sc->sfl_lock, "starving freelists", 0, MTX_DEF); 1239 TAILQ_INIT(&sc->sfl); 1240 callout_init_mtx(&sc->sfl_callout, &sc->sfl_lock, 0); 1241 1242 mtx_init(&sc->reg_lock, "indirect register access", 0, MTX_DEF); 1243 1244 sc->policy = NULL; 1245 rw_init(&sc->policy_lock, "connection offload policy"); 1246 1247 callout_init(&sc->ktls_tick, 1); 1248 1249 callout_init(&sc->cal_callout, 1); 1250 1251 refcount_init(&sc->vxlan_refcount, 0); 1252 1253 TASK_INIT(&sc->reset_task, 0, reset_adapter_task, sc); 1254 TASK_INIT(&sc->fatal_error_task, 0, fatal_error_task, sc); 1255 1256 sc->ctrlq_oid = SYSCTL_ADD_NODE(&sc->ctx, 1257 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), OID_AUTO, "ctrlq", 1258 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "control queues"); 1259 sc->fwq_oid = SYSCTL_ADD_NODE(&sc->ctx, 1260 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), OID_AUTO, "fwq", 1261 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "firmware event queue"); 1262 1263 rc = t4_map_bars_0_and_4(sc); 1264 if (rc != 0) 1265 goto done; /* error message displayed already */ 1266 1267 memset(sc->chan_map, 0xff, sizeof(sc->chan_map)); 1268 1269 /* Prepare the adapter for operation. */ 1270 buf = malloc(PAGE_SIZE, M_CXGBE, M_ZERO | M_WAITOK); 1271 rc = -t4_prep_adapter(sc, buf); 1272 free(buf, M_CXGBE); 1273 if (rc != 0) { 1274 device_printf(dev, "failed to prepare adapter: %d.\n", rc); 1275 goto done; 1276 } 1277 1278 /* 1279 * This is the real PF# to which we're attaching. Works from within PCI 1280 * passthrough environments too, where pci_get_function() could return a 1281 * different PF# depending on the passthrough configuration. We need to 1282 * use the real PF# in all our communication with the firmware. 1283 */ 1284 j = t4_read_reg(sc, A_PL_WHOAMI); 1285 sc->pf = chip_id(sc) <= CHELSIO_T5 ? G_SOURCEPF(j) : G_T6_SOURCEPF(j); 1286 sc->mbox = sc->pf; 1287 1288 t4_init_devnames(sc); 1289 if (sc->names == NULL) { 1290 rc = ENOTSUP; 1291 goto done; /* error message displayed already */ 1292 } 1293 1294 /* 1295 * Do this really early, with the memory windows set up even before the 1296 * character device. The userland tool's register i/o and mem read 1297 * will work even in "recovery mode". 1298 */ 1299 setup_memwin(sc); 1300 if (t4_init_devlog_params(sc, 0) == 0) 1301 fixup_devlog_params(sc); 1302 make_dev_args_init(&mda); 1303 mda.mda_devsw = &t4_cdevsw; 1304 mda.mda_uid = UID_ROOT; 1305 mda.mda_gid = GID_WHEEL; 1306 mda.mda_mode = 0600; 1307 mda.mda_si_drv1 = sc; 1308 rc = make_dev_s(&mda, &sc->cdev, "%s", device_get_nameunit(dev)); 1309 if (rc != 0) 1310 device_printf(dev, "failed to create nexus char device: %d.\n", 1311 rc); 1312 1313 /* Go no further if recovery mode has been requested. */ 1314 if (TUNABLE_INT_FETCH("hw.cxgbe.sos", &i) && i != 0) { 1315 device_printf(dev, "recovery mode.\n"); 1316 goto done; 1317 } 1318 1319 #if defined(__i386__) 1320 if ((cpu_feature & CPUID_CX8) == 0) { 1321 device_printf(dev, "64 bit atomics not available.\n"); 1322 rc = ENOTSUP; 1323 goto done; 1324 } 1325 #endif 1326 1327 /* Contact the firmware and try to become the master driver. */ 1328 rc = contact_firmware(sc); 1329 if (rc != 0) 1330 goto done; /* error message displayed already */ 1331 MPASS(sc->flags & FW_OK); 1332 1333 rc = get_params__pre_init(sc); 1334 if (rc != 0) 1335 goto done; /* error message displayed already */ 1336 1337 if (sc->flags & MASTER_PF) { 1338 rc = partition_resources(sc); 1339 if (rc != 0) 1340 goto done; /* error message displayed already */ 1341 } 1342 1343 rc = get_params__post_init(sc); 1344 if (rc != 0) 1345 goto done; /* error message displayed already */ 1346 1347 rc = set_params__post_init(sc); 1348 if (rc != 0) 1349 goto done; /* error message displayed already */ 1350 1351 rc = t4_map_bar_2(sc); 1352 if (rc != 0) 1353 goto done; /* error message displayed already */ 1354 1355 rc = t4_adj_doorbells(sc); 1356 if (rc != 0) 1357 goto done; /* error message displayed already */ 1358 1359 rc = t4_create_dma_tag(sc); 1360 if (rc != 0) 1361 goto done; /* error message displayed already */ 1362 1363 /* 1364 * First pass over all the ports - allocate VIs and initialize some 1365 * basic parameters like mac address, port type, etc. 1366 */ 1367 for_each_port(sc, i) { 1368 struct port_info *pi; 1369 1370 pi = malloc(sizeof(*pi), M_CXGBE, M_ZERO | M_WAITOK); 1371 sc->port[i] = pi; 1372 1373 /* These must be set before t4_port_init */ 1374 pi->adapter = sc; 1375 pi->port_id = i; 1376 /* 1377 * XXX: vi[0] is special so we can't delay this allocation until 1378 * pi->nvi's final value is known. 1379 */ 1380 pi->vi = malloc(sizeof(struct vi_info) * t4_num_vis, M_CXGBE, 1381 M_ZERO | M_WAITOK); 1382 1383 /* 1384 * Allocate the "main" VI and initialize parameters 1385 * like mac addr. 1386 */ 1387 rc = -t4_port_init(sc, sc->mbox, sc->pf, 0, i); 1388 if (rc != 0) { 1389 device_printf(dev, "unable to initialize port %d: %d\n", 1390 i, rc); 1391 free(pi->vi, M_CXGBE); 1392 free(pi, M_CXGBE); 1393 sc->port[i] = NULL; 1394 goto done; 1395 } 1396 1397 if (is_bt(pi->port_type)) 1398 setbit(&sc->bt_map, pi->tx_chan); 1399 else 1400 MPASS(!isset(&sc->bt_map, pi->tx_chan)); 1401 1402 snprintf(pi->lockname, sizeof(pi->lockname), "%sp%d", 1403 device_get_nameunit(dev), i); 1404 mtx_init(&pi->pi_lock, pi->lockname, 0, MTX_DEF); 1405 sc->chan_map[pi->tx_chan] = i; 1406 1407 /* 1408 * The MPS counter for FCS errors doesn't work correctly on the 1409 * T6 so we use the MAC counter here. Which MAC is in use 1410 * depends on the link settings which will be known when the 1411 * link comes up. 1412 */ 1413 if (is_t6(sc)) 1414 pi->fcs_reg = -1; 1415 else { 1416 pi->fcs_reg = t4_port_reg(sc, pi->tx_chan, 1417 A_MPS_PORT_STAT_RX_PORT_CRC_ERROR_L); 1418 } 1419 pi->fcs_base = 0; 1420 1421 /* All VIs on this port share this media. */ 1422 ifmedia_init(&pi->media, IFM_IMASK, cxgbe_media_change, 1423 cxgbe_media_status); 1424 1425 PORT_LOCK(pi); 1426 init_link_config(pi); 1427 fixup_link_config(pi); 1428 build_medialist(pi); 1429 if (fixed_ifmedia(pi)) 1430 pi->flags |= FIXED_IFMEDIA; 1431 PORT_UNLOCK(pi); 1432 1433 pi->dev = device_add_child(dev, sc->names->ifnet_name, 1434 t4_ifnet_unit(sc, pi)); 1435 if (pi->dev == NULL) { 1436 device_printf(dev, 1437 "failed to add device for port %d.\n", i); 1438 rc = ENXIO; 1439 goto done; 1440 } 1441 pi->vi[0].dev = pi->dev; 1442 device_set_softc(pi->dev, pi); 1443 } 1444 1445 /* 1446 * Interrupt type, # of interrupts, # of rx/tx queues, etc. 1447 */ 1448 nports = sc->params.nports; 1449 rc = cfg_itype_and_nqueues(sc, &iaq); 1450 if (rc != 0) 1451 goto done; /* error message displayed already */ 1452 1453 num_vis = iaq.num_vis; 1454 sc->intr_type = iaq.intr_type; 1455 sc->intr_count = iaq.nirq; 1456 1457 s = &sc->sge; 1458 s->nrxq = nports * iaq.nrxq; 1459 s->ntxq = nports * iaq.ntxq; 1460 if (num_vis > 1) { 1461 s->nrxq += nports * (num_vis - 1) * iaq.nrxq_vi; 1462 s->ntxq += nports * (num_vis - 1) * iaq.ntxq_vi; 1463 } 1464 s->neq = s->ntxq + s->nrxq; /* the free list in an rxq is an eq */ 1465 s->neq += nports; /* ctrl queues: 1 per port */ 1466 s->niq = s->nrxq + 1; /* 1 extra for firmware event queue */ 1467 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 1468 if (is_offload(sc) || is_ethoffload(sc)) { 1469 s->nofldtxq = nports * iaq.nofldtxq; 1470 if (num_vis > 1) 1471 s->nofldtxq += nports * (num_vis - 1) * iaq.nofldtxq_vi; 1472 s->neq += s->nofldtxq; 1473 1474 s->ofld_txq = malloc(s->nofldtxq * sizeof(struct sge_ofld_txq), 1475 M_CXGBE, M_ZERO | M_WAITOK); 1476 } 1477 #endif 1478 #ifdef TCP_OFFLOAD 1479 if (is_offload(sc)) { 1480 s->nofldrxq = nports * iaq.nofldrxq; 1481 if (num_vis > 1) 1482 s->nofldrxq += nports * (num_vis - 1) * iaq.nofldrxq_vi; 1483 s->neq += s->nofldrxq; /* free list */ 1484 s->niq += s->nofldrxq; 1485 1486 s->ofld_rxq = malloc(s->nofldrxq * sizeof(struct sge_ofld_rxq), 1487 M_CXGBE, M_ZERO | M_WAITOK); 1488 } 1489 #endif 1490 #ifdef DEV_NETMAP 1491 s->nnmrxq = 0; 1492 s->nnmtxq = 0; 1493 if (t4_native_netmap & NN_MAIN_VI) { 1494 s->nnmrxq += nports * iaq.nnmrxq; 1495 s->nnmtxq += nports * iaq.nnmtxq; 1496 } 1497 if (num_vis > 1 && t4_native_netmap & NN_EXTRA_VI) { 1498 s->nnmrxq += nports * (num_vis - 1) * iaq.nnmrxq_vi; 1499 s->nnmtxq += nports * (num_vis - 1) * iaq.nnmtxq_vi; 1500 } 1501 s->neq += s->nnmtxq + s->nnmrxq; 1502 s->niq += s->nnmrxq; 1503 1504 s->nm_rxq = malloc(s->nnmrxq * sizeof(struct sge_nm_rxq), 1505 M_CXGBE, M_ZERO | M_WAITOK); 1506 s->nm_txq = malloc(s->nnmtxq * sizeof(struct sge_nm_txq), 1507 M_CXGBE, M_ZERO | M_WAITOK); 1508 #endif 1509 MPASS(s->niq <= s->iqmap_sz); 1510 MPASS(s->neq <= s->eqmap_sz); 1511 1512 s->ctrlq = malloc(nports * sizeof(struct sge_wrq), M_CXGBE, 1513 M_ZERO | M_WAITOK); 1514 s->rxq = malloc(s->nrxq * sizeof(struct sge_rxq), M_CXGBE, 1515 M_ZERO | M_WAITOK); 1516 s->txq = malloc(s->ntxq * sizeof(struct sge_txq), M_CXGBE, 1517 M_ZERO | M_WAITOK); 1518 s->iqmap = malloc(s->iqmap_sz * sizeof(struct sge_iq *), M_CXGBE, 1519 M_ZERO | M_WAITOK); 1520 s->eqmap = malloc(s->eqmap_sz * sizeof(struct sge_eq *), M_CXGBE, 1521 M_ZERO | M_WAITOK); 1522 1523 sc->irq = malloc(sc->intr_count * sizeof(struct irq), M_CXGBE, 1524 M_ZERO | M_WAITOK); 1525 1526 t4_init_l2t(sc, M_WAITOK); 1527 t4_init_smt(sc, M_WAITOK); 1528 t4_init_tx_sched(sc); 1529 t4_init_atid_table(sc); 1530 #ifdef RATELIMIT 1531 t4_init_etid_table(sc); 1532 #endif 1533 #ifdef INET6 1534 t4_init_clip_table(sc); 1535 #endif 1536 if (sc->vres.key.size != 0) 1537 sc->key_map = vmem_create("T4TLS key map", sc->vres.key.start, 1538 sc->vres.key.size, 32, 0, M_FIRSTFIT | M_WAITOK); 1539 1540 /* 1541 * Second pass over the ports. This time we know the number of rx and 1542 * tx queues that each port should get. 1543 */ 1544 rqidx = tqidx = 0; 1545 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 1546 ofld_tqidx = 0; 1547 #endif 1548 #ifdef TCP_OFFLOAD 1549 ofld_rqidx = 0; 1550 #endif 1551 #ifdef DEV_NETMAP 1552 nm_rqidx = nm_tqidx = 0; 1553 #endif 1554 for_each_port(sc, i) { 1555 struct port_info *pi = sc->port[i]; 1556 struct vi_info *vi; 1557 1558 if (pi == NULL) 1559 continue; 1560 1561 pi->nvi = num_vis; 1562 for_each_vi(pi, j, vi) { 1563 vi->pi = pi; 1564 vi->adapter = sc; 1565 vi->first_intr = -1; 1566 vi->qsize_rxq = t4_qsize_rxq; 1567 vi->qsize_txq = t4_qsize_txq; 1568 1569 vi->first_rxq = rqidx; 1570 vi->first_txq = tqidx; 1571 vi->tmr_idx = t4_tmr_idx; 1572 vi->pktc_idx = t4_pktc_idx; 1573 vi->nrxq = j == 0 ? iaq.nrxq : iaq.nrxq_vi; 1574 vi->ntxq = j == 0 ? iaq.ntxq : iaq.ntxq_vi; 1575 1576 rqidx += vi->nrxq; 1577 tqidx += vi->ntxq; 1578 1579 if (j == 0 && vi->ntxq > 1) 1580 vi->rsrv_noflowq = t4_rsrv_noflowq ? 1 : 0; 1581 else 1582 vi->rsrv_noflowq = 0; 1583 1584 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 1585 vi->first_ofld_txq = ofld_tqidx; 1586 vi->nofldtxq = j == 0 ? iaq.nofldtxq : iaq.nofldtxq_vi; 1587 ofld_tqidx += vi->nofldtxq; 1588 #endif 1589 #ifdef TCP_OFFLOAD 1590 vi->ofld_tmr_idx = t4_tmr_idx_ofld; 1591 vi->ofld_pktc_idx = t4_pktc_idx_ofld; 1592 vi->first_ofld_rxq = ofld_rqidx; 1593 vi->nofldrxq = j == 0 ? iaq.nofldrxq : iaq.nofldrxq_vi; 1594 1595 ofld_rqidx += vi->nofldrxq; 1596 #endif 1597 #ifdef DEV_NETMAP 1598 vi->first_nm_rxq = nm_rqidx; 1599 vi->first_nm_txq = nm_tqidx; 1600 if (j == 0) { 1601 vi->nnmrxq = iaq.nnmrxq; 1602 vi->nnmtxq = iaq.nnmtxq; 1603 } else { 1604 vi->nnmrxq = iaq.nnmrxq_vi; 1605 vi->nnmtxq = iaq.nnmtxq_vi; 1606 } 1607 nm_rqidx += vi->nnmrxq; 1608 nm_tqidx += vi->nnmtxq; 1609 #endif 1610 } 1611 } 1612 1613 rc = t4_setup_intr_handlers(sc); 1614 if (rc != 0) { 1615 device_printf(dev, 1616 "failed to setup interrupt handlers: %d\n", rc); 1617 goto done; 1618 } 1619 1620 rc = bus_generic_probe(dev); 1621 if (rc != 0) { 1622 device_printf(dev, "failed to probe child drivers: %d\n", rc); 1623 goto done; 1624 } 1625 1626 /* 1627 * Ensure thread-safe mailbox access (in debug builds). 1628 * 1629 * So far this was the only thread accessing the mailbox but various 1630 * ifnets and sysctls are about to be created and their handlers/ioctls 1631 * will access the mailbox from different threads. 1632 */ 1633 sc->flags |= CHK_MBOX_ACCESS; 1634 1635 rc = bus_generic_attach(dev); 1636 if (rc != 0) { 1637 device_printf(dev, 1638 "failed to attach all child ports: %d\n", rc); 1639 goto done; 1640 } 1641 t4_calibration_start(sc); 1642 1643 device_printf(dev, 1644 "PCIe gen%d x%d, %d ports, %d %s interrupt%s, %d eq, %d iq\n", 1645 sc->params.pci.speed, sc->params.pci.width, sc->params.nports, 1646 sc->intr_count, sc->intr_type == INTR_MSIX ? "MSI-X" : 1647 (sc->intr_type == INTR_MSI ? "MSI" : "INTx"), 1648 sc->intr_count > 1 ? "s" : "", sc->sge.neq, sc->sge.niq); 1649 1650 t4_set_desc(sc); 1651 1652 notify_siblings(dev, 0); 1653 1654 done: 1655 if (rc != 0 && sc->cdev) { 1656 /* cdev was created and so cxgbetool works; recover that way. */ 1657 device_printf(dev, 1658 "error during attach, adapter is now in recovery mode.\n"); 1659 rc = 0; 1660 } 1661 1662 if (rc != 0) 1663 t4_detach_common(dev); 1664 else 1665 t4_sysctls(sc); 1666 1667 return (rc); 1668 } 1669 1670 static int 1671 t4_child_location(device_t bus, device_t dev, struct sbuf *sb) 1672 { 1673 struct adapter *sc; 1674 struct port_info *pi; 1675 int i; 1676 1677 sc = device_get_softc(bus); 1678 for_each_port(sc, i) { 1679 pi = sc->port[i]; 1680 if (pi != NULL && pi->dev == dev) { 1681 sbuf_printf(sb, "port=%d", pi->port_id); 1682 break; 1683 } 1684 } 1685 return (0); 1686 } 1687 1688 static int 1689 t4_ready(device_t dev) 1690 { 1691 struct adapter *sc; 1692 1693 sc = device_get_softc(dev); 1694 if (sc->flags & FW_OK) 1695 return (0); 1696 return (ENXIO); 1697 } 1698 1699 static int 1700 t4_read_port_device(device_t dev, int port, device_t *child) 1701 { 1702 struct adapter *sc; 1703 struct port_info *pi; 1704 1705 sc = device_get_softc(dev); 1706 if (port < 0 || port >= MAX_NPORTS) 1707 return (EINVAL); 1708 pi = sc->port[port]; 1709 if (pi == NULL || pi->dev == NULL) 1710 return (ENXIO); 1711 *child = pi->dev; 1712 return (0); 1713 } 1714 1715 static int 1716 notify_siblings(device_t dev, int detaching) 1717 { 1718 device_t sibling; 1719 int error, i; 1720 1721 error = 0; 1722 for (i = 0; i < PCI_FUNCMAX; i++) { 1723 if (i == pci_get_function(dev)) 1724 continue; 1725 sibling = pci_find_dbsf(pci_get_domain(dev), pci_get_bus(dev), 1726 pci_get_slot(dev), i); 1727 if (sibling == NULL || !device_is_attached(sibling)) 1728 continue; 1729 if (detaching) 1730 error = T4_DETACH_CHILD(sibling); 1731 else 1732 (void)T4_ATTACH_CHILD(sibling); 1733 if (error) 1734 break; 1735 } 1736 return (error); 1737 } 1738 1739 /* 1740 * Idempotent 1741 */ 1742 static int 1743 t4_detach(device_t dev) 1744 { 1745 int rc; 1746 1747 rc = notify_siblings(dev, 1); 1748 if (rc) { 1749 device_printf(dev, 1750 "failed to detach sibling devices: %d\n", rc); 1751 return (rc); 1752 } 1753 1754 return (t4_detach_common(dev)); 1755 } 1756 1757 int 1758 t4_detach_common(device_t dev) 1759 { 1760 struct adapter *sc; 1761 struct port_info *pi; 1762 int i, rc; 1763 1764 sc = device_get_softc(dev); 1765 1766 #ifdef TCP_OFFLOAD 1767 rc = t4_deactivate_all_uld(sc); 1768 if (rc) { 1769 device_printf(dev, 1770 "failed to detach upper layer drivers: %d\n", rc); 1771 return (rc); 1772 } 1773 #endif 1774 1775 if (sc->cdev) { 1776 destroy_dev(sc->cdev); 1777 sc->cdev = NULL; 1778 } 1779 1780 sx_xlock(&t4_list_lock); 1781 SLIST_REMOVE(&t4_list, sc, adapter, link); 1782 sx_xunlock(&t4_list_lock); 1783 1784 sc->flags &= ~CHK_MBOX_ACCESS; 1785 if (sc->flags & FULL_INIT_DONE) { 1786 if (!(sc->flags & IS_VF)) 1787 t4_intr_disable(sc); 1788 } 1789 1790 if (device_is_attached(dev)) { 1791 rc = bus_generic_detach(dev); 1792 if (rc) { 1793 device_printf(dev, 1794 "failed to detach child devices: %d\n", rc); 1795 return (rc); 1796 } 1797 } 1798 1799 for (i = 0; i < sc->intr_count; i++) 1800 t4_free_irq(sc, &sc->irq[i]); 1801 1802 if ((sc->flags & (IS_VF | FW_OK)) == FW_OK) 1803 t4_free_tx_sched(sc); 1804 1805 for (i = 0; i < MAX_NPORTS; i++) { 1806 pi = sc->port[i]; 1807 if (pi) { 1808 t4_free_vi(sc, sc->mbox, sc->pf, 0, pi->vi[0].viid); 1809 if (pi->dev) 1810 device_delete_child(dev, pi->dev); 1811 1812 mtx_destroy(&pi->pi_lock); 1813 free(pi->vi, M_CXGBE); 1814 free(pi, M_CXGBE); 1815 } 1816 } 1817 callout_stop(&sc->cal_callout); 1818 callout_drain(&sc->cal_callout); 1819 device_delete_children(dev); 1820 sysctl_ctx_free(&sc->ctx); 1821 adapter_full_uninit(sc); 1822 1823 if ((sc->flags & (IS_VF | FW_OK)) == FW_OK) 1824 t4_fw_bye(sc, sc->mbox); 1825 1826 if (sc->intr_type == INTR_MSI || sc->intr_type == INTR_MSIX) 1827 pci_release_msi(dev); 1828 1829 if (sc->regs_res) 1830 bus_release_resource(dev, SYS_RES_MEMORY, sc->regs_rid, 1831 sc->regs_res); 1832 1833 if (sc->udbs_res) 1834 bus_release_resource(dev, SYS_RES_MEMORY, sc->udbs_rid, 1835 sc->udbs_res); 1836 1837 if (sc->msix_res) 1838 bus_release_resource(dev, SYS_RES_MEMORY, sc->msix_rid, 1839 sc->msix_res); 1840 1841 if (sc->l2t) 1842 t4_free_l2t(sc->l2t); 1843 if (sc->smt) 1844 t4_free_smt(sc->smt); 1845 t4_free_atid_table(sc); 1846 #ifdef RATELIMIT 1847 t4_free_etid_table(sc); 1848 #endif 1849 if (sc->key_map) 1850 vmem_destroy(sc->key_map); 1851 #ifdef INET6 1852 t4_destroy_clip_table(sc); 1853 #endif 1854 1855 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 1856 free(sc->sge.ofld_txq, M_CXGBE); 1857 #endif 1858 #ifdef TCP_OFFLOAD 1859 free(sc->sge.ofld_rxq, M_CXGBE); 1860 #endif 1861 #ifdef DEV_NETMAP 1862 free(sc->sge.nm_rxq, M_CXGBE); 1863 free(sc->sge.nm_txq, M_CXGBE); 1864 #endif 1865 free(sc->irq, M_CXGBE); 1866 free(sc->sge.rxq, M_CXGBE); 1867 free(sc->sge.txq, M_CXGBE); 1868 free(sc->sge.ctrlq, M_CXGBE); 1869 free(sc->sge.iqmap, M_CXGBE); 1870 free(sc->sge.eqmap, M_CXGBE); 1871 free(sc->tids.ftid_tab, M_CXGBE); 1872 free(sc->tids.hpftid_tab, M_CXGBE); 1873 free_hftid_hash(&sc->tids); 1874 free(sc->tids.tid_tab, M_CXGBE); 1875 t4_destroy_dma_tag(sc); 1876 1877 callout_drain(&sc->ktls_tick); 1878 callout_drain(&sc->sfl_callout); 1879 if (mtx_initialized(&sc->tids.ftid_lock)) { 1880 mtx_destroy(&sc->tids.ftid_lock); 1881 cv_destroy(&sc->tids.ftid_cv); 1882 } 1883 if (mtx_initialized(&sc->tids.atid_lock)) 1884 mtx_destroy(&sc->tids.atid_lock); 1885 if (mtx_initialized(&sc->ifp_lock)) 1886 mtx_destroy(&sc->ifp_lock); 1887 1888 if (rw_initialized(&sc->policy_lock)) { 1889 rw_destroy(&sc->policy_lock); 1890 #ifdef TCP_OFFLOAD 1891 if (sc->policy != NULL) 1892 free_offload_policy(sc->policy); 1893 #endif 1894 } 1895 1896 for (i = 0; i < NUM_MEMWIN; i++) { 1897 struct memwin *mw = &sc->memwin[i]; 1898 1899 if (rw_initialized(&mw->mw_lock)) 1900 rw_destroy(&mw->mw_lock); 1901 } 1902 1903 mtx_destroy(&sc->sfl_lock); 1904 mtx_destroy(&sc->reg_lock); 1905 mtx_destroy(&sc->sc_lock); 1906 1907 bzero(sc, sizeof(*sc)); 1908 1909 return (0); 1910 } 1911 1912 static inline bool 1913 ok_to_reset(struct adapter *sc) 1914 { 1915 struct tid_info *t = &sc->tids; 1916 struct port_info *pi; 1917 struct vi_info *vi; 1918 int i, j; 1919 int caps = IFCAP_TOE | IFCAP_NETMAP | IFCAP_TXRTLMT; 1920 1921 if (is_t6(sc)) 1922 caps |= IFCAP_TXTLS; 1923 1924 ASSERT_SYNCHRONIZED_OP(sc); 1925 MPASS(!(sc->flags & IS_VF)); 1926 1927 for_each_port(sc, i) { 1928 pi = sc->port[i]; 1929 for_each_vi(pi, j, vi) { 1930 if (if_getcapenable(vi->ifp) & caps) 1931 return (false); 1932 } 1933 } 1934 1935 if (atomic_load_int(&t->tids_in_use) > 0) 1936 return (false); 1937 if (atomic_load_int(&t->stids_in_use) > 0) 1938 return (false); 1939 if (atomic_load_int(&t->atids_in_use) > 0) 1940 return (false); 1941 if (atomic_load_int(&t->ftids_in_use) > 0) 1942 return (false); 1943 if (atomic_load_int(&t->hpftids_in_use) > 0) 1944 return (false); 1945 if (atomic_load_int(&t->etids_in_use) > 0) 1946 return (false); 1947 1948 return (true); 1949 } 1950 1951 static inline int 1952 stop_adapter(struct adapter *sc) 1953 { 1954 if (atomic_testandset_int(&sc->error_flags, ilog2(ADAP_STOPPED))) 1955 return (1); /* Already stopped. */ 1956 return (t4_shutdown_adapter(sc)); 1957 } 1958 1959 static int 1960 t4_suspend(device_t dev) 1961 { 1962 struct adapter *sc = device_get_softc(dev); 1963 struct port_info *pi; 1964 struct vi_info *vi; 1965 if_t ifp; 1966 struct sge_rxq *rxq; 1967 struct sge_txq *txq; 1968 struct sge_wrq *wrq; 1969 #ifdef TCP_OFFLOAD 1970 struct sge_ofld_rxq *ofld_rxq; 1971 #endif 1972 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 1973 struct sge_ofld_txq *ofld_txq; 1974 #endif 1975 int rc, i, j, k; 1976 1977 CH_ALERT(sc, "suspend requested\n"); 1978 1979 rc = begin_synchronized_op(sc, NULL, SLEEP_OK, "t4sus"); 1980 if (rc != 0) 1981 return (ENXIO); 1982 1983 /* XXX: Can the kernel call suspend repeatedly without resume? */ 1984 MPASS(!hw_off_limits(sc)); 1985 1986 if (!ok_to_reset(sc)) { 1987 /* XXX: should list what resource is preventing suspend. */ 1988 CH_ERR(sc, "not safe to suspend.\n"); 1989 rc = EBUSY; 1990 goto done; 1991 } 1992 1993 /* No more DMA or interrupts. */ 1994 stop_adapter(sc); 1995 1996 /* Quiesce all activity. */ 1997 for_each_port(sc, i) { 1998 pi = sc->port[i]; 1999 pi->vxlan_tcam_entry = false; 2000 2001 PORT_LOCK(pi); 2002 if (pi->up_vis > 0) { 2003 /* 2004 * t4_shutdown_adapter has already shut down all the 2005 * PHYs but it also disables interrupts and DMA so there 2006 * won't be a link interrupt. So we update the state 2007 * manually and inform the kernel. 2008 */ 2009 pi->link_cfg.link_ok = false; 2010 t4_os_link_changed(pi); 2011 } 2012 PORT_UNLOCK(pi); 2013 2014 for_each_vi(pi, j, vi) { 2015 vi->xact_addr_filt = -1; 2016 mtx_lock(&vi->tick_mtx); 2017 vi->flags |= VI_SKIP_STATS; 2018 mtx_unlock(&vi->tick_mtx); 2019 if (!(vi->flags & VI_INIT_DONE)) 2020 continue; 2021 2022 ifp = vi->ifp; 2023 if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { 2024 mtx_lock(&vi->tick_mtx); 2025 callout_stop(&vi->tick); 2026 mtx_unlock(&vi->tick_mtx); 2027 callout_drain(&vi->tick); 2028 } 2029 2030 /* 2031 * Note that the HW is not available. 2032 */ 2033 for_each_txq(vi, k, txq) { 2034 TXQ_LOCK(txq); 2035 txq->eq.flags &= ~(EQ_ENABLED | EQ_HW_ALLOCATED); 2036 TXQ_UNLOCK(txq); 2037 } 2038 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 2039 for_each_ofld_txq(vi, k, ofld_txq) { 2040 ofld_txq->wrq.eq.flags &= ~EQ_HW_ALLOCATED; 2041 } 2042 #endif 2043 for_each_rxq(vi, k, rxq) { 2044 rxq->iq.flags &= ~IQ_HW_ALLOCATED; 2045 } 2046 #if defined(TCP_OFFLOAD) 2047 for_each_ofld_rxq(vi, k, ofld_rxq) { 2048 ofld_rxq->iq.flags &= ~IQ_HW_ALLOCATED; 2049 } 2050 #endif 2051 2052 quiesce_vi(vi); 2053 } 2054 2055 if (sc->flags & FULL_INIT_DONE) { 2056 /* Control queue */ 2057 wrq = &sc->sge.ctrlq[i]; 2058 wrq->eq.flags &= ~EQ_HW_ALLOCATED; 2059 quiesce_wrq(wrq); 2060 } 2061 } 2062 if (sc->flags & FULL_INIT_DONE) { 2063 /* Firmware event queue */ 2064 sc->sge.fwq.flags &= ~IQ_HW_ALLOCATED; 2065 quiesce_iq_fl(sc, &sc->sge.fwq, NULL); 2066 } 2067 2068 /* Stop calibration */ 2069 callout_stop(&sc->cal_callout); 2070 callout_drain(&sc->cal_callout); 2071 2072 /* Mark the adapter totally off limits. */ 2073 mtx_lock(&sc->reg_lock); 2074 atomic_set_int(&sc->error_flags, HW_OFF_LIMITS); 2075 sc->flags &= ~(FW_OK | MASTER_PF); 2076 sc->reset_thread = NULL; 2077 mtx_unlock(&sc->reg_lock); 2078 2079 if (t4_clock_gate_on_suspend) { 2080 t4_set_reg_field(sc, A_PMU_PART_CG_PWRMODE, F_MA_PART_CGEN | 2081 F_LE_PART_CGEN | F_EDC1_PART_CGEN | F_EDC0_PART_CGEN | 2082 F_TP_PART_CGEN | F_PDP_PART_CGEN | F_SGE_PART_CGEN, 0); 2083 } 2084 2085 CH_ALERT(sc, "suspend completed.\n"); 2086 done: 2087 end_synchronized_op(sc, 0); 2088 return (rc); 2089 } 2090 2091 struct adapter_pre_reset_state { 2092 u_int flags; 2093 uint16_t nbmcaps; 2094 uint16_t linkcaps; 2095 uint16_t switchcaps; 2096 uint16_t niccaps; 2097 uint16_t toecaps; 2098 uint16_t rdmacaps; 2099 uint16_t cryptocaps; 2100 uint16_t iscsicaps; 2101 uint16_t fcoecaps; 2102 2103 u_int cfcsum; 2104 char cfg_file[32]; 2105 2106 struct adapter_params params; 2107 struct t4_virt_res vres; 2108 struct tid_info tids; 2109 struct sge sge; 2110 2111 int rawf_base; 2112 int nrawf; 2113 2114 }; 2115 2116 static void 2117 save_caps_and_params(struct adapter *sc, struct adapter_pre_reset_state *o) 2118 { 2119 2120 ASSERT_SYNCHRONIZED_OP(sc); 2121 2122 o->flags = sc->flags; 2123 2124 o->nbmcaps = sc->nbmcaps; 2125 o->linkcaps = sc->linkcaps; 2126 o->switchcaps = sc->switchcaps; 2127 o->niccaps = sc->niccaps; 2128 o->toecaps = sc->toecaps; 2129 o->rdmacaps = sc->rdmacaps; 2130 o->cryptocaps = sc->cryptocaps; 2131 o->iscsicaps = sc->iscsicaps; 2132 o->fcoecaps = sc->fcoecaps; 2133 2134 o->cfcsum = sc->cfcsum; 2135 MPASS(sizeof(o->cfg_file) == sizeof(sc->cfg_file)); 2136 memcpy(o->cfg_file, sc->cfg_file, sizeof(o->cfg_file)); 2137 2138 o->params = sc->params; 2139 o->vres = sc->vres; 2140 o->tids = sc->tids; 2141 o->sge = sc->sge; 2142 2143 o->rawf_base = sc->rawf_base; 2144 o->nrawf = sc->nrawf; 2145 } 2146 2147 static int 2148 compare_caps_and_params(struct adapter *sc, struct adapter_pre_reset_state *o) 2149 { 2150 int rc = 0; 2151 2152 ASSERT_SYNCHRONIZED_OP(sc); 2153 2154 /* Capabilities */ 2155 #define COMPARE_CAPS(c) do { \ 2156 if (o->c##caps != sc->c##caps) { \ 2157 CH_ERR(sc, "%scaps 0x%04x -> 0x%04x.\n", #c, o->c##caps, \ 2158 sc->c##caps); \ 2159 rc = EINVAL; \ 2160 } \ 2161 } while (0) 2162 COMPARE_CAPS(nbm); 2163 COMPARE_CAPS(link); 2164 COMPARE_CAPS(switch); 2165 COMPARE_CAPS(nic); 2166 COMPARE_CAPS(toe); 2167 COMPARE_CAPS(rdma); 2168 COMPARE_CAPS(crypto); 2169 COMPARE_CAPS(iscsi); 2170 COMPARE_CAPS(fcoe); 2171 #undef COMPARE_CAPS 2172 2173 /* Firmware config file */ 2174 if (o->cfcsum != sc->cfcsum) { 2175 CH_ERR(sc, "config file %s (0x%x) -> %s (0x%x)\n", o->cfg_file, 2176 o->cfcsum, sc->cfg_file, sc->cfcsum); 2177 rc = EINVAL; 2178 } 2179 2180 #define COMPARE_PARAM(p, name) do { \ 2181 if (o->p != sc->p) { \ 2182 CH_ERR(sc, #name " %d -> %d\n", o->p, sc->p); \ 2183 rc = EINVAL; \ 2184 } \ 2185 } while (0) 2186 COMPARE_PARAM(sge.iq_start, iq_start); 2187 COMPARE_PARAM(sge.eq_start, eq_start); 2188 COMPARE_PARAM(tids.ftid_base, ftid_base); 2189 COMPARE_PARAM(tids.ftid_end, ftid_end); 2190 COMPARE_PARAM(tids.nftids, nftids); 2191 COMPARE_PARAM(vres.l2t.start, l2t_start); 2192 COMPARE_PARAM(vres.l2t.size, l2t_size); 2193 COMPARE_PARAM(sge.iqmap_sz, iqmap_sz); 2194 COMPARE_PARAM(sge.eqmap_sz, eqmap_sz); 2195 COMPARE_PARAM(tids.tid_base, tid_base); 2196 COMPARE_PARAM(tids.hpftid_base, hpftid_base); 2197 COMPARE_PARAM(tids.hpftid_end, hpftid_end); 2198 COMPARE_PARAM(tids.nhpftids, nhpftids); 2199 COMPARE_PARAM(rawf_base, rawf_base); 2200 COMPARE_PARAM(nrawf, nrawf); 2201 COMPARE_PARAM(params.mps_bg_map, mps_bg_map); 2202 COMPARE_PARAM(params.filter2_wr_support, filter2_wr_support); 2203 COMPARE_PARAM(params.ulptx_memwrite_dsgl, ulptx_memwrite_dsgl); 2204 COMPARE_PARAM(params.fr_nsmr_tpte_wr_support, fr_nsmr_tpte_wr_support); 2205 COMPARE_PARAM(params.max_pkts_per_eth_tx_pkts_wr, max_pkts_per_eth_tx_pkts_wr); 2206 COMPARE_PARAM(tids.ntids, ntids); 2207 COMPARE_PARAM(tids.etid_base, etid_base); 2208 COMPARE_PARAM(tids.etid_end, etid_end); 2209 COMPARE_PARAM(tids.netids, netids); 2210 COMPARE_PARAM(params.eo_wr_cred, eo_wr_cred); 2211 COMPARE_PARAM(params.ethoffload, ethoffload); 2212 COMPARE_PARAM(tids.natids, natids); 2213 COMPARE_PARAM(tids.stid_base, stid_base); 2214 COMPARE_PARAM(vres.ddp.start, ddp_start); 2215 COMPARE_PARAM(vres.ddp.size, ddp_size); 2216 COMPARE_PARAM(params.ofldq_wr_cred, ofldq_wr_cred); 2217 COMPARE_PARAM(vres.stag.start, stag_start); 2218 COMPARE_PARAM(vres.stag.size, stag_size); 2219 COMPARE_PARAM(vres.rq.start, rq_start); 2220 COMPARE_PARAM(vres.rq.size, rq_size); 2221 COMPARE_PARAM(vres.pbl.start, pbl_start); 2222 COMPARE_PARAM(vres.pbl.size, pbl_size); 2223 COMPARE_PARAM(vres.qp.start, qp_start); 2224 COMPARE_PARAM(vres.qp.size, qp_size); 2225 COMPARE_PARAM(vres.cq.start, cq_start); 2226 COMPARE_PARAM(vres.cq.size, cq_size); 2227 COMPARE_PARAM(vres.ocq.start, ocq_start); 2228 COMPARE_PARAM(vres.ocq.size, ocq_size); 2229 COMPARE_PARAM(vres.srq.start, srq_start); 2230 COMPARE_PARAM(vres.srq.size, srq_size); 2231 COMPARE_PARAM(params.max_ordird_qp, max_ordird_qp); 2232 COMPARE_PARAM(params.max_ird_adapter, max_ird_adapter); 2233 COMPARE_PARAM(vres.iscsi.start, iscsi_start); 2234 COMPARE_PARAM(vres.iscsi.size, iscsi_size); 2235 COMPARE_PARAM(vres.key.start, key_start); 2236 COMPARE_PARAM(vres.key.size, key_size); 2237 #undef COMPARE_PARAM 2238 2239 return (rc); 2240 } 2241 2242 static int 2243 t4_resume(device_t dev) 2244 { 2245 struct adapter *sc = device_get_softc(dev); 2246 struct adapter_pre_reset_state *old_state = NULL; 2247 struct port_info *pi; 2248 struct vi_info *vi; 2249 if_t ifp; 2250 struct sge_txq *txq; 2251 int rc, i, j, k; 2252 2253 CH_ALERT(sc, "resume requested.\n"); 2254 2255 rc = begin_synchronized_op(sc, NULL, SLEEP_OK, "t4res"); 2256 if (rc != 0) 2257 return (ENXIO); 2258 MPASS(hw_off_limits(sc)); 2259 MPASS((sc->flags & FW_OK) == 0); 2260 MPASS((sc->flags & MASTER_PF) == 0); 2261 MPASS(sc->reset_thread == NULL); 2262 sc->reset_thread = curthread; 2263 2264 /* Register access is expected to work by the time we're here. */ 2265 if (t4_read_reg(sc, A_PL_WHOAMI) == 0xffffffff) { 2266 CH_ERR(sc, "%s: can't read device registers\n", __func__); 2267 rc = ENXIO; 2268 goto done; 2269 } 2270 2271 /* Note that HW_OFF_LIMITS is cleared a bit later. */ 2272 atomic_clear_int(&sc->error_flags, ADAP_FATAL_ERR | ADAP_STOPPED); 2273 2274 /* Restore memory window. */ 2275 setup_memwin(sc); 2276 2277 /* Go no further if recovery mode has been requested. */ 2278 if (TUNABLE_INT_FETCH("hw.cxgbe.sos", &i) && i != 0) { 2279 CH_ALERT(sc, "recovery mode on resume.\n"); 2280 rc = 0; 2281 mtx_lock(&sc->reg_lock); 2282 atomic_clear_int(&sc->error_flags, HW_OFF_LIMITS); 2283 mtx_unlock(&sc->reg_lock); 2284 goto done; 2285 } 2286 2287 old_state = malloc(sizeof(*old_state), M_CXGBE, M_ZERO | M_WAITOK); 2288 save_caps_and_params(sc, old_state); 2289 2290 /* Reestablish contact with firmware and become the primary PF. */ 2291 rc = contact_firmware(sc); 2292 if (rc != 0) 2293 goto done; /* error message displayed already */ 2294 MPASS(sc->flags & FW_OK); 2295 2296 if (sc->flags & MASTER_PF) { 2297 rc = partition_resources(sc); 2298 if (rc != 0) 2299 goto done; /* error message displayed already */ 2300 } 2301 2302 rc = get_params__post_init(sc); 2303 if (rc != 0) 2304 goto done; /* error message displayed already */ 2305 2306 rc = set_params__post_init(sc); 2307 if (rc != 0) 2308 goto done; /* error message displayed already */ 2309 2310 rc = compare_caps_and_params(sc, old_state); 2311 if (rc != 0) 2312 goto done; /* error message displayed already */ 2313 2314 for_each_port(sc, i) { 2315 pi = sc->port[i]; 2316 MPASS(pi != NULL); 2317 MPASS(pi->vi != NULL); 2318 MPASS(pi->vi[0].dev == pi->dev); 2319 2320 rc = -t4_port_init(sc, sc->mbox, sc->pf, 0, i); 2321 if (rc != 0) { 2322 CH_ERR(sc, 2323 "failed to re-initialize port %d: %d\n", i, rc); 2324 goto done; 2325 } 2326 MPASS(sc->chan_map[pi->tx_chan] == i); 2327 2328 PORT_LOCK(pi); 2329 fixup_link_config(pi); 2330 build_medialist(pi); 2331 PORT_UNLOCK(pi); 2332 for_each_vi(pi, j, vi) { 2333 if (IS_MAIN_VI(vi)) 2334 continue; 2335 rc = alloc_extra_vi(sc, pi, vi); 2336 if (rc != 0) { 2337 CH_ERR(vi, 2338 "failed to re-allocate extra VI: %d\n", rc); 2339 goto done; 2340 } 2341 } 2342 } 2343 2344 /* 2345 * Interrupts and queues are about to be enabled and other threads will 2346 * want to access the hardware too. It is safe to do so. Note that 2347 * this thread is still in the middle of a synchronized_op. 2348 */ 2349 mtx_lock(&sc->reg_lock); 2350 atomic_clear_int(&sc->error_flags, HW_OFF_LIMITS); 2351 mtx_unlock(&sc->reg_lock); 2352 2353 if (sc->flags & FULL_INIT_DONE) { 2354 rc = adapter_full_init(sc); 2355 if (rc != 0) { 2356 CH_ERR(sc, "failed to re-initialize adapter: %d\n", rc); 2357 goto done; 2358 } 2359 2360 if (sc->vxlan_refcount > 0) 2361 enable_vxlan_rx(sc); 2362 2363 for_each_port(sc, i) { 2364 pi = sc->port[i]; 2365 for_each_vi(pi, j, vi) { 2366 mtx_lock(&vi->tick_mtx); 2367 vi->flags &= ~VI_SKIP_STATS; 2368 mtx_unlock(&vi->tick_mtx); 2369 if (!(vi->flags & VI_INIT_DONE)) 2370 continue; 2371 rc = vi_full_init(vi); 2372 if (rc != 0) { 2373 CH_ERR(vi, "failed to re-initialize " 2374 "interface: %d\n", rc); 2375 goto done; 2376 } 2377 2378 ifp = vi->ifp; 2379 if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) 2380 continue; 2381 /* 2382 * Note that we do not setup multicast addresses 2383 * in the first pass. This ensures that the 2384 * unicast DMACs for all VIs on all ports get an 2385 * MPS TCAM entry. 2386 */ 2387 rc = update_mac_settings(ifp, XGMAC_ALL & 2388 ~XGMAC_MCADDRS); 2389 if (rc != 0) { 2390 CH_ERR(vi, "failed to re-configure MAC: %d\n", rc); 2391 goto done; 2392 } 2393 rc = -t4_enable_vi(sc, sc->mbox, vi->viid, true, 2394 true); 2395 if (rc != 0) { 2396 CH_ERR(vi, "failed to re-enable VI: %d\n", rc); 2397 goto done; 2398 } 2399 for_each_txq(vi, k, txq) { 2400 TXQ_LOCK(txq); 2401 txq->eq.flags |= EQ_ENABLED; 2402 TXQ_UNLOCK(txq); 2403 } 2404 mtx_lock(&vi->tick_mtx); 2405 callout_schedule(&vi->tick, hz); 2406 mtx_unlock(&vi->tick_mtx); 2407 } 2408 PORT_LOCK(pi); 2409 if (pi->up_vis > 0) { 2410 t4_update_port_info(pi); 2411 fixup_link_config(pi); 2412 build_medialist(pi); 2413 apply_link_config(pi); 2414 if (pi->link_cfg.link_ok) 2415 t4_os_link_changed(pi); 2416 } 2417 PORT_UNLOCK(pi); 2418 } 2419 2420 /* Now reprogram the L2 multicast addresses. */ 2421 for_each_port(sc, i) { 2422 pi = sc->port[i]; 2423 for_each_vi(pi, j, vi) { 2424 if (!(vi->flags & VI_INIT_DONE)) 2425 continue; 2426 ifp = vi->ifp; 2427 if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) 2428 continue; 2429 rc = update_mac_settings(ifp, XGMAC_MCADDRS); 2430 if (rc != 0) { 2431 CH_ERR(vi, "failed to re-configure MCAST MACs: %d\n", rc); 2432 rc = 0; /* carry on */ 2433 } 2434 } 2435 } 2436 } 2437 2438 /* Reset all calibration */ 2439 t4_calibration_start(sc); 2440 2441 done: 2442 if (rc == 0) { 2443 sc->incarnation++; 2444 CH_ALERT(sc, "resume completed.\n"); 2445 } 2446 end_synchronized_op(sc, 0); 2447 free(old_state, M_CXGBE); 2448 return (rc); 2449 } 2450 2451 static int 2452 t4_reset_prepare(device_t dev, device_t child) 2453 { 2454 struct adapter *sc = device_get_softc(dev); 2455 2456 CH_ALERT(sc, "reset_prepare.\n"); 2457 return (0); 2458 } 2459 2460 static int 2461 t4_reset_post(device_t dev, device_t child) 2462 { 2463 struct adapter *sc = device_get_softc(dev); 2464 2465 CH_ALERT(sc, "reset_post.\n"); 2466 return (0); 2467 } 2468 2469 static int 2470 reset_adapter(struct adapter *sc) 2471 { 2472 int rc, oldinc, error_flags; 2473 2474 CH_ALERT(sc, "reset requested.\n"); 2475 2476 rc = begin_synchronized_op(sc, NULL, SLEEP_OK, "t4rst1"); 2477 if (rc != 0) 2478 return (EBUSY); 2479 2480 if (hw_off_limits(sc)) { 2481 CH_ERR(sc, "adapter is suspended, use resume (not reset).\n"); 2482 rc = ENXIO; 2483 goto done; 2484 } 2485 2486 if (!ok_to_reset(sc)) { 2487 /* XXX: should list what resource is preventing reset. */ 2488 CH_ERR(sc, "not safe to reset.\n"); 2489 rc = EBUSY; 2490 goto done; 2491 } 2492 2493 done: 2494 oldinc = sc->incarnation; 2495 end_synchronized_op(sc, 0); 2496 if (rc != 0) 2497 return (rc); /* Error logged already. */ 2498 2499 atomic_add_int(&sc->num_resets, 1); 2500 mtx_lock(&Giant); 2501 rc = BUS_RESET_CHILD(device_get_parent(sc->dev), sc->dev, 0); 2502 mtx_unlock(&Giant); 2503 if (rc != 0) 2504 CH_ERR(sc, "bus_reset_child failed: %d.\n", rc); 2505 else { 2506 rc = begin_synchronized_op(sc, NULL, SLEEP_OK, "t4rst2"); 2507 if (rc != 0) 2508 return (EBUSY); 2509 error_flags = atomic_load_int(&sc->error_flags); 2510 if (sc->incarnation > oldinc && error_flags == 0) { 2511 CH_ALERT(sc, "bus_reset_child succeeded.\n"); 2512 } else { 2513 CH_ERR(sc, "adapter did not reset properly, flags " 2514 "0x%08x, error_flags 0x%08x.\n", sc->flags, 2515 error_flags); 2516 rc = ENXIO; 2517 } 2518 end_synchronized_op(sc, 0); 2519 } 2520 2521 return (rc); 2522 } 2523 2524 static void 2525 reset_adapter_task(void *arg, int pending) 2526 { 2527 /* XXX: t4_async_event here? */ 2528 reset_adapter(arg); 2529 } 2530 2531 static int 2532 cxgbe_probe(device_t dev) 2533 { 2534 struct port_info *pi = device_get_softc(dev); 2535 2536 device_set_descf(dev, "port %d", pi->port_id); 2537 2538 return (BUS_PROBE_DEFAULT); 2539 } 2540 2541 #define T4_CAP (IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_HWCSUM | \ 2542 IFCAP_VLAN_HWCSUM | IFCAP_TSO | IFCAP_JUMBO_MTU | IFCAP_LRO | \ 2543 IFCAP_VLAN_HWTSO | IFCAP_LINKSTATE | IFCAP_HWCSUM_IPV6 | IFCAP_HWSTATS | \ 2544 IFCAP_HWRXTSTMP | IFCAP_MEXTPG) 2545 #define T4_CAP_ENABLE (T4_CAP) 2546 2547 static int 2548 cxgbe_vi_attach(device_t dev, struct vi_info *vi) 2549 { 2550 if_t ifp; 2551 struct sbuf *sb; 2552 struct sysctl_ctx_list *ctx = &vi->ctx; 2553 struct sysctl_oid_list *children; 2554 struct pfil_head_args pa; 2555 struct adapter *sc = vi->adapter; 2556 2557 sysctl_ctx_init(ctx); 2558 children = SYSCTL_CHILDREN(device_get_sysctl_tree(vi->dev)); 2559 vi->rxq_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "rxq", 2560 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "NIC rx queues"); 2561 vi->txq_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "txq", 2562 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "NIC tx queues"); 2563 #ifdef DEV_NETMAP 2564 vi->nm_rxq_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "nm_rxq", 2565 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "netmap rx queues"); 2566 vi->nm_txq_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "nm_txq", 2567 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "netmap tx queues"); 2568 #endif 2569 #ifdef TCP_OFFLOAD 2570 vi->ofld_rxq_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "ofld_rxq", 2571 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "TOE rx queues"); 2572 #endif 2573 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 2574 vi->ofld_txq_oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "ofld_txq", 2575 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "TOE/ETHOFLD tx queues"); 2576 #endif 2577 2578 vi->xact_addr_filt = -1; 2579 mtx_init(&vi->tick_mtx, "vi tick", NULL, MTX_DEF); 2580 callout_init_mtx(&vi->tick, &vi->tick_mtx, 0); 2581 if (sc->flags & IS_VF || t4_tx_vm_wr != 0) 2582 vi->flags |= TX_USES_VM_WR; 2583 2584 /* Allocate an ifnet and set it up */ 2585 ifp = if_alloc_dev(IFT_ETHER, dev); 2586 if (ifp == NULL) { 2587 device_printf(dev, "Cannot allocate ifnet\n"); 2588 return (ENOMEM); 2589 } 2590 vi->ifp = ifp; 2591 if_setsoftc(ifp, vi); 2592 2593 if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 2594 if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); 2595 2596 if_setinitfn(ifp, cxgbe_init); 2597 if_setioctlfn(ifp, cxgbe_ioctl); 2598 if_settransmitfn(ifp, cxgbe_transmit); 2599 if_setqflushfn(ifp, cxgbe_qflush); 2600 if (vi->pi->nvi > 1 || sc->flags & IS_VF) 2601 if_setgetcounterfn(ifp, vi_get_counter); 2602 else 2603 if_setgetcounterfn(ifp, cxgbe_get_counter); 2604 #if defined(KERN_TLS) || defined(RATELIMIT) 2605 if_setsndtagallocfn(ifp, cxgbe_snd_tag_alloc); 2606 #endif 2607 #ifdef RATELIMIT 2608 if_setratelimitqueryfn(ifp, cxgbe_ratelimit_query); 2609 #endif 2610 2611 if_setcapabilities(ifp, T4_CAP); 2612 if_setcapenable(ifp, T4_CAP_ENABLE); 2613 if_sethwassist(ifp, CSUM_TCP | CSUM_UDP | CSUM_IP | CSUM_TSO | 2614 CSUM_UDP_IPV6 | CSUM_TCP_IPV6); 2615 if (chip_id(sc) >= CHELSIO_T6) { 2616 if_setcapabilitiesbit(ifp, IFCAP_VXLAN_HWCSUM | IFCAP_VXLAN_HWTSO, 0); 2617 if_setcapenablebit(ifp, IFCAP_VXLAN_HWCSUM | IFCAP_VXLAN_HWTSO, 0); 2618 if_sethwassistbits(ifp, CSUM_INNER_IP6_UDP | CSUM_INNER_IP6_TCP | 2619 CSUM_INNER_IP6_TSO | CSUM_INNER_IP | CSUM_INNER_IP_UDP | 2620 CSUM_INNER_IP_TCP | CSUM_INNER_IP_TSO | CSUM_ENCAP_VXLAN, 0); 2621 } 2622 2623 #ifdef TCP_OFFLOAD 2624 if (vi->nofldrxq != 0) 2625 if_setcapabilitiesbit(ifp, IFCAP_TOE, 0); 2626 #endif 2627 #ifdef RATELIMIT 2628 if (is_ethoffload(sc) && vi->nofldtxq != 0) { 2629 if_setcapabilitiesbit(ifp, IFCAP_TXRTLMT, 0); 2630 if_setcapenablebit(ifp, IFCAP_TXRTLMT, 0); 2631 } 2632 #endif 2633 2634 if_sethwtsomax(ifp, IP_MAXPACKET); 2635 if (vi->flags & TX_USES_VM_WR) 2636 if_sethwtsomaxsegcount(ifp, TX_SGL_SEGS_VM_TSO); 2637 else 2638 if_sethwtsomaxsegcount(ifp, TX_SGL_SEGS_TSO); 2639 #ifdef RATELIMIT 2640 if (is_ethoffload(sc) && vi->nofldtxq != 0) 2641 if_sethwtsomaxsegcount(ifp, TX_SGL_SEGS_EO_TSO); 2642 #endif 2643 if_sethwtsomaxsegsize(ifp, 65536); 2644 #ifdef KERN_TLS 2645 if (is_ktls(sc)) { 2646 if_setcapabilitiesbit(ifp, IFCAP_TXTLS, 0); 2647 if (sc->flags & KERN_TLS_ON || !is_t6(sc)) 2648 if_setcapenablebit(ifp, IFCAP_TXTLS, 0); 2649 } 2650 #endif 2651 2652 ether_ifattach(ifp, vi->hw_addr); 2653 #ifdef DEV_NETMAP 2654 if (vi->nnmrxq != 0) 2655 cxgbe_nm_attach(vi); 2656 #endif 2657 sb = sbuf_new_auto(); 2658 sbuf_printf(sb, "%d txq, %d rxq (NIC)", vi->ntxq, vi->nrxq); 2659 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 2660 switch (if_getcapabilities(ifp) & (IFCAP_TOE | IFCAP_TXRTLMT)) { 2661 case IFCAP_TOE: 2662 sbuf_printf(sb, "; %d txq (TOE)", vi->nofldtxq); 2663 break; 2664 case IFCAP_TOE | IFCAP_TXRTLMT: 2665 sbuf_printf(sb, "; %d txq (TOE/ETHOFLD)", vi->nofldtxq); 2666 break; 2667 case IFCAP_TXRTLMT: 2668 sbuf_printf(sb, "; %d txq (ETHOFLD)", vi->nofldtxq); 2669 break; 2670 } 2671 #endif 2672 #ifdef TCP_OFFLOAD 2673 if (if_getcapabilities(ifp) & IFCAP_TOE) 2674 sbuf_printf(sb, ", %d rxq (TOE)", vi->nofldrxq); 2675 #endif 2676 #ifdef DEV_NETMAP 2677 if (if_getcapabilities(ifp) & IFCAP_NETMAP) 2678 sbuf_printf(sb, "; %d txq, %d rxq (netmap)", 2679 vi->nnmtxq, vi->nnmrxq); 2680 #endif 2681 sbuf_finish(sb); 2682 device_printf(dev, "%s\n", sbuf_data(sb)); 2683 sbuf_delete(sb); 2684 2685 vi_sysctls(vi); 2686 2687 pa.pa_version = PFIL_VERSION; 2688 pa.pa_flags = PFIL_IN; 2689 pa.pa_type = PFIL_TYPE_ETHERNET; 2690 pa.pa_headname = if_name(ifp); 2691 vi->pfil = pfil_head_register(&pa); 2692 2693 return (0); 2694 } 2695 2696 static int 2697 cxgbe_attach(device_t dev) 2698 { 2699 struct port_info *pi = device_get_softc(dev); 2700 struct adapter *sc = pi->adapter; 2701 struct vi_info *vi; 2702 int i, rc; 2703 2704 sysctl_ctx_init(&pi->ctx); 2705 2706 rc = cxgbe_vi_attach(dev, &pi->vi[0]); 2707 if (rc) 2708 return (rc); 2709 2710 for_each_vi(pi, i, vi) { 2711 if (i == 0) 2712 continue; 2713 vi->dev = device_add_child(dev, sc->names->vi_ifnet_name, -1); 2714 if (vi->dev == NULL) { 2715 device_printf(dev, "failed to add VI %d\n", i); 2716 continue; 2717 } 2718 device_set_softc(vi->dev, vi); 2719 } 2720 2721 cxgbe_sysctls(pi); 2722 2723 bus_generic_attach(dev); 2724 2725 return (0); 2726 } 2727 2728 static void 2729 cxgbe_vi_detach(struct vi_info *vi) 2730 { 2731 if_t ifp = vi->ifp; 2732 2733 if (vi->pfil != NULL) { 2734 pfil_head_unregister(vi->pfil); 2735 vi->pfil = NULL; 2736 } 2737 2738 ether_ifdetach(ifp); 2739 2740 /* Let detach proceed even if these fail. */ 2741 #ifdef DEV_NETMAP 2742 if (if_getcapabilities(ifp) & IFCAP_NETMAP) 2743 cxgbe_nm_detach(vi); 2744 #endif 2745 cxgbe_uninit_synchronized(vi); 2746 callout_drain(&vi->tick); 2747 mtx_destroy(&vi->tick_mtx); 2748 sysctl_ctx_free(&vi->ctx); 2749 vi_full_uninit(vi); 2750 2751 if_free(vi->ifp); 2752 vi->ifp = NULL; 2753 } 2754 2755 static int 2756 cxgbe_detach(device_t dev) 2757 { 2758 struct port_info *pi = device_get_softc(dev); 2759 struct adapter *sc = pi->adapter; 2760 int rc; 2761 2762 /* Detach the extra VIs first. */ 2763 rc = bus_generic_detach(dev); 2764 if (rc) 2765 return (rc); 2766 device_delete_children(dev); 2767 2768 sysctl_ctx_free(&pi->ctx); 2769 begin_vi_detach(sc, &pi->vi[0]); 2770 if (pi->flags & HAS_TRACEQ) { 2771 sc->traceq = -1; /* cloner should not create ifnet */ 2772 t4_tracer_port_detach(sc); 2773 } 2774 cxgbe_vi_detach(&pi->vi[0]); 2775 ifmedia_removeall(&pi->media); 2776 end_vi_detach(sc, &pi->vi[0]); 2777 2778 return (0); 2779 } 2780 2781 static void 2782 cxgbe_init(void *arg) 2783 { 2784 struct vi_info *vi = arg; 2785 struct adapter *sc = vi->adapter; 2786 2787 if (begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4init") != 0) 2788 return; 2789 cxgbe_init_synchronized(vi); 2790 end_synchronized_op(sc, 0); 2791 } 2792 2793 static int 2794 cxgbe_ioctl(if_t ifp, unsigned long cmd, caddr_t data) 2795 { 2796 int rc = 0, mtu, flags; 2797 struct vi_info *vi = if_getsoftc(ifp); 2798 struct port_info *pi = vi->pi; 2799 struct adapter *sc = pi->adapter; 2800 struct ifreq *ifr = (struct ifreq *)data; 2801 uint32_t mask; 2802 2803 switch (cmd) { 2804 case SIOCSIFMTU: 2805 mtu = ifr->ifr_mtu; 2806 if (mtu < ETHERMIN || mtu > MAX_MTU) 2807 return (EINVAL); 2808 2809 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4mtu"); 2810 if (rc) 2811 return (rc); 2812 if_setmtu(ifp, mtu); 2813 if (vi->flags & VI_INIT_DONE) { 2814 t4_update_fl_bufsize(ifp); 2815 if (!hw_off_limits(sc) && 2816 if_getdrvflags(ifp) & IFF_DRV_RUNNING) 2817 rc = update_mac_settings(ifp, XGMAC_MTU); 2818 } 2819 end_synchronized_op(sc, 0); 2820 break; 2821 2822 case SIOCSIFFLAGS: 2823 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4flg"); 2824 if (rc) 2825 return (rc); 2826 2827 if (hw_off_limits(sc)) { 2828 rc = ENXIO; 2829 goto fail; 2830 } 2831 2832 if (if_getflags(ifp) & IFF_UP) { 2833 if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { 2834 flags = vi->if_flags; 2835 if ((if_getflags(ifp) ^ flags) & 2836 (IFF_PROMISC | IFF_ALLMULTI)) { 2837 rc = update_mac_settings(ifp, 2838 XGMAC_PROMISC | XGMAC_ALLMULTI); 2839 } 2840 } else { 2841 rc = cxgbe_init_synchronized(vi); 2842 } 2843 vi->if_flags = if_getflags(ifp); 2844 } else if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { 2845 rc = cxgbe_uninit_synchronized(vi); 2846 } 2847 end_synchronized_op(sc, 0); 2848 break; 2849 2850 case SIOCADDMULTI: 2851 case SIOCDELMULTI: 2852 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4multi"); 2853 if (rc) 2854 return (rc); 2855 if (!hw_off_limits(sc) && if_getdrvflags(ifp) & IFF_DRV_RUNNING) 2856 rc = update_mac_settings(ifp, XGMAC_MCADDRS); 2857 end_synchronized_op(sc, 0); 2858 break; 2859 2860 case SIOCSIFCAP: 2861 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4cap"); 2862 if (rc) 2863 return (rc); 2864 2865 mask = ifr->ifr_reqcap ^ if_getcapenable(ifp); 2866 if (mask & IFCAP_TXCSUM) { 2867 if_togglecapenable(ifp, IFCAP_TXCSUM); 2868 if_togglehwassist(ifp, CSUM_TCP | CSUM_UDP | CSUM_IP); 2869 2870 if (IFCAP_TSO4 & if_getcapenable(ifp) && 2871 !(IFCAP_TXCSUM & if_getcapenable(ifp))) { 2872 mask &= ~IFCAP_TSO4; 2873 if_setcapenablebit(ifp, 0, IFCAP_TSO4); 2874 if_printf(ifp, 2875 "tso4 disabled due to -txcsum.\n"); 2876 } 2877 } 2878 if (mask & IFCAP_TXCSUM_IPV6) { 2879 if_togglecapenable(ifp, IFCAP_TXCSUM_IPV6); 2880 if_togglehwassist(ifp, CSUM_UDP_IPV6 | CSUM_TCP_IPV6); 2881 2882 if (IFCAP_TSO6 & if_getcapenable(ifp) && 2883 !(IFCAP_TXCSUM_IPV6 & if_getcapenable(ifp))) { 2884 mask &= ~IFCAP_TSO6; 2885 if_setcapenablebit(ifp, 0, IFCAP_TSO6); 2886 if_printf(ifp, 2887 "tso6 disabled due to -txcsum6.\n"); 2888 } 2889 } 2890 if (mask & IFCAP_RXCSUM) 2891 if_togglecapenable(ifp, IFCAP_RXCSUM); 2892 if (mask & IFCAP_RXCSUM_IPV6) 2893 if_togglecapenable(ifp, IFCAP_RXCSUM_IPV6); 2894 2895 /* 2896 * Note that we leave CSUM_TSO alone (it is always set). The 2897 * kernel takes both IFCAP_TSOx and CSUM_TSO into account before 2898 * sending a TSO request our way, so it's sufficient to toggle 2899 * IFCAP_TSOx only. 2900 */ 2901 if (mask & IFCAP_TSO4) { 2902 if (!(IFCAP_TSO4 & if_getcapenable(ifp)) && 2903 !(IFCAP_TXCSUM & if_getcapenable(ifp))) { 2904 if_printf(ifp, "enable txcsum first.\n"); 2905 rc = EAGAIN; 2906 goto fail; 2907 } 2908 if_togglecapenable(ifp, IFCAP_TSO4); 2909 } 2910 if (mask & IFCAP_TSO6) { 2911 if (!(IFCAP_TSO6 & if_getcapenable(ifp)) && 2912 !(IFCAP_TXCSUM_IPV6 & if_getcapenable(ifp))) { 2913 if_printf(ifp, "enable txcsum6 first.\n"); 2914 rc = EAGAIN; 2915 goto fail; 2916 } 2917 if_togglecapenable(ifp, IFCAP_TSO6); 2918 } 2919 if (mask & IFCAP_LRO) { 2920 #if defined(INET) || defined(INET6) 2921 int i; 2922 struct sge_rxq *rxq; 2923 2924 if_togglecapenable(ifp, IFCAP_LRO); 2925 for_each_rxq(vi, i, rxq) { 2926 if (if_getcapenable(ifp) & IFCAP_LRO) 2927 rxq->iq.flags |= IQ_LRO_ENABLED; 2928 else 2929 rxq->iq.flags &= ~IQ_LRO_ENABLED; 2930 } 2931 #endif 2932 } 2933 #ifdef TCP_OFFLOAD 2934 if (mask & IFCAP_TOE) { 2935 int enable = (if_getcapenable(ifp) ^ mask) & IFCAP_TOE; 2936 2937 rc = toe_capability(vi, enable); 2938 if (rc != 0) 2939 goto fail; 2940 2941 if_togglecapenable(ifp, mask); 2942 } 2943 #endif 2944 if (mask & IFCAP_VLAN_HWTAGGING) { 2945 if_togglecapenable(ifp, IFCAP_VLAN_HWTAGGING); 2946 if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) 2947 rc = update_mac_settings(ifp, XGMAC_VLANEX); 2948 } 2949 if (mask & IFCAP_VLAN_MTU) { 2950 if_togglecapenable(ifp, IFCAP_VLAN_MTU); 2951 2952 /* Need to find out how to disable auto-mtu-inflation */ 2953 } 2954 if (mask & IFCAP_VLAN_HWTSO) 2955 if_togglecapenable(ifp, IFCAP_VLAN_HWTSO); 2956 if (mask & IFCAP_VLAN_HWCSUM) 2957 if_togglecapenable(ifp, IFCAP_VLAN_HWCSUM); 2958 #ifdef RATELIMIT 2959 if (mask & IFCAP_TXRTLMT) 2960 if_togglecapenable(ifp, IFCAP_TXRTLMT); 2961 #endif 2962 if (mask & IFCAP_HWRXTSTMP) { 2963 int i; 2964 struct sge_rxq *rxq; 2965 2966 if_togglecapenable(ifp, IFCAP_HWRXTSTMP); 2967 for_each_rxq(vi, i, rxq) { 2968 if (if_getcapenable(ifp) & IFCAP_HWRXTSTMP) 2969 rxq->iq.flags |= IQ_RX_TIMESTAMP; 2970 else 2971 rxq->iq.flags &= ~IQ_RX_TIMESTAMP; 2972 } 2973 } 2974 if (mask & IFCAP_MEXTPG) 2975 if_togglecapenable(ifp, IFCAP_MEXTPG); 2976 2977 #ifdef KERN_TLS 2978 if (mask & IFCAP_TXTLS) { 2979 int enable = (if_getcapenable(ifp) ^ mask) & IFCAP_TXTLS; 2980 2981 rc = ktls_capability(sc, enable); 2982 if (rc != 0) 2983 goto fail; 2984 2985 if_togglecapenable(ifp, mask & IFCAP_TXTLS); 2986 } 2987 #endif 2988 if (mask & IFCAP_VXLAN_HWCSUM) { 2989 if_togglecapenable(ifp, IFCAP_VXLAN_HWCSUM); 2990 if_togglehwassist(ifp, CSUM_INNER_IP6_UDP | 2991 CSUM_INNER_IP6_TCP | CSUM_INNER_IP | 2992 CSUM_INNER_IP_UDP | CSUM_INNER_IP_TCP); 2993 } 2994 if (mask & IFCAP_VXLAN_HWTSO) { 2995 if_togglecapenable(ifp, IFCAP_VXLAN_HWTSO); 2996 if_togglehwassist(ifp, CSUM_INNER_IP6_TSO | 2997 CSUM_INNER_IP_TSO); 2998 } 2999 3000 #ifdef VLAN_CAPABILITIES 3001 VLAN_CAPABILITIES(ifp); 3002 #endif 3003 fail: 3004 end_synchronized_op(sc, 0); 3005 break; 3006 3007 case SIOCSIFMEDIA: 3008 case SIOCGIFMEDIA: 3009 case SIOCGIFXMEDIA: 3010 rc = ifmedia_ioctl(ifp, ifr, &pi->media, cmd); 3011 break; 3012 3013 case SIOCGI2C: { 3014 struct ifi2creq i2c; 3015 3016 rc = copyin(ifr_data_get_ptr(ifr), &i2c, sizeof(i2c)); 3017 if (rc != 0) 3018 break; 3019 if (i2c.dev_addr != 0xA0 && i2c.dev_addr != 0xA2) { 3020 rc = EPERM; 3021 break; 3022 } 3023 if (i2c.len > sizeof(i2c.data)) { 3024 rc = EINVAL; 3025 break; 3026 } 3027 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4i2c"); 3028 if (rc) 3029 return (rc); 3030 if (hw_off_limits(sc)) 3031 rc = ENXIO; 3032 else 3033 rc = -t4_i2c_rd(sc, sc->mbox, pi->port_id, i2c.dev_addr, 3034 i2c.offset, i2c.len, &i2c.data[0]); 3035 end_synchronized_op(sc, 0); 3036 if (rc == 0) 3037 rc = copyout(&i2c, ifr_data_get_ptr(ifr), sizeof(i2c)); 3038 break; 3039 } 3040 3041 default: 3042 rc = ether_ioctl(ifp, cmd, data); 3043 } 3044 3045 return (rc); 3046 } 3047 3048 static int 3049 cxgbe_transmit(if_t ifp, struct mbuf *m) 3050 { 3051 struct vi_info *vi = if_getsoftc(ifp); 3052 struct port_info *pi = vi->pi; 3053 struct adapter *sc; 3054 struct sge_txq *txq; 3055 void *items[1]; 3056 int rc; 3057 3058 M_ASSERTPKTHDR(m); 3059 MPASS(m->m_nextpkt == NULL); /* not quite ready for this yet */ 3060 #if defined(KERN_TLS) || defined(RATELIMIT) 3061 if (m->m_pkthdr.csum_flags & CSUM_SND_TAG) 3062 MPASS(m->m_pkthdr.snd_tag->ifp == ifp); 3063 #endif 3064 3065 if (__predict_false(pi->link_cfg.link_ok == false)) { 3066 m_freem(m); 3067 return (ENETDOWN); 3068 } 3069 3070 rc = parse_pkt(&m, vi->flags & TX_USES_VM_WR); 3071 if (__predict_false(rc != 0)) { 3072 if (__predict_true(rc == EINPROGRESS)) { 3073 /* queued by parse_pkt */ 3074 MPASS(m != NULL); 3075 return (0); 3076 } 3077 3078 MPASS(m == NULL); /* was freed already */ 3079 atomic_add_int(&pi->tx_parse_error, 1); /* rare, atomic is ok */ 3080 return (rc); 3081 } 3082 3083 /* Select a txq. */ 3084 sc = vi->adapter; 3085 txq = &sc->sge.txq[vi->first_txq]; 3086 if (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE) 3087 txq += ((m->m_pkthdr.flowid % (vi->ntxq - vi->rsrv_noflowq)) + 3088 vi->rsrv_noflowq); 3089 3090 items[0] = m; 3091 rc = mp_ring_enqueue(txq->r, items, 1, 256); 3092 if (__predict_false(rc != 0)) 3093 m_freem(m); 3094 3095 return (rc); 3096 } 3097 3098 static void 3099 cxgbe_qflush(if_t ifp) 3100 { 3101 struct vi_info *vi = if_getsoftc(ifp); 3102 struct sge_txq *txq; 3103 int i; 3104 3105 /* queues do not exist if !VI_INIT_DONE. */ 3106 if (vi->flags & VI_INIT_DONE) { 3107 for_each_txq(vi, i, txq) { 3108 TXQ_LOCK(txq); 3109 txq->eq.flags |= EQ_QFLUSH; 3110 TXQ_UNLOCK(txq); 3111 while (!mp_ring_is_idle(txq->r)) { 3112 mp_ring_check_drainage(txq->r, 4096); 3113 pause("qflush", 1); 3114 } 3115 TXQ_LOCK(txq); 3116 txq->eq.flags &= ~EQ_QFLUSH; 3117 TXQ_UNLOCK(txq); 3118 } 3119 } 3120 if_qflush(ifp); 3121 } 3122 3123 static uint64_t 3124 vi_get_counter(if_t ifp, ift_counter c) 3125 { 3126 struct vi_info *vi = if_getsoftc(ifp); 3127 struct fw_vi_stats_vf *s = &vi->stats; 3128 3129 mtx_lock(&vi->tick_mtx); 3130 vi_refresh_stats(vi); 3131 mtx_unlock(&vi->tick_mtx); 3132 3133 switch (c) { 3134 case IFCOUNTER_IPACKETS: 3135 return (s->rx_bcast_frames + s->rx_mcast_frames + 3136 s->rx_ucast_frames); 3137 case IFCOUNTER_IERRORS: 3138 return (s->rx_err_frames); 3139 case IFCOUNTER_OPACKETS: 3140 return (s->tx_bcast_frames + s->tx_mcast_frames + 3141 s->tx_ucast_frames + s->tx_offload_frames); 3142 case IFCOUNTER_OERRORS: 3143 return (s->tx_drop_frames); 3144 case IFCOUNTER_IBYTES: 3145 return (s->rx_bcast_bytes + s->rx_mcast_bytes + 3146 s->rx_ucast_bytes); 3147 case IFCOUNTER_OBYTES: 3148 return (s->tx_bcast_bytes + s->tx_mcast_bytes + 3149 s->tx_ucast_bytes + s->tx_offload_bytes); 3150 case IFCOUNTER_IMCASTS: 3151 return (s->rx_mcast_frames); 3152 case IFCOUNTER_OMCASTS: 3153 return (s->tx_mcast_frames); 3154 case IFCOUNTER_OQDROPS: { 3155 uint64_t drops; 3156 3157 drops = 0; 3158 if (vi->flags & VI_INIT_DONE) { 3159 int i; 3160 struct sge_txq *txq; 3161 3162 for_each_txq(vi, i, txq) 3163 drops += counter_u64_fetch(txq->r->dropped); 3164 } 3165 3166 return (drops); 3167 3168 } 3169 3170 default: 3171 return (if_get_counter_default(ifp, c)); 3172 } 3173 } 3174 3175 static uint64_t 3176 cxgbe_get_counter(if_t ifp, ift_counter c) 3177 { 3178 struct vi_info *vi = if_getsoftc(ifp); 3179 struct port_info *pi = vi->pi; 3180 struct port_stats *s = &pi->stats; 3181 3182 mtx_lock(&vi->tick_mtx); 3183 cxgbe_refresh_stats(vi); 3184 mtx_unlock(&vi->tick_mtx); 3185 3186 switch (c) { 3187 case IFCOUNTER_IPACKETS: 3188 return (s->rx_frames); 3189 3190 case IFCOUNTER_IERRORS: 3191 return (s->rx_jabber + s->rx_runt + s->rx_too_long + 3192 s->rx_fcs_err + s->rx_len_err); 3193 3194 case IFCOUNTER_OPACKETS: 3195 return (s->tx_frames); 3196 3197 case IFCOUNTER_OERRORS: 3198 return (s->tx_error_frames); 3199 3200 case IFCOUNTER_IBYTES: 3201 return (s->rx_octets); 3202 3203 case IFCOUNTER_OBYTES: 3204 return (s->tx_octets); 3205 3206 case IFCOUNTER_IMCASTS: 3207 return (s->rx_mcast_frames); 3208 3209 case IFCOUNTER_OMCASTS: 3210 return (s->tx_mcast_frames); 3211 3212 case IFCOUNTER_IQDROPS: 3213 return (s->rx_ovflow0 + s->rx_ovflow1 + s->rx_ovflow2 + 3214 s->rx_ovflow3 + s->rx_trunc0 + s->rx_trunc1 + s->rx_trunc2 + 3215 s->rx_trunc3 + pi->tnl_cong_drops); 3216 3217 case IFCOUNTER_OQDROPS: { 3218 uint64_t drops; 3219 3220 drops = s->tx_drop; 3221 if (vi->flags & VI_INIT_DONE) { 3222 int i; 3223 struct sge_txq *txq; 3224 3225 for_each_txq(vi, i, txq) 3226 drops += counter_u64_fetch(txq->r->dropped); 3227 } 3228 3229 return (drops); 3230 3231 } 3232 3233 default: 3234 return (if_get_counter_default(ifp, c)); 3235 } 3236 } 3237 3238 #if defined(KERN_TLS) || defined(RATELIMIT) 3239 static int 3240 cxgbe_snd_tag_alloc(if_t ifp, union if_snd_tag_alloc_params *params, 3241 struct m_snd_tag **pt) 3242 { 3243 int error; 3244 3245 switch (params->hdr.type) { 3246 #ifdef RATELIMIT 3247 case IF_SND_TAG_TYPE_RATE_LIMIT: 3248 error = cxgbe_rate_tag_alloc(ifp, params, pt); 3249 break; 3250 #endif 3251 #ifdef KERN_TLS 3252 case IF_SND_TAG_TYPE_TLS: 3253 { 3254 struct vi_info *vi = if_getsoftc(ifp); 3255 3256 if (is_t6(vi->pi->adapter)) 3257 error = t6_tls_tag_alloc(ifp, params, pt); 3258 else 3259 error = EOPNOTSUPP; 3260 break; 3261 } 3262 #endif 3263 default: 3264 error = EOPNOTSUPP; 3265 } 3266 return (error); 3267 } 3268 #endif 3269 3270 /* 3271 * The kernel picks a media from the list we had provided but we still validate 3272 * the requeste. 3273 */ 3274 int 3275 cxgbe_media_change(if_t ifp) 3276 { 3277 struct vi_info *vi = if_getsoftc(ifp); 3278 struct port_info *pi = vi->pi; 3279 struct ifmedia *ifm = &pi->media; 3280 struct link_config *lc = &pi->link_cfg; 3281 struct adapter *sc = pi->adapter; 3282 int rc; 3283 3284 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4mec"); 3285 if (rc != 0) 3286 return (rc); 3287 PORT_LOCK(pi); 3288 if (IFM_SUBTYPE(ifm->ifm_media) == IFM_AUTO) { 3289 /* ifconfig .. media autoselect */ 3290 if (!(lc->pcaps & FW_PORT_CAP32_ANEG)) { 3291 rc = ENOTSUP; /* AN not supported by transceiver */ 3292 goto done; 3293 } 3294 lc->requested_aneg = AUTONEG_ENABLE; 3295 lc->requested_speed = 0; 3296 lc->requested_fc |= PAUSE_AUTONEG; 3297 } else { 3298 lc->requested_aneg = AUTONEG_DISABLE; 3299 lc->requested_speed = 3300 ifmedia_baudrate(ifm->ifm_media) / 1000000; 3301 lc->requested_fc = 0; 3302 if (IFM_OPTIONS(ifm->ifm_media) & IFM_ETH_RXPAUSE) 3303 lc->requested_fc |= PAUSE_RX; 3304 if (IFM_OPTIONS(ifm->ifm_media) & IFM_ETH_TXPAUSE) 3305 lc->requested_fc |= PAUSE_TX; 3306 } 3307 if (pi->up_vis > 0 && !hw_off_limits(sc)) { 3308 fixup_link_config(pi); 3309 rc = apply_link_config(pi); 3310 } 3311 done: 3312 PORT_UNLOCK(pi); 3313 end_synchronized_op(sc, 0); 3314 return (rc); 3315 } 3316 3317 /* 3318 * Base media word (without ETHER, pause, link active, etc.) for the port at the 3319 * given speed. 3320 */ 3321 static int 3322 port_mword(struct port_info *pi, uint32_t speed) 3323 { 3324 3325 MPASS(speed & M_FW_PORT_CAP32_SPEED); 3326 MPASS(powerof2(speed)); 3327 3328 switch(pi->port_type) { 3329 case FW_PORT_TYPE_BT_SGMII: 3330 case FW_PORT_TYPE_BT_XFI: 3331 case FW_PORT_TYPE_BT_XAUI: 3332 /* BaseT */ 3333 switch (speed) { 3334 case FW_PORT_CAP32_SPEED_100M: 3335 return (IFM_100_T); 3336 case FW_PORT_CAP32_SPEED_1G: 3337 return (IFM_1000_T); 3338 case FW_PORT_CAP32_SPEED_10G: 3339 return (IFM_10G_T); 3340 } 3341 break; 3342 case FW_PORT_TYPE_KX4: 3343 if (speed == FW_PORT_CAP32_SPEED_10G) 3344 return (IFM_10G_KX4); 3345 break; 3346 case FW_PORT_TYPE_CX4: 3347 if (speed == FW_PORT_CAP32_SPEED_10G) 3348 return (IFM_10G_CX4); 3349 break; 3350 case FW_PORT_TYPE_KX: 3351 if (speed == FW_PORT_CAP32_SPEED_1G) 3352 return (IFM_1000_KX); 3353 break; 3354 case FW_PORT_TYPE_KR: 3355 case FW_PORT_TYPE_BP_AP: 3356 case FW_PORT_TYPE_BP4_AP: 3357 case FW_PORT_TYPE_BP40_BA: 3358 case FW_PORT_TYPE_KR4_100G: 3359 case FW_PORT_TYPE_KR_SFP28: 3360 case FW_PORT_TYPE_KR_XLAUI: 3361 switch (speed) { 3362 case FW_PORT_CAP32_SPEED_1G: 3363 return (IFM_1000_KX); 3364 case FW_PORT_CAP32_SPEED_10G: 3365 return (IFM_10G_KR); 3366 case FW_PORT_CAP32_SPEED_25G: 3367 return (IFM_25G_KR); 3368 case FW_PORT_CAP32_SPEED_40G: 3369 return (IFM_40G_KR4); 3370 case FW_PORT_CAP32_SPEED_50G: 3371 return (IFM_50G_KR2); 3372 case FW_PORT_CAP32_SPEED_100G: 3373 return (IFM_100G_KR4); 3374 } 3375 break; 3376 case FW_PORT_TYPE_FIBER_XFI: 3377 case FW_PORT_TYPE_FIBER_XAUI: 3378 case FW_PORT_TYPE_SFP: 3379 case FW_PORT_TYPE_QSFP_10G: 3380 case FW_PORT_TYPE_QSA: 3381 case FW_PORT_TYPE_QSFP: 3382 case FW_PORT_TYPE_CR4_QSFP: 3383 case FW_PORT_TYPE_CR_QSFP: 3384 case FW_PORT_TYPE_CR2_QSFP: 3385 case FW_PORT_TYPE_SFP28: 3386 /* Pluggable transceiver */ 3387 switch (pi->mod_type) { 3388 case FW_PORT_MOD_TYPE_LR: 3389 switch (speed) { 3390 case FW_PORT_CAP32_SPEED_1G: 3391 return (IFM_1000_LX); 3392 case FW_PORT_CAP32_SPEED_10G: 3393 return (IFM_10G_LR); 3394 case FW_PORT_CAP32_SPEED_25G: 3395 return (IFM_25G_LR); 3396 case FW_PORT_CAP32_SPEED_40G: 3397 return (IFM_40G_LR4); 3398 case FW_PORT_CAP32_SPEED_50G: 3399 return (IFM_50G_LR2); 3400 case FW_PORT_CAP32_SPEED_100G: 3401 return (IFM_100G_LR4); 3402 } 3403 break; 3404 case FW_PORT_MOD_TYPE_SR: 3405 switch (speed) { 3406 case FW_PORT_CAP32_SPEED_1G: 3407 return (IFM_1000_SX); 3408 case FW_PORT_CAP32_SPEED_10G: 3409 return (IFM_10G_SR); 3410 case FW_PORT_CAP32_SPEED_25G: 3411 return (IFM_25G_SR); 3412 case FW_PORT_CAP32_SPEED_40G: 3413 return (IFM_40G_SR4); 3414 case FW_PORT_CAP32_SPEED_50G: 3415 return (IFM_50G_SR2); 3416 case FW_PORT_CAP32_SPEED_100G: 3417 return (IFM_100G_SR4); 3418 } 3419 break; 3420 case FW_PORT_MOD_TYPE_ER: 3421 if (speed == FW_PORT_CAP32_SPEED_10G) 3422 return (IFM_10G_ER); 3423 break; 3424 case FW_PORT_MOD_TYPE_TWINAX_PASSIVE: 3425 case FW_PORT_MOD_TYPE_TWINAX_ACTIVE: 3426 switch (speed) { 3427 case FW_PORT_CAP32_SPEED_1G: 3428 return (IFM_1000_CX); 3429 case FW_PORT_CAP32_SPEED_10G: 3430 return (IFM_10G_TWINAX); 3431 case FW_PORT_CAP32_SPEED_25G: 3432 return (IFM_25G_CR); 3433 case FW_PORT_CAP32_SPEED_40G: 3434 return (IFM_40G_CR4); 3435 case FW_PORT_CAP32_SPEED_50G: 3436 return (IFM_50G_CR2); 3437 case FW_PORT_CAP32_SPEED_100G: 3438 return (IFM_100G_CR4); 3439 } 3440 break; 3441 case FW_PORT_MOD_TYPE_LRM: 3442 if (speed == FW_PORT_CAP32_SPEED_10G) 3443 return (IFM_10G_LRM); 3444 break; 3445 case FW_PORT_MOD_TYPE_NA: 3446 MPASS(0); /* Not pluggable? */ 3447 /* fall throough */ 3448 case FW_PORT_MOD_TYPE_ERROR: 3449 case FW_PORT_MOD_TYPE_UNKNOWN: 3450 case FW_PORT_MOD_TYPE_NOTSUPPORTED: 3451 break; 3452 case FW_PORT_MOD_TYPE_NONE: 3453 return (IFM_NONE); 3454 } 3455 break; 3456 case FW_PORT_TYPE_NONE: 3457 return (IFM_NONE); 3458 } 3459 3460 return (IFM_UNKNOWN); 3461 } 3462 3463 void 3464 cxgbe_media_status(if_t ifp, struct ifmediareq *ifmr) 3465 { 3466 struct vi_info *vi = if_getsoftc(ifp); 3467 struct port_info *pi = vi->pi; 3468 struct adapter *sc = pi->adapter; 3469 struct link_config *lc = &pi->link_cfg; 3470 3471 if (begin_synchronized_op(sc, vi , SLEEP_OK | INTR_OK, "t4med") != 0) 3472 return; 3473 PORT_LOCK(pi); 3474 3475 if (pi->up_vis == 0 && !hw_off_limits(sc)) { 3476 /* 3477 * If all the interfaces are administratively down the firmware 3478 * does not report transceiver changes. Refresh port info here 3479 * so that ifconfig displays accurate ifmedia at all times. 3480 * This is the only reason we have a synchronized op in this 3481 * function. Just PORT_LOCK would have been enough otherwise. 3482 */ 3483 t4_update_port_info(pi); 3484 build_medialist(pi); 3485 } 3486 3487 /* ifm_status */ 3488 ifmr->ifm_status = IFM_AVALID; 3489 if (lc->link_ok == false) 3490 goto done; 3491 ifmr->ifm_status |= IFM_ACTIVE; 3492 3493 /* ifm_active */ 3494 ifmr->ifm_active = IFM_ETHER | IFM_FDX; 3495 ifmr->ifm_active &= ~(IFM_ETH_TXPAUSE | IFM_ETH_RXPAUSE); 3496 if (lc->fc & PAUSE_RX) 3497 ifmr->ifm_active |= IFM_ETH_RXPAUSE; 3498 if (lc->fc & PAUSE_TX) 3499 ifmr->ifm_active |= IFM_ETH_TXPAUSE; 3500 ifmr->ifm_active |= port_mword(pi, speed_to_fwcap(lc->speed)); 3501 done: 3502 PORT_UNLOCK(pi); 3503 end_synchronized_op(sc, 0); 3504 } 3505 3506 static int 3507 vcxgbe_probe(device_t dev) 3508 { 3509 struct vi_info *vi = device_get_softc(dev); 3510 3511 device_set_descf(dev, "port %d vi %td", vi->pi->port_id, 3512 vi - vi->pi->vi); 3513 3514 return (BUS_PROBE_DEFAULT); 3515 } 3516 3517 static int 3518 alloc_extra_vi(struct adapter *sc, struct port_info *pi, struct vi_info *vi) 3519 { 3520 int func, index, rc; 3521 uint32_t param, val; 3522 3523 ASSERT_SYNCHRONIZED_OP(sc); 3524 3525 index = vi - pi->vi; 3526 MPASS(index > 0); /* This function deals with _extra_ VIs only */ 3527 KASSERT(index < nitems(vi_mac_funcs), 3528 ("%s: VI %s doesn't have a MAC func", __func__, 3529 device_get_nameunit(vi->dev))); 3530 func = vi_mac_funcs[index]; 3531 rc = t4_alloc_vi_func(sc, sc->mbox, pi->tx_chan, sc->pf, 0, 1, 3532 vi->hw_addr, &vi->rss_size, &vi->vfvld, &vi->vin, func, 0); 3533 if (rc < 0) { 3534 CH_ERR(vi, "failed to allocate virtual interface %d" 3535 "for port %d: %d\n", index, pi->port_id, -rc); 3536 return (-rc); 3537 } 3538 vi->viid = rc; 3539 3540 if (vi->rss_size == 1) { 3541 /* 3542 * This VI didn't get a slice of the RSS table. Reduce the 3543 * number of VIs being created (hw.cxgbe.num_vis) or modify the 3544 * configuration file (nvi, rssnvi for this PF) if this is a 3545 * problem. 3546 */ 3547 device_printf(vi->dev, "RSS table not available.\n"); 3548 vi->rss_base = 0xffff; 3549 3550 return (0); 3551 } 3552 3553 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | 3554 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_RSSINFO) | 3555 V_FW_PARAMS_PARAM_YZ(vi->viid); 3556 rc = t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val); 3557 if (rc) 3558 vi->rss_base = 0xffff; 3559 else { 3560 MPASS((val >> 16) == vi->rss_size); 3561 vi->rss_base = val & 0xffff; 3562 } 3563 3564 return (0); 3565 } 3566 3567 static int 3568 vcxgbe_attach(device_t dev) 3569 { 3570 struct vi_info *vi; 3571 struct port_info *pi; 3572 struct adapter *sc; 3573 int rc; 3574 3575 vi = device_get_softc(dev); 3576 pi = vi->pi; 3577 sc = pi->adapter; 3578 3579 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4via"); 3580 if (rc) 3581 return (rc); 3582 rc = alloc_extra_vi(sc, pi, vi); 3583 end_synchronized_op(sc, 0); 3584 if (rc) 3585 return (rc); 3586 3587 rc = cxgbe_vi_attach(dev, vi); 3588 if (rc) { 3589 t4_free_vi(sc, sc->mbox, sc->pf, 0, vi->viid); 3590 return (rc); 3591 } 3592 return (0); 3593 } 3594 3595 static int 3596 vcxgbe_detach(device_t dev) 3597 { 3598 struct vi_info *vi; 3599 struct adapter *sc; 3600 3601 vi = device_get_softc(dev); 3602 sc = vi->adapter; 3603 3604 begin_vi_detach(sc, vi); 3605 cxgbe_vi_detach(vi); 3606 t4_free_vi(sc, sc->mbox, sc->pf, 0, vi->viid); 3607 end_vi_detach(sc, vi); 3608 3609 return (0); 3610 } 3611 3612 static struct callout fatal_callout; 3613 static struct taskqueue *reset_tq; 3614 3615 static void 3616 delayed_panic(void *arg) 3617 { 3618 struct adapter *sc = arg; 3619 3620 panic("%s: panic on fatal error", device_get_nameunit(sc->dev)); 3621 } 3622 3623 static void 3624 fatal_error_task(void *arg, int pending) 3625 { 3626 struct adapter *sc = arg; 3627 int rc; 3628 3629 #ifdef TCP_OFFLOAD 3630 t4_async_event(sc); 3631 #endif 3632 if (atomic_testandclear_int(&sc->error_flags, ilog2(ADAP_CIM_ERR))) { 3633 dump_cim_regs(sc); 3634 dump_cimla(sc); 3635 dump_devlog(sc); 3636 } 3637 3638 if (t4_reset_on_fatal_err) { 3639 CH_ALERT(sc, "resetting on fatal error.\n"); 3640 rc = reset_adapter(sc); 3641 if (rc == 0 && t4_panic_on_fatal_err) { 3642 CH_ALERT(sc, "reset was successful, " 3643 "system will NOT panic.\n"); 3644 return; 3645 } 3646 } 3647 3648 if (t4_panic_on_fatal_err) { 3649 CH_ALERT(sc, "panicking on fatal error (after 30s).\n"); 3650 callout_reset(&fatal_callout, hz * 30, delayed_panic, sc); 3651 } 3652 } 3653 3654 void 3655 t4_fatal_err(struct adapter *sc, bool fw_error) 3656 { 3657 const bool verbose = (sc->debug_flags & DF_VERBOSE_SLOWINTR) != 0; 3658 3659 stop_adapter(sc); 3660 if (atomic_testandset_int(&sc->error_flags, ilog2(ADAP_FATAL_ERR))) 3661 return; 3662 if (fw_error) { 3663 /* 3664 * We are here because of a firmware error/timeout and not 3665 * because of a hardware interrupt. It is possible (although 3666 * not very likely) that an error interrupt was also raised but 3667 * this thread ran first and inhibited t4_intr_err. We walk the 3668 * main INT_CAUSE registers here to make sure we haven't missed 3669 * anything interesting. 3670 */ 3671 t4_slow_intr_handler(sc, verbose); 3672 atomic_set_int(&sc->error_flags, ADAP_CIM_ERR); 3673 } 3674 t4_report_fw_error(sc); 3675 log(LOG_ALERT, "%s: encountered fatal error, adapter stopped (%d).\n", 3676 device_get_nameunit(sc->dev), fw_error); 3677 taskqueue_enqueue(reset_tq, &sc->fatal_error_task); 3678 } 3679 3680 void 3681 t4_add_adapter(struct adapter *sc) 3682 { 3683 sx_xlock(&t4_list_lock); 3684 SLIST_INSERT_HEAD(&t4_list, sc, link); 3685 sx_xunlock(&t4_list_lock); 3686 } 3687 3688 int 3689 t4_map_bars_0_and_4(struct adapter *sc) 3690 { 3691 sc->regs_rid = PCIR_BAR(0); 3692 sc->regs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY, 3693 &sc->regs_rid, RF_ACTIVE); 3694 if (sc->regs_res == NULL) { 3695 device_printf(sc->dev, "cannot map registers.\n"); 3696 return (ENXIO); 3697 } 3698 sc->bt = rman_get_bustag(sc->regs_res); 3699 sc->bh = rman_get_bushandle(sc->regs_res); 3700 sc->mmio_len = rman_get_size(sc->regs_res); 3701 setbit(&sc->doorbells, DOORBELL_KDB); 3702 3703 sc->msix_rid = PCIR_BAR(4); 3704 sc->msix_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY, 3705 &sc->msix_rid, RF_ACTIVE); 3706 if (sc->msix_res == NULL) { 3707 device_printf(sc->dev, "cannot map MSI-X BAR.\n"); 3708 return (ENXIO); 3709 } 3710 3711 return (0); 3712 } 3713 3714 int 3715 t4_map_bar_2(struct adapter *sc) 3716 { 3717 3718 /* 3719 * T4: only iWARP driver uses the userspace doorbells. There is no need 3720 * to map it if RDMA is disabled. 3721 */ 3722 if (is_t4(sc) && sc->rdmacaps == 0) 3723 return (0); 3724 3725 sc->udbs_rid = PCIR_BAR(2); 3726 sc->udbs_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY, 3727 &sc->udbs_rid, RF_ACTIVE); 3728 if (sc->udbs_res == NULL) { 3729 device_printf(sc->dev, "cannot map doorbell BAR.\n"); 3730 return (ENXIO); 3731 } 3732 sc->udbs_base = rman_get_virtual(sc->udbs_res); 3733 3734 if (chip_id(sc) >= CHELSIO_T5) { 3735 setbit(&sc->doorbells, DOORBELL_UDB); 3736 #if defined(__i386__) || defined(__amd64__) 3737 if (t5_write_combine) { 3738 int rc, mode; 3739 3740 /* 3741 * Enable write combining on BAR2. This is the 3742 * userspace doorbell BAR and is split into 128B 3743 * (UDBS_SEG_SIZE) doorbell regions, each associated 3744 * with an egress queue. The first 64B has the doorbell 3745 * and the second 64B can be used to submit a tx work 3746 * request with an implicit doorbell. 3747 */ 3748 3749 rc = pmap_change_attr((vm_offset_t)sc->udbs_base, 3750 rman_get_size(sc->udbs_res), PAT_WRITE_COMBINING); 3751 if (rc == 0) { 3752 clrbit(&sc->doorbells, DOORBELL_UDB); 3753 setbit(&sc->doorbells, DOORBELL_WCWR); 3754 setbit(&sc->doorbells, DOORBELL_UDBWC); 3755 } else { 3756 device_printf(sc->dev, 3757 "couldn't enable write combining: %d\n", 3758 rc); 3759 } 3760 3761 mode = is_t5(sc) ? V_STATMODE(0) : V_T6_STATMODE(0); 3762 t4_write_reg(sc, A_SGE_STAT_CFG, 3763 V_STATSOURCE_T5(7) | mode); 3764 } 3765 #endif 3766 } 3767 sc->iwt.wc_en = isset(&sc->doorbells, DOORBELL_UDBWC) ? 1 : 0; 3768 3769 return (0); 3770 } 3771 3772 int 3773 t4_adj_doorbells(struct adapter *sc) 3774 { 3775 if ((sc->doorbells & t4_doorbells_allowed) != 0) { 3776 sc->doorbells &= t4_doorbells_allowed; 3777 return (0); 3778 } 3779 CH_ERR(sc, "No usable doorbell (available = 0x%x, allowed = 0x%x).\n", 3780 sc->doorbells, t4_doorbells_allowed); 3781 return (EINVAL); 3782 } 3783 3784 struct memwin_init { 3785 uint32_t base; 3786 uint32_t aperture; 3787 }; 3788 3789 static const struct memwin_init t4_memwin[NUM_MEMWIN] = { 3790 { MEMWIN0_BASE, MEMWIN0_APERTURE }, 3791 { MEMWIN1_BASE, MEMWIN1_APERTURE }, 3792 { MEMWIN2_BASE_T4, MEMWIN2_APERTURE_T4 } 3793 }; 3794 3795 static const struct memwin_init t5_memwin[NUM_MEMWIN] = { 3796 { MEMWIN0_BASE, MEMWIN0_APERTURE }, 3797 { MEMWIN1_BASE, MEMWIN1_APERTURE }, 3798 { MEMWIN2_BASE_T5, MEMWIN2_APERTURE_T5 }, 3799 }; 3800 3801 static void 3802 setup_memwin(struct adapter *sc) 3803 { 3804 const struct memwin_init *mw_init; 3805 struct memwin *mw; 3806 int i; 3807 uint32_t bar0; 3808 3809 if (is_t4(sc)) { 3810 /* 3811 * Read low 32b of bar0 indirectly via the hardware backdoor 3812 * mechanism. Works from within PCI passthrough environments 3813 * too, where rman_get_start() can return a different value. We 3814 * need to program the T4 memory window decoders with the actual 3815 * addresses that will be coming across the PCIe link. 3816 */ 3817 bar0 = t4_hw_pci_read_cfg4(sc, PCIR_BAR(0)); 3818 bar0 &= (uint32_t) PCIM_BAR_MEM_BASE; 3819 3820 mw_init = &t4_memwin[0]; 3821 } else { 3822 /* T5+ use the relative offset inside the PCIe BAR */ 3823 bar0 = 0; 3824 3825 mw_init = &t5_memwin[0]; 3826 } 3827 3828 for (i = 0, mw = &sc->memwin[0]; i < NUM_MEMWIN; i++, mw_init++, mw++) { 3829 if (!rw_initialized(&mw->mw_lock)) { 3830 rw_init(&mw->mw_lock, "memory window access"); 3831 mw->mw_base = mw_init->base; 3832 mw->mw_aperture = mw_init->aperture; 3833 mw->mw_curpos = 0; 3834 } 3835 t4_write_reg(sc, 3836 PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, i), 3837 (mw->mw_base + bar0) | V_BIR(0) | 3838 V_WINDOW(ilog2(mw->mw_aperture) - 10)); 3839 rw_wlock(&mw->mw_lock); 3840 position_memwin(sc, i, mw->mw_curpos); 3841 rw_wunlock(&mw->mw_lock); 3842 } 3843 3844 /* flush */ 3845 t4_read_reg(sc, PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_BASE_WIN, 2)); 3846 } 3847 3848 /* 3849 * Positions the memory window at the given address in the card's address space. 3850 * There are some alignment requirements and the actual position may be at an 3851 * address prior to the requested address. mw->mw_curpos always has the actual 3852 * position of the window. 3853 */ 3854 static void 3855 position_memwin(struct adapter *sc, int idx, uint32_t addr) 3856 { 3857 struct memwin *mw; 3858 uint32_t pf; 3859 uint32_t reg; 3860 3861 MPASS(idx >= 0 && idx < NUM_MEMWIN); 3862 mw = &sc->memwin[idx]; 3863 rw_assert(&mw->mw_lock, RA_WLOCKED); 3864 3865 if (is_t4(sc)) { 3866 pf = 0; 3867 mw->mw_curpos = addr & ~0xf; /* start must be 16B aligned */ 3868 } else { 3869 pf = V_PFNUM(sc->pf); 3870 mw->mw_curpos = addr & ~0x7f; /* start must be 128B aligned */ 3871 } 3872 reg = PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, idx); 3873 t4_write_reg(sc, reg, mw->mw_curpos | pf); 3874 t4_read_reg(sc, reg); /* flush */ 3875 } 3876 3877 int 3878 rw_via_memwin(struct adapter *sc, int idx, uint32_t addr, uint32_t *val, 3879 int len, int rw) 3880 { 3881 struct memwin *mw; 3882 uint32_t mw_end, v; 3883 3884 MPASS(idx >= 0 && idx < NUM_MEMWIN); 3885 3886 /* Memory can only be accessed in naturally aligned 4 byte units */ 3887 if (addr & 3 || len & 3 || len <= 0) 3888 return (EINVAL); 3889 3890 mw = &sc->memwin[idx]; 3891 while (len > 0) { 3892 rw_rlock(&mw->mw_lock); 3893 mw_end = mw->mw_curpos + mw->mw_aperture; 3894 if (addr >= mw_end || addr < mw->mw_curpos) { 3895 /* Will need to reposition the window */ 3896 if (!rw_try_upgrade(&mw->mw_lock)) { 3897 rw_runlock(&mw->mw_lock); 3898 rw_wlock(&mw->mw_lock); 3899 } 3900 rw_assert(&mw->mw_lock, RA_WLOCKED); 3901 position_memwin(sc, idx, addr); 3902 rw_downgrade(&mw->mw_lock); 3903 mw_end = mw->mw_curpos + mw->mw_aperture; 3904 } 3905 rw_assert(&mw->mw_lock, RA_RLOCKED); 3906 while (addr < mw_end && len > 0) { 3907 if (rw == 0) { 3908 v = t4_read_reg(sc, mw->mw_base + addr - 3909 mw->mw_curpos); 3910 *val++ = le32toh(v); 3911 } else { 3912 v = *val++; 3913 t4_write_reg(sc, mw->mw_base + addr - 3914 mw->mw_curpos, htole32(v)); 3915 } 3916 addr += 4; 3917 len -= 4; 3918 } 3919 rw_runlock(&mw->mw_lock); 3920 } 3921 3922 return (0); 3923 } 3924 3925 CTASSERT(M_TID_COOKIE == M_COOKIE); 3926 CTASSERT(MAX_ATIDS <= (M_TID_TID + 1)); 3927 3928 static void 3929 t4_init_atid_table(struct adapter *sc) 3930 { 3931 struct tid_info *t; 3932 int i; 3933 3934 t = &sc->tids; 3935 if (t->natids == 0) 3936 return; 3937 3938 MPASS(t->atid_tab == NULL); 3939 3940 t->atid_tab = malloc(t->natids * sizeof(*t->atid_tab), M_CXGBE, 3941 M_ZERO | M_WAITOK); 3942 mtx_init(&t->atid_lock, "atid lock", NULL, MTX_DEF); 3943 t->afree = t->atid_tab; 3944 t->atids_in_use = 0; 3945 for (i = 1; i < t->natids; i++) 3946 t->atid_tab[i - 1].next = &t->atid_tab[i]; 3947 t->atid_tab[t->natids - 1].next = NULL; 3948 } 3949 3950 static void 3951 t4_free_atid_table(struct adapter *sc) 3952 { 3953 struct tid_info *t; 3954 3955 t = &sc->tids; 3956 3957 KASSERT(t->atids_in_use == 0, 3958 ("%s: %d atids still in use.", __func__, t->atids_in_use)); 3959 3960 if (mtx_initialized(&t->atid_lock)) 3961 mtx_destroy(&t->atid_lock); 3962 free(t->atid_tab, M_CXGBE); 3963 t->atid_tab = NULL; 3964 } 3965 3966 int 3967 alloc_atid(struct adapter *sc, void *ctx) 3968 { 3969 struct tid_info *t = &sc->tids; 3970 int atid = -1; 3971 3972 mtx_lock(&t->atid_lock); 3973 if (t->afree) { 3974 union aopen_entry *p = t->afree; 3975 3976 atid = p - t->atid_tab; 3977 MPASS(atid <= M_TID_TID); 3978 t->afree = p->next; 3979 p->data = ctx; 3980 t->atids_in_use++; 3981 } 3982 mtx_unlock(&t->atid_lock); 3983 return (atid); 3984 } 3985 3986 void * 3987 lookup_atid(struct adapter *sc, int atid) 3988 { 3989 struct tid_info *t = &sc->tids; 3990 3991 return (t->atid_tab[atid].data); 3992 } 3993 3994 void 3995 free_atid(struct adapter *sc, int atid) 3996 { 3997 struct tid_info *t = &sc->tids; 3998 union aopen_entry *p = &t->atid_tab[atid]; 3999 4000 mtx_lock(&t->atid_lock); 4001 p->next = t->afree; 4002 t->afree = p; 4003 t->atids_in_use--; 4004 mtx_unlock(&t->atid_lock); 4005 } 4006 4007 static void 4008 queue_tid_release(struct adapter *sc, int tid) 4009 { 4010 4011 CXGBE_UNIMPLEMENTED("deferred tid release"); 4012 } 4013 4014 void 4015 release_tid(struct adapter *sc, int tid, struct sge_wrq *ctrlq) 4016 { 4017 struct wrqe *wr; 4018 struct cpl_tid_release *req; 4019 4020 wr = alloc_wrqe(sizeof(*req), ctrlq); 4021 if (wr == NULL) { 4022 queue_tid_release(sc, tid); /* defer */ 4023 return; 4024 } 4025 req = wrtod(wr); 4026 4027 INIT_TP_WR_MIT_CPL(req, CPL_TID_RELEASE, tid); 4028 4029 t4_wrq_tx(sc, wr); 4030 } 4031 4032 static int 4033 t4_range_cmp(const void *a, const void *b) 4034 { 4035 return ((const struct t4_range *)a)->start - 4036 ((const struct t4_range *)b)->start; 4037 } 4038 4039 /* 4040 * Verify that the memory range specified by the addr/len pair is valid within 4041 * the card's address space. 4042 */ 4043 static int 4044 validate_mem_range(struct adapter *sc, uint32_t addr, uint32_t len) 4045 { 4046 struct t4_range mem_ranges[4], *r, *next; 4047 uint32_t em, addr_len; 4048 int i, n, remaining; 4049 4050 /* Memory can only be accessed in naturally aligned 4 byte units */ 4051 if (addr & 3 || len & 3 || len == 0) 4052 return (EINVAL); 4053 4054 /* Enabled memories */ 4055 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE); 4056 4057 r = &mem_ranges[0]; 4058 n = 0; 4059 bzero(r, sizeof(mem_ranges)); 4060 if (em & F_EDRAM0_ENABLE) { 4061 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR); 4062 r->size = G_EDRAM0_SIZE(addr_len) << 20; 4063 if (r->size > 0) { 4064 r->start = G_EDRAM0_BASE(addr_len) << 20; 4065 if (addr >= r->start && 4066 addr + len <= r->start + r->size) 4067 return (0); 4068 r++; 4069 n++; 4070 } 4071 } 4072 if (em & F_EDRAM1_ENABLE) { 4073 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR); 4074 r->size = G_EDRAM1_SIZE(addr_len) << 20; 4075 if (r->size > 0) { 4076 r->start = G_EDRAM1_BASE(addr_len) << 20; 4077 if (addr >= r->start && 4078 addr + len <= r->start + r->size) 4079 return (0); 4080 r++; 4081 n++; 4082 } 4083 } 4084 if (em & F_EXT_MEM_ENABLE) { 4085 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR); 4086 r->size = G_EXT_MEM_SIZE(addr_len) << 20; 4087 if (r->size > 0) { 4088 r->start = G_EXT_MEM_BASE(addr_len) << 20; 4089 if (addr >= r->start && 4090 addr + len <= r->start + r->size) 4091 return (0); 4092 r++; 4093 n++; 4094 } 4095 } 4096 if (is_t5(sc) && em & F_EXT_MEM1_ENABLE) { 4097 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR); 4098 r->size = G_EXT_MEM1_SIZE(addr_len) << 20; 4099 if (r->size > 0) { 4100 r->start = G_EXT_MEM1_BASE(addr_len) << 20; 4101 if (addr >= r->start && 4102 addr + len <= r->start + r->size) 4103 return (0); 4104 r++; 4105 n++; 4106 } 4107 } 4108 MPASS(n <= nitems(mem_ranges)); 4109 4110 if (n > 1) { 4111 /* Sort and merge the ranges. */ 4112 qsort(mem_ranges, n, sizeof(struct t4_range), t4_range_cmp); 4113 4114 /* Start from index 0 and examine the next n - 1 entries. */ 4115 r = &mem_ranges[0]; 4116 for (remaining = n - 1; remaining > 0; remaining--, r++) { 4117 4118 MPASS(r->size > 0); /* r is a valid entry. */ 4119 next = r + 1; 4120 MPASS(next->size > 0); /* and so is the next one. */ 4121 4122 while (r->start + r->size >= next->start) { 4123 /* Merge the next one into the current entry. */ 4124 r->size = max(r->start + r->size, 4125 next->start + next->size) - r->start; 4126 n--; /* One fewer entry in total. */ 4127 if (--remaining == 0) 4128 goto done; /* short circuit */ 4129 next++; 4130 } 4131 if (next != r + 1) { 4132 /* 4133 * Some entries were merged into r and next 4134 * points to the first valid entry that couldn't 4135 * be merged. 4136 */ 4137 MPASS(next->size > 0); /* must be valid */ 4138 memcpy(r + 1, next, remaining * sizeof(*r)); 4139 #ifdef INVARIANTS 4140 /* 4141 * This so that the foo->size assertion in the 4142 * next iteration of the loop do the right 4143 * thing for entries that were pulled up and are 4144 * no longer valid. 4145 */ 4146 MPASS(n < nitems(mem_ranges)); 4147 bzero(&mem_ranges[n], (nitems(mem_ranges) - n) * 4148 sizeof(struct t4_range)); 4149 #endif 4150 } 4151 } 4152 done: 4153 /* Done merging the ranges. */ 4154 MPASS(n > 0); 4155 r = &mem_ranges[0]; 4156 for (i = 0; i < n; i++, r++) { 4157 if (addr >= r->start && 4158 addr + len <= r->start + r->size) 4159 return (0); 4160 } 4161 } 4162 4163 return (EFAULT); 4164 } 4165 4166 static int 4167 fwmtype_to_hwmtype(int mtype) 4168 { 4169 4170 switch (mtype) { 4171 case FW_MEMTYPE_EDC0: 4172 return (MEM_EDC0); 4173 case FW_MEMTYPE_EDC1: 4174 return (MEM_EDC1); 4175 case FW_MEMTYPE_EXTMEM: 4176 return (MEM_MC0); 4177 case FW_MEMTYPE_EXTMEM1: 4178 return (MEM_MC1); 4179 default: 4180 panic("%s: cannot translate fw mtype %d.", __func__, mtype); 4181 } 4182 } 4183 4184 /* 4185 * Verify that the memory range specified by the memtype/offset/len pair is 4186 * valid and lies entirely within the memtype specified. The global address of 4187 * the start of the range is returned in addr. 4188 */ 4189 static int 4190 validate_mt_off_len(struct adapter *sc, int mtype, uint32_t off, uint32_t len, 4191 uint32_t *addr) 4192 { 4193 uint32_t em, addr_len, maddr; 4194 4195 /* Memory can only be accessed in naturally aligned 4 byte units */ 4196 if (off & 3 || len & 3 || len == 0) 4197 return (EINVAL); 4198 4199 em = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE); 4200 switch (fwmtype_to_hwmtype(mtype)) { 4201 case MEM_EDC0: 4202 if (!(em & F_EDRAM0_ENABLE)) 4203 return (EINVAL); 4204 addr_len = t4_read_reg(sc, A_MA_EDRAM0_BAR); 4205 maddr = G_EDRAM0_BASE(addr_len) << 20; 4206 break; 4207 case MEM_EDC1: 4208 if (!(em & F_EDRAM1_ENABLE)) 4209 return (EINVAL); 4210 addr_len = t4_read_reg(sc, A_MA_EDRAM1_BAR); 4211 maddr = G_EDRAM1_BASE(addr_len) << 20; 4212 break; 4213 case MEM_MC: 4214 if (!(em & F_EXT_MEM_ENABLE)) 4215 return (EINVAL); 4216 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR); 4217 maddr = G_EXT_MEM_BASE(addr_len) << 20; 4218 break; 4219 case MEM_MC1: 4220 if (!is_t5(sc) || !(em & F_EXT_MEM1_ENABLE)) 4221 return (EINVAL); 4222 addr_len = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR); 4223 maddr = G_EXT_MEM1_BASE(addr_len) << 20; 4224 break; 4225 default: 4226 return (EINVAL); 4227 } 4228 4229 *addr = maddr + off; /* global address */ 4230 return (validate_mem_range(sc, *addr, len)); 4231 } 4232 4233 static int 4234 fixup_devlog_params(struct adapter *sc) 4235 { 4236 struct devlog_params *dparams = &sc->params.devlog; 4237 int rc; 4238 4239 rc = validate_mt_off_len(sc, dparams->memtype, dparams->start, 4240 dparams->size, &dparams->addr); 4241 4242 return (rc); 4243 } 4244 4245 static void 4246 update_nirq(struct intrs_and_queues *iaq, int nports) 4247 { 4248 4249 iaq->nirq = T4_EXTRA_INTR; 4250 iaq->nirq += nports * max(iaq->nrxq, iaq->nnmrxq); 4251 iaq->nirq += nports * iaq->nofldrxq; 4252 iaq->nirq += nports * (iaq->num_vis - 1) * 4253 max(iaq->nrxq_vi, iaq->nnmrxq_vi); 4254 iaq->nirq += nports * (iaq->num_vis - 1) * iaq->nofldrxq_vi; 4255 } 4256 4257 /* 4258 * Adjust requirements to fit the number of interrupts available. 4259 */ 4260 static void 4261 calculate_iaq(struct adapter *sc, struct intrs_and_queues *iaq, int itype, 4262 int navail) 4263 { 4264 int old_nirq; 4265 const int nports = sc->params.nports; 4266 4267 MPASS(nports > 0); 4268 MPASS(navail > 0); 4269 4270 bzero(iaq, sizeof(*iaq)); 4271 iaq->intr_type = itype; 4272 iaq->num_vis = t4_num_vis; 4273 iaq->ntxq = t4_ntxq; 4274 iaq->ntxq_vi = t4_ntxq_vi; 4275 iaq->nrxq = t4_nrxq; 4276 iaq->nrxq_vi = t4_nrxq_vi; 4277 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 4278 if (is_offload(sc) || is_ethoffload(sc)) { 4279 iaq->nofldtxq = t4_nofldtxq; 4280 iaq->nofldtxq_vi = t4_nofldtxq_vi; 4281 } 4282 #endif 4283 #ifdef TCP_OFFLOAD 4284 if (is_offload(sc)) { 4285 iaq->nofldrxq = t4_nofldrxq; 4286 iaq->nofldrxq_vi = t4_nofldrxq_vi; 4287 } 4288 #endif 4289 #ifdef DEV_NETMAP 4290 if (t4_native_netmap & NN_MAIN_VI) { 4291 iaq->nnmtxq = t4_nnmtxq; 4292 iaq->nnmrxq = t4_nnmrxq; 4293 } 4294 if (t4_native_netmap & NN_EXTRA_VI) { 4295 iaq->nnmtxq_vi = t4_nnmtxq_vi; 4296 iaq->nnmrxq_vi = t4_nnmrxq_vi; 4297 } 4298 #endif 4299 4300 update_nirq(iaq, nports); 4301 if (iaq->nirq <= navail && 4302 (itype != INTR_MSI || powerof2(iaq->nirq))) { 4303 /* 4304 * This is the normal case -- there are enough interrupts for 4305 * everything. 4306 */ 4307 goto done; 4308 } 4309 4310 /* 4311 * If extra VIs have been configured try reducing their count and see if 4312 * that works. 4313 */ 4314 while (iaq->num_vis > 1) { 4315 iaq->num_vis--; 4316 update_nirq(iaq, nports); 4317 if (iaq->nirq <= navail && 4318 (itype != INTR_MSI || powerof2(iaq->nirq))) { 4319 device_printf(sc->dev, "virtual interfaces per port " 4320 "reduced to %d from %d. nrxq=%u, nofldrxq=%u, " 4321 "nrxq_vi=%u nofldrxq_vi=%u, nnmrxq_vi=%u. " 4322 "itype %d, navail %u, nirq %d.\n", 4323 iaq->num_vis, t4_num_vis, iaq->nrxq, iaq->nofldrxq, 4324 iaq->nrxq_vi, iaq->nofldrxq_vi, iaq->nnmrxq_vi, 4325 itype, navail, iaq->nirq); 4326 goto done; 4327 } 4328 } 4329 4330 /* 4331 * Extra VIs will not be created. Log a message if they were requested. 4332 */ 4333 MPASS(iaq->num_vis == 1); 4334 iaq->ntxq_vi = iaq->nrxq_vi = 0; 4335 iaq->nofldtxq_vi = iaq->nofldrxq_vi = 0; 4336 iaq->nnmtxq_vi = iaq->nnmrxq_vi = 0; 4337 if (iaq->num_vis != t4_num_vis) { 4338 device_printf(sc->dev, "extra virtual interfaces disabled. " 4339 "nrxq=%u, nofldrxq=%u, nrxq_vi=%u nofldrxq_vi=%u, " 4340 "nnmrxq_vi=%u. itype %d, navail %u, nirq %d.\n", 4341 iaq->nrxq, iaq->nofldrxq, iaq->nrxq_vi, iaq->nofldrxq_vi, 4342 iaq->nnmrxq_vi, itype, navail, iaq->nirq); 4343 } 4344 4345 /* 4346 * Keep reducing the number of NIC rx queues to the next lower power of 4347 * 2 (for even RSS distribution) and halving the TOE rx queues and see 4348 * if that works. 4349 */ 4350 do { 4351 if (iaq->nrxq > 1) { 4352 iaq->nrxq = rounddown_pow_of_two(iaq->nrxq - 1); 4353 if (iaq->nnmrxq > iaq->nrxq) 4354 iaq->nnmrxq = iaq->nrxq; 4355 } 4356 if (iaq->nofldrxq > 1) 4357 iaq->nofldrxq >>= 1; 4358 4359 old_nirq = iaq->nirq; 4360 update_nirq(iaq, nports); 4361 if (iaq->nirq <= navail && 4362 (itype != INTR_MSI || powerof2(iaq->nirq))) { 4363 device_printf(sc->dev, "running with reduced number of " 4364 "rx queues because of shortage of interrupts. " 4365 "nrxq=%u, nofldrxq=%u. " 4366 "itype %d, navail %u, nirq %d.\n", iaq->nrxq, 4367 iaq->nofldrxq, itype, navail, iaq->nirq); 4368 goto done; 4369 } 4370 } while (old_nirq != iaq->nirq); 4371 4372 /* One interrupt for everything. Ugh. */ 4373 device_printf(sc->dev, "running with minimal number of queues. " 4374 "itype %d, navail %u.\n", itype, navail); 4375 iaq->nirq = 1; 4376 iaq->nrxq = 1; 4377 iaq->ntxq = 1; 4378 if (iaq->nofldrxq > 0) { 4379 iaq->nofldrxq = 1; 4380 iaq->nofldtxq = 1; 4381 } 4382 iaq->nnmtxq = 0; 4383 iaq->nnmrxq = 0; 4384 done: 4385 MPASS(iaq->num_vis > 0); 4386 if (iaq->num_vis > 1) { 4387 MPASS(iaq->nrxq_vi > 0); 4388 MPASS(iaq->ntxq_vi > 0); 4389 } 4390 MPASS(iaq->nirq > 0); 4391 MPASS(iaq->nrxq > 0); 4392 MPASS(iaq->ntxq > 0); 4393 if (itype == INTR_MSI) { 4394 MPASS(powerof2(iaq->nirq)); 4395 } 4396 } 4397 4398 static int 4399 cfg_itype_and_nqueues(struct adapter *sc, struct intrs_and_queues *iaq) 4400 { 4401 int rc, itype, navail, nalloc; 4402 4403 for (itype = INTR_MSIX; itype; itype >>= 1) { 4404 4405 if ((itype & t4_intr_types) == 0) 4406 continue; /* not allowed */ 4407 4408 if (itype == INTR_MSIX) 4409 navail = pci_msix_count(sc->dev); 4410 else if (itype == INTR_MSI) 4411 navail = pci_msi_count(sc->dev); 4412 else 4413 navail = 1; 4414 restart: 4415 if (navail == 0) 4416 continue; 4417 4418 calculate_iaq(sc, iaq, itype, navail); 4419 nalloc = iaq->nirq; 4420 rc = 0; 4421 if (itype == INTR_MSIX) 4422 rc = pci_alloc_msix(sc->dev, &nalloc); 4423 else if (itype == INTR_MSI) 4424 rc = pci_alloc_msi(sc->dev, &nalloc); 4425 4426 if (rc == 0 && nalloc > 0) { 4427 if (nalloc == iaq->nirq) 4428 return (0); 4429 4430 /* 4431 * Didn't get the number requested. Use whatever number 4432 * the kernel is willing to allocate. 4433 */ 4434 device_printf(sc->dev, "fewer vectors than requested, " 4435 "type=%d, req=%d, rcvd=%d; will downshift req.\n", 4436 itype, iaq->nirq, nalloc); 4437 pci_release_msi(sc->dev); 4438 navail = nalloc; 4439 goto restart; 4440 } 4441 4442 device_printf(sc->dev, 4443 "failed to allocate vectors:%d, type=%d, req=%d, rcvd=%d\n", 4444 itype, rc, iaq->nirq, nalloc); 4445 } 4446 4447 device_printf(sc->dev, 4448 "failed to find a usable interrupt type. " 4449 "allowed=%d, msi-x=%d, msi=%d, intx=1", t4_intr_types, 4450 pci_msix_count(sc->dev), pci_msi_count(sc->dev)); 4451 4452 return (ENXIO); 4453 } 4454 4455 #define FW_VERSION(chip) ( \ 4456 V_FW_HDR_FW_VER_MAJOR(chip##FW_VERSION_MAJOR) | \ 4457 V_FW_HDR_FW_VER_MINOR(chip##FW_VERSION_MINOR) | \ 4458 V_FW_HDR_FW_VER_MICRO(chip##FW_VERSION_MICRO) | \ 4459 V_FW_HDR_FW_VER_BUILD(chip##FW_VERSION_BUILD)) 4460 #define FW_INTFVER(chip, intf) (chip##FW_HDR_INTFVER_##intf) 4461 4462 /* Just enough of fw_hdr to cover all version info. */ 4463 struct fw_h { 4464 __u8 ver; 4465 __u8 chip; 4466 __be16 len512; 4467 __be32 fw_ver; 4468 __be32 tp_microcode_ver; 4469 __u8 intfver_nic; 4470 __u8 intfver_vnic; 4471 __u8 intfver_ofld; 4472 __u8 intfver_ri; 4473 __u8 intfver_iscsipdu; 4474 __u8 intfver_iscsi; 4475 __u8 intfver_fcoepdu; 4476 __u8 intfver_fcoe; 4477 }; 4478 /* Spot check a couple of fields. */ 4479 CTASSERT(offsetof(struct fw_h, fw_ver) == offsetof(struct fw_hdr, fw_ver)); 4480 CTASSERT(offsetof(struct fw_h, intfver_nic) == offsetof(struct fw_hdr, intfver_nic)); 4481 CTASSERT(offsetof(struct fw_h, intfver_fcoe) == offsetof(struct fw_hdr, intfver_fcoe)); 4482 4483 struct fw_info { 4484 uint8_t chip; 4485 char *kld_name; 4486 char *fw_mod_name; 4487 struct fw_h fw_h; 4488 } fw_info[] = { 4489 { 4490 .chip = CHELSIO_T4, 4491 .kld_name = "t4fw_cfg", 4492 .fw_mod_name = "t4fw", 4493 .fw_h = { 4494 .chip = FW_HDR_CHIP_T4, 4495 .fw_ver = htobe32(FW_VERSION(T4)), 4496 .intfver_nic = FW_INTFVER(T4, NIC), 4497 .intfver_vnic = FW_INTFVER(T4, VNIC), 4498 .intfver_ofld = FW_INTFVER(T4, OFLD), 4499 .intfver_ri = FW_INTFVER(T4, RI), 4500 .intfver_iscsipdu = FW_INTFVER(T4, ISCSIPDU), 4501 .intfver_iscsi = FW_INTFVER(T4, ISCSI), 4502 .intfver_fcoepdu = FW_INTFVER(T4, FCOEPDU), 4503 .intfver_fcoe = FW_INTFVER(T4, FCOE), 4504 }, 4505 }, { 4506 .chip = CHELSIO_T5, 4507 .kld_name = "t5fw_cfg", 4508 .fw_mod_name = "t5fw", 4509 .fw_h = { 4510 .chip = FW_HDR_CHIP_T5, 4511 .fw_ver = htobe32(FW_VERSION(T5)), 4512 .intfver_nic = FW_INTFVER(T5, NIC), 4513 .intfver_vnic = FW_INTFVER(T5, VNIC), 4514 .intfver_ofld = FW_INTFVER(T5, OFLD), 4515 .intfver_ri = FW_INTFVER(T5, RI), 4516 .intfver_iscsipdu = FW_INTFVER(T5, ISCSIPDU), 4517 .intfver_iscsi = FW_INTFVER(T5, ISCSI), 4518 .intfver_fcoepdu = FW_INTFVER(T5, FCOEPDU), 4519 .intfver_fcoe = FW_INTFVER(T5, FCOE), 4520 }, 4521 }, { 4522 .chip = CHELSIO_T6, 4523 .kld_name = "t6fw_cfg", 4524 .fw_mod_name = "t6fw", 4525 .fw_h = { 4526 .chip = FW_HDR_CHIP_T6, 4527 .fw_ver = htobe32(FW_VERSION(T6)), 4528 .intfver_nic = FW_INTFVER(T6, NIC), 4529 .intfver_vnic = FW_INTFVER(T6, VNIC), 4530 .intfver_ofld = FW_INTFVER(T6, OFLD), 4531 .intfver_ri = FW_INTFVER(T6, RI), 4532 .intfver_iscsipdu = FW_INTFVER(T6, ISCSIPDU), 4533 .intfver_iscsi = FW_INTFVER(T6, ISCSI), 4534 .intfver_fcoepdu = FW_INTFVER(T6, FCOEPDU), 4535 .intfver_fcoe = FW_INTFVER(T6, FCOE), 4536 }, 4537 } 4538 }; 4539 4540 static struct fw_info * 4541 find_fw_info(int chip) 4542 { 4543 int i; 4544 4545 for (i = 0; i < nitems(fw_info); i++) { 4546 if (fw_info[i].chip == chip) 4547 return (&fw_info[i]); 4548 } 4549 return (NULL); 4550 } 4551 4552 /* 4553 * Is the given firmware API compatible with the one the driver was compiled 4554 * with? 4555 */ 4556 static int 4557 fw_compatible(const struct fw_h *hdr1, const struct fw_h *hdr2) 4558 { 4559 4560 /* short circuit if it's the exact same firmware version */ 4561 if (hdr1->chip == hdr2->chip && hdr1->fw_ver == hdr2->fw_ver) 4562 return (1); 4563 4564 /* 4565 * XXX: Is this too conservative? Perhaps I should limit this to the 4566 * features that are supported in the driver. 4567 */ 4568 #define SAME_INTF(x) (hdr1->intfver_##x == hdr2->intfver_##x) 4569 if (hdr1->chip == hdr2->chip && SAME_INTF(nic) && SAME_INTF(vnic) && 4570 SAME_INTF(ofld) && SAME_INTF(ri) && SAME_INTF(iscsipdu) && 4571 SAME_INTF(iscsi) && SAME_INTF(fcoepdu) && SAME_INTF(fcoe)) 4572 return (1); 4573 #undef SAME_INTF 4574 4575 return (0); 4576 } 4577 4578 static int 4579 load_fw_module(struct adapter *sc, const struct firmware **dcfg, 4580 const struct firmware **fw) 4581 { 4582 struct fw_info *fw_info; 4583 4584 *dcfg = NULL; 4585 if (fw != NULL) 4586 *fw = NULL; 4587 4588 fw_info = find_fw_info(chip_id(sc)); 4589 if (fw_info == NULL) { 4590 device_printf(sc->dev, 4591 "unable to look up firmware information for chip %d.\n", 4592 chip_id(sc)); 4593 return (EINVAL); 4594 } 4595 4596 *dcfg = firmware_get(fw_info->kld_name); 4597 if (*dcfg != NULL) { 4598 if (fw != NULL) 4599 *fw = firmware_get(fw_info->fw_mod_name); 4600 return (0); 4601 } 4602 4603 return (ENOENT); 4604 } 4605 4606 static void 4607 unload_fw_module(struct adapter *sc, const struct firmware *dcfg, 4608 const struct firmware *fw) 4609 { 4610 4611 if (fw != NULL) 4612 firmware_put(fw, FIRMWARE_UNLOAD); 4613 if (dcfg != NULL) 4614 firmware_put(dcfg, FIRMWARE_UNLOAD); 4615 } 4616 4617 /* 4618 * Return values: 4619 * 0 means no firmware install attempted. 4620 * ERESTART means a firmware install was attempted and was successful. 4621 * +ve errno means a firmware install was attempted but failed. 4622 */ 4623 static int 4624 install_kld_firmware(struct adapter *sc, struct fw_h *card_fw, 4625 const struct fw_h *drv_fw, const char *reason, int *already) 4626 { 4627 const struct firmware *cfg, *fw; 4628 const uint32_t c = be32toh(card_fw->fw_ver); 4629 uint32_t d, k; 4630 int rc, fw_install; 4631 struct fw_h bundled_fw; 4632 bool load_attempted; 4633 4634 cfg = fw = NULL; 4635 load_attempted = false; 4636 fw_install = t4_fw_install < 0 ? -t4_fw_install : t4_fw_install; 4637 4638 memcpy(&bundled_fw, drv_fw, sizeof(bundled_fw)); 4639 if (t4_fw_install < 0) { 4640 rc = load_fw_module(sc, &cfg, &fw); 4641 if (rc != 0 || fw == NULL) { 4642 device_printf(sc->dev, 4643 "failed to load firmware module: %d. cfg %p, fw %p;" 4644 " will use compiled-in firmware version for" 4645 "hw.cxgbe.fw_install checks.\n", 4646 rc, cfg, fw); 4647 } else { 4648 memcpy(&bundled_fw, fw->data, sizeof(bundled_fw)); 4649 } 4650 load_attempted = true; 4651 } 4652 d = be32toh(bundled_fw.fw_ver); 4653 4654 if (reason != NULL) 4655 goto install; 4656 4657 if ((sc->flags & FW_OK) == 0) { 4658 4659 if (c == 0xffffffff) { 4660 reason = "missing"; 4661 goto install; 4662 } 4663 4664 rc = 0; 4665 goto done; 4666 } 4667 4668 if (!fw_compatible(card_fw, &bundled_fw)) { 4669 reason = "incompatible or unusable"; 4670 goto install; 4671 } 4672 4673 if (d > c) { 4674 reason = "older than the version bundled with this driver"; 4675 goto install; 4676 } 4677 4678 if (fw_install == 2 && d != c) { 4679 reason = "different than the version bundled with this driver"; 4680 goto install; 4681 } 4682 4683 /* No reason to do anything to the firmware already on the card. */ 4684 rc = 0; 4685 goto done; 4686 4687 install: 4688 rc = 0; 4689 if ((*already)++) 4690 goto done; 4691 4692 if (fw_install == 0) { 4693 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, " 4694 "but the driver is prohibited from installing a firmware " 4695 "on the card.\n", 4696 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c), 4697 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason); 4698 4699 goto done; 4700 } 4701 4702 /* 4703 * We'll attempt to install a firmware. Load the module first (if it 4704 * hasn't been loaded already). 4705 */ 4706 if (!load_attempted) { 4707 rc = load_fw_module(sc, &cfg, &fw); 4708 if (rc != 0 || fw == NULL) { 4709 device_printf(sc->dev, 4710 "failed to load firmware module: %d. cfg %p, fw %p\n", 4711 rc, cfg, fw); 4712 /* carry on */ 4713 } 4714 } 4715 if (fw == NULL) { 4716 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, " 4717 "but the driver cannot take corrective action because it " 4718 "is unable to load the firmware module.\n", 4719 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c), 4720 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason); 4721 rc = sc->flags & FW_OK ? 0 : ENOENT; 4722 goto done; 4723 } 4724 k = be32toh(((const struct fw_hdr *)fw->data)->fw_ver); 4725 if (k != d) { 4726 MPASS(t4_fw_install > 0); 4727 device_printf(sc->dev, 4728 "firmware in KLD (%u.%u.%u.%u) is not what the driver was " 4729 "expecting (%u.%u.%u.%u) and will not be used.\n", 4730 G_FW_HDR_FW_VER_MAJOR(k), G_FW_HDR_FW_VER_MINOR(k), 4731 G_FW_HDR_FW_VER_MICRO(k), G_FW_HDR_FW_VER_BUILD(k), 4732 G_FW_HDR_FW_VER_MAJOR(d), G_FW_HDR_FW_VER_MINOR(d), 4733 G_FW_HDR_FW_VER_MICRO(d), G_FW_HDR_FW_VER_BUILD(d)); 4734 rc = sc->flags & FW_OK ? 0 : EINVAL; 4735 goto done; 4736 } 4737 4738 device_printf(sc->dev, "firmware on card (%u.%u.%u.%u) is %s, " 4739 "installing firmware %u.%u.%u.%u on card.\n", 4740 G_FW_HDR_FW_VER_MAJOR(c), G_FW_HDR_FW_VER_MINOR(c), 4741 G_FW_HDR_FW_VER_MICRO(c), G_FW_HDR_FW_VER_BUILD(c), reason, 4742 G_FW_HDR_FW_VER_MAJOR(d), G_FW_HDR_FW_VER_MINOR(d), 4743 G_FW_HDR_FW_VER_MICRO(d), G_FW_HDR_FW_VER_BUILD(d)); 4744 4745 rc = -t4_fw_upgrade(sc, sc->mbox, fw->data, fw->datasize, 0); 4746 if (rc != 0) { 4747 device_printf(sc->dev, "failed to install firmware: %d\n", rc); 4748 } else { 4749 /* Installed successfully, update the cached header too. */ 4750 rc = ERESTART; 4751 memcpy(card_fw, fw->data, sizeof(*card_fw)); 4752 } 4753 done: 4754 unload_fw_module(sc, cfg, fw); 4755 4756 return (rc); 4757 } 4758 4759 /* 4760 * Establish contact with the firmware and attempt to become the master driver. 4761 * 4762 * A firmware will be installed to the card if needed (if the driver is allowed 4763 * to do so). 4764 */ 4765 static int 4766 contact_firmware(struct adapter *sc) 4767 { 4768 int rc, already = 0; 4769 enum dev_state state; 4770 struct fw_info *fw_info; 4771 struct fw_hdr *card_fw; /* fw on the card */ 4772 const struct fw_h *drv_fw; 4773 4774 fw_info = find_fw_info(chip_id(sc)); 4775 if (fw_info == NULL) { 4776 device_printf(sc->dev, 4777 "unable to look up firmware information for chip %d.\n", 4778 chip_id(sc)); 4779 return (EINVAL); 4780 } 4781 drv_fw = &fw_info->fw_h; 4782 4783 /* Read the header of the firmware on the card */ 4784 card_fw = malloc(sizeof(*card_fw), M_CXGBE, M_ZERO | M_WAITOK); 4785 restart: 4786 rc = -t4_get_fw_hdr(sc, card_fw); 4787 if (rc != 0) { 4788 device_printf(sc->dev, 4789 "unable to read firmware header from card's flash: %d\n", 4790 rc); 4791 goto done; 4792 } 4793 4794 rc = install_kld_firmware(sc, (struct fw_h *)card_fw, drv_fw, NULL, 4795 &already); 4796 if (rc == ERESTART) 4797 goto restart; 4798 if (rc != 0) 4799 goto done; 4800 4801 rc = t4_fw_hello(sc, sc->mbox, sc->mbox, MASTER_MAY, &state); 4802 if (rc < 0 || state == DEV_STATE_ERR) { 4803 rc = -rc; 4804 device_printf(sc->dev, 4805 "failed to connect to the firmware: %d, %d. " 4806 "PCIE_FW 0x%08x\n", rc, state, t4_read_reg(sc, A_PCIE_FW)); 4807 #if 0 4808 if (install_kld_firmware(sc, (struct fw_h *)card_fw, drv_fw, 4809 "not responding properly to HELLO", &already) == ERESTART) 4810 goto restart; 4811 #endif 4812 goto done; 4813 } 4814 MPASS(be32toh(card_fw->flags) & FW_HDR_FLAGS_RESET_HALT); 4815 sc->flags |= FW_OK; /* The firmware responded to the FW_HELLO. */ 4816 4817 if (rc == sc->pf) { 4818 sc->flags |= MASTER_PF; 4819 rc = install_kld_firmware(sc, (struct fw_h *)card_fw, drv_fw, 4820 NULL, &already); 4821 if (rc == ERESTART) 4822 rc = 0; 4823 else if (rc != 0) 4824 goto done; 4825 } else if (state == DEV_STATE_UNINIT) { 4826 /* 4827 * We didn't get to be the master so we definitely won't be 4828 * configuring the chip. It's a bug if someone else hasn't 4829 * configured it already. 4830 */ 4831 device_printf(sc->dev, "couldn't be master(%d), " 4832 "device not already initialized either(%d). " 4833 "PCIE_FW 0x%08x\n", rc, state, t4_read_reg(sc, A_PCIE_FW)); 4834 rc = EPROTO; 4835 goto done; 4836 } else { 4837 /* 4838 * Some other PF is the master and has configured the chip. 4839 * This is allowed but untested. 4840 */ 4841 device_printf(sc->dev, "PF%d is master, device state %d. " 4842 "PCIE_FW 0x%08x\n", rc, state, t4_read_reg(sc, A_PCIE_FW)); 4843 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "pf%d", rc); 4844 sc->cfcsum = 0; 4845 rc = 0; 4846 } 4847 done: 4848 if (rc != 0 && sc->flags & FW_OK) { 4849 t4_fw_bye(sc, sc->mbox); 4850 sc->flags &= ~FW_OK; 4851 } 4852 free(card_fw, M_CXGBE); 4853 return (rc); 4854 } 4855 4856 static int 4857 copy_cfg_file_to_card(struct adapter *sc, char *cfg_file, 4858 uint32_t mtype, uint32_t moff) 4859 { 4860 struct fw_info *fw_info; 4861 const struct firmware *dcfg, *rcfg = NULL; 4862 const uint32_t *cfdata; 4863 uint32_t cflen, addr; 4864 int rc; 4865 4866 load_fw_module(sc, &dcfg, NULL); 4867 4868 /* Card specific interpretation of "default". */ 4869 if (strncmp(cfg_file, DEFAULT_CF, sizeof(t4_cfg_file)) == 0) { 4870 if (pci_get_device(sc->dev) == 0x440a) 4871 snprintf(cfg_file, sizeof(t4_cfg_file), UWIRE_CF); 4872 if (is_fpga(sc)) 4873 snprintf(cfg_file, sizeof(t4_cfg_file), FPGA_CF); 4874 } 4875 4876 if (strncmp(cfg_file, DEFAULT_CF, sizeof(t4_cfg_file)) == 0) { 4877 if (dcfg == NULL) { 4878 device_printf(sc->dev, 4879 "KLD with default config is not available.\n"); 4880 rc = ENOENT; 4881 goto done; 4882 } 4883 cfdata = dcfg->data; 4884 cflen = dcfg->datasize & ~3; 4885 } else { 4886 char s[32]; 4887 4888 fw_info = find_fw_info(chip_id(sc)); 4889 if (fw_info == NULL) { 4890 device_printf(sc->dev, 4891 "unable to look up firmware information for chip %d.\n", 4892 chip_id(sc)); 4893 rc = EINVAL; 4894 goto done; 4895 } 4896 snprintf(s, sizeof(s), "%s_%s", fw_info->kld_name, cfg_file); 4897 4898 rcfg = firmware_get(s); 4899 if (rcfg == NULL) { 4900 device_printf(sc->dev, 4901 "unable to load module \"%s\" for configuration " 4902 "profile \"%s\".\n", s, cfg_file); 4903 rc = ENOENT; 4904 goto done; 4905 } 4906 cfdata = rcfg->data; 4907 cflen = rcfg->datasize & ~3; 4908 } 4909 4910 if (cflen > FLASH_CFG_MAX_SIZE) { 4911 device_printf(sc->dev, 4912 "config file too long (%d, max allowed is %d).\n", 4913 cflen, FLASH_CFG_MAX_SIZE); 4914 rc = EINVAL; 4915 goto done; 4916 } 4917 4918 rc = validate_mt_off_len(sc, mtype, moff, cflen, &addr); 4919 if (rc != 0) { 4920 device_printf(sc->dev, 4921 "%s: addr (%d/0x%x) or len %d is not valid: %d.\n", 4922 __func__, mtype, moff, cflen, rc); 4923 rc = EINVAL; 4924 goto done; 4925 } 4926 write_via_memwin(sc, 2, addr, cfdata, cflen); 4927 done: 4928 if (rcfg != NULL) 4929 firmware_put(rcfg, FIRMWARE_UNLOAD); 4930 unload_fw_module(sc, dcfg, NULL); 4931 return (rc); 4932 } 4933 4934 struct caps_allowed { 4935 uint16_t nbmcaps; 4936 uint16_t linkcaps; 4937 uint16_t switchcaps; 4938 uint16_t niccaps; 4939 uint16_t toecaps; 4940 uint16_t rdmacaps; 4941 uint16_t cryptocaps; 4942 uint16_t iscsicaps; 4943 uint16_t fcoecaps; 4944 }; 4945 4946 #define FW_PARAM_DEV(param) \ 4947 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \ 4948 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param)) 4949 #define FW_PARAM_PFVF(param) \ 4950 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \ 4951 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param)) 4952 4953 /* 4954 * Provide a configuration profile to the firmware and have it initialize the 4955 * chip accordingly. This may involve uploading a configuration file to the 4956 * card. 4957 */ 4958 static int 4959 apply_cfg_and_initialize(struct adapter *sc, char *cfg_file, 4960 const struct caps_allowed *caps_allowed) 4961 { 4962 int rc; 4963 struct fw_caps_config_cmd caps; 4964 uint32_t mtype, moff, finicsum, cfcsum, param, val; 4965 4966 rc = -t4_fw_reset(sc, sc->mbox, F_PIORSTMODE | F_PIORST); 4967 if (rc != 0) { 4968 device_printf(sc->dev, "firmware reset failed: %d.\n", rc); 4969 return (rc); 4970 } 4971 4972 bzero(&caps, sizeof(caps)); 4973 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) | 4974 F_FW_CMD_REQUEST | F_FW_CMD_READ); 4975 if (strncmp(cfg_file, BUILTIN_CF, sizeof(t4_cfg_file)) == 0) { 4976 mtype = 0; 4977 moff = 0; 4978 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps)); 4979 } else if (strncmp(cfg_file, FLASH_CF, sizeof(t4_cfg_file)) == 0) { 4980 mtype = FW_MEMTYPE_FLASH; 4981 moff = t4_flash_cfg_addr(sc); 4982 caps.cfvalid_to_len16 = htobe32(F_FW_CAPS_CONFIG_CMD_CFVALID | 4983 V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) | 4984 V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(moff >> 16) | 4985 FW_LEN16(caps)); 4986 } else { 4987 /* 4988 * Ask the firmware where it wants us to upload the config file. 4989 */ 4990 param = FW_PARAM_DEV(CF); 4991 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val); 4992 if (rc != 0) { 4993 /* No support for config file? Shouldn't happen. */ 4994 device_printf(sc->dev, 4995 "failed to query config file location: %d.\n", rc); 4996 goto done; 4997 } 4998 mtype = G_FW_PARAMS_PARAM_Y(val); 4999 moff = G_FW_PARAMS_PARAM_Z(val) << 16; 5000 caps.cfvalid_to_len16 = htobe32(F_FW_CAPS_CONFIG_CMD_CFVALID | 5001 V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) | 5002 V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(moff >> 16) | 5003 FW_LEN16(caps)); 5004 5005 rc = copy_cfg_file_to_card(sc, cfg_file, mtype, moff); 5006 if (rc != 0) { 5007 device_printf(sc->dev, 5008 "failed to upload config file to card: %d.\n", rc); 5009 goto done; 5010 } 5011 } 5012 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps); 5013 if (rc != 0) { 5014 device_printf(sc->dev, "failed to pre-process config file: %d " 5015 "(mtype %d, moff 0x%x).\n", rc, mtype, moff); 5016 goto done; 5017 } 5018 5019 finicsum = be32toh(caps.finicsum); 5020 cfcsum = be32toh(caps.cfcsum); /* actual */ 5021 if (finicsum != cfcsum) { 5022 device_printf(sc->dev, 5023 "WARNING: config file checksum mismatch: %08x %08x\n", 5024 finicsum, cfcsum); 5025 } 5026 sc->cfcsum = cfcsum; 5027 snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", cfg_file); 5028 5029 /* 5030 * Let the firmware know what features will (not) be used so it can tune 5031 * things accordingly. 5032 */ 5033 #define LIMIT_CAPS(x) do { \ 5034 caps.x##caps &= htobe16(caps_allowed->x##caps); \ 5035 } while (0) 5036 LIMIT_CAPS(nbm); 5037 LIMIT_CAPS(link); 5038 LIMIT_CAPS(switch); 5039 LIMIT_CAPS(nic); 5040 LIMIT_CAPS(toe); 5041 LIMIT_CAPS(rdma); 5042 LIMIT_CAPS(crypto); 5043 LIMIT_CAPS(iscsi); 5044 LIMIT_CAPS(fcoe); 5045 #undef LIMIT_CAPS 5046 if (caps.niccaps & htobe16(FW_CAPS_CONFIG_NIC_HASHFILTER)) { 5047 /* 5048 * TOE and hashfilters are mutually exclusive. It is a config 5049 * file or firmware bug if both are reported as available. Try 5050 * to cope with the situation in non-debug builds by disabling 5051 * TOE. 5052 */ 5053 MPASS(caps.toecaps == 0); 5054 5055 caps.toecaps = 0; 5056 caps.rdmacaps = 0; 5057 caps.iscsicaps = 0; 5058 } 5059 5060 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) | 5061 F_FW_CMD_REQUEST | F_FW_CMD_WRITE); 5062 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps)); 5063 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), NULL); 5064 if (rc != 0) { 5065 device_printf(sc->dev, 5066 "failed to process config file: %d.\n", rc); 5067 goto done; 5068 } 5069 5070 t4_tweak_chip_settings(sc); 5071 set_params__pre_init(sc); 5072 5073 /* get basic stuff going */ 5074 rc = -t4_fw_initialize(sc, sc->mbox); 5075 if (rc != 0) { 5076 device_printf(sc->dev, "fw_initialize failed: %d.\n", rc); 5077 goto done; 5078 } 5079 done: 5080 return (rc); 5081 } 5082 5083 /* 5084 * Partition chip resources for use between various PFs, VFs, etc. 5085 */ 5086 static int 5087 partition_resources(struct adapter *sc) 5088 { 5089 char cfg_file[sizeof(t4_cfg_file)]; 5090 struct caps_allowed caps_allowed; 5091 int rc; 5092 bool fallback; 5093 5094 /* Only the master driver gets to configure the chip resources. */ 5095 MPASS(sc->flags & MASTER_PF); 5096 5097 #define COPY_CAPS(x) do { \ 5098 caps_allowed.x##caps = t4_##x##caps_allowed; \ 5099 } while (0) 5100 bzero(&caps_allowed, sizeof(caps_allowed)); 5101 COPY_CAPS(nbm); 5102 COPY_CAPS(link); 5103 COPY_CAPS(switch); 5104 COPY_CAPS(nic); 5105 COPY_CAPS(toe); 5106 COPY_CAPS(rdma); 5107 COPY_CAPS(crypto); 5108 COPY_CAPS(iscsi); 5109 COPY_CAPS(fcoe); 5110 fallback = sc->debug_flags & DF_DISABLE_CFG_RETRY ? false : true; 5111 snprintf(cfg_file, sizeof(cfg_file), "%s", t4_cfg_file); 5112 retry: 5113 rc = apply_cfg_and_initialize(sc, cfg_file, &caps_allowed); 5114 if (rc != 0 && fallback) { 5115 dump_devlog(sc); 5116 device_printf(sc->dev, 5117 "failed (%d) to configure card with \"%s\" profile, " 5118 "will fall back to a basic configuration and retry.\n", 5119 rc, cfg_file); 5120 snprintf(cfg_file, sizeof(cfg_file), "%s", BUILTIN_CF); 5121 bzero(&caps_allowed, sizeof(caps_allowed)); 5122 COPY_CAPS(switch); 5123 caps_allowed.niccaps = FW_CAPS_CONFIG_NIC; 5124 fallback = false; 5125 goto retry; 5126 } 5127 #undef COPY_CAPS 5128 return (rc); 5129 } 5130 5131 /* 5132 * Retrieve parameters that are needed (or nice to have) very early. 5133 */ 5134 static int 5135 get_params__pre_init(struct adapter *sc) 5136 { 5137 int rc; 5138 uint32_t param[2], val[2]; 5139 5140 t4_get_version_info(sc); 5141 5142 snprintf(sc->fw_version, sizeof(sc->fw_version), "%u.%u.%u.%u", 5143 G_FW_HDR_FW_VER_MAJOR(sc->params.fw_vers), 5144 G_FW_HDR_FW_VER_MINOR(sc->params.fw_vers), 5145 G_FW_HDR_FW_VER_MICRO(sc->params.fw_vers), 5146 G_FW_HDR_FW_VER_BUILD(sc->params.fw_vers)); 5147 5148 snprintf(sc->bs_version, sizeof(sc->bs_version), "%u.%u.%u.%u", 5149 G_FW_HDR_FW_VER_MAJOR(sc->params.bs_vers), 5150 G_FW_HDR_FW_VER_MINOR(sc->params.bs_vers), 5151 G_FW_HDR_FW_VER_MICRO(sc->params.bs_vers), 5152 G_FW_HDR_FW_VER_BUILD(sc->params.bs_vers)); 5153 5154 snprintf(sc->tp_version, sizeof(sc->tp_version), "%u.%u.%u.%u", 5155 G_FW_HDR_FW_VER_MAJOR(sc->params.tp_vers), 5156 G_FW_HDR_FW_VER_MINOR(sc->params.tp_vers), 5157 G_FW_HDR_FW_VER_MICRO(sc->params.tp_vers), 5158 G_FW_HDR_FW_VER_BUILD(sc->params.tp_vers)); 5159 5160 snprintf(sc->er_version, sizeof(sc->er_version), "%u.%u.%u.%u", 5161 G_FW_HDR_FW_VER_MAJOR(sc->params.er_vers), 5162 G_FW_HDR_FW_VER_MINOR(sc->params.er_vers), 5163 G_FW_HDR_FW_VER_MICRO(sc->params.er_vers), 5164 G_FW_HDR_FW_VER_BUILD(sc->params.er_vers)); 5165 5166 param[0] = FW_PARAM_DEV(PORTVEC); 5167 param[1] = FW_PARAM_DEV(CCLK); 5168 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val); 5169 if (rc != 0) { 5170 device_printf(sc->dev, 5171 "failed to query parameters (pre_init): %d.\n", rc); 5172 return (rc); 5173 } 5174 5175 sc->params.portvec = val[0]; 5176 sc->params.nports = bitcount32(val[0]); 5177 sc->params.vpd.cclk = val[1]; 5178 5179 /* Read device log parameters. */ 5180 rc = -t4_init_devlog_params(sc, 1); 5181 if (rc == 0) 5182 fixup_devlog_params(sc); 5183 else { 5184 device_printf(sc->dev, 5185 "failed to get devlog parameters: %d.\n", rc); 5186 rc = 0; /* devlog isn't critical for device operation */ 5187 } 5188 5189 return (rc); 5190 } 5191 5192 /* 5193 * Any params that need to be set before FW_INITIALIZE. 5194 */ 5195 static int 5196 set_params__pre_init(struct adapter *sc) 5197 { 5198 int rc = 0; 5199 uint32_t param, val; 5200 5201 if (chip_id(sc) >= CHELSIO_T6) { 5202 param = FW_PARAM_DEV(HPFILTER_REGION_SUPPORT); 5203 val = 1; 5204 rc = -t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val); 5205 /* firmwares < 1.20.1.0 do not have this param. */ 5206 if (rc == FW_EINVAL && 5207 sc->params.fw_vers < FW_VERSION32(1, 20, 1, 0)) { 5208 rc = 0; 5209 } 5210 if (rc != 0) { 5211 device_printf(sc->dev, 5212 "failed to enable high priority filters :%d.\n", 5213 rc); 5214 } 5215 5216 param = FW_PARAM_DEV(PPOD_EDRAM); 5217 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val); 5218 if (rc == 0 && val == 1) { 5219 rc = -t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, 5220 &val); 5221 if (rc != 0) { 5222 device_printf(sc->dev, 5223 "failed to set PPOD_EDRAM: %d.\n", rc); 5224 } 5225 } 5226 } 5227 5228 /* Enable opaque VIIDs with firmwares that support it. */ 5229 param = FW_PARAM_DEV(OPAQUE_VIID_SMT_EXTN); 5230 val = 1; 5231 rc = -t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val); 5232 if (rc == 0 && val == 1) 5233 sc->params.viid_smt_extn_support = true; 5234 else 5235 sc->params.viid_smt_extn_support = false; 5236 5237 return (rc); 5238 } 5239 5240 /* 5241 * Retrieve various parameters that are of interest to the driver. The device 5242 * has been initialized by the firmware at this point. 5243 */ 5244 static int 5245 get_params__post_init(struct adapter *sc) 5246 { 5247 int rc; 5248 uint32_t param[7], val[7]; 5249 struct fw_caps_config_cmd caps; 5250 5251 param[0] = FW_PARAM_PFVF(IQFLINT_START); 5252 param[1] = FW_PARAM_PFVF(EQ_START); 5253 param[2] = FW_PARAM_PFVF(FILTER_START); 5254 param[3] = FW_PARAM_PFVF(FILTER_END); 5255 param[4] = FW_PARAM_PFVF(L2T_START); 5256 param[5] = FW_PARAM_PFVF(L2T_END); 5257 param[6] = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | 5258 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) | 5259 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_VDD); 5260 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 7, param, val); 5261 if (rc != 0) { 5262 device_printf(sc->dev, 5263 "failed to query parameters (post_init): %d.\n", rc); 5264 return (rc); 5265 } 5266 5267 sc->sge.iq_start = val[0]; 5268 sc->sge.eq_start = val[1]; 5269 if ((int)val[3] > (int)val[2]) { 5270 sc->tids.ftid_base = val[2]; 5271 sc->tids.ftid_end = val[3]; 5272 sc->tids.nftids = val[3] - val[2] + 1; 5273 } 5274 sc->vres.l2t.start = val[4]; 5275 sc->vres.l2t.size = val[5] - val[4] + 1; 5276 KASSERT(sc->vres.l2t.size <= L2T_SIZE, 5277 ("%s: L2 table size (%u) larger than expected (%u)", 5278 __func__, sc->vres.l2t.size, L2T_SIZE)); 5279 sc->params.core_vdd = val[6]; 5280 5281 param[0] = FW_PARAM_PFVF(IQFLINT_END); 5282 param[1] = FW_PARAM_PFVF(EQ_END); 5283 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val); 5284 if (rc != 0) { 5285 device_printf(sc->dev, 5286 "failed to query parameters (post_init2): %d.\n", rc); 5287 return (rc); 5288 } 5289 MPASS((int)val[0] >= sc->sge.iq_start); 5290 sc->sge.iqmap_sz = val[0] - sc->sge.iq_start + 1; 5291 MPASS((int)val[1] >= sc->sge.eq_start); 5292 sc->sge.eqmap_sz = val[1] - sc->sge.eq_start + 1; 5293 5294 if (chip_id(sc) >= CHELSIO_T6) { 5295 5296 sc->tids.tid_base = t4_read_reg(sc, 5297 A_LE_DB_ACTIVE_TABLE_START_INDEX); 5298 5299 param[0] = FW_PARAM_PFVF(HPFILTER_START); 5300 param[1] = FW_PARAM_PFVF(HPFILTER_END); 5301 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val); 5302 if (rc != 0) { 5303 device_printf(sc->dev, 5304 "failed to query hpfilter parameters: %d.\n", rc); 5305 return (rc); 5306 } 5307 if ((int)val[1] > (int)val[0]) { 5308 sc->tids.hpftid_base = val[0]; 5309 sc->tids.hpftid_end = val[1]; 5310 sc->tids.nhpftids = val[1] - val[0] + 1; 5311 5312 /* 5313 * These should go off if the layout changes and the 5314 * driver needs to catch up. 5315 */ 5316 MPASS(sc->tids.hpftid_base == 0); 5317 MPASS(sc->tids.tid_base == sc->tids.nhpftids); 5318 } 5319 5320 param[0] = FW_PARAM_PFVF(RAWF_START); 5321 param[1] = FW_PARAM_PFVF(RAWF_END); 5322 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val); 5323 if (rc != 0) { 5324 device_printf(sc->dev, 5325 "failed to query rawf parameters: %d.\n", rc); 5326 return (rc); 5327 } 5328 if ((int)val[1] > (int)val[0]) { 5329 sc->rawf_base = val[0]; 5330 sc->nrawf = val[1] - val[0] + 1; 5331 } 5332 } 5333 5334 /* 5335 * The parameters that follow may not be available on all firmwares. We 5336 * query them individually rather than in a compound query because old 5337 * firmwares fail the entire query if an unknown parameter is queried. 5338 */ 5339 5340 /* 5341 * MPS buffer group configuration. 5342 */ 5343 param[0] = FW_PARAM_DEV(MPSBGMAP); 5344 val[0] = 0; 5345 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val); 5346 if (rc == 0) 5347 sc->params.mps_bg_map = val[0]; 5348 else 5349 sc->params.mps_bg_map = UINT32_MAX; /* Not a legal value. */ 5350 5351 param[0] = FW_PARAM_DEV(TPCHMAP); 5352 val[0] = 0; 5353 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val); 5354 if (rc == 0) 5355 sc->params.tp_ch_map = val[0]; 5356 else 5357 sc->params.tp_ch_map = UINT32_MAX; /* Not a legal value. */ 5358 5359 /* 5360 * Determine whether the firmware supports the filter2 work request. 5361 */ 5362 param[0] = FW_PARAM_DEV(FILTER2_WR); 5363 val[0] = 0; 5364 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val); 5365 if (rc == 0) 5366 sc->params.filter2_wr_support = val[0] != 0; 5367 else 5368 sc->params.filter2_wr_support = 0; 5369 5370 /* 5371 * Find out whether we're allowed to use the ULPTX MEMWRITE DSGL. 5372 */ 5373 param[0] = FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL); 5374 val[0] = 0; 5375 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val); 5376 if (rc == 0) 5377 sc->params.ulptx_memwrite_dsgl = val[0] != 0; 5378 else 5379 sc->params.ulptx_memwrite_dsgl = false; 5380 5381 /* FW_RI_FR_NSMR_TPTE_WR support */ 5382 param[0] = FW_PARAM_DEV(RI_FR_NSMR_TPTE_WR); 5383 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val); 5384 if (rc == 0) 5385 sc->params.fr_nsmr_tpte_wr_support = val[0] != 0; 5386 else 5387 sc->params.fr_nsmr_tpte_wr_support = false; 5388 5389 /* Support for 512 SGL entries per FR MR. */ 5390 param[0] = FW_PARAM_DEV(DEV_512SGL_MR); 5391 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val); 5392 if (rc == 0) 5393 sc->params.dev_512sgl_mr = val[0] != 0; 5394 else 5395 sc->params.dev_512sgl_mr = false; 5396 5397 param[0] = FW_PARAM_PFVF(MAX_PKTS_PER_ETH_TX_PKTS_WR); 5398 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val); 5399 if (rc == 0) 5400 sc->params.max_pkts_per_eth_tx_pkts_wr = val[0]; 5401 else 5402 sc->params.max_pkts_per_eth_tx_pkts_wr = 15; 5403 5404 param[0] = FW_PARAM_DEV(NUM_TM_CLASS); 5405 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val); 5406 if (rc == 0) { 5407 MPASS(val[0] > 0 && val[0] < 256); /* nsched_cls is 8b */ 5408 sc->params.nsched_cls = val[0]; 5409 } else 5410 sc->params.nsched_cls = sc->chip_params->nsched_cls; 5411 5412 /* get capabilites */ 5413 bzero(&caps, sizeof(caps)); 5414 caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) | 5415 F_FW_CMD_REQUEST | F_FW_CMD_READ); 5416 caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps)); 5417 rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps); 5418 if (rc != 0) { 5419 device_printf(sc->dev, 5420 "failed to get card capabilities: %d.\n", rc); 5421 return (rc); 5422 } 5423 5424 #define READ_CAPS(x) do { \ 5425 sc->x = htobe16(caps.x); \ 5426 } while (0) 5427 READ_CAPS(nbmcaps); 5428 READ_CAPS(linkcaps); 5429 READ_CAPS(switchcaps); 5430 READ_CAPS(niccaps); 5431 READ_CAPS(toecaps); 5432 READ_CAPS(rdmacaps); 5433 READ_CAPS(cryptocaps); 5434 READ_CAPS(iscsicaps); 5435 READ_CAPS(fcoecaps); 5436 5437 if (sc->niccaps & FW_CAPS_CONFIG_NIC_HASHFILTER) { 5438 MPASS(chip_id(sc) > CHELSIO_T4); 5439 MPASS(sc->toecaps == 0); 5440 sc->toecaps = 0; 5441 5442 param[0] = FW_PARAM_DEV(NTID); 5443 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, param, val); 5444 if (rc != 0) { 5445 device_printf(sc->dev, 5446 "failed to query HASHFILTER parameters: %d.\n", rc); 5447 return (rc); 5448 } 5449 sc->tids.ntids = val[0]; 5450 if (sc->params.fw_vers < FW_VERSION32(1, 20, 5, 0)) { 5451 MPASS(sc->tids.ntids >= sc->tids.nhpftids); 5452 sc->tids.ntids -= sc->tids.nhpftids; 5453 } 5454 sc->tids.natids = min(sc->tids.ntids / 2, MAX_ATIDS); 5455 sc->params.hash_filter = 1; 5456 } 5457 if (sc->niccaps & FW_CAPS_CONFIG_NIC_ETHOFLD) { 5458 param[0] = FW_PARAM_PFVF(ETHOFLD_START); 5459 param[1] = FW_PARAM_PFVF(ETHOFLD_END); 5460 param[2] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ); 5461 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 3, param, val); 5462 if (rc != 0) { 5463 device_printf(sc->dev, 5464 "failed to query NIC parameters: %d.\n", rc); 5465 return (rc); 5466 } 5467 if ((int)val[1] > (int)val[0]) { 5468 sc->tids.etid_base = val[0]; 5469 sc->tids.etid_end = val[1]; 5470 sc->tids.netids = val[1] - val[0] + 1; 5471 sc->params.eo_wr_cred = val[2]; 5472 sc->params.ethoffload = 1; 5473 } 5474 } 5475 if (sc->toecaps) { 5476 /* query offload-related parameters */ 5477 param[0] = FW_PARAM_DEV(NTID); 5478 param[1] = FW_PARAM_PFVF(SERVER_START); 5479 param[2] = FW_PARAM_PFVF(SERVER_END); 5480 param[3] = FW_PARAM_PFVF(TDDP_START); 5481 param[4] = FW_PARAM_PFVF(TDDP_END); 5482 param[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ); 5483 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val); 5484 if (rc != 0) { 5485 device_printf(sc->dev, 5486 "failed to query TOE parameters: %d.\n", rc); 5487 return (rc); 5488 } 5489 sc->tids.ntids = val[0]; 5490 if (sc->params.fw_vers < FW_VERSION32(1, 20, 5, 0)) { 5491 MPASS(sc->tids.ntids >= sc->tids.nhpftids); 5492 sc->tids.ntids -= sc->tids.nhpftids; 5493 } 5494 sc->tids.natids = min(sc->tids.ntids / 2, MAX_ATIDS); 5495 if ((int)val[2] > (int)val[1]) { 5496 sc->tids.stid_base = val[1]; 5497 sc->tids.nstids = val[2] - val[1] + 1; 5498 } 5499 sc->vres.ddp.start = val[3]; 5500 sc->vres.ddp.size = val[4] - val[3] + 1; 5501 sc->params.ofldq_wr_cred = val[5]; 5502 sc->params.offload = 1; 5503 } else { 5504 /* 5505 * The firmware attempts memfree TOE configuration for -SO cards 5506 * and will report toecaps=0 if it runs out of resources (this 5507 * depends on the config file). It may not report 0 for other 5508 * capabilities dependent on the TOE in this case. Set them to 5509 * 0 here so that the driver doesn't bother tracking resources 5510 * that will never be used. 5511 */ 5512 sc->iscsicaps = 0; 5513 sc->rdmacaps = 0; 5514 } 5515 if (sc->rdmacaps) { 5516 param[0] = FW_PARAM_PFVF(STAG_START); 5517 param[1] = FW_PARAM_PFVF(STAG_END); 5518 param[2] = FW_PARAM_PFVF(RQ_START); 5519 param[3] = FW_PARAM_PFVF(RQ_END); 5520 param[4] = FW_PARAM_PFVF(PBL_START); 5521 param[5] = FW_PARAM_PFVF(PBL_END); 5522 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val); 5523 if (rc != 0) { 5524 device_printf(sc->dev, 5525 "failed to query RDMA parameters(1): %d.\n", rc); 5526 return (rc); 5527 } 5528 sc->vres.stag.start = val[0]; 5529 sc->vres.stag.size = val[1] - val[0] + 1; 5530 sc->vres.rq.start = val[2]; 5531 sc->vres.rq.size = val[3] - val[2] + 1; 5532 sc->vres.pbl.start = val[4]; 5533 sc->vres.pbl.size = val[5] - val[4] + 1; 5534 5535 param[0] = FW_PARAM_PFVF(SQRQ_START); 5536 param[1] = FW_PARAM_PFVF(SQRQ_END); 5537 param[2] = FW_PARAM_PFVF(CQ_START); 5538 param[3] = FW_PARAM_PFVF(CQ_END); 5539 param[4] = FW_PARAM_PFVF(OCQ_START); 5540 param[5] = FW_PARAM_PFVF(OCQ_END); 5541 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 6, param, val); 5542 if (rc != 0) { 5543 device_printf(sc->dev, 5544 "failed to query RDMA parameters(2): %d.\n", rc); 5545 return (rc); 5546 } 5547 sc->vres.qp.start = val[0]; 5548 sc->vres.qp.size = val[1] - val[0] + 1; 5549 sc->vres.cq.start = val[2]; 5550 sc->vres.cq.size = val[3] - val[2] + 1; 5551 sc->vres.ocq.start = val[4]; 5552 sc->vres.ocq.size = val[5] - val[4] + 1; 5553 5554 param[0] = FW_PARAM_PFVF(SRQ_START); 5555 param[1] = FW_PARAM_PFVF(SRQ_END); 5556 param[2] = FW_PARAM_DEV(MAXORDIRD_QP); 5557 param[3] = FW_PARAM_DEV(MAXIRD_ADAPTER); 5558 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 4, param, val); 5559 if (rc != 0) { 5560 device_printf(sc->dev, 5561 "failed to query RDMA parameters(3): %d.\n", rc); 5562 return (rc); 5563 } 5564 sc->vres.srq.start = val[0]; 5565 sc->vres.srq.size = val[1] - val[0] + 1; 5566 sc->params.max_ordird_qp = val[2]; 5567 sc->params.max_ird_adapter = val[3]; 5568 } 5569 if (sc->iscsicaps) { 5570 param[0] = FW_PARAM_PFVF(ISCSI_START); 5571 param[1] = FW_PARAM_PFVF(ISCSI_END); 5572 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val); 5573 if (rc != 0) { 5574 device_printf(sc->dev, 5575 "failed to query iSCSI parameters: %d.\n", rc); 5576 return (rc); 5577 } 5578 sc->vres.iscsi.start = val[0]; 5579 sc->vres.iscsi.size = val[1] - val[0] + 1; 5580 } 5581 if (sc->cryptocaps & FW_CAPS_CONFIG_TLSKEYS) { 5582 param[0] = FW_PARAM_PFVF(TLS_START); 5583 param[1] = FW_PARAM_PFVF(TLS_END); 5584 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 2, param, val); 5585 if (rc != 0) { 5586 device_printf(sc->dev, 5587 "failed to query TLS parameters: %d.\n", rc); 5588 return (rc); 5589 } 5590 sc->vres.key.start = val[0]; 5591 sc->vres.key.size = val[1] - val[0] + 1; 5592 } 5593 5594 /* 5595 * We've got the params we wanted to query directly from the firmware. 5596 * Grab some others via other means. 5597 */ 5598 t4_init_sge_params(sc); 5599 t4_init_tp_params(sc); 5600 t4_read_mtu_tbl(sc, sc->params.mtus, NULL); 5601 t4_load_mtus(sc, sc->params.mtus, sc->params.a_wnd, sc->params.b_wnd); 5602 5603 rc = t4_verify_chip_settings(sc); 5604 if (rc != 0) 5605 return (rc); 5606 t4_init_rx_buf_info(sc); 5607 5608 return (rc); 5609 } 5610 5611 #ifdef KERN_TLS 5612 static void 5613 ktls_tick(void *arg) 5614 { 5615 struct adapter *sc; 5616 uint32_t tstamp; 5617 5618 sc = arg; 5619 tstamp = tcp_ts_getticks(); 5620 t4_write_reg(sc, A_TP_SYNC_TIME_HI, tstamp >> 1); 5621 t4_write_reg(sc, A_TP_SYNC_TIME_LO, tstamp << 31); 5622 callout_schedule_sbt(&sc->ktls_tick, SBT_1MS, 0, C_HARDCLOCK); 5623 } 5624 5625 static int 5626 t6_config_kern_tls(struct adapter *sc, bool enable) 5627 { 5628 int rc; 5629 uint32_t param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | 5630 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_KTLS_HW) | 5631 V_FW_PARAMS_PARAM_Y(enable ? 1 : 0) | 5632 V_FW_PARAMS_PARAM_Z(FW_PARAMS_PARAM_DEV_KTLS_HW_USER_ENABLE); 5633 5634 rc = -t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, ¶m); 5635 if (rc != 0) { 5636 CH_ERR(sc, "failed to %s NIC TLS: %d\n", 5637 enable ? "enable" : "disable", rc); 5638 return (rc); 5639 } 5640 5641 if (enable) { 5642 sc->flags |= KERN_TLS_ON; 5643 callout_reset_sbt(&sc->ktls_tick, SBT_1MS, 0, ktls_tick, sc, 5644 C_HARDCLOCK); 5645 } else { 5646 sc->flags &= ~KERN_TLS_ON; 5647 callout_stop(&sc->ktls_tick); 5648 } 5649 5650 return (rc); 5651 } 5652 #endif 5653 5654 static int 5655 set_params__post_init(struct adapter *sc) 5656 { 5657 uint32_t mask, param, val; 5658 #ifdef TCP_OFFLOAD 5659 int i, v, shift; 5660 #endif 5661 5662 /* ask for encapsulated CPLs */ 5663 param = FW_PARAM_PFVF(CPLFW4MSG_ENCAP); 5664 val = 1; 5665 (void)t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val); 5666 5667 /* Enable 32b port caps if the firmware supports it. */ 5668 param = FW_PARAM_PFVF(PORT_CAPS32); 5669 val = 1; 5670 if (t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val) == 0) 5671 sc->params.port_caps32 = 1; 5672 5673 /* Let filter + maskhash steer to a part of the VI's RSS region. */ 5674 val = 1 << (G_MASKSIZE(t4_read_reg(sc, A_TP_RSS_CONFIG_TNL)) - 1); 5675 t4_set_reg_field(sc, A_TP_RSS_CONFIG_TNL, V_MASKFILTER(M_MASKFILTER), 5676 V_MASKFILTER(val - 1)); 5677 5678 mask = F_DROPERRORANY | F_DROPERRORMAC | F_DROPERRORIPVER | 5679 F_DROPERRORFRAG | F_DROPERRORATTACK | F_DROPERRORETHHDRLEN | 5680 F_DROPERRORIPHDRLEN | F_DROPERRORTCPHDRLEN | F_DROPERRORPKTLEN | 5681 F_DROPERRORTCPOPT | F_DROPERRORCSUMIP | F_DROPERRORCSUM; 5682 val = 0; 5683 if (chip_id(sc) < CHELSIO_T6 && t4_attack_filter != 0) { 5684 t4_set_reg_field(sc, A_TP_GLOBAL_CONFIG, F_ATTACKFILTERENABLE, 5685 F_ATTACKFILTERENABLE); 5686 val |= F_DROPERRORATTACK; 5687 } 5688 if (t4_drop_ip_fragments != 0) { 5689 t4_set_reg_field(sc, A_TP_GLOBAL_CONFIG, F_FRAGMENTDROP, 5690 F_FRAGMENTDROP); 5691 val |= F_DROPERRORFRAG; 5692 } 5693 if (t4_drop_pkts_with_l2_errors != 0) 5694 val |= F_DROPERRORMAC | F_DROPERRORETHHDRLEN; 5695 if (t4_drop_pkts_with_l3_errors != 0) { 5696 val |= F_DROPERRORIPVER | F_DROPERRORIPHDRLEN | 5697 F_DROPERRORCSUMIP; 5698 } 5699 if (t4_drop_pkts_with_l4_errors != 0) { 5700 val |= F_DROPERRORTCPHDRLEN | F_DROPERRORPKTLEN | 5701 F_DROPERRORTCPOPT | F_DROPERRORCSUM; 5702 } 5703 t4_set_reg_field(sc, A_TP_ERR_CONFIG, mask, val); 5704 5705 #ifdef TCP_OFFLOAD 5706 /* 5707 * Override the TOE timers with user provided tunables. This is not the 5708 * recommended way to change the timers (the firmware config file is) so 5709 * these tunables are not documented. 5710 * 5711 * All the timer tunables are in microseconds. 5712 */ 5713 if (t4_toe_keepalive_idle != 0) { 5714 v = us_to_tcp_ticks(sc, t4_toe_keepalive_idle); 5715 v &= M_KEEPALIVEIDLE; 5716 t4_set_reg_field(sc, A_TP_KEEP_IDLE, 5717 V_KEEPALIVEIDLE(M_KEEPALIVEIDLE), V_KEEPALIVEIDLE(v)); 5718 } 5719 if (t4_toe_keepalive_interval != 0) { 5720 v = us_to_tcp_ticks(sc, t4_toe_keepalive_interval); 5721 v &= M_KEEPALIVEINTVL; 5722 t4_set_reg_field(sc, A_TP_KEEP_INTVL, 5723 V_KEEPALIVEINTVL(M_KEEPALIVEINTVL), V_KEEPALIVEINTVL(v)); 5724 } 5725 if (t4_toe_keepalive_count != 0) { 5726 v = t4_toe_keepalive_count & M_KEEPALIVEMAXR2; 5727 t4_set_reg_field(sc, A_TP_SHIFT_CNT, 5728 V_KEEPALIVEMAXR1(M_KEEPALIVEMAXR1) | 5729 V_KEEPALIVEMAXR2(M_KEEPALIVEMAXR2), 5730 V_KEEPALIVEMAXR1(1) | V_KEEPALIVEMAXR2(v)); 5731 } 5732 if (t4_toe_rexmt_min != 0) { 5733 v = us_to_tcp_ticks(sc, t4_toe_rexmt_min); 5734 v &= M_RXTMIN; 5735 t4_set_reg_field(sc, A_TP_RXT_MIN, 5736 V_RXTMIN(M_RXTMIN), V_RXTMIN(v)); 5737 } 5738 if (t4_toe_rexmt_max != 0) { 5739 v = us_to_tcp_ticks(sc, t4_toe_rexmt_max); 5740 v &= M_RXTMAX; 5741 t4_set_reg_field(sc, A_TP_RXT_MAX, 5742 V_RXTMAX(M_RXTMAX), V_RXTMAX(v)); 5743 } 5744 if (t4_toe_rexmt_count != 0) { 5745 v = t4_toe_rexmt_count & M_RXTSHIFTMAXR2; 5746 t4_set_reg_field(sc, A_TP_SHIFT_CNT, 5747 V_RXTSHIFTMAXR1(M_RXTSHIFTMAXR1) | 5748 V_RXTSHIFTMAXR2(M_RXTSHIFTMAXR2), 5749 V_RXTSHIFTMAXR1(1) | V_RXTSHIFTMAXR2(v)); 5750 } 5751 for (i = 0; i < nitems(t4_toe_rexmt_backoff); i++) { 5752 if (t4_toe_rexmt_backoff[i] != -1) { 5753 v = t4_toe_rexmt_backoff[i] & M_TIMERBACKOFFINDEX0; 5754 shift = (i & 3) << 3; 5755 t4_set_reg_field(sc, A_TP_TCP_BACKOFF_REG0 + (i & ~3), 5756 M_TIMERBACKOFFINDEX0 << shift, v << shift); 5757 } 5758 } 5759 #endif 5760 5761 /* 5762 * Limit TOE connections to 2 reassembly "islands". This is 5763 * required to permit migrating TOE connections to either 5764 * ULP_MODE_TCPDDP or UPL_MODE_TLS. 5765 */ 5766 t4_tp_wr_bits_indirect(sc, A_TP_FRAG_CONFIG, V_PASSMODE(M_PASSMODE), 5767 V_PASSMODE(2)); 5768 5769 #ifdef KERN_TLS 5770 if (is_ktls(sc)) { 5771 sc->tlst.inline_keys = t4_tls_inline_keys; 5772 sc->tlst.combo_wrs = t4_tls_combo_wrs; 5773 if (t4_kern_tls != 0 && is_t6(sc)) 5774 t6_config_kern_tls(sc, true); 5775 } 5776 #endif 5777 return (0); 5778 } 5779 5780 #undef FW_PARAM_PFVF 5781 #undef FW_PARAM_DEV 5782 5783 static void 5784 t4_set_desc(struct adapter *sc) 5785 { 5786 struct adapter_params *p = &sc->params; 5787 5788 device_set_descf(sc->dev, "Chelsio %s", p->vpd.id); 5789 } 5790 5791 static inline void 5792 ifmedia_add4(struct ifmedia *ifm, int m) 5793 { 5794 5795 ifmedia_add(ifm, m, 0, NULL); 5796 ifmedia_add(ifm, m | IFM_ETH_TXPAUSE, 0, NULL); 5797 ifmedia_add(ifm, m | IFM_ETH_RXPAUSE, 0, NULL); 5798 ifmedia_add(ifm, m | IFM_ETH_TXPAUSE | IFM_ETH_RXPAUSE, 0, NULL); 5799 } 5800 5801 /* 5802 * This is the selected media, which is not quite the same as the active media. 5803 * The media line in ifconfig is "media: Ethernet selected (active)" if selected 5804 * and active are not the same, and "media: Ethernet selected" otherwise. 5805 */ 5806 static void 5807 set_current_media(struct port_info *pi) 5808 { 5809 struct link_config *lc; 5810 struct ifmedia *ifm; 5811 int mword; 5812 u_int speed; 5813 5814 PORT_LOCK_ASSERT_OWNED(pi); 5815 5816 /* Leave current media alone if it's already set to IFM_NONE. */ 5817 ifm = &pi->media; 5818 if (ifm->ifm_cur != NULL && 5819 IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_NONE) 5820 return; 5821 5822 lc = &pi->link_cfg; 5823 if (lc->requested_aneg != AUTONEG_DISABLE && 5824 lc->pcaps & FW_PORT_CAP32_ANEG) { 5825 ifmedia_set(ifm, IFM_ETHER | IFM_AUTO); 5826 return; 5827 } 5828 mword = IFM_ETHER | IFM_FDX; 5829 if (lc->requested_fc & PAUSE_TX) 5830 mword |= IFM_ETH_TXPAUSE; 5831 if (lc->requested_fc & PAUSE_RX) 5832 mword |= IFM_ETH_RXPAUSE; 5833 if (lc->requested_speed == 0) 5834 speed = port_top_speed(pi) * 1000; /* Gbps -> Mbps */ 5835 else 5836 speed = lc->requested_speed; 5837 mword |= port_mword(pi, speed_to_fwcap(speed)); 5838 ifmedia_set(ifm, mword); 5839 } 5840 5841 /* 5842 * Returns true if the ifmedia list for the port cannot change. 5843 */ 5844 static bool 5845 fixed_ifmedia(struct port_info *pi) 5846 { 5847 5848 return (pi->port_type == FW_PORT_TYPE_BT_SGMII || 5849 pi->port_type == FW_PORT_TYPE_BT_XFI || 5850 pi->port_type == FW_PORT_TYPE_BT_XAUI || 5851 pi->port_type == FW_PORT_TYPE_KX4 || 5852 pi->port_type == FW_PORT_TYPE_KX || 5853 pi->port_type == FW_PORT_TYPE_KR || 5854 pi->port_type == FW_PORT_TYPE_BP_AP || 5855 pi->port_type == FW_PORT_TYPE_BP4_AP || 5856 pi->port_type == FW_PORT_TYPE_BP40_BA || 5857 pi->port_type == FW_PORT_TYPE_KR4_100G || 5858 pi->port_type == FW_PORT_TYPE_KR_SFP28 || 5859 pi->port_type == FW_PORT_TYPE_KR_XLAUI); 5860 } 5861 5862 static void 5863 build_medialist(struct port_info *pi) 5864 { 5865 uint32_t ss, speed; 5866 int unknown, mword, bit; 5867 struct link_config *lc; 5868 struct ifmedia *ifm; 5869 5870 PORT_LOCK_ASSERT_OWNED(pi); 5871 5872 if (pi->flags & FIXED_IFMEDIA) 5873 return; 5874 5875 /* 5876 * Rebuild the ifmedia list. 5877 */ 5878 ifm = &pi->media; 5879 ifmedia_removeall(ifm); 5880 lc = &pi->link_cfg; 5881 ss = G_FW_PORT_CAP32_SPEED(lc->pcaps); /* Supported Speeds */ 5882 if (__predict_false(ss == 0)) { /* not supposed to happen. */ 5883 MPASS(ss != 0); 5884 no_media: 5885 MPASS(LIST_EMPTY(&ifm->ifm_list)); 5886 ifmedia_add(ifm, IFM_ETHER | IFM_NONE, 0, NULL); 5887 ifmedia_set(ifm, IFM_ETHER | IFM_NONE); 5888 return; 5889 } 5890 5891 unknown = 0; 5892 for (bit = S_FW_PORT_CAP32_SPEED; bit < fls(ss); bit++) { 5893 speed = 1 << bit; 5894 MPASS(speed & M_FW_PORT_CAP32_SPEED); 5895 if (ss & speed) { 5896 mword = port_mword(pi, speed); 5897 if (mword == IFM_NONE) { 5898 goto no_media; 5899 } else if (mword == IFM_UNKNOWN) 5900 unknown++; 5901 else 5902 ifmedia_add4(ifm, IFM_ETHER | IFM_FDX | mword); 5903 } 5904 } 5905 if (unknown > 0) /* Add one unknown for all unknown media types. */ 5906 ifmedia_add4(ifm, IFM_ETHER | IFM_FDX | IFM_UNKNOWN); 5907 if (lc->pcaps & FW_PORT_CAP32_ANEG) 5908 ifmedia_add(ifm, IFM_ETHER | IFM_AUTO, 0, NULL); 5909 5910 set_current_media(pi); 5911 } 5912 5913 /* 5914 * Initialize the requested fields in the link config based on driver tunables. 5915 */ 5916 static void 5917 init_link_config(struct port_info *pi) 5918 { 5919 struct link_config *lc = &pi->link_cfg; 5920 5921 PORT_LOCK_ASSERT_OWNED(pi); 5922 5923 lc->requested_caps = 0; 5924 lc->requested_speed = 0; 5925 5926 if (t4_autoneg == 0) 5927 lc->requested_aneg = AUTONEG_DISABLE; 5928 else if (t4_autoneg == 1) 5929 lc->requested_aneg = AUTONEG_ENABLE; 5930 else 5931 lc->requested_aneg = AUTONEG_AUTO; 5932 5933 lc->requested_fc = t4_pause_settings & (PAUSE_TX | PAUSE_RX | 5934 PAUSE_AUTONEG); 5935 5936 if (t4_fec & FEC_AUTO) 5937 lc->requested_fec = FEC_AUTO; 5938 else if (t4_fec == 0) 5939 lc->requested_fec = FEC_NONE; 5940 else { 5941 /* -1 is handled by the FEC_AUTO block above and not here. */ 5942 lc->requested_fec = t4_fec & 5943 (FEC_RS | FEC_BASER_RS | FEC_NONE | FEC_MODULE); 5944 if (lc->requested_fec == 0) 5945 lc->requested_fec = FEC_AUTO; 5946 } 5947 if (t4_force_fec < 0) 5948 lc->force_fec = -1; 5949 else if (t4_force_fec > 0) 5950 lc->force_fec = 1; 5951 else 5952 lc->force_fec = 0; 5953 } 5954 5955 /* 5956 * Makes sure that all requested settings comply with what's supported by the 5957 * port. Returns the number of settings that were invalid and had to be fixed. 5958 */ 5959 static int 5960 fixup_link_config(struct port_info *pi) 5961 { 5962 int n = 0; 5963 struct link_config *lc = &pi->link_cfg; 5964 uint32_t fwspeed; 5965 5966 PORT_LOCK_ASSERT_OWNED(pi); 5967 5968 /* Speed (when not autonegotiating) */ 5969 if (lc->requested_speed != 0) { 5970 fwspeed = speed_to_fwcap(lc->requested_speed); 5971 if ((fwspeed & lc->pcaps) == 0) { 5972 n++; 5973 lc->requested_speed = 0; 5974 } 5975 } 5976 5977 /* Link autonegotiation */ 5978 MPASS(lc->requested_aneg == AUTONEG_ENABLE || 5979 lc->requested_aneg == AUTONEG_DISABLE || 5980 lc->requested_aneg == AUTONEG_AUTO); 5981 if (lc->requested_aneg == AUTONEG_ENABLE && 5982 !(lc->pcaps & FW_PORT_CAP32_ANEG)) { 5983 n++; 5984 lc->requested_aneg = AUTONEG_AUTO; 5985 } 5986 5987 /* Flow control */ 5988 MPASS((lc->requested_fc & ~(PAUSE_TX | PAUSE_RX | PAUSE_AUTONEG)) == 0); 5989 if (lc->requested_fc & PAUSE_TX && 5990 !(lc->pcaps & FW_PORT_CAP32_FC_TX)) { 5991 n++; 5992 lc->requested_fc &= ~PAUSE_TX; 5993 } 5994 if (lc->requested_fc & PAUSE_RX && 5995 !(lc->pcaps & FW_PORT_CAP32_FC_RX)) { 5996 n++; 5997 lc->requested_fc &= ~PAUSE_RX; 5998 } 5999 if (!(lc->requested_fc & PAUSE_AUTONEG) && 6000 !(lc->pcaps & FW_PORT_CAP32_FORCE_PAUSE)) { 6001 n++; 6002 lc->requested_fc |= PAUSE_AUTONEG; 6003 } 6004 6005 /* FEC */ 6006 if ((lc->requested_fec & FEC_RS && 6007 !(lc->pcaps & FW_PORT_CAP32_FEC_RS)) || 6008 (lc->requested_fec & FEC_BASER_RS && 6009 !(lc->pcaps & FW_PORT_CAP32_FEC_BASER_RS))) { 6010 n++; 6011 lc->requested_fec = FEC_AUTO; 6012 } 6013 6014 return (n); 6015 } 6016 6017 /* 6018 * Apply the requested L1 settings, which are expected to be valid, to the 6019 * hardware. 6020 */ 6021 static int 6022 apply_link_config(struct port_info *pi) 6023 { 6024 struct adapter *sc = pi->adapter; 6025 struct link_config *lc = &pi->link_cfg; 6026 int rc; 6027 6028 #ifdef INVARIANTS 6029 ASSERT_SYNCHRONIZED_OP(sc); 6030 PORT_LOCK_ASSERT_OWNED(pi); 6031 6032 if (lc->requested_aneg == AUTONEG_ENABLE) 6033 MPASS(lc->pcaps & FW_PORT_CAP32_ANEG); 6034 if (!(lc->requested_fc & PAUSE_AUTONEG)) 6035 MPASS(lc->pcaps & FW_PORT_CAP32_FORCE_PAUSE); 6036 if (lc->requested_fc & PAUSE_TX) 6037 MPASS(lc->pcaps & FW_PORT_CAP32_FC_TX); 6038 if (lc->requested_fc & PAUSE_RX) 6039 MPASS(lc->pcaps & FW_PORT_CAP32_FC_RX); 6040 if (lc->requested_fec & FEC_RS) 6041 MPASS(lc->pcaps & FW_PORT_CAP32_FEC_RS); 6042 if (lc->requested_fec & FEC_BASER_RS) 6043 MPASS(lc->pcaps & FW_PORT_CAP32_FEC_BASER_RS); 6044 #endif 6045 if (!(sc->flags & IS_VF)) { 6046 rc = -t4_link_l1cfg(sc, sc->mbox, pi->tx_chan, lc); 6047 if (rc != 0) { 6048 device_printf(pi->dev, "l1cfg failed: %d\n", rc); 6049 return (rc); 6050 } 6051 } 6052 6053 /* 6054 * An L1_CFG will almost always result in a link-change event if the 6055 * link is up, and the driver will refresh the actual fec/fc/etc. when 6056 * the notification is processed. If the link is down then the actual 6057 * settings are meaningless. 6058 * 6059 * This takes care of the case where a change in the L1 settings may not 6060 * result in a notification. 6061 */ 6062 if (lc->link_ok && !(lc->requested_fc & PAUSE_AUTONEG)) 6063 lc->fc = lc->requested_fc & (PAUSE_TX | PAUSE_RX); 6064 6065 return (0); 6066 } 6067 6068 #define FW_MAC_EXACT_CHUNK 7 6069 struct mcaddr_ctx { 6070 if_t ifp; 6071 const uint8_t *mcaddr[FW_MAC_EXACT_CHUNK]; 6072 uint64_t hash; 6073 int i; 6074 int del; 6075 int rc; 6076 }; 6077 6078 static u_int 6079 add_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt) 6080 { 6081 struct mcaddr_ctx *ctx = arg; 6082 struct vi_info *vi = if_getsoftc(ctx->ifp); 6083 struct port_info *pi = vi->pi; 6084 struct adapter *sc = pi->adapter; 6085 6086 if (ctx->rc < 0) 6087 return (0); 6088 6089 ctx->mcaddr[ctx->i] = LLADDR(sdl); 6090 MPASS(ETHER_IS_MULTICAST(ctx->mcaddr[ctx->i])); 6091 ctx->i++; 6092 6093 if (ctx->i == FW_MAC_EXACT_CHUNK) { 6094 ctx->rc = t4_alloc_mac_filt(sc, sc->mbox, vi->viid, ctx->del, 6095 ctx->i, ctx->mcaddr, NULL, &ctx->hash, 0); 6096 if (ctx->rc < 0) { 6097 int j; 6098 6099 for (j = 0; j < ctx->i; j++) { 6100 if_printf(ctx->ifp, 6101 "failed to add mc address" 6102 " %02x:%02x:%02x:" 6103 "%02x:%02x:%02x rc=%d\n", 6104 ctx->mcaddr[j][0], ctx->mcaddr[j][1], 6105 ctx->mcaddr[j][2], ctx->mcaddr[j][3], 6106 ctx->mcaddr[j][4], ctx->mcaddr[j][5], 6107 -ctx->rc); 6108 } 6109 return (0); 6110 } 6111 ctx->del = 0; 6112 ctx->i = 0; 6113 } 6114 6115 return (1); 6116 } 6117 6118 /* 6119 * Program the port's XGMAC based on parameters in ifnet. The caller also 6120 * indicates which parameters should be programmed (the rest are left alone). 6121 */ 6122 int 6123 update_mac_settings(if_t ifp, int flags) 6124 { 6125 int rc = 0; 6126 struct vi_info *vi = if_getsoftc(ifp); 6127 struct port_info *pi = vi->pi; 6128 struct adapter *sc = pi->adapter; 6129 int mtu = -1, promisc = -1, allmulti = -1, vlanex = -1; 6130 uint8_t match_all_mac[ETHER_ADDR_LEN] = {0}; 6131 6132 ASSERT_SYNCHRONIZED_OP(sc); 6133 KASSERT(flags, ("%s: not told what to update.", __func__)); 6134 6135 if (flags & XGMAC_MTU) 6136 mtu = if_getmtu(ifp); 6137 6138 if (flags & XGMAC_PROMISC) 6139 promisc = if_getflags(ifp) & IFF_PROMISC ? 1 : 0; 6140 6141 if (flags & XGMAC_ALLMULTI) 6142 allmulti = if_getflags(ifp) & IFF_ALLMULTI ? 1 : 0; 6143 6144 if (flags & XGMAC_VLANEX) 6145 vlanex = if_getcapenable(ifp) & IFCAP_VLAN_HWTAGGING ? 1 : 0; 6146 6147 if (flags & (XGMAC_MTU|XGMAC_PROMISC|XGMAC_ALLMULTI|XGMAC_VLANEX)) { 6148 rc = -t4_set_rxmode(sc, sc->mbox, vi->viid, mtu, promisc, 6149 allmulti, 1, vlanex, false); 6150 if (rc) { 6151 if_printf(ifp, "set_rxmode (%x) failed: %d\n", flags, 6152 rc); 6153 return (rc); 6154 } 6155 } 6156 6157 if (flags & XGMAC_UCADDR) { 6158 uint8_t ucaddr[ETHER_ADDR_LEN]; 6159 6160 bcopy(if_getlladdr(ifp), ucaddr, sizeof(ucaddr)); 6161 rc = t4_change_mac(sc, sc->mbox, vi->viid, vi->xact_addr_filt, 6162 ucaddr, true, &vi->smt_idx); 6163 if (rc < 0) { 6164 rc = -rc; 6165 if_printf(ifp, "change_mac failed: %d\n", rc); 6166 return (rc); 6167 } else { 6168 vi->xact_addr_filt = rc; 6169 rc = 0; 6170 } 6171 } 6172 6173 if (flags & XGMAC_MCADDRS) { 6174 struct epoch_tracker et; 6175 struct mcaddr_ctx ctx; 6176 int j; 6177 6178 ctx.ifp = ifp; 6179 ctx.hash = 0; 6180 ctx.i = 0; 6181 ctx.del = 1; 6182 ctx.rc = 0; 6183 /* 6184 * Unlike other drivers, we accumulate list of pointers into 6185 * interface address lists and we need to keep it safe even 6186 * after if_foreach_llmaddr() returns, thus we must enter the 6187 * network epoch. 6188 */ 6189 NET_EPOCH_ENTER(et); 6190 if_foreach_llmaddr(ifp, add_maddr, &ctx); 6191 if (ctx.rc < 0) { 6192 NET_EPOCH_EXIT(et); 6193 rc = -ctx.rc; 6194 return (rc); 6195 } 6196 if (ctx.i > 0) { 6197 rc = t4_alloc_mac_filt(sc, sc->mbox, vi->viid, 6198 ctx.del, ctx.i, ctx.mcaddr, NULL, &ctx.hash, 0); 6199 NET_EPOCH_EXIT(et); 6200 if (rc < 0) { 6201 rc = -rc; 6202 for (j = 0; j < ctx.i; j++) { 6203 if_printf(ifp, 6204 "failed to add mcast address" 6205 " %02x:%02x:%02x:" 6206 "%02x:%02x:%02x rc=%d\n", 6207 ctx.mcaddr[j][0], ctx.mcaddr[j][1], 6208 ctx.mcaddr[j][2], ctx.mcaddr[j][3], 6209 ctx.mcaddr[j][4], ctx.mcaddr[j][5], 6210 rc); 6211 } 6212 return (rc); 6213 } 6214 ctx.del = 0; 6215 } else 6216 NET_EPOCH_EXIT(et); 6217 6218 rc = -t4_set_addr_hash(sc, sc->mbox, vi->viid, 0, ctx.hash, 0); 6219 if (rc != 0) 6220 if_printf(ifp, "failed to set mcast address hash: %d\n", 6221 rc); 6222 if (ctx.del == 0) { 6223 /* We clobbered the VXLAN entry if there was one. */ 6224 pi->vxlan_tcam_entry = false; 6225 } 6226 } 6227 6228 if (IS_MAIN_VI(vi) && sc->vxlan_refcount > 0 && 6229 pi->vxlan_tcam_entry == false) { 6230 rc = t4_alloc_raw_mac_filt(sc, vi->viid, match_all_mac, 6231 match_all_mac, sc->rawf_base + pi->port_id, 1, pi->port_id, 6232 true); 6233 if (rc < 0) { 6234 rc = -rc; 6235 if_printf(ifp, "failed to add VXLAN TCAM entry: %d.\n", 6236 rc); 6237 } else { 6238 MPASS(rc == sc->rawf_base + pi->port_id); 6239 rc = 0; 6240 pi->vxlan_tcam_entry = true; 6241 } 6242 } 6243 6244 return (rc); 6245 } 6246 6247 /* 6248 * {begin|end}_synchronized_op must be called from the same thread. 6249 */ 6250 int 6251 begin_synchronized_op(struct adapter *sc, struct vi_info *vi, int flags, 6252 char *wmesg) 6253 { 6254 int rc, pri; 6255 6256 #ifdef WITNESS 6257 /* the caller thinks it's ok to sleep, but is it really? */ 6258 if (flags & SLEEP_OK) 6259 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, 6260 "begin_synchronized_op"); 6261 #endif 6262 6263 if (INTR_OK) 6264 pri = PCATCH; 6265 else 6266 pri = 0; 6267 6268 ADAPTER_LOCK(sc); 6269 for (;;) { 6270 6271 if (vi && IS_DETACHING(vi)) { 6272 rc = ENXIO; 6273 goto done; 6274 } 6275 6276 if (!IS_BUSY(sc)) { 6277 rc = 0; 6278 break; 6279 } 6280 6281 if (!(flags & SLEEP_OK)) { 6282 rc = EBUSY; 6283 goto done; 6284 } 6285 6286 if (mtx_sleep(&sc->flags, &sc->sc_lock, pri, wmesg, 0)) { 6287 rc = EINTR; 6288 goto done; 6289 } 6290 } 6291 6292 KASSERT(!IS_BUSY(sc), ("%s: controller busy.", __func__)); 6293 SET_BUSY(sc); 6294 #ifdef INVARIANTS 6295 sc->last_op = wmesg; 6296 sc->last_op_thr = curthread; 6297 sc->last_op_flags = flags; 6298 #endif 6299 6300 done: 6301 if (!(flags & HOLD_LOCK) || rc) 6302 ADAPTER_UNLOCK(sc); 6303 6304 return (rc); 6305 } 6306 6307 /* 6308 * Tell if_ioctl and if_init that the VI is going away. This is 6309 * special variant of begin_synchronized_op and must be paired with a 6310 * call to end_vi_detach. 6311 */ 6312 void 6313 begin_vi_detach(struct adapter *sc, struct vi_info *vi) 6314 { 6315 ADAPTER_LOCK(sc); 6316 SET_DETACHING(vi); 6317 wakeup(&sc->flags); 6318 while (IS_BUSY(sc)) 6319 mtx_sleep(&sc->flags, &sc->sc_lock, 0, "t4detach", 0); 6320 SET_BUSY(sc); 6321 #ifdef INVARIANTS 6322 sc->last_op = "t4detach"; 6323 sc->last_op_thr = curthread; 6324 sc->last_op_flags = 0; 6325 #endif 6326 ADAPTER_UNLOCK(sc); 6327 } 6328 6329 void 6330 end_vi_detach(struct adapter *sc, struct vi_info *vi) 6331 { 6332 ADAPTER_LOCK(sc); 6333 KASSERT(IS_BUSY(sc), ("%s: controller not busy.", __func__)); 6334 CLR_BUSY(sc); 6335 CLR_DETACHING(vi); 6336 wakeup(&sc->flags); 6337 ADAPTER_UNLOCK(sc); 6338 } 6339 6340 /* 6341 * {begin|end}_synchronized_op must be called from the same thread. 6342 */ 6343 void 6344 end_synchronized_op(struct adapter *sc, int flags) 6345 { 6346 6347 if (flags & LOCK_HELD) 6348 ADAPTER_LOCK_ASSERT_OWNED(sc); 6349 else 6350 ADAPTER_LOCK(sc); 6351 6352 KASSERT(IS_BUSY(sc), ("%s: controller not busy.", __func__)); 6353 CLR_BUSY(sc); 6354 wakeup(&sc->flags); 6355 ADAPTER_UNLOCK(sc); 6356 } 6357 6358 static int 6359 cxgbe_init_synchronized(struct vi_info *vi) 6360 { 6361 struct port_info *pi = vi->pi; 6362 struct adapter *sc = pi->adapter; 6363 if_t ifp = vi->ifp; 6364 int rc = 0, i; 6365 struct sge_txq *txq; 6366 6367 ASSERT_SYNCHRONIZED_OP(sc); 6368 6369 if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) 6370 return (0); /* already running */ 6371 6372 if (!(sc->flags & FULL_INIT_DONE) && ((rc = adapter_init(sc)) != 0)) 6373 return (rc); /* error message displayed already */ 6374 6375 if (!(vi->flags & VI_INIT_DONE) && ((rc = vi_init(vi)) != 0)) 6376 return (rc); /* error message displayed already */ 6377 6378 rc = update_mac_settings(ifp, XGMAC_ALL); 6379 if (rc) 6380 goto done; /* error message displayed already */ 6381 6382 PORT_LOCK(pi); 6383 if (pi->up_vis == 0) { 6384 t4_update_port_info(pi); 6385 fixup_link_config(pi); 6386 build_medialist(pi); 6387 apply_link_config(pi); 6388 } 6389 6390 rc = -t4_enable_vi(sc, sc->mbox, vi->viid, true, true); 6391 if (rc != 0) { 6392 if_printf(ifp, "enable_vi failed: %d\n", rc); 6393 PORT_UNLOCK(pi); 6394 goto done; 6395 } 6396 6397 /* 6398 * Can't fail from this point onwards. Review cxgbe_uninit_synchronized 6399 * if this changes. 6400 */ 6401 6402 for_each_txq(vi, i, txq) { 6403 TXQ_LOCK(txq); 6404 txq->eq.flags |= EQ_ENABLED; 6405 TXQ_UNLOCK(txq); 6406 } 6407 6408 /* 6409 * The first iq of the first port to come up is used for tracing. 6410 */ 6411 if (sc->traceq < 0 && IS_MAIN_VI(vi)) { 6412 sc->traceq = sc->sge.rxq[vi->first_rxq].iq.abs_id; 6413 t4_write_reg(sc, is_t4(sc) ? A_MPS_TRC_RSS_CONTROL : 6414 A_MPS_T5_TRC_RSS_CONTROL, V_RSSCONTROL(pi->tx_chan) | 6415 V_QUEUENUMBER(sc->traceq)); 6416 pi->flags |= HAS_TRACEQ; 6417 } 6418 6419 /* all ok */ 6420 pi->up_vis++; 6421 if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0); 6422 if (pi->link_cfg.link_ok) 6423 t4_os_link_changed(pi); 6424 PORT_UNLOCK(pi); 6425 6426 mtx_lock(&vi->tick_mtx); 6427 if (vi->pi->nvi > 1 || sc->flags & IS_VF) 6428 callout_reset(&vi->tick, hz, vi_tick, vi); 6429 else 6430 callout_reset(&vi->tick, hz, cxgbe_tick, vi); 6431 mtx_unlock(&vi->tick_mtx); 6432 done: 6433 if (rc != 0) 6434 cxgbe_uninit_synchronized(vi); 6435 6436 return (rc); 6437 } 6438 6439 /* 6440 * Idempotent. 6441 */ 6442 static int 6443 cxgbe_uninit_synchronized(struct vi_info *vi) 6444 { 6445 struct port_info *pi = vi->pi; 6446 struct adapter *sc = pi->adapter; 6447 if_t ifp = vi->ifp; 6448 int rc, i; 6449 struct sge_txq *txq; 6450 6451 ASSERT_SYNCHRONIZED_OP(sc); 6452 6453 if (!(vi->flags & VI_INIT_DONE)) { 6454 if (__predict_false(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) { 6455 KASSERT(0, ("uninited VI is running")); 6456 if_printf(ifp, "uninited VI with running ifnet. " 6457 "vi->flags 0x%016lx, if_flags 0x%08x, " 6458 "if_drv_flags 0x%08x\n", vi->flags, if_getflags(ifp), 6459 if_getdrvflags(ifp)); 6460 } 6461 return (0); 6462 } 6463 6464 /* 6465 * Disable the VI so that all its data in either direction is discarded 6466 * by the MPS. Leave everything else (the queues, interrupts, and 1Hz 6467 * tick) intact as the TP can deliver negative advice or data that it's 6468 * holding in its RAM (for an offloaded connection) even after the VI is 6469 * disabled. 6470 */ 6471 rc = -t4_enable_vi(sc, sc->mbox, vi->viid, false, false); 6472 if (rc) { 6473 if_printf(ifp, "disable_vi failed: %d\n", rc); 6474 return (rc); 6475 } 6476 6477 for_each_txq(vi, i, txq) { 6478 TXQ_LOCK(txq); 6479 txq->eq.flags &= ~EQ_ENABLED; 6480 TXQ_UNLOCK(txq); 6481 } 6482 6483 mtx_lock(&vi->tick_mtx); 6484 callout_stop(&vi->tick); 6485 mtx_unlock(&vi->tick_mtx); 6486 6487 PORT_LOCK(pi); 6488 if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) { 6489 PORT_UNLOCK(pi); 6490 return (0); 6491 } 6492 if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING); 6493 pi->up_vis--; 6494 if (pi->up_vis > 0) { 6495 PORT_UNLOCK(pi); 6496 return (0); 6497 } 6498 6499 pi->link_cfg.link_ok = false; 6500 pi->link_cfg.speed = 0; 6501 pi->link_cfg.link_down_rc = 255; 6502 t4_os_link_changed(pi); 6503 PORT_UNLOCK(pi); 6504 6505 return (0); 6506 } 6507 6508 /* 6509 * It is ok for this function to fail midway and return right away. t4_detach 6510 * will walk the entire sc->irq list and clean up whatever is valid. 6511 */ 6512 int 6513 t4_setup_intr_handlers(struct adapter *sc) 6514 { 6515 int rc, rid, p, q, v; 6516 char s[8]; 6517 struct irq *irq; 6518 struct port_info *pi; 6519 struct vi_info *vi; 6520 struct sge *sge = &sc->sge; 6521 struct sge_rxq *rxq; 6522 #ifdef TCP_OFFLOAD 6523 struct sge_ofld_rxq *ofld_rxq; 6524 #endif 6525 #ifdef DEV_NETMAP 6526 struct sge_nm_rxq *nm_rxq; 6527 #endif 6528 #ifdef RSS 6529 int nbuckets = rss_getnumbuckets(); 6530 #endif 6531 6532 /* 6533 * Setup interrupts. 6534 */ 6535 irq = &sc->irq[0]; 6536 rid = sc->intr_type == INTR_INTX ? 0 : 1; 6537 if (forwarding_intr_to_fwq(sc)) 6538 return (t4_alloc_irq(sc, irq, rid, t4_intr_all, sc, "all")); 6539 6540 /* Multiple interrupts. */ 6541 if (sc->flags & IS_VF) 6542 KASSERT(sc->intr_count >= T4VF_EXTRA_INTR + sc->params.nports, 6543 ("%s: too few intr.", __func__)); 6544 else 6545 KASSERT(sc->intr_count >= T4_EXTRA_INTR + sc->params.nports, 6546 ("%s: too few intr.", __func__)); 6547 6548 /* The first one is always error intr on PFs */ 6549 if (!(sc->flags & IS_VF)) { 6550 rc = t4_alloc_irq(sc, irq, rid, t4_intr_err, sc, "err"); 6551 if (rc != 0) 6552 return (rc); 6553 irq++; 6554 rid++; 6555 } 6556 6557 /* The second one is always the firmware event queue (first on VFs) */ 6558 rc = t4_alloc_irq(sc, irq, rid, t4_intr_evt, &sge->fwq, "evt"); 6559 if (rc != 0) 6560 return (rc); 6561 irq++; 6562 rid++; 6563 6564 for_each_port(sc, p) { 6565 pi = sc->port[p]; 6566 for_each_vi(pi, v, vi) { 6567 vi->first_intr = rid - 1; 6568 6569 if (vi->nnmrxq > 0) { 6570 int n = max(vi->nrxq, vi->nnmrxq); 6571 6572 rxq = &sge->rxq[vi->first_rxq]; 6573 #ifdef DEV_NETMAP 6574 nm_rxq = &sge->nm_rxq[vi->first_nm_rxq]; 6575 #endif 6576 for (q = 0; q < n; q++) { 6577 snprintf(s, sizeof(s), "%x%c%x", p, 6578 'a' + v, q); 6579 if (q < vi->nrxq) 6580 irq->rxq = rxq++; 6581 #ifdef DEV_NETMAP 6582 if (q < vi->nnmrxq) 6583 irq->nm_rxq = nm_rxq++; 6584 6585 if (irq->nm_rxq != NULL && 6586 irq->rxq == NULL) { 6587 /* Netmap rx only */ 6588 rc = t4_alloc_irq(sc, irq, rid, 6589 t4_nm_intr, irq->nm_rxq, s); 6590 } 6591 if (irq->nm_rxq != NULL && 6592 irq->rxq != NULL) { 6593 /* NIC and Netmap rx */ 6594 rc = t4_alloc_irq(sc, irq, rid, 6595 t4_vi_intr, irq, s); 6596 } 6597 #endif 6598 if (irq->rxq != NULL && 6599 irq->nm_rxq == NULL) { 6600 /* NIC rx only */ 6601 rc = t4_alloc_irq(sc, irq, rid, 6602 t4_intr, irq->rxq, s); 6603 } 6604 if (rc != 0) 6605 return (rc); 6606 #ifdef RSS 6607 if (q < vi->nrxq) { 6608 bus_bind_intr(sc->dev, irq->res, 6609 rss_getcpu(q % nbuckets)); 6610 } 6611 #endif 6612 irq++; 6613 rid++; 6614 vi->nintr++; 6615 } 6616 } else { 6617 for_each_rxq(vi, q, rxq) { 6618 snprintf(s, sizeof(s), "%x%c%x", p, 6619 'a' + v, q); 6620 rc = t4_alloc_irq(sc, irq, rid, 6621 t4_intr, rxq, s); 6622 if (rc != 0) 6623 return (rc); 6624 #ifdef RSS 6625 bus_bind_intr(sc->dev, irq->res, 6626 rss_getcpu(q % nbuckets)); 6627 #endif 6628 irq++; 6629 rid++; 6630 vi->nintr++; 6631 } 6632 } 6633 #ifdef TCP_OFFLOAD 6634 for_each_ofld_rxq(vi, q, ofld_rxq) { 6635 snprintf(s, sizeof(s), "%x%c%x", p, 'A' + v, q); 6636 rc = t4_alloc_irq(sc, irq, rid, t4_intr, 6637 ofld_rxq, s); 6638 if (rc != 0) 6639 return (rc); 6640 irq++; 6641 rid++; 6642 vi->nintr++; 6643 } 6644 #endif 6645 } 6646 } 6647 MPASS(irq == &sc->irq[sc->intr_count]); 6648 6649 return (0); 6650 } 6651 6652 static void 6653 write_global_rss_key(struct adapter *sc) 6654 { 6655 #ifdef RSS 6656 int i; 6657 uint32_t raw_rss_key[RSS_KEYSIZE / sizeof(uint32_t)]; 6658 uint32_t rss_key[RSS_KEYSIZE / sizeof(uint32_t)]; 6659 6660 CTASSERT(RSS_KEYSIZE == 40); 6661 6662 rss_getkey((void *)&raw_rss_key[0]); 6663 for (i = 0; i < nitems(rss_key); i++) { 6664 rss_key[i] = htobe32(raw_rss_key[nitems(rss_key) - 1 - i]); 6665 } 6666 t4_write_rss_key(sc, &rss_key[0], -1, 1); 6667 #endif 6668 } 6669 6670 /* 6671 * Idempotent. 6672 */ 6673 static int 6674 adapter_full_init(struct adapter *sc) 6675 { 6676 int rc, i; 6677 6678 ASSERT_SYNCHRONIZED_OP(sc); 6679 6680 /* 6681 * queues that belong to the adapter (not any particular port). 6682 */ 6683 rc = t4_setup_adapter_queues(sc); 6684 if (rc != 0) 6685 return (rc); 6686 6687 MPASS(sc->params.nports <= nitems(sc->tq)); 6688 for (i = 0; i < sc->params.nports; i++) { 6689 if (sc->tq[i] != NULL) 6690 continue; 6691 sc->tq[i] = taskqueue_create("t4 taskq", M_NOWAIT, 6692 taskqueue_thread_enqueue, &sc->tq[i]); 6693 if (sc->tq[i] == NULL) { 6694 CH_ERR(sc, "failed to allocate task queue %d\n", i); 6695 return (ENOMEM); 6696 } 6697 taskqueue_start_threads(&sc->tq[i], 1, PI_NET, "%s tq%d", 6698 device_get_nameunit(sc->dev), i); 6699 } 6700 6701 if (!(sc->flags & IS_VF)) { 6702 write_global_rss_key(sc); 6703 t4_intr_enable(sc); 6704 } 6705 return (0); 6706 } 6707 6708 int 6709 adapter_init(struct adapter *sc) 6710 { 6711 int rc; 6712 6713 ASSERT_SYNCHRONIZED_OP(sc); 6714 ADAPTER_LOCK_ASSERT_NOTOWNED(sc); 6715 KASSERT((sc->flags & FULL_INIT_DONE) == 0, 6716 ("%s: FULL_INIT_DONE already", __func__)); 6717 6718 rc = adapter_full_init(sc); 6719 if (rc != 0) 6720 adapter_full_uninit(sc); 6721 else 6722 sc->flags |= FULL_INIT_DONE; 6723 6724 return (rc); 6725 } 6726 6727 /* 6728 * Idempotent. 6729 */ 6730 static void 6731 adapter_full_uninit(struct adapter *sc) 6732 { 6733 int i; 6734 6735 t4_teardown_adapter_queues(sc); 6736 6737 for (i = 0; i < nitems(sc->tq); i++) { 6738 if (sc->tq[i] == NULL) 6739 continue; 6740 taskqueue_free(sc->tq[i]); 6741 sc->tq[i] = NULL; 6742 } 6743 6744 sc->flags &= ~FULL_INIT_DONE; 6745 } 6746 6747 #ifdef RSS 6748 #define SUPPORTED_RSS_HASHTYPES (RSS_HASHTYPE_RSS_IPV4 | \ 6749 RSS_HASHTYPE_RSS_TCP_IPV4 | RSS_HASHTYPE_RSS_IPV6 | \ 6750 RSS_HASHTYPE_RSS_TCP_IPV6 | RSS_HASHTYPE_RSS_UDP_IPV4 | \ 6751 RSS_HASHTYPE_RSS_UDP_IPV6) 6752 6753 /* Translates kernel hash types to hardware. */ 6754 static int 6755 hashconfig_to_hashen(int hashconfig) 6756 { 6757 int hashen = 0; 6758 6759 if (hashconfig & RSS_HASHTYPE_RSS_IPV4) 6760 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN; 6761 if (hashconfig & RSS_HASHTYPE_RSS_IPV6) 6762 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN; 6763 if (hashconfig & RSS_HASHTYPE_RSS_UDP_IPV4) { 6764 hashen |= F_FW_RSS_VI_CONFIG_CMD_UDPEN | 6765 F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN; 6766 } 6767 if (hashconfig & RSS_HASHTYPE_RSS_UDP_IPV6) { 6768 hashen |= F_FW_RSS_VI_CONFIG_CMD_UDPEN | 6769 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN; 6770 } 6771 if (hashconfig & RSS_HASHTYPE_RSS_TCP_IPV4) 6772 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN; 6773 if (hashconfig & RSS_HASHTYPE_RSS_TCP_IPV6) 6774 hashen |= F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN; 6775 6776 return (hashen); 6777 } 6778 6779 /* Translates hardware hash types to kernel. */ 6780 static int 6781 hashen_to_hashconfig(int hashen) 6782 { 6783 int hashconfig = 0; 6784 6785 if (hashen & F_FW_RSS_VI_CONFIG_CMD_UDPEN) { 6786 /* 6787 * If UDP hashing was enabled it must have been enabled for 6788 * either IPv4 or IPv6 (inclusive or). Enabling UDP without 6789 * enabling any 4-tuple hash is nonsense configuration. 6790 */ 6791 MPASS(hashen & (F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN | 6792 F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN)); 6793 6794 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN) 6795 hashconfig |= RSS_HASHTYPE_RSS_UDP_IPV4; 6796 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN) 6797 hashconfig |= RSS_HASHTYPE_RSS_UDP_IPV6; 6798 } 6799 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN) 6800 hashconfig |= RSS_HASHTYPE_RSS_TCP_IPV4; 6801 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN) 6802 hashconfig |= RSS_HASHTYPE_RSS_TCP_IPV6; 6803 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN) 6804 hashconfig |= RSS_HASHTYPE_RSS_IPV4; 6805 if (hashen & F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN) 6806 hashconfig |= RSS_HASHTYPE_RSS_IPV6; 6807 6808 return (hashconfig); 6809 } 6810 #endif 6811 6812 /* 6813 * Idempotent. 6814 */ 6815 static int 6816 vi_full_init(struct vi_info *vi) 6817 { 6818 struct adapter *sc = vi->adapter; 6819 struct sge_rxq *rxq; 6820 int rc, i, j; 6821 #ifdef RSS 6822 int nbuckets = rss_getnumbuckets(); 6823 int hashconfig = rss_gethashconfig(); 6824 int extra; 6825 #endif 6826 6827 ASSERT_SYNCHRONIZED_OP(sc); 6828 6829 /* 6830 * Allocate tx/rx/fl queues for this VI. 6831 */ 6832 rc = t4_setup_vi_queues(vi); 6833 if (rc != 0) 6834 return (rc); 6835 6836 /* 6837 * Setup RSS for this VI. Save a copy of the RSS table for later use. 6838 */ 6839 if (vi->nrxq > vi->rss_size) { 6840 CH_ALERT(vi, "nrxq (%d) > hw RSS table size (%d); " 6841 "some queues will never receive traffic.\n", vi->nrxq, 6842 vi->rss_size); 6843 } else if (vi->rss_size % vi->nrxq) { 6844 CH_ALERT(vi, "nrxq (%d), hw RSS table size (%d); " 6845 "expect uneven traffic distribution.\n", vi->nrxq, 6846 vi->rss_size); 6847 } 6848 #ifdef RSS 6849 if (vi->nrxq != nbuckets) { 6850 CH_ALERT(vi, "nrxq (%d) != kernel RSS buckets (%d);" 6851 "performance will be impacted.\n", vi->nrxq, nbuckets); 6852 } 6853 #endif 6854 if (vi->rss == NULL) 6855 vi->rss = malloc(vi->rss_size * sizeof (*vi->rss), M_CXGBE, 6856 M_ZERO | M_WAITOK); 6857 for (i = 0; i < vi->rss_size;) { 6858 #ifdef RSS 6859 j = rss_get_indirection_to_bucket(i); 6860 j %= vi->nrxq; 6861 rxq = &sc->sge.rxq[vi->first_rxq + j]; 6862 vi->rss[i++] = rxq->iq.abs_id; 6863 #else 6864 for_each_rxq(vi, j, rxq) { 6865 vi->rss[i++] = rxq->iq.abs_id; 6866 if (i == vi->rss_size) 6867 break; 6868 } 6869 #endif 6870 } 6871 6872 rc = -t4_config_rss_range(sc, sc->mbox, vi->viid, 0, vi->rss_size, 6873 vi->rss, vi->rss_size); 6874 if (rc != 0) { 6875 CH_ERR(vi, "rss_config failed: %d\n", rc); 6876 return (rc); 6877 } 6878 6879 #ifdef RSS 6880 vi->hashen = hashconfig_to_hashen(hashconfig); 6881 6882 /* 6883 * We may have had to enable some hashes even though the global config 6884 * wants them disabled. This is a potential problem that must be 6885 * reported to the user. 6886 */ 6887 extra = hashen_to_hashconfig(vi->hashen) ^ hashconfig; 6888 6889 /* 6890 * If we consider only the supported hash types, then the enabled hashes 6891 * are a superset of the requested hashes. In other words, there cannot 6892 * be any supported hash that was requested but not enabled, but there 6893 * can be hashes that were not requested but had to be enabled. 6894 */ 6895 extra &= SUPPORTED_RSS_HASHTYPES; 6896 MPASS((extra & hashconfig) == 0); 6897 6898 if (extra) { 6899 CH_ALERT(vi, 6900 "global RSS config (0x%x) cannot be accommodated.\n", 6901 hashconfig); 6902 } 6903 if (extra & RSS_HASHTYPE_RSS_IPV4) 6904 CH_ALERT(vi, "IPv4 2-tuple hashing forced on.\n"); 6905 if (extra & RSS_HASHTYPE_RSS_TCP_IPV4) 6906 CH_ALERT(vi, "TCP/IPv4 4-tuple hashing forced on.\n"); 6907 if (extra & RSS_HASHTYPE_RSS_IPV6) 6908 CH_ALERT(vi, "IPv6 2-tuple hashing forced on.\n"); 6909 if (extra & RSS_HASHTYPE_RSS_TCP_IPV6) 6910 CH_ALERT(vi, "TCP/IPv6 4-tuple hashing forced on.\n"); 6911 if (extra & RSS_HASHTYPE_RSS_UDP_IPV4) 6912 CH_ALERT(vi, "UDP/IPv4 4-tuple hashing forced on.\n"); 6913 if (extra & RSS_HASHTYPE_RSS_UDP_IPV6) 6914 CH_ALERT(vi, "UDP/IPv6 4-tuple hashing forced on.\n"); 6915 #else 6916 vi->hashen = F_FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN | 6917 F_FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN | 6918 F_FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN | 6919 F_FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN | F_FW_RSS_VI_CONFIG_CMD_UDPEN; 6920 #endif 6921 rc = -t4_config_vi_rss(sc, sc->mbox, vi->viid, vi->hashen, vi->rss[0], 6922 0, 0); 6923 if (rc != 0) { 6924 CH_ERR(vi, "rss hash/defaultq config failed: %d\n", rc); 6925 return (rc); 6926 } 6927 6928 return (0); 6929 } 6930 6931 int 6932 vi_init(struct vi_info *vi) 6933 { 6934 int rc; 6935 6936 ASSERT_SYNCHRONIZED_OP(vi->adapter); 6937 KASSERT((vi->flags & VI_INIT_DONE) == 0, 6938 ("%s: VI_INIT_DONE already", __func__)); 6939 6940 rc = vi_full_init(vi); 6941 if (rc != 0) 6942 vi_full_uninit(vi); 6943 else 6944 vi->flags |= VI_INIT_DONE; 6945 6946 return (rc); 6947 } 6948 6949 /* 6950 * Idempotent. 6951 */ 6952 static void 6953 vi_full_uninit(struct vi_info *vi) 6954 { 6955 6956 if (vi->flags & VI_INIT_DONE) { 6957 quiesce_vi(vi); 6958 free(vi->rss, M_CXGBE); 6959 free(vi->nm_rss, M_CXGBE); 6960 } 6961 6962 t4_teardown_vi_queues(vi); 6963 vi->flags &= ~VI_INIT_DONE; 6964 } 6965 6966 static void 6967 quiesce_txq(struct sge_txq *txq) 6968 { 6969 struct sge_eq *eq = &txq->eq; 6970 struct sge_qstat *spg = (void *)&eq->desc[eq->sidx]; 6971 6972 MPASS(eq->flags & EQ_SW_ALLOCATED); 6973 MPASS(!(eq->flags & EQ_ENABLED)); 6974 6975 /* Wait for the mp_ring to empty. */ 6976 while (!mp_ring_is_idle(txq->r)) { 6977 mp_ring_check_drainage(txq->r, 4096); 6978 pause("rquiesce", 1); 6979 } 6980 MPASS(txq->txp.npkt == 0); 6981 6982 if (eq->flags & EQ_HW_ALLOCATED) { 6983 /* 6984 * Hardware is alive and working normally. Wait for it to 6985 * finish and then wait for the driver to catch up and reclaim 6986 * all descriptors. 6987 */ 6988 while (spg->cidx != htobe16(eq->pidx)) 6989 pause("equiesce", 1); 6990 while (eq->cidx != eq->pidx) 6991 pause("dquiesce", 1); 6992 } else { 6993 /* 6994 * Hardware is unavailable. Discard all pending tx and reclaim 6995 * descriptors directly. 6996 */ 6997 TXQ_LOCK(txq); 6998 while (eq->cidx != eq->pidx) { 6999 struct mbuf *m, *nextpkt; 7000 struct tx_sdesc *txsd; 7001 7002 txsd = &txq->sdesc[eq->cidx]; 7003 for (m = txsd->m; m != NULL; m = nextpkt) { 7004 nextpkt = m->m_nextpkt; 7005 m->m_nextpkt = NULL; 7006 m_freem(m); 7007 } 7008 IDXINCR(eq->cidx, txsd->desc_used, eq->sidx); 7009 } 7010 spg->pidx = spg->cidx = htobe16(eq->cidx); 7011 TXQ_UNLOCK(txq); 7012 } 7013 } 7014 7015 static void 7016 quiesce_wrq(struct sge_wrq *wrq) 7017 { 7018 7019 /* XXXTX */ 7020 } 7021 7022 static void 7023 quiesce_iq_fl(struct adapter *sc, struct sge_iq *iq, struct sge_fl *fl) 7024 { 7025 /* Synchronize with the interrupt handler */ 7026 while (!atomic_cmpset_int(&iq->state, IQS_IDLE, IQS_DISABLED)) 7027 pause("iqfree", 1); 7028 7029 if (fl != NULL) { 7030 MPASS(iq->flags & IQ_HAS_FL); 7031 7032 mtx_lock(&sc->sfl_lock); 7033 FL_LOCK(fl); 7034 fl->flags |= FL_DOOMED; 7035 FL_UNLOCK(fl); 7036 callout_stop(&sc->sfl_callout); 7037 mtx_unlock(&sc->sfl_lock); 7038 7039 KASSERT((fl->flags & FL_STARVING) == 0, 7040 ("%s: still starving", __func__)); 7041 7042 /* Release all buffers if hardware is no longer available. */ 7043 if (!(iq->flags & IQ_HW_ALLOCATED)) 7044 free_fl_buffers(sc, fl); 7045 } 7046 } 7047 7048 /* 7049 * Wait for all activity on all the queues of the VI to complete. It is assumed 7050 * that no new work is being enqueued by the hardware or the driver. That part 7051 * should be arranged before calling this function. 7052 */ 7053 static void 7054 quiesce_vi(struct vi_info *vi) 7055 { 7056 int i; 7057 struct adapter *sc = vi->adapter; 7058 struct sge_rxq *rxq; 7059 struct sge_txq *txq; 7060 #ifdef TCP_OFFLOAD 7061 struct sge_ofld_rxq *ofld_rxq; 7062 #endif 7063 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 7064 struct sge_ofld_txq *ofld_txq; 7065 #endif 7066 7067 if (!(vi->flags & VI_INIT_DONE)) 7068 return; 7069 7070 for_each_txq(vi, i, txq) { 7071 quiesce_txq(txq); 7072 } 7073 7074 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 7075 for_each_ofld_txq(vi, i, ofld_txq) { 7076 quiesce_wrq(&ofld_txq->wrq); 7077 } 7078 #endif 7079 7080 for_each_rxq(vi, i, rxq) { 7081 quiesce_iq_fl(sc, &rxq->iq, &rxq->fl); 7082 } 7083 7084 #ifdef TCP_OFFLOAD 7085 for_each_ofld_rxq(vi, i, ofld_rxq) { 7086 quiesce_iq_fl(sc, &ofld_rxq->iq, &ofld_rxq->fl); 7087 } 7088 #endif 7089 } 7090 7091 static int 7092 t4_alloc_irq(struct adapter *sc, struct irq *irq, int rid, 7093 driver_intr_t *handler, void *arg, char *name) 7094 { 7095 int rc; 7096 7097 irq->rid = rid; 7098 irq->res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &irq->rid, 7099 RF_SHAREABLE | RF_ACTIVE); 7100 if (irq->res == NULL) { 7101 device_printf(sc->dev, 7102 "failed to allocate IRQ for rid %d, name %s.\n", rid, name); 7103 return (ENOMEM); 7104 } 7105 7106 rc = bus_setup_intr(sc->dev, irq->res, INTR_MPSAFE | INTR_TYPE_NET, 7107 NULL, handler, arg, &irq->tag); 7108 if (rc != 0) { 7109 device_printf(sc->dev, 7110 "failed to setup interrupt for rid %d, name %s: %d\n", 7111 rid, name, rc); 7112 } else if (name) 7113 bus_describe_intr(sc->dev, irq->res, irq->tag, "%s", name); 7114 7115 return (rc); 7116 } 7117 7118 static int 7119 t4_free_irq(struct adapter *sc, struct irq *irq) 7120 { 7121 if (irq->tag) 7122 bus_teardown_intr(sc->dev, irq->res, irq->tag); 7123 if (irq->res) 7124 bus_release_resource(sc->dev, SYS_RES_IRQ, irq->rid, irq->res); 7125 7126 bzero(irq, sizeof(*irq)); 7127 7128 return (0); 7129 } 7130 7131 static void 7132 get_regs(struct adapter *sc, struct t4_regdump *regs, uint8_t *buf) 7133 { 7134 7135 regs->version = chip_id(sc) | chip_rev(sc) << 10; 7136 t4_get_regs(sc, buf, regs->len); 7137 } 7138 7139 #define A_PL_INDIR_CMD 0x1f8 7140 7141 #define S_PL_AUTOINC 31 7142 #define M_PL_AUTOINC 0x1U 7143 #define V_PL_AUTOINC(x) ((x) << S_PL_AUTOINC) 7144 #define G_PL_AUTOINC(x) (((x) >> S_PL_AUTOINC) & M_PL_AUTOINC) 7145 7146 #define S_PL_VFID 20 7147 #define M_PL_VFID 0xffU 7148 #define V_PL_VFID(x) ((x) << S_PL_VFID) 7149 #define G_PL_VFID(x) (((x) >> S_PL_VFID) & M_PL_VFID) 7150 7151 #define S_PL_ADDR 0 7152 #define M_PL_ADDR 0xfffffU 7153 #define V_PL_ADDR(x) ((x) << S_PL_ADDR) 7154 #define G_PL_ADDR(x) (((x) >> S_PL_ADDR) & M_PL_ADDR) 7155 7156 #define A_PL_INDIR_DATA 0x1fc 7157 7158 static uint64_t 7159 read_vf_stat(struct adapter *sc, u_int vin, int reg) 7160 { 7161 u32 stats[2]; 7162 7163 if (sc->flags & IS_VF) { 7164 stats[0] = t4_read_reg(sc, VF_MPS_REG(reg)); 7165 stats[1] = t4_read_reg(sc, VF_MPS_REG(reg + 4)); 7166 } else { 7167 mtx_assert(&sc->reg_lock, MA_OWNED); 7168 t4_write_reg(sc, A_PL_INDIR_CMD, V_PL_AUTOINC(1) | 7169 V_PL_VFID(vin) | V_PL_ADDR(VF_MPS_REG(reg))); 7170 stats[0] = t4_read_reg(sc, A_PL_INDIR_DATA); 7171 stats[1] = t4_read_reg(sc, A_PL_INDIR_DATA); 7172 } 7173 return (((uint64_t)stats[1]) << 32 | stats[0]); 7174 } 7175 7176 static void 7177 t4_get_vi_stats(struct adapter *sc, u_int vin, struct fw_vi_stats_vf *stats) 7178 { 7179 7180 #define GET_STAT(name) \ 7181 read_vf_stat(sc, vin, A_MPS_VF_STAT_##name##_L) 7182 7183 if (!(sc->flags & IS_VF)) 7184 mtx_lock(&sc->reg_lock); 7185 stats->tx_bcast_bytes = GET_STAT(TX_VF_BCAST_BYTES); 7186 stats->tx_bcast_frames = GET_STAT(TX_VF_BCAST_FRAMES); 7187 stats->tx_mcast_bytes = GET_STAT(TX_VF_MCAST_BYTES); 7188 stats->tx_mcast_frames = GET_STAT(TX_VF_MCAST_FRAMES); 7189 stats->tx_ucast_bytes = GET_STAT(TX_VF_UCAST_BYTES); 7190 stats->tx_ucast_frames = GET_STAT(TX_VF_UCAST_FRAMES); 7191 stats->tx_drop_frames = GET_STAT(TX_VF_DROP_FRAMES); 7192 stats->tx_offload_bytes = GET_STAT(TX_VF_OFFLOAD_BYTES); 7193 stats->tx_offload_frames = GET_STAT(TX_VF_OFFLOAD_FRAMES); 7194 stats->rx_bcast_bytes = GET_STAT(RX_VF_BCAST_BYTES); 7195 stats->rx_bcast_frames = GET_STAT(RX_VF_BCAST_FRAMES); 7196 stats->rx_mcast_bytes = GET_STAT(RX_VF_MCAST_BYTES); 7197 stats->rx_mcast_frames = GET_STAT(RX_VF_MCAST_FRAMES); 7198 stats->rx_ucast_bytes = GET_STAT(RX_VF_UCAST_BYTES); 7199 stats->rx_ucast_frames = GET_STAT(RX_VF_UCAST_FRAMES); 7200 stats->rx_err_frames = GET_STAT(RX_VF_ERR_FRAMES); 7201 if (!(sc->flags & IS_VF)) 7202 mtx_unlock(&sc->reg_lock); 7203 7204 #undef GET_STAT 7205 } 7206 7207 static void 7208 t4_clr_vi_stats(struct adapter *sc, u_int vin) 7209 { 7210 int reg; 7211 7212 t4_write_reg(sc, A_PL_INDIR_CMD, V_PL_AUTOINC(1) | V_PL_VFID(vin) | 7213 V_PL_ADDR(VF_MPS_REG(A_MPS_VF_STAT_TX_VF_BCAST_BYTES_L))); 7214 for (reg = A_MPS_VF_STAT_TX_VF_BCAST_BYTES_L; 7215 reg <= A_MPS_VF_STAT_RX_VF_ERR_FRAMES_H; reg += 4) 7216 t4_write_reg(sc, A_PL_INDIR_DATA, 0); 7217 } 7218 7219 static void 7220 vi_refresh_stats(struct vi_info *vi) 7221 { 7222 struct timeval tv; 7223 const struct timeval interval = {0, 250000}; /* 250ms */ 7224 7225 mtx_assert(&vi->tick_mtx, MA_OWNED); 7226 7227 if (vi->flags & VI_SKIP_STATS) 7228 return; 7229 7230 getmicrotime(&tv); 7231 timevalsub(&tv, &interval); 7232 if (timevalcmp(&tv, &vi->last_refreshed, <)) 7233 return; 7234 7235 t4_get_vi_stats(vi->adapter, vi->vin, &vi->stats); 7236 getmicrotime(&vi->last_refreshed); 7237 } 7238 7239 static void 7240 cxgbe_refresh_stats(struct vi_info *vi) 7241 { 7242 u_int i, v, tnl_cong_drops, chan_map; 7243 struct timeval tv; 7244 const struct timeval interval = {0, 250000}; /* 250ms */ 7245 struct port_info *pi; 7246 struct adapter *sc; 7247 7248 mtx_assert(&vi->tick_mtx, MA_OWNED); 7249 7250 if (vi->flags & VI_SKIP_STATS) 7251 return; 7252 7253 getmicrotime(&tv); 7254 timevalsub(&tv, &interval); 7255 if (timevalcmp(&tv, &vi->last_refreshed, <)) 7256 return; 7257 7258 pi = vi->pi; 7259 sc = vi->adapter; 7260 tnl_cong_drops = 0; 7261 t4_get_port_stats(sc, pi->port_id, &pi->stats); 7262 chan_map = pi->rx_e_chan_map; 7263 while (chan_map) { 7264 i = ffs(chan_map) - 1; 7265 mtx_lock(&sc->reg_lock); 7266 t4_read_indirect(sc, A_TP_MIB_INDEX, A_TP_MIB_DATA, &v, 1, 7267 A_TP_MIB_TNL_CNG_DROP_0 + i); 7268 mtx_unlock(&sc->reg_lock); 7269 tnl_cong_drops += v; 7270 chan_map &= ~(1 << i); 7271 } 7272 pi->tnl_cong_drops = tnl_cong_drops; 7273 getmicrotime(&vi->last_refreshed); 7274 } 7275 7276 static void 7277 cxgbe_tick(void *arg) 7278 { 7279 struct vi_info *vi = arg; 7280 7281 MPASS(IS_MAIN_VI(vi)); 7282 mtx_assert(&vi->tick_mtx, MA_OWNED); 7283 7284 cxgbe_refresh_stats(vi); 7285 callout_schedule(&vi->tick, hz); 7286 } 7287 7288 static void 7289 vi_tick(void *arg) 7290 { 7291 struct vi_info *vi = arg; 7292 7293 mtx_assert(&vi->tick_mtx, MA_OWNED); 7294 7295 vi_refresh_stats(vi); 7296 callout_schedule(&vi->tick, hz); 7297 } 7298 7299 /* 7300 * Should match fw_caps_config_<foo> enums in t4fw_interface.h 7301 */ 7302 static char *caps_decoder[] = { 7303 "\20\001IPMI\002NCSI", /* 0: NBM */ 7304 "\20\001PPP\002QFC\003DCBX", /* 1: link */ 7305 "\20\001INGRESS\002EGRESS", /* 2: switch */ 7306 "\20\001NIC\002VM\003IDS\004UM\005UM_ISGL" /* 3: NIC */ 7307 "\006HASHFILTER\007ETHOFLD", 7308 "\20\001TOE", /* 4: TOE */ 7309 "\20\001RDDP\002RDMAC", /* 5: RDMA */ 7310 "\20\001INITIATOR_PDU\002TARGET_PDU" /* 6: iSCSI */ 7311 "\003INITIATOR_CNXOFLD\004TARGET_CNXOFLD" 7312 "\005INITIATOR_SSNOFLD\006TARGET_SSNOFLD" 7313 "\007T10DIF" 7314 "\010INITIATOR_CMDOFLD\011TARGET_CMDOFLD", 7315 "\20\001LOOKASIDE\002TLSKEYS\003IPSEC_INLINE" /* 7: Crypto */ 7316 "\004TLS_HW", 7317 "\20\001INITIATOR\002TARGET\003CTRL_OFLD" /* 8: FCoE */ 7318 "\004PO_INITIATOR\005PO_TARGET", 7319 }; 7320 7321 void 7322 t4_sysctls(struct adapter *sc) 7323 { 7324 struct sysctl_ctx_list *ctx = &sc->ctx; 7325 struct sysctl_oid *oid; 7326 struct sysctl_oid_list *children, *c0; 7327 static char *doorbells = {"\20\1UDB\2WCWR\3UDBWC\4KDB"}; 7328 7329 /* 7330 * dev.t4nex.X. 7331 */ 7332 oid = device_get_sysctl_tree(sc->dev); 7333 c0 = children = SYSCTL_CHILDREN(oid); 7334 7335 sc->sc_do_rxcopy = 1; 7336 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "do_rx_copy", CTLFLAG_RW, 7337 &sc->sc_do_rxcopy, 1, "Do RX copy of small frames"); 7338 7339 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nports", CTLFLAG_RD, NULL, 7340 sc->params.nports, "# of ports"); 7341 7342 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "doorbells", 7343 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, doorbells, 7344 (uintptr_t)&sc->doorbells, sysctl_bitfield_8b, "A", 7345 "available doorbells"); 7346 7347 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "core_clock", CTLFLAG_RD, NULL, 7348 sc->params.vpd.cclk, "core clock frequency (in KHz)"); 7349 7350 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_timers", 7351 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, 7352 sc->params.sge.timer_val, sizeof(sc->params.sge.timer_val), 7353 sysctl_int_array, "A", "interrupt holdoff timer values (us)"); 7354 7355 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pkt_counts", 7356 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, 7357 sc->params.sge.counter_val, sizeof(sc->params.sge.counter_val), 7358 sysctl_int_array, "A", "interrupt holdoff packet counter values"); 7359 7360 t4_sge_sysctls(sc, ctx, children); 7361 7362 sc->lro_timeout = 100; 7363 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "lro_timeout", CTLFLAG_RW, 7364 &sc->lro_timeout, 0, "lro inactive-flush timeout (in us)"); 7365 7366 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "dflags", CTLFLAG_RW, 7367 &sc->debug_flags, 0, "flags to enable runtime debugging"); 7368 7369 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "tp_version", 7370 CTLFLAG_RD, sc->tp_version, 0, "TP microcode version"); 7371 7372 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "firmware_version", 7373 CTLFLAG_RD, sc->fw_version, 0, "firmware version"); 7374 7375 if (sc->flags & IS_VF) 7376 return; 7377 7378 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "hw_revision", CTLFLAG_RD, 7379 NULL, chip_rev(sc), "chip hardware revision"); 7380 7381 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "sn", 7382 CTLFLAG_RD, sc->params.vpd.sn, 0, "serial number"); 7383 7384 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "pn", 7385 CTLFLAG_RD, sc->params.vpd.pn, 0, "part number"); 7386 7387 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "ec", 7388 CTLFLAG_RD, sc->params.vpd.ec, 0, "engineering change"); 7389 7390 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "md_version", 7391 CTLFLAG_RD, sc->params.vpd.md, 0, "manufacturing diags version"); 7392 7393 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "na", 7394 CTLFLAG_RD, sc->params.vpd.na, 0, "network address"); 7395 7396 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "er_version", CTLFLAG_RD, 7397 sc->er_version, 0, "expansion ROM version"); 7398 7399 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "bs_version", CTLFLAG_RD, 7400 sc->bs_version, 0, "bootstrap firmware version"); 7401 7402 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "scfg_version", CTLFLAG_RD, 7403 NULL, sc->params.scfg_vers, "serial config version"); 7404 7405 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "vpd_version", CTLFLAG_RD, 7406 NULL, sc->params.vpd_vers, "VPD version"); 7407 7408 SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "cf", 7409 CTLFLAG_RD, sc->cfg_file, 0, "configuration file"); 7410 7411 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "cfcsum", CTLFLAG_RD, NULL, 7412 sc->cfcsum, "config file checksum"); 7413 7414 #define SYSCTL_CAP(name, n, text) \ 7415 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, #name, \ 7416 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, caps_decoder[n], \ 7417 (uintptr_t)&sc->name, sysctl_bitfield_16b, "A", \ 7418 "available " text " capabilities") 7419 7420 SYSCTL_CAP(nbmcaps, 0, "NBM"); 7421 SYSCTL_CAP(linkcaps, 1, "link"); 7422 SYSCTL_CAP(switchcaps, 2, "switch"); 7423 SYSCTL_CAP(niccaps, 3, "NIC"); 7424 SYSCTL_CAP(toecaps, 4, "TCP offload"); 7425 SYSCTL_CAP(rdmacaps, 5, "RDMA"); 7426 SYSCTL_CAP(iscsicaps, 6, "iSCSI"); 7427 SYSCTL_CAP(cryptocaps, 7, "crypto"); 7428 SYSCTL_CAP(fcoecaps, 8, "FCoE"); 7429 #undef SYSCTL_CAP 7430 7431 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nfilters", CTLFLAG_RD, 7432 NULL, sc->tids.nftids, "number of filters"); 7433 7434 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature", 7435 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7436 sysctl_temperature, "I", "chip temperature (in Celsius)"); 7437 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "reset_sensor", 7438 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0, 7439 sysctl_reset_sensor, "I", "reset the chip's temperature sensor."); 7440 7441 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "loadavg", 7442 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7443 sysctl_loadavg, "A", 7444 "microprocessor load averages (debug firmwares only)"); 7445 7446 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "core_vdd", 7447 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, sysctl_vdd, 7448 "I", "core Vdd (in mV)"); 7449 7450 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "local_cpus", 7451 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, LOCAL_CPUS, 7452 sysctl_cpus, "A", "local CPUs"); 7453 7454 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_cpus", 7455 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, INTR_CPUS, 7456 sysctl_cpus, "A", "preferred CPUs for interrupts"); 7457 7458 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "swintr", CTLFLAG_RW, 7459 &sc->swintr, 0, "software triggered interrupts"); 7460 7461 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "reset", 7462 CTLTYPE_INT | CTLFLAG_RW, sc, 0, sysctl_reset, "I", 7463 "1 = reset adapter, 0 = zero reset counter"); 7464 7465 /* 7466 * dev.t4nex.X.misc. Marked CTLFLAG_SKIP to avoid information overload. 7467 */ 7468 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "misc", 7469 CTLFLAG_RD | CTLFLAG_SKIP | CTLFLAG_MPSAFE, NULL, 7470 "logs and miscellaneous information"); 7471 children = SYSCTL_CHILDREN(oid); 7472 7473 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cctrl", 7474 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7475 sysctl_cctrl, "A", "congestion control"); 7476 7477 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp0", 7478 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7479 sysctl_cim_ibq_obq, "A", "CIM IBQ 0 (TP0)"); 7480 7481 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_tp1", 7482 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 1, 7483 sysctl_cim_ibq_obq, "A", "CIM IBQ 1 (TP1)"); 7484 7485 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ulp", 7486 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 2, 7487 sysctl_cim_ibq_obq, "A", "CIM IBQ 2 (ULP)"); 7488 7489 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge0", 7490 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 3, 7491 sysctl_cim_ibq_obq, "A", "CIM IBQ 3 (SGE0)"); 7492 7493 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_sge1", 7494 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 4, 7495 sysctl_cim_ibq_obq, "A", "CIM IBQ 4 (SGE1)"); 7496 7497 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ibq_ncsi", 7498 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 5, 7499 sysctl_cim_ibq_obq, "A", "CIM IBQ 5 (NCSI)"); 7500 7501 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_la", 7502 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7503 sysctl_cim_la, "A", "CIM logic analyzer"); 7504 7505 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_ma_la", 7506 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7507 sysctl_cim_ma_la, "A", "CIM MA logic analyzer"); 7508 7509 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp0", 7510 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7511 0 + CIM_NUM_IBQ, sysctl_cim_ibq_obq, "A", "CIM OBQ 0 (ULP0)"); 7512 7513 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp1", 7514 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7515 1 + CIM_NUM_IBQ, sysctl_cim_ibq_obq, "A", "CIM OBQ 1 (ULP1)"); 7516 7517 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp2", 7518 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7519 2 + CIM_NUM_IBQ, sysctl_cim_ibq_obq, "A", "CIM OBQ 2 (ULP2)"); 7520 7521 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ulp3", 7522 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7523 3 + CIM_NUM_IBQ, sysctl_cim_ibq_obq, "A", "CIM OBQ 3 (ULP3)"); 7524 7525 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge", 7526 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7527 4 + CIM_NUM_IBQ, sysctl_cim_ibq_obq, "A", "CIM OBQ 4 (SGE)"); 7528 7529 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_ncsi", 7530 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7531 5 + CIM_NUM_IBQ, sysctl_cim_ibq_obq, "A", "CIM OBQ 5 (NCSI)"); 7532 7533 if (chip_id(sc) > CHELSIO_T4) { 7534 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge0_rx", 7535 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7536 6 + CIM_NUM_IBQ, sysctl_cim_ibq_obq, "A", 7537 "CIM OBQ 6 (SGE0-RX)"); 7538 7539 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_obq_sge1_rx", 7540 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7541 7 + CIM_NUM_IBQ, sysctl_cim_ibq_obq, "A", 7542 "CIM OBQ 7 (SGE1-RX)"); 7543 } 7544 7545 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_pif_la", 7546 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7547 sysctl_cim_pif_la, "A", "CIM PIF logic analyzer"); 7548 7549 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cim_qcfg", 7550 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7551 sysctl_cim_qcfg, "A", "CIM queue configuration"); 7552 7553 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cpl_stats", 7554 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7555 sysctl_cpl_stats, "A", "CPL statistics"); 7556 7557 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ddp_stats", 7558 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7559 sysctl_ddp_stats, "A", "non-TCP DDP statistics"); 7560 7561 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tid_stats", 7562 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7563 sysctl_tid_stats, "A", "tid stats"); 7564 7565 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "devlog", 7566 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7567 sysctl_devlog, "A", "firmware's device log"); 7568 7569 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fcoe_stats", 7570 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7571 sysctl_fcoe_stats, "A", "FCoE statistics"); 7572 7573 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "hw_sched", 7574 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7575 sysctl_hw_sched, "A", "hardware scheduler "); 7576 7577 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "l2t", 7578 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7579 sysctl_l2t, "A", "hardware L2 table"); 7580 7581 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "smt", 7582 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7583 sysctl_smt, "A", "hardware source MAC table"); 7584 7585 #ifdef INET6 7586 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "clip", 7587 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7588 sysctl_clip, "A", "active CLIP table entries"); 7589 #endif 7590 7591 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "lb_stats", 7592 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7593 sysctl_lb_stats, "A", "loopback statistics"); 7594 7595 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "meminfo", 7596 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7597 sysctl_meminfo, "A", "memory regions"); 7598 7599 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "mps_tcam", 7600 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7601 chip_id(sc) <= CHELSIO_T5 ? sysctl_mps_tcam : sysctl_mps_tcam_t6, 7602 "A", "MPS TCAM entries"); 7603 7604 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "path_mtus", 7605 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7606 sysctl_path_mtus, "A", "path MTUs"); 7607 7608 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pm_stats", 7609 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7610 sysctl_pm_stats, "A", "PM statistics"); 7611 7612 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rdma_stats", 7613 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7614 sysctl_rdma_stats, "A", "RDMA statistics"); 7615 7616 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tcp_stats", 7617 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7618 sysctl_tcp_stats, "A", "TCP statistics"); 7619 7620 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tids", 7621 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7622 sysctl_tids, "A", "TID information"); 7623 7624 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_err_stats", 7625 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7626 sysctl_tp_err_stats, "A", "TP error statistics"); 7627 7628 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tnl_stats", 7629 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7630 sysctl_tnl_stats, "A", "TP tunnel statistics"); 7631 7632 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_la_mask", 7633 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0, 7634 sysctl_tp_la_mask, "I", "TP logic analyzer event capture mask"); 7635 7636 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tp_la", 7637 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7638 sysctl_tp_la, "A", "TP logic analyzer"); 7639 7640 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_rate", 7641 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7642 sysctl_tx_rate, "A", "Tx rate"); 7643 7644 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "ulprx_la", 7645 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7646 sysctl_ulprx_la, "A", "ULPRX logic analyzer"); 7647 7648 if (chip_id(sc) >= CHELSIO_T5) { 7649 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "wcwr_stats", 7650 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7651 sysctl_wcwr_stats, "A", "write combined work requests"); 7652 } 7653 7654 #ifdef KERN_TLS 7655 if (is_ktls(sc)) { 7656 /* 7657 * dev.t4nex.0.tls. 7658 */ 7659 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "tls", 7660 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "KERN_TLS parameters"); 7661 children = SYSCTL_CHILDREN(oid); 7662 7663 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "inline_keys", 7664 CTLFLAG_RW, &sc->tlst.inline_keys, 0, "Always pass TLS " 7665 "keys in work requests (1) or attempt to store TLS keys " 7666 "in card memory."); 7667 7668 if (is_t6(sc)) 7669 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "combo_wrs", 7670 CTLFLAG_RW, &sc->tlst.combo_wrs, 0, "Attempt to " 7671 "combine TCB field updates with TLS record work " 7672 "requests."); 7673 } 7674 #endif 7675 7676 #ifdef TCP_OFFLOAD 7677 if (is_offload(sc)) { 7678 int i; 7679 char s[4]; 7680 7681 /* 7682 * dev.t4nex.X.toe. 7683 */ 7684 oid = SYSCTL_ADD_NODE(ctx, c0, OID_AUTO, "toe", 7685 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "TOE parameters"); 7686 children = SYSCTL_CHILDREN(oid); 7687 7688 sc->tt.cong_algorithm = -1; 7689 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "cong_algorithm", 7690 CTLFLAG_RW, &sc->tt.cong_algorithm, 0, "congestion control " 7691 "(-1 = default, 0 = reno, 1 = tahoe, 2 = newreno, " 7692 "3 = highspeed)"); 7693 7694 sc->tt.sndbuf = -1; 7695 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "sndbuf", CTLFLAG_RW, 7696 &sc->tt.sndbuf, 0, "hardware send buffer"); 7697 7698 sc->tt.ddp = 0; 7699 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ddp", 7700 CTLFLAG_RW | CTLFLAG_SKIP, &sc->tt.ddp, 0, ""); 7701 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_zcopy", CTLFLAG_RW, 7702 &sc->tt.ddp, 0, "Enable zero-copy aio_read(2)"); 7703 7704 sc->tt.rx_coalesce = -1; 7705 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_coalesce", 7706 CTLFLAG_RW, &sc->tt.rx_coalesce, 0, "receive coalescing"); 7707 7708 sc->tt.tls = 0; 7709 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tls", CTLTYPE_INT | 7710 CTLFLAG_RW | CTLFLAG_MPSAFE, sc, 0, sysctl_tls, "I", 7711 "Inline TLS allowed"); 7712 7713 sc->tt.tx_align = -1; 7714 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_align", 7715 CTLFLAG_RW, &sc->tt.tx_align, 0, "chop and align payload"); 7716 7717 sc->tt.tx_zcopy = 0; 7718 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_zcopy", 7719 CTLFLAG_RW, &sc->tt.tx_zcopy, 0, 7720 "Enable zero-copy aio_write(2)"); 7721 7722 sc->tt.cop_managed_offloading = !!t4_cop_managed_offloading; 7723 SYSCTL_ADD_INT(ctx, children, OID_AUTO, 7724 "cop_managed_offloading", CTLFLAG_RW, 7725 &sc->tt.cop_managed_offloading, 0, 7726 "COP (Connection Offload Policy) controls all TOE offload"); 7727 7728 sc->tt.autorcvbuf_inc = 16 * 1024; 7729 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "autorcvbuf_inc", 7730 CTLFLAG_RW, &sc->tt.autorcvbuf_inc, 0, 7731 "autorcvbuf increment"); 7732 7733 sc->tt.update_hc_on_pmtu_change = 1; 7734 SYSCTL_ADD_INT(ctx, children, OID_AUTO, 7735 "update_hc_on_pmtu_change", CTLFLAG_RW, 7736 &sc->tt.update_hc_on_pmtu_change, 0, 7737 "Update hostcache entry if the PMTU changes"); 7738 7739 sc->tt.iso = 1; 7740 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "iso", CTLFLAG_RW, 7741 &sc->tt.iso, 0, "Enable iSCSI segmentation offload"); 7742 7743 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "timer_tick", 7744 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7745 sysctl_tp_tick, "A", "TP timer tick (us)"); 7746 7747 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "timestamp_tick", 7748 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 1, 7749 sysctl_tp_tick, "A", "TCP timestamp tick (us)"); 7750 7751 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "dack_tick", 7752 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 2, 7753 sysctl_tp_tick, "A", "DACK tick (us)"); 7754 7755 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "dack_timer", 7756 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, 7757 sysctl_tp_dack_timer, "IU", "DACK timer (us)"); 7758 7759 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_min", 7760 CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7761 A_TP_RXT_MIN, sysctl_tp_timer, "LU", 7762 "Minimum retransmit interval (us)"); 7763 7764 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_max", 7765 CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7766 A_TP_RXT_MAX, sysctl_tp_timer, "LU", 7767 "Maximum retransmit interval (us)"); 7768 7769 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "persist_min", 7770 CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7771 A_TP_PERS_MIN, sysctl_tp_timer, "LU", 7772 "Persist timer min (us)"); 7773 7774 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "persist_max", 7775 CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7776 A_TP_PERS_MAX, sysctl_tp_timer, "LU", 7777 "Persist timer max (us)"); 7778 7779 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_idle", 7780 CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7781 A_TP_KEEP_IDLE, sysctl_tp_timer, "LU", 7782 "Keepalive idle timer (us)"); 7783 7784 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_interval", 7785 CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7786 A_TP_KEEP_INTVL, sysctl_tp_timer, "LU", 7787 "Keepalive interval timer (us)"); 7788 7789 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "initial_srtt", 7790 CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7791 A_TP_INIT_SRTT, sysctl_tp_timer, "LU", "Initial SRTT (us)"); 7792 7793 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "finwait2_timer", 7794 CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7795 A_TP_FINWAIT2_TIMER, sysctl_tp_timer, "LU", 7796 "FINWAIT2 timer (us)"); 7797 7798 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "syn_rexmt_count", 7799 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7800 S_SYNSHIFTMAX, sysctl_tp_shift_cnt, "IU", 7801 "Number of SYN retransmissions before abort"); 7802 7803 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rexmt_count", 7804 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7805 S_RXTSHIFTMAXR2, sysctl_tp_shift_cnt, "IU", 7806 "Number of retransmissions before abort"); 7807 7808 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "keepalive_count", 7809 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7810 S_KEEPALIVEMAXR2, sysctl_tp_shift_cnt, "IU", 7811 "Number of keepalive probes before abort"); 7812 7813 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "rexmt_backoff", 7814 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 7815 "TOE retransmit backoffs"); 7816 children = SYSCTL_CHILDREN(oid); 7817 for (i = 0; i < 16; i++) { 7818 snprintf(s, sizeof(s), "%u", i); 7819 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, s, 7820 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 7821 i, sysctl_tp_backoff, "IU", 7822 "TOE retransmit backoff"); 7823 } 7824 } 7825 #endif 7826 } 7827 7828 void 7829 vi_sysctls(struct vi_info *vi) 7830 { 7831 struct sysctl_ctx_list *ctx = &vi->ctx; 7832 struct sysctl_oid *oid; 7833 struct sysctl_oid_list *children; 7834 7835 /* 7836 * dev.v?(cxgbe|cxl).X. 7837 */ 7838 oid = device_get_sysctl_tree(vi->dev); 7839 children = SYSCTL_CHILDREN(oid); 7840 7841 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "viid", CTLFLAG_RD, NULL, 7842 vi->viid, "VI identifer"); 7843 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nrxq", CTLFLAG_RD, 7844 &vi->nrxq, 0, "# of rx queues"); 7845 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "ntxq", CTLFLAG_RD, 7846 &vi->ntxq, 0, "# of tx queues"); 7847 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_rxq", CTLFLAG_RD, 7848 &vi->first_rxq, 0, "index of first rx queue"); 7849 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_txq", CTLFLAG_RD, 7850 &vi->first_txq, 0, "index of first tx queue"); 7851 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "rss_base", CTLFLAG_RD, NULL, 7852 vi->rss_base, "start of RSS indirection table"); 7853 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "rss_size", CTLFLAG_RD, NULL, 7854 vi->rss_size, "size of RSS indirection table"); 7855 7856 if (IS_MAIN_VI(vi)) { 7857 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rsrv_noflowq", 7858 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, vi, 0, 7859 sysctl_noflowq, "IU", 7860 "Reserve queue 0 for non-flowid packets"); 7861 } 7862 7863 if (vi->adapter->flags & IS_VF) { 7864 MPASS(vi->flags & TX_USES_VM_WR); 7865 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "tx_vm_wr", CTLFLAG_RD, 7866 NULL, 1, "use VM work requests for transmit"); 7867 } else { 7868 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "tx_vm_wr", 7869 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, vi, 0, 7870 sysctl_tx_vm_wr, "I", "use VM work requestes for transmit"); 7871 } 7872 7873 #ifdef TCP_OFFLOAD 7874 if (vi->nofldrxq != 0) { 7875 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldrxq", CTLFLAG_RD, 7876 &vi->nofldrxq, 0, 7877 "# of rx queues for offloaded TCP connections"); 7878 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_rxq", 7879 CTLFLAG_RD, &vi->first_ofld_rxq, 0, 7880 "index of first TOE rx queue"); 7881 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx_ofld", 7882 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, vi, 0, 7883 sysctl_holdoff_tmr_idx_ofld, "I", 7884 "holdoff timer index for TOE queues"); 7885 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx_ofld", 7886 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, vi, 0, 7887 sysctl_holdoff_pktc_idx_ofld, "I", 7888 "holdoff packet counter index for TOE queues"); 7889 } 7890 #endif 7891 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 7892 if (vi->nofldtxq != 0) { 7893 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nofldtxq", CTLFLAG_RD, 7894 &vi->nofldtxq, 0, 7895 "# of tx queues for TOE/ETHOFLD"); 7896 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_ofld_txq", 7897 CTLFLAG_RD, &vi->first_ofld_txq, 0, 7898 "index of first TOE/ETHOFLD tx queue"); 7899 } 7900 #endif 7901 #ifdef DEV_NETMAP 7902 if (vi->nnmrxq != 0) { 7903 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmrxq", CTLFLAG_RD, 7904 &vi->nnmrxq, 0, "# of netmap rx queues"); 7905 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "nnmtxq", CTLFLAG_RD, 7906 &vi->nnmtxq, 0, "# of netmap tx queues"); 7907 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_rxq", 7908 CTLFLAG_RD, &vi->first_nm_rxq, 0, 7909 "index of first netmap rx queue"); 7910 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "first_nm_txq", 7911 CTLFLAG_RD, &vi->first_nm_txq, 0, 7912 "index of first netmap tx queue"); 7913 } 7914 #endif 7915 7916 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_tmr_idx", 7917 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, vi, 0, 7918 sysctl_holdoff_tmr_idx, "I", "holdoff timer index"); 7919 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "holdoff_pktc_idx", 7920 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, vi, 0, 7921 sysctl_holdoff_pktc_idx, "I", "holdoff packet counter index"); 7922 7923 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_rxq", 7924 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, vi, 0, 7925 sysctl_qsize_rxq, "I", "rx queue size"); 7926 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "qsize_txq", 7927 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, vi, 0, 7928 sysctl_qsize_txq, "I", "tx queue size"); 7929 } 7930 7931 static void 7932 cxgbe_sysctls(struct port_info *pi) 7933 { 7934 struct sysctl_ctx_list *ctx = &pi->ctx; 7935 struct sysctl_oid *oid; 7936 struct sysctl_oid_list *children, *children2; 7937 struct adapter *sc = pi->adapter; 7938 int i; 7939 char name[16]; 7940 static char *tc_flags = {"\20\1USER"}; 7941 7942 /* 7943 * dev.cxgbe.X. 7944 */ 7945 oid = device_get_sysctl_tree(pi->dev); 7946 children = SYSCTL_CHILDREN(oid); 7947 7948 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "linkdnrc", 7949 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, pi, 0, 7950 sysctl_linkdnrc, "A", "reason why link is down"); 7951 if (pi->port_type == FW_PORT_TYPE_BT_XAUI) { 7952 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "temperature", 7953 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, pi, 0, 7954 sysctl_btphy, "I", "PHY temperature (in Celsius)"); 7955 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "fw_version", 7956 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, pi, 1, 7957 sysctl_btphy, "I", "PHY firmware version"); 7958 } 7959 7960 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "pause_settings", 7961 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, pi, 0, 7962 sysctl_pause_settings, "A", 7963 "PAUSE settings (bit 0 = rx_pause, 1 = tx_pause, 2 = pause_autoneg)"); 7964 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "link_fec", 7965 CTLTYPE_STRING | CTLFLAG_MPSAFE, pi, 0, sysctl_link_fec, "A", 7966 "FEC in use on the link"); 7967 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "requested_fec", 7968 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, pi, 0, 7969 sysctl_requested_fec, "A", 7970 "FECs to use (bit 0 = RS, 1 = FC, 2 = none, 5 = auto, 6 = module)"); 7971 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "module_fec", 7972 CTLTYPE_STRING | CTLFLAG_MPSAFE, pi, 0, sysctl_module_fec, "A", 7973 "FEC recommended by the cable/transceiver"); 7974 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "autoneg", 7975 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, pi, 0, 7976 sysctl_autoneg, "I", 7977 "autonegotiation (-1 = not supported)"); 7978 SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "force_fec", 7979 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, pi, 0, 7980 sysctl_force_fec, "I", "when to use FORCE_FEC bit for link config"); 7981 7982 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rcaps", CTLFLAG_RD, 7983 &pi->link_cfg.requested_caps, 0, "L1 config requested by driver"); 7984 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "pcaps", CTLFLAG_RD, 7985 &pi->link_cfg.pcaps, 0, "port capabilities"); 7986 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "acaps", CTLFLAG_RD, 7987 &pi->link_cfg.acaps, 0, "advertised capabilities"); 7988 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "lpacaps", CTLFLAG_RD, 7989 &pi->link_cfg.lpacaps, 0, "link partner advertised capabilities"); 7990 7991 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "max_speed", CTLFLAG_RD, NULL, 7992 port_top_speed(pi), "max speed (in Gbps)"); 7993 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "mps_bg_map", CTLFLAG_RD, NULL, 7994 pi->mps_bg_map, "MPS buffer group map"); 7995 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_e_chan_map", CTLFLAG_RD, 7996 NULL, pi->rx_e_chan_map, "TP rx e-channel map"); 7997 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "tx_chan", CTLFLAG_RD, NULL, 7998 pi->tx_chan, "TP tx c-channel"); 7999 SYSCTL_ADD_INT(ctx, children, OID_AUTO, "rx_chan", CTLFLAG_RD, NULL, 8000 pi->rx_chan, "TP rx c-channel"); 8001 8002 if (sc->flags & IS_VF) 8003 return; 8004 8005 /* 8006 * dev.(cxgbe|cxl).X.tc. 8007 */ 8008 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "tc", 8009 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 8010 "Tx scheduler traffic classes (cl_rl)"); 8011 children2 = SYSCTL_CHILDREN(oid); 8012 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "pktsize", 8013 CTLFLAG_RW, &pi->sched_params->pktsize, 0, 8014 "pktsize for per-flow cl-rl (0 means up to the driver )"); 8015 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "burstsize", 8016 CTLFLAG_RW, &pi->sched_params->burstsize, 0, 8017 "burstsize for per-flow cl-rl (0 means up to the driver)"); 8018 for (i = 0; i < sc->params.nsched_cls; i++) { 8019 struct tx_cl_rl_params *tc = &pi->sched_params->cl_rl[i]; 8020 8021 snprintf(name, sizeof(name), "%d", i); 8022 children2 = SYSCTL_CHILDREN(SYSCTL_ADD_NODE(ctx, 8023 SYSCTL_CHILDREN(oid), OID_AUTO, name, 8024 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "traffic class")); 8025 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "state", 8026 CTLFLAG_RD, &tc->state, 0, "current state"); 8027 SYSCTL_ADD_PROC(ctx, children2, OID_AUTO, "flags", 8028 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, tc_flags, 8029 (uintptr_t)&tc->flags, sysctl_bitfield_8b, "A", "flags"); 8030 SYSCTL_ADD_UINT(ctx, children2, OID_AUTO, "refcount", 8031 CTLFLAG_RD, &tc->refcount, 0, "references to this class"); 8032 SYSCTL_ADD_PROC(ctx, children2, OID_AUTO, "params", 8033 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 8034 (pi->port_id << 16) | i, sysctl_tc_params, "A", 8035 "traffic class parameters"); 8036 } 8037 8038 /* 8039 * dev.cxgbe.X.stats. 8040 */ 8041 oid = SYSCTL_ADD_NODE(ctx, children, OID_AUTO, "stats", 8042 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "port statistics"); 8043 children = SYSCTL_CHILDREN(oid); 8044 SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "tx_parse_error", CTLFLAG_RD, 8045 &pi->tx_parse_error, 0, 8046 "# of tx packets with invalid length or # of segments"); 8047 8048 #define T4_REGSTAT(name, stat, desc) \ 8049 SYSCTL_ADD_OID(ctx, children, OID_AUTO, #name, \ 8050 CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, \ 8051 t4_port_reg(sc, pi->tx_chan, A_MPS_PORT_STAT_##stat##_L), \ 8052 sysctl_handle_t4_reg64, "QU", desc) 8053 8054 /* We get these from port_stats and they may be stale by up to 1s */ 8055 #define T4_PORTSTAT(name, desc) \ 8056 SYSCTL_ADD_UQUAD(ctx, children, OID_AUTO, #name, CTLFLAG_RD, \ 8057 &pi->stats.name, desc) 8058 8059 T4_REGSTAT(tx_octets, TX_PORT_BYTES, "# of octets in good frames"); 8060 T4_REGSTAT(tx_frames, TX_PORT_FRAMES, "total # of good frames"); 8061 T4_REGSTAT(tx_bcast_frames, TX_PORT_BCAST, "# of broadcast frames"); 8062 T4_REGSTAT(tx_mcast_frames, TX_PORT_MCAST, "# of multicast frames"); 8063 T4_REGSTAT(tx_ucast_frames, TX_PORT_UCAST, "# of unicast frames"); 8064 T4_REGSTAT(tx_error_frames, TX_PORT_ERROR, "# of error frames"); 8065 T4_REGSTAT(tx_frames_64, TX_PORT_64B, "# of tx frames in this range"); 8066 T4_REGSTAT(tx_frames_65_127, TX_PORT_65B_127B, "# of tx frames in this range"); 8067 T4_REGSTAT(tx_frames_128_255, TX_PORT_128B_255B, "# of tx frames in this range"); 8068 T4_REGSTAT(tx_frames_256_511, TX_PORT_256B_511B, "# of tx frames in this range"); 8069 T4_REGSTAT(tx_frames_512_1023, TX_PORT_512B_1023B, "# of tx frames in this range"); 8070 T4_REGSTAT(tx_frames_1024_1518, TX_PORT_1024B_1518B, "# of tx frames in this range"); 8071 T4_REGSTAT(tx_frames_1519_max, TX_PORT_1519B_MAX, "# of tx frames in this range"); 8072 T4_REGSTAT(tx_drop, TX_PORT_DROP, "# of dropped tx frames"); 8073 T4_REGSTAT(tx_pause, TX_PORT_PAUSE, "# of pause frames transmitted"); 8074 T4_REGSTAT(tx_ppp0, TX_PORT_PPP0, "# of PPP prio 0 frames transmitted"); 8075 T4_REGSTAT(tx_ppp1, TX_PORT_PPP1, "# of PPP prio 1 frames transmitted"); 8076 T4_REGSTAT(tx_ppp2, TX_PORT_PPP2, "# of PPP prio 2 frames transmitted"); 8077 T4_REGSTAT(tx_ppp3, TX_PORT_PPP3, "# of PPP prio 3 frames transmitted"); 8078 T4_REGSTAT(tx_ppp4, TX_PORT_PPP4, "# of PPP prio 4 frames transmitted"); 8079 T4_REGSTAT(tx_ppp5, TX_PORT_PPP5, "# of PPP prio 5 frames transmitted"); 8080 T4_REGSTAT(tx_ppp6, TX_PORT_PPP6, "# of PPP prio 6 frames transmitted"); 8081 T4_REGSTAT(tx_ppp7, TX_PORT_PPP7, "# of PPP prio 7 frames transmitted"); 8082 8083 T4_REGSTAT(rx_octets, RX_PORT_BYTES, "# of octets in good frames"); 8084 T4_REGSTAT(rx_frames, RX_PORT_FRAMES, "total # of good frames"); 8085 T4_REGSTAT(rx_bcast_frames, RX_PORT_BCAST, "# of broadcast frames"); 8086 T4_REGSTAT(rx_mcast_frames, RX_PORT_MCAST, "# of multicast frames"); 8087 T4_REGSTAT(rx_ucast_frames, RX_PORT_UCAST, "# of unicast frames"); 8088 T4_REGSTAT(rx_too_long, RX_PORT_MTU_ERROR, "# of frames exceeding MTU"); 8089 T4_REGSTAT(rx_jabber, RX_PORT_MTU_CRC_ERROR, "# of jabber frames"); 8090 if (is_t6(sc)) { 8091 T4_PORTSTAT(rx_fcs_err, 8092 "# of frames received with bad FCS since last link up"); 8093 } else { 8094 T4_REGSTAT(rx_fcs_err, RX_PORT_CRC_ERROR, 8095 "# of frames received with bad FCS"); 8096 } 8097 T4_REGSTAT(rx_len_err, RX_PORT_LEN_ERROR, "# of frames received with length error"); 8098 T4_REGSTAT(rx_symbol_err, RX_PORT_SYM_ERROR, "symbol errors"); 8099 T4_REGSTAT(rx_runt, RX_PORT_LESS_64B, "# of short frames received"); 8100 T4_REGSTAT(rx_frames_64, RX_PORT_64B, "# of rx frames in this range"); 8101 T4_REGSTAT(rx_frames_65_127, RX_PORT_65B_127B, "# of rx frames in this range"); 8102 T4_REGSTAT(rx_frames_128_255, RX_PORT_128B_255B, "# of rx frames in this range"); 8103 T4_REGSTAT(rx_frames_256_511, RX_PORT_256B_511B, "# of rx frames in this range"); 8104 T4_REGSTAT(rx_frames_512_1023, RX_PORT_512B_1023B, "# of rx frames in this range"); 8105 T4_REGSTAT(rx_frames_1024_1518, RX_PORT_1024B_1518B, "# of rx frames in this range"); 8106 T4_REGSTAT(rx_frames_1519_max, RX_PORT_1519B_MAX, "# of rx frames in this range"); 8107 T4_REGSTAT(rx_pause, RX_PORT_PAUSE, "# of pause frames received"); 8108 T4_REGSTAT(rx_ppp0, RX_PORT_PPP0, "# of PPP prio 0 frames received"); 8109 T4_REGSTAT(rx_ppp1, RX_PORT_PPP1, "# of PPP prio 1 frames received"); 8110 T4_REGSTAT(rx_ppp2, RX_PORT_PPP2, "# of PPP prio 2 frames received"); 8111 T4_REGSTAT(rx_ppp3, RX_PORT_PPP3, "# of PPP prio 3 frames received"); 8112 T4_REGSTAT(rx_ppp4, RX_PORT_PPP4, "# of PPP prio 4 frames received"); 8113 T4_REGSTAT(rx_ppp5, RX_PORT_PPP5, "# of PPP prio 5 frames received"); 8114 T4_REGSTAT(rx_ppp6, RX_PORT_PPP6, "# of PPP prio 6 frames received"); 8115 T4_REGSTAT(rx_ppp7, RX_PORT_PPP7, "# of PPP prio 7 frames received"); 8116 8117 T4_PORTSTAT(rx_ovflow0, "# drops due to buffer-group 0 overflows"); 8118 T4_PORTSTAT(rx_ovflow1, "# drops due to buffer-group 1 overflows"); 8119 T4_PORTSTAT(rx_ovflow2, "# drops due to buffer-group 2 overflows"); 8120 T4_PORTSTAT(rx_ovflow3, "# drops due to buffer-group 3 overflows"); 8121 T4_PORTSTAT(rx_trunc0, "# of buffer-group 0 truncated packets"); 8122 T4_PORTSTAT(rx_trunc1, "# of buffer-group 1 truncated packets"); 8123 T4_PORTSTAT(rx_trunc2, "# of buffer-group 2 truncated packets"); 8124 T4_PORTSTAT(rx_trunc3, "# of buffer-group 3 truncated packets"); 8125 8126 #undef T4_REGSTAT 8127 #undef T4_PORTSTAT 8128 } 8129 8130 static int 8131 sysctl_int_array(SYSCTL_HANDLER_ARGS) 8132 { 8133 int rc, *i, space = 0; 8134 struct sbuf sb; 8135 8136 sbuf_new_for_sysctl(&sb, NULL, 64, req); 8137 for (i = arg1; arg2; arg2 -= sizeof(int), i++) { 8138 if (space) 8139 sbuf_printf(&sb, " "); 8140 sbuf_printf(&sb, "%d", *i); 8141 space = 1; 8142 } 8143 rc = sbuf_finish(&sb); 8144 sbuf_delete(&sb); 8145 return (rc); 8146 } 8147 8148 static int 8149 sysctl_bitfield_8b(SYSCTL_HANDLER_ARGS) 8150 { 8151 int rc; 8152 struct sbuf *sb; 8153 8154 rc = sysctl_wire_old_buffer(req, 0); 8155 if (rc != 0) 8156 return(rc); 8157 8158 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req); 8159 if (sb == NULL) 8160 return (ENOMEM); 8161 8162 sbuf_printf(sb, "%b", *(uint8_t *)(uintptr_t)arg2, (char *)arg1); 8163 rc = sbuf_finish(sb); 8164 sbuf_delete(sb); 8165 8166 return (rc); 8167 } 8168 8169 static int 8170 sysctl_bitfield_16b(SYSCTL_HANDLER_ARGS) 8171 { 8172 int rc; 8173 struct sbuf *sb; 8174 8175 rc = sysctl_wire_old_buffer(req, 0); 8176 if (rc != 0) 8177 return(rc); 8178 8179 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req); 8180 if (sb == NULL) 8181 return (ENOMEM); 8182 8183 sbuf_printf(sb, "%b", *(uint16_t *)(uintptr_t)arg2, (char *)arg1); 8184 rc = sbuf_finish(sb); 8185 sbuf_delete(sb); 8186 8187 return (rc); 8188 } 8189 8190 static int 8191 sysctl_btphy(SYSCTL_HANDLER_ARGS) 8192 { 8193 struct port_info *pi = arg1; 8194 int op = arg2; 8195 struct adapter *sc = pi->adapter; 8196 u_int v; 8197 int rc; 8198 8199 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK, "t4btt"); 8200 if (rc) 8201 return (rc); 8202 if (hw_off_limits(sc)) 8203 rc = ENXIO; 8204 else { 8205 /* XXX: magic numbers */ 8206 rc = -t4_mdio_rd(sc, sc->mbox, pi->mdio_addr, 0x1e, 8207 op ? 0x20 : 0xc820, &v); 8208 } 8209 end_synchronized_op(sc, 0); 8210 if (rc) 8211 return (rc); 8212 if (op == 0) 8213 v /= 256; 8214 8215 rc = sysctl_handle_int(oidp, &v, 0, req); 8216 return (rc); 8217 } 8218 8219 static int 8220 sysctl_noflowq(SYSCTL_HANDLER_ARGS) 8221 { 8222 struct vi_info *vi = arg1; 8223 int rc, val; 8224 8225 val = vi->rsrv_noflowq; 8226 rc = sysctl_handle_int(oidp, &val, 0, req); 8227 if (rc != 0 || req->newptr == NULL) 8228 return (rc); 8229 8230 if ((val >= 1) && (vi->ntxq > 1)) 8231 vi->rsrv_noflowq = 1; 8232 else 8233 vi->rsrv_noflowq = 0; 8234 8235 return (rc); 8236 } 8237 8238 static int 8239 sysctl_tx_vm_wr(SYSCTL_HANDLER_ARGS) 8240 { 8241 struct vi_info *vi = arg1; 8242 struct adapter *sc = vi->adapter; 8243 int rc, val, i; 8244 8245 MPASS(!(sc->flags & IS_VF)); 8246 8247 val = vi->flags & TX_USES_VM_WR ? 1 : 0; 8248 rc = sysctl_handle_int(oidp, &val, 0, req); 8249 if (rc != 0 || req->newptr == NULL) 8250 return (rc); 8251 8252 if (val != 0 && val != 1) 8253 return (EINVAL); 8254 8255 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK, 8256 "t4txvm"); 8257 if (rc) 8258 return (rc); 8259 if (hw_off_limits(sc)) 8260 rc = ENXIO; 8261 else if (if_getdrvflags(vi->ifp) & IFF_DRV_RUNNING) { 8262 /* 8263 * We don't want parse_pkt to run with one setting (VF or PF) 8264 * and then eth_tx to see a different setting but still use 8265 * stale information calculated by parse_pkt. 8266 */ 8267 rc = EBUSY; 8268 } else { 8269 struct port_info *pi = vi->pi; 8270 struct sge_txq *txq; 8271 uint32_t ctrl0; 8272 uint8_t npkt = sc->params.max_pkts_per_eth_tx_pkts_wr; 8273 8274 if (val) { 8275 vi->flags |= TX_USES_VM_WR; 8276 if_sethwtsomaxsegcount(vi->ifp, TX_SGL_SEGS_VM_TSO); 8277 ctrl0 = htobe32(V_TXPKT_OPCODE(CPL_TX_PKT_XT) | 8278 V_TXPKT_INTF(pi->tx_chan)); 8279 if (!(sc->flags & IS_VF)) 8280 npkt--; 8281 } else { 8282 vi->flags &= ~TX_USES_VM_WR; 8283 if_sethwtsomaxsegcount(vi->ifp, TX_SGL_SEGS_TSO); 8284 ctrl0 = htobe32(V_TXPKT_OPCODE(CPL_TX_PKT_XT) | 8285 V_TXPKT_INTF(pi->tx_chan) | V_TXPKT_PF(sc->pf) | 8286 V_TXPKT_VF(vi->vin) | V_TXPKT_VF_VLD(vi->vfvld)); 8287 } 8288 for_each_txq(vi, i, txq) { 8289 txq->cpl_ctrl0 = ctrl0; 8290 txq->txp.max_npkt = npkt; 8291 } 8292 } 8293 end_synchronized_op(sc, LOCK_HELD); 8294 return (rc); 8295 } 8296 8297 static int 8298 sysctl_holdoff_tmr_idx(SYSCTL_HANDLER_ARGS) 8299 { 8300 struct vi_info *vi = arg1; 8301 struct adapter *sc = vi->adapter; 8302 int idx, rc, i; 8303 struct sge_rxq *rxq; 8304 uint8_t v; 8305 8306 idx = vi->tmr_idx; 8307 8308 rc = sysctl_handle_int(oidp, &idx, 0, req); 8309 if (rc != 0 || req->newptr == NULL) 8310 return (rc); 8311 8312 if (idx < 0 || idx >= SGE_NTIMERS) 8313 return (EINVAL); 8314 8315 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK, 8316 "t4tmr"); 8317 if (rc) 8318 return (rc); 8319 8320 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(vi->pktc_idx != -1); 8321 for_each_rxq(vi, i, rxq) { 8322 #ifdef atomic_store_rel_8 8323 atomic_store_rel_8(&rxq->iq.intr_params, v); 8324 #else 8325 rxq->iq.intr_params = v; 8326 #endif 8327 } 8328 vi->tmr_idx = idx; 8329 8330 end_synchronized_op(sc, LOCK_HELD); 8331 return (0); 8332 } 8333 8334 static int 8335 sysctl_holdoff_pktc_idx(SYSCTL_HANDLER_ARGS) 8336 { 8337 struct vi_info *vi = arg1; 8338 struct adapter *sc = vi->adapter; 8339 int idx, rc; 8340 8341 idx = vi->pktc_idx; 8342 8343 rc = sysctl_handle_int(oidp, &idx, 0, req); 8344 if (rc != 0 || req->newptr == NULL) 8345 return (rc); 8346 8347 if (idx < -1 || idx >= SGE_NCOUNTERS) 8348 return (EINVAL); 8349 8350 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK, 8351 "t4pktc"); 8352 if (rc) 8353 return (rc); 8354 8355 if (vi->flags & VI_INIT_DONE) 8356 rc = EBUSY; /* cannot be changed once the queues are created */ 8357 else 8358 vi->pktc_idx = idx; 8359 8360 end_synchronized_op(sc, LOCK_HELD); 8361 return (rc); 8362 } 8363 8364 static int 8365 sysctl_qsize_rxq(SYSCTL_HANDLER_ARGS) 8366 { 8367 struct vi_info *vi = arg1; 8368 struct adapter *sc = vi->adapter; 8369 int qsize, rc; 8370 8371 qsize = vi->qsize_rxq; 8372 8373 rc = sysctl_handle_int(oidp, &qsize, 0, req); 8374 if (rc != 0 || req->newptr == NULL) 8375 return (rc); 8376 8377 if (qsize < 128 || (qsize & 7)) 8378 return (EINVAL); 8379 8380 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK, 8381 "t4rxqs"); 8382 if (rc) 8383 return (rc); 8384 8385 if (vi->flags & VI_INIT_DONE) 8386 rc = EBUSY; /* cannot be changed once the queues are created */ 8387 else 8388 vi->qsize_rxq = qsize; 8389 8390 end_synchronized_op(sc, LOCK_HELD); 8391 return (rc); 8392 } 8393 8394 static int 8395 sysctl_qsize_txq(SYSCTL_HANDLER_ARGS) 8396 { 8397 struct vi_info *vi = arg1; 8398 struct adapter *sc = vi->adapter; 8399 int qsize, rc; 8400 8401 qsize = vi->qsize_txq; 8402 8403 rc = sysctl_handle_int(oidp, &qsize, 0, req); 8404 if (rc != 0 || req->newptr == NULL) 8405 return (rc); 8406 8407 if (qsize < 128 || qsize > 65536) 8408 return (EINVAL); 8409 8410 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK, 8411 "t4txqs"); 8412 if (rc) 8413 return (rc); 8414 8415 if (vi->flags & VI_INIT_DONE) 8416 rc = EBUSY; /* cannot be changed once the queues are created */ 8417 else 8418 vi->qsize_txq = qsize; 8419 8420 end_synchronized_op(sc, LOCK_HELD); 8421 return (rc); 8422 } 8423 8424 static int 8425 sysctl_pause_settings(SYSCTL_HANDLER_ARGS) 8426 { 8427 struct port_info *pi = arg1; 8428 struct adapter *sc = pi->adapter; 8429 struct link_config *lc = &pi->link_cfg; 8430 int rc; 8431 8432 if (req->newptr == NULL) { 8433 struct sbuf *sb; 8434 static char *bits = "\20\1RX\2TX\3AUTO"; 8435 8436 rc = sysctl_wire_old_buffer(req, 0); 8437 if (rc != 0) 8438 return(rc); 8439 8440 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req); 8441 if (sb == NULL) 8442 return (ENOMEM); 8443 8444 if (lc->link_ok) { 8445 sbuf_printf(sb, "%b", (lc->fc & (PAUSE_TX | PAUSE_RX)) | 8446 (lc->requested_fc & PAUSE_AUTONEG), bits); 8447 } else { 8448 sbuf_printf(sb, "%b", lc->requested_fc & (PAUSE_TX | 8449 PAUSE_RX | PAUSE_AUTONEG), bits); 8450 } 8451 rc = sbuf_finish(sb); 8452 sbuf_delete(sb); 8453 } else { 8454 char s[2]; 8455 int n; 8456 8457 s[0] = '0' + (lc->requested_fc & (PAUSE_TX | PAUSE_RX | 8458 PAUSE_AUTONEG)); 8459 s[1] = 0; 8460 8461 rc = sysctl_handle_string(oidp, s, sizeof(s), req); 8462 if (rc != 0) 8463 return(rc); 8464 8465 if (s[1] != 0) 8466 return (EINVAL); 8467 if (s[0] < '0' || s[0] > '9') 8468 return (EINVAL); /* not a number */ 8469 n = s[0] - '0'; 8470 if (n & ~(PAUSE_TX | PAUSE_RX | PAUSE_AUTONEG)) 8471 return (EINVAL); /* some other bit is set too */ 8472 8473 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK, 8474 "t4PAUSE"); 8475 if (rc) 8476 return (rc); 8477 if (!hw_off_limits(sc)) { 8478 PORT_LOCK(pi); 8479 lc->requested_fc = n; 8480 fixup_link_config(pi); 8481 if (pi->up_vis > 0) 8482 rc = apply_link_config(pi); 8483 set_current_media(pi); 8484 PORT_UNLOCK(pi); 8485 } 8486 end_synchronized_op(sc, 0); 8487 } 8488 8489 return (rc); 8490 } 8491 8492 static int 8493 sysctl_link_fec(SYSCTL_HANDLER_ARGS) 8494 { 8495 struct port_info *pi = arg1; 8496 struct link_config *lc = &pi->link_cfg; 8497 int rc; 8498 struct sbuf *sb; 8499 static char *bits = "\20\1RS-FEC\2FC-FEC\3NO-FEC\4RSVD1\5RSVD2"; 8500 8501 rc = sysctl_wire_old_buffer(req, 0); 8502 if (rc != 0) 8503 return(rc); 8504 8505 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req); 8506 if (sb == NULL) 8507 return (ENOMEM); 8508 if (lc->link_ok) 8509 sbuf_printf(sb, "%b", lc->fec, bits); 8510 else 8511 sbuf_printf(sb, "no link"); 8512 rc = sbuf_finish(sb); 8513 sbuf_delete(sb); 8514 8515 return (rc); 8516 } 8517 8518 static int 8519 sysctl_requested_fec(SYSCTL_HANDLER_ARGS) 8520 { 8521 struct port_info *pi = arg1; 8522 struct adapter *sc = pi->adapter; 8523 struct link_config *lc = &pi->link_cfg; 8524 int rc; 8525 int8_t old; 8526 8527 if (req->newptr == NULL) { 8528 struct sbuf *sb; 8529 static char *bits = "\20\1RS-FEC\2FC-FEC\3NO-FEC\4RSVD2" 8530 "\5RSVD3\6auto\7module"; 8531 8532 rc = sysctl_wire_old_buffer(req, 0); 8533 if (rc != 0) 8534 return(rc); 8535 8536 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req); 8537 if (sb == NULL) 8538 return (ENOMEM); 8539 8540 sbuf_printf(sb, "%b", lc->requested_fec, bits); 8541 rc = sbuf_finish(sb); 8542 sbuf_delete(sb); 8543 } else { 8544 char s[8]; 8545 int n; 8546 8547 snprintf(s, sizeof(s), "%d", 8548 lc->requested_fec == FEC_AUTO ? -1 : 8549 lc->requested_fec & (M_FW_PORT_CAP32_FEC | FEC_MODULE)); 8550 8551 rc = sysctl_handle_string(oidp, s, sizeof(s), req); 8552 if (rc != 0) 8553 return(rc); 8554 8555 n = strtol(&s[0], NULL, 0); 8556 if (n < 0 || n & FEC_AUTO) 8557 n = FEC_AUTO; 8558 else if (n & ~(M_FW_PORT_CAP32_FEC | FEC_MODULE)) 8559 return (EINVAL);/* some other bit is set too */ 8560 8561 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK, 8562 "t4reqf"); 8563 if (rc) 8564 return (rc); 8565 PORT_LOCK(pi); 8566 old = lc->requested_fec; 8567 if (n == FEC_AUTO) 8568 lc->requested_fec = FEC_AUTO; 8569 else if (n == 0 || n == FEC_NONE) 8570 lc->requested_fec = FEC_NONE; 8571 else { 8572 if ((lc->pcaps | 8573 V_FW_PORT_CAP32_FEC(n & M_FW_PORT_CAP32_FEC)) != 8574 lc->pcaps) { 8575 rc = ENOTSUP; 8576 goto done; 8577 } 8578 lc->requested_fec = n & (M_FW_PORT_CAP32_FEC | 8579 FEC_MODULE); 8580 } 8581 if (!hw_off_limits(sc)) { 8582 fixup_link_config(pi); 8583 if (pi->up_vis > 0) { 8584 rc = apply_link_config(pi); 8585 if (rc != 0) { 8586 lc->requested_fec = old; 8587 if (rc == FW_EPROTO) 8588 rc = ENOTSUP; 8589 } 8590 } 8591 } 8592 done: 8593 PORT_UNLOCK(pi); 8594 end_synchronized_op(sc, 0); 8595 } 8596 8597 return (rc); 8598 } 8599 8600 static int 8601 sysctl_module_fec(SYSCTL_HANDLER_ARGS) 8602 { 8603 struct port_info *pi = arg1; 8604 struct adapter *sc = pi->adapter; 8605 struct link_config *lc = &pi->link_cfg; 8606 int rc; 8607 int8_t fec; 8608 struct sbuf *sb; 8609 static char *bits = "\20\1RS-FEC\2FC-FEC\3NO-FEC\4RSVD2\5RSVD3"; 8610 8611 rc = sysctl_wire_old_buffer(req, 0); 8612 if (rc != 0) 8613 return (rc); 8614 8615 sb = sbuf_new_for_sysctl(NULL, NULL, 128, req); 8616 if (sb == NULL) 8617 return (ENOMEM); 8618 8619 if (begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4mfec") != 0) { 8620 rc = EBUSY; 8621 goto done; 8622 } 8623 if (hw_off_limits(sc)) { 8624 rc = ENXIO; 8625 goto done; 8626 } 8627 PORT_LOCK(pi); 8628 if (pi->up_vis == 0) { 8629 /* 8630 * If all the interfaces are administratively down the firmware 8631 * does not report transceiver changes. Refresh port info here. 8632 * This is the only reason we have a synchronized op in this 8633 * function. Just PORT_LOCK would have been enough otherwise. 8634 */ 8635 t4_update_port_info(pi); 8636 } 8637 8638 fec = lc->fec_hint; 8639 if (pi->mod_type == FW_PORT_MOD_TYPE_NONE || 8640 !fec_supported(lc->pcaps)) { 8641 sbuf_printf(sb, "n/a"); 8642 } else { 8643 if (fec == 0) 8644 fec = FEC_NONE; 8645 sbuf_printf(sb, "%b", fec & M_FW_PORT_CAP32_FEC, bits); 8646 } 8647 rc = sbuf_finish(sb); 8648 PORT_UNLOCK(pi); 8649 done: 8650 sbuf_delete(sb); 8651 end_synchronized_op(sc, 0); 8652 8653 return (rc); 8654 } 8655 8656 static int 8657 sysctl_autoneg(SYSCTL_HANDLER_ARGS) 8658 { 8659 struct port_info *pi = arg1; 8660 struct adapter *sc = pi->adapter; 8661 struct link_config *lc = &pi->link_cfg; 8662 int rc, val; 8663 8664 if (lc->pcaps & FW_PORT_CAP32_ANEG) 8665 val = lc->requested_aneg == AUTONEG_DISABLE ? 0 : 1; 8666 else 8667 val = -1; 8668 rc = sysctl_handle_int(oidp, &val, 0, req); 8669 if (rc != 0 || req->newptr == NULL) 8670 return (rc); 8671 if (val == 0) 8672 val = AUTONEG_DISABLE; 8673 else if (val == 1) 8674 val = AUTONEG_ENABLE; 8675 else 8676 val = AUTONEG_AUTO; 8677 8678 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK, 8679 "t4aneg"); 8680 if (rc) 8681 return (rc); 8682 PORT_LOCK(pi); 8683 if (val == AUTONEG_ENABLE && !(lc->pcaps & FW_PORT_CAP32_ANEG)) { 8684 rc = ENOTSUP; 8685 goto done; 8686 } 8687 lc->requested_aneg = val; 8688 if (!hw_off_limits(sc)) { 8689 fixup_link_config(pi); 8690 if (pi->up_vis > 0) 8691 rc = apply_link_config(pi); 8692 set_current_media(pi); 8693 } 8694 done: 8695 PORT_UNLOCK(pi); 8696 end_synchronized_op(sc, 0); 8697 return (rc); 8698 } 8699 8700 static int 8701 sysctl_force_fec(SYSCTL_HANDLER_ARGS) 8702 { 8703 struct port_info *pi = arg1; 8704 struct adapter *sc = pi->adapter; 8705 struct link_config *lc = &pi->link_cfg; 8706 int rc, val; 8707 8708 val = lc->force_fec; 8709 MPASS(val >= -1 && val <= 1); 8710 rc = sysctl_handle_int(oidp, &val, 0, req); 8711 if (rc != 0 || req->newptr == NULL) 8712 return (rc); 8713 if (!(lc->pcaps & FW_PORT_CAP32_FORCE_FEC)) 8714 return (ENOTSUP); 8715 if (val < -1 || val > 1) 8716 return (EINVAL); 8717 8718 rc = begin_synchronized_op(sc, &pi->vi[0], SLEEP_OK | INTR_OK, "t4ff"); 8719 if (rc) 8720 return (rc); 8721 PORT_LOCK(pi); 8722 lc->force_fec = val; 8723 if (!hw_off_limits(sc)) { 8724 fixup_link_config(pi); 8725 if (pi->up_vis > 0) 8726 rc = apply_link_config(pi); 8727 } 8728 PORT_UNLOCK(pi); 8729 end_synchronized_op(sc, 0); 8730 return (rc); 8731 } 8732 8733 static int 8734 sysctl_handle_t4_reg64(SYSCTL_HANDLER_ARGS) 8735 { 8736 struct adapter *sc = arg1; 8737 int rc, reg = arg2; 8738 uint64_t val; 8739 8740 mtx_lock(&sc->reg_lock); 8741 if (hw_off_limits(sc)) 8742 rc = ENXIO; 8743 else { 8744 rc = 0; 8745 val = t4_read_reg64(sc, reg); 8746 } 8747 mtx_unlock(&sc->reg_lock); 8748 if (rc == 0) 8749 rc = sysctl_handle_64(oidp, &val, 0, req); 8750 return (rc); 8751 } 8752 8753 static int 8754 sysctl_temperature(SYSCTL_HANDLER_ARGS) 8755 { 8756 struct adapter *sc = arg1; 8757 int rc, t; 8758 uint32_t param, val; 8759 8760 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4temp"); 8761 if (rc) 8762 return (rc); 8763 if (hw_off_limits(sc)) 8764 rc = ENXIO; 8765 else { 8766 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | 8767 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) | 8768 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_TMP); 8769 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val); 8770 } 8771 end_synchronized_op(sc, 0); 8772 if (rc) 8773 return (rc); 8774 8775 /* unknown is returned as 0 but we display -1 in that case */ 8776 t = val == 0 ? -1 : val; 8777 8778 rc = sysctl_handle_int(oidp, &t, 0, req); 8779 return (rc); 8780 } 8781 8782 static int 8783 sysctl_vdd(SYSCTL_HANDLER_ARGS) 8784 { 8785 struct adapter *sc = arg1; 8786 int rc; 8787 uint32_t param, val; 8788 8789 if (sc->params.core_vdd == 0) { 8790 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, 8791 "t4vdd"); 8792 if (rc) 8793 return (rc); 8794 if (hw_off_limits(sc)) 8795 rc = ENXIO; 8796 else { 8797 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | 8798 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) | 8799 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_VDD); 8800 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, 8801 ¶m, &val); 8802 } 8803 end_synchronized_op(sc, 0); 8804 if (rc) 8805 return (rc); 8806 sc->params.core_vdd = val; 8807 } 8808 8809 return (sysctl_handle_int(oidp, &sc->params.core_vdd, 0, req)); 8810 } 8811 8812 static int 8813 sysctl_reset_sensor(SYSCTL_HANDLER_ARGS) 8814 { 8815 struct adapter *sc = arg1; 8816 int rc, v; 8817 uint32_t param, val; 8818 8819 v = sc->sensor_resets; 8820 rc = sysctl_handle_int(oidp, &v, 0, req); 8821 if (rc != 0 || req->newptr == NULL || v <= 0) 8822 return (rc); 8823 8824 if (sc->params.fw_vers < FW_VERSION32(1, 24, 7, 0) || 8825 chip_id(sc) < CHELSIO_T5) 8826 return (ENOTSUP); 8827 8828 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4srst"); 8829 if (rc) 8830 return (rc); 8831 if (hw_off_limits(sc)) 8832 rc = ENXIO; 8833 else { 8834 param = (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | 8835 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_DIAG) | 8836 V_FW_PARAMS_PARAM_Y(FW_PARAM_DEV_DIAG_RESET_TMP_SENSOR)); 8837 val = 1; 8838 rc = -t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val); 8839 } 8840 end_synchronized_op(sc, 0); 8841 if (rc == 0) 8842 sc->sensor_resets++; 8843 return (rc); 8844 } 8845 8846 static int 8847 sysctl_loadavg(SYSCTL_HANDLER_ARGS) 8848 { 8849 struct adapter *sc = arg1; 8850 struct sbuf *sb; 8851 int rc; 8852 uint32_t param, val; 8853 8854 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4lavg"); 8855 if (rc) 8856 return (rc); 8857 if (hw_off_limits(sc)) 8858 rc = ENXIO; 8859 else { 8860 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | 8861 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_LOAD); 8862 rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val); 8863 } 8864 end_synchronized_op(sc, 0); 8865 if (rc) 8866 return (rc); 8867 8868 rc = sysctl_wire_old_buffer(req, 0); 8869 if (rc != 0) 8870 return (rc); 8871 8872 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 8873 if (sb == NULL) 8874 return (ENOMEM); 8875 8876 if (val == 0xffffffff) { 8877 /* Only debug and custom firmwares report load averages. */ 8878 sbuf_printf(sb, "not available"); 8879 } else { 8880 sbuf_printf(sb, "%d %d %d", val & 0xff, (val >> 8) & 0xff, 8881 (val >> 16) & 0xff); 8882 } 8883 rc = sbuf_finish(sb); 8884 sbuf_delete(sb); 8885 8886 return (rc); 8887 } 8888 8889 static int 8890 sysctl_cctrl(SYSCTL_HANDLER_ARGS) 8891 { 8892 struct adapter *sc = arg1; 8893 struct sbuf *sb; 8894 int rc, i; 8895 uint16_t incr[NMTUS][NCCTRL_WIN]; 8896 static const char *dec_fac[] = { 8897 "0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875", 8898 "0.9375" 8899 }; 8900 8901 rc = sysctl_wire_old_buffer(req, 0); 8902 if (rc != 0) 8903 return (rc); 8904 8905 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 8906 if (sb == NULL) 8907 return (ENOMEM); 8908 8909 mtx_lock(&sc->reg_lock); 8910 if (hw_off_limits(sc)) 8911 rc = ENXIO; 8912 else 8913 t4_read_cong_tbl(sc, incr); 8914 mtx_unlock(&sc->reg_lock); 8915 if (rc) 8916 goto done; 8917 8918 for (i = 0; i < NCCTRL_WIN; ++i) { 8919 sbuf_printf(sb, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i, 8920 incr[0][i], incr[1][i], incr[2][i], incr[3][i], incr[4][i], 8921 incr[5][i], incr[6][i], incr[7][i]); 8922 sbuf_printf(sb, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n", 8923 incr[8][i], incr[9][i], incr[10][i], incr[11][i], 8924 incr[12][i], incr[13][i], incr[14][i], incr[15][i], 8925 sc->params.a_wnd[i], dec_fac[sc->params.b_wnd[i]]); 8926 } 8927 8928 rc = sbuf_finish(sb); 8929 done: 8930 sbuf_delete(sb); 8931 return (rc); 8932 } 8933 8934 static const char *qname[CIM_NUM_IBQ + CIM_NUM_OBQ_T5] = { 8935 "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI", /* ibq's */ 8936 "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI", /* obq's */ 8937 "SGE0-RX", "SGE1-RX" /* additional obq's (T5 onwards) */ 8938 }; 8939 8940 static int 8941 sysctl_cim_ibq_obq(SYSCTL_HANDLER_ARGS) 8942 { 8943 struct adapter *sc = arg1; 8944 struct sbuf *sb; 8945 int rc, i, n, qid = arg2; 8946 uint32_t *buf, *p; 8947 char *qtype; 8948 u_int cim_num_obq = sc->chip_params->cim_num_obq; 8949 8950 KASSERT(qid >= 0 && qid < CIM_NUM_IBQ + cim_num_obq, 8951 ("%s: bad qid %d\n", __func__, qid)); 8952 8953 if (qid < CIM_NUM_IBQ) { 8954 /* inbound queue */ 8955 qtype = "IBQ"; 8956 n = 4 * CIM_IBQ_SIZE; 8957 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK); 8958 mtx_lock(&sc->reg_lock); 8959 if (hw_off_limits(sc)) 8960 rc = -ENXIO; 8961 else 8962 rc = t4_read_cim_ibq(sc, qid, buf, n); 8963 mtx_unlock(&sc->reg_lock); 8964 } else { 8965 /* outbound queue */ 8966 qtype = "OBQ"; 8967 qid -= CIM_NUM_IBQ; 8968 n = 4 * cim_num_obq * CIM_OBQ_SIZE; 8969 buf = malloc(n * sizeof(uint32_t), M_CXGBE, M_ZERO | M_WAITOK); 8970 mtx_lock(&sc->reg_lock); 8971 if (hw_off_limits(sc)) 8972 rc = -ENXIO; 8973 else 8974 rc = t4_read_cim_obq(sc, qid, buf, n); 8975 mtx_unlock(&sc->reg_lock); 8976 } 8977 8978 if (rc < 0) { 8979 rc = -rc; 8980 goto done; 8981 } 8982 n = rc * sizeof(uint32_t); /* rc has # of words actually read */ 8983 8984 rc = sysctl_wire_old_buffer(req, 0); 8985 if (rc != 0) 8986 goto done; 8987 8988 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req); 8989 if (sb == NULL) { 8990 rc = ENOMEM; 8991 goto done; 8992 } 8993 8994 sbuf_printf(sb, "%s%d %s", qtype , qid, qname[arg2]); 8995 for (i = 0, p = buf; i < n; i += 16, p += 4) 8996 sbuf_printf(sb, "\n%#06x: %08x %08x %08x %08x", i, p[0], p[1], 8997 p[2], p[3]); 8998 8999 rc = sbuf_finish(sb); 9000 sbuf_delete(sb); 9001 done: 9002 free(buf, M_CXGBE); 9003 return (rc); 9004 } 9005 9006 static void 9007 sbuf_cim_la4(struct adapter *sc, struct sbuf *sb, uint32_t *buf, uint32_t cfg) 9008 { 9009 uint32_t *p; 9010 9011 sbuf_printf(sb, "Status Data PC%s", 9012 cfg & F_UPDBGLACAPTPCONLY ? "" : 9013 " LS0Stat LS0Addr LS0Data"); 9014 9015 for (p = buf; p <= &buf[sc->params.cim_la_size - 8]; p += 8) { 9016 if (cfg & F_UPDBGLACAPTPCONLY) { 9017 sbuf_printf(sb, "\n %02x %08x %08x", p[5] & 0xff, 9018 p[6], p[7]); 9019 sbuf_printf(sb, "\n %02x %02x%06x %02x%06x", 9020 (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8, 9021 p[4] & 0xff, p[5] >> 8); 9022 sbuf_printf(sb, "\n %02x %x%07x %x%07x", 9023 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4, 9024 p[1] & 0xf, p[2] >> 4); 9025 } else { 9026 sbuf_printf(sb, 9027 "\n %02x %x%07x %x%07x %08x %08x " 9028 "%08x%08x%08x%08x", 9029 (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4, 9030 p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5], 9031 p[6], p[7]); 9032 } 9033 } 9034 } 9035 9036 static void 9037 sbuf_cim_la6(struct adapter *sc, struct sbuf *sb, uint32_t *buf, uint32_t cfg) 9038 { 9039 uint32_t *p; 9040 9041 sbuf_printf(sb, "Status Inst Data PC%s", 9042 cfg & F_UPDBGLACAPTPCONLY ? "" : 9043 " LS0Stat LS0Addr LS0Data LS1Stat LS1Addr LS1Data"); 9044 9045 for (p = buf; p <= &buf[sc->params.cim_la_size - 10]; p += 10) { 9046 if (cfg & F_UPDBGLACAPTPCONLY) { 9047 sbuf_printf(sb, "\n %02x %08x %08x %08x", 9048 p[3] & 0xff, p[2], p[1], p[0]); 9049 sbuf_printf(sb, "\n %02x %02x%06x %02x%06x %02x%06x", 9050 (p[6] >> 8) & 0xff, p[6] & 0xff, p[5] >> 8, 9051 p[5] & 0xff, p[4] >> 8, p[4] & 0xff, p[3] >> 8); 9052 sbuf_printf(sb, "\n %02x %04x%04x %04x%04x %04x%04x", 9053 (p[9] >> 16) & 0xff, p[9] & 0xffff, p[8] >> 16, 9054 p[8] & 0xffff, p[7] >> 16, p[7] & 0xffff, 9055 p[6] >> 16); 9056 } else { 9057 sbuf_printf(sb, "\n %02x %04x%04x %04x%04x %04x%04x " 9058 "%08x %08x %08x %08x %08x %08x", 9059 (p[9] >> 16) & 0xff, 9060 p[9] & 0xffff, p[8] >> 16, 9061 p[8] & 0xffff, p[7] >> 16, 9062 p[7] & 0xffff, p[6] >> 16, 9063 p[2], p[1], p[0], p[5], p[4], p[3]); 9064 } 9065 } 9066 } 9067 9068 static int 9069 sbuf_cim_la(struct adapter *sc, struct sbuf *sb, int flags) 9070 { 9071 uint32_t cfg, *buf; 9072 int rc; 9073 9074 MPASS(flags == M_WAITOK || flags == M_NOWAIT); 9075 buf = malloc(sc->params.cim_la_size * sizeof(uint32_t), M_CXGBE, 9076 M_ZERO | flags); 9077 if (buf == NULL) 9078 return (ENOMEM); 9079 9080 mtx_lock(&sc->reg_lock); 9081 if (hw_off_limits(sc)) 9082 rc = ENXIO; 9083 else { 9084 rc = -t4_cim_read(sc, A_UP_UP_DBG_LA_CFG, 1, &cfg); 9085 if (rc == 0) 9086 rc = -t4_cim_read_la(sc, buf, NULL); 9087 } 9088 mtx_unlock(&sc->reg_lock); 9089 if (rc == 0) { 9090 if (chip_id(sc) < CHELSIO_T6) 9091 sbuf_cim_la4(sc, sb, buf, cfg); 9092 else 9093 sbuf_cim_la6(sc, sb, buf, cfg); 9094 } 9095 free(buf, M_CXGBE); 9096 return (rc); 9097 } 9098 9099 static int 9100 sysctl_cim_la(SYSCTL_HANDLER_ARGS) 9101 { 9102 struct adapter *sc = arg1; 9103 struct sbuf *sb; 9104 int rc; 9105 9106 rc = sysctl_wire_old_buffer(req, 0); 9107 if (rc != 0) 9108 return (rc); 9109 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 9110 if (sb == NULL) 9111 return (ENOMEM); 9112 9113 rc = sbuf_cim_la(sc, sb, M_WAITOK); 9114 if (rc == 0) 9115 rc = sbuf_finish(sb); 9116 sbuf_delete(sb); 9117 return (rc); 9118 } 9119 9120 static void 9121 dump_cim_regs(struct adapter *sc) 9122 { 9123 log(LOG_DEBUG, "%s: CIM debug regs1 %08x %08x %08x %08x %08x\n", 9124 device_get_nameunit(sc->dev), 9125 t4_read_reg(sc, A_EDC_H_BIST_USER_WDATA0), 9126 t4_read_reg(sc, A_EDC_H_BIST_USER_WDATA1), 9127 t4_read_reg(sc, A_EDC_H_BIST_USER_WDATA2), 9128 t4_read_reg(sc, A_EDC_H_BIST_DATA_PATTERN), 9129 t4_read_reg(sc, A_EDC_H_BIST_STATUS_RDATA)); 9130 log(LOG_DEBUG, "%s: CIM debug regs2 %08x %08x %08x %08x %08x\n", 9131 device_get_nameunit(sc->dev), 9132 t4_read_reg(sc, A_EDC_H_BIST_USER_WDATA0), 9133 t4_read_reg(sc, A_EDC_H_BIST_USER_WDATA1), 9134 t4_read_reg(sc, A_EDC_H_BIST_USER_WDATA0 + 0x800), 9135 t4_read_reg(sc, A_EDC_H_BIST_USER_WDATA1 + 0x800), 9136 t4_read_reg(sc, A_EDC_H_BIST_CMD_LEN)); 9137 } 9138 9139 static void 9140 dump_cimla(struct adapter *sc) 9141 { 9142 struct sbuf sb; 9143 int rc; 9144 9145 if (sbuf_new(&sb, NULL, 4096, SBUF_AUTOEXTEND) != &sb) { 9146 log(LOG_DEBUG, "%s: failed to generate CIM LA dump.\n", 9147 device_get_nameunit(sc->dev)); 9148 return; 9149 } 9150 rc = sbuf_cim_la(sc, &sb, M_WAITOK); 9151 if (rc == 0) { 9152 rc = sbuf_finish(&sb); 9153 if (rc == 0) { 9154 log(LOG_DEBUG, "%s: CIM LA dump follows.\n%s\n", 9155 device_get_nameunit(sc->dev), sbuf_data(&sb)); 9156 } 9157 } 9158 sbuf_delete(&sb); 9159 } 9160 9161 void 9162 t4_os_cim_err(struct adapter *sc) 9163 { 9164 atomic_set_int(&sc->error_flags, ADAP_CIM_ERR); 9165 } 9166 9167 static int 9168 sysctl_cim_ma_la(SYSCTL_HANDLER_ARGS) 9169 { 9170 struct adapter *sc = arg1; 9171 u_int i; 9172 struct sbuf *sb; 9173 uint32_t *buf, *p; 9174 int rc; 9175 9176 rc = sysctl_wire_old_buffer(req, 0); 9177 if (rc != 0) 9178 return (rc); 9179 9180 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 9181 if (sb == NULL) 9182 return (ENOMEM); 9183 9184 buf = malloc(2 * CIM_MALA_SIZE * 5 * sizeof(uint32_t), M_CXGBE, 9185 M_ZERO | M_WAITOK); 9186 9187 mtx_lock(&sc->reg_lock); 9188 if (hw_off_limits(sc)) 9189 rc = ENXIO; 9190 else 9191 t4_cim_read_ma_la(sc, buf, buf + 5 * CIM_MALA_SIZE); 9192 mtx_unlock(&sc->reg_lock); 9193 if (rc) 9194 goto done; 9195 9196 p = buf; 9197 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) { 9198 sbuf_printf(sb, "\n%02x%08x%08x%08x%08x", p[4], p[3], p[2], 9199 p[1], p[0]); 9200 } 9201 9202 sbuf_printf(sb, "\n\nCnt ID Tag UE Data RDY VLD"); 9203 for (i = 0; i < CIM_MALA_SIZE; i++, p += 5) { 9204 sbuf_printf(sb, "\n%3u %2u %x %u %08x%08x %u %u", 9205 (p[2] >> 10) & 0xff, (p[2] >> 7) & 7, 9206 (p[2] >> 3) & 0xf, (p[2] >> 2) & 1, 9207 (p[1] >> 2) | ((p[2] & 3) << 30), 9208 (p[0] >> 2) | ((p[1] & 3) << 30), (p[0] >> 1) & 1, 9209 p[0] & 1); 9210 } 9211 rc = sbuf_finish(sb); 9212 done: 9213 sbuf_delete(sb); 9214 free(buf, M_CXGBE); 9215 return (rc); 9216 } 9217 9218 static int 9219 sysctl_cim_pif_la(SYSCTL_HANDLER_ARGS) 9220 { 9221 struct adapter *sc = arg1; 9222 u_int i; 9223 struct sbuf *sb; 9224 uint32_t *buf, *p; 9225 int rc; 9226 9227 rc = sysctl_wire_old_buffer(req, 0); 9228 if (rc != 0) 9229 return (rc); 9230 9231 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 9232 if (sb == NULL) 9233 return (ENOMEM); 9234 9235 buf = malloc(2 * CIM_PIFLA_SIZE * 6 * sizeof(uint32_t), M_CXGBE, 9236 M_ZERO | M_WAITOK); 9237 9238 mtx_lock(&sc->reg_lock); 9239 if (hw_off_limits(sc)) 9240 rc = ENXIO; 9241 else 9242 t4_cim_read_pif_la(sc, buf, buf + 6 * CIM_PIFLA_SIZE, NULL, NULL); 9243 mtx_unlock(&sc->reg_lock); 9244 if (rc) 9245 goto done; 9246 9247 p = buf; 9248 sbuf_printf(sb, "Cntl ID DataBE Addr Data"); 9249 for (i = 0; i < CIM_PIFLA_SIZE; i++, p += 6) { 9250 sbuf_printf(sb, "\n %02x %02x %04x %08x %08x%08x%08x%08x", 9251 (p[5] >> 22) & 0xff, (p[5] >> 16) & 0x3f, p[5] & 0xffff, 9252 p[4], p[3], p[2], p[1], p[0]); 9253 } 9254 9255 sbuf_printf(sb, "\n\nCntl ID Data"); 9256 for (i = 0; i < CIM_PIFLA_SIZE; i++, p += 6) { 9257 sbuf_printf(sb, "\n %02x %02x %08x%08x%08x%08x", 9258 (p[4] >> 6) & 0xff, p[4] & 0x3f, p[3], p[2], p[1], p[0]); 9259 } 9260 9261 rc = sbuf_finish(sb); 9262 done: 9263 sbuf_delete(sb); 9264 free(buf, M_CXGBE); 9265 return (rc); 9266 } 9267 9268 static int 9269 sysctl_cim_qcfg(SYSCTL_HANDLER_ARGS) 9270 { 9271 struct adapter *sc = arg1; 9272 struct sbuf *sb; 9273 int rc, i; 9274 uint16_t base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5]; 9275 uint16_t size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5]; 9276 uint16_t thres[CIM_NUM_IBQ]; 9277 uint32_t obq_wr[2 * CIM_NUM_OBQ_T5], *wr = obq_wr; 9278 uint32_t stat[4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5)], *p = stat; 9279 u_int cim_num_obq, ibq_rdaddr, obq_rdaddr, nq; 9280 9281 cim_num_obq = sc->chip_params->cim_num_obq; 9282 if (is_t4(sc)) { 9283 ibq_rdaddr = A_UP_IBQ_0_RDADDR; 9284 obq_rdaddr = A_UP_OBQ_0_REALADDR; 9285 } else { 9286 ibq_rdaddr = A_UP_IBQ_0_SHADOW_RDADDR; 9287 obq_rdaddr = A_UP_OBQ_0_SHADOW_REALADDR; 9288 } 9289 nq = CIM_NUM_IBQ + cim_num_obq; 9290 9291 mtx_lock(&sc->reg_lock); 9292 if (hw_off_limits(sc)) 9293 rc = ENXIO; 9294 else { 9295 rc = -t4_cim_read(sc, ibq_rdaddr, 4 * nq, stat); 9296 if (rc == 0) { 9297 rc = -t4_cim_read(sc, obq_rdaddr, 2 * cim_num_obq, 9298 obq_wr); 9299 if (rc == 0) 9300 t4_read_cimq_cfg(sc, base, size, thres); 9301 } 9302 } 9303 mtx_unlock(&sc->reg_lock); 9304 if (rc) 9305 return (rc); 9306 9307 rc = sysctl_wire_old_buffer(req, 0); 9308 if (rc != 0) 9309 return (rc); 9310 9311 sb = sbuf_new_for_sysctl(NULL, NULL, PAGE_SIZE, req); 9312 if (sb == NULL) 9313 return (ENOMEM); 9314 9315 sbuf_printf(sb, 9316 " Queue Base Size Thres RdPtr WrPtr SOP EOP Avail"); 9317 9318 for (i = 0; i < CIM_NUM_IBQ; i++, p += 4) 9319 sbuf_printf(sb, "\n%7s %5x %5u %5u %6x %4x %4u %4u %5u", 9320 qname[i], base[i], size[i], thres[i], G_IBQRDADDR(p[0]), 9321 G_IBQWRADDR(p[1]), G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]), 9322 G_QUEREMFLITS(p[2]) * 16); 9323 for ( ; i < nq; i++, p += 4, wr += 2) 9324 sbuf_printf(sb, "\n%7s %5x %5u %12x %4x %4u %4u %5u", qname[i], 9325 base[i], size[i], G_QUERDADDR(p[0]) & 0x3fff, 9326 wr[0] - base[i], G_QUESOPCNT(p[3]), G_QUEEOPCNT(p[3]), 9327 G_QUEREMFLITS(p[2]) * 16); 9328 9329 rc = sbuf_finish(sb); 9330 sbuf_delete(sb); 9331 9332 return (rc); 9333 } 9334 9335 static int 9336 sysctl_cpl_stats(SYSCTL_HANDLER_ARGS) 9337 { 9338 struct adapter *sc = arg1; 9339 struct sbuf *sb; 9340 int rc; 9341 struct tp_cpl_stats stats; 9342 9343 rc = sysctl_wire_old_buffer(req, 0); 9344 if (rc != 0) 9345 return (rc); 9346 9347 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req); 9348 if (sb == NULL) 9349 return (ENOMEM); 9350 9351 mtx_lock(&sc->reg_lock); 9352 if (hw_off_limits(sc)) 9353 rc = ENXIO; 9354 else 9355 t4_tp_get_cpl_stats(sc, &stats, 0); 9356 mtx_unlock(&sc->reg_lock); 9357 if (rc) 9358 goto done; 9359 9360 if (sc->chip_params->nchan > 2) { 9361 sbuf_printf(sb, " channel 0 channel 1" 9362 " channel 2 channel 3"); 9363 sbuf_printf(sb, "\nCPL requests: %10u %10u %10u %10u", 9364 stats.req[0], stats.req[1], stats.req[2], stats.req[3]); 9365 sbuf_printf(sb, "\nCPL responses: %10u %10u %10u %10u", 9366 stats.rsp[0], stats.rsp[1], stats.rsp[2], stats.rsp[3]); 9367 } else { 9368 sbuf_printf(sb, " channel 0 channel 1"); 9369 sbuf_printf(sb, "\nCPL requests: %10u %10u", 9370 stats.req[0], stats.req[1]); 9371 sbuf_printf(sb, "\nCPL responses: %10u %10u", 9372 stats.rsp[0], stats.rsp[1]); 9373 } 9374 9375 rc = sbuf_finish(sb); 9376 done: 9377 sbuf_delete(sb); 9378 return (rc); 9379 } 9380 9381 static int 9382 sysctl_ddp_stats(SYSCTL_HANDLER_ARGS) 9383 { 9384 struct adapter *sc = arg1; 9385 struct sbuf *sb; 9386 int rc; 9387 struct tp_usm_stats stats; 9388 9389 rc = sysctl_wire_old_buffer(req, 0); 9390 if (rc != 0) 9391 return(rc); 9392 9393 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req); 9394 if (sb == NULL) 9395 return (ENOMEM); 9396 9397 mtx_lock(&sc->reg_lock); 9398 if (hw_off_limits(sc)) 9399 rc = ENXIO; 9400 else 9401 t4_get_usm_stats(sc, &stats, 1); 9402 mtx_unlock(&sc->reg_lock); 9403 if (rc == 0) { 9404 sbuf_printf(sb, "Frames: %u\n", stats.frames); 9405 sbuf_printf(sb, "Octets: %ju\n", stats.octets); 9406 sbuf_printf(sb, "Drops: %u", stats.drops); 9407 rc = sbuf_finish(sb); 9408 } 9409 sbuf_delete(sb); 9410 9411 return (rc); 9412 } 9413 9414 static int 9415 sysctl_tid_stats(SYSCTL_HANDLER_ARGS) 9416 { 9417 struct adapter *sc = arg1; 9418 struct sbuf *sb; 9419 int rc; 9420 struct tp_tid_stats stats; 9421 9422 rc = sysctl_wire_old_buffer(req, 0); 9423 if (rc != 0) 9424 return(rc); 9425 9426 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req); 9427 if (sb == NULL) 9428 return (ENOMEM); 9429 9430 mtx_lock(&sc->reg_lock); 9431 if (hw_off_limits(sc)) 9432 rc = ENXIO; 9433 else 9434 t4_tp_get_tid_stats(sc, &stats, 1); 9435 mtx_unlock(&sc->reg_lock); 9436 if (rc == 0) { 9437 sbuf_printf(sb, "Delete: %u\n", stats.del); 9438 sbuf_printf(sb, "Invalidate: %u\n", stats.inv); 9439 sbuf_printf(sb, "Active: %u\n", stats.act); 9440 sbuf_printf(sb, "Passive: %u", stats.pas); 9441 rc = sbuf_finish(sb); 9442 } 9443 sbuf_delete(sb); 9444 9445 return (rc); 9446 } 9447 9448 static const char * const devlog_level_strings[] = { 9449 [FW_DEVLOG_LEVEL_EMERG] = "EMERG", 9450 [FW_DEVLOG_LEVEL_CRIT] = "CRIT", 9451 [FW_DEVLOG_LEVEL_ERR] = "ERR", 9452 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE", 9453 [FW_DEVLOG_LEVEL_INFO] = "INFO", 9454 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG" 9455 }; 9456 9457 static const char * const devlog_facility_strings[] = { 9458 [FW_DEVLOG_FACILITY_CORE] = "CORE", 9459 [FW_DEVLOG_FACILITY_CF] = "CF", 9460 [FW_DEVLOG_FACILITY_SCHED] = "SCHED", 9461 [FW_DEVLOG_FACILITY_TIMER] = "TIMER", 9462 [FW_DEVLOG_FACILITY_RES] = "RES", 9463 [FW_DEVLOG_FACILITY_HW] = "HW", 9464 [FW_DEVLOG_FACILITY_FLR] = "FLR", 9465 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ", 9466 [FW_DEVLOG_FACILITY_PHY] = "PHY", 9467 [FW_DEVLOG_FACILITY_MAC] = "MAC", 9468 [FW_DEVLOG_FACILITY_PORT] = "PORT", 9469 [FW_DEVLOG_FACILITY_VI] = "VI", 9470 [FW_DEVLOG_FACILITY_FILTER] = "FILTER", 9471 [FW_DEVLOG_FACILITY_ACL] = "ACL", 9472 [FW_DEVLOG_FACILITY_TM] = "TM", 9473 [FW_DEVLOG_FACILITY_QFC] = "QFC", 9474 [FW_DEVLOG_FACILITY_DCB] = "DCB", 9475 [FW_DEVLOG_FACILITY_ETH] = "ETH", 9476 [FW_DEVLOG_FACILITY_OFLD] = "OFLD", 9477 [FW_DEVLOG_FACILITY_RI] = "RI", 9478 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI", 9479 [FW_DEVLOG_FACILITY_FCOE] = "FCOE", 9480 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI", 9481 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE", 9482 [FW_DEVLOG_FACILITY_CHNET] = "CHNET", 9483 }; 9484 9485 static int 9486 sbuf_devlog(struct adapter *sc, struct sbuf *sb, int flags) 9487 { 9488 int i, j, rc, nentries, first = 0; 9489 struct devlog_params *dparams = &sc->params.devlog; 9490 struct fw_devlog_e *buf, *e; 9491 uint64_t ftstamp = UINT64_MAX; 9492 9493 if (dparams->addr == 0) 9494 return (ENXIO); 9495 9496 MPASS(flags == M_WAITOK || flags == M_NOWAIT); 9497 buf = malloc(dparams->size, M_CXGBE, M_ZERO | flags); 9498 if (buf == NULL) 9499 return (ENOMEM); 9500 9501 mtx_lock(&sc->reg_lock); 9502 if (hw_off_limits(sc)) 9503 rc = ENXIO; 9504 else 9505 rc = read_via_memwin(sc, 1, dparams->addr, (void *)buf, 9506 dparams->size); 9507 mtx_unlock(&sc->reg_lock); 9508 if (rc != 0) 9509 goto done; 9510 9511 nentries = dparams->size / sizeof(struct fw_devlog_e); 9512 for (i = 0; i < nentries; i++) { 9513 e = &buf[i]; 9514 9515 if (e->timestamp == 0) 9516 break; /* end */ 9517 9518 e->timestamp = be64toh(e->timestamp); 9519 e->seqno = be32toh(e->seqno); 9520 for (j = 0; j < 8; j++) 9521 e->params[j] = be32toh(e->params[j]); 9522 9523 if (e->timestamp < ftstamp) { 9524 ftstamp = e->timestamp; 9525 first = i; 9526 } 9527 } 9528 9529 if (buf[first].timestamp == 0) 9530 goto done; /* nothing in the log */ 9531 9532 sbuf_printf(sb, "%10s %15s %8s %8s %s\n", 9533 "Seq#", "Tstamp", "Level", "Facility", "Message"); 9534 9535 i = first; 9536 do { 9537 e = &buf[i]; 9538 if (e->timestamp == 0) 9539 break; /* end */ 9540 9541 sbuf_printf(sb, "%10d %15ju %8s %8s ", 9542 e->seqno, e->timestamp, 9543 (e->level < nitems(devlog_level_strings) ? 9544 devlog_level_strings[e->level] : "UNKNOWN"), 9545 (e->facility < nitems(devlog_facility_strings) ? 9546 devlog_facility_strings[e->facility] : "UNKNOWN")); 9547 sbuf_printf(sb, e->fmt, e->params[0], e->params[1], 9548 e->params[2], e->params[3], e->params[4], 9549 e->params[5], e->params[6], e->params[7]); 9550 9551 if (++i == nentries) 9552 i = 0; 9553 } while (i != first); 9554 done: 9555 free(buf, M_CXGBE); 9556 return (rc); 9557 } 9558 9559 static int 9560 sysctl_devlog(SYSCTL_HANDLER_ARGS) 9561 { 9562 struct adapter *sc = arg1; 9563 int rc; 9564 struct sbuf *sb; 9565 9566 rc = sysctl_wire_old_buffer(req, 0); 9567 if (rc != 0) 9568 return (rc); 9569 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 9570 if (sb == NULL) 9571 return (ENOMEM); 9572 9573 rc = sbuf_devlog(sc, sb, M_WAITOK); 9574 if (rc == 0) 9575 rc = sbuf_finish(sb); 9576 sbuf_delete(sb); 9577 return (rc); 9578 } 9579 9580 static void 9581 dump_devlog(struct adapter *sc) 9582 { 9583 int rc; 9584 struct sbuf sb; 9585 9586 if (sbuf_new(&sb, NULL, 4096, SBUF_AUTOEXTEND) != &sb) { 9587 log(LOG_DEBUG, "%s: failed to generate devlog dump.\n", 9588 device_get_nameunit(sc->dev)); 9589 return; 9590 } 9591 rc = sbuf_devlog(sc, &sb, M_WAITOK); 9592 if (rc == 0) { 9593 rc = sbuf_finish(&sb); 9594 if (rc == 0) { 9595 log(LOG_DEBUG, "%s: device log follows.\n%s", 9596 device_get_nameunit(sc->dev), sbuf_data(&sb)); 9597 } 9598 } 9599 sbuf_delete(&sb); 9600 } 9601 9602 static int 9603 sysctl_fcoe_stats(SYSCTL_HANDLER_ARGS) 9604 { 9605 struct adapter *sc = arg1; 9606 struct sbuf *sb; 9607 int rc; 9608 struct tp_fcoe_stats stats[MAX_NCHAN]; 9609 int i, nchan = sc->chip_params->nchan; 9610 9611 rc = sysctl_wire_old_buffer(req, 0); 9612 if (rc != 0) 9613 return (rc); 9614 9615 mtx_lock(&sc->reg_lock); 9616 if (hw_off_limits(sc)) 9617 rc = ENXIO; 9618 else { 9619 for (i = 0; i < nchan; i++) 9620 t4_get_fcoe_stats(sc, i, &stats[i], 1); 9621 } 9622 mtx_unlock(&sc->reg_lock); 9623 if (rc != 0) 9624 return (rc); 9625 9626 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req); 9627 if (sb == NULL) 9628 return (ENOMEM); 9629 9630 if (nchan > 2) { 9631 sbuf_printf(sb, " channel 0 channel 1" 9632 " channel 2 channel 3"); 9633 sbuf_printf(sb, "\noctetsDDP: %16ju %16ju %16ju %16ju", 9634 stats[0].octets_ddp, stats[1].octets_ddp, 9635 stats[2].octets_ddp, stats[3].octets_ddp); 9636 sbuf_printf(sb, "\nframesDDP: %16u %16u %16u %16u", 9637 stats[0].frames_ddp, stats[1].frames_ddp, 9638 stats[2].frames_ddp, stats[3].frames_ddp); 9639 sbuf_printf(sb, "\nframesDrop: %16u %16u %16u %16u", 9640 stats[0].frames_drop, stats[1].frames_drop, 9641 stats[2].frames_drop, stats[3].frames_drop); 9642 } else { 9643 sbuf_printf(sb, " channel 0 channel 1"); 9644 sbuf_printf(sb, "\noctetsDDP: %16ju %16ju", 9645 stats[0].octets_ddp, stats[1].octets_ddp); 9646 sbuf_printf(sb, "\nframesDDP: %16u %16u", 9647 stats[0].frames_ddp, stats[1].frames_ddp); 9648 sbuf_printf(sb, "\nframesDrop: %16u %16u", 9649 stats[0].frames_drop, stats[1].frames_drop); 9650 } 9651 9652 rc = sbuf_finish(sb); 9653 sbuf_delete(sb); 9654 9655 return (rc); 9656 } 9657 9658 static int 9659 sysctl_hw_sched(SYSCTL_HANDLER_ARGS) 9660 { 9661 struct adapter *sc = arg1; 9662 struct sbuf *sb; 9663 int rc, i; 9664 unsigned int map, kbps, ipg, mode; 9665 unsigned int pace_tab[NTX_SCHED]; 9666 9667 rc = sysctl_wire_old_buffer(req, 0); 9668 if (rc != 0) 9669 return (rc); 9670 9671 sb = sbuf_new_for_sysctl(NULL, NULL, 512, req); 9672 if (sb == NULL) 9673 return (ENOMEM); 9674 9675 mtx_lock(&sc->reg_lock); 9676 if (hw_off_limits(sc)) { 9677 rc = ENXIO; 9678 goto done; 9679 } 9680 9681 map = t4_read_reg(sc, A_TP_TX_MOD_QUEUE_REQ_MAP); 9682 mode = G_TIMERMODE(t4_read_reg(sc, A_TP_MOD_CONFIG)); 9683 t4_read_pace_tbl(sc, pace_tab); 9684 9685 sbuf_printf(sb, "Scheduler Mode Channel Rate (Kbps) " 9686 "Class IPG (0.1 ns) Flow IPG (us)"); 9687 9688 for (i = 0; i < NTX_SCHED; ++i, map >>= 2) { 9689 t4_get_tx_sched(sc, i, &kbps, &ipg, 1); 9690 sbuf_printf(sb, "\n %u %-5s %u ", i, 9691 (mode & (1 << i)) ? "flow" : "class", map & 3); 9692 if (kbps) 9693 sbuf_printf(sb, "%9u ", kbps); 9694 else 9695 sbuf_printf(sb, " disabled "); 9696 9697 if (ipg) 9698 sbuf_printf(sb, "%13u ", ipg); 9699 else 9700 sbuf_printf(sb, " disabled "); 9701 9702 if (pace_tab[i]) 9703 sbuf_printf(sb, "%10u", pace_tab[i]); 9704 else 9705 sbuf_printf(sb, " disabled"); 9706 } 9707 rc = sbuf_finish(sb); 9708 done: 9709 mtx_unlock(&sc->reg_lock); 9710 sbuf_delete(sb); 9711 return (rc); 9712 } 9713 9714 static int 9715 sysctl_lb_stats(SYSCTL_HANDLER_ARGS) 9716 { 9717 struct adapter *sc = arg1; 9718 struct sbuf *sb; 9719 int rc, i, j; 9720 uint64_t *p0, *p1; 9721 struct lb_port_stats s[2]; 9722 static const char *stat_name[] = { 9723 "OctetsOK:", "FramesOK:", "BcastFrames:", "McastFrames:", 9724 "UcastFrames:", "ErrorFrames:", "Frames64:", "Frames65To127:", 9725 "Frames128To255:", "Frames256To511:", "Frames512To1023:", 9726 "Frames1024To1518:", "Frames1519ToMax:", "FramesDropped:", 9727 "BG0FramesDropped:", "BG1FramesDropped:", "BG2FramesDropped:", 9728 "BG3FramesDropped:", "BG0FramesTrunc:", "BG1FramesTrunc:", 9729 "BG2FramesTrunc:", "BG3FramesTrunc:" 9730 }; 9731 9732 rc = sysctl_wire_old_buffer(req, 0); 9733 if (rc != 0) 9734 return (rc); 9735 9736 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 9737 if (sb == NULL) 9738 return (ENOMEM); 9739 9740 memset(s, 0, sizeof(s)); 9741 9742 for (i = 0; i < sc->chip_params->nchan; i += 2) { 9743 mtx_lock(&sc->reg_lock); 9744 if (hw_off_limits(sc)) 9745 rc = ENXIO; 9746 else { 9747 t4_get_lb_stats(sc, i, &s[0]); 9748 t4_get_lb_stats(sc, i + 1, &s[1]); 9749 } 9750 mtx_unlock(&sc->reg_lock); 9751 if (rc != 0) 9752 break; 9753 9754 p0 = &s[0].octets; 9755 p1 = &s[1].octets; 9756 sbuf_printf(sb, "%s Loopback %u" 9757 " Loopback %u", i == 0 ? "" : "\n", i, i + 1); 9758 9759 for (j = 0; j < nitems(stat_name); j++) 9760 sbuf_printf(sb, "\n%-17s %20ju %20ju", stat_name[j], 9761 *p0++, *p1++); 9762 } 9763 9764 rc = sbuf_finish(sb); 9765 sbuf_delete(sb); 9766 9767 return (rc); 9768 } 9769 9770 static int 9771 sysctl_linkdnrc(SYSCTL_HANDLER_ARGS) 9772 { 9773 int rc = 0; 9774 struct port_info *pi = arg1; 9775 struct link_config *lc = &pi->link_cfg; 9776 struct sbuf *sb; 9777 9778 rc = sysctl_wire_old_buffer(req, 0); 9779 if (rc != 0) 9780 return(rc); 9781 sb = sbuf_new_for_sysctl(NULL, NULL, 64, req); 9782 if (sb == NULL) 9783 return (ENOMEM); 9784 9785 if (lc->link_ok || lc->link_down_rc == 255) 9786 sbuf_printf(sb, "n/a"); 9787 else 9788 sbuf_printf(sb, "%s", t4_link_down_rc_str(lc->link_down_rc)); 9789 9790 rc = sbuf_finish(sb); 9791 sbuf_delete(sb); 9792 9793 return (rc); 9794 } 9795 9796 struct mem_desc { 9797 u_int base; 9798 u_int limit; 9799 u_int idx; 9800 }; 9801 9802 static int 9803 mem_desc_cmp(const void *a, const void *b) 9804 { 9805 const u_int v1 = ((const struct mem_desc *)a)->base; 9806 const u_int v2 = ((const struct mem_desc *)b)->base; 9807 9808 if (v1 < v2) 9809 return (-1); 9810 else if (v1 > v2) 9811 return (1); 9812 9813 return (0); 9814 } 9815 9816 static void 9817 mem_region_show(struct sbuf *sb, const char *name, unsigned int from, 9818 unsigned int to) 9819 { 9820 unsigned int size; 9821 9822 if (from == to) 9823 return; 9824 9825 size = to - from + 1; 9826 if (size == 0) 9827 return; 9828 9829 /* XXX: need humanize_number(3) in libkern for a more readable 'size' */ 9830 sbuf_printf(sb, "%-15s %#x-%#x [%u]\n", name, from, to, size); 9831 } 9832 9833 static int 9834 sysctl_meminfo(SYSCTL_HANDLER_ARGS) 9835 { 9836 struct adapter *sc = arg1; 9837 struct sbuf *sb; 9838 int rc, i, n; 9839 uint32_t lo, hi, used, free, alloc; 9840 static const char *memory[] = { 9841 "EDC0:", "EDC1:", "MC:", "MC0:", "MC1:", "HMA:" 9842 }; 9843 static const char *region[] = { 9844 "DBQ contexts:", "IMSG contexts:", "FLM cache:", "TCBs:", 9845 "Pstructs:", "Timers:", "Rx FL:", "Tx FL:", "Pstruct FL:", 9846 "Tx payload:", "Rx payload:", "LE hash:", "iSCSI region:", 9847 "TDDP region:", "TPT region:", "STAG region:", "RQ region:", 9848 "RQUDP region:", "PBL region:", "TXPBL region:", 9849 "TLSKey region:", "DBVFIFO region:", "ULPRX state:", 9850 "ULPTX state:", "On-chip queues:", 9851 }; 9852 struct mem_desc avail[4]; 9853 struct mem_desc mem[nitems(region) + 3]; /* up to 3 holes */ 9854 struct mem_desc *md = mem; 9855 9856 rc = sysctl_wire_old_buffer(req, 0); 9857 if (rc != 0) 9858 return (rc); 9859 9860 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 9861 if (sb == NULL) 9862 return (ENOMEM); 9863 9864 for (i = 0; i < nitems(mem); i++) { 9865 mem[i].limit = 0; 9866 mem[i].idx = i; 9867 } 9868 9869 mtx_lock(&sc->reg_lock); 9870 if (hw_off_limits(sc)) { 9871 rc = ENXIO; 9872 goto done; 9873 } 9874 9875 /* Find and sort the populated memory ranges */ 9876 i = 0; 9877 lo = t4_read_reg(sc, A_MA_TARGET_MEM_ENABLE); 9878 if (lo & F_EDRAM0_ENABLE) { 9879 hi = t4_read_reg(sc, A_MA_EDRAM0_BAR); 9880 avail[i].base = G_EDRAM0_BASE(hi) << 20; 9881 avail[i].limit = avail[i].base + (G_EDRAM0_SIZE(hi) << 20); 9882 avail[i].idx = 0; 9883 i++; 9884 } 9885 if (lo & F_EDRAM1_ENABLE) { 9886 hi = t4_read_reg(sc, A_MA_EDRAM1_BAR); 9887 avail[i].base = G_EDRAM1_BASE(hi) << 20; 9888 avail[i].limit = avail[i].base + (G_EDRAM1_SIZE(hi) << 20); 9889 avail[i].idx = 1; 9890 i++; 9891 } 9892 if (lo & F_EXT_MEM_ENABLE) { 9893 hi = t4_read_reg(sc, A_MA_EXT_MEMORY_BAR); 9894 avail[i].base = G_EXT_MEM_BASE(hi) << 20; 9895 avail[i].limit = avail[i].base + (G_EXT_MEM_SIZE(hi) << 20); 9896 avail[i].idx = is_t5(sc) ? 3 : 2; /* Call it MC0 for T5 */ 9897 i++; 9898 } 9899 if (is_t5(sc) && lo & F_EXT_MEM1_ENABLE) { 9900 hi = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR); 9901 avail[i].base = G_EXT_MEM1_BASE(hi) << 20; 9902 avail[i].limit = avail[i].base + (G_EXT_MEM1_SIZE(hi) << 20); 9903 avail[i].idx = 4; 9904 i++; 9905 } 9906 if (is_t6(sc) && lo & F_HMA_MUX) { 9907 hi = t4_read_reg(sc, A_MA_EXT_MEMORY1_BAR); 9908 avail[i].base = G_EXT_MEM1_BASE(hi) << 20; 9909 avail[i].limit = avail[i].base + (G_EXT_MEM1_SIZE(hi) << 20); 9910 avail[i].idx = 5; 9911 i++; 9912 } 9913 MPASS(i <= nitems(avail)); 9914 if (!i) /* no memory available */ 9915 goto done; 9916 qsort(avail, i, sizeof(struct mem_desc), mem_desc_cmp); 9917 9918 (md++)->base = t4_read_reg(sc, A_SGE_DBQ_CTXT_BADDR); 9919 (md++)->base = t4_read_reg(sc, A_SGE_IMSG_CTXT_BADDR); 9920 (md++)->base = t4_read_reg(sc, A_SGE_FLM_CACHE_BADDR); 9921 (md++)->base = t4_read_reg(sc, A_TP_CMM_TCB_BASE); 9922 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_BASE); 9923 (md++)->base = t4_read_reg(sc, A_TP_CMM_TIMER_BASE); 9924 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_RX_FLST_BASE); 9925 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_TX_FLST_BASE); 9926 (md++)->base = t4_read_reg(sc, A_TP_CMM_MM_PS_FLST_BASE); 9927 9928 /* the next few have explicit upper bounds */ 9929 md->base = t4_read_reg(sc, A_TP_PMM_TX_BASE); 9930 md->limit = md->base - 1 + 9931 t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE) * 9932 G_PMTXMAXPAGE(t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE)); 9933 md++; 9934 9935 md->base = t4_read_reg(sc, A_TP_PMM_RX_BASE); 9936 md->limit = md->base - 1 + 9937 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) * 9938 G_PMRXMAXPAGE(t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE)); 9939 md++; 9940 9941 if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) { 9942 if (chip_id(sc) <= CHELSIO_T5) 9943 md->base = t4_read_reg(sc, A_LE_DB_HASH_TID_BASE); 9944 else 9945 md->base = t4_read_reg(sc, A_LE_DB_HASH_TBL_BASE_ADDR); 9946 md->limit = 0; 9947 } else { 9948 md->base = 0; 9949 md->idx = nitems(region); /* hide it */ 9950 } 9951 md++; 9952 9953 #define ulp_region(reg) \ 9954 md->base = t4_read_reg(sc, A_ULP_ ## reg ## _LLIMIT);\ 9955 (md++)->limit = t4_read_reg(sc, A_ULP_ ## reg ## _ULIMIT) 9956 9957 ulp_region(RX_ISCSI); 9958 ulp_region(RX_TDDP); 9959 ulp_region(TX_TPT); 9960 ulp_region(RX_STAG); 9961 ulp_region(RX_RQ); 9962 ulp_region(RX_RQUDP); 9963 ulp_region(RX_PBL); 9964 ulp_region(TX_PBL); 9965 if (sc->cryptocaps & FW_CAPS_CONFIG_TLSKEYS) { 9966 ulp_region(RX_TLS_KEY); 9967 } 9968 #undef ulp_region 9969 9970 md->base = 0; 9971 if (is_t4(sc)) 9972 md->idx = nitems(region); 9973 else { 9974 uint32_t size = 0; 9975 uint32_t sge_ctrl = t4_read_reg(sc, A_SGE_CONTROL2); 9976 uint32_t fifo_size = t4_read_reg(sc, A_SGE_DBVFIFO_SIZE); 9977 9978 if (is_t5(sc)) { 9979 if (sge_ctrl & F_VFIFO_ENABLE) 9980 size = fifo_size << 2; 9981 } else 9982 size = G_T6_DBVFIFO_SIZE(fifo_size) << 6; 9983 9984 if (size) { 9985 md->base = t4_read_reg(sc, A_SGE_DBVFIFO_BADDR); 9986 md->limit = md->base + size - 1; 9987 } else 9988 md->idx = nitems(region); 9989 } 9990 md++; 9991 9992 md->base = t4_read_reg(sc, A_ULP_RX_CTX_BASE); 9993 md->limit = 0; 9994 md++; 9995 md->base = t4_read_reg(sc, A_ULP_TX_ERR_TABLE_BASE); 9996 md->limit = 0; 9997 md++; 9998 9999 md->base = sc->vres.ocq.start; 10000 if (sc->vres.ocq.size) 10001 md->limit = md->base + sc->vres.ocq.size - 1; 10002 else 10003 md->idx = nitems(region); /* hide it */ 10004 md++; 10005 10006 /* add any address-space holes, there can be up to 3 */ 10007 for (n = 0; n < i - 1; n++) 10008 if (avail[n].limit < avail[n + 1].base) 10009 (md++)->base = avail[n].limit; 10010 if (avail[n].limit) 10011 (md++)->base = avail[n].limit; 10012 10013 n = md - mem; 10014 MPASS(n <= nitems(mem)); 10015 qsort(mem, n, sizeof(struct mem_desc), mem_desc_cmp); 10016 10017 for (lo = 0; lo < i; lo++) 10018 mem_region_show(sb, memory[avail[lo].idx], avail[lo].base, 10019 avail[lo].limit - 1); 10020 10021 sbuf_printf(sb, "\n"); 10022 for (i = 0; i < n; i++) { 10023 if (mem[i].idx >= nitems(region)) 10024 continue; /* skip holes */ 10025 if (!mem[i].limit) 10026 mem[i].limit = i < n - 1 ? mem[i + 1].base - 1 : ~0; 10027 mem_region_show(sb, region[mem[i].idx], mem[i].base, 10028 mem[i].limit); 10029 } 10030 10031 sbuf_printf(sb, "\n"); 10032 lo = t4_read_reg(sc, A_CIM_SDRAM_BASE_ADDR); 10033 hi = t4_read_reg(sc, A_CIM_SDRAM_ADDR_SIZE) + lo - 1; 10034 mem_region_show(sb, "uP RAM:", lo, hi); 10035 10036 lo = t4_read_reg(sc, A_CIM_EXTMEM2_BASE_ADDR); 10037 hi = t4_read_reg(sc, A_CIM_EXTMEM2_ADDR_SIZE) + lo - 1; 10038 mem_region_show(sb, "uP Extmem2:", lo, hi); 10039 10040 lo = t4_read_reg(sc, A_TP_PMM_RX_MAX_PAGE); 10041 for (i = 0, free = 0; i < 2; i++) 10042 free += G_FREERXPAGECOUNT(t4_read_reg(sc, A_TP_FLM_FREE_RX_CNT)); 10043 sbuf_printf(sb, "\n%u Rx pages (%u free) of size %uKiB for %u channels\n", 10044 G_PMRXMAXPAGE(lo), free, 10045 t4_read_reg(sc, A_TP_PMM_RX_PAGE_SIZE) >> 10, 10046 (lo & F_PMRXNUMCHN) ? 2 : 1); 10047 10048 lo = t4_read_reg(sc, A_TP_PMM_TX_MAX_PAGE); 10049 hi = t4_read_reg(sc, A_TP_PMM_TX_PAGE_SIZE); 10050 for (i = 0, free = 0; i < 4; i++) 10051 free += G_FREETXPAGECOUNT(t4_read_reg(sc, A_TP_FLM_FREE_TX_CNT)); 10052 sbuf_printf(sb, "%u Tx pages (%u free) of size %u%ciB for %u channels\n", 10053 G_PMTXMAXPAGE(lo), free, 10054 hi >= (1 << 20) ? (hi >> 20) : (hi >> 10), 10055 hi >= (1 << 20) ? 'M' : 'K', 1 << G_PMTXNUMCHN(lo)); 10056 sbuf_printf(sb, "%u p-structs (%u free)\n", 10057 t4_read_reg(sc, A_TP_CMM_MM_MAX_PSTRUCT), 10058 G_FREEPSTRUCTCOUNT(t4_read_reg(sc, A_TP_FLM_FREE_PS_CNT))); 10059 10060 for (i = 0; i < 4; i++) { 10061 if (chip_id(sc) > CHELSIO_T5) 10062 lo = t4_read_reg(sc, A_MPS_RX_MAC_BG_PG_CNT0 + i * 4); 10063 else 10064 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV0 + i * 4); 10065 if (is_t5(sc)) { 10066 used = G_T5_USED(lo); 10067 alloc = G_T5_ALLOC(lo); 10068 } else { 10069 used = G_USED(lo); 10070 alloc = G_ALLOC(lo); 10071 } 10072 /* For T6 these are MAC buffer groups */ 10073 sbuf_printf(sb, "\nPort %d using %u pages out of %u allocated", 10074 i, used, alloc); 10075 } 10076 for (i = 0; i < sc->chip_params->nchan; i++) { 10077 if (chip_id(sc) > CHELSIO_T5) 10078 lo = t4_read_reg(sc, A_MPS_RX_LPBK_BG_PG_CNT0 + i * 4); 10079 else 10080 lo = t4_read_reg(sc, A_MPS_RX_PG_RSV4 + i * 4); 10081 if (is_t5(sc)) { 10082 used = G_T5_USED(lo); 10083 alloc = G_T5_ALLOC(lo); 10084 } else { 10085 used = G_USED(lo); 10086 alloc = G_ALLOC(lo); 10087 } 10088 /* For T6 these are MAC buffer groups */ 10089 sbuf_printf(sb, 10090 "\nLoopback %d using %u pages out of %u allocated", 10091 i, used, alloc); 10092 } 10093 done: 10094 mtx_unlock(&sc->reg_lock); 10095 if (rc == 0) 10096 rc = sbuf_finish(sb); 10097 sbuf_delete(sb); 10098 return (rc); 10099 } 10100 10101 static inline void 10102 tcamxy2valmask(uint64_t x, uint64_t y, uint8_t *addr, uint64_t *mask) 10103 { 10104 *mask = x | y; 10105 y = htobe64(y); 10106 memcpy(addr, (char *)&y + 2, ETHER_ADDR_LEN); 10107 } 10108 10109 static int 10110 sysctl_mps_tcam(SYSCTL_HANDLER_ARGS) 10111 { 10112 struct adapter *sc = arg1; 10113 struct sbuf *sb; 10114 int rc, i; 10115 10116 MPASS(chip_id(sc) <= CHELSIO_T5); 10117 10118 rc = sysctl_wire_old_buffer(req, 0); 10119 if (rc != 0) 10120 return (rc); 10121 10122 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 10123 if (sb == NULL) 10124 return (ENOMEM); 10125 10126 sbuf_printf(sb, 10127 "Idx Ethernet address Mask Vld Ports PF" 10128 " VF Replication P0 P1 P2 P3 ML"); 10129 for (i = 0; i < sc->chip_params->mps_tcam_size; i++) { 10130 uint64_t tcamx, tcamy, mask; 10131 uint32_t cls_lo, cls_hi; 10132 uint8_t addr[ETHER_ADDR_LEN]; 10133 10134 mtx_lock(&sc->reg_lock); 10135 if (hw_off_limits(sc)) 10136 rc = ENXIO; 10137 else { 10138 tcamy = t4_read_reg64(sc, MPS_CLS_TCAM_Y_L(i)); 10139 tcamx = t4_read_reg64(sc, MPS_CLS_TCAM_X_L(i)); 10140 } 10141 mtx_unlock(&sc->reg_lock); 10142 if (rc != 0) 10143 break; 10144 if (tcamx & tcamy) 10145 continue; 10146 tcamxy2valmask(tcamx, tcamy, addr, &mask); 10147 mtx_lock(&sc->reg_lock); 10148 if (hw_off_limits(sc)) 10149 rc = ENXIO; 10150 else { 10151 cls_lo = t4_read_reg(sc, MPS_CLS_SRAM_L(i)); 10152 cls_hi = t4_read_reg(sc, MPS_CLS_SRAM_H(i)); 10153 } 10154 mtx_unlock(&sc->reg_lock); 10155 if (rc != 0) 10156 break; 10157 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x %012jx" 10158 " %c %#x%4u%4d", i, addr[0], addr[1], addr[2], 10159 addr[3], addr[4], addr[5], (uintmax_t)mask, 10160 (cls_lo & F_SRAM_VLD) ? 'Y' : 'N', 10161 G_PORTMAP(cls_hi), G_PF(cls_lo), 10162 (cls_lo & F_VF_VALID) ? G_VF(cls_lo) : -1); 10163 10164 if (cls_lo & F_REPLICATE) { 10165 struct fw_ldst_cmd ldst_cmd; 10166 10167 memset(&ldst_cmd, 0, sizeof(ldst_cmd)); 10168 ldst_cmd.op_to_addrspace = 10169 htobe32(V_FW_CMD_OP(FW_LDST_CMD) | 10170 F_FW_CMD_REQUEST | F_FW_CMD_READ | 10171 V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MPS)); 10172 ldst_cmd.cycles_to_len16 = htobe32(FW_LEN16(ldst_cmd)); 10173 ldst_cmd.u.mps.rplc.fid_idx = 10174 htobe16(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) | 10175 V_FW_LDST_CMD_IDX(i)); 10176 10177 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, 10178 "t4mps"); 10179 if (rc) 10180 break; 10181 if (hw_off_limits(sc)) 10182 rc = ENXIO; 10183 else 10184 rc = -t4_wr_mbox(sc, sc->mbox, &ldst_cmd, 10185 sizeof(ldst_cmd), &ldst_cmd); 10186 end_synchronized_op(sc, 0); 10187 if (rc != 0) 10188 break; 10189 else { 10190 sbuf_printf(sb, " %08x %08x %08x %08x", 10191 be32toh(ldst_cmd.u.mps.rplc.rplc127_96), 10192 be32toh(ldst_cmd.u.mps.rplc.rplc95_64), 10193 be32toh(ldst_cmd.u.mps.rplc.rplc63_32), 10194 be32toh(ldst_cmd.u.mps.rplc.rplc31_0)); 10195 } 10196 } else 10197 sbuf_printf(sb, "%36s", ""); 10198 10199 sbuf_printf(sb, "%4u%3u%3u%3u %#3x", G_SRAM_PRIO0(cls_lo), 10200 G_SRAM_PRIO1(cls_lo), G_SRAM_PRIO2(cls_lo), 10201 G_SRAM_PRIO3(cls_lo), (cls_lo >> S_MULTILISTEN0) & 0xf); 10202 } 10203 10204 if (rc) 10205 (void) sbuf_finish(sb); 10206 else 10207 rc = sbuf_finish(sb); 10208 sbuf_delete(sb); 10209 10210 return (rc); 10211 } 10212 10213 static int 10214 sysctl_mps_tcam_t6(SYSCTL_HANDLER_ARGS) 10215 { 10216 struct adapter *sc = arg1; 10217 struct sbuf *sb; 10218 int rc, i; 10219 10220 MPASS(chip_id(sc) > CHELSIO_T5); 10221 10222 rc = sysctl_wire_old_buffer(req, 0); 10223 if (rc != 0) 10224 return (rc); 10225 10226 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 10227 if (sb == NULL) 10228 return (ENOMEM); 10229 10230 sbuf_printf(sb, "Idx Ethernet address Mask VNI Mask" 10231 " IVLAN Vld DIP_Hit Lookup Port Vld Ports PF VF" 10232 " Replication" 10233 " P0 P1 P2 P3 ML\n"); 10234 10235 for (i = 0; i < sc->chip_params->mps_tcam_size; i++) { 10236 uint8_t dip_hit, vlan_vld, lookup_type, port_num; 10237 uint16_t ivlan; 10238 uint64_t tcamx, tcamy, val, mask; 10239 uint32_t cls_lo, cls_hi, ctl, data2, vnix, vniy; 10240 uint8_t addr[ETHER_ADDR_LEN]; 10241 10242 ctl = V_CTLREQID(1) | V_CTLCMDTYPE(0) | V_CTLXYBITSEL(0); 10243 if (i < 256) 10244 ctl |= V_CTLTCAMINDEX(i) | V_CTLTCAMSEL(0); 10245 else 10246 ctl |= V_CTLTCAMINDEX(i - 256) | V_CTLTCAMSEL(1); 10247 mtx_lock(&sc->reg_lock); 10248 if (hw_off_limits(sc)) 10249 rc = ENXIO; 10250 else { 10251 t4_write_reg(sc, A_MPS_CLS_TCAM_DATA2_CTL, ctl); 10252 val = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA1_REQ_ID1); 10253 tcamy = G_DMACH(val) << 32; 10254 tcamy |= t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA0_REQ_ID1); 10255 data2 = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA2_REQ_ID1); 10256 } 10257 mtx_unlock(&sc->reg_lock); 10258 if (rc != 0) 10259 break; 10260 10261 lookup_type = G_DATALKPTYPE(data2); 10262 port_num = G_DATAPORTNUM(data2); 10263 if (lookup_type && lookup_type != M_DATALKPTYPE) { 10264 /* Inner header VNI */ 10265 vniy = ((data2 & F_DATAVIDH2) << 23) | 10266 (G_DATAVIDH1(data2) << 16) | G_VIDL(val); 10267 dip_hit = data2 & F_DATADIPHIT; 10268 vlan_vld = 0; 10269 } else { 10270 vniy = 0; 10271 dip_hit = 0; 10272 vlan_vld = data2 & F_DATAVIDH2; 10273 ivlan = G_VIDL(val); 10274 } 10275 10276 ctl |= V_CTLXYBITSEL(1); 10277 mtx_lock(&sc->reg_lock); 10278 if (hw_off_limits(sc)) 10279 rc = ENXIO; 10280 else { 10281 t4_write_reg(sc, A_MPS_CLS_TCAM_DATA2_CTL, ctl); 10282 val = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA1_REQ_ID1); 10283 tcamx = G_DMACH(val) << 32; 10284 tcamx |= t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA0_REQ_ID1); 10285 data2 = t4_read_reg(sc, A_MPS_CLS_TCAM_RDATA2_REQ_ID1); 10286 } 10287 mtx_unlock(&sc->reg_lock); 10288 if (rc != 0) 10289 break; 10290 10291 if (lookup_type && lookup_type != M_DATALKPTYPE) { 10292 /* Inner header VNI mask */ 10293 vnix = ((data2 & F_DATAVIDH2) << 23) | 10294 (G_DATAVIDH1(data2) << 16) | G_VIDL(val); 10295 } else 10296 vnix = 0; 10297 10298 if (tcamx & tcamy) 10299 continue; 10300 tcamxy2valmask(tcamx, tcamy, addr, &mask); 10301 10302 mtx_lock(&sc->reg_lock); 10303 if (hw_off_limits(sc)) 10304 rc = ENXIO; 10305 else { 10306 cls_lo = t4_read_reg(sc, MPS_CLS_SRAM_L(i)); 10307 cls_hi = t4_read_reg(sc, MPS_CLS_SRAM_H(i)); 10308 } 10309 mtx_unlock(&sc->reg_lock); 10310 if (rc != 0) 10311 break; 10312 10313 if (lookup_type && lookup_type != M_DATALKPTYPE) { 10314 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x " 10315 "%012jx %06x %06x - - %3c" 10316 " I %4x %3c %#x%4u%4d", i, addr[0], 10317 addr[1], addr[2], addr[3], addr[4], addr[5], 10318 (uintmax_t)mask, vniy, vnix, dip_hit ? 'Y' : 'N', 10319 port_num, cls_lo & F_T6_SRAM_VLD ? 'Y' : 'N', 10320 G_PORTMAP(cls_hi), G_T6_PF(cls_lo), 10321 cls_lo & F_T6_VF_VALID ? G_T6_VF(cls_lo) : -1); 10322 } else { 10323 sbuf_printf(sb, "\n%3u %02x:%02x:%02x:%02x:%02x:%02x " 10324 "%012jx - - ", i, addr[0], addr[1], 10325 addr[2], addr[3], addr[4], addr[5], 10326 (uintmax_t)mask); 10327 10328 if (vlan_vld) 10329 sbuf_printf(sb, "%4u Y ", ivlan); 10330 else 10331 sbuf_printf(sb, " - N "); 10332 10333 sbuf_printf(sb, "- %3c %4x %3c %#x%4u%4d", 10334 lookup_type ? 'I' : 'O', port_num, 10335 cls_lo & F_T6_SRAM_VLD ? 'Y' : 'N', 10336 G_PORTMAP(cls_hi), G_T6_PF(cls_lo), 10337 cls_lo & F_T6_VF_VALID ? G_T6_VF(cls_lo) : -1); 10338 } 10339 10340 10341 if (cls_lo & F_T6_REPLICATE) { 10342 struct fw_ldst_cmd ldst_cmd; 10343 10344 memset(&ldst_cmd, 0, sizeof(ldst_cmd)); 10345 ldst_cmd.op_to_addrspace = 10346 htobe32(V_FW_CMD_OP(FW_LDST_CMD) | 10347 F_FW_CMD_REQUEST | F_FW_CMD_READ | 10348 V_FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_MPS)); 10349 ldst_cmd.cycles_to_len16 = htobe32(FW_LEN16(ldst_cmd)); 10350 ldst_cmd.u.mps.rplc.fid_idx = 10351 htobe16(V_FW_LDST_CMD_FID(FW_LDST_MPS_RPLC) | 10352 V_FW_LDST_CMD_IDX(i)); 10353 10354 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, 10355 "t6mps"); 10356 if (rc) 10357 break; 10358 if (hw_off_limits(sc)) 10359 rc = ENXIO; 10360 else 10361 rc = -t4_wr_mbox(sc, sc->mbox, &ldst_cmd, 10362 sizeof(ldst_cmd), &ldst_cmd); 10363 end_synchronized_op(sc, 0); 10364 if (rc != 0) 10365 break; 10366 else { 10367 sbuf_printf(sb, " %08x %08x %08x %08x" 10368 " %08x %08x %08x %08x", 10369 be32toh(ldst_cmd.u.mps.rplc.rplc255_224), 10370 be32toh(ldst_cmd.u.mps.rplc.rplc223_192), 10371 be32toh(ldst_cmd.u.mps.rplc.rplc191_160), 10372 be32toh(ldst_cmd.u.mps.rplc.rplc159_128), 10373 be32toh(ldst_cmd.u.mps.rplc.rplc127_96), 10374 be32toh(ldst_cmd.u.mps.rplc.rplc95_64), 10375 be32toh(ldst_cmd.u.mps.rplc.rplc63_32), 10376 be32toh(ldst_cmd.u.mps.rplc.rplc31_0)); 10377 } 10378 } else 10379 sbuf_printf(sb, "%72s", ""); 10380 10381 sbuf_printf(sb, "%4u%3u%3u%3u %#x", 10382 G_T6_SRAM_PRIO0(cls_lo), G_T6_SRAM_PRIO1(cls_lo), 10383 G_T6_SRAM_PRIO2(cls_lo), G_T6_SRAM_PRIO3(cls_lo), 10384 (cls_lo >> S_T6_MULTILISTEN0) & 0xf); 10385 } 10386 10387 if (rc) 10388 (void) sbuf_finish(sb); 10389 else 10390 rc = sbuf_finish(sb); 10391 sbuf_delete(sb); 10392 10393 return (rc); 10394 } 10395 10396 static int 10397 sysctl_path_mtus(SYSCTL_HANDLER_ARGS) 10398 { 10399 struct adapter *sc = arg1; 10400 struct sbuf *sb; 10401 int rc; 10402 uint16_t mtus[NMTUS]; 10403 10404 rc = sysctl_wire_old_buffer(req, 0); 10405 if (rc != 0) 10406 return (rc); 10407 10408 mtx_lock(&sc->reg_lock); 10409 if (hw_off_limits(sc)) 10410 rc = ENXIO; 10411 else 10412 t4_read_mtu_tbl(sc, mtus, NULL); 10413 mtx_unlock(&sc->reg_lock); 10414 if (rc != 0) 10415 return (rc); 10416 10417 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req); 10418 if (sb == NULL) 10419 return (ENOMEM); 10420 10421 sbuf_printf(sb, "%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u", 10422 mtus[0], mtus[1], mtus[2], mtus[3], mtus[4], mtus[5], mtus[6], 10423 mtus[7], mtus[8], mtus[9], mtus[10], mtus[11], mtus[12], mtus[13], 10424 mtus[14], mtus[15]); 10425 10426 rc = sbuf_finish(sb); 10427 sbuf_delete(sb); 10428 10429 return (rc); 10430 } 10431 10432 static int 10433 sysctl_pm_stats(SYSCTL_HANDLER_ARGS) 10434 { 10435 struct adapter *sc = arg1; 10436 struct sbuf *sb; 10437 int rc, i; 10438 uint32_t tx_cnt[MAX_PM_NSTATS], rx_cnt[MAX_PM_NSTATS]; 10439 uint64_t tx_cyc[MAX_PM_NSTATS], rx_cyc[MAX_PM_NSTATS]; 10440 static const char *tx_stats[MAX_PM_NSTATS] = { 10441 "Read:", "Write bypass:", "Write mem:", "Bypass + mem:", 10442 "Tx FIFO wait", NULL, "Tx latency" 10443 }; 10444 static const char *rx_stats[MAX_PM_NSTATS] = { 10445 "Read:", "Write bypass:", "Write mem:", "Flush:", 10446 "Rx FIFO wait", NULL, "Rx latency" 10447 }; 10448 10449 rc = sysctl_wire_old_buffer(req, 0); 10450 if (rc != 0) 10451 return (rc); 10452 10453 mtx_lock(&sc->reg_lock); 10454 if (hw_off_limits(sc)) 10455 rc = ENXIO; 10456 else { 10457 t4_pmtx_get_stats(sc, tx_cnt, tx_cyc); 10458 t4_pmrx_get_stats(sc, rx_cnt, rx_cyc); 10459 } 10460 mtx_unlock(&sc->reg_lock); 10461 if (rc != 0) 10462 return (rc); 10463 10464 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req); 10465 if (sb == NULL) 10466 return (ENOMEM); 10467 10468 sbuf_printf(sb, " Tx pcmds Tx bytes"); 10469 for (i = 0; i < 4; i++) { 10470 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i], 10471 tx_cyc[i]); 10472 } 10473 10474 sbuf_printf(sb, "\n Rx pcmds Rx bytes"); 10475 for (i = 0; i < 4; i++) { 10476 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i], 10477 rx_cyc[i]); 10478 } 10479 10480 if (chip_id(sc) > CHELSIO_T5) { 10481 sbuf_printf(sb, 10482 "\n Total wait Total occupancy"); 10483 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i], 10484 tx_cyc[i]); 10485 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i], 10486 rx_cyc[i]); 10487 10488 i += 2; 10489 MPASS(i < nitems(tx_stats)); 10490 10491 sbuf_printf(sb, 10492 "\n Reads Total wait"); 10493 sbuf_printf(sb, "\n%-13s %10u %20ju", tx_stats[i], tx_cnt[i], 10494 tx_cyc[i]); 10495 sbuf_printf(sb, "\n%-13s %10u %20ju", rx_stats[i], rx_cnt[i], 10496 rx_cyc[i]); 10497 } 10498 10499 rc = sbuf_finish(sb); 10500 sbuf_delete(sb); 10501 10502 return (rc); 10503 } 10504 10505 static int 10506 sysctl_rdma_stats(SYSCTL_HANDLER_ARGS) 10507 { 10508 struct adapter *sc = arg1; 10509 struct sbuf *sb; 10510 int rc; 10511 struct tp_rdma_stats stats; 10512 10513 rc = sysctl_wire_old_buffer(req, 0); 10514 if (rc != 0) 10515 return (rc); 10516 10517 mtx_lock(&sc->reg_lock); 10518 if (hw_off_limits(sc)) 10519 rc = ENXIO; 10520 else 10521 t4_tp_get_rdma_stats(sc, &stats, 0); 10522 mtx_unlock(&sc->reg_lock); 10523 if (rc != 0) 10524 return (rc); 10525 10526 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req); 10527 if (sb == NULL) 10528 return (ENOMEM); 10529 10530 sbuf_printf(sb, "NoRQEModDefferals: %u\n", stats.rqe_dfr_mod); 10531 sbuf_printf(sb, "NoRQEPktDefferals: %u", stats.rqe_dfr_pkt); 10532 10533 rc = sbuf_finish(sb); 10534 sbuf_delete(sb); 10535 10536 return (rc); 10537 } 10538 10539 static int 10540 sysctl_tcp_stats(SYSCTL_HANDLER_ARGS) 10541 { 10542 struct adapter *sc = arg1; 10543 struct sbuf *sb; 10544 int rc; 10545 struct tp_tcp_stats v4, v6; 10546 10547 rc = sysctl_wire_old_buffer(req, 0); 10548 if (rc != 0) 10549 return (rc); 10550 10551 mtx_lock(&sc->reg_lock); 10552 if (hw_off_limits(sc)) 10553 rc = ENXIO; 10554 else 10555 t4_tp_get_tcp_stats(sc, &v4, &v6, 0); 10556 mtx_unlock(&sc->reg_lock); 10557 if (rc != 0) 10558 return (rc); 10559 10560 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req); 10561 if (sb == NULL) 10562 return (ENOMEM); 10563 10564 sbuf_printf(sb, 10565 " IP IPv6\n"); 10566 sbuf_printf(sb, "OutRsts: %20u %20u\n", 10567 v4.tcp_out_rsts, v6.tcp_out_rsts); 10568 sbuf_printf(sb, "InSegs: %20ju %20ju\n", 10569 v4.tcp_in_segs, v6.tcp_in_segs); 10570 sbuf_printf(sb, "OutSegs: %20ju %20ju\n", 10571 v4.tcp_out_segs, v6.tcp_out_segs); 10572 sbuf_printf(sb, "RetransSegs: %20ju %20ju", 10573 v4.tcp_retrans_segs, v6.tcp_retrans_segs); 10574 10575 rc = sbuf_finish(sb); 10576 sbuf_delete(sb); 10577 10578 return (rc); 10579 } 10580 10581 static int 10582 sysctl_tids(SYSCTL_HANDLER_ARGS) 10583 { 10584 struct adapter *sc = arg1; 10585 struct sbuf *sb; 10586 int rc; 10587 uint32_t x, y; 10588 struct tid_info *t = &sc->tids; 10589 10590 rc = sysctl_wire_old_buffer(req, 0); 10591 if (rc != 0) 10592 return (rc); 10593 10594 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req); 10595 if (sb == NULL) 10596 return (ENOMEM); 10597 10598 if (t->natids) { 10599 sbuf_printf(sb, "ATID range: 0-%u, in use: %u\n", t->natids - 1, 10600 t->atids_in_use); 10601 } 10602 10603 if (t->nhpftids) { 10604 sbuf_printf(sb, "HPFTID range: %u-%u, in use: %u\n", 10605 t->hpftid_base, t->hpftid_end, t->hpftids_in_use); 10606 } 10607 10608 if (t->ntids) { 10609 bool hashen = false; 10610 10611 mtx_lock(&sc->reg_lock); 10612 if (hw_off_limits(sc)) 10613 rc = ENXIO; 10614 else if (t4_read_reg(sc, A_LE_DB_CONFIG) & F_HASHEN) { 10615 hashen = true; 10616 if (chip_id(sc) <= CHELSIO_T5) { 10617 x = t4_read_reg(sc, A_LE_DB_SERVER_INDEX) / 4; 10618 y = t4_read_reg(sc, A_LE_DB_TID_HASHBASE) / 4; 10619 } else { 10620 x = t4_read_reg(sc, A_LE_DB_SRVR_START_INDEX); 10621 y = t4_read_reg(sc, A_T6_LE_DB_HASH_TID_BASE); 10622 } 10623 } 10624 mtx_unlock(&sc->reg_lock); 10625 if (rc != 0) 10626 goto done; 10627 10628 sbuf_printf(sb, "TID range: "); 10629 if (hashen) { 10630 if (x) 10631 sbuf_printf(sb, "%u-%u, ", t->tid_base, x - 1); 10632 sbuf_printf(sb, "%u-%u", y, t->ntids - 1); 10633 } else { 10634 sbuf_printf(sb, "%u-%u", t->tid_base, t->tid_base + 10635 t->ntids - 1); 10636 } 10637 sbuf_printf(sb, ", in use: %u\n", 10638 atomic_load_acq_int(&t->tids_in_use)); 10639 } 10640 10641 if (t->nstids) { 10642 sbuf_printf(sb, "STID range: %u-%u, in use: %u\n", t->stid_base, 10643 t->stid_base + t->nstids - 1, t->stids_in_use); 10644 } 10645 10646 if (t->nftids) { 10647 sbuf_printf(sb, "FTID range: %u-%u, in use: %u\n", t->ftid_base, 10648 t->ftid_end, t->ftids_in_use); 10649 } 10650 10651 if (t->netids) { 10652 sbuf_printf(sb, "ETID range: %u-%u, in use: %u\n", t->etid_base, 10653 t->etid_base + t->netids - 1, t->etids_in_use); 10654 } 10655 10656 mtx_lock(&sc->reg_lock); 10657 if (hw_off_limits(sc)) 10658 rc = ENXIO; 10659 else { 10660 x = t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV4); 10661 y = t4_read_reg(sc, A_LE_DB_ACT_CNT_IPV6); 10662 } 10663 mtx_unlock(&sc->reg_lock); 10664 if (rc != 0) 10665 goto done; 10666 sbuf_printf(sb, "HW TID usage: %u IP users, %u IPv6 users", x, y); 10667 done: 10668 if (rc == 0) 10669 rc = sbuf_finish(sb); 10670 else 10671 (void)sbuf_finish(sb); 10672 sbuf_delete(sb); 10673 10674 return (rc); 10675 } 10676 10677 static int 10678 sysctl_tp_err_stats(SYSCTL_HANDLER_ARGS) 10679 { 10680 struct adapter *sc = arg1; 10681 struct sbuf *sb; 10682 int rc; 10683 struct tp_err_stats stats; 10684 10685 rc = sysctl_wire_old_buffer(req, 0); 10686 if (rc != 0) 10687 return (rc); 10688 10689 mtx_lock(&sc->reg_lock); 10690 if (hw_off_limits(sc)) 10691 rc = ENXIO; 10692 else 10693 t4_tp_get_err_stats(sc, &stats, 0); 10694 mtx_unlock(&sc->reg_lock); 10695 if (rc != 0) 10696 return (rc); 10697 10698 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req); 10699 if (sb == NULL) 10700 return (ENOMEM); 10701 10702 if (sc->chip_params->nchan > 2) { 10703 sbuf_printf(sb, " channel 0 channel 1" 10704 " channel 2 channel 3\n"); 10705 sbuf_printf(sb, "macInErrs: %10u %10u %10u %10u\n", 10706 stats.mac_in_errs[0], stats.mac_in_errs[1], 10707 stats.mac_in_errs[2], stats.mac_in_errs[3]); 10708 sbuf_printf(sb, "hdrInErrs: %10u %10u %10u %10u\n", 10709 stats.hdr_in_errs[0], stats.hdr_in_errs[1], 10710 stats.hdr_in_errs[2], stats.hdr_in_errs[3]); 10711 sbuf_printf(sb, "tcpInErrs: %10u %10u %10u %10u\n", 10712 stats.tcp_in_errs[0], stats.tcp_in_errs[1], 10713 stats.tcp_in_errs[2], stats.tcp_in_errs[3]); 10714 sbuf_printf(sb, "tcp6InErrs: %10u %10u %10u %10u\n", 10715 stats.tcp6_in_errs[0], stats.tcp6_in_errs[1], 10716 stats.tcp6_in_errs[2], stats.tcp6_in_errs[3]); 10717 sbuf_printf(sb, "tnlCongDrops: %10u %10u %10u %10u\n", 10718 stats.tnl_cong_drops[0], stats.tnl_cong_drops[1], 10719 stats.tnl_cong_drops[2], stats.tnl_cong_drops[3]); 10720 sbuf_printf(sb, "tnlTxDrops: %10u %10u %10u %10u\n", 10721 stats.tnl_tx_drops[0], stats.tnl_tx_drops[1], 10722 stats.tnl_tx_drops[2], stats.tnl_tx_drops[3]); 10723 sbuf_printf(sb, "ofldVlanDrops: %10u %10u %10u %10u\n", 10724 stats.ofld_vlan_drops[0], stats.ofld_vlan_drops[1], 10725 stats.ofld_vlan_drops[2], stats.ofld_vlan_drops[3]); 10726 sbuf_printf(sb, "ofldChanDrops: %10u %10u %10u %10u\n\n", 10727 stats.ofld_chan_drops[0], stats.ofld_chan_drops[1], 10728 stats.ofld_chan_drops[2], stats.ofld_chan_drops[3]); 10729 } else { 10730 sbuf_printf(sb, " channel 0 channel 1\n"); 10731 sbuf_printf(sb, "macInErrs: %10u %10u\n", 10732 stats.mac_in_errs[0], stats.mac_in_errs[1]); 10733 sbuf_printf(sb, "hdrInErrs: %10u %10u\n", 10734 stats.hdr_in_errs[0], stats.hdr_in_errs[1]); 10735 sbuf_printf(sb, "tcpInErrs: %10u %10u\n", 10736 stats.tcp_in_errs[0], stats.tcp_in_errs[1]); 10737 sbuf_printf(sb, "tcp6InErrs: %10u %10u\n", 10738 stats.tcp6_in_errs[0], stats.tcp6_in_errs[1]); 10739 sbuf_printf(sb, "tnlCongDrops: %10u %10u\n", 10740 stats.tnl_cong_drops[0], stats.tnl_cong_drops[1]); 10741 sbuf_printf(sb, "tnlTxDrops: %10u %10u\n", 10742 stats.tnl_tx_drops[0], stats.tnl_tx_drops[1]); 10743 sbuf_printf(sb, "ofldVlanDrops: %10u %10u\n", 10744 stats.ofld_vlan_drops[0], stats.ofld_vlan_drops[1]); 10745 sbuf_printf(sb, "ofldChanDrops: %10u %10u\n\n", 10746 stats.ofld_chan_drops[0], stats.ofld_chan_drops[1]); 10747 } 10748 10749 sbuf_printf(sb, "ofldNoNeigh: %u\nofldCongDefer: %u", 10750 stats.ofld_no_neigh, stats.ofld_cong_defer); 10751 10752 rc = sbuf_finish(sb); 10753 sbuf_delete(sb); 10754 10755 return (rc); 10756 } 10757 10758 static int 10759 sysctl_tnl_stats(SYSCTL_HANDLER_ARGS) 10760 { 10761 struct adapter *sc = arg1; 10762 struct sbuf *sb; 10763 int rc; 10764 struct tp_tnl_stats stats; 10765 10766 rc = sysctl_wire_old_buffer(req, 0); 10767 if (rc != 0) 10768 return(rc); 10769 10770 mtx_lock(&sc->reg_lock); 10771 if (hw_off_limits(sc)) 10772 rc = ENXIO; 10773 else 10774 t4_tp_get_tnl_stats(sc, &stats, 1); 10775 mtx_unlock(&sc->reg_lock); 10776 if (rc != 0) 10777 return (rc); 10778 10779 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req); 10780 if (sb == NULL) 10781 return (ENOMEM); 10782 10783 if (sc->chip_params->nchan > 2) { 10784 sbuf_printf(sb, " channel 0 channel 1" 10785 " channel 2 channel 3\n"); 10786 sbuf_printf(sb, "OutPkts: %10u %10u %10u %10u\n", 10787 stats.out_pkt[0], stats.out_pkt[1], 10788 stats.out_pkt[2], stats.out_pkt[3]); 10789 sbuf_printf(sb, "InPkts: %10u %10u %10u %10u", 10790 stats.in_pkt[0], stats.in_pkt[1], 10791 stats.in_pkt[2], stats.in_pkt[3]); 10792 } else { 10793 sbuf_printf(sb, " channel 0 channel 1\n"); 10794 sbuf_printf(sb, "OutPkts: %10u %10u\n", 10795 stats.out_pkt[0], stats.out_pkt[1]); 10796 sbuf_printf(sb, "InPkts: %10u %10u", 10797 stats.in_pkt[0], stats.in_pkt[1]); 10798 } 10799 10800 rc = sbuf_finish(sb); 10801 sbuf_delete(sb); 10802 10803 return (rc); 10804 } 10805 10806 static int 10807 sysctl_tp_la_mask(SYSCTL_HANDLER_ARGS) 10808 { 10809 struct adapter *sc = arg1; 10810 struct tp_params *tpp = &sc->params.tp; 10811 u_int mask; 10812 int rc; 10813 10814 mask = tpp->la_mask >> 16; 10815 rc = sysctl_handle_int(oidp, &mask, 0, req); 10816 if (rc != 0 || req->newptr == NULL) 10817 return (rc); 10818 if (mask > 0xffff) 10819 return (EINVAL); 10820 mtx_lock(&sc->reg_lock); 10821 if (hw_off_limits(sc)) 10822 rc = ENXIO; 10823 else { 10824 tpp->la_mask = mask << 16; 10825 t4_set_reg_field(sc, A_TP_DBG_LA_CONFIG, 0xffff0000U, 10826 tpp->la_mask); 10827 } 10828 mtx_unlock(&sc->reg_lock); 10829 10830 return (rc); 10831 } 10832 10833 struct field_desc { 10834 const char *name; 10835 u_int start; 10836 u_int width; 10837 }; 10838 10839 static void 10840 field_desc_show(struct sbuf *sb, uint64_t v, const struct field_desc *f) 10841 { 10842 char buf[32]; 10843 int line_size = 0; 10844 10845 while (f->name) { 10846 uint64_t mask = (1ULL << f->width) - 1; 10847 int len = snprintf(buf, sizeof(buf), "%s: %ju", f->name, 10848 ((uintmax_t)v >> f->start) & mask); 10849 10850 if (line_size + len >= 79) { 10851 line_size = 8; 10852 sbuf_printf(sb, "\n "); 10853 } 10854 sbuf_printf(sb, "%s ", buf); 10855 line_size += len + 1; 10856 f++; 10857 } 10858 sbuf_printf(sb, "\n"); 10859 } 10860 10861 static const struct field_desc tp_la0[] = { 10862 { "RcfOpCodeOut", 60, 4 }, 10863 { "State", 56, 4 }, 10864 { "WcfState", 52, 4 }, 10865 { "RcfOpcSrcOut", 50, 2 }, 10866 { "CRxError", 49, 1 }, 10867 { "ERxError", 48, 1 }, 10868 { "SanityFailed", 47, 1 }, 10869 { "SpuriousMsg", 46, 1 }, 10870 { "FlushInputMsg", 45, 1 }, 10871 { "FlushInputCpl", 44, 1 }, 10872 { "RssUpBit", 43, 1 }, 10873 { "RssFilterHit", 42, 1 }, 10874 { "Tid", 32, 10 }, 10875 { "InitTcb", 31, 1 }, 10876 { "LineNumber", 24, 7 }, 10877 { "Emsg", 23, 1 }, 10878 { "EdataOut", 22, 1 }, 10879 { "Cmsg", 21, 1 }, 10880 { "CdataOut", 20, 1 }, 10881 { "EreadPdu", 19, 1 }, 10882 { "CreadPdu", 18, 1 }, 10883 { "TunnelPkt", 17, 1 }, 10884 { "RcfPeerFin", 16, 1 }, 10885 { "RcfReasonOut", 12, 4 }, 10886 { "TxCchannel", 10, 2 }, 10887 { "RcfTxChannel", 8, 2 }, 10888 { "RxEchannel", 6, 2 }, 10889 { "RcfRxChannel", 5, 1 }, 10890 { "RcfDataOutSrdy", 4, 1 }, 10891 { "RxDvld", 3, 1 }, 10892 { "RxOoDvld", 2, 1 }, 10893 { "RxCongestion", 1, 1 }, 10894 { "TxCongestion", 0, 1 }, 10895 { NULL } 10896 }; 10897 10898 static const struct field_desc tp_la1[] = { 10899 { "CplCmdIn", 56, 8 }, 10900 { "CplCmdOut", 48, 8 }, 10901 { "ESynOut", 47, 1 }, 10902 { "EAckOut", 46, 1 }, 10903 { "EFinOut", 45, 1 }, 10904 { "ERstOut", 44, 1 }, 10905 { "SynIn", 43, 1 }, 10906 { "AckIn", 42, 1 }, 10907 { "FinIn", 41, 1 }, 10908 { "RstIn", 40, 1 }, 10909 { "DataIn", 39, 1 }, 10910 { "DataInVld", 38, 1 }, 10911 { "PadIn", 37, 1 }, 10912 { "RxBufEmpty", 36, 1 }, 10913 { "RxDdp", 35, 1 }, 10914 { "RxFbCongestion", 34, 1 }, 10915 { "TxFbCongestion", 33, 1 }, 10916 { "TxPktSumSrdy", 32, 1 }, 10917 { "RcfUlpType", 28, 4 }, 10918 { "Eread", 27, 1 }, 10919 { "Ebypass", 26, 1 }, 10920 { "Esave", 25, 1 }, 10921 { "Static0", 24, 1 }, 10922 { "Cread", 23, 1 }, 10923 { "Cbypass", 22, 1 }, 10924 { "Csave", 21, 1 }, 10925 { "CPktOut", 20, 1 }, 10926 { "RxPagePoolFull", 18, 2 }, 10927 { "RxLpbkPkt", 17, 1 }, 10928 { "TxLpbkPkt", 16, 1 }, 10929 { "RxVfValid", 15, 1 }, 10930 { "SynLearned", 14, 1 }, 10931 { "SetDelEntry", 13, 1 }, 10932 { "SetInvEntry", 12, 1 }, 10933 { "CpcmdDvld", 11, 1 }, 10934 { "CpcmdSave", 10, 1 }, 10935 { "RxPstructsFull", 8, 2 }, 10936 { "EpcmdDvld", 7, 1 }, 10937 { "EpcmdFlush", 6, 1 }, 10938 { "EpcmdTrimPrefix", 5, 1 }, 10939 { "EpcmdTrimPostfix", 4, 1 }, 10940 { "ERssIp4Pkt", 3, 1 }, 10941 { "ERssIp6Pkt", 2, 1 }, 10942 { "ERssTcpUdpPkt", 1, 1 }, 10943 { "ERssFceFipPkt", 0, 1 }, 10944 { NULL } 10945 }; 10946 10947 static const struct field_desc tp_la2[] = { 10948 { "CplCmdIn", 56, 8 }, 10949 { "MpsVfVld", 55, 1 }, 10950 { "MpsPf", 52, 3 }, 10951 { "MpsVf", 44, 8 }, 10952 { "SynIn", 43, 1 }, 10953 { "AckIn", 42, 1 }, 10954 { "FinIn", 41, 1 }, 10955 { "RstIn", 40, 1 }, 10956 { "DataIn", 39, 1 }, 10957 { "DataInVld", 38, 1 }, 10958 { "PadIn", 37, 1 }, 10959 { "RxBufEmpty", 36, 1 }, 10960 { "RxDdp", 35, 1 }, 10961 { "RxFbCongestion", 34, 1 }, 10962 { "TxFbCongestion", 33, 1 }, 10963 { "TxPktSumSrdy", 32, 1 }, 10964 { "RcfUlpType", 28, 4 }, 10965 { "Eread", 27, 1 }, 10966 { "Ebypass", 26, 1 }, 10967 { "Esave", 25, 1 }, 10968 { "Static0", 24, 1 }, 10969 { "Cread", 23, 1 }, 10970 { "Cbypass", 22, 1 }, 10971 { "Csave", 21, 1 }, 10972 { "CPktOut", 20, 1 }, 10973 { "RxPagePoolFull", 18, 2 }, 10974 { "RxLpbkPkt", 17, 1 }, 10975 { "TxLpbkPkt", 16, 1 }, 10976 { "RxVfValid", 15, 1 }, 10977 { "SynLearned", 14, 1 }, 10978 { "SetDelEntry", 13, 1 }, 10979 { "SetInvEntry", 12, 1 }, 10980 { "CpcmdDvld", 11, 1 }, 10981 { "CpcmdSave", 10, 1 }, 10982 { "RxPstructsFull", 8, 2 }, 10983 { "EpcmdDvld", 7, 1 }, 10984 { "EpcmdFlush", 6, 1 }, 10985 { "EpcmdTrimPrefix", 5, 1 }, 10986 { "EpcmdTrimPostfix", 4, 1 }, 10987 { "ERssIp4Pkt", 3, 1 }, 10988 { "ERssIp6Pkt", 2, 1 }, 10989 { "ERssTcpUdpPkt", 1, 1 }, 10990 { "ERssFceFipPkt", 0, 1 }, 10991 { NULL } 10992 }; 10993 10994 static void 10995 tp_la_show(struct sbuf *sb, uint64_t *p, int idx) 10996 { 10997 10998 field_desc_show(sb, *p, tp_la0); 10999 } 11000 11001 static void 11002 tp_la_show2(struct sbuf *sb, uint64_t *p, int idx) 11003 { 11004 11005 if (idx) 11006 sbuf_printf(sb, "\n"); 11007 field_desc_show(sb, p[0], tp_la0); 11008 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL) 11009 field_desc_show(sb, p[1], tp_la0); 11010 } 11011 11012 static void 11013 tp_la_show3(struct sbuf *sb, uint64_t *p, int idx) 11014 { 11015 11016 if (idx) 11017 sbuf_printf(sb, "\n"); 11018 field_desc_show(sb, p[0], tp_la0); 11019 if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL) 11020 field_desc_show(sb, p[1], (p[0] & (1 << 17)) ? tp_la2 : tp_la1); 11021 } 11022 11023 static int 11024 sysctl_tp_la(SYSCTL_HANDLER_ARGS) 11025 { 11026 struct adapter *sc = arg1; 11027 struct sbuf *sb; 11028 uint64_t *buf, *p; 11029 int rc; 11030 u_int i, inc; 11031 void (*show_func)(struct sbuf *, uint64_t *, int); 11032 11033 rc = sysctl_wire_old_buffer(req, 0); 11034 if (rc != 0) 11035 return (rc); 11036 11037 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 11038 if (sb == NULL) 11039 return (ENOMEM); 11040 11041 buf = malloc(TPLA_SIZE * sizeof(uint64_t), M_CXGBE, M_ZERO | M_WAITOK); 11042 11043 mtx_lock(&sc->reg_lock); 11044 if (hw_off_limits(sc)) 11045 rc = ENXIO; 11046 else { 11047 t4_tp_read_la(sc, buf, NULL); 11048 switch (G_DBGLAMODE(t4_read_reg(sc, A_TP_DBG_LA_CONFIG))) { 11049 case 2: 11050 inc = 2; 11051 show_func = tp_la_show2; 11052 break; 11053 case 3: 11054 inc = 2; 11055 show_func = tp_la_show3; 11056 break; 11057 default: 11058 inc = 1; 11059 show_func = tp_la_show; 11060 } 11061 } 11062 mtx_unlock(&sc->reg_lock); 11063 if (rc != 0) 11064 goto done; 11065 11066 p = buf; 11067 for (i = 0; i < TPLA_SIZE / inc; i++, p += inc) 11068 (*show_func)(sb, p, i); 11069 rc = sbuf_finish(sb); 11070 done: 11071 sbuf_delete(sb); 11072 free(buf, M_CXGBE); 11073 return (rc); 11074 } 11075 11076 static int 11077 sysctl_tx_rate(SYSCTL_HANDLER_ARGS) 11078 { 11079 struct adapter *sc = arg1; 11080 struct sbuf *sb; 11081 int rc; 11082 u64 nrate[MAX_NCHAN], orate[MAX_NCHAN]; 11083 11084 rc = sysctl_wire_old_buffer(req, 0); 11085 if (rc != 0) 11086 return (rc); 11087 11088 mtx_lock(&sc->reg_lock); 11089 if (hw_off_limits(sc)) 11090 rc = ENXIO; 11091 else 11092 t4_get_chan_txrate(sc, nrate, orate); 11093 mtx_unlock(&sc->reg_lock); 11094 if (rc != 0) 11095 return (rc); 11096 11097 sb = sbuf_new_for_sysctl(NULL, NULL, 256, req); 11098 if (sb == NULL) 11099 return (ENOMEM); 11100 11101 if (sc->chip_params->nchan > 2) { 11102 sbuf_printf(sb, " channel 0 channel 1" 11103 " channel 2 channel 3\n"); 11104 sbuf_printf(sb, "NIC B/s: %10ju %10ju %10ju %10ju\n", 11105 nrate[0], nrate[1], nrate[2], nrate[3]); 11106 sbuf_printf(sb, "Offload B/s: %10ju %10ju %10ju %10ju", 11107 orate[0], orate[1], orate[2], orate[3]); 11108 } else { 11109 sbuf_printf(sb, " channel 0 channel 1\n"); 11110 sbuf_printf(sb, "NIC B/s: %10ju %10ju\n", 11111 nrate[0], nrate[1]); 11112 sbuf_printf(sb, "Offload B/s: %10ju %10ju", 11113 orate[0], orate[1]); 11114 } 11115 11116 rc = sbuf_finish(sb); 11117 sbuf_delete(sb); 11118 11119 return (rc); 11120 } 11121 11122 static int 11123 sysctl_ulprx_la(SYSCTL_HANDLER_ARGS) 11124 { 11125 struct adapter *sc = arg1; 11126 struct sbuf *sb; 11127 uint32_t *buf, *p; 11128 int rc, i; 11129 11130 rc = sysctl_wire_old_buffer(req, 0); 11131 if (rc != 0) 11132 return (rc); 11133 11134 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 11135 if (sb == NULL) 11136 return (ENOMEM); 11137 11138 buf = malloc(ULPRX_LA_SIZE * 8 * sizeof(uint32_t), M_CXGBE, 11139 M_ZERO | M_WAITOK); 11140 11141 mtx_lock(&sc->reg_lock); 11142 if (hw_off_limits(sc)) 11143 rc = ENXIO; 11144 else 11145 t4_ulprx_read_la(sc, buf); 11146 mtx_unlock(&sc->reg_lock); 11147 if (rc != 0) 11148 goto done; 11149 11150 p = buf; 11151 sbuf_printf(sb, " Pcmd Type Message" 11152 " Data"); 11153 for (i = 0; i < ULPRX_LA_SIZE; i++, p += 8) { 11154 sbuf_printf(sb, "\n%08x%08x %4x %08x %08x%08x%08x%08x", 11155 p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]); 11156 } 11157 rc = sbuf_finish(sb); 11158 done: 11159 sbuf_delete(sb); 11160 free(buf, M_CXGBE); 11161 return (rc); 11162 } 11163 11164 static int 11165 sysctl_wcwr_stats(SYSCTL_HANDLER_ARGS) 11166 { 11167 struct adapter *sc = arg1; 11168 struct sbuf *sb; 11169 int rc; 11170 uint32_t cfg, s1, s2; 11171 11172 MPASS(chip_id(sc) >= CHELSIO_T5); 11173 11174 rc = sysctl_wire_old_buffer(req, 0); 11175 if (rc != 0) 11176 return (rc); 11177 11178 mtx_lock(&sc->reg_lock); 11179 if (hw_off_limits(sc)) 11180 rc = ENXIO; 11181 else { 11182 cfg = t4_read_reg(sc, A_SGE_STAT_CFG); 11183 s1 = t4_read_reg(sc, A_SGE_STAT_TOTAL); 11184 s2 = t4_read_reg(sc, A_SGE_STAT_MATCH); 11185 } 11186 mtx_unlock(&sc->reg_lock); 11187 if (rc != 0) 11188 return (rc); 11189 11190 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 11191 if (sb == NULL) 11192 return (ENOMEM); 11193 11194 if (G_STATSOURCE_T5(cfg) == 7) { 11195 int mode; 11196 11197 mode = is_t5(sc) ? G_STATMODE(cfg) : G_T6_STATMODE(cfg); 11198 if (mode == 0) 11199 sbuf_printf(sb, "total %d, incomplete %d", s1, s2); 11200 else if (mode == 1) 11201 sbuf_printf(sb, "total %d, data overflow %d", s1, s2); 11202 else 11203 sbuf_printf(sb, "unknown mode %d", mode); 11204 } 11205 rc = sbuf_finish(sb); 11206 sbuf_delete(sb); 11207 11208 return (rc); 11209 } 11210 11211 static int 11212 sysctl_cpus(SYSCTL_HANDLER_ARGS) 11213 { 11214 struct adapter *sc = arg1; 11215 enum cpu_sets op = arg2; 11216 cpuset_t cpuset; 11217 struct sbuf *sb; 11218 int i, rc; 11219 11220 MPASS(op == LOCAL_CPUS || op == INTR_CPUS); 11221 11222 CPU_ZERO(&cpuset); 11223 rc = bus_get_cpus(sc->dev, op, sizeof(cpuset), &cpuset); 11224 if (rc != 0) 11225 return (rc); 11226 11227 rc = sysctl_wire_old_buffer(req, 0); 11228 if (rc != 0) 11229 return (rc); 11230 11231 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 11232 if (sb == NULL) 11233 return (ENOMEM); 11234 11235 CPU_FOREACH(i) 11236 sbuf_printf(sb, "%d ", i); 11237 rc = sbuf_finish(sb); 11238 sbuf_delete(sb); 11239 11240 return (rc); 11241 } 11242 11243 static int 11244 sysctl_reset(SYSCTL_HANDLER_ARGS) 11245 { 11246 struct adapter *sc = arg1; 11247 u_int val; 11248 int rc; 11249 11250 val = atomic_load_int(&sc->num_resets); 11251 rc = sysctl_handle_int(oidp, &val, 0, req); 11252 if (rc != 0 || req->newptr == NULL) 11253 return (rc); 11254 11255 if (val == 0) { 11256 /* Zero out the counter that tracks reset. */ 11257 atomic_store_int(&sc->num_resets, 0); 11258 return (0); 11259 } 11260 11261 if (val != 1) 11262 return (EINVAL); /* 0 or 1 are the only legal values */ 11263 11264 if (hw_off_limits(sc)) /* harmless race */ 11265 return (EALREADY); 11266 11267 taskqueue_enqueue(reset_tq, &sc->reset_task); 11268 return (0); 11269 } 11270 11271 #ifdef TCP_OFFLOAD 11272 static int 11273 sysctl_tls(SYSCTL_HANDLER_ARGS) 11274 { 11275 struct adapter *sc = arg1; 11276 int i, j, v, rc; 11277 struct vi_info *vi; 11278 11279 v = sc->tt.tls; 11280 rc = sysctl_handle_int(oidp, &v, 0, req); 11281 if (rc != 0 || req->newptr == NULL) 11282 return (rc); 11283 11284 if (v != 0 && !(sc->cryptocaps & FW_CAPS_CONFIG_TLSKEYS)) 11285 return (ENOTSUP); 11286 11287 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4stls"); 11288 if (rc) 11289 return (rc); 11290 if (hw_off_limits(sc)) 11291 rc = ENXIO; 11292 else { 11293 sc->tt.tls = !!v; 11294 for_each_port(sc, i) { 11295 for_each_vi(sc->port[i], j, vi) { 11296 if (vi->flags & VI_INIT_DONE) 11297 t4_update_fl_bufsize(vi->ifp); 11298 } 11299 } 11300 } 11301 end_synchronized_op(sc, 0); 11302 11303 return (rc); 11304 11305 } 11306 11307 static void 11308 unit_conv(char *buf, size_t len, u_int val, u_int factor) 11309 { 11310 u_int rem = val % factor; 11311 11312 if (rem == 0) 11313 snprintf(buf, len, "%u", val / factor); 11314 else { 11315 while (rem % 10 == 0) 11316 rem /= 10; 11317 snprintf(buf, len, "%u.%u", val / factor, rem); 11318 } 11319 } 11320 11321 static int 11322 sysctl_tp_tick(SYSCTL_HANDLER_ARGS) 11323 { 11324 struct adapter *sc = arg1; 11325 char buf[16]; 11326 u_int res, re; 11327 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk; 11328 11329 mtx_lock(&sc->reg_lock); 11330 if (hw_off_limits(sc)) 11331 res = (u_int)-1; 11332 else 11333 res = t4_read_reg(sc, A_TP_TIMER_RESOLUTION); 11334 mtx_unlock(&sc->reg_lock); 11335 if (res == (u_int)-1) 11336 return (ENXIO); 11337 11338 switch (arg2) { 11339 case 0: 11340 /* timer_tick */ 11341 re = G_TIMERRESOLUTION(res); 11342 break; 11343 case 1: 11344 /* TCP timestamp tick */ 11345 re = G_TIMESTAMPRESOLUTION(res); 11346 break; 11347 case 2: 11348 /* DACK tick */ 11349 re = G_DELAYEDACKRESOLUTION(res); 11350 break; 11351 default: 11352 return (EDOOFUS); 11353 } 11354 11355 unit_conv(buf, sizeof(buf), (cclk_ps << re), 1000000); 11356 11357 return (sysctl_handle_string(oidp, buf, sizeof(buf), req)); 11358 } 11359 11360 static int 11361 sysctl_tp_dack_timer(SYSCTL_HANDLER_ARGS) 11362 { 11363 struct adapter *sc = arg1; 11364 int rc; 11365 u_int dack_tmr, dack_re, v; 11366 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk; 11367 11368 mtx_lock(&sc->reg_lock); 11369 if (hw_off_limits(sc)) 11370 rc = ENXIO; 11371 else { 11372 rc = 0; 11373 dack_re = G_DELAYEDACKRESOLUTION(t4_read_reg(sc, 11374 A_TP_TIMER_RESOLUTION)); 11375 dack_tmr = t4_read_reg(sc, A_TP_DACK_TIMER); 11376 } 11377 mtx_unlock(&sc->reg_lock); 11378 if (rc != 0) 11379 return (rc); 11380 11381 v = ((cclk_ps << dack_re) / 1000000) * dack_tmr; 11382 11383 return (sysctl_handle_int(oidp, &v, 0, req)); 11384 } 11385 11386 static int 11387 sysctl_tp_timer(SYSCTL_HANDLER_ARGS) 11388 { 11389 struct adapter *sc = arg1; 11390 int rc, reg = arg2; 11391 u_int tre; 11392 u_long tp_tick_us, v; 11393 u_int cclk_ps = 1000000000 / sc->params.vpd.cclk; 11394 11395 MPASS(reg == A_TP_RXT_MIN || reg == A_TP_RXT_MAX || 11396 reg == A_TP_PERS_MIN || reg == A_TP_PERS_MAX || 11397 reg == A_TP_KEEP_IDLE || reg == A_TP_KEEP_INTVL || 11398 reg == A_TP_INIT_SRTT || reg == A_TP_FINWAIT2_TIMER); 11399 11400 mtx_lock(&sc->reg_lock); 11401 if (hw_off_limits(sc)) 11402 rc = ENXIO; 11403 else { 11404 rc = 0; 11405 tre = G_TIMERRESOLUTION(t4_read_reg(sc, A_TP_TIMER_RESOLUTION)); 11406 tp_tick_us = (cclk_ps << tre) / 1000000; 11407 if (reg == A_TP_INIT_SRTT) 11408 v = tp_tick_us * G_INITSRTT(t4_read_reg(sc, reg)); 11409 else 11410 v = tp_tick_us * t4_read_reg(sc, reg); 11411 } 11412 mtx_unlock(&sc->reg_lock); 11413 if (rc != 0) 11414 return (rc); 11415 else 11416 return (sysctl_handle_long(oidp, &v, 0, req)); 11417 } 11418 11419 /* 11420 * All fields in TP_SHIFT_CNT are 4b and the starting location of the field is 11421 * passed to this function. 11422 */ 11423 static int 11424 sysctl_tp_shift_cnt(SYSCTL_HANDLER_ARGS) 11425 { 11426 struct adapter *sc = arg1; 11427 int rc, idx = arg2; 11428 u_int v; 11429 11430 MPASS(idx >= 0 && idx <= 24); 11431 11432 mtx_lock(&sc->reg_lock); 11433 if (hw_off_limits(sc)) 11434 rc = ENXIO; 11435 else { 11436 rc = 0; 11437 v = (t4_read_reg(sc, A_TP_SHIFT_CNT) >> idx) & 0xf; 11438 } 11439 mtx_unlock(&sc->reg_lock); 11440 if (rc != 0) 11441 return (rc); 11442 else 11443 return (sysctl_handle_int(oidp, &v, 0, req)); 11444 } 11445 11446 static int 11447 sysctl_tp_backoff(SYSCTL_HANDLER_ARGS) 11448 { 11449 struct adapter *sc = arg1; 11450 int rc, idx = arg2; 11451 u_int shift, v, r; 11452 11453 MPASS(idx >= 0 && idx < 16); 11454 11455 r = A_TP_TCP_BACKOFF_REG0 + (idx & ~3); 11456 shift = (idx & 3) << 3; 11457 mtx_lock(&sc->reg_lock); 11458 if (hw_off_limits(sc)) 11459 rc = ENXIO; 11460 else { 11461 rc = 0; 11462 v = (t4_read_reg(sc, r) >> shift) & M_TIMERBACKOFFINDEX0; 11463 } 11464 mtx_unlock(&sc->reg_lock); 11465 if (rc != 0) 11466 return (rc); 11467 else 11468 return (sysctl_handle_int(oidp, &v, 0, req)); 11469 } 11470 11471 static int 11472 sysctl_holdoff_tmr_idx_ofld(SYSCTL_HANDLER_ARGS) 11473 { 11474 struct vi_info *vi = arg1; 11475 struct adapter *sc = vi->adapter; 11476 int idx, rc, i; 11477 struct sge_ofld_rxq *ofld_rxq; 11478 uint8_t v; 11479 11480 idx = vi->ofld_tmr_idx; 11481 11482 rc = sysctl_handle_int(oidp, &idx, 0, req); 11483 if (rc != 0 || req->newptr == NULL) 11484 return (rc); 11485 11486 if (idx < 0 || idx >= SGE_NTIMERS) 11487 return (EINVAL); 11488 11489 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK, 11490 "t4otmr"); 11491 if (rc) 11492 return (rc); 11493 11494 v = V_QINTR_TIMER_IDX(idx) | V_QINTR_CNT_EN(vi->ofld_pktc_idx != -1); 11495 for_each_ofld_rxq(vi, i, ofld_rxq) { 11496 #ifdef atomic_store_rel_8 11497 atomic_store_rel_8(&ofld_rxq->iq.intr_params, v); 11498 #else 11499 ofld_rxq->iq.intr_params = v; 11500 #endif 11501 } 11502 vi->ofld_tmr_idx = idx; 11503 11504 end_synchronized_op(sc, LOCK_HELD); 11505 return (0); 11506 } 11507 11508 static int 11509 sysctl_holdoff_pktc_idx_ofld(SYSCTL_HANDLER_ARGS) 11510 { 11511 struct vi_info *vi = arg1; 11512 struct adapter *sc = vi->adapter; 11513 int idx, rc; 11514 11515 idx = vi->ofld_pktc_idx; 11516 11517 rc = sysctl_handle_int(oidp, &idx, 0, req); 11518 if (rc != 0 || req->newptr == NULL) 11519 return (rc); 11520 11521 if (idx < -1 || idx >= SGE_NCOUNTERS) 11522 return (EINVAL); 11523 11524 rc = begin_synchronized_op(sc, vi, HOLD_LOCK | SLEEP_OK | INTR_OK, 11525 "t4opktc"); 11526 if (rc) 11527 return (rc); 11528 11529 if (vi->flags & VI_INIT_DONE) 11530 rc = EBUSY; /* cannot be changed once the queues are created */ 11531 else 11532 vi->ofld_pktc_idx = idx; 11533 11534 end_synchronized_op(sc, LOCK_HELD); 11535 return (rc); 11536 } 11537 #endif 11538 11539 static int 11540 get_sge_context(struct adapter *sc, struct t4_sge_context *cntxt) 11541 { 11542 int rc; 11543 11544 if (cntxt->cid > M_CTXTQID) 11545 return (EINVAL); 11546 11547 if (cntxt->mem_id != CTXT_EGRESS && cntxt->mem_id != CTXT_INGRESS && 11548 cntxt->mem_id != CTXT_FLM && cntxt->mem_id != CTXT_CNM) 11549 return (EINVAL); 11550 11551 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ctxt"); 11552 if (rc) 11553 return (rc); 11554 11555 if (hw_off_limits(sc)) { 11556 rc = ENXIO; 11557 goto done; 11558 } 11559 11560 if (sc->flags & FW_OK) { 11561 rc = -t4_sge_ctxt_rd(sc, sc->mbox, cntxt->cid, cntxt->mem_id, 11562 &cntxt->data[0]); 11563 if (rc == 0) 11564 goto done; 11565 } 11566 11567 /* 11568 * Read via firmware failed or wasn't even attempted. Read directly via 11569 * the backdoor. 11570 */ 11571 rc = -t4_sge_ctxt_rd_bd(sc, cntxt->cid, cntxt->mem_id, &cntxt->data[0]); 11572 done: 11573 end_synchronized_op(sc, 0); 11574 return (rc); 11575 } 11576 11577 static int 11578 load_fw(struct adapter *sc, struct t4_data *fw) 11579 { 11580 int rc; 11581 uint8_t *fw_data; 11582 11583 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldfw"); 11584 if (rc) 11585 return (rc); 11586 11587 if (hw_off_limits(sc)) { 11588 rc = ENXIO; 11589 goto done; 11590 } 11591 11592 /* 11593 * The firmware, with the sole exception of the memory parity error 11594 * handler, runs from memory and not flash. It is almost always safe to 11595 * install a new firmware on a running system. Just set bit 1 in 11596 * hw.cxgbe.dflags or dev.<nexus>.<n>.dflags first. 11597 */ 11598 if (sc->flags & FULL_INIT_DONE && 11599 (sc->debug_flags & DF_LOAD_FW_ANYTIME) == 0) { 11600 rc = EBUSY; 11601 goto done; 11602 } 11603 11604 fw_data = malloc(fw->len, M_CXGBE, M_WAITOK); 11605 11606 rc = copyin(fw->data, fw_data, fw->len); 11607 if (rc == 0) 11608 rc = -t4_load_fw(sc, fw_data, fw->len); 11609 11610 free(fw_data, M_CXGBE); 11611 done: 11612 end_synchronized_op(sc, 0); 11613 return (rc); 11614 } 11615 11616 static int 11617 load_cfg(struct adapter *sc, struct t4_data *cfg) 11618 { 11619 int rc; 11620 uint8_t *cfg_data = NULL; 11621 11622 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldcf"); 11623 if (rc) 11624 return (rc); 11625 11626 if (hw_off_limits(sc)) { 11627 rc = ENXIO; 11628 goto done; 11629 } 11630 11631 if (cfg->len == 0) { 11632 /* clear */ 11633 rc = -t4_load_cfg(sc, NULL, 0); 11634 goto done; 11635 } 11636 11637 cfg_data = malloc(cfg->len, M_CXGBE, M_WAITOK); 11638 11639 rc = copyin(cfg->data, cfg_data, cfg->len); 11640 if (rc == 0) 11641 rc = -t4_load_cfg(sc, cfg_data, cfg->len); 11642 11643 free(cfg_data, M_CXGBE); 11644 done: 11645 end_synchronized_op(sc, 0); 11646 return (rc); 11647 } 11648 11649 static int 11650 load_boot(struct adapter *sc, struct t4_bootrom *br) 11651 { 11652 int rc; 11653 uint8_t *br_data = NULL; 11654 u_int offset; 11655 11656 if (br->len > 1024 * 1024) 11657 return (EFBIG); 11658 11659 if (br->pf_offset == 0) { 11660 /* pfidx */ 11661 if (br->pfidx_addr > 7) 11662 return (EINVAL); 11663 offset = G_OFFSET(t4_read_reg(sc, PF_REG(br->pfidx_addr, 11664 A_PCIE_PF_EXPROM_OFST))); 11665 } else if (br->pf_offset == 1) { 11666 /* offset */ 11667 offset = G_OFFSET(br->pfidx_addr); 11668 } else { 11669 return (EINVAL); 11670 } 11671 11672 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldbr"); 11673 if (rc) 11674 return (rc); 11675 11676 if (hw_off_limits(sc)) { 11677 rc = ENXIO; 11678 goto done; 11679 } 11680 11681 if (br->len == 0) { 11682 /* clear */ 11683 rc = -t4_load_boot(sc, NULL, offset, 0); 11684 goto done; 11685 } 11686 11687 br_data = malloc(br->len, M_CXGBE, M_WAITOK); 11688 11689 rc = copyin(br->data, br_data, br->len); 11690 if (rc == 0) 11691 rc = -t4_load_boot(sc, br_data, offset, br->len); 11692 11693 free(br_data, M_CXGBE); 11694 done: 11695 end_synchronized_op(sc, 0); 11696 return (rc); 11697 } 11698 11699 static int 11700 load_bootcfg(struct adapter *sc, struct t4_data *bc) 11701 { 11702 int rc; 11703 uint8_t *bc_data = NULL; 11704 11705 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldcf"); 11706 if (rc) 11707 return (rc); 11708 11709 if (hw_off_limits(sc)) { 11710 rc = ENXIO; 11711 goto done; 11712 } 11713 11714 if (bc->len == 0) { 11715 /* clear */ 11716 rc = -t4_load_bootcfg(sc, NULL, 0); 11717 goto done; 11718 } 11719 11720 bc_data = malloc(bc->len, M_CXGBE, M_WAITOK); 11721 11722 rc = copyin(bc->data, bc_data, bc->len); 11723 if (rc == 0) 11724 rc = -t4_load_bootcfg(sc, bc_data, bc->len); 11725 11726 free(bc_data, M_CXGBE); 11727 done: 11728 end_synchronized_op(sc, 0); 11729 return (rc); 11730 } 11731 11732 static int 11733 cudbg_dump(struct adapter *sc, struct t4_cudbg_dump *dump) 11734 { 11735 int rc; 11736 struct cudbg_init *cudbg; 11737 void *handle, *buf; 11738 11739 /* buf is large, don't block if no memory is available */ 11740 buf = malloc(dump->len, M_CXGBE, M_NOWAIT | M_ZERO); 11741 if (buf == NULL) 11742 return (ENOMEM); 11743 11744 handle = cudbg_alloc_handle(); 11745 if (handle == NULL) { 11746 rc = ENOMEM; 11747 goto done; 11748 } 11749 11750 cudbg = cudbg_get_init(handle); 11751 cudbg->adap = sc; 11752 cudbg->print = (cudbg_print_cb)printf; 11753 11754 #ifndef notyet 11755 device_printf(sc->dev, "%s: wr_flash %u, len %u, data %p.\n", 11756 __func__, dump->wr_flash, dump->len, dump->data); 11757 #endif 11758 11759 if (dump->wr_flash) 11760 cudbg->use_flash = 1; 11761 MPASS(sizeof(cudbg->dbg_bitmap) == sizeof(dump->bitmap)); 11762 memcpy(cudbg->dbg_bitmap, dump->bitmap, sizeof(cudbg->dbg_bitmap)); 11763 11764 rc = cudbg_collect(handle, buf, &dump->len); 11765 if (rc != 0) 11766 goto done; 11767 11768 rc = copyout(buf, dump->data, dump->len); 11769 done: 11770 cudbg_free_handle(handle); 11771 free(buf, M_CXGBE); 11772 return (rc); 11773 } 11774 11775 static void 11776 free_offload_policy(struct t4_offload_policy *op) 11777 { 11778 struct offload_rule *r; 11779 int i; 11780 11781 if (op == NULL) 11782 return; 11783 11784 r = &op->rule[0]; 11785 for (i = 0; i < op->nrules; i++, r++) { 11786 free(r->bpf_prog.bf_insns, M_CXGBE); 11787 } 11788 free(op->rule, M_CXGBE); 11789 free(op, M_CXGBE); 11790 } 11791 11792 static int 11793 set_offload_policy(struct adapter *sc, struct t4_offload_policy *uop) 11794 { 11795 int i, rc, len; 11796 struct t4_offload_policy *op, *old; 11797 struct bpf_program *bf; 11798 const struct offload_settings *s; 11799 struct offload_rule *r; 11800 void *u; 11801 11802 if (!is_offload(sc)) 11803 return (ENODEV); 11804 11805 if (uop->nrules == 0) { 11806 /* Delete installed policies. */ 11807 op = NULL; 11808 goto set_policy; 11809 } else if (uop->nrules > 256) { /* arbitrary */ 11810 return (E2BIG); 11811 } 11812 11813 /* Copy userspace offload policy to kernel */ 11814 op = malloc(sizeof(*op), M_CXGBE, M_ZERO | M_WAITOK); 11815 op->nrules = uop->nrules; 11816 len = op->nrules * sizeof(struct offload_rule); 11817 op->rule = malloc(len, M_CXGBE, M_ZERO | M_WAITOK); 11818 rc = copyin(uop->rule, op->rule, len); 11819 if (rc) { 11820 free(op->rule, M_CXGBE); 11821 free(op, M_CXGBE); 11822 return (rc); 11823 } 11824 11825 r = &op->rule[0]; 11826 for (i = 0; i < op->nrules; i++, r++) { 11827 11828 /* Validate open_type */ 11829 if (r->open_type != OPEN_TYPE_LISTEN && 11830 r->open_type != OPEN_TYPE_ACTIVE && 11831 r->open_type != OPEN_TYPE_PASSIVE && 11832 r->open_type != OPEN_TYPE_DONTCARE) { 11833 error: 11834 /* 11835 * Rules 0 to i have malloc'd filters that need to be 11836 * freed. Rules i+1 to nrules have userspace pointers 11837 * and should be left alone. 11838 */ 11839 op->nrules = i; 11840 free_offload_policy(op); 11841 return (rc); 11842 } 11843 11844 /* Validate settings */ 11845 s = &r->settings; 11846 if ((s->offload != 0 && s->offload != 1) || 11847 s->cong_algo < -1 || s->cong_algo > CONG_ALG_HIGHSPEED || 11848 s->sched_class < -1 || 11849 s->sched_class >= sc->params.nsched_cls) { 11850 rc = EINVAL; 11851 goto error; 11852 } 11853 11854 bf = &r->bpf_prog; 11855 u = bf->bf_insns; /* userspace ptr */ 11856 bf->bf_insns = NULL; 11857 if (bf->bf_len == 0) { 11858 /* legal, matches everything */ 11859 continue; 11860 } 11861 len = bf->bf_len * sizeof(*bf->bf_insns); 11862 bf->bf_insns = malloc(len, M_CXGBE, M_ZERO | M_WAITOK); 11863 rc = copyin(u, bf->bf_insns, len); 11864 if (rc != 0) 11865 goto error; 11866 11867 if (!bpf_validate(bf->bf_insns, bf->bf_len)) { 11868 rc = EINVAL; 11869 goto error; 11870 } 11871 } 11872 set_policy: 11873 rw_wlock(&sc->policy_lock); 11874 old = sc->policy; 11875 sc->policy = op; 11876 rw_wunlock(&sc->policy_lock); 11877 free_offload_policy(old); 11878 11879 return (0); 11880 } 11881 11882 #define MAX_READ_BUF_SIZE (128 * 1024) 11883 static int 11884 read_card_mem(struct adapter *sc, int win, struct t4_mem_range *mr) 11885 { 11886 uint32_t addr, remaining, n; 11887 uint32_t *buf; 11888 int rc; 11889 uint8_t *dst; 11890 11891 mtx_lock(&sc->reg_lock); 11892 if (hw_off_limits(sc)) 11893 rc = ENXIO; 11894 else 11895 rc = validate_mem_range(sc, mr->addr, mr->len); 11896 mtx_unlock(&sc->reg_lock); 11897 if (rc != 0) 11898 return (rc); 11899 11900 buf = malloc(min(mr->len, MAX_READ_BUF_SIZE), M_CXGBE, M_WAITOK); 11901 addr = mr->addr; 11902 remaining = mr->len; 11903 dst = (void *)mr->data; 11904 11905 while (remaining) { 11906 n = min(remaining, MAX_READ_BUF_SIZE); 11907 mtx_lock(&sc->reg_lock); 11908 if (hw_off_limits(sc)) 11909 rc = ENXIO; 11910 else 11911 read_via_memwin(sc, 2, addr, buf, n); 11912 mtx_unlock(&sc->reg_lock); 11913 if (rc != 0) 11914 break; 11915 11916 rc = copyout(buf, dst, n); 11917 if (rc != 0) 11918 break; 11919 11920 dst += n; 11921 remaining -= n; 11922 addr += n; 11923 } 11924 11925 free(buf, M_CXGBE); 11926 return (rc); 11927 } 11928 #undef MAX_READ_BUF_SIZE 11929 11930 static int 11931 read_i2c(struct adapter *sc, struct t4_i2c_data *i2cd) 11932 { 11933 int rc; 11934 11935 if (i2cd->len == 0 || i2cd->port_id >= sc->params.nports) 11936 return (EINVAL); 11937 11938 if (i2cd->len > sizeof(i2cd->data)) 11939 return (EFBIG); 11940 11941 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4i2crd"); 11942 if (rc) 11943 return (rc); 11944 if (hw_off_limits(sc)) 11945 rc = ENXIO; 11946 else 11947 rc = -t4_i2c_rd(sc, sc->mbox, i2cd->port_id, i2cd->dev_addr, 11948 i2cd->offset, i2cd->len, &i2cd->data[0]); 11949 end_synchronized_op(sc, 0); 11950 11951 return (rc); 11952 } 11953 11954 static int 11955 clear_stats(struct adapter *sc, u_int port_id) 11956 { 11957 int i, v, chan_map; 11958 struct port_info *pi; 11959 struct vi_info *vi; 11960 struct sge_rxq *rxq; 11961 struct sge_txq *txq; 11962 struct sge_wrq *wrq; 11963 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 11964 struct sge_ofld_txq *ofld_txq; 11965 #endif 11966 #ifdef TCP_OFFLOAD 11967 struct sge_ofld_rxq *ofld_rxq; 11968 #endif 11969 11970 if (port_id >= sc->params.nports) 11971 return (EINVAL); 11972 pi = sc->port[port_id]; 11973 if (pi == NULL) 11974 return (EIO); 11975 11976 mtx_lock(&sc->reg_lock); 11977 if (!hw_off_limits(sc)) { 11978 /* MAC stats */ 11979 t4_clr_port_stats(sc, pi->tx_chan); 11980 if (is_t6(sc)) { 11981 if (pi->fcs_reg != -1) 11982 pi->fcs_base = t4_read_reg64(sc, pi->fcs_reg); 11983 else 11984 pi->stats.rx_fcs_err = 0; 11985 } 11986 for_each_vi(pi, v, vi) { 11987 if (vi->flags & VI_INIT_DONE) 11988 t4_clr_vi_stats(sc, vi->vin); 11989 } 11990 chan_map = pi->rx_e_chan_map; 11991 v = 0; /* reuse */ 11992 while (chan_map) { 11993 i = ffs(chan_map) - 1; 11994 t4_write_indirect(sc, A_TP_MIB_INDEX, A_TP_MIB_DATA, &v, 11995 1, A_TP_MIB_TNL_CNG_DROP_0 + i); 11996 chan_map &= ~(1 << i); 11997 } 11998 } 11999 mtx_unlock(&sc->reg_lock); 12000 pi->tx_parse_error = 0; 12001 pi->tnl_cong_drops = 0; 12002 12003 /* 12004 * Since this command accepts a port, clear stats for 12005 * all VIs on this port. 12006 */ 12007 for_each_vi(pi, v, vi) { 12008 if (vi->flags & VI_INIT_DONE) { 12009 12010 for_each_rxq(vi, i, rxq) { 12011 #if defined(INET) || defined(INET6) 12012 rxq->lro.lro_queued = 0; 12013 rxq->lro.lro_flushed = 0; 12014 #endif 12015 rxq->rxcsum = 0; 12016 rxq->vlan_extraction = 0; 12017 rxq->vxlan_rxcsum = 0; 12018 12019 rxq->fl.cl_allocated = 0; 12020 rxq->fl.cl_recycled = 0; 12021 rxq->fl.cl_fast_recycled = 0; 12022 } 12023 12024 for_each_txq(vi, i, txq) { 12025 txq->txcsum = 0; 12026 txq->tso_wrs = 0; 12027 txq->vlan_insertion = 0; 12028 txq->imm_wrs = 0; 12029 txq->sgl_wrs = 0; 12030 txq->txpkt_wrs = 0; 12031 txq->txpkts0_wrs = 0; 12032 txq->txpkts1_wrs = 0; 12033 txq->txpkts0_pkts = 0; 12034 txq->txpkts1_pkts = 0; 12035 txq->txpkts_flush = 0; 12036 txq->raw_wrs = 0; 12037 txq->vxlan_tso_wrs = 0; 12038 txq->vxlan_txcsum = 0; 12039 txq->kern_tls_records = 0; 12040 txq->kern_tls_short = 0; 12041 txq->kern_tls_partial = 0; 12042 txq->kern_tls_full = 0; 12043 txq->kern_tls_octets = 0; 12044 txq->kern_tls_waste = 0; 12045 txq->kern_tls_options = 0; 12046 txq->kern_tls_header = 0; 12047 txq->kern_tls_fin = 0; 12048 txq->kern_tls_fin_short = 0; 12049 txq->kern_tls_cbc = 0; 12050 txq->kern_tls_gcm = 0; 12051 mp_ring_reset_stats(txq->r); 12052 } 12053 12054 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 12055 for_each_ofld_txq(vi, i, ofld_txq) { 12056 ofld_txq->wrq.tx_wrs_direct = 0; 12057 ofld_txq->wrq.tx_wrs_copied = 0; 12058 counter_u64_zero(ofld_txq->tx_iscsi_pdus); 12059 counter_u64_zero(ofld_txq->tx_iscsi_octets); 12060 counter_u64_zero(ofld_txq->tx_iscsi_iso_wrs); 12061 counter_u64_zero(ofld_txq->tx_aio_jobs); 12062 counter_u64_zero(ofld_txq->tx_aio_octets); 12063 counter_u64_zero(ofld_txq->tx_toe_tls_records); 12064 counter_u64_zero(ofld_txq->tx_toe_tls_octets); 12065 } 12066 #endif 12067 #ifdef TCP_OFFLOAD 12068 for_each_ofld_rxq(vi, i, ofld_rxq) { 12069 ofld_rxq->fl.cl_allocated = 0; 12070 ofld_rxq->fl.cl_recycled = 0; 12071 ofld_rxq->fl.cl_fast_recycled = 0; 12072 counter_u64_zero( 12073 ofld_rxq->rx_iscsi_ddp_setup_ok); 12074 counter_u64_zero( 12075 ofld_rxq->rx_iscsi_ddp_setup_error); 12076 ofld_rxq->rx_iscsi_ddp_pdus = 0; 12077 ofld_rxq->rx_iscsi_ddp_octets = 0; 12078 ofld_rxq->rx_iscsi_fl_pdus = 0; 12079 ofld_rxq->rx_iscsi_fl_octets = 0; 12080 ofld_rxq->rx_aio_ddp_jobs = 0; 12081 ofld_rxq->rx_aio_ddp_octets = 0; 12082 ofld_rxq->rx_toe_tls_records = 0; 12083 ofld_rxq->rx_toe_tls_octets = 0; 12084 ofld_rxq->rx_toe_ddp_octets = 0; 12085 counter_u64_zero(ofld_rxq->ddp_buffer_alloc); 12086 counter_u64_zero(ofld_rxq->ddp_buffer_reuse); 12087 counter_u64_zero(ofld_rxq->ddp_buffer_free); 12088 } 12089 #endif 12090 12091 if (IS_MAIN_VI(vi)) { 12092 wrq = &sc->sge.ctrlq[pi->port_id]; 12093 wrq->tx_wrs_direct = 0; 12094 wrq->tx_wrs_copied = 0; 12095 } 12096 } 12097 } 12098 12099 return (0); 12100 } 12101 12102 static int 12103 hold_clip_addr(struct adapter *sc, struct t4_clip_addr *ca) 12104 { 12105 #ifdef INET6 12106 struct in6_addr in6; 12107 12108 bcopy(&ca->addr[0], &in6.s6_addr[0], sizeof(in6.s6_addr)); 12109 if (t4_get_clip_entry(sc, &in6, true) != NULL) 12110 return (0); 12111 else 12112 return (EIO); 12113 #else 12114 return (ENOTSUP); 12115 #endif 12116 } 12117 12118 static int 12119 release_clip_addr(struct adapter *sc, struct t4_clip_addr *ca) 12120 { 12121 #ifdef INET6 12122 struct in6_addr in6; 12123 12124 bcopy(&ca->addr[0], &in6.s6_addr[0], sizeof(in6.s6_addr)); 12125 return (t4_release_clip_addr(sc, &in6)); 12126 #else 12127 return (ENOTSUP); 12128 #endif 12129 } 12130 12131 int 12132 t4_os_find_pci_capability(struct adapter *sc, int cap) 12133 { 12134 int i; 12135 12136 return (pci_find_cap(sc->dev, cap, &i) == 0 ? i : 0); 12137 } 12138 12139 int 12140 t4_os_pci_save_state(struct adapter *sc) 12141 { 12142 device_t dev; 12143 struct pci_devinfo *dinfo; 12144 12145 dev = sc->dev; 12146 dinfo = device_get_ivars(dev); 12147 12148 pci_cfg_save(dev, dinfo, 0); 12149 return (0); 12150 } 12151 12152 int 12153 t4_os_pci_restore_state(struct adapter *sc) 12154 { 12155 device_t dev; 12156 struct pci_devinfo *dinfo; 12157 12158 dev = sc->dev; 12159 dinfo = device_get_ivars(dev); 12160 12161 pci_cfg_restore(dev, dinfo); 12162 return (0); 12163 } 12164 12165 void 12166 t4_os_portmod_changed(struct port_info *pi) 12167 { 12168 struct adapter *sc = pi->adapter; 12169 struct vi_info *vi; 12170 if_t ifp; 12171 static const char *mod_str[] = { 12172 NULL, "LR", "SR", "ER", "TWINAX", "active TWINAX", "LRM" 12173 }; 12174 12175 KASSERT((pi->flags & FIXED_IFMEDIA) == 0, 12176 ("%s: port_type %u", __func__, pi->port_type)); 12177 12178 vi = &pi->vi[0]; 12179 if (begin_synchronized_op(sc, vi, HOLD_LOCK, "t4mod") == 0) { 12180 PORT_LOCK(pi); 12181 build_medialist(pi); 12182 if (pi->mod_type != FW_PORT_MOD_TYPE_NONE) { 12183 fixup_link_config(pi); 12184 apply_link_config(pi); 12185 } 12186 PORT_UNLOCK(pi); 12187 end_synchronized_op(sc, LOCK_HELD); 12188 } 12189 12190 ifp = vi->ifp; 12191 if (pi->mod_type == FW_PORT_MOD_TYPE_NONE) 12192 if_printf(ifp, "transceiver unplugged.\n"); 12193 else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN) 12194 if_printf(ifp, "unknown transceiver inserted.\n"); 12195 else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED) 12196 if_printf(ifp, "unsupported transceiver inserted.\n"); 12197 else if (pi->mod_type > 0 && pi->mod_type < nitems(mod_str)) { 12198 if_printf(ifp, "%dGbps %s transceiver inserted.\n", 12199 port_top_speed(pi), mod_str[pi->mod_type]); 12200 } else { 12201 if_printf(ifp, "transceiver (type %d) inserted.\n", 12202 pi->mod_type); 12203 } 12204 } 12205 12206 void 12207 t4_os_link_changed(struct port_info *pi) 12208 { 12209 struct vi_info *vi; 12210 if_t ifp; 12211 struct link_config *lc = &pi->link_cfg; 12212 struct adapter *sc = pi->adapter; 12213 int v; 12214 12215 PORT_LOCK_ASSERT_OWNED(pi); 12216 12217 if (is_t6(sc)) { 12218 if (lc->link_ok) { 12219 if (lc->speed > 25000 || 12220 (lc->speed == 25000 && lc->fec == FEC_RS)) { 12221 pi->fcs_reg = T5_PORT_REG(pi->tx_chan, 12222 A_MAC_PORT_AFRAMECHECKSEQUENCEERRORS); 12223 } else { 12224 pi->fcs_reg = T5_PORT_REG(pi->tx_chan, 12225 A_MAC_PORT_MTIP_1G10G_RX_CRCERRORS); 12226 } 12227 pi->fcs_base = t4_read_reg64(sc, pi->fcs_reg); 12228 pi->stats.rx_fcs_err = 0; 12229 } else { 12230 pi->fcs_reg = -1; 12231 } 12232 } else { 12233 MPASS(pi->fcs_reg != -1); 12234 MPASS(pi->fcs_base == 0); 12235 } 12236 12237 for_each_vi(pi, v, vi) { 12238 ifp = vi->ifp; 12239 if (ifp == NULL) 12240 continue; 12241 12242 if (lc->link_ok) { 12243 if_setbaudrate(ifp, IF_Mbps(lc->speed)); 12244 if_link_state_change(ifp, LINK_STATE_UP); 12245 } else { 12246 if_link_state_change(ifp, LINK_STATE_DOWN); 12247 } 12248 } 12249 } 12250 12251 void 12252 t4_iterate(void (*func)(struct adapter *, void *), void *arg) 12253 { 12254 struct adapter *sc; 12255 12256 sx_slock(&t4_list_lock); 12257 SLIST_FOREACH(sc, &t4_list, link) { 12258 /* 12259 * func should not make any assumptions about what state sc is 12260 * in - the only guarantee is that sc->sc_lock is a valid lock. 12261 */ 12262 func(sc, arg); 12263 } 12264 sx_sunlock(&t4_list_lock); 12265 } 12266 12267 static int 12268 t4_ioctl(struct cdev *dev, unsigned long cmd, caddr_t data, int fflag, 12269 struct thread *td) 12270 { 12271 int rc; 12272 struct adapter *sc = dev->si_drv1; 12273 12274 rc = priv_check(td, PRIV_DRIVER); 12275 if (rc != 0) 12276 return (rc); 12277 12278 switch (cmd) { 12279 case CHELSIO_T4_GETREG: { 12280 struct t4_reg *edata = (struct t4_reg *)data; 12281 12282 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len) 12283 return (EFAULT); 12284 12285 mtx_lock(&sc->reg_lock); 12286 if (hw_off_limits(sc)) 12287 rc = ENXIO; 12288 else if (edata->size == 4) 12289 edata->val = t4_read_reg(sc, edata->addr); 12290 else if (edata->size == 8) 12291 edata->val = t4_read_reg64(sc, edata->addr); 12292 else 12293 rc = EINVAL; 12294 mtx_unlock(&sc->reg_lock); 12295 12296 break; 12297 } 12298 case CHELSIO_T4_SETREG: { 12299 struct t4_reg *edata = (struct t4_reg *)data; 12300 12301 if ((edata->addr & 0x3) != 0 || edata->addr >= sc->mmio_len) 12302 return (EFAULT); 12303 12304 mtx_lock(&sc->reg_lock); 12305 if (hw_off_limits(sc)) 12306 rc = ENXIO; 12307 else if (edata->size == 4) { 12308 if (edata->val & 0xffffffff00000000) 12309 rc = EINVAL; 12310 t4_write_reg(sc, edata->addr, (uint32_t) edata->val); 12311 } else if (edata->size == 8) 12312 t4_write_reg64(sc, edata->addr, edata->val); 12313 else 12314 rc = EINVAL; 12315 mtx_unlock(&sc->reg_lock); 12316 12317 break; 12318 } 12319 case CHELSIO_T4_REGDUMP: { 12320 struct t4_regdump *regs = (struct t4_regdump *)data; 12321 int reglen = t4_get_regs_len(sc); 12322 uint8_t *buf; 12323 12324 if (regs->len < reglen) { 12325 regs->len = reglen; /* hint to the caller */ 12326 return (ENOBUFS); 12327 } 12328 12329 regs->len = reglen; 12330 buf = malloc(reglen, M_CXGBE, M_WAITOK | M_ZERO); 12331 mtx_lock(&sc->reg_lock); 12332 if (hw_off_limits(sc)) 12333 rc = ENXIO; 12334 else 12335 get_regs(sc, regs, buf); 12336 mtx_unlock(&sc->reg_lock); 12337 if (rc == 0) 12338 rc = copyout(buf, regs->data, reglen); 12339 free(buf, M_CXGBE); 12340 break; 12341 } 12342 case CHELSIO_T4_GET_FILTER_MODE: 12343 rc = get_filter_mode(sc, (uint32_t *)data); 12344 break; 12345 case CHELSIO_T4_SET_FILTER_MODE: 12346 rc = set_filter_mode(sc, *(uint32_t *)data); 12347 break; 12348 case CHELSIO_T4_SET_FILTER_MASK: 12349 rc = set_filter_mask(sc, *(uint32_t *)data); 12350 break; 12351 case CHELSIO_T4_GET_FILTER: 12352 rc = get_filter(sc, (struct t4_filter *)data); 12353 break; 12354 case CHELSIO_T4_SET_FILTER: 12355 rc = set_filter(sc, (struct t4_filter *)data); 12356 break; 12357 case CHELSIO_T4_DEL_FILTER: 12358 rc = del_filter(sc, (struct t4_filter *)data); 12359 break; 12360 case CHELSIO_T4_GET_SGE_CONTEXT: 12361 rc = get_sge_context(sc, (struct t4_sge_context *)data); 12362 break; 12363 case CHELSIO_T4_LOAD_FW: 12364 rc = load_fw(sc, (struct t4_data *)data); 12365 break; 12366 case CHELSIO_T4_GET_MEM: 12367 rc = read_card_mem(sc, 2, (struct t4_mem_range *)data); 12368 break; 12369 case CHELSIO_T4_GET_I2C: 12370 rc = read_i2c(sc, (struct t4_i2c_data *)data); 12371 break; 12372 case CHELSIO_T4_CLEAR_STATS: 12373 rc = clear_stats(sc, *(uint32_t *)data); 12374 break; 12375 case CHELSIO_T4_SCHED_CLASS: 12376 rc = t4_set_sched_class(sc, (struct t4_sched_params *)data); 12377 break; 12378 case CHELSIO_T4_SCHED_QUEUE: 12379 rc = t4_set_sched_queue(sc, (struct t4_sched_queue *)data); 12380 break; 12381 case CHELSIO_T4_GET_TRACER: 12382 rc = t4_get_tracer(sc, (struct t4_tracer *)data); 12383 break; 12384 case CHELSIO_T4_SET_TRACER: 12385 rc = t4_set_tracer(sc, (struct t4_tracer *)data); 12386 break; 12387 case CHELSIO_T4_LOAD_CFG: 12388 rc = load_cfg(sc, (struct t4_data *)data); 12389 break; 12390 case CHELSIO_T4_LOAD_BOOT: 12391 rc = load_boot(sc, (struct t4_bootrom *)data); 12392 break; 12393 case CHELSIO_T4_LOAD_BOOTCFG: 12394 rc = load_bootcfg(sc, (struct t4_data *)data); 12395 break; 12396 case CHELSIO_T4_CUDBG_DUMP: 12397 rc = cudbg_dump(sc, (struct t4_cudbg_dump *)data); 12398 break; 12399 case CHELSIO_T4_SET_OFLD_POLICY: 12400 rc = set_offload_policy(sc, (struct t4_offload_policy *)data); 12401 break; 12402 case CHELSIO_T4_HOLD_CLIP_ADDR: 12403 rc = hold_clip_addr(sc, (struct t4_clip_addr *)data); 12404 break; 12405 case CHELSIO_T4_RELEASE_CLIP_ADDR: 12406 rc = release_clip_addr(sc, (struct t4_clip_addr *)data); 12407 break; 12408 default: 12409 rc = ENOTTY; 12410 } 12411 12412 return (rc); 12413 } 12414 12415 #ifdef TCP_OFFLOAD 12416 static int 12417 toe_capability(struct vi_info *vi, bool enable) 12418 { 12419 int rc; 12420 struct port_info *pi = vi->pi; 12421 struct adapter *sc = pi->adapter; 12422 12423 ASSERT_SYNCHRONIZED_OP(sc); 12424 12425 if (!is_offload(sc)) 12426 return (ENODEV); 12427 if (hw_off_limits(sc)) 12428 return (ENXIO); 12429 12430 if (enable) { 12431 #ifdef KERN_TLS 12432 if (sc->flags & KERN_TLS_ON && is_t6(sc)) { 12433 int i, j, n; 12434 struct port_info *p; 12435 struct vi_info *v; 12436 12437 /* 12438 * Reconfigure hardware for TOE if TXTLS is not enabled 12439 * on any ifnet. 12440 */ 12441 n = 0; 12442 for_each_port(sc, i) { 12443 p = sc->port[i]; 12444 for_each_vi(p, j, v) { 12445 if (if_getcapenable(v->ifp) & IFCAP_TXTLS) { 12446 CH_WARN(sc, 12447 "%s has NIC TLS enabled.\n", 12448 device_get_nameunit(v->dev)); 12449 n++; 12450 } 12451 } 12452 } 12453 if (n > 0) { 12454 CH_WARN(sc, "Disable NIC TLS on all interfaces " 12455 "associated with this adapter before " 12456 "trying to enable TOE.\n"); 12457 return (EAGAIN); 12458 } 12459 rc = t6_config_kern_tls(sc, false); 12460 if (rc) 12461 return (rc); 12462 } 12463 #endif 12464 if ((if_getcapenable(vi->ifp) & IFCAP_TOE) != 0) { 12465 /* TOE is already enabled. */ 12466 return (0); 12467 } 12468 12469 /* 12470 * We need the port's queues around so that we're able to send 12471 * and receive CPLs to/from the TOE even if the ifnet for this 12472 * port has never been UP'd administratively. 12473 */ 12474 if (!(vi->flags & VI_INIT_DONE) && ((rc = vi_init(vi)) != 0)) 12475 return (rc); 12476 if (!(pi->vi[0].flags & VI_INIT_DONE) && 12477 ((rc = vi_init(&pi->vi[0])) != 0)) 12478 return (rc); 12479 12480 if (isset(&sc->offload_map, pi->port_id)) { 12481 /* TOE is enabled on another VI of this port. */ 12482 pi->uld_vis++; 12483 return (0); 12484 } 12485 12486 if (!uld_active(sc, ULD_TOM)) { 12487 rc = t4_activate_uld(sc, ULD_TOM); 12488 if (rc == EAGAIN) { 12489 log(LOG_WARNING, 12490 "You must kldload t4_tom.ko before trying " 12491 "to enable TOE on a cxgbe interface.\n"); 12492 } 12493 if (rc != 0) 12494 return (rc); 12495 KASSERT(sc->tom_softc != NULL, 12496 ("%s: TOM activated but softc NULL", __func__)); 12497 KASSERT(uld_active(sc, ULD_TOM), 12498 ("%s: TOM activated but flag not set", __func__)); 12499 } 12500 12501 /* Activate iWARP and iSCSI too, if the modules are loaded. */ 12502 if (!uld_active(sc, ULD_IWARP)) 12503 (void) t4_activate_uld(sc, ULD_IWARP); 12504 if (!uld_active(sc, ULD_ISCSI)) 12505 (void) t4_activate_uld(sc, ULD_ISCSI); 12506 12507 pi->uld_vis++; 12508 setbit(&sc->offload_map, pi->port_id); 12509 } else { 12510 pi->uld_vis--; 12511 12512 if (!isset(&sc->offload_map, pi->port_id) || pi->uld_vis > 0) 12513 return (0); 12514 12515 KASSERT(uld_active(sc, ULD_TOM), 12516 ("%s: TOM never initialized?", __func__)); 12517 clrbit(&sc->offload_map, pi->port_id); 12518 } 12519 12520 return (0); 12521 } 12522 12523 /* 12524 * Add an upper layer driver to the global list. 12525 */ 12526 int 12527 t4_register_uld(struct uld_info *ui) 12528 { 12529 int rc = 0; 12530 struct uld_info *u; 12531 12532 sx_xlock(&t4_uld_list_lock); 12533 SLIST_FOREACH(u, &t4_uld_list, link) { 12534 if (u->uld_id == ui->uld_id) { 12535 rc = EEXIST; 12536 goto done; 12537 } 12538 } 12539 12540 SLIST_INSERT_HEAD(&t4_uld_list, ui, link); 12541 ui->refcount = 0; 12542 done: 12543 sx_xunlock(&t4_uld_list_lock); 12544 return (rc); 12545 } 12546 12547 int 12548 t4_unregister_uld(struct uld_info *ui) 12549 { 12550 int rc = EINVAL; 12551 struct uld_info *u; 12552 12553 sx_xlock(&t4_uld_list_lock); 12554 12555 SLIST_FOREACH(u, &t4_uld_list, link) { 12556 if (u == ui) { 12557 if (ui->refcount > 0) { 12558 rc = EBUSY; 12559 goto done; 12560 } 12561 12562 SLIST_REMOVE(&t4_uld_list, ui, uld_info, link); 12563 rc = 0; 12564 goto done; 12565 } 12566 } 12567 done: 12568 sx_xunlock(&t4_uld_list_lock); 12569 return (rc); 12570 } 12571 12572 int 12573 t4_activate_uld(struct adapter *sc, int id) 12574 { 12575 int rc; 12576 struct uld_info *ui; 12577 12578 ASSERT_SYNCHRONIZED_OP(sc); 12579 12580 if (id < 0 || id > ULD_MAX) 12581 return (EINVAL); 12582 rc = EAGAIN; /* kldoad the module with this ULD and try again. */ 12583 12584 sx_slock(&t4_uld_list_lock); 12585 12586 SLIST_FOREACH(ui, &t4_uld_list, link) { 12587 if (ui->uld_id == id) { 12588 if (!(sc->flags & FULL_INIT_DONE)) { 12589 rc = adapter_init(sc); 12590 if (rc != 0) 12591 break; 12592 } 12593 12594 rc = ui->activate(sc); 12595 if (rc == 0) { 12596 setbit(&sc->active_ulds, id); 12597 ui->refcount++; 12598 } 12599 break; 12600 } 12601 } 12602 12603 sx_sunlock(&t4_uld_list_lock); 12604 12605 return (rc); 12606 } 12607 12608 int 12609 t4_deactivate_uld(struct adapter *sc, int id) 12610 { 12611 int rc; 12612 struct uld_info *ui; 12613 12614 ASSERT_SYNCHRONIZED_OP(sc); 12615 12616 if (id < 0 || id > ULD_MAX) 12617 return (EINVAL); 12618 rc = ENXIO; 12619 12620 sx_slock(&t4_uld_list_lock); 12621 12622 SLIST_FOREACH(ui, &t4_uld_list, link) { 12623 if (ui->uld_id == id) { 12624 rc = ui->deactivate(sc); 12625 if (rc == 0) { 12626 clrbit(&sc->active_ulds, id); 12627 ui->refcount--; 12628 } 12629 break; 12630 } 12631 } 12632 12633 sx_sunlock(&t4_uld_list_lock); 12634 12635 return (rc); 12636 } 12637 12638 static int 12639 t4_deactivate_all_uld(struct adapter *sc) 12640 { 12641 int rc; 12642 struct uld_info *ui; 12643 12644 rc = begin_synchronized_op(sc, NULL, SLEEP_OK, "t4detuld"); 12645 if (rc != 0) 12646 return (ENXIO); 12647 12648 sx_slock(&t4_uld_list_lock); 12649 12650 SLIST_FOREACH(ui, &t4_uld_list, link) { 12651 if (isset(&sc->active_ulds, ui->uld_id)) { 12652 rc = ui->deactivate(sc); 12653 if (rc != 0) 12654 break; 12655 clrbit(&sc->active_ulds, ui->uld_id); 12656 ui->refcount--; 12657 } 12658 } 12659 12660 sx_sunlock(&t4_uld_list_lock); 12661 end_synchronized_op(sc, 0); 12662 12663 return (rc); 12664 } 12665 12666 static void 12667 t4_async_event(struct adapter *sc) 12668 { 12669 struct uld_info *ui; 12670 12671 if (begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4async") != 0) 12672 return; 12673 sx_slock(&t4_uld_list_lock); 12674 SLIST_FOREACH(ui, &t4_uld_list, link) { 12675 if (ui->uld_id == ULD_IWARP) { 12676 ui->async_event(sc); 12677 break; 12678 } 12679 } 12680 sx_sunlock(&t4_uld_list_lock); 12681 end_synchronized_op(sc, 0); 12682 } 12683 12684 int 12685 uld_active(struct adapter *sc, int uld_id) 12686 { 12687 12688 MPASS(uld_id >= 0 && uld_id <= ULD_MAX); 12689 12690 return (isset(&sc->active_ulds, uld_id)); 12691 } 12692 #endif 12693 12694 #ifdef KERN_TLS 12695 static int 12696 ktls_capability(struct adapter *sc, bool enable) 12697 { 12698 ASSERT_SYNCHRONIZED_OP(sc); 12699 12700 if (!is_ktls(sc)) 12701 return (ENODEV); 12702 if (!is_t6(sc)) 12703 return (0); 12704 if (hw_off_limits(sc)) 12705 return (ENXIO); 12706 12707 if (enable) { 12708 if (sc->flags & KERN_TLS_ON) 12709 return (0); /* already on */ 12710 if (sc->offload_map != 0) { 12711 CH_WARN(sc, 12712 "Disable TOE on all interfaces associated with " 12713 "this adapter before trying to enable NIC TLS.\n"); 12714 return (EAGAIN); 12715 } 12716 return (t6_config_kern_tls(sc, true)); 12717 } else { 12718 /* 12719 * Nothing to do for disable. If TOE is enabled sometime later 12720 * then toe_capability will reconfigure the hardware. 12721 */ 12722 return (0); 12723 } 12724 } 12725 #endif 12726 12727 /* 12728 * t = ptr to tunable. 12729 * nc = number of CPUs. 12730 * c = compiled in default for that tunable. 12731 */ 12732 static void 12733 calculate_nqueues(int *t, int nc, const int c) 12734 { 12735 int nq; 12736 12737 if (*t > 0) 12738 return; 12739 nq = *t < 0 ? -*t : c; 12740 *t = min(nc, nq); 12741 } 12742 12743 /* 12744 * Come up with reasonable defaults for some of the tunables, provided they're 12745 * not set by the user (in which case we'll use the values as is). 12746 */ 12747 static void 12748 tweak_tunables(void) 12749 { 12750 int nc = mp_ncpus; /* our snapshot of the number of CPUs */ 12751 12752 if (t4_ntxq < 1) { 12753 #ifdef RSS 12754 t4_ntxq = rss_getnumbuckets(); 12755 #else 12756 calculate_nqueues(&t4_ntxq, nc, NTXQ); 12757 #endif 12758 } 12759 12760 calculate_nqueues(&t4_ntxq_vi, nc, NTXQ_VI); 12761 12762 if (t4_nrxq < 1) { 12763 #ifdef RSS 12764 t4_nrxq = rss_getnumbuckets(); 12765 #else 12766 calculate_nqueues(&t4_nrxq, nc, NRXQ); 12767 #endif 12768 } 12769 12770 calculate_nqueues(&t4_nrxq_vi, nc, NRXQ_VI); 12771 12772 #if defined(TCP_OFFLOAD) || defined(RATELIMIT) 12773 calculate_nqueues(&t4_nofldtxq, nc, NOFLDTXQ); 12774 calculate_nqueues(&t4_nofldtxq_vi, nc, NOFLDTXQ_VI); 12775 #endif 12776 #ifdef TCP_OFFLOAD 12777 calculate_nqueues(&t4_nofldrxq, nc, NOFLDRXQ); 12778 calculate_nqueues(&t4_nofldrxq_vi, nc, NOFLDRXQ_VI); 12779 #endif 12780 12781 #if defined(TCP_OFFLOAD) || defined(KERN_TLS) 12782 if (t4_toecaps_allowed == -1) 12783 t4_toecaps_allowed = FW_CAPS_CONFIG_TOE; 12784 #else 12785 if (t4_toecaps_allowed == -1) 12786 t4_toecaps_allowed = 0; 12787 #endif 12788 12789 #ifdef TCP_OFFLOAD 12790 if (t4_rdmacaps_allowed == -1) { 12791 t4_rdmacaps_allowed = FW_CAPS_CONFIG_RDMA_RDDP | 12792 FW_CAPS_CONFIG_RDMA_RDMAC; 12793 } 12794 12795 if (t4_iscsicaps_allowed == -1) { 12796 t4_iscsicaps_allowed = FW_CAPS_CONFIG_ISCSI_INITIATOR_PDU | 12797 FW_CAPS_CONFIG_ISCSI_TARGET_PDU | 12798 FW_CAPS_CONFIG_ISCSI_T10DIF; 12799 } 12800 12801 if (t4_tmr_idx_ofld < 0 || t4_tmr_idx_ofld >= SGE_NTIMERS) 12802 t4_tmr_idx_ofld = TMR_IDX_OFLD; 12803 12804 if (t4_pktc_idx_ofld < -1 || t4_pktc_idx_ofld >= SGE_NCOUNTERS) 12805 t4_pktc_idx_ofld = PKTC_IDX_OFLD; 12806 #else 12807 if (t4_rdmacaps_allowed == -1) 12808 t4_rdmacaps_allowed = 0; 12809 12810 if (t4_iscsicaps_allowed == -1) 12811 t4_iscsicaps_allowed = 0; 12812 #endif 12813 12814 #ifdef DEV_NETMAP 12815 calculate_nqueues(&t4_nnmtxq, nc, NNMTXQ); 12816 calculate_nqueues(&t4_nnmrxq, nc, NNMRXQ); 12817 calculate_nqueues(&t4_nnmtxq_vi, nc, NNMTXQ_VI); 12818 calculate_nqueues(&t4_nnmrxq_vi, nc, NNMRXQ_VI); 12819 #endif 12820 12821 if (t4_tmr_idx < 0 || t4_tmr_idx >= SGE_NTIMERS) 12822 t4_tmr_idx = TMR_IDX; 12823 12824 if (t4_pktc_idx < -1 || t4_pktc_idx >= SGE_NCOUNTERS) 12825 t4_pktc_idx = PKTC_IDX; 12826 12827 if (t4_qsize_txq < 128) 12828 t4_qsize_txq = 128; 12829 12830 if (t4_qsize_rxq < 128) 12831 t4_qsize_rxq = 128; 12832 while (t4_qsize_rxq & 7) 12833 t4_qsize_rxq++; 12834 12835 t4_intr_types &= INTR_MSIX | INTR_MSI | INTR_INTX; 12836 12837 /* 12838 * Number of VIs to create per-port. The first VI is the "main" regular 12839 * VI for the port. The rest are additional virtual interfaces on the 12840 * same physical port. Note that the main VI does not have native 12841 * netmap support but the extra VIs do. 12842 * 12843 * Limit the number of VIs per port to the number of available 12844 * MAC addresses per port. 12845 */ 12846 if (t4_num_vis < 1) 12847 t4_num_vis = 1; 12848 if (t4_num_vis > nitems(vi_mac_funcs)) { 12849 t4_num_vis = nitems(vi_mac_funcs); 12850 printf("cxgbe: number of VIs limited to %d\n", t4_num_vis); 12851 } 12852 12853 if (pcie_relaxed_ordering < 0 || pcie_relaxed_ordering > 2) { 12854 pcie_relaxed_ordering = 1; 12855 #if defined(__i386__) || defined(__amd64__) 12856 if (cpu_vendor_id == CPU_VENDOR_INTEL) 12857 pcie_relaxed_ordering = 0; 12858 #endif 12859 } 12860 } 12861 12862 #ifdef DDB 12863 static void 12864 t4_dump_tcb(struct adapter *sc, int tid) 12865 { 12866 uint32_t base, i, j, off, pf, reg, save, tcb_addr, win_pos; 12867 12868 reg = PCIE_MEM_ACCESS_REG(A_PCIE_MEM_ACCESS_OFFSET, 2); 12869 save = t4_read_reg(sc, reg); 12870 base = sc->memwin[2].mw_base; 12871 12872 /* Dump TCB for the tid */ 12873 tcb_addr = t4_read_reg(sc, A_TP_CMM_TCB_BASE); 12874 tcb_addr += tid * TCB_SIZE; 12875 12876 if (is_t4(sc)) { 12877 pf = 0; 12878 win_pos = tcb_addr & ~0xf; /* start must be 16B aligned */ 12879 } else { 12880 pf = V_PFNUM(sc->pf); 12881 win_pos = tcb_addr & ~0x7f; /* start must be 128B aligned */ 12882 } 12883 t4_write_reg(sc, reg, win_pos | pf); 12884 t4_read_reg(sc, reg); 12885 12886 off = tcb_addr - win_pos; 12887 for (i = 0; i < 4; i++) { 12888 uint32_t buf[8]; 12889 for (j = 0; j < 8; j++, off += 4) 12890 buf[j] = htonl(t4_read_reg(sc, base + off)); 12891 12892 db_printf("%08x %08x %08x %08x %08x %08x %08x %08x\n", 12893 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], 12894 buf[7]); 12895 } 12896 12897 t4_write_reg(sc, reg, save); 12898 t4_read_reg(sc, reg); 12899 } 12900 12901 static void 12902 t4_dump_devlog(struct adapter *sc) 12903 { 12904 struct devlog_params *dparams = &sc->params.devlog; 12905 struct fw_devlog_e e; 12906 int i, first, j, m, nentries, rc; 12907 uint64_t ftstamp = UINT64_MAX; 12908 12909 if (dparams->start == 0) { 12910 db_printf("devlog params not valid\n"); 12911 return; 12912 } 12913 12914 nentries = dparams->size / sizeof(struct fw_devlog_e); 12915 m = fwmtype_to_hwmtype(dparams->memtype); 12916 12917 /* Find the first entry. */ 12918 first = -1; 12919 for (i = 0; i < nentries && !db_pager_quit; i++) { 12920 rc = -t4_mem_read(sc, m, dparams->start + i * sizeof(e), 12921 sizeof(e), (void *)&e); 12922 if (rc != 0) 12923 break; 12924 12925 if (e.timestamp == 0) 12926 break; 12927 12928 e.timestamp = be64toh(e.timestamp); 12929 if (e.timestamp < ftstamp) { 12930 ftstamp = e.timestamp; 12931 first = i; 12932 } 12933 } 12934 12935 if (first == -1) 12936 return; 12937 12938 i = first; 12939 do { 12940 rc = -t4_mem_read(sc, m, dparams->start + i * sizeof(e), 12941 sizeof(e), (void *)&e); 12942 if (rc != 0) 12943 return; 12944 12945 if (e.timestamp == 0) 12946 return; 12947 12948 e.timestamp = be64toh(e.timestamp); 12949 e.seqno = be32toh(e.seqno); 12950 for (j = 0; j < 8; j++) 12951 e.params[j] = be32toh(e.params[j]); 12952 12953 db_printf("%10d %15ju %8s %8s ", 12954 e.seqno, e.timestamp, 12955 (e.level < nitems(devlog_level_strings) ? 12956 devlog_level_strings[e.level] : "UNKNOWN"), 12957 (e.facility < nitems(devlog_facility_strings) ? 12958 devlog_facility_strings[e.facility] : "UNKNOWN")); 12959 db_printf(e.fmt, e.params[0], e.params[1], e.params[2], 12960 e.params[3], e.params[4], e.params[5], e.params[6], 12961 e.params[7]); 12962 12963 if (++i == nentries) 12964 i = 0; 12965 } while (i != first && !db_pager_quit); 12966 } 12967 12968 static DB_DEFINE_TABLE(show, t4, show_t4); 12969 12970 DB_TABLE_COMMAND_FLAGS(show_t4, devlog, db_show_devlog, CS_OWN) 12971 { 12972 device_t dev; 12973 int t; 12974 bool valid; 12975 12976 valid = false; 12977 t = db_read_token(); 12978 if (t == tIDENT) { 12979 dev = device_lookup_by_name(db_tok_string); 12980 valid = true; 12981 } 12982 db_skip_to_eol(); 12983 if (!valid) { 12984 db_printf("usage: show t4 devlog <nexus>\n"); 12985 return; 12986 } 12987 12988 if (dev == NULL) { 12989 db_printf("device not found\n"); 12990 return; 12991 } 12992 12993 t4_dump_devlog(device_get_softc(dev)); 12994 } 12995 12996 DB_TABLE_COMMAND_FLAGS(show_t4, tcb, db_show_t4tcb, CS_OWN) 12997 { 12998 device_t dev; 12999 int radix, tid, t; 13000 bool valid; 13001 13002 valid = false; 13003 radix = db_radix; 13004 db_radix = 10; 13005 t = db_read_token(); 13006 if (t == tIDENT) { 13007 dev = device_lookup_by_name(db_tok_string); 13008 t = db_read_token(); 13009 if (t == tNUMBER) { 13010 tid = db_tok_number; 13011 valid = true; 13012 } 13013 } 13014 db_radix = radix; 13015 db_skip_to_eol(); 13016 if (!valid) { 13017 db_printf("usage: show t4 tcb <nexus> <tid>\n"); 13018 return; 13019 } 13020 13021 if (dev == NULL) { 13022 db_printf("device not found\n"); 13023 return; 13024 } 13025 if (tid < 0) { 13026 db_printf("invalid tid\n"); 13027 return; 13028 } 13029 13030 t4_dump_tcb(device_get_softc(dev), tid); 13031 } 13032 #endif 13033 13034 static eventhandler_tag vxlan_start_evtag; 13035 static eventhandler_tag vxlan_stop_evtag; 13036 13037 struct vxlan_evargs { 13038 if_t ifp; 13039 uint16_t port; 13040 }; 13041 13042 static void 13043 enable_vxlan_rx(struct adapter *sc) 13044 { 13045 int i, rc; 13046 struct port_info *pi; 13047 uint8_t match_all_mac[ETHER_ADDR_LEN] = {0}; 13048 13049 ASSERT_SYNCHRONIZED_OP(sc); 13050 13051 t4_write_reg(sc, A_MPS_RX_VXLAN_TYPE, V_VXLAN(sc->vxlan_port) | 13052 F_VXLAN_EN); 13053 for_each_port(sc, i) { 13054 pi = sc->port[i]; 13055 if (pi->vxlan_tcam_entry == true) 13056 continue; 13057 rc = t4_alloc_raw_mac_filt(sc, pi->vi[0].viid, match_all_mac, 13058 match_all_mac, sc->rawf_base + pi->port_id, 1, pi->port_id, 13059 true); 13060 if (rc < 0) { 13061 rc = -rc; 13062 CH_ERR(&pi->vi[0], 13063 "failed to add VXLAN TCAM entry: %d.\n", rc); 13064 } else { 13065 MPASS(rc == sc->rawf_base + pi->port_id); 13066 pi->vxlan_tcam_entry = true; 13067 } 13068 } 13069 } 13070 13071 static void 13072 t4_vxlan_start(struct adapter *sc, void *arg) 13073 { 13074 struct vxlan_evargs *v = arg; 13075 13076 if (sc->nrawf == 0 || chip_id(sc) <= CHELSIO_T5) 13077 return; 13078 if (begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4vxst") != 0) 13079 return; 13080 13081 if (sc->vxlan_refcount == 0) { 13082 sc->vxlan_port = v->port; 13083 sc->vxlan_refcount = 1; 13084 if (!hw_off_limits(sc)) 13085 enable_vxlan_rx(sc); 13086 } else if (sc->vxlan_port == v->port) { 13087 sc->vxlan_refcount++; 13088 } else { 13089 CH_ERR(sc, "VXLAN already configured on port %d; " 13090 "ignoring attempt to configure it on port %d\n", 13091 sc->vxlan_port, v->port); 13092 } 13093 end_synchronized_op(sc, 0); 13094 } 13095 13096 static void 13097 t4_vxlan_stop(struct adapter *sc, void *arg) 13098 { 13099 struct vxlan_evargs *v = arg; 13100 13101 if (sc->nrawf == 0 || chip_id(sc) <= CHELSIO_T5) 13102 return; 13103 if (begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4vxsp") != 0) 13104 return; 13105 13106 /* 13107 * VXLANs may have been configured before the driver was loaded so we 13108 * may see more stops than starts. This is not handled cleanly but at 13109 * least we keep the refcount sane. 13110 */ 13111 if (sc->vxlan_port != v->port) 13112 goto done; 13113 if (sc->vxlan_refcount == 0) { 13114 CH_ERR(sc, "VXLAN operation on port %d was stopped earlier; " 13115 "ignoring attempt to stop it again.\n", sc->vxlan_port); 13116 } else if (--sc->vxlan_refcount == 0 && !hw_off_limits(sc)) 13117 t4_set_reg_field(sc, A_MPS_RX_VXLAN_TYPE, F_VXLAN_EN, 0); 13118 done: 13119 end_synchronized_op(sc, 0); 13120 } 13121 13122 static void 13123 t4_vxlan_start_handler(void *arg __unused, if_t ifp, 13124 sa_family_t family, u_int port) 13125 { 13126 struct vxlan_evargs v; 13127 13128 MPASS(family == AF_INET || family == AF_INET6); 13129 v.ifp = ifp; 13130 v.port = port; 13131 13132 t4_iterate(t4_vxlan_start, &v); 13133 } 13134 13135 static void 13136 t4_vxlan_stop_handler(void *arg __unused, if_t ifp, sa_family_t family, 13137 u_int port) 13138 { 13139 struct vxlan_evargs v; 13140 13141 MPASS(family == AF_INET || family == AF_INET6); 13142 v.ifp = ifp; 13143 v.port = port; 13144 13145 t4_iterate(t4_vxlan_stop, &v); 13146 } 13147 13148 13149 static struct sx mlu; /* mod load unload */ 13150 SX_SYSINIT(cxgbe_mlu, &mlu, "cxgbe mod load/unload"); 13151 13152 static int 13153 mod_event(module_t mod, int cmd, void *arg) 13154 { 13155 int rc = 0; 13156 static int loaded = 0; 13157 13158 switch (cmd) { 13159 case MOD_LOAD: 13160 sx_xlock(&mlu); 13161 if (loaded++ == 0) { 13162 t4_sge_modload(); 13163 t4_register_shared_cpl_handler(CPL_SET_TCB_RPL, 13164 t4_filter_rpl, CPL_COOKIE_FILTER); 13165 t4_register_shared_cpl_handler(CPL_L2T_WRITE_RPL, 13166 do_l2t_write_rpl, CPL_COOKIE_FILTER); 13167 t4_register_shared_cpl_handler(CPL_ACT_OPEN_RPL, 13168 t4_hashfilter_ao_rpl, CPL_COOKIE_HASHFILTER); 13169 t4_register_shared_cpl_handler(CPL_SET_TCB_RPL, 13170 t4_hashfilter_tcb_rpl, CPL_COOKIE_HASHFILTER); 13171 t4_register_shared_cpl_handler(CPL_ABORT_RPL_RSS, 13172 t4_del_hashfilter_rpl, CPL_COOKIE_HASHFILTER); 13173 t4_register_cpl_handler(CPL_TRACE_PKT, t4_trace_pkt); 13174 t4_register_cpl_handler(CPL_T5_TRACE_PKT, t5_trace_pkt); 13175 t4_register_cpl_handler(CPL_SMT_WRITE_RPL, 13176 do_smt_write_rpl); 13177 sx_init(&t4_list_lock, "T4/T5 adapters"); 13178 SLIST_INIT(&t4_list); 13179 callout_init(&fatal_callout, 1); 13180 #ifdef TCP_OFFLOAD 13181 sx_init(&t4_uld_list_lock, "T4/T5 ULDs"); 13182 SLIST_INIT(&t4_uld_list); 13183 #endif 13184 #ifdef INET6 13185 t4_clip_modload(); 13186 #endif 13187 #ifdef KERN_TLS 13188 t6_ktls_modload(); 13189 #endif 13190 t4_tracer_modload(); 13191 tweak_tunables(); 13192 vxlan_start_evtag = 13193 EVENTHANDLER_REGISTER(vxlan_start, 13194 t4_vxlan_start_handler, NULL, 13195 EVENTHANDLER_PRI_ANY); 13196 vxlan_stop_evtag = 13197 EVENTHANDLER_REGISTER(vxlan_stop, 13198 t4_vxlan_stop_handler, NULL, 13199 EVENTHANDLER_PRI_ANY); 13200 reset_tq = taskqueue_create("t4_rst_tq", M_WAITOK, 13201 taskqueue_thread_enqueue, &reset_tq); 13202 taskqueue_start_threads(&reset_tq, 1, PI_SOFT, 13203 "t4_rst_thr"); 13204 } 13205 sx_xunlock(&mlu); 13206 break; 13207 13208 case MOD_UNLOAD: 13209 sx_xlock(&mlu); 13210 if (--loaded == 0) { 13211 int tries; 13212 13213 taskqueue_free(reset_tq); 13214 sx_slock(&t4_list_lock); 13215 if (!SLIST_EMPTY(&t4_list)) { 13216 rc = EBUSY; 13217 sx_sunlock(&t4_list_lock); 13218 goto done_unload; 13219 } 13220 #ifdef TCP_OFFLOAD 13221 sx_slock(&t4_uld_list_lock); 13222 if (!SLIST_EMPTY(&t4_uld_list)) { 13223 rc = EBUSY; 13224 sx_sunlock(&t4_uld_list_lock); 13225 sx_sunlock(&t4_list_lock); 13226 goto done_unload; 13227 } 13228 #endif 13229 tries = 0; 13230 while (tries++ < 5 && t4_sge_extfree_refs() != 0) { 13231 uprintf("%ju clusters with custom free routine " 13232 "still is use.\n", t4_sge_extfree_refs()); 13233 pause("t4unload", 2 * hz); 13234 } 13235 #ifdef TCP_OFFLOAD 13236 sx_sunlock(&t4_uld_list_lock); 13237 #endif 13238 sx_sunlock(&t4_list_lock); 13239 13240 if (t4_sge_extfree_refs() == 0) { 13241 EVENTHANDLER_DEREGISTER(vxlan_start, 13242 vxlan_start_evtag); 13243 EVENTHANDLER_DEREGISTER(vxlan_stop, 13244 vxlan_stop_evtag); 13245 t4_tracer_modunload(); 13246 #ifdef KERN_TLS 13247 t6_ktls_modunload(); 13248 #endif 13249 #ifdef INET6 13250 t4_clip_modunload(); 13251 #endif 13252 #ifdef TCP_OFFLOAD 13253 sx_destroy(&t4_uld_list_lock); 13254 #endif 13255 sx_destroy(&t4_list_lock); 13256 t4_sge_modunload(); 13257 loaded = 0; 13258 } else { 13259 rc = EBUSY; 13260 loaded++; /* undo earlier decrement */ 13261 } 13262 } 13263 done_unload: 13264 sx_xunlock(&mlu); 13265 break; 13266 } 13267 13268 return (rc); 13269 } 13270 13271 DRIVER_MODULE(t4nex, pci, t4_driver, mod_event, 0); 13272 MODULE_VERSION(t4nex, 1); 13273 MODULE_DEPEND(t4nex, firmware, 1, 1, 1); 13274 #ifdef DEV_NETMAP 13275 MODULE_DEPEND(t4nex, netmap, 1, 1, 1); 13276 #endif /* DEV_NETMAP */ 13277 13278 DRIVER_MODULE(t5nex, pci, t5_driver, mod_event, 0); 13279 MODULE_VERSION(t5nex, 1); 13280 MODULE_DEPEND(t5nex, firmware, 1, 1, 1); 13281 #ifdef DEV_NETMAP 13282 MODULE_DEPEND(t5nex, netmap, 1, 1, 1); 13283 #endif /* DEV_NETMAP */ 13284 13285 DRIVER_MODULE(t6nex, pci, t6_driver, mod_event, 0); 13286 MODULE_VERSION(t6nex, 1); 13287 MODULE_DEPEND(t6nex, crypto, 1, 1, 1); 13288 MODULE_DEPEND(t6nex, firmware, 1, 1, 1); 13289 #ifdef DEV_NETMAP 13290 MODULE_DEPEND(t6nex, netmap, 1, 1, 1); 13291 #endif /* DEV_NETMAP */ 13292 13293 DRIVER_MODULE(cxgbe, t4nex, cxgbe_driver, 0, 0); 13294 MODULE_VERSION(cxgbe, 1); 13295 13296 DRIVER_MODULE(cxl, t5nex, cxl_driver, 0, 0); 13297 MODULE_VERSION(cxl, 1); 13298 13299 DRIVER_MODULE(cc, t6nex, cc_driver, 0, 0); 13300 MODULE_VERSION(cc, 1); 13301 13302 DRIVER_MODULE(vcxgbe, cxgbe, vcxgbe_driver, 0, 0); 13303 MODULE_VERSION(vcxgbe, 1); 13304 13305 DRIVER_MODULE(vcxl, cxl, vcxl_driver, 0, 0); 13306 MODULE_VERSION(vcxl, 1); 13307 13308 DRIVER_MODULE(vcc, cc, vcc_driver, 0, 0); 13309 MODULE_VERSION(vcc, 1); 13310