Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 05 Apr 2026 21:08:16 +0000
From:      Andrew Gallatin <gallatin@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: cf1f21572897 - main - net: Add SIOCGI2CPB ioctl & add page/bank fields to ifi2creq
Message-ID:  <69d2cf40.3d30c.21904523@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by gallatin:

URL: https://cgit.FreeBSD.org/src/commit/?id=cf1f21572897ffc85789fbb1792603967297f6fc

commit cf1f21572897ffc85789fbb1792603967297f6fc
Author:     Andrew Gallatin <gallatin@FreeBSD.org>
AuthorDate: 2026-04-05 19:58:10 +0000
Commit:     Andrew Gallatin <gallatin@FreeBSD.org>
CommitDate: 2026-04-05 21:04:38 +0000

    net: Add SIOCGI2CPB ioctl & add page/bank fields to ifi2creq
    
    This commit adds page & bank fields to ifi2creq in preparation
    for adding CMIS support for 400g optics to ifconfig.
    The new ioctl SIOCGI2CPB is added, so that drivers can distinguish
    between callers asking for page/bank selection and legacy callers
    that simply failed to zero out all ifi2creq fields.
    
    The mlx5en(4) driver and iflib(4) driver frameork have been updated
    to use this new SIOCGI2CPB ioctl and support page/bank operations.
    A follow-on patchset will add support to ifconfig for reporting
    data from CMIS optics.
    
    This has been tested on Nvidia ConnectX-7 and Broadcom Thor2 (using
    out of tree driver) based NICs.
    
    Differential Revision: https://reviews.freebsd.org/D55912
    Sponsored by: Netflix Inc.
    Reviewed by: kib
---
 sys/dev/mlx5/mlx5_en/mlx5_en_main.c | 18 ++++++++++++++++--
 sys/net/if.h                        |  5 +++--
 sys/net/iflib.c                     |  9 +++++++++
 sys/net/iflib.h                     |  5 ++++-
 sys/sys/sockio.h                    |  1 +
 5 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_main.c b/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
index 0baeab31b100..fb8b79c8f787 100644
--- a/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
+++ b/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
@@ -3728,6 +3728,8 @@ out:
 		break;
 
 	case SIOCGI2C:
+		/* fallthru */
+	case SIOCGI2CPB:
 		ifr = (struct ifreq *)data;
 
 		/*
@@ -3737,6 +3739,9 @@ out:
 		error = copyin(ifr_data_get_ptr(ifr), &i2c, sizeof(i2c));
 		if (error)
 			break;
+		/* ensure page and bank are 0 for legacy SIOCGI2C ioctls */
+		if (command == SIOCGI2C)
+			i2c.page = i2c.bank = 0;
 
 		if (i2c.len > sizeof(i2c.data)) {
 			error = EINVAL;
@@ -3778,8 +3783,17 @@ out:
 			error = EINVAL;
 			goto err_i2c;
 		}
+
+		if (i2c.bank != 0) {
+			mlx5_en_err(ifp,
+			    "Query eeprom failed, Invalid Bank: %X\n",
+			    i2c.bank);
+			error = EINVAL;
+			goto err_i2c;
+		}
+
 		error = mlx5_query_eeprom(priv->mdev,
-		    read_addr, MLX5_EEPROM_LOW_PAGE,
+		    read_addr, i2c.page,
 		    (uint32_t)i2c.offset, (uint32_t)i2c.len, module_num,
 		    (uint32_t *)i2c.data, &size_read);
 		if (error) {
@@ -3791,7 +3805,7 @@ out:
 
 		if (i2c.len > MLX5_EEPROM_MAX_BYTES) {
 			error = mlx5_query_eeprom(priv->mdev,
-			    read_addr, MLX5_EEPROM_LOW_PAGE,
+			    read_addr, i2c.page,
 			    (uint32_t)(i2c.offset + size_read),
 			    (uint32_t)(i2c.len - size_read), module_num,
 			    (uint32_t *)(i2c.data + size_read), &size_read);
diff --git a/sys/net/if.h b/sys/net/if.h
index 7c0a476708d6..1b47237e46bb 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -604,8 +604,9 @@ struct ifi2creq {
 	uint8_t dev_addr;	/* i2c address (0xA0, 0xA2) */
 	uint8_t offset;		/* read offset */
 	uint8_t len;		/* read length */
-	uint8_t spare0;
-	uint32_t spare1;
+	uint8_t page;		/* CMIS page number (0 for legacy) */
+	uint8_t bank;		/* CMIS bank number (0 for legacy) */
+	uint8_t spare[3];	/* reserved for future use */
 	uint8_t data[8];	/* read buffer */
 }; 
 
diff --git a/sys/net/iflib.c b/sys/net/iflib.c
index 08282d1799b8..f9d0b1af0f83 100644
--- a/sys/net/iflib.c
+++ b/sys/net/iflib.c
@@ -4468,8 +4468,11 @@ iflib_if_ioctl(if_t ifp, u_long command, caddr_t data)
 		err = ifmedia_ioctl(ifp, ifr, ctx->ifc_mediap, command);
 		break;
 	case SIOCGI2C:
+		/* FALLTHROUGH */
+	case SIOCGI2CPB:
 	{
 		struct ifi2creq i2c;
+		if_shared_ctx_t sctx = ctx->ifc_sctx;
 
 		err = copyin(ifr_data_get_ptr(ifr), &i2c, sizeof(i2c));
 		if (err != 0)
@@ -4482,6 +4485,12 @@ iflib_if_ioctl(if_t ifp, u_long command, caddr_t data)
 			err = EINVAL;
 			break;
 		}
+		if (command == SIOCGI2C) {
+			i2c.page = i2c.bank = 0;
+		} else if ((sctx->isc_flags & IFLIB_I2C_PAGE_BANK) == 0) {
+			err = EINVAL;
+			break;
+		}
 
 		if ((err = IFDI_I2C_REQ(ctx, &i2c)) == 0)
 			err = copyout(&i2c, ifr_data_get_ptr(ifr),
diff --git a/sys/net/iflib.h b/sys/net/iflib.h
index fe70fc5775cd..c73c50e5a3b3 100644
--- a/sys/net/iflib.h
+++ b/sys/net/iflib.h
@@ -348,7 +348,10 @@ typedef enum {
  * Driver needs frames padded to some minimum length
  */
 #define IFLIB_NEED_ETHER_PAD	0x100
-#define	IFLIB_SPARE7		0x200
+/*
+ * Driver understands page/bank i2c reads
+ */
+#define	IFLIB_I2C_PAGE_BANK	0x200
 #define	IFLIB_SPARE6		0x400
 #define	IFLIB_SPARE5		0x800
 #define	IFLIB_SPARE4		0x1000
diff --git a/sys/sys/sockio.h b/sys/sys/sockio.h
index cf612079c2f3..de2cc236223c 100644
--- a/sys/sys/sockio.h
+++ b/sys/sys/sockio.h
@@ -150,5 +150,6 @@
 #define	SIOCGUMBINFO	_IOWR('i', 157, struct ifreq)	/* get MBIM info */
 #define	SIOCSUMBPARAM	 _IOW('i', 158, struct ifreq)	/* set MBIM param */
 #define	SIOCGUMBPARAM	_IOWR('i', 159, struct ifreq)	/* get MBIM param */
+#define	SIOCGI2CPB	_IOWR('i', 160, struct ifreq)	/* get I2C data   */
 
 #endif /* !_SYS_SOCKIO_H_ */


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69d2cf40.3d30c.21904523>