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 #define ENICPMD_FUNC_TRACE() \
52 RTE_LOG(DEBUG, PMD, "ENICPMD trace: %s\n", __func__)
55 * The set of PCI devices this driver supports
57 static struct rte_pci_id pci_id_enic_map[] = {
58 #define RTE_PCI_DEV_ID_DECL_ENIC(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
59 #ifndef PCI_VENDOR_ID_CISCO
60 #define PCI_VENDOR_ID_CISCO 0x1137
62 #include "rte_pci_dev_ids.h"
63 RTE_PCI_DEV_ID_DECL_ENIC(PCI_VENDOR_ID_CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET)
64 RTE_PCI_DEV_ID_DECL_ENIC(PCI_VENDOR_ID_CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET_VF)
65 {.vendor_id = 0, /* Sentinal */},
68 static int enicpmd_fdir_remove_perfect_filter(struct rte_eth_dev *eth_dev,
69 struct rte_fdir_filter *fdir_filter,
70 __rte_unused uint16_t soft_id)
72 struct enic *enic = pmd_priv(eth_dev);
75 return enic_fdir_del_fltr(enic, fdir_filter);
78 static int enicpmd_fdir_add_perfect_filter(struct rte_eth_dev *eth_dev,
79 struct rte_fdir_filter *fdir_filter, __rte_unused uint16_t soft_id,
80 uint8_t queue, uint8_t drop)
82 struct enic *enic = pmd_priv(eth_dev);
85 return enic_fdir_add_fltr(enic, fdir_filter, (uint16_t)queue, drop);
88 static void enicpmd_fdir_info_get(struct rte_eth_dev *eth_dev,
89 struct rte_eth_fdir *fdir)
91 struct enic *enic = pmd_priv(eth_dev);
94 *fdir = enic->fdir.stats;
97 static void enicpmd_dev_tx_queue_release(void *txq)
103 static int enicpmd_dev_setup_intr(struct enic *enic)
108 ENICPMD_FUNC_TRACE();
110 /* Are we done with the init of all the queues? */
111 for (index = 0; index < enic->cq_count; index++) {
112 if (!enic->cq[index].ctrl)
116 if (enic->cq_count != index)
119 ret = enic_alloc_intr_resources(enic);
121 dev_err(enic, "alloc intr failed\n");
124 enic_init_vnic_resources(enic);
126 ret = enic_setup_finish(enic);
128 dev_err(enic, "setup could not be finished\n");
133 static int enicpmd_dev_tx_queue_setup(struct rte_eth_dev *eth_dev,
136 unsigned int socket_id,
137 __rte_unused const struct rte_eth_txconf *tx_conf)
140 struct enic *enic = pmd_priv(eth_dev);
142 ENICPMD_FUNC_TRACE();
143 eth_dev->data->tx_queues[queue_idx] = (void *)&enic->wq[queue_idx];
145 ret = enic_alloc_wq(enic, queue_idx, socket_id, nb_desc);
147 dev_err(enic, "error in allocating wq\n");
151 return enicpmd_dev_setup_intr(enic);
154 static int enicpmd_dev_tx_queue_start(struct rte_eth_dev *eth_dev,
157 struct enic *enic = pmd_priv(eth_dev);
159 ENICPMD_FUNC_TRACE();
161 enic_start_wq(enic, queue_idx);
166 static int enicpmd_dev_tx_queue_stop(struct rte_eth_dev *eth_dev,
170 struct enic *enic = pmd_priv(eth_dev);
172 ENICPMD_FUNC_TRACE();
174 ret = enic_stop_wq(enic, queue_idx);
176 dev_err(enic, "error in stopping wq %d\n", queue_idx);
181 static int enicpmd_dev_rx_queue_start(struct rte_eth_dev *eth_dev,
184 struct enic *enic = pmd_priv(eth_dev);
186 ENICPMD_FUNC_TRACE();
188 enic_start_rq(enic, queue_idx);
193 static int enicpmd_dev_rx_queue_stop(struct rte_eth_dev *eth_dev,
197 struct enic *enic = pmd_priv(eth_dev);
199 ENICPMD_FUNC_TRACE();
201 ret = enic_stop_rq(enic, queue_idx);
203 dev_err(enic, "error in stopping rq %d\n", queue_idx);
208 static void enicpmd_dev_rx_queue_release(void *rxq)
210 ENICPMD_FUNC_TRACE();
214 static int enicpmd_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
217 unsigned int socket_id,
218 __rte_unused const struct rte_eth_rxconf *rx_conf,
219 struct rte_mempool *mp)
222 struct enic *enic = pmd_priv(eth_dev);
224 ENICPMD_FUNC_TRACE();
225 eth_dev->data->rx_queues[queue_idx] = (void *)&enic->rq[queue_idx];
227 ret = enic_alloc_rq(enic, queue_idx, socket_id, mp, nb_desc);
229 dev_err(enic, "error in allocating rq\n");
233 return enicpmd_dev_setup_intr(enic);
236 static int enicpmd_vlan_filter_set(struct rte_eth_dev *eth_dev,
237 uint16_t vlan_id, int on)
239 struct enic *enic = pmd_priv(eth_dev);
241 ENICPMD_FUNC_TRACE();
243 enic_add_vlan(enic, vlan_id);
245 enic_del_vlan(enic, vlan_id);
249 static void enicpmd_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
251 struct enic *enic = pmd_priv(eth_dev);
253 ENICPMD_FUNC_TRACE();
255 if (mask & ETH_VLAN_STRIP_MASK) {
256 if (eth_dev->data->dev_conf.rxmode.hw_vlan_strip)
257 enic->ig_vlan_strip_en = 1;
259 enic->ig_vlan_strip_en = 0;
261 enic_set_rss_nic_cfg(enic);
264 if (mask & ETH_VLAN_FILTER_MASK) {
266 "Configuration of VLAN filter is not supported\n");
269 if (mask & ETH_VLAN_EXTEND_MASK) {
271 "Configuration of extended VLAN is not supported\n");
275 static int enicpmd_dev_configure(struct rte_eth_dev *eth_dev)
278 struct enic *enic = pmd_priv(eth_dev);
280 ENICPMD_FUNC_TRACE();
281 ret = enic_set_vnic_res(enic);
283 dev_err(enic, "Set vNIC resource num failed, aborting\n");
287 if (eth_dev->data->dev_conf.rxmode.split_hdr_size &&
288 eth_dev->data->dev_conf.rxmode.header_split) {
289 /* Enable header-data-split */
290 enic_set_hdr_split_size(enic,
291 eth_dev->data->dev_conf.rxmode.split_hdr_size);
294 enic->hw_ip_checksum = eth_dev->data->dev_conf.rxmode.hw_ip_checksum;
299 * It returns 0 on success.
301 static int enicpmd_dev_start(struct rte_eth_dev *eth_dev)
303 struct enic *enic = pmd_priv(eth_dev);
305 ENICPMD_FUNC_TRACE();
306 return enic_enable(enic);
310 * Stop device: disable rx and tx functions to allow for reconfiguring.
312 static void enicpmd_dev_stop(struct rte_eth_dev *eth_dev)
314 struct rte_eth_link link;
315 struct enic *enic = pmd_priv(eth_dev);
317 ENICPMD_FUNC_TRACE();
319 memset(&link, 0, sizeof(link));
320 rte_atomic64_cmpset((uint64_t *)ð_dev->data->dev_link,
321 *(uint64_t *)ð_dev->data->dev_link,
328 static void enicpmd_dev_close(struct rte_eth_dev *eth_dev)
330 struct enic *enic = pmd_priv(eth_dev);
332 ENICPMD_FUNC_TRACE();
336 static int enicpmd_dev_link_update(struct rte_eth_dev *eth_dev,
337 __rte_unused int wait_to_complete)
339 struct enic *enic = pmd_priv(eth_dev);
343 ENICPMD_FUNC_TRACE();
344 link_status = enic_get_link_status(enic);
345 ret = (link_status == enic->link_status);
346 enic->link_status = link_status;
347 eth_dev->data->dev_link.link_status = link_status;
348 eth_dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
349 eth_dev->data->dev_link.link_speed = vnic_dev_port_speed(enic->vdev);
353 static void enicpmd_dev_stats_get(struct rte_eth_dev *eth_dev,
354 struct rte_eth_stats *stats)
356 struct enic *enic = pmd_priv(eth_dev);
358 ENICPMD_FUNC_TRACE();
359 enic_dev_stats_get(enic, stats);
362 static void enicpmd_dev_stats_reset(struct rte_eth_dev *eth_dev)
364 struct enic *enic = pmd_priv(eth_dev);
366 ENICPMD_FUNC_TRACE();
367 enic_dev_stats_clear(enic);
370 static void enicpmd_dev_info_get(struct rte_eth_dev *eth_dev,
371 struct rte_eth_dev_info *device_info)
373 struct enic *enic = pmd_priv(eth_dev);
375 ENICPMD_FUNC_TRACE();
376 device_info->max_rx_queues = enic->rq_count;
377 device_info->max_tx_queues = enic->wq_count;
378 device_info->min_rx_bufsize = ENIC_MIN_MTU;
379 device_info->max_rx_pktlen = enic->config.mtu;
380 device_info->max_mac_addrs = 1;
381 device_info->rx_offload_capa =
382 DEV_RX_OFFLOAD_VLAN_STRIP |
383 DEV_RX_OFFLOAD_IPV4_CKSUM |
384 DEV_RX_OFFLOAD_UDP_CKSUM |
385 DEV_RX_OFFLOAD_TCP_CKSUM;
386 device_info->tx_offload_capa =
387 DEV_TX_OFFLOAD_VLAN_INSERT |
388 DEV_TX_OFFLOAD_IPV4_CKSUM |
389 DEV_TX_OFFLOAD_UDP_CKSUM |
390 DEV_TX_OFFLOAD_TCP_CKSUM;
393 static void enicpmd_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
395 struct enic *enic = pmd_priv(eth_dev);
397 ENICPMD_FUNC_TRACE();
399 enic_add_packet_filter(enic);
402 static void enicpmd_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
404 struct enic *enic = pmd_priv(eth_dev);
406 ENICPMD_FUNC_TRACE();
408 enic_add_packet_filter(enic);
411 static void enicpmd_dev_allmulticast_enable(struct rte_eth_dev *eth_dev)
413 struct enic *enic = pmd_priv(eth_dev);
415 ENICPMD_FUNC_TRACE();
417 enic_add_packet_filter(enic);
420 static void enicpmd_dev_allmulticast_disable(struct rte_eth_dev *eth_dev)
422 struct enic *enic = pmd_priv(eth_dev);
424 ENICPMD_FUNC_TRACE();
426 enic_add_packet_filter(enic);
429 static void enicpmd_add_mac_addr(struct rte_eth_dev *eth_dev,
430 struct ether_addr *mac_addr,
431 __rte_unused uint32_t index, __rte_unused uint32_t pool)
433 struct enic *enic = pmd_priv(eth_dev);
435 ENICPMD_FUNC_TRACE();
436 enic_set_mac_address(enic, mac_addr->addr_bytes);
439 static void enicpmd_remove_mac_addr(struct rte_eth_dev *eth_dev, __rte_unused uint32_t index)
441 struct enic *enic = pmd_priv(eth_dev);
443 ENICPMD_FUNC_TRACE();
444 enic_del_mac_address(enic);
448 static uint16_t enicpmd_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
453 unsigned int pkt_len;
454 unsigned int seg_len;
455 unsigned int inc_len;
456 unsigned int nb_segs;
457 struct rte_mbuf *tx_pkt;
458 struct vnic_wq *wq = (struct vnic_wq *)tx_queue;
459 struct enic *enic = vnic_dev_priv(wq->vdev);
460 unsigned short vlan_id;
461 unsigned short ol_flags;
463 for (index = 0; index < nb_pkts; index++) {
466 nb_segs = tx_pkt->nb_segs;
467 if (nb_segs > vnic_wq_desc_avail(wq)) {
468 /* wq cleanup and try again */
469 if (!enic_cleanup_wq(enic, wq) ||
470 (nb_segs > vnic_wq_desc_avail(wq)))
473 pkt_len = tx_pkt->pkt_len;
474 vlan_id = tx_pkt->vlan_tci;
475 ol_flags = tx_pkt->ol_flags;
476 for (frags = 0; inc_len < pkt_len; frags++) {
479 seg_len = tx_pkt->data_len;
481 if (enic_send_pkt(enic, wq, tx_pkt,
482 (unsigned short)seg_len, !frags,
483 (pkt_len == inc_len), ol_flags, vlan_id)) {
486 tx_pkt = tx_pkt->next;
490 enic_cleanup_wq(enic, wq);
494 static uint16_t enicpmd_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
497 struct vnic_rq *rq = (struct vnic_rq *)rx_queue;
498 unsigned int work_done;
500 if (enic_poll(rq, rx_pkts, (unsigned int)nb_pkts, &work_done))
501 dev_err(enic, "error in enicpmd poll\n");
506 static struct eth_dev_ops enicpmd_eth_dev_ops = {
507 .dev_configure = enicpmd_dev_configure,
508 .dev_start = enicpmd_dev_start,
509 .dev_stop = enicpmd_dev_stop,
510 .dev_set_link_up = NULL,
511 .dev_set_link_down = NULL,
512 .dev_close = enicpmd_dev_close,
513 .promiscuous_enable = enicpmd_dev_promiscuous_enable,
514 .promiscuous_disable = enicpmd_dev_promiscuous_disable,
515 .allmulticast_enable = enicpmd_dev_allmulticast_enable,
516 .allmulticast_disable = enicpmd_dev_allmulticast_disable,
517 .link_update = enicpmd_dev_link_update,
518 .stats_get = enicpmd_dev_stats_get,
519 .stats_reset = enicpmd_dev_stats_reset,
520 .queue_stats_mapping_set = NULL,
521 .dev_infos_get = enicpmd_dev_info_get,
523 .vlan_filter_set = enicpmd_vlan_filter_set,
524 .vlan_tpid_set = NULL,
525 .vlan_offload_set = enicpmd_vlan_offload_set,
526 .vlan_strip_queue_set = NULL,
527 .rx_queue_start = enicpmd_dev_rx_queue_start,
528 .rx_queue_stop = enicpmd_dev_rx_queue_stop,
529 .tx_queue_start = enicpmd_dev_tx_queue_start,
530 .tx_queue_stop = enicpmd_dev_tx_queue_stop,
531 .rx_queue_setup = enicpmd_dev_rx_queue_setup,
532 .rx_queue_release = enicpmd_dev_rx_queue_release,
533 .rx_queue_count = NULL,
534 .rx_descriptor_done = NULL,
535 .tx_queue_setup = enicpmd_dev_tx_queue_setup,
536 .tx_queue_release = enicpmd_dev_tx_queue_release,
539 .flow_ctrl_get = NULL,
540 .flow_ctrl_set = NULL,
541 .priority_flow_ctrl_set = NULL,
542 .mac_addr_add = enicpmd_add_mac_addr,
543 .mac_addr_remove = enicpmd_remove_mac_addr,
544 .fdir_add_signature_filter = NULL,
545 .fdir_update_signature_filter = NULL,
546 .fdir_remove_signature_filter = NULL,
547 .fdir_infos_get = enicpmd_fdir_info_get,
548 .fdir_add_perfect_filter = enicpmd_fdir_add_perfect_filter,
549 .fdir_update_perfect_filter = enicpmd_fdir_add_perfect_filter,
550 .fdir_remove_perfect_filter = enicpmd_fdir_remove_perfect_filter,
551 .fdir_set_masks = NULL,
554 struct enic *enicpmd_list_head = NULL;
555 /* Initialize the driver
556 * It returns 0 on success.
558 static int eth_enicpmd_dev_init(
559 __attribute__((unused))struct eth_driver *eth_drv,
560 struct rte_eth_dev *eth_dev)
562 struct rte_pci_device *pdev;
563 struct rte_pci_addr *addr;
564 struct enic *enic = pmd_priv(eth_dev);
566 ENICPMD_FUNC_TRACE();
568 enic->rte_dev = eth_dev;
569 eth_dev->dev_ops = &enicpmd_eth_dev_ops;
570 eth_dev->rx_pkt_burst = &enicpmd_recv_pkts;
571 eth_dev->tx_pkt_burst = &enicpmd_xmit_pkts;
573 pdev = eth_dev->pci_dev;
577 snprintf(enic->bdf_name, ENICPMD_BDF_LENGTH, "%04x:%02x:%02x.%x",
578 addr->domain, addr->bus, addr->devid, addr->function);
580 return enic_probe(enic);
583 static struct eth_driver rte_enic_pmd = {
585 .name = "rte_enic_pmd",
586 .id_table = pci_id_enic_map,
587 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
589 .eth_dev_init = eth_enicpmd_dev_init,
590 .dev_private_size = sizeof(struct enic),
593 /* Driver initialization routine.
594 * Invoked once at EAL init time.
595 * Register as the [Poll Mode] Driver of Cisco ENIC device.
598 rte_enic_pmd_init(const char *name __rte_unused,
599 const char *params __rte_unused)
601 ENICPMD_FUNC_TRACE();
603 rte_eth_driver_register(&rte_enic_pmd);
607 static struct rte_driver rte_enic_driver = {
609 .init = rte_enic_pmd_init,
612 PMD_REGISTER_DRIVER(rte_enic_driver);