From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 4B6362E8F for ; Wed, 8 Apr 2015 22:59:12 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP; 08 Apr 2015 13:59:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,545,1422950400"; d="scan'208";a="553097628" Received: from unknown (HELO rkwiles-desk.ger.corp.intel.com) ([10.255.41.10]) by orsmga003.jf.intel.com with ESMTP; 08 Apr 2015 13:59:10 -0700 From: Keith Wiles To: dev@dpdk.org Date: Wed, 8 Apr 2015 15:58:40 -0500 Message-Id: <1428526720-50221-5-git-send-email-keith.wiles@intel.com> X-Mailer: git-send-email 2.3.0 In-Reply-To: <1428526720-50221-1-git-send-email-keith.wiles@intel.com> References: <1428526720-50221-1-git-send-email-keith.wiles@intel.com> Subject: [dpdk-dev] [RFC PATCH 4/4] Update the rte_ethdev.[ch] files for the new device generic changes. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Apr 2015 20:59:13 -0000 rte_ethdev.c (main points): - Collect up the globals and static variables in the file into a new rte_eth_globals structure. - Update the global references to use the new global structure - Move parts of the callback routines into eal_common_device.c to all other device a common routine - Moved the debug macros PROC_PRIMARY_OR_ERR_RET, PROC_PRIMARY_OR_RET, FUNC_PTR_OR_ERR_RET and FUNC_PTR_OR_RET into the rte_common_device.h as a common macro between devices. rte_ethdev.h (main points): - Replace the first couple members in rte_eth_dev_info to commmon macro - Remove rte_eth_dev_cb_list define an use common rte_dev_cb_list instead - Move eth_[rt]x_burst_t to dev_[rt]x_burst_t in eal_common_device.h - Move rte_[rt]x_callback typedefs to eal_common_device.h as they are generic - Move rte_eth_dev_type to eal_common_device.h and rename to rte_dev_type - Move rte_eth_event_type to eal_common_device.h and rename to rte_dev_event_type - Replace the content of rte_eth_dev with macro RTE_COMMON_DEV in eal_common_device.h Replace part of the content of rte_eth_dev_data with macro RTE_COMMON_DEV_DATA Replace part of the content of rte_eth_dev_info with macro RTE_COMMON_DEV_INFO - Added the new global device structure to hold device local data instead of globals. - Some of the simple functions rte_eth_dev_count and others now call rte_dev_count() via macro. The eal_common_device.c and rte_common_device.h could merged into eal_common_dev.c and rte_common_dev.h, which is not done here as to not effect those files. Signed-off-by: Keith Wiles --- lib/librte_ether/rte_ethdev.c | 290 +++++++++--------------------------------- lib/librte_ether/rte_ethdev.h | 225 ++++++++++---------------------- 2 files changed, 126 insertions(+), 389 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index e20cca5..84cef16 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -77,38 +77,20 @@ #define PMD_DEBUG_TRACE(fmt, args...) #endif -/* Macros for checking for restricting functions to primary instance only */ -#define PROC_PRIMARY_OR_ERR_RET(retval) do { \ - if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \ - PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \ - return (retval); \ - } \ -} while(0) -#define PROC_PRIMARY_OR_RET() do { \ - if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \ - PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \ - return; \ - } \ -} while(0) - -/* Macros to check for invlaid function pointers in dev_ops structure */ -#define FUNC_PTR_OR_ERR_RET(func, retval) do { \ - if ((func) == NULL) { \ - PMD_DEBUG_TRACE("Function not supported\n"); \ - return (retval); \ - } \ -} while(0) -#define FUNC_PTR_OR_RET(func) do { \ - if ((func) == NULL) { \ - PMD_DEBUG_TRACE("Function not supported\n"); \ - return; \ - } \ -} while(0) - -static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data"; struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS]; -static struct rte_eth_dev_data *rte_eth_dev_data = NULL; -static uint8_t nb_ports = 0; + +static struct rte_eth_global eth_globals = { + .devs = &rte_eth_devices[0], + .data = NULL, + .nb_ports = 0, + .max_ports = RTE_MAX_ETHPORTS, + .dflt_mtu = ETHER_MTU, + .dev_size = sizeof(struct rte_eth_dev), + .data_size = sizeof(struct rte_eth_dev_data), + .mz_dev_data = "rte_eth_dev_data" +}; + +struct rte_eth_global * rte_eth_globals = ð_globals; /* spinlock for eth device callbacks */ static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER; @@ -155,30 +137,11 @@ static struct rte_eth_xstats_name_off rte_txq_stats_strings[] = { sizeof(rte_txq_stats_strings[0])) -/** - * The user application callback description. - * - * It contains callback address to be registered by user application, - * the pointer to the parameters for callback, and the event type. - */ -struct rte_eth_dev_callback { - TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */ - rte_eth_dev_cb_fn cb_fn; /**< Callback address */ - void *cb_arg; /**< Parameter for callback */ - enum rte_eth_event_type event; /**< Interrupt event type */ - uint32_t active; /**< Callback is executing */ -}; - enum { STAT_QMAP_TX = 0, STAT_QMAP_RX }; -enum { - DEV_DETACHED = 0, - DEV_ATTACHED -}; - static inline void rte_eth_dev_data_alloc(void) { @@ -186,18 +149,18 @@ rte_eth_dev_data_alloc(void) const struct rte_memzone *mz; if (rte_eal_process_type() == RTE_PROC_PRIMARY){ - mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA, - RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data), + mz = rte_memzone_reserve(eth_globals.mz_dev_data, + eth_globals.max_ports * eth_globals.data_size, rte_socket_id(), flags); } else - mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA); + mz = rte_memzone_lookup(eth_globals.mz_dev_data); if (mz == NULL) rte_panic("Cannot allocate memzone for ethernet port data\n"); - rte_eth_dev_data = mz->addr; + eth_globals.data = mz->addr; if (rte_eal_process_type() == RTE_PROC_PRIMARY) - memset(rte_eth_dev_data, 0, - RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data)); + memset(eth_globals.data, 0, + eth_globals.max_ports * eth_globals.data_size); } struct rte_eth_dev * @@ -205,7 +168,7 @@ rte_eth_dev_allocated(const char *name) { unsigned i; - for (i = 0; i < RTE_MAX_ETHPORTS; i++) { + for (i = 0; i < eth_globals.max_ports; i++) { if ((rte_eth_devices[i].attached == DEV_ATTACHED) && strcmp(rte_eth_devices[i].data->name, name) == 0) return &rte_eth_devices[i]; @@ -218,26 +181,26 @@ rte_eth_dev_find_free_port(void) { unsigned i; - for (i = 0; i < RTE_MAX_ETHPORTS; i++) { + for (i = 0; i < eth_globals.max_ports; i++) { if (rte_eth_devices[i].attached == DEV_DETACHED) return i; } - return RTE_MAX_ETHPORTS; + return eth_globals.max_ports; } struct rte_eth_dev * -rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type) +rte_eth_dev_allocate(const char *name, enum rte_dev_type type) { uint8_t port_id; struct rte_eth_dev *eth_dev; port_id = rte_eth_dev_find_free_port(); - if (port_id == RTE_MAX_ETHPORTS) { + if (port_id == eth_globals.max_ports) { PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n"); return NULL; } - if (rte_eth_dev_data == NULL) + if (eth_globals.data == NULL) rte_eth_dev_data_alloc(); if (rte_eth_dev_allocated(name) != NULL) { @@ -246,12 +209,12 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type) } eth_dev = &rte_eth_devices[port_id]; - eth_dev->data = &rte_eth_dev_data[port_id]; + eth_dev->data = ð_globals.data[port_id]; snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name); eth_dev->data->port_id = port_id; eth_dev->attached = DEV_ATTACHED; eth_dev->dev_type = type; - nb_ports++; + eth_globals.nb_ports++; return eth_dev; } @@ -279,7 +242,7 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev) return -EINVAL; eth_dev->attached = 0; - nb_ports--; + eth_globals.nb_ports--; return 0; } @@ -299,7 +262,7 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv, rte_eth_dev_create_unique_device_name(ethdev_name, sizeof(ethdev_name), pci_dev); - eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI); + eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_DEV_PCI); if (eth_dev == NULL) return -ENOMEM; @@ -334,7 +297,7 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv, if (rte_eal_process_type() == RTE_PROC_PRIMARY) rte_free(eth_dev->data->dev_private); eth_dev->attached = DEV_DETACHED; - nb_ports--; + eth_globals.nb_ports--; return diag; } @@ -401,16 +364,6 @@ rte_eth_driver_register(struct eth_driver *eth_drv) rte_eal_pci_register(ð_drv->pci_drv); } -static int -rte_eth_dev_is_valid_port(uint8_t port_id) -{ - if (port_id >= RTE_MAX_ETHPORTS || - rte_eth_devices[port_id].attached != DEV_ATTACHED) - return 0; - else - return 1; -} - int rte_eth_dev_socket_id(uint8_t port_id) { @@ -419,20 +372,14 @@ rte_eth_dev_socket_id(uint8_t port_id) return rte_eth_devices[port_id].pci_dev->numa_node; } -uint8_t -rte_eth_dev_count(void) -{ - return (nb_ports); -} - /* So far, DPDK hotplug function only supports linux */ #ifdef RTE_LIBRTE_EAL_HOTPLUG -static enum rte_eth_dev_type +static enum rte_dev_type rte_eth_dev_get_device_type(uint8_t port_id) { if (!rte_eth_dev_is_valid_port(port_id)) - return RTE_ETH_DEV_UNKNOWN; + return RTE_DEV_UNKNOWN; return rte_eth_devices[port_id].dev_type; } @@ -440,7 +387,7 @@ static int rte_eth_dev_save(struct rte_eth_dev *devs, size_t size) { if ((devs == NULL) || - (size != sizeof(struct rte_eth_dev) * RTE_MAX_ETHPORTS)) + (size != sizeof(struct rte_eth_dev) * eth_globals.max_ports)) return -EINVAL; /* save current rte_eth_devices */ @@ -455,7 +402,7 @@ rte_eth_dev_get_changed_port(struct rte_eth_dev *devs, uint8_t *port_id) return -EINVAL; /* check which port was attached or detached */ - for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++, devs++) { + for (*port_id = 0; *port_id < eth_globals.max_ports; (*port_id)++, devs++) { if (rte_eth_devices[*port_id].attached ^ devs->attached) return 0; } @@ -496,7 +443,7 @@ rte_eth_dev_get_name_by_port(uint8_t port_id, char *name) /* shouldn't check 'rte_eth_devices[i].data', * because it might be overwritten by VDEV PMD */ - tmp = rte_eth_dev_data[port_id].name; + tmp = eth_globals.data[port_id].name; strcpy(name, tmp); return 0; } @@ -506,12 +453,12 @@ rte_eth_dev_is_detachable(uint8_t port_id) { uint32_t drv_flags; - if (port_id >= RTE_MAX_ETHPORTS) { + if (port_id >= eth_globals.max_ports) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -EINVAL; } - if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) { + if (rte_eth_devices[port_id].dev_type == RTE_DEV_PCI) { switch (rte_eth_devices[port_id].pci_dev->kdrv) { case RTE_KDRV_IGB_UIO: case RTE_KDRV_UIO_GENERIC: @@ -691,7 +638,7 @@ rte_eth_dev_detach(uint8_t port_id, char *name) if (name == NULL) return -EINVAL; - if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) { + if (rte_eth_dev_get_device_type(port_id) == RTE_DEV_PCI) { ret = rte_eth_dev_get_addr_by_port(port_id, &addr); if (ret < 0) return ret; @@ -2507,7 +2454,7 @@ rte_eth_dev_rss_reta_query(uint8_t port_id, struct rte_eth_dev *dev; int ret; - if (port_id >= nb_ports) { + if (port_id >= eth_globals.nb_ports) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -ENODEV; } @@ -3178,11 +3125,10 @@ rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset) int rte_eth_dev_callback_register(uint8_t port_id, - enum rte_eth_event_type event, - rte_eth_dev_cb_fn cb_fn, void *cb_arg) + enum rte_dev_event_type event, + rte_dev_cb_fn cb_fn, void *cb_arg) { struct rte_eth_dev *dev; - struct rte_eth_dev_callback *user_cb; if (!cb_fn) return (-EINVAL); @@ -3193,37 +3139,16 @@ rte_eth_dev_callback_register(uint8_t port_id, } dev = &rte_eth_devices[port_id]; - rte_spinlock_lock(&rte_eth_dev_cb_lock); - - TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) { - if (user_cb->cb_fn == cb_fn && - user_cb->cb_arg == cb_arg && - user_cb->event == event) { - break; - } - } - - /* create a new callback. */ - if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK", - sizeof(struct rte_eth_dev_callback), 0)) != NULL) { - user_cb->cb_fn = cb_fn; - user_cb->cb_arg = cb_arg; - user_cb->event = event; - TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next); - } - - rte_spinlock_unlock(&rte_eth_dev_cb_lock); - return ((user_cb == NULL) ? -ENOMEM : 0); + return rte_dev_callback_register(&dev->link_intr_cbs, + &rte_eth_dev_cb_lock, event, cb_fn, cb_arg); } int rte_eth_dev_callback_unregister(uint8_t port_id, - enum rte_eth_event_type event, - rte_eth_dev_cb_fn cb_fn, void *cb_arg) + enum rte_dev_event_type event, + rte_dev_cb_fn cb_fn, void *cb_arg) { - int ret; struct rte_eth_dev *dev; - struct rte_eth_dev_callback *cb, *next; if (!cb_fn) return (-EINVAL); @@ -3234,55 +3159,18 @@ rte_eth_dev_callback_unregister(uint8_t port_id, } dev = &rte_eth_devices[port_id]; - rte_spinlock_lock(&rte_eth_dev_cb_lock); - - ret = 0; - for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) { - - next = TAILQ_NEXT(cb, next); - - if (cb->cb_fn != cb_fn || cb->event != event || - (cb->cb_arg != (void *)-1 && - cb->cb_arg != cb_arg)) - continue; - - /* - * if this callback is not executing right now, - * then remove it. - */ - if (cb->active == 0) { - TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next); - rte_free(cb); - } else { - ret = -EAGAIN; - } - } - - rte_spinlock_unlock(&rte_eth_dev_cb_lock); - return (ret); + return rte_dev_callback_unregister(&dev->link_intr_cbs, + &rte_eth_dev_cb_lock, event, cb_fn, cb_arg); } void _rte_eth_dev_callback_process(struct rte_eth_dev *dev, - enum rte_eth_event_type event) + enum rte_dev_event_type event) { - struct rte_eth_dev_callback *cb_lst; - struct rte_eth_dev_callback dev_cb; - - rte_spinlock_lock(&rte_eth_dev_cb_lock); - TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) { - if (cb_lst->cb_fn == NULL || cb_lst->event != event) - continue; - dev_cb = *cb_lst; - cb_lst->active = 1; - rte_spinlock_unlock(&rte_eth_dev_cb_lock); - dev_cb.cb_fn(dev->data->port_id, dev_cb.event, - dev_cb.cb_arg); - rte_spinlock_lock(&rte_eth_dev_cb_lock); - cb_lst->active = 0; - } - rte_spinlock_unlock(&rte_eth_dev_cb_lock); + rte_dev_callback_process(&dev->link_intr_cbs, dev->data->port_id, + event, &rte_eth_dev_cb_lock); } + #ifdef RTE_NIC_BYPASS int rte_eth_dev_bypass_init(uint8_t port_id) { @@ -3510,18 +3398,7 @@ rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id, return NULL; } - struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0); - - if (cb == NULL) { - rte_errno = ENOMEM; - return NULL; - } - - cb->fn.rx = fn; - cb->param = user_param; - cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id]; - rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb; - return cb; + return rte_dev_add_callback(&rte_eth_devices[port_id].post_rx_burst_cbs[queue_id], fn, user_param); } void * @@ -3539,23 +3416,12 @@ rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id, return NULL; } - struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0); - - if (cb == NULL) { - rte_errno = ENOMEM; - return NULL; - } - - cb->fn.tx = fn; - cb->param = user_param; - cb->next = rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id]; - rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb; - return cb; + return rte_dev_add_callback(&rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id], fn, user_param); } int rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id, - struct rte_eth_rxtx_callback *user_cb) + struct rte_dev_rxtx_callback *user_cb) { #ifndef RTE_ETHDEV_RXTX_CALLBACKS return (-ENOTSUP); @@ -3567,34 +3433,13 @@ rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id, } struct rte_eth_dev *dev = &rte_eth_devices[port_id]; - struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id]; - struct rte_eth_rxtx_callback *prev_cb; - /* Reset head pointer and remove user cb if first in the list. */ - if (cb == user_cb) { - dev->post_rx_burst_cbs[queue_id] = user_cb->next; - return 0; - } - - /* Remove the user cb from the callback list. */ - do { - prev_cb = cb; - cb = cb->next; - - if (cb == user_cb) { - prev_cb->next = user_cb->next; - return 0; - } - - } while (cb != NULL); - - /* Callback wasn't found. */ - return (-EINVAL); + return rte_dev_remove_callback(&dev->post_rx_burst_cbs[queue_id], user_cb); } int rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id, - struct rte_eth_rxtx_callback *user_cb) + struct rte_dev_rxtx_callback *user_cb) { #ifndef RTE_ETHDEV_RXTX_CALLBACKS return (-ENOTSUP); @@ -3606,27 +3451,6 @@ rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id, } struct rte_eth_dev *dev = &rte_eth_devices[port_id]; - struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id]; - struct rte_eth_rxtx_callback *prev_cb; - - /* Reset head pointer and remove user cb if first in the list. */ - if (cb == user_cb) { - dev->pre_tx_burst_cbs[queue_id] = user_cb->next; - return 0; - } - - /* Remove the user cb from the callback list. */ - do { - prev_cb = cb; - cb = cb->next; - - if (cb == user_cb) { - prev_cb->next = user_cb->next; - return 0; - } - - } while (cb != NULL); - /* Callback wasn't found. */ - return (-EINVAL); + return rte_dev_remove_callback(&dev->pre_tx_burst_cbs[queue_id], user_cb); } diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index e8df027..991e8a5 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -178,6 +178,7 @@ extern "C" { #include #include #include +#include #include "rte_ether.h" #include "rte_eth_ctrl.h" @@ -896,10 +897,8 @@ struct rte_eth_conf { #define DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM 0x00000080 /**< Used for tunneling packet. */ struct rte_eth_dev_info { - struct rte_pci_device *pci_dev; /**< Device PCI information. */ - const char *driver_name; /**< Device Driver name. */ - unsigned int if_index; /**< Index to bound host interface, or 0 if none. - Use if_indextoname() to translate into an interface name. */ + RTE_COMMON_DEV_INFO; + uint32_t min_rx_bufsize; /**< Minimum size of RX buffer. */ uint32_t max_rx_pktlen; /**< Maximum configurable length of RX pkt. */ uint16_t max_rx_queues; /**< Maximum number of RX queues. */ @@ -939,10 +938,6 @@ struct rte_eth_xstats { struct rte_eth_dev; -struct rte_eth_dev_callback; -/** @internal Structure to keep track of registered callbacks */ -TAILQ_HEAD(rte_eth_dev_cb_list, rte_eth_dev_callback); - /* * Definitions of all functions exported by an Ethernet driver through the * the generic structure of type *eth_dev_ops* supplied in the *rte_eth_dev* @@ -1065,16 +1060,6 @@ typedef void (*vlan_strip_queue_set_t)(struct rte_eth_dev *dev, int on); /**< @internal VLAN stripping enable/disable by an queue of Ethernet device. */ -typedef uint16_t (*eth_rx_burst_t)(void *rxq, - struct rte_mbuf **rx_pkts, - uint16_t nb_pkts); -/**< @internal Retrieve input packets from a receive queue of an Ethernet device. */ - -typedef uint16_t (*eth_tx_burst_t)(void *txq, - struct rte_mbuf **tx_pkts, - uint16_t nb_pkts); -/**< @internal Send output packets on a transmit queue of an Ethernet device. */ - typedef int (*fdir_add_signature_filter_t)(struct rte_eth_dev *dev, struct rte_fdir_filter *fdir_ftr, uint8_t rx_queue); @@ -1384,80 +1369,6 @@ struct eth_dev_ops { }; /** - * Function type used for RX packet processing packet callbacks. - * - * The callback function is called on RX with a burst of packets that have - * been received on the given port and queue. - * - * @param port - * The Ethernet port on which RX is being performed. - * @param queue - * The queue on the Ethernet port which is being used to receive the packets. - * @param pkts - * The burst of packets that have just been received. - * @param nb_pkts - * The number of packets in the burst pointed to by "pkts". - * @param max_pkts - * The max number of packets that can be stored in the "pkts" array. - * @param user_param - * The arbitrary user parameter passed in by the application when the callback - * was originally configured. - * @return - * The number of packets returned to the user. - */ -typedef uint16_t (*rte_rx_callback_fn)(uint8_t port, uint16_t queue, - struct rte_mbuf *pkts[], uint16_t nb_pkts, uint16_t max_pkts, - void *user_param); - -/** - * Function type used for TX packet processing packet callbacks. - * - * The callback function is called on TX with a burst of packets immediately - * before the packets are put onto the hardware queue for transmission. - * - * @param port - * The Ethernet port on which TX is being performed. - * @param queue - * The queue on the Ethernet port which is being used to transmit the packets. - * @param pkts - * The burst of packets that are about to be transmitted. - * @param nb_pkts - * The number of packets in the burst pointed to by "pkts". - * @param user_param - * The arbitrary user parameter passed in by the application when the callback - * was originally configured. - * @return - * The number of packets to be written to the NIC. - */ -typedef uint16_t (*rte_tx_callback_fn)(uint8_t port, uint16_t queue, - struct rte_mbuf *pkts[], uint16_t nb_pkts, void *user_param); - -/** - * @internal - * Structure used to hold information about the callbacks to be called for a - * queue on RX and TX. - */ -struct rte_eth_rxtx_callback { - struct rte_eth_rxtx_callback *next; - union{ - rte_rx_callback_fn rx; - rte_tx_callback_fn tx; - } fn; - void *param; -}; - -/* - * The eth device type - */ -enum rte_eth_dev_type { - RTE_ETH_DEV_UNKNOWN, /**< unknown device type */ - RTE_ETH_DEV_PCI, - /**< Physical function and Virtual function of PCI devices */ - RTE_ETH_DEV_VIRTUAL, /**< non hardware device */ - RTE_ETH_DEV_MAX /**< max value of this enum */ -}; - -/** * @internal * The generic data structure associated with each ethernet device. * @@ -1468,26 +1379,7 @@ enum rte_eth_dev_type { * process, while the actual configuration data for the device is shared. */ struct rte_eth_dev { - eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */ - eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */ - struct rte_eth_dev_data *data; /**< Pointer to device data */ - const struct eth_driver *driver;/**< Driver for this device */ - struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */ - struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing */ - /** User application callbacks for NIC interrupts */ - struct rte_eth_dev_cb_list link_intr_cbs; - /** - * User-supplied functions called from rx_burst to post-process - * received packets before passing them to the user - */ - struct rte_eth_rxtx_callback *post_rx_burst_cbs[RTE_MAX_QUEUES_PER_PORT]; - /** - * User-supplied functions called from tx_burst to pre-process - * received packets before passing them to the driver for transmission. - */ - struct rte_eth_rxtx_callback *pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT]; - uint8_t attached; /**< Flag indicating the port is attached */ - enum rte_eth_dev_type dev_type; /**< Flag indicating the device type */ + RTE_COMMON_DEV(eth_); }; struct rte_eth_dev_sriov { @@ -1498,7 +1390,7 @@ struct rte_eth_dev_sriov { }; #define RTE_ETH_DEV_SRIOV(dev) ((dev)->data->sriov) -#define RTE_ETH_NAME_MAX_LEN (32) +#define RTE_ETH_NAME_MAX_LEN RTE_DEV_NAME_MAX_LEN /** * @internal @@ -1508,33 +1400,20 @@ struct rte_eth_dev_sriov { * processes in a multi-process configuration. */ struct rte_eth_dev_data { - char name[RTE_ETH_NAME_MAX_LEN]; /**< Unique identifier name */ - - void **rx_queues; /**< Array of pointers to RX queues. */ - void **tx_queues; /**< Array of pointers to TX queues. */ - uint16_t nb_rx_queues; /**< Number of RX queues. */ - uint16_t nb_tx_queues; /**< Number of TX queues. */ + RTE_COMMON_DEV_DATA; struct rte_eth_dev_sriov sriov; /**< SRIOV data */ - void *dev_private; /**< PMD-specific private data */ - struct rte_eth_link dev_link; /**< Link-level information & status */ struct rte_eth_conf dev_conf; /**< Configuration applied to device. */ - uint16_t mtu; /**< Maximum Transmission Unit. */ - - uint32_t min_rx_buf_size; - /**< Common rx buffer size handled by all queues */ - - uint64_t rx_mbuf_alloc_failed; /**< RX ring mbuf allocation failures. */ - struct ether_addr* mac_addrs;/**< Device Ethernet Link address. */ + struct ether_addr* mac_addrs; /**< Device Ethernet Link address. */ uint64_t mac_pool_sel[ETH_NUM_RECEIVE_MAC_ADDR]; /** bitmap array of associating Ethernet MAC addresses to pools */ struct ether_addr* hash_mac_addrs; + /** Device Ethernet MAC addresses of hash filtering. */ - uint8_t port_id; /**< Device [external] port identifier. */ uint8_t promiscuous : 1, /**< RX promiscuous mode ON(1) / OFF(0). */ scattered_rx : 1, /**< RX of scattered packets is ON(1) / OFF(0) */ all_multicast : 1, /**< RX all multicast mode ON(1) / OFF(0). */ @@ -1549,6 +1428,41 @@ struct rte_eth_dev_data { extern struct rte_eth_dev rte_eth_devices[]; /** + * @internal + * A global structure to hold global values per device type. + */ +struct rte_eth_global { + RTE_COMMON_GLOBAL(eth_); +}; + +/** + * @internal + * The Ethernet device data structure. Look in file. + */ +extern struct rte_eth_global *rte_eth_globals; + +/** + * Return the global structure pointer. + * + * @return + * Return the global structure pointer. + */ +static inline struct rte_eth_global * rte_eth_dev_global(void) { + return rte_eth_globals; +} + +/** + * Validate if the port number is valid + * + * @param port_id Port ID value to select the device. + * + * @return + * - Number of ports found in the system. + */ +#define rte_eth_dev_is_valid_port(port_id) \ + rte_dev_is_valid_port((struct rte_pkt_global *)rte_eth_globals, port_id) + +/** * Get the total number of Ethernet devices that have been successfully * initialized by the [matching] Ethernet driver during the PCI probing phase. * All devices whose port identifier is in the range @@ -1561,7 +1475,20 @@ extern struct rte_eth_dev rte_eth_devices[]; * @return * - The total number of usable Ethernet devices. */ -extern uint8_t rte_eth_dev_count(void); +#define rte_eth_dev_count() \ + rte_dev_count((struct rte_dev_global *)rte_eth_globals) + +/** + * Get the rte_eth_dev structure device pointer for the device. + * + * @param pid + * Port ID value to select the device structure. + * + * @return + * - The rte_eth_dev structure pointer for the given port ID. + */ +#define rte_eth_get_dev(pid) \ + (struct rte_eth_dev *)rte_get_dev((struct rte_dev_global *)rte_eth_globals, pid) /** * Function for internal use by port hotplug functions. @@ -1585,7 +1512,7 @@ extern struct rte_eth_dev *rte_eth_dev_allocated(const char *name); * - Slot in the rte_dev_devices array for a new device; */ struct rte_eth_dev *rte_eth_dev_allocate(const char *name, - enum rte_eth_dev_type type); + enum rte_dev_type type); /** * Function for internal use by dummy drivers primarily, e.g. ring-based @@ -2418,7 +2345,7 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id, rx_pkts, nb_pkts); #ifdef RTE_ETHDEV_RXTX_CALLBACKS - struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id]; + struct rte_dev_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id]; if (unlikely(cb != NULL)) { do { @@ -2558,7 +2485,7 @@ rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id, dev = &rte_eth_devices[port_id]; #ifdef RTE_ETHDEV_RXTX_CALLBACKS - struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id]; + struct rte_dev_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id]; if (unlikely(cb != NULL)) { do { @@ -2789,20 +2716,6 @@ int rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id, int rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask); -/** - * The eth device event type for interrupt, and maybe others in the future. - */ -enum rte_eth_event_type { - RTE_ETH_EVENT_UNKNOWN, /**< unknown event type */ - RTE_ETH_EVENT_INTR_LSC, /**< lsc interrupt event */ - RTE_ETH_EVENT_MAX /**< max value of this enum */ -}; - -typedef void (*rte_eth_dev_cb_fn)(uint8_t port_id, \ - enum rte_eth_event_type event, void *cb_arg); -/**< user application callback to be registered for interrupts */ - - /** * Register a callback function for specific port id. @@ -2821,8 +2734,8 @@ typedef void (*rte_eth_dev_cb_fn)(uint8_t port_id, \ * - On failure, a negative value. */ int rte_eth_dev_callback_register(uint8_t port_id, - enum rte_eth_event_type event, - rte_eth_dev_cb_fn cb_fn, void *cb_arg); + enum rte_dev_event_type event, + rte_dev_cb_fn cb_fn, void *cb_arg); /** * Unregister a callback function for specific port id. @@ -2842,8 +2755,8 @@ int rte_eth_dev_callback_register(uint8_t port_id, * - On failure, a negative value. */ int rte_eth_dev_callback_unregister(uint8_t port_id, - enum rte_eth_event_type event, - rte_eth_dev_cb_fn cb_fn, void *cb_arg); + enum rte_dev_event_type event, + rte_dev_cb_fn cb_fn, void *cb_arg); /** * @internal Executes all the user application registered callbacks for @@ -2859,7 +2772,7 @@ int rte_eth_dev_callback_unregister(uint8_t port_id, * void */ void _rte_eth_dev_callback_process(struct rte_eth_dev *dev, - enum rte_eth_event_type event); + enum rte_dev_event_type event); /** * Turn on the LED on the Ethernet device. @@ -3512,7 +3425,7 @@ int rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type, * On success, a pointer value which can later be used to remove the callback. */ void *rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id, - rte_rx_callback_fn fn, void *user_param); + rte_rx_callback_fn fn, void *user_param); /** * Add a callback to be called on packet TX on a given port and queue. @@ -3537,7 +3450,7 @@ void *rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id, * On success, a pointer value which can later be used to remove the callback. */ void *rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id, - rte_tx_callback_fn fn, void *user_param); + rte_tx_callback_fn fn, void *user_param); /** * Remove an RX packet callback from a given port and queue. @@ -3570,7 +3483,7 @@ void *rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id, * is NULL or not found for the port/queue. */ int rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id, - struct rte_eth_rxtx_callback *user_cb); + struct rte_dev_rxtx_callback *user_cb); /** * Remove a TX packet callback from a given port and queue. @@ -3603,7 +3516,7 @@ int rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id, * is NULL or not found for the port/queue. */ int rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id, - struct rte_eth_rxtx_callback *user_cb); + struct rte_dev_rxtx_callback *user_cb); #ifdef __cplusplus } -- 2.3.0