introduce line card support for modular switch
Subsystems (5)
Jiri Pirko
maintainerv2 cover introduce line card support for modular switch
From: Jiri Pirko <[email protected]>
This patchset introduces support for modular switch systems. NVIDIA Mellanox SN4800 is an example of such. It contains 8 slots to accomodate line cards - basically replaceable PHY modules. Available line cards include:
16X 100GbE (QSFP28)
8X 200GbE (QSFP56)
4X 400GbE (QSFP-DD)
Similar to split cabels, it is essencial for the correctness of configuration and funcionality to treat the line card entities in the same way, no matter the line card is inserted or not. Meaning, the netdevice of a line card port cannot just disappear when line card is removed. Also, system admin needs to be able to apply configuration on netdevices belonging to line card port even before the linecard gets inserted. The nature of a line card is not "a pluggable device", but "a pluggable PHY module".
To resolve this, a concept of "provisioning" is introduced. The user may "provision" certain slot with a line card type. Driver then creates all instances (devlink ports, netdevices, etc) related to this line card type. The carrier of netdevices stays down. Once the line card is inserted and activated, the carrier of the related netdevices goes up.
Once user does not want to use the line card related instances anymore, he can "unprovision" the slot. Driver then removes the instances.
Patches 1-5 are extending devlink driver API and UAPI in order to register, show, dump, provision and activate the line card. Patches 6-9 are implementing the introduced API in netdevsim
Example:
# Create a new netdevsim device, with no ports and 2 line cards:
$ echo "10 0 2" >/sys/bus/netdevsim/new_device
$ devlink port # No ports are listed
$ devlink lc
netdevsim/netdevsim10:
lc 0 state unprovisioned
supported_types:
card1port card2ports card4ports
lc 1 state unprovisioned
supported_types:
card1port card2ports card4ports# Note that driver advertizes supported line card types. In case of # netdevsim, these are 3.
$ devlink lc set netdevsim/netdevsim10 lc 0 type card4ports
$ devlink lc
netdevsim/netdevsim10:
lc 0 state provisioned type card4ports
supported_types:
card1port card2ports card4ports
lc 1 state unprovisioned
supported_types:
card1port card2ports card4ports
$ devlink port
netdevsim/netdevsim10/1000: type eth netdev eni10nl0p1 flavour physical lc 0 port 1 splittable false
netdevsim/netdevsim10/1001: type eth netdev eni10nl0p2 flavour physical lc 0 port 2 splittable false
netdevsim/netdevsim10/1002: type eth netdev eni10nl0p3 flavour physical lc 0 port 3 splittable false
netdevsim/netdevsim10/1003: type eth netdev eni10nl0p4 flavour physical lc 0 port 4 splittable false
# ^^ ^^^^
# netdev name adjusted index of a line card this port belongs to$ ip link set eni10nl0p1 up
$ ip link show eni10nl0p1
165: eni10nl0p1: <NO-CARRIER,BROADCAST,NOARP,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
link/ether 7e:2d:05:93:d3:d1 brd ff:ff:ff:ff:ff:ff# Now insert the line card using debugfs. That emulates plug-in even
# on real hardware:
$ echo "card4ports"> /sys/kernel/debug/netdevsim/netdevsim10/linecards/0/inserted_type
$ ip link show eni10nl0p1
165: eni10nl0p1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
link/ether 7e:2d:05:93:d3:d1 brd ff:ff:ff:ff:ff:ff
# The carrier is UP now.Jiri Pirko (10):
devlink: add support to create line card and expose to user
devlink: implement line card provisioning
devlink: implement line card active state
devlink: append split port number to the port name
devlink: add port to line card relationship set
netdevsim: introduce line card support
netdevsim: allow port objects to be linked with line cards
netdevsim: create devlink line card object and implement provisioning
netdevsim: implement line card activation
selftests: add netdevsim devlink lc test
drivers/net/netdevsim/bus.c | 21 +- drivers/net/netdevsim/dev.c | 425 +++++++++++++++- drivers/net/netdevsim/netdev.c | 2 + drivers/net/netdevsim/netdevsim.h | 26 + include/net/devlink.h | 44 ++ include/uapi/linux/devlink.h | 23 + net/core/devlink.c | 463 +++++++++++++++++- .../drivers/net/netdevsim/devlink.sh | 62 ++- 8 files changed, 1040 insertions(+), 26 deletions(-)
Signature · 1 line
2.26.2
Jiri Pirko
maintainerRFC PATCH v2 1/10 devlink: add support to create line card and expose to user
From: Jiri Pirko <[email protected]>
Extend the devlink API so the driver is going to be able to create and destroy linecard instances. There can be multiple line cards per devlink device. Expose this new type of object over devlink netlink API to the userspace, with notifications.
---RFC->RFCv2:
- s/register/create in function comment
- s/create/destroy/ for destroy exported symbol
--- include/net/devlink.h | 10 ++ include/uapi/linux/devlink.h | 7 ++ net/core/devlink.c | 227 ++++++++++++++++++++++++++++++++++- 3 files changed, 243 insertions(+), 1 deletion(-)
include/net/devlink.h +10 -0
@@ -45,6 +45,7 @@ struct devlink {struct list_head trap_list;struct list_head trap_group_list;struct list_head trap_policer_list; +struct list_head linecard_list;const struct devlink_ops *ops;struct xarray snapshot_ids;struct devlink_dev_stats stats;
@@ -138,6 +139,12 @@ struct devlink_port {struct mutex reporters_lock;/* Protects reporter_list */ }; +struct devlink_linecard { +struct list_head list; +struct devlink *devlink; +unsigned int index; +}; +struct devlink_sb_pool_info {enum devlink_sb_pool_type pool_type;u32 size;
@@ -1407,6 +1414,9 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 contro u16 pf, bool external);void devlink_port_attrs_pci_vf_set (struct devlink_port *devlink_port,u32 controller,u16 pf,u16 vf,bool external); +struct devlink_linecard *devlink_linecard_create (struct devlink *devlink, +unsigned int linecard_index); +void devlink_linecard_destroy (struct devlink_linecard *linecard); int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, u32 size, u16 ingress_pools_count, u16 egress_pools_count, u16 ingress_tc_count,
include/uapi/linux/devlink.h +7 -0
@@ -126,6 +126,11 @@ enum devlink_command {DEVLINK_CMD_HEALTH_REPORTER_TEST , +DEVLINK_CMD_LINECARD_GET ,/* can dump */ +DEVLINK_CMD_LINECARD_SET , +DEVLINK_CMD_LINECARD_NEW , +DEVLINK_CMD_LINECARD_DEL , +/* add new commands above here */ __DEVLINK_CMD_MAX,DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX -1
@@ -529,6 +534,8 @@ enum devlink_attr {DEVLINK_ATTR_RELOAD_ACTION_INFO ,/* nested */ DEVLINK_ATTR_RELOAD_ACTION_STATS ,/* nested */ +DEVLINK_ATTR_LINECARD_INDEX ,/* u32 */ +/* add new attributes above here, update the policy in devlink.c */ __DEVLINK_ATTR_MAX,
net/core/devlink.c +226 -1
290 lines not on this page · raw message
Signature · 1 line
2.26.2
Jiri Pirko
maintainerRFC PATCH v2 2/10 devlink: implement line card provisioning
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
In order to be able to configure all needed stuff on a port/netdevice of a line card without the line card being present, introduce line card provisioning. Basically by setting a type, provisioning process will start and driver is supposed to create a placeholder for instances (ports/netdevices) for a line card type.
Allow the user to query the supported line card types over line card get command. Then implement two netlink command SET to allow user to set/unset the card type.
On the driver API side, add provision/unprovision ops and supported types array to be advertised. Upon provision op call, the driver should take care of creating the instances for the particular line card type. Introduce provision_set/clear() functions to be called by the driver once the provisioning/unprovisioning is done on its side. These helpers are not to be called directly due to the async nature of provisioning.
---RFC->RFCv2:
- added missed const to supported_types
- converted provision/unprovision commands to SET.type command
- adjusted the patch description a bit
- added state "provisioning_failed" and a helper to set it from driver
--- include/net/devlink.h | 32 ++++++- include/uapi/linux/devlink.h | 15 +++ net/core/devlink.c | 177 ++++++++++++++++++++++++++++++++++- 3 files changed, 220 insertions(+), 4 deletions(-)
include/net/devlink.h +30 -2
@@ -139,10 +139,33 @@ struct devlink_port {struct mutex reporters_lock;/* Protects reporter_list */ }; +struct devlink_linecard_ops ; +struct devlink_linecard {struct list_head list;struct devlink *devlink;unsigned int index; +const struct devlink_linecard_ops *ops; +void *priv; +enum devlink_linecard_state state; +const char *type; +}; + +/** +* struct devlink_linecard_ops - Linecard operations +* @supported_types: array of supported types of linecards +* @supported_types_count: number of elements in the array above +* @provision: callback to provision the linecard slot with certain +* type of linecard +* @unprovision: callback to unprovision the linecard slot +*/ +struct devlink_linecard_ops { +const char *const *supported_types; +unsigned int supported_types_count; +int (*provision)(struct devlink_linecard *linecard,void *priv, +u32 type_index,struct netlink_ext_ack *extack); +int (*unprovision)(struct devlink_linecard *linecard,void *priv, +struct netlink_ext_ack *extack); };struct devlink_sb_pool_info {
@@ -1414,9 +1437,14 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 contro u16 pf, bool external);void devlink_port_attrs_pci_vf_set (struct devlink_port *devlink_port,u32 controller,u16 pf,u16 vf,bool external); -struct devlink_linecard *devlink_linecard_create (struct devlink *devlink, -unsigned int linecard_index); +struct devlink_linecard * +devlink_linecard_create (struct devlink *devlink,unsigned int linecard_index, +const struct devlink_linecard_ops *ops,void *priv);void devlink_linecard_destroy (struct devlink_linecard *linecard); +void devlink_linecard_provision_set (struct devlink_linecard *linecard, +u32 type_index); +void devlink_linecard_provision_clear (struct devlink_linecard *linecard); +void devlink_linecard_provision_fail (struct devlink_linecard *linecard); int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, u32 size, u16 ingress_pools_count, u16 egress_pools_count, u16 ingress_tc_count,
include/uapi/linux/devlink.h +15 -0
@@ -329,6 +329,18 @@ enum devlink_reload_limit {#define DEVLINK_RELOAD_LIMITS_VALID_MASK (_BITUL(__DEVLINK_RELOAD_LIMIT_MAX) - 1) +enum devlink_linecard_state { +DEVLINK_LINECARD_STATE_UNSPEC , +DEVLINK_LINECARD_STATE_UNPROVISIONED , +DEVLINK_LINECARD_STATE_UNPROVISIONING , +DEVLINK_LINECARD_STATE_PROVISIONING , +DEVLINK_LINECARD_STATE_PROVISIONING_FAILED , +DEVLINK_LINECARD_STATE_PROVISIONED , + + __DEVLINK_LINECARD_STATE_MAX, +DEVLINK_LINECARD_STATE_MAX = __DEVLINK_LINECARD_STATE_MAX -1 +}; +enum devlink_attr {/* don't change the order or add anything between, this is ABI! */ DEVLINK_ATTR_UNSPEC ,
@@ -535,6 +547,9 @@ enum devlink_attr {DEVLINK_ATTR_RELOAD_ACTION_STATS ,/* nested */ DEVLINK_ATTR_LINECARD_INDEX ,/* u32 */ +DEVLINK_ATTR_LINECARD_STATE ,/* u8 */ +DEVLINK_ATTR_LINECARD_TYPE ,/* string */ + DEVLINK_ATTR_LINECARD_SUPPORTED_TYPES, /* nested *//* add new attributes above here, update the policy in devlink.c */
net/core/devlink.c +175 -2
229 lines not on this page · raw message
Signature · 1 line
2.26.2
Jiri Pirko
maintainerRFC PATCH v2 3/10 devlink: implement line card active state
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Allow driver to mark a linecard as active. Expose this state to the userspace over devlink netlink interface with proper notifications.
---RFC->RFCv2:
- s/deactive/inactive in function comment
- removed is_active() helper which is no longer needed
--- include/net/devlink.h | 3 +++ include/uapi/linux/devlink.h | 1 + net/core/devlink.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+)
include/net/devlink.h +3 -0
@@ -149,6 +149,7 @@ struct devlink_linecard {void *priv;enum devlink_linecard_state state;const char *type; +bool active; };/**
@@ -1445,6 +1446,8 @@ void devlink_linecard_provision_set(struct devlink_linecard *linecard, u32 type_index);void devlink_linecard_provision_clear (struct devlink_linecard *linecard);void devlink_linecard_provision_fail (struct devlink_linecard *linecard); +void devlink_linecard_activate (struct devlink_linecard *linecard); +void devlink_linecard_deactivate (struct devlink_linecard *linecard); int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, u32 size, u16 ingress_pools_count, u16 egress_pools_count, u16 ingress_tc_count,
include/uapi/linux/devlink.h +1 -0
@@ -336,6 +336,7 @@ enum devlink_linecard_state {DEVLINK_LINECARD_STATE_PROVISIONING ,DEVLINK_LINECARD_STATE_PROVISIONING_FAILED ,DEVLINK_LINECARD_STATE_PROVISIONED , +DEVLINK_LINECARD_STATE_ACTIVE , __DEVLINK_LINECARD_STATE_MAX,DEVLINK_LINECARD_STATE_MAX = __DEVLINK_LINECARD_STATE_MAX -1
net/core/devlink.c +30 -0
@@ -8826,6 +8826,36 @@ void devlink_linecard_provision_fail(struct devlink_linecard *linecard) }EXPORT_SYMBOL_GPL (devlink_linecard_provision_fail); +/** +* devlink_linecard_activate - Set linecard active +* +* @devlink_linecard: devlink linecard +*/ +void devlink_linecard_activate (struct devlink_linecard *linecard) +{ +mutex_lock (&linecard->devlink->lock); +WARN_ON (linecard->state !=DEVLINK_LINECARD_STATE_PROVISIONED ); + linecard->state =DEVLINK_LINECARD_STATE_ACTIVE ; +devlink_linecard_notify (linecard,DEVLINK_CMD_LINECARD_NEW ); +mutex_unlock (&linecard->devlink->lock); +} +EXPORT_SYMBOL_GPL (devlink_linecard_activate); + +/** +* devlink_linecard_deactivate - Set linecard inactive +* +* @devlink_linecard: devlink linecard +*/ +void devlink_linecard_deactivate (struct devlink_linecard *linecard) +{ +mutex_lock (&linecard->devlink->lock); +WARN_ON (linecard->state !=DEVLINK_LINECARD_STATE_ACTIVE ); + linecard->state =DEVLINK_LINECARD_STATE_PROVISIONED ; +devlink_linecard_notify (linecard,DEVLINK_CMD_LINECARD_NEW ); +mutex_unlock (&linecard->devlink->lock); +} +EXPORT_SYMBOL_GPL (devlink_linecard_deactivate); + int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, u32 size, u16 ingress_pools_count, u16 egress_pools_count, u16 ingress_tc_count,
Signature · 1 line
2.26.2
Jiri Pirko
maintainerRFC PATCH v2 1/1 devlink: add support for linecard show and provision
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
--- devlink/devlink.c | 206 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 202 insertions(+), 4 deletions(-)
devlink/devlink.c +202 -4
@@ -306,6 +306,8 @@ static void ifname_map_free(struct ifname_map *ifname_map)#define DL_OPT_FLASH_OVERWRITE BIT(39)#define DL_OPT_RELOAD_ACTION BIT(40)#define DL_OPT_RELOAD_LIMIT BIT(41) +#define DL_OPT_LINECARD BIT(42) +#define DL_OPT_LINECARD_TYPE BIT(43)struct dl_opts {uint64_t present;/* flags of present items */
@@ -356,6 +358,8 @@ struct dl_opts {uint32_t overwrite_mask;enum devlink_reload_action reload_action;enum devlink_reload_limit reload_limit; +uint32_t linecard_index; +const char *linecard_type; };struct dl {
@@ -1414,6 +1418,8 @@ static const struct dl_args_metadata dl_args_required[] = { {DL_OPT_TRAP_NAME, "Trap's name is expected."}, {DL_OPT_TRAP_GROUP_NAME, "Trap group's name is expected."}, {DL_OPT_PORT_FUNCTION_HW_ADDR, "Port function's hardware address is expected."}, + {DL_OPT_LINECARD, "Linecard index expected."}, + {DL_OPT_LINECARD_TYPE, "Linecard type expected."}, }; static int dl_args_finding_required_validate(uint64_t o_required,
@@ -1832,7 +1838,25 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,if (err)return err; o_found |=DL_OPT_PORT_FUNCTION_HW_ADDR ; - + }else if (dl_argv_match (dl,"lc" ) && + (o_all &DL_OPT_LINECARD )) { +dl_arg_inc (dl); + err =dl_argv_uint32_t (dl, &opts->linecard_index); +if (err) +return err; + o_found |=DL_OPT_LINECARD ; + }else if (dl_argv_match (dl,"type" ) && + (o_all &DL_OPT_LINECARD_TYPE )) { +dl_arg_inc (dl); + err =dl_argv_str (dl, &opts->linecard_type); +if (err) +return err; + o_found |=DL_OPT_LINECARD_TYPE ; + }else if (dl_argv_match (dl,"notype" ) && + (o_all &DL_OPT_LINECARD_TYPE )) { +dl_arg_inc (dl); + opts->linecard_type ="" ; + o_found |=DL_OPT_LINECARD_TYPE ; }else {pr_err ("Unknown option \"%s\"\n" ,dl_argv (dl));return -EINVAL ;
@@ -2015,6 +2039,12 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl) opts->trap_policer_burst);if (opts->present &DL_OPT_PORT_FUNCTION_HW_ADDR )dl_function_attr_put (nlh, opts); +if (opts->present &DL_OPT_LINECARD ) +mnl_attr_put_u32 (nlh,DEVLINK_ATTR_LINECARD_INDEX , + opts->linecard_index); +if (opts->present &DL_OPT_LINECARD_TYPE ) +mnl_attr_put_strz (nlh,DEVLINK_ATTR_LINECARD_TYPE , + opts->linecard_type); } static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
@@ -2036,6 +2066,7 @@ static bool dl_dump_filter(struct dl *dl, struct nlattr **tb)struct nlattr *attr_dev_name = tb[DEVLINK_ATTR_DEV_NAME ];struct nlattr *attr_port_index = tb[DEVLINK_ATTR_PORT_INDEX ];struct nlattr *attr_sb_index = tb[DEVLINK_ATTR_SB_INDEX ]; +struct nlattr *attr_linecard_index = tb[DEVLINK_ATTR_LINECARD_INDEX ];if (opts->present &DL_OPT_HANDLE && attr_bus_name && attr_dev_name) {
@@ -2063,6 +2094,12 @@ static bool dl_dump_filter(struct dl *dl, struct nlattr **tb)if (sb_index != opts->sb_index)return false; } +if (opts->present &DL_OPT_LINECARD && attr_linecard_index) { +uint32_t linecard_index =mnl_attr_get_u32 (attr_linecard_index); + +if (linecard_index != opts->linecard_index) +return false; + }return true; }
@@ -3833,6 +3870,9 @@ static void pr_out_port(struct dl *dl, struct nlattr **tb)break ; } } +if (tb[DEVLINK_ATTR_LINECARD_INDEX ]) +print_uint (PRINT_ANY ,"lc" ," lc %u" , +mnl_attr_get_u32 (tb[DEVLINK_ATTR_LINECARD_INDEX ]));if (tb[DEVLINK_ATTR_PORT_NUMBER ]) {uint32_t port_number;
@@ -4005,6 +4045,139 @@ static int cmd_port(struct dl *dl)return -ENOENT ; } +static void cmd_linecard_help (void ) +{ +pr_err ("Usage: devlink lc show [ DEV [ lc LC_INDEX ] ]\n" ); +pr_err (" devlink lc set DEV lc LC_INDEX [ { type LC_TYPE | notype } ]\n" ); +} + +static const char *linecard_state_name (uint16_t flavour) +{ +switch (flavour) { +case DEVLINK_LINECARD_STATE_UNPROVISIONED : +return "unprovisioned" ; +case DEVLINK_LINECARD_STATE_UNPROVISIONING : +return "unprovisioning" ; +case DEVLINK_LINECARD_STATE_PROVISIONING : +return "provisioning" ; +case DEVLINK_LINECARD_STATE_PROVISIONING_FAILED : +return "provisioning_failed" ; +case DEVLINK_LINECARD_STATE_PROVISIONED : +return "provisioned" ; +case DEVLINK_LINECARD_STATE_ACTIVE : +return "active" ; +default : +return "<unknown state>" ; + } +} + +static void pr_out_linecard_supported_types (struct dl *dl,struct nlattr **tb) +{ +struct nlattr *nla_types = tb[DEVLINK_ATTR_LINECARD_SUPPORTED_TYPES ]; +struct nlattr *nla_type; + +if (!nla_types) +return ; + +pr_out_array_start (dl,"supported_types" ); +check_indent_newline (dl); +mnl_attr_for_each_nested (nla_type, nla_types) { +print_string (PRINT_ANY ,NULL ," %s" , +mnl_attr_get_str (nla_type)); + } +pr_out_array_end (dl); +} + +static void pr_out_linecard (struct dl *dl,struct nlattr **tb) +{ +uint8_t state; + +pr_out_handle_start_arr (dl, tb); +check_indent_newline (dl); +print_uint (PRINT_ANY ,"lc" ,"lc %u" , +mnl_attr_get_u32 (tb[DEVLINK_ATTR_LINECARD_INDEX ])); + state =mnl_attr_get_u8 (tb[DEVLINK_ATTR_LINECARD_STATE ]); +print_string (PRINT_ANY ,"state" ," state %s" , +linecard_state_name (state)); +if (tb[DEVLINK_ATTR_LINECARD_TYPE ]) +print_string (PRINT_ANY ,"type" ," type %s" , +mnl_attr_get_str (tb[DEVLINK_ATTR_LINECARD_TYPE ])); +pr_out_linecard_supported_types (dl, tb); +pr_out_handle_end (dl); +} + +static int cmd_linecard_show_cb (const struct nlmsghdr *nlh,void *data) +{ +struct dl *dl = data; +struct nlattr *tb[DEVLINK_ATTR_MAX +1 ] = {}; +struct genlmsghdr *genl =mnl_nlmsg_get_payload (nlh); + +mnl_attr_parse (nlh,sizeof (*genl), attr_cb, tb); +if (!tb[DEVLINK_ATTR_BUS_NAME ] || !tb[DEVLINK_ATTR_DEV_NAME ] || + !tb[DEVLINK_ATTR_LINECARD_INDEX ] || + !tb[DEVLINK_ATTR_LINECARD_STATE ]) +return MNL_CB_ERROR ; +pr_out_linecard (dl, tb); +return MNL_CB_OK ; +} + +static int cmd_linecard_show (struct dl *dl) +{ +struct nlmsghdr *nlh; +uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ; +int err; + +if (dl_argc (dl) ==0 ) + flags |=NLM_F_DUMP ; + + nlh =mnlg_msg_prepare (dl->nlg,DEVLINK_CMD_LINECARD_GET , flags); + +if (dl_argc (dl) >0 ) { + err =dl_argv_parse_put (nlh, dl,DL_OPT_HANDLE , +DL_OPT_LINECARD ); +if (err) +return err; + } + +pr_out_section_start (dl,"lc" ); + err =_mnlg_socket_sndrcv (dl->nlg, nlh, cmd_linecard_show_cb, dl); +pr_out_section_end (dl); +return err; +} + +static int cmd_linecard_set (struct dl *dl) +{ +struct nlmsghdr *nlh; +int err; + + nlh =mnlg_msg_prepare (dl->nlg,DEVLINK_CMD_LINECARD_SET , +NLM_F_REQUEST |NLM_F_ACK ); + + err =dl_argv_parse_put (nlh, dl,DL_OPT_HANDLE |DL_OPT_LINECARD | +DL_OPT_LINECARD_TYPE ,0 ); +if (err) +return err; + +return _mnlg_socket_sndrcv (dl->nlg, nlh,NULL ,NULL ); +} + +static int cmd_linecard (struct dl *dl) +{ +if (dl_argv_match (dl,"help" )) { +cmd_linecard_help (); +return 0 ; + }else if (dl_argv_match (dl,"show" ) || +dl_argv_match (dl,"list" ) ||dl_no_arg (dl)) { +dl_arg_inc (dl); +return cmd_linecard_show (dl); + }else if (dl_argv_match (dl,"set" )) { +dl_arg_inc (dl); +return cmd_linecard_set (dl); + } +pr_err ("Command \"%s\" not found\n" ,dl_argv (dl)); +return -ENOENT ; +} +static void cmd_sb_help (void ) {pr_err ("Usage: devlink sb show [ DEV [ sb SB_INDEX ] ]\n" );
@@ -4818,6 +4991,10 @@ static const char *cmd_name(uint8_t cmd)case DEVLINK_CMD_TRAP_POLICER_SET :return "set" ;case DEVLINK_CMD_TRAP_POLICER_NEW :return "new" ;case DEVLINK_CMD_TRAP_POLICER_DEL :return "del" ; +case DEVLINK_CMD_LINECARD_GET :return "get" ; +case DEVLINK_CMD_LINECARD_SET :return "set" ; +case DEVLINK_CMD_LINECARD_NEW :return "new" ; +case DEVLINK_CMD_LINECARD_DEL :return "del" ;default :return "<unknown cmd>" ; } }
@@ -4867,6 +5044,11 @@ static const char *cmd_obj(uint8_t cmd)case DEVLINK_CMD_TRAP_POLICER_NEW :case DEVLINK_CMD_TRAP_POLICER_DEL :return "trap-policer" ; +case DEVLINK_CMD_LINECARD_GET : +case DEVLINK_CMD_LINECARD_SET : +case DEVLINK_CMD_LINECARD_NEW : +case DEVLINK_CMD_LINECARD_DEL : +return "lc" ;default :return "<unknown obj>" ; } }
@@ -5059,6 +5241,18 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)pr_out_mon_header (genl->cmd);pr_out_trap_policer (dl, tb, false);break ; +case DEVLINK_CMD_LINECARD_GET :/* fall through */ +case DEVLINK_CMD_LINECARD_SET :/* fall through */ +case DEVLINK_CMD_LINECARD_NEW :/* fall through */ +case DEVLINK_CMD_LINECARD_DEL : +mnl_attr_parse (nlh,sizeof (*genl), attr_cb, tb); +if (!tb[DEVLINK_ATTR_BUS_NAME ] || !tb[DEVLINK_ATTR_DEV_NAME ] || + !tb[DEVLINK_ATTR_LINECARD_INDEX ]) +return MNL_CB_ERROR ; +pr_out_mon_header (genl->cmd); +pr_out_linecard (dl, tb); +pr_out_mon_footer (); +break ; }fflush (stdout);return MNL_CB_OK ;
@@ -5077,7 +5271,8 @@ static int cmd_mon_show(struct dl *dl) strcmp(cur_obj, "health") != 0 && strcmp(cur_obj, "trap") != 0 && strcmp(cur_obj, "trap-group") != 0 && - strcmp(cur_obj, "trap-policer") != 0) { + strcmp(cur_obj, "trap-policer") != 0 && + strcmp(cur_obj, "lc") != 0) {pr_err ("Unknown object \"%s\"\n" , cur_obj);return -EINVAL ; }
@@ -5098,7 +5293,7 @@ static int cmd_mon_show(struct dl *dl)static void cmd_mon_help (void ) {pr_err ("Usage: devlink monitor [ all | OBJECT-LIST ]\n" -"where OBJECT-LIST := { dev | port | health | trap | trap-group | trap-policer }\n" ); +"where OBJECT-LIST := { dev | port | lc | health | trap | trap-group | trap-policer }\n" ); }static int cmd_mon (struct dl *dl)
@@ -8073,7 +8268,7 @@ static void help(void) {pr_err ("Usage: devlink [ OPTIONS ] OBJECT { COMMAND | help }\n" " devlink [ -f[orce] ] -b[atch] filename -N[etns] netnsname\n" -"where OBJECT := { dev | port | sb | monitor | dpipe | resource | region | health | trap }\n" +"where OBJECT := { dev | port | lc | sb | monitor | dpipe | resource | region | health | trap }\n" " OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] | -v[erbose] -s[tatistics] }\n" ); }
@@ -8112,6 +8307,9 @@ static int dl_cmd(struct dl *dl, int argc, char **argv) }else if (dl_argv_match (dl,"trap" )) {dl_arg_inc (dl);return cmd_trap (dl); + }else if (dl_argv_match (dl,"lc" )) { +dl_arg_inc (dl); +return cmd_linecard (dl); }pr_err ("Object \"%s\" not found\n" ,dl_argv (dl));return -ENOENT ;
Signature · 1 line
2.26.2
Jiri Pirko
maintainerRFC PATCH v2 4/10 devlink: append split port number to the port name
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Instead of doing sprintf twice in case the port is split or not, append the split port suffix in case the port is split.
--- net/core/devlink.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
net/core/devlink.c +4 -6
@@ -8673,12 +8673,10 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,switch (attrs->flavour) {case DEVLINK_PORT_FLAVOUR_PHYSICAL :case DEVLINK_PORT_FLAVOUR_VIRTUAL : -if (!attrs->split) - n =snprintf (name, len,"p%u" , attrs->phys.port_number); -else - n =snprintf (name, len,"p%us%u" , - attrs->phys.port_number, - attrs->phys.split_subport_number); + n =snprintf (name, len,"p%u" , attrs->phys.port_number); +if (attrs->split) + n +=snprintf (name + n, len - n,"s%u" , + attrs->phys.split_subport_number);break ;case DEVLINK_PORT_FLAVOUR_CPU :case DEVLINK_PORT_FLAVOUR_DSA :
Signature · 1 line
2.26.2
Jiri Pirko
maintainerRFC PATCH v2 5/10 devlink: add port to line card relationship set
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
In order to properly inform user about relationship between port and line card, introduce a driver API to set line card for a port. Use this information to extend port devlink netlink message by line card index and also include the line card index into phys_port_name and by that into a netdevice name.
--- include/net/devlink.h | 3 +++ net/core/devlink.c | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-)
include/net/devlink.h +3 -0
@@ -137,6 +137,7 @@ struct devlink_port {struct delayed_work type_warn_dw;struct list_head reporter_list;struct mutex reporters_lock;/* Protects reporter_list */ +struct devlink_linecard *linecard; };struct devlink_linecard_ops ;
@@ -1438,6 +1439,8 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 contro u16 pf, bool external);void devlink_port_attrs_pci_vf_set (struct devlink_port *devlink_port,u32 controller,u16 pf,u16 vf,bool external); +void devlink_port_linecard_set (struct devlink_port *devlink_port, +struct devlink_linecard *linecard);struct devlink_linecard *devlink_linecard_create (struct devlink *devlink,unsigned int linecard_index,const struct devlink_linecard_ops *ops,void *priv);
net/core/devlink.c +24 -1
@@ -855,6 +855,10 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink, goto nla_put_failure;if (devlink_nl_port_function_attrs_put (msg, devlink_port, extack)) goto nla_put_failure; +if (devlink_port->linecard && +nla_put_u32 (msg,DEVLINK_ATTR_LINECARD_INDEX , + devlink_port->linecard->index)) + goto nla_put_failure;genlmsg_end (msg, hdr);return 0 ;
@@ -8661,6 +8665,21 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro }EXPORT_SYMBOL_GPL (devlink_port_attrs_pci_vf_set); +/** +* devlink_port_linecard_set - Link port with a linecard +* +* @devlink_port: devlink port +* @devlink_linecard: devlink linecard +*/ +void devlink_port_linecard_set (struct devlink_port *devlink_port, +struct devlink_linecard *linecard) +{ +if (WARN_ON (devlink_port->registered)) +return ; + devlink_port->linecard = linecard; +} +EXPORT_SYMBOL_GPL (devlink_port_linecard_set); +static int __devlink_port_phys_port_name_get (struct devlink_port *devlink_port,char *name,size_t len) {
@@ -8673,7 +8692,11 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,switch (attrs->flavour) {case DEVLINK_PORT_FLAVOUR_PHYSICAL :case DEVLINK_PORT_FLAVOUR_VIRTUAL : - n =snprintf (name, len,"p%u" , attrs->phys.port_number); +if (devlink_port->linecard) + n =snprintf (name, len,"l%u" , + devlink_port->linecard->index); + n +=snprintf (name + n, len - n,"p%u" , + attrs->phys.port_number);if (attrs->split) n +=snprintf (name + n, len - n,"s%u" , attrs->phys.split_subport_number);
Signature · 1 line
2.26.2
Jiri Pirko
maintainerRFC PATCH v2 6/10 netdevsim: introduce line card support
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Add support for line card objects. Expose them over debugfs and allow user to specify number of line cards to be created for a new device. Similar to ports, the number of line cards is fixed.
Extend "new_device" sysfs file write by third number to allow to specify number line cards like this:
$ echo "10 4 2" >/sys/bus/netdevsim/new_device
This command asks to create two line cards. By default, if this number is not preset, no line card is created.
--- drivers/net/netdevsim/bus.c | 17 +++-- drivers/net/netdevsim/dev.c | 108 +++++++++++++++++++++++++++++- drivers/net/netdevsim/netdevsim.h | 15 +++++ 3 files changed, 133 insertions(+), 7 deletions(-)
drivers/net/netdevsim/bus.c +12 -5
@@ -179,29 +179,34 @@ static struct device_type nsim_bus_dev_type = { };static struct nsim_bus_dev * -nsim_bus_dev_new (unsigned int id,unsigned int port_count); +nsim_bus_dev_new (unsigned int id,unsigned int port_count, +unsigned int linecard_count);static ssize_t new_device_store (struct bus_type *bus,const char *buf,size_t count) {struct nsim_bus_dev *nsim_bus_dev; +unsigned int linecard_count;unsigned int port_count;unsigned int id;int err; - err =sscanf (buf,"%u %u" , &id, &port_count); + err =sscanf (buf,"%u %u %u" , &id, &port_count, &linecard_count);switch (err) {case 1 : port_count =1 ; fallthrough;case 2 : + linecard_count =0 ; + fallthrough; +case 3 :if (id >INT_MAX ) {pr_err ("Value of \"id\" is too big.\n" );return -EINVAL ; }break ;default : -pr_err ("Format for adding new device is \"id port_count\" (uint uint).\n" ); +pr_err ("Format for adding new device is \"id port_count linecard_count\" (uint uint uint).\n" );return -EINVAL ; }
@@ -212,7 +217,7 @@ new_device_store(struct bus_type *bus, const char *buf, size_t count) goto err; } - nsim_bus_dev =nsim_bus_dev_new (id, port_count); + nsim_bus_dev =nsim_bus_dev_new (id, port_count, linecard_count);if (IS_ERR (nsim_bus_dev)) { err =PTR_ERR (nsim_bus_dev); goto err;
@@ -312,7 +317,8 @@ static struct bus_type nsim_bus = { };static struct nsim_bus_dev * -nsim_bus_dev_new (unsigned int id,unsigned int port_count) +nsim_bus_dev_new (unsigned int id,unsigned int port_count, +unsigned int linecard_count) {struct nsim_bus_dev *nsim_bus_dev;int err;
@@ -328,6 +334,7 @@ nsim_bus_dev_new(unsigned int id, unsigned int port_count) nsim_bus_dev->dev.bus = &nsim_bus; nsim_bus_dev->dev.type = &nsim_bus_dev_type; nsim_bus_dev->port_count = port_count; + nsim_bus_dev->linecard_count = linecard_count; nsim_bus_dev->initial_net = current->nsproxy->net_ns;mutex_init (&nsim_bus_dev->nsim_bus_reload_lock);/* Disallow using nsim_bus_dev */
drivers/net/netdevsim/dev.c +106 -2
178 lines not on this page · raw message
drivers/net/netdevsim/netdevsim.h +15 -0
@@ -180,20 +180,33 @@ struct nsim_dev_health {int nsim_dev_health_init (struct nsim_dev *nsim_dev,struct devlink *devlink);void nsim_dev_health_exit (struct nsim_dev *nsim_dev); +struct nsim_dev_linecard ; +struct nsim_dev_port {struct list_head list;struct devlink_port devlink_port; +struct nsim_dev_linecard *linecard;unsigned int port_index;struct dentry *ddir;struct netdevsim *ns; }; +struct nsim_dev ; + +struct nsim_dev_linecard { +struct list_head list; +struct nsim_dev *nsim_dev; +unsigned int linecard_index; +struct dentry *ddir; +}; +struct nsim_dev {struct nsim_bus_dev *nsim_bus_dev;struct nsim_fib_data *fib_data;struct nsim_trap_data *trap_data;struct dentry *ddir;struct dentry *ports_ddir; +struct dentry *linecards_ddir;struct dentry *take_snapshot;struct bpf_offload_dev *bpf_dev;bool bpf_bind_accept;
@@ -206,6 +219,7 @@ struct nsim_dev {struct netdev_phys_item_id switch_id;struct list_head port_list;struct mutex port_list_lock;/* protects port list */ +struct list_head linecard_list;bool fw_update_status;u32 fw_update_overwrite_mask;u32 max_macs;
@@ -287,6 +301,7 @@ struct nsim_bus_dev {struct device dev;struct list_head list;unsigned int port_count; +unsigned int linecard_count;struct net *initial_net;/* Purpose of this is to carry net pointer * during the probe time only. */
Signature · 1 line
2.26.2
Jiri Pirko
maintainerRFC PATCH v2 7/10 netdevsim: allow port objects to be linked with line cards
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Line cards contain ports. Allow ports to be places on the line cards. Track the ports that belong under certain line card. Make sure that the line card port carrier is down, as it will be taken up later on during "activation".
--- drivers/net/netdevsim/bus.c | 4 +-- drivers/net/netdevsim/dev.c | 48 +++++++++++++++++++++++++------ drivers/net/netdevsim/netdev.c | 2 ++ drivers/net/netdevsim/netdevsim.h | 4 +++ 4 files changed, 48 insertions(+), 10 deletions(-)
drivers/net/netdevsim/bus.c +2 -2
@@ -113,7 +113,7 @@ new_port_store(struct device *dev, struct device_attribute *attr,mutex_lock (&nsim_bus_dev->nsim_bus_reload_lock);devlink_reload_disable (devlink); - ret =nsim_dev_port_add (nsim_bus_dev, port_index); + ret =nsim_dev_port_add (nsim_bus_dev,NULL , port_index);devlink_reload_enable (devlink);mutex_unlock (&nsim_bus_dev->nsim_bus_reload_lock);return ret ? ret : count;
@@ -142,7 +142,7 @@ del_port_store(struct device *dev, struct device_attribute *attr,mutex_lock (&nsim_bus_dev->nsim_bus_reload_lock);devlink_reload_disable (devlink); - ret =nsim_dev_port_del (nsim_bus_dev, port_index); + ret =nsim_dev_port_del (nsim_bus_dev,NULL , port_index);devlink_reload_enable (devlink);mutex_unlock (&nsim_bus_dev->nsim_bus_reload_lock);return ret ? ret : count;
drivers/net/netdevsim/dev.c +40 -8
130 lines not on this page · raw message
drivers/net/netdevsim/netdev.c +2 -0
@@ -312,6 +312,8 @@ nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port)nsim_ipsec_init (ns); +netif_carrier_off (dev); + err =register_netdevice (dev);if (err) goto err_ipsec_teardown;
drivers/net/netdevsim/netdevsim.h +4 -0
@@ -184,6 +184,7 @@ struct nsim_dev_linecard;struct nsim_dev_port {struct list_head list; +struct list_head list_lc;/* node in linecard list */ struct devlink_port devlink_port;struct nsim_dev_linecard *linecard;unsigned int port_index;
@@ -196,6 +197,7 @@ struct nsim_dev;struct nsim_dev_linecard {struct list_head list;struct nsim_dev *nsim_dev; +struct list_head port_list;unsigned int linecard_index;struct dentry *ddir; };
@@ -255,8 +257,10 @@ void nsim_dev_exit(void);int nsim_dev_probe (struct nsim_bus_dev *nsim_bus_dev);void nsim_dev_remove (struct nsim_bus_dev *nsim_bus_dev);int nsim_dev_port_add (struct nsim_bus_dev *nsim_bus_dev, +struct nsim_dev_linecard *nsim_dev_linecard,unsigned int port_index);int nsim_dev_port_del (struct nsim_bus_dev *nsim_bus_dev, +struct nsim_dev_linecard *nsim_dev_linecard,unsigned int port_index); struct nsim_fib_data *nsim_fib_create(struct devlink *devlink,
Signature · 1 line
2.26.2
Jiri Pirko
maintainerRFC PATCH v2 8/10 netdevsim: create devlink line card object and implement provisioning
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Use devlink_linecard_create/destroy() to register the line card with devlink core. Implement provisioning ops with a list of supported line cards. To avoid deadlock and to mimic actual HW flow, use workqueue to add/del ports during provisioning as the port add/del calls devlink_port_register/unregister() which take devlink mutex.
---RFC->RFCv2:
- cancel work in linecard_del, have separate work for unprovision
- call provision_set() without type
- use provision_fail() helper in case provisioning was not successful
--- drivers/net/netdevsim/dev.c | 135 +++++++++++++++++++++++++++++- drivers/net/netdevsim/netdevsim.h | 5 ++ 2 files changed, 139 insertions(+), 1 deletion(-)
drivers/net/netdevsim/dev.c +134 -1
@@ -35,6 +35,20 @@#include "netdevsim.h" +static const char *const nsim_dev_linecard_supported_types[] = { +"card1port" ,"card2ports" ,"card4ports" , +}; + +static const unsigned int nsim_dev_linecard_port_counts[] = { +1 ,2 ,4 , +}; + +static unsigned int +nsim_dev_linecard_port_count (struct nsim_dev_linecard *nsim_dev_linecard) +{ +return nsim_dev_linecard_port_counts[nsim_dev_linecard->type_index]; +} +#define NSIM_DEV_LINECARD_PORT_INDEX_BASE 1000#define NSIM_DEV_LINECARD_PORT_INDEX_STEP 100
@@ -285,6 +299,25 @@ static void nsim_dev_port_debugfs_exit(struct nsim_dev_port *nsim_dev_port)debugfs_remove_recursive (nsim_dev_port->ddir); } +static ssize_t nsim_dev_linecard_type_read (struct file *file,char __user *data, +size_t count,loff_t *ppos) +{ +struct nsim_dev_linecard *nsim_dev_linecard = file->private_data; +const char *type; + +if (!nsim_dev_linecard->provisioned) +return -EOPNOTSUPP ; + + type = nsim_dev_linecard_supported_types[nsim_dev_linecard->type_index]; +return simple_read_from_buffer (data, count, ppos, type,strlen (type)); +} + +static const struct file_operations nsim_dev_linecard_type_fops = { + .open = simple_open, + .read = nsim_dev_linecard_type_read, + .owner =THIS_MODULE , +}; +static int nsim_dev_linecard_debugfs_init (struct nsim_dev *nsim_dev,struct nsim_dev_linecard *nsim_dev_linecard)
@@ -301,6 +334,8 @@ nsim_dev_linecard_debugfs_init(struct nsim_dev *nsim_dev,sprintf (dev_link_name,"../../../" DRV_NAME "%u" , nsim_dev->nsim_bus_dev->dev.id);debugfs_create_symlink ("dev" , nsim_dev_linecard->ddir, dev_link_name); +debugfs_create_file ("type" ,0400 , nsim_dev_linecard->ddir, + nsim_dev_linecard, &nsim_dev_linecard_type_fops);return 0 ; }
@@ -977,6 +1012,9 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev,memcpy (attrs.switch_id.id, nsim_dev->switch_id.id, nsim_dev->switch_id.id_len); attrs.switch_id.id_len = nsim_dev->switch_id.id_len;devlink_port_attrs_set (devlink_port, &attrs); +if (nsim_dev_linecard) +devlink_port_linecard_set (devlink_port, + nsim_dev_linecard->devlink_linecard); err =devlink_port_register (priv_to_devlink (nsim_dev), devlink_port, nsim_dev_port->port_index);if (err)
@@ -1053,10 +1091,82 @@ static int nsim_dev_port_add_all(struct nsim_dev *nsim_dev,return err; } +static void nsim_dev_linecard_provision_work (struct work_struct *work) +{ +struct nsim_dev_linecard *nsim_dev_linecard; +struct nsim_bus_dev *nsim_bus_dev; +int err; +int i; + + nsim_dev_linecard = container_of(work, struct nsim_dev_linecard, + provision_work); + + nsim_bus_dev = nsim_dev_linecard->nsim_dev->nsim_bus_dev; +for (i =0 ; i <nsim_dev_linecard_port_count (nsim_dev_linecard); i++) { + err =nsim_dev_port_add (nsim_bus_dev, nsim_dev_linecard, i); +if (err) + goto err_port_del_all; + } + nsim_dev_linecard->provisioned = true; +devlink_linecard_provision_set (nsim_dev_linecard->devlink_linecard, + nsim_dev_linecard->type_index); +return ; + +err_port_del_all: +for (i--; i >=0 ; i--) +nsim_dev_port_del (nsim_bus_dev, nsim_dev_linecard, i); +devlink_linecard_provision_fail (nsim_dev_linecard->devlink_linecard); +} + +static int nsim_dev_linecard_provision (struct devlink_linecard *linecard, +void *priv,u32 type_index, +struct netlink_ext_ack *extack) +{ +struct nsim_dev_linecard *nsim_dev_linecard = priv; + + nsim_dev_linecard->type_index = type_index; +schedule_work (&nsim_dev_linecard->provision_work); +return 0 ; +} + +static void nsim_dev_linecard_unprovision_work (struct work_struct *work) +{ +struct nsim_dev_linecard *nsim_dev_linecard; +struct nsim_bus_dev *nsim_bus_dev; +int i; + + nsim_dev_linecard = container_of(work, struct nsim_dev_linecard, + unprovision_work); + + nsim_bus_dev = nsim_dev_linecard->nsim_dev->nsim_bus_dev; + nsim_dev_linecard->provisioned = false; +devlink_linecard_provision_clear (nsim_dev_linecard->devlink_linecard); +for (i =0 ; i <nsim_dev_linecard_port_count (nsim_dev_linecard); i++) +nsim_dev_port_del (nsim_bus_dev, nsim_dev_linecard, i); +} + +static int nsim_dev_linecard_unprovision (struct devlink_linecard *linecard, +void *priv, +struct netlink_ext_ack *extack) +{ +struct nsim_dev_linecard *nsim_dev_linecard = priv; + +schedule_work (&nsim_dev_linecard->unprovision_work); +return 0 ; +} + +static const struct devlink_linecard_ops nsim_dev_linecard_ops = { + .supported_types = nsim_dev_linecard_supported_types, + .supported_types_count =ARRAY_SIZE (nsim_dev_linecard_supported_types), + .provision = nsim_dev_linecard_provision, + .unprovision = nsim_dev_linecard_unprovision, +}; +static int __nsim_dev_linecard_add (struct nsim_dev *nsim_dev,unsigned int linecard_index) {struct nsim_dev_linecard *nsim_dev_linecard; +struct devlink_linecard *devlink_linecard;int err; nsim_dev_linecard =kzalloc (sizeof (*nsim_dev_linecard),GFP_KERNEL );
@@ -1065,15 +1175,32 @@ static int __nsim_dev_linecard_add(struct nsim_dev *nsim_dev, nsim_dev_linecard->nsim_dev = nsim_dev; nsim_dev_linecard->linecard_index = linecard_index;INIT_LIST_HEAD (&nsim_dev_linecard->port_list); +INIT_WORK (&nsim_dev_linecard->provision_work, + nsim_dev_linecard_provision_work); +INIT_WORK (&nsim_dev_linecard->unprovision_work, + nsim_dev_linecard_unprovision_work); + + devlink_linecard =devlink_linecard_create (priv_to_devlink (nsim_dev), + linecard_index, + &nsim_dev_linecard_ops, + nsim_dev_linecard); +if (IS_ERR (devlink_linecard)) { + err =PTR_ERR (devlink_linecard); + goto err_linecard_free; + } + + nsim_dev_linecard->devlink_linecard = devlink_linecard; err =nsim_dev_linecard_debugfs_init (nsim_dev, nsim_dev_linecard);if (err) - goto err_linecard_free; + goto err_dl_linecard_destroy;list_add (&nsim_dev_linecard->list, &nsim_dev->linecard_list);return 0 ; +err_dl_linecard_destroy: +devlink_linecard_destroy (devlink_linecard); err_linecard_free:kfree (nsim_dev_linecard);return err;
@@ -1081,8 +1208,14 @@ static int __nsim_dev_linecard_add(struct nsim_dev *nsim_dev,static void __nsim_dev_linecard_del (struct nsim_dev_linecard *nsim_dev_linecard) { +struct devlink_linecard *devlink_linecard = + nsim_dev_linecard->devlink_linecard; + +cancel_work_sync (&nsim_dev_linecard->provision_work); +cancel_work_sync (&nsim_dev_linecard->unprovision_work);list_del (&nsim_dev_linecard->list);nsim_dev_linecard_debugfs_exit (nsim_dev_linecard); +devlink_linecard_destroy (devlink_linecard);kfree (nsim_dev_linecard); }
drivers/net/netdevsim/netdevsim.h +5 -0
@@ -196,10 +196,15 @@ struct nsim_dev;struct nsim_dev_linecard {struct list_head list; +struct devlink_linecard *devlink_linecard;struct nsim_dev *nsim_dev;struct list_head port_list;unsigned int linecard_index;struct dentry *ddir; +bool provisioned; +u32 type_index; +struct work_struct provision_work; +struct work_struct unprovision_work; };struct nsim_dev {
Signature · 1 line
2.26.2
Jiri Pirko
maintainerRFC PATCH v2 9/10 netdevsim: implement line card activation
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
On real HW, the activation typically happens upon line card insertion. Emulate such event using write to debugfs file "inserted_type".
---RFC->RFCv2:
- converted bool "active" to string "inserted_type" and adjust loginc around it wrt provision/unprovision work
--- drivers/net/netdevsim/dev.c | 136 ++++++++++++++++++++++++++++++ drivers/net/netdevsim/netdevsim.h | 2 + 2 files changed, 138 insertions(+)
drivers/net/netdevsim/dev.c +136 -0
@@ -43,6 +43,16 @@ static const unsigned int nsim_dev_linecard_port_counts[] = { 1, 2, 4, }; +static int nsim_dev_linecard_type_index (const char *type) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (nsim_dev_linecard_supported_types); i++) +if (!strcmp (nsim_dev_linecard_supported_types[i], type)) +return i; +return -1 ; +} +static unsigned int nsim_dev_linecard_port_count (struct nsim_dev_linecard *nsim_dev_linecard) {
@@ -64,6 +74,60 @@ nsim_dev_port_index(struct nsim_dev_linecard *nsim_dev_linecard, port_index; } +static int +nsim_dev_linecard_activate (struct nsim_dev_linecard *nsim_dev_linecard) +{ +struct nsim_dev_port *nsim_dev_port; + +if (!nsim_dev_linecard->inserted || !nsim_dev_linecard->provisioned) +return 0 ; + +if (nsim_dev_linecard->type_index != + nsim_dev_linecard->inserted_type_index) +return -EINVAL ; + +list_for_each_entry (nsim_dev_port, &nsim_dev_linecard->port_list, + list_lc) +netif_carrier_on (nsim_dev_port->ns->netdev); + +devlink_linecard_activate (nsim_dev_linecard->devlink_linecard); +return 0 ; +} + +static int +nsim_dev_linecard_insert (struct nsim_dev_linecard *nsim_dev_linecard, +u32 inserted_type_index) +{ +if (nsim_dev_linecard->type_index != inserted_type_index) +return -EINVAL ; + + nsim_dev_linecard->inserted_type_index = inserted_type_index; + nsim_dev_linecard->inserted = true; +return nsim_dev_linecard_activate (nsim_dev_linecard); +} + +static void +nsim_dev_linecard_deactivate (struct nsim_dev_linecard *nsim_dev_linecard) +{ +struct nsim_dev_port *nsim_dev_port; + +if (!nsim_dev_linecard->inserted) +return ; +list_for_each_entry (nsim_dev_port, &nsim_dev_linecard->port_list, + list_lc) +netif_carrier_off (nsim_dev_port->ns->netdev); +} + +static void +nsim_dev_linecard_remove (struct nsim_dev_linecard *nsim_dev_linecard) +{ +if (!nsim_dev_linecard->inserted) +return ; +nsim_dev_linecard_deactivate (nsim_dev_linecard); + nsim_dev_linecard->inserted = false; +devlink_linecard_deactivate (nsim_dev_linecard->devlink_linecard); +} +static struct dentry *nsim_dev_ddir;#define NSIM_DEV_DUMMY_REGION_SIZE (1024 * 32)
@@ -299,6 +363,72 @@ static void nsim_dev_port_debugfs_exit(struct nsim_dev_port *nsim_dev_port)debugfs_remove_recursive (nsim_dev_port->ddir); } +static ssize_t nsim_dev_linecard_inserted_type_read (struct file *file, +char __user *data, +size_t count,loff_t *ppos) +{ +struct nsim_dev_linecard *nsim_dev_linecard = file->private_data; +const char *type; + +if (!nsim_dev_linecard->inserted) +return -EOPNOTSUPP ; + + type = nsim_dev_linecard_supported_types[nsim_dev_linecard->inserted_type_index]; +return simple_read_from_buffer (data, count, ppos, type,strlen (type)); +} + +static ssize_t nsim_dev_linecard_inserted_type_write (struct file *file, +const char __user *data, +size_t count,loff_t *ppos) +{ +struct nsim_dev_linecard *nsim_dev_linecard = file->private_data; +char *buf; +int err; +int ret; + +if (*ppos !=0 ) +return -EINVAL ; + buf =kmalloc (count,GFP_KERNEL | __GFP_NOWARN); +if (!buf) +return -ENOMEM ; + + ret =simple_write_to_buffer (buf, count, ppos, data, count); +if (ret <0 ) + goto free_buf; + + buf[count -1 ] ='\0' ; +if (strlen (buf) >0 ) { +int inserted_type_index; + + inserted_type_index =nsim_dev_linecard_type_index (buf); +if (inserted_type_index ==-1 ) +return -EINVAL ; + +if (nsim_dev_linecard->inserted) +return -EBUSY ; + + err =nsim_dev_linecard_insert (nsim_dev_linecard, + inserted_type_index); +if (err) +return err; + }else { +nsim_dev_linecard_remove (nsim_dev_linecard); + } +return count; + +free_buf: +kfree (buf); +return ret; +} + +static const struct file_operations nsim_dev_linecard_inserted_type_fops = { + .open = simple_open, + .read = nsim_dev_linecard_inserted_type_read, + .write = nsim_dev_linecard_inserted_type_write, + .llseek = generic_file_llseek, + .owner =THIS_MODULE , +}; +static ssize_t nsim_dev_linecard_type_read (struct file *file,char __user *data,size_t count,loff_t *ppos) {
@@ -334,6 +464,8 @@ nsim_dev_linecard_debugfs_init(struct nsim_dev *nsim_dev,sprintf (dev_link_name,"../../../" DRV_NAME "%u" , nsim_dev->nsim_bus_dev->dev.id);debugfs_create_symlink ("dev" , nsim_dev_linecard->ddir, dev_link_name); +debugfs_create_file ("inserted_type" ,0600 , nsim_dev_linecard->ddir, + nsim_dev_linecard, &nsim_dev_linecard_inserted_type_fops);debugfs_create_file ("type" ,0400 , nsim_dev_linecard->ddir, nsim_dev_linecard, &nsim_dev_linecard_type_fops);
@@ -1110,6 +1242,8 @@ static void nsim_dev_linecard_provision_work(struct work_struct *work) nsim_dev_linecard->provisioned = true;devlink_linecard_provision_set (nsim_dev_linecard->devlink_linecard, nsim_dev_linecard->type_index); + +nsim_dev_linecard_activate (nsim_dev_linecard);return ; err_port_del_all:
@@ -1138,6 +1272,8 @@ static void nsim_dev_linecard_unprovision_work(struct work_struct *work) nsim_dev_linecard = container_of(work, struct nsim_dev_linecard, unprovision_work); +nsim_dev_linecard_deactivate (nsim_dev_linecard); + nsim_bus_dev = nsim_dev_linecard->nsim_dev->nsim_bus_dev; nsim_dev_linecard->provisioned = false;devlink_linecard_provision_clear (nsim_dev_linecard->devlink_linecard);
drivers/net/netdevsim/netdevsim.h +2 -0
@@ -203,6 +203,8 @@ struct nsim_dev_linecard {struct dentry *ddir;bool provisioned;u32 type_index; +bool inserted; +u32 inserted_type_index;struct work_struct provision_work;struct work_struct unprovision_work; };
Signature · 1 line
2.26.2
Jiri Pirko
maintainerRFC PATCH v2 10/10 selftests: add netdevsim devlink lc test
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Add test to verify netdevsim driver line card functionality.
---RFC->RFCv2:
- adjusted to "active"->"insert_type" activation conversion
--- .../drivers/net/netdevsim/devlink.sh | 62 ++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-)
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +60 -2
@@ -5,12 +5,13 @@ lib_dir=$(dirname $0)/../../../net/forwarding ALL_TESTS="fw_flash_test params_test regions_test reload_test \ netns_reload_test resource_test dev_info_test \ - empty_reporter_test dummy_reporter_test" + empty_reporter_test dummy_reporter_test linecard_test" NUM_NETIFS=0 source $lib_dir/lib.sh BUS_ADDR=10 PORT_COUNT=4 +LINECARD_COUNT=2 DEV_NAME=netdevsim$BUS_ADDR SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV_NAME/net/ DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV_NAME/
@@ -507,10 +508,67 @@ dummy_reporter_test() log_test "dummy reporter test" } +check_linecards_state() +{ + local expected_state_0=$1 + local expected_state_1=$2 + + local state=$(devlink lc show $DL_HANDLE lc 0 -j | jq -e -r ".[][][].state") + check_err $? "Failed to get linecard 0 state" + + [ "$state" == "$expected_state_0" ] + check_err $? "Unexpected linecard 0 state (got $state, expected $expected_state_0)" + + local state=$(devlink lc show $DL_HANDLE lc 1 -j | jq -e -r ".[][][].state") + check_err $? "Failed to get linecard 1 state" + + [ "$state" == "$expected_state_1" ] + check_err $? "Unexpected linecard 1 state (got $state, expected $expected_state_1)" +} + +linecard_test() +{ + RET=0 + + check_linecards_state "unprovisioned" "unprovisioned" + + devlink lc set $DL_HANDLE lc 0 type card2ports + check_err $? "Failed to provision linecard 0 with card2ports" + + check_linecards_state "provisioned" "unprovisioned" + + devlink lc set $DL_HANDLE lc 1 type card4ports + check_err $? "Failed to provision linecard 0 with card4ports" + + check_linecards_state "provisioned" "provisioned" + + echo "card2ports"> $DEBUGFS_DIR/linecards/0/inserted_type + check_err $? "Failed to insert linecard 0" + + check_linecards_state "active" "provisioned" + + echo "card4ports"> $DEBUGFS_DIR/linecards/1/inserted_type + check_err $? "Failed to insert linecard 1" + + check_linecards_state "active" "active" + + devlink lc set $DL_HANDLE lc 0 notype + check_err $? "Failed to unprovision linecard 0" + + check_linecards_state "unprovisioned" "active" + + devlink lc set $DL_HANDLE lc 1 notype + check_err $? "Failed to unprovision linecard 1" + + check_linecards_state "unprovisioned" "unprovisioned" + + log_test "linecard test" +} + setup_prepare() { modprobe netdevsim - echo "$BUS_ADDR $PORT_COUNT" > /sys/bus/netdevsim/new_device + echo "$BUS_ADDR $PORT_COUNT $LINECARD_COUNT" > /sys/bus/netdevsim/new_device while [ ! -d $SYSFS_NET_DIR ] ; do :; done }
Signature · 1 line
2.26.2