net/octeontx2: add Rx and Tx descriptor operations
[dpdk.git] / drivers / net / octeontx2 / otx2_ethdev_ops.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #include <rte_mbuf_pool_ops.h>
6
7 #include "otx2_ethdev.h"
8
9 static void
10 nix_cgx_promisc_config(struct rte_eth_dev *eth_dev, int en)
11 {
12         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
13         struct otx2_mbox *mbox = dev->mbox;
14
15         if (otx2_dev_is_vf(dev))
16                 return;
17
18         if (en)
19                 otx2_mbox_alloc_msg_cgx_promisc_enable(mbox);
20         else
21                 otx2_mbox_alloc_msg_cgx_promisc_disable(mbox);
22
23         otx2_mbox_process(mbox);
24 }
25
26 void
27 otx2_nix_promisc_config(struct rte_eth_dev *eth_dev, int en)
28 {
29         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
30         struct otx2_mbox *mbox = dev->mbox;
31         struct nix_rx_mode *req;
32
33         if (otx2_dev_is_vf(dev))
34                 return;
35
36         req = otx2_mbox_alloc_msg_nix_set_rx_mode(mbox);
37
38         if (en)
39                 req->mode = NIX_RX_MODE_UCAST | NIX_RX_MODE_PROMISC;
40
41         otx2_mbox_process(mbox);
42         eth_dev->data->promiscuous = en;
43 }
44
45 void
46 otx2_nix_promisc_enable(struct rte_eth_dev *eth_dev)
47 {
48         otx2_nix_promisc_config(eth_dev, 1);
49         nix_cgx_promisc_config(eth_dev, 1);
50 }
51
52 void
53 otx2_nix_promisc_disable(struct rte_eth_dev *eth_dev)
54 {
55         otx2_nix_promisc_config(eth_dev, 0);
56         nix_cgx_promisc_config(eth_dev, 0);
57 }
58
59 static void
60 nix_allmulticast_config(struct rte_eth_dev *eth_dev, int en)
61 {
62         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
63         struct otx2_mbox *mbox = dev->mbox;
64         struct nix_rx_mode *req;
65
66         if (otx2_dev_is_vf(dev))
67                 return;
68
69         req = otx2_mbox_alloc_msg_nix_set_rx_mode(mbox);
70
71         if (en)
72                 req->mode = NIX_RX_MODE_UCAST | NIX_RX_MODE_ALLMULTI;
73         else if (eth_dev->data->promiscuous)
74                 req->mode = NIX_RX_MODE_UCAST | NIX_RX_MODE_PROMISC;
75
76         otx2_mbox_process(mbox);
77 }
78
79 void
80 otx2_nix_allmulticast_enable(struct rte_eth_dev *eth_dev)
81 {
82         nix_allmulticast_config(eth_dev, 1);
83 }
84
85 void
86 otx2_nix_allmulticast_disable(struct rte_eth_dev *eth_dev)
87 {
88         nix_allmulticast_config(eth_dev, 0);
89 }
90
91 void
92 otx2_nix_rxq_info_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
93                       struct rte_eth_rxq_info *qinfo)
94 {
95         struct otx2_eth_rxq *rxq;
96
97         rxq = eth_dev->data->rx_queues[queue_id];
98
99         qinfo->mp = rxq->pool;
100         qinfo->scattered_rx = eth_dev->data->scattered_rx;
101         qinfo->nb_desc = rxq->qconf.nb_desc;
102
103         qinfo->conf.rx_free_thresh = 0;
104         qinfo->conf.rx_drop_en = 0;
105         qinfo->conf.rx_deferred_start = 0;
106         qinfo->conf.offloads = rxq->offloads;
107 }
108
109 void
110 otx2_nix_txq_info_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
111                       struct rte_eth_txq_info *qinfo)
112 {
113         struct otx2_eth_txq *txq;
114
115         txq = eth_dev->data->tx_queues[queue_id];
116
117         qinfo->nb_desc = txq->qconf.nb_desc;
118
119         qinfo->conf.tx_thresh.pthresh = 0;
120         qinfo->conf.tx_thresh.hthresh = 0;
121         qinfo->conf.tx_thresh.wthresh = 0;
122
123         qinfo->conf.tx_free_thresh = 0;
124         qinfo->conf.tx_rs_thresh = 0;
125         qinfo->conf.offloads = txq->offloads;
126         qinfo->conf.tx_deferred_start = 0;
127 }
128
129 static void
130 nix_rx_head_tail_get(struct otx2_eth_dev *dev,
131                      uint32_t *head, uint32_t *tail, uint16_t queue_idx)
132 {
133         uint64_t reg, val;
134
135         if (head == NULL || tail == NULL)
136                 return;
137
138         reg = (((uint64_t)queue_idx) << 32);
139         val = otx2_atomic64_add_nosync(reg, (int64_t *)
140                                        (dev->base + NIX_LF_CQ_OP_STATUS));
141         if (val & (OP_ERR | CQ_ERR))
142                 val = 0;
143
144         *tail = (uint32_t)(val & 0xFFFFF);
145         *head = (uint32_t)((val >> 20) & 0xFFFFF);
146 }
147
148 uint32_t
149 otx2_nix_rx_queue_count(struct rte_eth_dev *eth_dev, uint16_t queue_idx)
150 {
151         struct otx2_eth_rxq *rxq = eth_dev->data->rx_queues[queue_idx];
152         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
153         uint32_t head, tail;
154
155         nix_rx_head_tail_get(dev, &head, &tail, queue_idx);
156         return (tail - head) % rxq->qlen;
157 }
158
159 static inline int
160 nix_offset_has_packet(uint32_t head, uint32_t tail, uint16_t offset)
161 {
162         /* Check given offset(queue index) has packet filled by HW */
163         if (tail > head && offset <= tail && offset >= head)
164                 return 1;
165         /* Wrap around case */
166         if (head > tail && (offset >= head || offset <= tail))
167                 return 1;
168
169         return 0;
170 }
171
172 int
173 otx2_nix_rx_descriptor_done(void *rx_queue, uint16_t offset)
174 {
175         struct otx2_eth_rxq *rxq = rx_queue;
176         uint32_t head, tail;
177
178         nix_rx_head_tail_get(otx2_eth_pmd_priv(rxq->eth_dev),
179                              &head, &tail, rxq->rq);
180
181         return nix_offset_has_packet(head, tail, offset);
182 }
183
184 int
185 otx2_nix_rx_descriptor_status(void *rx_queue, uint16_t offset)
186 {
187         struct otx2_eth_rxq *rxq = rx_queue;
188         uint32_t head, tail;
189
190         if (rxq->qlen >= offset)
191                 return -EINVAL;
192
193         nix_rx_head_tail_get(otx2_eth_pmd_priv(rxq->eth_dev),
194                              &head, &tail, rxq->rq);
195
196         if (nix_offset_has_packet(head, tail, offset))
197                 return RTE_ETH_RX_DESC_DONE;
198         else
199                 return RTE_ETH_RX_DESC_AVAIL;
200 }
201
202 /* It is a NOP for octeontx2 as HW frees the buffer on xmit */
203 int
204 otx2_nix_tx_done_cleanup(void *txq, uint32_t free_cnt)
205 {
206         RTE_SET_USED(txq);
207         RTE_SET_USED(free_cnt);
208
209         return 0;
210 }
211
212 int
213 otx2_nix_pool_ops_supported(struct rte_eth_dev *eth_dev, const char *pool)
214 {
215         RTE_SET_USED(eth_dev);
216
217         if (!strcmp(pool, rte_mbuf_platform_mempool_ops()))
218                 return 0;
219
220         return -ENOTSUP;
221 }
222
223 void
224 otx2_nix_info_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *devinfo)
225 {
226         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
227         struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
228
229         devinfo->min_rx_bufsize = NIX_MIN_FRS;
230         devinfo->max_rx_pktlen = NIX_MAX_FRS;
231         devinfo->max_rx_queues = RTE_MAX_QUEUES_PER_PORT;
232         devinfo->max_tx_queues = RTE_MAX_QUEUES_PER_PORT;
233         devinfo->max_mac_addrs = dev->max_mac_entries;
234         devinfo->max_vfs = pci_dev->max_vfs;
235         devinfo->max_mtu = devinfo->max_rx_pktlen - NIX_L2_OVERHEAD;
236         devinfo->min_mtu = devinfo->min_rx_bufsize - NIX_L2_OVERHEAD;
237
238         devinfo->rx_offload_capa = dev->rx_offload_capa;
239         devinfo->tx_offload_capa = dev->tx_offload_capa;
240         devinfo->rx_queue_offload_capa = 0;
241         devinfo->tx_queue_offload_capa = 0;
242
243         devinfo->reta_size = dev->rss_info.rss_size;
244         devinfo->hash_key_size = NIX_HASH_KEY_SIZE;
245         devinfo->flow_type_rss_offloads = NIX_RSS_OFFLOAD;
246
247         devinfo->default_rxconf = (struct rte_eth_rxconf) {
248                 .rx_drop_en = 0,
249                 .offloads = 0,
250         };
251
252         devinfo->default_txconf = (struct rte_eth_txconf) {
253                 .offloads = 0,
254         };
255
256         devinfo->rx_desc_lim = (struct rte_eth_desc_lim) {
257                 .nb_max = UINT16_MAX,
258                 .nb_min = NIX_RX_MIN_DESC,
259                 .nb_align = NIX_RX_MIN_DESC_ALIGN,
260                 .nb_seg_max = NIX_RX_NB_SEG_MAX,
261                 .nb_mtu_seg_max = NIX_RX_NB_SEG_MAX,
262         };
263         devinfo->rx_desc_lim.nb_max =
264                 RTE_ALIGN_MUL_FLOOR(devinfo->rx_desc_lim.nb_max,
265                                     NIX_RX_MIN_DESC_ALIGN);
266
267         devinfo->tx_desc_lim = (struct rte_eth_desc_lim) {
268                 .nb_max = UINT16_MAX,
269                 .nb_min = 1,
270                 .nb_align = 1,
271                 .nb_seg_max = NIX_TX_NB_SEG_MAX,
272                 .nb_mtu_seg_max = NIX_TX_NB_SEG_MAX,
273         };
274
275         /* Auto negotiation disabled */
276         devinfo->speed_capa = ETH_LINK_SPEED_FIXED;
277         devinfo->speed_capa |= ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
278                                 ETH_LINK_SPEED_25G | ETH_LINK_SPEED_40G |
279                                 ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G;
280
281         devinfo->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
282                                 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
283 }