net/cxgbe: add control queue to communicate filter requests
[dpdk.git] / drivers / net / cxgbe / base / adapter.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2018 Chelsio Communications.
3  * All rights reserved.
4  */
5
6 /* This file should not be included directly.  Include common.h instead. */
7
8 #ifndef __T4_ADAPTER_H__
9 #define __T4_ADAPTER_H__
10
11 #include <rte_bus_pci.h>
12 #include <rte_mbuf.h>
13 #include <rte_io.h>
14 #include <rte_ethdev.h>
15
16 #include "cxgbe_compat.h"
17 #include "t4_regs_values.h"
18 #include "cxgbe_ofld.h"
19
20 enum {
21         MAX_ETH_QSETS = 64,           /* # of Ethernet Tx/Rx queue sets */
22         MAX_CTRL_QUEUES = NCHAN,      /* # of control Tx queues */
23 };
24
25 struct adapter;
26 struct sge_rspq;
27
28 enum {
29         PORT_RSS_DONE = (1 << 0),
30 };
31
32 struct port_info {
33         struct adapter *adapter;        /* adapter that this port belongs to */
34         struct rte_eth_dev *eth_dev;    /* associated rte eth device */
35         struct port_stats stats_base;   /* port statistics base */
36         struct link_config link_cfg;    /* link configuration info */
37
38         unsigned long flags;            /* port related flags */
39         short int xact_addr_filt;       /* index of exact MAC address filter */
40
41         u16    viid;                    /* associated virtual interface id */
42         s8     mdio_addr;               /* address of the PHY */
43         u8     port_type;               /* firmware port type */
44         u8     mod_type;                /* firmware module type */
45         u8     port_id;                 /* physical port ID */
46         u8     pidx;                    /* port index for this PF */
47         u8     tx_chan;                 /* associated channel */
48
49         u8     n_rx_qsets;              /* # of rx qsets */
50         u8     n_tx_qsets;              /* # of tx qsets */
51         u8     first_qset;              /* index of first qset */
52
53         u16    *rss;                    /* rss table */
54         u8     rss_mode;                /* rss mode */
55         u16    rss_size;                /* size of VI's RSS table slice */
56         u64    rss_hf;                  /* RSS Hash Function */
57 };
58
59 /* Enable or disable autonegotiation.  If this is set to enable,
60  * the forced link modes above are completely ignored.
61  */
62 #define AUTONEG_DISABLE         0x00
63 #define AUTONEG_ENABLE          0x01
64
65 enum {                                 /* adapter flags */
66         FULL_INIT_DONE     = (1 << 0),
67         USING_MSI          = (1 << 1),
68         USING_MSIX         = (1 << 2),
69         FW_QUEUE_BOUND     = (1 << 3),
70         FW_OK              = (1 << 4),
71         CFG_QUEUES         = (1 << 5),
72         MASTER_PF          = (1 << 6),
73 };
74
75 struct rx_sw_desc {                /* SW state per Rx descriptor */
76         void *buf;                 /* struct page or mbuf */
77         dma_addr_t dma_addr;
78 };
79
80 struct sge_fl {                     /* SGE free-buffer queue state */
81         /* RO fields */
82         struct rx_sw_desc *sdesc;   /* address of SW Rx descriptor ring */
83
84         dma_addr_t addr;            /* bus address of HW ring start */
85         __be64 *desc;               /* address of HW Rx descriptor ring */
86
87         void __iomem *bar2_addr;    /* address of BAR2 Queue registers */
88         unsigned int bar2_qid;      /* Queue ID for BAR2 Queue registers */
89
90         unsigned int cntxt_id;      /* SGE relative QID for the free list */
91         unsigned int size;          /* capacity of free list */
92
93         unsigned int avail;         /* # of available Rx buffers */
94         unsigned int pend_cred;     /* new buffers since last FL DB ring */
95         unsigned int cidx;          /* consumer index */
96         unsigned int pidx;          /* producer index */
97
98         unsigned long alloc_failed; /* # of times buffer allocation failed */
99         unsigned long low;          /* # of times momentarily starving */
100 };
101
102 #define MAX_MBUF_FRAGS (16384 / 512 + 2)
103
104 /* A packet gather list */
105 struct pkt_gl {
106         union {
107                 struct rte_mbuf *mbufs[MAX_MBUF_FRAGS];
108         } /* UNNAMED */;
109         void *va;                         /* virtual address of first byte */
110         unsigned int nfrags;              /* # of fragments */
111         unsigned int tot_len;             /* total length of fragments */
112         bool usembufs;                    /* use mbufs for fragments */
113 };
114
115 typedef int (*rspq_handler_t)(struct sge_rspq *q, const __be64 *rsp,
116                               const struct pkt_gl *gl);
117
118 struct sge_rspq {                   /* state for an SGE response queue */
119         struct adapter *adapter;      /* adapter that this queue belongs to */
120         struct rte_eth_dev *eth_dev;  /* associated rte eth device */
121         struct rte_mempool  *mb_pool; /* associated mempool */
122
123         dma_addr_t phys_addr;       /* physical address of the ring */
124         __be64 *desc;               /* address of HW response ring */
125         const __be64 *cur_desc;     /* current descriptor in queue */
126
127         void __iomem *bar2_addr;    /* address of BAR2 Queue registers */
128         unsigned int bar2_qid;      /* Queue ID for BAR2 Queue registers */
129         struct sge_qstat *stat;
130
131         unsigned int cidx;          /* consumer index */
132         unsigned int gts_idx;       /* last gts write sent */
133         unsigned int iqe_len;       /* entry size */
134         unsigned int size;          /* capacity of response queue */
135         int offset;                 /* offset into current Rx buffer */
136
137         u8 gen;                     /* current generation bit */
138         u8 intr_params;             /* interrupt holdoff parameters */
139         u8 next_intr_params;        /* holdoff params for next interrupt */
140         u8 pktcnt_idx;              /* interrupt packet threshold */
141         u8 port_id;                 /* associated port-id */
142         u8 idx;                     /* queue index within its group */
143         u16 cntxt_id;               /* SGE relative QID for the response Q */
144         u16 abs_id;                 /* absolute SGE id for the response q */
145
146         rspq_handler_t handler;     /* associated handler for this response q */
147 };
148
149 struct sge_eth_rx_stats {       /* Ethernet rx queue statistics */
150         u64 pkts;               /* # of ethernet packets */
151         u64 rx_bytes;           /* # of ethernet bytes */
152         u64 rx_cso;             /* # of Rx checksum offloads */
153         u64 vlan_ex;            /* # of Rx VLAN extractions */
154         u64 rx_drops;           /* # of packets dropped due to no mem */
155 };
156
157 struct sge_eth_rxq {                /* a SW Ethernet Rx queue */
158         struct sge_rspq rspq;
159         struct sge_fl fl;
160         struct sge_eth_rx_stats stats;
161         bool usembufs;               /* one ingress packet per mbuf FL buffer */
162 } __rte_cache_aligned;
163
164 /*
165  * Currently there are two types of coalesce WR. Type 0 needs 48 bytes per
166  * packet (if one sgl is present) and type 1 needs 32 bytes. This means
167  * that type 0 can fit a maximum of 10 packets per WR and type 1 can fit
168  * 15 packets. We need to keep track of the mbuf pointers in a coalesce WR
169  * to be able to free those mbufs when we get completions back from the FW.
170  * Allocating the maximum number of pointers in every tx desc is a waste
171  * of memory resources so we only store 2 pointers per tx desc which should
172  * be enough since a tx desc can only fit 2 packets in the best case
173  * scenario where a packet needs 32 bytes.
174  */
175 #define ETH_COALESCE_PKT_NUM 15
176 #define ETH_COALESCE_VF_PKT_NUM 7
177 #define ETH_COALESCE_PKT_PER_DESC 2
178
179 struct tx_eth_coal_desc {
180         struct rte_mbuf *mbuf[ETH_COALESCE_PKT_PER_DESC];
181         struct ulptx_sgl *sgl[ETH_COALESCE_PKT_PER_DESC];
182         int idx;
183 };
184
185 struct tx_desc {
186         __be64 flit[8];
187 };
188
189 struct tx_sw_desc {                /* SW state per Tx descriptor */
190         struct rte_mbuf *mbuf;
191         struct ulptx_sgl *sgl;
192         struct tx_eth_coal_desc coalesce;
193 };
194
195 enum {
196         EQ_STOPPED = (1 << 0),
197 };
198
199 struct eth_coalesce {
200         unsigned char *ptr;
201         unsigned char type;
202         unsigned int idx;
203         unsigned int len;
204         unsigned int flits;
205         unsigned int max;
206         __u8 ethmacdst[ETHER_ADDR_LEN];
207         __u8 ethmacsrc[ETHER_ADDR_LEN];
208         __be16 ethtype;
209         __be16 vlantci;
210 };
211
212 struct sge_txq {
213         struct tx_desc *desc;       /* address of HW Tx descriptor ring */
214         struct tx_sw_desc *sdesc;   /* address of SW Tx descriptor ring */
215         struct sge_qstat *stat;     /* queue status entry */
216         struct eth_coalesce coalesce; /* coalesce info */
217
218         uint64_t phys_addr;         /* physical address of the ring */
219
220         void __iomem *bar2_addr;    /* address of BAR2 Queue registers */
221         unsigned int bar2_qid;      /* Queue ID for BAR2 Queue registers */
222
223         unsigned int cntxt_id;     /* SGE relative QID for the Tx Q */
224         unsigned int in_use;       /* # of in-use Tx descriptors */
225         unsigned int size;         /* # of descriptors */
226         unsigned int cidx;         /* SW consumer index */
227         unsigned int pidx;         /* producer index */
228         unsigned int dbidx;        /* last idx when db ring was done */
229         unsigned int equeidx;      /* last sent credit request */
230         unsigned int last_pidx;    /* last pidx recorded by tx monitor */
231         unsigned int last_coal_idx;/* last coal-idx recorded by tx monitor */
232         unsigned int abs_id;
233
234         int db_disabled;            /* doorbell state */
235         unsigned short db_pidx;     /* doorbell producer index */
236         unsigned short db_pidx_inc; /* doorbell producer increment */
237 };
238
239 struct sge_eth_tx_stats {       /* Ethernet tx queue statistics */
240         u64 pkts;               /* # of ethernet packets */
241         u64 tx_bytes;           /* # of ethernet bytes */
242         u64 tso;                /* # of TSO requests */
243         u64 tx_cso;             /* # of Tx checksum offloads */
244         u64 vlan_ins;           /* # of Tx VLAN insertions */
245         u64 mapping_err;        /* # of I/O MMU packet mapping errors */
246         u64 coal_wr;            /* # of coalesced wr */
247         u64 coal_pkts;          /* # of coalesced packets */
248 };
249
250 struct sge_eth_txq {                   /* state for an SGE Ethernet Tx queue */
251         struct sge_txq q;
252         struct rte_eth_dev *eth_dev;   /* port that this queue belongs to */
253         struct rte_eth_dev_data *data;
254         struct sge_eth_tx_stats stats; /* queue statistics */
255         rte_spinlock_t txq_lock;
256
257         unsigned int flags;            /* flags for state of the queue */
258 } __rte_cache_aligned;
259
260 struct sge_ctrl_txq {                /* State for an SGE control Tx queue */
261         struct sge_txq q;            /* txq */
262         struct adapter *adapter;     /* adapter associated with this queue */
263         rte_spinlock_t ctrlq_lock;   /* control queue lock */
264         u8 full;                     /* the Tx ring is full */
265         u64 txp;                     /* number of transmits */
266         struct rte_mempool *mb_pool; /* mempool to generate ctrl pkts */
267 } __rte_cache_aligned;
268
269 struct sge {
270         struct sge_eth_txq ethtxq[MAX_ETH_QSETS];
271         struct sge_eth_rxq ethrxq[MAX_ETH_QSETS];
272         struct sge_rspq fw_evtq __rte_cache_aligned;
273         struct sge_ctrl_txq ctrlq[MAX_CTRL_QUEUES];
274
275         u16 max_ethqsets;           /* # of available Ethernet queue sets */
276         u32 stat_len;               /* length of status page at ring end */
277         u32 pktshift;               /* padding between CPL & packet data */
278
279         /* response queue interrupt parameters */
280         u16 timer_val[SGE_NTIMERS];
281         u8  counter_val[SGE_NCOUNTERS];
282
283         u32 fl_align;               /* response queue message alignment */
284         u32 fl_pg_order;            /* large page allocation size */
285         u32 fl_starve_thres;        /* Free List starvation threshold */
286 };
287
288 #define T4_OS_NEEDS_MBOX_LOCKING 1
289
290 /*
291  * OS Lock/List primitives for those interfaces in the Common Code which
292  * need this.
293  */
294
295 struct mbox_entry {
296         TAILQ_ENTRY(mbox_entry) next;
297 };
298
299 TAILQ_HEAD(mbox_list, mbox_entry);
300
301 struct adapter {
302         struct rte_pci_device *pdev;       /* associated rte pci device */
303         struct rte_eth_dev *eth_dev;       /* first port's rte eth device */
304         struct adapter_params params;      /* adapter parameters */
305         struct port_info *port[MAX_NPORTS];/* ports belonging to this adapter */
306         struct sge sge;                    /* associated SGE */
307
308         /* support for single-threading access to adapter mailbox registers */
309         struct mbox_list mbox_list;
310         rte_spinlock_t mbox_lock;
311
312         u8 *regs;              /* pointer to registers region */
313         u8 *bar2;              /* pointer to bar2 region */
314         unsigned long flags;   /* adapter flags */
315         unsigned int mbox;     /* associated mailbox */
316         unsigned int pf;       /* associated physical function id */
317
318         unsigned int vpd_busy;
319         unsigned int vpd_flag;
320
321         int use_unpacked_mode; /* unpacked rx mode state */
322
323         struct tid_info tids;     /* Info used to access TID related tables */
324 };
325
326 /**
327  * ethdev2pinfo - return the port_info structure associated with a rte_eth_dev
328  * @dev: the rte_eth_dev
329  *
330  * Return the struct port_info associated with a rte_eth_dev
331  */
332 static inline struct port_info *ethdev2pinfo(const struct rte_eth_dev *dev)
333 {
334         return (struct port_info *)dev->data->dev_private;
335 }
336
337 /**
338  * adap2pinfo - return the port_info of a port
339  * @adap: the adapter
340  * @idx: the port index
341  *
342  * Return the port_info structure for the port of the given index.
343  */
344 static inline struct port_info *adap2pinfo(const struct adapter *adap, int idx)
345 {
346         return adap->port[idx];
347 }
348
349 /**
350  * ethdev2adap - return the adapter structure associated with a rte_eth_dev
351  * @dev: the rte_eth_dev
352  *
353  * Return the struct adapter associated with a rte_eth_dev
354  */
355 static inline struct adapter *ethdev2adap(const struct rte_eth_dev *dev)
356 {
357         return ethdev2pinfo(dev)->adapter;
358 }
359
360 #define CXGBE_PCI_REG(reg) rte_read32(reg)
361
362 static inline uint64_t cxgbe_read_addr64(volatile void *addr)
363 {
364         uint64_t val = CXGBE_PCI_REG(addr);
365         uint64_t val2 = CXGBE_PCI_REG(((volatile uint8_t *)(addr) + 4));
366
367         val2 = (uint64_t)(val2 << 32);
368         val += val2;
369         return val;
370 }
371
372 static inline uint32_t cxgbe_read_addr(volatile void *addr)
373 {
374         return CXGBE_PCI_REG(addr);
375 }
376
377 #define CXGBE_PCI_REG_ADDR(adap, reg) \
378         ((volatile uint32_t *)((char *)(adap)->regs + (reg)))
379
380 #define CXGBE_READ_REG(adap, reg) \
381         cxgbe_read_addr(CXGBE_PCI_REG_ADDR((adap), (reg)))
382
383 #define CXGBE_READ_REG64(adap, reg) \
384         cxgbe_read_addr64(CXGBE_PCI_REG_ADDR((adap), (reg)))
385
386 #define CXGBE_PCI_REG_WRITE(reg, value) rte_write32((value), (reg))
387
388 #define CXGBE_PCI_REG_WRITE_RELAXED(reg, value) \
389         rte_write32_relaxed((value), (reg))
390
391 #define CXGBE_WRITE_REG(adap, reg, value) \
392         CXGBE_PCI_REG_WRITE(CXGBE_PCI_REG_ADDR((adap), (reg)), (value))
393
394 #define CXGBE_WRITE_REG_RELAXED(adap, reg, value) \
395         CXGBE_PCI_REG_WRITE_RELAXED(CXGBE_PCI_REG_ADDR((adap), (reg)), (value))
396
397 static inline uint64_t cxgbe_write_addr64(volatile void *addr, uint64_t val)
398 {
399         CXGBE_PCI_REG_WRITE(addr, val);
400         CXGBE_PCI_REG_WRITE(((volatile uint8_t *)(addr) + 4), (val >> 32));
401         return val;
402 }
403
404 #define CXGBE_WRITE_REG64(adap, reg, value) \
405         cxgbe_write_addr64(CXGBE_PCI_REG_ADDR((adap), (reg)), (value))
406
407 /**
408  * t4_read_reg - read a HW register
409  * @adapter: the adapter
410  * @reg_addr: the register address
411  *
412  * Returns the 32-bit value of the given HW register.
413  */
414 static inline u32 t4_read_reg(struct adapter *adapter, u32 reg_addr)
415 {
416         u32 val = CXGBE_READ_REG(adapter, reg_addr);
417
418         CXGBE_DEBUG_REG(adapter, "read register 0x%x value 0x%x\n", reg_addr,
419                         val);
420         return val;
421 }
422
423 /**
424  * t4_write_reg - write a HW register with barrier
425  * @adapter: the adapter
426  * @reg_addr: the register address
427  * @val: the value to write
428  *
429  * Write a 32-bit value into the given HW register.
430  */
431 static inline void t4_write_reg(struct adapter *adapter, u32 reg_addr, u32 val)
432 {
433         CXGBE_DEBUG_REG(adapter, "setting register 0x%x to 0x%x\n", reg_addr,
434                         val);
435         CXGBE_WRITE_REG(adapter, reg_addr, val);
436 }
437
438 /**
439  * t4_write_reg_relaxed - write a HW register with no barrier
440  * @adapter: the adapter
441  * @reg_addr: the register address
442  * @val: the value to write
443  *
444  * Write a 32-bit value into the given HW register.
445  */
446 static inline void t4_write_reg_relaxed(struct adapter *adapter, u32 reg_addr,
447                                         u32 val)
448 {
449         CXGBE_DEBUG_REG(adapter, "setting register 0x%x to 0x%x\n", reg_addr,
450                         val);
451         CXGBE_WRITE_REG_RELAXED(adapter, reg_addr, val);
452 }
453
454 /**
455  * t4_read_reg64 - read a 64-bit HW register
456  * @adapter: the adapter
457  * @reg_addr: the register address
458  *
459  * Returns the 64-bit value of the given HW register.
460  */
461 static inline u64 t4_read_reg64(struct adapter *adapter, u32 reg_addr)
462 {
463         u64 val = CXGBE_READ_REG64(adapter, reg_addr);
464
465         CXGBE_DEBUG_REG(adapter, "64-bit read register %#x value %#llx\n",
466                         reg_addr, (unsigned long long)val);
467         return val;
468 }
469
470 /**
471  * t4_write_reg64 - write a 64-bit HW register
472  * @adapter: the adapter
473  * @reg_addr: the register address
474  * @val: the value to write
475  *
476  * Write a 64-bit value into the given HW register.
477  */
478 static inline void t4_write_reg64(struct adapter *adapter, u32 reg_addr,
479                                   u64 val)
480 {
481         CXGBE_DEBUG_REG(adapter, "setting register %#x to %#llx\n", reg_addr,
482                         (unsigned long long)val);
483
484         CXGBE_WRITE_REG64(adapter, reg_addr, val);
485 }
486
487 #define PCI_STATUS              0x06    /* 16 bits */
488 #define PCI_STATUS_CAP_LIST     0x10    /* Support Capability List */
489 #define PCI_CAPABILITY_LIST     0x34
490 /* Offset of first capability list entry */
491 #define PCI_CAP_ID_EXP          0x10    /* PCI Express */
492 #define PCI_CAP_LIST_ID         0       /* Capability ID */
493 #define PCI_CAP_LIST_NEXT       1       /* Next capability in the list */
494 #define PCI_EXP_DEVCTL          0x0008  /* Device control */
495 #define PCI_EXP_DEVCTL2         40      /* Device Control 2 */
496 #define PCI_EXP_DEVCTL_EXT_TAG  0x0100  /* Extended Tag Field Enable */
497 #define PCI_EXP_DEVCTL_PAYLOAD  0x00E0  /* Max payload */
498 #define PCI_CAP_ID_VPD          0x03    /* Vital Product Data */
499 #define PCI_VPD_ADDR            2       /* Address to access (15 bits!) */
500 #define PCI_VPD_ADDR_F          0x8000  /* Write 0, 1 indicates completion */
501 #define PCI_VPD_DATA            4       /* 32-bits of data returned here */
502
503 /**
504  * t4_os_pci_write_cfg4 - 32-bit write to PCI config space
505  * @adapter: the adapter
506  * @addr: the register address
507  * @val: the value to write
508  *
509  * Write a 32-bit value into the given register in PCI config space.
510  */
511 static inline void t4_os_pci_write_cfg4(struct adapter *adapter, size_t addr,
512                                         off_t val)
513 {
514         u32 val32 = val;
515
516         if (rte_pci_write_config(adapter->pdev, &val32, sizeof(val32),
517                                      addr) < 0)
518                 dev_err(adapter, "Can't write to PCI config space\n");
519 }
520
521 /**
522  * t4_os_pci_read_cfg4 - read a 32-bit value from PCI config space
523  * @adapter: the adapter
524  * @addr: the register address
525  * @val: where to store the value read
526  *
527  * Read a 32-bit value from the given register in PCI config space.
528  */
529 static inline void t4_os_pci_read_cfg4(struct adapter *adapter, size_t addr,
530                                        u32 *val)
531 {
532         if (rte_pci_read_config(adapter->pdev, val, sizeof(*val),
533                                     addr) < 0)
534                 dev_err(adapter, "Can't read from PCI config space\n");
535 }
536
537 /**
538  * t4_os_pci_write_cfg2 - 16-bit write to PCI config space
539  * @adapter: the adapter
540  * @addr: the register address
541  * @val: the value to write
542  *
543  * Write a 16-bit value into the given register in PCI config space.
544  */
545 static inline void t4_os_pci_write_cfg2(struct adapter *adapter, size_t addr,
546                                         off_t val)
547 {
548         u16 val16 = val;
549
550         if (rte_pci_write_config(adapter->pdev, &val16, sizeof(val16),
551                                      addr) < 0)
552                 dev_err(adapter, "Can't write to PCI config space\n");
553 }
554
555 /**
556  * t4_os_pci_read_cfg2 - read a 16-bit value from PCI config space
557  * @adapter: the adapter
558  * @addr: the register address
559  * @val: where to store the value read
560  *
561  * Read a 16-bit value from the given register in PCI config space.
562  */
563 static inline void t4_os_pci_read_cfg2(struct adapter *adapter, size_t addr,
564                                        u16 *val)
565 {
566         if (rte_pci_read_config(adapter->pdev, val, sizeof(*val),
567                                     addr) < 0)
568                 dev_err(adapter, "Can't read from PCI config space\n");
569 }
570
571 /**
572  * t4_os_pci_read_cfg - read a 8-bit value from PCI config space
573  * @adapter: the adapter
574  * @addr: the register address
575  * @val: where to store the value read
576  *
577  * Read a 8-bit value from the given register in PCI config space.
578  */
579 static inline void t4_os_pci_read_cfg(struct adapter *adapter, size_t addr,
580                                       u8 *val)
581 {
582         if (rte_pci_read_config(adapter->pdev, val, sizeof(*val),
583                                     addr) < 0)
584                 dev_err(adapter, "Can't read from PCI config space\n");
585 }
586
587 /**
588  * t4_os_find_pci_capability - lookup a capability in the PCI capability list
589  * @adapter: the adapter
590  * @cap: the capability
591  *
592  * Return the address of the given capability within the PCI capability list.
593  */
594 static inline int t4_os_find_pci_capability(struct adapter *adapter, int cap)
595 {
596         u16 status;
597         int ttl = 48;
598         u8 pos = 0;
599         u8 id = 0;
600
601         t4_os_pci_read_cfg2(adapter, PCI_STATUS, &status);
602         if (!(status & PCI_STATUS_CAP_LIST)) {
603                 dev_err(adapter, "PCIe capability reading failed\n");
604                 return -1;
605         }
606
607         t4_os_pci_read_cfg(adapter, PCI_CAPABILITY_LIST, &pos);
608         while (ttl-- && pos >= 0x40) {
609                 pos &= ~3;
610                 t4_os_pci_read_cfg(adapter, (pos + PCI_CAP_LIST_ID), &id);
611
612                 if (id == 0xff)
613                         break;
614
615                 if (id == cap)
616                         return (int)pos;
617
618                 t4_os_pci_read_cfg(adapter, (pos + PCI_CAP_LIST_NEXT), &pos);
619         }
620         return 0;
621 }
622
623 /**
624  * t4_os_set_hw_addr - store a port's MAC address in SW
625  * @adapter: the adapter
626  * @port_idx: the port index
627  * @hw_addr: the Ethernet address
628  *
629  * Store the Ethernet address of the given port in SW.  Called by the
630  * common code when it retrieves a port's Ethernet address from EEPROM.
631  */
632 static inline void t4_os_set_hw_addr(struct adapter *adapter, int port_idx,
633                                      u8 hw_addr[])
634 {
635         struct port_info *pi = adap2pinfo(adapter, port_idx);
636
637         ether_addr_copy((struct ether_addr *)hw_addr,
638                         &pi->eth_dev->data->mac_addrs[0]);
639 }
640
641 /**
642  * t4_os_lock_init - initialize spinlock
643  * @lock: the spinlock
644  */
645 static inline void t4_os_lock_init(rte_spinlock_t *lock)
646 {
647         rte_spinlock_init(lock);
648 }
649
650 /**
651  * t4_os_lock - spin until lock is acquired
652  * @lock: the spinlock
653  */
654 static inline void t4_os_lock(rte_spinlock_t *lock)
655 {
656         rte_spinlock_lock(lock);
657 }
658
659 /**
660  * t4_os_unlock - unlock a spinlock
661  * @lock: the spinlock
662  */
663 static inline void t4_os_unlock(rte_spinlock_t *lock)
664 {
665         rte_spinlock_unlock(lock);
666 }
667
668 /**
669  * t4_os_trylock - try to get a lock
670  * @lock: the spinlock
671  */
672 static inline int t4_os_trylock(rte_spinlock_t *lock)
673 {
674         return rte_spinlock_trylock(lock);
675 }
676
677 /**
678  * t4_os_init_list_head - initialize
679  * @head: head of list to initialize [to empty]
680  */
681 static inline void t4_os_init_list_head(struct mbox_list *head)
682 {
683         TAILQ_INIT(head);
684 }
685
686 static inline struct mbox_entry *t4_os_list_first_entry(struct mbox_list *head)
687 {
688         return TAILQ_FIRST(head);
689 }
690
691 /**
692  * t4_os_atomic_add_tail - Enqueue list element atomically onto list
693  * @new: the entry to be addded to the queue
694  * @head: current head of the linked list
695  * @lock: lock to use to guarantee atomicity
696  */
697 static inline void t4_os_atomic_add_tail(struct mbox_entry *entry,
698                                          struct mbox_list *head,
699                                          rte_spinlock_t *lock)
700 {
701         t4_os_lock(lock);
702         TAILQ_INSERT_TAIL(head, entry, next);
703         t4_os_unlock(lock);
704 }
705
706 /**
707  * t4_os_atomic_list_del - Dequeue list element atomically from list
708  * @entry: the entry to be remove/dequeued from the list.
709  * @lock: the spinlock
710  */
711 static inline void t4_os_atomic_list_del(struct mbox_entry *entry,
712                                          struct mbox_list *head,
713                                          rte_spinlock_t *lock)
714 {
715         t4_os_lock(lock);
716         TAILQ_REMOVE(head, entry, next);
717         t4_os_unlock(lock);
718 }
719
720 void *t4_alloc_mem(size_t size);
721 void t4_free_mem(void *addr);
722 #define t4_os_alloc(_size)     t4_alloc_mem((_size))
723 #define t4_os_free(_ptr)       t4_free_mem((_ptr))
724
725 void t4_os_portmod_changed(const struct adapter *adap, int port_id);
726 void t4_os_link_changed(struct adapter *adap, int port_id, int link_stat);
727
728 void reclaim_completed_tx(struct sge_txq *q);
729 void t4_free_sge_resources(struct adapter *adap);
730 void t4_sge_tx_monitor_start(struct adapter *adap);
731 void t4_sge_tx_monitor_stop(struct adapter *adap);
732 int t4_eth_xmit(struct sge_eth_txq *txq, struct rte_mbuf *mbuf,
733                 uint16_t nb_pkts);
734 int t4_mgmt_tx(struct sge_ctrl_txq *txq, struct rte_mbuf *mbuf);
735 int t4_ethrx_handler(struct sge_rspq *q, const __be64 *rsp,
736                      const struct pkt_gl *gl);
737 int t4_sge_init(struct adapter *adap);
738 int t4vf_sge_init(struct adapter *adap);
739 int t4_sge_alloc_eth_txq(struct adapter *adap, struct sge_eth_txq *txq,
740                          struct rte_eth_dev *eth_dev, uint16_t queue_id,
741                          unsigned int iqid, int socket_id);
742 int t4_sge_alloc_ctrl_txq(struct adapter *adap, struct sge_ctrl_txq *txq,
743                           struct rte_eth_dev *eth_dev, uint16_t queue_id,
744                           unsigned int iqid, int socket_id);
745 int t4_sge_alloc_rxq(struct adapter *adap, struct sge_rspq *rspq, bool fwevtq,
746                      struct rte_eth_dev *eth_dev, int intr_idx,
747                      struct sge_fl *fl, rspq_handler_t handler,
748                      int cong, struct rte_mempool *mp, int queue_id,
749                      int socket_id);
750 int t4_sge_eth_txq_start(struct sge_eth_txq *txq);
751 int t4_sge_eth_txq_stop(struct sge_eth_txq *txq);
752 void t4_sge_eth_txq_release(struct adapter *adap, struct sge_eth_txq *txq);
753 int t4_sge_eth_rxq_start(struct adapter *adap, struct sge_rspq *rq);
754 int t4_sge_eth_rxq_stop(struct adapter *adap, struct sge_rspq *rq);
755 void t4_sge_eth_rxq_release(struct adapter *adap, struct sge_eth_rxq *rxq);
756 void t4_sge_eth_clear_queues(struct port_info *pi);
757 int cxgb4_set_rspq_intr_params(struct sge_rspq *q, unsigned int us,
758                                unsigned int cnt);
759 int cxgbe_poll(struct sge_rspq *q, struct rte_mbuf **rx_pkts,
760                unsigned int budget, unsigned int *work_done);
761 int cxgbe_write_rss(const struct port_info *pi, const u16 *queues);
762 int cxgbe_write_rss_conf(const struct port_info *pi, uint64_t flags);
763
764 #endif /* __T4_ADAPTER_H__ */