summaryrefslogtreecommitdiff
path: root/lib/librte_eal
diff options
context:
space:
mode:
authorIntel <intel.com>2013-09-18 12:00:00 +0200
committerThomas Monjalon <thomas.monjalon@6wind.com>2013-10-09 16:16:15 +0200
commitfbf895d44cfebf7bd92bb4edf3f7ff15365e57a5 (patch)
treef723b0d22fb5f0dfd5eb4a37204c2d2bb6cf678b /lib/librte_eal
parent0b44a857c8b4e3ba4e2f24d5bb4cc52acbafa897 (diff)
downloaddpdk-fbf895d44cfebf7bd92bb4edf3f7ff15365e57a5.zip
dpdk-fbf895d44cfebf7bd92bb4edf3f7ff15365e57a5.tar.gz
dpdk-fbf895d44cfebf7bd92bb4edf3f7ff15365e57a5.tar.xz
kni: identify device by name
Some old API functions based on port_id are deprecated. Signed-off-by: Intel
Diffstat (limited to 'lib/librte_eal')
-rwxr-xr-xlib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h18
-rw-r--r--lib/librte_eal/linuxapp/kni/kni_dev.h4
-rw-r--r--lib/librte_eal/linuxapp/kni/kni_misc.c38
-rw-r--r--lib/librte_eal/linuxapp/kni/kni_net.c4
4 files changed, 46 insertions, 18 deletions
diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
index 7980404..6a8de7f 100755
--- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
+++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
@@ -63,6 +63,11 @@
#include <linux/if.h>
#endif
+/**
+ * KNI name is part of memzone name.
+ */
+#define RTE_KNI_NAMESIZE 32
+
/*
* Request id.
*/
@@ -118,9 +123,8 @@ struct rte_kni_mbuf {
* Struct used to create a KNI device. Passed to the kernel in IOCTL call
*/
-struct rte_kni_device_info
-{
- char name[IFNAMSIZ];
+struct rte_kni_device_info {
+ char name[RTE_KNI_NAMESIZE]; /**< Network device name for KNI */
phys_addr_t tx_phys;
phys_addr_t rx_phys;
@@ -143,7 +147,11 @@ struct rte_kni_device_info
uint8_t bus; /**< Device bus */
uint8_t devid; /**< Device ID */
uint8_t function; /**< Device function. */
- uint8_t port_id; /**< Port ID */
+
+ uint16_t group_id; /**< Group ID */
+ uint32_t core_id; /**< core ID to bind for kernel thread */
+
+ uint8_t force_bind : 1; /**< Flag for kernel thread binding */
/* mbuf size */
unsigned mbuf_size;
@@ -153,6 +161,6 @@ struct rte_kni_device_info
#define RTE_KNI_IOCTL_TEST _IOWR(0, 1, int)
#define RTE_KNI_IOCTL_CREATE _IOWR(0, 2, struct rte_kni_device_info)
-#define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, uint8_t)
+#define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info)
#endif /* _RTE_KNI_COMMON_H_ */
diff --git a/lib/librte_eal/linuxapp/kni/kni_dev.h b/lib/librte_eal/linuxapp/kni/kni_dev.h
index fda9432..cb13888 100644
--- a/lib/librte_eal/linuxapp/kni/kni_dev.h
+++ b/lib/librte_eal/linuxapp/kni/kni_dev.h
@@ -32,6 +32,7 @@
#include <linux/spinlock.h>
#include <linux/list.h>
+#include <exec-env/rte_kni_common.h>
#define KNI_KTHREAD_RESCHEDULE_INTERVAL 10 /* us */
/**
@@ -44,7 +45,8 @@ struct kni_dev {
struct net_device_stats stats;
int status;
- int port_id;
+ uint16_t group_id; /* Group ID of a group of KNI devices */
+ char name[RTE_KNI_NAMESIZE]; /* Network device name */
/* wait queue for req/resp */
wait_queue_head_t wq;
diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
index 4ef210d..9adf697 100644
--- a/lib/librte_eal/linuxapp/kni/kni_misc.c
+++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
@@ -200,6 +200,21 @@ kni_thread(void *unused)
}
static int
+kni_check_param(struct kni_dev *kni, struct rte_kni_device_info *dev)
+{
+ if (!kni || !dev)
+ return -1;
+
+ /* Check if network name has been used */
+ if (!strncmp(kni->name, dev->name, RTE_KNI_NAMESIZE)) {
+ KNI_ERR("KNI name %s duplicated\n", dev->name);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
{
int ret;
@@ -225,10 +240,8 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
/* Check if it has been created */
down_read(&kni_list_lock);
list_for_each_entry_safe(dev, n, &kni_list_head, list) {
- if (dev->port_id == dev_info.port_id) {
+ if (kni_check_param(dev, &dev_info) < 0) {
up_read(&kni_list_lock);
- KNI_ERR("Port %d has already been created\n",
- dev_info.port_id);
return -EINVAL;
}
}
@@ -244,7 +257,8 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
kni = netdev_priv(net_dev);
kni->net_dev = net_dev;
- kni->port_id = dev_info.port_id;
+ kni->group_id = dev_info.group_id;
+ strncpy(kni->name, dev_info.name, RTE_KNI_NAMESIZE);
/* Translate user space info into kernel space info */
kni->tx_q = phys_to_virt(dev_info.tx_phys);
@@ -353,21 +367,25 @@ static int
kni_ioctl_release(unsigned int ioctl_num, unsigned long ioctl_param)
{
int ret = -EINVAL;
- uint8_t port_id;
struct kni_dev *dev, *n;
+ struct rte_kni_device_info dev_info;
- if (_IOC_SIZE(ioctl_num) > sizeof(port_id))
+ if (_IOC_SIZE(ioctl_num) > sizeof(dev_info))
return -EINVAL;
- ret = copy_from_user(&port_id, (void *)ioctl_param, sizeof(port_id));
+ ret = copy_from_user(&dev_info, (void *)ioctl_param, sizeof(dev_info));
if (ret) {
KNI_ERR("copy_from_user in kni_ioctl_release");
return -EIO;
}
+ /* Release the network device according to its name */
+ if (strlen(dev_info.name) == 0)
+ return ret;
+
down_write(&kni_list_lock);
list_for_each_entry_safe(dev, n, &kni_list_head, list) {
- if (dev->port_id != port_id)
+ if (strncmp(dev->name, dev_info.name, RTE_KNI_NAMESIZE) != 0)
continue;
switch (dev->device_id) {
@@ -389,8 +407,8 @@ kni_ioctl_release(unsigned int ioctl_num, unsigned long ioctl_param)
break;
}
up_write(&kni_list_lock);
- printk(KERN_INFO "KNI: %s release kni for port %d\n",
- (ret == 0 ? "Successfully" : "Unsuccessfully"), port_id);
+ printk(KERN_INFO "KNI: %s release kni named %s\n",
+ (ret == 0 ? "Successfully" : "Unsuccessfully"), dev_info.name);
return ret;
}
diff --git a/lib/librte_eal/linuxapp/kni/kni_net.c b/lib/librte_eal/linuxapp/kni/kni_net.c
index 2e27663..823c321 100644
--- a/lib/librte_eal/linuxapp/kni/kni_net.c
+++ b/lib/librte_eal/linuxapp/kni/kni_net.c
@@ -535,8 +535,8 @@ kni_net_tx_timeout (struct net_device *dev)
static int
kni_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
{
- struct kni_dev *kni = netdev_priv(dev);
- KNI_DBG("kni_net_ioctl %d\n", kni->port_id);
+ KNI_DBG("kni_net_ioctl %d\n",
+ ((struct kni_dev *)netdev_priv(dev))->group_id);
return 0;
}