Skip to contentSkip to conversation

octeon_ep: deferred probe and mailbox

PATCH Superseded Veerasenareddy Burru 2 participants 15 messages Mar 22, 2023 – Mar 29, 2023

Subsystems (4)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Veerasenareddy Burru

author maintainer
#0 lore raw

v4 cover octeon_ep: deferred probe and mailbox

Implement Deferred probe, mailbox enhancements and heartbeat monitor.

v3 -> v4:
- addressed review comments on v3

     https://lore.kernel.org/all/[email protected]/
   - 0004-xxx.patch v3 is split into 0004-xxx.patch and 0005-xxx.patch
     in v4.

- API changes to accept function ID are moved to 0005-xxx.patch.
- fixed rct violations.
- reverted newly added changes that do not yet have use cases.

v2 -> v3:
- removed SRIOV VF support changes from v2, as new drivers which use ndo_get_vf_xxx() and ndo_set_vf_xxx() are not accepted.
https://lore.kernel.org/all/[email protected]/

Will implement VF representors and submit again.
- 0007-xxx.patch and 0008-xxx.patch from v2 are removed and

     0009-xxx.patch in v2 is now 0007-xxx.patch in v3.

- accordingly, changed title for cover letter.

v1 -> v2:
- remove separate workqueue task to wait for firmware ready. instead defer probe when firmware is not ready.

- This change has resulted in update of 0001-xxx.patch and all other patches in the patchset.

Veerasenareddy Burru (8):
octeon_ep: defer probe if firmware not ready
octeon_ep: poll for control messages
octeon_ep: control mailbox for multiple PFs
octeon_ep: add separate mailbox command and response queues
octeon_ep: include function id in mailbox commands
octeon_ep: support asynchronous notifications
octeon_ep: function id in link info and stats mailbox commands
octeon_ep: add heartbeat monitor

 .../marvell/octeon_ep/octep_cn9k_pf.c         |  72 ++--
 .../ethernet/marvell/octeon_ep/octep_config.h |   6 +
 .../marvell/octeon_ep/octep_ctrl_mbox.c       | 276 +++++++------
 .../marvell/octeon_ep/octep_ctrl_mbox.h       |  88 ++--
 .../marvell/octeon_ep/octep_ctrl_net.c        | 387 ++++++++++++------
 .../marvell/octeon_ep/octep_ctrl_net.h        | 196 +++++----
 .../marvell/octeon_ep/octep_ethtool.c         |  12 +-
 .../ethernet/marvell/octeon_ep/octep_main.c   | 181 +++++---
 .../ethernet/marvell/octeon_ep/octep_main.h   |  18 +-
 .../marvell/octeon_ep/octep_regs_cn9k_pf.h    |   6 +
 10 files changed, 785 insertions(+), 457 deletions(-)

base-commit: 56c874f7dbcab2ab5cf8055d46a2ef36dec3d664

Signature · 1 line
2.36.0
author maintainer
#1 lore raw

PATCH v4 1/8 octeon_ep: defer probe if firmware not ready

Defer probe if firmware is not ready for device usage.

---
v3 -> v4:
* address review comments
https://lore.kernel.org/all/Y+vFlfakHj33DEkt@boxer/
- fix return statement for get_fw_ready_status().

v2 -> v3:
* fix review comments
https://lore.kernel.org/all/Y4chWyR6qTlptkTE@unreal/
- change get_fw_ready_status() to return bool
- fix the success oriented flow while looking for PCI extended capability

v1 -> v2:
* was scheduling workqueue task to wait for firmware ready, to probe/initialize the device.
* now, removed the workqueue task; the probe returns EPROBE_DEFER, if firmware is not ready.
* removed device status oct->status, as it is not required with the modified implementation.

 .../ethernet/marvell/octeon_ep/octep_main.c   | 26 +++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +26 -0
index fdce78ceea87..0a50da52dc27 100644
@@ -1016,6 +1016,26 @@ static void octep_device_cleanup(struct octep_device *oct)
 	oct->conf = NULL;
 }
 
+static bool get_fw_ready_status(struct pci_dev *pdev)
+{
+	u32 pos = 0;
+	u16 vsec_id;
+	u8 status;
+
+	while ((pos = pci_find_next_ext_capability(pdev, pos,
+						   PCI_EXT_CAP_ID_VNDR))) {
+		pci_read_config_word(pdev, pos + 4, &vsec_id);
+#define FW_STATUS_VSEC_ID  0xA3
+		if (vsec_id != FW_STATUS_VSEC_ID)
+			continue;
+
+		pci_read_config_byte(pdev, (pos + 8), &status);
+		dev_info(&pdev->dev, "Firmware ready status = %u\n", status);
+		return status;
+	}
+	return false;
+}
+
 /**
  * octep_probe() - Octeon PCI device probe handler.
  *
@@ -1051,6 +1071,12 @@ static int octep_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	pci_set_master(pdev);
 
+	if (!get_fw_ready_status(pdev)) {
+		dev_notice(&pdev->dev, "Firmware not ready; defer probe.\n");
+		err = -EPROBE_DEFER;
+		goto err_alloc_netdev;
+	}
+
 	netdev = alloc_etherdev_mq(sizeof(struct octep_device),
 				   OCTEP_MAX_QUEUES);
 	if (!netdev) {
Signature · 1 line
2.36.0
author maintainer
#2 lore raw

PATCH v4 2/8 octeon_ep: poll for control messages

In reply to Veerasenareddy Burru

Poll for control messages until interrupts are enabled.
All the interrupts are enabled in ndo_open().
Add ability to listen for notifications from firmware before ndo_open(). Once interrupts are enabled, this polling is disabled and all the messages are processed by bottom half of interrupt handler.

---
v3-> v4:
* resovled review comments
https://lore.kernel.org/all/Y+vIHjaUvkWXw55x@boxer/
- changed return type from integer to bool, where the possible return values are only 0 and 1.
- reverted an unnecessary change that caused rct breakage.

v2-> v3:
* resovled review comment; fixed reverse christmas tree.

v1 -> v2:
* removed device status oct->status, as it is not required with the modified implementation in 0001-xxxx.patch

 .../marvell/octeon_ep/octep_cn9k_pf.c         | 47 +++++++++----------
 .../ethernet/marvell/octeon_ep/octep_main.c   | 35 ++++++++++++++
 .../ethernet/marvell/octeon_ep/octep_main.h   | 11 ++++-
 .../marvell/octeon_ep/octep_regs_cn9k_pf.h    |  4 ++
 4 files changed, 70 insertions(+), 27 deletions(-)
drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +21 -26
index 6ad88d0fe43f..adc2279bc66d 100644
@@ -352,19 +352,28 @@ static void octep_setup_mbox_regs_cn93_pf(struct octep_device *oct, int q_no)
 	mbox->mbox_read_reg = oct->mmio[0].hw_addr + CN93_SDP_R_MBOX_VF_PF_DATA(q_no);
 }
 
-/* Mailbox Interrupt handler */
-static void cn93_handle_pf_mbox_intr(struct octep_device *oct)
+/* Process non-ioq interrupts required to keep pf interface running.
+ * OEI_RINT is needed for control mailbox
+ */
+static bool octep_poll_non_ioq_interrupts_cn93_pf(struct octep_device *oct)
 {
-	u64 mbox_int_val = 0ULL, val = 0ULL, qno = 0ULL;
+	bool handled = false;
+	u64 reg0;
 
-	mbox_int_val = readq(oct->mbox[0]->mbox_int_reg);
-	for (qno = 0; qno < OCTEP_MAX_VF; qno++) {
-		val = readq(oct->mbox[qno]->mbox_read_reg);
-		dev_dbg(&oct->pdev->dev,
-			"PF MBOX READ: val:%llx from VF:%llx\n", val, qno);
+	/* Check for OEI INTR */
+	reg0 = octep_read_csr64(oct, CN93_SDP_EPF_OEI_RINT);
+	if (reg0) {
+		dev_info(&oct->pdev->dev,
+			 "Received OEI_RINT intr: 0x%llx\n",
+			 reg0);
+		octep_write_csr64(oct, CN93_SDP_EPF_OEI_RINT, reg0);
+		if (reg0 & CN93_SDP_EPF_OEI_RINT_DATA_BIT_MBOX)
+			queue_work(octep_wq, &oct->ctrl_mbox_task);
+
+		handled = true;
 	}
 
-	writeq(mbox_int_val, oct->mbox[0]->mbox_int_reg);
+	return handled;
 }
 
 /* Interrupts handler for all non-queue generic interrupts. */
@@ -434,24 +443,9 @@ static irqreturn_t octep_non_ioq_intr_handler_cn93_pf(void *dev)
 		goto irq_handled;
 	}
 
-	/* Check for MBOX INTR */
-	reg_val = octep_read_csr64(oct, CN93_SDP_EPF_MBOX_RINT(0));
-	if (reg_val) {
-		dev_info(&pdev->dev,
-			 "Received MBOX_RINT intr: 0x%llx\n", reg_val);
-		cn93_handle_pf_mbox_intr(oct);
+	/* Check for MBOX INTR and OEI INTR */
+	if (octep_poll_non_ioq_interrupts_cn93_pf(oct))
 		goto irq_handled;
-	}
-
-	/* Check for OEI INTR */
-	reg_val = octep_read_csr64(oct, CN93_SDP_EPF_OEI_RINT);
-	if (reg_val) {
-		dev_info(&pdev->dev,
-			 "Received OEI_EINT intr: 0x%llx\n", reg_val);
-		octep_write_csr64(oct, CN93_SDP_EPF_OEI_RINT, reg_val);
-		queue_work(octep_wq, &oct->ctrl_mbox_task);
-		goto irq_handled;
-	}
 
 	/* Check for DMA INTR */
 	reg_val = octep_read_csr64(oct, CN93_SDP_EPF_DMA_RINT);
@@ -712,6 +706,7 @@ void octep_device_setup_cn93_pf(struct octep_device *oct)
 
 	oct->hw_ops.enable_interrupts = octep_enable_interrupts_cn93_pf;
 	oct->hw_ops.disable_interrupts = octep_disable_interrupts_cn93_pf;
+	oct->hw_ops.poll_non_ioq_interrupts = octep_poll_non_ioq_interrupts_cn93_pf;
 
 	oct->hw_ops.update_iq_read_idx = octep_update_iq_read_index_cn93_pf;
 
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +35 -0
index 0a50da52dc27..a3e4d9355681 100644
@@ -17,6 +17,7 @@
 #include "octep_main.h"
 #include "octep_ctrl_net.h"
 
+#define OCTEP_INTR_POLL_TIME_MSECS    100
 struct workqueue_struct *octep_wq;
 
 /* Supported Devices */
@@ -511,6 +512,7 @@ static int octep_open(struct net_device *netdev)
 	ret = octep_get_link_status(oct);
 	if (!ret)
 		octep_set_link_status(oct, true);
+	oct->poll_non_ioq_intr = false;
 
 	/* Enable the input and output queues for this Octeon device */
 	oct->hw_ops.enable_io_queues(oct);
@@ -572,6 +574,11 @@ static int octep_stop(struct net_device *netdev)
 	oct->hw_ops.reset_io_queues(oct);
 	octep_free_oqs(oct);
 	octep_free_iqs(oct);
+
+	oct->poll_non_ioq_intr = true;
+	queue_delayed_work(octep_wq, &oct->intr_poll_task,
+			   msecs_to_jiffies(OCTEP_INTR_POLL_TIME_MSECS));
+
 	netdev_info(netdev, "Device stopped !!\n");
 	return 0;
 }
@@ -864,6 +871,28 @@ static const struct net_device_ops octep_netdev_ops = {
 	.ndo_change_mtu          = octep_change_mtu,
 };
 
+/**
+ * octep_intr_poll_task - work queue task to process non-ioq interrupts.
+ *
+ * @work: pointer to mbox work_struct
+ *
+ * Process non-ioq interrupts to handle control mailbox, pfvf mailbox.
+ **/
+static void octep_intr_poll_task(struct work_struct *work)
+{
+	struct octep_device *oct = container_of(work, struct octep_device,
+						intr_poll_task.work);
+
+	if (!oct->poll_non_ioq_intr) {
+		dev_info(&oct->pdev->dev, "Interrupt poll task stopped.\n");
+		return;
+	}
+
+	oct->hw_ops.poll_non_ioq_interrupts(oct);
+	queue_delayed_work(octep_wq, &oct->intr_poll_task,
+			   msecs_to_jiffies(OCTEP_INTR_POLL_TIME_MSECS));
+}
+
 /**
  * octep_ctrl_mbox_task - work queue task to handle ctrl mbox messages.
  *
@@ -1099,6 +1128,10 @@ static int octep_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	}
 	INIT_WORK(&octep_dev->tx_timeout_task, octep_tx_timeout_task);
 	INIT_WORK(&octep_dev->ctrl_mbox_task, octep_ctrl_mbox_task);
+	INIT_DELAYED_WORK(&octep_dev->intr_poll_task, octep_intr_poll_task);
+	octep_dev->poll_non_ioq_intr = true;
+	queue_delayed_work(octep_wq, &octep_dev->intr_poll_task,
+			   msecs_to_jiffies(OCTEP_INTR_POLL_TIME_MSECS));
 
 	netdev->netdev_ops = &octep_netdev_ops;
 	octep_set_ethtool_ops(netdev);
@@ -1159,6 +1192,8 @@ static void octep_remove(struct pci_dev *pdev)
 	if (netdev->reg_state == NETREG_REGISTERED)
 		unregister_netdev(netdev);
 
+	oct->poll_non_ioq_intr = false;
+	cancel_delayed_work_sync(&oct->intr_poll_task);
 	octep_device_cleanup(oct);
 	pci_release_mem_regions(pdev);
 	free_netdev(netdev);
drivers/net/ethernet/marvell/octeon_ep/octep_main.h +10 -1
index 123ffc13754d..836d990ba3fa 100644
@@ -73,6 +73,7 @@ struct octep_hw_ops {
 
 	void (*enable_interrupts)(struct octep_device *oct);
 	void (*disable_interrupts)(struct octep_device *oct);
+	bool (*poll_non_ioq_interrupts)(struct octep_device *oct);
 
 	void (*enable_io_queues)(struct octep_device *oct);
 	void (*disable_io_queues)(struct octep_device *oct);
@@ -270,7 +271,15 @@ struct octep_device {
 
 	/* Work entry to handle ctrl mbox interrupt */
 	struct work_struct ctrl_mbox_task;
-
+	/* Wait queue for host to firmware requests */
+	wait_queue_head_t ctrl_req_wait_q;
+	/* List of objects waiting for h2f response */
+	struct list_head ctrl_req_wait_list;
+
+	/* Enable non-ioq interrupt polling */
+	bool poll_non_ioq_intr;
+	/* Work entry to poll non-ioq interrupts */
+	struct delayed_work intr_poll_task;
 };
 
 static inline u16 OCTEP_MAJOR_REV(struct octep_device *oct)
drivers/net/ethernet/marvell/octeon_ep/octep_regs_cn9k_pf.h +4 -0
index 3d5d39a52fe6..0466fd9a002d 100644
@@ -364,4 +364,8 @@
 
 /* Number of non-queue interrupts in CN93xx */
 #define    CN93_NUM_NON_IOQ_INTR    16
+
+/* bit 0 for control mbox interrupt */
+#define CN93_SDP_EPF_OEI_RINT_DATA_BIT_MBOX	BIT_ULL(0)
+
 #endif /* _OCTEP_REGS_CN9K_PF_H_ */
Signature · 1 line
2.36.0
author maintainer
#3 lore raw

PATCH v4 3/8 octeon_ep: control mailbox for multiple PFs

In reply to Veerasenareddy Burru

Add control mailbox support for multiple PFs.
Update control mbox base address calculation based on PF function link.

---
v3 -> v4:
* resovled review comments
https://lore.kernel.org/all/Y+vJkPO1UZPDSFT2@boxer/
- fixed rct violation.

v2 -> v3:
* no change

v1 -> v2:
* no change

 .../ethernet/marvell/octeon_ep/octep_cn9k_pf.c   | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +15 -1
index adc2279bc66d..e2503c9bc8a1 100644
@@ -13,6 +13,9 @@
 #include "octep_main.h"
 #include "octep_regs_cn9k_pf.h"
 
+#define CTRL_MBOX_MAX_PF	128
+#define CTRL_MBOX_SZ		((size_t)(0x400000 / CTRL_MBOX_MAX_PF))
+
 /* Names of Hardware non-queue generic interrupts */
 static char *cn93_non_ioq_msix_names[] = {
 	"epf_ire_rint",
@@ -198,7 +201,9 @@ static void octep_init_config_cn93_pf(struct octep_device *oct)
 {
 	struct octep_config *conf = oct->conf;
 	struct pci_dev *pdev = oct->pdev;
+	u8 link = 0;
 	u64 val;
+	int pos;
 
 	/* Read ring configuration:
 	 * PF ring count, number of VFs and rings per VF supported
@@ -234,7 +239,16 @@ static void octep_init_config_cn93_pf(struct octep_device *oct)
 	conf->msix_cfg.ioq_msix = conf->pf_ring_cfg.active_io_rings;
 	conf->msix_cfg.non_ioq_msix_names = cn93_non_ioq_msix_names;
 
-	conf->ctrl_mbox_cfg.barmem_addr = (void __iomem *)oct->mmio[2].hw_addr + (0x400000ull * 7);
+	pos = pci_find_ext_capability(oct->pdev, PCI_EXT_CAP_ID_SRIOV);
+	if (pos) {
+		pci_read_config_byte(oct->pdev,
+				     pos + PCI_SRIOV_FUNC_LINK,
+				     &link);
+		link = PCI_DEVFN(PCI_SLOT(oct->pdev->devfn), link);
+	}
+	conf->ctrl_mbox_cfg.barmem_addr = (void __iomem *)oct->mmio[2].hw_addr +
+					   (0x400000ull * 7) +
+					   (link * CTRL_MBOX_SZ);
 }
 
 /* Setup registers for a hardware Tx Queue  */
Signature · 1 line
2.36.0
author maintainer
#4 lore raw

PATCH v4 4/8 octeon_ep: add separate mailbox command and response queues

In reply to Veerasenareddy Burru

Enhance control mailbox protocol to support following
- separate command and response queues
* command queue to send control commands to firmware.
* response queue to receive responses and notifications from firmware.
- variable size messages using scatter/gather

---
v3 -> v4:
* addressed review comments
https://lore.kernel.org/all/Y+0AW3b9No9pyWrr@boxer/
- fixed rct violation.
- separated out changes to APIs accepting function ID to work for PF and VFs. Separated changes are included in patch 0005.
- modified return types from int to void for functions where.
- renamed write_mbox_data() to octep_write_mbox_data() and now returns void.
- renamed read_mbox_data() to octep_read_mbox_data() and now returns void.
- removed num argument from octep_ctrl_mbox_send/recv APIs.
- renamed send_mbox_req() to octep_send_mbox_req().
- octep_ctrl_net_recv_fw_messages() now returns void.

v2 -> v3:
* no change

v1 -> v2:
* modified the patch to work with device status "oct->status" removed.

 .../marvell/octeon_ep/octep_ctrl_mbox.c       | 276 ++++++++-------
 .../marvell/octeon_ep/octep_ctrl_mbox.h       |  88 ++---
 .../marvell/octeon_ep/octep_ctrl_net.c        | 330 ++++++++++++------
 .../marvell/octeon_ep/octep_ctrl_net.h        | 164 +++++----
 .../marvell/octeon_ep/octep_ethtool.c         |   6 +-
 .../ethernet/marvell/octeon_ep/octep_main.c   |  76 +---
 6 files changed, 529 insertions(+), 411 deletions(-)
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_mbox.c +150 -126
index 39322e4dd100..a4ee6f3ae354 100644
@@ -24,41 +24,49 @@
 /* Time in msecs to wait for message response */
 #define OCTEP_CTRL_MBOX_MSG_WAIT_MS			10
 
-#define OCTEP_CTRL_MBOX_INFO_MAGIC_NUM_OFFSET(m)	(m)
-#define OCTEP_CTRL_MBOX_INFO_BARMEM_SZ_OFFSET(m)	((m) + 8)
-#define OCTEP_CTRL_MBOX_INFO_HOST_STATUS_OFFSET(m)	((m) + 24)
-#define OCTEP_CTRL_MBOX_INFO_FW_STATUS_OFFSET(m)	((m) + 144)
-
-#define OCTEP_CTRL_MBOX_H2FQ_INFO_OFFSET(m)		((m) + OCTEP_CTRL_MBOX_INFO_SZ)
-#define OCTEP_CTRL_MBOX_H2FQ_PROD_OFFSET(m)		(OCTEP_CTRL_MBOX_H2FQ_INFO_OFFSET(m))
-#define OCTEP_CTRL_MBOX_H2FQ_CONS_OFFSET(m)		((OCTEP_CTRL_MBOX_H2FQ_INFO_OFFSET(m)) + 4)
-#define OCTEP_CTRL_MBOX_H2FQ_ELEM_SZ_OFFSET(m)		((OCTEP_CTRL_MBOX_H2FQ_INFO_OFFSET(m)) + 8)
-#define OCTEP_CTRL_MBOX_H2FQ_ELEM_CNT_OFFSET(m)		((OCTEP_CTRL_MBOX_H2FQ_INFO_OFFSET(m)) + 12)
-
-#define OCTEP_CTRL_MBOX_F2HQ_INFO_OFFSET(m)		((m) + \
-							 OCTEP_CTRL_MBOX_INFO_SZ + \
-							 OCTEP_CTRL_MBOX_H2FQ_INFO_SZ)
-#define OCTEP_CTRL_MBOX_F2HQ_PROD_OFFSET(m)		(OCTEP_CTRL_MBOX_F2HQ_INFO_OFFSET(m))
-#define OCTEP_CTRL_MBOX_F2HQ_CONS_OFFSET(m)		((OCTEP_CTRL_MBOX_F2HQ_INFO_OFFSET(m)) + 4)
-#define OCTEP_CTRL_MBOX_F2HQ_ELEM_SZ_OFFSET(m)		((OCTEP_CTRL_MBOX_F2HQ_INFO_OFFSET(m)) + 8)
-#define OCTEP_CTRL_MBOX_F2HQ_ELEM_CNT_OFFSET(m)		((OCTEP_CTRL_MBOX_F2HQ_INFO_OFFSET(m)) + 12)
-
-#define OCTEP_CTRL_MBOX_Q_OFFSET(m, i)			((m) + \
-							 (sizeof(struct octep_ctrl_mbox_msg) * (i)))
-
-static u32 octep_ctrl_mbox_circq_inc(u32 index, u32 mask)
+/* Size of mbox info in bytes */
+#define OCTEP_CTRL_MBOX_INFO_SZ				256
+/* Size of mbox host to fw queue info in bytes */
+#define OCTEP_CTRL_MBOX_H2FQ_INFO_SZ			16
+/* Size of mbox fw to host queue info in bytes */
+#define OCTEP_CTRL_MBOX_F2HQ_INFO_SZ			16
+
+#define OCTEP_CTRL_MBOX_TOTAL_INFO_SZ	(OCTEP_CTRL_MBOX_INFO_SZ + \
+					 OCTEP_CTRL_MBOX_H2FQ_INFO_SZ + \
+					 OCTEP_CTRL_MBOX_F2HQ_INFO_SZ)
+
+#define OCTEP_CTRL_MBOX_INFO_MAGIC_NUM(m)	(m)
+#define OCTEP_CTRL_MBOX_INFO_BARMEM_SZ(m)	((m) + 8)
+#define OCTEP_CTRL_MBOX_INFO_HOST_STATUS(m)	((m) + 24)
+#define OCTEP_CTRL_MBOX_INFO_FW_STATUS(m)	((m) + 144)
+
+#define OCTEP_CTRL_MBOX_H2FQ_INFO(m)	((m) + OCTEP_CTRL_MBOX_INFO_SZ)
+#define OCTEP_CTRL_MBOX_H2FQ_PROD(m)	(OCTEP_CTRL_MBOX_H2FQ_INFO(m))
+#define OCTEP_CTRL_MBOX_H2FQ_CONS(m)	((OCTEP_CTRL_MBOX_H2FQ_INFO(m)) + 4)
+#define OCTEP_CTRL_MBOX_H2FQ_SZ(m)	((OCTEP_CTRL_MBOX_H2FQ_INFO(m)) + 8)
+
+#define OCTEP_CTRL_MBOX_F2HQ_INFO(m)	((m) + \
+					 OCTEP_CTRL_MBOX_INFO_SZ + \
+					 OCTEP_CTRL_MBOX_H2FQ_INFO_SZ)
+#define OCTEP_CTRL_MBOX_F2HQ_PROD(m)	(OCTEP_CTRL_MBOX_F2HQ_INFO(m))
+#define OCTEP_CTRL_MBOX_F2HQ_CONS(m)	((OCTEP_CTRL_MBOX_F2HQ_INFO(m)) + 4)
+#define OCTEP_CTRL_MBOX_F2HQ_SZ(m)	((OCTEP_CTRL_MBOX_F2HQ_INFO(m)) + 8)
+
+static const u32 mbox_hdr_sz = sizeof(union octep_ctrl_mbox_msg_hdr);
+
+static u32 octep_ctrl_mbox_circq_inc(u32 index, u32 inc, u32 sz)
 {
-	return (index + 1) & mask;
+	return (index + inc) % sz;
 }
 
-static u32 octep_ctrl_mbox_circq_space(u32 pi, u32 ci, u32 mask)
+static u32 octep_ctrl_mbox_circq_space(u32 pi, u32 ci, u32 sz)
 {
-	return mask - ((pi - ci) & mask);
+	return sz - (abs(pi - ci) % sz);
 }
 
-static u32 octep_ctrl_mbox_circq_depth(u32 pi, u32 ci, u32 mask)
+static u32 octep_ctrl_mbox_circq_depth(u32 pi, u32 ci, u32 sz)
 {
-	return ((pi - ci) & mask);
+	return (abs(pi - ci) % sz);
 }
 
 int octep_ctrl_mbox_init(struct octep_ctrl_mbox *mbox)
@@ -73,153 +81,170 @@ int octep_ctrl_mbox_init(struct octep_ctrl_mbox *mbox)
 		return -EINVAL;
 	}
 
-	magic_num = readq(OCTEP_CTRL_MBOX_INFO_MAGIC_NUM_OFFSET(mbox->barmem));
+	magic_num = readq(OCTEP_CTRL_MBOX_INFO_MAGIC_NUM(mbox->barmem));
 	if (magic_num != OCTEP_CTRL_MBOX_MAGIC_NUMBER) {
 		pr_info("octep_ctrl_mbox : Invalid magic number %llx\n", magic_num);
 		return -EINVAL;
 	}
 
-	status = readq(OCTEP_CTRL_MBOX_INFO_FW_STATUS_OFFSET(mbox->barmem));
+	status = readq(OCTEP_CTRL_MBOX_INFO_FW_STATUS(mbox->barmem));
 	if (status != OCTEP_CTRL_MBOX_STATUS_READY) {
 		pr_info("octep_ctrl_mbox : Firmware is not ready.\n");
 		return -EINVAL;
 	}
 
-	mbox->barmem_sz = readl(OCTEP_CTRL_MBOX_INFO_BARMEM_SZ_OFFSET(mbox->barmem));
+	mbox->barmem_sz = readl(OCTEP_CTRL_MBOX_INFO_BARMEM_SZ(mbox->barmem));
 
-	writeq(OCTEP_CTRL_MBOX_STATUS_INIT, OCTEP_CTRL_MBOX_INFO_HOST_STATUS_OFFSET(mbox->barmem));
+	writeq(OCTEP_CTRL_MBOX_STATUS_INIT,
+	       OCTEP_CTRL_MBOX_INFO_HOST_STATUS(mbox->barmem));
 
-	mbox->h2fq.elem_cnt = readl(OCTEP_CTRL_MBOX_H2FQ_ELEM_CNT_OFFSET(mbox->barmem));
-	mbox->h2fq.elem_sz = readl(OCTEP_CTRL_MBOX_H2FQ_ELEM_SZ_OFFSET(mbox->barmem));
-	mbox->h2fq.mask = (mbox->h2fq.elem_cnt - 1);
-	mutex_init(&mbox->h2fq_lock);
+	mbox->h2fq.sz = readl(OCTEP_CTRL_MBOX_H2FQ_SZ(mbox->barmem));
+	mbox->h2fq.hw_prod = OCTEP_CTRL_MBOX_H2FQ_PROD(mbox->barmem);
+	mbox->h2fq.hw_cons = OCTEP_CTRL_MBOX_H2FQ_CONS(mbox->barmem);
+	mbox->h2fq.hw_q = mbox->barmem + OCTEP_CTRL_MBOX_TOTAL_INFO_SZ;
 
-	mbox->f2hq.elem_cnt = readl(OCTEP_CTRL_MBOX_F2HQ_ELEM_CNT_OFFSET(mbox->barmem));
-	mbox->f2hq.elem_sz = readl(OCTEP_CTRL_MBOX_F2HQ_ELEM_SZ_OFFSET(mbox->barmem));
-	mbox->f2hq.mask = (mbox->f2hq.elem_cnt - 1);
-	mutex_init(&mbox->f2hq_lock);
-
-	mbox->h2fq.hw_prod = OCTEP_CTRL_MBOX_H2FQ_PROD_OFFSET(mbox->barmem);
-	mbox->h2fq.hw_cons = OCTEP_CTRL_MBOX_H2FQ_CONS_OFFSET(mbox->barmem);
-	mbox->h2fq.hw_q = mbox->barmem +
-			  OCTEP_CTRL_MBOX_INFO_SZ +
-			  OCTEP_CTRL_MBOX_H2FQ_INFO_SZ +
-			  OCTEP_CTRL_MBOX_F2HQ_INFO_SZ;
-
-	mbox->f2hq.hw_prod = OCTEP_CTRL_MBOX_F2HQ_PROD_OFFSET(mbox->barmem);
-	mbox->f2hq.hw_cons = OCTEP_CTRL_MBOX_F2HQ_CONS_OFFSET(mbox->barmem);
-	mbox->f2hq.hw_q = mbox->h2fq.hw_q +
-			  ((mbox->h2fq.elem_sz + sizeof(union octep_ctrl_mbox_msg_hdr)) *
-			   mbox->h2fq.elem_cnt);
+	mbox->f2hq.sz = readl(OCTEP_CTRL_MBOX_F2HQ_SZ(mbox->barmem));
+	mbox->f2hq.hw_prod = OCTEP_CTRL_MBOX_F2HQ_PROD(mbox->barmem);
+	mbox->f2hq.hw_cons = OCTEP_CTRL_MBOX_F2HQ_CONS(mbox->barmem);
+	mbox->f2hq.hw_q = mbox->barmem +
+			  OCTEP_CTRL_MBOX_TOTAL_INFO_SZ +
+			  mbox->h2fq.sz;
 
 	/* ensure ready state is seen after everything is initialized */
 	wmb();
-	writeq(OCTEP_CTRL_MBOX_STATUS_READY, OCTEP_CTRL_MBOX_INFO_HOST_STATUS_OFFSET(mbox->barmem));
+	writeq(OCTEP_CTRL_MBOX_STATUS_READY,
+	       OCTEP_CTRL_MBOX_INFO_HOST_STATUS(mbox->barmem));
 
 	pr_info("Octep ctrl mbox : Init successful.\n");
 
 	return 0;
 }
 
+static void
+octep_write_mbox_data(struct octep_ctrl_mbox_q *q, u32 *pi, u32 ci, void *buf, u32 w_sz)
+{
+	u8 __iomem *qbuf;
+	u32 cp_sz;
+
+	/* Assumption: Caller has ensured enough write space */
+	qbuf = (q->hw_q + *pi);
+	if (*pi < ci) {
+		/* copy entire w_sz */
+		memcpy_toio(qbuf, buf, w_sz);
+		*pi = octep_ctrl_mbox_circq_inc(*pi, w_sz, q->sz);
+	} else {
+		/* copy up to end of queue */
+		cp_sz = min((q->sz - *pi), w_sz);
+		memcpy_toio(qbuf, buf, cp_sz);
+		w_sz -= cp_sz;
+		*pi = octep_ctrl_mbox_circq_inc(*pi, cp_sz, q->sz);
+		if (w_sz) {
+			/* roll over and copy remaining w_sz */
+			buf += cp_sz;
+			qbuf = (q->hw_q + *pi);
+			memcpy_toio(qbuf, buf, w_sz);
+			*pi = octep_ctrl_mbox_circq_inc(*pi, w_sz, q->sz);
+		}
+	}
+}
+
 int octep_ctrl_mbox_send(struct octep_ctrl_mbox *mbox, struct octep_ctrl_mbox_msg *msg)
 {
-	unsigned long timeout = msecs_to_jiffies(OCTEP_CTRL_MBOX_MSG_TIMEOUT_MS);
-	unsigned long period = msecs_to_jiffies(OCTEP_CTRL_MBOX_MSG_WAIT_MS);
+	struct octep_ctrl_mbox_msg_buf *sg;
 	struct octep_ctrl_mbox_q *q;
-	unsigned long expire;
-	u64 *mbuf, *word0;
-	u8 __iomem *qidx;
-	u16 pi, ci;
-	int i;
+	u32 pi, ci, buf_sz, w_sz;
+	int s;
 
 	if (!mbox || !msg)
 		return -EINVAL;
 
+	if (readq(OCTEP_CTRL_MBOX_INFO_FW_STATUS(mbox->barmem)) != OCTEP_CTRL_MBOX_STATUS_READY)
+		return -EIO;
+
+	mutex_lock(&mbox->h2fq_lock);
 	q = &mbox->h2fq;
 	pi = readl(q->hw_prod);
 	ci = readl(q->hw_cons);
 
-	if (!octep_ctrl_mbox_circq_space(pi, ci, q->mask))
-		return -ENOMEM;
-
-	qidx = OCTEP_CTRL_MBOX_Q_OFFSET(q->hw_q, pi);
-	mbuf = (u64 *)msg->msg;
-	word0 = &msg->hdr.word0;
-
-	mutex_lock(&mbox->h2fq_lock);
-	for (i = 1; i <= msg->hdr.sizew; i++)
-		writeq(*mbuf++, (qidx + (i * 8)));
-
-	writeq(*word0, qidx);
+	if (octep_ctrl_mbox_circq_space(pi, ci, q->sz) < (msg->hdr.s.sz + mbox_hdr_sz)) {
+		mutex_unlock(&mbox->f2hq_lock);
+		return -EAGAIN;
+	}
 
-	pi = octep_ctrl_mbox_circq_inc(pi, q->mask);
+	octep_write_mbox_data(q, &pi, ci, (void *)&msg->hdr, mbox_hdr_sz);
+	buf_sz = msg->hdr.s.sz;
+	for (s = 0; ((s < msg->sg_num) && (buf_sz > 0)); s++) {
+		sg = &msg->sg_list[s];
+		w_sz = (sg->sz <= buf_sz) ? sg->sz : buf_sz;
+		octep_write_mbox_data(q, &pi, ci, sg->msg, w_sz);
+		buf_sz -= w_sz;
+	}
 	writel(pi, q->hw_prod);
 	mutex_unlock(&mbox->h2fq_lock);
 
-	/* don't check for notification response */
-	if (msg->hdr.flags & OCTEP_CTRL_MBOX_MSG_HDR_FLAG_NOTIFY)
-		return 0;
-
-	expire = jiffies + timeout;
-	while (true) {
-		*word0 = readq(qidx);
-		if (msg->hdr.flags == OCTEP_CTRL_MBOX_MSG_HDR_FLAG_RESP)
-			break;
-		schedule_timeout_interruptible(period);
-		if (signal_pending(current) || time_after(jiffies, expire)) {
-			pr_info("octep_ctrl_mbox: Timed out\n");
-			return -EBUSY;
+	return 0;
+}
+
+static void
+octep_read_mbox_data(struct octep_ctrl_mbox_q *q, u32 pi, u32 *ci, void *buf, u32 r_sz)
+{
+	u8 __iomem *qbuf;
+	u32 cp_sz;
+
+	/* Assumption: Caller has ensured enough read space */
+	qbuf = (q->hw_q + *ci);
+	if (*ci < pi) {
+		/* copy entire r_sz */
+		memcpy_fromio(buf, qbuf, r_sz);
+		*ci = octep_ctrl_mbox_circq_inc(*ci, r_sz, q->sz);
+	} else {
+		/* copy up to end of queue */
+		cp_sz = min((q->sz - *ci), r_sz);
+		memcpy_fromio(buf, qbuf, cp_sz);
+		r_sz -= cp_sz;
+		*ci = octep_ctrl_mbox_circq_inc(*ci, cp_sz, q->sz);
+		if (r_sz) {
+			/* roll over and copy remaining r_sz */
+			buf += cp_sz;
+			qbuf = (q->hw_q + *ci);
+			memcpy_fromio(buf, qbuf, r_sz);
+			*ci = octep_ctrl_mbox_circq_inc(*ci, r_sz, q->sz);
 		}
 	}
-	mbuf = (u64 *)msg->msg;
-	for (i = 1; i <= msg->hdr.sizew; i++)
-		*mbuf++ = readq(qidx + (i * 8));
-
-	return 0;
 }
 
 int octep_ctrl_mbox_recv(struct octep_ctrl_mbox *mbox, struct octep_ctrl_mbox_msg *msg)
 {
+	struct octep_ctrl_mbox_msg_buf *sg;
+	u32 pi, ci, r_sz, buf_sz, q_depth;
 	struct octep_ctrl_mbox_q *q;
-	u32 count, pi, ci;
-	u8 __iomem *qidx;
-	u64 *mbuf;
-	int i;
+	int s;
 
-	if (!mbox || !msg)
-		return -EINVAL;
+	if (readq(OCTEP_CTRL_MBOX_INFO_FW_STATUS(mbox->barmem)) != OCTEP_CTRL_MBOX_STATUS_READY)
+		return -EIO;
 
+	mutex_lock(&mbox->f2hq_lock);
 	q = &mbox->f2hq;
 	pi = readl(q->hw_prod);
 	ci = readl(q->hw_cons);
-	count = octep_ctrl_mbox_circq_depth(pi, ci, q->mask);
-	if (!count)
-		return -EAGAIN;
-
-	qidx = OCTEP_CTRL_MBOX_Q_OFFSET(q->hw_q, ci);
-	mbuf = (u64 *)msg->msg;
 
-	mutex_lock(&mbox->f2hq_lock);
-
-	msg->hdr.word0 = readq(qidx);
-	for (i = 1; i <= msg->hdr.sizew; i++)
-		*mbuf++ = readq(qidx + (i * 8));
+	q_depth = octep_ctrl_mbox_circq_depth(pi, ci, q->sz);
+	if (q_depth < mbox_hdr_sz) {
+		mutex_unlock(&mbox->f2hq_lock);
+		return -EAGAIN;
+	}
 
-	ci = octep_ctrl_mbox_circq_inc(ci, q->mask);
+	octep_read_mbox_data(q, pi, &ci, (void *)&msg->hdr, mbox_hdr_sz);
+	buf_sz = msg->hdr.s.sz;
+	for (s = 0; ((s < msg->sg_num) && (buf_sz > 0)); s++) {
+		sg = &msg->sg_list[s];
+		r_sz = (sg->sz <= buf_sz) ? sg->sz : buf_sz;
+		octep_read_mbox_data(q, pi, &ci, sg->msg, r_sz);
+		buf_sz -= r_sz;
+	}
 	writel(ci, q->hw_cons);
-
 	mutex_unlock(&mbox->f2hq_lock);
 
-	if (msg->hdr.flags != OCTEP_CTRL_MBOX_MSG_HDR_FLAG_REQ || !mbox->process_req)
-		return 0;
-
-	mbox->process_req(mbox->user_ctx, msg);
-	mbuf = (u64 *)msg->msg;
-	for (i = 1; i <= msg->hdr.sizew; i++)
-		writeq(*mbuf++, (qidx + (i * 8)));
-
-	writeq(msg->hdr.word0, qidx);
-
 	return 0;
 }
 
@@ -227,18 +252,17 @@ int octep_ctrl_mbox_uninit(struct octep_ctrl_mbox *mbox)
 {
 	if (!mbox)
 		return -EINVAL;
+	if (!mbox->barmem)
+		return -EINVAL;
 
-	writeq(OCTEP_CTRL_MBOX_STATUS_UNINIT,
-	       OCTEP_CTRL_MBOX_INFO_HOST_STATUS_OFFSET(mbox->barmem));
+	writeq(OCTEP_CTRL_MBOX_STATUS_INVALID,
+	       OCTEP_CTRL_MBOX_INFO_HOST_STATUS(mbox->barmem));
 	/* ensure uninit state is written before uninitialization */
 	wmb();
 
 	mutex_destroy(&mbox->h2fq_lock);
 	mutex_destroy(&mbox->f2hq_lock);
 
-	writeq(OCTEP_CTRL_MBOX_STATUS_INVALID,
-	       OCTEP_CTRL_MBOX_INFO_HOST_STATUS_OFFSET(mbox->barmem));
-
 	pr_info("Octep ctrl mbox : Uninit successful.\n");
 
 	return 0;
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_mbox.h +46 -42

162 lines not on this page · raw message

drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +220 -110

405 lines not on this page · raw message

drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.h +92 -72

260 lines not on this page · raw message

drivers/net/ethernet/marvell/octeon_ep/octep_ethtool.c +3 -3
index 87ef129b269a..a1ddb64791f2 100644
@@ -150,7 +150,7 @@ octep_get_ethtool_stats(struct net_device *netdev,
 	rx_packets = 0;
 	rx_bytes = 0;
 
-	octep_get_if_stats(oct);
+	octep_ctrl_net_get_if_stats(oct);
 	iface_tx_stats = &oct->iface_tx_stats;
 	iface_rx_stats = &oct->iface_rx_stats;
 
@@ -283,7 +283,7 @@ static int octep_get_link_ksettings(struct net_device *netdev,
 	ethtool_link_ksettings_zero_link_mode(cmd, supported);
 	ethtool_link_ksettings_zero_link_mode(cmd, advertising);
 
-	octep_get_link_info(oct);
+	octep_ctrl_net_get_link_info(oct);
 
 	advertised_modes = oct->link_info.advertised_modes;
 	supported_modes = oct->link_info.supported_modes;
@@ -439,7 +439,7 @@ static int octep_set_link_ksettings(struct net_device *netdev,
 	link_info_new.speed = cmd->base.speed;
 	link_info_new.autoneg = autoneg;
 
-	err = octep_set_link_info(oct, &link_info_new);
+	err = octep_ctrl_net_set_link_info(oct, &link_info_new, true);
 	if (err)
 		return err;
 
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +18 -58

148 lines not on this page · raw message

Signature · 1 line
2.36.0
author maintainer
#5 lore raw

PATCH v4 5/8 octeon_ep: include function id in mailbox commands

In reply to Veerasenareddy Burru

Extend control command structure to include vfid and update APIs to accept VF ID.

---
v3 -> v4:
* address review comments
https://lore.kernel.org/all/Y+0AW3b9No9pyWrr@boxer/
* subset of 0004-xxx.patch moved to this new patch.

 .../marvell/octeon_ep/octep_ctrl_net.c        | 43 +++++++++++--------
 .../marvell/octeon_ep/octep_ctrl_net.h        | 28 ++++++++----
 .../marvell/octeon_ep/octep_ethtool.c         |  7 +--
 .../ethernet/marvell/octeon_ep/octep_main.c   | 24 +++++++----
 4 files changed, 63 insertions(+), 39 deletions(-)
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +24 -19
index 8d4d74e18a67..cef4bc3b1ec0 100644
@@ -22,7 +22,8 @@ static const u32 link_info_sz = sizeof(struct octep_ctrl_net_link_info);
 static const u32 get_stats_sz = sizeof(struct octep_ctrl_net_h2f_req_cmd_get_stats);
 static atomic_t ctrl_net_msg_id;
 
-static void init_send_req(struct octep_ctrl_mbox_msg *msg, void *buf, u16 sz)
+static void init_send_req(struct octep_ctrl_mbox_msg *msg, void *buf,
+			  u16 sz, int vfid)
 {
 	msg->hdr.s.flags = OCTEP_CTRL_MBOX_MSG_HDR_FLAG_REQ;
 	msg->hdr.s.msg_id = atomic_inc_return(&ctrl_net_msg_id) &
@@ -31,6 +32,10 @@ static void init_send_req(struct octep_ctrl_mbox_msg *msg, void *buf, u16 sz)
 	msg->sg_num = 1;
 	msg->sg_list[0].msg = buf;
 	msg->sg_list[0].sz = msg->hdr.s.sz;
+	if (vfid != OCTEP_CTRL_NET_INVALID_VFID) {
+		msg->hdr.s.is_vf = 1;
+		msg->hdr.s.vf_idx = vfid;
+	}
 }
 
 static int octep_send_mbox_req(struct octep_device *oct,
@@ -91,13 +96,13 @@ int octep_ctrl_net_init(struct octep_device *oct)
 	return 0;
 }
 
-int octep_ctrl_net_get_link_status(struct octep_device *oct)
+int octep_ctrl_net_get_link_status(struct octep_device *oct, int vfid)
 {
 	struct octep_ctrl_net_wait_data d = {0};
 	struct octep_ctrl_net_h2f_req *req = &d.data.req;
 	int err;
 
-	init_send_req(&d.msg, (void *)req, state_sz);
+	init_send_req(&d.msg, (void *)req, state_sz, vfid);
 	req->hdr.s.cmd = OCTEP_CTRL_NET_H2F_CMD_LINK_STATUS;
 	req->link.cmd = OCTEP_CTRL_NET_CMD_GET;
 	err = octep_send_mbox_req(oct, &d, true);
@@ -107,13 +112,13 @@ int octep_ctrl_net_get_link_status(struct octep_device *oct)
 	return d.data.resp.link.state;
 }
 
-int octep_ctrl_net_set_link_status(struct octep_device *oct, bool up,
+int octep_ctrl_net_set_link_status(struct octep_device *oct, int vfid, bool up,
 				   bool wait_for_response)
 {
 	struct octep_ctrl_net_wait_data d = {0};
 	struct octep_ctrl_net_h2f_req *req = &d.data.req;
 
-	init_send_req(&d.msg, req, state_sz);
+	init_send_req(&d.msg, req, state_sz, vfid);
 	req->hdr.s.cmd = OCTEP_CTRL_NET_H2F_CMD_LINK_STATUS;
 	req->link.cmd = OCTEP_CTRL_NET_CMD_SET;
 	req->link.state = (up) ? OCTEP_CTRL_NET_STATE_UP :
@@ -122,13 +127,13 @@ int octep_ctrl_net_set_link_status(struct octep_device *oct, bool up,
 	return octep_send_mbox_req(oct, &d, wait_for_response);
 }
 
-int octep_ctrl_net_set_rx_state(struct octep_device *oct, bool up,
+int octep_ctrl_net_set_rx_state(struct octep_device *oct, int vfid, bool up,
 				bool wait_for_response)
 {
 	struct octep_ctrl_net_wait_data d = {0};
 	struct octep_ctrl_net_h2f_req *req = &d.data.req;
 
-	init_send_req(&d.msg, req, state_sz);
+	init_send_req(&d.msg, req, state_sz, vfid);
 	req->hdr.s.cmd = OCTEP_CTRL_NET_H2F_CMD_RX_STATE;
 	req->link.cmd = OCTEP_CTRL_NET_CMD_SET;
 	req->link.state = (up) ? OCTEP_CTRL_NET_STATE_UP :
@@ -137,13 +142,13 @@ int octep_ctrl_net_set_rx_state(struct octep_device *oct, bool up,
 	return octep_send_mbox_req(oct, &d, wait_for_response);
 }
 
-int octep_ctrl_net_get_mac_addr(struct octep_device *oct, u8 *addr)
+int octep_ctrl_net_get_mac_addr(struct octep_device *oct, int vfid, u8 *addr)
 {
 	struct octep_ctrl_net_wait_data d = {0};
 	struct octep_ctrl_net_h2f_req *req = &d.data.req;
 	int err;
 
-	init_send_req(&d.msg, req, mac_sz);
+	init_send_req(&d.msg, req, mac_sz, vfid);
 	req->hdr.s.cmd = OCTEP_CTRL_NET_H2F_CMD_MAC;
 	req->link.cmd = OCTEP_CTRL_NET_CMD_GET;
 	err = octep_send_mbox_req(oct, &d, true);
@@ -155,13 +160,13 @@ int octep_ctrl_net_get_mac_addr(struct octep_device *oct, u8 *addr)
 	return 0;
 }
 
-int octep_ctrl_net_set_mac_addr(struct octep_device *oct, u8 *addr,
+int octep_ctrl_net_set_mac_addr(struct octep_device *oct, int vfid, u8 *addr,
 				bool wait_for_response)
 {
 	struct octep_ctrl_net_wait_data d = {0};
 	struct octep_ctrl_net_h2f_req *req = &d.data.req;
 
-	init_send_req(&d.msg, req, mac_sz);
+	init_send_req(&d.msg, req, mac_sz, vfid);
 	req->hdr.s.cmd = OCTEP_CTRL_NET_H2F_CMD_MAC;
 	req->mac.cmd = OCTEP_CTRL_NET_CMD_SET;
 	memcpy(&req->mac.addr, addr, ETH_ALEN);
@@ -169,13 +174,13 @@ int octep_ctrl_net_set_mac_addr(struct octep_device *oct, u8 *addr,
 	return octep_send_mbox_req(oct, &d, wait_for_response);
 }
 
-int octep_ctrl_net_set_mtu(struct octep_device *oct, int mtu,
+int octep_ctrl_net_set_mtu(struct octep_device *oct, int vfid, int mtu,
 			   bool wait_for_response)
 {
 	struct octep_ctrl_net_wait_data d = {0};
 	struct octep_ctrl_net_h2f_req *req = &d.data.req;
 
-	init_send_req(&d.msg, req, mtu_sz);
+	init_send_req(&d.msg, req, mtu_sz, vfid);
 	req->hdr.s.cmd = OCTEP_CTRL_NET_H2F_CMD_MTU;
 	req->mtu.cmd = OCTEP_CTRL_NET_CMD_SET;
 	req->mtu.val = mtu;
@@ -183,7 +188,7 @@ int octep_ctrl_net_set_mtu(struct octep_device *oct, int mtu,
 	return octep_send_mbox_req(oct, &d, wait_for_response);
 }
 
-int octep_ctrl_net_get_if_stats(struct octep_device *oct)
+int octep_ctrl_net_get_if_stats(struct octep_device *oct, int vfid)
 {
 	struct octep_ctrl_net_wait_data d = {0};
 	struct octep_ctrl_net_h2f_req *req = &d.data.req;
@@ -191,7 +196,7 @@ int octep_ctrl_net_get_if_stats(struct octep_device *oct)
 	void __iomem *iface_tx_stats;
 	int err;
 
-	init_send_req(&d.msg, req, get_stats_sz);
+	init_send_req(&d.msg, req, get_stats_sz, vfid);
 	req->hdr.s.cmd = OCTEP_CTRL_NET_H2F_CMD_GET_IF_STATS;
 	req->get_stats.offset = oct->ctrl_mbox_ifstats_offset;
 	err = octep_send_mbox_req(oct, &d, true);
@@ -207,14 +212,14 @@ int octep_ctrl_net_get_if_stats(struct octep_device *oct)
 	return 0;
 }
 
-int octep_ctrl_net_get_link_info(struct octep_device *oct)
+int octep_ctrl_net_get_link_info(struct octep_device *oct, int vfid)
 {
 	struct octep_ctrl_net_wait_data d = {0};
 	struct octep_ctrl_net_h2f_req *req = &d.data.req;
 	struct octep_ctrl_net_h2f_resp *resp;
 	int err;
 
-	init_send_req(&d.msg, req, link_info_sz);
+	init_send_req(&d.msg, req, link_info_sz, vfid);
 	req->hdr.s.cmd = OCTEP_CTRL_NET_H2F_CMD_LINK_INFO;
 	req->link_info.cmd = OCTEP_CTRL_NET_CMD_GET;
 	err = octep_send_mbox_req(oct, &d, true);
@@ -231,14 +236,14 @@ int octep_ctrl_net_get_link_info(struct octep_device *oct)
 	return 0;
 }
 
-int octep_ctrl_net_set_link_info(struct octep_device *oct,
+int octep_ctrl_net_set_link_info(struct octep_device *oct, int vfid,
 				 struct octep_iface_link_info *link_info,
 				 bool wait_for_response)
 {
 	struct octep_ctrl_net_wait_data d = {0};
 	struct octep_ctrl_net_h2f_req *req = &d.data.req;
 
-	init_send_req(&d.msg, req, link_info_sz);
+	init_send_req(&d.msg, req, link_info_sz, vfid);
 	req->hdr.s.cmd = OCTEP_CTRL_NET_H2F_CMD_LINK_INFO;
 	req->link_info.cmd = OCTEP_CTRL_NET_CMD_SET;
 	req->link_info.info.advertised_modes = link_info->advertised_modes;
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.h +20 -8
index aba373ec28a4..de0759365f13 100644
@@ -7,6 +7,8 @@
 #ifndef __OCTEP_CTRL_NET_H__
 #define __OCTEP_CTRL_NET_H__
 
+#define OCTEP_CTRL_NET_INVALID_VFID	(-1)
+
 /* Supported commands */
 enum octep_ctrl_net_cmd {
 	OCTEP_CTRL_NET_CMD_GET = 0,
@@ -216,89 +218,99 @@ int octep_ctrl_net_init(struct octep_device *oct);
 /** Get link status from firmware.
  *
  * @param oct: non-null pointer to struct octep_device.
+ * @param vfid: Index of virtual function.
  *
  * return value: link status 0=down, 1=up.
  */
-int octep_ctrl_net_get_link_status(struct octep_device *oct);
+int octep_ctrl_net_get_link_status(struct octep_device *oct, int vfid);
 
 /** Set link status in firmware.
  *
  * @param oct: non-null pointer to struct octep_device.
+ * @param vfid: Index of virtual function.
  * @param up: boolean status.
  * @param wait_for_response: poll for response.
  *
  * return value: 0 on success, -errno on failure
  */
-int octep_ctrl_net_set_link_status(struct octep_device *oct, bool up,
+int octep_ctrl_net_set_link_status(struct octep_device *oct, int vfid, bool up,
 				   bool wait_for_response);
 
 /** Set rx state in firmware.
  *
  * @param oct: non-null pointer to struct octep_device.
+ * @param vfid: Index of virtual function.
  * @param up: boolean status.
  * @param wait_for_response: poll for response.
  *
  * return value: 0 on success, -errno on failure.
  */
-int octep_ctrl_net_set_rx_state(struct octep_device *oct, bool up,
+int octep_ctrl_net_set_rx_state(struct octep_device *oct, int vfid, bool up,
 				bool wait_for_response);
 
 /** Get mac address from firmware.
  *
  * @param oct: non-null pointer to struct octep_device.
+ * @param vfid: Index of virtual function.
  * @param addr: non-null pointer to mac address.
  *
  * return value: 0 on success, -errno on failure.
  */
-int octep_ctrl_net_get_mac_addr(struct octep_device *oct, u8 *addr);
+int octep_ctrl_net_get_mac_addr(struct octep_device *oct, int vfid, u8 *addr);
 
 /** Set mac address in firmware.
  *
  * @param oct: non-null pointer to struct octep_device.
+ * @param vfid: Index of virtual function.
  * @param addr: non-null pointer to mac address.
  * @param wait_for_response: poll for response.
  *
  * return value: 0 on success, -errno on failure.
  */
-int octep_ctrl_net_set_mac_addr(struct octep_device *oct, u8 *addr,
+int octep_ctrl_net_set_mac_addr(struct octep_device *oct, int vfid, u8 *addr,
 				bool wait_for_response);
 
 /** Set mtu in firmware.
  *
  * @param oct: non-null pointer to struct octep_device.
+ * @param vfid: Index of virtual function.
  * @param mtu: mtu.
  * @param wait_for_response: poll for response.
  *
  * return value: 0 on success, -errno on failure.
  */
-int octep_ctrl_net_set_mtu(struct octep_device *oct, int mtu,
+int octep_ctrl_net_set_mtu(struct octep_device *oct, int vfid, int mtu,
 			   bool wait_for_response);
 
 /** Get interface statistics from firmware.
  *
  * @param oct: non-null pointer to struct octep_device.
+ * @param vfid: Index of virtual function.
  *
  * return value: 0 on success, -errno on failure.
  */
-int octep_ctrl_net_get_if_stats(struct octep_device *oct);
+int octep_ctrl_net_get_if_stats(struct octep_device *oct, int vfid);
 
 /** Get link info from firmware.
  *
  * @param oct: non-null pointer to struct octep_device.
+ * @param vfid: Index of virtual function.
  *
  * return value: 0 on success, -errno on failure.
  */
-int octep_ctrl_net_get_link_info(struct octep_device *oct);
+int octep_ctrl_net_get_link_info(struct octep_device *oct, int vfid);
 
 /** Set link info in firmware.
  *
  * @param oct: non-null pointer to struct octep_device.
+ * @param vfid: Index of virtual function.
  * @param link_info: non-null pointer to struct octep_iface_link_info.
  * @param wait_for_response: poll for response.
  *
  * return value: 0 on success, -errno on failure.
  */
 int octep_ctrl_net_set_link_info(struct octep_device *oct,
+				 int vfid,
 				 struct octep_iface_link_info *link_info,
 				 bool wait_for_response);
 
drivers/net/ethernet/marvell/octeon_ep/octep_ethtool.c +4 -3
index a1ddb64791f2..389042b57787 100644
@@ -150,7 +150,7 @@ octep_get_ethtool_stats(struct net_device *netdev,
 	rx_packets = 0;
 	rx_bytes = 0;
 
-	octep_ctrl_net_get_if_stats(oct);
+	octep_ctrl_net_get_if_stats(oct, OCTEP_CTRL_NET_INVALID_VFID);
 	iface_tx_stats = &oct->iface_tx_stats;
 	iface_rx_stats = &oct->iface_rx_stats;
 
@@ -283,7 +283,7 @@ static int octep_get_link_ksettings(struct net_device *netdev,
 	ethtool_link_ksettings_zero_link_mode(cmd, supported);
 	ethtool_link_ksettings_zero_link_mode(cmd, advertising);
 
-	octep_ctrl_net_get_link_info(oct);
+	octep_ctrl_net_get_link_info(oct, OCTEP_CTRL_NET_INVALID_VFID);
 
 	advertised_modes = oct->link_info.advertised_modes;
 	supported_modes = oct->link_info.supported_modes;
@@ -439,7 +439,8 @@ static int octep_set_link_ksettings(struct net_device *netdev,
 	link_info_new.speed = cmd->base.speed;
 	link_info_new.autoneg = autoneg;
 
-	err = octep_ctrl_net_set_link_info(oct, &link_info_new, true);
+	err = octep_ctrl_net_set_link_info(oct, OCTEP_CTRL_NET_INVALID_VFID,
+					   &link_info_new, true);
 	if (err)
 		return err;
 
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +15 -9
index 43fff8979854..112d3825e544 100644
@@ -507,8 +507,10 @@ static int octep_open(struct net_device *netdev)
 	octep_napi_enable(oct);
 
 	oct->link_info.admin_up = 1;
-	octep_ctrl_net_set_rx_state(oct, true, false);
-	octep_ctrl_net_set_link_status(oct, true, false);
+	octep_ctrl_net_set_rx_state(oct, OCTEP_CTRL_NET_INVALID_VFID, true,
+				    false);
+	octep_ctrl_net_set_link_status(oct, OCTEP_CTRL_NET_INVALID_VFID, true,
+				       false);
 	oct->poll_non_ioq_intr = false;
 
 	/* Enable the input and output queues for this Octeon device */
@@ -519,7 +521,7 @@ static int octep_open(struct net_device *netdev)
 
 	octep_oq_dbell_init(oct);
 
-	ret = octep_ctrl_net_get_link_status(oct);
+	ret = octep_ctrl_net_get_link_status(oct, OCTEP_CTRL_NET_INVALID_VFID);
 	if (ret > 0)
 		octep_link_up(netdev);
 
@@ -549,8 +551,10 @@ static int octep_stop(struct net_device *netdev)
 
 	netdev_info(netdev, "Stopping the device ...\n");
 
-	octep_ctrl_net_set_link_status(oct, false, false);
-	octep_ctrl_net_set_rx_state(oct, false, false);
+	octep_ctrl_net_set_link_status(oct, OCTEP_CTRL_NET_INVALID_VFID, false,
+				       false);
+	octep_ctrl_net_set_rx_state(oct, OCTEP_CTRL_NET_INVALID_VFID, false,
+				    false);
 
 	/* Stop Tx from stack */
 	netif_tx_stop_all_queues(netdev);
@@ -759,7 +763,7 @@ static void octep_get_stats64(struct net_device *netdev,
 	int q;
 
 	if (netif_running(netdev))
-		octep_ctrl_net_get_if_stats(oct);
+		octep_ctrl_net_get_if_stats(oct, OCTEP_CTRL_NET_INVALID_VFID);
 
 	tx_packets = 0;
 	tx_bytes = 0;
@@ -831,7 +835,8 @@ static int octep_set_mac(struct net_device *netdev, void *p)
 	if (!is_valid_ether_addr(addr->sa_data))
 		return -EADDRNOTAVAIL;
 
-	err = octep_ctrl_net_set_mac_addr(oct, addr->sa_data, true);
+	err = octep_ctrl_net_set_mac_addr(oct, OCTEP_CTRL_NET_INVALID_VFID,
+					  addr->sa_data, true);
 	if (err)
 		return err;
 
@@ -851,7 +856,8 @@ static int octep_change_mtu(struct net_device *netdev, int new_mtu)
 	if (link_info->mtu == new_mtu)
 		return 0;
 
-	err = octep_ctrl_net_set_mtu(oct, new_mtu, true);
+	err = octep_ctrl_net_set_mtu(oct, OCTEP_CTRL_NET_INVALID_VFID, new_mtu,
+				     true);
 	if (!err) {
 		oct->link_info.mtu = new_mtu;
 		netdev->mtu = new_mtu;
@@ -1102,7 +1108,7 @@ static int octep_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	netdev->max_mtu = OCTEP_MAX_MTU;
 	netdev->mtu = OCTEP_DEFAULT_MTU;
 
-	err = octep_ctrl_net_get_mac_addr(octep_dev,
+	err = octep_ctrl_net_get_mac_addr(octep_dev, OCTEP_CTRL_NET_INVALID_VFID,
 					  octep_dev->mac_addr);
 	if (err) {
 		dev_err(&pdev->dev, "Failed to get mac address\n");
Signature · 1 line
2.36.0
author maintainer
#6 lore raw

PATCH v4 6/8 octeon_ep: support asynchronous notifications

In reply to Veerasenareddy Burru

Add asynchronous notification support to the control mailbox.

---
v3 -> v4:
* 0005-xxx.patch in v3 is 0006-xxx.patch in v4.
* addressed review comments
https://lore.kernel.org/all/Y+0J94sowllCe5Gs@boxer/
- fixed rct violation.
- process_mbox_notify() now returns void.

v2 -> v3:
* no change

v1 -> v2:
* no change

 .../marvell/octeon_ep/octep_ctrl_net.c        | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +29 -0
index cef4bc3b1ec0..465eef2824e3 100644
@@ -271,6 +271,33 @@ static void process_mbox_resp(struct octep_device *oct,
 	}
 }
 
+static int process_mbox_notify(struct octep_device *oct,
+			       struct octep_ctrl_mbox_msg *msg)
+{
+	struct net_device *netdev = oct->netdev;
+	struct octep_ctrl_net_f2h_req *req;
+
+	req = (struct octep_ctrl_net_f2h_req *)msg->sg_list[0].msg;
+	switch (req->hdr.s.cmd) {
+	case OCTEP_CTRL_NET_F2H_CMD_LINK_STATUS:
+		if (netif_running(netdev)) {
+			if (req->link.state) {
+				dev_info(&oct->pdev->dev, "netif_carrier_on\n");
+				netif_carrier_on(netdev);
+			} else {
+				dev_info(&oct->pdev->dev, "netif_carrier_off\n");
+				netif_carrier_off(netdev);
+			}
+		}
+		break;
+	default:
+		pr_info("Unknown mbox req : %u\n", req->hdr.s.cmd);
+		break;
+	}
+
+	return 0;
+}
+
 void octep_ctrl_net_recv_fw_messages(struct octep_device *oct)
 {
 	static u16 msg_sz = sizeof(union octep_ctrl_net_max_data);
@@ -291,6 +318,8 @@ void octep_ctrl_net_recv_fw_messages(struct octep_device *oct)
 
 		if (msg.hdr.s.flags & OCTEP_CTRL_MBOX_MSG_HDR_FLAG_RESP)
 			process_mbox_resp(oct, &msg);
+		else if (msg.hdr.s.flags & OCTEP_CTRL_MBOX_MSG_HDR_FLAG_NOTIFY)
+			process_mbox_notify(oct, &msg);
 	}
 }
 
Signature · 1 line
2.36.0
#7 lore raw

Re: [PATCH net-next v4 6/8] octeon_ep: support asynchronous notifications

Quoted 36 lines · Veerasenareddy Burru

Add asynchronous notification support to the control mailbox.

---
v3 -> v4:
* 0005-xxx.patch in v3 is 0006-xxx.patch in v4.
* addressed review comments
https://lore.kernel.org/all/Y+0J94sowllCe5Gs@boxer/
- fixed rct violation.
- process_mbox_notify() now returns void.

v2 -> v3:
* no change

v1 -> v2:
* no change

 .../marvell/octeon_ep/octep_ctrl_net.c        | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +7 -0
index cef4bc3b1ec0..465eef2824e3 100644
@@ -271,6 +271,33 @@ static void process_mbox_resp(struct octep_device *oct,
 	}
 }
 
+static int process_mbox_notify(struct octep_device *oct,
+			       struct octep_ctrl_mbox_msg *msg)
+{
+	struct net_device *netdev = oct->netdev;
+	struct octep_ctrl_net_f2h_req *req;
+
+	req = (struct octep_ctrl_net_f2h_req *)msg->sg_list[0].msg;

drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c static void process_mbox_resp(struct octep_device *oct, · line 290

Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +10 -0
+	switch (req->hdr.s.cmd) {
+	case OCTEP_CTRL_NET_F2H_CMD_LINK_STATUS:
+		if (netif_running(netdev)) {
+			if (req->link.state) {
+				dev_info(&oct->pdev->dev, "netif_carrier_on\n");
+				netif_carrier_on(netdev);
+			} else {
+				dev_info(&oct->pdev->dev, "netif_carrier_off\n");
+				netif_carrier_off(netdev);
+			}

Shouldn't netdev changes be protected by some lock? Is is safe to get event from FW and process it as is?

Thanks

author maintainer
#8 lore raw

RE: [EXT] Re: [PATCH net-next v4 6/8] octeon_ep: support asynchronous notifications

Quoted 70 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Thursday, March 23, 2023 3:39 AM
To: Veerasenareddy Burru <[email protected]>
Cc: [email protected]; [email protected]; Abhijit Ayarekar <[email protected]>; Sathesh B Edara <[email protected]>; Satananda Burla <[email protected]>; [email protected]; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>
Subject: [EXT] Re: [PATCH net-next v4 6/8] octeon_ep: support asynchronous notifications

External Email

----------------------------------------------------------------------

Quoted 9 lines · Veerasenareddy Burru

Add asynchronous notification support to the control mailbox.

---
v3 -> v4:
* 0005-xxx.patch in v3 is 0006-xxx.patch in v4.
* addressed review comments
https://urldefense.proofpoint.com/v2/url?u=https-

3A__lore.kernel.org_all_Y-2B0J94sowllCe5Gs- 40boxer_&d=DwIBAg&c=nKjWec2b6R0mOyPaz7xtfQ&r=XkP_75lnbPIeeucsP X36ZgjiMqEKttwZfwNyWMCLjT0&m=5CnsD- SX6ZoW98szwM0k4IXgNC3wY0EwCQHxDKGyNIRUJxdaNe3zorLcOhc9iU6d&s =k73McQSsjbjj87VbCCB8EFFtGWtksMIGhn15RK12XF8&e=

drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c static void process_mbox_resp(struct

Quoted 18 lines

- fixed rct violation.
- process_mbox_notify() now returns void.

v2 -> v3:
* no change

v1 -> v2:
* no change

 .../marvell/octeon_ep/octep_ctrl_net.c        | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +0 -0
index cef4bc3b1ec0..465eef2824e3 100644
@@ -271,6 +271,33 @@ static void process_mbox_resp(struct

octep_device *oct,

Quoted 4 lines
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +1 -0
 	}
 }
 
+static int process_mbox_notify(struct octep_device *oct,

drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c static void process_mbox_resp(struct octep_device *oct,

Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +10 -0
+			       struct octep_ctrl_mbox_msg *msg) {
+	struct net_device *netdev = oct->netdev;
+	struct octep_ctrl_net_f2h_req *req;
+
+	req = (struct octep_ctrl_net_f2h_req *)msg->sg_list[0].msg;
+	switch (req->hdr.s.cmd) {
+	case OCTEP_CTRL_NET_F2H_CMD_LINK_STATUS:
+		if (netif_running(netdev)) {
+			if (req->link.state) {
+				dev_info(&oct->pdev->dev,

"netif_carrier_on\n");

drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c static void process_mbox_resp(struct octep_device *oct,

Quoted 3 lines
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +3 -0
+				netif_carrier_on(netdev);
+			} else {
+				dev_info(&oct->pdev->dev,

"netif_carrier_off\n");

Quoted 7 lines

drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c static void process_mbox_resp(struct · line 289

Quoted 2 lines
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +2 -0
+				netif_carrier_off(netdev);
+			}

Shouldn't netdev changes be protected by some lock? Is is safe to get event from FW and process it as is?

Thanks

Thanks for the kind feedback.
I do not see netif_carrier_on/off require any protection. I referred few other drivers and do not see such protection used for carrier on/off. Please suggest if I am missing something here.

#9 lore raw

Re: [EXT] Re: [PATCH net-next v4 6/8] octeon_ep: support asynchronous notifications

Quoted 76 lines · Veerasenareddy Burru
Quoted 76 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Thursday, March 23, 2023 3:39 AM
To: Veerasenareddy Burru <[email protected]>
Cc: [email protected]; [email protected]; Abhijit Ayarekar <[email protected]>; Sathesh B Edara <[email protected]>; Satananda Burla <[email protected]>; [email protected]; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>
Subject: [EXT] Re: [PATCH net-next v4 6/8] octeon_ep: support asynchronous notifications

External Email

----------------------------------------------------------------------

Quoted 9 lines · Veerasenareddy Burru

Add asynchronous notification support to the control mailbox.

---
v3 -> v4:
* 0005-xxx.patch in v3 is 0006-xxx.patch in v4.
* addressed review comments
https://urldefense.proofpoint.com/v2/url?u=https-

3A__lore.kernel.org_all_Y-2B0J94sowllCe5Gs- 40boxer_&d=DwIBAg&c=nKjWec2b6R0mOyPaz7xtfQ&r=XkP_75lnbPIeeucsP X36ZgjiMqEKttwZfwNyWMCLjT0&m=5CnsD- SX6ZoW98szwM0k4IXgNC3wY0EwCQHxDKGyNIRUJxdaNe3zorLcOhc9iU6d&s =k73McQSsjbjj87VbCCB8EFFtGWtksMIGhn15RK12XF8&e=

drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c static void process_mbox_resp(struct

Quoted 18 lines

- fixed rct violation.
- process_mbox_notify() now returns void.

v2 -> v3:
* no change

v1 -> v2:
* no change

 .../marvell/octeon_ep/octep_ctrl_net.c        | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +0 -0
index cef4bc3b1ec0..465eef2824e3 100644
@@ -271,6 +271,33 @@ static void process_mbox_resp(struct

octep_device *oct,

Quoted 4 lines
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +1 -0
 	}
 }
 
+static int process_mbox_notify(struct octep_device *oct,

drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c static void process_mbox_resp(struct octep_device *oct,

Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +10 -0
+			       struct octep_ctrl_mbox_msg *msg) {
+	struct net_device *netdev = oct->netdev;
+	struct octep_ctrl_net_f2h_req *req;
+
+	req = (struct octep_ctrl_net_f2h_req *)msg->sg_list[0].msg;
+	switch (req->hdr.s.cmd) {
+	case OCTEP_CTRL_NET_F2H_CMD_LINK_STATUS:
+		if (netif_running(netdev)) {
+			if (req->link.state) {
+				dev_info(&oct->pdev->dev,

"netif_carrier_on\n");

drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c static void process_mbox_resp(struct octep_device *oct,

Quoted 3 lines
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +3 -0
+				netif_carrier_on(netdev);
+			} else {
+				dev_info(&oct->pdev->dev,

"netif_carrier_off\n");

drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c static void process_mbox_resp(struct · line 289

Quoted 2 lines
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +2 -0
+				netif_carrier_off(netdev);
+			}

Shouldn't netdev changes be protected by some lock? Is is safe to get event from FW and process it as is?

Quoted 5 lines
Quoted 1 line

Thanks

Thanks for the kind feedback.
I do not see netif_carrier_on/off require any protection. I referred few other drivers and do not see such protection used for carrier on/off. Please suggest if I am missing something here.

I see that Dave already applied your v5. I think that you are missing context in which you are running FW commands. They run independently from netdev and makes netif_running() check to be racy.

Thanks

Quoted 1 line
author maintainer
#10 lore raw

PATCH v4 7/8 octeon_ep: function id in link info and stats mailbox commands

In reply to Veerasenareddy Burru

Update control mailbox API to include function id in get stats and link info.

---
v3 -> v4:
* 0006-xxx.patch in v3 is 0007-xxx.patch in v4.

v2 -> v3:
* no change

v1 -> v2:
* no change

 .../marvell/octeon_ep/octep_ctrl_net.c        | 33 +++++++++----------
 .../marvell/octeon_ep/octep_ctrl_net.h        | 24 +++++++++-----
 .../marvell/octeon_ep/octep_ethtool.c         |  9 +++--
 .../ethernet/marvell/octeon_ep/octep_main.c   |  5 ++-
 4 files changed, 40 insertions(+), 31 deletions(-)
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +15 -18
index 465eef2824e3..1cc6af2feb38 100644
@@ -19,7 +19,6 @@ static const u32 mtu_sz = sizeof(struct octep_ctrl_net_h2f_req_cmd_mtu);
 static const u32 mac_sz = sizeof(struct octep_ctrl_net_h2f_req_cmd_mac);
 static const u32 state_sz = sizeof(struct octep_ctrl_net_h2f_req_cmd_state);
 static const u32 link_info_sz = sizeof(struct octep_ctrl_net_link_info);
-static const u32 get_stats_sz = sizeof(struct octep_ctrl_net_h2f_req_cmd_get_stats);
 static atomic_t ctrl_net_msg_id;
 
 static void init_send_req(struct octep_ctrl_mbox_msg *msg, void *buf,
@@ -188,31 +187,29 @@ int octep_ctrl_net_set_mtu(struct octep_device *oct, int vfid, int mtu,
 	return octep_send_mbox_req(oct, &d, wait_for_response);
 }
 
-int octep_ctrl_net_get_if_stats(struct octep_device *oct, int vfid)
+int octep_ctrl_net_get_if_stats(struct octep_device *oct, int vfid,
+				struct octep_iface_rx_stats *rx_stats,
+				struct octep_iface_tx_stats *tx_stats)
 {
 	struct octep_ctrl_net_wait_data d = {0};
 	struct octep_ctrl_net_h2f_req *req = &d.data.req;
-	void __iomem *iface_rx_stats;
-	void __iomem *iface_tx_stats;
+	struct octep_ctrl_net_h2f_resp *resp;
 	int err;
 
-	init_send_req(&d.msg, req, get_stats_sz, vfid);
+	init_send_req(&d.msg, req, 0, vfid);
 	req->hdr.s.cmd = OCTEP_CTRL_NET_H2F_CMD_GET_IF_STATS;
-	req->get_stats.offset = oct->ctrl_mbox_ifstats_offset;
 	err = octep_send_mbox_req(oct, &d, true);
 	if (err < 0)
 		return err;
 
-	iface_rx_stats = oct->ctrl_mbox.barmem + oct->ctrl_mbox_ifstats_offset;
-	iface_tx_stats = oct->ctrl_mbox.barmem + oct->ctrl_mbox_ifstats_offset +
-			 sizeof(struct octep_iface_rx_stats);
-	memcpy_fromio(&oct->iface_rx_stats, iface_rx_stats, sizeof(struct octep_iface_rx_stats));
-	memcpy_fromio(&oct->iface_tx_stats, iface_tx_stats, sizeof(struct octep_iface_tx_stats));
-
+	resp = &d.data.resp;
+	memcpy(rx_stats, &resp->if_stats.rx_stats, sizeof(struct octep_iface_rx_stats));
+	memcpy(tx_stats, &resp->if_stats.tx_stats, sizeof(struct octep_iface_tx_stats));
 	return 0;
 }
 
-int octep_ctrl_net_get_link_info(struct octep_device *oct, int vfid)
+int octep_ctrl_net_get_link_info(struct octep_device *oct, int vfid,
+				 struct octep_iface_link_info *link_info)
 {
 	struct octep_ctrl_net_wait_data d = {0};
 	struct octep_ctrl_net_h2f_req *req = &d.data.req;
@@ -227,11 +224,11 @@ int octep_ctrl_net_get_link_info(struct octep_device *oct, int vfid)
 		return err;
 
 	resp = &d.data.resp;
-	oct->link_info.supported_modes = resp->link_info.supported_modes;
-	oct->link_info.advertised_modes = resp->link_info.advertised_modes;
-	oct->link_info.autoneg = resp->link_info.autoneg;
-	oct->link_info.pause = resp->link_info.pause;
-	oct->link_info.speed = resp->link_info.speed;
+	link_info->supported_modes = resp->link_info.supported_modes;
+	link_info->advertised_modes = resp->link_info.advertised_modes;
+	link_info->autoneg = resp->link_info.autoneg;
+	link_info->pause = resp->link_info.pause;
+	link_info->speed = resp->link_info.speed;
 
 	return 0;
 }
drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.h +15 -9
index de0759365f13..37880dd79116 100644
@@ -77,12 +77,6 @@ struct octep_ctrl_net_h2f_req_cmd_mac {
 	u8 addr[ETH_ALEN];
 };
 
-/* get if_stats, xstats, q_stats request */
-struct octep_ctrl_net_h2f_req_cmd_get_stats {
-	/* offset into barmem where fw should copy over stats */
-	u32 offset;
-};
-
 /* get/set link state, rx state */
 struct octep_ctrl_net_h2f_req_cmd_state {
 	/* enum octep_ctrl_net_cmd */
@@ -119,7 +113,6 @@ struct octep_ctrl_net_h2f_req {
 	union {
 		struct octep_ctrl_net_h2f_req_cmd_mtu mtu;
 		struct octep_ctrl_net_h2f_req_cmd_mac mac;
-		struct octep_ctrl_net_h2f_req_cmd_get_stats get_stats;
 		struct octep_ctrl_net_h2f_req_cmd_state link;
 		struct octep_ctrl_net_h2f_req_cmd_state rx;
 		struct octep_ctrl_net_h2f_req_cmd_link_info link_info;
@@ -152,6 +145,12 @@ struct octep_ctrl_net_h2f_resp_cmd_mac {
 	u8 addr[ETH_ALEN];
 };
 
+/* get if_stats, xstats, q_stats request */
+struct octep_ctrl_net_h2f_resp_cmd_get_stats {
+	struct octep_iface_rx_stats rx_stats;
+	struct octep_iface_tx_stats tx_stats;
+};
+
 /* get link state, rx state response */
 struct octep_ctrl_net_h2f_resp_cmd_state {
 	/* enum octep_ctrl_net_state */
@@ -164,6 +163,7 @@ struct octep_ctrl_net_h2f_resp {
 	union {
 		struct octep_ctrl_net_h2f_resp_cmd_mtu mtu;
 		struct octep_ctrl_net_h2f_resp_cmd_mac mac;
+		struct octep_ctrl_net_h2f_resp_cmd_get_stats if_stats;
 		struct octep_ctrl_net_h2f_resp_cmd_state link;
 		struct octep_ctrl_net_h2f_resp_cmd_state rx;
 		struct octep_ctrl_net_link_info link_info;
@@ -286,19 +286,25 @@ int octep_ctrl_net_set_mtu(struct octep_device *oct, int vfid, int mtu,
  *
  * @param oct: non-null pointer to struct octep_device.
  * @param vfid: Index of virtual function.
+ * @param rx_stats: non-null pointer struct octep_iface_rx_stats.
+ * @param tx_stats: non-null pointer struct octep_iface_tx_stats.
  *
  * return value: 0 on success, -errno on failure.
  */
-int octep_ctrl_net_get_if_stats(struct octep_device *oct, int vfid);
+int octep_ctrl_net_get_if_stats(struct octep_device *oct, int vfid,
+				struct octep_iface_rx_stats *rx_stats,
+				struct octep_iface_tx_stats *tx_stats);
 
 /** Get link info from firmware.
  *
  * @param oct: non-null pointer to struct octep_device.
  * @param vfid: Index of virtual function.
+ * @param link_info: non-null pointer to struct octep_iface_link_info.
  *
  * return value: 0 on success, -errno on failure.
  */
-int octep_ctrl_net_get_link_info(struct octep_device *oct, int vfid);
+int octep_ctrl_net_get_link_info(struct octep_device *oct, int vfid,
+				 struct octep_iface_link_info *link_info);
 
 /** Set link info in firmware.
  *
drivers/net/ethernet/marvell/octeon_ep/octep_ethtool.c +6 -3
index 389042b57787..7d0124b283da 100644
@@ -150,9 +150,12 @@ octep_get_ethtool_stats(struct net_device *netdev,
 	rx_packets = 0;
 	rx_bytes = 0;
 
-	octep_ctrl_net_get_if_stats(oct, OCTEP_CTRL_NET_INVALID_VFID);
 	iface_tx_stats = &oct->iface_tx_stats;
 	iface_rx_stats = &oct->iface_rx_stats;
+	octep_ctrl_net_get_if_stats(oct,
+				    OCTEP_CTRL_NET_INVALID_VFID,
+				    iface_rx_stats,
+				    iface_tx_stats);
 
 	for (q = 0; q < oct->num_oqs; q++) {
 		struct octep_iq *iq = oct->iq[q];
@@ -283,11 +286,11 @@ static int octep_get_link_ksettings(struct net_device *netdev,
 	ethtool_link_ksettings_zero_link_mode(cmd, supported);
 	ethtool_link_ksettings_zero_link_mode(cmd, advertising);
 
-	octep_ctrl_net_get_link_info(oct, OCTEP_CTRL_NET_INVALID_VFID);
+	link_info = &oct->link_info;
+	octep_ctrl_net_get_link_info(oct, OCTEP_CTRL_NET_INVALID_VFID, link_info);
 
 	advertised_modes = oct->link_info.advertised_modes;
 	supported_modes = oct->link_info.supported_modes;
-	link_info = &oct->link_info;
 
 	OCTEP_SET_ETHTOOL_LINK_MODES_BITMAP(supported_modes, cmd, supported);
 	OCTEP_SET_ETHTOOL_LINK_MODES_BITMAP(advertised_modes, cmd, advertising);
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +4 -1
index 112d3825e544..ba0d5fe3081d 100644
@@ -763,7 +763,10 @@ static void octep_get_stats64(struct net_device *netdev,
 	int q;
 
 	if (netif_running(netdev))
-		octep_ctrl_net_get_if_stats(oct, OCTEP_CTRL_NET_INVALID_VFID);
+		octep_ctrl_net_get_if_stats(oct,
+					    OCTEP_CTRL_NET_INVALID_VFID,
+					    &oct->iface_rx_stats,
+					    &oct->iface_tx_stats);
 
 	tx_packets = 0;
 	tx_bytes = 0;
Signature · 1 line
2.36.0
author maintainer
#11 lore raw

PATCH v4 8/8 octeon_ep: add heartbeat monitor

In reply to Veerasenareddy Burru

Monitor periodic heartbeat messages from device firmware. Presence of heartbeat indicates the device is active and running. If the heartbeat is missed for configured interval indicates firmware has crashed and device is unusable; in this case, PF driver stops and uninitialize the device.

---
v3 -> v4:
* 0007-xxx.patch in v3 is 0008-xxx.patch in v4.

v2 -> v3:
* 0009-xxx.patch in v2 is now 0007-xxx.patch in v3 due to 0007 and 0008.patch from v2 are removed in v3.

v1 -> v2:
* no change

 .../marvell/octeon_ep/octep_cn9k_pf.c         |  9 ++++
 .../ethernet/marvell/octeon_ep/octep_config.h |  6 +++
 .../ethernet/marvell/octeon_ep/octep_main.c   | 45 ++++++++++++++++++-
 .../ethernet/marvell/octeon_ep/octep_main.h   |  7 +++
 .../marvell/octeon_ep/octep_regs_cn9k_pf.h    |  2 +
 5 files changed, 67 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +9 -0
index e2503c9bc8a1..90c3a419932d 100644
@@ -16,6 +16,9 @@
 #define CTRL_MBOX_MAX_PF	128
 #define CTRL_MBOX_SZ		((size_t)(0x400000 / CTRL_MBOX_MAX_PF))
 
+#define FW_HB_INTERVAL_IN_SECS		1
+#define FW_HB_MISS_COUNT		10
+
 /* Names of Hardware non-queue generic interrupts */
 static char *cn93_non_ioq_msix_names[] = {
 	"epf_ire_rint",
@@ -249,6 +252,10 @@ static void octep_init_config_cn93_pf(struct octep_device *oct)
 	conf->ctrl_mbox_cfg.barmem_addr = (void __iomem *)oct->mmio[2].hw_addr +
 					   (0x400000ull * 7) +
 					   (link * CTRL_MBOX_SZ);
+
+	conf->hb_interval = FW_HB_INTERVAL_IN_SECS;
+	conf->max_hb_miss_cnt = FW_HB_MISS_COUNT;
+
 }
 
 /* Setup registers for a hardware Tx Queue  */
@@ -383,6 +390,8 @@ static bool octep_poll_non_ioq_interrupts_cn93_pf(struct octep_device *oct)
 		octep_write_csr64(oct, CN93_SDP_EPF_OEI_RINT, reg0);
 		if (reg0 & CN93_SDP_EPF_OEI_RINT_DATA_BIT_MBOX)
 			queue_work(octep_wq, &oct->ctrl_mbox_task);
+		else if (reg0 & CN93_SDP_EPF_OEI_RINT_DATA_BIT_HBEAT)
+			atomic_set(&oct->hb_miss_cnt, 0);
 
 		handled = true;
 	}
drivers/net/ethernet/marvell/octeon_ep/octep_config.h +6 -0
index f208f3f9a447..df7cd39d9fce 100644
@@ -200,5 +200,11 @@ struct octep_config {
 
 	/* ctrl mbox config */
 	struct octep_ctrl_mbox_config ctrl_mbox_cfg;
+
+	/* Configured maximum heartbeat miss count */
+	u32 max_hb_miss_cnt;
+
+	/* Configured firmware heartbeat interval in secs */
+	u32 hb_interval;
 };
 #endif /* _OCTEP_CONFIG_H_ */
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +43 -2

69 lines not on this page · raw message

drivers/net/ethernet/marvell/octeon_ep/octep_main.h +7 -0
index 836d990ba3fa..e0907a719133 100644
@@ -280,6 +280,13 @@ struct octep_device {
 	bool poll_non_ioq_intr;
 	/* Work entry to poll non-ioq interrupts */
 	struct delayed_work intr_poll_task;
+
+	/* Firmware heartbeat timer */
+	struct timer_list hb_timer;
+	/* Firmware heartbeat miss count tracked by timer */
+	atomic_t hb_miss_cnt;
+	/* Task to reset device on heartbeat miss */
+	struct delayed_work hb_task;
 };
 
 static inline u16 OCTEP_MAJOR_REV(struct octep_device *oct)
drivers/net/ethernet/marvell/octeon_ep/octep_regs_cn9k_pf.h +2 -0
index 0466fd9a002d..b25c3093dc7b 100644
@@ -367,5 +367,7 @@
 
 /* bit 0 for control mbox interrupt */
 #define CN93_SDP_EPF_OEI_RINT_DATA_BIT_MBOX	BIT_ULL(0)
+/* bit 1 for firmware heartbeat interrupt */
+#define CN93_SDP_EPF_OEI_RINT_DATA_BIT_HBEAT	BIT_ULL(1)
 
 #endif /* _OCTEP_REGS_CN9K_PF_H_ */
Signature · 1 line
2.36.0
#12 lore raw

Re: [PATCH net-next v4 8/8] octeon_ep: add heartbeat monitor

Quoted 92 lines · Veerasenareddy Burru

Monitor periodic heartbeat messages from device firmware. Presence of heartbeat indicates the device is active and running. If the heartbeat is missed for configured interval indicates firmware has crashed and device is unusable; in this case, PF driver stops and uninitialize the device.

---
v3 -> v4:
* 0007-xxx.patch in v3 is 0008-xxx.patch in v4.

v2 -> v3:
* 0009-xxx.patch in v2 is now 0007-xxx.patch in v3 due to 0007 and 0008.patch from v2 are removed in v3.

v1 -> v2:
* no change

 .../marvell/octeon_ep/octep_cn9k_pf.c         |  9 ++++
 .../ethernet/marvell/octeon_ep/octep_config.h |  6 +++
 .../ethernet/marvell/octeon_ep/octep_main.c   | 45 ++++++++++++++++++-
 .../ethernet/marvell/octeon_ep/octep_main.h   |  7 +++
 .../marvell/octeon_ep/octep_regs_cn9k_pf.h    |  2 +
 5 files changed, 67 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +9 -0
index e2503c9bc8a1..90c3a419932d 100644
@@ -16,6 +16,9 @@
 #define CTRL_MBOX_MAX_PF	128
 #define CTRL_MBOX_SZ		((size_t)(0x400000 / CTRL_MBOX_MAX_PF))
 
+#define FW_HB_INTERVAL_IN_SECS		1
+#define FW_HB_MISS_COUNT		10
+
 /* Names of Hardware non-queue generic interrupts */
 static char *cn93_non_ioq_msix_names[] = {
 	"epf_ire_rint",
@@ -249,6 +252,10 @@ static void octep_init_config_cn93_pf(struct octep_device *oct)
 	conf->ctrl_mbox_cfg.barmem_addr = (void __iomem *)oct->mmio[2].hw_addr +
 					   (0x400000ull * 7) +
 					   (link * CTRL_MBOX_SZ);
+
+	conf->hb_interval = FW_HB_INTERVAL_IN_SECS;
+	conf->max_hb_miss_cnt = FW_HB_MISS_COUNT;
+
 }
 
 /* Setup registers for a hardware Tx Queue  */
@@ -383,6 +390,8 @@ static bool octep_poll_non_ioq_interrupts_cn93_pf(struct octep_device *oct)
 		octep_write_csr64(oct, CN93_SDP_EPF_OEI_RINT, reg0);
 		if (reg0 & CN93_SDP_EPF_OEI_RINT_DATA_BIT_MBOX)
 			queue_work(octep_wq, &oct->ctrl_mbox_task);
+		else if (reg0 & CN93_SDP_EPF_OEI_RINT_DATA_BIT_HBEAT)
+			atomic_set(&oct->hb_miss_cnt, 0);
 
 		handled = true;
 	}
drivers/net/ethernet/marvell/octeon_ep/octep_config.h +6 -0
index f208f3f9a447..df7cd39d9fce 100644
@@ -200,5 +200,11 @@ struct octep_config {
 
 	/* ctrl mbox config */
 	struct octep_ctrl_mbox_config ctrl_mbox_cfg;
+
+	/* Configured maximum heartbeat miss count */
+	u32 max_hb_miss_cnt;
+
+	/* Configured firmware heartbeat interval in secs */
+	u32 hb_interval;
 };
 #endif /* _OCTEP_CONFIG_H_ */
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +8 -0
index ba0d5fe3081d..415dd06ff344 100644
@@ -901,6 +901,38 @@ static void octep_intr_poll_task(struct work_struct *work)
 			   msecs_to_jiffies(OCTEP_INTR_POLL_TIME_MSECS));
 }
 
+/**
+ * octep_hb_timeout_task - work queue task to check firmware heartbeat.
+ *
+ * @work: pointer to hb work_struct
+ *
+ * Check for heartbeat miss count. Uninitialize oct device if miss count
+ * exceeds configured max heartbeat miss count.
+ *

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static void octep_intr_poll_task(struct work_struct *work) · line 921

Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +10 -0
+ **/
+static void octep_hb_timeout_task(struct work_struct *work)
+{
+	struct octep_device *oct = container_of(work, struct octep_device,
+						hb_task.work);
+
+	int miss_cnt;
+
+	atomic_inc(&oct->hb_miss_cnt);
+	miss_cnt = atomic_read(&oct->hb_miss_cnt);

miss_cnt = atomic_inc_return(&oct->hb_miss_cnt);

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static void octep_intr_poll_task(struct work_struct *work) · line 922

Quoted 1 line
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +1 -0
+	if (miss_cnt < oct->conf->max_hb_miss_cnt) {

How is this heartbeat working? You increment on every entry to octep_hb_timeout_task(), After max_hb_miss_cnt invocations, you will stop your device.

Thanks

Quoted 83 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +24 -2
+		queue_delayed_work(octep_wq, &oct->hb_task,
+				   msecs_to_jiffies(oct->conf->hb_interval * 1000));
+		return;
+	}
+
+	dev_err(&oct->pdev->dev, "Missed %u heartbeats. Uninitializing\n",
+		miss_cnt);
+	rtnl_lock();
+	if (netif_running(oct->netdev))
+		octep_stop(oct->netdev);
+	rtnl_unlock();
+}
+
 /**
  * octep_ctrl_mbox_task - work queue task to handle ctrl mbox messages.
  *
@@ -938,7 +970,7 @@ static const char *octep_devid_to_str(struct octep_device *oct)
 int octep_device_setup(struct octep_device *oct)
 {
 	struct pci_dev *pdev = oct->pdev;
-	int i;
+	int i, ret;
 
 	/* allocate memory for oct->conf */
 	oct->conf = kzalloc(sizeof(*oct->conf), GFP_KERNEL);
@@ -973,7 +1005,15 @@ int octep_device_setup(struct octep_device *oct)
 
 	oct->pkind = CFG_GET_IQ_PKIND(oct->conf);
 
-	return octep_ctrl_net_init(oct);
+	ret = octep_ctrl_net_init(oct);
+	if (ret)
+		return ret;
+
+	atomic_set(&oct->hb_miss_cnt, 0);
+	INIT_DELAYED_WORK(&oct->hb_task, octep_hb_timeout_task);
+	queue_delayed_work(octep_wq, &oct->hb_task,
+			   msecs_to_jiffies(oct->conf->hb_interval * 1000));
+	return 0;
 
 unsupported_dev:
 	for (i = 0; i < OCTEP_MMIO_REGIONS; i++)
@@ -1002,6 +1042,7 @@ static void octep_device_cleanup(struct octep_device *oct)
 	}
 
 	octep_ctrl_net_uninit(oct);
+	cancel_delayed_work_sync(&oct->hb_task);
 
 	oct->hw_ops.soft_reset(oct);
 	for (i = 0; i < OCTEP_MMIO_REGIONS; i++) {
drivers/net/ethernet/marvell/octeon_ep/octep_main.h +7 -0
index 836d990ba3fa..e0907a719133 100644
@@ -280,6 +280,13 @@ struct octep_device {
 	bool poll_non_ioq_intr;
 	/* Work entry to poll non-ioq interrupts */
 	struct delayed_work intr_poll_task;
+
+	/* Firmware heartbeat timer */
+	struct timer_list hb_timer;
+	/* Firmware heartbeat miss count tracked by timer */
+	atomic_t hb_miss_cnt;
+	/* Task to reset device on heartbeat miss */
+	struct delayed_work hb_task;
 };
 
 static inline u16 OCTEP_MAJOR_REV(struct octep_device *oct)
drivers/net/ethernet/marvell/octeon_ep/octep_regs_cn9k_pf.h +2 -0
index 0466fd9a002d..b25c3093dc7b 100644
@@ -367,5 +367,7 @@
 
 /* bit 0 for control mbox interrupt */
 #define CN93_SDP_EPF_OEI_RINT_DATA_BIT_MBOX	BIT_ULL(0)
+/* bit 1 for firmware heartbeat interrupt */
+#define CN93_SDP_EPF_OEI_RINT_DATA_BIT_HBEAT	BIT_ULL(1)
 
 #endif /* _OCTEP_REGS_CN9K_PF_H_ */
Signature · 1 line
2.36.0
author maintainer
#13 lore raw

RE: [EXT] Re: [PATCH net-next v4 8/8] octeon_ep: add heartbeat monitor

Quoted 125 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Thursday, March 23, 2023 3:47 AM
To: Veerasenareddy Burru <[email protected]>
Cc: [email protected]; [email protected]; Abhijit Ayarekar <[email protected]>; Sathesh B Edara <[email protected]>; Satananda Burla <[email protected]>; [email protected]; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>
Subject: [EXT] Re: [PATCH net-next v4 8/8] octeon_ep: add heartbeat monitor

External Email

----------------------------------------------------------------------

Quoted 16 lines · Veerasenareddy Burru

Monitor periodic heartbeat messages from device firmware. Presence of heartbeat indicates the device is active and running. If the heartbeat is missed for configured interval indicates firmware has crashed and device is unusable; in this case, PF driver stops and uninitialize the device.

---
v3 -> v4:
* 0007-xxx.patch in v3 is 0008-xxx.patch in v4.

v2 -> v3:
* 0009-xxx.patch in v2 is now 0007-xxx.patch in v3 due to 0007 and 0008.patch from v2 are removed in v3.

Quoted 6 lines

v1 -> v2:
* no change

 .../marvell/octeon_ep/octep_cn9k_pf.c         |  9 ++++
 .../ethernet/marvell/octeon_ep/octep_config.h |  6 +++
 .../ethernet/marvell/octeon_ep/octep_main.c   | 45

++++++++++++++++++-

drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c line 17

Quoted 12 lines
 .../ethernet/marvell/octeon_ep/octep_main.h   |  7 +++
 .../marvell/octeon_ep/octep_regs_cn9k_pf.h    |  2 +
 5 files changed, 67 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +0 -0
index e2503c9bc8a1..90c3a419932d 100644
@@ -16,6 +16,9 @@
 #define CTRL_MBOX_MAX_PF	128
 #define CTRL_MBOX_SZ		((size_t)(0x400000 /

CTRL_MBOX_MAX_PF))

drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c static void octep_init_config_cn93_pf(struct

Quoted 8 lines
drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +3 -0
+#define FW_HB_INTERVAL_IN_SECS		1
+#define FW_HB_MISS_COUNT		10
+
 /* Names of Hardware non-queue generic interrupts */  static char
 *cn93_non_ioq_msix_names[] = {
 	"epf_ire_rint",
@@ -249,6 +252,10 @@ static void octep_init_config_cn93_pf(struct

octep_device *oct)

Quoted 11 lines
drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +0 -0
 	conf->ctrl_mbox_cfg.barmem_addr = (void __iomem *)oct-

mmio[2].hw_addr +

drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +4 -0
 					   (0x400000ull * 7) +
 					   (link * CTRL_MBOX_SZ);
+
+	conf->hb_interval = FW_HB_INTERVAL_IN_SECS;
+	conf->max_hb_miss_cnt = FW_HB_MISS_COUNT;
+
 }
 
 /* Setup registers for a hardware Tx Queue  */ @@ -383,6 +390,8 @@
Quoted 1 line

static bool octep_poll_non_ioq_interrupts_cn93_pf(struct octep_device

*oct)

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static void octep_intr_poll_task(struct work_struct

Quoted 31 lines
drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +2 -0
 		octep_write_csr64(oct, CN93_SDP_EPF_OEI_RINT, reg0);
 		if (reg0 & CN93_SDP_EPF_OEI_RINT_DATA_BIT_MBOX)
 			queue_work(octep_wq, &oct->ctrl_mbox_task);
+		else if (reg0 & CN93_SDP_EPF_OEI_RINT_DATA_BIT_HBEAT)
+			atomic_set(&oct->hb_miss_cnt, 0);
 
 		handled = true;
 	}
drivers/net/ethernet/marvell/octeon_ep/octep_config.h +6 -0
index f208f3f9a447..df7cd39d9fce 100644
@@ -200,5 +200,11 @@ struct octep_config {
 
 	/* ctrl mbox config */
 	struct octep_ctrl_mbox_config ctrl_mbox_cfg;
+
+	/* Configured maximum heartbeat miss count */
+	u32 max_hb_miss_cnt;
+
+	/* Configured firmware heartbeat interval in secs */
+	u32 hb_interval;
 };
 #endif /* _OCTEP_CONFIG_H_ */
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +0 -0
index ba0d5fe3081d..415dd06ff344 100644
@@ -901,6 +901,38 @@ static void octep_intr_poll_task(struct work_struct

*work)

Quoted 1 line

msecs_to_jiffies(OCTEP_INTR_POLL_TIME_MSECS));

Quoted 4 lines

}

+/**
+ * octep_hb_timeout_task - work queue task to check firmware

heartbeat.

Quoted 10 lines

+ *
+ * @work: pointer to hb work_struct
+ *
+ * Check for heartbeat miss count. Uninitialize oct device if miss

drivers/net/ethernet/marvell/octeon_ep/octep_main.c +6 -0
+count
+ * exceeds configured max heartbeat miss count.
+ *
+ **/
+static void octep_hb_timeout_task(struct work_struct *work) {
+	struct octep_device *oct = container_of(work, struct octep_device,
Quoted 9 lines

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static void octep_intr_poll_task(struct work_struct *work) · line 921

Quoted 6 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +6 -0
+						hb_task.work);
+
+	int miss_cnt;
+
+	atomic_inc(&oct->hb_miss_cnt);
+	miss_cnt = atomic_read(&oct->hb_miss_cnt);

miss_cnt = atomic_inc_return(&oct->hb_miss_cnt);

Thanks for the feedback. Will fix it.

Quoted 8 lines

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static void octep_intr_poll_task(struct work_struct *work) · line 922

Quoted 1 line
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +1 -0
+	if (miss_cnt < oct->conf->max_hb_miss_cnt) {

How is this heartbeat working? You increment on every entry to octep_hb_timeout_task(), After max_hb_miss_cnt invocations, you will stop your device.

Thanks

Yes, device will be stopped after max_hb_miss_cnt heartbeats are missed.

Quoted 86 lines

drivers/net/ethernet/marvell/octeon_ep/octep_main.c

Quoted 2 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +2 -0
+		queue_delayed_work(octep_wq, &oct->hb_task,
+				   msecs_to_jiffies(oct->conf->hb_interval *

1000));

Quoted 83 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +22 -2
+		return;
+	}
+
+	dev_err(&oct->pdev->dev, "Missed %u heartbeats. Uninitializing\n",
+		miss_cnt);
+	rtnl_lock();
+	if (netif_running(oct->netdev))
+		octep_stop(oct->netdev);
+	rtnl_unlock();
+}
+
 /**
  * octep_ctrl_mbox_task - work queue task to handle ctrl mbox messages.
  *
@@ -938,7 +970,7 @@ static const char *octep_devid_to_str(struct
 octep_device *oct)  int octep_device_setup(struct octep_device *oct)
 {
 	struct pci_dev *pdev = oct->pdev;
-	int i;
+	int i, ret;
 
 	/* allocate memory for oct->conf */
 	oct->conf = kzalloc(sizeof(*oct->conf), GFP_KERNEL); @@ -973,7
+1005,15 @@ int octep_device_setup(struct octep_device *oct)
 
 	oct->pkind = CFG_GET_IQ_PKIND(oct->conf);
 
-	return octep_ctrl_net_init(oct);
+	ret = octep_ctrl_net_init(oct);
+	if (ret)
+		return ret;
+
+	atomic_set(&oct->hb_miss_cnt, 0);
+	INIT_DELAYED_WORK(&oct->hb_task, octep_hb_timeout_task);
+	queue_delayed_work(octep_wq, &oct->hb_task,
+			   msecs_to_jiffies(oct->conf->hb_interval * 1000));
+	return 0;
 
 unsupported_dev:
 	for (i = 0; i < OCTEP_MMIO_REGIONS; i++) @@ -1002,6 +1042,7 @@

static void octep_device_cleanup(struct octep_device *oct)

drivers/net/ethernet/marvell/octeon_ep/octep_main.c +1 -0
 	}
 
 	octep_ctrl_net_uninit(oct);
+	cancel_delayed_work_sync(&oct->hb_task);
 
 	oct->hw_ops.soft_reset(oct);
 	for (i = 0; i < OCTEP_MMIO_REGIONS; i++) { diff --git

a/drivers/net/ethernet/marvell/octeon_ep/octep_main.h b/drivers/net/ethernet/marvell/octeon_ep/octep_main.h index 836d990ba3fa..e0907a719133 100644

drivers/net/ethernet/marvell/octeon_ep/octep_main.h +7 -1
@@ -280,6 +280,13 @@ struct octep_device {
 	bool poll_non_ioq_intr;
 	/* Work entry to poll non-ioq interrupts */
 	struct delayed_work intr_poll_task;
+
+	/* Firmware heartbeat timer */
+	struct timer_list hb_timer;
+	/* Firmware heartbeat miss count tracked by timer */
+	atomic_t hb_miss_cnt;
+	/* Task to reset device on heartbeat miss */
+	struct delayed_work hb_task;
 };
 
 static inline u16 OCTEP_MAJOR_REV(struct octep_device *oct) diff
--git a/drivers/net/ethernet/marvell/octeon_ep/octep_regs_cn9k_pf.h

b/drivers/net/ethernet/marvell/octeon_ep/octep_regs_cn9k_pf.h index 0466fd9a002d..b25c3093dc7b 100644

drivers/net/ethernet/marvell/octeon_ep/octep_regs_cn9k_pf.h +2 -1
@@ -367,5 +367,7 @@
 
 /* bit 0 for control mbox interrupt */
 #define CN93_SDP_EPF_OEI_RINT_DATA_BIT_MBOX	BIT_ULL(0)
+/* bit 1 for firmware heartbeat interrupt */
+#define CN93_SDP_EPF_OEI_RINT_DATA_BIT_HBEAT	BIT_ULL(1)
 
 #endif /* _OCTEP_REGS_CN9K_PF_H_ */
--

2.36.0

#14 lore raw

Re: [EXT] Re: [PATCH net-next v4 8/8] octeon_ep: add heartbeat monitor

Quoted 36 lines · Veerasenareddy Burru
Quoted 36 lines

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Thursday, March 23, 2023 3:47 AM
To: Veerasenareddy Burru <[email protected]>
Cc: [email protected]; [email protected]; Abhijit Ayarekar <[email protected]>; Sathesh B Edara <[email protected]>; Satananda Burla <[email protected]>; [email protected]; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>
Subject: [EXT] Re: [PATCH net-next v4 8/8] octeon_ep: add heartbeat monitor

External Email

----------------------------------------------------------------------

Quoted 18 lines · Veerasenareddy Burru

Monitor periodic heartbeat messages from device firmware. Presence of heartbeat indicates the device is active and running. If the heartbeat is missed for configured interval indicates firmware has crashed and device is unusable; in this case, PF driver stops and uninitialize the device.

---
v3 -> v4:
* 0007-xxx.patch in v3 is 0008-xxx.patch in v4.

v2 -> v3:
* 0009-xxx.patch in v2 is now 0007-xxx.patch in v3 due to 0007 and 0008.patch from v2 are removed in v3.

v1 -> v2:
* no change

<...>

Quoted 19 lines
Quoted 10 lines

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static void octep_intr_poll_task(struct work_struct *work) · line 921

Quoted 7 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +7 -0
+	struct octep_device *oct = container_of(work, struct octep_device,
+						hb_task.work);
+
+	int miss_cnt;
+
+	atomic_inc(&oct->hb_miss_cnt);
+	miss_cnt = atomic_read(&oct->hb_miss_cnt);

miss_cnt = atomic_inc_return(&oct->hb_miss_cnt);

Thanks for the feedback. Will fix it.

Quoted 6 lines

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static void octep_intr_poll_task(struct work_struct *work) · line 922

Quoted 1 line
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +1 -0
+	if (miss_cnt < oct->conf->max_hb_miss_cnt) {

How is this heartbeat working? You increment on every entry to octep_hb_timeout_task(), After max_hb_miss_cnt invocations, you will stop your device.

Quoted 4 lines
Quoted 2 lines

Thanks

Yes, device will be stopped after max_hb_miss_cnt heartbeats are missed.

If I read code correctly, device will stop after octep_hb_timeout_task() calls which happens every msecs_to_jiffies(oct->conf->hb_interval * 1000. You don't cancel/resechdule job if timeout doesn't happen.

Thanks

Quoted 4 lines
Quoted 4 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+		queue_delayed_work(octep_wq, &oct->hb_task,
+				   msecs_to_jiffies(oct->conf->hb_interval *

1000));