2 * Copyright 2008-2014 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
5 * Copyright (c) 2014, Cisco Systems, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
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
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
41 #include <rte_ethdev.h>
42 #include <rte_string_fns.h>
44 #include "vnic_intr.h"
48 #include "vnic_enet.h"
51 #ifdef RTE_LIBRTE_ENIC_DEBUG
52 #define ENICPMD_FUNC_TRACE() \
53 RTE_LOG(DEBUG, PMD, "ENICPMD trace: %s\n", __func__)
55 #define ENICPMD_FUNC_TRACE() (void)0
59 * The set of PCI devices this driver supports
61 static struct rte_pci_id pci_id_enic_map[] = {
62 #define RTE_PCI_DEV_ID_DECL_ENIC(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
63 #ifndef PCI_VENDOR_ID_CISCO
64 #define PCI_VENDOR_ID_CISCO 0x1137
66 #include "rte_pci_dev_ids.h"
67 RTE_PCI_DEV_ID_DECL_ENIC(PCI_VENDOR_ID_CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET)
68 RTE_PCI_DEV_ID_DECL_ENIC(PCI_VENDOR_ID_CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET_VF)
69 {.vendor_id = 0, /* Sentinal */},
72 static int enicpmd_fdir_remove_perfect_filter(struct rte_eth_dev *eth_dev,
73 struct rte_fdir_filter *fdir_filter,
74 __rte_unused uint16_t soft_id)
76 struct enic *enic = pmd_priv(eth_dev);
79 return enic_fdir_del_fltr(enic, fdir_filter);
82 static int enicpmd_fdir_add_perfect_filter(struct rte_eth_dev *eth_dev,
83 struct rte_fdir_filter *fdir_filter, __rte_unused uint16_t soft_id,
84 uint8_t queue, uint8_t drop)
86 struct enic *enic = pmd_priv(eth_dev);
89 return enic_fdir_add_fltr(enic, fdir_filter, (uint16_t)queue, drop);
92 static void enicpmd_fdir_info_get(struct rte_eth_dev *eth_dev,
93 struct rte_eth_fdir *fdir)
95 struct enic *enic = pmd_priv(eth_dev);
98 *fdir = enic->fdir.stats;
101 static void enicpmd_dev_tx_queue_release(void *txq)
103 ENICPMD_FUNC_TRACE();
107 static int enicpmd_dev_setup_intr(struct enic *enic)
112 ENICPMD_FUNC_TRACE();
114 /* Are we done with the init of all the queues? */
115 for (index = 0; index < enic->cq_count; index++) {
116 if (!enic->cq[index].ctrl)
120 if (enic->cq_count != index)
123 ret = enic_alloc_intr_resources(enic);
125 dev_err(enic, "alloc intr failed\n");
128 enic_init_vnic_resources(enic);
130 ret = enic_setup_finish(enic);
132 dev_err(enic, "setup could not be finished\n");
137 static int enicpmd_dev_tx_queue_setup(struct rte_eth_dev *eth_dev,
140 unsigned int socket_id,
141 __rte_unused const struct rte_eth_txconf *tx_conf)
144 struct enic *enic = pmd_priv(eth_dev);
146 ENICPMD_FUNC_TRACE();
147 eth_dev->data->tx_queues[queue_idx] = (void *)&enic->wq[queue_idx];
149 ret = enic_alloc_wq(enic, queue_idx, socket_id, nb_desc);
151 dev_err(enic, "error in allocating wq\n");
155 return enicpmd_dev_setup_intr(enic);
158 static int enicpmd_dev_tx_queue_start(struct rte_eth_dev *eth_dev,
161 struct enic *enic = pmd_priv(eth_dev);
163 ENICPMD_FUNC_TRACE();
165 enic_start_wq(enic, queue_idx);
170 static int enicpmd_dev_tx_queue_stop(struct rte_eth_dev *eth_dev,
174 struct enic *enic = pmd_priv(eth_dev);
176 ENICPMD_FUNC_TRACE();
178 ret = enic_stop_wq(enic, queue_idx);
180 dev_err(enic, "error in stopping wq %d\n", queue_idx);
185 static int enicpmd_dev_rx_queue_start(struct rte_eth_dev *eth_dev,
188 struct enic *enic = pmd_priv(eth_dev);
190 ENICPMD_FUNC_TRACE();
192 enic_start_rq(enic, queue_idx);
197 static int enicpmd_dev_rx_queue_stop(struct rte_eth_dev *eth_dev,
201 struct enic *enic = pmd_priv(eth_dev);
203 ENICPMD_FUNC_TRACE();
205 ret = enic_stop_rq(enic, queue_idx);
207 dev_err(enic, "error in stopping rq %d\n", queue_idx);
212 static void enicpmd_dev_rx_queue_release(void *rxq)
214 ENICPMD_FUNC_TRACE();
218 static int enicpmd_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
221 unsigned int socket_id,
222 __rte_unused const struct rte_eth_rxconf *rx_conf,
223 struct rte_mempool *mp)
226 struct enic *enic = pmd_priv(eth_dev);
228 ENICPMD_FUNC_TRACE();
229 eth_dev->data->rx_queues[queue_idx] = (void *)&enic->rq[queue_idx];
231 ret = enic_alloc_rq(enic, queue_idx, socket_id, mp, nb_desc);
233 dev_err(enic, "error in allocating rq\n");
237 return enicpmd_dev_setup_intr(enic);
240 static int enicpmd_vlan_filter_set(struct rte_eth_dev *eth_dev,
241 uint16_t vlan_id, int on)
243 struct enic *enic = pmd_priv(eth_dev);
245 ENICPMD_FUNC_TRACE();
247 enic_add_vlan(enic, vlan_id);
249 enic_del_vlan(enic, vlan_id);
253 static void enicpmd_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
255 struct enic *enic = pmd_priv(eth_dev);
257 ENICPMD_FUNC_TRACE();
259 if (mask & ETH_VLAN_STRIP_MASK) {
260 if (eth_dev->data->dev_conf.rxmode.hw_vlan_strip)
261 enic->ig_vlan_strip_en = 1;
263 enic->ig_vlan_strip_en = 0;
265 enic_set_rss_nic_cfg(enic);
268 if (mask & ETH_VLAN_FILTER_MASK) {
270 "Configuration of VLAN filter is not supported\n");
273 if (mask & ETH_VLAN_EXTEND_MASK) {
275 "Configuration of extended VLAN is not supported\n");
279 static int enicpmd_dev_configure(struct rte_eth_dev *eth_dev)
282 struct enic *enic = pmd_priv(eth_dev);
284 ENICPMD_FUNC_TRACE();
285 ret = enic_set_vnic_res(enic);
287 dev_err(enic, "Set vNIC resource num failed, aborting\n");
291 if (eth_dev->data->dev_conf.rxmode.split_hdr_size &&
292 eth_dev->data->dev_conf.rxmode.header_split) {
293 /* Enable header-data-split */
294 enic_set_hdr_split_size(enic,
295 eth_dev->data->dev_conf.rxmode.split_hdr_size);
298 enic->hw_ip_checksum = eth_dev->data->dev_conf.rxmode.hw_ip_checksum;
303 * It returns 0 on success.
305 static int enicpmd_dev_start(struct rte_eth_dev *eth_dev)
307 struct enic *enic = pmd_priv(eth_dev);
309 ENICPMD_FUNC_TRACE();
310 return enic_enable(enic);
314 * Stop device: disable rx and tx functions to allow for reconfiguring.
316 static void enicpmd_dev_stop(struct rte_eth_dev *eth_dev)
318 struct rte_eth_link link;
319 struct enic *enic = pmd_priv(eth_dev);
321 ENICPMD_FUNC_TRACE();
323 memset(&link, 0, sizeof(link));
324 rte_atomic64_cmpset((uint64_t *)ð_dev->data->dev_link,
325 *(uint64_t *)ð_dev->data->dev_link,
332 static void enicpmd_dev_close(struct rte_eth_dev *eth_dev)
334 struct enic *enic = pmd_priv(eth_dev);
336 ENICPMD_FUNC_TRACE();
340 static int enicpmd_dev_link_update(struct rte_eth_dev *eth_dev,
341 __rte_unused int wait_to_complete)
343 struct enic *enic = pmd_priv(eth_dev);
347 ENICPMD_FUNC_TRACE();
348 link_status = enic_get_link_status(enic);
349 ret = (link_status == enic->link_status);
350 enic->link_status = link_status;
351 eth_dev->data->dev_link.link_status = link_status;
352 eth_dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
353 eth_dev->data->dev_link.link_speed = vnic_dev_port_speed(enic->vdev);
357 static void enicpmd_dev_stats_get(struct rte_eth_dev *eth_dev,
358 struct rte_eth_stats *stats)
360 struct enic *enic = pmd_priv(eth_dev);
362 ENICPMD_FUNC_TRACE();
363 enic_dev_stats_get(enic, stats);
366 static void enicpmd_dev_stats_reset(struct rte_eth_dev *eth_dev)
368 struct enic *enic = pmd_priv(eth_dev);
370 ENICPMD_FUNC_TRACE();
371 enic_dev_stats_clear(enic);
374 static void enicpmd_dev_info_get(struct rte_eth_dev *eth_dev,
375 struct rte_eth_dev_info *device_info)
377 struct enic *enic = pmd_priv(eth_dev);
379 ENICPMD_FUNC_TRACE();
380 device_info->max_rx_queues = enic->rq_count;
381 device_info->max_tx_queues = enic->wq_count;
382 device_info->min_rx_bufsize = ENIC_MIN_MTU;
383 device_info->max_rx_pktlen = enic->config.mtu;
384 device_info->max_mac_addrs = 1;
385 device_info->rx_offload_capa =
386 DEV_RX_OFFLOAD_VLAN_STRIP |
387 DEV_RX_OFFLOAD_IPV4_CKSUM |
388 DEV_RX_OFFLOAD_UDP_CKSUM |
389 DEV_RX_OFFLOAD_TCP_CKSUM;
390 device_info->tx_offload_capa =
391 DEV_TX_OFFLOAD_VLAN_INSERT |
392 DEV_TX_OFFLOAD_IPV4_CKSUM |
393 DEV_TX_OFFLOAD_UDP_CKSUM |
394 DEV_TX_OFFLOAD_TCP_CKSUM;
397 static void enicpmd_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
399 struct enic *enic = pmd_priv(eth_dev);
401 ENICPMD_FUNC_TRACE();
403 enic_add_packet_filter(enic);
406 static void enicpmd_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
408 struct enic *enic = pmd_priv(eth_dev);
410 ENICPMD_FUNC_TRACE();
412 enic_add_packet_filter(enic);
415 static void enicpmd_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
417 struct enic *enic = pmd_priv(eth_dev);
419 ENICPMD_FUNC_TRACE();
421 enic_add_packet_filter(enic);
424 static void enicpmd_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
426 struct enic *enic = pmd_priv(eth_dev);
428 ENICPMD_FUNC_TRACE();
430 enic_add_packet_filter(enic);
433 static void enicpmd_add_mac_addr(struct rte_eth_dev *eth_dev,
434 struct ether_addr *mac_addr,
435 __rte_unused uint32_t index, __rte_unused uint32_t pool)
437 struct enic *enic = pmd_priv(eth_dev);
439 ENICPMD_FUNC_TRACE();
440 enic_set_mac_address(enic, mac_addr->addr_bytes);
443 static void enicpmd_remove_mac_addr(struct rte_eth_dev *eth_dev, __rte_unused uint32_t index)
445 struct enic *enic = pmd_priv(eth_dev);
447 ENICPMD_FUNC_TRACE();
448 enic_del_mac_address(enic);
452 static uint16_t enicpmd_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
457 unsigned int pkt_len;
458 unsigned int seg_len;
459 unsigned int inc_len;
460 unsigned int nb_segs;
461 struct rte_mbuf *tx_pkt;
462 struct vnic_wq *wq = (struct vnic_wq *)tx_queue;
463 struct enic *enic = vnic_dev_priv(wq->vdev);
464 unsigned short vlan_id;
465 unsigned short ol_flags;
467 for (index = 0; index < nb_pkts; index++) {
470 nb_segs = tx_pkt->nb_segs;
471 if (nb_segs > vnic_wq_desc_avail(wq)) {
472 /* wq cleanup and try again */
473 if (!enic_cleanup_wq(enic, wq) ||
474 (nb_segs > vnic_wq_desc_avail(wq)))
477 pkt_len = tx_pkt->pkt_len;
478 vlan_id = tx_pkt->vlan_tci;
479 ol_flags = tx_pkt->ol_flags;
480 for (frags = 0; inc_len < pkt_len; frags++) {
483 seg_len = tx_pkt->data_len;
485 if (enic_send_pkt(enic, wq, tx_pkt,
486 (unsigned short)seg_len, !frags,
487 (pkt_len == inc_len), ol_flags, vlan_id)) {
490 tx_pkt = tx_pkt->next;
494 enic_cleanup_wq(enic, wq);
498 static uint16_t enicpmd_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
501 struct vnic_rq *rq = (struct vnic_rq *)rx_queue;
502 unsigned int work_done;
504 if (enic_poll(rq, rx_pkts, (unsigned int)nb_pkts, &work_done))
505 dev_err(enic, "error in enicpmd poll\n");
510 static const struct eth_dev_ops enicpmd_eth_dev_ops = {
511 .dev_configure = enicpmd_dev_configure,
512 .dev_start = enicpmd_dev_start,
513 .dev_stop = enicpmd_dev_stop,
514 .dev_set_link_up = NULL,
515 .dev_set_link_down = NULL,
516 .dev_close = enicpmd_dev_close,
517 .promiscuous_enable = enicpmd_dev_promiscuous_enable,
518 .promiscuous_disable = enicpmd_dev_promiscuous_disable,
519 .allmulticast_enable = enicpmd_dev_allmulticast_enable,
520 .allmulticast_disable = enicpmd_dev_allmulticast_disable,
521 .link_update = enicpmd_dev_link_update,
522 .stats_get = enicpmd_dev_stats_get,
523 .stats_reset = enicpmd_dev_stats_reset,
524 .queue_stats_mapping_set = NULL,
525 .dev_infos_get = enicpmd_dev_info_get,
527 .vlan_filter_set = enicpmd_vlan_filter_set,
528 .vlan_tpid_set = NULL,
529 .vlan_offload_set = enicpmd_vlan_offload_set,
530 .vlan_strip_queue_set = NULL,
531 .rx_queue_start = enicpmd_dev_rx_queue_start,
532 .rx_queue_stop = enicpmd_dev_rx_queue_stop,
533 .tx_queue_start = enicpmd_dev_tx_queue_start,
534 .tx_queue_stop = enicpmd_dev_tx_queue_stop,
535 .rx_queue_setup = enicpmd_dev_rx_queue_setup,
536 .rx_queue_release = enicpmd_dev_rx_queue_release,
537 .rx_queue_count = NULL,
538 .rx_descriptor_done = NULL,
539 .tx_queue_setup = enicpmd_dev_tx_queue_setup,
540 .tx_queue_release = enicpmd_dev_tx_queue_release,
543 .flow_ctrl_get = NULL,
544 .flow_ctrl_set = NULL,
545 .priority_flow_ctrl_set = NULL,
546 .mac_addr_add = enicpmd_add_mac_addr,
547 .mac_addr_remove = enicpmd_remove_mac_addr,
548 .fdir_add_signature_filter = NULL,
549 .fdir_update_signature_filter = NULL,
550 .fdir_remove_signature_filter = NULL,
551 .fdir_infos_get = enicpmd_fdir_info_get,
552 .fdir_add_perfect_filter = enicpmd_fdir_add_perfect_filter,
553 .fdir_update_perfect_filter = enicpmd_fdir_add_perfect_filter,
554 .fdir_remove_perfect_filter = enicpmd_fdir_remove_perfect_filter,
555 .fdir_set_masks = NULL,
558 struct enic *enicpmd_list_head = NULL;
559 /* Initialize the driver
560 * It returns 0 on success.
562 static int eth_enicpmd_dev_init(struct rte_eth_dev *eth_dev)
564 struct rte_pci_device *pdev;
565 struct rte_pci_addr *addr;
566 struct enic *enic = pmd_priv(eth_dev);
568 ENICPMD_FUNC_TRACE();
570 enic->port_id = eth_dev->data->port_id;
571 enic->rte_dev = eth_dev;
572 eth_dev->dev_ops = &enicpmd_eth_dev_ops;
573 eth_dev->rx_pkt_burst = &enicpmd_recv_pkts;
574 eth_dev->tx_pkt_burst = &enicpmd_xmit_pkts;
576 pdev = eth_dev->pci_dev;
580 snprintf(enic->bdf_name, ENICPMD_BDF_LENGTH, "%04x:%02x:%02x.%x",
581 addr->domain, addr->bus, addr->devid, addr->function);
583 return enic_probe(enic);
586 static struct eth_driver rte_enic_pmd = {
588 .name = "rte_enic_pmd",
589 .id_table = pci_id_enic_map,
590 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
592 .eth_dev_init = eth_enicpmd_dev_init,
593 .dev_private_size = sizeof(struct enic),
596 /* Driver initialization routine.
597 * Invoked once at EAL init time.
598 * Register as the [Poll Mode] Driver of Cisco ENIC device.
601 rte_enic_pmd_init(const char *name __rte_unused,
602 const char *params __rte_unused)
604 ENICPMD_FUNC_TRACE();
606 rte_eth_driver_register(&rte_enic_pmd);
610 static struct rte_driver rte_enic_driver = {
612 .init = rte_enic_pmd_init,
615 PMD_REGISTER_DRIVER(rte_enic_driver);