From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id BDD0C5A08 for ; Tue, 19 May 2015 02:54:31 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP; 18 May 2015 17:54:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,456,1427785200"; d="scan'208";a="495298861" Received: from pgsmsx105.gar.corp.intel.com ([10.221.44.96]) by FMSMGA003.fm.intel.com with ESMTP; 18 May 2015 17:54:28 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by PGSMSX105.gar.corp.intel.com (10.221.44.96) with Microsoft SMTP Server (TLS) id 14.3.224.2; Tue, 19 May 2015 08:54:24 +0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.94]) by SHSMSX101.ccr.corp.intel.com ([10.239.4.153]) with mapi id 14.03.0224.002; Tue, 19 May 2015 08:54:23 +0800 From: "Zhang, Helin" To: Vijayakumar Muthuvel Manickam , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] kni: Add link status update Thread-Index: AQHQkcM+hN/Dynd+u06WVBRIYcSUdJ2CeCZw Date: Tue, 19 May 2015 00:54:22 +0000 Message-ID: References: <1431992009-13573-1-git-send-email-mmvijay@gmail.com> In-Reply-To: <1431992009-13573-1-git-send-email-mmvijay@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] kni: Add link status update 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: Tue, 19 May 2015 00:54:32 -0000 Hello > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Vijayakumar > Muthuvel Manickam > Sent: Tuesday, May 19, 2015 7:33 AM > To: dev@dpdk.org > Subject: [dpdk-dev] [PATCH] kni: Add link status update >=20 > Add an ioctl command in rte_kni module to enable DPDK applications to > propagate link state changes to kni virtual interfaces. >=20 > Signed-off-by: Vijayakumar Muthuvel Manickam > --- > .../linuxapp/eal/include/exec-env/rte_kni_common.h | 2 ++ > lib/librte_eal/linuxapp/kni/kni_misc.c | 39 > ++++++++++++++++++++++ > lib/librte_kni/rte_kni.c | 18 ++++++++++ > lib/librte_kni/rte_kni.h | 17 ++++++++++ > 4 files changed, 76 insertions(+) >=20 > 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 1e55c2d..b68001d 100644 > --- 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 > @@ -163,6 +163,7 @@ struct rte_kni_device_info { >=20 > /* mbuf size */ > unsigned mbuf_size; > + uint8_t link_state; How about transfer more states from user space to kernel space, such as lin= k speed, duplex, etc? > }; >=20 > #define KNI_DEVICE "kni" > @@ -170,5 +171,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, > struct rte_kni_device_info) > +#define RTE_KNI_IOCTL_LINK_UPDATE _IOWR(0, 4, struct > +rte_kni_device_info) >=20 > #endif /* _RTE_KNI_COMMON_H_ */ > diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c > b/lib/librte_eal/linuxapp/kni/kni_misc.c > index 1935d32..b1015cd 100644 > --- a/lib/librte_eal/linuxapp/kni/kni_misc.c > +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c > @@ -548,6 +548,42 @@ kni_ioctl_release(unsigned int ioctl_num, > unsigned long ioctl_param) } >=20 > static int > +kni_ioctl_update_link_state(unsigned int ioctl_num, unsigned long > +ioctl_param) { > + int ret =3D -EINVAL; > + struct kni_dev *dev, *n; > + struct rte_kni_device_info dev_info; > + > + if (_IOC_SIZE(ioctl_num) > sizeof(dev_info)) > + return -EINVAL; > + > + ret =3D copy_from_user(&dev_info, (void *)ioctl_param, > sizeof(dev_info)); > + if (ret) { > + KNI_ERR("copy_from_user in kni_ioctl_update_link_status"); > + return -EIO; > + } > + > + if (strlen(dev_info.name) =3D=3D 0) > + return ret; > + > + down_write(&kni_list_lock); > + list_for_each_entry_safe(dev, n, &kni_list_head, list) { > + if (strncmp(dev->name, dev_info.name, RTE_KNI_NAMESIZE) !=3D > 0) > + continue; > + > + if (dev_info.link_state =3D=3D 0) > + netif_carrier_off(dev->net_dev); > + else > + netif_carrier_on(dev->net_dev); > + ret =3D 0; > + break; > + } > + up_write(&kni_list_lock); > + > + return ret; > +} > + > +static int > kni_ioctl(struct inode *inode, > unsigned int ioctl_num, > unsigned long ioctl_param) > @@ -569,6 +605,9 @@ kni_ioctl(struct inode *inode, > case _IOC_NR(RTE_KNI_IOCTL_RELEASE): > ret =3D kni_ioctl_release(ioctl_num, ioctl_param); > break; > + case _IOC_NR(RTE_KNI_IOCTL_LINK_UPDATE): > + ret =3D kni_ioctl_update_link_state(ioctl_num, ioctl_param); > + break; > default: > KNI_DBG("IOCTL default \n"); > break; > diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index > 4e70fa0..b6eda8a 100644 > --- a/lib/librte_kni/rte_kni.c > +++ b/lib/librte_kni/rte_kni.c > @@ -512,6 +512,24 @@ rte_kni_release(struct rte_kni *kni) } >=20 > int > +rte_kni_update_link_state(struct rte_kni *kni, uint8_t if_up) { > + struct rte_kni_device_info dev_info; > + > + if (!kni || !kni->in_use) > + return -1; > + > + snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name); > + dev_info.link_state =3D if_up; > + if (ioctl(kni_fd, RTE_KNI_IOCTL_LINK_UPDATE, &dev_info) < 0) { > + RTE_LOG(ERR, KNI, "Fail to update link state\n"); > + return -1; > + } > + > + return 0; > +} > + This new interface should be called at the end of rte_kni_alloc() to notify the link status after a KNI interface is created. Thanks, Helin > +int > rte_kni_handle_request(struct rte_kni *kni) { > unsigned ret; > diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h index > 98edd72..a1bafd9 100644 > --- a/lib/librte_kni/rte_kni.h > +++ b/lib/librte_kni/rte_kni.h > @@ -167,6 +167,23 @@ extern struct rte_kni *rte_kni_create(uint8_t > port_id, extern int rte_kni_release(struct rte_kni *kni); >=20 > /** > + * Send link state changes to KNI interface in kernel space > + * > + * rte_kni_update_link_state is thread safe. > + * > + * @param kni > + * The pointer to the context of an existent KNI interface. > + * @param if_up > + * interface link status > + * > + * @return > + * - 0 indicates success. > + * - negative value indicates failure. > + */ > + > +extern int rte_kni_update_link_state(struct rte_kni *kni, uint8_t > +if_up); > + > +/** > * It is used to handle the request mbufs sent from kernel space. > * Then analyzes it and calls the specific actions for the specific requ= ests. > * Finally constructs the response mbuf and puts it back to the resp_q. > -- > 1.8.1.4