Skip to contentSkip to conversation

ionic support for firmware upgrade

PATCH Superseded Shannon Nelson 3 participants 11 messages Mar 12, 2020 – Mar 13, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ionic support for firmware upgrade

The Pensando Distributed Services Card can get firmware upgrades from the off-host centralized management suite, and can be upgraded without a host reboot or driver reload. This patchset sets up the support for fw upgrade in the Linux driver.

When the upgrade begins, the DSC first brings the link down, then stops the firmware. The driver will notice this and quiesce itself by stopping the queues and releasing DMA resources, then monitoring for firmware to start back up. When the upgrade is finished the firmware is restarted and link is brought up, and the driver rebuilds the queues and restarts traffic flow. Typical link down time is around 30 seconds.

First we fix up the state machine so that we take the Tx and Rx queues completely down and back up when we get LINK_DOWN and LINK_UP events. Next, we attend to a few error handling details. Lastly, we add handling of the FW reset itself, tearing down and rebuilding the lif internals.

Depending on timing of net updates into net-next, the 4th patch may have a minor conflict with 905fc4f8a399 ("ionic: fix vf op lock usage")

Shannon Nelson (7):
ionic: tx and rx queues state follows link state
ionic: keep old lif dentry
ionic: ignore eexist on rx filter add
ionic: add a flag for FW in reset
ionic: remove lifs on fw reset
ionic: trigger fw reset response on fw_status
ionic: check for link when link down

 .../ethernet/pensando/ionic/ionic_bus_pci.c   |   4 +
 .../ethernet/pensando/ionic/ionic_debugfs.c   |   8 +-
 .../net/ethernet/pensando/ionic/ionic_dev.c   |  56 +++-
 .../net/ethernet/pensando/ionic/ionic_dev.h   |   1 +
 .../ethernet/pensando/ionic/ionic_ethtool.c   |  17 +-
 .../net/ethernet/pensando/ionic/ionic_lif.c   | 263 +++++++++++++-----
 .../net/ethernet/pensando/ionic/ionic_lif.h   |   6 +
 .../net/ethernet/pensando/ionic/ionic_main.c  |  16 +-
 8 files changed, 296 insertions(+), 75 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/7 ionic: tx and rx queues state follows link state

When link goes down, tear down the Tx and Rx queues. When link comes back up, rebuild the queues. This lets us release memory resources for devices that aren't going to use them, and prepares us for support of fw upgrade. We also add a couple of checks on tear down to watch out for structs already torn down.

---
 .../net/ethernet/pensando/ionic/ionic_lif.c   | 76 +++++++++++++------
 .../net/ethernet/pensando/ionic/ionic_main.c  |  7 +-
 2 files changed, 58 insertions(+), 25 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_lif.c +52 -24
index aaf4a40fa98b..682f4b5af704 100644
@@ -73,6 +73,11 @@ static void ionic_link_status_check(struct ionic_lif *lif)
 	u16 link_status;
 	bool link_up;
 
+	if (lif->ionic->is_mgmt_nic) {
+		clear_bit(IONIC_LIF_F_LINK_CHECK_REQUESTED, lif->state);
+		return;
+	}
+
 	link_status = le16_to_cpu(lif->info->status.link_status);
 	link_up = link_status == IONIC_PORT_OPER_STATUS_UP;
 
@@ -81,20 +86,28 @@ static void ionic_link_status_check(struct ionic_lif *lif)
 		goto link_out;
 
 	if (link_up) {
-		netdev_info(netdev, "Link up - %d Gbps\n",
-			    le32_to_cpu(lif->info->status.link_speed) / 1000);
+		u32 link_speed;
 
-		if (test_bit(IONIC_LIF_F_UP, lif->state)) {
-			netif_tx_wake_all_queues(lif->netdev);
-			netif_carrier_on(netdev);
+		link_speed = le16_to_cpu(lif->info->status.link_speed);
+		netdev_info(netdev, "Link up - %d Gbps\n", link_speed / 1000);
+
+		if (!test_bit(IONIC_LIF_F_UP, lif->state) &&
+		    netif_running(netdev)) {
+			rtnl_lock();
+			ionic_open(netdev);
+			rtnl_unlock();
 		}
+
+		netif_carrier_on(netdev);
 	} else {
 		netdev_info(netdev, "Link down\n");
-
-		/* carrier off first to avoid watchdog timeout */
 		netif_carrier_off(netdev);
-		if (test_bit(IONIC_LIF_F_UP, lif->state))
-			netif_tx_stop_all_queues(netdev);
+
+		if (test_bit(IONIC_LIF_F_UP, lif->state)) {
+			rtnl_lock();
+			ionic_stop(netdev);
+			rtnl_unlock();
+		}
 	}
 
 link_out:
@@ -275,8 +288,10 @@ static void ionic_lif_qcq_deinit(struct ionic_lif *lif, struct ionic_qcq *qcq)
 	if (qcq->flags & IONIC_QCQ_F_INTR) {
 		ionic_intr_mask(idev->intr_ctrl, qcq->intr.index,
 				IONIC_INTR_MASK_SET);
+		irq_set_affinity_hint(qcq->intr.vector, NULL);
 		devm_free_irq(dev, qcq->intr.vector, &qcq->napi);
 		netif_napi_del(&qcq->napi);
+		qcq->intr.vector = 0;
 	}
 
 	qcq->flags &= ~IONIC_QCQ_F_INITED;
@@ -318,19 +333,21 @@ static void ionic_qcqs_free(struct ionic_lif *lif)
 		lif->adminqcq = NULL;
 	}
 
-	for (i = 0; i < lif->nxqs; i++)
-		if (lif->rxqcqs[i].stats)
-			devm_kfree(dev, lif->rxqcqs[i].stats);
-
-	devm_kfree(dev, lif->rxqcqs);
-	lif->rxqcqs = NULL;
-
-	for (i = 0; i < lif->nxqs; i++)
-		if (lif->txqcqs[i].stats)
-			devm_kfree(dev, lif->txqcqs[i].stats);
+	if (lif->rxqcqs) {
+		for (i = 0; i < lif->nxqs; i++)
+			if (lif->rxqcqs[i].stats)
+				devm_kfree(dev, lif->rxqcqs[i].stats);
+		devm_kfree(dev, lif->rxqcqs);
+		lif->rxqcqs = NULL;
+	}
 
-	devm_kfree(dev, lif->txqcqs);
-	lif->txqcqs = NULL;
+	if (lif->txqcqs) {
+		for (i = 0; i < lif->nxqs; i++)
+			if (lif->txqcqs[i].stats)
+				devm_kfree(dev, lif->txqcqs[i].stats);
+		devm_kfree(dev, lif->txqcqs);
+		lif->txqcqs = NULL;
+	}
 }
 
 static void ionic_link_qcq_interrupts(struct ionic_qcq *src_qcq,
@@ -1573,7 +1590,17 @@ int ionic_open(struct net_device *netdev)
 	struct ionic_lif *lif = netdev_priv(netdev);
 	int err;
 
-	netif_carrier_off(netdev);
+	if (test_bit(IONIC_LIF_F_UP, lif->state)) {
+		dev_dbg(lif->ionic->dev, "%s: %s called when state=UP\n",
+			__func__, lif->name);
+		return 0;
+	}
+
+	ionic_link_status_check_request(lif);
+
+	/* wait until carrier is up before creating rx and tx queues */
+	if (!netif_carrier_ok(lif->netdev))
+		return 0;
 
 	err = ionic_txrx_alloc(lif);
 	if (err)
@@ -1592,7 +1619,6 @@ int ionic_open(struct net_device *netdev)
 
 	set_bit(IONIC_LIF_F_UP, lif->state);
 
-	ionic_link_status_check_request(lif);
 	if (netif_carrier_ok(netdev))
 		netif_tx_wake_all_queues(netdev);
 
@@ -1611,7 +1637,7 @@ int ionic_stop(struct net_device *netdev)
 	int err = 0;
 
 	if (!test_bit(IONIC_LIF_F_UP, lif->state)) {
-		dev_dbg(lif->ionic->dev, "%s: %s state=DOWN\n",
+		dev_dbg(lif->ionic->dev, "%s: %s called when state=DOWN\n",
 			__func__, lif->name);
 		return 0;
 	}
@@ -1922,6 +1948,8 @@ static struct ionic_lif *ionic_lif_alloc(struct ionic *ionic, unsigned int index
 	ionic_ethtool_set_ops(netdev);
 
 	netdev->watchdog_timeo = 2 * HZ;
+	netif_carrier_off(netdev);
+
 	netdev->min_mtu = IONIC_MIN_MTU;
 	netdev->max_mtu = IONIC_MAX_MTU;
 
drivers/net/ethernet/pensando/ionic/ionic_main.c +6 -1
index e4a76e66f542..40345281b2c9 100644
@@ -240,11 +240,16 @@ static void ionic_adminq_cb(struct ionic_queue *q,
 
 static int ionic_adminq_post(struct ionic_lif *lif, struct ionic_admin_ctx *ctx)
 {
-	struct ionic_queue *adminq = &lif->adminqcq->q;
+	struct ionic_queue *adminq;
 	int err = 0;
 
 	WARN_ON(in_interrupt());
 
+	if (!lif->adminqcq)
+		return -EIO;
+
+	adminq = &lif->adminqcq->q;
+
 	spin_lock(&lif->adminq_lock);
 	if (!ionic_q_has_space(adminq, 1)) {
 		err = -ENOSPC;
Signature · 1 line
2.17.1
#5 lore raw

PATCH 2/7 ionic: keep old lif dentry

In reply to Shannon Nelson

Don't replace the lif->dentry until we know we have a good new value.

---
 drivers/net/ethernet/pensando/ionic/ionic_debugfs.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/pensando/ionic/ionic_debugfs.c +7 -1
index bc03cecf80cc..5f8fc58d42b3 100644
@@ -228,7 +228,13 @@ DEFINE_SHOW_ATTRIBUTE(netdev);
 
 void ionic_debugfs_add_lif(struct ionic_lif *lif)
 {
-	lif->dentry = debugfs_create_dir(lif->name, lif->ionic->dentry);
+	struct dentry *lif_dentry;
+
+	lif_dentry = debugfs_create_dir(lif->name, lif->ionic->dentry);
+	if (IS_ERR_OR_NULL(lif_dentry))
+		return;
+	lif->dentry = lif_dentry;
+
 	debugfs_create_file("netdev", 0400, lif->dentry,
 			    lif->netdev, &netdev_fops);
 }
Signature · 1 line
2.17.1
#6 lore raw

PATCH 3/7 ionic: ignore eexist on rx filter add

In reply to Shannon Nelson

Don't worry if the rx filter add firmware request fails on EEXIST, at least we know the filter is there. Same for the delete request, at least we know it isn't there.

---
 drivers/net/ethernet/pensando/ionic/ionic_lif.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_lif.c +2 -2
index 682f4b5af704..eb1e885a2f70 100644
@@ -849,7 +849,7 @@ static int ionic_lif_addr_add(struct ionic_lif *lif, const u8 *addr)
 
 	memcpy(ctx.cmd.rx_filter_add.mac.addr, addr, ETH_ALEN);
 	err = ionic_adminq_post_wait(lif, &ctx);
-	if (err)
+	if (err && err != -EEXIST)
 		return err;
 
 	return ionic_rx_filter_save(lif, 0, IONIC_RXQ_INDEX_ANY, 0, &ctx);
@@ -879,7 +879,7 @@ static int ionic_lif_addr_del(struct ionic_lif *lif, const u8 *addr)
 	spin_unlock_bh(&lif->rx_filters.lock);
 
 	err = ionic_adminq_post_wait(lif, &ctx);
-	if (err)
+	if (err && err != -EEXIST)
 		return err;
 
 	netdev_dbg(lif->netdev, "rx_filter del ADDR %pM (id %d)\n", addr,
Signature · 1 line
2.17.1
#9 lore raw

PATCH 6/7 ionic: trigger fw reset response on fw_status

In reply to Shannon Nelson

If the fw_status goes to 0 (stopped) or to 0xff (no PCI connection), then shut down the driver activity. Normally the driver will have received a RESET event to stop its activity, but if the events weren't sent, or the firmware was rebooted or crashed, this will catch the issue and quiesce the driver.

When the fw_status goes back to IONIC_FW_STS_F_RUNNING we can restart the driver operations.

---
 .../net/ethernet/pensando/ionic/ionic_dev.c   | 46 ++++++++++++++++++-
 .../net/ethernet/pensando/ionic/ionic_dev.h   |  1 +
 .../net/ethernet/pensando/ionic/ionic_lif.c   |  4 +-
 .../net/ethernet/pensando/ionic/ionic_lif.h   |  2 +
 4 files changed, 49 insertions(+), 4 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_dev.c +44 -2
index 46107de5e6c3..bb513db7163c 100644
@@ -82,6 +82,7 @@ int ionic_dev_setup(struct ionic *ionic)
 		return -EFAULT;
 	}
 
+	idev->last_fw_status = 0xff;
 	timer_setup(&ionic->watchdog_timer, ionic_watchdog_cb, 0);
 	ionic->watchdog_period = IONIC_WATCHDOG_SECS * HZ;
 	mod_timer(&ionic->watchdog_timer,
@@ -115,8 +116,49 @@ int ionic_heartbeat_check(struct ionic *ionic)
 	 * fw_status != 0xff (bad PCI read)
 	 */
 	fw_status = ioread8(&idev->dev_info_regs->fw_status);
-	if (fw_status == 0xff ||
-	    !(fw_status & IONIC_FW_STS_F_RUNNING))
+	if (fw_status != 0xff)
+		fw_status &= IONIC_FW_STS_F_RUNNING;  /* use only the run bit */
+
+	/* is this a transition? */
+	if (fw_status != idev->last_fw_status &&
+	    idev->last_fw_status != 0xff) {
+		struct ionic_lif *lif = ionic->master_lif;
+		bool trigger = false;
+
+		if (!fw_status || fw_status == 0xff) {
+			dev_info(ionic->dev, "FW stopped %u\n", fw_status);
+			if (lif &&
+			    !test_bit(IONIC_LIF_F_FW_RESET, lif->state)) {
+				dev_info(ionic->dev, "... stopping queues\n");
+				trigger = true;
+			}
+		} else {
+			dev_info(ionic->dev, "FW running %u\n", fw_status);
+			if (lif &&
+			    test_bit(IONIC_LIF_F_FW_RESET, lif->state)) {
+				dev_info(ionic->dev, "... starting queues\n");
+				trigger = true;
+			}
+		}
+
+		if (trigger) {
+			struct ionic_deferred_work *work;
+
+			work = kzalloc(sizeof(*work), GFP_ATOMIC);
+			if (!work) {
+				dev_err(ionic->dev, "%s OOM\n", __func__);
+			} else {
+				work->type = IONIC_DW_TYPE_LIF_RESET;
+				if (fw_status & IONIC_FW_STS_F_RUNNING &&
+				    fw_status != 0xff)
+					work->fw_status = 1;
+				ionic_lif_deferred_enqueue(&lif->deferred, work);
+			}
+		}
+	}
+	idev->last_fw_status = fw_status;
+
+	if (!fw_status || fw_status == 0xff)
 		return -ENXIO;
 
 	/* early FW has no heartbeat, else FW will return non-zero */
drivers/net/ethernet/pensando/ionic/ionic_dev.h +1 -0
index 7838e342c4fd..587398b01997 100644
@@ -132,6 +132,7 @@ struct ionic_dev {
 
 	unsigned long last_hb_time;
 	u32 last_hb;
+	u8 last_fw_status;
 
 	u64 __iomem *db_pages;
 	dma_addr_t phy_db_pages;
drivers/net/ethernet/pensando/ionic/ionic_lif.c +2 -2
index a6af75031347..8027b72835b6 100644
@@ -67,8 +67,8 @@ static void ionic_lif_deferred_work(struct work_struct *work)
 	}
 }
 
-static void ionic_lif_deferred_enqueue(struct ionic_deferred *def,
-				       struct ionic_deferred_work *work)
+void ionic_lif_deferred_enqueue(struct ionic_deferred *def,
+				struct ionic_deferred_work *work)
 {
 	spin_lock_bh(&def->lock);
 	list_add_tail(&work->list, &def->list);
drivers/net/ethernet/pensando/ionic/ionic_lif.h +2 -0
index 732dc1f99d24..fdbb25774755 100644
@@ -226,6 +226,8 @@ static inline u32 ionic_coal_hw_to_usec(struct ionic *ionic, u32 units)
 	return (units * div) / mult;
 }
 
+void ionic_lif_deferred_enqueue(struct ionic_deferred *def,
+				struct ionic_deferred_work *work);
 int ionic_lifs_alloc(struct ionic *ionic);
 void ionic_lifs_free(struct ionic *ionic);
 void ionic_lifs_deinit(struct ionic *ionic);
Signature · 1 line
2.17.1
#8 lore raw

PATCH 5/7 ionic: remove lifs on fw reset

In reply to Shannon Nelson

When the FW RESET event comes to the driver from the firmware, tear down the LIFs. This event signals a FW upgrade where we need to quiesce all operations and wait for the FW to restart. The FW will continue the update process once it sees all the LIFs are reset. When the update process is done it will set the fw_status back to RUNNING. Meanwhile, the heartbeat check continues and when the fw_status is seen as set to running we can rebuild the LIFs.

We expect that there was a LINK_DOWN event before this to stop the queues, and there will be a LINK_UP event afterwards to get things started again.

---
 .../net/ethernet/pensando/ionic/ionic_lif.c   | 79 ++++++++++++++++---
 .../net/ethernet/pensando/ionic/ionic_lif.h   |  1 +
 2 files changed, 70 insertions(+), 10 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_lif.c +69 -10
index 7909a037d5f7..a6af75031347 100644
@@ -21,6 +21,9 @@ static void ionic_lif_rx_mode(struct ionic_lif *lif, unsigned int rx_mode);
 static int ionic_lif_addr_add(struct ionic_lif *lif, const u8 *addr);
 static int ionic_lif_addr_del(struct ionic_lif *lif, const u8 *addr);
 static void ionic_link_status_check(struct ionic_lif *lif);
+static void ionic_lif_handle_fw_down(struct ionic_lif *lif);
+static void ionic_lif_handle_fw_up(struct ionic_lif *lif);
+static void ionic_lif_set_netdev_info(struct ionic_lif *lif);
 
 static void ionic_lif_deferred_work(struct work_struct *work)
 {
@@ -50,6 +53,12 @@ static void ionic_lif_deferred_work(struct work_struct *work)
 		case IONIC_DW_TYPE_LINK_STATUS:
 			ionic_link_status_check(lif);
 			break;
+		case IONIC_DW_TYPE_LIF_RESET:
+			if (w->fw_status)
+				ionic_lif_handle_fw_up(lif);
+			else
+				ionic_lif_handle_fw_down(lif);
+			break;
 		default:
 			break;
 		}
@@ -690,6 +699,7 @@ static bool ionic_notifyq_service(struct ionic_cq *cq,
 				  struct ionic_cq_info *cq_info)
 {
 	union ionic_notifyq_comp *comp = cq_info->cq_desc;
+	struct ionic_deferred_work *work;
 	struct net_device *netdev;
 	struct ionic_queue *q;
 	struct ionic_lif *lif;
@@ -715,11 +725,13 @@ static bool ionic_notifyq_service(struct ionic_cq *cq,
 		ionic_link_status_check_request(lif);
 		break;
 	case IONIC_EVENT_RESET:
-		netdev_info(netdev, "Notifyq IONIC_EVENT_RESET eid=%lld\n",
-			    eid);
-		netdev_info(netdev, "  reset_code=%d state=%d\n",
-			    comp->reset.reset_code,
-			    comp->reset.state);
+		work = kzalloc(sizeof(*work), GFP_ATOMIC);
+		if (!work) {
+			netdev_err(lif->netdev, "%s OOM\n", __func__);
+		} else {
+			work->type = IONIC_DW_TYPE_LIF_RESET;
+			ionic_lif_deferred_enqueue(&lif->deferred, work);
+		}
 		break;
 	default:
 		netdev_warn(netdev, "Notifyq unknown event ecode=%d eid=%lld\n",
@@ -1232,7 +1244,8 @@ static int ionic_init_nic_features(struct ionic_lif *lif)
 	netdev->hw_features |= netdev->hw_enc_features;
 	netdev->features |= netdev->hw_features;
 
-	netdev->priv_flags |= IFF_UNICAST_FLT;
+	netdev->priv_flags |= IFF_UNICAST_FLT |
+			      IFF_LIVE_ADDR_CHANGE;
 
 	return 0;
 }
@@ -2067,6 +2080,51 @@ static void ionic_lif_reset(struct ionic_lif *lif)
 	mutex_unlock(&lif->ionic->dev_cmd_lock);
 }
 
+static void ionic_lif_handle_fw_down(struct ionic_lif *lif)
+{
+	struct ionic *ionic = lif->ionic;
+
+	set_bit(IONIC_LIF_F_FW_RESET, lif->state);
+	dev_info(ionic->dev, "FW Down: Stopping LIFs\n");
+
+	if (test_bit(IONIC_LIF_F_UP, lif->state)) {
+		dev_info(ionic->dev, "Surprise FW stop, stopping netdev\n");
+		rtnl_lock();
+		ionic_stop(lif->netdev);
+		rtnl_unlock();
+	}
+
+	ionic_lifs_deinit(ionic);
+	ionic_qcqs_free(lif);
+
+	dev_info(ionic->dev, "FW Down: LIFs stopped\n");
+}
+
+static void ionic_lif_handle_fw_up(struct ionic_lif *lif)
+{
+	struct ionic *ionic = lif->ionic;
+	int err;
+
+	dev_info(ionic->dev, "FW Up: restarting LIFs\n");
+
+	err = ionic_qcqs_alloc(lif);
+	if (!err)
+		err = ionic_lifs_init(ionic);
+
+	if (lif->registered)
+		ionic_lif_set_netdev_info(lif);
+
+	if (!err)
+		clear_bit(IONIC_LIF_F_FW_RESET, lif->state);
+
+	ionic_link_status_check_request(lif);
+
+	if (!err)
+		dev_info(ionic->dev, "FW Up: LIFs restarted\n");
+	else
+		dev_info(ionic->dev, "FW Up: LIFs restart failed\n");
+}
+
 static void ionic_lif_free(struct ionic_lif *lif)
 {
 	struct device *dev = lif->ionic->dev;
@@ -2229,6 +2287,7 @@ static int ionic_lif_notifyq_init(struct ionic_lif *lif)
 	if (err)
 		return err;
 
+	lif->last_eid = 0;
 	q->hw_type = ctx.comp.q_init.hw_type;
 	q->hw_index = le32_to_cpu(ctx.comp.q_init.hw_index);
 	q->dbval = IONIC_DBELL_QID(q->hw_index);
@@ -2271,8 +2330,8 @@ static int ionic_station_set(struct ionic_lif *lif)
 	addr.sa_family = AF_INET;
 	err = eth_prepare_mac_addr_change(netdev, &addr);
 	if (err) {
-		netdev_warn(lif->netdev, "ignoring bad MAC addr from NIC %pM\n",
-			    addr.sa_data);
+		netdev_warn(lif->netdev, "ignoring bad MAC addr from NIC %pM - err %d\n",
+			    addr.sa_data, err);
 		return 0;
 	}
 
@@ -2296,8 +2355,6 @@ static int ionic_lif_init(struct ionic_lif *lif)
 	int dbpage_num;
 	int err;
 
-	ionic_debugfs_add_lif(lif);
-
 	mutex_lock(&lif->ionic->dev_cmd_lock);
 	ionic_dev_cmd_lif_init(idev, lif->index, lif->info_pa);
 	err = ionic_dev_cmd_wait(lif->ionic, DEVCMD_TIMEOUT);
@@ -2333,6 +2390,8 @@ static int ionic_lif_init(struct ionic_lif *lif)
 		goto err_out_free_dbid;
 	}
 
+	ionic_debugfs_add_lif(lif);
+
 	err = ionic_lif_adminq_init(lif);
 	if (err)
 		goto err_out_adminq_deinit;
drivers/net/ethernet/pensando/ionic/ionic_lif.h +1 -0
index d811cbb790dc..732dc1f99d24 100644
@@ -98,6 +98,7 @@ struct ionic_deferred_work {
 	union {
 		unsigned int rx_mode;
 		u8 addr[ETH_ALEN];
+		u8 fw_status;
 	};
 };
 
Signature · 1 line
2.17.1
#10 lore raw

PATCH 7/7 ionic: check for link when link down

In reply to Shannon Nelson

While the link is down, have the heartbeat watchdog also check the link for changes in case no Event is sent.

Meanwhile, sometimes the link status check runs into itself or the ionic_open() thread, and can either confuse itself, throw incorrect error messages, or even miss the link message. This patch cleans up the code and gets the right messages out to the log file when they happen.

- rearrange the link_up/link_down messages so that we announce link up when we first notice that the link is up when the driver loads, and decouple the link_up/link_down messages from the UP and DOWN netdev state.
- add error checking of ionic_qcq_disable() so as to not have to wait too long on shutdown when everything it timeout out.
- add a state to indicate transitions between netdev UP and DOWN so as to prevent recursion.
- don't clean the dev_cmd when we notice that the fw has halted, it's possible it might still execute the request.

---
 .../net/ethernet/pensando/ionic/ionic_dev.c   | 10 ++-
 .../net/ethernet/pensando/ionic/ionic_lif.c   | 78 ++++++++++++-------
 .../net/ethernet/pensando/ionic/ionic_lif.h   |  2 +
 .../net/ethernet/pensando/ionic/ionic_main.c  |  1 -
 4 files changed, 61 insertions(+), 30 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_dev.c +9 -1
index bb513db7163c..349b63f3ab54 100644
@@ -14,11 +14,19 @@
 static void ionic_watchdog_cb(struct timer_list *t)
 {
 	struct ionic *ionic = from_timer(ionic, t, watchdog_timer);
+	struct ionic_lif *lif = ionic->master_lif;
+	int hb;
 
 	mod_timer(&ionic->watchdog_timer,
 		  round_jiffies(jiffies + ionic->watchdog_period));
 
-	ionic_heartbeat_check(ionic);
+	hb = ionic_heartbeat_check(ionic);
+
+	/* check link if we're waiting for link to come back up */
+	if (hb >= 0 && lif && netif_running(lif->netdev) &&
+	    !test_bit(IONIC_LIF_F_UP, lif->state)) {
+		ionic_link_status_check_request(lif);
+	}
 }
 
 void ionic_init_devinfo(struct ionic *ionic)
drivers/net/ethernet/pensando/ionic/ionic_lif.c +50 -28

169 lines not on this page · raw message

drivers/net/ethernet/pensando/ionic/ionic_lif.h +2 -0
index fdbb25774755..7c6e8495322d 100644
@@ -125,6 +125,7 @@ enum ionic_lif_state_flags {
 	IONIC_LIF_F_INITED,
 	IONIC_LIF_F_SW_DEBUG_STATS,
 	IONIC_LIF_F_UP,
+	IONIC_LIF_F_TRANS,
 	IONIC_LIF_F_LINK_CHECK_REQUESTED,
 	IONIC_LIF_F_QUEUE_RESET,
 	IONIC_LIF_F_FW_RESET,
@@ -228,6 +229,7 @@ static inline u32 ionic_coal_hw_to_usec(struct ionic *ionic, u32 units)
 
 void ionic_lif_deferred_enqueue(struct ionic_deferred *def,
 				struct ionic_deferred_work *work);
+void ionic_link_status_check_request(struct ionic_lif *lif);
 int ionic_lifs_alloc(struct ionic *ionic);
 void ionic_lifs_free(struct ionic *ionic);
 void ionic_lifs_deinit(struct ionic *ionic);
drivers/net/ethernet/pensando/ionic/ionic_main.c +0 -1
index 601865db7e03..1dafc047b136 100644
@@ -364,7 +364,6 @@ int ionic_dev_cmd_wait(struct ionic *ionic, unsigned long max_seconds)
 		done, duration / HZ, duration);
 
 	if (!done && hb) {
-		ionic_dev_cmd_clean(ionic);
 		dev_warn(ionic->dev, "DEVCMD %s (%d) failed - FW halted\n",
 			 ionic_opcode_to_str(opcode), opcode);
 		return -ENXIO;
Signature · 1 line
2.17.1
#7 lore raw

PATCH 4/7 ionic: add a flag for FW in reset

In reply to Shannon Nelson

Add the FW_RESET flag, and prevent a few things from happening if the FW_RESET flag is set. Code for setting and clearing it is in a following patch.

---

Depending on timing of net updates into net-next, this may have a conflict with 905fc4f8a399 ("ionic: fix vf op lock usage")

 .../ethernet/pensando/ionic/ionic_bus_pci.c   |  4 ++
 .../ethernet/pensando/ionic/ionic_ethtool.c   | 17 +++++++-
 .../net/ethernet/pensando/ionic/ionic_lif.c   | 40 +++++++++++++++----
 .../net/ethernet/pensando/ionic/ionic_lif.h   |  1 +
 .../net/ethernet/pensando/ionic/ionic_main.c  |  8 ++--
 5 files changed, 58 insertions(+), 12 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +4 -0
index 60fc191a35e5..c55e28f3c986 100644
@@ -185,6 +185,10 @@ static int ionic_sriov_configure(struct pci_dev *pdev, int num_vfs)
 	struct device *dev = ionic->dev;
 	int ret = 0;
 
+	if (ionic->master_lif &&
+	    test_bit(IONIC_LIF_F_FW_RESET, ionic->master_lif->state))
+		return -EBUSY;
+
 	if (num_vfs > 0) {
 		ret = pci_enable_sriov(pdev, num_vfs);
 		if (ret) {
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +15 -2
index a233716eac29..ddae21b1f80a 100644
@@ -27,10 +27,11 @@ static void ionic_get_stats_strings(struct ionic_lif *lif, u8 *buf)
 static void ionic_get_stats(struct net_device *netdev,
 			    struct ethtool_stats *stats, u64 *buf)
 {
-	struct ionic_lif *lif;
+	struct ionic_lif *lif = netdev_priv(netdev);
 	u32 i;
 
-	lif = netdev_priv(netdev);
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return;
 
 	memset(buf, 0, stats->n_stats * sizeof(*buf));
 	for (i = 0; i < ionic_num_stats_grps; i++)
@@ -255,6 +256,9 @@ static int ionic_set_link_ksettings(struct net_device *netdev,
 	struct ionic_dev *idev;
 	int err = 0;
 
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return -EBUSY;
+
 	idev = &lif->ionic->idev;
 
 	/* set autoneg */
@@ -303,6 +307,9 @@ static int ionic_set_pauseparam(struct net_device *netdev,
 	u32 requested_pause;
 	int err;
 
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return -EBUSY;
+
 	if (pause->autoneg)
 		return -EOPNOTSUPP;
 
@@ -355,6 +362,9 @@ static int ionic_set_fecparam(struct net_device *netdev,
 	u8 fec_type;
 	int ret = 0;
 
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return -EBUSY;
+
 	if (lif->ionic->idev.port_info->config.an_enable) {
 		netdev_err(netdev, "FEC request not allowed while autoneg is enabled\n");
 		return -EINVAL;
@@ -739,6 +749,9 @@ static int ionic_nway_reset(struct net_device *netdev)
 	struct ionic *ionic = lif->ionic;
 	int err = 0;
 
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return -EBUSY;
+
 	/* flap the link to force auto-negotiation */
 
 	mutex_lock(&ionic->dev_cmd_lock);
drivers/net/ethernet/pensando/ionic/ionic_lif.c +33 -7
index eb1e885a2f70..7909a037d5f7 100644
@@ -1664,6 +1664,9 @@ static int ionic_get_vf_config(struct net_device *netdev,
 	struct ionic *ionic = lif->ionic;
 	int ret = 0;
 
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return -EBUSY;
+
 	down_read(&ionic->vf_op_lock);
 
 	if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1691,6 +1694,9 @@ static int ionic_get_vf_stats(struct net_device *netdev, int vf,
 	struct ionic_lif_stats *vs;
 	int ret = 0;
 
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return -EBUSY;
+
 	down_read(&ionic->vf_op_lock);
 
 	if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1726,6 +1732,9 @@ static int ionic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
 	if (!(is_zero_ether_addr(mac) || is_valid_ether_addr(mac)))
 		return -EINVAL;
 
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return -EBUSY;
+
 	down_read(&ionic->vf_op_lock);
 
 	if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1757,6 +1766,9 @@ static int ionic_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan,
 	if (proto != htons(ETH_P_8021Q))
 		return -EPROTONOSUPPORT;
 
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return -EBUSY;
+
 	down_read(&ionic->vf_op_lock);
 
 	if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1783,6 +1795,9 @@ static int ionic_set_vf_rate(struct net_device *netdev, int vf,
 	if (tx_min)
 		return -EINVAL;
 
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return -EBUSY;
+
 	down_write(&ionic->vf_op_lock);
 
 	if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1805,6 +1820,9 @@ static int ionic_set_vf_spoofchk(struct net_device *netdev, int vf, bool set)
 	u8 data = set;  /* convert to u8 for config */
 	int ret;
 
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return -EBUSY;
+
 	down_write(&ionic->vf_op_lock);
 
 	if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1827,6 +1845,9 @@ static int ionic_set_vf_trust(struct net_device *netdev, int vf, bool set)
 	u8 data = set;  /* convert to u8 for config */
 	int ret;
 
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return -EBUSY;
+
 	down_write(&ionic->vf_op_lock);
 
 	if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -1863,6 +1884,9 @@ static int ionic_set_vf_link_state(struct net_device *netdev, int vf, int set)
 		return -EINVAL;
 	}
 
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return -EBUSY;
+
 	down_write(&ionic->vf_op_lock);
 
 	if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
@@ -2055,7 +2079,8 @@ static void ionic_lif_free(struct ionic_lif *lif)
 
 	/* free queues */
 	ionic_qcqs_free(lif);
-	ionic_lif_reset(lif);
+	if (!test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		ionic_lif_reset(lif);
 
 	/* free lif info */
 	dma_free_coherent(dev, lif->info_sz, lif->info, lif->info_pa);
@@ -2093,6 +2118,11 @@ static void ionic_lif_deinit(struct ionic_lif *lif)
 
 	clear_bit(IONIC_LIF_F_INITED, lif->state);
 
+	if (!test_bit(IONIC_LIF_F_FW_RESET, lif->state)) {
+		cancel_work_sync(&lif->deferred.work);
+		cancel_work_sync(&lif->tx_timeout_work);
+	}
+
 	ionic_rx_filters_deinit(lif);
 	ionic_lif_rss_deinit(lif);
 
@@ -2454,12 +2484,8 @@ void ionic_lifs_unregister(struct ionic *ionic)
 	 * current model, so don't bother searching the
 	 * ionic->lif for candidates to unregister
 	 */
-	if (!ionic->master_lif)
-		return;
-
-	cancel_work_sync(&ionic->master_lif->deferred.work);
-	cancel_work_sync(&ionic->master_lif->tx_timeout_work);
-	if (ionic->master_lif->netdev->reg_state == NETREG_REGISTERED)
+	if (ionic->master_lif &&
+	    ionic->master_lif->netdev->reg_state == NETREG_REGISTERED)
 		unregister_netdev(ionic->master_lif->netdev);
 }
 
drivers/net/ethernet/pensando/ionic/ionic_lif.h +1 -0
index 7c0c6fef8c0b..d811cbb790dc 100644
@@ -126,6 +126,7 @@ enum ionic_lif_state_flags {
 	IONIC_LIF_F_UP,
 	IONIC_LIF_F_LINK_CHECK_REQUESTED,
 	IONIC_LIF_F_QUEUE_RESET,
+	IONIC_LIF_F_FW_RESET,
 
 	/* leave this as last */
 	IONIC_LIF_F_STATE_SIZE
drivers/net/ethernet/pensando/ionic/ionic_main.c +5 -3
index 40345281b2c9..601865db7e03 100644
@@ -283,9 +283,11 @@ int ionic_adminq_post_wait(struct ionic_lif *lif, struct ionic_admin_ctx *ctx)
 
 	err = ionic_adminq_post(lif, ctx);
 	if (err) {
-		name = ionic_opcode_to_str(ctx->cmd.cmd.opcode);
-		netdev_err(netdev, "Posting of %s (%d) failed: %d\n",
-			   name, ctx->cmd.cmd.opcode, err);
+		if (!test_bit(IONIC_LIF_F_FW_RESET, lif->state)) {
+			name = ionic_opcode_to_str(ctx->cmd.cmd.opcode);
+			netdev_err(netdev, "Posting of %s (%d) failed: %d\n",
+				   name, ctx->cmd.cmd.opcode, err);
+		}
 		return err;
 	}
 
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH net-next 1/7] ionic: tx and rx queues state follows link state

In reply to Shannon Nelson

From: Shannon Nelson <[email protected]>
Date: Thu, 12 Mar 2020 14:50:09 -0700

drivers/net/ethernet/pensando/ionic/ionic_lif.c static void ionic_link_status_check(struct ionic_lif *lif) · line 99

Quoted 6 lines
drivers/net/ethernet/pensando/ionic/ionic_lif.c +5 -0
+		if (!test_bit(IONIC_LIF_F_UP, lif->state) &&
+		    netif_running(netdev)) {
+			rtnl_lock();
+			ionic_open(netdev);
+			rtnl_unlock();
 		}

You're running into a major problem area here.

ionic_open() can fail, particularly because it allocates resources.

Yet you are doing this in an operational path that doesn't handle and unwind from errors.

You must find a way to do this properly, because the current approach can result in an inoperable interface.

#3 lore raw

Re: [PATCH net-next 1/7] ionic: tx and rx queues state follows link state

Quoted 11 lines · David Miller

From: Shannon Nelson <[email protected]>
Date: Thu, 12 Mar 2020 14:50:09 -0700

drivers/net/ethernet/pensando/ionic/ionic_lif.c static void ionic_link_status_check(struct ionic_lif *lif) · line 99

Quoted 6 lines
drivers/net/ethernet/pensando/ionic/ionic_lif.c +5 -0
+		if (!test_bit(IONIC_LIF_F_UP, lif->state) &&
+		    netif_running(netdev)) {
+			rtnl_lock();
+			ionic_open(netdev);
+			rtnl_unlock();
  		}

You're running into a major problem area here.

Quoted 7 lines

ionic_open() can fail, particularly because it allocates resources.

Yet you are doing this in an operational path that doesn't handle and unwind from errors.

You must find a way to do this properly, because the current approach can result in an inoperable interface.

I don't see this as much different from how we use it in ionic_reset_queues(), which was modeled after some other drivers' uses of the open call.  In the fw reset case, though, the time between the close and the open is many seconds.

Yes, ionic_open() can fail, and it unwinds its own work.  There isn't anything here in ionic_link_status_check() to unwind, and no one to report the error to, so we don't catch the error here. However, it would be better if I move the addition of the IONIC_LIF_F_TRANS flag and a couple other bits from patch 7 into this patch - I can do that for a v2 patchset.

sln

maintainer
#4 lore raw

Re: [PATCH net-next 1/7] ionic: tx and rx queues state follows link state

Quoted 17 lines · On Thu, 12 Mar 2020 17:12:45 -0700 Shannon Nelson wrote:
Quoted 16 lines · David Miller

From: Shannon Nelson <[email protected]>
Date: Thu, 12 Mar 2020 14:50:09 -0700

drivers/net/ethernet/pensando/ionic/ionic_lif.c static void ionic_link_status_check(struct ionic_lif *lif) · line 99

Quoted 6 lines
drivers/net/ethernet/pensando/ionic/ionic_lif.c +5 -0
+		if (!test_bit(IONIC_LIF_F_UP, lif->state) &&
+		    netif_running(netdev)) {
+			rtnl_lock();
+			ionic_open(netdev);
+			rtnl_unlock();
  		}  

You're running into a major problem area here.

ionic_open() can fail, particularly because it allocates resources.

Yet you are doing this in an operational path that doesn't handle and unwind from errors.

Quoted 7 lines
Quoted 2 lines

You must find a way to do this properly, because the current approach can result in an inoperable interface.

I don't see this as much different from how we use it in ionic_reset_queues(), which was modeled after some other drivers' uses of the open call.  In the fw reset case, though, the time between the close and the open is many seconds.

Precedent does not make it any better. You're really pushing the re-open hack to new levels here :(

Why don't you just unregister the netdev? 30 sec is orders of magnitude past the point where "no impact to the user" could be claimed.

FWIW please take a look at NFP, nfp_net_ring_reconfig() and its uses, to see a better way of handling shutdown and reconfiguration.

Quoted 6 lines

Yes, ionic_open() can fail, and it unwinds its own work.  There isn't anything here in ionic_link_status_check() to unwind, and no one to report the error to, so we don't catch the error here. However, it would be better if I move the addition of the IONIC_LIF_F_TRANS flag and a couple other bits from patch 7 into this patch - I can do that for a v2 patchset.

Those layers of "how open is the device _really_" state within drivers are just a breeding ground for bugs. Already you're doing this:

+ if (!test_bit(IONIC_LIF_F_UP, lif->state) &&
+ netif_running(netdev)) {
+ rtnl_lock();
+ ionic_open(netdev);
+ rtnl_unlock();

A lot may happen right before rtnl_lock().

You got the UP bit, the RESET bit, and now TRANS bit..