]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/cxgbe/adapter.h
MFV r323914: 8661 remove "zil-cw2" dtrace probe
[FreeBSD/FreeBSD.git] / sys / dev / cxgbe / adapter.h
1 /*-
2  * Copyright (c) 2011 Chelsio Communications, Inc.
3  * All rights reserved.
4  * Written by: Navdeep Parhar <np@FreeBSD.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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.
14  *
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
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  *
29  */
30
31 #ifndef __T4_ADAPTER_H__
32 #define __T4_ADAPTER_H__
33
34 #include <sys/kernel.h>
35 #include <sys/bus.h>
36 #include <sys/rman.h>
37 #include <sys/types.h>
38 #include <sys/lock.h>
39 #include <sys/malloc.h>
40 #include <sys/rwlock.h>
41 #include <sys/sx.h>
42 #include <vm/uma.h>
43
44 #include <dev/pci/pcivar.h>
45 #include <dev/pci/pcireg.h>
46 #include <machine/bus.h>
47 #include <sys/socket.h>
48 #include <sys/sysctl.h>
49 #include <net/ethernet.h>
50 #include <net/if.h>
51 #include <net/if_var.h>
52 #include <net/if_media.h>
53 #include <netinet/in.h>
54 #include <netinet/tcp_lro.h>
55
56 #include "offload.h"
57 #include "t4_ioctl.h"
58 #include "common/t4_msg.h"
59 #include "firmware/t4fw_interface.h"
60
61 #define KTR_CXGBE       KTR_SPARE3
62 MALLOC_DECLARE(M_CXGBE);
63 #define CXGBE_UNIMPLEMENTED(s) \
64     panic("%s (%s, line %d) not implemented yet.", s, __FILE__, __LINE__)
65
66 #if defined(__i386__) || defined(__amd64__)
67 static __inline void
68 prefetch(void *x)
69 {
70         __asm volatile("prefetcht0 %0" :: "m" (*(unsigned long *)x));
71 }
72 #else
73 #define prefetch(x)
74 #endif
75
76 #ifndef SYSCTL_ADD_UQUAD
77 #define SYSCTL_ADD_UQUAD SYSCTL_ADD_QUAD
78 #define sysctl_handle_64 sysctl_handle_quad
79 #define CTLTYPE_U64 CTLTYPE_QUAD
80 #endif
81
82 #if (__FreeBSD_version >= 900030) || \
83     ((__FreeBSD_version >= 802507) && (__FreeBSD_version < 900000))
84 #define SBUF_DRAIN 1
85 #endif
86
87 struct adapter;
88 typedef struct adapter adapter_t;
89
90 enum {
91         /*
92          * All ingress queues use this entry size.  Note that the firmware event
93          * queue and any iq expecting CPL_RX_PKT in the descriptor needs this to
94          * be at least 64.
95          */
96         IQ_ESIZE = 64,
97
98         /* Default queue sizes for all kinds of ingress queues */
99         FW_IQ_QSIZE = 256,
100         RX_IQ_QSIZE = 1024,
101
102         /* All egress queues use this entry size */
103         EQ_ESIZE = 64,
104
105         /* Default queue sizes for all kinds of egress queues */
106         CTRL_EQ_QSIZE = 128,
107         TX_EQ_QSIZE = 1024,
108
109 #if MJUMPAGESIZE != MCLBYTES
110         SW_ZONE_SIZES = 4,      /* cluster, jumbop, jumbo9k, jumbo16k */
111 #else
112         SW_ZONE_SIZES = 3,      /* cluster, jumbo9k, jumbo16k */
113 #endif
114         CL_METADATA_SIZE = CACHE_LINE_SIZE,
115
116         SGE_MAX_WR_NDESC = SGE_MAX_WR_LEN / EQ_ESIZE, /* max WR size in desc */
117         TX_SGL_SEGS = 39,
118         TX_SGL_SEGS_TSO = 38,
119         TX_WR_FLITS = SGE_MAX_WR_LEN / 8
120 };
121
122 enum {
123         /* adapter intr_type */
124         INTR_INTX       = (1 << 0),
125         INTR_MSI        = (1 << 1),
126         INTR_MSIX       = (1 << 2)
127 };
128
129 enum {
130         XGMAC_MTU       = (1 << 0),
131         XGMAC_PROMISC   = (1 << 1),
132         XGMAC_ALLMULTI  = (1 << 2),
133         XGMAC_VLANEX    = (1 << 3),
134         XGMAC_UCADDR    = (1 << 4),
135         XGMAC_MCADDRS   = (1 << 5),
136
137         XGMAC_ALL       = 0xffff
138 };
139
140 enum {
141         /* flags understood by begin_synchronized_op */
142         HOLD_LOCK       = (1 << 0),
143         SLEEP_OK        = (1 << 1),
144         INTR_OK         = (1 << 2),
145
146         /* flags understood by end_synchronized_op */
147         LOCK_HELD       = HOLD_LOCK,
148 };
149
150 enum {
151         /* adapter flags */
152         FULL_INIT_DONE  = (1 << 0),
153         FW_OK           = (1 << 1),
154         CHK_MBOX_ACCESS = (1 << 2),
155         MASTER_PF       = (1 << 3),
156         ADAP_SYSCTL_CTX = (1 << 4),
157         /* TOM_INIT_DONE= (1 << 5),     No longer used */
158         BUF_PACKING_OK  = (1 << 6),
159         IS_VF           = (1 << 7),
160
161         CXGBE_BUSY      = (1 << 9),
162
163         /* port flags */
164         HAS_TRACEQ      = (1 << 3),
165
166         /* VI flags */
167         DOOMED          = (1 << 0),
168         VI_INIT_DONE    = (1 << 1),
169         VI_SYSCTL_CTX   = (1 << 2),
170         INTR_RXQ        = (1 << 4),     /* All NIC rxq's take interrupts */
171         INTR_OFLD_RXQ   = (1 << 5),     /* All TOE rxq's take interrupts */
172         INTR_ALL        = (INTR_RXQ | INTR_OFLD_RXQ),
173
174         /* adapter debug_flags */
175         DF_DUMP_MBOX            = (1 << 0),     /* Log all mbox cmd/rpl. */
176         DF_LOAD_FW_ANYTIME      = (1 << 1),     /* Allow LOAD_FW after init */
177         DF_DISABLE_TCB_CACHE    = (1 << 2),     /* Disable TCB cache (T6+) */
178 };
179
180 #define IS_DOOMED(vi)   ((vi)->flags & DOOMED)
181 #define SET_DOOMED(vi)  do {(vi)->flags |= DOOMED;} while (0)
182 #define IS_BUSY(sc)     ((sc)->flags & CXGBE_BUSY)
183 #define SET_BUSY(sc)    do {(sc)->flags |= CXGBE_BUSY;} while (0)
184 #define CLR_BUSY(sc)    do {(sc)->flags &= ~CXGBE_BUSY;} while (0)
185
186 struct vi_info {
187         device_t dev;
188         struct port_info *pi;
189
190         struct ifnet *ifp;
191
192         unsigned long flags;
193         int if_flags;
194
195         uint16_t *rss, *nm_rss;
196         int smt_idx;            /* for convenience */
197         uint16_t viid;
198         int16_t  xact_addr_filt;/* index of exact MAC address filter */
199         uint16_t rss_size;      /* size of VI's RSS table slice */
200         uint16_t rss_base;      /* start of VI's RSS table slice */
201
202         eventhandler_tag vlan_c;
203
204         int nintr;
205         int first_intr;
206
207         /* These need to be int as they are used in sysctl */
208         int ntxq;               /* # of tx queues */
209         int first_txq;          /* index of first tx queue */
210         int rsrv_noflowq;       /* Reserve queue 0 for non-flowid packets */
211         int nrxq;               /* # of rx queues */
212         int first_rxq;          /* index of first rx queue */
213         int nofldtxq;           /* # of offload tx queues */
214         int first_ofld_txq;     /* index of first offload tx queue */
215         int nofldrxq;           /* # of offload rx queues */
216         int first_ofld_rxq;     /* index of first offload rx queue */
217         int nnmtxq;
218         int first_nm_txq;
219         int nnmrxq;
220         int first_nm_rxq;
221         int tmr_idx;
222         int pktc_idx;
223         int qsize_rxq;
224         int qsize_txq;
225
226         struct timeval last_refreshed;
227         struct fw_vi_stats_vf stats;
228
229         struct callout tick;
230         struct sysctl_ctx_list ctx;     /* from ifconfig up to driver detach */
231
232         uint8_t hw_addr[ETHER_ADDR_LEN]; /* factory MAC address, won't change */
233 };
234
235 struct tx_ch_rl_params {
236         enum fw_sched_params_rate ratemode;     /* %port (REL) or kbps (ABS) */
237         uint32_t maxrate;
238 };
239
240 enum {
241         TX_CLRL_REFRESH = (1 << 0),     /* Need to update hardware state. */
242         TX_CLRL_ERROR   = (1 << 1),     /* Error, hardware state unknown. */
243 };
244
245 struct tx_cl_rl_params {
246         int refcount;
247         u_int flags;
248         enum fw_sched_params_rate ratemode;     /* %port REL or ABS value */
249         enum fw_sched_params_unit rateunit;     /* kbps or pps (when ABS) */
250         enum fw_sched_params_mode mode;         /* aggr or per-flow */
251         uint32_t maxrate;
252         uint16_t pktsize;
253 };
254
255 /* Tx scheduler parameters for a channel/port */
256 struct tx_sched_params {
257         /* Channel Rate Limiter */
258         struct tx_ch_rl_params ch_rl;
259
260         /* Class WRR */
261         /* XXX */
262
263         /* Class Rate Limiter */
264         struct tx_cl_rl_params cl_rl[];
265 };
266
267 struct port_info {
268         device_t dev;
269         struct adapter *adapter;
270
271         struct vi_info *vi;
272         int nvi;
273         int up_vis;
274         int uld_vis;
275
276         struct tx_sched_params *sched_params;
277
278         struct mtx pi_lock;
279         char lockname[16];
280         unsigned long flags;
281
282         uint8_t  lport;         /* associated offload logical port */
283         int8_t   mdio_addr;
284         uint8_t  port_type;
285         uint8_t  mod_type;
286         uint8_t  port_id;
287         uint8_t  tx_chan;
288         uint8_t  rx_chan_map;   /* rx MPS channel bitmap */
289
290         struct link_config link_cfg;
291         struct link_config old_link_cfg;
292         struct ifmedia media;
293
294         struct timeval last_refreshed;
295         struct port_stats stats;
296         u_int tnl_cong_drops;
297         u_int tx_parse_error;
298
299         struct callout tick;
300 };
301
302 #define IS_MAIN_VI(vi)          ((vi) == &((vi)->pi->vi[0]))
303
304 /* Where the cluster came from, how it has been carved up. */
305 struct cluster_layout {
306         int8_t zidx;
307         int8_t hwidx;
308         uint16_t region1;       /* mbufs laid out within this region */
309                                 /* region2 is the DMA region */
310         uint16_t region3;       /* cluster_metadata within this region */
311 };
312
313 struct cluster_metadata {
314         u_int refcount;
315         struct fl_sdesc *sd;    /* For debug only.  Could easily be stale */
316 };
317
318 struct fl_sdesc {
319         caddr_t cl;
320         uint16_t nmbuf; /* # of driver originated mbufs with ref on cluster */
321         struct cluster_layout cll;
322 };
323
324 struct tx_desc {
325         __be64 flit[8];
326 };
327
328 struct tx_sdesc {
329         struct mbuf *m;         /* m_nextpkt linked chain of frames */
330         uint8_t desc_used;      /* # of hardware descriptors used by the WR */
331 };
332
333
334 #define IQ_PAD (IQ_ESIZE - sizeof(struct rsp_ctrl) - sizeof(struct rss_header))
335 struct iq_desc {
336         struct rss_header rss;
337         uint8_t cpl[IQ_PAD];
338         struct rsp_ctrl rsp;
339 };
340 #undef IQ_PAD
341 CTASSERT(sizeof(struct iq_desc) == IQ_ESIZE);
342
343 enum {
344         /* iq flags */
345         IQ_ALLOCATED    = (1 << 0),     /* firmware resources allocated */
346         IQ_HAS_FL       = (1 << 1),     /* iq associated with a freelist */
347         IQ_INTR         = (1 << 2),     /* iq takes direct interrupt */
348         IQ_LRO_ENABLED  = (1 << 3),     /* iq is an eth rxq with LRO enabled */
349         IQ_ADJ_CREDIT   = (1 << 4),     /* hw is off by 1 credit for this iq */
350
351         /* iq state */
352         IQS_DISABLED    = 0,
353         IQS_BUSY        = 1,
354         IQS_IDLE        = 2,
355
356         /* netmap related flags */
357         NM_OFF  = 0,
358         NM_ON   = 1,
359         NM_BUSY = 2,
360 };
361
362 struct sge_iq;
363 struct rss_header;
364 typedef int (*cpl_handler_t)(struct sge_iq *, const struct rss_header *,
365     struct mbuf *);
366 typedef int (*an_handler_t)(struct sge_iq *, const struct rsp_ctrl *);
367 typedef int (*fw_msg_handler_t)(struct adapter *, const __be64 *);
368
369 /*
370  * Ingress Queue: T4 is producer, driver is consumer.
371  */
372 struct sge_iq {
373         uint32_t flags;
374         volatile int state;
375         struct adapter *adapter;
376         cpl_handler_t set_tcb_rpl;
377         cpl_handler_t l2t_write_rpl;
378         struct iq_desc  *desc;  /* KVA of descriptor ring */
379         int8_t   intr_pktc_idx; /* packet count threshold index */
380         uint8_t  gen;           /* generation bit */
381         uint8_t  intr_params;   /* interrupt holdoff parameters */
382         uint8_t  intr_next;     /* XXX: holdoff for next interrupt */
383         uint16_t qsize;         /* size (# of entries) of the queue */
384         uint16_t sidx;          /* index of the entry with the status page */
385         uint16_t cidx;          /* consumer index */
386         uint16_t cntxt_id;      /* SGE context id for the iq */
387         uint16_t abs_id;        /* absolute SGE id for the iq */
388
389         STAILQ_ENTRY(sge_iq) link;
390
391         bus_dma_tag_t desc_tag;
392         bus_dmamap_t desc_map;
393         bus_addr_t ba;          /* bus address of descriptor ring */
394 };
395
396 enum {
397         EQ_CTRL         = 1,
398         EQ_ETH          = 2,
399         EQ_OFLD         = 3,
400
401         /* eq flags */
402         EQ_TYPEMASK     = 0x3,          /* 2 lsbits hold the type (see above) */
403         EQ_ALLOCATED    = (1 << 2),     /* firmware resources allocated */
404         EQ_ENABLED      = (1 << 3),     /* open for business */
405         EQ_QFLUSH       = (1 << 4),     /* if_qflush in progress */
406 };
407
408 /* Listed in order of preference.  Update t4_sysctls too if you change these */
409 enum {DOORBELL_UDB, DOORBELL_WCWR, DOORBELL_UDBWC, DOORBELL_KDB};
410
411 /*
412  * Egress Queue: driver is producer, T4 is consumer.
413  *
414  * Note: A free list is an egress queue (driver produces the buffers and T4
415  * consumes them) but it's special enough to have its own struct (see sge_fl).
416  */
417 struct sge_eq {
418         unsigned int flags;     /* MUST be first */
419         unsigned int cntxt_id;  /* SGE context id for the eq */
420         unsigned int abs_id;    /* absolute SGE id for the eq */
421         struct mtx eq_lock;
422
423         struct tx_desc *desc;   /* KVA of descriptor ring */
424         uint16_t doorbells;
425         volatile uint32_t *udb; /* KVA of doorbell (lies within BAR2) */
426         u_int udb_qid;          /* relative qid within the doorbell page */
427         uint16_t sidx;          /* index of the entry with the status page */
428         uint16_t cidx;          /* consumer idx (desc idx) */
429         uint16_t pidx;          /* producer idx (desc idx) */
430         uint16_t equeqidx;      /* EQUEQ last requested at this pidx */
431         uint16_t dbidx;         /* pidx of the most recent doorbell */
432         uint16_t iqid;          /* iq that gets egr_update for the eq */
433         uint8_t tx_chan;        /* tx channel used by the eq */
434         volatile u_int equiq;   /* EQUIQ outstanding */
435
436         bus_dma_tag_t desc_tag;
437         bus_dmamap_t desc_map;
438         bus_addr_t ba;          /* bus address of descriptor ring */
439         char lockname[16];
440 };
441
442 struct sw_zone_info {
443         uma_zone_t zone;        /* zone that this cluster comes from */
444         int size;               /* size of cluster: 2K, 4K, 9K, 16K, etc. */
445         int type;               /* EXT_xxx type of the cluster */
446         int8_t head_hwidx;
447         int8_t tail_hwidx;
448 };
449
450 struct hw_buf_info {
451         int8_t zidx;            /* backpointer to zone; -ve means unused */
452         int8_t next;            /* next hwidx for this zone; -1 means no more */
453         int size;
454 };
455
456 enum {
457         NUM_MEMWIN = 3,
458
459         MEMWIN0_APERTURE = 2048,
460         MEMWIN0_BASE     = 0x1b800,
461
462         MEMWIN1_APERTURE = 32768,
463         MEMWIN1_BASE     = 0x28000,
464
465         MEMWIN2_APERTURE_T4 = 65536,
466         MEMWIN2_BASE_T4     = 0x30000,
467
468         MEMWIN2_APERTURE_T5 = 128 * 1024,
469         MEMWIN2_BASE_T5     = 0x60000,
470 };
471
472 struct memwin {
473         struct rwlock mw_lock __aligned(CACHE_LINE_SIZE);
474         uint32_t mw_base;       /* constant after setup_memwin */
475         uint32_t mw_aperture;   /* ditto */
476         uint32_t mw_curpos;     /* protected by mw_lock */
477 };
478
479 enum {
480         FL_STARVING     = (1 << 0), /* on the adapter's list of starving fl's */
481         FL_DOOMED       = (1 << 1), /* about to be destroyed */
482         FL_BUF_PACKING  = (1 << 2), /* buffer packing enabled */
483         FL_BUF_RESUME   = (1 << 3), /* resume from the middle of the frame */
484 };
485
486 #define FL_RUNNING_LOW(fl) \
487     (IDXDIFF(fl->dbidx * 8, fl->cidx, fl->sidx * 8) <= fl->lowat)
488 #define FL_NOT_RUNNING_LOW(fl) \
489     (IDXDIFF(fl->dbidx * 8, fl->cidx, fl->sidx * 8) >= 2 * fl->lowat)
490
491 struct sge_fl {
492         struct mtx fl_lock;
493         __be64 *desc;           /* KVA of descriptor ring, ptr to addresses */
494         struct fl_sdesc *sdesc; /* KVA of software descriptor ring */
495         struct cluster_layout cll_def;  /* default refill zone, layout */
496         uint16_t lowat;         /* # of buffers <= this means fl needs help */
497         int flags;
498         uint16_t buf_boundary;
499
500         /* The 16b idx all deal with hw descriptors */
501         uint16_t dbidx;         /* hw pidx after last doorbell */
502         uint16_t sidx;          /* index of status page */
503         volatile uint16_t hw_cidx;
504
505         /* The 32b idx are all buffer idx, not hardware descriptor idx */
506         uint32_t cidx;          /* consumer index */
507         uint32_t pidx;          /* producer index */
508
509         uint32_t dbval;
510         u_int rx_offset;        /* offset in fl buf (when buffer packing) */
511         volatile uint32_t *udb;
512
513         uint64_t mbuf_allocated;/* # of mbuf allocated from zone_mbuf */
514         uint64_t mbuf_inlined;  /* # of mbuf created within clusters */
515         uint64_t cl_allocated;  /* # of clusters allocated */
516         uint64_t cl_recycled;   /* # of clusters recycled */
517         uint64_t cl_fast_recycled; /* # of clusters recycled (fast) */
518
519         /* These 3 are valid when FL_BUF_RESUME is set, stale otherwise. */
520         struct mbuf *m0;
521         struct mbuf **pnext;
522         u_int remaining;
523
524         uint16_t qsize;         /* # of hw descriptors (status page included) */
525         uint16_t cntxt_id;      /* SGE context id for the freelist */
526         TAILQ_ENTRY(sge_fl) link; /* All starving freelists */
527         bus_dma_tag_t desc_tag;
528         bus_dmamap_t desc_map;
529         char lockname[16];
530         bus_addr_t ba;          /* bus address of descriptor ring */
531         struct cluster_layout cll_alt;  /* alternate refill zone, layout */
532 };
533
534 struct mp_ring;
535
536 /* txq: SGE egress queue + what's needed for Ethernet NIC */
537 struct sge_txq {
538         struct sge_eq eq;       /* MUST be first */
539
540         struct ifnet *ifp;      /* the interface this txq belongs to */
541         struct mp_ring *r;      /* tx software ring */
542         struct tx_sdesc *sdesc; /* KVA of software descriptor ring */
543         struct sglist *gl;
544         __be32 cpl_ctrl0;       /* for convenience */
545         int tc_idx;             /* traffic class */
546
547         struct task tx_reclaim_task;
548         /* stats for common events first */
549
550         uint64_t txcsum;        /* # of times hardware assisted with checksum */
551         uint64_t tso_wrs;       /* # of TSO work requests */
552         uint64_t vlan_insertion;/* # of times VLAN tag was inserted */
553         uint64_t imm_wrs;       /* # of work requests with immediate data */
554         uint64_t sgl_wrs;       /* # of work requests with direct SGL */
555         uint64_t txpkt_wrs;     /* # of txpkt work requests (not coalesced) */
556         uint64_t txpkts0_wrs;   /* # of type0 coalesced tx work requests */
557         uint64_t txpkts1_wrs;   /* # of type1 coalesced tx work requests */
558         uint64_t txpkts0_pkts;  /* # of frames in type0 coalesced tx WRs */
559         uint64_t txpkts1_pkts;  /* # of frames in type1 coalesced tx WRs */
560
561         /* stats for not-that-common events */
562 } __aligned(CACHE_LINE_SIZE);
563
564 /* rxq: SGE ingress queue + SGE free list + miscellaneous items */
565 struct sge_rxq {
566         struct sge_iq iq;       /* MUST be first */
567         struct sge_fl fl;       /* MUST follow iq */
568
569         struct ifnet *ifp;      /* the interface this rxq belongs to */
570 #if defined(INET) || defined(INET6)
571         struct lro_ctrl lro;    /* LRO state */
572 #endif
573
574         /* stats for common events first */
575
576         uint64_t rxcsum;        /* # of times hardware assisted with checksum */
577         uint64_t vlan_extraction;/* # of times VLAN tag was extracted */
578
579         /* stats for not-that-common events */
580
581 } __aligned(CACHE_LINE_SIZE);
582
583 static inline struct sge_rxq *
584 iq_to_rxq(struct sge_iq *iq)
585 {
586
587         return (__containerof(iq, struct sge_rxq, iq));
588 }
589
590
591 /* ofld_rxq: SGE ingress queue + SGE free list + miscellaneous items */
592 struct sge_ofld_rxq {
593         struct sge_iq iq;       /* MUST be first */
594         struct sge_fl fl;       /* MUST follow iq */
595 } __aligned(CACHE_LINE_SIZE);
596
597 static inline struct sge_ofld_rxq *
598 iq_to_ofld_rxq(struct sge_iq *iq)
599 {
600
601         return (__containerof(iq, struct sge_ofld_rxq, iq));
602 }
603
604 struct wrqe {
605         STAILQ_ENTRY(wrqe) link;
606         struct sge_wrq *wrq;
607         int wr_len;
608         char wr[] __aligned(16);
609 };
610
611 struct wrq_cookie {
612         TAILQ_ENTRY(wrq_cookie) link;
613         int ndesc;
614         int pidx;
615 };
616
617 /*
618  * wrq: SGE egress queue that is given prebuilt work requests.  Both the control
619  * and offload tx queues are of this type.
620  */
621 struct sge_wrq {
622         struct sge_eq eq;       /* MUST be first */
623
624         struct adapter *adapter;
625         struct task wrq_tx_task;
626
627         /* Tx desc reserved but WR not "committed" yet. */
628         TAILQ_HEAD(wrq_incomplete_wrs , wrq_cookie) incomplete_wrs;
629
630         /* List of WRs ready to go out as soon as descriptors are available. */
631         STAILQ_HEAD(, wrqe) wr_list;
632         u_int nwr_pending;
633         u_int ndesc_needed;
634
635         /* stats for common events first */
636
637         uint64_t tx_wrs_direct; /* # of WRs written directly to desc ring. */
638         uint64_t tx_wrs_ss;     /* # of WRs copied from scratch space. */
639         uint64_t tx_wrs_copied; /* # of WRs queued and copied to desc ring. */
640
641         /* stats for not-that-common events */
642
643         /*
644          * Scratch space for work requests that wrap around after reaching the
645          * status page, and some information about the last WR that used it.
646          */
647         uint16_t ss_pidx;
648         uint16_t ss_len;
649         uint8_t ss[SGE_MAX_WR_LEN];
650
651 } __aligned(CACHE_LINE_SIZE);
652
653 #define INVALID_NM_RXQ_CNTXT_ID ((uint16_t)(-1))
654 struct sge_nm_rxq {
655         struct vi_info *vi;
656
657         struct iq_desc *iq_desc;
658         uint16_t iq_abs_id;
659         uint16_t iq_cntxt_id;
660         uint16_t iq_cidx;
661         uint16_t iq_sidx;
662         uint8_t iq_gen;
663
664         __be64  *fl_desc;
665         uint16_t fl_cntxt_id;
666         uint32_t fl_cidx;
667         uint32_t fl_pidx;
668         uint32_t fl_sidx;
669         uint32_t fl_db_val;
670         u_int fl_hwidx:4;
671
672         u_int nid;              /* netmap ring # for this queue */
673
674         /* infrequently used items after this */
675
676         bus_dma_tag_t iq_desc_tag;
677         bus_dmamap_t iq_desc_map;
678         bus_addr_t iq_ba;
679         int intr_idx;
680
681         bus_dma_tag_t fl_desc_tag;
682         bus_dmamap_t fl_desc_map;
683         bus_addr_t fl_ba;
684 } __aligned(CACHE_LINE_SIZE);
685
686 #define INVALID_NM_TXQ_CNTXT_ID ((u_int)(-1))
687 struct sge_nm_txq {
688         struct tx_desc *desc;
689         uint16_t cidx;
690         uint16_t pidx;
691         uint16_t sidx;
692         uint16_t equiqidx;      /* EQUIQ last requested at this pidx */
693         uint16_t equeqidx;      /* EQUEQ last requested at this pidx */
694         uint16_t dbidx;         /* pidx of the most recent doorbell */
695         uint16_t doorbells;
696         volatile uint32_t *udb;
697         u_int udb_qid;
698         u_int cntxt_id;
699         __be32 cpl_ctrl0;       /* for convenience */
700         u_int nid;              /* netmap ring # for this queue */
701
702         /* infrequently used items after this */
703
704         bus_dma_tag_t desc_tag;
705         bus_dmamap_t desc_map;
706         bus_addr_t ba;
707         int iqidx;
708 } __aligned(CACHE_LINE_SIZE);
709
710 struct sge {
711         int nrxq;       /* total # of Ethernet rx queues */
712         int ntxq;       /* total # of Ethernet tx queues */
713         int nofldrxq;   /* total # of TOE rx queues */
714         int nofldtxq;   /* total # of TOE tx queues */
715         int nnmrxq;     /* total # of netmap rx queues */
716         int nnmtxq;     /* total # of netmap tx queues */
717         int niq;        /* total # of ingress queues */
718         int neq;        /* total # of egress queues */
719
720         struct sge_iq fwq;      /* Firmware event queue */
721         struct sge_wrq mgmtq;   /* Management queue (control queue) */
722         struct sge_wrq *ctrlq;  /* Control queues */
723         struct sge_txq *txq;    /* NIC tx queues */
724         struct sge_rxq *rxq;    /* NIC rx queues */
725         struct sge_wrq *ofld_txq;       /* TOE tx queues */
726         struct sge_ofld_rxq *ofld_rxq;  /* TOE rx queues */
727         struct sge_nm_txq *nm_txq;      /* netmap tx queues */
728         struct sge_nm_rxq *nm_rxq;      /* netmap rx queues */
729
730         uint16_t iq_start;      /* first cntxt_id */
731         uint16_t iq_base;       /* first abs_id */
732         int eq_start;           /* first cntxt_id */
733         int eq_base;            /* first abs_id */
734         struct sge_iq **iqmap;  /* iq->cntxt_id to iq mapping */
735         struct sge_eq **eqmap;  /* eq->cntxt_id to eq mapping */
736
737         int8_t safe_hwidx1;     /* may not have room for metadata */
738         int8_t safe_hwidx2;     /* with room for metadata and maybe more */
739         struct sw_zone_info sw_zone_info[SW_ZONE_SIZES];
740         struct hw_buf_info hw_buf_info[SGE_FLBUF_SIZES];
741 };
742
743 struct devnames {
744         const char *nexus_name;
745         const char *ifnet_name;
746         const char *vi_ifnet_name;
747         const char *pf03_drv_name;
748         const char *vf_nexus_name;
749         const char *vf_ifnet_name;
750 };
751
752 struct adapter {
753         SLIST_ENTRY(adapter) link;
754         device_t dev;
755         struct cdev *cdev;
756         const struct devnames *names;
757
758         /* PCIe register resources */
759         int regs_rid;
760         struct resource *regs_res;
761         int msix_rid;
762         struct resource *msix_res;
763         bus_space_handle_t bh;
764         bus_space_tag_t bt;
765         bus_size_t mmio_len;
766         int udbs_rid;
767         struct resource *udbs_res;
768         volatile uint8_t *udbs_base;
769
770         unsigned int pf;
771         unsigned int mbox;
772         unsigned int vpd_busy;
773         unsigned int vpd_flag;
774
775         /* Interrupt information */
776         int intr_type;
777         int intr_count;
778         struct irq {
779                 struct resource *res;
780                 int rid;
781                 volatile int nm_state;  /* NM_OFF, NM_ON, or NM_BUSY */
782                 void *tag;
783                 struct sge_rxq *rxq;
784                 struct sge_nm_rxq *nm_rxq;
785         } __aligned(CACHE_LINE_SIZE) *irq;
786         int sge_gts_reg;
787         int sge_kdoorbell_reg;
788
789         bus_dma_tag_t dmat;     /* Parent DMA tag */
790
791         struct sge sge;
792         int lro_timeout;
793         int sc_do_rxcopy;
794
795         struct taskqueue *tq[MAX_NCHAN];        /* General purpose taskqueues */
796         struct port_info *port[MAX_NPORTS];
797         uint8_t chan_map[MAX_NCHAN];
798
799         void *tom_softc;        /* (struct tom_data *) */
800         struct tom_tunables tt;
801         void *iwarp_softc;      /* (struct c4iw_dev *) */
802         void *iscsi_ulp_softc;  /* (struct cxgbei_data *) */
803         void *ccr_softc;        /* (struct ccr_softc *) */
804         struct l2t_data *l2t;   /* L2 table */
805         struct tid_info tids;
806
807         uint16_t doorbells;
808         int offload_map;        /* ports with IFCAP_TOE enabled */
809         int active_ulds;        /* ULDs activated on this adapter */
810         int flags;
811         int debug_flags;
812
813         char ifp_lockname[16];
814         struct mtx ifp_lock;
815         struct ifnet *ifp;      /* tracer ifp */
816         struct ifmedia media;
817         int traceq;             /* iq used by all tracers, -1 if none */
818         int tracer_valid;       /* bitmap of valid tracers */
819         int tracer_enabled;     /* bitmap of enabled tracers */
820
821         char fw_version[16];
822         char tp_version[16];
823         char er_version[16];
824         char bs_version[16];
825         char cfg_file[32];
826         u_int cfcsum;
827         struct adapter_params params;
828         const struct chip_params *chip_params;
829         struct t4_virt_res vres;
830
831         uint16_t nbmcaps;
832         uint16_t linkcaps;
833         uint16_t switchcaps;
834         uint16_t niccaps;
835         uint16_t toecaps;
836         uint16_t rdmacaps;
837         uint16_t cryptocaps;
838         uint16_t iscsicaps;
839         uint16_t fcoecaps;
840
841         struct sysctl_ctx_list ctx; /* from adapter_full_init to full_uninit */
842
843         struct mtx sc_lock;
844         char lockname[16];
845
846         /* Starving free lists */
847         struct mtx sfl_lock;    /* same cache-line as sc_lock? but that's ok */
848         TAILQ_HEAD(, sge_fl) sfl;
849         struct callout sfl_callout;
850
851         struct mtx reg_lock;    /* for indirect register access */
852
853         struct memwin memwin[NUM_MEMWIN];       /* memory windows */
854
855         struct mtx tc_lock;
856         struct task tc_task;
857
858         const char *last_op;
859         const void *last_op_thr;
860         int last_op_flags;
861 };
862
863 #define ADAPTER_LOCK(sc)                mtx_lock(&(sc)->sc_lock)
864 #define ADAPTER_UNLOCK(sc)              mtx_unlock(&(sc)->sc_lock)
865 #define ADAPTER_LOCK_ASSERT_OWNED(sc)   mtx_assert(&(sc)->sc_lock, MA_OWNED)
866 #define ADAPTER_LOCK_ASSERT_NOTOWNED(sc) mtx_assert(&(sc)->sc_lock, MA_NOTOWNED)
867
868 #define ASSERT_SYNCHRONIZED_OP(sc)      \
869     KASSERT(IS_BUSY(sc) && \
870         (mtx_owned(&(sc)->sc_lock) || sc->last_op_thr == curthread), \
871         ("%s: operation not synchronized.", __func__))
872
873 #define PORT_LOCK(pi)                   mtx_lock(&(pi)->pi_lock)
874 #define PORT_UNLOCK(pi)                 mtx_unlock(&(pi)->pi_lock)
875 #define PORT_LOCK_ASSERT_OWNED(pi)      mtx_assert(&(pi)->pi_lock, MA_OWNED)
876 #define PORT_LOCK_ASSERT_NOTOWNED(pi)   mtx_assert(&(pi)->pi_lock, MA_NOTOWNED)
877
878 #define FL_LOCK(fl)                     mtx_lock(&(fl)->fl_lock)
879 #define FL_TRYLOCK(fl)                  mtx_trylock(&(fl)->fl_lock)
880 #define FL_UNLOCK(fl)                   mtx_unlock(&(fl)->fl_lock)
881 #define FL_LOCK_ASSERT_OWNED(fl)        mtx_assert(&(fl)->fl_lock, MA_OWNED)
882 #define FL_LOCK_ASSERT_NOTOWNED(fl)     mtx_assert(&(fl)->fl_lock, MA_NOTOWNED)
883
884 #define RXQ_FL_LOCK(rxq)                FL_LOCK(&(rxq)->fl)
885 #define RXQ_FL_UNLOCK(rxq)              FL_UNLOCK(&(rxq)->fl)
886 #define RXQ_FL_LOCK_ASSERT_OWNED(rxq)   FL_LOCK_ASSERT_OWNED(&(rxq)->fl)
887 #define RXQ_FL_LOCK_ASSERT_NOTOWNED(rxq) FL_LOCK_ASSERT_NOTOWNED(&(rxq)->fl)
888
889 #define EQ_LOCK(eq)                     mtx_lock(&(eq)->eq_lock)
890 #define EQ_TRYLOCK(eq)                  mtx_trylock(&(eq)->eq_lock)
891 #define EQ_UNLOCK(eq)                   mtx_unlock(&(eq)->eq_lock)
892 #define EQ_LOCK_ASSERT_OWNED(eq)        mtx_assert(&(eq)->eq_lock, MA_OWNED)
893 #define EQ_LOCK_ASSERT_NOTOWNED(eq)     mtx_assert(&(eq)->eq_lock, MA_NOTOWNED)
894
895 #define TXQ_LOCK(txq)                   EQ_LOCK(&(txq)->eq)
896 #define TXQ_TRYLOCK(txq)                EQ_TRYLOCK(&(txq)->eq)
897 #define TXQ_UNLOCK(txq)                 EQ_UNLOCK(&(txq)->eq)
898 #define TXQ_LOCK_ASSERT_OWNED(txq)      EQ_LOCK_ASSERT_OWNED(&(txq)->eq)
899 #define TXQ_LOCK_ASSERT_NOTOWNED(txq)   EQ_LOCK_ASSERT_NOTOWNED(&(txq)->eq)
900
901 #define CH_DUMP_MBOX(sc, mbox, data_reg) \
902         do { \
903                 if (sc->debug_flags & DF_DUMP_MBOX) { \
904                         log(LOG_NOTICE, \
905                             "%s mbox %u: %016llx %016llx %016llx %016llx " \
906                             "%016llx %016llx %016llx %016llx\n", \
907                             device_get_nameunit(sc->dev), mbox, \
908                             (unsigned long long)t4_read_reg64(sc, data_reg), \
909                             (unsigned long long)t4_read_reg64(sc, data_reg + 8), \
910                             (unsigned long long)t4_read_reg64(sc, data_reg + 16), \
911                             (unsigned long long)t4_read_reg64(sc, data_reg + 24), \
912                             (unsigned long long)t4_read_reg64(sc, data_reg + 32), \
913                             (unsigned long long)t4_read_reg64(sc, data_reg + 40), \
914                             (unsigned long long)t4_read_reg64(sc, data_reg + 48), \
915                             (unsigned long long)t4_read_reg64(sc, data_reg + 56)); \
916                 } \
917         } while (0)
918
919 #define for_each_txq(vi, iter, q) \
920         for (q = &vi->pi->adapter->sge.txq[vi->first_txq], iter = 0; \
921             iter < vi->ntxq; ++iter, ++q)
922 #define for_each_rxq(vi, iter, q) \
923         for (q = &vi->pi->adapter->sge.rxq[vi->first_rxq], iter = 0; \
924             iter < vi->nrxq; ++iter, ++q)
925 #define for_each_ofld_txq(vi, iter, q) \
926         for (q = &vi->pi->adapter->sge.ofld_txq[vi->first_ofld_txq], iter = 0; \
927             iter < vi->nofldtxq; ++iter, ++q)
928 #define for_each_ofld_rxq(vi, iter, q) \
929         for (q = &vi->pi->adapter->sge.ofld_rxq[vi->first_ofld_rxq], iter = 0; \
930             iter < vi->nofldrxq; ++iter, ++q)
931 #define for_each_nm_txq(vi, iter, q) \
932         for (q = &vi->pi->adapter->sge.nm_txq[vi->first_nm_txq], iter = 0; \
933             iter < vi->nnmtxq; ++iter, ++q)
934 #define for_each_nm_rxq(vi, iter, q) \
935         for (q = &vi->pi->adapter->sge.nm_rxq[vi->first_nm_rxq], iter = 0; \
936             iter < vi->nnmrxq; ++iter, ++q)
937 #define for_each_vi(_pi, _iter, _vi) \
938         for ((_vi) = (_pi)->vi, (_iter) = 0; (_iter) < (_pi)->nvi; \
939              ++(_iter), ++(_vi))
940
941 #define IDXINCR(idx, incr, wrap) do { \
942         idx = wrap - idx > incr ? idx + incr : incr - (wrap - idx); \
943 } while (0)
944 #define IDXDIFF(head, tail, wrap) \
945         ((head) >= (tail) ? (head) - (tail) : (wrap) - (tail) + (head))
946
947 /* One for errors, one for firmware events */
948 #define T4_EXTRA_INTR 2
949
950 /* One for firmware events */
951 #define T4VF_EXTRA_INTR 1
952
953 static inline uint32_t
954 t4_read_reg(struct adapter *sc, uint32_t reg)
955 {
956
957         return bus_space_read_4(sc->bt, sc->bh, reg);
958 }
959
960 static inline void
961 t4_write_reg(struct adapter *sc, uint32_t reg, uint32_t val)
962 {
963
964         bus_space_write_4(sc->bt, sc->bh, reg, val);
965 }
966
967 static inline uint64_t
968 t4_read_reg64(struct adapter *sc, uint32_t reg)
969 {
970
971 #ifdef __LP64__
972         return bus_space_read_8(sc->bt, sc->bh, reg);
973 #else
974         return (uint64_t)bus_space_read_4(sc->bt, sc->bh, reg) +
975             ((uint64_t)bus_space_read_4(sc->bt, sc->bh, reg + 4) << 32);
976
977 #endif
978 }
979
980 static inline void
981 t4_write_reg64(struct adapter *sc, uint32_t reg, uint64_t val)
982 {
983
984 #ifdef __LP64__
985         bus_space_write_8(sc->bt, sc->bh, reg, val);
986 #else
987         bus_space_write_4(sc->bt, sc->bh, reg, val);
988         bus_space_write_4(sc->bt, sc->bh, reg + 4, val>> 32);
989 #endif
990 }
991
992 static inline void
993 t4_os_pci_read_cfg1(struct adapter *sc, int reg, uint8_t *val)
994 {
995
996         *val = pci_read_config(sc->dev, reg, 1);
997 }
998
999 static inline void
1000 t4_os_pci_write_cfg1(struct adapter *sc, int reg, uint8_t val)
1001 {
1002
1003         pci_write_config(sc->dev, reg, val, 1);
1004 }
1005
1006 static inline void
1007 t4_os_pci_read_cfg2(struct adapter *sc, int reg, uint16_t *val)
1008 {
1009
1010         *val = pci_read_config(sc->dev, reg, 2);
1011 }
1012
1013 static inline void
1014 t4_os_pci_write_cfg2(struct adapter *sc, int reg, uint16_t val)
1015 {
1016
1017         pci_write_config(sc->dev, reg, val, 2);
1018 }
1019
1020 static inline void
1021 t4_os_pci_read_cfg4(struct adapter *sc, int reg, uint32_t *val)
1022 {
1023
1024         *val = pci_read_config(sc->dev, reg, 4);
1025 }
1026
1027 static inline void
1028 t4_os_pci_write_cfg4(struct adapter *sc, int reg, uint32_t val)
1029 {
1030
1031         pci_write_config(sc->dev, reg, val, 4);
1032 }
1033
1034 static inline struct port_info *
1035 adap2pinfo(struct adapter *sc, int idx)
1036 {
1037
1038         return (sc->port[idx]);
1039 }
1040
1041 static inline void
1042 t4_os_set_hw_addr(struct port_info *pi, uint8_t hw_addr[])
1043 {
1044
1045         bcopy(hw_addr, pi->vi[0].hw_addr, ETHER_ADDR_LEN);
1046 }
1047
1048 static inline bool
1049 is_10G_port(const struct port_info *pi)
1050 {
1051
1052         return ((pi->link_cfg.supported & FW_PORT_CAP_SPEED_10G) != 0);
1053 }
1054
1055 static inline bool
1056 is_25G_port(const struct port_info *pi)
1057 {
1058
1059         return ((pi->link_cfg.supported & FW_PORT_CAP_SPEED_25G) != 0);
1060 }
1061
1062 static inline bool
1063 is_40G_port(const struct port_info *pi)
1064 {
1065
1066         return ((pi->link_cfg.supported & FW_PORT_CAP_SPEED_40G) != 0);
1067 }
1068
1069 static inline bool
1070 is_100G_port(const struct port_info *pi)
1071 {
1072
1073         return ((pi->link_cfg.supported & FW_PORT_CAP_SPEED_100G) != 0);
1074 }
1075
1076 static inline int
1077 port_top_speed(const struct port_info *pi)
1078 {
1079
1080         if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_100G)
1081                 return (100);
1082         if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_40G)
1083                 return (40);
1084         if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_25G)
1085                 return (25);
1086         if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_10G)
1087                 return (10);
1088         if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_1G)
1089                 return (1);
1090
1091         return (0);
1092 }
1093
1094 static inline int
1095 tx_resume_threshold(struct sge_eq *eq)
1096 {
1097
1098         /* not quite the same as qsize / 4, but this will do. */
1099         return (eq->sidx / 4);
1100 }
1101
1102 static inline int
1103 t4_use_ldst(struct adapter *sc)
1104 {
1105
1106 #ifdef notyet
1107         return (sc->flags & FW_OK || !sc->use_bd);
1108 #else
1109         return (0);
1110 #endif
1111 }
1112
1113 /* t4_main.c */
1114 extern int t4_ntxq10g;
1115 extern int t4_nrxq10g;
1116 extern int t4_ntxq1g;
1117 extern int t4_nrxq1g;
1118 extern int t4_intr_types;
1119 extern int t4_tmr_idx_10g;
1120 extern int t4_pktc_idx_10g;
1121 extern int t4_tmr_idx_1g;
1122 extern int t4_pktc_idx_1g;
1123 extern unsigned int t4_qsize_rxq;
1124 extern unsigned int t4_qsize_txq;
1125 extern device_method_t cxgbe_methods[];
1126
1127 int t4_os_find_pci_capability(struct adapter *, int);
1128 int t4_os_pci_save_state(struct adapter *);
1129 int t4_os_pci_restore_state(struct adapter *);
1130 void t4_os_portmod_changed(struct port_info *);
1131 void t4_os_link_changed(struct port_info *);
1132 void t4_iterate(void (*)(struct adapter *, void *), void *);
1133 void t4_init_devnames(struct adapter *);
1134 void t4_add_adapter(struct adapter *);
1135 int t4_detach_common(device_t);
1136 int t4_filter_rpl(struct sge_iq *, const struct rss_header *, struct mbuf *);
1137 int t4_map_bars_0_and_4(struct adapter *);
1138 int t4_map_bar_2(struct adapter *);
1139 int t4_setup_intr_handlers(struct adapter *);
1140 void t4_sysctls(struct adapter *);
1141 int begin_synchronized_op(struct adapter *, struct vi_info *, int, char *);
1142 void doom_vi(struct adapter *, struct vi_info *);
1143 void end_synchronized_op(struct adapter *, int);
1144 int update_mac_settings(struct ifnet *, int);
1145 int adapter_full_init(struct adapter *);
1146 int adapter_full_uninit(struct adapter *);
1147 uint64_t cxgbe_get_counter(struct ifnet *, ift_counter);
1148 int vi_full_init(struct vi_info *);
1149 int vi_full_uninit(struct vi_info *);
1150 void vi_sysctls(struct vi_info *);
1151 void vi_tick(void *);
1152
1153 #ifdef DEV_NETMAP
1154 /* t4_netmap.c */
1155 void cxgbe_nm_attach(struct vi_info *);
1156 void cxgbe_nm_detach(struct vi_info *);
1157 void t4_nm_intr(void *);
1158 #endif
1159
1160 /* t4_sge.c */
1161 void t4_sge_modload(void);
1162 void t4_sge_modunload(void);
1163 uint64_t t4_sge_extfree_refs(void);
1164 void t4_tweak_chip_settings(struct adapter *);
1165 int t4_read_chip_settings(struct adapter *);
1166 int t4_create_dma_tag(struct adapter *);
1167 void t4_sge_sysctls(struct adapter *, struct sysctl_ctx_list *,
1168     struct sysctl_oid_list *);
1169 int t4_destroy_dma_tag(struct adapter *);
1170 int t4_setup_adapter_queues(struct adapter *);
1171 int t4_teardown_adapter_queues(struct adapter *);
1172 int t4_setup_vi_queues(struct vi_info *);
1173 int t4_teardown_vi_queues(struct vi_info *);
1174 void t4_intr_all(void *);
1175 void t4_intr(void *);
1176 void t4_vi_intr(void *);
1177 void t4_intr_err(void *);
1178 void t4_intr_evt(void *);
1179 void t4_wrq_tx_locked(struct adapter *, struct sge_wrq *, struct wrqe *);
1180 void t4_update_fl_bufsize(struct ifnet *);
1181 int parse_pkt(struct adapter *, struct mbuf **);
1182 void *start_wrq_wr(struct sge_wrq *, int, struct wrq_cookie *);
1183 void commit_wrq_wr(struct sge_wrq *, void *, struct wrq_cookie *);
1184 int tnl_cong(struct port_info *, int);
1185 int t4_register_an_handler(an_handler_t);
1186 int t4_register_fw_msg_handler(int, fw_msg_handler_t);
1187 int t4_register_cpl_handler(int, cpl_handler_t);
1188
1189 /* t4_tracer.c */
1190 struct t4_tracer;
1191 void t4_tracer_modload(void);
1192 void t4_tracer_modunload(void);
1193 void t4_tracer_port_detach(struct adapter *);
1194 int t4_get_tracer(struct adapter *, struct t4_tracer *);
1195 int t4_set_tracer(struct adapter *, struct t4_tracer *);
1196 int t4_trace_pkt(struct sge_iq *, const struct rss_header *, struct mbuf *);
1197 int t5_trace_pkt(struct sge_iq *, const struct rss_header *, struct mbuf *);
1198
1199 /* t4_sched.c */
1200 int t4_set_sched_class(struct adapter *, struct t4_sched_params *);
1201 int t4_set_sched_queue(struct adapter *, struct t4_sched_queue *);
1202 int t4_init_tx_sched(struct adapter *);
1203 int t4_free_tx_sched(struct adapter *);
1204 void t4_update_tx_sched(struct adapter *);
1205 int t4_reserve_cl_rl_kbps(struct adapter *, int, u_int, int *);
1206 void t4_release_cl_rl_kbps(struct adapter *, int, int);
1207
1208 static inline struct wrqe *
1209 alloc_wrqe(int wr_len, struct sge_wrq *wrq)
1210 {
1211         int len = offsetof(struct wrqe, wr) + wr_len;
1212         struct wrqe *wr;
1213
1214         wr = malloc(len, M_CXGBE, M_NOWAIT);
1215         if (__predict_false(wr == NULL))
1216                 return (NULL);
1217         wr->wr_len = wr_len;
1218         wr->wrq = wrq;
1219         return (wr);
1220 }
1221
1222 static inline void *
1223 wrtod(struct wrqe *wr)
1224 {
1225         return (&wr->wr[0]);
1226 }
1227
1228 static inline void
1229 free_wrqe(struct wrqe *wr)
1230 {
1231         free(wr, M_CXGBE);
1232 }
1233
1234 static inline void
1235 t4_wrq_tx(struct adapter *sc, struct wrqe *wr)
1236 {
1237         struct sge_wrq *wrq = wr->wrq;
1238
1239         TXQ_LOCK(wrq);
1240         t4_wrq_tx_locked(sc, wrq, wr);
1241         TXQ_UNLOCK(wrq);
1242 }
1243
1244 #endif