提交 d3f4aadd 编写于 作者: A Amrani, Ram 提交者: Doug Ledford

RDMA/core: Add the function ib_mtu_int_to_enum

As the functionality to convert the MTU from a number to enum_ib_mtu
is ubiquitous, define a dedicated function and remove the duplicated
code.
Signed-off-by: NRam Amrani <Ram.Amrani@cavium.com>
Reviewed-by: NLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: NDoug Ledford <dledford@redhat.com>
上级 ff89b070
...@@ -1135,16 +1135,7 @@ static int iwch_query_port(struct ib_device *ibdev, ...@@ -1135,16 +1135,7 @@ static int iwch_query_port(struct ib_device *ibdev,
memset(props, 0, sizeof(struct ib_port_attr)); memset(props, 0, sizeof(struct ib_port_attr));
props->max_mtu = IB_MTU_4096; props->max_mtu = IB_MTU_4096;
if (netdev->mtu >= 4096) props->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
props->active_mtu = IB_MTU_4096;
else if (netdev->mtu >= 2048)
props->active_mtu = IB_MTU_2048;
else if (netdev->mtu >= 1024)
props->active_mtu = IB_MTU_1024;
else if (netdev->mtu >= 512)
props->active_mtu = IB_MTU_512;
else
props->active_mtu = IB_MTU_256;
if (!netif_carrier_ok(netdev)) if (!netif_carrier_ok(netdev))
props->state = IB_PORT_DOWN; props->state = IB_PORT_DOWN;
......
...@@ -373,16 +373,7 @@ static int c4iw_query_port(struct ib_device *ibdev, u8 port, ...@@ -373,16 +373,7 @@ static int c4iw_query_port(struct ib_device *ibdev, u8 port,
memset(props, 0, sizeof(struct ib_port_attr)); memset(props, 0, sizeof(struct ib_port_attr));
props->max_mtu = IB_MTU_4096; props->max_mtu = IB_MTU_4096;
if (netdev->mtu >= 4096) props->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
props->active_mtu = IB_MTU_4096;
else if (netdev->mtu >= 2048)
props->active_mtu = IB_MTU_2048;
else if (netdev->mtu >= 1024)
props->active_mtu = IB_MTU_1024;
else if (netdev->mtu >= 512)
props->active_mtu = IB_MTU_512;
else
props->active_mtu = IB_MTU_256;
if (!netif_carrier_ok(netdev)) if (!netif_carrier_ok(netdev))
props->state = IB_PORT_DOWN; props->state = IB_PORT_DOWN;
......
...@@ -100,16 +100,7 @@ static int i40iw_query_port(struct ib_device *ibdev, ...@@ -100,16 +100,7 @@ static int i40iw_query_port(struct ib_device *ibdev,
memset(props, 0, sizeof(*props)); memset(props, 0, sizeof(*props));
props->max_mtu = IB_MTU_4096; props->max_mtu = IB_MTU_4096;
if (netdev->mtu >= 4096) props->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
props->active_mtu = IB_MTU_4096;
else if (netdev->mtu >= 2048)
props->active_mtu = IB_MTU_2048;
else if (netdev->mtu >= 1024)
props->active_mtu = IB_MTU_1024;
else if (netdev->mtu >= 512)
props->active_mtu = IB_MTU_512;
else
props->active_mtu = IB_MTU_256;
props->lid = 1; props->lid = 1;
if (netif_carrier_ok(iwdev->netdev)) if (netif_carrier_ok(iwdev->netdev))
......
...@@ -478,17 +478,7 @@ static int nes_query_port(struct ib_device *ibdev, u8 port, struct ib_port_attr ...@@ -478,17 +478,7 @@ static int nes_query_port(struct ib_device *ibdev, u8 port, struct ib_port_attr
memset(props, 0, sizeof(*props)); memset(props, 0, sizeof(*props));
props->max_mtu = IB_MTU_4096; props->max_mtu = IB_MTU_4096;
props->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
if (netdev->mtu >= 4096)
props->active_mtu = IB_MTU_4096;
else if (netdev->mtu >= 2048)
props->active_mtu = IB_MTU_2048;
else if (netdev->mtu >= 1024)
props->active_mtu = IB_MTU_1024;
else if (netdev->mtu >= 512)
props->active_mtu = IB_MTU_512;
else
props->active_mtu = IB_MTU_256;
props->lid = 1; props->lid = 1;
props->lmc = 0; props->lmc = 0;
......
...@@ -352,6 +352,20 @@ static inline int ib_mtu_enum_to_int(enum ib_mtu mtu) ...@@ -352,6 +352,20 @@ static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
} }
} }
static inline enum ib_mtu ib_mtu_int_to_enum(int mtu)
{
if (mtu >= 4096)
return IB_MTU_4096;
else if (mtu >= 2048)
return IB_MTU_2048;
else if (mtu >= 1024)
return IB_MTU_1024;
else if (mtu >= 512)
return IB_MTU_512;
else
return IB_MTU_256;
}
enum ib_port_state { enum ib_port_state {
IB_PORT_NOP = 0, IB_PORT_NOP = 0,
IB_PORT_DOWN = 1, IB_PORT_DOWN = 1,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册