drivers: use PCI registration macro
[dpdk.git] / drivers / net / bnxt / bnxt_ethdev.c
index b3b76f1..d389fc8 100644 (file)
 static const char bnxt_version[] =
        "Broadcom Cumulus driver " DRV_MODULE_NAME "\n";
 
+#define PCI_VENDOR_ID_BROADCOM 0x14E4
+
+#define BROADCOM_DEV_ID_57301 0x16c8
+#define BROADCOM_DEV_ID_57302 0x16c9
+#define BROADCOM_DEV_ID_57304_PF 0x16ca
+#define BROADCOM_DEV_ID_57304_VF 0x16cb
+#define BROADCOM_DEV_ID_57402 0x16d0
+#define BROADCOM_DEV_ID_57404 0x16d1
+#define BROADCOM_DEV_ID_57406_PF 0x16d2
+#define BROADCOM_DEV_ID_57406_VF 0x16d3
+#define BROADCOM_DEV_ID_57406_MF 0x16d4
+#define BROADCOM_DEV_ID_57314 0x16df
+
 static struct rte_pci_id bnxt_pci_id_map[] = {
-#define RTE_PCI_DEV_ID_DECL_BNXT(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
-#include "rte_pci_dev_ids.h"
-       {.device_id = 0},
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57301) },
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57302) },
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_PF) },
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_VF) },
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402) },
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404) },
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_PF) },
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_VF) },
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_MF) },
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57314) },
+       { .vendor_id = 0, /* sentinel */ },
 };
 
+#define BNXT_ETH_RSS_SUPPORT ( \
+       ETH_RSS_IPV4 |          \
+       ETH_RSS_NONFRAG_IPV4_TCP |      \
+       ETH_RSS_NONFRAG_IPV4_UDP |      \
+       ETH_RSS_IPV6 |          \
+       ETH_RSS_NONFRAG_IPV6_TCP |      \
+       ETH_RSS_NONFRAG_IPV6_UDP)
+
 /***********************/
 
 /*
@@ -636,6 +665,198 @@ static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
        return 0;
 }
 
+static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
+                                  struct rte_eth_rss_conf *rss_conf)
+{
+       struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
+       struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
+       struct bnxt_vnic_info *vnic;
+       uint16_t hash_type = 0;
+       int i;
+
+       /*
+        * If RSS enablement were different than dev_configure,
+        * then return -EINVAL
+        */
+       if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
+               if (!rss_conf->rss_hf)
+                       return -EINVAL;
+       } else {
+               if (rss_conf->rss_hf & BNXT_ETH_RSS_SUPPORT)
+                       return -EINVAL;
+       }
+       if (rss_conf->rss_hf & ETH_RSS_IPV4)
+               hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
+       if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
+               hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
+       if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
+               hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
+       if (rss_conf->rss_hf & ETH_RSS_IPV6)
+               hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
+       if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
+               hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
+       if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
+               hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
+
+       /* Update the RSS VNIC(s) */
+       for (i = 0; i < MAX_FF_POOLS; i++) {
+               STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
+                       vnic->hash_type = hash_type;
+
+                       /*
+                        * Use the supplied key if the key length is
+                        * acceptable and the rss_key is not NULL
+                        */
+                       if (rss_conf->rss_key &&
+                           rss_conf->rss_key_len <= HW_HASH_KEY_SIZE)
+                               memcpy(vnic->rss_hash_key, rss_conf->rss_key,
+                                      rss_conf->rss_key_len);
+
+                       bnxt_hwrm_vnic_rss_cfg(bp, vnic);
+               }
+       }
+       return 0;
+}
+
+static int bnxt_rss_hash_conf_get_op(struct rte_eth_dev *eth_dev,
+                                    struct rte_eth_rss_conf *rss_conf)
+{
+       struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
+       struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
+       int len;
+       uint32_t hash_types;
+
+       /* RSS configuration is the same for all VNICs */
+       if (vnic && vnic->rss_hash_key) {
+               if (rss_conf->rss_key) {
+                       len = rss_conf->rss_key_len <= HW_HASH_KEY_SIZE ?
+                             rss_conf->rss_key_len : HW_HASH_KEY_SIZE;
+                       memcpy(rss_conf->rss_key, vnic->rss_hash_key, len);
+               }
+
+               hash_types = vnic->hash_type;
+               rss_conf->rss_hf = 0;
+               if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4) {
+                       rss_conf->rss_hf |= ETH_RSS_IPV4;
+                       hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
+               }
+               if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4) {
+                       rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
+                       hash_types &=
+                               ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
+               }
+               if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4) {
+                       rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
+                       hash_types &=
+                               ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
+               }
+               if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6) {
+                       rss_conf->rss_hf |= ETH_RSS_IPV6;
+                       hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
+               }
+               if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6) {
+                       rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
+                       hash_types &=
+                               ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
+               }
+               if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6) {
+                       rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
+                       hash_types &=
+                               ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
+               }
+               if (hash_types) {
+                       RTE_LOG(ERR, PMD,
+                               "Unknwon RSS config from firmware (%08x), RSS disabled",
+                               vnic->hash_type);
+                       return -ENOTSUP;
+               }
+       } else {
+               rss_conf->rss_hf = 0;
+       }
+       return 0;
+}
+
+static int bnxt_flow_ctrl_get_op(struct rte_eth_dev *dev,
+                              struct rte_eth_fc_conf *fc_conf __rte_unused)
+{
+       struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
+       struct rte_eth_link link_info;
+       int rc;
+
+       rc = bnxt_get_hwrm_link_config(bp, &link_info);
+       if (rc)
+               return rc;
+
+       memset(fc_conf, 0, sizeof(*fc_conf));
+       if (bp->link_info.auto_pause)
+               fc_conf->autoneg = 1;
+       switch (bp->link_info.pause) {
+       case 0:
+               fc_conf->mode = RTE_FC_NONE;
+               break;
+       case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX:
+               fc_conf->mode = RTE_FC_TX_PAUSE;
+               break;
+       case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX:
+               fc_conf->mode = RTE_FC_RX_PAUSE;
+               break;
+       case (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
+                       HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX):
+               fc_conf->mode = RTE_FC_FULL;
+               break;
+       }
+       return 0;
+}
+
+static int bnxt_flow_ctrl_set_op(struct rte_eth_dev *dev,
+                              struct rte_eth_fc_conf *fc_conf)
+{
+       struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
+
+       switch (fc_conf->mode) {
+       case RTE_FC_NONE:
+               bp->link_info.auto_pause = 0;
+               bp->link_info.force_pause = 0;
+               break;
+       case RTE_FC_RX_PAUSE:
+               if (fc_conf->autoneg) {
+                       bp->link_info.auto_pause =
+                                       HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
+                       bp->link_info.force_pause = 0;
+               } else {
+                       bp->link_info.auto_pause = 0;
+                       bp->link_info.force_pause =
+                                       HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
+               }
+               break;
+       case RTE_FC_TX_PAUSE:
+               if (fc_conf->autoneg) {
+                       bp->link_info.auto_pause =
+                                       HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX;
+                       bp->link_info.force_pause = 0;
+               } else {
+                       bp->link_info.auto_pause = 0;
+                       bp->link_info.force_pause =
+                                       HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX;
+               }
+               break;
+       case RTE_FC_FULL:
+               if (fc_conf->autoneg) {
+                       bp->link_info.auto_pause =
+                                       HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX |
+                                       HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
+                       bp->link_info.force_pause = 0;
+               } else {
+                       bp->link_info.auto_pause = 0;
+                       bp->link_info.force_pause =
+                                       HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX |
+                                       HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
+               }
+               break;
+       }
+       return bnxt_set_hwrm_link_config(bp, true);
+}
+
 /*
  * Initialization
  */
@@ -656,6 +877,8 @@ static struct eth_dev_ops bnxt_dev_ops = {
        .tx_queue_release = bnxt_tx_queue_release_op,
        .reta_update = bnxt_reta_update_op,
        .reta_query = bnxt_reta_query_op,
+       .rss_hash_update = bnxt_rss_hash_update_op,
+       .rss_hash_conf_get = bnxt_rss_hash_conf_get_op,
        .link_update = bnxt_link_update_op,
        .promiscuous_enable = bnxt_promiscuous_enable_op,
        .promiscuous_disable = bnxt_promiscuous_disable_op,
@@ -663,6 +886,8 @@ static struct eth_dev_ops bnxt_dev_ops = {
        .allmulticast_disable = bnxt_allmulticast_disable_op,
        .mac_addr_add = bnxt_mac_addr_add_op,
        .mac_addr_remove = bnxt_mac_addr_remove_op,
+       .flow_ctrl_get = bnxt_flow_ctrl_get_op,
+       .flow_ctrl_set = bnxt_flow_ctrl_set_op,
 };
 
 static bool bnxt_vf_pciid(uint16_t id)
@@ -823,23 +1048,13 @@ static struct eth_driver bnxt_rte_pmd = {
                    .name = "rte_" DRV_MODULE_NAME "_pmd",
                    .id_table = bnxt_pci_id_map,
                    .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+                   .probe = rte_eth_dev_pci_probe,
+                   .remove = rte_eth_dev_pci_remove
                    },
        .eth_dev_init = bnxt_dev_init,
        .eth_dev_uninit = bnxt_dev_uninit,
        .dev_private_size = sizeof(struct bnxt),
 };
 
-static int bnxt_rte_pmd_init(const char *name, const char *params __rte_unused)
-{
-       RTE_LOG(INFO, PMD, "bnxt_rte_pmd_init() called for %s\n", name);
-       rte_eth_driver_register(&bnxt_rte_pmd);
-       return 0;
-}
-
-static struct rte_driver bnxt_pmd_drv = {
-       .name = "eth_bnxt",
-       .type = PMD_PDEV,
-       .init = bnxt_rte_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(bnxt_pmd_drv);
+DRIVER_REGISTER_PCI(net_bnxt, bnxt_rte_pmd.pci_drv);
+DRIVER_REGISTER_PCI_TABLE(net_bnxt, bnxt_pci_id_map);