diff mbox series

[v7,2/5] IB/rxe: Reuse code which sets port state

Message ID 8ee7efc93c47cb6186834d4e17196238223cd2e6.1544826079.git.swise@opengridcomputing.com (mailing list archive)
State Superseded
Delegated to: Jason Gunthorpe
Headers show
Series Dynamic rdma link creation | expand

Commit Message

Yuval Shaia Dec. 14, 2018, 4:05 p.m. UTC
Same code is executed in both rxe_param_set_add and rxe_notify functions.
Make one function and call it from both places.

Note that the code that checks validity of rxe object is omitted since
both callers already make sure it is valid.

Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com> 
Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com>
---
 drivers/infiniband/sw/rxe/rxe.h       |  1 +
 drivers/infiniband/sw/rxe/rxe_net.c   | 13 +++++++++----
 drivers/infiniband/sw/rxe/rxe_sysfs.c | 12 +-----------
 3 files changed, 11 insertions(+), 15 deletions(-)

Comments

Jason Gunthorpe Dec. 20, 2018, 9:30 p.m. UTC | #1
On Fri, Dec 14, 2018 at 08:05:49AM -0800, Yuval Shaia wrote:
> Same code is executed in both rxe_param_set_add and rxe_notify functions.
> Make one function and call it from both places.
> 
> Note that the code that checks validity of rxe object is omitted since
> both callers already make sure it is valid.
> 
> Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
> Reviewed-by: Steve Wise <swise@opengridcomputing.com> 
> Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com>
> ---
>  drivers/infiniband/sw/rxe/rxe.h       |  1 +
>  drivers/infiniband/sw/rxe/rxe_net.c   | 13 +++++++++----
>  drivers/infiniband/sw/rxe/rxe_sysfs.c | 12 +-----------
>  3 files changed, 11 insertions(+), 15 deletions(-)

I rebased and edited this a bit - there is no reason to pass a net
and a rxe into the function, rxe->ndev is fine.

Applied to for-next

Thanks,
Jason
diff mbox series

Patch

diff --git a/drivers/infiniband/sw/rxe/rxe.h b/drivers/infiniband/sw/rxe/rxe.h
index 75e7113a756d..4ff33d921865 100644
--- a/drivers/infiniband/sw/rxe/rxe.h
+++ b/drivers/infiniband/sw/rxe/rxe.h
@@ -112,5 +112,6 @@  static inline struct rxe_dev *rxe_get_dev_from_net(struct net_device *ndev)
 
 void rxe_port_up(struct rxe_dev *rxe);
 void rxe_port_down(struct rxe_dev *rxe);
+void rxe_set_port_state(struct net_device *ndev, struct rxe_dev *rxe);
 
 #endif /* RXE_H */
diff --git a/drivers/infiniband/sw/rxe/rxe_net.c b/drivers/infiniband/sw/rxe/rxe_net.c
index c7637ad5e584..6a25b514d448 100644
--- a/drivers/infiniband/sw/rxe/rxe_net.c
+++ b/drivers/infiniband/sw/rxe/rxe_net.c
@@ -577,6 +577,14 @@  void rxe_port_down(struct rxe_dev *rxe)
 	dev_info(&rxe->ib_dev.dev, "set down\n");
 }
 
+void rxe_set_port_state(struct net_device *ndev, struct rxe_dev *rxe)
+{
+	if (netif_running(ndev) && netif_carrier_ok(ndev))
+		rxe_port_up(rxe);
+	else
+		rxe_port_down(rxe);
+}
+
 static int rxe_notify(struct notifier_block *not_blk,
 		      unsigned long event,
 		      void *arg)
@@ -603,10 +611,7 @@  static int rxe_notify(struct notifier_block *not_blk,
 		rxe_set_mtu(rxe, ndev->mtu);
 		break;
 	case NETDEV_CHANGE:
-		if (netif_running(ndev) && netif_carrier_ok(ndev))
-			rxe_port_up(rxe);
-		else
-			rxe_port_down(rxe);
+		rxe_set_port_state(ndev, rxe);
 		break;
 	case NETDEV_REBOOT:
 	case NETDEV_GOING_DOWN:
diff --git a/drivers/infiniband/sw/rxe/rxe_sysfs.c b/drivers/infiniband/sw/rxe/rxe_sysfs.c
index 87c17675cf9d..de9f51056f52 100644
--- a/drivers/infiniband/sw/rxe/rxe_sysfs.c
+++ b/drivers/infiniband/sw/rxe/rxe_sysfs.c
@@ -53,16 +53,6 @@  static int sanitize_arg(const char *val, char *intf, int intf_len)
 	return len;
 }
 
-static void rxe_set_port_state(struct rxe_dev *rxe, struct net_device *ndev)
-{
-	bool is_up = netif_running(ndev) && netif_carrier_ok(ndev);
-
-	if (is_up)
-		rxe_port_up(rxe);
-	else
-		rxe_port_down(rxe); /* down for unknown state */
-}
-
 static int rxe_param_set_add(const char *val, const struct kernel_param *kp)
 {
 	int len;
@@ -99,7 +89,7 @@  static int rxe_param_set_add(const char *val, const struct kernel_param *kp)
 		goto err;
 	}
 
-	rxe_set_port_state(rxe, ndev);
+	rxe_set_port_state(ndev, rxe);
 	dev_info(&rxe->ib_dev.dev, "added %s\n", intf);
 
 err: