From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 183617D19 for ; Mon, 15 Jan 2018 11:49:16 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jan 2018 02:49:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,363,1511856000"; d="scan'208";a="22237607" Received: from jeffguo-z170x-ud5.sh.intel.com (HELO localhost.localdomain) ([10.67.104.10]) by fmsmga001.fm.intel.com with ESMTP; 15 Jan 2018 02:49:14 -0800 From: Jeff Guo To: stephen@networkplumber.org, bruce.richardson@intel.com, ferruh.yigit@intel.com, gaetan.rivet@6wind.com Cc: konstantin.ananyev@intel.com, jblunck@infradead.org, shreyansh.jain@nxp.com, jingjing.wu@intel.com, dev@dpdk.org, jia.guo@intel.com, thomas@monjalon.net, helin.zhang@intel.com, motih@mellanox.com Date: Mon, 15 Jan 2018 18:48:50 +0800 Message-Id: <1516013331-18939-2-git-send-email-jia.guo@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516013331-18939-1-git-send-email-jia.guo@intel.com> References: <1515679534-22473-2-git-send-email-jia.guo@intel.com> <1516013331-18939-1-git-send-email-jia.guo@intel.com> Subject: [dpdk-dev] [PATCH V11 2/3] eal: add uevent pass and process function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Jan 2018 10:49:17 -0000 In order to handle the uevent which have been detected from the kernel side, add uevent process function, let hot plug event to be example to show uevent mechanism how to pass the uevent and process the uevent. About uevent passing and processing, add below functions in linux eal dev layer. FreeBSD not support uevent ,so let it to be void and do not implement in function. a.dev_uev_parse b.dev_uev_receive c.dev_uev_process Signed-off-by: Jeff Guo --- v11->v10: fix some typo issue. --- lib/librte_eal/common/include/rte_dev.h | 17 +++++ lib/librte_eal/linuxapp/eal/eal_dev.c | 110 +++++++++++++++++++++++++++++++- 2 files changed, 125 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index f6c9acb..0dbbaa8 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -51,6 +51,23 @@ extern "C" { #include +#define RTE_EAL_UEV_MSG_LEN 4096 +#define RTE_EAL_UEV_MSG_ELEM_LEN 128 + +enum rte_dev_state { + RTE_DEV_UNDEFINED, /**< unknown device state */ + RTE_DEV_FAULT, /**< device fault or error */ + RTE_DEV_PARSED, /**< device has been scanned on bus*/ + RTE_DEV_PROBED, /**< device has been probed driver */ +}; + +enum rte_dev_event_subsystem { + RTE_DEV_EVENT_SUBSYSTEM_UIO, + RTE_DEV_EVENT_SUBSYSTEM_VFIO, + RTE_DEV_EVENT_SUBSYSTEM_PCI, + RTE_DEV_EVENT_SUBSYSTEM_MAX +}; + /** * The device event type. */ diff --git a/lib/librte_eal/linuxapp/eal/eal_dev.c b/lib/librte_eal/linuxapp/eal/eal_dev.c index 4f4beb5..bda4618 100644 --- a/lib/librte_eal/linuxapp/eal/eal_dev.c +++ b/lib/librte_eal/linuxapp/eal/eal_dev.c @@ -79,10 +79,116 @@ dev_monitor_enable(int netlink_fd) return -1; } +static void +dev_uev_parse(const char *buf, struct rte_dev_event *event) +{ + char action[RTE_EAL_UEV_MSG_ELEM_LEN]; + char subsystem[RTE_EAL_UEV_MSG_ELEM_LEN]; + char dev_path[RTE_EAL_UEV_MSG_ELEM_LEN]; + char pci_slot_name[RTE_EAL_UEV_MSG_ELEM_LEN]; + int i = 0; + + memset(action, 0, RTE_EAL_UEV_MSG_ELEM_LEN); + memset(subsystem, 0, RTE_EAL_UEV_MSG_ELEM_LEN); + memset(dev_path, 0, RTE_EAL_UEV_MSG_ELEM_LEN); + memset(pci_slot_name, 0, RTE_EAL_UEV_MSG_ELEM_LEN); + + while (i < RTE_EAL_UEV_MSG_LEN) { + for (; i < RTE_EAL_UEV_MSG_LEN; i++) { + if (*buf) + break; + buf++; + } + if (!strncmp(buf, "libudev", 7)) { + buf += 7; + i += 7; + return; + } + if (!strncmp(buf, "ACTION=", 7)) { + buf += 7; + i += 7; + snprintf(action, sizeof(action), "%s", buf); + } else if (!strncmp(buf, "DEVPATH=", 8)) { + buf += 8; + i += 8; + snprintf(dev_path, sizeof(dev_path), "%s", buf); + } else if (!strncmp(buf, "SUBSYSTEM=", 10)) { + buf += 10; + i += 10; + snprintf(subsystem, sizeof(subsystem), "%s", buf); + } else if (!strncmp(buf, "PCI_SLOT_NAME=", 14)) { + buf += 14; + i += 14; + snprintf(pci_slot_name, sizeof(subsystem), "%s", buf); + event->devname = pci_slot_name; + } + for (; i < RTE_EAL_UEV_MSG_LEN; i++) { + if (*buf == '\0') + break; + buf++; + } + } + + if (!strncmp(subsystem, "pci", 3)) + event->subsystem = RTE_DEV_EVENT_SUBSYSTEM_UIO; + if (!strncmp(action, "add", 3)) + event->type = RTE_DEV_EVENT_ADD; + if (!strncmp(action, "remove", 6)) + event->type = RTE_DEV_EVENT_REMOVE; + event->devname = pci_slot_name; +} + +static int +dev_uev_receive(int fd, struct rte_dev_event *uevent) +{ + int ret; + char buf[RTE_EAL_UEV_MSG_LEN]; + + memset(uevent, 0, sizeof(struct rte_dev_event)); + memset(buf, 0, RTE_EAL_UEV_MSG_LEN); + + ret = recv(fd, buf, RTE_EAL_UEV_MSG_LEN - 1, MSG_DONTWAIT); + if (ret < 0) { + RTE_LOG(ERR, EAL, + "Socket read error(%d): %s\n", + errno, strerror(errno)); + return -1; + } else if (ret == 0) + /* connection closed */ + return -1; + + dev_uev_parse(buf, uevent); + + return 0; +} + static int -dev_uev_process(__rte_unused struct epoll_event *events, __rte_unused int nfds) +dev_uev_process(struct epoll_event *events, int nfds) { - /* TODO: device uevent processing */ + struct rte_dev_event uevent; + int i; + + for (i = 0; i < nfds; i++) { + /** + * check device uevent from kernel side, no need to check + * uevent from udev. + */ + if (dev_uev_receive(events[i].data.fd, &uevent)) + return 0; + + /* default handle all pci devcie when is being hot plug */ + if (uevent.subsystem == RTE_DEV_EVENT_SUBSYSTEM_UIO) { + if (uevent.type == RTE_DEV_EVENT_REMOVE) { + return(_rte_dev_callback_process( + uevent.devname, + RTE_DEV_EVENT_REMOVE, NULL)); + } else if (uevent.type == RTE_DEV_EVENT_ADD) { + return(_rte_dev_callback_process( + uevent.devname, + RTE_DEV_EVENT_ADD, NULL)); + } + } + } return 0; } -- 2.7.4