Commit ff25dcb9 authored by Thomas Falcon's avatar Thomas Falcon Committed by David S. Miller

ibmvnic: Serialize device queries

Provide some serialization for device CRQ commands
and queries to ensure that the shared variable used for
storing return codes is properly synchronized.
Signed-off-by: default avatarThomas Falcon <tlfalcon@linux.ibm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 476d96ca
...@@ -210,11 +210,14 @@ static int alloc_long_term_buff(struct ibmvnic_adapter *adapter, ...@@ -210,11 +210,14 @@ static int alloc_long_term_buff(struct ibmvnic_adapter *adapter,
ltb->map_id = adapter->map_id; ltb->map_id = adapter->map_id;
adapter->map_id++; adapter->map_id++;
mutex_lock(&adapter->fw_lock);
adapter->fw_done_rc = 0;
reinit_completion(&adapter->fw_done); reinit_completion(&adapter->fw_done);
rc = send_request_map(adapter, ltb->addr, rc = send_request_map(adapter, ltb->addr,
ltb->size, ltb->map_id); ltb->size, ltb->map_id);
if (rc) { if (rc) {
dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr); dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
mutex_unlock(&adapter->fw_lock);
return rc; return rc;
} }
...@@ -224,6 +227,7 @@ static int alloc_long_term_buff(struct ibmvnic_adapter *adapter, ...@@ -224,6 +227,7 @@ static int alloc_long_term_buff(struct ibmvnic_adapter *adapter,
"Long term map request aborted or timed out,rc = %d\n", "Long term map request aborted or timed out,rc = %d\n",
rc); rc);
dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr); dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
mutex_unlock(&adapter->fw_lock);
return rc; return rc;
} }
...@@ -231,8 +235,10 @@ static int alloc_long_term_buff(struct ibmvnic_adapter *adapter, ...@@ -231,8 +235,10 @@ static int alloc_long_term_buff(struct ibmvnic_adapter *adapter,
dev_err(dev, "Couldn't map long term buffer,rc = %d\n", dev_err(dev, "Couldn't map long term buffer,rc = %d\n",
adapter->fw_done_rc); adapter->fw_done_rc);
dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr); dma_free_coherent(dev, ltb->size, ltb->buff, ltb->addr);
mutex_unlock(&adapter->fw_lock);
return -1; return -1;
} }
mutex_unlock(&adapter->fw_lock);
return 0; return 0;
} }
...@@ -258,15 +264,21 @@ static int reset_long_term_buff(struct ibmvnic_adapter *adapter, ...@@ -258,15 +264,21 @@ static int reset_long_term_buff(struct ibmvnic_adapter *adapter,
memset(ltb->buff, 0, ltb->size); memset(ltb->buff, 0, ltb->size);
mutex_lock(&adapter->fw_lock);
adapter->fw_done_rc = 0;
reinit_completion(&adapter->fw_done); reinit_completion(&adapter->fw_done);
rc = send_request_map(adapter, ltb->addr, ltb->size, ltb->map_id); rc = send_request_map(adapter, ltb->addr, ltb->size, ltb->map_id);
if (rc) if (rc) {
mutex_unlock(&adapter->fw_lock);
return rc; return rc;
}
rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000);
if (rc) { if (rc) {
dev_info(dev, dev_info(dev,
"Reset failed, long term map request timed out or aborted\n"); "Reset failed, long term map request timed out or aborted\n");
mutex_unlock(&adapter->fw_lock);
return rc; return rc;
} }
...@@ -274,8 +286,10 @@ static int reset_long_term_buff(struct ibmvnic_adapter *adapter, ...@@ -274,8 +286,10 @@ static int reset_long_term_buff(struct ibmvnic_adapter *adapter,
dev_info(dev, dev_info(dev,
"Reset failed, attempting to free and reallocate buffer\n"); "Reset failed, attempting to free and reallocate buffer\n");
free_long_term_buff(adapter, ltb); free_long_term_buff(adapter, ltb);
mutex_unlock(&adapter->fw_lock);
return alloc_long_term_buff(adapter, ltb, ltb->size); return alloc_long_term_buff(adapter, ltb, ltb->size);
} }
mutex_unlock(&adapter->fw_lock);
return 0; return 0;
} }
...@@ -992,18 +1006,25 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter) ...@@ -992,18 +1006,25 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter)
if (adapter->vpd->buff) if (adapter->vpd->buff)
len = adapter->vpd->len; len = adapter->vpd->len;
mutex_lock(&adapter->fw_lock);
adapter->fw_done_rc = 0;
reinit_completion(&adapter->fw_done); reinit_completion(&adapter->fw_done);
crq.get_vpd_size.first = IBMVNIC_CRQ_CMD; crq.get_vpd_size.first = IBMVNIC_CRQ_CMD;
crq.get_vpd_size.cmd = GET_VPD_SIZE; crq.get_vpd_size.cmd = GET_VPD_SIZE;
rc = ibmvnic_send_crq(adapter, &crq); rc = ibmvnic_send_crq(adapter, &crq);
if (rc) if (rc) {
mutex_unlock(&adapter->fw_lock);
return rc; return rc;
}
rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000);
if (rc) { if (rc) {
dev_err(dev, "Could not retrieve VPD size, rc = %d\n", rc); dev_err(dev, "Could not retrieve VPD size, rc = %d\n", rc);
mutex_unlock(&adapter->fw_lock);
return rc; return rc;
} }
mutex_unlock(&adapter->fw_lock);
if (!adapter->vpd->len) if (!adapter->vpd->len)
return -ENODATA; return -ENODATA;
...@@ -1030,7 +1051,10 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter) ...@@ -1030,7 +1051,10 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter)
return -ENOMEM; return -ENOMEM;
} }
mutex_lock(&adapter->fw_lock);
adapter->fw_done_rc = 0;
reinit_completion(&adapter->fw_done); reinit_completion(&adapter->fw_done);
crq.get_vpd.first = IBMVNIC_CRQ_CMD; crq.get_vpd.first = IBMVNIC_CRQ_CMD;
crq.get_vpd.cmd = GET_VPD; crq.get_vpd.cmd = GET_VPD;
crq.get_vpd.ioba = cpu_to_be32(adapter->vpd->dma_addr); crq.get_vpd.ioba = cpu_to_be32(adapter->vpd->dma_addr);
...@@ -1039,6 +1063,7 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter) ...@@ -1039,6 +1063,7 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter)
if (rc) { if (rc) {
kfree(adapter->vpd->buff); kfree(adapter->vpd->buff);
adapter->vpd->buff = NULL; adapter->vpd->buff = NULL;
mutex_unlock(&adapter->fw_lock);
return rc; return rc;
} }
...@@ -1047,9 +1072,11 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter) ...@@ -1047,9 +1072,11 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter)
dev_err(dev, "Unable to retrieve VPD, rc = %d\n", rc); dev_err(dev, "Unable to retrieve VPD, rc = %d\n", rc);
kfree(adapter->vpd->buff); kfree(adapter->vpd->buff);
adapter->vpd->buff = NULL; adapter->vpd->buff = NULL;
mutex_unlock(&adapter->fw_lock);
return rc; return rc;
} }
mutex_unlock(&adapter->fw_lock);
return 0; return 0;
} }
...@@ -1750,10 +1777,14 @@ static int __ibmvnic_set_mac(struct net_device *netdev, u8 *dev_addr) ...@@ -1750,10 +1777,14 @@ static int __ibmvnic_set_mac(struct net_device *netdev, u8 *dev_addr)
crq.change_mac_addr.cmd = CHANGE_MAC_ADDR; crq.change_mac_addr.cmd = CHANGE_MAC_ADDR;
ether_addr_copy(&crq.change_mac_addr.mac_addr[0], dev_addr); ether_addr_copy(&crq.change_mac_addr.mac_addr[0], dev_addr);
mutex_lock(&adapter->fw_lock);
adapter->fw_done_rc = 0;
reinit_completion(&adapter->fw_done); reinit_completion(&adapter->fw_done);
rc = ibmvnic_send_crq(adapter, &crq); rc = ibmvnic_send_crq(adapter, &crq);
if (rc) { if (rc) {
rc = -EIO; rc = -EIO;
mutex_unlock(&adapter->fw_lock);
goto err; goto err;
} }
...@@ -1761,9 +1792,10 @@ static int __ibmvnic_set_mac(struct net_device *netdev, u8 *dev_addr) ...@@ -1761,9 +1792,10 @@ static int __ibmvnic_set_mac(struct net_device *netdev, u8 *dev_addr)
/* netdev->dev_addr is changed in handle_change_mac_rsp function */ /* netdev->dev_addr is changed in handle_change_mac_rsp function */
if (rc || adapter->fw_done_rc) { if (rc || adapter->fw_done_rc) {
rc = -EIO; rc = -EIO;
mutex_unlock(&adapter->fw_lock);
goto err; goto err;
} }
mutex_unlock(&adapter->fw_lock);
return 0; return 0;
err: err:
ether_addr_copy(adapter->mac_addr, netdev->dev_addr); ether_addr_copy(adapter->mac_addr, netdev->dev_addr);
...@@ -4486,15 +4518,24 @@ static int send_query_phys_parms(struct ibmvnic_adapter *adapter) ...@@ -4486,15 +4518,24 @@ static int send_query_phys_parms(struct ibmvnic_adapter *adapter)
memset(&crq, 0, sizeof(crq)); memset(&crq, 0, sizeof(crq));
crq.query_phys_parms.first = IBMVNIC_CRQ_CMD; crq.query_phys_parms.first = IBMVNIC_CRQ_CMD;
crq.query_phys_parms.cmd = QUERY_PHYS_PARMS; crq.query_phys_parms.cmd = QUERY_PHYS_PARMS;
mutex_lock(&adapter->fw_lock);
adapter->fw_done_rc = 0;
reinit_completion(&adapter->fw_done); reinit_completion(&adapter->fw_done);
rc = ibmvnic_send_crq(adapter, &crq); rc = ibmvnic_send_crq(adapter, &crq);
if (rc) if (rc) {
mutex_unlock(&adapter->fw_lock);
return rc; return rc;
}
rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000); rc = ibmvnic_wait_for_completion(adapter, &adapter->fw_done, 10000);
if (rc) if (rc) {
mutex_unlock(&adapter->fw_lock);
return rc; return rc;
}
mutex_unlock(&adapter->fw_lock);
return adapter->fw_done_rc ? -EIO : 0; return adapter->fw_done_rc ? -EIO : 0;
} }
...@@ -5050,6 +5091,7 @@ static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id) ...@@ -5050,6 +5091,7 @@ static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
__ibmvnic_delayed_reset); __ibmvnic_delayed_reset);
INIT_LIST_HEAD(&adapter->rwi_list); INIT_LIST_HEAD(&adapter->rwi_list);
spin_lock_init(&adapter->rwi_lock); spin_lock_init(&adapter->rwi_lock);
mutex_init(&adapter->fw_lock);
init_completion(&adapter->init_done); init_completion(&adapter->init_done);
init_completion(&adapter->fw_done); init_completion(&adapter->fw_done);
init_completion(&adapter->reset_done); init_completion(&adapter->reset_done);
...@@ -5111,6 +5153,7 @@ static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id) ...@@ -5111,6 +5153,7 @@ static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
ibmvnic_init_fail: ibmvnic_init_fail:
release_sub_crqs(adapter, 1); release_sub_crqs(adapter, 1);
release_crq_queue(adapter); release_crq_queue(adapter);
mutex_destroy(&adapter->fw_lock);
free_netdev(netdev); free_netdev(netdev);
return rc; return rc;
...@@ -5135,6 +5178,7 @@ static int ibmvnic_remove(struct vio_dev *dev) ...@@ -5135,6 +5178,7 @@ static int ibmvnic_remove(struct vio_dev *dev)
adapter->state = VNIC_REMOVED; adapter->state = VNIC_REMOVED;
rtnl_unlock(); rtnl_unlock();
mutex_destroy(&adapter->fw_lock);
device_remove_file(&dev->dev, &dev_attr_failover); device_remove_file(&dev->dev, &dev_attr_failover);
free_netdev(netdev); free_netdev(netdev);
dev_set_drvdata(&dev->dev, NULL); dev_set_drvdata(&dev->dev, NULL);
......
...@@ -1026,6 +1026,8 @@ struct ibmvnic_adapter { ...@@ -1026,6 +1026,8 @@ struct ibmvnic_adapter {
int init_done_rc; int init_done_rc;
struct completion fw_done; struct completion fw_done;
/* Used for serialization of device commands */
struct mutex fw_lock;
int fw_done_rc; int fw_done_rc;
struct completion reset_done; struct completion reset_done;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment