All of lore.kernel.org
 help / color / mirror / Atom feed
From: Santosh Shukla <santosh.shukla@caviumnetworks.com>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, jerin.jacob@caviumnetworks.com,
	Santosh Shukla <santosh.shukla@caviumnetworks.com>
Subject: [PATCH v2 12/26] net/octeontx: create ethdev ports
Date: Sun,  8 Oct 2017 18:14:16 +0530	[thread overview]
Message-ID: <20171008124430.1866-13-santosh.shukla@caviumnetworks.com> (raw)
In-Reply-To: <20171008124430.1866-1-santosh.shukla@caviumnetworks.com>

From: Jerin Jacob <jerin.jacob@caviumnetworks.com>

Create ethdev ports by registering  withethdev subsystem based on
"nr_port" vdev argument or maximum physical ports available in the system.

Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
Co-authored-by: Santosh Shukla <santosh.shukla@caviumnetworks.com>
Signed-off-by: Santosh Shukla <santosh.shukla@caviumnetworks.com>
---
 drivers/net/octeontx/octeontx_ethdev.c | 172 ++++++++++++++++++++++++++++++++-
 1 file changed, 167 insertions(+), 5 deletions(-)

diff --git a/drivers/net/octeontx/octeontx_ethdev.c b/drivers/net/octeontx/octeontx_ethdev.c
index 621035233..6a727a0f0 100644
--- a/drivers/net/octeontx/octeontx_ethdev.c
+++ b/drivers/net/octeontx/octeontx_ethdev.c
@@ -105,6 +105,50 @@ octeontx_parse_vdev_init_params(struct octeontx_vdev_init_params *params,
 	return ret;
 }
 
+static int
+octeontx_port_open(struct octeontx_nic *nic)
+{
+	octeontx_mbox_bgx_port_conf_t bgx_port_conf;
+	int res;
+
+	res = 0;
+
+	PMD_INIT_FUNC_TRACE();
+
+	res = octeontx_bgx_port_open(nic->port_id, &bgx_port_conf);
+	if (res < 0) {
+		octeontx_log_err("failed to open port %d", res);
+		return res;
+	}
+
+	nic->node = bgx_port_conf.node;
+	nic->port_ena = bgx_port_conf.enable;
+	nic->base_ichan = bgx_port_conf.base_chan;
+	nic->base_ochan = bgx_port_conf.base_chan;
+	nic->num_ichans = bgx_port_conf.num_chans;
+	nic->num_ochans = bgx_port_conf.num_chans;
+	nic->mtu = bgx_port_conf.mtu;
+	nic->bpen = bgx_port_conf.bpen;
+	nic->fcs_strip = bgx_port_conf.fcs_strip;
+	nic->bcast_mode = bgx_port_conf.bcast_mode;
+	nic->mcast_mode = bgx_port_conf.mcast_mode;
+	nic->speed	= bgx_port_conf.mode;
+
+	memcpy(&nic->mac_addr[0], &bgx_port_conf.macaddr[0], ETHER_ADDR_LEN);
+
+	octeontx_log_dbg("port opened %d", nic->port_id);
+	return res;
+}
+
+static void
+octeontx_port_close(struct octeontx_nic *nic)
+{
+	PMD_INIT_FUNC_TRACE();
+
+	octeontx_bgx_port_close(nic->port_id);
+	octeontx_log_dbg("port closed %d", nic->port_id);
+}
+
 static inline void
 devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
 				struct rte_event_dev_info *info)
@@ -126,17 +170,135 @@ devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
 			info->max_num_events;
 }
 
+/* Initialize and register driver with DPDK Application */
+static const struct eth_dev_ops octeontx_dev_ops = {
+};
+
 /* Create Ethdev interface per BGX LMAC ports */
 static int
 octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
 			int socket_id)
 {
-	RTE_SET_USED(dev);
-	RTE_SET_USED(port);
-	RTE_SET_USED(evdev);
-	RTE_SET_USED(socket_id);
+	int res;
+	char octtx_name[OCTEONTX_MAX_NAME_LEN];
+	struct octeontx_nic *nic = NULL;
+	struct rte_eth_dev *eth_dev = NULL;
+	struct rte_eth_dev_data *data = NULL;
+	const char *name = rte_vdev_device_name(dev);
 
-	return -ENODEV;
+	PMD_INIT_FUNC_TRACE();
+
+	sprintf(octtx_name, "%s_%d", name, port);
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
+		eth_dev = rte_eth_dev_attach_secondary(octtx_name);
+		if (eth_dev == NULL)
+			return -ENODEV;
+
+		return 0;
+	}
+
+	data = rte_zmalloc_socket(octtx_name, sizeof(*data), 0, socket_id);
+	if (data == NULL) {
+		octeontx_log_err("failed to allocate devdata");
+		res = -ENOMEM;
+		goto err;
+	}
+
+	nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id);
+	if (nic == NULL) {
+		octeontx_log_err("failed to allocate nic structure");
+		res = -ENOMEM;
+		goto err;
+	}
+
+	nic->port_id = port;
+	nic->evdev = evdev;
+
+	res = octeontx_port_open(nic);
+	if (res < 0)
+		goto err;
+
+	/* Rx side port configuration */
+	res = octeontx_pki_port_open(port);
+	if (res != 0) {
+		octeontx_log_err("failed to open PKI port %d", port);
+		res = -ENODEV;
+		goto err;
+	}
+
+	/* Reserve an ethdev entry */
+	eth_dev = rte_eth_dev_allocate(octtx_name);
+	if (eth_dev == NULL) {
+		octeontx_log_err("failed to allocate rte_eth_dev");
+		res = -ENOMEM;
+		goto err;
+	}
+
+	eth_dev->device = &dev->device;
+	eth_dev->intr_handle = NULL;
+	eth_dev->data->kdrv = RTE_KDRV_NONE;
+	eth_dev->data->numa_node = dev->device.numa_node;
+
+	rte_memcpy(data, (eth_dev)->data, sizeof(*data));
+	data->dev_private = nic;
+
+	data->port_id = eth_dev->data->port_id;
+	snprintf(data->name, sizeof(data->name), "%s", eth_dev->data->name);
+
+	nic->ev_queues = 1;
+	nic->ev_ports = 1;
+
+	data->dev_link.link_status = ETH_LINK_DOWN;
+	data->dev_started = 0;
+	data->promiscuous = 0;
+	data->all_multicast = 0;
+	data->scattered_rx = 0;
+
+	data->mac_addrs = rte_zmalloc_socket(octtx_name, ETHER_ADDR_LEN, 0,
+							socket_id);
+	if (data->mac_addrs == NULL) {
+		octeontx_log_err("failed to allocate memory for mac_addrs");
+		res = -ENOMEM;
+		goto err;
+	}
+
+	eth_dev->data = data;
+	eth_dev->dev_ops = &octeontx_dev_ops;
+
+	/* Finally save ethdev pointer to the NIC structure */
+	nic->dev = eth_dev;
+
+	if (nic->port_id != data->port_id) {
+		octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
+				data->port_id, nic->port_id);
+		res = -EINVAL;
+		goto err;
+	}
+
+	/* Update port_id mac to eth_dev */
+	memcpy(data->mac_addrs, nic->mac_addr, ETHER_ADDR_LEN);
+
+	PMD_INIT_LOG(DEBUG, "ethdev info: ");
+	PMD_INIT_LOG(DEBUG, "port %d, port_ena %d ochan %d num_ochan %d tx_q %d",
+				nic->port_id, nic->port_ena,
+				nic->base_ochan, nic->num_ochans,
+				nic->num_tx_queues);
+	PMD_INIT_LOG(DEBUG, "speed %d mtu %d", nic->speed, nic->mtu);
+
+	return data->port_id;
+
+err:
+	if (port)
+		octeontx_port_close(nic);
+
+	if (eth_dev != NULL) {
+		rte_free(eth_dev->data->mac_addrs);
+		rte_free(data);
+		rte_free(nic);
+		rte_eth_dev_release_port(eth_dev);
+	}
+
+	return res;
 }
 
 /* Un initialize octeontx device */
-- 
2.14.1

  parent reply	other threads:[~2017-10-08 12:45 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 14:54 [PATCH 00/26] DPDK PMD for OCTEONTX NW device Jerin Jacob
2017-08-31 14:54 ` [PATCH 01/26] net/octeontx: add build infrastructure Jerin Jacob
2017-08-31 14:54 ` [PATCH 02/26] net/octeontx/base: add octeontx io operations Jerin Jacob
2017-08-31 14:54 ` [PATCH 03/26] event/octeontx: introduce specialized mbox message copy Jerin Jacob
2017-08-31 14:54 ` [PATCH 04/26] net/octeontx/base: add base BGX operations Jerin Jacob
2017-08-31 14:54 ` [PATCH 05/26] net/octeontx/base: add remaining " Jerin Jacob
2017-08-31 14:54 ` [PATCH 06/26] net/octeontx/base: probe PKI and PKO PCIe VF devices Jerin Jacob
2017-09-05 17:44   ` Ferruh Yigit
2017-09-11 18:27     ` Jerin Jacob
2017-08-31 14:54 ` [PATCH 07/26] net/octeontx/base: add base PKI operations Jerin Jacob
2017-08-31 14:54 ` [PATCH 08/26] net/octeontx/base: add remaining " Jerin Jacob
2017-08-31 14:54 ` [PATCH 09/26] net/octeontx/base: add base PKO operations Jerin Jacob
2017-08-31 14:54 ` [PATCH 10/26] net/octeontx/base: add remaining " Jerin Jacob
2017-08-31 14:54 ` [PATCH 11/26] net/octeontx: add eth device probe and remove Jerin Jacob
2017-08-31 14:54 ` [PATCH 12/26] net/octeontx: create ethdev ports Jerin Jacob
2017-08-31 14:54 ` [PATCH 13/26] net/octeontx: add device configure Jerin Jacob
2017-08-31 14:54 ` [PATCH 14/26] net/octeontx: add device info Jerin Jacob
2017-08-31 14:54 ` [PATCH 15/26] net/octeontx: add link update Jerin Jacob
2017-08-31 14:54 ` [PATCH 16/26] net/octeontx: add promiscuous mode ops Jerin Jacob
2017-08-31 14:54 ` [PATCH 17/26] net/octeontx: add basic stats support Jerin Jacob
2017-08-31 14:54 ` [PATCH 18/26] net/octeontx: add MAC addr set op Jerin Jacob
2017-08-31 14:54 ` [PATCH 19/26] net/octeontx: add Rx queue setup and release ops Jerin Jacob
2017-08-31 14:54 ` [PATCH 20/26] net/octeontx: add Tx queue start and stop Jerin Jacob
2017-08-31 14:54 ` [PATCH 21/26] net/octeontx: add Tx queue setup and release ops Jerin Jacob
2017-08-31 14:54 ` [PATCH 22/26] net/octeontx: add packet transmit burst function Jerin Jacob
2017-08-31 14:54 ` [PATCH 23/26] net/octeontx: add packet receive " Jerin Jacob
2017-08-31 14:54 ` [PATCH 24/26] net/octeontx: add packet type parsing support Jerin Jacob
2017-08-31 14:54 ` [PATCH 25/26] net/octeontx: add start and stop support Jerin Jacob
2017-08-31 14:54 ` [PATCH 26/26] doc: add octeontx ethdev driver documentation Jerin Jacob
2017-09-19 13:59   ` Mcnamara, John
2017-09-05 17:43 ` [PATCH 00/26] DPDK PMD for OCTEONTX NW device Ferruh Yigit
2017-09-11 18:15   ` Jerin Jacob
2017-10-03 19:01     ` Ferruh Yigit
2017-10-04  5:27       ` santosh
2017-10-08 12:44 ` [PATCH v2 " Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 01/26] net/octeontx: add build infrastructure Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 02/26] net/octeontx/base: add octeontx io operations Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 03/26] event/octeontx: introduce specialized mbox message copy Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 04/26] net/octeontx/base: add base BGX operations Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 05/26] net/octeontx/base: add remaining " Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 06/26] net/octeontx/base: probe PKI and PKO PCIe VF devices Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 07/26] net/octeontx/base: add base PKI operations Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 08/26] net/octeontx/base: add remaining " Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 09/26] net/octeontx/base: add base PKO operations Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 10/26] net/octeontx/base: add remaining " Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 11/26] net/octeontx: add eth device probe and remove Santosh Shukla
2017-10-08 12:44   ` Santosh Shukla [this message]
2017-10-08 12:44   ` [PATCH v2 13/26] net/octeontx: add device configure Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 14/26] net/octeontx: add device info Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 15/26] net/octeontx: add link update Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 16/26] net/octeontx: add promiscuous mode ops Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 17/26] net/octeontx: add basic stats support Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 18/26] net/octeontx: add MAC addr set op Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 19/26] net/octeontx: add Rx queue setup and release ops Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 20/26] net/octeontx: add Tx queue start and stop Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 21/26] net/octeontx: add Tx queue setup and release ops Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 22/26] net/octeontx: add packet transmit burst function Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 23/26] net/octeontx: add packet receive " Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 24/26] net/octeontx: add packet type parsing support Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 25/26] net/octeontx: add start and stop support Santosh Shukla
2017-10-08 12:44   ` [PATCH v2 26/26] doc: add octeontx ethdev driver documentation Santosh Shukla
2017-10-09  2:07   ` [PATCH v2 00/26] DPDK PMD for OCTEONTX NW device Ferruh Yigit
2017-10-09  5:12     ` santosh
2017-10-11 10:35     ` Thomas Monjalon
2017-10-11 10:58       ` Jerin Jacob

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=20171008124430.1866-13-santosh.shukla@caviumnetworks.com \
    --to=santosh.shukla@caviumnetworks.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=jerin.jacob@caviumnetworks.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.