RE: [PATCH iproute2-next 3/5] devlink: Supporting add and delete of devlink port
From: Parav Pandit <hidden>
Date: 2021-02-01 20:43:41
From: David Ahern <redacted> Sent: Sunday, January 31, 2021 10:56 PM On 1/29/21 9:56 AM, Parav Pandit wrote:quoted
@@ -1383,6 +1389,37 @@ static int reload_limit_get(struct dl *dl, constchar *limitstr,quoted
return 0; } +static int port_flavour_parse(const char *flavour, uint16_t *value) { + if (!flavour) + return -EINVAL; + + if (strcmp(flavour, "physical") == 0) { + *value = DEVLINK_PORT_FLAVOUR_PHYSICAL; + return 0; + } else if (strcmp(flavour, "cpu") == 0) { + *value = DEVLINK_PORT_FLAVOUR_CPU; + return 0; + } else if (strcmp(flavour, "dsa") == 0) { + *value = DEVLINK_PORT_FLAVOUR_DSA; + return 0; + } else if (strcmp(flavour, "pcipf") == 0) { + *value = DEVLINK_PORT_FLAVOUR_PCI_PF; + return 0; + } else if (strcmp(flavour, "pcivf") == 0) { + *value = DEVLINK_PORT_FLAVOUR_PCI_VF; + return 0; + } else if (strcmp(flavour, "pcisf") == 0) { + *value = DEVLINK_PORT_FLAVOUR_PCI_SF; + return 0; + } else if (strcmp(flavour, "virtual") == 0) { + *value = DEVLINK_PORT_FLAVOUR_VIRTUAL; + return 0; + } else { + return -EINVAL; + } +}use a struct for the string - value conversions; that should have been done for port_flavour_name so it can be refactored to use that kind of relationship. This function is just the inverse of it.
Yep. Doing it in v2. Added utils routine for it. Few more functions will benefit from this helper routine post this series.