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