DPDK patches and discussions
 help / color / mirror / Atom feed
From: Alfredo Cardigliano <cardigliano@ntop.org>
To: Alfredo Cardigliano <cardigliano@ntop.org>
Cc: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v5 05/17] net/ionic: add port management commands
Date: Sun, 19 Jan 2020 16:53:43 +0100	[thread overview]
Message-ID: <20200119155356.20403-6-cardigliano@ntop.org> (raw)
In-Reply-To: <20200119155356.20403-1-cardigliano@ntop.org>

Add port management commands that apply to the physical
ports associated with the PCI device, which might be
shared among several logical interfaces.

Signed-off-by: Alfredo Cardigliano <cardigliano@ntop.org>
Reviewed-by: Shannon Nelson <snelson@pensando.io>
---
 drivers/net/ionic/ionic.h        |   6 ++
 drivers/net/ionic/ionic_dev.c    | 127 +++++++++++++++++++++++++++++++
 drivers/net/ionic/ionic_dev.h    |  18 +++++
 drivers/net/ionic/ionic_ethdev.c |  14 ++++
 drivers/net/ionic/ionic_main.c   | 127 +++++++++++++++++++++++++++++++
 5 files changed, 292 insertions(+)

diff --git a/drivers/net/ionic/ionic.h b/drivers/net/ionic/ionic.h
index a415dd80a..1adea8f7d 100644
--- a/drivers/net/ionic/ionic.h
+++ b/drivers/net/ionic/ionic.h
@@ -8,6 +8,8 @@
 #include <stdint.h>
 #include <inttypes.h>
 
+#include <rte_bus_pci.h>
+
 #include "ionic_dev.h"
 #include "ionic_if.h"
 #include "ionic_osdep.h"
@@ -61,4 +63,8 @@ int ionic_identify(struct ionic_adapter *adapter);
 int ionic_init(struct ionic_adapter *adapter);
 int ionic_reset(struct ionic_adapter *adapter);
 
+int ionic_port_identify(struct ionic_adapter *adapter);
+int ionic_port_init(struct ionic_adapter *adapter);
+int ionic_port_reset(struct ionic_adapter *adapter);
+
 #endif /* _IONIC_H_ */
diff --git a/drivers/net/ionic/ionic_dev.c b/drivers/net/ionic/ionic_dev.c
index a8ad5358f..d74834122 100644
--- a/drivers/net/ionic/ionic_dev.c
+++ b/drivers/net/ionic/ionic_dev.c
@@ -132,3 +132,130 @@ ionic_dev_cmd_reset(struct ionic_dev *idev)
 
 	ionic_dev_cmd_go(idev, &cmd);
 }
+
+/* Port commands */
+
+void
+ionic_dev_cmd_port_identify(struct ionic_dev *idev)
+{
+	union ionic_dev_cmd cmd = {
+		.port_init.opcode = IONIC_CMD_PORT_IDENTIFY,
+		.port_init.index = 0,
+	};
+
+	ionic_dev_cmd_go(idev, &cmd);
+}
+
+void
+ionic_dev_cmd_port_init(struct ionic_dev *idev)
+{
+	union ionic_dev_cmd cmd = {
+		.port_init.opcode = IONIC_CMD_PORT_INIT,
+		.port_init.index = 0,
+		.port_init.info_pa = idev->port_info_pa,
+	};
+
+	ionic_dev_cmd_go(idev, &cmd);
+}
+
+void
+ionic_dev_cmd_port_reset(struct ionic_dev *idev)
+{
+	union ionic_dev_cmd cmd = {
+		.port_reset.opcode = IONIC_CMD_PORT_RESET,
+		.port_reset.index = 0,
+	};
+
+	ionic_dev_cmd_go(idev, &cmd);
+}
+
+void
+ionic_dev_cmd_port_state(struct ionic_dev *idev, uint8_t state)
+{
+	union ionic_dev_cmd cmd = {
+		.port_setattr.opcode = IONIC_CMD_PORT_SETATTR,
+		.port_setattr.index = 0,
+		.port_setattr.attr = IONIC_PORT_ATTR_STATE,
+		.port_setattr.state = state,
+	};
+
+	ionic_dev_cmd_go(idev, &cmd);
+}
+
+void
+ionic_dev_cmd_port_speed(struct ionic_dev *idev, uint32_t speed)
+{
+	union ionic_dev_cmd cmd = {
+		.port_setattr.opcode = IONIC_CMD_PORT_SETATTR,
+		.port_setattr.index = 0,
+		.port_setattr.attr = IONIC_PORT_ATTR_SPEED,
+		.port_setattr.speed = speed,
+	};
+
+	ionic_dev_cmd_go(idev, &cmd);
+}
+
+void
+ionic_dev_cmd_port_mtu(struct ionic_dev *idev, uint32_t mtu)
+{
+	union ionic_dev_cmd cmd = {
+		.port_setattr.opcode = IONIC_CMD_PORT_SETATTR,
+		.port_setattr.index = 0,
+		.port_setattr.attr = IONIC_PORT_ATTR_MTU,
+		.port_setattr.mtu = mtu,
+	};
+
+	ionic_dev_cmd_go(idev, &cmd);
+}
+
+void
+ionic_dev_cmd_port_autoneg(struct ionic_dev *idev, uint8_t an_enable)
+{
+	union ionic_dev_cmd cmd = {
+		.port_setattr.opcode = IONIC_CMD_PORT_SETATTR,
+		.port_setattr.index = 0,
+		.port_setattr.attr = IONIC_PORT_ATTR_AUTONEG,
+		.port_setattr.an_enable = an_enable,
+	};
+
+	ionic_dev_cmd_go(idev, &cmd);
+}
+
+void
+ionic_dev_cmd_port_fec(struct ionic_dev *idev, uint8_t fec_type)
+{
+	union ionic_dev_cmd cmd = {
+		.port_setattr.opcode = IONIC_CMD_PORT_SETATTR,
+		.port_setattr.index = 0,
+		.port_setattr.attr = IONIC_PORT_ATTR_FEC,
+		.port_setattr.fec_type = fec_type,
+	};
+
+	ionic_dev_cmd_go(idev, &cmd);
+}
+
+void
+ionic_dev_cmd_port_pause(struct ionic_dev *idev, uint8_t pause_type)
+{
+	union ionic_dev_cmd cmd = {
+		.port_setattr.opcode = IONIC_CMD_PORT_SETATTR,
+		.port_setattr.index = 0,
+		.port_setattr.attr = IONIC_PORT_ATTR_PAUSE,
+		.port_setattr.pause_type = pause_type,
+	};
+
+	ionic_dev_cmd_go(idev, &cmd);
+}
+
+void
+ionic_dev_cmd_port_loopback(struct ionic_dev *idev, uint8_t loopback_mode)
+{
+	union ionic_dev_cmd cmd = {
+		.port_setattr.opcode = IONIC_CMD_PORT_SETATTR,
+		.port_setattr.index = 0,
+		.port_setattr.attr = IONIC_PORT_ATTR_LOOPBACK,
+		.port_setattr.loopback_mode = loopback_mode,
+	};
+
+	ionic_dev_cmd_go(idev, &cmd);
+}
diff --git a/drivers/net/ionic/ionic_dev.h b/drivers/net/ionic/ionic_dev.h
index 82a3cdb70..75c50d4cb 100644
--- a/drivers/net/ionic/ionic_dev.h
+++ b/drivers/net/ionic/ionic_dev.h
@@ -10,6 +10,7 @@
 #include "ionic_regs.h"
 
 #define IONIC_DEVCMD_TIMEOUT	30 /* devcmd_timeout */
+#define	IONIC_ALIGN             4096
 
 struct ionic_adapter;
 
@@ -111,6 +112,11 @@ struct ionic_dev {
 	struct ionic_intr __iomem *intr_ctrl;
 
 	struct ionic_intr_status __iomem *intr_status;
+
+	struct ionic_port_info *port_info;
+	const struct rte_memzone *port_info_z;
+	rte_iova_t port_info_pa;
+	uint32_t port_info_sz;
 };
 
 int ionic_dev_setup(struct ionic_adapter *adapter);
@@ -124,4 +130,16 @@ void ionic_dev_cmd_identify(struct ionic_dev *idev, uint8_t ver);
 void ionic_dev_cmd_init(struct ionic_dev *idev);
 void ionic_dev_cmd_reset(struct ionic_dev *idev);
 
+void ionic_dev_cmd_port_identify(struct ionic_dev *idev);
+void ionic_dev_cmd_port_init(struct ionic_dev *idev);
+void ionic_dev_cmd_port_reset(struct ionic_dev *idev);
+void ionic_dev_cmd_port_state(struct ionic_dev *idev, uint8_t state);
+void ionic_dev_cmd_port_speed(struct ionic_dev *idev, uint32_t speed);
+void ionic_dev_cmd_port_mtu(struct ionic_dev *idev, uint32_t mtu);
+void ionic_dev_cmd_port_autoneg(struct ionic_dev *idev, uint8_t an_enable);
+void ionic_dev_cmd_port_fec(struct ionic_dev *idev, uint8_t fec_type);
+void ionic_dev_cmd_port_pause(struct ionic_dev *idev, uint8_t pause_type);
+void ionic_dev_cmd_port_loopback(struct ionic_dev *idev,
+	uint8_t loopback_mode);
+
 #endif /* _IONIC_DEV_H_ */
diff --git a/drivers/net/ionic/ionic_ethdev.c b/drivers/net/ionic/ionic_ethdev.c
index e23d0622c..b0ae7b076 100644
--- a/drivers/net/ionic/ionic_ethdev.c
+++ b/drivers/net/ionic/ionic_ethdev.c
@@ -98,6 +98,20 @@ eth_ionic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 		goto err_free_adapter;
 	}
 
+	/* Configure the ports */
+	err = ionic_port_identify(adapter);
+	if (err) {
+		IONIC_PRINT(ERR, "Cannot identify port: %d, aborting",
+			err);
+		goto err_free_adapter;
+	}
+
+	err = ionic_port_init(adapter);
+	if (err) {
+		IONIC_PRINT(ERR, "Cannot init port: %d, aborting", err);
+		goto err_free_adapter;
+	}
+
 	return 0;
 
 err_free_adapter:
diff --git a/drivers/net/ionic/ionic_main.c b/drivers/net/ionic/ionic_main.c
index 63b4ffc46..0b420ee0b 100644
--- a/drivers/net/ionic/ionic_main.c
+++ b/drivers/net/ionic/ionic_main.c
@@ -2,6 +2,8 @@
  * Copyright(c) 2018-2019 Pensando Systems, Inc. All rights reserved.
  */
 
+#include <rte_memzone.h>
+
 #include "ionic.h"
 
 static int
@@ -128,3 +130,128 @@ ionic_reset(struct ionic_adapter *adapter)
 	err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
 	return err;
 }
+
+int
+ionic_port_identify(struct ionic_adapter *adapter)
+{
+	struct ionic_dev *idev = &adapter->idev;
+	struct ionic_identity *ident = &adapter->ident;
+	unsigned int port_words = sizeof(ident->port.words) /
+		sizeof(ident->port.words[0]);
+	unsigned int cmd_words = sizeof(idev->dev_cmd->data) /
+		sizeof(idev->dev_cmd->data[0]);
+	unsigned int i;
+	unsigned int nwords;
+	int err;
+
+	ionic_dev_cmd_port_identify(idev);
+	err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
+	if (!err) {
+		nwords = RTE_MIN(port_words, cmd_words);
+		for (i = 0; i < nwords; i++)
+			ident->port.words[i] =
+				ioread32(&idev->dev_cmd->data[i]);
+	}
+
+	IONIC_PRINT(INFO, "speed %d ", ident->port.config.speed);
+	IONIC_PRINT(INFO, "mtu %d ", ident->port.config.mtu);
+	IONIC_PRINT(INFO, "state %d ", ident->port.config.state);
+	IONIC_PRINT(INFO, "an_enable %d ", ident->port.config.an_enable);
+	IONIC_PRINT(INFO, "fec_type %d ", ident->port.config.fec_type);
+	IONIC_PRINT(INFO, "pause_type %d ", ident->port.config.pause_type);
+	IONIC_PRINT(INFO, "loopback_mode %d",
+		ident->port.config.loopback_mode);
+
+	return err;
+}
+
+static const struct rte_memzone *
+ionic_memzone_reserve(const char *name, uint32_t len, int socket_id)
+{
+	const struct rte_memzone *mz;
+
+	mz = rte_memzone_lookup(name);
+	if (mz)
+		return mz;
+
+	mz = rte_memzone_reserve_aligned(name, len, socket_id,
+		RTE_MEMZONE_IOVA_CONTIG, IONIC_ALIGN);
+	return mz;
+}
+
+int
+ionic_port_init(struct ionic_adapter *adapter)
+{
+	struct ionic_dev *idev = &adapter->idev;
+	struct ionic_identity *ident = &adapter->ident;
+	char z_name[RTE_MEMZONE_NAMESIZE];
+	unsigned int config_words = sizeof(ident->port.config.words) /
+		sizeof(ident->port.config.words[0]);
+	unsigned int cmd_words = sizeof(idev->dev_cmd->data) /
+		sizeof(idev->dev_cmd->data[0]);
+	unsigned int nwords;
+	unsigned int i;
+	int err;
+
+	if (idev->port_info)
+		return 0;
+
+	idev->port_info_sz = RTE_ALIGN(sizeof(*idev->port_info), PAGE_SIZE);
+
+	snprintf(z_name, sizeof(z_name), "%s_port_%s_info",
+		IONIC_DRV_NAME,
+		adapter->pci_dev->device.name);
+
+	idev->port_info_z = ionic_memzone_reserve(z_name, idev->port_info_sz,
+		SOCKET_ID_ANY);
+	if (!idev->port_info_z) {
+		IONIC_PRINT(ERR, "Cannot reserve port info DMA memory");
+		return -ENOMEM;
+	}
+
+	idev->port_info = idev->port_info_z->addr;
+	idev->port_info_pa = idev->port_info_z->iova;
+
+	nwords = RTE_MIN(config_words, cmd_words);
+
+	for (i = 0; i < nwords; i++)
+		iowrite32(ident->port.config.words[i], &idev->dev_cmd->data[i]);
+
+	ionic_dev_cmd_port_init(idev);
+	err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
+	if (err) {
+		IONIC_PRINT(ERR, "Failed to init port");
+		return err;
+	}
+
+	ionic_dev_cmd_port_state(idev, IONIC_PORT_ADMIN_STATE_UP);
+	err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
+	if (err) {
+		IONIC_PRINT(WARNING, "Failed to bring port UP");
+		return err;
+	}
+
+	return 0;
+}
+
+int
+ionic_port_reset(struct ionic_adapter *adapter)
+{
+	struct ionic_dev *idev = &adapter->idev;
+	int err;
+
+	if (!idev->port_info)
+		return 0;
+
+	ionic_dev_cmd_port_reset(idev);
+	err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
+	if (err) {
+		IONIC_PRINT(ERR, "Failed to reset port");
+		return err;
+	}
+
+	idev->port_info = NULL;
+	idev->port_info_pa = 0;
+
+	return 0;
+}
-- 
2.17.1


  parent reply	other threads:[~2020-01-19 15:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-19 15:53 [dpdk-dev] [PATCH v5 00/17] Introduces net/ionic PMD Alfredo Cardigliano
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 01/17] net/ionic: add skeleton Alfredo Cardigliano
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 02/17] net/ionic: add hardware structures definitions Alfredo Cardigliano
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 03/17] net/ionic: add log Alfredo Cardigliano
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 04/17] net/ionic: register and initialize the adapter Alfredo Cardigliano
2020-01-19 15:53 ` Alfredo Cardigliano [this message]
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 06/17] net/ionic: add basic lif support Alfredo Cardigliano
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 07/17] net/ionic: add doorbells Alfredo Cardigliano
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 08/17] net/ionic: add adminq support Alfredo Cardigliano
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 09/17] net/ionic: add notifyq support Alfredo Cardigliano
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 10/17] net/ionic: add basic port operations Alfredo Cardigliano
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 11/17] net/ionic: add Rx filters support Alfredo Cardigliano
2020-01-20 16:57   ` Ferruh Yigit
2020-01-21  7:43     ` Raslan Darawsheh
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 12/17] net/ionic: add Flow Control support Alfredo Cardigliano
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 13/17] net/ionic: add Rx and Tx handling Alfredo Cardigliano
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 14/17] net/ionic: add RSS support Alfredo Cardigliano
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 15/17] net/ionic: add stats Alfredo Cardigliano
2020-01-20 12:10   ` Ferruh Yigit
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 16/17] net/ionic: add Tx checksum support Alfredo Cardigliano
2020-01-19 15:53 ` [dpdk-dev] [PATCH v5 17/17] net/ionic: read Fw version Alfredo Cardigliano
2020-01-20 13:05 ` [dpdk-dev] [PATCH v5 00/17] Introduces net/ionic PMD Ferruh Yigit
2020-01-20 13:38   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200119155356.20403-6-cardigliano@ntop.org \
    --to=cardigliano@ntop.org \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).