2 * Copyright (c) 2011 Chelsio Communications, Inc.
4 * Written by: Navdeep Parhar <np@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #ifndef __T4_ADAPTER_H__
32 #define __T4_ADAPTER_H__
34 #include <sys/kernel.h>
37 #include <sys/types.h>
38 #include <sys/malloc.h>
39 #include <dev/pci/pcivar.h>
40 #include <dev/pci/pcireg.h>
41 #include <machine/bus.h>
42 #include <sys/socket.h>
43 #include <sys/sysctl.h>
44 #include <net/ethernet.h>
46 #include <net/if_media.h>
47 #include <netinet/in.h>
48 #include <netinet/tcp_lro.h>
51 #include "common/t4_msg.h"
52 #include "firmware/t4fw_interface.h"
54 #define KTR_CXGBE KTR_SPARE3
55 MALLOC_DECLARE(M_CXGBE);
56 #define CXGBE_UNIMPLEMENTED(s) \
57 panic("%s (%s, line %d) not implemented yet.", s, __FILE__, __LINE__)
59 #if defined(__i386__) || defined(__amd64__)
63 __asm volatile("prefetcht0 %0" :: "m" (*(unsigned long *)x));
69 #ifndef SYSCTL_ADD_UQUAD
70 #define SYSCTL_ADD_UQUAD SYSCTL_ADD_QUAD
71 #define sysctl_handle_64 sysctl_handle_quad
72 #define CTLTYPE_U64 CTLTYPE_QUAD
75 #if (__FreeBSD_version >= 900030) || \
76 ((__FreeBSD_version >= 802507) && (__FreeBSD_version < 900000))
81 /* XXX: need systemwide bus_space_read_8/bus_space_write_8 */
82 static __inline uint64_t
83 t4_bus_space_read_8(bus_space_tag_t tag, bus_space_handle_t handle,
86 KASSERT(tag == X86_BUS_SPACE_MEM,
87 ("%s: can only handle mem space", __func__));
89 return (*(volatile uint64_t *)(handle + offset));
93 t4_bus_space_write_8(bus_space_tag_t tag, bus_space_handle_t bsh,
94 bus_size_t offset, uint64_t value)
96 KASSERT(tag == X86_BUS_SPACE_MEM,
97 ("%s: can only handle mem space", __func__));
99 *(volatile uint64_t *)(bsh + offset) = value;
102 static __inline uint64_t
103 t4_bus_space_read_8(bus_space_tag_t tag, bus_space_handle_t handle,
106 return (uint64_t)bus_space_read_4(tag, handle, offset) +
107 ((uint64_t)bus_space_read_4(tag, handle, offset + 4) << 32);
111 t4_bus_space_write_8(bus_space_tag_t tag, bus_space_handle_t bsh,
112 bus_size_t offset, uint64_t value)
114 bus_space_write_4(tag, bsh, offset, value);
115 bus_space_write_4(tag, bsh, offset + 4, value >> 32);
120 typedef struct adapter adapter_t;
124 * All ingress queues use this entry size. Note that the firmware event
125 * queue and any iq expecting CPL_RX_PKT in the descriptor needs this to
130 /* Default queue sizes for all kinds of ingress queues */
134 /* All egress queues use this entry size */
137 /* Default queue sizes for all kinds of egress queues */
141 #if MJUMPAGESIZE != MCLBYTES
142 SW_ZONE_SIZES = 4, /* cluster, jumbop, jumbo9k, jumbo16k */
144 SW_ZONE_SIZES = 3, /* cluster, jumbo9k, jumbo16k */
146 CL_METADATA_SIZE = CACHE_LINE_SIZE,
148 SGE_MAX_WR_NDESC = SGE_MAX_WR_LEN / EQ_ESIZE, /* max WR size in desc */
150 TX_SGL_SEGS_TSO = 38,
151 TX_WR_FLITS = SGE_MAX_WR_LEN / 8
155 /* adapter intr_type */
156 INTR_INTX = (1 << 0),
162 XGMAC_MTU = (1 << 0),
163 XGMAC_PROMISC = (1 << 1),
164 XGMAC_ALLMULTI = (1 << 2),
165 XGMAC_VLANEX = (1 << 3),
166 XGMAC_UCADDR = (1 << 4),
167 XGMAC_MCADDRS = (1 << 5),
173 /* flags understood by begin_synchronized_op */
174 HOLD_LOCK = (1 << 0),
178 /* flags understood by end_synchronized_op */
179 LOCK_HELD = HOLD_LOCK,
184 FULL_INIT_DONE = (1 << 0),
186 /* INTR_DIRECT = (1 << 2), No longer used. */
187 MASTER_PF = (1 << 3),
188 ADAP_SYSCTL_CTX = (1 << 4),
189 /* TOM_INIT_DONE= (1 << 5), No longer used */
190 BUF_PACKING_OK = (1 << 6),
192 CXGBE_BUSY = (1 << 9),
196 PORT_INIT_DONE = (1 << 1),
197 PORT_SYSCTL_CTX = (1 << 2),
198 HAS_TRACEQ = (1 << 3),
199 INTR_RXQ = (1 << 4), /* All NIC rxq's take interrupts */
200 INTR_OFLD_RXQ = (1 << 5), /* All TOE rxq's take interrupts */
201 INTR_NM_RXQ = (1 << 6), /* All netmap rxq's take interrupts */
202 INTR_ALL = (INTR_RXQ | INTR_OFLD_RXQ | INTR_NM_RXQ),
205 #define IS_DOOMED(pi) ((pi)->flags & DOOMED)
206 #define SET_DOOMED(pi) do {(pi)->flags |= DOOMED;} while (0)
207 #define IS_BUSY(sc) ((sc)->flags & CXGBE_BUSY)
208 #define SET_BUSY(sc) do {(sc)->flags |= CXGBE_BUSY;} while (0)
209 #define CLR_BUSY(sc) do {(sc)->flags &= ~CXGBE_BUSY;} while (0)
213 struct adapter *adapter;
216 struct ifmedia media;
225 int16_t xact_addr_filt;/* index of exact MAC address filter */
226 uint16_t rss_size; /* size of VI's RSS table slice */
227 uint8_t lport; /* associated offload logical port */
233 uint8_t rx_chan_map; /* rx MPS channel bitmap */
235 /* These need to be int as they are used in sysctl */
236 int ntxq; /* # of tx queues */
237 int first_txq; /* index of first tx queue */
238 int rsrv_noflowq; /* Reserve queue 0 for non-flowid packets */
239 int nrxq; /* # of rx queues */
240 int first_rxq; /* index of first rx queue */
242 int nofldtxq; /* # of offload tx queues */
243 int first_ofld_txq; /* index of first offload tx queue */
244 int nofldrxq; /* # of offload rx queues */
245 int first_ofld_rxq; /* index of first offload rx queue */
248 int nnmtxq; /* # of netmap tx queues */
249 int first_nm_txq; /* index of first netmap tx queue */
250 int nnmrxq; /* # of netmap rx queues */
251 int first_nm_rxq; /* index of first netmap rx queue */
253 struct ifnet *nm_ifp;
254 struct ifmedia nm_media;
257 int16_t nm_xact_addr_filt;
258 uint16_t nm_rss_size; /* size of netmap VI's RSS table slice */
266 struct link_config link_cfg;
268 struct timeval last_refreshed;
269 struct port_stats stats;
270 u_int tx_parse_error;
272 eventhandler_tag vlan_c;
275 struct sysctl_ctx_list ctx; /* from ifconfig up to driver detach */
277 uint8_t hw_addr[ETHER_ADDR_LEN]; /* factory MAC address, won't change */
280 /* Where the cluster came from, how it has been carved up. */
281 struct cluster_layout {
284 uint16_t region1; /* mbufs laid out within this region */
285 /* region2 is the DMA region */
286 uint16_t region3; /* cluster_metadata within this region */
289 struct cluster_metadata {
292 struct fl_sdesc *sd; /* For debug only. Could easily be stale */
298 uint16_t nmbuf; /* # of driver originated mbufs with ref on cluster */
299 struct cluster_layout cll;
307 struct mbuf *m; /* m_nextpkt linked chain of frames */
308 uint8_t desc_used; /* # of hardware descriptors used by the WR */
312 #define IQ_PAD (IQ_ESIZE - sizeof(struct rsp_ctrl) - sizeof(struct rss_header))
314 struct rss_header rss;
319 CTASSERT(sizeof(struct iq_desc) == IQ_ESIZE);
323 IQ_ALLOCATED = (1 << 0), /* firmware resources allocated */
324 IQ_HAS_FL = (1 << 1), /* iq associated with a freelist */
325 IQ_INTR = (1 << 2), /* iq takes direct interrupt */
326 IQ_LRO_ENABLED = (1 << 3), /* iq is an eth rxq with LRO enabled */
335 * Ingress Queue: T4 is producer, driver is consumer.
340 struct adapter *adapter;
341 struct iq_desc *desc; /* KVA of descriptor ring */
342 int8_t intr_pktc_idx; /* packet count threshold index */
343 uint8_t gen; /* generation bit */
344 uint8_t intr_params; /* interrupt holdoff parameters */
345 uint8_t intr_next; /* XXX: holdoff for next interrupt */
346 uint16_t qsize; /* size (# of entries) of the queue */
347 uint16_t sidx; /* index of the entry with the status page */
348 uint16_t cidx; /* consumer index */
349 uint16_t cntxt_id; /* SGE context id for the iq */
350 uint16_t abs_id; /* absolute SGE id for the iq */
352 STAILQ_ENTRY(sge_iq) link;
354 bus_dma_tag_t desc_tag;
355 bus_dmamap_t desc_map;
356 bus_addr_t ba; /* bus address of descriptor ring */
365 EQ_TYPEMASK = 0x3, /* 2 lsbits hold the type (see above) */
366 EQ_ALLOCATED = (1 << 2), /* firmware resources allocated */
367 EQ_ENABLED = (1 << 3), /* open for business */
370 /* Listed in order of preference. Update t4_sysctls too if you change these */
371 enum {DOORBELL_UDB, DOORBELL_WCWR, DOORBELL_UDBWC, DOORBELL_KDB};
374 * Egress Queue: driver is producer, T4 is consumer.
376 * Note: A free list is an egress queue (driver produces the buffers and T4
377 * consumes them) but it's special enough to have its own struct (see sge_fl).
380 unsigned int flags; /* MUST be first */
381 unsigned int cntxt_id; /* SGE context id for the eq */
384 struct tx_desc *desc; /* KVA of descriptor ring */
386 volatile uint32_t *udb; /* KVA of doorbell (lies within BAR2) */
387 u_int udb_qid; /* relative qid within the doorbell page */
388 uint16_t sidx; /* index of the entry with the status page */
389 uint16_t cidx; /* consumer idx (desc idx) */
390 uint16_t pidx; /* producer idx (desc idx) */
391 uint16_t equeqidx; /* EQUEQ last requested at this pidx */
392 uint16_t dbidx; /* pidx of the most recent doorbell */
393 uint16_t iqid; /* iq that gets egr_update for the eq */
394 uint8_t tx_chan; /* tx channel used by the eq */
395 volatile u_int equiq; /* EQUIQ outstanding */
397 bus_dma_tag_t desc_tag;
398 bus_dmamap_t desc_map;
399 bus_addr_t ba; /* bus address of descriptor ring */
403 struct sw_zone_info {
404 uma_zone_t zone; /* zone that this cluster comes from */
405 int size; /* size of cluster: 2K, 4K, 9K, 16K, etc. */
406 int type; /* EXT_xxx type of the cluster */
412 int8_t zidx; /* backpointer to zone; -ve means unused */
413 int8_t next; /* next hwidx for this zone; -1 means no more */
418 FL_STARVING = (1 << 0), /* on the adapter's list of starving fl's */
419 FL_DOOMED = (1 << 1), /* about to be destroyed */
420 FL_BUF_PACKING = (1 << 2), /* buffer packing enabled */
421 FL_BUF_RESUME = (1 << 3), /* resume from the middle of the frame */
424 #define FL_RUNNING_LOW(fl) \
425 (IDXDIFF(fl->dbidx * 8, fl->cidx, fl->sidx * 8) <= fl->lowat)
426 #define FL_NOT_RUNNING_LOW(fl) \
427 (IDXDIFF(fl->dbidx * 8, fl->cidx, fl->sidx * 8) >= 2 * fl->lowat)
431 __be64 *desc; /* KVA of descriptor ring, ptr to addresses */
432 struct fl_sdesc *sdesc; /* KVA of software descriptor ring */
433 struct cluster_layout cll_def; /* default refill zone, layout */
434 uint16_t lowat; /* # of buffers <= this means fl needs help */
436 uint16_t buf_boundary;
438 /* The 16b idx all deal with hw descriptors */
439 uint16_t dbidx; /* hw pidx after last doorbell */
440 uint16_t sidx; /* index of status page */
441 volatile uint16_t hw_cidx;
443 /* The 32b idx are all buffer idx, not hardware descriptor idx */
444 uint32_t cidx; /* consumer index */
445 uint32_t pidx; /* producer index */
448 u_int rx_offset; /* offset in fl buf (when buffer packing) */
449 volatile uint32_t *udb;
451 uint64_t mbuf_allocated;/* # of mbuf allocated from zone_mbuf */
452 uint64_t mbuf_inlined; /* # of mbuf created within clusters */
453 uint64_t cl_allocated; /* # of clusters allocated */
454 uint64_t cl_recycled; /* # of clusters recycled */
455 uint64_t cl_fast_recycled; /* # of clusters recycled (fast) */
457 /* These 3 are valid when FL_BUF_RESUME is set, stale otherwise. */
462 uint16_t qsize; /* # of hw descriptors (status page included) */
463 uint16_t cntxt_id; /* SGE context id for the freelist */
464 TAILQ_ENTRY(sge_fl) link; /* All starving freelists */
465 bus_dma_tag_t desc_tag;
466 bus_dmamap_t desc_map;
468 bus_addr_t ba; /* bus address of descriptor ring */
469 struct cluster_layout cll_alt; /* alternate refill zone, layout */
474 /* txq: SGE egress queue + what's needed for Ethernet NIC */
476 struct sge_eq eq; /* MUST be first */
478 struct ifnet *ifp; /* the interface this txq belongs to */
479 struct mp_ring *r; /* tx software ring */
480 struct tx_sdesc *sdesc; /* KVA of software descriptor ring */
482 __be32 cpl_ctrl0; /* for convenience */
484 struct task tx_reclaim_task;
485 /* stats for common events first */
487 uint64_t txcsum; /* # of times hardware assisted with checksum */
488 uint64_t tso_wrs; /* # of TSO work requests */
489 uint64_t vlan_insertion;/* # of times VLAN tag was inserted */
490 uint64_t imm_wrs; /* # of work requests with immediate data */
491 uint64_t sgl_wrs; /* # of work requests with direct SGL */
492 uint64_t txpkt_wrs; /* # of txpkt work requests (not coalesced) */
493 uint64_t txpkts0_wrs; /* # of type0 coalesced tx work requests */
494 uint64_t txpkts1_wrs; /* # of type1 coalesced tx work requests */
495 uint64_t txpkts0_pkts; /* # of frames in type0 coalesced tx WRs */
496 uint64_t txpkts1_pkts; /* # of frames in type1 coalesced tx WRs */
498 /* stats for not-that-common events */
499 } __aligned(CACHE_LINE_SIZE);
501 /* rxq: SGE ingress queue + SGE free list + miscellaneous items */
503 struct sge_iq iq; /* MUST be first */
504 struct sge_fl fl; /* MUST follow iq */
506 struct ifnet *ifp; /* the interface this rxq belongs to */
507 #if defined(INET) || defined(INET6)
508 struct lro_ctrl lro; /* LRO state */
511 /* stats for common events first */
513 uint64_t rxcsum; /* # of times hardware assisted with checksum */
514 uint64_t vlan_extraction;/* # of times VLAN tag was extracted */
516 /* stats for not-that-common events */
518 } __aligned(CACHE_LINE_SIZE);
520 static inline struct sge_rxq *
521 iq_to_rxq(struct sge_iq *iq)
524 return (__containerof(iq, struct sge_rxq, iq));
529 /* ofld_rxq: SGE ingress queue + SGE free list + miscellaneous items */
530 struct sge_ofld_rxq {
531 struct sge_iq iq; /* MUST be first */
532 struct sge_fl fl; /* MUST follow iq */
533 } __aligned(CACHE_LINE_SIZE);
535 static inline struct sge_ofld_rxq *
536 iq_to_ofld_rxq(struct sge_iq *iq)
539 return (__containerof(iq, struct sge_ofld_rxq, iq));
544 STAILQ_ENTRY(wrqe) link;
547 char wr[] __aligned(16);
551 TAILQ_ENTRY(wrq_cookie) link;
557 * wrq: SGE egress queue that is given prebuilt work requests. Both the control
558 * and offload tx queues are of this type.
561 struct sge_eq eq; /* MUST be first */
563 struct adapter *adapter;
564 struct task wrq_tx_task;
566 /* Tx desc reserved but WR not "committed" yet. */
567 TAILQ_HEAD(wrq_incomplete_wrs , wrq_cookie) incomplete_wrs;
569 /* List of WRs ready to go out as soon as descriptors are available. */
570 STAILQ_HEAD(, wrqe) wr_list;
574 /* stats for common events first */
576 uint64_t tx_wrs_direct; /* # of WRs written directly to desc ring. */
577 uint64_t tx_wrs_ss; /* # of WRs copied from scratch space. */
578 uint64_t tx_wrs_copied; /* # of WRs queued and copied to desc ring. */
580 /* stats for not-that-common events */
583 * Scratch space for work requests that wrap around after reaching the
584 * status page, and some infomation about the last WR that used it.
588 uint8_t ss[SGE_MAX_WR_LEN];
590 } __aligned(CACHE_LINE_SIZE);
595 struct port_info *pi;
597 struct iq_desc *iq_desc;
599 uint16_t iq_cntxt_id;
605 uint16_t fl_cntxt_id;
612 u_int nid; /* netmap ring # for this queue */
614 /* infrequently used items after this */
616 bus_dma_tag_t iq_desc_tag;
617 bus_dmamap_t iq_desc_map;
621 bus_dma_tag_t fl_desc_tag;
622 bus_dmamap_t fl_desc_map;
624 } __aligned(CACHE_LINE_SIZE);
627 struct tx_desc *desc;
631 uint16_t equiqidx; /* EQUIQ last requested at this pidx */
632 uint16_t equeqidx; /* EQUEQ last requested at this pidx */
633 uint16_t dbidx; /* pidx of the most recent doorbell */
635 volatile uint32_t *udb;
638 __be32 cpl_ctrl0; /* for convenience */
639 u_int nid; /* netmap ring # for this queue */
641 /* infrequently used items after this */
643 bus_dma_tag_t desc_tag;
644 bus_dmamap_t desc_map;
647 } __aligned(CACHE_LINE_SIZE);
651 int timer_val[SGE_NTIMERS];
652 int counter_val[SGE_NCOUNTERS];
653 int fl_starve_threshold;
654 int fl_starve_threshold2;
658 int nrxq; /* total # of Ethernet rx queues */
659 int ntxq; /* total # of Ethernet tx tx queues */
661 int nofldrxq; /* total # of TOE rx queues */
662 int nofldtxq; /* total # of TOE tx queues */
665 int nnmrxq; /* total # of netmap rx queues */
666 int nnmtxq; /* total # of netmap tx queues */
668 int niq; /* total # of ingress queues */
669 int neq; /* total # of egress queues */
671 struct sge_iq fwq; /* Firmware event queue */
672 struct sge_wrq mgmtq; /* Management queue (control queue) */
673 struct sge_wrq *ctrlq; /* Control queues */
674 struct sge_txq *txq; /* NIC tx queues */
675 struct sge_rxq *rxq; /* NIC rx queues */
677 struct sge_wrq *ofld_txq; /* TOE tx queues */
678 struct sge_ofld_rxq *ofld_rxq; /* TOE rx queues */
681 struct sge_nm_txq *nm_txq; /* netmap tx queues */
682 struct sge_nm_rxq *nm_rxq; /* netmap rx queues */
687 struct sge_iq **iqmap; /* iq->cntxt_id to iq mapping */
688 struct sge_eq **eqmap; /* eq->cntxt_id to eq mapping */
692 int8_t safe_hwidx1; /* may not have room for metadata */
693 int8_t safe_hwidx2; /* with room for metadata and maybe more */
694 struct sw_zone_info sw_zone_info[SW_ZONE_SIZES];
695 struct hw_buf_info hw_buf_info[SGE_FLBUF_SIZES];
699 typedef int (*cpl_handler_t)(struct sge_iq *, const struct rss_header *,
701 typedef int (*an_handler_t)(struct sge_iq *, const struct rsp_ctrl *);
702 typedef int (*fw_msg_handler_t)(struct adapter *, const __be64 *);
705 SLIST_ENTRY(adapter) link;
709 /* PCIe register resources */
711 struct resource *regs_res;
713 struct resource *msix_res;
714 bus_space_handle_t bh;
718 struct resource *udbs_res;
719 volatile uint8_t *udbs_base;
724 /* Interrupt information */
728 struct resource *res;
733 bus_dma_tag_t dmat; /* Parent DMA tag */
738 struct taskqueue *tq[NCHAN]; /* General purpose taskqueues */
739 struct port_info *port[MAX_NPORTS];
740 uint8_t chan_map[NCHAN];
743 void *tom_softc; /* (struct tom_data *) */
744 struct tom_tunables tt;
745 void *iwarp_softc; /* (struct c4iw_dev *) */
748 struct l2t_data *l2t; /* L2 table */
749 struct tid_info tids;
754 int offload_map; /* ports with IFCAP_TOE enabled */
755 int active_ulds; /* ULDs activated on this adapter */
759 char ifp_lockname[16];
761 struct ifnet *ifp; /* tracer ifp */
762 struct ifmedia media;
763 int traceq; /* iq used by all tracers, -1 if none */
764 int tracer_valid; /* bitmap of valid tracers */
765 int tracer_enabled; /* bitmap of enabled tracers */
770 struct adapter_params params;
771 struct t4_virt_res vres;
780 struct sysctl_ctx_list ctx; /* from adapter_full_init to full_uninit */
785 /* Starving free lists */
786 struct mtx sfl_lock; /* same cache-line as sc_lock? but that's ok */
787 TAILQ_HEAD(, sge_fl) sfl;
788 struct callout sfl_callout;
790 struct mtx regwin_lock; /* for indirect reads and memory windows */
792 an_handler_t an_handler __aligned(CACHE_LINE_SIZE);
793 fw_msg_handler_t fw_msg_handler[5]; /* NUM_FW6_TYPES */
794 cpl_handler_t cpl_handler[0xef]; /* NUM_CPL_CMDS */
798 const void *last_op_thr;
804 #define ADAPTER_LOCK(sc) mtx_lock(&(sc)->sc_lock)
805 #define ADAPTER_UNLOCK(sc) mtx_unlock(&(sc)->sc_lock)
806 #define ADAPTER_LOCK_ASSERT_OWNED(sc) mtx_assert(&(sc)->sc_lock, MA_OWNED)
807 #define ADAPTER_LOCK_ASSERT_NOTOWNED(sc) mtx_assert(&(sc)->sc_lock, MA_NOTOWNED)
809 #define ASSERT_SYNCHRONIZED_OP(sc) \
810 KASSERT(IS_BUSY(sc) && \
811 (mtx_owned(&(sc)->sc_lock) || sc->last_op_thr == curthread), \
812 ("%s: operation not synchronized.", __func__))
814 #define PORT_LOCK(pi) mtx_lock(&(pi)->pi_lock)
815 #define PORT_UNLOCK(pi) mtx_unlock(&(pi)->pi_lock)
816 #define PORT_LOCK_ASSERT_OWNED(pi) mtx_assert(&(pi)->pi_lock, MA_OWNED)
817 #define PORT_LOCK_ASSERT_NOTOWNED(pi) mtx_assert(&(pi)->pi_lock, MA_NOTOWNED)
819 #define FL_LOCK(fl) mtx_lock(&(fl)->fl_lock)
820 #define FL_TRYLOCK(fl) mtx_trylock(&(fl)->fl_lock)
821 #define FL_UNLOCK(fl) mtx_unlock(&(fl)->fl_lock)
822 #define FL_LOCK_ASSERT_OWNED(fl) mtx_assert(&(fl)->fl_lock, MA_OWNED)
823 #define FL_LOCK_ASSERT_NOTOWNED(fl) mtx_assert(&(fl)->fl_lock, MA_NOTOWNED)
825 #define RXQ_FL_LOCK(rxq) FL_LOCK(&(rxq)->fl)
826 #define RXQ_FL_UNLOCK(rxq) FL_UNLOCK(&(rxq)->fl)
827 #define RXQ_FL_LOCK_ASSERT_OWNED(rxq) FL_LOCK_ASSERT_OWNED(&(rxq)->fl)
828 #define RXQ_FL_LOCK_ASSERT_NOTOWNED(rxq) FL_LOCK_ASSERT_NOTOWNED(&(rxq)->fl)
830 #define EQ_LOCK(eq) mtx_lock(&(eq)->eq_lock)
831 #define EQ_TRYLOCK(eq) mtx_trylock(&(eq)->eq_lock)
832 #define EQ_UNLOCK(eq) mtx_unlock(&(eq)->eq_lock)
833 #define EQ_LOCK_ASSERT_OWNED(eq) mtx_assert(&(eq)->eq_lock, MA_OWNED)
834 #define EQ_LOCK_ASSERT_NOTOWNED(eq) mtx_assert(&(eq)->eq_lock, MA_NOTOWNED)
836 #define TXQ_LOCK(txq) EQ_LOCK(&(txq)->eq)
837 #define TXQ_TRYLOCK(txq) EQ_TRYLOCK(&(txq)->eq)
838 #define TXQ_UNLOCK(txq) EQ_UNLOCK(&(txq)->eq)
839 #define TXQ_LOCK_ASSERT_OWNED(txq) EQ_LOCK_ASSERT_OWNED(&(txq)->eq)
840 #define TXQ_LOCK_ASSERT_NOTOWNED(txq) EQ_LOCK_ASSERT_NOTOWNED(&(txq)->eq)
842 #define for_each_txq(pi, iter, q) \
843 for (q = &pi->adapter->sge.txq[pi->first_txq], iter = 0; \
844 iter < pi->ntxq; ++iter, ++q)
845 #define for_each_rxq(pi, iter, q) \
846 for (q = &pi->adapter->sge.rxq[pi->first_rxq], iter = 0; \
847 iter < pi->nrxq; ++iter, ++q)
848 #define for_each_ofld_txq(pi, iter, q) \
849 for (q = &pi->adapter->sge.ofld_txq[pi->first_ofld_txq], iter = 0; \
850 iter < pi->nofldtxq; ++iter, ++q)
851 #define for_each_ofld_rxq(pi, iter, q) \
852 for (q = &pi->adapter->sge.ofld_rxq[pi->first_ofld_rxq], iter = 0; \
853 iter < pi->nofldrxq; ++iter, ++q)
854 #define for_each_nm_txq(pi, iter, q) \
855 for (q = &pi->adapter->sge.nm_txq[pi->first_nm_txq], iter = 0; \
856 iter < pi->nnmtxq; ++iter, ++q)
857 #define for_each_nm_rxq(pi, iter, q) \
858 for (q = &pi->adapter->sge.nm_rxq[pi->first_nm_rxq], iter = 0; \
859 iter < pi->nnmrxq; ++iter, ++q)
861 #define IDXINCR(idx, incr, wrap) do { \
862 idx = wrap - idx > incr ? idx + incr : incr - (wrap - idx); \
864 #define IDXDIFF(head, tail, wrap) \
865 ((head) >= (tail) ? (head) - (tail) : (wrap) - (tail) + (head))
867 /* One for errors, one for firmware events */
868 #define T4_EXTRA_INTR 2
870 static inline uint32_t
871 t4_read_reg(struct adapter *sc, uint32_t reg)
874 return bus_space_read_4(sc->bt, sc->bh, reg);
878 t4_write_reg(struct adapter *sc, uint32_t reg, uint32_t val)
881 bus_space_write_4(sc->bt, sc->bh, reg, val);
884 static inline uint64_t
885 t4_read_reg64(struct adapter *sc, uint32_t reg)
888 return t4_bus_space_read_8(sc->bt, sc->bh, reg);
892 t4_write_reg64(struct adapter *sc, uint32_t reg, uint64_t val)
895 t4_bus_space_write_8(sc->bt, sc->bh, reg, val);
899 t4_os_pci_read_cfg1(struct adapter *sc, int reg, uint8_t *val)
902 *val = pci_read_config(sc->dev, reg, 1);
906 t4_os_pci_write_cfg1(struct adapter *sc, int reg, uint8_t val)
909 pci_write_config(sc->dev, reg, val, 1);
913 t4_os_pci_read_cfg2(struct adapter *sc, int reg, uint16_t *val)
916 *val = pci_read_config(sc->dev, reg, 2);
920 t4_os_pci_write_cfg2(struct adapter *sc, int reg, uint16_t val)
923 pci_write_config(sc->dev, reg, val, 2);
927 t4_os_pci_read_cfg4(struct adapter *sc, int reg, uint32_t *val)
930 *val = pci_read_config(sc->dev, reg, 4);
934 t4_os_pci_write_cfg4(struct adapter *sc, int reg, uint32_t val)
937 pci_write_config(sc->dev, reg, val, 4);
940 static inline struct port_info *
941 adap2pinfo(struct adapter *sc, int idx)
944 return (sc->port[idx]);
948 t4_os_set_hw_addr(struct adapter *sc, int idx, uint8_t hw_addr[])
951 bcopy(hw_addr, sc->port[idx]->hw_addr, ETHER_ADDR_LEN);
955 is_10G_port(const struct port_info *pi)
958 return ((pi->link_cfg.supported & FW_PORT_CAP_SPEED_10G) != 0);
962 is_40G_port(const struct port_info *pi)
965 return ((pi->link_cfg.supported & FW_PORT_CAP_SPEED_40G) != 0);
969 tx_resume_threshold(struct sge_eq *eq)
972 /* not quite the same as qsize / 4, but this will do. */
973 return (eq->sidx / 4);
977 int t4_os_find_pci_capability(struct adapter *, int);
978 int t4_os_pci_save_state(struct adapter *);
979 int t4_os_pci_restore_state(struct adapter *);
980 void t4_os_portmod_changed(const struct adapter *, int);
981 void t4_os_link_changed(struct adapter *, int, int, int);
982 void t4_iterate(void (*)(struct adapter *, void *), void *);
983 int t4_register_cpl_handler(struct adapter *, int, cpl_handler_t);
984 int t4_register_an_handler(struct adapter *, an_handler_t);
985 int t4_register_fw_msg_handler(struct adapter *, int, fw_msg_handler_t);
986 int t4_filter_rpl(struct sge_iq *, const struct rss_header *, struct mbuf *);
987 int begin_synchronized_op(struct adapter *, struct port_info *, int, char *);
988 void end_synchronized_op(struct adapter *, int);
989 int update_mac_settings(struct ifnet *, int);
990 int adapter_full_init(struct adapter *);
991 int adapter_full_uninit(struct adapter *);
992 int port_full_init(struct port_info *);
993 int port_full_uninit(struct port_info *);
997 int create_netmap_ifnet(struct port_info *);
998 int destroy_netmap_ifnet(struct port_info *);
999 void t4_nm_intr(void *);
1003 void t4_sge_modload(void);
1004 void t4_sge_modunload(void);
1005 uint64_t t4_sge_extfree_refs(void);
1006 void t4_init_sge_cpl_handlers(struct adapter *);
1007 void t4_tweak_chip_settings(struct adapter *);
1008 int t4_read_chip_settings(struct adapter *);
1009 int t4_create_dma_tag(struct adapter *);
1010 void t4_sge_sysctls(struct adapter *, struct sysctl_ctx_list *,
1011 struct sysctl_oid_list *);
1012 int t4_destroy_dma_tag(struct adapter *);
1013 int t4_setup_adapter_queues(struct adapter *);
1014 int t4_teardown_adapter_queues(struct adapter *);
1015 int t4_setup_port_queues(struct port_info *);
1016 int t4_teardown_port_queues(struct port_info *);
1017 void t4_intr_all(void *);
1018 void t4_intr(void *);
1019 void t4_intr_err(void *);
1020 void t4_intr_evt(void *);
1021 void t4_wrq_tx_locked(struct adapter *, struct sge_wrq *, struct wrqe *);
1022 void t4_update_fl_bufsize(struct ifnet *);
1023 int parse_pkt(struct mbuf **);
1024 void *start_wrq_wr(struct sge_wrq *, int, struct wrq_cookie *);
1025 void commit_wrq_wr(struct sge_wrq *, void *, struct wrq_cookie *);
1026 int tnl_cong(struct port_info *);
1030 void t4_tracer_modload(void);
1031 void t4_tracer_modunload(void);
1032 void t4_tracer_port_detach(struct adapter *);
1033 int t4_get_tracer(struct adapter *, struct t4_tracer *);
1034 int t4_set_tracer(struct adapter *, struct t4_tracer *);
1035 int t4_trace_pkt(struct sge_iq *, const struct rss_header *, struct mbuf *);
1036 int t5_trace_pkt(struct sge_iq *, const struct rss_header *, struct mbuf *);
1038 static inline struct wrqe *
1039 alloc_wrqe(int wr_len, struct sge_wrq *wrq)
1041 int len = offsetof(struct wrqe, wr) + wr_len;
1044 wr = malloc(len, M_CXGBE, M_NOWAIT);
1045 if (__predict_false(wr == NULL))
1047 wr->wr_len = wr_len;
1052 static inline void *
1053 wrtod(struct wrqe *wr)
1055 return (&wr->wr[0]);
1059 free_wrqe(struct wrqe *wr)
1065 t4_wrq_tx(struct adapter *sc, struct wrqe *wr)
1067 struct sge_wrq *wrq = wr->wrq;
1070 t4_wrq_tx_locked(sc, wrq, wr);