Message ID | 1690360493-8428-1-git-send-email-selvin.xavier@broadcom.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | IB/core: Add more speed parsing in ib_get_eth_speed() | expand |
On Wed, Jul 26, 2023 at 01:34:53AM -0700, Selvin Xavier wrote: > From: Kalesh AP <kalesh-anakkur.purayil@broadcom.com> > > The function ib_get_eth_speed() does not take consideration > of 50G, 56G, 100G and 200G speeds. Added these speeds parsing. > We are not considering the lane width now. This can be enhanced > later. > > Also, refactored the code to use switch case instead of if-else. > > Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com> > Signed-off-by: Selvin Xavier <selvin.xavier@broadcom.com> > --- > drivers/infiniband/core/verbs.c | 34 ++++++++++++++++++++++++++++------ > 1 file changed, 28 insertions(+), 6 deletions(-) > > diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c > index b99b3cc..ebd389a 100644 > --- a/drivers/infiniband/core/verbs.c > +++ b/drivers/infiniband/core/verbs.c > @@ -1908,22 +1908,44 @@ int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width) > netdev_speed); > } > > - if (netdev_speed <= SPEED_1000) { > + switch (netdev_speed) { > + case SPEED_1000: > *width = IB_WIDTH_1X; > *speed = IB_SPEED_SDR; > - } else if (netdev_speed <= SPEED_10000) { > + break; > + case SPEED_10000: This conversion is not equal to code before. We have more speeds between SPEED_1000 and SPEED_10000. include/uapi/linux/ethtool.h ... 1889 #define SPEED_1000 1000 1890 #define SPEED_2500 2500 1891 #define SPEED_5000 5000 1892 #define SPEED_10000 10000 Thanks > *width = IB_WIDTH_1X; > *speed = IB_SPEED_FDR10; > - } else if (netdev_speed <= SPEED_20000) { > + break; > + case SPEED_20000: > *width = IB_WIDTH_4X; > *speed = IB_SPEED_DDR; > - } else if (netdev_speed <= SPEED_25000) { > + break; > + case SPEED_25000: > *width = IB_WIDTH_1X; > *speed = IB_SPEED_EDR; > - } else if (netdev_speed <= SPEED_40000) { > + break; > + case SPEED_40000: > *width = IB_WIDTH_4X; > *speed = IB_SPEED_FDR10; > - } else { > + break; > + case SPEED_50000: > + *width = IB_WIDTH_2X; > + *speed = IB_SPEED_EDR; > + break; > + case SPEED_56000: > + *width = IB_WIDTH_4X; > + *speed = IB_SPEED_FDR; > + break; > + case SPEED_100000: > + *width = IB_WIDTH_4X; > + *speed = IB_SPEED_EDR; > + break; > + case SPEED_200000: > + *width = IB_WIDTH_4X; > + *speed = IB_SPEED_HDR; > + break; > + default: > *width = IB_WIDTH_4X; > *speed = IB_SPEED_EDR; > } > -- > 2.5.5 >
On Wed, Jul 26, 2023 at 6:37 PM Leon Romanovsky <leon@kernel.org> wrote: > > On Wed, Jul 26, 2023 at 01:34:53AM -0700, Selvin Xavier wrote: > > From: Kalesh AP <kalesh-anakkur.purayil@broadcom.com> > > > > The function ib_get_eth_speed() does not take consideration > > of 50G, 56G, 100G and 200G speeds. Added these speeds parsing. > > We are not considering the lane width now. This can be enhanced > > later. > > > > Also, refactored the code to use switch case instead of if-else. > > > > Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com> > > Signed-off-by: Selvin Xavier <selvin.xavier@broadcom.com> > > --- > > drivers/infiniband/core/verbs.c | 34 ++++++++++++++++++++++++++++------ > > 1 file changed, 28 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c > > index b99b3cc..ebd389a 100644 > > --- a/drivers/infiniband/core/verbs.c > > +++ b/drivers/infiniband/core/verbs.c > > @@ -1908,22 +1908,44 @@ int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width) > > netdev_speed); > > } > > > > - if (netdev_speed <= SPEED_1000) { > > + switch (netdev_speed) { > > + case SPEED_1000: > > *width = IB_WIDTH_1X; > > *speed = IB_SPEED_SDR; > > - } else if (netdev_speed <= SPEED_10000) { > > + break; > > + case SPEED_10000: > > This conversion is not equal to code before. We have more speeds between > SPEED_1000 and SPEED_10000. > > include/uapi/linux/ethtool.h > ... > 1889 #define SPEED_1000 1000 > 1890 #define SPEED_2500 2500 > 1891 #define SPEED_5000 5000 > 1892 #define SPEED_10000 10000 Sure. We will handle the two cases that are missing and spin a v2 patch. > > > Thanks > > > > > *width = IB_WIDTH_1X; > > *speed = IB_SPEED_FDR10; > > - } else if (netdev_speed <= SPEED_20000) { > > + break; > > + case SPEED_20000: > > *width = IB_WIDTH_4X; > > *speed = IB_SPEED_DDR; > > - } else if (netdev_speed <= SPEED_25000) { > > + break; > > + case SPEED_25000: > > *width = IB_WIDTH_1X; > > *speed = IB_SPEED_EDR; > > - } else if (netdev_speed <= SPEED_40000) { > > + break; > > + case SPEED_40000: > > *width = IB_WIDTH_4X; > > *speed = IB_SPEED_FDR10; > > - } else { > > + break; > > + case SPEED_50000: > > + *width = IB_WIDTH_2X; > > + *speed = IB_SPEED_EDR; > > + break; > > + case SPEED_56000: > > + *width = IB_WIDTH_4X; > > + *speed = IB_SPEED_FDR; > > + break; > > + case SPEED_100000: > > + *width = IB_WIDTH_4X; > > + *speed = IB_SPEED_EDR; > > + break; > > + case SPEED_200000: > > + *width = IB_WIDTH_4X; > > + *speed = IB_SPEED_HDR; > > + break; > > + default: > > *width = IB_WIDTH_4X; > > *speed = IB_SPEED_EDR; > > } > > -- > > 2.5.5 > > > >
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index b99b3cc..ebd389a 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -1908,22 +1908,44 @@ int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width) netdev_speed); } - if (netdev_speed <= SPEED_1000) { + switch (netdev_speed) { + case SPEED_1000: *width = IB_WIDTH_1X; *speed = IB_SPEED_SDR; - } else if (netdev_speed <= SPEED_10000) { + break; + case SPEED_10000: *width = IB_WIDTH_1X; *speed = IB_SPEED_FDR10; - } else if (netdev_speed <= SPEED_20000) { + break; + case SPEED_20000: *width = IB_WIDTH_4X; *speed = IB_SPEED_DDR; - } else if (netdev_speed <= SPEED_25000) { + break; + case SPEED_25000: *width = IB_WIDTH_1X; *speed = IB_SPEED_EDR; - } else if (netdev_speed <= SPEED_40000) { + break; + case SPEED_40000: *width = IB_WIDTH_4X; *speed = IB_SPEED_FDR10; - } else { + break; + case SPEED_50000: + *width = IB_WIDTH_2X; + *speed = IB_SPEED_EDR; + break; + case SPEED_56000: + *width = IB_WIDTH_4X; + *speed = IB_SPEED_FDR; + break; + case SPEED_100000: + *width = IB_WIDTH_4X; + *speed = IB_SPEED_EDR; + break; + case SPEED_200000: + *width = IB_WIDTH_4X; + *speed = IB_SPEED_HDR; + break; + default: *width = IB_WIDTH_4X; *speed = IB_SPEED_EDR; }