ibmvnic: Create separate initialization routine for resets
authorThomas Falcon <tlfalcon@linux.vnet.ibm.com>
Wed, 23 May 2018 18:38:00 +0000 (13:38 -0500)
committerDavid S. Miller <davem@davemloft.net>
Fri, 25 May 2018 02:19:26 +0000 (22:19 -0400)
Instead of having one initialization routine for all cases, create
a separate, simpler function for standard initialization, such as during
device probe. Use the original initialization function to handle
device reset scenarios. The goal of this patch is to avoid having
a single, cluttered init function to handle all possible
scenarios.

Signed-off-by: Thomas Falcon <tlfalcon@linux.vnet.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/ibm/ibmvnic.c

index b1bbd5bcc129c62e6f1610be4483166f9be2408a..f26e1f893441c27328b77c48c04580d77c1867dc 100644 (file)
@@ -116,6 +116,7 @@ static void send_cap_queries(struct ibmvnic_adapter *adapter);
 static int init_sub_crqs(struct ibmvnic_adapter *);
 static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter);
 static int ibmvnic_init(struct ibmvnic_adapter *);
+static int ibmvnic_reset_init(struct ibmvnic_adapter *);
 static void release_crq_queue(struct ibmvnic_adapter *);
 static int __ibmvnic_set_mac(struct net_device *netdev, struct sockaddr *p);
 static int init_crq_queue(struct ibmvnic_adapter *adapter);
@@ -1807,7 +1808,7 @@ static int do_reset(struct ibmvnic_adapter *adapter,
                        return rc;
                }
 
-               rc = ibmvnic_init(adapter);
+               rc = ibmvnic_reset_init(adapter);
                if (rc)
                        return IBMVNIC_INIT_FAILED;
 
@@ -4571,7 +4572,7 @@ map_failed:
        return retrc;
 }
 
-static int ibmvnic_init(struct ibmvnic_adapter *adapter)
+static int ibmvnic_reset_init(struct ibmvnic_adapter *adapter)
 {
        struct device *dev = &adapter->vdev->dev;
        unsigned long timeout = msecs_to_jiffies(30000);
@@ -4630,6 +4631,49 @@ static int ibmvnic_init(struct ibmvnic_adapter *adapter)
        return rc;
 }
 
+static int ibmvnic_init(struct ibmvnic_adapter *adapter)
+{
+       struct device *dev = &adapter->vdev->dev;
+       unsigned long timeout = msecs_to_jiffies(30000);
+       int rc;
+
+       adapter->from_passive_init = false;
+
+       init_completion(&adapter->init_done);
+       adapter->init_done_rc = 0;
+       ibmvnic_send_crq_init(adapter);
+       if (!wait_for_completion_timeout(&adapter->init_done, timeout)) {
+               dev_err(dev, "Initialization sequence timed out\n");
+               return -1;
+       }
+
+       if (adapter->init_done_rc) {
+               release_crq_queue(adapter);
+               return adapter->init_done_rc;
+       }
+
+       if (adapter->from_passive_init) {
+               adapter->state = VNIC_OPEN;
+               adapter->from_passive_init = false;
+               return -1;
+       }
+
+       rc = init_sub_crqs(adapter);
+       if (rc) {
+               dev_err(dev, "Initialization of sub crqs failed\n");
+               release_crq_queue(adapter);
+               return rc;
+       }
+
+       rc = init_sub_crq_irqs(adapter);
+       if (rc) {
+               dev_err(dev, "Failed to initialize sub crq irqs\n");
+               release_crq_queue(adapter);
+       }
+
+       return rc;
+}
+
 static struct device_attribute dev_attr_failover;
 
 static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)