1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2015-2018 Atomic Rules LLC
9 #include <rte_bus_pci.h>
10 #include <ethdev_pci.h>
11 #include <rte_kvargs.h>
13 #include "ark_global.h"
15 #include "ark_ethdev_tx.h"
16 #include "ark_ethdev_rx.h"
21 #include "ark_pktdir.h"
22 #include "ark_pktgen.h"
23 #include "ark_pktchkr.h"
25 /* Internal prototypes */
26 static int eth_ark_check_args(struct ark_adapter *ark, const char *params);
27 static int eth_ark_dev_init(struct rte_eth_dev *dev);
28 static int ark_config_device(struct rte_eth_dev *dev);
29 static int eth_ark_dev_uninit(struct rte_eth_dev *eth_dev);
30 static int eth_ark_dev_configure(struct rte_eth_dev *dev);
31 static int eth_ark_dev_start(struct rte_eth_dev *dev);
32 static int eth_ark_dev_stop(struct rte_eth_dev *dev);
33 static int eth_ark_dev_close(struct rte_eth_dev *dev);
34 static int eth_ark_dev_info_get(struct rte_eth_dev *dev,
35 struct rte_eth_dev_info *dev_info);
36 static int eth_ark_dev_link_update(struct rte_eth_dev *dev,
37 int wait_to_complete);
38 static int eth_ark_dev_set_link_up(struct rte_eth_dev *dev);
39 static int eth_ark_dev_set_link_down(struct rte_eth_dev *dev);
40 static int eth_ark_dev_stats_get(struct rte_eth_dev *dev,
41 struct rte_eth_stats *stats);
42 static int eth_ark_dev_stats_reset(struct rte_eth_dev *dev);
43 static int eth_ark_set_default_mac_addr(struct rte_eth_dev *dev,
44 struct rte_ether_addr *mac_addr);
45 static int eth_ark_macaddr_add(struct rte_eth_dev *dev,
46 struct rte_ether_addr *mac_addr,
49 static void eth_ark_macaddr_remove(struct rte_eth_dev *dev,
51 static int eth_ark_set_mtu(struct rte_eth_dev *dev, uint16_t size);
54 * The packet generator is a functional block used to generate packet
55 * patterns for testing. It is not intended for nominal use.
57 #define ARK_PKTGEN_ARG "Pkt_gen"
60 * The packet checker is a functional block used to verify packet
61 * patterns for testing. It is not intended for nominal use.
63 #define ARK_PKTCHKR_ARG "Pkt_chkr"
66 * The packet director is used to select the internal ingress and
67 * egress packets paths during testing. It is not intended for
70 #define ARK_PKTDIR_ARG "Pkt_dir"
72 /* Devinfo configurations */
73 #define ARK_RX_MAX_QUEUE (4096 * 4)
74 #define ARK_RX_MIN_QUEUE (512)
75 #define ARK_RX_MAX_PKT_LEN ((16 * 1024) - 128)
76 #define ARK_RX_MIN_BUFSIZE (1024)
78 #define ARK_TX_MAX_QUEUE (4096 * 4)
79 #define ARK_TX_MIN_QUEUE (256)
81 static const char * const valid_arguments[] = {
88 #define AR_VENDOR_ID 0x1d6c
89 static const struct rte_pci_id pci_id_ark_map[] = {
90 {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x100d)},
91 {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x100e)},
92 {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x100f)},
93 {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x1010)},
94 {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x1017)},
95 {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x1018)},
96 {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x1019)},
97 {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x101a)},
98 {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x101b)},
99 {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x101c)},
100 {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x101e)},
101 {RTE_PCI_DEVICE(AR_VENDOR_ID, 0x101f)},
102 {.vendor_id = 0, /* sentinel */ },
106 * This structure is used to statically define the capabilities
107 * of supported devices.
110 * Some HW variants require that PCIe read-requests be correctly throttled.
111 * This is called "rqpacing" and has to do with credit and flow control
112 * on certain Arkville implementations.
118 struct ark_dev_caps {
120 struct ark_caps caps;
122 #define SET_DEV_CAPS(id, rqp, vf) \
123 {id, {.rqpacing = rqp, .isvf = vf} }
125 static const struct ark_dev_caps
126 ark_device_caps[] = {
127 SET_DEV_CAPS(0x100d, true, false),
128 SET_DEV_CAPS(0x100e, true, false),
129 SET_DEV_CAPS(0x100f, true, false),
130 SET_DEV_CAPS(0x1010, false, false),
131 SET_DEV_CAPS(0x1017, true, false),
132 SET_DEV_CAPS(0x1018, true, false),
133 SET_DEV_CAPS(0x1019, true, false),
134 SET_DEV_CAPS(0x101a, true, false),
135 SET_DEV_CAPS(0x101b, true, false),
136 SET_DEV_CAPS(0x101c, true, true),
137 SET_DEV_CAPS(0x101e, false, false),
138 SET_DEV_CAPS(0x101f, false, false),
143 eth_ark_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
144 struct rte_pci_device *pci_dev)
146 struct rte_eth_dev *eth_dev;
149 eth_dev = rte_eth_dev_pci_allocate(pci_dev, sizeof(struct ark_adapter));
154 ret = eth_ark_dev_init(eth_dev);
156 rte_eth_dev_release_port(eth_dev);
162 eth_ark_pci_remove(struct rte_pci_device *pci_dev)
164 return rte_eth_dev_pci_generic_remove(pci_dev, eth_ark_dev_uninit);
167 static struct rte_pci_driver rte_ark_pmd = {
168 .id_table = pci_id_ark_map,
169 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
170 .probe = eth_ark_pci_probe,
171 .remove = eth_ark_pci_remove,
174 static const struct eth_dev_ops ark_eth_dev_ops = {
175 .dev_configure = eth_ark_dev_configure,
176 .dev_start = eth_ark_dev_start,
177 .dev_stop = eth_ark_dev_stop,
178 .dev_close = eth_ark_dev_close,
180 .dev_infos_get = eth_ark_dev_info_get,
182 .rx_queue_setup = eth_ark_dev_rx_queue_setup,
183 .tx_queue_setup = eth_ark_tx_queue_setup,
185 .link_update = eth_ark_dev_link_update,
186 .dev_set_link_up = eth_ark_dev_set_link_up,
187 .dev_set_link_down = eth_ark_dev_set_link_down,
189 .rx_queue_start = eth_ark_rx_start_queue,
190 .rx_queue_stop = eth_ark_rx_stop_queue,
192 .tx_queue_start = eth_ark_tx_queue_start,
193 .tx_queue_stop = eth_ark_tx_queue_stop,
195 .stats_get = eth_ark_dev_stats_get,
196 .stats_reset = eth_ark_dev_stats_reset,
198 .mac_addr_add = eth_ark_macaddr_add,
199 .mac_addr_remove = eth_ark_macaddr_remove,
200 .mac_addr_set = eth_ark_set_default_mac_addr,
202 .mtu_set = eth_ark_set_mtu,
206 check_for_ext(struct ark_adapter *ark)
211 const char *dllpath = getenv("ARK_EXT_PATH");
213 if (dllpath == NULL) {
214 ARK_PMD_LOG(DEBUG, "EXT NO dll path specified\n");
217 ARK_PMD_LOG(NOTICE, "EXT found dll path at %s\n", dllpath);
219 /* Open and load the .so */
220 ark->d_handle = dlopen(dllpath, RTLD_LOCAL | RTLD_LAZY);
221 if (ark->d_handle == NULL) {
222 ARK_PMD_LOG(ERR, "Could not load user extension %s\n",
226 ARK_PMD_LOG(DEBUG, "SUCCESS: loaded user extension %s\n",
229 /* Get the entry points */
230 ark->user_ext.dev_init =
231 (void *(*)(struct rte_eth_dev *, void *, int))
232 dlsym(ark->d_handle, "rte_pmd_ark_dev_init");
233 ARK_PMD_LOG(DEBUG, "device ext init pointer = %p\n",
234 ark->user_ext.dev_init);
235 ark->user_ext.dev_get_port_count =
236 (int (*)(struct rte_eth_dev *, void *))
237 dlsym(ark->d_handle, "rte_pmd_ark_dev_get_port_count");
238 ark->user_ext.dev_uninit =
239 (void (*)(struct rte_eth_dev *, void *))
240 dlsym(ark->d_handle, "rte_pmd_ark_dev_uninit");
241 ark->user_ext.dev_configure =
242 (int (*)(struct rte_eth_dev *, void *))
243 dlsym(ark->d_handle, "rte_pmd_ark_dev_configure");
244 ark->user_ext.dev_start =
245 (int (*)(struct rte_eth_dev *, void *))
246 dlsym(ark->d_handle, "rte_pmd_ark_dev_start");
247 ark->user_ext.dev_stop =
248 (void (*)(struct rte_eth_dev *, void *))
249 dlsym(ark->d_handle, "rte_pmd_ark_dev_stop");
250 ark->user_ext.dev_close =
251 (void (*)(struct rte_eth_dev *, void *))
252 dlsym(ark->d_handle, "rte_pmd_ark_dev_close");
253 ark->user_ext.link_update =
254 (int (*)(struct rte_eth_dev *, int, void *))
255 dlsym(ark->d_handle, "rte_pmd_ark_link_update");
256 ark->user_ext.dev_set_link_up =
257 (int (*)(struct rte_eth_dev *, void *))
258 dlsym(ark->d_handle, "rte_pmd_ark_dev_set_link_up");
259 ark->user_ext.dev_set_link_down =
260 (int (*)(struct rte_eth_dev *, void *))
261 dlsym(ark->d_handle, "rte_pmd_ark_dev_set_link_down");
262 ark->user_ext.stats_get =
263 (int (*)(struct rte_eth_dev *, struct rte_eth_stats *,
265 dlsym(ark->d_handle, "rte_pmd_ark_stats_get");
266 ark->user_ext.stats_reset =
267 (void (*)(struct rte_eth_dev *, void *))
268 dlsym(ark->d_handle, "rte_pmd_ark_stats_reset");
269 ark->user_ext.mac_addr_add =
270 (void (*)(struct rte_eth_dev *, struct rte_ether_addr *,
271 uint32_t, uint32_t, void *))
272 dlsym(ark->d_handle, "rte_pmd_ark_mac_addr_add");
273 ark->user_ext.mac_addr_remove =
274 (void (*)(struct rte_eth_dev *, uint32_t, void *))
275 dlsym(ark->d_handle, "rte_pmd_ark_mac_addr_remove");
276 ark->user_ext.mac_addr_set =
277 (void (*)(struct rte_eth_dev *, struct rte_ether_addr *,
279 dlsym(ark->d_handle, "rte_pmd_ark_mac_addr_set");
280 ark->user_ext.set_mtu =
281 (int (*)(struct rte_eth_dev *, uint16_t,
283 dlsym(ark->d_handle, "rte_pmd_ark_set_mtu");
284 ark->user_ext.rx_user_meta_hook =
285 (rx_user_meta_hook_fn)dlsym(ark->d_handle,
286 "rte_pmd_ark_rx_user_meta_hook");
287 ark->user_ext.tx_user_meta_hook =
288 (tx_user_meta_hook_fn)dlsym(ark->d_handle,
289 "rte_pmd_ark_tx_user_meta_hook");
295 eth_ark_dev_init(struct rte_eth_dev *dev)
297 struct ark_adapter *ark = dev->data->dev_private;
298 struct rte_pci_device *pci_dev;
302 bool rqpacing = false;
306 ARK_PMD_LOG(DEBUG, "\n");
308 /* Check to see if there is an extension that we need to load */
309 ret = check_for_ext(ark);
313 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
314 rte_eth_copy_pci_info(dev, pci_dev);
315 dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
318 while (ark_device_caps[p].device_id != 0) {
319 if (pci_dev->id.device_id == ark_device_caps[p].device_id) {
320 rqpacing = ark_device_caps[p].caps.rqpacing;
321 ark->isvf = ark_device_caps[p].caps.isvf;
327 /* Use dummy function until setup */
328 dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
329 dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
331 ark->bar0 = (uint8_t *)pci_dev->mem_resource[0].addr;
332 ark->a_bar = (uint8_t *)pci_dev->mem_resource[2].addr;
334 ark->sysctrl.v = (void *)&ark->bar0[ARK_SYSCTRL_BASE];
335 ark->mpurx.v = (void *)&ark->bar0[ARK_MPU_RX_BASE];
336 ark->udm.v = (void *)&ark->bar0[ARK_UDM_BASE];
337 ark->mputx.v = (void *)&ark->bar0[ARK_MPU_TX_BASE];
338 ark->ddm.v = (void *)&ark->bar0[ARK_DDM_BASE];
339 ark->cmac.v = (void *)&ark->bar0[ARK_CMAC_BASE];
340 ark->external.v = (void *)&ark->bar0[ARK_EXTERNAL_BASE];
341 ark->pktdir.v = (void *)&ark->bar0[ARK_PKTDIR_BASE];
342 ark->pktgen.v = (void *)&ark->bar0[ARK_PKTGEN_BASE];
343 ark->pktchkr.v = (void *)&ark->bar0[ARK_PKTCHKR_BASE];
347 (struct ark_rqpace_t *)(ark->bar0 + ARK_RCPACING_BASE);
349 ark->rqpacing = NULL;
352 ark->pkt_dir_v = ARK_PKT_DIR_INIT_VAL;
354 ARK_PMD_LOG(INFO, "Sys Ctrl Const = 0x%x HW Commit_ID: %08x\n",
356 rte_be_to_cpu_32(ark->sysctrl.t32[0x20 / 4]));
357 ARK_PMD_LOG(NOTICE, "Arkville HW Commit_ID: %08x\n",
358 rte_be_to_cpu_32(ark->sysctrl.t32[0x20 / 4]));
360 /* If HW sanity test fails, return an error */
361 if (ark->sysctrl.t32[4] != 0xcafef00d) {
363 "HW Sanity test has failed, expected constant"
364 " 0x%x, read 0x%x (%s)\n",
366 ark->sysctrl.t32[4], __func__);
369 if (ark->sysctrl.t32[3] != 0) {
371 if (ark_rqp_lasped(ark->rqpacing)) {
372 ARK_PMD_LOG(ERR, "Arkville Evaluation System - "
373 "Timer has Expired\n");
376 ARK_PMD_LOG(WARNING, "Arkville Evaluation System - "
377 "Timer is Running\n");
382 "HW Sanity test has PASSED, expected constant"
383 " 0x%x, read 0x%x (%s)\n",
384 0xcafef00d, ark->sysctrl.t32[4], __func__);
386 /* We are a single function multi-port device. */
387 ret = ark_config_device(dev);
391 dev->dev_ops = &ark_eth_dev_ops;
392 dev->rx_queue_count = eth_ark_dev_rx_queue_count;
394 dev->data->mac_addrs = rte_zmalloc("ark", RTE_ETHER_ADDR_LEN, 0);
395 if (!dev->data->mac_addrs) {
397 "Failed to allocated memory for storing mac address"
401 if (ark->user_ext.dev_init) {
402 ark->user_data[dev->data->port_id] =
403 ark->user_ext.dev_init(dev, ark->a_bar, 0);
404 if (!ark->user_data[dev->data->port_id]) {
406 "Failed to initialize PMD extension!"
407 " continuing without it\n");
408 memset(&ark->user_ext, 0, sizeof(struct ark_user_ext));
409 dlclose(ark->d_handle);
413 if (pci_dev->device.devargs)
414 ret = eth_ark_check_args(ark, pci_dev->device.devargs->args);
416 ARK_PMD_LOG(INFO, "No Device args found\n");
421 * We will create additional devices based on the number of requested
424 if (ark->user_ext.dev_get_port_count)
426 ark->user_ext.dev_get_port_count(dev,
427 ark->user_data[dev->data->port_id]);
428 ark->num_ports = port_count;
430 for (p = 0; p < port_count; p++) {
431 struct rte_eth_dev *eth_dev;
432 char name[RTE_ETH_NAME_MAX_LEN];
434 snprintf(name, sizeof(name), "arketh%d",
435 dev->data->port_id + p);
438 /* First port is already allocated by DPDK */
439 eth_dev = ark->eth_dev;
440 rte_eth_dev_probing_finish(eth_dev);
444 /* reserve an ethdev entry */
445 eth_dev = rte_eth_dev_allocate(name);
448 "Could not allocate eth_dev for port %d\n",
453 eth_dev->device = &pci_dev->device;
454 eth_dev->data->dev_private = ark;
455 eth_dev->dev_ops = ark->eth_dev->dev_ops;
456 eth_dev->tx_pkt_burst = ark->eth_dev->tx_pkt_burst;
457 eth_dev->rx_pkt_burst = ark->eth_dev->rx_pkt_burst;
459 rte_eth_copy_pci_info(eth_dev, pci_dev);
460 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
462 eth_dev->data->mac_addrs = rte_zmalloc(name,
463 RTE_ETHER_ADDR_LEN, 0);
464 if (!eth_dev->data->mac_addrs) {
466 "Memory allocation for MAC failed!"
471 if (ark->user_ext.dev_init) {
472 ark->user_data[eth_dev->data->port_id] =
473 ark->user_ext.dev_init(dev, ark->a_bar, p);
476 rte_eth_dev_probing_finish(eth_dev);
482 rte_free(dev->data->mac_addrs);
483 dev->data->mac_addrs = NULL;
488 *Initial device configuration when device is opened
489 * setup the DDM, and UDM
490 * Called once per PCIE device
493 ark_config_device(struct rte_eth_dev *dev)
495 struct ark_adapter *ark = dev->data->dev_private;
497 struct ark_mpu_t *mpu;
500 * Make sure that the packet director, generator and checker are in a
506 ark->pg = ark_pktgen_init(ark->pktgen.v, 0, 1);
509 ark_pktgen_reset(ark->pg);
510 ark->pc = ark_pktchkr_init(ark->pktchkr.v, 0, 1);
513 ark_pktchkr_stop(ark->pc);
514 ark->pd = ark_pktdir_init(ark->pktdir.v);
519 if (ark_udm_verify(ark->udm.v))
521 if (ark_ddm_verify(ark->ddm.v))
526 num_q = ark_api_num_queues(mpu);
527 ark->rx_queues = num_q;
528 for (i = 0; i < num_q; i++) {
529 mpu = RTE_PTR_ADD(mpu, ARK_MPU_QOFFSET);
533 num_q = ark_api_num_queues(mpu);
534 ark->tx_queues = num_q;
535 for (i = 0; i < num_q; i++) {
536 mpu = RTE_PTR_ADD(mpu, ARK_MPU_QOFFSET);
539 if (!ark->isvf && ark->rqpacing)
540 ark_rqp_stats_reset(ark->rqpacing);
546 eth_ark_dev_uninit(struct rte_eth_dev *dev)
548 struct ark_adapter *ark = dev->data->dev_private;
550 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
553 if (ark->user_ext.dev_uninit)
554 ark->user_ext.dev_uninit(dev,
555 ark->user_data[dev->data->port_id]);
558 ark_pktgen_uninit(ark->pg);
559 ark_pktchkr_uninit(ark->pc);
566 eth_ark_dev_configure(struct rte_eth_dev *dev)
568 struct ark_adapter *ark = dev->data->dev_private;
570 eth_ark_dev_set_link_up(dev);
571 if (ark->user_ext.dev_configure)
572 return ark->user_ext.dev_configure(dev,
573 ark->user_data[dev->data->port_id]);
578 eth_ark_dev_start(struct rte_eth_dev *dev)
580 struct ark_adapter *ark = dev->data->dev_private;
584 for (i = 0; i < dev->data->nb_rx_queues; i++)
585 eth_ark_rx_start_queue(dev, i);
588 for (i = 0; i < dev->data->nb_tx_queues; i++)
589 eth_ark_tx_queue_start(dev, i);
592 /* set xmit and receive function */
593 dev->rx_pkt_burst = ð_ark_recv_pkts;
594 dev->tx_pkt_burst = ð_ark_xmit_pkts;
596 if (!ark->isvf && ark->start_pg)
597 ark_pktchkr_run(ark->pc);
599 if (!ark->isvf && ark->start_pg && !ark->pg_running) {
602 /* Delay packet generatpr start allow the hardware to be ready
603 * This is only used for sanity checking with internal generator
606 snprintf(tname, sizeof(tname), "ark-delay-pg-%d",
609 if (rte_ctrl_thread_create(&thread, tname, NULL,
610 ark_pktgen_delay_start, ark->pg)) {
611 ARK_PMD_LOG(ERR, "Could not create pktgen "
618 if (ark->user_ext.dev_start)
619 ark->user_ext.dev_start(dev,
620 ark->user_data[dev->data->port_id]);
626 eth_ark_dev_stop(struct rte_eth_dev *dev)
630 struct ark_adapter *ark = dev->data->dev_private;
632 if (ark->started == 0)
635 dev->data->dev_started = 0;
637 /* Stop the extension first */
638 if (ark->user_ext.dev_stop)
639 ark->user_ext.dev_stop(dev,
640 ark->user_data[dev->data->port_id]);
642 /* Stop the packet generator */
643 if (!ark->isvf && ark->start_pg && ark->pg_running) {
644 ark_pktgen_pause(ark->pg);
648 dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
649 dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
652 for (i = 0; i < dev->data->nb_rx_queues; i++)
653 eth_ark_rx_stop_queue(dev, i);
656 for (i = 0; i < dev->data->nb_tx_queues; i++) {
657 status = eth_ark_tx_queue_stop(dev, i);
659 uint16_t port = dev->data->port_id;
661 "tx_queue stop anomaly"
662 " port %u, queue %u\n",
667 ark_udm_dump_stats(ark->udm.v, "Post stop");
669 for (i = 0; i < dev->data->nb_rx_queues; i++)
670 eth_ark_rx_dump_queue(dev, i, __func__);
672 /* Stop the packet checker if it is running */
673 if (!ark->isvf && ark->start_pg) {
674 ark_pktchkr_dump_stats(ark->pc);
675 ark_pktchkr_stop(ark->pc);
682 eth_ark_dev_close(struct rte_eth_dev *dev)
684 struct ark_adapter *ark = dev->data->dev_private;
687 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
690 if (ark->user_ext.dev_close)
691 ark->user_ext.dev_close(dev,
692 ark->user_data[dev->data->port_id]);
694 eth_ark_dev_stop(dev);
697 * This should only be called once for the device during shutdown
700 ark_rqp_dump(ark->rqpacing);
702 /* return to power-on state */
704 ark_pktdir_setup(ark->pd, ARK_PKT_DIR_INIT_VAL);
706 for (i = 0; i < dev->data->nb_tx_queues; i++) {
707 eth_ark_tx_queue_release(dev->data->tx_queues[i]);
708 dev->data->tx_queues[i] = 0;
711 for (i = 0; i < dev->data->nb_rx_queues; i++) {
712 eth_ark_dev_rx_queue_release(dev->data->rx_queues[i]);
713 dev->data->rx_queues[i] = 0;
720 eth_ark_dev_info_get(struct rte_eth_dev *dev,
721 struct rte_eth_dev_info *dev_info)
723 struct ark_adapter *ark = dev->data->dev_private;
724 struct ark_mpu_t *tx_mpu = RTE_PTR_ADD(ark->bar0, ARK_MPU_TX_BASE);
725 struct ark_mpu_t *rx_mpu = RTE_PTR_ADD(ark->bar0, ARK_MPU_RX_BASE);
726 uint16_t ports = ark->num_ports;
728 dev_info->max_rx_pktlen = ARK_RX_MAX_PKT_LEN;
729 dev_info->min_rx_bufsize = ARK_RX_MIN_BUFSIZE;
731 dev_info->max_rx_queues = ark_api_num_queues_per_port(rx_mpu, ports);
732 dev_info->max_tx_queues = ark_api_num_queues_per_port(tx_mpu, ports);
734 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
735 .nb_max = ARK_RX_MAX_QUEUE,
736 .nb_min = ARK_RX_MIN_QUEUE,
737 .nb_align = ARK_RX_MIN_QUEUE}; /* power of 2 */
739 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
740 .nb_max = ARK_TX_MAX_QUEUE,
741 .nb_min = ARK_TX_MIN_QUEUE,
742 .nb_align = ARK_TX_MIN_QUEUE}; /* power of 2 */
744 /* ARK PMD supports all line rates, how do we indicate that here ?? */
745 dev_info->speed_capa = (RTE_ETH_LINK_SPEED_1G |
746 RTE_ETH_LINK_SPEED_10G |
747 RTE_ETH_LINK_SPEED_25G |
748 RTE_ETH_LINK_SPEED_40G |
749 RTE_ETH_LINK_SPEED_50G |
750 RTE_ETH_LINK_SPEED_100G);
752 dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_TIMESTAMP;
758 eth_ark_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
760 ARK_PMD_LOG(DEBUG, "link status = %d\n",
761 dev->data->dev_link.link_status);
762 struct ark_adapter *ark = dev->data->dev_private;
764 if (ark->user_ext.link_update) {
765 return ark->user_ext.link_update
766 (dev, wait_to_complete,
767 ark->user_data[dev->data->port_id]);
773 eth_ark_dev_set_link_up(struct rte_eth_dev *dev)
775 dev->data->dev_link.link_status = 1;
776 struct ark_adapter *ark = dev->data->dev_private;
778 if (ark->user_ext.dev_set_link_up)
779 return ark->user_ext.dev_set_link_up(dev,
780 ark->user_data[dev->data->port_id]);
785 eth_ark_dev_set_link_down(struct rte_eth_dev *dev)
787 dev->data->dev_link.link_status = 0;
788 struct ark_adapter *ark = dev->data->dev_private;
790 if (ark->user_ext.dev_set_link_down)
791 return ark->user_ext.dev_set_link_down(dev,
792 ark->user_data[dev->data->port_id]);
797 eth_ark_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
800 struct ark_adapter *ark = dev->data->dev_private;
809 for (i = 0; i < dev->data->nb_tx_queues; i++)
810 eth_tx_queue_stats_get(dev->data->tx_queues[i], stats);
811 for (i = 0; i < dev->data->nb_rx_queues; i++)
812 eth_rx_queue_stats_get(dev->data->rx_queues[i], stats);
813 if (ark->user_ext.stats_get)
814 return ark->user_ext.stats_get(dev, stats,
815 ark->user_data[dev->data->port_id]);
820 eth_ark_dev_stats_reset(struct rte_eth_dev *dev)
823 struct ark_adapter *ark = dev->data->dev_private;
825 for (i = 0; i < dev->data->nb_tx_queues; i++)
826 eth_tx_queue_stats_reset(dev->data->tx_queues[i]);
827 for (i = 0; i < dev->data->nb_rx_queues; i++)
828 eth_rx_queue_stats_reset(dev->data->rx_queues[i]);
829 if (ark->user_ext.stats_reset)
830 ark->user_ext.stats_reset(dev,
831 ark->user_data[dev->data->port_id]);
837 eth_ark_macaddr_add(struct rte_eth_dev *dev,
838 struct rte_ether_addr *mac_addr,
842 struct ark_adapter *ark = dev->data->dev_private;
844 if (ark->user_ext.mac_addr_add) {
845 ark->user_ext.mac_addr_add(dev,
849 ark->user_data[dev->data->port_id]);
856 eth_ark_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
858 struct ark_adapter *ark = dev->data->dev_private;
860 if (ark->user_ext.mac_addr_remove)
861 ark->user_ext.mac_addr_remove(dev, index,
862 ark->user_data[dev->data->port_id]);
866 eth_ark_set_default_mac_addr(struct rte_eth_dev *dev,
867 struct rte_ether_addr *mac_addr)
869 struct ark_adapter *ark = dev->data->dev_private;
871 if (ark->user_ext.mac_addr_set) {
872 ark->user_ext.mac_addr_set(dev, mac_addr,
873 ark->user_data[dev->data->port_id]);
880 eth_ark_set_mtu(struct rte_eth_dev *dev, uint16_t size)
882 struct ark_adapter *ark = dev->data->dev_private;
884 if (ark->user_ext.set_mtu)
885 return ark->user_ext.set_mtu(dev, size,
886 ark->user_data[dev->data->port_id]);
892 process_pktdir_arg(const char *key, const char *value,
895 ARK_PMD_LOG(DEBUG, "key = %s, value = %s\n",
897 struct ark_adapter *ark =
898 (struct ark_adapter *)extra_args;
900 ark->pkt_dir_v = strtol(value, NULL, 16);
901 ARK_PMD_LOG(DEBUG, "pkt_dir_v = 0x%x\n", ark->pkt_dir_v);
906 process_file_args(const char *key, const char *value, void *extra_args)
908 ARK_PMD_LOG(DEBUG, "key = %s, value = %s\n",
910 char *args = (char *)extra_args;
912 /* Open the configuration file */
913 FILE *file = fopen(value, "r");
914 char line[ARK_MAX_ARG_LEN];
919 ARK_PMD_LOG(ERR, "Unable to open "
920 "config file %s\n", value);
924 while (fgets(line, sizeof(line), file)) {
925 size += strlen(line);
926 if (size >= ARK_MAX_ARG_LEN) {
927 ARK_PMD_LOG(ERR, "Unable to parse file %s args, "
928 "parameter list is too long\n", value);
933 strncpy(args, line, ARK_MAX_ARG_LEN);
936 strncat(args, line, ARK_MAX_ARG_LEN);
939 ARK_PMD_LOG(DEBUG, "file = %s\n", args);
945 eth_ark_check_args(struct ark_adapter *ark, const char *params)
947 struct rte_kvargs *kvlist;
949 struct rte_kvargs_pair *pair = NULL;
952 kvlist = rte_kvargs_parse(params, valid_arguments);
956 ark->pkt_gen_args[0] = 0;
957 ark->pkt_chkr_args[0] = 0;
959 for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
960 pair = &kvlist->pairs[k_idx];
961 ARK_PMD_LOG(DEBUG, "**** Arg passed to PMD = %s:%s\n",
966 if (rte_kvargs_process(kvlist,
970 ARK_PMD_LOG(ERR, "Unable to parse arg %s\n", ARK_PKTDIR_ARG);
974 if (rte_kvargs_process(kvlist,
977 ark->pkt_gen_args) != 0) {
978 ARK_PMD_LOG(ERR, "Unable to parse arg %s\n", ARK_PKTGEN_ARG);
982 if (rte_kvargs_process(kvlist,
985 ark->pkt_chkr_args) != 0) {
986 ARK_PMD_LOG(ERR, "Unable to parse arg %s\n", ARK_PKTCHKR_ARG);
994 ARK_PMD_LOG(INFO, "packet director set to 0x%x\n", ark->pkt_dir_v);
995 /* Setup the packet director */
996 ark_pktdir_setup(ark->pd, ark->pkt_dir_v);
998 /* Setup the packet generator */
999 if (ark->pkt_gen_args[0]) {
1000 ARK_PMD_LOG(DEBUG, "Setting up the packet generator\n");
1001 ark_pktgen_parse(ark->pkt_gen_args);
1002 ark_pktgen_reset(ark->pg);
1003 ark_pktgen_setup(ark->pg);
1007 /* Setup the packet checker */
1008 if (ark->pkt_chkr_args[0]) {
1009 ark_pktchkr_parse(ark->pkt_chkr_args);
1010 ark_pktchkr_setup(ark->pc);
1016 rte_kvargs_free(kvlist);
1021 RTE_PMD_REGISTER_PCI(net_ark, rte_ark_pmd);
1022 RTE_PMD_REGISTER_KMOD_DEP(net_ark, "* igb_uio | uio_pci_generic ");
1023 RTE_PMD_REGISTER_PCI_TABLE(net_ark, pci_id_ark_map);
1024 RTE_PMD_REGISTER_PARAM_STRING(net_ark,
1025 ARK_PKTGEN_ARG "=<filename> "
1026 ARK_PKTCHKR_ARG "=<filename> "
1027 ARK_PKTDIR_ARG "=<bitmap>");
1028 RTE_LOG_REGISTER_DEFAULT(ark_logtype, NOTICE);