net/hns3: refactor multi-process initialization
[dpdk.git] / drivers / raw / ntb / ntb.c
index 7f6b835..46ac02e 100644 (file)
@@ -25,6 +25,7 @@
 
 static const struct rte_pci_id pci_id_ntb_map[] = {
        { RTE_PCI_DEVICE(NTB_INTEL_VENDOR_ID, NTB_INTEL_DEV_ID_B2B_SKX) },
+       { RTE_PCI_DEVICE(NTB_INTEL_VENDOR_ID, NTB_INTEL_DEV_ID_B2B_ICX) },
        { .vendor_id = 0, /* sentinel */ },
 };
 
@@ -244,19 +245,28 @@ ntb_dev_intr_handler(void *param)
                hw->peer_dev_up = 0;
                return;
        }
+
+       /* Clear other received doorbells. */
+       (*hw->ntb_ops->db_clear)(dev, db_bits);
 }
 
-static void
+static int
 ntb_queue_conf_get(struct rte_rawdev *dev,
                   uint16_t queue_id,
-                  rte_rawdev_obj_t queue_conf)
+                  rte_rawdev_obj_t queue_conf,
+                  size_t conf_size)
 {
        struct ntb_queue_conf *q_conf = queue_conf;
        struct ntb_hw *hw = dev->dev_private;
 
+       if (conf_size != sizeof(*q_conf))
+               return -EINVAL;
+
        q_conf->tx_free_thresh = hw->tx_queues[queue_id]->tx_free_thresh;
        q_conf->nb_desc = hw->rx_queues[queue_id]->nb_rx_desc;
        q_conf->rx_mp = hw->rx_queues[queue_id]->mpool;
+
+       return 0;
 }
 
 static void
@@ -294,12 +304,16 @@ ntb_rxq_release(struct ntb_rx_queue *rxq)
 static int
 ntb_rxq_setup(struct rte_rawdev *dev,
              uint16_t qp_id,
-             rte_rawdev_obj_t queue_conf)
+             rte_rawdev_obj_t queue_conf,
+             size_t conf_size)
 {
        struct ntb_queue_conf *rxq_conf = queue_conf;
        struct ntb_hw *hw = dev->dev_private;
        struct ntb_rx_queue *rxq;
 
+       if (conf_size != sizeof(*rxq_conf))
+               return -EINVAL;
+
        /* Allocate the rx queue data structure */
        rxq = rte_zmalloc_socket("ntb rx queue",
                                 sizeof(struct ntb_rx_queue),
@@ -375,13 +389,17 @@ ntb_txq_release(struct ntb_tx_queue *txq)
 static int
 ntb_txq_setup(struct rte_rawdev *dev,
              uint16_t qp_id,
-             rte_rawdev_obj_t queue_conf)
+             rte_rawdev_obj_t queue_conf,
+             size_t conf_size)
 {
        struct ntb_queue_conf *txq_conf = queue_conf;
        struct ntb_hw *hw = dev->dev_private;
        struct ntb_tx_queue *txq;
        uint16_t i, prev;
 
+       if (conf_size != sizeof(*txq_conf))
+               return -EINVAL;
+
        /* Allocate the TX queue data structure. */
        txq = rte_zmalloc_socket("ntb tx queue",
                                  sizeof(struct ntb_tx_queue),
@@ -439,7 +457,8 @@ ntb_txq_setup(struct rte_rawdev *dev,
 static int
 ntb_queue_setup(struct rte_rawdev *dev,
                uint16_t queue_id,
-               rte_rawdev_obj_t queue_conf)
+               rte_rawdev_obj_t queue_conf,
+               size_t conf_size)
 {
        struct ntb_hw *hw = dev->dev_private;
        int ret;
@@ -447,11 +466,11 @@ ntb_queue_setup(struct rte_rawdev *dev,
        if (queue_id >= hw->queue_pairs)
                return -EINVAL;
 
-       ret = ntb_txq_setup(dev, queue_id, queue_conf);
+       ret = ntb_txq_setup(dev, queue_id, queue_conf, conf_size);
        if (ret < 0)
                return ret;
 
-       ret = ntb_rxq_setup(dev, queue_id, queue_conf);
+       ret = ntb_rxq_setup(dev, queue_id, queue_conf, conf_size);
 
        return ret;
 }
@@ -904,6 +923,11 @@ ntb_dev_start(struct rte_rawdev *dev)
 
        hw->peer_mw_base = rte_zmalloc("ntb_peer_mw_base", hw->mw_cnt *
                                        sizeof(uint64_t), 0);
+       if (hw->peer_mw_base == NULL) {
+               NTB_LOG(ERR, "Cannot allocate memory for peer mw base.");
+               ret = -ENOMEM;
+               goto err_q_init;
+       }
 
        if (hw->ntb_ops->spad_read == NULL) {
                ret = -ENOTSUP;
@@ -1020,13 +1044,10 @@ ntb_dev_close(struct rte_rawdev *dev)
                ntb_queue_release(dev, i);
        hw->queue_pairs = 0;
 
-       intr_handle = &hw->pci_dev->intr_handle;
+       intr_handle = hw->pci_dev->intr_handle;
        /* Clean datapath event and vec mapping */
        rte_intr_efd_disable(intr_handle);
-       if (intr_handle->intr_vec) {
-               rte_free(intr_handle->intr_vec);
-               intr_handle->intr_vec = NULL;
-       }
+       rte_intr_vec_list_free(intr_handle);
        /* Disable uio intr before callback unregister */
        rte_intr_disable(intr_handle);
 
@@ -1061,6 +1082,10 @@ ntb_attr_set(struct rte_rawdev *dev, const char *attr_name,
                if (hw->ntb_ops->spad_write == NULL)
                        return -ENOTSUP;
                index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+               if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+                       NTB_LOG(ERR, "Invalid attribute (%s)", attr_name);
+                       return -EINVAL;
+               }
                (*hw->ntb_ops->spad_write)(dev, hw->spad_user_list[index],
                                           1, attr_value);
                NTB_LOG(DEBUG, "Set attribute (%s) Value (%" PRIu64 ")",
@@ -1155,6 +1180,10 @@ ntb_attr_get(struct rte_rawdev *dev, const char *attr_name,
                if (hw->ntb_ops->spad_read == NULL)
                        return -ENOTSUP;
                index = atoi(&attr_name[NTB_SPAD_USER_LEN]);
+               if (index < 0 || index >= NTB_SPAD_USER_MAX_NUM) {
+                       NTB_LOG(ERR, "Attribute (%s) out of range", attr_name);
+                       return -EINVAL;
+               }
                *attr_value = (*hw->ntb_ops->spad_read)(dev,
                                hw->spad_user_list[index], 0);
                NTB_LOG(DEBUG, "Attribute (%s) Value (%" PRIu64 ")",
@@ -1345,6 +1374,7 @@ ntb_init_hw(struct rte_rawdev *dev, struct rte_pci_device *pci_dev)
 
        switch (pci_dev->id.device_id) {
        case NTB_INTEL_DEV_ID_B2B_SKX:
+       case NTB_INTEL_DEV_ID_B2B_ICX:
                hw->ntb_ops = &intel_ntb_ops;
                break;
        default:
@@ -1369,7 +1399,7 @@ ntb_init_hw(struct rte_rawdev *dev, struct rte_pci_device *pci_dev)
        /* Init doorbell. */
        hw->db_valid_mask = RTE_LEN2MASK(hw->db_cnt, uint64_t);
 
-       intr_handle = &pci_dev->intr_handle;
+       intr_handle = pci_dev->intr_handle;
        /* Register callback func to eal lib */
        rte_intr_callback_register(intr_handle,
                                   ntb_dev_intr_handler, dev);
@@ -1514,4 +1544,4 @@ static struct rte_pci_driver rte_ntb_pmd = {
 RTE_PMD_REGISTER_PCI(raw_ntb, rte_ntb_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(raw_ntb, pci_id_ntb_map);
 RTE_PMD_REGISTER_KMOD_DEP(raw_ntb, "* igb_uio | uio_pci_generic | vfio-pci");
-RTE_LOG_REGISTER(ntb_logtype, pmd.raw.ntb, INFO);
+RTE_LOG_REGISTER_DEFAULT(ntb_logtype, INFO);