From: Ferruh Yigit <ferruh.yigit@intel.com>
To: dev@dpdk.org
Cc: Ferruh Yigit <ferruh.yigit@intel.com>,
Stephen Hemminger <stephen@networkplumber.org>,
Bruce Richardson <bruce.richardson@intel.com>,
Anatoly Burakov <anatoly.burakov@intel.com>
Subject: [dpdk-dev] [PATCH v10 11/20] unci: add netlink exec
Date: Tue, 4 Jul 2017 17:13:28 +0100 [thread overview]
Message-ID: <20170704161337.45926-12-ferruh.yigit@intel.com> (raw)
In-Reply-To: <20170704161337.45926-1-ferruh.yigit@intel.com>
Add netlink exec function, which sends a message to userspace and waits
and receives the response from userspace.
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
.../linuxapp/eal/include/exec-env/unci.h | 6 +
lib/librte_eal/linuxapp/unci/unci_dev.h | 4 +
lib/librte_eal/linuxapp/unci/unci_net.c | 5 +
lib/librte_eal/linuxapp/unci/unci_nl.c | 180 +++++++++++++++++++++
4 files changed, 195 insertions(+)
diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h b/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h
index 6d3490aee..3d88b7ef3 100644
--- a/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h
+++ b/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h
@@ -74,6 +74,12 @@ struct unci_nl_msg {
int err;
};
+enum unci_ethtool_msg_flag {
+ UNCI_MSG_FLAG_NONE,
+ UNCI_MSG_FLAG_REQUEST,
+ UNCI_MSG_FLAG_RESPONSE,
+};
+
/* can go into include/uapi/linux/if_link.h */
enum {
IFLA_UNCI_UNSPEC,
diff --git a/lib/librte_eal/linuxapp/unci/unci_dev.h b/lib/librte_eal/linuxapp/unci/unci_dev.h
index a748abf98..8d9ca6970 100644
--- a/lib/librte_eal/linuxapp/unci/unci_dev.h
+++ b/lib/librte_eal/linuxapp/unci/unci_dev.h
@@ -37,9 +37,13 @@
struct unci_dev {
__u32 port_id;
__u32 pid;
+ struct completion msg_received;
+ u32 nb_timedout_msg;
};
int unci_nl_init(void);
void unci_nl_release(void);
+int unci_nl_exec(u32 cmd, struct net_device *dev, void *in_data,
+ size_t in_len, void *out_data, size_t out_len);
#endif /* _UNCI_DEV_H_ */
diff --git a/lib/librte_eal/linuxapp/unci/unci_net.c b/lib/librte_eal/linuxapp/unci/unci_net.c
index 1989b6d23..27b9f9f70 100644
--- a/lib/librte_eal/linuxapp/unci/unci_net.c
+++ b/lib/librte_eal/linuxapp/unci/unci_net.c
@@ -31,8 +31,13 @@ static const struct net_device_ops unci_net_netdev_ops = { 0 };
static void unci_net_setup(struct net_device *dev)
{
+ struct unci_dev *unci;
+
ether_setup(dev);
dev->netdev_ops = &unci_net_netdev_ops;
+
+ unci = netdev_priv(dev);
+ init_completion(&unci->msg_received);
}
static int unci_net_newlink(struct net *net, struct net_device *dev,
diff --git a/lib/librte_eal/linuxapp/unci/unci_nl.c b/lib/librte_eal/linuxapp/unci/unci_nl.c
index 1461a3309..fd79ec8f9 100644
--- a/lib/librte_eal/linuxapp/unci/unci_nl.c
+++ b/lib/librte_eal/linuxapp/unci/unci_nl.c
@@ -26,6 +26,180 @@
#include "unci_dev.h"
+#define UNCI_GENL_MSG_LEN 1536
+
+#define UNCI_CMD_TIMEOUT 500 /* ms */
+
+static struct response_buffer {
+ int magic; /* for sanity check */
+ void *buffer;
+ size_t length;
+ struct completion *msg_received;
+ int *err;
+ u32 in_use;
+} response_buffer;
+
+static DEFINE_MUTEX(sync_lock);
+
+static int unci_response_buffer_register(int magic, void *buffer, size_t length,
+ struct completion *msg_received, int *err)
+{
+ if (!response_buffer.in_use) {
+ response_buffer.magic = magic;
+ response_buffer.buffer = buffer;
+ response_buffer.length = length;
+ response_buffer.msg_received = msg_received;
+ response_buffer.err = err;
+ response_buffer.in_use = 1;
+ return 0;
+ }
+
+ return 1;
+}
+
+static void unci_response_buffer_unregister(int magic)
+{
+ if (response_buffer.in_use) {
+ if (magic == response_buffer.magic) {
+ response_buffer.magic = -1;
+ response_buffer.buffer = NULL;
+ response_buffer.length = 0;
+ response_buffer.msg_received = NULL;
+ response_buffer.err = NULL;
+ response_buffer.in_use = 0;
+ } else {
+ pr_err("Unregister magic mismatch\n");
+ }
+ }
+}
+
+static void nl_recv_user_request(struct unci_nl_msg *nl_msg)
+{
+ /* Userspace requests not supported yet */
+ pr_debug("Request from userspace received\n");
+}
+
+static void nl_recv_user_response(struct unci_nl_msg *nl_msg)
+{
+ struct completion *msg_received;
+ size_t recv_len;
+ size_t expected_len;
+
+ if (response_buffer.in_use) {
+ if (response_buffer.buffer != NULL) {
+ recv_len = nl_msg->output_buffer_len;
+ expected_len = response_buffer.length;
+
+ memcpy(response_buffer.buffer,
+ nl_msg->output_buffer,
+ response_buffer.length);
+
+ if (nl_msg->err == 0 && recv_len != expected_len)
+ pr_info("Expected and received len not match "
+ "%zu - %zu\n", recv_len, expected_len);
+ }
+
+ *response_buffer.err = nl_msg->err;
+ msg_received = response_buffer.msg_received;
+ unci_response_buffer_unregister(response_buffer.magic);
+ complete(msg_received);
+ }
+}
+
+static struct genl_family unci_genl_family;
+
+static int unci_nl_send(u32 cmd_id, u32 port_id, u32 pid, void *in_data,
+ size_t in_data_len)
+{
+ struct unci_nl_msg nl_msg;
+ struct sk_buff *skb;
+ void *payload;
+ u32 size = 0;
+
+ if (pid == 0)
+ return -1;
+
+ memset(&nl_msg, 0, sizeof(struct unci_nl_msg));
+ nl_msg.cmd_id = cmd_id;
+ nl_msg.port_id = port_id;
+
+ if (in_data) {
+ if (in_data_len == 0 || in_data_len > UNCI_NL_MSG_LEN)
+ return -EINVAL;
+ nl_msg.input_buffer_len = in_data_len;
+ memcpy(nl_msg.input_buffer, in_data, in_data_len);
+ }
+
+ skb = genlmsg_new(UNCI_GENL_MSG_LEN, GFP_ATOMIC);
+ if (!skb)
+ return -ENOMEM;
+
+ size = sizeof(struct unci_nl_msg) + GENL_HDRLEN +
+ unci_genl_family.hdrsize;
+
+ payload = genlmsg_put(skb, 0, 0, &unci_genl_family, 0, UNCI_CMD_MSG);
+ if (payload == NULL) {
+ nlmsg_free(skb);
+ return -EMSGSIZE;
+ }
+
+ nla_put(skb, UNCI_ATTR_MSG, sizeof(struct unci_nl_msg), &nl_msg);
+
+ genlmsg_end(skb, payload);
+
+ genlmsg_unicast(&init_net, skb, pid);
+ pr_debug("Sent cmd:%u port:%u pid:%u\n", cmd_id, port_id, pid);
+
+ return 0;
+}
+
+int unci_nl_exec(u32 cmd, struct net_device *dev, void *in_data,
+ size_t in_data_len, void *out_data, size_t out_data_len)
+{
+ struct unci_dev *unci = netdev_priv(dev);
+ int err = -EINVAL;
+ int ret;
+
+ if (out_data_len > UNCI_NL_MSG_LEN) {
+ pr_err("Message is too big to receive:%zu\n", out_data_len);
+ return err;
+ }
+
+ mutex_lock(&sync_lock);
+ ret = unci_response_buffer_register(cmd, out_data, out_data_len,
+ &unci->msg_received, &err);
+ if (ret) {
+ mutex_unlock(&sync_lock);
+ return -EINVAL;
+ }
+
+ ret = unci_nl_send(cmd, unci->port_id, unci->pid, in_data, in_data_len);
+ if (ret) {
+ unci_response_buffer_unregister(response_buffer.magic);
+ mutex_unlock(&sync_lock);
+ return ret;
+ }
+
+ ret = wait_for_completion_interruptible_timeout(&unci->msg_received,
+ msecs_to_jiffies(UNCI_CMD_TIMEOUT));
+ if (ret == 0 || err < 0) {
+ unci_response_buffer_unregister(response_buffer.magic);
+ mutex_unlock(&sync_lock);
+ if (ret == 0) { /* timeout */
+ unci->nb_timedout_msg++;
+ pr_info("Command timed-out for port:%u cmd:%u (%u)\n",
+ unci->port_id, cmd, unci->nb_timedout_msg);
+ return -EINVAL;
+ }
+ pr_debug("Command return error for port:%d cmd:%d err:%d\n",
+ unci->port_id, cmd, err);
+ return err;
+ }
+ mutex_unlock(&sync_lock);
+
+ return 0;
+}
+
static int unci_genl_process(struct sk_buff *skb, struct genl_info *info)
{
struct nlattr **attrs = info->attrs;
@@ -37,6 +211,12 @@ static int unci_genl_process(struct sk_buff *skb, struct genl_info *info)
nla_memcpy(&nl_msg, attrs[UNCI_ATTR_MSG], sizeof(struct unci_nl_msg));
pr_debug("cmd: %u\n", nl_msg.cmd_id);
+ if (nl_msg.flag & UNCI_MSG_FLAG_REQUEST) {
+ nl_recv_user_request(&nl_msg);
+ return 0;
+ }
+
+ nl_recv_user_response(&nl_msg);
return 0;
}
--
2.13.0
next prev parent reply other threads:[~2017-07-04 16:14 UTC|newest]
Thread overview: 91+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-26 16:52 [dpdk-dev] [RFC] Kernel Control Path (KCP) Ferruh Yigit
2017-05-28 16:55 ` Wiles, Keith
2017-05-29 9:26 ` Bruce Richardson
2017-05-29 17:29 ` Wiles, Keith
2017-06-16 15:54 ` Ferruh Yigit
2017-06-20 12:33 ` Ferruh Yigit
2017-05-30 10:55 ` Thomas Monjalon
2017-06-13 17:21 ` Ferruh Yigit
2017-06-13 18:00 ` Jay Rolette
2017-06-13 18:04 ` Dumitrescu, Cristian
2017-06-13 18:18 ` Wiles, Keith
2017-06-15 12:07 ` Alex Rosenbaum
2017-06-16 15:27 ` Ferruh Yigit
2017-06-16 16:48 ` Stephen Hemminger
2017-06-13 18:17 ` Wiles, Keith
2017-06-21 11:06 ` [dpdk-dev] [PATCH v8 0/4] Userspace Network Control Interface (UNCI) Ferruh Yigit
2017-06-21 11:06 ` [dpdk-dev] [PATCH v8 1/4] ethtool: move from sample folder to lib folder Ferruh Yigit
2017-06-26 11:02 ` Bruce Richardson
2017-06-21 11:06 ` [dpdk-dev] [PATCH v8 2/4] unci: add kernel control path kernel module Ferruh Yigit
2017-06-21 15:23 ` Stephen Hemminger
2017-06-30 17:02 ` Ferruh Yigit
2017-06-21 11:06 ` [dpdk-dev] [PATCH v8 3/4] rte_ctrl_if: add control interface library Ferruh Yigit
2017-06-26 11:09 ` Bruce Richardson
2017-06-26 11:30 ` Bruce Richardson
2017-06-21 11:06 ` [dpdk-dev] [PATCH v8 4/4] ethdev: add control interface support Ferruh Yigit
2017-06-21 15:24 ` Stephen Hemminger
2017-06-30 17:06 ` Ferruh Yigit
2017-06-26 11:39 ` [dpdk-dev] [PATCH v8 0/4] Userspace Network Control Interface (UNCI) Bruce Richardson
2017-06-29 16:13 ` Ferruh Yigit
2017-06-30 16:56 ` Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 00/20] " Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 01/20] ethtool: add library skeleton Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 02/20] ethtool: move from sample folder into lib folder Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 03/20] ethtool: remove PMD specific API call Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 04/20] ethtool: update header doxygen syntax Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 05/20] ethtool: enable library Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 06/20] doc: add ethtool library documentation Ferruh Yigit
2017-07-02 20:18 ` Mcnamara, John
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 07/20] doc: update ethtool sample app doc Ferruh Yigit
2017-07-02 20:17 ` Mcnamara, John
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 08/20] unci: add module skeleton Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 09/20] unci: add rtnl newlink Ferruh Yigit
2017-06-30 17:27 ` Stephen Hemminger
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 10/20] unci: init netlink Ferruh Yigit
2017-06-30 17:28 ` Stephen Hemminger
2017-06-30 17:29 ` Stephen Hemminger
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 11/20] unci: add netlink exec Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 12/20] unci: add netdevice ops Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 13/20] unci: add ethtool support Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 14/20] ctrl_if: add library skeleton Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 15/20] ctrl_if: add create destroy interface APIs Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 16/20] ctrl_if: initialize netlink interface Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 17/20] ctrl_if: process control messages Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 18/20] ctrl_if: process ethtool messages Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 19/20] doc: add control interface library documentation Ferruh Yigit
2017-07-02 20:16 ` Mcnamara, John
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 20/20] ethdev: add control interface support Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 00/20] Userspace Network Control Interface (UNCI) Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 01/20] ethtool: add library skeleton Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 02/20] ethtool: move from sample folder into lib folder Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 03/20] ethtool: remove PMD specific API call Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 04/20] ethtool: update header doxygen syntax Ferruh Yigit
2017-07-06 9:18 ` Burakov, Anatoly
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 05/20] ethtool: enable library Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 06/20] doc: add ethtool library documentation Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 07/20] doc: update ethtool sample app doc Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 08/20] unci: add module skeleton Ferruh Yigit
2017-07-06 9:25 ` Burakov, Anatoly
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 09/20] unci: add rtnl newlink Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 10/20] unci: init netlink Ferruh Yigit
2017-07-06 9:32 ` Burakov, Anatoly
2017-07-04 16:13 ` Ferruh Yigit [this message]
2017-07-05 19:07 ` [dpdk-dev] [PATCH v10 11/20] unci: add netlink exec Stephen Hemminger
2017-07-06 10:45 ` Ferruh Yigit
2017-07-07 0:25 ` Stephen Hemminger
2017-07-05 19:15 ` Stephen Hemminger
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 12/20] unci: add netdevice ops Ferruh Yigit
2017-07-05 19:12 ` Stephen Hemminger
2017-07-05 19:12 ` Stephen Hemminger
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 13/20] unci: add ethtool support Ferruh Yigit
2017-07-05 19:07 ` Stephen Hemminger
2017-07-05 19:08 ` Stephen Hemminger
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 14/20] ctrl_if: add library skeleton Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 15/20] ctrl_if: add create destroy interface APIs Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 16/20] ctrl_if: initialize generic netlink interface Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 17/20] ctrl_if: process control messages Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 18/20] ctrl_if: process ethtool messages Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 19/20] doc: add control interface library documentation Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 20/20] ethdev: add control interface support Ferruh Yigit
2017-07-08 6:28 ` Yuanhan Liu
2017-07-20 14:55 ` Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170704161337.45926-12-ferruh.yigit@intel.com \
--to=ferruh.yigit@intel.com \
--cc=anatoly.burakov@intel.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).