Skip to content

Commit

Permalink
common/mlx5: fix controller index parsing
Browse files Browse the repository at this point in the history
[ upstream commit 3cd5e500b5cb1b72ee182be4043018f22a5f8a3b ]

When probing the Linux kernel network interfaces attached to E-Switch,
mlx5 PMD decides the representor type and represented entity
using phys_port_name exposed by the mlx5 kernel driver in sysfs.
mlx5 PMD first checks this name for multihost controller index.
In multihost scenarios, phys_port_name is prefixed with "c[0-9]+" string.
Included integer is the controller index.

Assuming that phys_port_name contains a string representing a physical
port, i.e. "p[0-9]+" string, the parsing logic is incorrect.
Both "p[0-9]+" and "c[0-9]+" match the formatting string used to parse
phys_port_name, but controller index is still filled out.

This patch fixes this behavior by storing the parsed index
in a temporary variable and setting controller index
if and only if phys_port_name matches multihost controller syntax.

Fixes: 59df97f ("common/mlx5: support sub-function representor parsing")

Signed-off-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
  • Loading branch information
sodar authored and kevintraynor committed Nov 16, 2023
1 parent 986d9d2 commit 981460d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/common/mlx5/linux/mlx5_common_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ mlx5_translate_port_name(const char *port_name_in,
char ctrl = 0, pf_c1, pf_c2, vf_c1, vf_c2, eol;
char *end;
int sc_items;
int32_t ctrl_num = -1;

sc_items = sscanf(port_name_in, "%c%d",
&ctrl, &port_info_out->ctrl_num);
sc_items = sscanf(port_name_in, "%c%d", &ctrl, &ctrl_num);
if (sc_items == 2 && ctrl == 'c') {
port_info_out->ctrl_num = ctrl_num;
port_name_in++; /* 'c' */
port_name_in += snprintf(NULL, 0, "%d",
port_info_out->ctrl_num);
Expand Down

0 comments on commit 981460d

Please sign in to comment.