Skip to contentSkip to conversation

net/virtio: remove duplicate port id from virtio_user

PATCH In review David Marchand 3 participants 4 messages Feb 1, 2021 – Mar 31, 2021 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/virtio: remove duplicate port id from virtio_user

The private virtio_user_dev structure embeds a virtio_hw which itself contains the ethdev port_id.
Make use of it and remove the duplicate port_id field.

---
Posting this cleanup that I caught when reviewing/discussing the port_id fix from Maxime.
It can wait 21.05.

---
 drivers/net/virtio/virtio_user/vhost_user.c      | 3 ++-
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 6 +++---
 drivers/net/virtio/virtio_user/virtio_user_dev.h | 1 -
 drivers/net/virtio/virtio_user_ethdev.c          | 1 -
 4 files changed, 5 insertions(+), 6 deletions(-)
drivers/net/virtio/virtio_user/vhost_user.c +2 -1
index ec2c53c8fb..18ae29eed2 100644
@@ -950,7 +950,8 @@ vhost_user_update_link_state(struct virtio_user_dev *dev)
 		r = recv(data->vhostfd, buf, 128, MSG_PEEK);
 		if (r == 0 || (r < 0 && errno != EAGAIN)) {
 			dev->net_status &= (~VIRTIO_NET_S_LINK_UP);
-			PMD_DRV_LOG(ERR, "virtio-user port %u is down", dev->port_id);
+			PMD_DRV_LOG(ERR, "virtio-user port %u is down",
+				dev->hw.port_id);
 
 			/* This function could be called in the process
 			 * of interrupt handling, callback cannot be
drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -3
index 1b54d55bd8..2255c99a36 100644
@@ -340,7 +340,7 @@ static int
 virtio_user_fill_intr_handle(struct virtio_user_dev *dev)
 {
 	uint32_t i;
-	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
+	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->hw.port_id];
 
 	if (!eth_dev->intr_handle) {
 		eth_dev->intr_handle = malloc(sizeof(*eth_dev->intr_handle));
@@ -888,7 +888,7 @@ void
 virtio_user_dev_delayed_handler(void *param)
 {
 	struct virtio_user_dev *dev = param;
-	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
+	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->hw.port_id];
 
 	if (rte_intr_disable(eth_dev->intr_handle) < 0) {
 		PMD_DRV_LOG(ERR, "interrupt disable failed");
@@ -913,7 +913,7 @@ int
 virtio_user_dev_server_reconnect(struct virtio_user_dev *dev)
 {
 	int ret, old_status;
-	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
+	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->hw.port_id];
 	struct virtio_hw *hw = &dev->hw;
 
 	if (!dev->ops->server_reconnect) {
drivers/net/virtio/virtio_user/virtio_user_dev.h +0 -1
index 8a62f7ea79..7fd4622f01 100644
@@ -43,7 +43,6 @@ struct virtio_user_dev {
 	uint64_t	unsupported_features; /* unsupported features mask */
 	uint8_t		status;
 	uint16_t	net_status;
-	uint16_t	port_id;
 	uint8_t		mac_addr[RTE_ETHER_ADDR_LEN];
 	char		path[PATH_MAX];
 	char		*ifname;
drivers/net/virtio/virtio_user_ethdev.c +0 -1
index 1810a54694..fb1fe355d3 100644
@@ -428,7 +428,6 @@ virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev)
 	hw = &dev->hw;
 
 	hw->port_id = data->port_id;
-	dev->port_id = data->port_id;
 	VIRTIO_OPS(hw) = &virtio_user_ops;
 
 	hw->intr_lsc = 1;
Signature · 1 line
2.23.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · David Marchand

The private virtio_user_dev structure embeds a virtio_hw which itself contains the ethdev port_id.
Make use of it and remove the duplicate port_id field.

---
Posting this cleanup that I caught when reviewing/discussing the port_id fix from Maxime.
It can wait 21.05.

---
 drivers/net/virtio/virtio_user/vhost_user.c      | 3 ++-
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 6 +++---
 drivers/net/virtio/virtio_user/virtio_user_dev.h | 1 -
 drivers/net/virtio/virtio_user_ethdev.c          | 1 -
 4 files changed, 5 insertions(+), 6 deletions(-)
drivers/net/virtio/virtio_user/vhost_user.c +0 -0
index ec2c53c8fb..18ae29eed2 100644

drivers/net/virtio/virtio_user/vhost_user.c vhost_user_update_link_state(struct virtio_user_dev *dev) · line 954

Quoted 6 lines
drivers/net/virtio/virtio_user/vhost_user.c +2 -1
@@ -950,7 +950,8 @@ vhost_user_update_link_state(struct virtio_user_dev *dev)
 		r = recv(data->vhostfd, buf, 128, MSG_PEEK);
 		if (r == 0 || (r < 0 && errno != EAGAIN)) {
 			dev->net_status &= (~VIRTIO_NET_S_LINK_UP);
-			PMD_DRV_LOG(ERR, "virtio-user port %u is down", dev->port_id);
+			PMD_DRV_LOG(ERR, "virtio-user port %u is down",
+				dev->hw.port_id);

Trivial, but it can fit in a single line, as IIRC, we can go up to 100 chars now. If you agree, we can fix it while applying, no need to resubmit.

Thanks,
Maxime

#2 lore raw
Quoted 7 lines · Maxime Coquelin
Quoted 7 lines
drivers/net/virtio/virtio_user/vhost_user.c +0 -0
index ec2c53c8fb..18ae29eed2 100644
@@ -950,7 +950,8 @@ vhost_user_update_link_state(struct virtio_user_dev *dev)
              r = recv(data->vhostfd, buf, 128, MSG_PEEK);
              if (r == 0 || (r < 0 && errno != EAGAIN)) {
Quoted 8 lines

drivers/net/virtio/virtio_user/vhost_user.c vhost_user_update_link_state(struct virtio_user_dev *dev) · line 954

Quoted 4 lines
drivers/net/virtio/virtio_user/vhost_user.c +2 -1
                      dev->net_status &= (~VIRTIO_NET_S_LINK_UP);
-                     PMD_DRV_LOG(ERR, "virtio-user port %u is down", dev->port_id);
+                     PMD_DRV_LOG(ERR, "virtio-user port %u is down",
+                             dev->hw.port_id);

Trivial, but it can fit in a single line, as IIRC, we can go up to 100 chars now. If you agree, we can fix it while applying, no need to resubmit.

Yep, ok for me, thanks.

Signature · 1 line
David Marchand
#3 lore raw
In reply to David Marchand
Quoted 8 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Tuesday, February 2, 2021 1:46 AM
To: [email protected]
Cc: Maxime Coquelin <[email protected]>; Xia, Chenbo <[email protected]>
Subject: [PATCH 21.05] net/virtio: remove duplicate port id from virtio_user

Quoted 8 lines

The private virtio_user_dev structure embeds a virtio_hw which itself contains the ethdev port_id.
Make use of it and remove the duplicate port_id field.

---
--
2.23.0

Add Maxime's suggested fix and change 'virtio_user' to 'virtio-user' to avoid check-git-log error.

With above fixed, patch applied to next-virtio/main. Thanks!