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"
45 /* Internal prototypes */
46 static int eth_ark_check_args(struct ark_adapter *ark, const char *params);
47 static int eth_ark_dev_init(struct rte_eth_dev *dev);
48 static int eth_ark_dev_uninit(struct rte_eth_dev *eth_dev);
49 static int eth_ark_dev_configure(struct rte_eth_dev *dev);
50 static void eth_ark_dev_info_get(struct rte_eth_dev *dev,
51 struct rte_eth_dev_info *dev_info);
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 static const struct rte_pci_id pci_id_ark_map[] = {
89 {RTE_PCI_DEVICE(0x1d6c, 0x100d)},
90 {RTE_PCI_DEVICE(0x1d6c, 0x100e)},
91 {.vendor_id = 0, /* sentinel */ },
95 eth_ark_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
96 struct rte_pci_device *pci_dev)
98 struct rte_eth_dev *eth_dev;
101 eth_dev = rte_eth_dev_pci_allocate(pci_dev, sizeof(struct ark_adapter));
106 ret = eth_ark_dev_init(eth_dev);
108 rte_eth_dev_pci_release(eth_dev);
114 eth_ark_pci_remove(struct rte_pci_device *pci_dev)
116 return rte_eth_dev_pci_generic_remove(pci_dev, eth_ark_dev_uninit);
119 static struct rte_pci_driver rte_ark_pmd = {
120 .id_table = pci_id_ark_map,
121 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
122 .probe = eth_ark_pci_probe,
123 .remove = eth_ark_pci_remove,
126 static const struct eth_dev_ops ark_eth_dev_ops = {
127 .dev_configure = eth_ark_dev_configure,
128 .dev_infos_get = eth_ark_dev_info_get,
132 eth_ark_dev_init(struct rte_eth_dev *dev)
134 struct ark_adapter *ark =
135 (struct ark_adapter *)dev->data->dev_private;
136 struct rte_pci_device *pci_dev;
141 PMD_FUNC_LOG(DEBUG, "\n");
143 pci_dev = ARK_DEV_TO_PCI(dev);
144 rte_eth_copy_pci_info(dev, pci_dev);
146 ark->bar0 = (uint8_t *)pci_dev->mem_resource[0].addr;
147 ark->a_bar = (uint8_t *)pci_dev->mem_resource[2].addr;
149 dev->dev_ops = &ark_eth_dev_ops;
150 dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
152 if (pci_dev->device.devargs)
153 ret = eth_ark_check_args(ark, pci_dev->device.devargs->args);
155 PMD_DRV_LOG(INFO, "No Device args found\n");
161 eth_ark_dev_uninit(struct rte_eth_dev *dev)
163 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
167 dev->rx_pkt_burst = NULL;
168 dev->tx_pkt_burst = NULL;
173 eth_ark_dev_configure(struct rte_eth_dev *dev __rte_unused)
175 PMD_FUNC_LOG(DEBUG, "\n");
180 eth_ark_dev_info_get(struct rte_eth_dev *dev,
181 struct rte_eth_dev_info *dev_info)
183 dev_info->max_rx_pktlen = ARK_RX_MAX_PKT_LEN;
184 dev_info->min_rx_bufsize = ARK_RX_MIN_BUFSIZE;
186 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
187 .nb_max = ARK_RX_MAX_QUEUE,
188 .nb_min = ARK_RX_MIN_QUEUE,
189 .nb_align = ARK_RX_MIN_QUEUE}; /* power of 2 */
191 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
192 .nb_max = ARK_TX_MAX_QUEUE,
193 .nb_min = ARK_TX_MIN_QUEUE,
194 .nb_align = ARK_TX_MIN_QUEUE}; /* power of 2 */
196 /* ARK PMD supports all line rates, how do we indicate that here ?? */
197 dev_info->speed_capa = (ETH_LINK_SPEED_1G |
202 ETH_LINK_SPEED_100G);
203 dev_info->pci_dev = ARK_DEV_TO_PCI(dev);
207 process_pktdir_arg(const char *key, const char *value,
210 PMD_FUNC_LOG(DEBUG, "key = %s, value = %s\n",
212 struct ark_adapter *ark =
213 (struct ark_adapter *)extra_args;
215 ark->pkt_dir_v = strtol(value, NULL, 16);
216 PMD_FUNC_LOG(DEBUG, "pkt_dir_v = 0x%x\n", ark->pkt_dir_v);
221 process_file_args(const char *key, const char *value, void *extra_args)
223 PMD_FUNC_LOG(DEBUG, "key = %s, value = %s\n",
225 char *args = (char *)extra_args;
227 /* Open the configuration file */
228 FILE *file = fopen(value, "r");
229 char line[ARK_MAX_ARG_LEN];
233 while (fgets(line, sizeof(line), file)) {
234 size += strlen(line);
235 if (size >= ARK_MAX_ARG_LEN) {
236 PMD_DRV_LOG(ERR, "Unable to parse file %s args, "
237 "parameter list is too long\n", value);
242 strncpy(args, line, ARK_MAX_ARG_LEN);
245 strncat(args, line, ARK_MAX_ARG_LEN);
248 PMD_FUNC_LOG(DEBUG, "file = %s\n", args);
254 eth_ark_check_args(struct ark_adapter *ark, const char *params)
256 struct rte_kvargs *kvlist;
258 struct rte_kvargs_pair *pair = NULL;
260 kvlist = rte_kvargs_parse(params, valid_arguments);
264 ark->pkt_gen_args[0] = 0;
265 ark->pkt_chkr_args[0] = 0;
267 for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
268 pair = &kvlist->pairs[k_idx];
269 PMD_FUNC_LOG(DEBUG, "**** Arg passed to PMD = %s:%s\n",
274 if (rte_kvargs_process(kvlist,
278 PMD_DRV_LOG(ERR, "Unable to parse arg %s\n", ARK_PKTDIR_ARG);
282 if (rte_kvargs_process(kvlist,
285 ark->pkt_gen_args) != 0) {
286 PMD_DRV_LOG(ERR, "Unable to parse arg %s\n", ARK_PKTGEN_ARG);
290 if (rte_kvargs_process(kvlist,
293 ark->pkt_chkr_args) != 0) {
294 PMD_DRV_LOG(ERR, "Unable to parse arg %s\n", ARK_PKTCHKR_ARG);
298 PMD_DRV_LOG(INFO, "packet director set to 0x%x\n", ark->pkt_dir_v);
303 RTE_PMD_REGISTER_PCI(net_ark, rte_ark_pmd);
304 RTE_PMD_REGISTER_KMOD_DEP(net_ark, "* igb_uio | uio_pci_generic ");
305 RTE_PMD_REGISTER_PCI_TABLE(net_ark, pci_id_ark_map);
306 RTE_PMD_REGISTER_PARAM_STRING(net_ark,
307 ARK_PKTGEN_ARG "=<filename> "
308 ARK_PKTCHKR_ARG "=<filename> "
309 ARK_PKTDIR_ARG "=<bitmap>");