mxge: Add SIOCGI2C support for devices with SFP/XFP cages
This commit is contained in:
parent
6f077571b9
commit
df131e8459
@ -4153,11 +4153,51 @@ mxge_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
|
||||
ifmr->ifm_active |= sc->current_media;
|
||||
}
|
||||
|
||||
static int
|
||||
mxge_fetch_i2c(mxge_softc_t *sc, struct ifi2creq *i2c)
|
||||
{
|
||||
mxge_cmd_t cmd;
|
||||
uint32_t i2c_args;
|
||||
int i, ms, err;
|
||||
|
||||
|
||||
if (i2c->dev_addr != 0xA0 &&
|
||||
i2c->dev_addr != 0xA2)
|
||||
return (EINVAL);
|
||||
if (i2c->len > sizeof(i2c->data))
|
||||
return (EINVAL);
|
||||
|
||||
for (i = 0; i < i2c->len; i++) {
|
||||
i2c_args = i2c->dev_addr << 0x8;
|
||||
i2c_args |= i2c->offset + i;
|
||||
cmd.data0 = 0; /* just fetch 1 byte, not all 256 */
|
||||
cmd.data1 = i2c_args;
|
||||
err = mxge_send_cmd(sc, MXGEFW_CMD_I2C_READ, &cmd);
|
||||
|
||||
if (err != MXGEFW_CMD_OK)
|
||||
return (EIO);
|
||||
/* now we wait for the data to be cached */
|
||||
cmd.data0 = i2c_args & 0xff;
|
||||
err = mxge_send_cmd(sc, MXGEFW_CMD_I2C_BYTE, &cmd);
|
||||
for (ms = 0; (err == EBUSY) && (ms < 50); ms++) {
|
||||
cmd.data0 = i2c_args & 0xff;
|
||||
err = mxge_send_cmd(sc, MXGEFW_CMD_I2C_BYTE, &cmd);
|
||||
if (err == EBUSY)
|
||||
DELAY(1000);
|
||||
}
|
||||
if (err != MXGEFW_CMD_OK)
|
||||
return (EIO);
|
||||
i2c->data[i] = cmd.data0;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
mxge_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
|
||||
{
|
||||
mxge_softc_t *sc = ifp->if_softc;
|
||||
struct ifreq *ifr = (struct ifreq *)data;
|
||||
struct ifi2creq i2c;
|
||||
int err, mask;
|
||||
|
||||
err = 0;
|
||||
@ -4292,6 +4332,26 @@ mxge_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
|
||||
&sc->media, command);
|
||||
break;
|
||||
|
||||
case SIOCGI2C:
|
||||
if (sc->connector != MXGE_XFP &&
|
||||
sc->connector != MXGE_SFP) {
|
||||
err = ENXIO;
|
||||
break;
|
||||
}
|
||||
err = copyin(ifr_data_get_ptr(ifr), &i2c, sizeof(i2c));
|
||||
if (err != 0)
|
||||
break;
|
||||
mtx_lock(&sc->driver_mtx);
|
||||
if (sc->dying) {
|
||||
mtx_unlock(&sc->driver_mtx);
|
||||
return (EINVAL);
|
||||
}
|
||||
err = mxge_fetch_i2c(sc, &i2c);
|
||||
mtx_unlock(&sc->driver_mtx);
|
||||
if (err == 0)
|
||||
err = copyout(&i2c, ifr->ifr_ifru.ifru_data,
|
||||
sizeof(i2c));
|
||||
break;
|
||||
default:
|
||||
err = ether_ioctl(ifp, command, data);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user