net/ixgbe: add VLAN info in queue info msg to VF
[dpdk.git] / drivers / net / liquidio / lio_ethdev.c
index 60dfa61..5f3c05e 100644 (file)
  */
 
 #include <rte_ethdev.h>
+#include <rte_ethdev_pci.h>
 #include <rte_cycles.h>
 #include <rte_malloc.h>
 #include <rte_alarm.h>
+#include <rte_ether.h>
 
 #include "lio_logs.h"
 #include "lio_23xx_vf.h"
@@ -393,6 +395,25 @@ lio_dev_info_get(struct rte_eth_dev *eth_dev,
                 struct rte_eth_dev_info *devinfo)
 {
        struct lio_device *lio_dev = LIO_DEV(eth_dev);
+       struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+
+       devinfo->pci_dev = pci_dev;
+
+       switch (pci_dev->id.subsystem_device_id) {
+       /* CN23xx 10G cards */
+       case PCI_SUBSYS_DEV_ID_CN2350_210:
+       case PCI_SUBSYS_DEV_ID_CN2360_210:
+               devinfo->speed_capa = ETH_LINK_SPEED_10G;
+               break;
+       /* CN23xx 25G cards */
+       case PCI_SUBSYS_DEV_ID_CN2350_225:
+       case PCI_SUBSYS_DEV_ID_CN2360_225:
+               devinfo->speed_capa = ETH_LINK_SPEED_25G;
+               break;
+       default:
+               lio_dev_err(lio_dev,
+                           "Unknown CN23XX subsystem device id. Not setting speed capability.\n");
+       }
 
        devinfo->max_rx_queues = lio_dev->max_rx_queues;
        devinfo->max_tx_queues = lio_dev->max_tx_queues;
@@ -404,7 +425,8 @@ lio_dev_info_get(struct rte_eth_dev *eth_dev,
 
        devinfo->rx_offload_capa = (DEV_RX_OFFLOAD_IPV4_CKSUM           |
                                    DEV_RX_OFFLOAD_UDP_CKSUM            |
-                                   DEV_RX_OFFLOAD_TCP_CKSUM);
+                                   DEV_RX_OFFLOAD_TCP_CKSUM            |
+                                   DEV_RX_OFFLOAD_VLAN_STRIP);
        devinfo->tx_offload_capa = (DEV_TX_OFFLOAD_IPV4_CKSUM           |
                                    DEV_TX_OFFLOAD_UDP_CKSUM            |
                                    DEV_TX_OFFLOAD_TCP_CKSUM            |
@@ -825,6 +847,47 @@ lio_dev_udp_tunnel_del(struct rte_eth_dev *eth_dev,
        return 0;
 }
 
+static int
+lio_dev_vlan_filter_set(struct rte_eth_dev *eth_dev, uint16_t vlan_id, int on)
+{
+       struct lio_device *lio_dev = LIO_DEV(eth_dev);
+       struct lio_dev_ctrl_cmd ctrl_cmd;
+       struct lio_ctrl_pkt ctrl_pkt;
+
+       if (lio_dev->linfo.vlan_is_admin_assigned)
+               return -EPERM;
+
+       /* flush added to prevent cmd failure
+        * incase the queue is full
+        */
+       lio_flush_iq(lio_dev, lio_dev->instr_queue[0]);
+
+       memset(&ctrl_pkt, 0, sizeof(struct lio_ctrl_pkt));
+       memset(&ctrl_cmd, 0, sizeof(struct lio_dev_ctrl_cmd));
+
+       ctrl_cmd.eth_dev = eth_dev;
+       ctrl_cmd.cond = 0;
+
+       ctrl_pkt.ncmd.s.cmd = on ?
+                       LIO_CMD_ADD_VLAN_FILTER : LIO_CMD_DEL_VLAN_FILTER;
+       ctrl_pkt.ncmd.s.param1 = vlan_id;
+       ctrl_pkt.ctrl_cmd = &ctrl_cmd;
+
+       if (lio_send_ctrl_pkt(lio_dev, &ctrl_pkt)) {
+               lio_dev_err(lio_dev, "Failed to %s VLAN port\n",
+                           on ? "add" : "remove");
+               return -1;
+       }
+
+       if (lio_wait_for_ctrl_cmd(lio_dev, &ctrl_cmd)) {
+               lio_dev_err(lio_dev, "Command to %s VLAN port timed out\n",
+                           on ? "add" : "remove");
+               return -1;
+       }
+
+       return 0;
+}
+
 /**
  * Atomically writes the link status information into global
  * structure rte_eth_dev.
@@ -894,6 +957,9 @@ lio_dev_link_update(struct rte_eth_dev *eth_dev,
        case LIO_LINK_SPEED_10000:
                link.link_speed = ETH_SPEED_NUM_10G;
                break;
+       case LIO_LINK_SPEED_25000:
+               link.link_speed = ETH_SPEED_NUM_25G;
+               break;
        default:
                link.link_speed = ETH_SPEED_NUM_NONE;
                link.link_duplex = ETH_LINK_HALF_DUPLEX;
@@ -1113,14 +1179,13 @@ void
 lio_dev_rx_queue_release(void *rxq)
 {
        struct lio_droq *droq = rxq;
-       struct lio_device *lio_dev = droq->lio_dev;
        int oq_no;
 
-       /* Run time queue deletion not supported */
-       if (lio_dev->port_configured)
-               return;
+       if (droq) {
+               /* Run time queue deletion not supported */
+               if (droq->lio_dev->port_configured)
+                       return;
 
-       if (droq != NULL) {
                oq_no = droq->q_no;
                lio_delete_droq_queue(droq->lio_dev, oq_no);
        }
@@ -1208,14 +1273,14 @@ void
 lio_dev_tx_queue_release(void *txq)
 {
        struct lio_instr_queue *tq = txq;
-       struct lio_device *lio_dev = tq->lio_dev;
        uint32_t fw_mapped_iq_no;
 
-       /* Run time queue deletion not supported */
-       if (lio_dev->port_configured)
-               return;
 
-       if (tq != NULL) {
+       if (tq) {
+               /* Run time queue deletion not supported */
+               if (tq->lio_dev->port_configured)
+                       return;
+
                /* Free sg_list */
                lio_delete_sglist(tq);
 
@@ -1303,7 +1368,8 @@ lio_sync_link_state_check(void *eth_dev)
 static int
 lio_dev_start(struct rte_eth_dev *eth_dev)
 {
-       uint16_t mtu = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
+       uint16_t mtu;
+       uint32_t frame_len = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
        struct lio_device *lio_dev = LIO_DEV(eth_dev);
        uint16_t timeout = LIO_MAX_CMD_TIMEOUT;
        int ret = 0;
@@ -1341,12 +1407,29 @@ lio_dev_start(struct rte_eth_dev *eth_dev)
                goto dev_mtu_check_error;
        }
 
+       if (eth_dev->data->dev_conf.rxmode.jumbo_frame == 1) {
+               if (frame_len <= ETHER_MAX_LEN ||
+                   frame_len > LIO_MAX_RX_PKTLEN) {
+                       lio_dev_err(lio_dev, "max packet length should be >= %d and < %d when jumbo frame is enabled\n",
+                                   ETHER_MAX_LEN, LIO_MAX_RX_PKTLEN);
+                       ret = -EINVAL;
+                       goto dev_mtu_check_error;
+               }
+               mtu = (uint16_t)(frame_len - ETHER_HDR_LEN - ETHER_CRC_LEN);
+       } else {
+               /* default MTU */
+               mtu = ETHER_MTU;
+               eth_dev->data->dev_conf.rxmode.max_rx_pkt_len = ETHER_MAX_LEN;
+       }
+
        if (lio_dev->linfo.link.s.mtu != mtu) {
                ret = lio_dev_validate_vf_mtu(eth_dev, mtu);
                if (ret)
                        goto dev_mtu_check_error;
        }
 
+       eth_dev->data->mtu = mtu;
+
        return 0;
 
 dev_mtu_check_error:
@@ -1476,9 +1559,6 @@ lio_dev_close(struct rte_eth_dev *eth_dev)
                rte_write32(pkt_count, droq->pkts_sent_reg);
        }
 
-       /* Do FLR for the VF */
-       cn23xx_vf_ask_pf_to_do_flr(lio_dev);
-
        /* lio_free_mbox */
        lio_dev->fn_list.free_mbox(lio_dev);
 
@@ -1750,6 +1830,7 @@ static const struct eth_dev_ops liovf_eth_dev_ops = {
        .stats_reset            = lio_dev_stats_reset,
        .xstats_reset           = lio_dev_xstats_reset,
        .dev_infos_get          = lio_dev_info_get,
+       .vlan_filter_set        = lio_dev_vlan_filter_set,
        .rx_queue_setup         = lio_dev_rx_queue_setup,
        .rx_queue_release       = lio_dev_rx_queue_release,
        .tx_queue_setup         = lio_dev_tx_queue_setup,
@@ -1845,11 +1926,6 @@ lio_first_time_init(struct lio_device *lio_dev,
        if (cn23xx_pfvf_handshake(lio_dev))
                goto error;
 
-       /* Initial reset */
-       cn23xx_vf_ask_pf_to_do_flr(lio_dev);
-       /* Wait for FLR for 100ms per SRIOV specification */
-       rte_delay_ms(100);
-
        if (cn23xx_vf_set_io_queues_off(lio_dev)) {
                lio_dev_err(lio_dev, "Setting io queues off failed\n");
                goto error;
@@ -1912,7 +1988,7 @@ lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
 static int
 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
 {
-       struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
+       struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(eth_dev);
        struct lio_device *lio_dev = LIO_DEV(eth_dev);
 
        PMD_INIT_FUNC_TRACE();
@@ -1968,24 +2044,45 @@ lio_eth_dev_init(struct rte_eth_dev *eth_dev)
        return 0;
 }
 
+static int
+lio_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+                     struct rte_pci_device *pci_dev)
+{
+       struct rte_eth_dev *eth_dev;
+       int ret;
+
+       eth_dev = rte_eth_dev_pci_allocate(pci_dev,
+                                          sizeof(struct lio_device));
+       if (eth_dev == NULL)
+               return -ENOMEM;
+
+       ret = lio_eth_dev_init(eth_dev);
+       if (ret)
+               rte_eth_dev_pci_release(eth_dev);
+
+       return ret;
+}
+
+static int
+lio_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
+{
+       return rte_eth_dev_pci_generic_remove(pci_dev,
+                                             lio_eth_dev_uninit);
+}
+
 /* Set of PCI devices this driver supports */
 static const struct rte_pci_id pci_id_liovf_map[] = {
        { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
        { .vendor_id = 0, /* sentinel */ }
 };
 
-static struct eth_driver rte_liovf_pmd = {
-       .pci_drv = {
-               .id_table       = pci_id_liovf_map,
-               .drv_flags      = RTE_PCI_DRV_NEED_MAPPING,
-               .probe          = rte_eth_dev_pci_probe,
-               .remove         = rte_eth_dev_pci_remove,
-       },
-       .eth_dev_init           = lio_eth_dev_init,
-       .eth_dev_uninit         = lio_eth_dev_uninit,
-       .dev_private_size       = sizeof(struct lio_device),
+static struct rte_pci_driver rte_liovf_pmd = {
+       .id_table       = pci_id_liovf_map,
+       .drv_flags      = RTE_PCI_DRV_NEED_MAPPING,
+       .probe          = lio_eth_dev_pci_probe,
+       .remove         = lio_eth_dev_pci_remove,
 };
 
-RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd.pci_drv);
+RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
-RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio");
+RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio-pci");