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