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 [ - + ]: 306 : RTE_LOG_REGISTER_SUFFIX(otx_net_logtype_mbox, mbox, NOTICE);
65 [ - + ]: 306 : RTE_LOG_REGISTER_SUFFIX(otx_net_logtype_init, init, NOTICE);
66 [ - + ]: 306 : 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->offloads & RTE_ETH_TX_OFFLOAD_MT_LOCKFREE)) {
498 : 0 : PMD_INIT_LOG(NOTICE, "cant disable lockfree tx");
499 : 0 : txmode->offloads |= RTE_ETH_TX_OFFLOAD_MT_LOCKFREE;
500 : : }
501 : :
502 [ # # ]: 0 : if (conf->dcb_capability_en) {
503 : 0 : octeontx_log_err("DCB enable not supported");
504 : 0 : return -EINVAL;
505 : : }
506 : :
507 : 0 : nic->num_tx_queues = dev->data->nb_tx_queues;
508 : :
509 [ # # ]: 0 : if (!nic->reconfigure) {
510 : 0 : ret = octeontx_pko_channel_open(nic->pko_vfid * PKO_VF_NUM_DQ,
511 : : nic->num_tx_queues,
512 : : nic->base_ochan);
513 [ # # ]: 0 : if (ret) {
514 : 0 : octeontx_log_err("failed to open channel %d no-of-txq %d",
515 : : nic->base_ochan, nic->num_tx_queues);
516 : 0 : return -EFAULT;
517 : : }
518 : :
519 : 0 : ret = octeontx_dev_vlan_offload_init(dev);
520 [ # # ]: 0 : if (ret) {
521 : 0 : octeontx_log_err("failed to initialize vlan offload");
522 : 0 : return -EFAULT;
523 : : }
524 : :
525 : 0 : nic->pki.classifier_enable = false;
526 : 0 : nic->pki.hash_enable = true;
527 : 0 : nic->pki.initialized = false;
528 : : }
529 : :
530 : 0 : nic->rx_offloads |= rxmode->offloads;
531 [ # # ]: 0 : nic->tx_offloads |= txmode->offloads;
532 : 0 : nic->rx_offload_flags |= octeontx_rx_offload_flags(dev);
533 : 0 : nic->tx_offload_flags |= octeontx_tx_offload_flags(dev);
534 : :
535 : 0 : nic->reconfigure = true;
536 : :
537 : 0 : return 0;
538 : : }
539 : :
540 : : static int
541 : 0 : octeontx_dev_close(struct rte_eth_dev *dev)
542 : : {
543 : : struct octeontx_txq *txq = NULL;
544 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
545 : : unsigned int i;
546 : : int ret;
547 : :
548 : 0 : PMD_INIT_FUNC_TRACE();
549 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
550 : : return 0;
551 : :
552 : : /* Stopping/closing event device once all eth ports are closed. */
553 [ # # ]: 0 : if (rte_atomic_fetch_sub_explicit(&evdev_refcnt, 1, rte_memory_order_acquire) - 1 == 0) {
554 : 0 : rte_event_dev_stop(nic->evdev);
555 : 0 : rte_event_dev_close(nic->evdev);
556 : : }
557 : :
558 : 0 : octeontx_dev_flow_ctrl_fini(dev);
559 : :
560 : 0 : octeontx_dev_vlan_offload_fini(dev);
561 : :
562 : 0 : ret = octeontx_pko_channel_close(nic->base_ochan);
563 [ # # ]: 0 : if (ret < 0) {
564 : 0 : octeontx_log_err("failed to close channel %d VF%d %d %d",
565 : : nic->base_ochan, nic->port_id, nic->num_tx_queues,
566 : : ret);
567 : : }
568 : : /* Free txq resources for this port */
569 [ # # ]: 0 : for (i = 0; i < nic->num_tx_queues; i++) {
570 : 0 : txq = dev->data->tx_queues[i];
571 [ # # ]: 0 : if (!txq)
572 : 0 : continue;
573 : :
574 : 0 : rte_free(txq);
575 : : }
576 : :
577 : 0 : octeontx_port_close(nic);
578 : 0 : nic->reconfigure = false;
579 : :
580 : 0 : return 0;
581 : : }
582 : :
583 : : static int
584 : 0 : octeontx_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
585 : : {
586 [ # # ]: 0 : uint32_t buffsz, frame_size = mtu + OCCTX_L2_OVERHEAD;
587 : : struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
588 : : struct rte_eth_dev_data *data = eth_dev->data;
589 : : int rc = 0;
590 : :
591 : 0 : buffsz = data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
592 : :
593 : : /* Refuse MTU that requires the support of scattered packets
594 : : * when this feature has not been enabled before.
595 : : */
596 [ # # # # ]: 0 : if (data->dev_started && frame_size > buffsz &&
597 [ # # ]: 0 : !(nic->rx_offloads & RTE_ETH_RX_OFFLOAD_SCATTER)) {
598 : 0 : octeontx_log_err("Scatter mode is disabled");
599 : 0 : return -EINVAL;
600 : : }
601 : :
602 : : /* Check <seg size> * <max_seg> >= max_frame */
603 [ # # ]: 0 : if ((nic->rx_offloads & RTE_ETH_RX_OFFLOAD_SCATTER) &&
604 [ # # ]: 0 : (frame_size > buffsz * OCCTX_RX_NB_SEG_MAX))
605 : : return -EINVAL;
606 : :
607 : 0 : rc = octeontx_pko_send_mtu(nic->port_id, frame_size);
608 [ # # ]: 0 : if (rc)
609 : : return rc;
610 : :
611 : 0 : rc = octeontx_bgx_port_mtu_set(nic->port_id, frame_size);
612 [ # # ]: 0 : if (rc)
613 : : return rc;
614 : :
615 : 0 : octeontx_log_info("Received pkt beyond maxlen %d will be dropped",
616 : : frame_size);
617 : :
618 : 0 : return rc;
619 : : }
620 : :
621 : : static int
622 : 0 : octeontx_recheck_rx_offloads(struct octeontx_rxq *rxq)
623 : : {
624 [ # # ]: 0 : struct rte_eth_dev *eth_dev = rxq->eth_dev;
625 : : struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
626 : : struct rte_eth_dev_data *data = eth_dev->data;
627 : : struct rte_pktmbuf_pool_private *mbp_priv;
628 : : struct evdev_priv_data *evdev_priv;
629 : : struct rte_eventdev *dev;
630 : : uint32_t buffsz;
631 : :
632 : : /* Get rx buffer size */
633 : 0 : mbp_priv = rte_mempool_get_priv(rxq->pool);
634 : 0 : buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
635 : :
636 : : /* Setup scatter mode if needed by jumbo */
637 [ # # ]: 0 : if (data->mtu > buffsz) {
638 [ # # ]: 0 : nic->rx_offloads |= RTE_ETH_RX_OFFLOAD_SCATTER;
639 : 0 : nic->rx_offload_flags |= octeontx_rx_offload_flags(eth_dev);
640 : 0 : nic->tx_offload_flags |= octeontx_tx_offload_flags(eth_dev);
641 : : }
642 : :
643 : : /* Sharing offload flags via eventdev priv region */
644 : 0 : dev = &rte_eventdevs[rxq->evdev];
645 : 0 : evdev_priv = dev->data->dev_private;
646 : 0 : evdev_priv->rx_offload_flags = nic->rx_offload_flags;
647 : 0 : evdev_priv->tx_offload_flags = nic->tx_offload_flags;
648 : :
649 : : /* Setup MTU */
650 : 0 : nic->mtu = data->mtu;
651 : :
652 : 0 : return 0;
653 : : }
654 : :
655 : : static int
656 : 0 : octeontx_dev_start(struct rte_eth_dev *dev)
657 : : {
658 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
659 : : struct octeontx_rxq *rxq;
660 : : int ret, i;
661 : :
662 : 0 : PMD_INIT_FUNC_TRACE();
663 : : /* Rechecking if any new offload set to update
664 : : * rx/tx burst function pointer accordingly.
665 : : */
666 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
667 : 0 : rxq = dev->data->rx_queues[i];
668 : 0 : octeontx_recheck_rx_offloads(rxq);
669 : : }
670 : :
671 : : /* Setting up the mtu */
672 : 0 : ret = octeontx_dev_mtu_set(dev, nic->mtu);
673 [ # # ]: 0 : if (ret) {
674 : 0 : octeontx_log_err("Failed to set default MTU size %d", ret);
675 : 0 : goto error;
676 : : }
677 : :
678 : : /* Apply new link configurations if changed */
679 : 0 : ret = octeontx_apply_link_speed(dev);
680 [ # # ]: 0 : if (ret) {
681 : 0 : octeontx_log_err("Failed to set link configuration: %d", ret);
682 : 0 : goto error;
683 : : }
684 : :
685 : : /*
686 : : * Tx start
687 : : */
688 : 0 : octeontx_set_tx_function(dev);
689 : 0 : ret = octeontx_pko_channel_start(nic->base_ochan);
690 [ # # ]: 0 : if (ret < 0) {
691 : 0 : octeontx_log_err("fail to conf VF%d no. txq %d chan %d ret %d",
692 : : nic->port_id, nic->num_tx_queues, nic->base_ochan,
693 : : ret);
694 : 0 : goto error;
695 : : }
696 : :
697 : : /*
698 : : * Rx start
699 : : */
700 : 0 : dev->rx_pkt_burst = octeontx_recv_pkts;
701 : 0 : ret = octeontx_pki_port_start(nic->port_id);
702 [ # # ]: 0 : if (ret < 0) {
703 : 0 : octeontx_log_err("fail to start Rx on port %d", nic->port_id);
704 : 0 : goto channel_stop_error;
705 : : }
706 : :
707 : : /*
708 : : * Start port
709 : : */
710 : 0 : ret = octeontx_port_start(nic);
711 [ # # ]: 0 : if (ret < 0) {
712 : 0 : octeontx_log_err("failed start port %d", ret);
713 : 0 : goto pki_port_stop_error;
714 : : }
715 : :
716 : 0 : PMD_TX_LOG(DEBUG, "pko: start channel %d no.of txq %d port %d",
717 : : nic->base_ochan, nic->num_tx_queues, nic->port_id);
718 : :
719 : 0 : ret = rte_event_dev_start(nic->evdev);
720 [ # # ]: 0 : if (ret < 0) {
721 : 0 : octeontx_log_err("failed to start evdev: ret (%d)", ret);
722 : 0 : goto pki_port_stop_error;
723 : : }
724 : :
725 : : /* Success */
726 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
727 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
728 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
729 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
730 : :
731 : : return ret;
732 : :
733 : 0 : pki_port_stop_error:
734 : 0 : octeontx_pki_port_stop(nic->port_id);
735 : 0 : channel_stop_error:
736 : 0 : octeontx_pko_channel_stop(nic->base_ochan);
737 : : error:
738 : : return ret;
739 : : }
740 : :
741 : : static int
742 : 0 : octeontx_dev_stop(struct rte_eth_dev *dev)
743 : : {
744 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
745 : : uint16_t i;
746 : : int ret;
747 : :
748 : 0 : PMD_INIT_FUNC_TRACE();
749 : :
750 : 0 : ret = octeontx_port_stop(nic);
751 [ # # ]: 0 : if (ret < 0) {
752 : 0 : octeontx_log_err("failed to req stop port %d res=%d",
753 : : nic->port_id, ret);
754 : 0 : return ret;
755 : : }
756 : :
757 : 0 : ret = octeontx_pki_port_stop(nic->port_id);
758 [ # # ]: 0 : if (ret < 0) {
759 : 0 : octeontx_log_err("failed to stop pki port %d res=%d",
760 : : nic->port_id, ret);
761 : 0 : return ret;
762 : : }
763 : :
764 : 0 : ret = octeontx_pko_channel_stop(nic->base_ochan);
765 [ # # ]: 0 : if (ret < 0) {
766 : 0 : octeontx_log_err("failed to stop channel %d VF%d %d %d",
767 : : nic->base_ochan, nic->port_id, nic->num_tx_queues,
768 : : ret);
769 : 0 : return ret;
770 : : }
771 : :
772 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
773 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
774 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
775 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
776 : :
777 : : return 0;
778 : : }
779 : :
780 : : static int
781 : 0 : octeontx_dev_promisc_enable(struct rte_eth_dev *dev)
782 : : {
783 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
784 : :
785 : 0 : PMD_INIT_FUNC_TRACE();
786 : 0 : return octeontx_port_promisc_set(nic, 1);
787 : : }
788 : :
789 : : static int
790 : 0 : octeontx_dev_promisc_disable(struct rte_eth_dev *dev)
791 : : {
792 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
793 : :
794 : 0 : PMD_INIT_FUNC_TRACE();
795 : 0 : return octeontx_port_promisc_set(nic, 0);
796 : : }
797 : :
798 : : static int
799 : 0 : octeontx_port_link_status(struct octeontx_nic *nic)
800 : : {
801 : : int res;
802 : :
803 : 0 : PMD_INIT_FUNC_TRACE();
804 : 0 : res = octeontx_bgx_port_link_status(nic->port_id);
805 [ # # ]: 0 : if (res < 0) {
806 : 0 : octeontx_log_err("failed to get port %d link status",
807 : : nic->port_id);
808 : 0 : return res;
809 : : }
810 : :
811 [ # # # # ]: 0 : if (nic->link_up != (uint8_t)res || nic->print_flag == -1) {
812 : 0 : nic->link_up = (uint8_t)res;
813 : 0 : nic->print_flag = 1;
814 : : }
815 : 0 : octeontx_log_dbg("port %d link status %d", nic->port_id, nic->link_up);
816 : :
817 : 0 : return res;
818 : : }
819 : :
820 : : /*
821 : : * Return 0 means link status changed, -1 means not changed
822 : : */
823 : : static int
824 : 0 : octeontx_dev_link_update(struct rte_eth_dev *dev,
825 : : int wait_to_complete __rte_unused)
826 : : {
827 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
828 : : struct rte_eth_link link;
829 : : int res;
830 : :
831 : 0 : PMD_INIT_FUNC_TRACE();
832 : :
833 : 0 : res = octeontx_port_link_status(nic);
834 [ # # ]: 0 : if (res < 0) {
835 : 0 : octeontx_log_err("failed to request link status %d", res);
836 : 0 : return res;
837 : : }
838 : :
839 : 0 : octeontx_link_status_update(nic, &link);
840 [ # # ]: 0 : if (nic->print_flag) {
841 : 0 : octeontx_link_status_print(nic->dev, &link);
842 : 0 : nic->print_flag = 0;
843 : : }
844 : :
845 : : return rte_eth_linkstatus_set(dev, &link);
846 : : }
847 : :
848 : : static int
849 : 0 : octeontx_port_mcast_set(struct octeontx_nic *nic, int en)
850 : : {
851 : : struct rte_eth_dev *dev;
852 : : int res;
853 : :
854 : : res = 0;
855 : 0 : PMD_INIT_FUNC_TRACE();
856 : 0 : dev = nic->dev;
857 : :
858 : 0 : res = octeontx_bgx_port_multicast_set(nic->port_id, en);
859 [ # # ]: 0 : if (res < 0) {
860 : 0 : octeontx_log_err("failed to set multicast mode %d",
861 : : nic->port_id);
862 : 0 : return res;
863 : : }
864 : :
865 : : /* Set proper flag for the mode */
866 : 0 : dev->data->all_multicast = (en != 0) ? 1 : 0;
867 : :
868 [ # # ]: 0 : octeontx_log_dbg("port %d : multicast mode %s",
869 : : nic->port_id, en ? "set" : "unset");
870 : :
871 : 0 : return 0;
872 : : }
873 : :
874 : : static int
875 : 0 : octeontx_allmulticast_enable(struct rte_eth_dev *dev)
876 : : {
877 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
878 : :
879 : 0 : PMD_INIT_FUNC_TRACE();
880 : 0 : return octeontx_port_mcast_set(nic, 1);
881 : : }
882 : :
883 : : static int
884 : 0 : octeontx_allmulticast_disable(struct rte_eth_dev *dev)
885 : : {
886 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
887 : :
888 : 0 : PMD_INIT_FUNC_TRACE();
889 : 0 : return octeontx_port_mcast_set(nic, 0);
890 : : }
891 : :
892 : : static inline int octeontx_dev_total_xstat(void)
893 : : {
894 : : return NUM_BGX_XSTAT;
895 : : }
896 : :
897 : : static int
898 : 0 : octeontx_port_xstats(struct octeontx_nic *nic, struct rte_eth_xstat *xstats,
899 : : unsigned int n)
900 : : {
901 : : octeontx_mbox_bgx_port_stats_t bgx_stats;
902 : : int stat_cnt, res, si, i;
903 : :
904 : 0 : res = octeontx_bgx_port_xstats(nic->port_id, &bgx_stats);
905 [ # # ]: 0 : if (res < 0) {
906 : 0 : octeontx_log_err("failed to get port stats %d", nic->port_id);
907 : 0 : return res;
908 : : }
909 : :
910 : : si = 0;
911 : : /* Fill BGX stats */
912 : 0 : stat_cnt = (n > NUM_BGX_XSTAT) ? NUM_BGX_XSTAT : n;
913 : : n = n - stat_cnt;
914 [ # # ]: 0 : for (i = 0; i < stat_cnt; i++) {
915 : 0 : xstats[si].id = si;
916 : 0 : xstats[si].value = *(uint64_t *)(((char *)&bgx_stats) +
917 : 0 : octeontx_bgx_xstats[i].soffset);
918 : 0 : si++;
919 : : }
920 : : /*TODO: Similarly fill rest of HW stats */
921 : :
922 : : return si;
923 : : }
924 : :
925 : : static int
926 : 0 : octeontx_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
927 : : uint64_t *stat_val, unsigned int n)
928 : 0 : {
929 : : unsigned int i, xstat_cnt = octeontx_dev_total_xstat();
930 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
931 : 0 : struct rte_eth_xstat xstats[xstat_cnt];
932 : :
933 : 0 : octeontx_port_xstats(nic, xstats, xstat_cnt);
934 [ # # ]: 0 : for (i = 0; i < n; i++) {
935 [ # # ]: 0 : if (ids[i] >= xstat_cnt) {
936 : 0 : PMD_INIT_LOG(ERR, "out of range id value");
937 : 0 : return -1;
938 : : }
939 : 0 : stat_val[i] = xstats[ids[i]].value;
940 : : }
941 : 0 : return n;
942 : : }
943 : :
944 : : static int
945 : 0 : octeontx_dev_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
946 : : struct rte_eth_xstat_name *xstats_names,
947 : : unsigned int size)
948 : : {
949 : : int stat_cnt, si, i;
950 : :
951 [ # # ]: 0 : if (xstats_names) {
952 : : si = 0;
953 : : /* Fill BGX stats */
954 : 0 : stat_cnt = (size > NUM_BGX_XSTAT) ? NUM_BGX_XSTAT : size;
955 : : size = size - stat_cnt;
956 [ # # ]: 0 : for (i = 0; i < stat_cnt; i++) {
957 : 0 : strlcpy(xstats_names[si].name,
958 : : octeontx_bgx_xstats[i].sname,
959 : : sizeof(xstats_names[si].name));
960 : 0 : si++;
961 : : }
962 : : /*TODO: Similarly fill rest of HW stats */
963 : 0 : return si;
964 : : } else {
965 : : return octeontx_dev_total_xstat();
966 : : }
967 : : }
968 : :
969 : 0 : static void build_xstat_names(struct rte_eth_xstat_name *xstat_names)
970 : : {
971 : : unsigned int i;
972 : :
973 [ # # ]: 0 : for (i = 0; i < NUM_BGX_XSTAT; i++) {
974 : 0 : strlcpy(xstat_names[i].name, octeontx_bgx_xstats[i].sname,
975 : : RTE_ETH_XSTATS_NAME_SIZE);
976 : : }
977 : 0 : }
978 : :
979 : : static int
980 : 0 : octeontx_dev_xstats_get_names_by_id(struct rte_eth_dev *dev __rte_unused,
981 : : const uint64_t *ids,
982 : : struct rte_eth_xstat_name *stat_names,
983 : : unsigned int n)
984 : 0 : {
985 : : unsigned int i, xstat_cnt = octeontx_dev_total_xstat();
986 : 0 : struct rte_eth_xstat_name xstat_names[xstat_cnt];
987 : :
988 : 0 : build_xstat_names(xstat_names);
989 [ # # ]: 0 : for (i = 0; i < n; i++) {
990 [ # # ]: 0 : if (ids[i] >= xstat_cnt) {
991 : 0 : PMD_INIT_LOG(ERR, "out of range id value");
992 : 0 : return -1;
993 : : }
994 : 0 : strlcpy(stat_names[i].name, xstat_names[ids[i]].name,
995 : : sizeof(stat_names[i].name));
996 : : }
997 : : /*TODO: Similarly fill rest of HW stats */
998 : :
999 : 0 : return n;
1000 : : }
1001 : :
1002 : : static int
1003 : 0 : octeontx_dev_xstats_get(struct rte_eth_dev *dev,
1004 : : struct rte_eth_xstat *xstats,
1005 : : unsigned int n)
1006 : : {
1007 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1008 : :
1009 : 0 : PMD_INIT_FUNC_TRACE();
1010 : 0 : return octeontx_port_xstats(nic, xstats, n);
1011 : : }
1012 : :
1013 : : static int
1014 : 0 : octeontx_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
1015 : : struct eth_queue_stats *qstats __rte_unused)
1016 : : {
1017 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1018 : :
1019 : 0 : PMD_INIT_FUNC_TRACE();
1020 : 0 : return octeontx_port_stats(nic, stats);
1021 : : }
1022 : :
1023 : : static int
1024 : 0 : octeontx_dev_stats_reset(struct rte_eth_dev *dev)
1025 : : {
1026 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1027 : :
1028 : 0 : PMD_INIT_FUNC_TRACE();
1029 : 0 : return octeontx_port_stats_clr(nic);
1030 : : }
1031 : :
1032 : : static void
1033 : 0 : octeontx_dev_mac_addr_del(struct rte_eth_dev *dev, uint32_t index)
1034 : : {
1035 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1036 : : int ret;
1037 : :
1038 : 0 : ret = octeontx_bgx_port_mac_del(nic->port_id, index);
1039 [ # # ]: 0 : if (ret != 0)
1040 : 0 : octeontx_log_err("failed to del MAC address filter on port %d",
1041 : : nic->port_id);
1042 : 0 : }
1043 : :
1044 : : static int
1045 : 0 : octeontx_dev_mac_addr_add(struct rte_eth_dev *dev,
1046 : : struct rte_ether_addr *mac_addr,
1047 : : uint32_t index,
1048 : : __rte_unused uint32_t vmdq)
1049 : : {
1050 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1051 : : int ret;
1052 : :
1053 : 0 : ret = octeontx_bgx_port_mac_add(nic->port_id, mac_addr->addr_bytes,
1054 : : index);
1055 [ # # ]: 0 : if (ret < 0) {
1056 : 0 : octeontx_log_err("failed to add MAC address filter on port %d",
1057 : : nic->port_id);
1058 : 0 : return ret;
1059 : : }
1060 : :
1061 : : return 0;
1062 : : }
1063 : :
1064 : : static int
1065 : 0 : octeontx_dev_default_mac_addr_set(struct rte_eth_dev *dev,
1066 : : struct rte_ether_addr *addr)
1067 : : {
1068 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1069 : : int ret;
1070 : :
1071 : 0 : ret = octeontx_bgx_port_mac_set(nic->port_id, addr->addr_bytes);
1072 [ # # ]: 0 : if (ret == 0) {
1073 : : /* Update same mac address to BGX CAM table */
1074 : 0 : ret = octeontx_bgx_port_mac_add(nic->port_id, addr->addr_bytes,
1075 : : 0);
1076 : : }
1077 [ # # ]: 0 : if (ret < 0) {
1078 : 0 : octeontx_log_err("failed to set MAC address on port %d",
1079 : : nic->port_id);
1080 : : }
1081 : :
1082 : 0 : return ret;
1083 : : }
1084 : :
1085 : : static int
1086 : 0 : octeontx_dev_info(struct rte_eth_dev *dev,
1087 : : struct rte_eth_dev_info *dev_info)
1088 : : {
1089 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1090 : :
1091 : : /* Autonegotiation may be disabled */
1092 : : dev_info->speed_capa = RTE_ETH_LINK_SPEED_FIXED;
1093 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_10M | RTE_ETH_LINK_SPEED_100M |
1094 : : RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G |
1095 : : RTE_ETH_LINK_SPEED_40G;
1096 : :
1097 : : /* Min/Max MTU supported */
1098 : 0 : dev_info->min_rx_bufsize = OCCTX_MIN_FRS;
1099 : 0 : dev_info->max_rx_pktlen = OCCTX_MAX_FRS;
1100 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - OCCTX_L2_OVERHEAD;
1101 : 0 : dev_info->min_mtu = dev_info->min_rx_bufsize - OCCTX_L2_OVERHEAD;
1102 : :
1103 : 0 : dev_info->max_mac_addrs =
1104 : 0 : octeontx_bgx_port_mac_entries_get(nic->port_id);
1105 : 0 : dev_info->max_rx_queues = 1;
1106 : 0 : dev_info->max_tx_queues = PKO_MAX_NUM_DQ;
1107 : 0 : dev_info->min_rx_bufsize = 0;
1108 : :
1109 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
1110 : : .rx_free_thresh = 0,
1111 : : .rx_drop_en = 0,
1112 : : .offloads = OCTEONTX_RX_OFFLOADS,
1113 : : };
1114 : :
1115 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
1116 : : .tx_free_thresh = 0,
1117 : : .offloads = OCTEONTX_TX_OFFLOADS,
1118 : : };
1119 : :
1120 : 0 : dev_info->rx_offload_capa = OCTEONTX_RX_OFFLOADS;
1121 : 0 : dev_info->tx_offload_capa = OCTEONTX_TX_OFFLOADS;
1122 : 0 : dev_info->rx_queue_offload_capa = OCTEONTX_RX_OFFLOADS;
1123 : 0 : dev_info->tx_queue_offload_capa = OCTEONTX_TX_OFFLOADS;
1124 : :
1125 : 0 : return 0;
1126 : : }
1127 : :
1128 : : static void
1129 : 0 : octeontx_dq_info_getter(octeontx_dq_t *dq, void *out)
1130 : : {
1131 : 0 : ((octeontx_dq_t *)out)->lmtline_va = dq->lmtline_va;
1132 : 0 : ((octeontx_dq_t *)out)->ioreg_va = dq->ioreg_va;
1133 : 0 : ((octeontx_dq_t *)out)->fc_status_va = dq->fc_status_va;
1134 : 0 : }
1135 : :
1136 : : static int
1137 : 0 : octeontx_vf_start_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
1138 : : uint16_t qidx)
1139 : : {
1140 : : struct octeontx_txq *txq;
1141 : : int res;
1142 : :
1143 : 0 : PMD_INIT_FUNC_TRACE();
1144 : :
1145 [ # # ]: 0 : if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED)
1146 : : return 0;
1147 : :
1148 : 0 : txq = dev->data->tx_queues[qidx];
1149 : :
1150 : 0 : res = octeontx_pko_channel_query_dqs(nic->base_ochan,
1151 : 0 : &txq->dq,
1152 : : sizeof(octeontx_dq_t),
1153 : 0 : txq->queue_id,
1154 : : octeontx_dq_info_getter);
1155 [ # # ]: 0 : if (res < 0) {
1156 : : res = -EFAULT;
1157 : 0 : goto close_port;
1158 : : }
1159 : :
1160 : 0 : dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
1161 : 0 : return res;
1162 : :
1163 : : close_port:
1164 : 0 : (void)octeontx_port_stop(nic);
1165 : 0 : octeontx_pko_channel_stop(nic->base_ochan);
1166 : 0 : octeontx_pko_channel_close(nic->base_ochan);
1167 : 0 : dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1168 : 0 : return res;
1169 : : }
1170 : :
1171 : : int
1172 : 0 : octeontx_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
1173 : : {
1174 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1175 : :
1176 : 0 : PMD_INIT_FUNC_TRACE();
1177 : 0 : qidx = qidx % PKO_VF_NUM_DQ;
1178 : 0 : return octeontx_vf_start_tx_queue(dev, nic, qidx);
1179 : : }
1180 : :
1181 : : static inline int
1182 : 0 : octeontx_vf_stop_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
1183 : : uint16_t qidx)
1184 : : {
1185 : : int ret = 0;
1186 : :
1187 : : RTE_SET_USED(nic);
1188 : 0 : PMD_INIT_FUNC_TRACE();
1189 : :
1190 [ # # ]: 0 : if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED)
1191 : : return 0;
1192 : :
1193 : 0 : dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1194 : 0 : return ret;
1195 : : }
1196 : :
1197 : : int
1198 : 0 : octeontx_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
1199 : : {
1200 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1201 : :
1202 : 0 : PMD_INIT_FUNC_TRACE();
1203 : 0 : qidx = qidx % PKO_VF_NUM_DQ;
1204 : :
1205 : 0 : return octeontx_vf_stop_tx_queue(dev, nic, qidx);
1206 : : }
1207 : :
1208 : : static void
1209 : 0 : octeontx_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1210 : : {
1211 : : int res;
1212 : :
1213 : 0 : PMD_INIT_FUNC_TRACE();
1214 : :
1215 [ # # ]: 0 : if (dev->data->tx_queues[qid]) {
1216 : 0 : res = octeontx_dev_tx_queue_stop(dev, qid);
1217 [ # # ]: 0 : if (res < 0)
1218 : 0 : octeontx_log_err("failed stop tx_queue(%d)", qid);
1219 : :
1220 : 0 : rte_free(dev->data->tx_queues[qid]);
1221 : : }
1222 : 0 : }
1223 : :
1224 : : static int
1225 [ # # ]: 0 : octeontx_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
1226 : : uint16_t nb_desc, unsigned int socket_id,
1227 : : const struct rte_eth_txconf *tx_conf __rte_unused)
1228 : : {
1229 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1230 : : struct octeontx_txq *txq = NULL;
1231 : : uint16_t dq_num;
1232 : : int res = 0;
1233 : :
1234 : : RTE_SET_USED(nb_desc);
1235 : : RTE_SET_USED(socket_id);
1236 : :
1237 : 0 : dq_num = (nic->pko_vfid * PKO_VF_NUM_DQ) + qidx;
1238 : :
1239 : : /* Socket id check */
1240 [ # # ]: 0 : if (socket_id != (unsigned int)SOCKET_ID_ANY &&
1241 [ # # ]: 0 : socket_id != (unsigned int)nic->node)
1242 : 0 : PMD_TX_LOG(INFO, "socket_id expected %d, configured %d",
1243 : : socket_id, nic->node);
1244 : :
1245 : : /* Free memory prior to re-allocation if needed. */
1246 [ # # ]: 0 : if (dev->data->tx_queues[qidx] != NULL) {
1247 : 0 : PMD_TX_LOG(DEBUG, "freeing memory prior to re-allocation %d",
1248 : : qidx);
1249 : 0 : octeontx_dev_tx_queue_release(dev, qidx);
1250 : 0 : dev->data->tx_queues[qidx] = NULL;
1251 : : }
1252 : :
1253 : : /* Allocating tx queue data structure */
1254 : 0 : txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct octeontx_txq),
1255 : : RTE_CACHE_LINE_SIZE, nic->node);
1256 [ # # ]: 0 : if (txq == NULL) {
1257 : 0 : octeontx_log_err("failed to allocate txq=%d", qidx);
1258 : : res = -ENOMEM;
1259 : 0 : goto err;
1260 : : }
1261 : :
1262 : 0 : txq->eth_dev = dev;
1263 : 0 : txq->queue_id = dq_num;
1264 : 0 : dev->data->tx_queues[qidx] = txq;
1265 : 0 : dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1266 : :
1267 : 0 : res = octeontx_pko_channel_query_dqs(nic->base_ochan,
1268 : 0 : &txq->dq,
1269 : : sizeof(octeontx_dq_t),
1270 : : txq->queue_id,
1271 : : octeontx_dq_info_getter);
1272 [ # # ]: 0 : if (res < 0) {
1273 : : res = -EFAULT;
1274 : 0 : goto err;
1275 : : }
1276 : :
1277 : 0 : PMD_TX_LOG(DEBUG, "[%d]:[%d] txq=%p nb_desc=%d lmtline=%p ioreg_va=%p fc_status_va=%p",
1278 : : qidx, txq->queue_id, txq, nb_desc, txq->dq.lmtline_va,
1279 : : txq->dq.ioreg_va,
1280 : : txq->dq.fc_status_va);
1281 : :
1282 : 0 : return res;
1283 : :
1284 : 0 : err:
1285 : 0 : rte_free(txq);
1286 : :
1287 : 0 : return res;
1288 : : }
1289 : :
1290 : : static int
1291 [ # # ]: 0 : octeontx_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
1292 : : uint16_t nb_desc, unsigned int socket_id,
1293 : : const struct rte_eth_rxconf *rx_conf,
1294 : : struct rte_mempool *mb_pool)
1295 : : {
1296 : : struct octeontx_nic *nic = octeontx_pmd_priv(dev);
1297 : : struct rte_mempool_ops *mp_ops = NULL;
1298 : : struct octeontx_rxq *rxq = NULL;
1299 : : pki_pktbuf_cfg_t pktbuf_conf;
1300 : : pki_hash_cfg_t pki_hash;
1301 : : pki_qos_cfg_t pki_qos;
1302 : : uintptr_t pool;
1303 : : int ret, port;
1304 : : uint16_t gaura;
1305 : 0 : unsigned int ev_queues = (nic->ev_queues * nic->port_id) + qidx;
1306 [ # # ]: 0 : unsigned int ev_ports = (nic->ev_ports * nic->port_id) + qidx;
1307 : :
1308 : : RTE_SET_USED(nb_desc);
1309 : :
1310 : : memset(&pktbuf_conf, 0, sizeof(pktbuf_conf));
1311 : : memset(&pki_hash, 0, sizeof(pki_hash));
1312 : : memset(&pki_qos, 0, sizeof(pki_qos));
1313 : :
1314 : 0 : mp_ops = rte_mempool_get_ops(mb_pool->ops_index);
1315 [ # # ]: 0 : if (strcmp(mp_ops->name, "octeontx_fpavf")) {
1316 : 0 : octeontx_log_err("failed to find octeontx_fpavf mempool");
1317 : 0 : return -ENOTSUP;
1318 : : }
1319 : :
1320 : : /* Handle forbidden configurations */
1321 [ # # ]: 0 : if (nic->pki.classifier_enable) {
1322 : 0 : octeontx_log_err("cannot setup queue %d. "
1323 : : "Classifier option unsupported", qidx);
1324 : 0 : return -EINVAL;
1325 : : }
1326 : :
1327 : 0 : port = nic->port_id;
1328 : :
1329 : : /* Rx deferred start is not supported */
1330 [ # # ]: 0 : if (rx_conf->rx_deferred_start) {
1331 : 0 : octeontx_log_err("rx deferred start not supported");
1332 : 0 : return -EINVAL;
1333 : : }
1334 : :
1335 : : /* Verify queue index */
1336 [ # # ]: 0 : if (qidx >= dev->data->nb_rx_queues) {
1337 : 0 : octeontx_log_err("QID %d not supported (0 - %d available)",
1338 : : qidx, (dev->data->nb_rx_queues - 1));
1339 : 0 : return -ENOTSUP;
1340 : : }
1341 : :
1342 : : /* Socket id check */
1343 [ # # ]: 0 : if (socket_id != (unsigned int)SOCKET_ID_ANY &&
1344 [ # # ]: 0 : socket_id != (unsigned int)nic->node)
1345 : 0 : PMD_RX_LOG(INFO, "socket_id expected %d, configured %d",
1346 : : socket_id, nic->node);
1347 : :
1348 : : /* Allocating rx queue data structure */
1349 : 0 : rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct octeontx_rxq),
1350 : : RTE_CACHE_LINE_SIZE, nic->node);
1351 [ # # ]: 0 : if (rxq == NULL) {
1352 : 0 : octeontx_log_err("failed to allocate rxq=%d", qidx);
1353 : 0 : return -ENOMEM;
1354 : : }
1355 : :
1356 [ # # ]: 0 : if (!nic->pki.initialized) {
1357 : 0 : pktbuf_conf.port_type = 0;
1358 : 0 : pki_hash.port_type = 0;
1359 : 0 : pki_qos.port_type = 0;
1360 : :
1361 : 0 : pktbuf_conf.mmask.f_wqe_skip = 1;
1362 : 0 : pktbuf_conf.mmask.f_first_skip = 1;
1363 : 0 : pktbuf_conf.mmask.f_later_skip = 1;
1364 : 0 : pktbuf_conf.mmask.f_mbuff_size = 1;
1365 : 0 : pktbuf_conf.mmask.f_cache_mode = 1;
1366 : :
1367 : 0 : pktbuf_conf.wqe_skip = OCTTX_PACKET_WQE_SKIP;
1368 : 0 : pktbuf_conf.first_skip = OCTTX_PACKET_FIRST_SKIP(mb_pool);
1369 : 0 : pktbuf_conf.later_skip = OCTTX_PACKET_LATER_SKIP;
1370 : 0 : pktbuf_conf.mbuff_size = (mb_pool->elt_size -
1371 : 0 : RTE_PKTMBUF_HEADROOM -
1372 : 0 : rte_pktmbuf_priv_size(mb_pool) -
1373 : : sizeof(struct rte_mbuf));
1374 : :
1375 : 0 : pktbuf_conf.cache_mode = PKI_OPC_MODE_STF2_STT;
1376 : :
1377 : 0 : ret = octeontx_pki_port_pktbuf_config(port, &pktbuf_conf);
1378 [ # # ]: 0 : if (ret != 0) {
1379 : 0 : octeontx_log_err("fail to configure pktbuf for port %d",
1380 : : port);
1381 : 0 : rte_free(rxq);
1382 : 0 : return ret;
1383 : : }
1384 : 0 : PMD_RX_LOG(DEBUG, "Port %d Rx pktbuf configured:",
1385 : : port);
1386 : 0 : PMD_RX_LOG(DEBUG, "\tmbuf_size:\t0x%0x",
1387 : : pktbuf_conf.mbuff_size);
1388 : 0 : PMD_RX_LOG(DEBUG, "\twqe_skip:\t0x%0x",
1389 : : pktbuf_conf.wqe_skip);
1390 : 0 : PMD_RX_LOG(DEBUG, "\tfirst_skip:\t0x%0x",
1391 : : pktbuf_conf.first_skip);
1392 : 0 : PMD_RX_LOG(DEBUG, "\tlater_skip:\t0x%0x",
1393 : : pktbuf_conf.later_skip);
1394 [ # # # # : 0 : PMD_RX_LOG(DEBUG, "\tcache_mode:\t%s",
# # ]
1395 : : (pktbuf_conf.cache_mode ==
1396 : : PKI_OPC_MODE_STT) ?
1397 : : "STT" :
1398 : : (pktbuf_conf.cache_mode ==
1399 : : PKI_OPC_MODE_STF) ?
1400 : : "STF" :
1401 : : (pktbuf_conf.cache_mode ==
1402 : : PKI_OPC_MODE_STF1_STT) ?
1403 : : "STF1_STT" : "STF2_STT");
1404 : :
1405 [ # # ]: 0 : if (nic->pki.hash_enable) {
1406 : 0 : pki_hash.tag_dlc = 1;
1407 : 0 : pki_hash.tag_slc = 1;
1408 : 0 : pki_hash.tag_dlf = 1;
1409 : 0 : pki_hash.tag_slf = 1;
1410 : 0 : pki_hash.tag_prt = 1;
1411 : 0 : octeontx_pki_port_hash_config(port, &pki_hash);
1412 : : }
1413 : :
1414 : 0 : pool = (uintptr_t)mb_pool->pool_id;
1415 : :
1416 : : /* Get the gaura Id */
1417 : : gaura = octeontx_fpa_bufpool_gaura(pool);
1418 : :
1419 : 0 : pki_qos.qpg_qos = PKI_QPG_QOS_NONE;
1420 : 0 : pki_qos.num_entry = 1;
1421 : 0 : pki_qos.drop_policy = 0;
1422 : 0 : pki_qos.tag_type = 0L;
1423 : 0 : pki_qos.qos_entry[0].port_add = 0;
1424 : 0 : pki_qos.qos_entry[0].gaura = gaura;
1425 : 0 : pki_qos.qos_entry[0].ggrp_ok = ev_queues;
1426 : 0 : pki_qos.qos_entry[0].ggrp_bad = ev_queues;
1427 : 0 : pki_qos.qos_entry[0].grptag_bad = 0;
1428 : 0 : pki_qos.qos_entry[0].grptag_ok = 0;
1429 : :
1430 : 0 : ret = octeontx_pki_port_create_qos(port, &pki_qos);
1431 [ # # ]: 0 : if (ret < 0) {
1432 : 0 : octeontx_log_err("failed to create QOS port=%d, q=%d",
1433 : : port, qidx);
1434 : 0 : rte_free(rxq);
1435 : 0 : return ret;
1436 : : }
1437 : 0 : nic->pki.initialized = true;
1438 : : }
1439 : :
1440 : 0 : rxq->port_id = nic->port_id;
1441 : 0 : rxq->eth_dev = dev;
1442 : 0 : rxq->queue_id = qidx;
1443 : 0 : rxq->evdev = nic->evdev;
1444 : 0 : rxq->ev_queues = ev_queues;
1445 : 0 : rxq->ev_ports = ev_ports;
1446 : 0 : rxq->pool = mb_pool;
1447 : :
1448 : 0 : octeontx_recheck_rx_offloads(rxq);
1449 : 0 : dev->data->rx_queues[qidx] = rxq;
1450 : 0 : dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1451 : :
1452 : 0 : return 0;
1453 : : }
1454 : :
1455 : : static void
1456 : 0 : octeontx_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1457 : : {
1458 : 0 : rte_free(dev->data->rx_queues[qid]);
1459 : 0 : }
1460 : :
1461 : : static const uint32_t *
1462 : 0 : octeontx_dev_supported_ptypes_get(struct rte_eth_dev *dev,
1463 : : size_t *no_of_elements)
1464 : : {
1465 : : static const uint32_t ptypes[] = {
1466 : : RTE_PTYPE_L3_IPV4,
1467 : : RTE_PTYPE_L3_IPV4_EXT,
1468 : : RTE_PTYPE_L3_IPV6,
1469 : : RTE_PTYPE_L3_IPV6_EXT,
1470 : : RTE_PTYPE_L4_TCP,
1471 : : RTE_PTYPE_L4_UDP,
1472 : : RTE_PTYPE_L4_FRAG,
1473 : : };
1474 : :
1475 [ # # ]: 0 : if (dev->rx_pkt_burst == octeontx_recv_pkts) {
1476 : 0 : *no_of_elements = RTE_DIM(ptypes);
1477 : 0 : return ptypes;
1478 : : }
1479 : : return NULL;
1480 : : }
1481 : :
1482 : : static int
1483 : 0 : octeontx_pool_ops(struct rte_eth_dev *dev, const char *pool)
1484 : : {
1485 : : RTE_SET_USED(dev);
1486 : :
1487 [ # # ]: 0 : if (!strcmp(pool, "octeontx_fpavf"))
1488 : 0 : return 0;
1489 : :
1490 : : return -ENOTSUP;
1491 : : }
1492 : :
1493 : : /* Initialize and register driver with DPDK Application */
1494 : : static const struct eth_dev_ops octeontx_dev_ops = {
1495 : : .dev_configure = octeontx_dev_configure,
1496 : : .dev_infos_get = octeontx_dev_info,
1497 : : .dev_close = octeontx_dev_close,
1498 : : .dev_start = octeontx_dev_start,
1499 : : .dev_stop = octeontx_dev_stop,
1500 : : .promiscuous_enable = octeontx_dev_promisc_enable,
1501 : : .promiscuous_disable = octeontx_dev_promisc_disable,
1502 : : .link_update = octeontx_dev_link_update,
1503 : : .stats_get = octeontx_dev_stats_get,
1504 : : .stats_reset = octeontx_dev_stats_reset,
1505 : : .mac_addr_remove = octeontx_dev_mac_addr_del,
1506 : : .mac_addr_add = octeontx_dev_mac_addr_add,
1507 : : .mac_addr_set = octeontx_dev_default_mac_addr_set,
1508 : : .vlan_offload_set = octeontx_dev_vlan_offload_set,
1509 : : .vlan_filter_set = octeontx_dev_vlan_filter_set,
1510 : : .tx_queue_start = octeontx_dev_tx_queue_start,
1511 : : .tx_queue_stop = octeontx_dev_tx_queue_stop,
1512 : : .tx_queue_setup = octeontx_dev_tx_queue_setup,
1513 : : .tx_queue_release = octeontx_dev_tx_queue_release,
1514 : : .rx_queue_setup = octeontx_dev_rx_queue_setup,
1515 : : .rx_queue_release = octeontx_dev_rx_queue_release,
1516 : : .dev_set_link_up = octeontx_dev_set_link_up,
1517 : : .dev_set_link_down = octeontx_dev_set_link_down,
1518 : : .dev_supported_ptypes_get = octeontx_dev_supported_ptypes_get,
1519 : : .mtu_set = octeontx_dev_mtu_set,
1520 : : .pool_ops_supported = octeontx_pool_ops,
1521 : : .flow_ctrl_get = octeontx_dev_flow_ctrl_get,
1522 : : .flow_ctrl_set = octeontx_dev_flow_ctrl_set,
1523 : : .xstats_get = octeontx_dev_xstats_get,
1524 : : .xstats_get_by_id = octeontx_dev_xstats_get_by_id,
1525 : : .xstats_get_names = octeontx_dev_xstats_get_names,
1526 : : .xstats_get_names_by_id = octeontx_dev_xstats_get_names_by_id,
1527 : : .allmulticast_enable = octeontx_allmulticast_enable,
1528 : : .allmulticast_disable = octeontx_allmulticast_disable,
1529 : : };
1530 : :
1531 : : /* Create Ethdev interface per BGX LMAC ports */
1532 : : static int
1533 [ # # ]: 0 : octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
1534 : : int socket_id)
1535 : : {
1536 : : int res;
1537 : : size_t pko_vfid;
1538 : : char octtx_name[OCTEONTX_MAX_NAME_LEN];
1539 : : struct octeontx_nic *nic = NULL;
1540 : : struct rte_eth_dev *eth_dev = NULL;
1541 : : struct rte_eth_dev_data *data;
1542 : : const char *name = rte_vdev_device_name(dev);
1543 : : int max_entries;
1544 : :
1545 : 0 : PMD_INIT_FUNC_TRACE();
1546 : :
1547 : : snprintf(octtx_name, sizeof(octtx_name), "%s_%d", name, port);
1548 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1549 : 0 : eth_dev = rte_eth_dev_attach_secondary(octtx_name);
1550 [ # # ]: 0 : if (eth_dev == NULL)
1551 : : return -ENODEV;
1552 : :
1553 : 0 : eth_dev->dev_ops = &octeontx_dev_ops;
1554 : 0 : eth_dev->device = &dev->device;
1555 : 0 : octeontx_set_tx_function(eth_dev);
1556 : 0 : eth_dev->rx_pkt_burst = octeontx_recv_pkts;
1557 : 0 : rte_eth_dev_probing_finish(eth_dev);
1558 : 0 : return 0;
1559 : : }
1560 : :
1561 : : /* Reserve an ethdev entry */
1562 : 0 : eth_dev = rte_eth_dev_allocate(octtx_name);
1563 [ # # ]: 0 : if (eth_dev == NULL) {
1564 : 0 : octeontx_log_err("failed to allocate rte_eth_dev");
1565 : : res = -ENOMEM;
1566 : 0 : goto err;
1567 : : }
1568 : 0 : data = eth_dev->data;
1569 : :
1570 : 0 : nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id);
1571 [ # # ]: 0 : if (nic == NULL) {
1572 : 0 : octeontx_log_err("failed to allocate nic structure");
1573 : : res = -ENOMEM;
1574 : 0 : goto err;
1575 : : }
1576 : 0 : data->dev_private = nic;
1577 : 0 : pko_vfid = octeontx_pko_get_vfid();
1578 : :
1579 [ # # ]: 0 : if (pko_vfid == SIZE_MAX) {
1580 : 0 : octeontx_log_err("failed to get pko vfid");
1581 : : res = -ENODEV;
1582 : 0 : goto err;
1583 : : }
1584 : :
1585 : 0 : nic->pko_vfid = pko_vfid;
1586 : 0 : nic->port_id = port;
1587 : 0 : nic->evdev = evdev;
1588 : 0 : rte_atomic_fetch_add_explicit(&evdev_refcnt, 1, rte_memory_order_acquire);
1589 : :
1590 : 0 : res = octeontx_port_open(nic);
1591 [ # # ]: 0 : if (res < 0)
1592 : 0 : goto err;
1593 : :
1594 : : /* Rx side port configuration */
1595 : 0 : res = octeontx_pki_port_open(port);
1596 [ # # ]: 0 : if (res != 0) {
1597 : 0 : octeontx_log_err("failed to open PKI port %d", port);
1598 : : res = -ENODEV;
1599 : 0 : goto err;
1600 : : }
1601 : :
1602 : 0 : eth_dev->device = &dev->device;
1603 : 0 : eth_dev->intr_handle = NULL;
1604 : 0 : eth_dev->data->numa_node = dev->device.numa_node;
1605 : :
1606 : 0 : data->port_id = eth_dev->data->port_id;
1607 : :
1608 : 0 : nic->ev_queues = 1;
1609 : 0 : nic->ev_ports = 1;
1610 : 0 : nic->print_flag = -1;
1611 : 0 : nic->reconfigure = false;
1612 : :
1613 : 0 : data->dev_link.link_status = RTE_ETH_LINK_DOWN;
1614 : 0 : data->dev_started = 0;
1615 : 0 : data->promiscuous = 0;
1616 : 0 : data->all_multicast = 0;
1617 : 0 : data->scattered_rx = 0;
1618 : :
1619 : : /* Get maximum number of supported MAC entries */
1620 : 0 : max_entries = octeontx_bgx_port_mac_entries_get(nic->port_id);
1621 [ # # ]: 0 : if (max_entries < 0) {
1622 : 0 : octeontx_log_err("Failed to get max entries for mac addr");
1623 : : res = -ENOTSUP;
1624 : 0 : goto err;
1625 : : }
1626 : :
1627 : 0 : data->mac_addrs = rte_zmalloc_socket(octtx_name, max_entries *
1628 : : RTE_ETHER_ADDR_LEN, 0,
1629 : : socket_id);
1630 [ # # ]: 0 : if (data->mac_addrs == NULL) {
1631 : 0 : octeontx_log_err("failed to allocate memory for mac_addrs");
1632 : : res = -ENOMEM;
1633 : 0 : goto err;
1634 : : }
1635 : :
1636 : 0 : eth_dev->dev_ops = &octeontx_dev_ops;
1637 : :
1638 : : /* Finally save ethdev pointer to the NIC structure */
1639 : 0 : nic->dev = eth_dev;
1640 : :
1641 [ # # ]: 0 : if (nic->port_id != data->port_id) {
1642 : 0 : octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
1643 : : data->port_id, nic->port_id);
1644 : : res = -EINVAL;
1645 : 0 : goto free_mac_addrs;
1646 : : }
1647 : :
1648 : 0 : res = rte_eal_alarm_set(OCCTX_INTR_POLL_INTERVAL_MS * 1000,
1649 : : octeontx_link_status_poll, nic);
1650 [ # # ]: 0 : if (res) {
1651 : 0 : octeontx_log_err("Failed to start link polling alarm");
1652 : 0 : goto err;
1653 : : }
1654 : :
1655 : : /* Update port_id mac to eth_dev */
1656 : 0 : memcpy(data->mac_addrs, nic->mac_addr, RTE_ETHER_ADDR_LEN);
1657 : :
1658 : : /* Update same mac address to BGX CAM table at index 0 */
1659 : 0 : octeontx_bgx_port_mac_add(nic->port_id, nic->mac_addr, 0);
1660 : :
1661 : 0 : res = octeontx_dev_flow_ctrl_init(eth_dev);
1662 [ # # ]: 0 : if (res < 0)
1663 : 0 : goto err;
1664 : :
1665 : 0 : PMD_INIT_LOG(DEBUG, "ethdev info: ");
1666 : 0 : PMD_INIT_LOG(DEBUG, "port %d, port_ena %d ochan %d num_ochan %d tx_q %d",
1667 : : nic->port_id, nic->port_ena,
1668 : : nic->base_ochan, nic->num_ochans,
1669 : : nic->num_tx_queues);
1670 : 0 : PMD_INIT_LOG(DEBUG, "speed %d mtu %d", nic->speed, nic->bgx_mtu);
1671 : :
1672 : 0 : rte_octeontx_pchan_map[(nic->base_ochan >> 8) & 0x7]
1673 : 0 : [(nic->base_ochan >> 4) & 0xF] = data->port_id;
1674 : :
1675 : 0 : rte_eth_dev_probing_finish(eth_dev);
1676 : 0 : return data->port_id;
1677 : :
1678 : : free_mac_addrs:
1679 : 0 : rte_free(data->mac_addrs);
1680 : 0 : data->mac_addrs = NULL;
1681 : 0 : err:
1682 [ # # ]: 0 : if (nic)
1683 : 0 : octeontx_port_close(nic);
1684 : :
1685 : 0 : rte_eth_dev_release_port(eth_dev);
1686 : :
1687 : 0 : return res;
1688 : : }
1689 : :
1690 : : /* Un initialize octeontx device */
1691 : : static int
1692 : 0 : octeontx_remove(struct rte_vdev_device *dev)
1693 : : {
1694 : : char octtx_name[OCTEONTX_MAX_NAME_LEN];
1695 : : struct rte_eth_dev *eth_dev = NULL;
1696 : : struct octeontx_nic *nic = NULL;
1697 : : int i;
1698 : :
1699 [ # # ]: 0 : if (dev == NULL)
1700 : : return -EINVAL;
1701 : :
1702 [ # # ]: 0 : for (i = 0; i < OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT; i++) {
1703 : : snprintf(octtx_name, sizeof(octtx_name), "eth_octeontx_%d", i);
1704 : :
1705 : 0 : eth_dev = rte_eth_dev_allocated(octtx_name);
1706 [ # # ]: 0 : if (eth_dev == NULL)
1707 : 0 : continue; /* port already released */
1708 : :
1709 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1710 : 0 : rte_eth_dev_release_port(eth_dev);
1711 : 0 : continue;
1712 : : }
1713 : :
1714 : : nic = octeontx_pmd_priv(eth_dev);
1715 : 0 : rte_event_dev_stop(nic->evdev);
1716 : 0 : PMD_INIT_LOG(INFO, "Closing octeontx device %s", octtx_name);
1717 : 0 : octeontx_dev_close(eth_dev);
1718 : 0 : rte_eth_dev_release_port(eth_dev);
1719 : : }
1720 : :
1721 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1722 : : return 0;
1723 : :
1724 : : /* Free FC resource */
1725 : 0 : octeontx_pko_fc_free();
1726 : :
1727 : 0 : return 0;
1728 : : }
1729 : :
1730 : : /* Initialize octeontx device */
1731 : : static int
1732 : 0 : octeontx_probe(struct rte_vdev_device *dev)
1733 : : {
1734 : : const char *dev_name;
1735 : : static int probe_once;
1736 : : uint8_t socket_id, qlist;
1737 : : int tx_vfcnt, port_id, evdev, qnum, pnum, res, i;
1738 : : struct rte_event_dev_config dev_conf;
1739 : : const char *eventdev_name = "event_octeontx";
1740 : : struct rte_event_dev_info info;
1741 : : struct rte_eth_dev *eth_dev;
1742 : :
1743 [ # # ]: 0 : struct octeontx_vdev_init_params init_params = {
1744 : : OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT
1745 : : };
1746 : :
1747 : : dev_name = rte_vdev_device_name(dev);
1748 : :
1749 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
1750 [ # # ]: 0 : strlen(rte_vdev_device_args(dev)) == 0) {
1751 : 0 : eth_dev = rte_eth_dev_attach_secondary(dev_name);
1752 [ # # ]: 0 : if (!eth_dev) {
1753 : 0 : PMD_INIT_LOG(ERR, "Failed to probe %s", dev_name);
1754 : 0 : return -1;
1755 : : }
1756 : : /* TODO: request info from primary to set up Rx and Tx */
1757 : 0 : eth_dev->dev_ops = &octeontx_dev_ops;
1758 : 0 : eth_dev->device = &dev->device;
1759 : 0 : rte_eth_dev_probing_finish(eth_dev);
1760 : 0 : return 0;
1761 : : }
1762 : :
1763 : 0 : res = octeontx_parse_vdev_init_params(&init_params, dev);
1764 [ # # ]: 0 : if (res < 0)
1765 : : return -EINVAL;
1766 : :
1767 [ # # ]: 0 : if (init_params.nr_port > OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT) {
1768 : 0 : octeontx_log_err("nr_port (%d) > max (%d)", init_params.nr_port,
1769 : : OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT);
1770 : 0 : return -ENOTSUP;
1771 : : }
1772 : :
1773 : 0 : PMD_INIT_LOG(DEBUG, "initializing %s pmd", dev_name);
1774 : :
1775 : 0 : socket_id = rte_socket_id();
1776 : :
1777 : 0 : tx_vfcnt = octeontx_pko_vf_count();
1778 : :
1779 [ # # ]: 0 : if (tx_vfcnt < init_params.nr_port) {
1780 : 0 : octeontx_log_err("not enough PKO (%d) for port number (%d)",
1781 : : tx_vfcnt, init_params.nr_port);
1782 : 0 : return -EINVAL;
1783 : : }
1784 : 0 : evdev = rte_event_dev_get_dev_id(eventdev_name);
1785 [ # # ]: 0 : if (evdev < 0) {
1786 : 0 : octeontx_log_err("eventdev %s not found", eventdev_name);
1787 : 0 : return -ENODEV;
1788 : : }
1789 : :
1790 : 0 : res = rte_event_dev_info_get(evdev, &info);
1791 [ # # ]: 0 : if (res < 0) {
1792 : 0 : octeontx_log_err("failed to eventdev info %d", res);
1793 : 0 : return -EINVAL;
1794 : : }
1795 : :
1796 : 0 : PMD_INIT_LOG(DEBUG, "max_queue %d max_port %d",
1797 : : info.max_event_queues, info.max_event_ports);
1798 : :
1799 [ # # ]: 0 : if (octeontx_pko_init_fc(tx_vfcnt))
1800 : : return -ENOMEM;
1801 : :
1802 : 0 : devconf_set_default_sane_values(&dev_conf, &info);
1803 : 0 : res = rte_event_dev_configure(evdev, &dev_conf);
1804 [ # # ]: 0 : if (res < 0)
1805 : 0 : goto parse_error;
1806 : :
1807 : 0 : rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_PORT_COUNT,
1808 : : (uint32_t *)&pnum);
1809 : 0 : rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_QUEUE_COUNT,
1810 : : (uint32_t *)&qnum);
1811 [ # # ]: 0 : if (pnum < qnum) {
1812 : 0 : octeontx_log_err("too few event ports (%d) for event_q(%d)",
1813 : : pnum, qnum);
1814 : : res = -EINVAL;
1815 : 0 : goto parse_error;
1816 : : }
1817 : :
1818 : : /* Enable all queues available */
1819 [ # # ]: 0 : for (i = 0; i < qnum; i++) {
1820 : 0 : res = rte_event_queue_setup(evdev, i, NULL);
1821 [ # # ]: 0 : if (res < 0) {
1822 : 0 : octeontx_log_err("failed to setup event_q(%d): res %d",
1823 : : i, res);
1824 : 0 : goto parse_error;
1825 : : }
1826 : : }
1827 : :
1828 : : /* Enable all ports available */
1829 [ # # ]: 0 : for (i = 0; i < pnum; i++) {
1830 : 0 : res = rte_event_port_setup(evdev, i, NULL);
1831 [ # # ]: 0 : if (res < 0) {
1832 : : res = -ENODEV;
1833 : 0 : octeontx_log_err("failed to setup ev port(%d) res=%d",
1834 : : i, res);
1835 : 0 : goto parse_error;
1836 : : }
1837 : : }
1838 : :
1839 : 0 : rte_atomic_store_explicit(&evdev_refcnt, 0, rte_memory_order_release);
1840 : : /*
1841 : : * Do 1:1 links for ports & queues. All queues would be mapped to
1842 : : * one port. If there are more ports than queues, then some ports
1843 : : * won't be linked to any queue.
1844 : : */
1845 [ # # ]: 0 : for (i = 0; i < qnum; i++) {
1846 : : /* Link one queue to one event port */
1847 : 0 : qlist = i;
1848 : 0 : res = rte_event_port_link(evdev, i, &qlist, NULL, 1);
1849 [ # # ]: 0 : if (res < 0) {
1850 : : res = -ENODEV;
1851 : 0 : octeontx_log_err("failed to link port (%d): res=%d",
1852 : : i, res);
1853 : 0 : goto parse_error;
1854 : : }
1855 : : }
1856 : :
1857 : : /* Create ethdev interface */
1858 [ # # ]: 0 : for (i = 0; i < init_params.nr_port; i++) {
1859 : 0 : port_id = octeontx_create(dev, i, evdev, socket_id);
1860 [ # # ]: 0 : if (port_id < 0) {
1861 : 0 : octeontx_log_err("failed to create device %s",
1862 : : dev_name);
1863 : : res = -ENODEV;
1864 : 0 : goto parse_error;
1865 : : }
1866 : :
1867 : 0 : PMD_INIT_LOG(INFO, "created ethdev %s for port %d", dev_name,
1868 : : port_id);
1869 : : }
1870 : :
1871 [ # # ]: 0 : if (probe_once) {
1872 : 0 : octeontx_log_err("interface %s not supported", dev_name);
1873 : 0 : octeontx_remove(dev);
1874 : : res = -ENOTSUP;
1875 : 0 : goto parse_error;
1876 : : }
1877 : 0 : rte_mbuf_set_platform_mempool_ops("octeontx_fpavf");
1878 : 0 : probe_once = 1;
1879 : :
1880 : 0 : return 0;
1881 : :
1882 : 0 : parse_error:
1883 : 0 : octeontx_pko_fc_free();
1884 : 0 : return res;
1885 : : }
1886 : :
1887 : : static struct rte_vdev_driver octeontx_pmd_drv = {
1888 : : .driver.alias = "eth_octeontx",
1889 : : .probe = octeontx_probe,
1890 : : .remove = octeontx_remove,
1891 : : };
1892 : :
1893 : 306 : RTE_PMD_REGISTER_VDEV(OCTEONTX_PMD, octeontx_pmd_drv);
1894 : : RTE_PMD_REGISTER_PARAM_STRING(OCTEONTX_PMD, "nr_port=<int> ");
|