[PATCH 1/4] net: mhi: Rename MHI interface to improve clarity

Vivek.Pernamitta@quicinc.com posted 4 patches 2 months, 1 week ago
There is a newer version of this series
[PATCH 1/4] net: mhi: Rename MHI interface to improve clarity
Posted by Vivek.Pernamitta@quicinc.com 2 months, 1 week ago
From: Vivek Pernamitta <quic_vpernami@quicinc.com>

Rename the MHI network interface to include the device name, improving
clarity when multiple MHI controllers are connected.

Currently, MHI NET device interfaces are created as mhi_swip<n>/
mhi_hwip<n> for each channel, making it difficult to distinguish between
channels when multiple EP/MHI controllers are connected.

Rename the MHI interface to include the device name, for example:
- Channel IP_SW0 for the 1st MHI controller will be named mhi0_IP_SW0.
- Channel IP_SW0 for the 2nd MHI controller will be named mhi1_IP_SW0.
- Channel IP_HW0 for the 1st MHI controller will be named mhi0_IP_HW0.
Signed-off-by: Vivek Pernamitta <quic_vpernami@quicinc.com>
---
 drivers/net/mhi_net.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mhi_net.c b/drivers/net/mhi_net.c
index ae169929a9d8e449b5a427993abf68e8d032fae2..08ab67f9a769ec64e1007853e47743003a197ec4 100644
--- a/drivers/net/mhi_net.c
+++ b/drivers/net/mhi_net.c
@@ -351,11 +351,20 @@ static void mhi_net_dellink(struct mhi_device *mhi_dev, struct net_device *ndev)
 static int mhi_net_probe(struct mhi_device *mhi_dev,
 			 const struct mhi_device_id *id)
 {
-	const struct mhi_device_info *info = (struct mhi_device_info *)id->driver_data;
+	const struct mhi_device_info *info;
+	struct device *dev = &mhi_dev->dev;
+	char netname[IFNAMSIZ] = {0};
 	struct net_device *ndev;
 	int err;
 
-	ndev = alloc_netdev(sizeof(struct mhi_net_dev), info->netname,
+	info = (struct mhi_device_info *)id->driver_data;
+
+	if (snprintf(netname, sizeof(netname), "%s", dev_name(dev)) >= IFNAMSIZ) {
+		dev_err(dev, "Invalid interface name: '%s'\n", netname);
+		return -EINVAL;
+	}
+
+	ndev = alloc_netdev(sizeof(struct mhi_net_dev), netname,
 			    NET_NAME_PREDICTABLE, mhi_net_setup);
 	if (!ndev)
 		return -ENOMEM;

-- 
2.34.1
Re: [PATCH 1/4] net: mhi: Rename MHI interface to improve clarity
Posted by Jakub Kicinski 2 months, 1 week ago
On Thu, 24 Jul 2025 19:21:17 +0530 Vivek.Pernamitta@quicinc.com wrote:
> From: Vivek Pernamitta <quic_vpernami@quicinc.com>
> 
> Rename the MHI network interface to include the device name, improving
> clarity when multiple MHI controllers are connected.
> 
> Currently, MHI NET device interfaces are created as mhi_swip<n>/
> mhi_hwip<n> for each channel, making it difficult to distinguish between
> channels when multiple EP/MHI controllers are connected.
> 
> Rename the MHI interface to include the device name, for example:
> - Channel IP_SW0 for the 1st MHI controller will be named mhi0_IP_SW0.
> - Channel IP_SW0 for the 2nd MHI controller will be named mhi1_IP_SW0.
> - Channel IP_HW0 for the 1st MHI controller will be named mhi0_IP_HW0.

The userspace can rename the interfaces. It has the association with
the underlying device right there in the udev event.