git: dbfa2d02310a - stable/15 - net: Add SIOCGI2CPB ioctl & add page/bank fields to ifi2creq
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 29 Oct 2026 06:03:29 UTC
The branch stable/15 has been updated by kbowling:
URL: https://cgit.FreeBSD.org/src/commit/?id=dbfa2d02310a3c0e72a00db4d2c0741c342b4b38
commit dbfa2d02310a3c0e72a00db4d2c0741c342b4b38
Author: Andrew Gallatin <gallatin@FreeBSD.org>
AuthorDate: 2026-04-05 19:58:10 +0000
Commit: Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2026-10-29 05:44:39 +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
(cherry picked from commit cf1f21572897ffc85789fbb1792603967297f6fc)
---
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 7cfbeb106952..e8c42b65a5f0 100644
--- a/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
+++ b/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
@@ -3802,6 +3802,8 @@ out:
break;
case SIOCGI2C:
+ /* fallthru */
+ case SIOCGI2CPB:
ifr = (struct ifreq *)data;
/*
@@ -3811,6 +3813,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;
@@ -3852,8 +3857,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) {
@@ -3865,7 +3879,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 d54190f6ccf8..78f1d67babb9 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -605,8 +605,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 104a7cbc658b..718bfc4d6508 100644
--- a/sys/net/iflib.c
+++ b/sys/net/iflib.c
@@ -4913,8 +4913,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)
@@ -4927,6 +4930,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 48aed3671575..d629e6b3c6b9 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_ */