12aa5c722SRahul Lakkireddy /* SPDX-License-Identifier: BSD-3-Clause
22aa5c722SRahul Lakkireddy * Copyright(c) 2014-2018 Chelsio Communications.
33bd122eeSRahul Lakkireddy * All rights reserved.
43bd122eeSRahul Lakkireddy */
53bd122eeSRahul Lakkireddy
63bd122eeSRahul Lakkireddy /* This file should not be included directly. Include common.h instead. */
73bd122eeSRahul Lakkireddy
83bd122eeSRahul Lakkireddy #ifndef __T4_ADAPTER_H__
93bd122eeSRahul Lakkireddy #define __T4_ADAPTER_H__
103bd122eeSRahul Lakkireddy
111f37cb2bSDavid Marchand #include <bus_pci_driver.h>
123bd122eeSRahul Lakkireddy #include <rte_mbuf.h>
13c167acb6SSantosh Shukla #include <rte_io.h>
143f2c1e20SShagun Agrawal #include <rte_rwlock.h>
15f9bdee26SKonstantin Ananyev #include <ethdev_driver.h>
163bd122eeSRahul Lakkireddy
1789c8bd95SRahul Lakkireddy #include "../cxgbe_compat.h"
1889c8bd95SRahul Lakkireddy #include "../cxgbe_ofld.h"
193bd122eeSRahul Lakkireddy #include "t4_regs_values.h"
203bd122eeSRahul Lakkireddy
213bd122eeSRahul Lakkireddy enum {
223a3aaabcSShagun Agrawal MAX_CTRL_QUEUES = NCHAN, /* # of control Tx queues */
233bd122eeSRahul Lakkireddy };
243bd122eeSRahul Lakkireddy
253bd122eeSRahul Lakkireddy struct adapter;
263bd122eeSRahul Lakkireddy struct sge_rspq;
273bd122eeSRahul Lakkireddy
283bd122eeSRahul Lakkireddy enum {
293bd122eeSRahul Lakkireddy PORT_RSS_DONE = (1 << 0),
303bd122eeSRahul Lakkireddy };
313bd122eeSRahul Lakkireddy
323bd122eeSRahul Lakkireddy struct port_info {
333bd122eeSRahul Lakkireddy struct adapter *adapter; /* adapter that this port belongs to */
343bd122eeSRahul Lakkireddy struct rte_eth_dev *eth_dev; /* associated rte eth device */
353bd122eeSRahul Lakkireddy struct port_stats stats_base; /* port statistics base */
363bd122eeSRahul Lakkireddy struct link_config link_cfg; /* link configuration info */
373bd122eeSRahul Lakkireddy
383bd122eeSRahul Lakkireddy unsigned long flags; /* port related flags */
393bd122eeSRahul Lakkireddy short int xact_addr_filt; /* index of exact MAC address filter */
403bd122eeSRahul Lakkireddy
413bd122eeSRahul Lakkireddy u16 viid; /* associated virtual interface id */
423bd122eeSRahul Lakkireddy u8 port_id; /* physical port ID */
435e80364aSKumar Sanghvi u8 pidx; /* port index for this PF */
443bd122eeSRahul Lakkireddy u8 tx_chan; /* associated channel */
453bd122eeSRahul Lakkireddy
467b3d5298SRahul Lakkireddy u16 n_rx_qsets; /* # of rx qsets */
477b3d5298SRahul Lakkireddy u16 n_tx_qsets; /* # of tx qsets */
487b3d5298SRahul Lakkireddy u16 first_rxqset; /* index of first rxqset */
497b3d5298SRahul Lakkireddy u16 first_txqset; /* index of first txqset */
503bd122eeSRahul Lakkireddy
513bd122eeSRahul Lakkireddy u16 *rss; /* rss table */
523bd122eeSRahul Lakkireddy u8 rss_mode; /* rss mode */
533bd122eeSRahul Lakkireddy u16 rss_size; /* size of VI's RSS table slice */
5408e21af9SKumar Sanghvi u64 rss_hf; /* RSS Hash Function */
5524c1d49aSKarra Satwik
5624c1d49aSKarra Satwik /* viid fields either returned by fw
5724c1d49aSKarra Satwik * or decoded by parsing viid by driver.
5824c1d49aSKarra Satwik */
5924c1d49aSKarra Satwik u8 vin;
6024c1d49aSKarra Satwik u8 vivld;
6123d5fee3SRahul Lakkireddy
6223d5fee3SRahul Lakkireddy u8 vi_en_rx; /* Enable/disable VI Rx */
6323d5fee3SRahul Lakkireddy u8 vi_en_tx; /* Enable/disable VI Tx */
643bd122eeSRahul Lakkireddy };
653bd122eeSRahul Lakkireddy
663bd122eeSRahul Lakkireddy enum { /* adapter flags */
673bd122eeSRahul Lakkireddy FULL_INIT_DONE = (1 << 0),
683bd122eeSRahul Lakkireddy USING_MSI = (1 << 1),
693bd122eeSRahul Lakkireddy USING_MSIX = (1 << 2),
703bd122eeSRahul Lakkireddy FW_QUEUE_BOUND = (1 << 3),
713bd122eeSRahul Lakkireddy FW_OK = (1 << 4),
723bd122eeSRahul Lakkireddy CFG_QUEUES = (1 << 5),
733bd122eeSRahul Lakkireddy MASTER_PF = (1 << 6),
743bd122eeSRahul Lakkireddy };
753bd122eeSRahul Lakkireddy
763bd122eeSRahul Lakkireddy struct rx_sw_desc { /* SW state per Rx descriptor */
773bd122eeSRahul Lakkireddy void *buf; /* struct page or mbuf */
783bd122eeSRahul Lakkireddy dma_addr_t dma_addr;
793bd122eeSRahul Lakkireddy };
803bd122eeSRahul Lakkireddy
813bd122eeSRahul Lakkireddy struct sge_fl { /* SGE free-buffer queue state */
823bd122eeSRahul Lakkireddy /* RO fields */
833bd122eeSRahul Lakkireddy struct rx_sw_desc *sdesc; /* address of SW Rx descriptor ring */
843bd122eeSRahul Lakkireddy
853bd122eeSRahul Lakkireddy dma_addr_t addr; /* bus address of HW ring start */
863bd122eeSRahul Lakkireddy __be64 *desc; /* address of HW Rx descriptor ring */
873bd122eeSRahul Lakkireddy
883bd122eeSRahul Lakkireddy void __iomem *bar2_addr; /* address of BAR2 Queue registers */
893bd122eeSRahul Lakkireddy unsigned int bar2_qid; /* Queue ID for BAR2 Queue registers */
903bd122eeSRahul Lakkireddy
913bd122eeSRahul Lakkireddy unsigned int cntxt_id; /* SGE relative QID for the free list */
923bd122eeSRahul Lakkireddy unsigned int size; /* capacity of free list */
933bd122eeSRahul Lakkireddy
943bd122eeSRahul Lakkireddy unsigned int avail; /* # of available Rx buffers */
953bd122eeSRahul Lakkireddy unsigned int pend_cred; /* new buffers since last FL DB ring */
963bd122eeSRahul Lakkireddy unsigned int cidx; /* consumer index */
973bd122eeSRahul Lakkireddy unsigned int pidx; /* producer index */
983bd122eeSRahul Lakkireddy
993bd122eeSRahul Lakkireddy unsigned long alloc_failed; /* # of times buffer allocation failed */
1003bd122eeSRahul Lakkireddy unsigned long low; /* # of times momentarily starving */
101745b8836SRahul Lakkireddy u8 fl_buf_size_idx; /* Selected SGE_FL_BUFFER_SIZE index */
1023bd122eeSRahul Lakkireddy };
1033bd122eeSRahul Lakkireddy
1043bd122eeSRahul Lakkireddy #define MAX_MBUF_FRAGS (16384 / 512 + 2)
1053bd122eeSRahul Lakkireddy
1063bd122eeSRahul Lakkireddy /* A packet gather list */
1073bd122eeSRahul Lakkireddy struct pkt_gl {
1083bd122eeSRahul Lakkireddy union {
1093bd122eeSRahul Lakkireddy struct rte_mbuf *mbufs[MAX_MBUF_FRAGS];
1103bd122eeSRahul Lakkireddy } /* UNNAMED */;
1113bd122eeSRahul Lakkireddy void *va; /* virtual address of first byte */
1123bd122eeSRahul Lakkireddy unsigned int nfrags; /* # of fragments */
1133bd122eeSRahul Lakkireddy unsigned int tot_len; /* total length of fragments */
1143bd122eeSRahul Lakkireddy };
1153bd122eeSRahul Lakkireddy
1163bd122eeSRahul Lakkireddy typedef int (*rspq_handler_t)(struct sge_rspq *q, const __be64 *rsp,
1173bd122eeSRahul Lakkireddy const struct pkt_gl *gl);
1183bd122eeSRahul Lakkireddy
1193bd122eeSRahul Lakkireddy struct sge_rspq { /* state for an SGE response queue */
1203bd122eeSRahul Lakkireddy struct adapter *adapter; /* adapter that this queue belongs to */
1213bd122eeSRahul Lakkireddy struct rte_eth_dev *eth_dev; /* associated rte eth device */
1223bd122eeSRahul Lakkireddy struct rte_mempool *mb_pool; /* associated mempool */
1233bd122eeSRahul Lakkireddy
1243bd122eeSRahul Lakkireddy dma_addr_t phys_addr; /* physical address of the ring */
1253bd122eeSRahul Lakkireddy __be64 *desc; /* address of HW response ring */
1263bd122eeSRahul Lakkireddy const __be64 *cur_desc; /* current descriptor in queue */
1273bd122eeSRahul Lakkireddy
1283bd122eeSRahul Lakkireddy void __iomem *bar2_addr; /* address of BAR2 Queue registers */
1293bd122eeSRahul Lakkireddy unsigned int bar2_qid; /* Queue ID for BAR2 Queue registers */
1306c280962SRahul Lakkireddy struct sge_qstat *stat;
1313bd122eeSRahul Lakkireddy
1323bd122eeSRahul Lakkireddy unsigned int cidx; /* consumer index */
13378fc1a71SRahul Lakkireddy unsigned int gts_idx; /* last gts write sent */
1343bd122eeSRahul Lakkireddy unsigned int iqe_len; /* entry size */
1353bd122eeSRahul Lakkireddy unsigned int size; /* capacity of response queue */
1363bd122eeSRahul Lakkireddy int offset; /* offset into current Rx buffer */
1373bd122eeSRahul Lakkireddy
1383bd122eeSRahul Lakkireddy u8 gen; /* current generation bit */
1393bd122eeSRahul Lakkireddy u8 intr_params; /* interrupt holdoff parameters */
1403bd122eeSRahul Lakkireddy u8 next_intr_params; /* holdoff params for next interrupt */
1413bd122eeSRahul Lakkireddy u8 pktcnt_idx; /* interrupt packet threshold */
14278fc1a71SRahul Lakkireddy u8 port_id; /* associated port-id */
1433bd122eeSRahul Lakkireddy u8 idx; /* queue index within its group */
1443bd122eeSRahul Lakkireddy u16 cntxt_id; /* SGE relative QID for the response Q */
1453bd122eeSRahul Lakkireddy u16 abs_id; /* absolute SGE id for the response q */
1463bd122eeSRahul Lakkireddy
1473bd122eeSRahul Lakkireddy rspq_handler_t handler; /* associated handler for this response q */
1483bd122eeSRahul Lakkireddy };
1493bd122eeSRahul Lakkireddy
1503bd122eeSRahul Lakkireddy struct sge_eth_rx_stats { /* Ethernet rx queue statistics */
1513bd122eeSRahul Lakkireddy u64 pkts; /* # of ethernet packets */
1523bd122eeSRahul Lakkireddy u64 rx_bytes; /* # of ethernet bytes */
1533bd122eeSRahul Lakkireddy u64 rx_cso; /* # of Rx checksum offloads */
1543bd122eeSRahul Lakkireddy u64 vlan_ex; /* # of Rx VLAN extractions */
1553bd122eeSRahul Lakkireddy u64 rx_drops; /* # of packets dropped due to no mem */
1563bd122eeSRahul Lakkireddy };
1573bd122eeSRahul Lakkireddy
158*27595cd8STyler Retzlaff struct __rte_cache_aligned sge_eth_rxq { /* a SW Ethernet Rx queue */
159e30e5407SRahul Lakkireddy unsigned int flags; /* flags for state of the queue */
1603bd122eeSRahul Lakkireddy struct sge_rspq rspq;
1613bd122eeSRahul Lakkireddy struct sge_fl fl;
1623bd122eeSRahul Lakkireddy struct sge_eth_rx_stats stats;
163*27595cd8STyler Retzlaff };
1643bd122eeSRahul Lakkireddy
1653bd122eeSRahul Lakkireddy /*
1663bd122eeSRahul Lakkireddy * Currently there are two types of coalesce WR. Type 0 needs 48 bytes per
1673bd122eeSRahul Lakkireddy * packet (if one sgl is present) and type 1 needs 32 bytes. This means
1683bd122eeSRahul Lakkireddy * that type 0 can fit a maximum of 10 packets per WR and type 1 can fit
1693bd122eeSRahul Lakkireddy * 15 packets. We need to keep track of the mbuf pointers in a coalesce WR
1703bd122eeSRahul Lakkireddy * to be able to free those mbufs when we get completions back from the FW.
1713bd122eeSRahul Lakkireddy * Allocating the maximum number of pointers in every tx desc is a waste
1723bd122eeSRahul Lakkireddy * of memory resources so we only store 2 pointers per tx desc which should
1733bd122eeSRahul Lakkireddy * be enough since a tx desc can only fit 2 packets in the best case
1743bd122eeSRahul Lakkireddy * scenario where a packet needs 32 bytes.
1753bd122eeSRahul Lakkireddy */
1763bd122eeSRahul Lakkireddy #define ETH_COALESCE_PKT_NUM 15
177880ead4eSKumar Sanghvi #define ETH_COALESCE_VF_PKT_NUM 7
1783bd122eeSRahul Lakkireddy #define ETH_COALESCE_PKT_PER_DESC 2
1793bd122eeSRahul Lakkireddy
1803bd122eeSRahul Lakkireddy struct tx_eth_coal_desc {
1813bd122eeSRahul Lakkireddy struct rte_mbuf *mbuf[ETH_COALESCE_PKT_PER_DESC];
1823bd122eeSRahul Lakkireddy struct ulptx_sgl *sgl[ETH_COALESCE_PKT_PER_DESC];
1833bd122eeSRahul Lakkireddy int idx;
1843bd122eeSRahul Lakkireddy };
1853bd122eeSRahul Lakkireddy
1863bd122eeSRahul Lakkireddy struct tx_desc {
1873bd122eeSRahul Lakkireddy __be64 flit[8];
1883bd122eeSRahul Lakkireddy };
1893bd122eeSRahul Lakkireddy
1903bd122eeSRahul Lakkireddy struct tx_sw_desc { /* SW state per Tx descriptor */
1913bd122eeSRahul Lakkireddy struct rte_mbuf *mbuf;
1923bd122eeSRahul Lakkireddy struct ulptx_sgl *sgl;
1933bd122eeSRahul Lakkireddy struct tx_eth_coal_desc coalesce;
1943bd122eeSRahul Lakkireddy };
1953bd122eeSRahul Lakkireddy
196e30e5407SRahul Lakkireddy enum cxgbe_txq_state {
1973bd122eeSRahul Lakkireddy EQ_STOPPED = (1 << 0),
1983bd122eeSRahul Lakkireddy };
1993bd122eeSRahul Lakkireddy
200e30e5407SRahul Lakkireddy enum cxgbe_rxq_state {
201e30e5407SRahul Lakkireddy IQ_STOPPED = (1 << 0),
202e30e5407SRahul Lakkireddy };
203e30e5407SRahul Lakkireddy
2043bd122eeSRahul Lakkireddy struct eth_coalesce {
2053bd122eeSRahul Lakkireddy unsigned char *ptr;
2063bd122eeSRahul Lakkireddy unsigned char type;
2073bd122eeSRahul Lakkireddy unsigned int idx;
2083bd122eeSRahul Lakkireddy unsigned int len;
2093bd122eeSRahul Lakkireddy unsigned int flits;
2103bd122eeSRahul Lakkireddy unsigned int max;
211880ead4eSKumar Sanghvi __u8 ethmacdst[ETHER_ADDR_LEN];
212880ead4eSKumar Sanghvi __u8 ethmacsrc[ETHER_ADDR_LEN];
213880ead4eSKumar Sanghvi __be16 ethtype;
214880ead4eSKumar Sanghvi __be16 vlantci;
2153bd122eeSRahul Lakkireddy };
2163bd122eeSRahul Lakkireddy
2173bd122eeSRahul Lakkireddy struct sge_txq {
2183bd122eeSRahul Lakkireddy struct tx_desc *desc; /* address of HW Tx descriptor ring */
2193bd122eeSRahul Lakkireddy struct tx_sw_desc *sdesc; /* address of SW Tx descriptor ring */
2203bd122eeSRahul Lakkireddy struct sge_qstat *stat; /* queue status entry */
2213bd122eeSRahul Lakkireddy struct eth_coalesce coalesce; /* coalesce info */
2223bd122eeSRahul Lakkireddy
2233bd122eeSRahul Lakkireddy uint64_t phys_addr; /* physical address of the ring */
2243bd122eeSRahul Lakkireddy
2253bd122eeSRahul Lakkireddy void __iomem *bar2_addr; /* address of BAR2 Queue registers */
2263bd122eeSRahul Lakkireddy unsigned int bar2_qid; /* Queue ID for BAR2 Queue registers */
2273bd122eeSRahul Lakkireddy
2283bd122eeSRahul Lakkireddy unsigned int cntxt_id; /* SGE relative QID for the Tx Q */
2293bd122eeSRahul Lakkireddy unsigned int in_use; /* # of in-use Tx descriptors */
2303bd122eeSRahul Lakkireddy unsigned int size; /* # of descriptors */
2313bd122eeSRahul Lakkireddy unsigned int cidx; /* SW consumer index */
2323bd122eeSRahul Lakkireddy unsigned int pidx; /* producer index */
2333bd122eeSRahul Lakkireddy unsigned int dbidx; /* last idx when db ring was done */
2343bd122eeSRahul Lakkireddy unsigned int equeidx; /* last sent credit request */
2353bd122eeSRahul Lakkireddy unsigned int last_pidx; /* last pidx recorded by tx monitor */
2363bd122eeSRahul Lakkireddy unsigned int last_coal_idx;/* last coal-idx recorded by tx monitor */
2375e59e39aSKumar Sanghvi unsigned int abs_id;
2383bd122eeSRahul Lakkireddy
2393bd122eeSRahul Lakkireddy int db_disabled; /* doorbell state */
2403bd122eeSRahul Lakkireddy unsigned short db_pidx; /* doorbell producer index */
2413bd122eeSRahul Lakkireddy unsigned short db_pidx_inc; /* doorbell producer increment */
2423bd122eeSRahul Lakkireddy };
2433bd122eeSRahul Lakkireddy
2443bd122eeSRahul Lakkireddy struct sge_eth_tx_stats { /* Ethernet tx queue statistics */
2453bd122eeSRahul Lakkireddy u64 pkts; /* # of ethernet packets */
2463bd122eeSRahul Lakkireddy u64 tx_bytes; /* # of ethernet bytes */
2473bd122eeSRahul Lakkireddy u64 tso; /* # of TSO requests */
2483bd122eeSRahul Lakkireddy u64 tx_cso; /* # of Tx checksum offloads */
2493bd122eeSRahul Lakkireddy u64 vlan_ins; /* # of Tx VLAN insertions */
2503bd122eeSRahul Lakkireddy u64 mapping_err; /* # of I/O MMU packet mapping errors */
2513bd122eeSRahul Lakkireddy u64 coal_wr; /* # of coalesced wr */
2523bd122eeSRahul Lakkireddy u64 coal_pkts; /* # of coalesced packets */
2533bd122eeSRahul Lakkireddy };
2543bd122eeSRahul Lakkireddy
255*27595cd8STyler Retzlaff struct __rte_cache_aligned sge_eth_txq { /* state for an SGE Ethernet Tx queue */
2563bd122eeSRahul Lakkireddy struct sge_txq q;
2573bd122eeSRahul Lakkireddy struct rte_eth_dev *eth_dev; /* port that this queue belongs to */
258da5cf85eSKumar Sanghvi struct rte_eth_dev_data *data;
2593bd122eeSRahul Lakkireddy struct sge_eth_tx_stats stats; /* queue statistics */
2603bd122eeSRahul Lakkireddy rte_spinlock_t txq_lock;
2613bd122eeSRahul Lakkireddy
2623bd122eeSRahul Lakkireddy unsigned int flags; /* flags for state of the queue */
263*27595cd8STyler Retzlaff };
2643bd122eeSRahul Lakkireddy
265*27595cd8STyler Retzlaff struct __rte_cache_aligned sge_ctrl_txq { /* State for an SGE control Tx queue */
2663a3aaabcSShagun Agrawal struct sge_txq q; /* txq */
2673a3aaabcSShagun Agrawal struct adapter *adapter; /* adapter associated with this queue */
2683a3aaabcSShagun Agrawal rte_spinlock_t ctrlq_lock; /* control queue lock */
2693a3aaabcSShagun Agrawal u8 full; /* the Tx ring is full */
2703a3aaabcSShagun Agrawal u64 txp; /* number of transmits */
2713a3aaabcSShagun Agrawal struct rte_mempool *mb_pool; /* mempool to generate ctrl pkts */
272*27595cd8STyler Retzlaff };
2733a3aaabcSShagun Agrawal
2743bd122eeSRahul Lakkireddy struct sge {
2757b3d5298SRahul Lakkireddy struct sge_eth_txq *ethtxq;
2767b3d5298SRahul Lakkireddy struct sge_eth_rxq *ethrxq;
277*27595cd8STyler Retzlaff alignas(RTE_CACHE_LINE_SIZE) struct sge_rspq fw_evtq;
2783a3aaabcSShagun Agrawal struct sge_ctrl_txq ctrlq[MAX_CTRL_QUEUES];
2793bd122eeSRahul Lakkireddy
2803bd122eeSRahul Lakkireddy u16 max_ethqsets; /* # of available Ethernet queue sets */
2813bd122eeSRahul Lakkireddy u32 stat_len; /* length of status page at ring end */
2823bd122eeSRahul Lakkireddy u32 pktshift; /* padding between CPL & packet data */
2833bd122eeSRahul Lakkireddy
2843bd122eeSRahul Lakkireddy /* response queue interrupt parameters */
2853bd122eeSRahul Lakkireddy u16 timer_val[SGE_NTIMERS];
2863bd122eeSRahul Lakkireddy u8 counter_val[SGE_NCOUNTERS];
2873bd122eeSRahul Lakkireddy
2883bd122eeSRahul Lakkireddy u32 fl_starve_thres; /* Free List starvation threshold */
289745b8836SRahul Lakkireddy u32 fl_buffer_size[SGE_FL_BUFFER_SIZE_NUM]; /* Free List buffer sizes */
2903bd122eeSRahul Lakkireddy };
2913bd122eeSRahul Lakkireddy
2923bd122eeSRahul Lakkireddy /*
2933bd122eeSRahul Lakkireddy * OS Lock/List primitives for those interfaces in the Common Code which
2943bd122eeSRahul Lakkireddy * need this.
2953bd122eeSRahul Lakkireddy */
2963bd122eeSRahul Lakkireddy
2973bd122eeSRahul Lakkireddy struct mbox_entry {
2983bd122eeSRahul Lakkireddy TAILQ_ENTRY(mbox_entry) next;
2993bd122eeSRahul Lakkireddy };
3003bd122eeSRahul Lakkireddy
3013bd122eeSRahul Lakkireddy TAILQ_HEAD(mbox_list, mbox_entry);
3023bd122eeSRahul Lakkireddy
303dd7c9f12SRahul Lakkireddy struct adapter_devargs {
304dd7c9f12SRahul Lakkireddy bool keep_ovlan;
305dd7c9f12SRahul Lakkireddy bool force_link_up;
306fa033437SRahul Lakkireddy bool tx_mode_latency;
307536db938SKarra Satwik u32 filtermode;
308536db938SKarra Satwik u32 filtermask;
309dd7c9f12SRahul Lakkireddy };
310dd7c9f12SRahul Lakkireddy
3113bd122eeSRahul Lakkireddy struct adapter {
3123bd122eeSRahul Lakkireddy struct rte_pci_device *pdev; /* associated rte pci device */
3133bd122eeSRahul Lakkireddy struct rte_eth_dev *eth_dev; /* first port's rte eth device */
3143bd122eeSRahul Lakkireddy struct adapter_params params; /* adapter parameters */
3152195df6dSRahul Lakkireddy struct port_info *port[MAX_NPORTS];/* ports belonging to this adapter */
3163bd122eeSRahul Lakkireddy struct sge sge; /* associated SGE */
3173bd122eeSRahul Lakkireddy
3183bd122eeSRahul Lakkireddy /* support for single-threading access to adapter mailbox registers */
3193bd122eeSRahul Lakkireddy struct mbox_list mbox_list;
3203bd122eeSRahul Lakkireddy rte_spinlock_t mbox_lock;
3213bd122eeSRahul Lakkireddy
3223bd122eeSRahul Lakkireddy u8 *regs; /* pointer to registers region */
3233bd122eeSRahul Lakkireddy u8 *bar2; /* pointer to bar2 region */
3243bd122eeSRahul Lakkireddy unsigned long flags; /* adapter flags */
3253bd122eeSRahul Lakkireddy unsigned int mbox; /* associated mailbox */
3263bd122eeSRahul Lakkireddy unsigned int pf; /* associated physical function id */
3273bd122eeSRahul Lakkireddy
328fe0bd9eeSRahul Lakkireddy unsigned int vpd_busy;
329fe0bd9eeSRahul Lakkireddy unsigned int vpd_flag;
330fe0bd9eeSRahul Lakkireddy
3313bd122eeSRahul Lakkireddy int use_unpacked_mode; /* unpacked rx mode state */
3328d3c12e1SShagun Agrawal rte_spinlock_t win0_lock;
3336f2a064bSShagun Agrawal
33497e02581SRahul Lakkireddy rte_spinlock_t flow_lock; /* Serialize access for rte_flow ops */
33597e02581SRahul Lakkireddy
3363f2c1e20SShagun Agrawal unsigned int clipt_start; /* CLIP table start */
3373f2c1e20SShagun Agrawal unsigned int clipt_end; /* CLIP table end */
33823af667fSShagun Agrawal unsigned int l2t_start; /* Layer 2 table start */
33923af667fSShagun Agrawal unsigned int l2t_end; /* Layer 2 table end */
3403f2c1e20SShagun Agrawal struct clip_tbl *clipt; /* CLIP table */
34123af667fSShagun Agrawal struct l2t_data *l2t; /* Layer 2 table */
342a99564c6SKarra Satwik struct smt_data *smt; /* Source mac table */
3436fda3f0dSShagun Agrawal struct mpstcam_table *mpstcam;
3443f2c1e20SShagun Agrawal
3456f2a064bSShagun Agrawal struct tid_info tids; /* Info used to access TID related tables */
346dd7c9f12SRahul Lakkireddy
347dd7c9f12SRahul Lakkireddy struct adapter_devargs devargs;
3483bd122eeSRahul Lakkireddy };
3493bd122eeSRahul Lakkireddy
3502195df6dSRahul Lakkireddy /**
3513f2c1e20SShagun Agrawal * t4_os_rwlock_init - initialize rwlock
3523f2c1e20SShagun Agrawal * @lock: the rwlock
3533f2c1e20SShagun Agrawal */
354a027e890SDavid Marchand #define t4_os_rwlock_init(lock) rte_rwlock_init(lock)
3553f2c1e20SShagun Agrawal
3563f2c1e20SShagun Agrawal /**
3573f2c1e20SShagun Agrawal * t4_os_write_lock - get a write lock
3583f2c1e20SShagun Agrawal * @lock: the rwlock
3593f2c1e20SShagun Agrawal */
360a027e890SDavid Marchand #define t4_os_write_lock(lock) rte_rwlock_write_lock(lock)
3613f2c1e20SShagun Agrawal
3623f2c1e20SShagun Agrawal /**
3633f2c1e20SShagun Agrawal * t4_os_write_unlock - unlock a write lock
3643f2c1e20SShagun Agrawal * @lock: the rwlock
3653f2c1e20SShagun Agrawal */
366a027e890SDavid Marchand #define t4_os_write_unlock(lock) rte_rwlock_write_unlock(lock)
3673f2c1e20SShagun Agrawal
3683f2c1e20SShagun Agrawal /**
369ee61f511SShagun Agrawal * ethdev2pinfo - return the port_info structure associated with a rte_eth_dev
370ee61f511SShagun Agrawal * @dev: the rte_eth_dev
371ee61f511SShagun Agrawal *
372ee61f511SShagun Agrawal * Return the struct port_info associated with a rte_eth_dev
373ee61f511SShagun Agrawal */
ethdev2pinfo(const struct rte_eth_dev * dev)374ee61f511SShagun Agrawal static inline struct port_info *ethdev2pinfo(const struct rte_eth_dev *dev)
375ee61f511SShagun Agrawal {
37663a97e58SStephen Hemminger return dev->data->dev_private;
377ee61f511SShagun Agrawal }
378ee61f511SShagun Agrawal
379ee61f511SShagun Agrawal /**
3802195df6dSRahul Lakkireddy * adap2pinfo - return the port_info of a port
3812195df6dSRahul Lakkireddy * @adap: the adapter
3822195df6dSRahul Lakkireddy * @idx: the port index
3832195df6dSRahul Lakkireddy *
3842195df6dSRahul Lakkireddy * Return the port_info structure for the port of the given index.
3852195df6dSRahul Lakkireddy */
adap2pinfo(const struct adapter * adap,int idx)3862195df6dSRahul Lakkireddy static inline struct port_info *adap2pinfo(const struct adapter *adap, int idx)
3872195df6dSRahul Lakkireddy {
3882195df6dSRahul Lakkireddy return adap->port[idx];
3892195df6dSRahul Lakkireddy }
3902195df6dSRahul Lakkireddy
391ee61f511SShagun Agrawal /**
392ee61f511SShagun Agrawal * ethdev2adap - return the adapter structure associated with a rte_eth_dev
393ee61f511SShagun Agrawal * @dev: the rte_eth_dev
394ee61f511SShagun Agrawal *
395ee61f511SShagun Agrawal * Return the struct adapter associated with a rte_eth_dev
396ee61f511SShagun Agrawal */
ethdev2adap(const struct rte_eth_dev * dev)397ee61f511SShagun Agrawal static inline struct adapter *ethdev2adap(const struct rte_eth_dev *dev)
398ee61f511SShagun Agrawal {
399ee61f511SShagun Agrawal return ethdev2pinfo(dev)->adapter;
400ee61f511SShagun Agrawal }
401ee61f511SShagun Agrawal
402c167acb6SSantosh Shukla #define CXGBE_PCI_REG(reg) rte_read32(reg)
4033bd122eeSRahul Lakkireddy
cxgbe_read_addr64(volatile void * addr)4043bd122eeSRahul Lakkireddy static inline uint64_t cxgbe_read_addr64(volatile void *addr)
4053bd122eeSRahul Lakkireddy {
4063bd122eeSRahul Lakkireddy uint64_t val = CXGBE_PCI_REG(addr);
4073bd122eeSRahul Lakkireddy uint64_t val2 = CXGBE_PCI_REG(((volatile uint8_t *)(addr) + 4));
4083bd122eeSRahul Lakkireddy
4093bd122eeSRahul Lakkireddy val2 = (uint64_t)(val2 << 32);
4103bd122eeSRahul Lakkireddy val += val2;
4113bd122eeSRahul Lakkireddy return val;
4123bd122eeSRahul Lakkireddy }
4133bd122eeSRahul Lakkireddy
cxgbe_read_addr(volatile void * addr)4143bd122eeSRahul Lakkireddy static inline uint32_t cxgbe_read_addr(volatile void *addr)
4153bd122eeSRahul Lakkireddy {
4163bd122eeSRahul Lakkireddy return CXGBE_PCI_REG(addr);
4173bd122eeSRahul Lakkireddy }
4183bd122eeSRahul Lakkireddy
4193bd122eeSRahul Lakkireddy #define CXGBE_PCI_REG_ADDR(adap, reg) \
4203bd122eeSRahul Lakkireddy ((volatile uint32_t *)((char *)(adap)->regs + (reg)))
4213bd122eeSRahul Lakkireddy
4223bd122eeSRahul Lakkireddy #define CXGBE_READ_REG(adap, reg) \
4233bd122eeSRahul Lakkireddy cxgbe_read_addr(CXGBE_PCI_REG_ADDR((adap), (reg)))
4243bd122eeSRahul Lakkireddy
4253bd122eeSRahul Lakkireddy #define CXGBE_READ_REG64(adap, reg) \
4263bd122eeSRahul Lakkireddy cxgbe_read_addr64(CXGBE_PCI_REG_ADDR((adap), (reg)))
4273bd122eeSRahul Lakkireddy
428c167acb6SSantosh Shukla #define CXGBE_PCI_REG_WRITE(reg, value) rte_write32((value), (reg))
429c167acb6SSantosh Shukla
430c167acb6SSantosh Shukla #define CXGBE_PCI_REG_WRITE_RELAXED(reg, value) \
431c167acb6SSantosh Shukla rte_write32_relaxed((value), (reg))
4323bd122eeSRahul Lakkireddy
4333bd122eeSRahul Lakkireddy #define CXGBE_WRITE_REG(adap, reg, value) \
4343bd122eeSRahul Lakkireddy CXGBE_PCI_REG_WRITE(CXGBE_PCI_REG_ADDR((adap), (reg)), (value))
4353bd122eeSRahul Lakkireddy
436c167acb6SSantosh Shukla #define CXGBE_WRITE_REG_RELAXED(adap, reg, value) \
437c167acb6SSantosh Shukla CXGBE_PCI_REG_WRITE_RELAXED(CXGBE_PCI_REG_ADDR((adap), (reg)), (value))
438c167acb6SSantosh Shukla
cxgbe_write_addr64(volatile void * addr,uint64_t val)4393bd122eeSRahul Lakkireddy static inline uint64_t cxgbe_write_addr64(volatile void *addr, uint64_t val)
4403bd122eeSRahul Lakkireddy {
441c167acb6SSantosh Shukla CXGBE_PCI_REG_WRITE(addr, val);
442c167acb6SSantosh Shukla CXGBE_PCI_REG_WRITE(((volatile uint8_t *)(addr) + 4), (val >> 32));
4433bd122eeSRahul Lakkireddy return val;
4443bd122eeSRahul Lakkireddy }
4453bd122eeSRahul Lakkireddy
4463bd122eeSRahul Lakkireddy #define CXGBE_WRITE_REG64(adap, reg, value) \
4473bd122eeSRahul Lakkireddy cxgbe_write_addr64(CXGBE_PCI_REG_ADDR((adap), (reg)), (value))
4483bd122eeSRahul Lakkireddy
4493bd122eeSRahul Lakkireddy /**
4503bd122eeSRahul Lakkireddy * t4_read_reg - read a HW register
4513bd122eeSRahul Lakkireddy * @adapter: the adapter
4523bd122eeSRahul Lakkireddy * @reg_addr: the register address
4533bd122eeSRahul Lakkireddy *
4543bd122eeSRahul Lakkireddy * Returns the 32-bit value of the given HW register.
4553bd122eeSRahul Lakkireddy */
t4_read_reg(struct adapter * adapter,u32 reg_addr)4563bd122eeSRahul Lakkireddy static inline u32 t4_read_reg(struct adapter *adapter, u32 reg_addr)
4573bd122eeSRahul Lakkireddy {
45870977725SRahul Lakkireddy return CXGBE_READ_REG(adapter, reg_addr);
4593bd122eeSRahul Lakkireddy }
4603bd122eeSRahul Lakkireddy
4613bd122eeSRahul Lakkireddy /**
462c167acb6SSantosh Shukla * t4_write_reg - write a HW register with barrier
4633bd122eeSRahul Lakkireddy * @adapter: the adapter
4643bd122eeSRahul Lakkireddy * @reg_addr: the register address
4653bd122eeSRahul Lakkireddy * @val: the value to write
4663bd122eeSRahul Lakkireddy *
4673bd122eeSRahul Lakkireddy * Write a 32-bit value into the given HW register.
4683bd122eeSRahul Lakkireddy */
t4_write_reg(struct adapter * adapter,u32 reg_addr,u32 val)4693bd122eeSRahul Lakkireddy static inline void t4_write_reg(struct adapter *adapter, u32 reg_addr, u32 val)
4703bd122eeSRahul Lakkireddy {
4713bd122eeSRahul Lakkireddy CXGBE_WRITE_REG(adapter, reg_addr, val);
4723bd122eeSRahul Lakkireddy }
4733bd122eeSRahul Lakkireddy
4743bd122eeSRahul Lakkireddy /**
475c167acb6SSantosh Shukla * t4_write_reg_relaxed - write a HW register with no barrier
476c167acb6SSantosh Shukla * @adapter: the adapter
477c167acb6SSantosh Shukla * @reg_addr: the register address
478c167acb6SSantosh Shukla * @val: the value to write
479c167acb6SSantosh Shukla *
480c167acb6SSantosh Shukla * Write a 32-bit value into the given HW register.
481c167acb6SSantosh Shukla */
t4_write_reg_relaxed(struct adapter * adapter,u32 reg_addr,u32 val)482c167acb6SSantosh Shukla static inline void t4_write_reg_relaxed(struct adapter *adapter, u32 reg_addr,
483c167acb6SSantosh Shukla u32 val)
484c167acb6SSantosh Shukla {
485c167acb6SSantosh Shukla CXGBE_WRITE_REG_RELAXED(adapter, reg_addr, val);
486c167acb6SSantosh Shukla }
487c167acb6SSantosh Shukla
488c167acb6SSantosh Shukla /**
4893bd122eeSRahul Lakkireddy * t4_read_reg64 - read a 64-bit HW register
4903bd122eeSRahul Lakkireddy * @adapter: the adapter
4913bd122eeSRahul Lakkireddy * @reg_addr: the register address
4923bd122eeSRahul Lakkireddy *
4933bd122eeSRahul Lakkireddy * Returns the 64-bit value of the given HW register.
4943bd122eeSRahul Lakkireddy */
t4_read_reg64(struct adapter * adapter,u32 reg_addr)4953bd122eeSRahul Lakkireddy static inline u64 t4_read_reg64(struct adapter *adapter, u32 reg_addr)
4963bd122eeSRahul Lakkireddy {
49770977725SRahul Lakkireddy return CXGBE_READ_REG64(adapter, reg_addr);
4983bd122eeSRahul Lakkireddy }
4993bd122eeSRahul Lakkireddy
5003bd122eeSRahul Lakkireddy /**
5013bd122eeSRahul Lakkireddy * t4_write_reg64 - write a 64-bit HW register
5023bd122eeSRahul Lakkireddy * @adapter: the adapter
5033bd122eeSRahul Lakkireddy * @reg_addr: the register address
5043bd122eeSRahul Lakkireddy * @val: the value to write
5053bd122eeSRahul Lakkireddy *
5063bd122eeSRahul Lakkireddy * Write a 64-bit value into the given HW register.
5073bd122eeSRahul Lakkireddy */
t4_write_reg64(struct adapter * adapter,u32 reg_addr,u64 val)5083bd122eeSRahul Lakkireddy static inline void t4_write_reg64(struct adapter *adapter, u32 reg_addr,
5093bd122eeSRahul Lakkireddy u64 val)
5103bd122eeSRahul Lakkireddy {
5113bd122eeSRahul Lakkireddy CXGBE_WRITE_REG64(adapter, reg_addr, val);
5123bd122eeSRahul Lakkireddy }
5133bd122eeSRahul Lakkireddy
514baa9c550SDavid Marchand #define PCI_CAP_ID_EXP RTE_PCI_CAP_ID_EXP
515edd04c61SRahul Lakkireddy #define PCI_EXP_DEVCTL 0x0008 /* Device control */
516d90c1961SRahul Lakkireddy #define PCI_EXP_DEVCTL2 40 /* Device Control 2 */
517ee606d92SRahul Lakkireddy #define PCI_EXP_DEVCTL_EXT_TAG 0x0100 /* Extended Tag Field Enable */
518edd04c61SRahul Lakkireddy #define PCI_EXP_DEVCTL_PAYLOAD 0x00E0 /* Max payload */
519fe0bd9eeSRahul Lakkireddy #define PCI_CAP_ID_VPD 0x03 /* Vital Product Data */
520fe0bd9eeSRahul Lakkireddy #define PCI_VPD_ADDR 2 /* Address to access (15 bits!) */
521fe0bd9eeSRahul Lakkireddy #define PCI_VPD_ADDR_F 0x8000 /* Write 0, 1 indicates completion */
522fe0bd9eeSRahul Lakkireddy #define PCI_VPD_DATA 4 /* 32-bits of data returned here */
5235c81b1a9SRahul Lakkireddy
5245c81b1a9SRahul Lakkireddy /**
5255c81b1a9SRahul Lakkireddy * t4_os_pci_write_cfg4 - 32-bit write to PCI config space
5265c81b1a9SRahul Lakkireddy * @adapter: the adapter
5275c81b1a9SRahul Lakkireddy * @addr: the register address
5285c81b1a9SRahul Lakkireddy * @val: the value to write
5295c81b1a9SRahul Lakkireddy *
5305c81b1a9SRahul Lakkireddy * Write a 32-bit value into the given register in PCI config space.
5315c81b1a9SRahul Lakkireddy */
t4_os_pci_write_cfg4(struct adapter * adapter,size_t addr,off_t val)5325c81b1a9SRahul Lakkireddy static inline void t4_os_pci_write_cfg4(struct adapter *adapter, size_t addr,
5335c81b1a9SRahul Lakkireddy off_t val)
5345c81b1a9SRahul Lakkireddy {
5355c81b1a9SRahul Lakkireddy u32 val32 = val;
5365c81b1a9SRahul Lakkireddy
5373dcfe039SThomas Monjalon if (rte_pci_write_config(adapter->pdev, &val32, sizeof(val32),
5385c81b1a9SRahul Lakkireddy addr) < 0)
5395c81b1a9SRahul Lakkireddy dev_err(adapter, "Can't write to PCI config space\n");
5405c81b1a9SRahul Lakkireddy }
5415c81b1a9SRahul Lakkireddy
5425c81b1a9SRahul Lakkireddy /**
5435c81b1a9SRahul Lakkireddy * t4_os_pci_read_cfg4 - read a 32-bit value from PCI config space
5445c81b1a9SRahul Lakkireddy * @adapter: the adapter
5455c81b1a9SRahul Lakkireddy * @addr: the register address
5465c81b1a9SRahul Lakkireddy * @val: where to store the value read
5475c81b1a9SRahul Lakkireddy *
5485c81b1a9SRahul Lakkireddy * Read a 32-bit value from the given register in PCI config space.
5495c81b1a9SRahul Lakkireddy */
t4_os_pci_read_cfg4(struct adapter * adapter,size_t addr,u32 * val)5505c81b1a9SRahul Lakkireddy static inline void t4_os_pci_read_cfg4(struct adapter *adapter, size_t addr,
5515c81b1a9SRahul Lakkireddy u32 *val)
5525c81b1a9SRahul Lakkireddy {
5533dcfe039SThomas Monjalon if (rte_pci_read_config(adapter->pdev, val, sizeof(*val),
5545c81b1a9SRahul Lakkireddy addr) < 0)
5555c81b1a9SRahul Lakkireddy dev_err(adapter, "Can't read from PCI config space\n");
5565c81b1a9SRahul Lakkireddy }
5575c81b1a9SRahul Lakkireddy
5585c81b1a9SRahul Lakkireddy /**
5595c81b1a9SRahul Lakkireddy * t4_os_pci_write_cfg2 - 16-bit write to PCI config space
5605c81b1a9SRahul Lakkireddy * @adapter: the adapter
5615c81b1a9SRahul Lakkireddy * @addr: the register address
5625c81b1a9SRahul Lakkireddy * @val: the value to write
5635c81b1a9SRahul Lakkireddy *
5645c81b1a9SRahul Lakkireddy * Write a 16-bit value into the given register in PCI config space.
5655c81b1a9SRahul Lakkireddy */
t4_os_pci_write_cfg2(struct adapter * adapter,size_t addr,off_t val)5665c81b1a9SRahul Lakkireddy static inline void t4_os_pci_write_cfg2(struct adapter *adapter, size_t addr,
5675c81b1a9SRahul Lakkireddy off_t val)
5685c81b1a9SRahul Lakkireddy {
5695c81b1a9SRahul Lakkireddy u16 val16 = val;
5705c81b1a9SRahul Lakkireddy
5713dcfe039SThomas Monjalon if (rte_pci_write_config(adapter->pdev, &val16, sizeof(val16),
5725c81b1a9SRahul Lakkireddy addr) < 0)
5735c81b1a9SRahul Lakkireddy dev_err(adapter, "Can't write to PCI config space\n");
5745c81b1a9SRahul Lakkireddy }
5755c81b1a9SRahul Lakkireddy
5765c81b1a9SRahul Lakkireddy /**
5775c81b1a9SRahul Lakkireddy * t4_os_pci_read_cfg2 - read a 16-bit value from PCI config space
5785c81b1a9SRahul Lakkireddy * @adapter: the adapter
5795c81b1a9SRahul Lakkireddy * @addr: the register address
5805c81b1a9SRahul Lakkireddy * @val: where to store the value read
5815c81b1a9SRahul Lakkireddy *
5825c81b1a9SRahul Lakkireddy * Read a 16-bit value from the given register in PCI config space.
5835c81b1a9SRahul Lakkireddy */
t4_os_pci_read_cfg2(struct adapter * adapter,size_t addr,u16 * val)5845c81b1a9SRahul Lakkireddy static inline void t4_os_pci_read_cfg2(struct adapter *adapter, size_t addr,
5855c81b1a9SRahul Lakkireddy u16 *val)
5865c81b1a9SRahul Lakkireddy {
5873dcfe039SThomas Monjalon if (rte_pci_read_config(adapter->pdev, val, sizeof(*val),
5885c81b1a9SRahul Lakkireddy addr) < 0)
5895c81b1a9SRahul Lakkireddy dev_err(adapter, "Can't read from PCI config space\n");
5905c81b1a9SRahul Lakkireddy }
5915c81b1a9SRahul Lakkireddy
5925c81b1a9SRahul Lakkireddy /**
5935c81b1a9SRahul Lakkireddy * t4_os_pci_read_cfg - read a 8-bit value from PCI config space
5945c81b1a9SRahul Lakkireddy * @adapter: the adapter
5955c81b1a9SRahul Lakkireddy * @addr: the register address
5965c81b1a9SRahul Lakkireddy * @val: where to store the value read
5975c81b1a9SRahul Lakkireddy *
5985c81b1a9SRahul Lakkireddy * Read a 8-bit value from the given register in PCI config space.
5995c81b1a9SRahul Lakkireddy */
t4_os_pci_read_cfg(struct adapter * adapter,size_t addr,u8 * val)6005c81b1a9SRahul Lakkireddy static inline void t4_os_pci_read_cfg(struct adapter *adapter, size_t addr,
6015c81b1a9SRahul Lakkireddy u8 *val)
6025c81b1a9SRahul Lakkireddy {
6033dcfe039SThomas Monjalon if (rte_pci_read_config(adapter->pdev, val, sizeof(*val),
6045c81b1a9SRahul Lakkireddy addr) < 0)
6055c81b1a9SRahul Lakkireddy dev_err(adapter, "Can't read from PCI config space\n");
6065c81b1a9SRahul Lakkireddy }
6075c81b1a9SRahul Lakkireddy
6085c81b1a9SRahul Lakkireddy /**
6095c81b1a9SRahul Lakkireddy * t4_os_find_pci_capability - lookup a capability in the PCI capability list
6105c81b1a9SRahul Lakkireddy * @adapter: the adapter
6115c81b1a9SRahul Lakkireddy * @cap: the capability
6125c81b1a9SRahul Lakkireddy *
6135c81b1a9SRahul Lakkireddy * Return the address of the given capability within the PCI capability list.
6145c81b1a9SRahul Lakkireddy */
t4_os_find_pci_capability(struct adapter * adapter,int cap)6155c81b1a9SRahul Lakkireddy static inline int t4_os_find_pci_capability(struct adapter *adapter, int cap)
6165c81b1a9SRahul Lakkireddy {
617a10b6e53SDavid Marchand if (!rte_pci_has_capability_list(adapter->pdev)) {
6185c81b1a9SRahul Lakkireddy dev_err(adapter, "PCIe capability reading failed\n");
6195c81b1a9SRahul Lakkireddy return -1;
6205c81b1a9SRahul Lakkireddy }
6215c81b1a9SRahul Lakkireddy
622a10b6e53SDavid Marchand return rte_pci_find_capability(adapter->pdev, cap);
6235c81b1a9SRahul Lakkireddy }
6245c81b1a9SRahul Lakkireddy
6253bd122eeSRahul Lakkireddy /**
6263bd122eeSRahul Lakkireddy * t4_os_set_hw_addr - store a port's MAC address in SW
6273bd122eeSRahul Lakkireddy * @adapter: the adapter
6283bd122eeSRahul Lakkireddy * @port_idx: the port index
6293bd122eeSRahul Lakkireddy * @hw_addr: the Ethernet address
6303bd122eeSRahul Lakkireddy *
6313bd122eeSRahul Lakkireddy * Store the Ethernet address of the given port in SW. Called by the
6323bd122eeSRahul Lakkireddy * common code when it retrieves a port's Ethernet address from EEPROM.
6333bd122eeSRahul Lakkireddy */
t4_os_set_hw_addr(struct adapter * adapter,int port_idx,u8 hw_addr[])6343bd122eeSRahul Lakkireddy static inline void t4_os_set_hw_addr(struct adapter *adapter, int port_idx,
6353bd122eeSRahul Lakkireddy u8 hw_addr[])
6363bd122eeSRahul Lakkireddy {
6372195df6dSRahul Lakkireddy struct port_info *pi = adap2pinfo(adapter, port_idx);
6383bd122eeSRahul Lakkireddy
639538da7a1SOlivier Matz rte_ether_addr_copy((struct rte_ether_addr *)hw_addr,
6403bd122eeSRahul Lakkireddy &pi->eth_dev->data->mac_addrs[0]);
6413bd122eeSRahul Lakkireddy }
6423bd122eeSRahul Lakkireddy
6433bd122eeSRahul Lakkireddy /**
6443bd122eeSRahul Lakkireddy * t4_os_lock_init - initialize spinlock
6453bd122eeSRahul Lakkireddy * @lock: the spinlock
6463bd122eeSRahul Lakkireddy */
647a027e890SDavid Marchand #define t4_os_lock_init(lock) rte_spinlock_init(lock)
6483bd122eeSRahul Lakkireddy
6493bd122eeSRahul Lakkireddy /**
6503bd122eeSRahul Lakkireddy * t4_os_lock - spin until lock is acquired
6513bd122eeSRahul Lakkireddy * @lock: the spinlock
6523bd122eeSRahul Lakkireddy */
653a027e890SDavid Marchand #define t4_os_lock(lock) rte_spinlock_lock(lock)
6543bd122eeSRahul Lakkireddy
6553bd122eeSRahul Lakkireddy /**
6563bd122eeSRahul Lakkireddy * t4_os_unlock - unlock a spinlock
6573bd122eeSRahul Lakkireddy * @lock: the spinlock
6583bd122eeSRahul Lakkireddy */
659a027e890SDavid Marchand #define t4_os_unlock(lock) rte_spinlock_unlock(lock)
6603bd122eeSRahul Lakkireddy
6613bd122eeSRahul Lakkireddy /**
662334505baSRahul Lakkireddy * t4_os_trylock - try to get a lock
663334505baSRahul Lakkireddy * @lock: the spinlock
664334505baSRahul Lakkireddy */
665a027e890SDavid Marchand #define t4_os_trylock(lock) rte_spinlock_trylock(lock)
666334505baSRahul Lakkireddy
667334505baSRahul Lakkireddy /**
6683bd122eeSRahul Lakkireddy * t4_os_init_list_head - initialize
6693bd122eeSRahul Lakkireddy * @head: head of list to initialize [to empty]
6703bd122eeSRahul Lakkireddy */
t4_os_init_list_head(struct mbox_list * head)6713bd122eeSRahul Lakkireddy static inline void t4_os_init_list_head(struct mbox_list *head)
6723bd122eeSRahul Lakkireddy {
6733bd122eeSRahul Lakkireddy TAILQ_INIT(head);
6743bd122eeSRahul Lakkireddy }
6753bd122eeSRahul Lakkireddy
t4_os_list_first_entry(struct mbox_list * head)6763bd122eeSRahul Lakkireddy static inline struct mbox_entry *t4_os_list_first_entry(struct mbox_list *head)
6773bd122eeSRahul Lakkireddy {
6783bd122eeSRahul Lakkireddy return TAILQ_FIRST(head);
6793bd122eeSRahul Lakkireddy }
6803bd122eeSRahul Lakkireddy
6813bd122eeSRahul Lakkireddy /**
6823bd122eeSRahul Lakkireddy * t4_os_atomic_add_tail - Enqueue list element atomically onto list
6833bd122eeSRahul Lakkireddy * @new: the entry to be addded to the queue
6843bd122eeSRahul Lakkireddy * @head: current head of the linked list
6853bd122eeSRahul Lakkireddy * @lock: lock to use to guarantee atomicity
6863bd122eeSRahul Lakkireddy */
t4_os_atomic_add_tail(struct mbox_entry * entry,struct mbox_list * head,rte_spinlock_t * lock)6873bd122eeSRahul Lakkireddy static inline void t4_os_atomic_add_tail(struct mbox_entry *entry,
6883bd122eeSRahul Lakkireddy struct mbox_list *head,
6893bd122eeSRahul Lakkireddy rte_spinlock_t *lock)
6903bd122eeSRahul Lakkireddy {
6913bd122eeSRahul Lakkireddy t4_os_lock(lock);
6923bd122eeSRahul Lakkireddy TAILQ_INSERT_TAIL(head, entry, next);
6933bd122eeSRahul Lakkireddy t4_os_unlock(lock);
6943bd122eeSRahul Lakkireddy }
6953bd122eeSRahul Lakkireddy
6963bd122eeSRahul Lakkireddy /**
6973bd122eeSRahul Lakkireddy * t4_os_atomic_list_del - Dequeue list element atomically from list
6983bd122eeSRahul Lakkireddy * @entry: the entry to be remove/dequeued from the list.
6993bd122eeSRahul Lakkireddy * @lock: the spinlock
7003bd122eeSRahul Lakkireddy */
t4_os_atomic_list_del(struct mbox_entry * entry,struct mbox_list * head,rte_spinlock_t * lock)7013bd122eeSRahul Lakkireddy static inline void t4_os_atomic_list_del(struct mbox_entry *entry,
7023bd122eeSRahul Lakkireddy struct mbox_list *head,
7033bd122eeSRahul Lakkireddy rte_spinlock_t *lock)
7043bd122eeSRahul Lakkireddy {
7053bd122eeSRahul Lakkireddy t4_os_lock(lock);
7063bd122eeSRahul Lakkireddy TAILQ_REMOVE(head, entry, next);
7073bd122eeSRahul Lakkireddy t4_os_unlock(lock);
7083bd122eeSRahul Lakkireddy }
7093bd122eeSRahul Lakkireddy
7109eb2c9a4SShagun Agrawal /**
7119eb2c9a4SShagun Agrawal * t4_init_completion - initialize completion
7129eb2c9a4SShagun Agrawal * @c: the completion context
7139eb2c9a4SShagun Agrawal */
t4_init_completion(struct t4_completion * c)7149eb2c9a4SShagun Agrawal static inline void t4_init_completion(struct t4_completion *c)
7159eb2c9a4SShagun Agrawal {
7169eb2c9a4SShagun Agrawal c->done = 0;
7179eb2c9a4SShagun Agrawal t4_os_lock_init(&c->lock);
7189eb2c9a4SShagun Agrawal }
7199eb2c9a4SShagun Agrawal
7209eb2c9a4SShagun Agrawal /**
7219eb2c9a4SShagun Agrawal * t4_complete - set completion as done
7229eb2c9a4SShagun Agrawal * @c: the completion context
7239eb2c9a4SShagun Agrawal */
t4_complete(struct t4_completion * c)7249eb2c9a4SShagun Agrawal static inline void t4_complete(struct t4_completion *c)
7259eb2c9a4SShagun Agrawal {
7269eb2c9a4SShagun Agrawal t4_os_lock(&c->lock);
7279eb2c9a4SShagun Agrawal c->done = 1;
7289eb2c9a4SShagun Agrawal t4_os_unlock(&c->lock);
7299eb2c9a4SShagun Agrawal }
7309eb2c9a4SShagun Agrawal
731af44a577SShagun Agrawal /**
732af44a577SShagun Agrawal * cxgbe_port_viid - get the VI id of a port
733af44a577SShagun Agrawal * @dev: the device for the port
734af44a577SShagun Agrawal *
735af44a577SShagun Agrawal * Return the VI id of the given port.
736af44a577SShagun Agrawal */
cxgbe_port_viid(const struct rte_eth_dev * dev)737af44a577SShagun Agrawal static inline unsigned int cxgbe_port_viid(const struct rte_eth_dev *dev)
738af44a577SShagun Agrawal {
739af44a577SShagun Agrawal return ethdev2pinfo(dev)->viid;
740af44a577SShagun Agrawal }
741af44a577SShagun Agrawal
7423bd122eeSRahul Lakkireddy void *t4_alloc_mem(size_t size);
7433bd122eeSRahul Lakkireddy void t4_free_mem(void *addr);
7443bd122eeSRahul Lakkireddy #define t4_os_alloc(_size) t4_alloc_mem((_size))
7453bd122eeSRahul Lakkireddy #define t4_os_free(_ptr) t4_free_mem((_ptr))
7463bd122eeSRahul Lakkireddy
7473bd122eeSRahul Lakkireddy void t4_os_portmod_changed(const struct adapter *adap, int port_id);
74823d5fee3SRahul Lakkireddy void t4_os_link_changed(struct adapter *adap, int port_id);
7493bd122eeSRahul Lakkireddy
7503bd122eeSRahul Lakkireddy void reclaim_completed_tx(struct sge_txq *q);
7513bd122eeSRahul Lakkireddy void t4_free_sge_resources(struct adapter *adap);
7523bd122eeSRahul Lakkireddy void t4_sge_tx_monitor_start(struct adapter *adap);
7533bd122eeSRahul Lakkireddy void t4_sge_tx_monitor_stop(struct adapter *adap);
7546c280962SRahul Lakkireddy int t4_eth_xmit(struct sge_eth_txq *txq, struct rte_mbuf *mbuf,
7556c280962SRahul Lakkireddy uint16_t nb_pkts);
7563a3aaabcSShagun Agrawal int t4_mgmt_tx(struct sge_ctrl_txq *txq, struct rte_mbuf *mbuf);
7573bd122eeSRahul Lakkireddy int t4_sge_init(struct adapter *adap);
7585e59e39aSKumar Sanghvi int t4vf_sge_init(struct adapter *adap);
7593bd122eeSRahul Lakkireddy int t4_sge_alloc_eth_txq(struct adapter *adap, struct sge_eth_txq *txq,
7603bd122eeSRahul Lakkireddy struct rte_eth_dev *eth_dev, uint16_t queue_id,
7613bd122eeSRahul Lakkireddy unsigned int iqid, int socket_id);
7623a3aaabcSShagun Agrawal int t4_sge_alloc_ctrl_txq(struct adapter *adap, struct sge_ctrl_txq *txq,
7633a3aaabcSShagun Agrawal struct rte_eth_dev *eth_dev, uint16_t queue_id,
7643a3aaabcSShagun Agrawal unsigned int iqid, int socket_id);
7653bd122eeSRahul Lakkireddy int t4_sge_alloc_rxq(struct adapter *adap, struct sge_rspq *rspq, bool fwevtq,
7663bd122eeSRahul Lakkireddy struct rte_eth_dev *eth_dev, int intr_idx,
7673bd122eeSRahul Lakkireddy struct sge_fl *fl, rspq_handler_t handler,
7683bd122eeSRahul Lakkireddy int cong, struct rte_mempool *mp, int queue_id,
7693bd122eeSRahul Lakkireddy int socket_id);
7703bd122eeSRahul Lakkireddy int t4_sge_eth_txq_start(struct sge_eth_txq *txq);
7713bd122eeSRahul Lakkireddy int t4_sge_eth_txq_stop(struct sge_eth_txq *txq);
7723bd122eeSRahul Lakkireddy void t4_sge_eth_txq_release(struct adapter *adap, struct sge_eth_txq *txq);
773e30e5407SRahul Lakkireddy int t4_sge_eth_rxq_start(struct adapter *adap, struct sge_eth_rxq *rxq);
774e30e5407SRahul Lakkireddy int t4_sge_eth_rxq_stop(struct adapter *adap, struct sge_eth_rxq *rxq);
7753bd122eeSRahul Lakkireddy void t4_sge_eth_rxq_release(struct adapter *adap, struct sge_eth_rxq *rxq);
7763bd122eeSRahul Lakkireddy void t4_sge_eth_clear_queues(struct port_info *pi);
7776b78a629SRahul Lakkireddy void t4_sge_eth_release_queues(struct port_info *pi);
7783bd122eeSRahul Lakkireddy int cxgb4_set_rspq_intr_params(struct sge_rspq *q, unsigned int us,
7793bd122eeSRahul Lakkireddy unsigned int cnt);
7803bd122eeSRahul Lakkireddy int cxgbe_poll(struct sge_rspq *q, struct rte_mbuf **rx_pkts,
7813bd122eeSRahul Lakkireddy unsigned int budget, unsigned int *work_done);
78208e21af9SKumar Sanghvi int cxgbe_write_rss(const struct port_info *pi, const u16 *queues);
78308e21af9SKumar Sanghvi int cxgbe_write_rss_conf(const struct port_info *pi, uint64_t flags);
7843bd122eeSRahul Lakkireddy
7853bd122eeSRahul Lakkireddy #endif /* __T4_ADAPTER_H__ */
786