From owner-svn-src-head@freebsd.org Wed Jul 4 18:54:45 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 02C71102F96A; Wed, 4 Jul 2018 18:54:45 +0000 (UTC) (envelope-from gallatin@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A933E8D616; Wed, 4 Jul 2018 18:54:44 +0000 (UTC) (envelope-from gallatin@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8B8097200; Wed, 4 Jul 2018 18:54:44 +0000 (UTC) (envelope-from gallatin@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w64IsiNK075722; Wed, 4 Jul 2018 18:54:44 GMT (envelope-from gallatin@FreeBSD.org) Received: (from gallatin@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w64IsiVA075721; Wed, 4 Jul 2018 18:54:44 GMT (envelope-from gallatin@FreeBSD.org) Message-Id: <201807041854.w64IsiVA075721@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: gallatin set sender to gallatin@FreeBSD.org using -f From: Andrew Gallatin Date: Wed, 4 Jul 2018 18:54:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335966 - head/sys/dev/mxge X-SVN-Group: head X-SVN-Commit-Author: gallatin X-SVN-Commit-Paths: head/sys/dev/mxge X-SVN-Commit-Revision: 335966 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jul 2018 18:54:45 -0000 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;