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 "firmware/t4fw_interface.h"
53 MALLOC_DECLARE(M_CXGBE);
54 #define CXGBE_UNIMPLEMENTED(s) \
55 panic("%s (%s, line %d) not implemented yet.", s, __FILE__, __LINE__)
57 #if defined(__i386__) || defined(__amd64__)
61 __asm volatile("prefetcht0 %0" :: "m" (*(unsigned long *)x));
67 #ifndef SYSCTL_ADD_UQUAD
68 #define SYSCTL_ADD_UQUAD SYSCTL_ADD_QUAD
69 #define sysctl_handle_64 sysctl_handle_quad
70 #define CTLTYPE_U64 CTLTYPE_QUAD
73 #if (__FreeBSD_version >= 900030) || \
74 ((__FreeBSD_version >= 802507) && (__FreeBSD_version < 900000))
79 /* XXX: need systemwide bus_space_read_8/bus_space_write_8 */
80 static __inline uint64_t
81 t4_bus_space_read_8(bus_space_tag_t tag, bus_space_handle_t handle,
84 KASSERT(tag == X86_BUS_SPACE_MEM,
85 ("%s: can only handle mem space", __func__));
87 return (*(volatile uint64_t *)(handle + offset));
91 t4_bus_space_write_8(bus_space_tag_t tag, bus_space_handle_t bsh,
92 bus_size_t offset, uint64_t value)
94 KASSERT(tag == X86_BUS_SPACE_MEM,
95 ("%s: can only handle mem space", __func__));
97 *(volatile uint64_t *)(bsh + offset) = value;
100 static __inline uint64_t
101 t4_bus_space_read_8(bus_space_tag_t tag, bus_space_handle_t handle,
104 return (uint64_t)bus_space_read_4(tag, handle, offset) +
105 ((uint64_t)bus_space_read_4(tag, handle, offset + 4) << 32);
109 t4_bus_space_write_8(bus_space_tag_t tag, bus_space_handle_t bsh,
110 bus_size_t offset, uint64_t value)
112 bus_space_write_4(tag, bsh, offset, value);
113 bus_space_write_4(tag, bsh, offset + 4, value >> 32);
118 typedef struct adapter adapter_t;
122 FW_IQ_ESIZE = 64, /* At least 64 mandated by the firmware spec */
125 RX_IQ_ESIZE = 64, /* At least 64 so CPL_RX_PKT will fit */
127 EQ_ESIZE = 64, /* All egress queues use this entry size */
129 RX_FL_ESIZE = EQ_ESIZE, /* 8 64bit addresses */
130 #if MJUMPAGESIZE != MCLBYTES
131 FL_BUF_SIZES_MAX = 5, /* cluster, jumbop, jumbo9k, jumbo16k, extra */
133 FL_BUF_SIZES_MAX = 4, /* cluster, jumbo9k, jumbo16k, extra */
140 TX_WR_FLITS = SGE_MAX_WR_LEN / 8
144 /* adapter intr_type */
145 INTR_INTX = (1 << 0),
151 /* flags understood by begin_synchronized_op */
152 HOLD_LOCK = (1 << 0),
156 /* flags understood by end_synchronized_op */
157 LOCK_HELD = HOLD_LOCK,
162 FULL_INIT_DONE = (1 << 0),
164 INTR_DIRECT = (1 << 2), /* direct interrupts for everything */
165 MASTER_PF = (1 << 3),
166 ADAP_SYSCTL_CTX = (1 << 4),
167 TOM_INIT_DONE = (1 << 5),
168 BUF_PACKING_OK = (1 << 6),
170 CXGBE_BUSY = (1 << 9),
174 PORT_INIT_DONE = (1 << 1),
175 PORT_SYSCTL_CTX = (1 << 2),
176 HAS_TRACEQ = (1 << 3),
179 #define IS_DOOMED(pi) ((pi)->flags & DOOMED)
180 #define SET_DOOMED(pi) do {(pi)->flags |= DOOMED;} while (0)
181 #define IS_BUSY(sc) ((sc)->flags & CXGBE_BUSY)
182 #define SET_BUSY(sc) do {(sc)->flags |= CXGBE_BUSY;} while (0)
183 #define CLR_BUSY(sc) do {(sc)->flags &= ~CXGBE_BUSY;} while (0)
187 struct adapter *adapter;
190 struct ifmedia media;
199 int16_t xact_addr_filt;/* index of exact MAC address filter */
200 uint16_t rss_size; /* size of VI's RSS table slice */
201 uint8_t lport; /* associated offload logical port */
208 /* These need to be int as they are used in sysctl */
209 int ntxq; /* # of tx queues */
210 int first_txq; /* index of first tx queue */
211 int nrxq; /* # of rx queues */
212 int first_rxq; /* index of first rx queue */
214 int nofldtxq; /* # of offload tx queues */
215 int first_ofld_txq; /* index of first offload tx queue */
216 int nofldrxq; /* # of offload rx queues */
217 int first_ofld_rxq; /* index of first offload rx queue */
225 struct link_config link_cfg;
226 struct port_stats stats;
228 eventhandler_tag vlan_c;
231 struct sysctl_ctx_list ctx; /* from ifconfig up to driver detach */
233 uint8_t hw_addr[ETHER_ADDR_LEN]; /* factory MAC address, won't change */
239 uint8_t tag_idx; /* the fl->tag entry this map comes from */
254 /* DMA maps used for tx */
257 uint32_t map_total; /* # of DMA maps */
258 uint32_t map_pidx; /* next map to be used */
259 uint32_t map_cidx; /* reclaimed up to this index */
260 uint32_t map_avail; /* # of available maps */
264 uint8_t desc_used; /* # of hardware descriptors used by the WR */
265 uint8_t credits; /* NIC txq: # of frames sent out in the WR */
270 IQ_ALLOCATED = (1 << 0), /* firmware resources allocated */
271 IQ_HAS_FL = (1 << 1), /* iq associated with a freelist */
272 IQ_INTR = (1 << 2), /* iq takes direct interrupt */
273 IQ_LRO_ENABLED = (1 << 3), /* iq is an eth rxq with LRO enabled */
282 * Ingress Queue: T4 is producer, driver is consumer.
285 bus_dma_tag_t desc_tag;
286 bus_dmamap_t desc_map;
287 bus_addr_t ba; /* bus address of descriptor ring */
289 uint16_t abs_id; /* absolute SGE id for the iq */
290 int8_t intr_pktc_idx; /* packet count threshold index */
292 __be64 *desc; /* KVA of descriptor ring */
295 struct adapter *adapter;
296 const __be64 *cdesc; /* current descriptor */
297 uint8_t gen; /* generation bit */
298 uint8_t intr_params; /* interrupt holdoff parameters */
299 uint8_t intr_next; /* XXX: holdoff for next interrupt */
300 uint8_t esize; /* size (bytes) of each entry in the queue */
301 uint16_t qsize; /* size (# of entries) of the queue */
302 uint16_t cidx; /* consumer index */
303 uint16_t cntxt_id; /* SGE context id for the iq */
305 STAILQ_ENTRY(sge_iq) link;
316 EQ_TYPEMASK = 7, /* 3 lsbits hold the type */
317 EQ_ALLOCATED = (1 << 3), /* firmware resources allocated */
318 EQ_DOOMED = (1 << 4), /* about to be destroyed */
319 EQ_CRFLUSHED = (1 << 5), /* expecting an update from SGE */
320 EQ_STALLED = (1 << 6), /* out of hw descriptors or dmamaps */
323 /* Listed in order of preference. Update t4_sysctls too if you change these */
324 enum {DOORBELL_UDB, DOORBELL_WCWR, DOORBELL_UDBWC, DOORBELL_KDB};
327 * Egress Queue: driver is producer, T4 is consumer.
329 * Note: A free list is an egress queue (driver produces the buffers and T4
330 * consumes them) but it's special enough to have its own struct (see sge_fl).
333 unsigned int flags; /* MUST be first */
334 unsigned int cntxt_id; /* SGE context id for the eq */
335 bus_dma_tag_t desc_tag;
336 bus_dmamap_t desc_map;
340 struct tx_desc *desc; /* KVA of descriptor ring */
341 bus_addr_t ba; /* bus address of descriptor ring */
342 struct sge_qstat *spg; /* status page, for convenience */
344 volatile uint32_t *udb; /* KVA of doorbell (lies within BAR2) */
345 u_int udb_qid; /* relative qid within the doorbell page */
346 uint16_t cap; /* max # of desc, for convenience */
347 uint16_t avail; /* available descriptors, for convenience */
348 uint16_t qsize; /* size (# of entries) of the queue */
349 uint16_t cidx; /* consumer idx (desc idx) */
350 uint16_t pidx; /* producer idx (desc idx) */
351 uint16_t pending; /* # of descriptors used since last doorbell */
352 uint16_t iqid; /* iq that gets egr_update for the eq */
353 uint8_t tx_chan; /* tx channel used by the eq */
355 struct callout tx_callout;
359 uint32_t egr_update; /* # of SGE_EGR_UPDATE notifications for eq */
360 uint32_t unstalled; /* recovered from stall */
366 int hwtag:4; /* tag in low 4 bits of the pa. */
369 #define FL_BUF_SIZES(sc) (sc->sge.fl_buf_sizes)
370 #define FL_BUF_SIZE(sc, x) (sc->sge.fl_buf_info[x].size)
371 #define FL_BUF_TYPE(sc, x) (sc->sge.fl_buf_info[x].type)
372 #define FL_BUF_HWTAG(sc, x) (sc->sge.fl_buf_info[x].hwtag)
373 #define FL_BUF_ZONE(sc, x) (sc->sge.fl_buf_info[x].zone)
376 FL_STARVING = (1 << 0), /* on the adapter's list of starving fl's */
377 FL_DOOMED = (1 << 1), /* about to be destroyed */
378 FL_BUF_PACKING = (1 << 2), /* buffer packing enabled */
381 #define FL_RUNNING_LOW(fl) (fl->cap - fl->needed <= fl->lowat)
382 #define FL_NOT_RUNNING_LOW(fl) (fl->cap - fl->needed >= 2 * fl->lowat)
385 bus_dma_tag_t desc_tag;
386 bus_dmamap_t desc_map;
387 bus_dma_tag_t tag[FL_BUF_SIZES_MAX]; /* only first FL_BUF_SIZES(sc) are
394 __be64 *desc; /* KVA of descriptor ring, ptr to addresses */
395 bus_addr_t ba; /* bus address of descriptor ring */
396 struct fl_sdesc *sdesc; /* KVA of software descriptor ring */
397 uint32_t cap; /* max # of buffers, for convenience */
398 uint16_t qsize; /* size (# of entries) of the queue */
399 uint16_t cntxt_id; /* SGE context id for the freelist */
400 uint32_t cidx; /* consumer idx (buffer idx, NOT hw desc idx) */
401 uint32_t rx_offset; /* offset in fl buf (when buffer packing) */
402 uint32_t pidx; /* producer idx (buffer idx, NOT hw desc idx) */
403 uint32_t needed; /* # of buffers needed to fill up fl. */
404 uint32_t lowat; /* # of buffers <= this means fl needs help */
405 uint32_t pending; /* # of bufs allocated since last doorbell */
407 struct mbuf *mstash[8];
408 TAILQ_ENTRY(sge_fl) link; /* All starving freelists */
411 /* txq: SGE egress queue + what's needed for Ethernet NIC */
413 struct sge_eq eq; /* MUST be first */
415 struct ifnet *ifp; /* the interface this txq belongs to */
416 bus_dma_tag_t tx_tag; /* tag for transmit buffers */
417 struct buf_ring *br; /* tx buffer ring */
418 struct tx_sdesc *sdesc; /* KVA of software descriptor ring */
419 struct mbuf *m; /* held up due to temporary resource shortage */
421 struct tx_maps txmaps;
423 /* stats for common events first */
425 uint64_t txcsum; /* # of times hardware assisted with checksum */
426 uint64_t tso_wrs; /* # of TSO work requests */
427 uint64_t vlan_insertion;/* # of times VLAN tag was inserted */
428 uint64_t imm_wrs; /* # of work requests with immediate data */
429 uint64_t sgl_wrs; /* # of work requests with direct SGL */
430 uint64_t txpkt_wrs; /* # of txpkt work requests (not coalesced) */
431 uint64_t txpkts_wrs; /* # of coalesced tx work requests */
432 uint64_t txpkts_pkts; /* # of frames in coalesced tx work requests */
434 /* stats for not-that-common events */
436 uint32_t no_dmamap; /* no DMA map to load the mbuf */
437 uint32_t no_desc; /* out of hardware descriptors */
438 } __aligned(CACHE_LINE_SIZE);
440 /* rxq: SGE ingress queue + SGE free list + miscellaneous items */
442 struct sge_iq iq; /* MUST be first */
443 struct sge_fl fl; /* MUST follow iq */
445 struct ifnet *ifp; /* the interface this rxq belongs to */
446 #if defined(INET) || defined(INET6)
447 struct lro_ctrl lro; /* LRO state */
450 /* stats for common events first */
452 uint64_t rxcsum; /* # of times hardware assisted with checksum */
453 uint64_t vlan_extraction;/* # of times VLAN tag was extracted */
455 /* stats for not-that-common events */
457 } __aligned(CACHE_LINE_SIZE);
459 static inline struct sge_rxq *
460 iq_to_rxq(struct sge_iq *iq)
463 return (__containerof(iq, struct sge_rxq, iq));
468 /* ofld_rxq: SGE ingress queue + SGE free list + miscellaneous items */
469 struct sge_ofld_rxq {
470 struct sge_iq iq; /* MUST be first */
471 struct sge_fl fl; /* MUST follow iq */
472 } __aligned(CACHE_LINE_SIZE);
474 static inline struct sge_ofld_rxq *
475 iq_to_ofld_rxq(struct sge_iq *iq)
478 return (__containerof(iq, struct sge_ofld_rxq, iq));
483 STAILQ_ENTRY(wrqe) link;
486 uint64_t wr[] __aligned(16);
490 * wrq: SGE egress queue that is given prebuilt work requests. Both the control
491 * and offload tx queues are of this type.
494 struct sge_eq eq; /* MUST be first */
496 struct adapter *adapter;
498 /* List of WRs held up due to lack of tx descriptors */
499 STAILQ_HEAD(, wrqe) wr_list;
501 /* stats for common events first */
503 uint64_t tx_wrs; /* # of tx work requests */
505 /* stats for not-that-common events */
507 uint32_t no_desc; /* out of hardware descriptors */
508 } __aligned(CACHE_LINE_SIZE);
511 int timer_val[SGE_NTIMERS];
512 int counter_val[SGE_NCOUNTERS];
513 int fl_starve_threshold;
517 int nrxq; /* total # of Ethernet rx queues */
518 int ntxq; /* total # of Ethernet tx tx queues */
520 int nofldrxq; /* total # of TOE rx queues */
521 int nofldtxq; /* total # of TOE tx queues */
523 int niq; /* total # of ingress queues */
524 int neq; /* total # of egress queues */
526 struct sge_iq fwq; /* Firmware event queue */
527 struct sge_wrq mgmtq; /* Management queue (control queue) */
528 struct sge_wrq *ctrlq; /* Control queues */
529 struct sge_txq *txq; /* NIC tx queues */
530 struct sge_rxq *rxq; /* NIC rx queues */
532 struct sge_wrq *ofld_txq; /* TOE tx queues */
533 struct sge_ofld_rxq *ofld_rxq; /* TOE rx queues */
538 struct sge_iq **iqmap; /* iq->cntxt_id to iq mapping */
539 struct sge_eq **eqmap; /* eq->cntxt_id to eq mapping */
541 u_int fl_buf_sizes __aligned(CACHE_LINE_SIZE);
542 struct fl_buf_info fl_buf_info[FL_BUF_SIZES_MAX];
546 typedef int (*cpl_handler_t)(struct sge_iq *, const struct rss_header *,
548 typedef int (*an_handler_t)(struct sge_iq *, const struct rsp_ctrl *);
549 typedef int (*fw_msg_handler_t)(struct adapter *, const __be64 *);
552 SLIST_ENTRY(adapter) link;
556 /* PCIe register resources */
558 struct resource *regs_res;
560 struct resource *msix_res;
561 bus_space_handle_t bh;
565 struct resource *udbs_res;
566 volatile uint8_t *udbs_base;
571 /* Interrupt information */
575 struct resource *res;
580 bus_dma_tag_t dmat; /* Parent DMA tag */
585 struct taskqueue *tq[NCHAN]; /* taskqueues that flush data out */
586 struct port_info *port[MAX_NPORTS];
587 uint8_t chan_map[NCHAN];
590 void *tom_softc; /* (struct tom_data *) */
591 struct tom_tunables tt;
592 void *iwarp_softc; /* (struct c4iw_dev *) */
594 struct l2t_data *l2t; /* L2 table */
595 struct tid_info tids;
604 char ifp_lockname[16];
606 struct ifnet *ifp; /* tracer ifp */
607 struct ifmedia media;
608 int traceq; /* iq used by all tracers, -1 if none */
609 int tracer_valid; /* bitmap of valid tracers */
610 int tracer_enabled; /* bitmap of enabled tracers */
615 struct adapter_params params;
616 struct t4_virt_res vres;
625 struct sysctl_ctx_list ctx; /* from adapter_full_init to full_uninit */
630 /* Starving free lists */
631 struct mtx sfl_lock; /* same cache-line as sc_lock? but that's ok */
632 TAILQ_HEAD(, sge_fl) sfl;
633 struct callout sfl_callout;
635 an_handler_t an_handler __aligned(CACHE_LINE_SIZE);
636 fw_msg_handler_t fw_msg_handler[5]; /* NUM_FW6_TYPES */
637 cpl_handler_t cpl_handler[0xef]; /* NUM_CPL_CMDS */
641 const void *last_op_thr;
645 #define ADAPTER_LOCK(sc) mtx_lock(&(sc)->sc_lock)
646 #define ADAPTER_UNLOCK(sc) mtx_unlock(&(sc)->sc_lock)
647 #define ADAPTER_LOCK_ASSERT_OWNED(sc) mtx_assert(&(sc)->sc_lock, MA_OWNED)
648 #define ADAPTER_LOCK_ASSERT_NOTOWNED(sc) mtx_assert(&(sc)->sc_lock, MA_NOTOWNED)
650 /* XXX: not bulletproof, but much better than nothing */
651 #define ASSERT_SYNCHRONIZED_OP(sc) \
652 KASSERT(IS_BUSY(sc) && \
653 (mtx_owned(&(sc)->sc_lock) || sc->last_op_thr == curthread), \
654 ("%s: operation not synchronized.", __func__))
656 #define PORT_LOCK(pi) mtx_lock(&(pi)->pi_lock)
657 #define PORT_UNLOCK(pi) mtx_unlock(&(pi)->pi_lock)
658 #define PORT_LOCK_ASSERT_OWNED(pi) mtx_assert(&(pi)->pi_lock, MA_OWNED)
659 #define PORT_LOCK_ASSERT_NOTOWNED(pi) mtx_assert(&(pi)->pi_lock, MA_NOTOWNED)
661 #define FL_LOCK(fl) mtx_lock(&(fl)->fl_lock)
662 #define FL_TRYLOCK(fl) mtx_trylock(&(fl)->fl_lock)
663 #define FL_UNLOCK(fl) mtx_unlock(&(fl)->fl_lock)
664 #define FL_LOCK_ASSERT_OWNED(fl) mtx_assert(&(fl)->fl_lock, MA_OWNED)
665 #define FL_LOCK_ASSERT_NOTOWNED(fl) mtx_assert(&(fl)->fl_lock, MA_NOTOWNED)
667 #define RXQ_FL_LOCK(rxq) FL_LOCK(&(rxq)->fl)
668 #define RXQ_FL_UNLOCK(rxq) FL_UNLOCK(&(rxq)->fl)
669 #define RXQ_FL_LOCK_ASSERT_OWNED(rxq) FL_LOCK_ASSERT_OWNED(&(rxq)->fl)
670 #define RXQ_FL_LOCK_ASSERT_NOTOWNED(rxq) FL_LOCK_ASSERT_NOTOWNED(&(rxq)->fl)
672 #define EQ_LOCK(eq) mtx_lock(&(eq)->eq_lock)
673 #define EQ_TRYLOCK(eq) mtx_trylock(&(eq)->eq_lock)
674 #define EQ_UNLOCK(eq) mtx_unlock(&(eq)->eq_lock)
675 #define EQ_LOCK_ASSERT_OWNED(eq) mtx_assert(&(eq)->eq_lock, MA_OWNED)
676 #define EQ_LOCK_ASSERT_NOTOWNED(eq) mtx_assert(&(eq)->eq_lock, MA_NOTOWNED)
678 #define TXQ_LOCK(txq) EQ_LOCK(&(txq)->eq)
679 #define TXQ_TRYLOCK(txq) EQ_TRYLOCK(&(txq)->eq)
680 #define TXQ_UNLOCK(txq) EQ_UNLOCK(&(txq)->eq)
681 #define TXQ_LOCK_ASSERT_OWNED(txq) EQ_LOCK_ASSERT_OWNED(&(txq)->eq)
682 #define TXQ_LOCK_ASSERT_NOTOWNED(txq) EQ_LOCK_ASSERT_NOTOWNED(&(txq)->eq)
684 #define for_each_txq(pi, iter, q) \
685 for (q = &pi->adapter->sge.txq[pi->first_txq], iter = 0; \
686 iter < pi->ntxq; ++iter, ++q)
687 #define for_each_rxq(pi, iter, q) \
688 for (q = &pi->adapter->sge.rxq[pi->first_rxq], iter = 0; \
689 iter < pi->nrxq; ++iter, ++q)
690 #define for_each_ofld_txq(pi, iter, q) \
691 for (q = &pi->adapter->sge.ofld_txq[pi->first_ofld_txq], iter = 0; \
692 iter < pi->nofldtxq; ++iter, ++q)
693 #define for_each_ofld_rxq(pi, iter, q) \
694 for (q = &pi->adapter->sge.ofld_rxq[pi->first_ofld_rxq], iter = 0; \
695 iter < pi->nofldrxq; ++iter, ++q)
697 /* One for errors, one for firmware events */
698 #define T4_EXTRA_INTR 2
700 static inline uint32_t
701 t4_read_reg(struct adapter *sc, uint32_t reg)
704 return bus_space_read_4(sc->bt, sc->bh, reg);
708 t4_write_reg(struct adapter *sc, uint32_t reg, uint32_t val)
711 bus_space_write_4(sc->bt, sc->bh, reg, val);
714 static inline uint64_t
715 t4_read_reg64(struct adapter *sc, uint32_t reg)
718 return t4_bus_space_read_8(sc->bt, sc->bh, reg);
722 t4_write_reg64(struct adapter *sc, uint32_t reg, uint64_t val)
725 t4_bus_space_write_8(sc->bt, sc->bh, reg, val);
729 t4_os_pci_read_cfg1(struct adapter *sc, int reg, uint8_t *val)
732 *val = pci_read_config(sc->dev, reg, 1);
736 t4_os_pci_write_cfg1(struct adapter *sc, int reg, uint8_t val)
739 pci_write_config(sc->dev, reg, val, 1);
743 t4_os_pci_read_cfg2(struct adapter *sc, int reg, uint16_t *val)
746 *val = pci_read_config(sc->dev, reg, 2);
750 t4_os_pci_write_cfg2(struct adapter *sc, int reg, uint16_t val)
753 pci_write_config(sc->dev, reg, val, 2);
757 t4_os_pci_read_cfg4(struct adapter *sc, int reg, uint32_t *val)
760 *val = pci_read_config(sc->dev, reg, 4);
764 t4_os_pci_write_cfg4(struct adapter *sc, int reg, uint32_t val)
767 pci_write_config(sc->dev, reg, val, 4);
770 static inline struct port_info *
771 adap2pinfo(struct adapter *sc, int idx)
774 return (sc->port[idx]);
778 t4_os_set_hw_addr(struct adapter *sc, int idx, uint8_t hw_addr[])
781 bcopy(hw_addr, sc->port[idx]->hw_addr, ETHER_ADDR_LEN);
785 is_10G_port(const struct port_info *pi)
788 return ((pi->link_cfg.supported & FW_PORT_CAP_SPEED_10G) != 0);
792 is_40G_port(const struct port_info *pi)
795 return ((pi->link_cfg.supported & FW_PORT_CAP_SPEED_40G) != 0);
799 tx_resume_threshold(struct sge_eq *eq)
802 return (eq->qsize / 4);
806 void t4_tx_task(void *, int);
807 void t4_tx_callout(void *);
808 int t4_os_find_pci_capability(struct adapter *, int);
809 int t4_os_pci_save_state(struct adapter *);
810 int t4_os_pci_restore_state(struct adapter *);
811 void t4_os_portmod_changed(const struct adapter *, int);
812 void t4_os_link_changed(struct adapter *, int, int, int);
813 void t4_iterate(void (*)(struct adapter *, void *), void *);
814 int t4_register_cpl_handler(struct adapter *, int, cpl_handler_t);
815 int t4_register_an_handler(struct adapter *, an_handler_t);
816 int t4_register_fw_msg_handler(struct adapter *, int, fw_msg_handler_t);
817 int t4_filter_rpl(struct sge_iq *, const struct rss_header *, struct mbuf *);
818 int begin_synchronized_op(struct adapter *, struct port_info *, int, char *);
819 void end_synchronized_op(struct adapter *, int);
822 void t4_sge_modload(void);
823 void t4_init_sge_cpl_handlers(struct adapter *);
824 void t4_tweak_chip_settings(struct adapter *);
825 int t4_read_chip_settings(struct adapter *);
826 int t4_create_dma_tag(struct adapter *);
827 void t4_sge_sysctls(struct adapter *, struct sysctl_ctx_list *,
828 struct sysctl_oid_list *);
829 int t4_destroy_dma_tag(struct adapter *);
830 int t4_setup_adapter_queues(struct adapter *);
831 int t4_teardown_adapter_queues(struct adapter *);
832 int t4_setup_port_queues(struct port_info *);
833 int t4_teardown_port_queues(struct port_info *);
834 int t4_alloc_tx_maps(struct tx_maps *, bus_dma_tag_t, int, int);
835 void t4_free_tx_maps(struct tx_maps *, bus_dma_tag_t);
836 void t4_intr_all(void *);
837 void t4_intr(void *);
838 void t4_intr_err(void *);
839 void t4_intr_evt(void *);
840 void t4_wrq_tx_locked(struct adapter *, struct sge_wrq *, struct wrqe *);
841 int t4_eth_tx(struct ifnet *, struct sge_txq *, struct mbuf *);
842 void t4_update_fl_bufsize(struct ifnet *);
843 int can_resume_tx(struct sge_eq *);
847 void t4_tracer_modload(void);
848 void t4_tracer_modunload(void);
849 void t4_tracer_port_detach(struct adapter *);
850 int t4_get_tracer(struct adapter *, struct t4_tracer *);
851 int t4_set_tracer(struct adapter *, struct t4_tracer *);
852 int t4_trace_pkt(struct sge_iq *, const struct rss_header *, struct mbuf *);
853 int t5_trace_pkt(struct sge_iq *, const struct rss_header *, struct mbuf *);
855 static inline struct wrqe *
856 alloc_wrqe(int wr_len, struct sge_wrq *wrq)
858 int len = offsetof(struct wrqe, wr) + wr_len;
861 wr = malloc(len, M_CXGBE, M_NOWAIT);
862 if (__predict_false(wr == NULL))
870 wrtod(struct wrqe *wr)
876 free_wrqe(struct wrqe *wr)
882 t4_wrq_tx(struct adapter *sc, struct wrqe *wr)
884 struct sge_wrq *wrq = wr->wrq;
887 t4_wrq_tx_locked(sc, wrq, wr);