Date: Wed, 4 Jul 2018 18:54:44 +0000 (UTC) From: Andrew Gallatin <gallatin@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335966 - head/sys/dev/mxge Message-ID: <201807041854.w64IsiVA075721@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gallatin Date: Wed Jul 4 18:54:44 2018 New Revision: 335966 URL: https://svnweb.freebsd.org/changeset/base/335966 Log: mxge: Add SIOCGI2C support for devices with SFP/XFP cages Modified: head/sys/dev/mxge/if_mxge.c Modified: head/sys/dev/mxge/if_mxge.c ============================================================================== --- head/sys/dev/mxge/if_mxge.c Wed Jul 4 18:03:19 2018 (r335965) +++ head/sys/dev/mxge/if_mxge.c Wed Jul 4 18:54:44 2018 (r335966) @@ -4154,10 +4154,50 @@ mxge_media_status(struct ifnet *ifp, struct ifmediareq } 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 &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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201807041854.w64IsiVA075721>