4 * Copyright (C) Cavium Inc. 2017. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium networks nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <rte_alarm.h>
40 #include <rte_branch_prediction.h>
41 #include <rte_debug.h>
42 #include <rte_devargs.h>
44 #include <rte_kvargs.h>
45 #include <rte_malloc.h>
46 #include <rte_prefetch.h>
49 #include "octeontx_ethdev.h"
50 #include "octeontx_logs.h"
52 struct octeontx_vdev_init_params {
56 /* Parse integer from integer argument */
58 parse_integer_arg(const char *key __rte_unused,
59 const char *value, void *extra_args)
61 int *i = (int *)extra_args;
65 octeontx_log_err("argument has to be positive.");
73 octeontx_parse_vdev_init_params(struct octeontx_vdev_init_params *params,
74 struct rte_vdev_device *dev)
76 struct rte_kvargs *kvlist = NULL;
79 static const char * const octeontx_vdev_valid_params[] = {
80 OCTEONTX_VDEV_NR_PORT_ARG,
84 const char *input_args = rte_vdev_device_args(dev);
90 kvlist = rte_kvargs_parse(input_args,
91 octeontx_vdev_valid_params);
95 ret = rte_kvargs_process(kvlist,
96 OCTEONTX_VDEV_NR_PORT_ARG,
104 rte_kvargs_free(kvlist);
109 octeontx_port_open(struct octeontx_nic *nic)
111 octeontx_mbox_bgx_port_conf_t bgx_port_conf;
116 PMD_INIT_FUNC_TRACE();
118 res = octeontx_bgx_port_open(nic->port_id, &bgx_port_conf);
120 octeontx_log_err("failed to open port %d", res);
124 nic->node = bgx_port_conf.node;
125 nic->port_ena = bgx_port_conf.enable;
126 nic->base_ichan = bgx_port_conf.base_chan;
127 nic->base_ochan = bgx_port_conf.base_chan;
128 nic->num_ichans = bgx_port_conf.num_chans;
129 nic->num_ochans = bgx_port_conf.num_chans;
130 nic->mtu = bgx_port_conf.mtu;
131 nic->bpen = bgx_port_conf.bpen;
132 nic->fcs_strip = bgx_port_conf.fcs_strip;
133 nic->bcast_mode = bgx_port_conf.bcast_mode;
134 nic->mcast_mode = bgx_port_conf.mcast_mode;
135 nic->speed = bgx_port_conf.mode;
137 memcpy(&nic->mac_addr[0], &bgx_port_conf.macaddr[0], ETHER_ADDR_LEN);
139 octeontx_log_dbg("port opened %d", nic->port_id);
144 octeontx_port_close(struct octeontx_nic *nic)
146 PMD_INIT_FUNC_TRACE();
148 octeontx_bgx_port_close(nic->port_id);
149 octeontx_log_dbg("port closed %d", nic->port_id);
153 devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
154 struct rte_event_dev_info *info)
156 memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
157 dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
159 dev_conf->nb_event_ports = info->max_event_ports;
160 dev_conf->nb_event_queues = info->max_event_queues;
162 dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
163 dev_conf->nb_event_port_dequeue_depth =
164 info->max_event_port_dequeue_depth;
165 dev_conf->nb_event_port_enqueue_depth =
166 info->max_event_port_enqueue_depth;
167 dev_conf->nb_event_port_enqueue_depth =
168 info->max_event_port_enqueue_depth;
169 dev_conf->nb_events_limit =
170 info->max_num_events;
174 octeontx_dev_configure(struct rte_eth_dev *dev)
176 struct rte_eth_dev_data *data = dev->data;
177 struct rte_eth_conf *conf = &data->dev_conf;
178 struct rte_eth_rxmode *rxmode = &conf->rxmode;
179 struct rte_eth_txmode *txmode = &conf->txmode;
180 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
183 PMD_INIT_FUNC_TRACE();
186 if (!rte_eal_has_hugepages()) {
187 octeontx_log_err("huge page is not configured");
191 if (txmode->mq_mode) {
192 octeontx_log_err("tx mq_mode DCB or VMDq not supported");
196 if (rxmode->mq_mode != ETH_MQ_RX_NONE &&
197 rxmode->mq_mode != ETH_MQ_RX_RSS) {
198 octeontx_log_err("unsupported rx qmode %d", rxmode->mq_mode);
202 if (!rxmode->hw_strip_crc) {
203 PMD_INIT_LOG(NOTICE, "can't disable hw crc strip");
204 rxmode->hw_strip_crc = 1;
207 if (rxmode->hw_ip_checksum) {
208 PMD_INIT_LOG(NOTICE, "rxcksum not supported");
209 rxmode->hw_ip_checksum = 0;
212 if (rxmode->split_hdr_size) {
213 octeontx_log_err("rxmode does not support split header");
217 if (rxmode->hw_vlan_filter) {
218 octeontx_log_err("VLAN filter not supported");
222 if (rxmode->hw_vlan_extend) {
223 octeontx_log_err("VLAN extended not supported");
227 if (rxmode->enable_lro) {
228 octeontx_log_err("LRO not supported");
232 if (conf->link_speeds & ETH_LINK_SPEED_FIXED) {
233 octeontx_log_err("setting link speed/duplex not supported");
237 if (conf->dcb_capability_en) {
238 octeontx_log_err("DCB enable not supported");
242 if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) {
243 octeontx_log_err("flow director not supported");
247 nic->num_tx_queues = dev->data->nb_tx_queues;
249 ret = octeontx_pko_channel_open(nic->port_id * PKO_VF_NUM_DQ,
253 octeontx_log_err("failed to open channel %d no-of-txq %d",
254 nic->base_ochan, nic->num_tx_queues);
258 nic->pki.classifier_enable = false;
259 nic->pki.hash_enable = true;
260 nic->pki.initialized = false;
265 /* Initialize and register driver with DPDK Application */
266 static const struct eth_dev_ops octeontx_dev_ops = {
267 .dev_configure = octeontx_dev_configure,
270 /* Create Ethdev interface per BGX LMAC ports */
272 octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
276 char octtx_name[OCTEONTX_MAX_NAME_LEN];
277 struct octeontx_nic *nic = NULL;
278 struct rte_eth_dev *eth_dev = NULL;
279 struct rte_eth_dev_data *data = NULL;
280 const char *name = rte_vdev_device_name(dev);
282 PMD_INIT_FUNC_TRACE();
284 sprintf(octtx_name, "%s_%d", name, port);
285 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
286 eth_dev = rte_eth_dev_attach_secondary(octtx_name);
293 data = rte_zmalloc_socket(octtx_name, sizeof(*data), 0, socket_id);
295 octeontx_log_err("failed to allocate devdata");
300 nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id);
302 octeontx_log_err("failed to allocate nic structure");
310 res = octeontx_port_open(nic);
314 /* Rx side port configuration */
315 res = octeontx_pki_port_open(port);
317 octeontx_log_err("failed to open PKI port %d", port);
322 /* Reserve an ethdev entry */
323 eth_dev = rte_eth_dev_allocate(octtx_name);
324 if (eth_dev == NULL) {
325 octeontx_log_err("failed to allocate rte_eth_dev");
330 eth_dev->device = &dev->device;
331 eth_dev->intr_handle = NULL;
332 eth_dev->data->kdrv = RTE_KDRV_NONE;
333 eth_dev->data->numa_node = dev->device.numa_node;
335 rte_memcpy(data, (eth_dev)->data, sizeof(*data));
336 data->dev_private = nic;
338 data->port_id = eth_dev->data->port_id;
339 snprintf(data->name, sizeof(data->name), "%s", eth_dev->data->name);
344 data->dev_link.link_status = ETH_LINK_DOWN;
345 data->dev_started = 0;
346 data->promiscuous = 0;
347 data->all_multicast = 0;
348 data->scattered_rx = 0;
350 data->mac_addrs = rte_zmalloc_socket(octtx_name, ETHER_ADDR_LEN, 0,
352 if (data->mac_addrs == NULL) {
353 octeontx_log_err("failed to allocate memory for mac_addrs");
358 eth_dev->data = data;
359 eth_dev->dev_ops = &octeontx_dev_ops;
361 /* Finally save ethdev pointer to the NIC structure */
364 if (nic->port_id != data->port_id) {
365 octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
366 data->port_id, nic->port_id);
371 /* Update port_id mac to eth_dev */
372 memcpy(data->mac_addrs, nic->mac_addr, ETHER_ADDR_LEN);
374 PMD_INIT_LOG(DEBUG, "ethdev info: ");
375 PMD_INIT_LOG(DEBUG, "port %d, port_ena %d ochan %d num_ochan %d tx_q %d",
376 nic->port_id, nic->port_ena,
377 nic->base_ochan, nic->num_ochans,
379 PMD_INIT_LOG(DEBUG, "speed %d mtu %d", nic->speed, nic->mtu);
381 return data->port_id;
385 octeontx_port_close(nic);
387 if (eth_dev != NULL) {
388 rte_free(eth_dev->data->mac_addrs);
391 rte_eth_dev_release_port(eth_dev);
397 /* Un initialize octeontx device */
399 octeontx_remove(struct rte_vdev_device *dev)
401 char octtx_name[OCTEONTX_MAX_NAME_LEN];
402 struct rte_eth_dev *eth_dev = NULL;
403 struct octeontx_nic *nic = NULL;
409 for (i = 0; i < OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT; i++) {
410 sprintf(octtx_name, "eth_octeontx_%d", i);
412 /* reserve an ethdev entry */
413 eth_dev = rte_eth_dev_allocated(octtx_name);
417 nic = octeontx_pmd_priv(eth_dev);
418 rte_event_dev_stop(nic->evdev);
419 PMD_INIT_LOG(INFO, "Closing octeontx device %s", octtx_name);
421 rte_free(eth_dev->data->mac_addrs);
422 rte_free(eth_dev->data->dev_private);
423 rte_free(eth_dev->data);
424 rte_eth_dev_release_port(eth_dev);
425 rte_event_dev_close(nic->evdev);
428 /* Free FC resource */
429 octeontx_pko_fc_free();
434 /* Initialize octeontx device */
436 octeontx_probe(struct rte_vdev_device *dev)
438 const char *dev_name;
439 static int probe_once;
440 uint8_t socket_id, qlist;
441 int tx_vfcnt, port_id, evdev, qnum, pnum, res, i;
442 struct rte_event_dev_config dev_conf;
443 const char *eventdev_name = "event_octeontx";
444 struct rte_event_dev_info info;
446 struct octeontx_vdev_init_params init_params = {
447 OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT
450 dev_name = rte_vdev_device_name(dev);
451 res = octeontx_parse_vdev_init_params(&init_params, dev);
455 if (init_params.nr_port > OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT) {
456 octeontx_log_err("nr_port (%d) > max (%d)", init_params.nr_port,
457 OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT);
461 PMD_INIT_LOG(DEBUG, "initializing %s pmd", dev_name);
463 socket_id = rte_socket_id();
465 tx_vfcnt = octeontx_pko_vf_count();
467 if (tx_vfcnt < init_params.nr_port) {
468 octeontx_log_err("not enough PKO (%d) for port number (%d)",
469 tx_vfcnt, init_params.nr_port);
472 evdev = rte_event_dev_get_dev_id(eventdev_name);
474 octeontx_log_err("eventdev %s not found", eventdev_name);
478 res = rte_event_dev_info_get(evdev, &info);
480 octeontx_log_err("failed to eventdev info %d", res);
484 PMD_INIT_LOG(DEBUG, "max_queue %d max_port %d",
485 info.max_event_queues, info.max_event_ports);
487 if (octeontx_pko_init_fc(tx_vfcnt))
490 devconf_set_default_sane_values(&dev_conf, &info);
491 res = rte_event_dev_configure(evdev, &dev_conf);
495 rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_PORT_COUNT,
497 rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_QUEUE_COUNT,
500 octeontx_log_err("too few event ports (%d) for event_q(%d)",
507 * We don't poll on event ports
508 * that do not have any queues assigned.
512 "reducing number of active event ports to %d", pnum);
514 for (i = 0; i < qnum; i++) {
515 res = rte_event_queue_setup(evdev, i, NULL);
517 octeontx_log_err("failed to setup event_q(%d): res %d",
523 for (i = 0; i < pnum; i++) {
524 res = rte_event_port_setup(evdev, i, NULL);
527 octeontx_log_err("failed to setup ev port(%d) res=%d",
531 /* Link one queue to one event port */
533 res = rte_event_port_link(evdev, i, &qlist, NULL, 1);
536 octeontx_log_err("failed to link port (%d): res=%d",
542 /* Create ethdev interface */
543 for (i = 0; i < init_params.nr_port; i++) {
544 port_id = octeontx_create(dev, i, evdev, socket_id);
546 octeontx_log_err("failed to create device %s",
552 PMD_INIT_LOG(INFO, "created ethdev %s for port %d", dev_name,
557 octeontx_log_err("interface %s not supported", dev_name);
558 octeontx_remove(dev);
567 octeontx_pko_fc_free();
571 static struct rte_vdev_driver octeontx_pmd_drv = {
572 .probe = octeontx_probe,
573 .remove = octeontx_remove,
576 RTE_PMD_REGISTER_VDEV(OCTEONTX_PMD, octeontx_pmd_drv);
577 RTE_PMD_REGISTER_ALIAS(OCTEONTX_PMD, eth_octeontx);
578 RTE_PMD_REGISTER_PARAM_STRING(OCTEONTX_PMD, "nr_port=<int> ");