From: Parav Pandit <parav@nvidia.com>
To: <netdev@vger.kernel.org>, <davem@davemloft.net>, <kuba@kernel.org>
Cc: Parav Pandit <parav@nvidia.com>
Subject: [PATCH net-next 3/7] netdevsim: Simulate get hardware address of a PCI port
Date: Sat, 6 Feb 2021 14:55:47 +0200 [thread overview]
Message-ID: <20210206125551.8616-4-parav@nvidia.com> (raw)
In-Reply-To: <20210206125551.8616-1-parav@nvidia.com>
Allow users to get hardware address for the PCI port.
Below example creates one devlink port, queries a port and its hardware
address.
Example of a PCI SF port which supports a port function hw_addr set:
Create a device with ID=10 and one physical port.
$ echo "10 1" > /sys/bus/netdevsim/new_device
Add PCI PF port:
$ devlink port add netdevsim/netdevsim10 flavour pcipf pfnum 2
netdevsim/netdevsim10/1: type eth netdev eth1 flavour pcipf controller 0 pfnum 2 external false splittable false
function:
hw_addr 00:00:00:00:00:00
$ devlink port add netdevsim/netdevsim10 flavour pcisf pfnum 2
netdevsim/netdevsim10/2: type eth netdev eth2 flavour pcisf controller 0 pfnum 2 sfnum 0 splittable false
function:
hw_addr 00:00:00:00:00:00
Show devlink ports:
$ devlink port show
netdevsim/netdevsim10/0: type eth netdev eth0 flavour physical port 1 splittable false
netdevsim/netdevsim10/1: type eth netdev eth1 flavour pcipf controller 0 pfnum 2 external false splittable false
function:
hw_addr 00:00:00:00:00:00
netdevsim/netdevsim10/2: type eth netdev eth2 flavour pcisf controller 0 pfnum 2 sfnum 0 splittable false
function:
hw_addr 00:00:00:00:00:00
Show the port and function attributes in JSON format:
$ devlink port show netdevsim/netdevsim10/2 -jp
{
"port": {
"netdevsim/netdevsim10/2": {
"type": "eth",
"netdev": "eth2",
"flavour": "pcisf",
"controller": 0,
"pfnum": 2,
"sfnum": 0,
"splittable": false,
"function": {
"hw_addr": "00:00:00:00:00:00"
}
}
}
}
Signed-off-by: Parav Pandit <parav@nvidia.com>
---
drivers/net/netdevsim/dev.c | 1 +
drivers/net/netdevsim/netdevsim.h | 4 ++++
drivers/net/netdevsim/port_function.c | 30 +++++++++++++++++++++++++++
3 files changed, 35 insertions(+)
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index 806e387918fe..6046906d6b85 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -907,6 +907,7 @@ static const struct devlink_ops nsim_dev_devlink_ops = {
.trap_policer_counter_get = nsim_dev_devlink_trap_policer_counter_get,
.port_new = nsim_dev_devlink_port_new,
.port_del = nsim_dev_devlink_port_del,
+ .port_function_hw_addr_get = nsim_dev_port_fn_hw_addr_get,
};
#define NSIM_DEV_MAX_MACS_DEFAULT 32
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index efa7c08d842a..e910c3cf480d 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -320,3 +320,7 @@ int nsim_dev_devlink_port_new(struct devlink *devlink,
unsigned int *new_port_index);
int nsim_dev_devlink_port_del(struct devlink *devlink, unsigned int port_index,
struct netlink_ext_ack *extack);
+int nsim_dev_port_fn_hw_addr_get(struct devlink *devlink,
+ struct devlink_port *port,
+ u8 *hw_addr, int *hw_addr_len,
+ struct netlink_ext_ack *extack);
diff --git a/drivers/net/netdevsim/port_function.c b/drivers/net/netdevsim/port_function.c
index a2f62a609e9b..4031598e2076 100644
--- a/drivers/net/netdevsim/port_function.c
+++ b/drivers/net/netdevsim/port_function.c
@@ -16,6 +16,7 @@ struct nsim_port_fn {
int refcount; /* Counts how many sf ports are bound attached to this pf port. */
u32 sfnum;
u16 pfnum;
+ u8 hw_addr[ETH_ALEN];
};
static struct devlink_port *
@@ -431,3 +432,32 @@ void nsim_dev_port_fn_disable(struct nsim_dev *nsim_dev)
nsim_devlink_port_fn_free(nsim_dev, port);
}
}
+
+static struct nsim_port_fn *
+nsim_dev_to_port_fn(struct nsim_dev *nsim_dev, struct devlink_port *dl_port,
+ struct netlink_ext_ack *extack)
+{
+ if (nsim_dev_port_index_internal(nsim_dev, dl_port->index)) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Port index doesn't belong to user created port");
+ return ERR_PTR(-EOPNOTSUPP);
+ }
+ return container_of(dl_port, struct nsim_port_fn, dl_port);
+}
+
+int nsim_dev_port_fn_hw_addr_get(struct devlink *devlink,
+ struct devlink_port *dl_port,
+ u8 *hw_addr, int *hw_addr_len,
+ struct netlink_ext_ack *extack)
+{
+ struct nsim_dev *nsim_dev = devlink_priv(devlink);
+ struct nsim_port_fn *port;
+
+ port = nsim_dev_to_port_fn(nsim_dev, dl_port, extack);
+ if (IS_ERR(port))
+ return PTR_ERR(port);
+
+ memcpy(hw_addr, port->hw_addr, ETH_ALEN);
+ *hw_addr_len = ETH_ALEN;
+ return 0;
+}
--
2.26.2
next prev parent reply other threads:[~2021-02-06 12:57 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-06 12:55 [PATCH net-next 0/7] netdevsim port add, delete support Parav Pandit
2021-02-06 12:55 ` [PATCH net-next 1/7] netdevsim: Add support for add and delete of a PCI PF port Parav Pandit
2021-02-06 14:34 ` kernel test robot
2021-02-07 7:59 ` Parav Pandit
2021-02-07 8:04 ` [kbuild-all] " Rong Chen
2021-02-06 16:24 ` kernel test robot
2021-02-06 18:28 ` kernel test robot
2021-02-06 12:55 ` [PATCH net-next 2/7] netdevsim: Add support for add and delete PCI SF port Parav Pandit
2021-02-06 17:42 ` kernel test robot
2021-02-06 12:55 ` Parav Pandit [this message]
2021-02-06 12:55 ` [PATCH net-next 4/7] netdevsim: Simulate set hardware address of a PCI port Parav Pandit
2021-02-06 12:55 ` [PATCH net-next 5/7] netdevsim: Simulate port function state for " Parav Pandit
2021-02-06 18:30 ` kernel test robot
2021-02-06 12:55 ` [PATCH net-next 6/7] netdevsim: Simulate port function set " Parav Pandit
2021-02-06 12:55 ` [PATCH net-next 7/7] netdevsim: Add netdevsim port add test cases Parav Pandit
2021-02-07 8:44 ` [PATCH net-next v2 0/7] netdevsim port add, delete support Parav Pandit
2021-02-07 8:44 ` [PATCH net-next v2 1/7] netdevsim: Add support for add and delete of a PCI PF port Parav Pandit
2021-02-07 12:00 ` kernel test robot
2021-02-07 8:44 ` [PATCH net-next v2 2/7] netdevsim: Add support for add and delete PCI SF port Parav Pandit
2021-02-07 12:28 ` kernel test robot
2021-02-07 8:44 ` [PATCH net-next v2 3/7] netdevsim: Simulate get hardware address of a PCI port Parav Pandit
2021-02-07 8:44 ` [PATCH net-next v2 4/7] netdevsim: Simulate set " Parav Pandit
2021-02-07 8:44 ` [PATCH net-next v2 5/7] netdevsim: Simulate port function state for " Parav Pandit
2021-02-07 13:09 ` kernel test robot
2021-02-07 8:44 ` [PATCH net-next v2 6/7] netdevsim: Simulate port function set " Parav Pandit
2021-02-07 8:44 ` [PATCH net-next v2 7/7] netdevsim: Add netdevsim port add test cases Parav Pandit
2021-02-08 21:21 ` Jakub Kicinski
2021-02-09 3:59 ` Parav Pandit
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=20210206125551.8616-4-parav@nvidia.com \
--to=parav@nvidia.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.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).