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