4 * Copyright (c) 2015-2017 Atomic Rules LLC
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <rte_ethdev_pci.h>
39 #include <rte_kvargs.h>
41 #include "ark_global.h"
43 #include "ark_ethdev.h"
44 #include "ark_ethdev_tx.h"
45 #include "ark_ethdev_rx.h"
50 #include "ark_pktdir.h"
51 #include "ark_pktgen.h"
52 #include "ark_pktchkr.h"
54 /* Internal prototypes */
55 static int eth_ark_check_args(struct ark_adapter *ark, const char *params);
56 static int eth_ark_dev_init(struct rte_eth_dev *dev);
57 static int ark_config_device(struct rte_eth_dev *dev);
58 static int eth_ark_dev_uninit(struct rte_eth_dev *eth_dev);
59 static int eth_ark_dev_configure(struct rte_eth_dev *dev);
60 static int eth_ark_dev_start(struct rte_eth_dev *dev);
61 static void eth_ark_dev_stop(struct rte_eth_dev *dev);
62 static void eth_ark_dev_close(struct rte_eth_dev *dev);
63 static void eth_ark_dev_info_get(struct rte_eth_dev *dev,
64 struct rte_eth_dev_info *dev_info);
65 static int eth_ark_dev_link_update(struct rte_eth_dev *dev,
66 int wait_to_complete);
67 static int eth_ark_dev_set_link_up(struct rte_eth_dev *dev);
68 static int eth_ark_dev_set_link_down(struct rte_eth_dev *dev);
69 static void eth_ark_dev_stats_get(struct rte_eth_dev *dev,
70 struct rte_eth_stats *stats);
71 static void eth_ark_dev_stats_reset(struct rte_eth_dev *dev);
72 static void eth_ark_set_default_mac_addr(struct rte_eth_dev *dev,
73 struct ether_addr *mac_addr);
74 static int eth_ark_macaddr_add(struct rte_eth_dev *dev,
75 struct ether_addr *mac_addr,
78 static void eth_ark_macaddr_remove(struct rte_eth_dev *dev,
82 * The packet generator is a functional block used to generate packet
83 * patterns for testing. It is not intended for nominal use.
85 #define ARK_PKTGEN_ARG "Pkt_gen"
88 * The packet checker is a functional block used to verify packet
89 * patterns for testing. It is not intended for nominal use.
91 #define ARK_PKTCHKR_ARG "Pkt_chkr"
94 * The packet director is used to select the internal ingress and
95 * egress packets paths during testing. It is not intended for
98 #define ARK_PKTDIR_ARG "Pkt_dir"
100 /* Devinfo configurations */
101 #define ARK_RX_MAX_QUEUE (4096 * 4)
102 #define ARK_RX_MIN_QUEUE (512)
103 #define ARK_RX_MAX_PKT_LEN ((16 * 1024) - 128)
104 #define ARK_RX_MIN_BUFSIZE (1024)
106 #define ARK_TX_MAX_QUEUE (4096 * 4)
107 #define ARK_TX_MIN_QUEUE (256)
109 static const char * const valid_arguments[] = {
116 static const struct rte_pci_id pci_id_ark_map[] = {
117 {RTE_PCI_DEVICE(0x1d6c, 0x100d)},
118 {RTE_PCI_DEVICE(0x1d6c, 0x100e)},
119 {.vendor_id = 0, /* sentinel */ },
123 eth_ark_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
124 struct rte_pci_device *pci_dev)
126 struct rte_eth_dev *eth_dev;
129 eth_dev = rte_eth_dev_pci_allocate(pci_dev, sizeof(struct ark_adapter));
134 ret = eth_ark_dev_init(eth_dev);
136 rte_eth_dev_pci_release(eth_dev);
142 eth_ark_pci_remove(struct rte_pci_device *pci_dev)
144 return rte_eth_dev_pci_generic_remove(pci_dev, eth_ark_dev_uninit);
147 static struct rte_pci_driver rte_ark_pmd = {
148 .id_table = pci_id_ark_map,
149 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
150 .probe = eth_ark_pci_probe,
151 .remove = eth_ark_pci_remove,
154 static const struct eth_dev_ops ark_eth_dev_ops = {
155 .dev_configure = eth_ark_dev_configure,
156 .dev_start = eth_ark_dev_start,
157 .dev_stop = eth_ark_dev_stop,
158 .dev_close = eth_ark_dev_close,
160 .dev_infos_get = eth_ark_dev_info_get,
162 .rx_queue_setup = eth_ark_dev_rx_queue_setup,
163 .rx_queue_count = eth_ark_dev_rx_queue_count,
164 .tx_queue_setup = eth_ark_tx_queue_setup,
166 .link_update = eth_ark_dev_link_update,
167 .dev_set_link_up = eth_ark_dev_set_link_up,
168 .dev_set_link_down = eth_ark_dev_set_link_down,
170 .rx_queue_start = eth_ark_rx_start_queue,
171 .rx_queue_stop = eth_ark_rx_stop_queue,
173 .tx_queue_start = eth_ark_tx_queue_start,
174 .tx_queue_stop = eth_ark_tx_queue_stop,
176 .stats_get = eth_ark_dev_stats_get,
177 .stats_reset = eth_ark_dev_stats_reset,
179 .mac_addr_add = eth_ark_macaddr_add,
180 .mac_addr_remove = eth_ark_macaddr_remove,
181 .mac_addr_set = eth_ark_set_default_mac_addr,
185 check_for_ext(struct ark_adapter *ark)
190 const char *dllpath = getenv("ARK_EXT_PATH");
192 if (dllpath == NULL) {
193 PMD_DEBUG_LOG(DEBUG, "ARK EXT NO dll path specified\n");
196 PMD_DRV_LOG(INFO, "ARK EXT found dll path at %s\n", dllpath);
198 /* Open and load the .so */
199 ark->d_handle = dlopen(dllpath, RTLD_LOCAL | RTLD_LAZY);
200 if (ark->d_handle == NULL) {
201 PMD_DRV_LOG(ERR, "Could not load user extension %s\n",
205 PMD_DRV_LOG(INFO, "SUCCESS: loaded user extension %s\n",
208 /* Get the entry points */
209 ark->user_ext.dev_init =
210 (void *(*)(struct rte_eth_dev *, void *, int))
211 dlsym(ark->d_handle, "dev_init");
212 PMD_DEBUG_LOG(DEBUG, "device ext init pointer = %p\n",
213 ark->user_ext.dev_init);
214 ark->user_ext.dev_get_port_count =
215 (int (*)(struct rte_eth_dev *, void *))
216 dlsym(ark->d_handle, "dev_get_port_count");
217 ark->user_ext.dev_uninit =
218 (void (*)(struct rte_eth_dev *, void *))
219 dlsym(ark->d_handle, "dev_uninit");
220 ark->user_ext.dev_configure =
221 (int (*)(struct rte_eth_dev *, void *))
222 dlsym(ark->d_handle, "dev_configure");
223 ark->user_ext.dev_start =
224 (int (*)(struct rte_eth_dev *, void *))
225 dlsym(ark->d_handle, "dev_start");
226 ark->user_ext.dev_stop =
227 (void (*)(struct rte_eth_dev *, void *))
228 dlsym(ark->d_handle, "dev_stop");
229 ark->user_ext.dev_close =
230 (void (*)(struct rte_eth_dev *, void *))
231 dlsym(ark->d_handle, "dev_close");
232 ark->user_ext.link_update =
233 (int (*)(struct rte_eth_dev *, int, void *))
234 dlsym(ark->d_handle, "link_update");
235 ark->user_ext.dev_set_link_up =
236 (int (*)(struct rte_eth_dev *, void *))
237 dlsym(ark->d_handle, "dev_set_link_up");
238 ark->user_ext.dev_set_link_down =
239 (int (*)(struct rte_eth_dev *, void *))
240 dlsym(ark->d_handle, "dev_set_link_down");
241 ark->user_ext.stats_get =
242 (void (*)(struct rte_eth_dev *, struct rte_eth_stats *,
244 dlsym(ark->d_handle, "stats_get");
245 ark->user_ext.stats_reset =
246 (void (*)(struct rte_eth_dev *, void *))
247 dlsym(ark->d_handle, "stats_reset");
248 ark->user_ext.mac_addr_add =
249 (void (*)(struct rte_eth_dev *, struct ether_addr *, uint32_t,
251 dlsym(ark->d_handle, "mac_addr_add");
252 ark->user_ext.mac_addr_remove =
253 (void (*)(struct rte_eth_dev *, uint32_t, void *))
254 dlsym(ark->d_handle, "mac_addr_remove");
255 ark->user_ext.mac_addr_set =
256 (void (*)(struct rte_eth_dev *, struct ether_addr *,
258 dlsym(ark->d_handle, "mac_addr_set");
264 eth_ark_dev_init(struct rte_eth_dev *dev)
266 struct ark_adapter *ark =
267 (struct ark_adapter *)dev->data->dev_private;
268 struct rte_pci_device *pci_dev;
275 PMD_FUNC_LOG(DEBUG, "\n");
277 /* Check to see if there is an extension that we need to load */
278 ret = check_for_ext(ark);
281 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
282 rte_eth_copy_pci_info(dev, pci_dev);
284 /* Use dummy function until setup */
285 dev->rx_pkt_burst = ð_ark_recv_pkts_noop;
286 dev->tx_pkt_burst = ð_ark_xmit_pkts_noop;
288 ark->bar0 = (uint8_t *)pci_dev->mem_resource[0].addr;
289 ark->a_bar = (uint8_t *)pci_dev->mem_resource[2].addr;
291 ark->sysctrl.v = (void *)&ark->bar0[ARK_SYSCTRL_BASE];
292 ark->mpurx.v = (void *)&ark->bar0[ARK_MPU_RX_BASE];
293 ark->udm.v = (void *)&ark->bar0[ARK_UDM_BASE];
294 ark->mputx.v = (void *)&ark->bar0[ARK_MPU_TX_BASE];
295 ark->ddm.v = (void *)&ark->bar0[ARK_DDM_BASE];
296 ark->cmac.v = (void *)&ark->bar0[ARK_CMAC_BASE];
297 ark->external.v = (void *)&ark->bar0[ARK_EXTERNAL_BASE];
298 ark->pktdir.v = (void *)&ark->bar0[ARK_PKTDIR_BASE];
299 ark->pktgen.v = (void *)&ark->bar0[ARK_PKTGEN_BASE];
300 ark->pktchkr.v = (void *)&ark->bar0[ARK_PKTCHKR_BASE];
303 (struct ark_rqpace_t *)(ark->bar0 + ARK_RCPACING_BASE);
306 PMD_DEBUG_LOG(INFO, "Sys Ctrl Const = 0x%x HW Commit_ID: %08x\n",
308 rte_be_to_cpu_32(ark->sysctrl.t32[0x20 / 4]));
309 PMD_DRV_LOG(INFO, "Arkville HW Commit_ID: %08x\n",
310 rte_be_to_cpu_32(ark->sysctrl.t32[0x20 / 4]));
312 /* If HW sanity test fails, return an error */
313 if (ark->sysctrl.t32[4] != 0xcafef00d) {
315 "HW Sanity test has failed, expected constant"
316 " 0x%x, read 0x%x (%s)\n",
318 ark->sysctrl.t32[4], __func__);
321 if (ark->sysctrl.t32[3] != 0) {
322 if (ark_rqp_lasped(ark->rqpacing)) {
323 PMD_DRV_LOG(ERR, "Arkville Evaluation System - "
324 "Timer has Expired\n");
327 PMD_DRV_LOG(WARNING, "Arkville Evaluation System - "
328 "Timer is Running\n");
332 "HW Sanity test has PASSED, expected constant"
333 " 0x%x, read 0x%x (%s)\n",
334 0xcafef00d, ark->sysctrl.t32[4], __func__);
336 /* We are a single function multi-port device. */
337 ret = ark_config_device(dev);
338 dev->dev_ops = &ark_eth_dev_ops;
339 dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
341 dev->data->mac_addrs = rte_zmalloc("ark", ETHER_ADDR_LEN, 0);
342 if (!dev->data->mac_addrs) {
344 "Failed to allocated memory for storing mac address"
348 if (ark->user_ext.dev_init) {
349 ark->user_data[dev->data->port_id] =
350 ark->user_ext.dev_init(dev, ark->a_bar, 0);
351 if (!ark->user_data[dev->data->port_id]) {
353 "Failed to initialize PMD extension!"
354 " continuing without it\n");
355 memset(&ark->user_ext, 0, sizeof(struct ark_user_ext));
356 dlclose(ark->d_handle);
360 if (pci_dev->device.devargs)
361 ret = eth_ark_check_args(ark, pci_dev->device.devargs->args);
363 PMD_DRV_LOG(INFO, "No Device args found\n");
368 * We will create additional devices based on the number of requested
371 if (ark->user_ext.dev_get_port_count)
373 ark->user_ext.dev_get_port_count(dev,
374 ark->user_data[dev->data->port_id]);
375 ark->num_ports = port_count;
377 for (p = 0; p < port_count; p++) {
378 struct rte_eth_dev *eth_dev;
379 char name[RTE_ETH_NAME_MAX_LEN];
381 snprintf(name, sizeof(name), "arketh%d",
382 dev->data->port_id + p);
385 /* First port is already allocated by DPDK */
386 eth_dev = ark->eth_dev;
390 /* reserve an ethdev entry */
391 eth_dev = rte_eth_dev_allocate(name);
394 "Could not allocate eth_dev for port %d\n",
399 eth_dev->device = &pci_dev->device;
400 eth_dev->data->dev_private = ark;
401 eth_dev->dev_ops = ark->eth_dev->dev_ops;
402 eth_dev->tx_pkt_burst = ark->eth_dev->tx_pkt_burst;
403 eth_dev->rx_pkt_burst = ark->eth_dev->rx_pkt_burst;
405 rte_eth_copy_pci_info(eth_dev, pci_dev);
407 eth_dev->data->mac_addrs = rte_zmalloc(name, ETHER_ADDR_LEN, 0);
408 if (!eth_dev->data->mac_addrs) {
410 "Memory allocation for MAC failed!"
415 if (ark->user_ext.dev_init) {
416 ark->user_data[eth_dev->data->port_id] =
417 ark->user_ext.dev_init(dev, ark->a_bar, p);
424 if (dev->data->mac_addrs)
425 rte_free(dev->data->mac_addrs);
430 *Initial device configuration when device is opened
431 * setup the DDM, and UDM
432 * Called once per PCIE device
435 ark_config_device(struct rte_eth_dev *dev)
437 struct ark_adapter *ark =
438 (struct ark_adapter *)dev->data->dev_private;
440 struct ark_mpu_t *mpu;
443 * Make sure that the packet director, generator and checker are in a
447 ark->pg = ark_pktgen_init(ark->pktgen.v, 0, 1);
448 ark_pktgen_reset(ark->pg);
449 ark->pc = ark_pktchkr_init(ark->pktchkr.v, 0, 1);
450 ark_pktchkr_stop(ark->pc);
451 ark->pd = ark_pktdir_init(ark->pktdir.v);
454 if (ark_udm_verify(ark->udm.v))
456 if (ark_ddm_verify(ark->ddm.v))
460 if (ark_udm_reset(ark->udm.v)) {
461 PMD_DRV_LOG(ERR, "Unable to stop and reset UDM\n");
464 /* Keep in reset until the MPU are cleared */
468 num_q = ark_api_num_queues(mpu);
469 ark->rx_queues = num_q;
470 for (i = 0; i < num_q; i++) {
472 mpu = RTE_PTR_ADD(mpu, ARK_MPU_QOFFSET);
475 ark_udm_stop(ark->udm.v, 0);
476 ark_udm_configure(ark->udm.v,
477 RTE_PKTMBUF_HEADROOM,
478 RTE_MBUF_DEFAULT_DATAROOM,
479 ARK_RX_WRITE_TIME_NS);
480 ark_udm_stats_reset(ark->udm.v);
481 ark_udm_stop(ark->udm.v, 0);
484 if (ark_ddm_stop(ark->ddm.v, 1))
485 PMD_DRV_LOG(ERR, "Unable to stop DDM\n");
488 num_q = ark_api_num_queues(mpu);
489 ark->tx_queues = num_q;
490 for (i = 0; i < num_q; i++) {
492 mpu = RTE_PTR_ADD(mpu, ARK_MPU_QOFFSET);
495 ark_ddm_reset(ark->ddm.v);
496 ark_ddm_stats_reset(ark->ddm.v);
498 ark_ddm_stop(ark->ddm.v, 0);
499 ark_rqp_stats_reset(ark->rqpacing);
505 eth_ark_dev_uninit(struct rte_eth_dev *dev)
507 struct ark_adapter *ark =
508 (struct ark_adapter *)dev->data->dev_private;
510 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
513 if (ark->user_ext.dev_uninit)
514 ark->user_ext.dev_uninit(dev,
515 ark->user_data[dev->data->port_id]);
517 ark_pktgen_uninit(ark->pg);
518 ark_pktchkr_uninit(ark->pc);
521 dev->rx_pkt_burst = NULL;
522 dev->tx_pkt_burst = NULL;
523 rte_free(dev->data->mac_addrs);
528 eth_ark_dev_configure(struct rte_eth_dev *dev)
530 PMD_FUNC_LOG(DEBUG, "\n");
531 struct ark_adapter *ark =
532 (struct ark_adapter *)dev->data->dev_private;
534 eth_ark_dev_set_link_up(dev);
535 if (ark->user_ext.dev_configure)
536 return ark->user_ext.dev_configure(dev,
537 ark->user_data[dev->data->port_id]);
542 delay_pg_start(void *arg)
544 struct ark_adapter *ark = (struct ark_adapter *)arg;
546 /* This function is used exclusively for regression testing, We
547 * perform a blind sleep here to ensure that the external test
548 * application has time to setup the test before we generate packets
551 ark_pktgen_run(ark->pg);
556 eth_ark_dev_start(struct rte_eth_dev *dev)
558 struct ark_adapter *ark =
559 (struct ark_adapter *)dev->data->dev_private;
562 PMD_FUNC_LOG(DEBUG, "\n");
566 ark_udm_start(ark->udm.v);
568 for (i = 0; i < dev->data->nb_rx_queues; i++)
569 eth_ark_rx_start_queue(dev, i);
572 for (i = 0; i < dev->data->nb_tx_queues; i++)
573 eth_ark_tx_queue_start(dev, i);
576 ark_ddm_start(ark->ddm.v);
579 /* set xmit and receive function */
580 dev->rx_pkt_burst = ð_ark_recv_pkts;
581 dev->tx_pkt_burst = ð_ark_xmit_pkts;
584 ark_pktchkr_run(ark->pc);
586 if (ark->start_pg && (dev->data->port_id == 0)) {
589 /* Delay packet generatpr start allow the hardware to be ready
590 * This is only used for sanity checking with internal generator
592 if (pthread_create(&thread, NULL, delay_pg_start, ark)) {
593 PMD_DRV_LOG(ERR, "Could not create pktgen "
599 if (ark->user_ext.dev_start)
600 ark->user_ext.dev_start(dev,
601 ark->user_data[dev->data->port_id]);
607 eth_ark_dev_stop(struct rte_eth_dev *dev)
611 struct ark_adapter *ark =
612 (struct ark_adapter *)dev->data->dev_private;
613 struct ark_mpu_t *mpu;
615 PMD_FUNC_LOG(DEBUG, "\n");
617 if (ark->started == 0)
621 /* Stop the extension first */
622 if (ark->user_ext.dev_stop)
623 ark->user_ext.dev_stop(dev,
624 ark->user_data[dev->data->port_id]);
626 /* Stop the packet generator */
628 ark_pktgen_pause(ark->pg);
630 dev->rx_pkt_burst = ð_ark_recv_pkts_noop;
631 dev->tx_pkt_burst = ð_ark_xmit_pkts_noop;
634 for (i = 0; i < dev->data->nb_tx_queues; i++) {
635 status = eth_ark_tx_queue_stop(dev, i);
637 uint8_t port = dev->data->port_id;
639 "tx_queue stop anomaly"
640 " port %u, queue %u\n",
646 /* Wait up to 0.1 second. each stop is up to 1000 * 10 useconds */
647 for (i = 0; i < 10; i++) {
648 status = ark_ddm_stop(ark->ddm.v, 1);
652 if (status || i != 0) {
653 PMD_DRV_LOG(ERR, "DDM stop anomaly. status:"
654 " %d iter: %u. (%s)\n",
658 ark_ddm_dump(ark->ddm.v, "Stop anomaly");
661 for (i = 0; i < ark->tx_queues; i++) {
662 ark_mpu_dump(mpu, "DDM failure dump", i);
663 mpu = RTE_PTR_ADD(mpu, ARK_MPU_QOFFSET);
668 /* Stop UDM multiple tries attempted */
669 for (i = 0; i < 10; i++) {
670 status = ark_udm_stop(ark->udm.v, 1);
674 if (status || i != 0) {
675 PMD_DRV_LOG(ERR, "UDM stop anomaly. status %d iter: %u. (%s)\n",
676 status, i, __func__);
677 ark_udm_dump(ark->udm.v, "Stop anomaly");
680 for (i = 0; i < ark->rx_queues; i++) {
681 ark_mpu_dump(mpu, "UDM Stop anomaly", i);
682 mpu = RTE_PTR_ADD(mpu, ARK_MPU_QOFFSET);
686 ark_udm_dump_stats(ark->udm.v, "Post stop");
687 ark_udm_dump_perf(ark->udm.v, "Post stop");
689 for (i = 0; i < dev->data->nb_tx_queues; i++)
690 eth_ark_rx_dump_queue(dev, i, __func__);
692 /* Stop the packet checker if it is running */
694 ark_pktchkr_dump_stats(ark->pc);
695 ark_pktchkr_stop(ark->pc);
700 eth_ark_dev_close(struct rte_eth_dev *dev)
702 struct ark_adapter *ark =
703 (struct ark_adapter *)dev->data->dev_private;
706 if (ark->user_ext.dev_close)
707 ark->user_ext.dev_close(dev,
708 ark->user_data[dev->data->port_id]);
710 eth_ark_dev_stop(dev);
711 eth_ark_udm_force_close(dev);
714 * TODO This should only be called once for the device during shutdown
716 ark_rqp_dump(ark->rqpacing);
718 for (i = 0; i < dev->data->nb_tx_queues; i++) {
719 eth_ark_tx_queue_release(dev->data->tx_queues[i]);
720 dev->data->tx_queues[i] = 0;
723 for (i = 0; i < dev->data->nb_rx_queues; i++) {
724 eth_ark_dev_rx_queue_release(dev->data->rx_queues[i]);
725 dev->data->rx_queues[i] = 0;
730 eth_ark_dev_info_get(struct rte_eth_dev *dev,
731 struct rte_eth_dev_info *dev_info)
733 struct ark_adapter *ark =
734 (struct ark_adapter *)dev->data->dev_private;
735 struct ark_mpu_t *tx_mpu = RTE_PTR_ADD(ark->bar0, ARK_MPU_TX_BASE);
736 struct ark_mpu_t *rx_mpu = RTE_PTR_ADD(ark->bar0, ARK_MPU_RX_BASE);
737 uint16_t ports = ark->num_ports;
739 dev_info->max_rx_pktlen = ARK_RX_MAX_PKT_LEN;
740 dev_info->min_rx_bufsize = ARK_RX_MIN_BUFSIZE;
742 dev_info->max_rx_queues = ark_api_num_queues_per_port(rx_mpu, ports);
743 dev_info->max_tx_queues = ark_api_num_queues_per_port(tx_mpu, ports);
745 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
746 .nb_max = ARK_RX_MAX_QUEUE,
747 .nb_min = ARK_RX_MIN_QUEUE,
748 .nb_align = ARK_RX_MIN_QUEUE}; /* power of 2 */
750 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
751 .nb_max = ARK_TX_MAX_QUEUE,
752 .nb_min = ARK_TX_MIN_QUEUE,
753 .nb_align = ARK_TX_MIN_QUEUE}; /* power of 2 */
755 /* ARK PMD supports all line rates, how do we indicate that here ?? */
756 dev_info->speed_capa = (ETH_LINK_SPEED_1G |
761 ETH_LINK_SPEED_100G);
762 dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
766 eth_ark_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
768 PMD_DEBUG_LOG(DEBUG, "link status = %d\n",
769 dev->data->dev_link.link_status);
770 struct ark_adapter *ark =
771 (struct ark_adapter *)dev->data->dev_private;
773 if (ark->user_ext.link_update) {
774 return ark->user_ext.link_update
775 (dev, wait_to_complete,
776 ark->user_data[dev->data->port_id]);
782 eth_ark_dev_set_link_up(struct rte_eth_dev *dev)
784 dev->data->dev_link.link_status = 1;
785 struct ark_adapter *ark =
786 (struct ark_adapter *)dev->data->dev_private;
788 if (ark->user_ext.dev_set_link_up)
789 return ark->user_ext.dev_set_link_up(dev,
790 ark->user_data[dev->data->port_id]);
795 eth_ark_dev_set_link_down(struct rte_eth_dev *dev)
797 dev->data->dev_link.link_status = 0;
798 struct ark_adapter *ark =
799 (struct ark_adapter *)dev->data->dev_private;
801 if (ark->user_ext.dev_set_link_down)
802 return ark->user_ext.dev_set_link_down(dev,
803 ark->user_data[dev->data->port_id]);
808 eth_ark_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
811 struct ark_adapter *ark =
812 (struct ark_adapter *)dev->data->dev_private;
821 for (i = 0; i < dev->data->nb_tx_queues; i++)
822 eth_tx_queue_stats_get(dev->data->tx_queues[i], stats);
823 for (i = 0; i < dev->data->nb_rx_queues; i++)
824 eth_rx_queue_stats_get(dev->data->rx_queues[i], stats);
825 if (ark->user_ext.stats_get)
826 ark->user_ext.stats_get(dev, stats,
827 ark->user_data[dev->data->port_id]);
831 eth_ark_dev_stats_reset(struct rte_eth_dev *dev)
834 struct ark_adapter *ark =
835 (struct ark_adapter *)dev->data->dev_private;
837 for (i = 0; i < dev->data->nb_tx_queues; i++)
838 eth_tx_queue_stats_reset(dev->data->rx_queues[i]);
839 for (i = 0; i < dev->data->nb_rx_queues; i++)
840 eth_rx_queue_stats_reset(dev->data->rx_queues[i]);
841 if (ark->user_ext.stats_reset)
842 ark->user_ext.stats_reset(dev,
843 ark->user_data[dev->data->port_id]);
847 eth_ark_macaddr_add(struct rte_eth_dev *dev,
848 struct ether_addr *mac_addr,
852 struct ark_adapter *ark =
853 (struct ark_adapter *)dev->data->dev_private;
855 if (ark->user_ext.mac_addr_add) {
856 ark->user_ext.mac_addr_add(dev,
860 ark->user_data[dev->data->port_id]);
867 eth_ark_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
869 struct ark_adapter *ark =
870 (struct ark_adapter *)dev->data->dev_private;
872 if (ark->user_ext.mac_addr_remove)
873 ark->user_ext.mac_addr_remove(dev, index,
874 ark->user_data[dev->data->port_id]);
878 eth_ark_set_default_mac_addr(struct rte_eth_dev *dev,
879 struct ether_addr *mac_addr)
881 struct ark_adapter *ark =
882 (struct ark_adapter *)dev->data->dev_private;
884 if (ark->user_ext.mac_addr_set)
885 ark->user_ext.mac_addr_set(dev, mac_addr,
886 ark->user_data[dev->data->port_id]);
890 process_pktdir_arg(const char *key, const char *value,
893 PMD_FUNC_LOG(DEBUG, "key = %s, value = %s\n",
895 struct ark_adapter *ark =
896 (struct ark_adapter *)extra_args;
898 ark->pkt_dir_v = strtol(value, NULL, 16);
899 PMD_FUNC_LOG(DEBUG, "pkt_dir_v = 0x%x\n", ark->pkt_dir_v);
904 process_file_args(const char *key, const char *value, void *extra_args)
906 PMD_FUNC_LOG(DEBUG, "key = %s, value = %s\n",
908 char *args = (char *)extra_args;
910 /* Open the configuration file */
911 FILE *file = fopen(value, "r");
912 char line[ARK_MAX_ARG_LEN];
917 PMD_DRV_LOG(ERR, "Unable to open "
918 "config file %s\n", value);
922 while (fgets(line, sizeof(line), file)) {
923 size += strlen(line);
924 if (size >= ARK_MAX_ARG_LEN) {
925 PMD_DRV_LOG(ERR, "Unable to parse file %s args, "
926 "parameter list is too long\n", value);
931 strncpy(args, line, ARK_MAX_ARG_LEN);
934 strncat(args, line, ARK_MAX_ARG_LEN);
937 PMD_FUNC_LOG(DEBUG, "file = %s\n", args);
943 eth_ark_check_args(struct ark_adapter *ark, const char *params)
945 struct rte_kvargs *kvlist;
947 struct rte_kvargs_pair *pair = NULL;
950 kvlist = rte_kvargs_parse(params, valid_arguments);
954 ark->pkt_gen_args[0] = 0;
955 ark->pkt_chkr_args[0] = 0;
957 for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
958 pair = &kvlist->pairs[k_idx];
959 PMD_FUNC_LOG(DEBUG, "**** Arg passed to PMD = %s:%s\n",
964 if (rte_kvargs_process(kvlist,
968 PMD_DRV_LOG(ERR, "Unable to parse arg %s\n", ARK_PKTDIR_ARG);
972 if (rte_kvargs_process(kvlist,
975 ark->pkt_gen_args) != 0) {
976 PMD_DRV_LOG(ERR, "Unable to parse arg %s\n", ARK_PKTGEN_ARG);
980 if (rte_kvargs_process(kvlist,
983 ark->pkt_chkr_args) != 0) {
984 PMD_DRV_LOG(ERR, "Unable to parse arg %s\n", ARK_PKTCHKR_ARG);
988 PMD_DRV_LOG(INFO, "packet director set to 0x%x\n", ark->pkt_dir_v);
989 /* Setup the packet director */
990 ark_pktdir_setup(ark->pd, ark->pkt_dir_v);
992 /* Setup the packet generator */
993 if (ark->pkt_gen_args[0]) {
994 PMD_DRV_LOG(INFO, "Setting up the packet generator\n");
995 ark_pktgen_parse(ark->pkt_gen_args);
996 ark_pktgen_reset(ark->pg);
997 ark_pktgen_setup(ark->pg);
1001 /* Setup the packet checker */
1002 if (ark->pkt_chkr_args[0]) {
1003 ark_pktchkr_parse(ark->pkt_chkr_args);
1004 ark_pktchkr_setup(ark->pc);
1010 rte_kvargs_free(kvlist);
1015 RTE_PMD_REGISTER_PCI(net_ark, rte_ark_pmd);
1016 RTE_PMD_REGISTER_KMOD_DEP(net_ark, "* igb_uio | uio_pci_generic ");
1017 RTE_PMD_REGISTER_PCI_TABLE(net_ark, pci_id_ark_map);
1018 RTE_PMD_REGISTER_PARAM_STRING(net_ark,
1019 ARK_PKTGEN_ARG "=<filename> "
1020 ARK_PKTCHKR_ARG "=<filename> "
1021 ARK_PKTDIR_ARG "=<bitmap>");