Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2017 Cavium, Inc
3 : : */
4 : :
5 : : #include <stdio.h>
6 : : #include <stdarg.h>
7 : : #include <stdbool.h>
8 : : #include <stdint.h>
9 : : #include <stdlib.h>
10 : : #include <string.h>
11 : : #include <unistd.h>
12 : :
13 : : #include <eventdev_pmd.h>
14 : : #include <eal_export.h>
15 : : #include <rte_alarm.h>
16 : : #include <rte_branch_prediction.h>
17 : : #include <bus_vdev_driver.h>
18 : : #include <rte_cycles.h>
19 : : #include <rte_debug.h>
20 : : #include <dev_driver.h>
21 : : #include <rte_devargs.h>
22 : : #include <rte_kvargs.h>
23 : : #include <rte_malloc.h>
24 : : #include <rte_mbuf_pool_ops.h>
25 : : #include <rte_prefetch.h>
26 : :
27 : : #include "octeontx_ethdev.h"
28 : : #include "octeontx_rxtx.h"
29 : : #include "octeontx_logs.h"
30 : : #include "octeontx_stats.h"
31 : :
32 : : /* Useful in stopping/closing event device if no of
33 : : * eth ports are using it.
34 : : */
35 : : RTE_ATOMIC(uint16_t) evdev_refcnt;
36 : :
37 : : #define OCTEONTX_QLM_MODE_SGMII 7
38 : : #define OCTEONTX_QLM_MODE_XFI 12
39 : :
40 : : struct __rte_cache_aligned evdev_priv_data {
41 : : OFFLOAD_FLAGS; /*Sequence should not be changed */
42 : : };
43 : :
44 : : struct octeontx_vdev_init_params {
45 : : uint8_t nr_port;
46 : : };
47 : :
48 : : RTE_EXPORT_SYMBOL(rte_octeontx_pchan_map)
49 : : uint16_t
50 : : rte_octeontx_pchan_map[OCTEONTX_MAX_BGX_PORTS][OCTEONTX_MAX_LMAC_PER_BGX];
51 : :
52 : : enum octeontx_link_speed {
53 : : OCTEONTX_LINK_SPEED_SGMII,
54 : : OCTEONTX_LINK_SPEED_XAUI,
55 : : OCTEONTX_LINK_SPEED_RXAUI,
56 : : OCTEONTX_LINK_SPEED_10G_R,
57 : : OCTEONTX_LINK_SPEED_40G_R,
58 : : OCTEONTX_LINK_SPEED_RESERVE1,
59 : : OCTEONTX_LINK_SPEED_QSGMII,
60 : : OCTEONTX_LINK_SPEED_RESERVE2,
61 : : OCTEONTX_LINK_SPEED_UNKNOWN = 255
62 : : };
63 : :
64 [ - + ]: 252 : RTE_LOG_REGISTER_SUFFIX(otx_net_logtype_mbox, mbox, NOTICE);
65 [ - + ]: 252 : RTE_LOG_REGISTER_SUFFIX(otx_net_logtype_init, init, NOTICE);
66 [ - + ]: 252 : RTE_LOG_REGISTER_SUFFIX(otx_net_logtype_driver, driver, NOTICE);
67 : :
68 : : /* Parse integer from integer argument */
69 : : static int
70 : 0 : parse_integer_arg(const char *key __rte_unused,
71 : : const char *value, void *extra_args)
72 : : {
73 : : int *i = (int *)extra_args;
74 : :
75 : 0 : *i = atoi(value);
76 [ # # ]: 0 : if (*i < 0) {
77 : 0 : octeontx_log_err("argument has to be positive.");
78 : 0 : return -1;
79 : : }
80 : :
81 : : return 0;
82 : : }
83 : :
84 : : static int
85 [ # # ]: 0 : octeontx_parse_vdev_init_params(struct octeontx_vdev_init_params *params,
86 : : struct rte_vdev_device *dev)
87 : : {
88 : : struct rte_kvargs *kvlist = NULL;
89 : : int ret = 0;
90 : :
91 : : static const char * const octeontx_vdev_valid_params[] = {
92 : : OCTEONTX_VDEV_NR_PORT_ARG,
93 : : NULL
94 : : };
95 : :
96 : : const char *input_args = rte_vdev_device_args(dev);
97 [ # # ]: 0 : if (params == NULL)
98 : : return -EINVAL;
99 : :
100 : :
101 [ # # ]: 0 : if (input_args) {
102 : 0 : kvlist = rte_kvargs_parse(input_args,
103 : : octeontx_vdev_valid_params);
104 [ # # ]: 0 : if (kvlist == NULL)
105 : : return -1;
106 : :
107 : 0 : ret = rte_kvargs_process(kvlist,
108 : : OCTEONTX_VDEV_NR_PORT_ARG,
109 : : &parse_integer_arg,
110 : 0 : ¶ms->nr_port);
111 [ # # ]: 0 : if (ret < 0)
112 : 0 : goto free_kvlist;
113 : : }
114 : :
115 : 0 : free_kvlist:
116 : 0 : rte_kvargs_free(kvlist);
117 : 0 : return ret;
118 : : }
119 : :
120 : : static int
121 : 0 : octeontx_port_open(struct octeontx_nic *nic)
122 : : {
123 : : octeontx_mbox_bgx_port_conf_t bgx_port_conf;
124 : : octeontx_mbox_bgx_port_fifo_cfg_t fifo_cfg;
125 : : int res;
126 : :
127 : : res = 0;
128 : : memset(&bgx_port_conf, 0x0, sizeof(bgx_port_conf));
129 : 0 : PMD_INIT_FUNC_TRACE();
130 : :
131 : 0 : res = octeontx_bgx_port_open(nic->port_id, &bgx_port_conf);
132 [ # # ]: 0 : if (res < 0) {
133 : 0 : octeontx_log_err("failed to open port %d", res);
134 : 0 : return res;
135 : : }
136 : :
137 : 0 : nic->node = bgx_port_conf.node;
138 : 0 : nic->port_ena = bgx_port_conf.enable;
139 : 0 : nic->base_ichan = bgx_port_conf.base_chan;
140 : 0 : nic->base_ochan = bgx_port_conf.base_chan;
141 : 0 : nic->num_ichans = bgx_port_conf.num_chans;
142 : 0 : nic->num_ochans = bgx_port_conf.num_chans;
143 : 0 : nic->bgx_mtu = bgx_port_conf.mtu;
144 : 0 : nic->bpen = bgx_port_conf.bpen;
145 : 0 : nic->fcs_strip = bgx_port_conf.fcs_strip;
146 : 0 : nic->bcast_mode = bgx_port_conf.bcast_mode;
147 : 0 : nic->mcast_mode = bgx_port_conf.mcast_mode;
148 : 0 : nic->speed = bgx_port_conf.mode;
149 : :
150 : 0 : nic->duplex = RTE_ETH_LINK_FULL_DUPLEX;
151 : : memset(&fifo_cfg, 0x0, sizeof(fifo_cfg));
152 : :
153 : 0 : res = octeontx_bgx_port_get_fifo_cfg(nic->port_id, &fifo_cfg);
154 [ # # ]: 0 : if (res < 0) {
155 : 0 : octeontx_log_err("failed to get port %d fifo cfg", res);
156 : 0 : return res;
157 : : }
158 : :
159 : 0 : nic->fc.rx_fifosz = fifo_cfg.rx_fifosz;
160 : :
161 : 0 : memcpy(&nic->mac_addr[0], &bgx_port_conf.macaddr[0],
162 : : RTE_ETHER_ADDR_LEN);
163 : :
164 : 0 : octeontx_log_dbg("port opened %d", nic->port_id);
165 : 0 : return res;
166 : : }
167 : :
168 : : static void
169 : 0 : octeontx_link_status_print(struct rte_eth_dev *eth_dev,
170 : : struct rte_eth_link *link)
171 : : {
172 [ # # # # ]: 0 : if (link && link->link_status)
173 [ # # ]: 0 : octeontx_log_info("Port %u: Link Up - speed %u Mbps - %s",
174 : : (eth_dev->data->port_id),
175 : : link->link_speed,
176 : : link->link_duplex == RTE_ETH_LINK_FULL_DUPLEX ?
177 : : "full-duplex" : "half-duplex");
178 : : else
179 : 0 : octeontx_log_info("Port %d: Link Down",
180 : : (int)(eth_dev->data->port_id));
181 : 0 : }
182 : :
183 : : static inline uint32_t
184 : : octeontx_parse_link_speeds(uint32_t link_speeds)
185 : : {
186 : : uint32_t link_speed = OCTEONTX_LINK_SPEED_UNKNOWN;
187 : :
188 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_40G)
189 : : link_speed = OCTEONTX_LINK_SPEED_40G_R;
190 : :
191 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_10G) {
192 : : link_speed = OCTEONTX_LINK_SPEED_XAUI;
193 : : link_speed |= OCTEONTX_LINK_SPEED_RXAUI;
194 : : link_speed |= OCTEONTX_LINK_SPEED_10G_R;
195 : : }
196 : :
197 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_5G)
198 : : link_speed = OCTEONTX_LINK_SPEED_QSGMII;
199 : :
200 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_1G)
201 : : link_speed = OCTEONTX_LINK_SPEED_SGMII;
202 : :
203 : : return link_speed;
204 : : }
205 : :
206 : : static inline uint8_t
207 : : octeontx_parse_eth_link_duplex(uint32_t link_speeds)
208 : : {
209 : 0 : if ((link_speeds & RTE_ETH_LINK_SPEED_10M_HD) ||
210 : : (link_speeds & RTE_ETH_LINK_SPEED_100M_HD))
211 : : return RTE_ETH_LINK_HALF_DUPLEX;
212 : : else
213 : 0 : return RTE_ETH_LINK_FULL_DUPLEX;
214 : : }
215 : :
216 : : static int
217 [ # # ]: 0 : octeontx_apply_link_speed(struct rte_eth_dev *dev)
218 : : {
219 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
220 : : struct rte_eth_conf *conf = &dev->data->dev_conf;
221 : : octeontx_mbox_bgx_port_change_mode_t cfg;
222 : :
223 [ # # ]: 0 : if (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG)
224 : : return 0;
225 : :
226 : 0 : cfg.speed = octeontx_parse_link_speeds(conf->link_speeds);
227 [ # # ]: 0 : cfg.autoneg = (conf->link_speeds & RTE_ETH_LINK_SPEED_FIXED) ? 1 : 0;
228 : 0 : cfg.duplex = octeontx_parse_eth_link_duplex(conf->link_speeds);
229 [ # # # # ]: 0 : cfg.qlm_mode = ((conf->link_speeds & RTE_ETH_LINK_SPEED_1G) ?
230 : : OCTEONTX_QLM_MODE_SGMII :
231 : : (conf->link_speeds & RTE_ETH_LINK_SPEED_10G) ?
232 : : OCTEONTX_QLM_MODE_XFI : 0);
233 : :
234 [ # # ]: 0 : if (cfg.speed != OCTEONTX_LINK_SPEED_UNKNOWN &&
235 [ # # # # ]: 0 : (cfg.speed != nic->speed || cfg.duplex != nic->duplex)) {
236 : 0 : nic->speed = cfg.speed;
237 : 0 : nic->duplex = cfg.duplex;
238 : 0 : return octeontx_bgx_port_change_mode(nic->port_id, &cfg);
239 : : } else {
240 : : return 0;
241 : : }
242 : : }
243 : :
244 : : static void
245 [ # # # # : 0 : octeontx_link_status_update(struct octeontx_nic *nic,
# # ]
246 : : struct rte_eth_link *link)
247 : : {
248 : : memset(link, 0, sizeof(*link));
249 : :
250 : 0 : link->link_status = nic->link_up ? RTE_ETH_LINK_UP : RTE_ETH_LINK_DOWN;
251 : :
252 [ # # # # : 0 : switch (nic->speed) {
# # ]
253 : 0 : case OCTEONTX_LINK_SPEED_SGMII:
254 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
255 : 0 : break;
256 : :
257 : 0 : case OCTEONTX_LINK_SPEED_XAUI:
258 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
259 : 0 : break;
260 : :
261 : 0 : case OCTEONTX_LINK_SPEED_RXAUI:
262 : : case OCTEONTX_LINK_SPEED_10G_R:
263 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
264 : 0 : break;
265 : 0 : case OCTEONTX_LINK_SPEED_QSGMII:
266 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_5G;
267 : 0 : break;
268 : 0 : case OCTEONTX_LINK_SPEED_40G_R:
269 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_40G;
270 : 0 : break;
271 : :
272 : 0 : case OCTEONTX_LINK_SPEED_RESERVE1:
273 : : case OCTEONTX_LINK_SPEED_RESERVE2:
274 : : default:
275 : : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
276 : 0 : octeontx_log_err("incorrect link speed %d", nic->speed);
277 : 0 : break;
278 : : }
279 : :
280 : 0 : link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
281 : 0 : link->link_autoneg = RTE_ETH_LINK_AUTONEG;
282 : 0 : }
283 : :
284 : : static void
285 : 0 : octeontx_link_status_poll(void *arg)
286 : : {
287 : : struct octeontx_nic *nic = arg;
288 : : struct rte_eth_link link;
289 : : struct rte_eth_dev *dev;
290 : : int res;
291 : :
292 : 0 : PMD_INIT_FUNC_TRACE();
293 : :
294 : 0 : dev = nic->dev;
295 : :
296 : 0 : res = octeontx_bgx_port_link_status(nic->port_id);
297 [ # # ]: 0 : if (res < 0) {
298 : 0 : octeontx_log_err("Failed to get port %d link status",
299 : : nic->port_id);
300 : : } else {
301 [ # # ]: 0 : if (nic->link_up != (uint8_t)res) {
302 : 0 : nic->link_up = (uint8_t)res;
303 : 0 : octeontx_link_status_update(nic, &link);
304 : 0 : octeontx_link_status_print(dev, &link);
305 : 0 : rte_eth_linkstatus_set(dev, &link);
306 : 0 : rte_eth_dev_callback_process(dev,
307 : : RTE_ETH_EVENT_INTR_LSC,
308 : : NULL);
309 : : }
310 : : }
311 : :
312 : 0 : res = rte_eal_alarm_set(OCCTX_INTR_POLL_INTERVAL_MS * 1000,
313 : : octeontx_link_status_poll, nic);
314 [ # # ]: 0 : if (res < 0)
315 : 0 : octeontx_log_err("Failed to restart alarm for port %d, err: %d",
316 : : nic->port_id, res);
317 : 0 : }
318 : :
319 : : static void
320 : 0 : octeontx_port_close(struct octeontx_nic *nic)
321 : : {
322 : 0 : PMD_INIT_FUNC_TRACE();
323 : :
324 : 0 : rte_eal_alarm_cancel(octeontx_link_status_poll, nic);
325 : 0 : octeontx_bgx_port_close(nic->port_id);
326 : 0 : octeontx_log_dbg("port closed %d", nic->port_id);
327 : 0 : }
328 : :
329 : : static int
330 : 0 : octeontx_port_start(struct octeontx_nic *nic)
331 : : {
332 : 0 : PMD_INIT_FUNC_TRACE();
333 : :
334 : 0 : return octeontx_bgx_port_start(nic->port_id);
335 : : }
336 : :
337 : : static int
338 : 0 : octeontx_port_stop(struct octeontx_nic *nic)
339 : : {
340 : 0 : PMD_INIT_FUNC_TRACE();
341 : :
342 : 0 : return octeontx_bgx_port_stop(nic->port_id);
343 : : }
344 : :
345 : : static int
346 : 0 : octeontx_port_promisc_set(struct octeontx_nic *nic, int en)
347 : : {
348 : : struct rte_eth_dev *dev;
349 : : int res;
350 : :
351 : : res = 0;
352 : 0 : PMD_INIT_FUNC_TRACE();
353 : 0 : dev = nic->dev;
354 : :
355 : 0 : res = octeontx_bgx_port_promisc_set(nic->port_id, en);
356 [ # # ]: 0 : if (res < 0) {
357 : 0 : octeontx_log_err("failed to set promiscuous mode %d",
358 : : nic->port_id);
359 : 0 : return res;
360 : : }
361 : :
362 : : /* Set proper flag for the mode */
363 : 0 : dev->data->promiscuous = (en != 0) ? 1 : 0;
364 : :
365 [ # # ]: 0 : octeontx_log_dbg("port %d : promiscuous mode %s",
366 : : nic->port_id, en ? "set" : "unset");
367 : :
368 : 0 : return 0;
369 : : }
370 : :
371 : : static int
372 : 0 : octeontx_port_stats(struct octeontx_nic *nic, struct rte_eth_stats *stats)
373 : : {
374 : : octeontx_mbox_bgx_port_stats_t bgx_stats;
375 : : int res;
376 : :
377 : 0 : PMD_INIT_FUNC_TRACE();
378 : :
379 : 0 : res = octeontx_bgx_port_stats(nic->port_id, &bgx_stats);
380 [ # # ]: 0 : if (res < 0) {
381 : 0 : octeontx_log_err("failed to get port stats %d", nic->port_id);
382 : 0 : return res;
383 : : }
384 : :
385 : 0 : stats->ipackets = bgx_stats.rx_packets;
386 : 0 : stats->ibytes = bgx_stats.rx_bytes;
387 : 0 : stats->imissed = bgx_stats.rx_dropped;
388 : 0 : stats->ierrors = bgx_stats.rx_errors;
389 : 0 : stats->opackets = bgx_stats.tx_packets;
390 : 0 : stats->obytes = bgx_stats.tx_bytes;
391 : 0 : stats->oerrors = bgx_stats.tx_errors;
392 : :
393 : 0 : octeontx_log_dbg("port%d stats inpkts=%" PRIx64 " outpkts=%" PRIx64 "",
394 : : nic->port_id, stats->ipackets, stats->opackets);
395 : :
396 : 0 : return 0;
397 : : }
398 : :
399 : : static int
400 : 0 : octeontx_port_stats_clr(struct octeontx_nic *nic)
401 : : {
402 : 0 : PMD_INIT_FUNC_TRACE();
403 : :
404 : 0 : return octeontx_bgx_port_stats_clr(nic->port_id);
405 : : }
406 : :
407 : : static inline void
408 : 0 : devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
409 : : struct rte_event_dev_info *info)
410 : : {
411 : : memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
412 : 0 : dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
413 : :
414 : 0 : dev_conf->nb_event_ports = info->max_event_ports;
415 : 0 : dev_conf->nb_event_queues = info->max_event_queues;
416 : :
417 : 0 : dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
418 : 0 : dev_conf->nb_event_port_dequeue_depth =
419 : 0 : info->max_event_port_dequeue_depth;
420 : 0 : dev_conf->nb_event_port_enqueue_depth =
421 : 0 : info->max_event_port_enqueue_depth;
422 : : dev_conf->nb_event_port_enqueue_depth =
423 : : info->max_event_port_enqueue_depth;
424 : 0 : dev_conf->nb_events_limit =
425 : 0 : info->max_num_events;
426 : 0 : }
427 : :
428 : : static uint16_t
429 [ # # ]: 0 : octeontx_tx_offload_flags(struct rte_eth_dev *eth_dev)
430 : : {
431 : : struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
432 : : uint16_t flags = 0;
433 : :
434 [ # # ]: 0 : if (nic->tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM ||
435 : : nic->tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
436 : : flags |= OCCTX_TX_OFFLOAD_OL3_OL4_CSUM_F;
437 : :
438 : 0 : if (nic->tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM ||
439 : : nic->tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM ||
440 [ # # ]: 0 : nic->tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM ||
441 : : nic->tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)
442 : 0 : flags |= OCCTX_TX_OFFLOAD_L3_L4_CSUM_F;
443 : :
444 [ # # ]: 0 : if (!(nic->tx_offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE))
445 : 0 : flags |= OCCTX_TX_OFFLOAD_MBUF_NOFF_F;
446 : :
447 [ # # ]: 0 : if (nic->tx_offloads & RTE_ETH_TX_OFFLOAD_MULTI_SEGS)
448 : 0 : flags |= OCCTX_TX_MULTI_SEG_F;
449 : :
450 : 0 : return flags;
451 : : }
452 : :
453 : : static uint16_t
454 : : octeontx_rx_offload_flags(struct rte_eth_dev *eth_dev)
455 : : {
456 : : struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
457 : : uint16_t flags = 0;
458 : :
459 [ # # ]: 0 : if (nic->rx_offloads & (RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
460 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM))
461 : : flags |= OCCTX_RX_OFFLOAD_CSUM_F;
462 : :
463 [ # # # # ]: 0 : if (nic->rx_offloads & (RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
464 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM))
465 : : flags |= OCCTX_RX_OFFLOAD_CSUM_F;
466 : :
467 [ # # ]: 0 : if (nic->rx_offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
468 : 0 : flags |= OCCTX_RX_MULTI_SEG_F;
469 : 0 : eth_dev->data->scattered_rx = 1;
470 : : /* If scatter mode is enabled, TX should also be in multi
471 : : * seg mode, else memory leak will occur
472 : : */
473 : 0 : nic->tx_offloads |= RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
474 : : }
475 : :
476 : : return flags;
477 : : }
478 : :
479 : : static int
480 : 0 : octeontx_dev_configure(struct rte_eth_dev *dev)
481 : : {
482 : 0 : struct rte_eth_dev_data *data = dev->data;
483 : : struct rte_eth_conf *conf = &data->dev_conf;
484 : : struct rte_eth_rxmode *rxmode = &conf->rxmode;
485 : : struct rte_eth_txmode *txmode = &conf->txmode;
486 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
487 : : int ret;
488 : :
489 : 0 : PMD_INIT_FUNC_TRACE();
490 : : RTE_SET_USED(conf);
491 : :
492 [ # # ]: 0 : if (!rte_eal_has_hugepages()) {
493 : 0 : octeontx_log_err("huge page is not configured");
494 : 0 : return -EINVAL;
495 : : }
496 : :
497 [ # # ]: 0 : if (txmode->mq_mode) {
498 : 0 : octeontx_log_err("tx mq_mode DCB or VMDq not supported");
499 : 0 : return -EINVAL;
500 : : }
501 : :
502 [ # # ]: 0 : if (rxmode->mq_mode != RTE_ETH_MQ_RX_NONE &&
503 : : rxmode->mq_mode != RTE_ETH_MQ_RX_RSS) {
504 : 0 : octeontx_log_err("unsupported rx qmode %d", rxmode->mq_mode);
505 : 0 : return -EINVAL;
506 : : }
507 : :
508 [ # # ]: 0 : if (!(txmode->offloads & RTE_ETH_TX_OFFLOAD_MT_LOCKFREE)) {
509 : 0 : PMD_INIT_LOG(NOTICE, "cant disable lockfree tx");
510 : 0 : txmode->offloads |= RTE_ETH_TX_OFFLOAD_MT_LOCKFREE;
511 : : }
512 : :
513 [ # # ]: 0 : if (conf->dcb_capability_en) {
514 : 0 : octeontx_log_err("DCB enable not supported");
515 : 0 : return -EINVAL;
516 : : }
517 : :
518 : 0 : nic->num_tx_queues = dev->data->nb_tx_queues;
519 : :
520 [ # # ]: 0 : if (!nic->reconfigure) {
521 : 0 : ret = octeontx_pko_channel_open(nic->pko_vfid * PKO_VF_NUM_DQ,
522 : : nic->num_tx_queues,
523 : : nic->base_ochan);
524 [ # # ]: 0 : if (ret) {
525 : 0 : octeontx_log_err("failed to open channel %d no-of-txq %d",
526 : : nic->base_ochan, nic->num_tx_queues);
527 : 0 : return -EFAULT;
528 : : }
529 : :
530 : 0 : ret = octeontx_dev_vlan_offload_init(dev);
531 [ # # ]: 0 : if (ret) {
532 : 0 : octeontx_log_err("failed to initialize vlan offload");
533 : 0 : return -EFAULT;
534 : : }
535 : :
536 : 0 : nic->pki.classifier_enable = false;
537 : 0 : nic->pki.hash_enable = true;
538 : 0 : nic->pki.initialized = false;
539 : : }
540 : :
541 : 0 : nic->rx_offloads |= rxmode->offloads;
542 [ # # ]: 0 : nic->tx_offloads |= txmode->offloads;
543 : 0 : nic->rx_offload_flags |= octeontx_rx_offload_flags(dev);
544 : 0 : nic->tx_offload_flags |= octeontx_tx_offload_flags(dev);
545 : :
546 : 0 : nic->reconfigure = true;
547 : :
548 : 0 : return 0;
549 : : }
550 : :
551 : : static int
552 : 0 : octeontx_dev_close(struct rte_eth_dev *dev)
553 : : {
554 : : struct octeontx_txq *txq = NULL;
555 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
556 : : unsigned int i;
557 : : int ret;
558 : :
559 : 0 : PMD_INIT_FUNC_TRACE();
560 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
561 : : return 0;
562 : :
563 : : /* Stopping/closing event device once all eth ports are closed. */
564 [ # # ]: 0 : if (rte_atomic_fetch_sub_explicit(&evdev_refcnt, 1, rte_memory_order_acquire) - 1 == 0) {
565 : 0 : rte_event_dev_stop(nic->evdev);
566 : 0 : rte_event_dev_close(nic->evdev);
567 : : }
568 : :
569 : 0 : octeontx_dev_flow_ctrl_fini(dev);
570 : :
571 : 0 : octeontx_dev_vlan_offload_fini(dev);
572 : :
573 : 0 : ret = octeontx_pko_channel_close(nic->base_ochan);
574 [ # # ]: 0 : if (ret < 0) {
575 : 0 : octeontx_log_err("failed to close channel %d VF%d %d %d",
576 : : nic->base_ochan, nic->port_id, nic->num_tx_queues,
577 : : ret);
578 : : }
579 : : /* Free txq resources for this port */
580 [ # # ]: 0 : for (i = 0; i < nic->num_tx_queues; i++) {
581 : 0 : txq = dev->data->tx_queues[i];
582 [ # # ]: 0 : if (!txq)
583 : 0 : continue;
584 : :
585 : 0 : rte_free(txq);
586 : : }
587 : :
588 : 0 : octeontx_port_close(nic);
589 : 0 : nic->reconfigure = false;
590 : :
591 : 0 : return 0;
592 : : }
593 : :
594 : : static int
595 : 0 : octeontx_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
596 : : {
597 [ # # ]: 0 : uint32_t buffsz, frame_size = mtu + OCCTX_L2_OVERHEAD;
598 : : struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
599 : : struct rte_eth_dev_data *data = eth_dev->data;
600 : : int rc = 0;
601 : :
602 : 0 : buffsz = data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
603 : :
604 : : /* Refuse MTU that requires the support of scattered packets
605 : : * when this feature has not been enabled before.
606 : : */
607 [ # # # # ]: 0 : if (data->dev_started && frame_size > buffsz &&
608 [ # # ]: 0 : !(nic->rx_offloads & RTE_ETH_RX_OFFLOAD_SCATTER)) {
609 : 0 : octeontx_log_err("Scatter mode is disabled");
610 : 0 : return -EINVAL;
611 : : }
612 : :
613 : : /* Check <seg size> * <max_seg> >= max_frame */
614 [ # # ]: 0 : if ((nic->rx_offloads & RTE_ETH_RX_OFFLOAD_SCATTER) &&
615 [ # # ]: 0 : (frame_size > buffsz * OCCTX_RX_NB_SEG_MAX))
616 : : return -EINVAL;
617 : :
618 : 0 : rc = octeontx_pko_send_mtu(nic->port_id, frame_size);
619 [ # # ]: 0 : if (rc)
620 : : return rc;
621 : :
622 : 0 : rc = octeontx_bgx_port_mtu_set(nic->port_id, frame_size);
623 [ # # ]: 0 : if (rc)
624 : : return rc;
625 : :
626 : 0 : octeontx_log_info("Received pkt beyond maxlen %d will be dropped",
627 : : frame_size);
628 : :
629 : 0 : return rc;
630 : : }
631 : :
632 : : static int
633 : 0 : octeontx_recheck_rx_offloads(struct octeontx_rxq *rxq)
634 : : {
635 [ # # ]: 0 : struct rte_eth_dev *eth_dev = rxq->eth_dev;
636 : : struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
637 : : struct rte_eth_dev_data *data = eth_dev->data;
638 : : struct rte_pktmbuf_pool_private *mbp_priv;
639 : : struct evdev_priv_data *evdev_priv;
640 : : struct rte_eventdev *dev;
641 : : uint32_t buffsz;
642 : :
643 : : /* Get rx buffer size */
644 [ # # ]: 0 : mbp_priv = rte_mempool_get_priv(rxq->pool);
645 : 0 : buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
646 : :
647 : : /* Setup scatter mode if needed by jumbo */
648 [ # # ]: 0 : if (data->mtu > buffsz) {
649 [ # # ]: 0 : nic->rx_offloads |= RTE_ETH_RX_OFFLOAD_SCATTER;
650 : 0 : nic->rx_offload_flags |= octeontx_rx_offload_flags(eth_dev);
651 : 0 : nic->tx_offload_flags |= octeontx_tx_offload_flags(eth_dev);
652 : : }
653 : :
654 : : /* Sharing offload flags via eventdev priv region */
655 : 0 : dev = &rte_eventdevs[rxq->evdev];
656 : 0 : evdev_priv = dev->data->dev_private;
657 : 0 : evdev_priv->rx_offload_flags = nic->rx_offload_flags;
658 : 0 : evdev_priv->tx_offload_flags = nic->tx_offload_flags;
659 : :
660 : : /* Setup MTU */
661 : 0 : nic->mtu = data->mtu;
662 : :
663 : 0 : return 0;
664 : : }
665 : :
666 : : static int
667 : 0 : octeontx_dev_start(struct rte_eth_dev *dev)
668 : : {
669 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
670 : : struct octeontx_rxq *rxq;
671 : : int ret, i;
672 : :
673 : 0 : PMD_INIT_FUNC_TRACE();
674 : : /* Rechecking if any new offload set to update
675 : : * rx/tx burst function pointer accordingly.
676 : : */
677 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
678 : 0 : rxq = dev->data->rx_queues[i];
679 : 0 : octeontx_recheck_rx_offloads(rxq);
680 : : }
681 : :
682 : : /* Setting up the mtu */
683 : 0 : ret = octeontx_dev_mtu_set(dev, nic->mtu);
684 [ # # ]: 0 : if (ret) {
685 : 0 : octeontx_log_err("Failed to set default MTU size %d", ret);
686 : 0 : goto error;
687 : : }
688 : :
689 : : /* Apply new link configurations if changed */
690 : 0 : ret = octeontx_apply_link_speed(dev);
691 [ # # ]: 0 : if (ret) {
692 : 0 : octeontx_log_err("Failed to set link configuration: %d", ret);
693 : 0 : goto error;
694 : : }
695 : :
696 : : /*
697 : : * Tx start
698 : : */
699 : 0 : octeontx_set_tx_function(dev);
700 : 0 : ret = octeontx_pko_channel_start(nic->base_ochan);
701 [ # # ]: 0 : if (ret < 0) {
702 : 0 : octeontx_log_err("fail to conf VF%d no. txq %d chan %d ret %d",
703 : : nic->port_id, nic->num_tx_queues, nic->base_ochan,
704 : : ret);
705 : 0 : goto error;
706 : : }
707 : :
708 : : /*
709 : : * Rx start
710 : : */
711 : 0 : dev->rx_pkt_burst = octeontx_recv_pkts;
712 : 0 : ret = octeontx_pki_port_start(nic->port_id);
713 [ # # ]: 0 : if (ret < 0) {
714 : 0 : octeontx_log_err("fail to start Rx on port %d", nic->port_id);
715 : 0 : goto channel_stop_error;
716 : : }
717 : :
718 : : /*
719 : : * Start port
720 : : */
721 : 0 : ret = octeontx_port_start(nic);
722 [ # # ]: 0 : if (ret < 0) {
723 : 0 : octeontx_log_err("failed start port %d", ret);
724 : 0 : goto pki_port_stop_error;
725 : : }
726 : :
727 : 0 : PMD_TX_LOG(DEBUG, "pko: start channel %d no.of txq %d port %d",
728 : : nic->base_ochan, nic->num_tx_queues, nic->port_id);
729 : :
730 : 0 : ret = rte_event_dev_start(nic->evdev);
731 [ # # ]: 0 : if (ret < 0) {
732 : 0 : octeontx_log_err("failed to start evdev: ret (%d)", ret);
733 : 0 : goto pki_port_stop_error;
734 : : }
735 : :
736 : : /* Success */
737 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
738 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
739 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
740 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
741 : :
742 : : return ret;
743 : :
744 : 0 : pki_port_stop_error:
745 : 0 : octeontx_pki_port_stop(nic->port_id);
746 : 0 : channel_stop_error:
747 : 0 : octeontx_pko_channel_stop(nic->base_ochan);
748 : : error:
749 : : return ret;
750 : : }
751 : :
752 : : static int
753 : 0 : octeontx_dev_stop(struct rte_eth_dev *dev)
754 : : {
755 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
756 : : uint16_t i;
757 : : int ret;
758 : :
759 : 0 : PMD_INIT_FUNC_TRACE();
760 : :
761 : 0 : ret = octeontx_port_stop(nic);
762 [ # # ]: 0 : if (ret < 0) {
763 : 0 : octeontx_log_err("failed to req stop port %d res=%d",
764 : : nic->port_id, ret);
765 : 0 : return ret;
766 : : }
767 : :
768 : 0 : ret = octeontx_pki_port_stop(nic->port_id);
769 [ # # ]: 0 : if (ret < 0) {
770 : 0 : octeontx_log_err("failed to stop pki port %d res=%d",
771 : : nic->port_id, ret);
772 : 0 : return ret;
773 : : }
774 : :
775 : 0 : ret = octeontx_pko_channel_stop(nic->base_ochan);
776 [ # # ]: 0 : if (ret < 0) {
777 : 0 : octeontx_log_err("failed to stop channel %d VF%d %d %d",
778 : : nic->base_ochan, nic->port_id, nic->num_tx_queues,
779 : : ret);
780 : 0 : return ret;
781 : : }
782 : :
783 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
784 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
785 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
786 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
787 : :
788 : : return 0;
789 : : }
790 : :
791 : : static int
792 : 0 : octeontx_dev_promisc_enable(struct rte_eth_dev *dev)
793 : : {
794 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
795 : :
796 : 0 : PMD_INIT_FUNC_TRACE();
797 : 0 : return octeontx_port_promisc_set(nic, 1);
798 : : }
799 : :
800 : : static int
801 : 0 : octeontx_dev_promisc_disable(struct rte_eth_dev *dev)
802 : : {
803 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
804 : :
805 : 0 : PMD_INIT_FUNC_TRACE();
806 : 0 : return octeontx_port_promisc_set(nic, 0);
807 : : }
808 : :
809 : : static int
810 : 0 : octeontx_port_link_status(struct octeontx_nic *nic)
811 : : {
812 : : int res;
813 : :
814 : 0 : PMD_INIT_FUNC_TRACE();
815 : 0 : res = octeontx_bgx_port_link_status(nic->port_id);
816 [ # # ]: 0 : if (res < 0) {
817 : 0 : octeontx_log_err("failed to get port %d link status",
818 : : nic->port_id);
819 : 0 : return res;
820 : : }
821 : :
822 [ # # # # ]: 0 : if (nic->link_up != (uint8_t)res || nic->print_flag == -1) {
823 : 0 : nic->link_up = (uint8_t)res;
824 : 0 : nic->print_flag = 1;
825 : : }
826 : 0 : octeontx_log_dbg("port %d link status %d", nic->port_id, nic->link_up);
827 : :
828 : 0 : return res;
829 : : }
830 : :
831 : : /*
832 : : * Return 0 means link status changed, -1 means not changed
833 : : */
834 : : static int
835 : 0 : octeontx_dev_link_update(struct rte_eth_dev *dev,
836 : : int wait_to_complete __rte_unused)
837 : : {
838 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
839 : : struct rte_eth_link link;
840 : : int res;
841 : :
842 : 0 : PMD_INIT_FUNC_TRACE();
843 : :
844 : 0 : res = octeontx_port_link_status(nic);
845 [ # # ]: 0 : if (res < 0) {
846 : 0 : octeontx_log_err("failed to request link status %d", res);
847 : 0 : return res;
848 : : }
849 : :
850 : 0 : octeontx_link_status_update(nic, &link);
851 [ # # ]: 0 : if (nic->print_flag) {
852 : 0 : octeontx_link_status_print(nic->dev, &link);
853 : 0 : nic->print_flag = 0;
854 : : }
855 : :
856 : : return rte_eth_linkstatus_set(dev, &link);
857 : : }
858 : :
859 : : static int
860 : 0 : octeontx_port_mcast_set(struct octeontx_nic *nic, int en)
861 : : {
862 : : struct rte_eth_dev *dev;
863 : : int res;
864 : :
865 : : res = 0;
866 : 0 : PMD_INIT_FUNC_TRACE();
867 : 0 : dev = nic->dev;
868 : :
869 : 0 : res = octeontx_bgx_port_multicast_set(nic->port_id, en);
870 [ # # ]: 0 : if (res < 0) {
871 : 0 : octeontx_log_err("failed to set multicast mode %d",
872 : : nic->port_id);
873 : 0 : return res;
874 : : }
875 : :
876 : : /* Set proper flag for the mode */
877 : 0 : dev->data->all_multicast = (en != 0) ? 1 : 0;
878 : :
879 [ # # ]: 0 : octeontx_log_dbg("port %d : multicast mode %s",
880 : : nic->port_id, en ? "set" : "unset");
881 : :
882 : 0 : return 0;
883 : : }
884 : :
885 : : static int
886 : 0 : octeontx_allmulticast_enable(struct rte_eth_dev *dev)
887 : : {
888 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
889 : :
890 : 0 : PMD_INIT_FUNC_TRACE();
891 : 0 : return octeontx_port_mcast_set(nic, 1);
892 : : }
893 : :
894 : : static int
895 : 0 : octeontx_allmulticast_disable(struct rte_eth_dev *dev)
896 : : {
897 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
898 : :
899 : 0 : PMD_INIT_FUNC_TRACE();
900 : 0 : return octeontx_port_mcast_set(nic, 0);
901 : : }
902 : :
903 : : static inline int octeontx_dev_total_xstat(void)
904 : : {
905 : : return NUM_BGX_XSTAT;
906 : : }
907 : :
908 : : static int
909 : 0 : octeontx_port_xstats(struct octeontx_nic *nic, struct rte_eth_xstat *xstats,
910 : : unsigned int n)
911 : : {
912 : : octeontx_mbox_bgx_port_stats_t bgx_stats;
913 : : int stat_cnt, res, si, i;
914 : :
915 : 0 : res = octeontx_bgx_port_xstats(nic->port_id, &bgx_stats);
916 [ # # ]: 0 : if (res < 0) {
917 : 0 : octeontx_log_err("failed to get port stats %d", nic->port_id);
918 : 0 : return res;
919 : : }
920 : :
921 : : si = 0;
922 : : /* Fill BGX stats */
923 : 0 : stat_cnt = (n > NUM_BGX_XSTAT) ? NUM_BGX_XSTAT : n;
924 : : n = n - stat_cnt;
925 [ # # ]: 0 : for (i = 0; i < stat_cnt; i++) {
926 : 0 : xstats[si].id = si;
927 : 0 : xstats[si].value = *(uint64_t *)(((char *)&bgx_stats) +
928 : 0 : octeontx_bgx_xstats[i].soffset);
929 : 0 : si++;
930 : : }
931 : : /*TODO: Similarly fill rest of HW stats */
932 : :
933 : : return si;
934 : : }
935 : :
936 : : static int
937 : 0 : octeontx_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
938 : : uint64_t *stat_val, unsigned int n)
939 : 0 : {
940 : : unsigned int i, xstat_cnt = octeontx_dev_total_xstat();
941 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
942 : 0 : struct rte_eth_xstat xstats[xstat_cnt];
943 : :
944 : 0 : octeontx_port_xstats(nic, xstats, xstat_cnt);
945 [ # # ]: 0 : for (i = 0; i < n; i++) {
946 [ # # ]: 0 : if (ids[i] >= xstat_cnt) {
947 : 0 : PMD_INIT_LOG(ERR, "out of range id value");
948 : 0 : return -1;
949 : : }
950 : 0 : stat_val[i] = xstats[ids[i]].value;
951 : : }
952 : 0 : return n;
953 : : }
954 : :
955 : : static int
956 : 0 : octeontx_dev_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
957 : : struct rte_eth_xstat_name *xstats_names,
958 : : unsigned int size)
959 : : {
960 : : int stat_cnt, si, i;
961 : :
962 [ # # ]: 0 : if (xstats_names) {
963 : : si = 0;
964 : : /* Fill BGX stats */
965 : 0 : stat_cnt = (size > NUM_BGX_XSTAT) ? NUM_BGX_XSTAT : size;
966 : : size = size - stat_cnt;
967 [ # # ]: 0 : for (i = 0; i < stat_cnt; i++) {
968 : 0 : strlcpy(xstats_names[si].name,
969 : : octeontx_bgx_xstats[i].sname,
970 : : sizeof(xstats_names[si].name));
971 : 0 : si++;
972 : : }
973 : : /*TODO: Similarly fill rest of HW stats */
974 : 0 : return si;
975 : : } else {
976 : : return octeontx_dev_total_xstat();
977 : : }
978 : : }
979 : :
980 : 0 : static void build_xstat_names(struct rte_eth_xstat_name *xstat_names)
981 : : {
982 : : unsigned int i;
983 : :
984 [ # # ]: 0 : for (i = 0; i < NUM_BGX_XSTAT; i++) {
985 : 0 : strlcpy(xstat_names[i].name, octeontx_bgx_xstats[i].sname,
986 : : RTE_ETH_XSTATS_NAME_SIZE);
987 : : }
988 : 0 : }
989 : :
990 : : static int
991 : 0 : octeontx_dev_xstats_get_names_by_id(struct rte_eth_dev *dev __rte_unused,
992 : : const uint64_t *ids,
993 : : struct rte_eth_xstat_name *stat_names,
994 : : unsigned int n)
995 : 0 : {
996 : : unsigned int i, xstat_cnt = octeontx_dev_total_xstat();
997 : 0 : struct rte_eth_xstat_name xstat_names[xstat_cnt];
998 : :
999 : 0 : build_xstat_names(xstat_names);
1000 [ # # ]: 0 : for (i = 0; i < n; i++) {
1001 [ # # ]: 0 : if (ids[i] >= xstat_cnt) {
1002 : 0 : PMD_INIT_LOG(ERR, "out of range id value");
1003 : 0 : return -1;
1004 : : }
1005 : 0 : strlcpy(stat_names[i].name, xstat_names[ids[i]].name,
1006 : : sizeof(stat_names[i].name));
1007 : : }
1008 : : /*TODO: Similarly fill rest of HW stats */
1009 : :
1010 : 0 : return n;
1011 : : }
1012 : :
1013 : : static int
1014 : 0 : octeontx_dev_xstats_get(struct rte_eth_dev *dev,
1015 : : struct rte_eth_xstat *xstats,
1016 : : unsigned int n)
1017 : : {
1018 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1019 : :
1020 : 0 : PMD_INIT_FUNC_TRACE();
1021 : 0 : return octeontx_port_xstats(nic, xstats, n);
1022 : : }
1023 : :
1024 : : static int
1025 : 0 : octeontx_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1026 : : {
1027 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1028 : :
1029 : 0 : PMD_INIT_FUNC_TRACE();
1030 : 0 : return octeontx_port_stats(nic, stats);
1031 : : }
1032 : :
1033 : : static int
1034 : 0 : octeontx_dev_stats_reset(struct rte_eth_dev *dev)
1035 : : {
1036 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1037 : :
1038 : 0 : PMD_INIT_FUNC_TRACE();
1039 : 0 : return octeontx_port_stats_clr(nic);
1040 : : }
1041 : :
1042 : : static void
1043 : 0 : octeontx_dev_mac_addr_del(struct rte_eth_dev *dev, uint32_t index)
1044 : : {
1045 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1046 : : int ret;
1047 : :
1048 : 0 : ret = octeontx_bgx_port_mac_del(nic->port_id, index);
1049 [ # # ]: 0 : if (ret != 0)
1050 : 0 : octeontx_log_err("failed to del MAC address filter on port %d",
1051 : : nic->port_id);
1052 : 0 : }
1053 : :
1054 : : static int
1055 : 0 : octeontx_dev_mac_addr_add(struct rte_eth_dev *dev,
1056 : : struct rte_ether_addr *mac_addr,
1057 : : uint32_t index,
1058 : : __rte_unused uint32_t vmdq)
1059 : : {
1060 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1061 : : int ret;
1062 : :
1063 : 0 : ret = octeontx_bgx_port_mac_add(nic->port_id, mac_addr->addr_bytes,
1064 : : index);
1065 [ # # ]: 0 : if (ret < 0) {
1066 : 0 : octeontx_log_err("failed to add MAC address filter on port %d",
1067 : : nic->port_id);
1068 : 0 : return ret;
1069 : : }
1070 : :
1071 : : return 0;
1072 : : }
1073 : :
1074 : : static int
1075 : 0 : octeontx_dev_default_mac_addr_set(struct rte_eth_dev *dev,
1076 : : struct rte_ether_addr *addr)
1077 : : {
1078 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1079 : : int ret;
1080 : :
1081 : 0 : ret = octeontx_bgx_port_mac_set(nic->port_id, addr->addr_bytes);
1082 [ # # ]: 0 : if (ret == 0) {
1083 : : /* Update same mac address to BGX CAM table */
1084 : 0 : ret = octeontx_bgx_port_mac_add(nic->port_id, addr->addr_bytes,
1085 : : 0);
1086 : : }
1087 [ # # ]: 0 : if (ret < 0) {
1088 : 0 : octeontx_log_err("failed to set MAC address on port %d",
1089 : : nic->port_id);
1090 : : }
1091 : :
1092 : 0 : return ret;
1093 : : }
1094 : :
1095 : : static int
1096 : 0 : octeontx_dev_info(struct rte_eth_dev *dev,
1097 : : struct rte_eth_dev_info *dev_info)
1098 : : {
1099 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1100 : :
1101 : : /* Autonegotiation may be disabled */
1102 : : dev_info->speed_capa = RTE_ETH_LINK_SPEED_FIXED;
1103 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_10M | RTE_ETH_LINK_SPEED_100M |
1104 : : RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G |
1105 : : RTE_ETH_LINK_SPEED_40G;
1106 : :
1107 : : /* Min/Max MTU supported */
1108 : 0 : dev_info->min_rx_bufsize = OCCTX_MIN_FRS;
1109 : 0 : dev_info->max_rx_pktlen = OCCTX_MAX_FRS;
1110 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - OCCTX_L2_OVERHEAD;
1111 : 0 : dev_info->min_mtu = dev_info->min_rx_bufsize - OCCTX_L2_OVERHEAD;
1112 : :
1113 : 0 : dev_info->max_mac_addrs =
1114 : 0 : octeontx_bgx_port_mac_entries_get(nic->port_id);
1115 : 0 : dev_info->max_rx_queues = 1;
1116 : 0 : dev_info->max_tx_queues = PKO_MAX_NUM_DQ;
1117 : 0 : dev_info->min_rx_bufsize = 0;
1118 : :
1119 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
1120 : : .rx_free_thresh = 0,
1121 : : .rx_drop_en = 0,
1122 : : .offloads = OCTEONTX_RX_OFFLOADS,
1123 : : };
1124 : :
1125 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
1126 : : .tx_free_thresh = 0,
1127 : : .offloads = OCTEONTX_TX_OFFLOADS,
1128 : : };
1129 : :
1130 : 0 : dev_info->rx_offload_capa = OCTEONTX_RX_OFFLOADS;
1131 : 0 : dev_info->tx_offload_capa = OCTEONTX_TX_OFFLOADS;
1132 : 0 : dev_info->rx_queue_offload_capa = OCTEONTX_RX_OFFLOADS;
1133 : 0 : dev_info->tx_queue_offload_capa = OCTEONTX_TX_OFFLOADS;
1134 : :
1135 : 0 : return 0;
1136 : : }
1137 : :
1138 : : static void
1139 : 0 : octeontx_dq_info_getter(octeontx_dq_t *dq, void *out)
1140 : : {
1141 : 0 : ((octeontx_dq_t *)out)->lmtline_va = dq->lmtline_va;
1142 : 0 : ((octeontx_dq_t *)out)->ioreg_va = dq->ioreg_va;
1143 : 0 : ((octeontx_dq_t *)out)->fc_status_va = dq->fc_status_va;
1144 : 0 : }
1145 : :
1146 : : static int
1147 : 0 : octeontx_vf_start_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
1148 : : uint16_t qidx)
1149 : : {
1150 : : struct octeontx_txq *txq;
1151 : : int res;
1152 : :
1153 : 0 : PMD_INIT_FUNC_TRACE();
1154 : :
1155 [ # # ]: 0 : if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED)
1156 : : return 0;
1157 : :
1158 : 0 : txq = dev->data->tx_queues[qidx];
1159 : :
1160 : 0 : res = octeontx_pko_channel_query_dqs(nic->base_ochan,
1161 : 0 : &txq->dq,
1162 : : sizeof(octeontx_dq_t),
1163 : 0 : txq->queue_id,
1164 : : octeontx_dq_info_getter);
1165 [ # # ]: 0 : if (res < 0) {
1166 : : res = -EFAULT;
1167 : 0 : goto close_port;
1168 : : }
1169 : :
1170 : 0 : dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
1171 : 0 : return res;
1172 : :
1173 : : close_port:
1174 : 0 : (void)octeontx_port_stop(nic);
1175 : 0 : octeontx_pko_channel_stop(nic->base_ochan);
1176 : 0 : octeontx_pko_channel_close(nic->base_ochan);
1177 : 0 : dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1178 : 0 : return res;
1179 : : }
1180 : :
1181 : : int
1182 : 0 : octeontx_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
1183 : : {
1184 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1185 : :
1186 : 0 : PMD_INIT_FUNC_TRACE();
1187 : 0 : qidx = qidx % PKO_VF_NUM_DQ;
1188 : 0 : return octeontx_vf_start_tx_queue(dev, nic, qidx);
1189 : : }
1190 : :
1191 : : static inline int
1192 : 0 : octeontx_vf_stop_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
1193 : : uint16_t qidx)
1194 : : {
1195 : : int ret = 0;
1196 : :
1197 : : RTE_SET_USED(nic);
1198 : 0 : PMD_INIT_FUNC_TRACE();
1199 : :
1200 [ # # ]: 0 : if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED)
1201 : : return 0;
1202 : :
1203 : 0 : dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1204 : 0 : return ret;
1205 : : }
1206 : :
1207 : : int
1208 : 0 : octeontx_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
1209 : : {
1210 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1211 : :
1212 : 0 : PMD_INIT_FUNC_TRACE();
1213 : 0 : qidx = qidx % PKO_VF_NUM_DQ;
1214 : :
1215 : 0 : return octeontx_vf_stop_tx_queue(dev, nic, qidx);
1216 : : }
1217 : :
1218 : : static void
1219 : 0 : octeontx_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1220 : : {
1221 : : int res;
1222 : :
1223 : 0 : PMD_INIT_FUNC_TRACE();
1224 : :
1225 [ # # ]: 0 : if (dev->data->tx_queues[qid]) {
1226 : 0 : res = octeontx_dev_tx_queue_stop(dev, qid);
1227 [ # # ]: 0 : if (res < 0)
1228 : 0 : octeontx_log_err("failed stop tx_queue(%d)", qid);
1229 : :
1230 : 0 : rte_free(dev->data->tx_queues[qid]);
1231 : : }
1232 : 0 : }
1233 : :
1234 : : static int
1235 [ # # ]: 0 : octeontx_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
1236 : : uint16_t nb_desc, unsigned int socket_id,
1237 : : const struct rte_eth_txconf *tx_conf __rte_unused)
1238 : : {
1239 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1240 : : struct octeontx_txq *txq = NULL;
1241 : : uint16_t dq_num;
1242 : : int res = 0;
1243 : :
1244 : : RTE_SET_USED(nb_desc);
1245 : : RTE_SET_USED(socket_id);
1246 : :
1247 : 0 : dq_num = (nic->pko_vfid * PKO_VF_NUM_DQ) + qidx;
1248 : :
1249 : : /* Socket id check */
1250 [ # # ]: 0 : if (socket_id != (unsigned int)SOCKET_ID_ANY &&
1251 [ # # ]: 0 : socket_id != (unsigned int)nic->node)
1252 : 0 : PMD_TX_LOG(INFO, "socket_id expected %d, configured %d",
1253 : : socket_id, nic->node);
1254 : :
1255 : : /* Free memory prior to re-allocation if needed. */
1256 [ # # ]: 0 : if (dev->data->tx_queues[qidx] != NULL) {
1257 : 0 : PMD_TX_LOG(DEBUG, "freeing memory prior to re-allocation %d",
1258 : : qidx);
1259 : 0 : octeontx_dev_tx_queue_release(dev, qidx);
1260 : 0 : dev->data->tx_queues[qidx] = NULL;
1261 : : }
1262 : :
1263 : : /* Allocating tx queue data structure */
1264 : 0 : txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct octeontx_txq),
1265 : : RTE_CACHE_LINE_SIZE, nic->node);
1266 [ # # ]: 0 : if (txq == NULL) {
1267 : 0 : octeontx_log_err("failed to allocate txq=%d", qidx);
1268 : : res = -ENOMEM;
1269 : 0 : goto err;
1270 : : }
1271 : :
1272 : 0 : txq->eth_dev = dev;
1273 : 0 : txq->queue_id = dq_num;
1274 : 0 : dev->data->tx_queues[qidx] = txq;
1275 : 0 : dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1276 : :
1277 : 0 : res = octeontx_pko_channel_query_dqs(nic->base_ochan,
1278 : 0 : &txq->dq,
1279 : : sizeof(octeontx_dq_t),
1280 : : txq->queue_id,
1281 : : octeontx_dq_info_getter);
1282 [ # # ]: 0 : if (res < 0) {
1283 : : res = -EFAULT;
1284 : 0 : goto err;
1285 : : }
1286 : :
1287 : 0 : PMD_TX_LOG(DEBUG, "[%d]:[%d] txq=%p nb_desc=%d lmtline=%p ioreg_va=%p fc_status_va=%p",
1288 : : qidx, txq->queue_id, txq, nb_desc, txq->dq.lmtline_va,
1289 : : txq->dq.ioreg_va,
1290 : : txq->dq.fc_status_va);
1291 : :
1292 : 0 : return res;
1293 : :
1294 : 0 : err:
1295 : 0 : rte_free(txq);
1296 : :
1297 : 0 : return res;
1298 : : }
1299 : :
1300 : : static int
1301 [ # # ]: 0 : octeontx_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
1302 : : uint16_t nb_desc, unsigned int socket_id,
1303 : : const struct rte_eth_rxconf *rx_conf,
1304 : : struct rte_mempool *mb_pool)
1305 : : {
1306 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1307 : : struct rte_mempool_ops *mp_ops = NULL;
1308 : : struct octeontx_rxq *rxq = NULL;
1309 : : pki_pktbuf_cfg_t pktbuf_conf;
1310 : : pki_hash_cfg_t pki_hash;
1311 : : pki_qos_cfg_t pki_qos;
1312 : : uintptr_t pool;
1313 : : int ret, port;
1314 : : uint16_t gaura;
1315 : 0 : unsigned int ev_queues = (nic->ev_queues * nic->port_id) + qidx;
1316 [ # # ]: 0 : unsigned int ev_ports = (nic->ev_ports * nic->port_id) + qidx;
1317 : :
1318 : : RTE_SET_USED(nb_desc);
1319 : :
1320 : : memset(&pktbuf_conf, 0, sizeof(pktbuf_conf));
1321 : : memset(&pki_hash, 0, sizeof(pki_hash));
1322 : : memset(&pki_qos, 0, sizeof(pki_qos));
1323 : :
1324 [ # # ]: 0 : mp_ops = rte_mempool_get_ops(mb_pool->ops_index);
1325 [ # # ]: 0 : if (strcmp(mp_ops->name, "octeontx_fpavf")) {
1326 : 0 : octeontx_log_err("failed to find octeontx_fpavf mempool");
1327 : 0 : return -ENOTSUP;
1328 : : }
1329 : :
1330 : : /* Handle forbidden configurations */
1331 [ # # ]: 0 : if (nic->pki.classifier_enable) {
1332 : 0 : octeontx_log_err("cannot setup queue %d. "
1333 : : "Classifier option unsupported", qidx);
1334 : 0 : return -EINVAL;
1335 : : }
1336 : :
1337 : 0 : port = nic->port_id;
1338 : :
1339 : : /* Rx deferred start is not supported */
1340 [ # # ]: 0 : if (rx_conf->rx_deferred_start) {
1341 : 0 : octeontx_log_err("rx deferred start not supported");
1342 : 0 : return -EINVAL;
1343 : : }
1344 : :
1345 : : /* Verify queue index */
1346 [ # # ]: 0 : if (qidx >= dev->data->nb_rx_queues) {
1347 : 0 : octeontx_log_err("QID %d not supported (0 - %d available)",
1348 : : qidx, (dev->data->nb_rx_queues - 1));
1349 : 0 : return -ENOTSUP;
1350 : : }
1351 : :
1352 : : /* Socket id check */
1353 [ # # ]: 0 : if (socket_id != (unsigned int)SOCKET_ID_ANY &&
1354 [ # # ]: 0 : socket_id != (unsigned int)nic->node)
1355 : 0 : PMD_RX_LOG(INFO, "socket_id expected %d, configured %d",
1356 : : socket_id, nic->node);
1357 : :
1358 : : /* Allocating rx queue data structure */
1359 : 0 : rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct octeontx_rxq),
1360 : : RTE_CACHE_LINE_SIZE, nic->node);
1361 [ # # ]: 0 : if (rxq == NULL) {
1362 : 0 : octeontx_log_err("failed to allocate rxq=%d", qidx);
1363 : 0 : return -ENOMEM;
1364 : : }
1365 : :
1366 [ # # ]: 0 : if (!nic->pki.initialized) {
1367 : 0 : pktbuf_conf.port_type = 0;
1368 : 0 : pki_hash.port_type = 0;
1369 : 0 : pki_qos.port_type = 0;
1370 : :
1371 : 0 : pktbuf_conf.mmask.f_wqe_skip = 1;
1372 : 0 : pktbuf_conf.mmask.f_first_skip = 1;
1373 : 0 : pktbuf_conf.mmask.f_later_skip = 1;
1374 : 0 : pktbuf_conf.mmask.f_mbuff_size = 1;
1375 : 0 : pktbuf_conf.mmask.f_cache_mode = 1;
1376 : :
1377 [ # # ]: 0 : pktbuf_conf.wqe_skip = OCTTX_PACKET_WQE_SKIP;
1378 : 0 : pktbuf_conf.first_skip = OCTTX_PACKET_FIRST_SKIP(mb_pool);
1379 : 0 : pktbuf_conf.later_skip = OCTTX_PACKET_LATER_SKIP;
1380 : 0 : pktbuf_conf.mbuff_size = (mb_pool->elt_size -
1381 : 0 : RTE_PKTMBUF_HEADROOM -
1382 : 0 : rte_pktmbuf_priv_size(mb_pool) -
1383 : : sizeof(struct rte_mbuf));
1384 : :
1385 : 0 : pktbuf_conf.cache_mode = PKI_OPC_MODE_STF2_STT;
1386 : :
1387 : 0 : ret = octeontx_pki_port_pktbuf_config(port, &pktbuf_conf);
1388 [ # # ]: 0 : if (ret != 0) {
1389 : 0 : octeontx_log_err("fail to configure pktbuf for port %d",
1390 : : port);
1391 : 0 : rte_free(rxq);
1392 : 0 : return ret;
1393 : : }
1394 : 0 : PMD_RX_LOG(DEBUG, "Port %d Rx pktbuf configured:",
1395 : : port);
1396 : 0 : PMD_RX_LOG(DEBUG, "\tmbuf_size:\t0x%0x",
1397 : : pktbuf_conf.mbuff_size);
1398 : 0 : PMD_RX_LOG(DEBUG, "\twqe_skip:\t0x%0x",
1399 : : pktbuf_conf.wqe_skip);
1400 : 0 : PMD_RX_LOG(DEBUG, "\tfirst_skip:\t0x%0x",
1401 : : pktbuf_conf.first_skip);
1402 : 0 : PMD_RX_LOG(DEBUG, "\tlater_skip:\t0x%0x",
1403 : : pktbuf_conf.later_skip);
1404 [ # # # # : 0 : PMD_RX_LOG(DEBUG, "\tcache_mode:\t%s",
# # ]
1405 : : (pktbuf_conf.cache_mode ==
1406 : : PKI_OPC_MODE_STT) ?
1407 : : "STT" :
1408 : : (pktbuf_conf.cache_mode ==
1409 : : PKI_OPC_MODE_STF) ?
1410 : : "STF" :
1411 : : (pktbuf_conf.cache_mode ==
1412 : : PKI_OPC_MODE_STF1_STT) ?
1413 : : "STF1_STT" : "STF2_STT");
1414 : :
1415 [ # # ]: 0 : if (nic->pki.hash_enable) {
1416 : 0 : pki_hash.tag_dlc = 1;
1417 : 0 : pki_hash.tag_slc = 1;
1418 : 0 : pki_hash.tag_dlf = 1;
1419 : 0 : pki_hash.tag_slf = 1;
1420 : 0 : pki_hash.tag_prt = 1;
1421 : 0 : octeontx_pki_port_hash_config(port, &pki_hash);
1422 : : }
1423 : :
1424 : 0 : pool = (uintptr_t)mb_pool->pool_id;
1425 : :
1426 : : /* Get the gaura Id */
1427 : : gaura = octeontx_fpa_bufpool_gaura(pool);
1428 : :
1429 : 0 : pki_qos.qpg_qos = PKI_QPG_QOS_NONE;
1430 : 0 : pki_qos.num_entry = 1;
1431 : 0 : pki_qos.drop_policy = 0;
1432 : 0 : pki_qos.tag_type = 0L;
1433 : 0 : pki_qos.qos_entry[0].port_add = 0;
1434 : 0 : pki_qos.qos_entry[0].gaura = gaura;
1435 : 0 : pki_qos.qos_entry[0].ggrp_ok = ev_queues;
1436 : 0 : pki_qos.qos_entry[0].ggrp_bad = ev_queues;
1437 : 0 : pki_qos.qos_entry[0].grptag_bad = 0;
1438 : 0 : pki_qos.qos_entry[0].grptag_ok = 0;
1439 : :
1440 : 0 : ret = octeontx_pki_port_create_qos(port, &pki_qos);
1441 [ # # ]: 0 : if (ret < 0) {
1442 : 0 : octeontx_log_err("failed to create QOS port=%d, q=%d",
1443 : : port, qidx);
1444 : 0 : rte_free(rxq);
1445 : 0 : return ret;
1446 : : }
1447 : 0 : nic->pki.initialized = true;
1448 : : }
1449 : :
1450 : 0 : rxq->port_id = nic->port_id;
1451 : 0 : rxq->eth_dev = dev;
1452 : 0 : rxq->queue_id = qidx;
1453 : 0 : rxq->evdev = nic->evdev;
1454 : 0 : rxq->ev_queues = ev_queues;
1455 : 0 : rxq->ev_ports = ev_ports;
1456 : 0 : rxq->pool = mb_pool;
1457 : :
1458 : 0 : octeontx_recheck_rx_offloads(rxq);
1459 : 0 : dev->data->rx_queues[qidx] = rxq;
1460 : 0 : dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1461 : :
1462 : 0 : return 0;
1463 : : }
1464 : :
1465 : : static void
1466 : 0 : octeontx_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1467 : : {
1468 : 0 : rte_free(dev->data->rx_queues[qid]);
1469 : 0 : }
1470 : :
1471 : : static const uint32_t *
1472 : 0 : octeontx_dev_supported_ptypes_get(struct rte_eth_dev *dev,
1473 : : size_t *no_of_elements)
1474 : : {
1475 : : static const uint32_t ptypes[] = {
1476 : : RTE_PTYPE_L3_IPV4,
1477 : : RTE_PTYPE_L3_IPV4_EXT,
1478 : : RTE_PTYPE_L3_IPV6,
1479 : : RTE_PTYPE_L3_IPV6_EXT,
1480 : : RTE_PTYPE_L4_TCP,
1481 : : RTE_PTYPE_L4_UDP,
1482 : : RTE_PTYPE_L4_FRAG,
1483 : : };
1484 : :
1485 [ # # ]: 0 : if (dev->rx_pkt_burst == octeontx_recv_pkts) {
1486 : 0 : *no_of_elements = RTE_DIM(ptypes);
1487 : 0 : return ptypes;
1488 : : }
1489 : : return NULL;
1490 : : }
1491 : :
1492 : : static int
1493 : 0 : octeontx_pool_ops(struct rte_eth_dev *dev, const char *pool)
1494 : : {
1495 : : RTE_SET_USED(dev);
1496 : :
1497 [ # # ]: 0 : if (!strcmp(pool, "octeontx_fpavf"))
1498 : 0 : return 0;
1499 : :
1500 : : return -ENOTSUP;
1501 : : }
1502 : :
1503 : : /* Initialize and register driver with DPDK Application */
1504 : : static const struct eth_dev_ops octeontx_dev_ops = {
1505 : : .dev_configure = octeontx_dev_configure,
1506 : : .dev_infos_get = octeontx_dev_info,
1507 : : .dev_close = octeontx_dev_close,
1508 : : .dev_start = octeontx_dev_start,
1509 : : .dev_stop = octeontx_dev_stop,
1510 : : .promiscuous_enable = octeontx_dev_promisc_enable,
1511 : : .promiscuous_disable = octeontx_dev_promisc_disable,
1512 : : .link_update = octeontx_dev_link_update,
1513 : : .stats_get = octeontx_dev_stats_get,
1514 : : .stats_reset = octeontx_dev_stats_reset,
1515 : : .mac_addr_remove = octeontx_dev_mac_addr_del,
1516 : : .mac_addr_add = octeontx_dev_mac_addr_add,
1517 : : .mac_addr_set = octeontx_dev_default_mac_addr_set,
1518 : : .vlan_offload_set = octeontx_dev_vlan_offload_set,
1519 : : .vlan_filter_set = octeontx_dev_vlan_filter_set,
1520 : : .tx_queue_start = octeontx_dev_tx_queue_start,
1521 : : .tx_queue_stop = octeontx_dev_tx_queue_stop,
1522 : : .tx_queue_setup = octeontx_dev_tx_queue_setup,
1523 : : .tx_queue_release = octeontx_dev_tx_queue_release,
1524 : : .rx_queue_setup = octeontx_dev_rx_queue_setup,
1525 : : .rx_queue_release = octeontx_dev_rx_queue_release,
1526 : : .dev_set_link_up = octeontx_dev_set_link_up,
1527 : : .dev_set_link_down = octeontx_dev_set_link_down,
1528 : : .dev_supported_ptypes_get = octeontx_dev_supported_ptypes_get,
1529 : : .mtu_set = octeontx_dev_mtu_set,
1530 : : .pool_ops_supported = octeontx_pool_ops,
1531 : : .flow_ctrl_get = octeontx_dev_flow_ctrl_get,
1532 : : .flow_ctrl_set = octeontx_dev_flow_ctrl_set,
1533 : : .xstats_get = octeontx_dev_xstats_get,
1534 : : .xstats_get_by_id = octeontx_dev_xstats_get_by_id,
1535 : : .xstats_get_names = octeontx_dev_xstats_get_names,
1536 : : .xstats_get_names_by_id = octeontx_dev_xstats_get_names_by_id,
1537 : : .allmulticast_enable = octeontx_allmulticast_enable,
1538 : : .allmulticast_disable = octeontx_allmulticast_disable,
1539 : : };
1540 : :
1541 : : /* Create Ethdev interface per BGX LMAC ports */
1542 : : static int
1543 [ # # ]: 0 : octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
1544 : : int socket_id)
1545 : : {
1546 : : int res;
1547 : : size_t pko_vfid;
1548 : : char octtx_name[OCTEONTX_MAX_NAME_LEN];
1549 : : struct octeontx_nic *nic = NULL;
1550 : : struct rte_eth_dev *eth_dev = NULL;
1551 : : struct rte_eth_dev_data *data;
1552 : : const char *name = rte_vdev_device_name(dev);
1553 : : int max_entries;
1554 : :
1555 : 0 : PMD_INIT_FUNC_TRACE();
1556 : :
1557 : : sprintf(octtx_name, "%s_%d", name, port);
1558 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1559 : 0 : eth_dev = rte_eth_dev_attach_secondary(octtx_name);
1560 [ # # ]: 0 : if (eth_dev == NULL)
1561 : : return -ENODEV;
1562 : :
1563 : 0 : eth_dev->dev_ops = &octeontx_dev_ops;
1564 : 0 : eth_dev->device = &dev->device;
1565 : 0 : octeontx_set_tx_function(eth_dev);
1566 : 0 : eth_dev->rx_pkt_burst = octeontx_recv_pkts;
1567 : 0 : rte_eth_dev_probing_finish(eth_dev);
1568 : 0 : return 0;
1569 : : }
1570 : :
1571 : : /* Reserve an ethdev entry */
1572 : 0 : eth_dev = rte_eth_dev_allocate(octtx_name);
1573 [ # # ]: 0 : if (eth_dev == NULL) {
1574 : 0 : octeontx_log_err("failed to allocate rte_eth_dev");
1575 : : res = -ENOMEM;
1576 : 0 : goto err;
1577 : : }
1578 : 0 : data = eth_dev->data;
1579 : :
1580 : 0 : nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id);
1581 [ # # ]: 0 : if (nic == NULL) {
1582 : 0 : octeontx_log_err("failed to allocate nic structure");
1583 : : res = -ENOMEM;
1584 : 0 : goto err;
1585 : : }
1586 : 0 : data->dev_private = nic;
1587 : 0 : pko_vfid = octeontx_pko_get_vfid();
1588 : :
1589 [ # # ]: 0 : if (pko_vfid == SIZE_MAX) {
1590 : 0 : octeontx_log_err("failed to get pko vfid");
1591 : : res = -ENODEV;
1592 : 0 : goto err;
1593 : : }
1594 : :
1595 : 0 : nic->pko_vfid = pko_vfid;
1596 : 0 : nic->port_id = port;
1597 : 0 : nic->evdev = evdev;
1598 : 0 : rte_atomic_fetch_add_explicit(&evdev_refcnt, 1, rte_memory_order_acquire);
1599 : :
1600 : 0 : res = octeontx_port_open(nic);
1601 [ # # ]: 0 : if (res < 0)
1602 : 0 : goto err;
1603 : :
1604 : : /* Rx side port configuration */
1605 : 0 : res = octeontx_pki_port_open(port);
1606 [ # # ]: 0 : if (res != 0) {
1607 : 0 : octeontx_log_err("failed to open PKI port %d", port);
1608 : : res = -ENODEV;
1609 : 0 : goto err;
1610 : : }
1611 : :
1612 : 0 : eth_dev->device = &dev->device;
1613 : 0 : eth_dev->intr_handle = NULL;
1614 : 0 : eth_dev->data->numa_node = dev->device.numa_node;
1615 : :
1616 : 0 : data->port_id = eth_dev->data->port_id;
1617 : :
1618 : 0 : nic->ev_queues = 1;
1619 : 0 : nic->ev_ports = 1;
1620 : 0 : nic->print_flag = -1;
1621 : 0 : nic->reconfigure = false;
1622 : :
1623 : 0 : data->dev_link.link_status = RTE_ETH_LINK_DOWN;
1624 : 0 : data->dev_started = 0;
1625 : 0 : data->promiscuous = 0;
1626 : 0 : data->all_multicast = 0;
1627 : 0 : data->scattered_rx = 0;
1628 : :
1629 : : /* Get maximum number of supported MAC entries */
1630 : 0 : max_entries = octeontx_bgx_port_mac_entries_get(nic->port_id);
1631 [ # # ]: 0 : if (max_entries < 0) {
1632 : 0 : octeontx_log_err("Failed to get max entries for mac addr");
1633 : : res = -ENOTSUP;
1634 : 0 : goto err;
1635 : : }
1636 : :
1637 : 0 : data->mac_addrs = rte_zmalloc_socket(octtx_name, max_entries *
1638 : : RTE_ETHER_ADDR_LEN, 0,
1639 : : socket_id);
1640 [ # # ]: 0 : if (data->mac_addrs == NULL) {
1641 : 0 : octeontx_log_err("failed to allocate memory for mac_addrs");
1642 : : res = -ENOMEM;
1643 : 0 : goto err;
1644 : : }
1645 : :
1646 : 0 : eth_dev->dev_ops = &octeontx_dev_ops;
1647 : :
1648 : : /* Finally save ethdev pointer to the NIC structure */
1649 : 0 : nic->dev = eth_dev;
1650 : :
1651 [ # # ]: 0 : if (nic->port_id != data->port_id) {
1652 : 0 : octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
1653 : : data->port_id, nic->port_id);
1654 : : res = -EINVAL;
1655 : 0 : goto free_mac_addrs;
1656 : : }
1657 : :
1658 : 0 : res = rte_eal_alarm_set(OCCTX_INTR_POLL_INTERVAL_MS * 1000,
1659 : : octeontx_link_status_poll, nic);
1660 [ # # ]: 0 : if (res) {
1661 : 0 : octeontx_log_err("Failed to start link polling alarm");
1662 : 0 : goto err;
1663 : : }
1664 : :
1665 : : /* Update port_id mac to eth_dev */
1666 : 0 : memcpy(data->mac_addrs, nic->mac_addr, RTE_ETHER_ADDR_LEN);
1667 : :
1668 : : /* Update same mac address to BGX CAM table at index 0 */
1669 : 0 : octeontx_bgx_port_mac_add(nic->port_id, nic->mac_addr, 0);
1670 : :
1671 : 0 : res = octeontx_dev_flow_ctrl_init(eth_dev);
1672 [ # # ]: 0 : if (res < 0)
1673 : 0 : goto err;
1674 : :
1675 : 0 : PMD_INIT_LOG(DEBUG, "ethdev info: ");
1676 : 0 : PMD_INIT_LOG(DEBUG, "port %d, port_ena %d ochan %d num_ochan %d tx_q %d",
1677 : : nic->port_id, nic->port_ena,
1678 : : nic->base_ochan, nic->num_ochans,
1679 : : nic->num_tx_queues);
1680 : 0 : PMD_INIT_LOG(DEBUG, "speed %d mtu %d", nic->speed, nic->bgx_mtu);
1681 : :
1682 : 0 : rte_octeontx_pchan_map[(nic->base_ochan >> 8) & 0x7]
1683 : 0 : [(nic->base_ochan >> 4) & 0xF] = data->port_id;
1684 : :
1685 : 0 : rte_eth_dev_probing_finish(eth_dev);
1686 : 0 : return data->port_id;
1687 : :
1688 : : free_mac_addrs:
1689 : 0 : rte_free(data->mac_addrs);
1690 : 0 : data->mac_addrs = NULL;
1691 : 0 : err:
1692 [ # # ]: 0 : if (nic)
1693 : 0 : octeontx_port_close(nic);
1694 : :
1695 : 0 : rte_eth_dev_release_port(eth_dev);
1696 : :
1697 : 0 : return res;
1698 : : }
1699 : :
1700 : : /* Un initialize octeontx device */
1701 : : static int
1702 : 0 : octeontx_remove(struct rte_vdev_device *dev)
1703 : : {
1704 : : char octtx_name[OCTEONTX_MAX_NAME_LEN];
1705 : : struct rte_eth_dev *eth_dev = NULL;
1706 : : struct octeontx_nic *nic = NULL;
1707 : : int i;
1708 : :
1709 [ # # ]: 0 : if (dev == NULL)
1710 : : return -EINVAL;
1711 : :
1712 [ # # ]: 0 : for (i = 0; i < OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT; i++) {
1713 : : sprintf(octtx_name, "eth_octeontx_%d", i);
1714 : :
1715 : 0 : eth_dev = rte_eth_dev_allocated(octtx_name);
1716 [ # # ]: 0 : if (eth_dev == NULL)
1717 : 0 : continue; /* port already released */
1718 : :
1719 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1720 : 0 : rte_eth_dev_release_port(eth_dev);
1721 : 0 : continue;
1722 : : }
1723 : :
1724 : : nic = octeontx_pmd_priv(eth_dev);
1725 : 0 : rte_event_dev_stop(nic->evdev);
1726 : 0 : PMD_INIT_LOG(INFO, "Closing octeontx device %s", octtx_name);
1727 : 0 : octeontx_dev_close(eth_dev);
1728 : 0 : rte_eth_dev_release_port(eth_dev);
1729 : : }
1730 : :
1731 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1732 : : return 0;
1733 : :
1734 : : /* Free FC resource */
1735 : 0 : octeontx_pko_fc_free();
1736 : :
1737 : 0 : return 0;
1738 : : }
1739 : :
1740 : : /* Initialize octeontx device */
1741 : : static int
1742 : 0 : octeontx_probe(struct rte_vdev_device *dev)
1743 : : {
1744 : : const char *dev_name;
1745 : : static int probe_once;
1746 : : uint8_t socket_id, qlist;
1747 : : int tx_vfcnt, port_id, evdev, qnum, pnum, res, i;
1748 : : struct rte_event_dev_config dev_conf;
1749 : : const char *eventdev_name = "event_octeontx";
1750 : : struct rte_event_dev_info info;
1751 : : struct rte_eth_dev *eth_dev;
1752 : :
1753 [ # # ]: 0 : struct octeontx_vdev_init_params init_params = {
1754 : : OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT
1755 : : };
1756 : :
1757 : : dev_name = rte_vdev_device_name(dev);
1758 : :
1759 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
1760 [ # # ]: 0 : strlen(rte_vdev_device_args(dev)) == 0) {
1761 : 0 : eth_dev = rte_eth_dev_attach_secondary(dev_name);
1762 [ # # ]: 0 : if (!eth_dev) {
1763 : 0 : PMD_INIT_LOG(ERR, "Failed to probe %s", dev_name);
1764 : 0 : return -1;
1765 : : }
1766 : : /* TODO: request info from primary to set up Rx and Tx */
1767 : 0 : eth_dev->dev_ops = &octeontx_dev_ops;
1768 : 0 : eth_dev->device = &dev->device;
1769 : 0 : rte_eth_dev_probing_finish(eth_dev);
1770 : 0 : return 0;
1771 : : }
1772 : :
1773 : 0 : res = octeontx_parse_vdev_init_params(&init_params, dev);
1774 [ # # ]: 0 : if (res < 0)
1775 : : return -EINVAL;
1776 : :
1777 [ # # ]: 0 : if (init_params.nr_port > OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT) {
1778 : 0 : octeontx_log_err("nr_port (%d) > max (%d)", init_params.nr_port,
1779 : : OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT);
1780 : 0 : return -ENOTSUP;
1781 : : }
1782 : :
1783 : 0 : PMD_INIT_LOG(DEBUG, "initializing %s pmd", dev_name);
1784 : :
1785 : 0 : socket_id = rte_socket_id();
1786 : :
1787 : 0 : tx_vfcnt = octeontx_pko_vf_count();
1788 : :
1789 [ # # ]: 0 : if (tx_vfcnt < init_params.nr_port) {
1790 : 0 : octeontx_log_err("not enough PKO (%d) for port number (%d)",
1791 : : tx_vfcnt, init_params.nr_port);
1792 : 0 : return -EINVAL;
1793 : : }
1794 : 0 : evdev = rte_event_dev_get_dev_id(eventdev_name);
1795 [ # # ]: 0 : if (evdev < 0) {
1796 : 0 : octeontx_log_err("eventdev %s not found", eventdev_name);
1797 : 0 : return -ENODEV;
1798 : : }
1799 : :
1800 : 0 : res = rte_event_dev_info_get(evdev, &info);
1801 [ # # ]: 0 : if (res < 0) {
1802 : 0 : octeontx_log_err("failed to eventdev info %d", res);
1803 : 0 : return -EINVAL;
1804 : : }
1805 : :
1806 : 0 : PMD_INIT_LOG(DEBUG, "max_queue %d max_port %d",
1807 : : info.max_event_queues, info.max_event_ports);
1808 : :
1809 [ # # ]: 0 : if (octeontx_pko_init_fc(tx_vfcnt))
1810 : : return -ENOMEM;
1811 : :
1812 : 0 : devconf_set_default_sane_values(&dev_conf, &info);
1813 : 0 : res = rte_event_dev_configure(evdev, &dev_conf);
1814 [ # # ]: 0 : if (res < 0)
1815 : 0 : goto parse_error;
1816 : :
1817 : 0 : rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_PORT_COUNT,
1818 : : (uint32_t *)&pnum);
1819 : 0 : rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_QUEUE_COUNT,
1820 : : (uint32_t *)&qnum);
1821 [ # # ]: 0 : if (pnum < qnum) {
1822 : 0 : octeontx_log_err("too few event ports (%d) for event_q(%d)",
1823 : : pnum, qnum);
1824 : : res = -EINVAL;
1825 : 0 : goto parse_error;
1826 : : }
1827 : :
1828 : : /* Enable all queues available */
1829 [ # # ]: 0 : for (i = 0; i < qnum; i++) {
1830 : 0 : res = rte_event_queue_setup(evdev, i, NULL);
1831 [ # # ]: 0 : if (res < 0) {
1832 : 0 : octeontx_log_err("failed to setup event_q(%d): res %d",
1833 : : i, res);
1834 : 0 : goto parse_error;
1835 : : }
1836 : : }
1837 : :
1838 : : /* Enable all ports available */
1839 [ # # ]: 0 : for (i = 0; i < pnum; i++) {
1840 : 0 : res = rte_event_port_setup(evdev, i, NULL);
1841 [ # # ]: 0 : if (res < 0) {
1842 : : res = -ENODEV;
1843 : 0 : octeontx_log_err("failed to setup ev port(%d) res=%d",
1844 : : i, res);
1845 : 0 : goto parse_error;
1846 : : }
1847 : : }
1848 : :
1849 : 0 : rte_atomic_store_explicit(&evdev_refcnt, 0, rte_memory_order_release);
1850 : : /*
1851 : : * Do 1:1 links for ports & queues. All queues would be mapped to
1852 : : * one port. If there are more ports than queues, then some ports
1853 : : * won't be linked to any queue.
1854 : : */
1855 [ # # ]: 0 : for (i = 0; i < qnum; i++) {
1856 : : /* Link one queue to one event port */
1857 : 0 : qlist = i;
1858 : 0 : res = rte_event_port_link(evdev, i, &qlist, NULL, 1);
1859 [ # # ]: 0 : if (res < 0) {
1860 : : res = -ENODEV;
1861 : 0 : octeontx_log_err("failed to link port (%d): res=%d",
1862 : : i, res);
1863 : 0 : goto parse_error;
1864 : : }
1865 : : }
1866 : :
1867 : : /* Create ethdev interface */
1868 [ # # ]: 0 : for (i = 0; i < init_params.nr_port; i++) {
1869 : 0 : port_id = octeontx_create(dev, i, evdev, socket_id);
1870 [ # # ]: 0 : if (port_id < 0) {
1871 : 0 : octeontx_log_err("failed to create device %s",
1872 : : dev_name);
1873 : : res = -ENODEV;
1874 : 0 : goto parse_error;
1875 : : }
1876 : :
1877 : 0 : PMD_INIT_LOG(INFO, "created ethdev %s for port %d", dev_name,
1878 : : port_id);
1879 : : }
1880 : :
1881 [ # # ]: 0 : if (probe_once) {
1882 : 0 : octeontx_log_err("interface %s not supported", dev_name);
1883 : 0 : octeontx_remove(dev);
1884 : : res = -ENOTSUP;
1885 : 0 : goto parse_error;
1886 : : }
1887 : 0 : rte_mbuf_set_platform_mempool_ops("octeontx_fpavf");
1888 : 0 : probe_once = 1;
1889 : :
1890 : 0 : return 0;
1891 : :
1892 : 0 : parse_error:
1893 : 0 : octeontx_pko_fc_free();
1894 : 0 : return res;
1895 : : }
1896 : :
1897 : : static struct rte_vdev_driver octeontx_pmd_drv = {
1898 : : .probe = octeontx_probe,
1899 : : .remove = octeontx_remove,
1900 : : };
1901 : :
1902 : 252 : RTE_PMD_REGISTER_VDEV(OCTEONTX_PMD, octeontx_pmd_drv);
1903 : : RTE_PMD_REGISTER_ALIAS(OCTEONTX_PMD, eth_octeontx);
1904 : : RTE_PMD_REGISTER_PARAM_STRING(OCTEONTX_PMD, "nr_port=<int> ");
|