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
This commit is contained in:
@@ -3728,6 +3728,8 @@ mlx5e_ioctl(if_t ifp, u_long command, caddr_t data)
|
||||
break;
|
||||
|
||||
case SIOCGI2C:
|
||||
/* fallthru */
|
||||
case SIOCGI2CPB:
|
||||
ifr = (struct ifreq *)data;
|
||||
|
||||
/*
|
||||
@@ -3737,6 +3739,9 @@ mlx5e_ioctl(if_t ifp, u_long command, caddr_t data)
|
||||
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 @@ mlx5e_ioctl(if_t ifp, u_long command, caddr_t data)
|
||||
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 @@ mlx5e_ioctl(if_t ifp, u_long command, caddr_t data)
|
||||
|
||||
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);
|
||||
|
||||
+3
-2
@@ -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 */
|
||||
};
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
+4
-1
@@ -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
|
||||
|
||||
@@ -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_ */
|
||||
|
||||
Reference in New Issue
Block a user