From 37e40fa8f62ba33021cb0050e38f87d7519ee447 Mon Sep 17 00:00:00 2001 From: Thomas Falcon Date: Fri, 6 Apr 2018 18:37:02 -0500 Subject: [PATCH 1/5] ibmvnic: Fix DMA mapping mistakes Fix some mistakes caught by the DMA debugger. The first change fixes a unnecessary unmap that should have been removed in an earlier update. The next hunk fixes another bad unmap by zeroing the bit checked to determine that an unmap is needed. The final change fixes some buffers that are unmapped with the wrong direction specified. Signed-off-by: Thomas Falcon Signed-off-by: David S. Miller --- drivers/net/ethernet/ibm/ibmvnic.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c index b492af6affc3..58e01432c2aa 100644 --- a/drivers/net/ethernet/ibm/ibmvnic.c +++ b/drivers/net/ethernet/ibm/ibmvnic.c @@ -320,9 +320,6 @@ failure: dev_info(dev, "replenish pools failure\n"); pool->free_map[pool->next_free] = index; pool->rx_buff[index].skb = NULL; - if (!dma_mapping_error(dev, dma_addr)) - dma_unmap_single(dev, dma_addr, pool->buff_size, - DMA_FROM_DEVICE); dev_kfree_skb_any(skb); adapter->replenish_add_buff_failure++; @@ -2574,7 +2571,7 @@ static int ibmvnic_complete_tx(struct ibmvnic_adapter *adapter, union sub_crq *next; int index; int i, j; - u8 first; + u8 *first; restart_loop: while (pending_scrq(adapter, scrq)) { @@ -2605,11 +2602,12 @@ restart_loop: txbuff->data_dma[j] = 0; } /* if sub_crq was sent indirectly */ - first = txbuff->indir_arr[0].generic.first; - if (first == IBMVNIC_CRQ_CMD) { + first = &txbuff->indir_arr[0].generic.first; + if (*first == IBMVNIC_CRQ_CMD) { dma_unmap_single(dev, txbuff->indir_dma, sizeof(txbuff->indir_arr), DMA_TO_DEVICE); + *first = 0; } if (txbuff->last_frag) { @@ -3882,9 +3880,9 @@ static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq, int i; dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz, - DMA_BIDIRECTIONAL); + DMA_TO_DEVICE); dma_unmap_single(dev, adapter->login_rsp_buf_token, - adapter->login_rsp_buf_sz, DMA_BIDIRECTIONAL); + adapter->login_rsp_buf_sz, DMA_FROM_DEVICE); /* If the number of queues requested can't be allocated by the * server, the login response will return with code 1. We will need From 41f714672f93608751dbd2fa2291d476a8ff0150 Mon Sep 17 00:00:00 2001 From: Thomas Falcon Date: Fri, 6 Apr 2018 18:37:03 -0500 Subject: [PATCH 2/5] ibmvnic: Zero used TX descriptor counter on reset The counter that tracks used TX descriptors pending completion needs to be zeroed as part of a device reset. This change fixes a bug causing transmit queues to be stopped unnecessarily and in some cases a transmit queue stall and timeout reset. If the counter is not reset, the remaining descriptors will not be "removed", effectively reducing queue capacity. If the queue is over half full, it will cause the queue to stall if stopped. Signed-off-by: Thomas Falcon Signed-off-by: David S. Miller --- drivers/net/ethernet/ibm/ibmvnic.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c index 58e01432c2aa..153a868c5135 100644 --- a/drivers/net/ethernet/ibm/ibmvnic.c +++ b/drivers/net/ethernet/ibm/ibmvnic.c @@ -2361,6 +2361,7 @@ static int reset_one_sub_crq_queue(struct ibmvnic_adapter *adapter, } memset(scrq->msgs, 0, 4 * PAGE_SIZE); + atomic_set(&scrq->used, 0); scrq->cur = 0; rc = h_reg_sub_crq(adapter->vdev->unit_address, scrq->msg_token, From af894d239840908dfebb2215e13a713e63d2ffb0 Mon Sep 17 00:00:00 2001 From: Thomas Falcon Date: Fri, 6 Apr 2018 18:37:04 -0500 Subject: [PATCH 3/5] ibmvnic: Fix reset scheduler error handling In some cases, if the driver is waiting for a reset following a device parameter change, failure to schedule a reset can result in a hang since a completion signal is never sent. If the device configuration is being altered by a tool such as ethtool or ifconfig, it could cause the console to hang if the reset request does not get scheduled. Add some additional error handling code to exit the wait_for_completion if there is one in progress. Signed-off-by: Thomas Falcon Signed-off-by: David S. Miller --- drivers/net/ethernet/ibm/ibmvnic.c | 39 ++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c index 153a868c5135..bbcd07a02694 100644 --- a/drivers/net/ethernet/ibm/ibmvnic.c +++ b/drivers/net/ethernet/ibm/ibmvnic.c @@ -1875,23 +1875,25 @@ static void __ibmvnic_reset(struct work_struct *work) mutex_unlock(&adapter->reset_lock); } -static void ibmvnic_reset(struct ibmvnic_adapter *adapter, - enum ibmvnic_reset_reason reason) +static int ibmvnic_reset(struct ibmvnic_adapter *adapter, + enum ibmvnic_reset_reason reason) { struct ibmvnic_rwi *rwi, *tmp; struct net_device *netdev = adapter->netdev; struct list_head *entry; + int ret; if (adapter->state == VNIC_REMOVING || adapter->state == VNIC_REMOVED) { + ret = EBUSY; netdev_dbg(netdev, "Adapter removing, skipping reset\n"); - return; + goto err; } if (adapter->state == VNIC_PROBING) { netdev_warn(netdev, "Adapter reset during probe\n"); - adapter->init_done_rc = EAGAIN; - return; + ret = adapter->init_done_rc = EAGAIN; + goto err; } mutex_lock(&adapter->rwi_lock); @@ -1901,7 +1903,8 @@ static void ibmvnic_reset(struct ibmvnic_adapter *adapter, if (tmp->reset_reason == reason) { netdev_dbg(netdev, "Skipping matching reset\n"); mutex_unlock(&adapter->rwi_lock); - return; + ret = EBUSY; + goto err; } } @@ -1909,7 +1912,8 @@ static void ibmvnic_reset(struct ibmvnic_adapter *adapter, if (!rwi) { mutex_unlock(&adapter->rwi_lock); ibmvnic_close(netdev); - return; + ret = ENOMEM; + goto err; } rwi->reset_reason = reason; @@ -1918,6 +1922,12 @@ static void ibmvnic_reset(struct ibmvnic_adapter *adapter, netdev_dbg(adapter->netdev, "Scheduling reset (reason %d)\n", reason); schedule_work(&adapter->ibmvnic_reset); + + return 0; +err: + if (adapter->wait_for_reset) + adapter->wait_for_reset = false; + return -ret; } static void ibmvnic_tx_timeout(struct net_device *dev) @@ -2052,6 +2062,8 @@ static void ibmvnic_netpoll_controller(struct net_device *dev) static int wait_for_reset(struct ibmvnic_adapter *adapter) { + int rc, ret; + adapter->fallback.mtu = adapter->req_mtu; adapter->fallback.rx_queues = adapter->req_rx_queues; adapter->fallback.tx_queues = adapter->req_tx_queues; @@ -2059,11 +2071,15 @@ static int wait_for_reset(struct ibmvnic_adapter *adapter) adapter->fallback.tx_entries = adapter->req_tx_entries_per_subcrq; init_completion(&adapter->reset_done); - ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM); adapter->wait_for_reset = true; + rc = ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM); + if (rc) + return rc; wait_for_completion(&adapter->reset_done); + ret = 0; if (adapter->reset_done_rc) { + ret = -EIO; adapter->desired.mtu = adapter->fallback.mtu; adapter->desired.rx_queues = adapter->fallback.rx_queues; adapter->desired.tx_queues = adapter->fallback.tx_queues; @@ -2071,12 +2087,15 @@ static int wait_for_reset(struct ibmvnic_adapter *adapter) adapter->desired.tx_entries = adapter->fallback.tx_entries; init_completion(&adapter->reset_done); - ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM); + adapter->wait_for_reset = true; + rc = ibmvnic_reset(adapter, VNIC_RESET_CHANGE_PARAM); + if (rc) + return ret; wait_for_completion(&adapter->reset_done); } adapter->wait_for_reset = false; - return adapter->reset_done_rc; + return ret; } static int ibmvnic_change_mtu(struct net_device *netdev, int new_mtu) From 5a18e1e0c193b2f6a8d4651f38aaabee58080647 Mon Sep 17 00:00:00 2001 From: Thomas Falcon Date: Fri, 6 Apr 2018 18:37:05 -0500 Subject: [PATCH 4/5] ibmvnic: Fix failover case for non-redundant configuration There is a failover case for a non-redundant pseries VNIC configuration that was not being handled properly. The current implementation assumes that the driver will always have a redandant device to communicate with following a failover notification. There are cases, however, when a non-redundant configuration can receive a failover request. If that happens, the driver should wait until it receives a signal that the device is ready for operation. The driver is agnostic of its backing hardware configuration, so this fix necessarily affects all device failover management. The driver needs to wait until it receives a signal that the device is ready for resetting. A flag is introduced to track this intermediary state where the driver is waiting for an active device. Signed-off-by: Thomas Falcon Signed-off-by: David S. Miller --- drivers/net/ethernet/ibm/ibmvnic.c | 37 +++++++++++++++++++++++------- drivers/net/ethernet/ibm/ibmvnic.h | 1 + 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c index bbcd07a02694..151542e79884 100644 --- a/drivers/net/ethernet/ibm/ibmvnic.c +++ b/drivers/net/ethernet/ibm/ibmvnic.c @@ -325,10 +325,11 @@ failure: adapter->replenish_add_buff_failure++; atomic_add(buffers_added, &pool->available); - if (lpar_rc == H_CLOSED) { + if (lpar_rc == H_CLOSED || adapter->failover_pending) { /* Disable buffer pool replenishment and report carrier off if - * queue is closed. Firmware guarantees that a signal will - * be sent to the driver, triggering a reset. + * queue is closed or pending failover. + * Firmware guarantees that a signal will be sent to the + * driver, triggering a reset. */ deactivate_rx_pools(adapter); netif_carrier_off(adapter->netdev); @@ -1068,6 +1069,14 @@ static int ibmvnic_open(struct net_device *netdev) struct ibmvnic_adapter *adapter = netdev_priv(netdev); int rc; + /* If device failover is pending, just set device state and return. + * Device operation will be handled by reset routine. + */ + if (adapter->failover_pending) { + adapter->state = VNIC_OPEN; + return 0; + } + mutex_lock(&adapter->reset_lock); if (adapter->state != VNIC_CLOSED) { @@ -1225,6 +1234,14 @@ static int ibmvnic_close(struct net_device *netdev) struct ibmvnic_adapter *adapter = netdev_priv(netdev); int rc; + /* If device failover is pending, just set device state and return. + * Device operation will be handled by reset routine. + */ + if (adapter->failover_pending) { + adapter->state = VNIC_CLOSED; + return 0; + } + mutex_lock(&adapter->reset_lock); rc = __ibmvnic_close(netdev); mutex_unlock(&adapter->reset_lock); @@ -1559,8 +1576,9 @@ static int ibmvnic_xmit(struct sk_buff *skb, struct net_device *netdev) dev_kfree_skb_any(skb); tx_buff->skb = NULL; - if (lpar_rc == H_CLOSED) { - /* Disable TX and report carrier off if queue is closed. + if (lpar_rc == H_CLOSED || adapter->failover_pending) { + /* Disable TX and report carrier off if queue is closed + * or pending failover. * Firmware guarantees that a signal will be sent to the * driver, triggering a reset or some other action. */ @@ -1884,9 +1902,10 @@ static int ibmvnic_reset(struct ibmvnic_adapter *adapter, int ret; if (adapter->state == VNIC_REMOVING || - adapter->state == VNIC_REMOVED) { + adapter->state == VNIC_REMOVED || + adapter->failover_pending) { ret = EBUSY; - netdev_dbg(netdev, "Adapter removing, skipping reset\n"); + netdev_dbg(netdev, "Adapter removing or pending failover, skipping reset\n"); goto err; } @@ -4162,7 +4181,9 @@ static void ibmvnic_handle_crq(union ibmvnic_crq *crq, case IBMVNIC_CRQ_INIT: dev_info(dev, "Partner initialized\n"); adapter->from_passive_init = true; + adapter->failover_pending = false; complete(&adapter->init_done); + ibmvnic_reset(adapter, VNIC_RESET_FAILOVER); break; case IBMVNIC_CRQ_INIT_COMPLETE: dev_info(dev, "Partner initialization complete\n"); @@ -4179,7 +4200,7 @@ static void ibmvnic_handle_crq(union ibmvnic_crq *crq, ibmvnic_reset(adapter, VNIC_RESET_MOBILITY); } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) { dev_info(dev, "Backing device failover detected\n"); - ibmvnic_reset(adapter, VNIC_RESET_FAILOVER); + adapter->failover_pending = true; } else { /* The adapter lost the connection */ dev_err(dev, "Virtual Adapter failed (rc=%d)\n", diff --git a/drivers/net/ethernet/ibm/ibmvnic.h b/drivers/net/ethernet/ibm/ibmvnic.h index 89efe700eafe..99c0b58c2c39 100644 --- a/drivers/net/ethernet/ibm/ibmvnic.h +++ b/drivers/net/ethernet/ibm/ibmvnic.h @@ -1108,6 +1108,7 @@ struct ibmvnic_adapter { bool napi_enabled, from_passive_init; bool mac_change_pending; + bool failover_pending; struct ibmvnic_tunables desired; struct ibmvnic_tunables fallback; From 30f796258c49baa313222456bcf5b0246da55ff1 Mon Sep 17 00:00:00 2001 From: Nathan Fontenot Date: Fri, 6 Apr 2018 18:37:06 -0500 Subject: [PATCH 5/5] ibmvnic: Do not reset CRQ for Mobility driver resets When resetting the ibmvnic driver after a partition migration occurs there is no requirement to do a reset of the main CRQ. The current driver code does the required re-enable of the main CRQ, then does a reset of the main CRQ later. What we should be doing for a driver reset after a migration is to re-enable the main CRQ, release all the sub-CRQs, and then allocate new sub-CRQs after capability negotiation. This patch updates the handling of mobility resets to do the proper work and not reset the main CRQ. To do this the initialization/reset of the main CRQ had to be moved out of the ibmvnic_init routine and in to the ibmvnic_probe and do_reset routines. Signed-off-by: Nathan Fontenot Signed-off-by: Thomas Falcon Signed-off-by: David S. Miller --- drivers/net/ethernet/ibm/ibmvnic.c | 55 +++++++++++++++++------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c index 151542e79884..aad5658d79d5 100644 --- a/drivers/net/ethernet/ibm/ibmvnic.c +++ b/drivers/net/ethernet/ibm/ibmvnic.c @@ -118,6 +118,7 @@ static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter); static int ibmvnic_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); struct ibmvnic_stat { char name[ETH_GSTRING_LEN]; @@ -1224,7 +1225,6 @@ static int __ibmvnic_close(struct net_device *netdev) rc = set_link_state(adapter, IBMVNIC_LOGICAL_LNK_DN); if (rc) return rc; - ibmvnic_cleanup(netdev); adapter->state = VNIC_CLOSED; return 0; } @@ -1244,6 +1244,7 @@ static int ibmvnic_close(struct net_device *netdev) mutex_lock(&adapter->reset_lock); rc = __ibmvnic_close(netdev); + ibmvnic_cleanup(netdev); mutex_unlock(&adapter->reset_lock); return rc; @@ -1726,14 +1727,10 @@ static int do_reset(struct ibmvnic_adapter *adapter, old_num_rx_queues = adapter->req_rx_queues; old_num_tx_queues = adapter->req_tx_queues; - if (rwi->reset_reason == VNIC_RESET_MOBILITY) { - rc = ibmvnic_reenable_crq_queue(adapter); - if (rc) - return 0; - ibmvnic_cleanup(netdev); - } else if (rwi->reset_reason == VNIC_RESET_FAILOVER) { - ibmvnic_cleanup(netdev); - } else { + ibmvnic_cleanup(netdev); + + if (adapter->reset_reason != VNIC_RESET_MOBILITY && + adapter->reset_reason != VNIC_RESET_FAILOVER) { rc = __ibmvnic_close(netdev); if (rc) return rc; @@ -1752,6 +1749,23 @@ static int do_reset(struct ibmvnic_adapter *adapter, */ adapter->state = VNIC_PROBED; + if (adapter->wait_for_reset) { + rc = init_crq_queue(adapter); + } else if (adapter->reset_reason == VNIC_RESET_MOBILITY) { + rc = ibmvnic_reenable_crq_queue(adapter); + release_sub_crqs(adapter, 1); + } else { + rc = ibmvnic_reset_crq(adapter); + if (!rc) + rc = vio_enable_interrupts(adapter->vdev); + } + + if (rc) { + netdev_err(adapter->netdev, + "Couldn't initialize crq. rc=%d\n", rc); + return rc; + } + rc = ibmvnic_init(adapter); if (rc) return IBMVNIC_INIT_FAILED; @@ -4500,19 +4514,6 @@ static int ibmvnic_init(struct ibmvnic_adapter *adapter) u64 old_num_rx_queues, old_num_tx_queues; int rc; - if (adapter->resetting && !adapter->wait_for_reset) { - rc = ibmvnic_reset_crq(adapter); - if (!rc) - rc = vio_enable_interrupts(adapter->vdev); - } else { - rc = init_crq_queue(adapter); - } - - if (rc) { - dev_err(dev, "Couldn't initialize crq. rc=%d\n", rc); - return rc; - } - adapter->from_passive_init = false; old_num_rx_queues = adapter->req_rx_queues; @@ -4537,7 +4538,8 @@ static int ibmvnic_init(struct ibmvnic_adapter *adapter) return -1; } - if (adapter->resetting && !adapter->wait_for_reset) { + if (adapter->resetting && !adapter->wait_for_reset && + adapter->reset_reason != VNIC_RESET_MOBILITY) { if (adapter->req_rx_queues != old_num_rx_queues || adapter->req_tx_queues != old_num_tx_queues) { release_sub_crqs(adapter, 0); @@ -4625,6 +4627,13 @@ static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id) adapter->mac_change_pending = false; do { + rc = init_crq_queue(adapter); + if (rc) { + dev_err(&dev->dev, "Couldn't initialize crq. rc=%d\n", + rc); + goto ibmvnic_init_fail; + } + rc = ibmvnic_init(adapter); if (rc && rc != EAGAIN) goto ibmvnic_init_fail;