1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * This file is part of the Chelsio T4 support code. 14 * 15 * Copyright (C) 2011-2013 Chelsio Communications. All rights reserved. 16 * 17 * This program is distributed in the hope that it will be useful, but WITHOUT 18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 * FITNESS FOR A PARTICULAR PURPOSE. See the LICENSE file included in this 20 * release for licensing terms and conditions. 21 */ 22 23 /* 24 * Copyright 2024 Oxide Computer Company 25 */ 26 27 #ifndef __CXGBE_ADAPTER_H 28 #define __CXGBE_ADAPTER_H 29 30 #include <sys/ddi.h> 31 #include <sys/mac_provider.h> 32 #include <sys/ethernet.h> 33 #include <sys/queue.h> 34 #include <sys/containerof.h> 35 #include <sys/ddi_ufm.h> 36 37 #include "offload.h" 38 #include "firmware/t4fw_interface.h" 39 #include "shared.h" 40 41 struct adapter; 42 typedef struct adapter adapter_t; 43 44 enum { 45 FW_IQ_QSIZE = 256, 46 FW_IQ_ESIZE = 64, /* At least 64 mandated by the firmware spec */ 47 48 RX_IQ_QSIZE = 1024, 49 RX_IQ_ESIZE = 64, /* At least 64 so CPL_RX_PKT will fit */ 50 51 EQ_ESIZE = 64, /* All egres queues use this entry size */ 52 53 RX_FL_ESIZE = 64, /* 8 64bit addresses */ 54 55 FL_BUF_SIZES = 4, 56 57 CTRL_EQ_QSIZE = 128, 58 59 TX_EQ_QSIZE = 1024, 60 TX_SGL_SEGS = 36, 61 TX_WR_FLITS = SGE_MAX_WR_LEN / 8 62 }; 63 64 enum { 65 /* adapter flags */ 66 FULL_INIT_DONE = (1 << 0), 67 FW_OK = (1 << 1), 68 INTR_FWD = (1 << 2), 69 INTR_ALLOCATED = (1 << 3), 70 MASTER_PF = (1 << 4), 71 72 CXGBE_BUSY = (1 << 9), 73 74 /* port flags */ 75 DOOMED = (1 << 0), 76 PORT_INIT_DONE = (1 << 1), 77 }; 78 79 enum { 80 /* Features */ 81 CXGBE_HW_LSO = (1 << 0), 82 CXGBE_HW_CSUM = (1 << 1), 83 }; 84 85 enum { 86 UDBS_SEG_SHIFT = 7, /* log2(UDBS_SEG_SIZE) */ 87 UDBS_DB_OFFSET = 8, /* offset of the 4B doorbell in a segment */ 88 UDBS_WR_OFFSET = 64, /* offset of the work request in a segment */ 89 }; 90 91 #define IS_DOOMED(pi) (pi->flags & DOOMED) 92 #define SET_DOOMED(pi) do { pi->flags |= DOOMED; } while (0) 93 #define IS_BUSY(sc) (sc->flags & CXGBE_BUSY) 94 #define SET_BUSY(sc) do { sc->flags |= CXGBE_BUSY; } while (0) 95 #define CLR_BUSY(sc) do { sc->flags &= ~CXGBE_BUSY; } while (0) 96 97 struct port_info { 98 dev_info_t *dip; 99 mac_handle_t mh; 100 mac_callbacks_t *mc; 101 void *props; 102 int mtu; 103 uint8_t hw_addr[ETHERADDRL]; 104 105 kmutex_t lock; 106 struct adapter *adapter; 107 108 unsigned int flags; 109 110 uint16_t viid; 111 int16_t xact_addr_filt; /* index of exact MAC address filter */ 112 uint16_t rss_size; /* size of VI's RSS table slice */ 113 uint16_t ntxq; /* # of tx queues */ 114 uint16_t first_txq; /* index of first tx queue */ 115 uint16_t nrxq; /* # of rx queues */ 116 uint16_t first_rxq; /* index of first rx queue */ 117 uint8_t lport; /* associated offload logical port */ 118 int8_t mdio_addr; 119 uint8_t port_type; 120 uint8_t mod_type; 121 uint8_t port_id; 122 uint8_t tx_chan; 123 uint8_t rx_chan; 124 uint8_t rx_cchan; 125 uint8_t instance; /* Associated adapter instance */ 126 uint8_t child_inst; /* Associated child instance */ 127 uint8_t tmr_idx; 128 int8_t pktc_idx; 129 struct link_config link_cfg; 130 struct port_stats stats; 131 uint32_t features; 132 uint8_t macaddr_cnt; 133 u8 rss_mode; 134 u16 viid_mirror; 135 kstat_t *ksp_config; 136 kstat_t *ksp_info; 137 kstat_t *ksp_fec; 138 139 u8 vivld; 140 u8 vin; 141 u8 smt_idx; 142 143 u8 vivld_mirror; 144 u8 vin_mirror; 145 u8 smt_idx_mirror; 146 }; 147 148 struct fl_sdesc { 149 struct rxbuf *rxb; 150 }; 151 152 struct tx_desc { 153 __be64 flit[8]; 154 }; 155 156 /* DMA maps used for tx */ 157 struct tx_maps { 158 ddi_dma_handle_t *map; 159 uint32_t map_total; /* # of DMA maps */ 160 uint32_t map_pidx; /* next map to be used */ 161 uint32_t map_cidx; /* reclaimed up to this index */ 162 uint32_t map_avail; /* # of available maps */ 163 }; 164 165 struct tx_sdesc { 166 mblk_t *m; 167 uint32_t txb_used; /* # of bytes of tx copy buffer used */ 168 uint16_t hdls_used; /* # of dma handles used */ 169 uint16_t desc_used; /* # of hardware descriptors used */ 170 }; 171 172 enum { 173 /* iq flags */ 174 IQ_ALLOCATED = (1 << 0), /* firmware resources allocated */ 175 IQ_INTR = (1 << 1), /* iq takes direct interrupt */ 176 IQ_HAS_FL = (1 << 2), /* iq has fl */ 177 178 /* iq state */ 179 IQS_DISABLED = 0, 180 IQS_BUSY = 1, 181 IQS_IDLE = 2, 182 }; 183 184 struct rxbuf_cache_params { 185 dev_info_t *dip; 186 ddi_dma_attr_t dma_attr_rx; 187 ddi_device_acc_attr_t acc_attr_rx; 188 size_t buf_size; 189 }; 190 191 /* 192 * Ingress Queue: T4 is producer, driver is consumer. 193 */ 194 struct sge_iq { 195 unsigned int flags; 196 ddi_dma_handle_t dhdl; 197 ddi_acc_handle_t ahdl; 198 199 volatile uint_t state; 200 __be64 *desc; /* KVA of descriptor ring */ 201 uint64_t ba; /* bus address of descriptor ring */ 202 const __be64 *cdesc; /* current descriptor */ 203 struct adapter *adapter; /* associated adapter */ 204 uint8_t gen; /* generation bit */ 205 uint8_t intr_params; /* interrupt holdoff parameters */ 206 int8_t intr_pktc_idx; /* packet count threshold index */ 207 uint8_t intr_next; /* holdoff for next interrupt */ 208 uint8_t esize; /* size (bytes) of each entry in the queue */ 209 uint16_t qsize; /* size (# of entries) of the queue */ 210 uint16_t cidx; /* consumer index */ 211 uint16_t pending; /* # of descs processed since last doorbell */ 212 uint16_t cntxt_id; /* SGE context id for the iq */ 213 uint16_t abs_id; /* absolute SGE id for the iq */ 214 kmutex_t lock; /* Rx access lock */ 215 uint8_t polling; 216 217 STAILQ_ENTRY(sge_iq) link; 218 }; 219 220 enum { 221 EQ_CTRL = 1, 222 EQ_ETH = 2, 223 224 /* eq flags */ 225 EQ_TYPEMASK = 7, /* 3 lsbits hold the type */ 226 EQ_ALLOCATED = (1 << 3), /* firmware resources allocated */ 227 EQ_DOOMED = (1 << 4), /* about to be destroyed */ 228 EQ_CRFLUSHED = (1 << 5), /* expecting an update from SGE */ 229 EQ_STALLED = (1 << 6), /* out of hw descriptors or dmamaps */ 230 EQ_MTX = (1 << 7), /* mutex has been initialized */ 231 EQ_STARTED = (1 << 8), /* started */ 232 }; 233 234 /* Listed in order of preference. Update t4_sysctls too if you change these */ 235 enum {DOORBELL_UDB=0x1 , DOORBELL_WCWR=0x2, DOORBELL_UDBWC=0x4, DOORBELL_KDB=0x8}; 236 237 /* 238 * Egress Queue: driver is producer, T4 is consumer. 239 * 240 * Note: A free list is an egress queue (driver produces the buffers and T4 241 * consumes them) but it's special enough to have its own struct (see sge_fl). 242 */ 243 struct sge_eq { 244 ddi_dma_handle_t desc_dhdl; 245 ddi_acc_handle_t desc_ahdl; 246 unsigned int flags; 247 kmutex_t lock; 248 249 struct tx_desc *desc; /* KVA of descriptor ring */ 250 uint64_t ba; /* bus address of descriptor ring */ 251 struct sge_qstat *spg; /* status page, for convenience */ 252 int doorbells; 253 volatile uint32_t *udb; /* KVA of doorbell (lies within BAR2) */ 254 u_int udb_qid; /* relative qid within the doorbell page */ 255 uint16_t cap; /* max # of desc, for convenience */ 256 uint16_t avail; /* available descriptors, for convenience */ 257 uint16_t qsize; /* size (# of entries) of the queue */ 258 uint16_t cidx; /* consumer idx (desc idx) */ 259 uint16_t pidx; /* producer idx (desc idx) */ 260 uint16_t pending; /* # of descriptors used since last doorbell */ 261 uint16_t iqid; /* iq that gets egr_update for the eq */ 262 uint8_t tx_chan; /* tx channel used by the eq */ 263 uint32_t cntxt_id; /* SGE context id for the eq */ 264 }; 265 266 enum { 267 /* fl flags */ 268 FL_MTX = (1 << 0), /* mutex has been initialized */ 269 FL_STARVING = (1 << 1), /* on the list of starving fl's */ 270 FL_DOOMED = (1 << 2), /* about to be destroyed */ 271 }; 272 273 #define FL_RUNNING_LOW(fl) (fl->cap - fl->needed <= fl->lowat) 274 #define FL_NOT_RUNNING_LOW(fl) (fl->cap - fl->needed >= 2 * fl->lowat) 275 276 struct sge_fl { 277 unsigned int flags; 278 kmutex_t lock; 279 ddi_dma_handle_t dhdl; 280 ddi_acc_handle_t ahdl; 281 282 __be64 *desc; /* KVA of descriptor ring, ptr to addresses */ 283 uint64_t ba; /* bus address of descriptor ring */ 284 struct fl_sdesc *sdesc; /* KVA of software descriptor ring */ 285 uint32_t cap; /* max # of buffers, for convenience */ 286 uint16_t qsize; /* size (# of entries) of the queue */ 287 uint16_t cntxt_id; /* SGE context id for the freelist */ 288 uint32_t cidx; /* consumer idx (buffer idx, NOT hw desc idx) */ 289 uint32_t pidx; /* producer idx (buffer idx, NOT hw desc idx) */ 290 uint32_t needed; /* # of buffers needed to fill up fl. */ 291 uint32_t lowat; /* # of buffers <= this means fl needs help */ 292 uint32_t pending; /* # of bufs allocated since last doorbell */ 293 uint32_t offset; /* current packet within the larger buffer */ 294 uint16_t copy_threshold; /* anything this size or less is copied up */ 295 296 uint64_t copied_up; /* # of frames copied into mblk and handed up */ 297 uint64_t passed_up; /* # of frames wrapped in mblk and handed up */ 298 uint64_t allocb_fail; /* # of mblk allocation failures */ 299 300 TAILQ_ENTRY(sge_fl) link; /* All starving freelists */ 301 }; 302 303 /* txq: SGE egress queue + miscellaneous items */ 304 struct sge_txq { 305 struct sge_eq eq; /* MUST be first */ 306 307 struct port_info *port; /* the port this txq belongs to */ 308 struct tx_sdesc *sdesc; /* KVA of software descriptor ring */ 309 mac_ring_handle_t ring_handle; 310 311 /* DMA handles used for tx */ 312 ddi_dma_handle_t *tx_dhdl; 313 uint32_t tx_dhdl_total; /* Total # of handles */ 314 uint32_t tx_dhdl_pidx; /* next handle to be used */ 315 uint32_t tx_dhdl_cidx; /* reclaimed up to this index */ 316 uint32_t tx_dhdl_avail; /* # of available handles */ 317 318 /* Copy buffers for tx */ 319 ddi_dma_handle_t txb_dhdl; 320 ddi_acc_handle_t txb_ahdl; 321 caddr_t txb_va; /* KVA of copy buffers area */ 322 uint64_t txb_ba; /* bus address of copy buffers area */ 323 uint32_t txb_size; /* total size */ 324 uint32_t txb_next; /* offset of next useable area in the buffer */ 325 uint32_t txb_avail; /* # of bytes available */ 326 uint16_t copy_threshold; /* anything this size or less is copied up */ 327 328 uint64_t txpkts; /* # of ethernet packets */ 329 uint64_t txbytes; /* # of ethernet bytes */ 330 kstat_t *ksp; 331 332 /* stats for common events first */ 333 334 uint64_t txcsum; /* # of times hardware assisted with checksum */ 335 uint64_t tso_wrs; /* # of IPv4 TSO work requests */ 336 uint64_t imm_wrs; /* # of work requests with immediate data */ 337 uint64_t sgl_wrs; /* # of work requests with direct SGL */ 338 uint64_t txpkt_wrs; /* # of txpkt work requests (not coalesced) */ 339 uint64_t txpkts_wrs; /* # of coalesced tx work requests */ 340 uint64_t txpkts_pkts; /* # of frames in coalesced tx work requests */ 341 uint64_t txb_used; /* # of tx copy buffers used (64 byte each) */ 342 uint64_t hdl_used; /* # of DMA handles used */ 343 344 /* stats for not-that-common events */ 345 346 uint32_t txb_full; /* txb ran out of space */ 347 uint32_t dma_hdl_failed; /* couldn't obtain DMA handle */ 348 uint32_t dma_map_failed; /* couldn't obtain DMA mapping */ 349 uint32_t qfull; /* out of hardware descriptors */ 350 uint32_t qflush; /* # of SGE_EGR_UPDATE notifications for txq */ 351 uint32_t pullup_early; /* # of pullups before starting frame's SGL */ 352 uint32_t pullup_late; /* # of pullups while building frame's SGL */ 353 uint32_t pullup_failed; /* # of failed pullups */ 354 uint32_t csum_failed; /* # of csum reqs we failed to fulfill */ 355 }; 356 357 /* rxq: SGE ingress queue + SGE free list + miscellaneous items */ 358 struct sge_rxq { 359 struct sge_iq iq; /* MUST be first */ 360 struct sge_fl fl; 361 362 struct port_info *port; /* the port this rxq belongs to */ 363 kstat_t *ksp; 364 365 mac_ring_handle_t ring_handle; 366 uint64_t ring_gen_num; 367 368 /* stats for common events first */ 369 370 uint64_t rxcsum; /* # of times hardware assisted with checksum */ 371 uint64_t rxpkts; /* # of ethernet packets */ 372 uint64_t rxbytes; /* # of ethernet bytes */ 373 374 /* stats for not-that-common events */ 375 376 uint32_t nomem; /* mblk allocation during rx failed */ 377 }; 378 379 struct sge { 380 int fl_starve_threshold; 381 int s_qpp; 382 383 int nrxq; /* total rx queues (all ports and the rest) */ 384 int ntxq; /* total tx queues (all ports and the rest) */ 385 int niq; /* total ingress queues */ 386 int neq; /* total egress queues */ 387 int stat_len; /* length of status page at ring end */ 388 int pktshift; /* padding between CPL & packet data */ 389 int fl_align; /* response queue message alignment */ 390 391 struct sge_iq fwq; /* Firmware event queue */ 392 struct sge_txq *txq; /* NIC tx queues */ 393 struct sge_rxq *rxq; /* NIC rx queues */ 394 395 int iq_start; /* iq context id map start index */ 396 int eq_start; /* eq context id map start index */ 397 int iqmap_sz; /* size of iq context id map */ 398 int eqmap_sz; /* size of eq context id map */ 399 struct sge_iq **iqmap; /* iq->cntxt_id to iq mapping */ 400 struct sge_eq **eqmap; /* eq->cntxt_id to eq mapping */ 401 402 /* Device access and DMA attributes for all the descriptor rings */ 403 ddi_device_acc_attr_t acc_attr_desc; 404 ddi_dma_attr_t dma_attr_desc; 405 406 /* Device access and DMA attributes for tx buffers */ 407 ddi_device_acc_attr_t acc_attr_tx; 408 ddi_dma_attr_t dma_attr_tx; 409 410 /* Device access and DMA attributes for rx buffers are in rxb_params */ 411 kmem_cache_t *rxbuf_cache; 412 struct rxbuf_cache_params rxb_params; 413 }; 414 415 struct driver_properties { 416 /* There is a driver.conf variable for each of these */ 417 int max_ntxq_10g; 418 int max_nrxq_10g; 419 int max_ntxq_1g; 420 int max_nrxq_1g; 421 int intr_types; 422 int tmr_idx_10g; 423 int pktc_idx_10g; 424 int tmr_idx_1g; 425 int pktc_idx_1g; 426 int qsize_txq; 427 int qsize_rxq; 428 429 int timer_val[SGE_NTIMERS]; 430 int counter_val[SGE_NCOUNTERS]; 431 432 int wc; 433 434 int multi_rings; 435 int t4_fw_install; 436 }; 437 438 struct rss_header; 439 typedef int (*cpl_handler_t)(struct sge_iq *, const struct rss_header *, 440 mblk_t *); 441 typedef int (*fw_msg_handler_t)(struct adapter *, const __be64 *); 442 443 struct t4_mbox_list { 444 STAILQ_ENTRY(t4_mbox_list) link; 445 }; 446 447 struct adapter { 448 SLIST_ENTRY(adapter) link; 449 dev_info_t *dip; 450 dev_t dev; 451 452 unsigned int pf; 453 unsigned int mbox; 454 455 unsigned int vpd_busy; 456 unsigned int vpd_flag; 457 458 u32 t4_bar0; 459 460 uint_t open; /* character device is open */ 461 462 /* PCI config space access handle */ 463 ddi_acc_handle_t pci_regh; 464 465 /* MMIO register access handle */ 466 ddi_acc_handle_t regh; 467 caddr_t regp; 468 /* BAR1 register access handle */ 469 ddi_acc_handle_t reg1h; 470 caddr_t reg1p; 471 472 /* Interrupt information */ 473 int intr_type; 474 int intr_count; 475 int intr_cap; 476 uint_t intr_pri; 477 ddi_intr_handle_t *intr_handle; 478 479 struct driver_properties props; 480 kstat_t *ksp; 481 kstat_t *ksp_stat; 482 483 struct sge sge; 484 485 struct port_info *port[MAX_NPORTS]; 486 ddi_taskq_t *tq[NCHAN]; 487 uint8_t chan_map[NCHAN]; 488 uint32_t filter_mode; 489 490 struct l2t_data *l2t; /* L2 table */ 491 struct tid_info tids; 492 493 int doorbells; 494 int registered_device_map; 495 int open_device_map; 496 int flags; 497 498 unsigned int cfcsum; 499 struct adapter_params params; 500 struct t4_virt_res vres; 501 502 uint16_t linkcaps; 503 uint16_t niccaps; 504 uint16_t toecaps; 505 uint16_t rdmacaps; 506 uint16_t iscsicaps; 507 uint16_t fcoecaps; 508 509 fw_msg_handler_t fw_msg_handler[5]; /* NUM_FW6_TYPES */ 510 cpl_handler_t cpl_handler[0xef]; /* NUM_CPL_CMDS */ 511 512 kmutex_t lock; 513 kcondvar_t cv; 514 515 /* Starving free lists */ 516 kmutex_t sfl_lock; /* same cache-line as sc_lock? but that's ok */ 517 TAILQ_HEAD(, sge_fl) sfl; 518 timeout_id_t sfl_timer; 519 520 /* Sensors */ 521 id_t temp_sensor; 522 id_t volt_sensor; 523 524 ddi_ufm_handle_t *ufm_hdl; 525 526 /* support for single-threading access to adapter mailbox registers */ 527 kmutex_t mbox_lock; 528 STAILQ_HEAD(, t4_mbox_list) mbox_list; 529 }; 530 531 enum { 532 NIC_H = 0, 533 TOM_H, 534 IW_H, 535 ISCSI_H 536 }; 537 538 struct memwin { 539 uint32_t base; 540 uint32_t aperture; 541 }; 542 543 #define ADAPTER_LOCK(sc) mutex_enter(&(sc)->lock) 544 #define ADAPTER_UNLOCK(sc) mutex_exit(&(sc)->lock) 545 #define ADAPTER_LOCK_ASSERT_OWNED(sc) ASSERT(mutex_owned(&(sc)->lock)) 546 #define ADAPTER_LOCK_ASSERT_NOTOWNED(sc) ASSERT(!mutex_owned(&(sc)->lock)) 547 548 #define PORT_LOCK(pi) mutex_enter(&(pi)->lock) 549 #define PORT_UNLOCK(pi) mutex_exit(&(pi)->lock) 550 #define PORT_LOCK_ASSERT_OWNED(pi) ASSERT(mutex_owned(&(pi)->lock)) 551 #define PORT_LOCK_ASSERT_NOTOWNED(pi) ASSERT(!mutex_owned(&(pi)->lock)) 552 553 #define IQ_LOCK(iq) mutex_enter(&(iq)->lock) 554 #define IQ_UNLOCK(iq) mutex_exit(&(iq)->lock) 555 #define IQ_LOCK_ASSERT_OWNED(iq) ASSERT(mutex_owned(&(iq)->lock)) 556 #define IQ_LOCK_ASSERT_NOTOWNED(iq) ASSERT(!mutex_owned(&(iq)->lock)) 557 558 #define FL_LOCK(fl) mutex_enter(&(fl)->lock) 559 #define FL_UNLOCK(fl) mutex_exit(&(fl)->lock) 560 #define FL_LOCK_ASSERT_OWNED(fl) ASSERT(mutex_owned(&(fl)->lock)) 561 #define FL_LOCK_ASSERT_NOTOWNED(fl) ASSERT(!mutex_owned(&(fl)->lock)) 562 563 #define RXQ_LOCK(rxq) IQ_LOCK(&(rxq)->iq) 564 #define RXQ_UNLOCK(rxq) IQ_UNLOCK(&(rxq)->iq) 565 #define RXQ_LOCK_ASSERT_OWNED(rxq) IQ_LOCK_ASSERT_OWNED(&(rxq)->iq) 566 #define RXQ_LOCK_ASSERT_NOTOWNED(rxq) IQ_LOCK_ASSERT_NOTOWNED(&(rxq)->iq) 567 568 #define RXQ_FL_LOCK(rxq) FL_LOCK(&(rxq)->fl) 569 #define RXQ_FL_UNLOCK(rxq) FL_UNLOCK(&(rxq)->fl) 570 #define RXQ_FL_LOCK_ASSERT_OWNED(rxq) FL_LOCK_ASSERT_OWNED(&(rxq)->fl) 571 #define RXQ_FL_LOCK_ASSERT_NOTOWNED(rxq) FL_LOCK_ASSERT_NOTOWNED(&(rxq)->fl) 572 573 #define EQ_LOCK(eq) mutex_enter(&(eq)->lock) 574 #define EQ_UNLOCK(eq) mutex_exit(&(eq)->lock) 575 #define EQ_LOCK_ASSERT_OWNED(eq) ASSERT(mutex_owned(&(eq)->lock)) 576 #define EQ_LOCK_ASSERT_NOTOWNED(eq) ASSERT(!mutex_owned(&(eq)->lock)) 577 578 #define TXQ_LOCK(txq) EQ_LOCK(&(txq)->eq) 579 #define TXQ_UNLOCK(txq) EQ_UNLOCK(&(txq)->eq) 580 #define TXQ_LOCK_ASSERT_OWNED(txq) EQ_LOCK_ASSERT_OWNED(&(txq)->eq) 581 #define TXQ_LOCK_ASSERT_NOTOWNED(txq) EQ_LOCK_ASSERT_NOTOWNED(&(txq)->eq) 582 583 #define for_each_txq(pi, iter, txq) \ 584 txq = &pi->adapter->sge.txq[pi->first_txq]; \ 585 for (iter = 0; iter < pi->ntxq; ++iter, ++txq) 586 #define for_each_rxq(pi, iter, rxq) \ 587 rxq = &pi->adapter->sge.rxq[pi->first_rxq]; \ 588 for (iter = 0; iter < pi->nrxq; ++iter, ++rxq) 589 #define for_each_ofld_txq(pi, iter, ofld_txq) \ 590 ofld_txq = &pi->adapter->sge.ofld_txq[pi->first_ofld_txq]; \ 591 for (iter = 0; iter < pi->nofldtxq; ++iter, ++ofld_txq) 592 #define for_each_ofld_rxq(pi, iter, ofld_rxq) \ 593 ofld_rxq = &pi->adapter->sge.ofld_rxq[pi->first_ofld_rxq]; \ 594 for (iter = 0; iter < pi->nofldrxq; ++iter, ++ofld_rxq) 595 596 #define NFIQ(sc) ((sc)->intr_count > 1 ? (sc)->intr_count - 1 : 1) 597 598 /* One for errors, one for firmware events */ 599 #define T4_EXTRA_INTR 2 600 601 static inline void t4_mbox_list_add(struct adapter *adap, 602 struct t4_mbox_list *entry) 603 { 604 mutex_enter(&adap->mbox_lock); 605 STAILQ_INSERT_TAIL(&adap->mbox_list, entry, link); 606 mutex_exit(&adap->mbox_lock); 607 } 608 609 static inline void t4_mbox_list_del(struct adapter *adap, 610 struct t4_mbox_list *entry) 611 { 612 mutex_enter(&adap->mbox_lock); 613 STAILQ_REMOVE(&adap->mbox_list, entry, t4_mbox_list, link); 614 mutex_exit(&adap->mbox_lock); 615 } 616 617 static inline struct t4_mbox_list * 618 t4_mbox_list_first_entry(struct adapter *adap) 619 { 620 return STAILQ_FIRST(&adap->mbox_list); 621 } 622 623 static inline uint32_t 624 t4_read_reg(struct adapter *sc, uint32_t reg) 625 { 626 /* LINTED: E_BAD_PTR_CAST_ALIGN */ 627 return (ddi_get32(sc->regh, (uint32_t *)(sc->regp + reg))); 628 } 629 630 static inline void 631 t4_write_reg(struct adapter *sc, uint32_t reg, uint32_t val) 632 { 633 /* LINTED: E_BAD_PTR_CAST_ALIGN */ 634 ddi_put32(sc->regh, (uint32_t *)(sc->regp + reg), val); 635 } 636 637 static inline void 638 t4_os_pci_read_cfg1(struct adapter *sc, int reg, uint8_t *val) 639 { 640 *val = pci_config_get8(sc->pci_regh, reg); 641 } 642 643 static inline void 644 t4_os_pci_write_cfg1(struct adapter *sc, int reg, uint8_t val) 645 { 646 pci_config_put8(sc->pci_regh, reg, val); 647 } 648 649 static inline void 650 t4_os_pci_read_cfg2(struct adapter *sc, int reg, uint16_t *val) 651 { 652 *val = pci_config_get16(sc->pci_regh, reg); 653 } 654 655 static inline void 656 t4_os_pci_write_cfg2(struct adapter *sc, int reg, uint16_t val) 657 { 658 pci_config_put16(sc->pci_regh, reg, val); 659 } 660 661 static inline void 662 t4_os_pci_read_cfg4(struct adapter *sc, int reg, uint32_t *val) 663 { 664 *val = pci_config_get32(sc->pci_regh, reg); 665 } 666 667 static inline void 668 t4_os_pci_write_cfg4(struct adapter *sc, int reg, uint32_t val) 669 { 670 pci_config_put32(sc->pci_regh, reg, val); 671 } 672 673 static inline uint32_t 674 t4_read_reg32(struct adapter *sc, uint32_t reg) 675 { 676 return (ddi_get32(sc->regh, (uint32_t *)(sc->regp + reg))); 677 } 678 679 static inline uint64_t 680 t4_read_reg64(struct adapter *sc, uint32_t reg) 681 { 682 return (ddi_get64(sc->regh, (uint64_t *)(sc->regp + reg))); 683 } 684 685 static inline void 686 t4_write_reg64(struct adapter *sc, uint32_t reg, uint64_t val) 687 { 688 ddi_put64(sc->regh, (uint64_t *)(sc->regp + reg), val); 689 } 690 691 static inline struct port_info * 692 adap2pinfo(struct adapter *sc, int idx) 693 { 694 return (sc->port[idx]); 695 } 696 697 static inline void 698 t4_os_set_hw_addr(struct adapter *sc, int idx, uint8_t hw_addr[]) 699 { 700 bcopy(hw_addr, sc->port[idx]->hw_addr, ETHERADDRL); 701 } 702 703 static inline bool 704 is_10G_port(const struct port_info *pi) 705 { 706 return ((pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_10G) != 0); 707 } 708 709 static inline struct sge_rxq * 710 iq_to_rxq(struct sge_iq *iq) 711 { 712 return (__containerof(iq, struct sge_rxq, iq)); 713 } 714 715 static inline bool 716 is_25G_port(const struct port_info *pi) 717 { 718 return ((pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_25G) != 0); 719 } 720 721 static inline bool 722 is_40G_port(const struct port_info *pi) 723 { 724 return ((pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_40G) != 0); 725 } 726 727 static inline bool 728 is_50G_port(const struct port_info *pi) 729 { 730 return ((pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_50G) != 0); 731 } 732 733 static inline bool 734 is_100G_port(const struct port_info *pi) 735 { 736 return ((pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100G) != 0); 737 } 738 739 static inline bool 740 is_10XG_port(const struct port_info *pi) 741 { 742 return (is_10G_port(pi) || is_40G_port(pi) || 743 is_25G_port(pi) || is_50G_port(pi) || 744 is_100G_port(pi)); 745 } 746 747 /** 748 * t4_os_pci_read_seeprom - read four bytes of SEEPROM/VPD contents 749 * @adapter: the adapter 750 * @addr: SEEPROM/VPD Address to read 751 * @valp: where to store the value read 752 * 753 * Read a 32-bit value from the given address in the SEEPROM/VPD. The address 754 * must be four-byte aligned. Returns 0 on success, a negative erro number 755 * on failure. 756 */ 757 static inline int t4_os_pci_read_seeprom(adapter_t *adapter, 758 int addr, u32 *valp) 759 { 760 int t4_seeprom_read(struct adapter *adapter, u32 addr, u32 *data); 761 int ret; 762 763 ret = t4_seeprom_read(adapter, addr, valp); 764 765 return ret >= 0 ? 0 : ret; 766 } 767 768 /** 769 * t4_os_pci_write_seeprom - write four bytes of SEEPROM/VPD contents 770 * @adapter: the adapter 771 * @addr: SEEPROM/VPD Address to write 772 * @val: the value write 773 * 774 * Write a 32-bit value to the given address in the SEEPROM/VPD. The address 775 * must be four-byte aligned. Returns 0 on success, a negative erro number 776 * on failure. 777 */ 778 static inline int t4_os_pci_write_seeprom(adapter_t *adapter, 779 int addr, u32 val) 780 { 781 int t4_seeprom_write(struct adapter *adapter, u32 addr, u32 data); 782 int ret; 783 784 ret = t4_seeprom_write(adapter, addr, val); 785 786 return ret >= 0 ? 0 : ret; 787 } 788 789 static inline int t4_os_pci_set_vpd_size(struct adapter *adapter, size_t len) 790 { 791 return 0; 792 } 793 794 static inline unsigned int t4_use_ldst(struct adapter *adap) 795 { 796 return (adap->flags & FW_OK); 797 } 798 799 static inline void t4_db_full(struct adapter *adap) {} 800 static inline void t4_db_dropped(struct adapter *adap) {} 801 802 /* t4_nexus.c */ 803 int t4_os_find_pci_capability(struct adapter *sc, int cap); 804 void t4_os_portmod_changed(struct adapter *sc, int idx); 805 int adapter_full_init(struct adapter *sc); 806 int adapter_full_uninit(struct adapter *sc); 807 int port_full_init(struct port_info *pi); 808 int port_full_uninit(struct port_info *pi); 809 void enable_port_queues(struct port_info *pi); 810 void disable_port_queues(struct port_info *pi); 811 int t4_register_cpl_handler(struct adapter *sc, int opcode, cpl_handler_t h); 812 int t4_register_fw_msg_handler(struct adapter *, int, fw_msg_handler_t); 813 void t4_iterate(void (*func)(int, void *), void *arg); 814 815 /* t4_sge.c */ 816 void t4_sge_init(struct adapter *sc); 817 int t4_setup_adapter_queues(struct adapter *sc); 818 int t4_teardown_adapter_queues(struct adapter *sc); 819 int t4_setup_port_queues(struct port_info *pi); 820 int t4_teardown_port_queues(struct port_info *pi); 821 uint_t t4_intr_all(caddr_t arg1, caddr_t arg2); 822 uint_t t4_intr(caddr_t arg1, caddr_t arg2); 823 uint_t t4_intr_err(caddr_t arg1, caddr_t arg2); 824 int t4_mgmt_tx(struct adapter *sc, mblk_t *m); 825 void memwin_info(struct adapter *, int, uint32_t *, uint32_t *); 826 uint32_t position_memwin(struct adapter *, int, uint32_t); 827 828 mblk_t *t4_eth_tx(void *, mblk_t *); 829 mblk_t *t4_mc_tx(void *arg, mblk_t *m); 830 mblk_t *t4_ring_rx(struct sge_rxq *rxq, int poll_bytes); 831 int t4_alloc_tx_maps(struct adapter *sc, struct tx_maps *txmaps, int count, 832 int flags); 833 834 /* t4_mac.c */ 835 void t4_mc_init(struct port_info *pi); 836 void t4_mc_cb_init(struct port_info *); 837 void t4_os_link_changed(struct adapter *sc, int idx, int link_stat); 838 void t4_mac_rx(struct port_info *pi, struct sge_rxq *rxq, mblk_t *m); 839 void t4_mac_tx_update(struct port_info *pi, struct sge_txq *txq); 840 int t4_addmac(void *arg, const uint8_t *ucaddr); 841 842 /* t4_ioctl.c */ 843 int t4_ioctl(struct adapter *sc, int cmd, void *data, int mode); 844 845 struct l2t_data *t4_init_l2t(struct adapter *sc); 846 int begin_synchronized_op(struct port_info *pi, int hold, int waitok); 847 void end_synchronized_op(struct port_info *pi, int held); 848 849 #define setbit(a, i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY)) 850 #define clrbit(a, i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) 851 #define isset(a, i) ((a)[(i)/NBBY] & (1<<((i)%NBBY))) 852 853 #endif /* __CXGBE_ADAPTER_H */ 854