export device physical port id to userspace
Subsystems (2)
v2 cover export device physical port id to userspace
This patchset is based on patch by [email protected]
Once device which can change phys port id during its lifetime adopts this, NETDEV_CHANGEPHYSPORTID event will be added and driver will call call_netdevice_notifiers(NETDEV_NETDEV_CHANGEPHYSPORTID, dev) to propagate the change to userspace.
v1->v2: as suggested by Ben, handle -EOPNOTSUPP in rtnl code (wrapped up ndo call)
Jiri Pirko (3):
net: add ndo to get id of physical port of the device
rtnl: export physical port id via RT netlink
net: export physical port id via sysfs
include/linux/netdevice.h | 20 ++++++++++++++++++++ include/uapi/linux/if_link.h | 1 + net/core/dev.c | 18 ++++++++++++++++++ net/core/net-sysfs.c | 42 ++++++++++++++++++++++++++++++++++++++++++ net/core/rtnetlink.c | 25 ++++++++++++++++++++++++- 5 files changed, 105 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.1.4
PATCH v2 1/3 net: add ndo to get id of physical port of the device
This patch adds a ndo for getting physical port of the device. Driver which is aware of being virtual function of some physical port should implement this ndo.
--- include/linux/netdevice.h | 20 ++++++++++++++++++++ net/core/dev.c | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+)
include/linux/netdevice.h +20 -0
@@ -728,6 +728,16 @@ struct netdev_fcoe_hbainfo { };#endif +#define MAX_PHYS_PORT_ID_LEN 32 + +/* This structure holds a unique identifier to identify the +* physical port used by a netdevice. +*/ +struct netdev_phys_port_id { +unsigned char id[MAX_PHYS_PORT_ID_LEN ]; +unsigned char id_len; +}; +/* * This structure defines the management hooks for network devices. * The following hooks can be defined; unless noted otherwise, they are
@@ -932,6 +942,12 @@ struct netdev_fcoe_hbainfo {* that determine carrier state from physical hardware properties (eg * network cables) or protocol-dependent mechanisms (eg * USB_CDC_NOTIFY_NETWORK_CONNECTION) should NOT implement this function. +* +* int (*ndo_get_phys_port_id)(struct net_device *dev, +* struct netdev_phys_port_id *ppid); +* Called to get ID of physical port of this device. If driver does +* not implement this, it is assumed that the hw is not able to have +* multiple net devices on single physical port. */ struct net_device_ops {int (*ndo_init)(struct net_device *dev);
@@ -1060,6 +1076,8 @@ struct net_device_ops { struct nlmsghdr *nlh);int (*ndo_change_carrier)(struct net_device *dev,bool new_carrier); +int (*ndo_get_phys_port_id)(struct net_device *dev, +struct netdev_phys_port_id *ppid); };/*
@@ -2317,6 +2335,8 @@ extern int dev_set_mac_address(struct net_device *, struct sockaddr *);extern int dev_change_carrier (struct net_device *,bool new_carrier); +extern int dev_get_phys_port_id (struct net_device *dev, +struct netdev_phys_port_id *ppid);extern int dev_hard_start_xmit (struct sk_buff *skb,struct net_device *dev,struct netdev_queue *txq);
net/core/dev.c +18 -0
@@ -4989,6 +4989,24 @@ int dev_change_carrier(struct net_device *dev, bool new_carrier)EXPORT_SYMBOL (dev_change_carrier);/** +* dev_get_phys_port_id - Get device physical port ID +* @dev: device +* @ppid: port ID +* +* Get device physical port ID +*/ +int dev_get_phys_port_id (struct net_device *dev, +struct netdev_phys_port_id *ppid) +{ +const struct net_device_ops *ops = dev->netdev_ops; + +if (!ops->ndo_get_phys_port_id) +return -EOPNOTSUPP ; +return ops->ndo_get_phys_port_id (dev, ppid); +} +EXPORT_SYMBOL (dev_get_phys_port_id); + +/** * dev_new_index - allocate an ifindex * @net: the applicable net namespace *
Signature · 1 line
1.8.1.4
Re: [patch net-next v2 1/3] net: add ndo to get id of physical port of the device
Quoted 18 lines · Jiri Pirko
This patch adds a ndo for getting physical port of the device. Driver which is aware of being virtual function of some physical port should implement this ndo.
Signed-off-by Jiri Pirko <[email protected]>--- include/linux/netdevice.h | 20 ++++++++++++++++++++ net/core/dev.c | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+)include/linux/netdevice.h +0
-0@@ -728,6 +728,16 @@ struct netdev_fcoe_hbainfo { };#endif
include/linux/netdevice.h struct netdev_fcoe_hbainfo { · line 739
Quoted 10 lines
include/linux/netdevice.h +9
-0+#define MAX_PHYS_PORT_ID_LEN 32 + +/* This structure holds a unique identifier to identify the +* physical port used by a netdevice. +*/ +struct netdev_phys_port_id { +unsigned char id[MAX_PHYS_PORT_ID_LEN ]; +unsigned char id_len; +};
So an integer (four bytes?) is OK here? does it need to be in certain byte order?
Re: [patch net-next v2 1/3] net: add ndo to get id of physical port of the device
Quoted 20 lines · Or Gerlitz
Quoted 19 lines · Jiri Pirko
This patch adds a ndo for getting physical port of the device. Driver which is aware of being virtual function of some physical port should implement this ndo.
Signed-off-by Jiri Pirko <[email protected]>--- include/linux/netdevice.h | 20 ++++++++++++++++++++ net/core/dev.c | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+)include/linux/netdevice.h +0
-0@@ -728,6 +728,16 @@ struct netdev_fcoe_hbainfo { };#endif
Quoted 13 lines
include/linux/netdevice.h struct netdev_fcoe_hbainfo { · line 739
Quoted 9 lines
include/linux/netdevice.h +9
-0+#define MAX_PHYS_PORT_ID_LEN 32 + +/* This structure holds a unique identifier to identify the +* physical port used by a netdevice. +*/ +struct netdev_phys_port_id { +unsigned char id[MAX_PHYS_PORT_ID_LEN ]; +unsigned char id_len; +};So an integer (four bytes?) is OK here? does it need to be in certain byte order?
It's an arbitrary value but is supposed to be universally unique. So you could use, for example, the first non-volatile MAC address assigned to the port (if there is one).
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [patch net-next v2 1/3] net: add ndo to get id of physical port of the device
In reply to Jiri PirkoQuoted 5 lines · Jiri Pirko
This patch adds a ndo for getting physical port of the device. Driver which is aware of being virtual function of some physical port should implement this ndo.
Signed-off-by Jiri Pirko <[email protected]>
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [patch net-next v2 1/3] net: add ndo to get id of physical port of the device
In reply to Jiri PirkoQuoted 4 lines · Jiri Pirko
This patch adds a ndo for getting physical port of the device. Driver which is aware of being virtual function of some physical port should implement this ndo.
Do you mean virtual function literally? that is in the PCI IOV aspect?
Quoted 29 lines
Signed-off-by Jiri Pirko <[email protected]>--- include/linux/netdevice.h | 20 ++++++++++++++++++++ net/core/dev.c | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+)include/linux/netdevice.h +10
-0@@ -728,6 +728,16 @@ struct netdev_fcoe_hbainfo { };#endif +#define MAX_PHYS_PORT_ID_LEN 32 + +/* This structure holds a unique identifier to identify the +* physical port used by a netdevice. +*/ +struct netdev_phys_port_id { +unsigned char id[MAX_PHYS_PORT_ID_LEN ]; +unsigned char id_len; +}; +/* * This structure defines the management hooks for network devices. * The following hooks can be defined; unless noted otherwise, they are
include/linux/netdevice.h struct netdev_fcoe_hbainfo { · line 951
Quoted 10 lines
include/linux/netdevice.h +6
-0@@ -932,6 +942,12 @@ struct netdev_fcoe_hbainfo {* that determine carrier state from physical hardware properties (eg * network cables) or protocol-dependent mechanisms (eg * USB_CDC_NOTIFY_NETWORK_CONNECTION) should NOT implement this function. +* +* int (*ndo_get_phys_port_id)(struct net_device *dev, +* struct netdev_phys_port_id *ppid); +* Called to get ID of physical port of this device. If driver does +* not implement this, it is assumed that the hw is not able to have +* multiple net devices on single physical port. */
I am not sure to understand what is assumed here and why it it mandated.
Re: [patch net-next v2 1/3] net: add ndo to get id of physical port of the device
Quoted 8 lines · Sun, Jul 21, 2013 at 10:26:32PM CEST, [email protected] wrote:
Quoted 4 lines · Jiri Pirko
This patch adds a ndo for getting physical port of the device. Driver which is aware of being virtual function of some physical port should implement this ndo.
Do you mean virtual function literally? that is in the PCI IOV aspect?
This is applicable not only for IOV, nbut for other solutions (NPAR, multichannel) as well. Basically if there is possible to have multiple netdevs on the single hw port.
Quoted 35 lines
Quoted 35 lines
Signed-off-by Jiri Pirko <[email protected]>--- include/linux/netdevice.h | 20 ++++++++++++++++++++ net/core/dev.c | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+)include/linux/netdevice.h +11
-0@@ -728,6 +728,16 @@ struct netdev_fcoe_hbainfo { };#endif +#define MAX_PHYS_PORT_ID_LEN 32 + +/* This structure holds a unique identifier to identify the +* physical port used by a netdevice. +*/ +struct netdev_phys_port_id { +unsigned char id[MAX_PHYS_PORT_ID_LEN ]; +unsigned char id_len; +}; +/* * This structure defines the management hooks for network devices. * The following hooks can be defined; unless noted otherwise, they are @@ -932,6 +942,12 @@ struct netdev_fcoe_hbainfo {* that determine carrier state from physical hardware properties (eg * network cables) or protocol-dependent mechanisms (eg * USB_CDC_NOTIFY_NETWORK_CONNECTION) should NOT implement this function. +*
Quoted 8 lines
include/linux/netdevice.h struct netdev_fcoe_hbainfo { · line 951
Quoted 6 lines
include/linux/netdevice.h +5
-0+* int (*ndo_get_phys_port_id)(struct net_device *dev, +* struct netdev_phys_port_id *ppid); +* Called to get ID of physical port of this device. If driver does +* not implement this, it is assumed that the hw is not able to have +* multiple net devices on single physical port. */ I am not sure to understand what is assumed here and why it it mandated.
It is not mandated. The key is to provide clear info to user that couple of netdevs share the same port. The goal is to have this implemented for all drivers which are able to have more netdevs on single hw port.
Jiri
Re: [patch net-next v2 1/3] net: add ndo to get id of physical port of the device
Quoted 9 lines · Jiri Pirko
Quoted 7 lines · Sun, Jul 21, 2013 at 10:26:32PM CEST, [email protected] wrote:
Quoted 4 lines · Jiri Pirko
This patch adds a ndo for getting physical port of the device. Driver which is aware of being virtual function of some physical port should implement this ndo.
Quoted 5 lines
Quoted 1 line
Do you mean virtual function literally? that is in the PCI IOV aspect?
This is applicable not only for IOV, nbut for other solutions (NPAR, multichannel) as well. Basically if there is possible to have multiple netdevs on the single hw port.
I think it would be useful to include this information in the commit message.
Signature · 4 lines
With regards, Narendra K Linux Engineering Dell Inc.
Re: [patch net-next v2 1/3] net: add ndo to get id of physical port of the device
Quoted 10 lines · Mon, Jul 22, 2013 at 01:29:50PM CEST, [email protected] wrote:
Quoted 9 lines · Jiri Pirko
Quoted 7 lines · Sun, Jul 21, 2013 at 10:26:32PM CEST, [email protected] wrote:
Quoted 4 lines · Jiri Pirko
This patch adds a ndo for getting physical port of the device. Driver which is aware of being virtual function of some physical port should implement this ndo.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Do you mean virtual function literally? that is in the PCI IOV aspect?
This is applicable not only for IOV, nbut for other solutions (NPAR, multichannel) as well. Basically if there is possible to have multiple netdevs on the single hw port.
I think it would be useful to include this information in the commit message.
ok. I will resend the patchset soon.
Quoted 6 lines
Signature · 5 lines
-- With regards, Narendra K Linux Engineering Dell Inc.
Re: [patch net-next v2 1/3] net: add ndo to get id of physical port of the device
In reply to Jiri PirkoQuoted 58 lines · Jiri Pirko
Quoted 8 lines · Sun, Jul 21, 2013 at 10:26:32PM CEST, [email protected] wrote:
Quoted 4 lines · Jiri Pirko
This patch adds a ndo for getting physical port of the device. Driver which is aware of being virtual function of some physical port should implement this ndo.
Do you mean virtual function literally? that is in the PCI IOV aspect?
This is applicable not only for IOV, nbut for other solutions (NPAR, multichannel) as well. Basically if there is possible to have multiple netdevs on the single hw port.
Quoted 35 lines
Quoted 35 lines
Signed-off-by Jiri Pirko <[email protected]>--- include/linux/netdevice.h | 20 ++++++++++++++++++++ net/core/dev.c | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+)include/linux/netdevice.h +11
-0@@ -728,6 +728,16 @@ struct netdev_fcoe_hbainfo { };#endif +#define MAX_PHYS_PORT_ID_LEN 32 + +/* This structure holds a unique identifier to identify the +* physical port used by a netdevice. +*/ +struct netdev_phys_port_id { +unsigned char id[MAX_PHYS_PORT_ID_LEN ]; +unsigned char id_len; +}; +/* * This structure defines the management hooks for network devices. * The following hooks can be defined; unless noted otherwise, they are @@ -932,6 +942,12 @@ struct netdev_fcoe_hbainfo {* that determine carrier state from physical hardware properties (eg * network cables) or protocol-dependent mechanisms (eg * USB_CDC_NOTIFY_NETWORK_CONNECTION) should NOT implement this function. +* Quoted 8 lines
include/linux/netdevice.h struct netdev_fcoe_hbainfo { · line 951
Quoted 6 lines
include/linux/netdevice.h +5
-0+* int (*ndo_get_phys_port_id)(struct net_device *dev, +* struct netdev_phys_port_id *ppid); +* Called to get ID of physical port of this device. If driver does +* not implement this, it is assumed that the hw is not able to have +* multiple net devices on single physical port. */ I am not sure to understand what is assumed here and why it it mandated.
Quoted 3 lines
It is not mandated. The key is to provide clear info to user that couple of netdevs share the same port. The goal is to have this implemented for all drivers which are able to have more netdevs on single hw port.
But why say that if a certain driver did not implement this NDO, their HW can't have multiple netdevs on the same port? e.g think on a driver that supports SRIOV such that multiple VFs can be assigned to the same guest but their VF driver doesn't support this NDO, what's the problem with that? why the documentation does this <-- link
Or.
PATCH v2 2/3 rtnl: export physical port id via RT netlink
In reply to Jiri Pirko--- include/uapi/linux/if_link.h | 1 + net/core/rtnetlink.c | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-)
include/uapi/linux/if_link.h +1 -0
@@ -143,6 +143,7 @@ enum {IFLA_NUM_TX_QUEUES ,IFLA_NUM_RX_QUEUES ,IFLA_CARRIER , +IFLA_PHYS_PORT_ID , __IFLA_MAX };
net/core/rtnetlink.c +24 -1
@@ -767,7 +767,8 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, +rtnl_vfinfo_size (dev, ext_filter_mask)/* IFLA_VFINFO_LIST */ +rtnl_port_size (dev)/* IFLA_VF_PORTS + IFLA_PORT_SELF */ +rtnl_link_get_size (dev)/* IFLA_LINKINFO */ - +rtnl_link_get_af_size (dev);/* IFLA_AF_SPEC */ + +rtnl_link_get_af_size (dev)/* IFLA_AF_SPEC */ + +nla_total_size (MAX_PHYS_PORT_ID_LEN );/* IFLA_PHYS_PORT_ID */ }static int rtnl_vf_ports_fill (struct sk_buff *skb,struct net_device *dev)
@@ -846,6 +847,24 @@ static int rtnl_port_fill(struct sk_buff *skb, struct net_device *dev)return 0 ; } +static int rtnl_phys_port_id_fill (struct sk_buff *skb,struct net_device *dev) +{ +int err; +struct netdev_phys_port_id ppid; + + err =dev_get_phys_port_id (dev, &ppid); +if (err) { +if (err == -EOPNOTSUPP ) +return 0 ; +return err; + } + +if (nla_put (skb,IFLA_PHYS_PORT_ID , ppid.id_len, ppid.id)) +return -EMSGSIZE ; + +return 0 ; +} +static int rtnl_fill_ifinfo (struct sk_buff *skb,struct net_device *dev,int type,u32 pid,u32 seq,u32 change,unsigned int flags,u32 ext_filter_mask)
@@ -913,6 +932,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, goto nla_put_failure; } +if (rtnl_phys_port_id_fill (skb, dev)) + goto nla_put_failure; + attr =nla_reserve (skb,IFLA_STATS ,sizeof (struct rtnl_link_stats ));if (attr ==NULL )
@@ -1113,6 +1135,7 @@ const struct nla_policy ifla_policy[IFLA_MAX+1] = { [IFLA_PROMISCUITY] = { .type = NLA_U32 }, [IFLA_NUM_TX_QUEUES] = { .type = NLA_U32 }, [IFLA_NUM_RX_QUEUES] = { .type = NLA_U32 }, + [IFLA_PHYS_PORT_ID ] = { .type =NLA_BINARY , .len =MAX_PHYS_PORT_ID_LEN }, };EXPORT_SYMBOL (ifla_policy );
Signature · 1 line
1.8.1.4
Re: [patch net-next v2 2/3] rtnl: export physical port id via RT netlink
Quoted 1 line · Jiri Pirko
Signed-off-by Jiri Pirko <[email protected]>
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [patch net-next v2 2/3] rtnl: export physical port id via RT netlink
In reply to Jiri PirkoQuoted 3 lines · Jiri Pirko
Signed-off-by Jiri Pirko <[email protected]>---
Signature · 4 lines
With regards, Narendra K Linux Engineering Dell Inc.
PATCH v2 3/3 net: export physical port id via sysfs
In reply to Jiri Pirko--- net/core/net-sysfs.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
net/core/net-sysfs.c +42 -0
@@ -334,6 +334,47 @@ static ssize_t store_group(struct device *dev, struct device_attribute *attr,return netdev_store (dev, attr, buf, len, change_group); } +static size_t _format_port_id (char *buf,int buflen, +const unsigned char *id,int len) +{ +int i; +char *cp = buf; + +for (i =0 ; i < len; i++) + cp +=scnprintf (cp, buflen - (cp - buf),"%02x" , id[i]); +return cp - buf; +} + +ssize_t sysfs_format_port_id (char *buf,const unsigned char *id,int len) +{ +size_t l; + + l =_format_port_id (buf,PAGE_SIZE , id, len); + l +=scnprintf (buf + l,PAGE_SIZE - l,"\n" ); +return (ssize_t )l; +} + +static ssize_t show_phys_port_id (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct net_device *netdev =to_net_dev (dev); +ssize_t ret = -EINVAL ; + +if (!rtnl_trylock ()) +return restart_syscall (); + +if (dev_isalive (netdev)) { +struct netdev_phys_port_id ppid; + + ret =dev_get_phys_port_id (netdev, &ppid); +if (!ret) + ret =sysfs_format_port_id (buf, ppid.id, ppid.id_len); + } +rtnl_unlock (); + +return ret; +} +static struct device_attribute net_class_attributes[] = {__ATTR (addr_assign_type,S_IRUGO , show_addr_assign_type,NULL ),__ATTR (addr_len,S_IRUGO , show_addr_len,NULL ),
@@ -355,6 +396,7 @@ static struct device_attribute net_class_attributes[] = {__ATTR (tx_queue_len,S_IRUGO |S_IWUSR , show_tx_queue_len, store_tx_queue_len),__ATTR (netdev_group,S_IRUGO |S_IWUSR , show_group, store_group), + __ATTR(phys_port_id, S_IRUGO, show_phys_port_id, NULL), {} };
Signature · 1 line
1.8.1.4
Re: [patch net-next v2 3/3] net: export physical port id via sysfs
Quoted 1 line · Jiri Pirko
Signed-off-by Jiri Pirko <[email protected]>
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [patch net-next v2 3/3] net: export physical port id via sysfs
In reply to Jiri PirkoQuoted 3 lines · Jiri Pirko
Signed-off-by Jiri Pirko <[email protected]>---
Signature · 4 lines
With regards, Narendra K Linux Engineering Dell Inc.
Quoted 1 line · Jiri Pirko
This patchset is based on patch by [email protected]
Hi Jiri,
Just a small note to make we're not running (at least not foo fast...) here... the patch you mentioned
is still not finalized I think. At least, as I mentioned there, lets see it allows to modify
the current drivers that make use of the dev_id field to denote port number to the new scheme, before we build the 2nd floor of the building.
Or.
Quoted 7 lines · Sun, Jul 21, 2013 at 07:59:54AM CEST, [email protected] wrote:
Quoted 1 line · Jiri Pirko
This patchset is based on patch by [email protected]
Hi Jiri,
Just a small note to make we're not running (at least not foo fast...) here... the patch you mentioned
This patchset replaces the mentioned patch. So there's no dependency.
Quoted 4 lines
is still not finalized I think. At least, as I mentioned there, lets see it allows to modify
the current drivers that make use of thedev_idfield to denote port number to the new scheme, before we build the 2nd floor of the building.
Just implement ndo_get_phys_port_id for those drivers, that's all needed (of course after this patchset is applied)
Quoted 2 lines
Or.