ethdev: add Rx interrupt control functions
authorCunming Liang <cunming.liang@intel.com>
Mon, 20 Jul 2015 03:02:26 +0000 (11:02 +0800)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Mon, 27 Jul 2015 21:13:57 +0000 (23:13 +0200)
The patch adds two dev_ops functions to enable and disable rx queue
interrupts.
In addition, it adds rte_eth_dev_rx_intr_ctl/rx_intr_q to support
per port or per queue rx intr event set.

Signed-off-by: Danny Zhou <danny.zhou@intel.com>
Signed-off-by: Cunming Liang <cunming.liang@intel.com>
lib/librte_ether/rte_ethdev.c
lib/librte_ether/rte_ethdev.h
lib/librte_ether/rte_ether_version.map

index 8751801..5fe1906 100644 (file)
@@ -3032,6 +3032,153 @@ _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
        }
        rte_spinlock_unlock(&rte_eth_dev_cb_lock);
 }
+
+#ifdef RTE_NEXT_ABI
+int
+rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
+{
+       uint32_t vec;
+       struct rte_eth_dev *dev;
+       struct rte_intr_handle *intr_handle;
+       uint16_t qid;
+       int rc;
+
+       if (!rte_eth_dev_is_valid_port(port_id)) {
+               PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
+               return -ENODEV;
+       }
+
+       dev = &rte_eth_devices[port_id];
+       intr_handle = &dev->pci_dev->intr_handle;
+       if (!intr_handle->intr_vec) {
+               PMD_DEBUG_TRACE("RX Intr vector unset\n");
+               return -EPERM;
+       }
+
+       for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
+               vec = intr_handle->intr_vec[qid];
+               rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
+               if (rc && rc != -EEXIST) {
+                       PMD_DEBUG_TRACE("p %u q %u rx ctl error"
+                                       " op %d epfd %d vec %u\n",
+                                       port_id, qid, op, epfd, vec);
+               }
+       }
+
+       return 0;
+}
+
+int
+rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
+                         int epfd, int op, void *data)
+{
+       uint32_t vec;
+       struct rte_eth_dev *dev;
+       struct rte_intr_handle *intr_handle;
+       int rc;
+
+       if (!rte_eth_dev_is_valid_port(port_id)) {
+               PMD_DEBUG_TRACE("Invalid port_id=%u\n", port_id);
+               return -ENODEV;
+       }
+
+       dev = &rte_eth_devices[port_id];
+       if (queue_id >= dev->data->nb_rx_queues) {
+               PMD_DEBUG_TRACE("Invalid RX queue_id=%u\n", queue_id);
+               return -EINVAL;
+       }
+
+       intr_handle = &dev->pci_dev->intr_handle;
+       if (!intr_handle->intr_vec) {
+               PMD_DEBUG_TRACE("RX Intr vector unset\n");
+               return -EPERM;
+       }
+
+       vec = intr_handle->intr_vec[queue_id];
+       rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
+       if (rc && rc != -EEXIST) {
+               PMD_DEBUG_TRACE("p %u q %u rx ctl error"
+                               " op %d epfd %d vec %u\n",
+                               port_id, queue_id, op, epfd, vec);
+               return rc;
+       }
+
+       return 0;
+}
+
+int
+rte_eth_dev_rx_intr_enable(uint8_t port_id,
+                          uint16_t queue_id)
+{
+       struct rte_eth_dev *dev;
+
+       if (!rte_eth_dev_is_valid_port(port_id)) {
+               PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
+               return -ENODEV;
+       }
+
+       dev = &rte_eth_devices[port_id];
+
+       FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP);
+       return (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id);
+}
+
+int
+rte_eth_dev_rx_intr_disable(uint8_t port_id,
+                           uint16_t queue_id)
+{
+       struct rte_eth_dev *dev;
+
+       if (!rte_eth_dev_is_valid_port(port_id)) {
+               PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
+               return -ENODEV;
+       }
+
+       dev = &rte_eth_devices[port_id];
+
+       FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP);
+       return (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id);
+}
+#else
+int
+rte_eth_dev_rx_intr_enable(uint8_t port_id, uint16_t queue_id)
+{
+       RTE_SET_USED(port_id);
+       RTE_SET_USED(queue_id);
+       return -ENOTSUP;
+}
+
+int
+rte_eth_dev_rx_intr_disable(uint8_t port_id, uint16_t queue_id)
+{
+       RTE_SET_USED(port_id);
+       RTE_SET_USED(queue_id);
+       return -ENOTSUP;
+}
+
+int
+rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data)
+{
+       RTE_SET_USED(port_id);
+       RTE_SET_USED(epfd);
+       RTE_SET_USED(op);
+       RTE_SET_USED(data);
+       return -1;
+}
+
+int
+rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
+                         int epfd, int op, void *data)
+{
+       RTE_SET_USED(port_id);
+       RTE_SET_USED(queue_id);
+       RTE_SET_USED(epfd);
+       RTE_SET_USED(op);
+       RTE_SET_USED(data);
+       return -1;
+}
+#endif
+
 #ifdef RTE_NIC_BYPASS
 int rte_eth_dev_bypass_init(uint8_t port_id)
 {
index 62c166e..f1e622b 100644 (file)
@@ -845,6 +845,10 @@ struct rte_eth_fdir {
 struct rte_intr_conf {
        /** enable/disable lsc interrupt. 0 (default) - disable, 1 enable */
        uint16_t lsc;
+#ifdef RTE_NEXT_ABI
+       /** enable/disable rxq interrupt. 0 (default) - disable, 1 enable */
+       uint16_t rxq;
+#endif
 };
 
 /**
@@ -1053,6 +1057,14 @@ typedef int (*eth_tx_queue_setup_t)(struct rte_eth_dev *dev,
                                    const struct rte_eth_txconf *tx_conf);
 /**< @internal Setup a transmit queue of an Ethernet device. */
 
+typedef int (*eth_rx_enable_intr_t)(struct rte_eth_dev *dev,
+                                   uint16_t rx_queue_id);
+/**< @internal Enable interrupt of a receive queue of an Ethernet device. */
+
+typedef int (*eth_rx_disable_intr_t)(struct rte_eth_dev *dev,
+                                   uint16_t rx_queue_id);
+/**< @internal Disable interrupt of a receive queue of an Ethernet device. */
+
 typedef void (*eth_queue_release_t)(void *queue);
 /**< @internal Release memory resources allocated by given RX/TX queue. */
 
@@ -1380,6 +1392,12 @@ struct eth_dev_ops {
        eth_queue_release_t        rx_queue_release;/**< Release RX queue.*/
        eth_rx_queue_count_t       rx_queue_count; /**< Get Rx queue count. */
        eth_rx_descriptor_done_t   rx_descriptor_done;  /**< Check rxd DD bit */
+#ifdef RTE_NEXT_ABI
+       /**< Enable Rx queue interrupt. */
+       eth_rx_enable_intr_t       rx_queue_intr_enable;
+       /**< Disable Rx queue interrupt.*/
+       eth_rx_disable_intr_t      rx_queue_intr_disable;
+#endif
        eth_tx_queue_setup_t       tx_queue_setup;/**< Set up device TX queue.*/
        eth_queue_release_t        tx_queue_release;/**< Release TX queue.*/
        eth_dev_led_on_t           dev_led_on;    /**< Turn on LED. */
@@ -2956,6 +2974,92 @@ int rte_eth_dev_callback_unregister(uint8_t port_id,
 void _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
                                enum rte_eth_event_type event);
 
+/**
+ * When there is no rx packet coming in Rx Queue for a long time, we can
+ * sleep lcore related to RX Queue for power saving, and enable rx interrupt
+ * to be triggered when rx packect arrives.
+ *
+ * The rte_eth_dev_rx_intr_enable() function enables rx queue
+ * interrupt on specific rx queue of a port.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param queue_id
+ *   The index of the receive queue from which to retrieve input packets.
+ *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
+ *   to rte_eth_dev_configure().
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if underlying hardware OR driver doesn't support
+ *     that operation.
+ *   - (-ENODEV) if *port_id* invalid.
+ */
+int rte_eth_dev_rx_intr_enable(uint8_t port_id, uint16_t queue_id);
+
+/**
+ * When lcore wakes up from rx interrupt indicating packet coming, disable rx
+ * interrupt and returns to polling mode.
+ *
+ * The rte_eth_dev_rx_intr_disable() function disables rx queue
+ * interrupt on specific rx queue of a port.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param queue_id
+ *   The index of the receive queue from which to retrieve input packets.
+ *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
+ *   to rte_eth_dev_configure().
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if underlying hardware OR driver doesn't support
+ *     that operation.
+ *   - (-ENODEV) if *port_id* invalid.
+ */
+int rte_eth_dev_rx_intr_disable(uint8_t port_id, uint16_t queue_id);
+
+/**
+ * RX Interrupt control per port.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param epfd
+ *   Epoll instance fd which the intr vector associated to.
+ *   Using RTE_EPOLL_PER_THREAD allows to use per thread epoll instance.
+ * @param op
+ *   The operation be performed for the vector.
+ *   Operation type of {RTE_INTR_EVENT_ADD, RTE_INTR_EVENT_DEL}.
+ * @param data
+ *   User raw data.
+ * @return
+ *   - On success, zero.
+ *   - On failure, a negative value.
+ */
+int rte_eth_dev_rx_intr_ctl(uint8_t port_id, int epfd, int op, void *data);
+
+/**
+ * RX Interrupt control per queue.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param queue_id
+ *   The index of the receive queue from which to retrieve input packets.
+ *   The value must be in the range [0, nb_rx_queue - 1] previously supplied
+ *   to rte_eth_dev_configure().
+ * @param epfd
+ *   Epoll instance fd which the intr vector associated to.
+ *   Using RTE_EPOLL_PER_THREAD allows to use per thread epoll instance.
+ * @param op
+ *   The operation be performed for the vector.
+ *   Operation type of {RTE_INTR_EVENT_ADD, RTE_INTR_EVENT_DEL}.
+ * @param data
+ *   User raw data.
+ * @return
+ *   - On success, zero.
+ *   - On failure, a negative value.
+ */
+int rte_eth_dev_rx_intr_ctl_q(uint8_t port_id, uint16_t queue_id,
+                             int epfd, int op, void *data);
+
 /**
  * Turn on the LED on the Ethernet device.
  * This function turns on the LED on the Ethernet device.
index 23cfee9..8345a6c 100644 (file)
@@ -115,6 +115,10 @@ DPDK_2.1 {
        rte_eth_dev_get_reg_info;
        rte_eth_dev_get_reg_length;
        rte_eth_dev_is_valid_port;
+       rte_eth_dev_rx_intr_ctl;
+       rte_eth_dev_rx_intr_ctl_q;
+       rte_eth_dev_rx_intr_disable;
+       rte_eth_dev_rx_intr_enable;
        rte_eth_dev_set_eeprom;
        rte_eth_dev_set_mc_addr_list;
        rte_eth_timesync_disable;