8c830a5c0650b845ee9a0ce67219177f325ff72a
[dpdk.git] / drivers / net / enetc / enetc.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018-2019 NXP
3  */
4
5 #ifndef _ENETC_H_
6 #define _ENETC_H_
7
8 #include <rte_time.h>
9
10 #include "base/enetc_hw.h"
11
12 #define PCI_VENDOR_ID_FREESCALE 0x1957
13
14 /* Max TX rings per ENETC. */
15 #define MAX_TX_RINGS    2
16
17 /* Max RX rings per ENTEC. */
18 #define MAX_RX_RINGS    1
19
20 /* Max BD counts per Ring. */
21 #define MAX_BD_COUNT   64000
22 /* Min BD counts per Ring. */
23 #define MIN_BD_COUNT   32
24 /* BD ALIGN */
25 #define BD_ALIGN       8
26
27 /* minimum frame size supported */
28 #define ENETC_MAC_MINFRM_SIZE   68
29 /* maximum frame size supported */
30 #define ENETC_MAC_MAXFRM_SIZE   9600
31
32 /*
33  * upper_32_bits - return bits 32-63 of a number
34  * @n: the number we're accessing
35  *
36  * A basic shift-right of a 64- or 32-bit quantity.  Use this to suppress
37  * the "right shift count >= width of type" warning when that quantity is
38  * 32-bits.
39  */
40 #define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16))
41
42 /*
43  * lower_32_bits - return bits 0-31 of a number
44  * @n: the number we're accessing
45  */
46 #define lower_32_bits(n) ((uint32_t)(n))
47
48 #define ENETC_TXBD(BDR, i) (&(((struct enetc_tx_bd *)((BDR).bd_base))[i]))
49 #define ENETC_RXBD(BDR, i) (&(((union enetc_rx_bd *)((BDR).bd_base))[i]))
50
51 struct enetc_swbd {
52         struct rte_mbuf *buffer_addr;
53 };
54
55 struct enetc_bdr {
56         struct rte_eth_dev *ndev;
57         struct rte_mempool *mb_pool;   /* mbuf pool to populate RX ring. */
58         void *bd_base;                  /* points to Rx or Tx BD ring */
59         union {
60                 void *tcir;
61                 void *rcir;
62         };
63         uint16_t index;
64         int bd_count; /* # of BDs */
65         int next_to_use;
66         int next_to_clean;
67         struct enetc_swbd *q_swbd;
68         union {
69                 void *tcisr; /* Tx */
70                 int next_to_alloc; /* Rx */
71         };
72         uint8_t crc_len; /* 0 if CRC stripped, 4 otherwise */
73 };
74
75 /*
76  * Structure to store private data for each driver instance (for each port).
77  */
78 struct enetc_eth_adapter {
79         struct rte_eth_dev *ndev;
80         struct enetc_eth_hw hw;
81 };
82
83 #define ENETC_DEV_PRIVATE(adapter) \
84         ((struct enetc_eth_adapter *)adapter)
85
86 #define ENETC_DEV_PRIVATE_TO_HW(adapter) \
87         (&((struct enetc_eth_adapter *)adapter)->hw)
88
89 #define ENETC_DEV_PRIVATE_TO_STATS(adapter) \
90         (&((struct enetc_eth_adapter *)adapter)->stats)
91
92 #define ENETC_DEV_PRIVATE_TO_INTR(adapter) \
93         (&((struct enetc_eth_adapter *)adapter)->intr)
94
95 /*
96  * RX/TX ENETC function prototypes
97  */
98 uint16_t enetc_xmit_pkts(void *txq, struct rte_mbuf **tx_pkts,
99                 uint16_t nb_pkts);
100 uint16_t enetc_recv_pkts(void *rxq, struct rte_mbuf **rx_pkts,
101                 uint16_t nb_pkts);
102
103
104 int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt);
105
106 static inline int
107 enetc_bd_unused(struct enetc_bdr *bdr)
108 {
109         if (bdr->next_to_clean > bdr->next_to_use)
110                 return bdr->next_to_clean - bdr->next_to_use - 1;
111
112         return bdr->bd_count + bdr->next_to_clean - bdr->next_to_use - 1;
113 }
114 #endif /* _ENETC_H_ */