diff --git a/sys/dev/dpaa/if_dtsec.c b/sys/dev/dpaa/if_dtsec.c index e9e394d93ad..16d4afdf812 100644 --- a/sys/dev/dpaa/if_dtsec.c +++ b/sys/dev/dpaa/if_dtsec.c @@ -78,11 +78,11 @@ #include "if_dtsec_im.h" #include "if_dtsec_rm.h" +#include + #define DTSEC_MIN_FRAME_SIZE 64 #define DTSEC_MAX_FRAME_SIZE 9600 -static void dtsec_sfp_poll(struct dtsec_softc *sc); - #if (DPAA_VERSION < 11) #define DTSEC_REG_MAXFRM 0x110 #define DTSEC_REG_GADDR(i) (0x0a0 + 4*(i)) @@ -573,8 +573,6 @@ dtsec_if_tick(void *arg) if (sc->sc_mii != NULL) mii_tick(sc->sc_mii); - dtsec_sfp_poll(sc); - callout_reset(&sc->sc_tick_callout, hz, dtsec_if_tick, sc); DTSEC_UNLOCK(sc); @@ -588,8 +586,6 @@ dtsec_if_deinit_locked(struct dtsec_softc *sc) DTSEC_UNLOCK(sc); callout_drain(&sc->sc_tick_callout); - taskqueue_drain(taskqueue_thread, &sc->sc_sfp_task); - taskqueue_drain(taskqueue_thread, &sc->sc_sfp_phy_task); DTSEC_LOCK(sc); } @@ -667,124 +663,10 @@ dtsec_if_watchdog(if_t ifp) /** - * @group SFP module management. + * @group SFP upstream callbacks (from sfp_fdt state machine). * @{ */ -/* SFF-8024 connector types */ -#define SFP_CONNECTOR_LC 0x07 -#define SFP_CONNECTOR_RJ45 0x22 /* copper RJ45 */ - -/* SFF-8472 EEPROM A0h field offsets */ -#define SFP_ID_OFFSET 0 -#define SFP_CONNECTOR_OFFSET 2 -#define SFP_VENDOR_OFFSET 20 -#define SFP_VENDOR_LEN 16 -#define SFP_PARTNUM_OFFSET 40 -#define SFP_PARTNUM_LEN 16 - -/* I2C address for SFP EEPROM (A0h page, 7-bit) */ -#define SFP_I2C_ADDR 0x50 - -/* IEEE 802.3 Clause 45 MMD device numbers */ -#define MDIO_MMD_PMAPMD 1 /* PMA/PMD */ -#define MDIO_MMD_AN 7 /* Auto-Negotiation */ - -/* Standard C45 register offsets */ -#define MDIO_CTRL1 0 -#define MDIO_STAT1 1 -#define MDIO_DEVID1 2 -#define MDIO_DEVID2 3 -#define MDIO_PMA_EXTABLE 11 -#define MDIO_PMA_NG_EXTABLE 21 -#define MDIO_AN_ADVERTISE 16 -#define MDIO_AN_LPA 19 -#define MDIO_AN_10GBT_CTRL 32 -#define MDIO_AN_10GBT_STAT 33 - -/* STAT1 bits */ -#define MDIO_STAT1_LSTATUS (1 << 2) - -/* AN CTRL1 bits */ -#define MDIO_AN_CTRL1_XNP (1 << 13) -#define MDIO_AN_CTRL1_ENABLE (1 << 12) -#define MDIO_AN_CTRL1_RESTART (1 << 9) - -/* AN STAT1 bits */ -#define MDIO_AN_STAT1_COMPLETE (1 << 5) - -/* PMA EXTABLE bits */ -#define MDIO_PMA_EXTABLE_10GBT (1 << 2) -#define MDIO_PMA_EXTABLE_1000BT (1 << 5) -#define MDIO_PMA_EXTABLE_NBT (1 << 14) - -/* PMA NG_EXTABLE bits (NBASE-T) */ -#define MDIO_PMA_NG_EXTABLE_2_5GBT (1 << 0) -#define MDIO_PMA_NG_EXTABLE_5GBT (1 << 1) - -/* AN 10GBT_CTRL advertisement bits */ -#define MDIO_AN_10GBT_CTRL_ADV10G (1 << 12) -#define MDIO_AN_10GBT_CTRL_ADV5G (1 << 8) -#define MDIO_AN_10GBT_CTRL_ADV2_5G (1 << 7) - -/* AN 10GBT_STAT link partner bits */ -#define MDIO_AN_10GBT_STAT_LP10G (1 << 11) -#define MDIO_AN_10GBT_STAT_LP5G (1 << 6) -#define MDIO_AN_10GBT_STAT_LP2_5G (1 << 5) - -/* AN base page advertisement bits (reg 16) */ - -#define MDIO_AN_ADV_1000BT_HDX (1 << 6) - -static int -dtsec_sfp_read_eeprom(struct dtsec_softc *sc) -{ - struct iic_msg msgs[2]; - uint8_t offset; - int error; - - if (sc->sc_sfp_i2c == NULL) - return (ENXIO); - - offset = 0; - - /* Write offset byte */ - msgs[0].slave = SFP_I2C_ADDR << 1; - msgs[0].flags = IIC_M_WR; - msgs[0].len = 1; - msgs[0].buf = &offset; - - /* Read 64 bytes of base ID */ - msgs[1].slave = SFP_I2C_ADDR << 1; - msgs[1].flags = IIC_M_RD; - msgs[1].len = sizeof(sc->sc_sfp_id); - msgs[1].buf = sc->sc_sfp_id; - - /* sc_sfp_i2c is the iicbus device (from SFF_GET_I2C_BUS), - * not a slave child, so use the bus-level API directly. - * iicbus_request_bus(bus, owner, how) acquires exclusive access, - * iicbus_transfer(bus, ...) routes to the controller. */ - error = iicbus_request_bus(sc->sc_sfp_i2c, sc->sc_dev, - IIC_INTRWAIT); - if (error != 0) { - device_printf(sc->sc_dev, - "SFP: failed to acquire I2C bus: %d\n", error); - return (error); - } - - error = iicbus_transfer(sc->sc_sfp_i2c, msgs, 2); - - iicbus_release_bus(sc->sc_sfp_i2c, sc->sc_dev); - - if (error != 0) { - device_printf(sc->sc_dev, "SFP EEPROM read failed: %d\n", - error); - memset(sc->sc_sfp_id, 0, sizeof(sc->sc_sfp_id)); - } - - return (error); -} - static void dtsec_sfp_trim(char *dst, const uint8_t *src, int len) { @@ -792,781 +674,59 @@ dtsec_sfp_trim(char *dst, const uint8_t *src, int len) memcpy(dst, src, len); dst[len] = '\0'; - /* Trim trailing spaces */ for (i = len - 1; i >= 0 && dst[i] == ' '; i--) dst[i] = '\0'; } +static int +dtsec_sfp_module_insert(void *arg, const uint8_t *id, int id_len) +{ + struct dtsec_softc *sc = arg; + + memcpy(sc->sc_sfp_id, id, MIN((int)sizeof(sc->sc_sfp_id), id_len)); + sc->sc_sfp_modpresent = true; + + return (0); /* accept all modules */ +} + static void -dtsec_sfp_log_module(struct dtsec_softc *sc) +dtsec_sfp_module_remove(void *arg) { - char vendor[SFP_VENDOR_LEN + 1]; - char partnum[SFP_PARTNUM_LEN + 1]; - uint8_t connector; + struct dtsec_softc *sc = arg; - dtsec_sfp_trim(vendor, &sc->sc_sfp_id[SFP_VENDOR_OFFSET], - SFP_VENDOR_LEN); - dtsec_sfp_trim(partnum, &sc->sc_sfp_id[SFP_PARTNUM_OFFSET], - SFP_PARTNUM_LEN); - connector = sc->sc_sfp_id[SFP_CONNECTOR_OFFSET]; - - device_printf(sc->sc_dev, - "SFP+ module inserted: %s %s (connector 0x%02x%s)\n", - vendor, partnum, connector, - connector == SFP_CONNECTOR_RJ45 ? " RJ45" : ""); -} - -/* - * Standard I2C-MDIO bridge (SFF-8472) for Clause 45 PHY access. - * PHY address 22 mapped to I2C address 0x56 (phy_addr + 0x40). - * Read: write [0x20|devad, reg_hi, reg_lo], read 2 bytes. - * Write: write [devad, reg_hi, reg_lo, val_hi, val_lo]. - * Reference: Linux drivers/net/mdio/mdio-i2c.c - */ -#define MDIOI2C_I2C_ADDR 0x56 - -static int -mdioi2c_read(struct dtsec_softc *sc, int devad, int reg) -{ - struct iic_msg msgs[2]; - uint8_t addr[3], data[2]; - int error; - - addr[0] = 0x20 | (devad & 0x1F); - addr[1] = (reg >> 8) & 0xFF; - addr[2] = reg & 0xFF; - - msgs[0].slave = MDIOI2C_I2C_ADDR << 1; - msgs[0].flags = IIC_M_WR; - msgs[0].len = 3; - msgs[0].buf = addr; - msgs[1].slave = MDIOI2C_I2C_ADDR << 1; - msgs[1].flags = IIC_M_RD; - msgs[1].len = 2; - msgs[1].buf = data; - - error = iicbus_request_bus(sc->sc_sfp_i2c, sc->sc_dev, IIC_INTRWAIT); - if (error != 0) - return (-1); - error = iicbus_transfer(sc->sc_sfp_i2c, msgs, 2); - iicbus_release_bus(sc->sc_sfp_i2c, sc->sc_dev); - - if (error != 0) - return (-1); - return ((data[0] << 8) | data[1]); -} - -static int -mdioi2c_write(struct dtsec_softc *sc, int devad, int reg, int val) -{ - struct iic_msg msg; - uint8_t buf[5]; - int error; - - buf[0] = devad & 0x1F; - buf[1] = (reg >> 8) & 0xFF; - buf[2] = reg & 0xFF; - buf[3] = (val >> 8) & 0xFF; - buf[4] = val & 0xFF; - - msg.slave = MDIOI2C_I2C_ADDR << 1; - msg.flags = IIC_M_WR; - msg.len = 5; - msg.buf = buf; - - error = iicbus_request_bus(sc->sc_sfp_i2c, sc->sc_dev, IIC_INTRWAIT); - if (error != 0) - return (error); - error = iicbus_transfer(sc->sc_sfp_i2c, &msg, 1); - iicbus_release_bus(sc->sc_sfp_i2c, sc->sc_dev); - - return (error); -} - -/* - * RollBall I2C-to-MDIO bridge for Clause 45 PHY access. - * Used by FLEXOPTIX and many other 10GBASE-T SFP+ modules. - * PHY registers are accessed via a mailbox at I2C address 0x51: - * - Page register at offset 0x7F selects EEPROM page - * - Command/data at offsets 0x80-0x85 on page 3 - * Protocol: write devad+reg+cmd, poll for DONE, read result. - * Must be called from sleepable context (taskqueue). - * - * Reference: Linux drivers/net/mdio/mdio-i2c.c - */ -#define ROLLBALL_I2C_ADDR 0x51 -#define ROLLBALL_PAGE_REG 0x7F /* SFP page select register */ -#define ROLLBALL_PAGE 3 /* page for PHY access */ -#define ROLLBALL_PASSWORD_REG 0x7B /* password register */ -#define ROLLBALL_CMD_ADDR 0x80 /* command register */ -#define ROLLBALL_DATA_ADDR 0x81 /* data start register */ -#define ROLLBALL_CMD_READ 0x02 -#define ROLLBALL_CMD_WRITE 0x01 -#define ROLLBALL_CMD_DONE 0x04 -#define ROLLBALL_POLL_RETRIES 20 -#define ROLLBALL_POLL_MS 20 - -/* - * Low-level I2C helpers for RollBall. - * Bus must already be acquired by caller. - */ -static int -rollball_i2c_write(struct dtsec_softc *sc, uint8_t *buf, int len) -{ - struct iic_msg msg; - - msg.slave = ROLLBALL_I2C_ADDR << 1; - msg.flags = IIC_M_WR; - msg.len = len; - msg.buf = buf; - return (iicbus_transfer(sc->sc_sfp_i2c, &msg, 1)); -} - -static int -rollball_i2c_read(struct dtsec_softc *sc, uint8_t reg, uint8_t *buf, int len) -{ - struct iic_msg msgs[2]; - - msgs[0].slave = ROLLBALL_I2C_ADDR << 1; - msgs[0].flags = IIC_M_WR; - msgs[0].len = 1; - msgs[0].buf = ® - msgs[1].slave = ROLLBALL_I2C_ADDR << 1; - msgs[1].flags = IIC_M_RD; - msgs[1].len = len; - msgs[1].buf = buf; - return (iicbus_transfer(sc->sc_sfp_i2c, msgs, 2)); -} - -/* - * Send RollBall password (one-time init after module insertion). - * Must be called with I2C bus NOT held. - */ -static int -dtsec_sfp_phy_rollball_init(struct dtsec_softc *sc) -{ - uint8_t pw[] = { ROLLBALL_PASSWORD_REG, 0xFF, 0xFF, 0xFF, 0xFF }; - int error; - - error = iicbus_request_bus(sc->sc_sfp_i2c, sc->sc_dev, - IIC_INTRWAIT); - if (error != 0) - return (error); - error = rollball_i2c_write(sc, pw, sizeof(pw)); - iicbus_release_bus(sc->sc_sfp_i2c, sc->sc_dev); - - return (error); -} - -/* - * Save current page, switch to RollBall page 3. - * Bus must already be acquired. - */ -static int -rollball_page_set(struct dtsec_softc *sc, uint8_t *saved_page) -{ - uint8_t buf[2]; - int error; - - /* Read current page */ - error = rollball_i2c_read(sc, ROLLBALL_PAGE_REG, saved_page, 1); - if (error != 0) - return (error); - - /* Set page 3 — must be a separate transfer */ - buf[0] = ROLLBALL_PAGE_REG; - buf[1] = ROLLBALL_PAGE; - return (rollball_i2c_write(sc, buf, 2)); -} - -/* - * Restore saved page. Bus must already be acquired. - */ -static int -rollball_page_restore(struct dtsec_softc *sc, uint8_t saved_page) -{ - uint8_t buf[2] = { ROLLBALL_PAGE_REG, saved_page }; - - return (rollball_i2c_write(sc, buf, 2)); -} - -static int -rollball_phy_read(struct dtsec_softc *sc, int devad, int reg) -{ - uint8_t data_buf[4], cmd_buf[2], res[6]; - uint8_t saved_page; - int error, i; - - if (sc->sc_sfp_i2c == NULL) - return (-1); - - error = iicbus_request_bus(sc->sc_sfp_i2c, sc->sc_dev, - IIC_INTRWAIT); - if (error != 0) - return (-1); - - /* Save page and switch to page 3 */ - error = rollball_page_set(sc, &saved_page); - if (error != 0) - goto out; - - /* Write devad + register address */ - data_buf[0] = ROLLBALL_DATA_ADDR; - data_buf[1] = devad; - data_buf[2] = (reg >> 8) & 0xFF; - data_buf[3] = reg & 0xFF; - error = rollball_i2c_write(sc, data_buf, 4); - if (error != 0) - goto restore; - - /* Write read command */ - cmd_buf[0] = ROLLBALL_CMD_ADDR; - cmd_buf[1] = ROLLBALL_CMD_READ; - error = rollball_i2c_write(sc, cmd_buf, 2); - if (error != 0) - goto restore; - - /* Restore page before polling (each poll does its own page switch) */ - rollball_page_restore(sc, saved_page); - iicbus_release_bus(sc->sc_sfp_i2c, sc->sc_dev); - - /* Poll for completion */ - for (i = 0; i < ROLLBALL_POLL_RETRIES; i++) { - pause_sbt("rbpoll", SBT_1MS * ROLLBALL_POLL_MS, 0, C_PREL(2)); - - error = iicbus_request_bus(sc->sc_sfp_i2c, sc->sc_dev, - IIC_INTRWAIT); - if (error != 0) - return (-1); - - error = rollball_page_set(sc, &saved_page); - if (error != 0) { - iicbus_release_bus(sc->sc_sfp_i2c, sc->sc_dev); - return (-1); - } - - error = rollball_i2c_read(sc, ROLLBALL_CMD_ADDR, res, 6); - - rollball_page_restore(sc, saved_page); - iicbus_release_bus(sc->sc_sfp_i2c, sc->sc_dev); - - if (error != 0) - return (-1); - - if (res[0] == ROLLBALL_CMD_DONE) - return ((res[4] << 8) | res[5]); - } - - return (-1); /* timeout */ - -restore: - rollball_page_restore(sc, saved_page); -out: - iicbus_release_bus(sc->sc_sfp_i2c, sc->sc_dev); - return (-1); -} - -static int -rollball_phy_write(struct dtsec_softc *sc, int devad, int reg, int val) -{ - uint8_t data_buf[6], cmd_buf[2], status; - uint8_t saved_page; - int error, i; - - if (sc->sc_sfp_i2c == NULL) - return (ENXIO); - - error = iicbus_request_bus(sc->sc_sfp_i2c, sc->sc_dev, - IIC_INTRWAIT); - if (error != 0) - return (error); - - error = rollball_page_set(sc, &saved_page); - if (error != 0) - goto out; - - /* Write devad + register + value */ - data_buf[0] = ROLLBALL_DATA_ADDR; - data_buf[1] = devad; - data_buf[2] = (reg >> 8) & 0xFF; - data_buf[3] = reg & 0xFF; - data_buf[4] = (val >> 8) & 0xFF; - data_buf[5] = val & 0xFF; - error = rollball_i2c_write(sc, data_buf, 6); - if (error != 0) - goto restore; - - /* Write write command */ - cmd_buf[0] = ROLLBALL_CMD_ADDR; - cmd_buf[1] = ROLLBALL_CMD_WRITE; - error = rollball_i2c_write(sc, cmd_buf, 2); - if (error != 0) - goto restore; - - rollball_page_restore(sc, saved_page); - iicbus_release_bus(sc->sc_sfp_i2c, sc->sc_dev); - - /* Poll for completion */ - for (i = 0; i < ROLLBALL_POLL_RETRIES; i++) { - pause_sbt("rbpoll", SBT_1MS * ROLLBALL_POLL_MS, 0, C_PREL(2)); - - error = iicbus_request_bus(sc->sc_sfp_i2c, sc->sc_dev, - IIC_INTRWAIT); - if (error != 0) - return (error); - - error = rollball_page_set(sc, &saved_page); - if (error != 0) { - iicbus_release_bus(sc->sc_sfp_i2c, sc->sc_dev); - return (error); - } - - error = rollball_i2c_read(sc, ROLLBALL_CMD_ADDR, &status, 1); - - rollball_page_restore(sc, saved_page); - iicbus_release_bus(sc->sc_sfp_i2c, sc->sc_dev); - - if (error != 0) - return (error); - - if (status == ROLLBALL_CMD_DONE) - return (0); - } - - return (ETIMEDOUT); - -restore: - rollball_page_restore(sc, saved_page); -out: - iicbus_release_bus(sc->sc_sfp_i2c, sc->sc_dev); - return (error); -} - -/* - * Protocol-dispatching wrappers for PHY register access. - * Called by all PHY management code; the probe selects the protocol. - */ -static int -dtsec_sfp_phy_read(struct dtsec_softc *sc, int devad, int reg) -{ - - if (sc->sc_sfp_phy_proto == DTSEC_SFP_PHY_MDIOI2C) - return (mdioi2c_read(sc, devad, reg)); - return (rollball_phy_read(sc, devad, reg)); -} - -static int -dtsec_sfp_phy_write(struct dtsec_softc *sc, int devad, int reg, int val) -{ - - if (sc->sc_sfp_phy_proto == DTSEC_SFP_PHY_MDIOI2C) - return (mdioi2c_write(sc, devad, reg, val)); - return (rollball_phy_write(sc, devad, reg, val)); -} - -/* - * Configure auto-negotiation for 10GBASE-T. - * Advertises all speeds the PHY supports, then restarts AN. - */ -static void -dtsec_sfp_phy_config_aneg(struct dtsec_softc *sc) -{ - int adv10g; - - /* Advertise 10GBASE-T and NBASE-T speeds in register 7.32. - * 1000BASE-T is advertised by the PHY firmware via extended - * next pages automatically — no explicit config needed. */ - adv10g = MDIO_AN_10GBT_CTRL_ADV10G | - MDIO_AN_10GBT_CTRL_ADV5G | MDIO_AN_10GBT_CTRL_ADV2_5G; - dtsec_sfp_phy_write(sc, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL, adv10g); - - /* Enable and restart AN. XNP (Extended Next Page) is critical — - * 10GBASE-T capability is exchanged via extended next pages. - * Without XNP, only base-page speeds (1G and below) negotiate. */ - dtsec_sfp_phy_write(sc, MDIO_MMD_AN, MDIO_CTRL1, - MDIO_AN_CTRL1_XNP | MDIO_AN_CTRL1_ENABLE | - MDIO_AN_CTRL1_RESTART); - - device_printf(sc->sc_dev, "SFP+ PHY: auto-negotiation started\n"); -} - -/* - * Probe for a Clause 45 PHY inside an SFP+ copper module. - * Reads PHY ID, logs it, configures auto-negotiation. - * Must be called from sleepable context. - */ -static void -dtsec_sfp_phy_probe(struct dtsec_softc *sc) -{ - int id1, id2, err, retry; - uint32_t phy_id; - int extable; - - id1 = -1; - - /* - * Try RollBall protocol first (I2C addr 0x51, page 3). - * Most 10GBASE-T SFP+ modules use this. - */ - sc->sc_sfp_phy_proto = DTSEC_SFP_PHY_ROLLBALL; - err = dtsec_sfp_phy_rollball_init(sc); - if (err == 0) { - /* - * Poll for PHY to become responsive. PHY firmware - * inside 10GBASE-T SFP+ modules can take several - * seconds to boot. Try up to 4.5 seconds. - */ - for (retry = 0; retry < 9; retry++) { - pause_sbt("phyboot", SBT_1MS * 500, 0, C_PREL(2)); - - id1 = dtsec_sfp_phy_read(sc, MDIO_MMD_PMAPMD, - MDIO_DEVID1); - if (id1 > 0 && id1 != 0xFFFF) - break; - } - } - - /* - * If RollBall failed, try standard I2C-MDIO (addr 0x56). - * Some modules (e.g. certain FLEXOPTIX) use this instead. - */ - if (id1 <= 0 || id1 == 0xFFFF) { - sc->sc_sfp_phy_proto = DTSEC_SFP_PHY_MDIOI2C; - id1 = dtsec_sfp_phy_read(sc, MDIO_MMD_PMAPMD, MDIO_DEVID1); - } - - if (id1 <= 0 || id1 == 0xFFFF) { - device_printf(sc->sc_dev, - "SFP+ PHY: no C45 PHY detected " - "(tried RollBall and I2C-MDIO)\n"); - sc->sc_sfp_phy_proto = 0; - return; - } - - id2 = dtsec_sfp_phy_read(sc, MDIO_MMD_PMAPMD, MDIO_DEVID2); - if (id2 < 0 || id2 == 0xFFFF) { - device_printf(sc->sc_dev, - "SFP+ PHY: DEVID1=0x%04x but DEVID2 read failed\n", - id1 & 0xFFFF); - sc->sc_sfp_phy_proto = 0; - return; - } - - phy_id = ((uint32_t)id1 << 16) | id2; - - device_printf(sc->sc_dev, - "SFP+ PHY detected via %s: ID %08x " - "(OUI %06x model %02x rev %01x)\n", - sc->sc_sfp_phy_proto == DTSEC_SFP_PHY_ROLLBALL ? - "RollBall" : "I2C-MDIO", - phy_id, - (id1 << 6) | (id2 >> 10), - (id2 >> 4) & 0x3F, - id2 & 0x0F); - - /* Read supported speeds for informational logging */ - extable = dtsec_sfp_phy_read(sc, MDIO_MMD_PMAPMD, MDIO_PMA_EXTABLE); - if (extable >= 0) { - device_printf(sc->sc_dev, - "SFP+ PHY abilities: %s%s%s\n", - (extable & MDIO_PMA_EXTABLE_10GBT) ? "10GBASE-T " : "", - (extable & MDIO_PMA_EXTABLE_1000BT) ? "1000BASE-T " : "", - (extable & MDIO_PMA_EXTABLE_NBT) ? "NBASE-T" : ""); - } - - sc->sc_sfp_phy_id = phy_id; - sc->sc_sfp_has_phy = true; + memset(sc->sc_sfp_id, 0, sizeof(sc->sc_sfp_id)); + sc->sc_sfp_modpresent = false; sc->sc_sfp_phy_link = false; sc->sc_sfp_phy_speed = 0; - - /* Start auto-negotiation */ - dtsec_sfp_phy_config_aneg(sc); + if_link_state_change(sc->sc_ifnet, LINK_STATE_UNKNOWN); } -/* - * Read negotiated speed after AN completes. - * Returns speed in Mbps or 0 if unknown. - */ -static int -dtsec_sfp_phy_read_speed(struct dtsec_softc *sc) -{ - int stat, lpa10g, ctrl1; - - /* Check if AN is complete */ - stat = dtsec_sfp_phy_read(sc, MDIO_MMD_AN, MDIO_STAT1); - if (stat < 0 || !(stat & MDIO_AN_STAT1_COMPLETE)) - return (0); - - /* Check 10G/5G/2.5G partner abilities */ - lpa10g = dtsec_sfp_phy_read(sc, MDIO_MMD_AN, MDIO_AN_10GBT_STAT); - if (lpa10g >= 0) { - if (lpa10g & MDIO_AN_10GBT_STAT_LP10G) - return (10000); - if (lpa10g & MDIO_AN_10GBT_STAT_LP5G) - return (5000); - if (lpa10g & MDIO_AN_10GBT_STAT_LP2_5G) - return (2500); - } - - /* Read PMA/PMD CTRL1 for actual operating speed. - * 1000BASE-T is negotiated via extended next pages and isn't - * in the base page (reg 7.19) or 10GBT_STAT (reg 7.33). - * PMA/PMD CTRL1 speed select: bit 13 (SS13), bit 6 (SS6): - * SS13=1: 10G - * SS13=0, SS6=1: 1G - * SS13=0, SS6=0: 10M/100M */ - ctrl1 = dtsec_sfp_phy_read(sc, MDIO_MMD_PMAPMD, MDIO_CTRL1); - if (ctrl1 >= 0) { - if (ctrl1 & (1 << 13)) - return (10000); - if (ctrl1 & (1 << 6)) - return (1000); - return (100); - } - - return (0); -} - -/* - * PHY link status poll task — runs in taskqueue_thread (sleepable). - * Reads PMA/PMD STAT1 to determine link state, updates ifnet. - */ static void -dtsec_sfp_phy_poll_task(void *arg, int pending) +dtsec_sfp_link_up(void *arg, int speed) { struct dtsec_softc *sc = arg; - int stat, speed; - bool link_up; - /* Module may have been removed between enqueue and execution */ - if (!sc->sc_sfp_has_phy) - return; - - /* Read PMA/PMD link status (standard C45 register) */ - stat = dtsec_sfp_phy_read(sc, MDIO_MMD_PMAPMD, MDIO_STAT1); - if (stat < 0) - return; /* I2C error, skip this poll */ - - link_up = (stat & MDIO_STAT1_LSTATUS) != 0; - - /* Detect link state change */ - if (link_up != sc->sc_sfp_phy_link) { - sc->sc_sfp_phy_link = link_up; - - if (link_up) { - speed = dtsec_sfp_phy_read_speed(sc); - sc->sc_sfp_phy_speed = speed; - if (speed > 0) - device_printf(sc->sc_dev, - "SFP+ PHY: link up at %d Mbps\n", - speed); - else - device_printf(sc->sc_dev, - "SFP+ PHY: link up (speed unknown)\n"); - if_link_state_change(sc->sc_ifnet, LINK_STATE_UP); - } else { - sc->sc_sfp_phy_speed = 0; - device_printf(sc->sc_dev, - "SFP+ PHY: link down\n"); - if_link_state_change(sc->sc_ifnet, LINK_STATE_DOWN); - } - } - - /* Keep polling for speed if link is up but speed not yet known - * (AN may complete after PMA link comes up) */ - if (link_up && sc->sc_sfp_phy_speed == 0) { - speed = dtsec_sfp_phy_read_speed(sc); - if (speed > 0) { - sc->sc_sfp_phy_speed = speed; - device_printf(sc->sc_dev, - "SFP+ PHY: negotiated %d Mbps\n", speed); - } - } + sc->sc_sfp_phy_link = true; + sc->sc_sfp_phy_speed = speed; + if_link_state_change(sc->sc_ifnet, LINK_STATE_UP); } -/* - * DDM-based link poll for copper modules without accessible PHY. - * Reads DDM status byte (A2h offset 0x6E, bit 1 = RX_LOS) via I2C. - * Runs in taskqueue_thread (sleepable context). - */ static void -dtsec_sfp_ddm_poll_task(void *arg, int pending) +dtsec_sfp_link_down(void *arg) { struct dtsec_softc *sc = arg; - struct iic_msg msgs[2]; - uint8_t reg, ddm_status; - int error; - bool link_up; - if (sc->sc_sfp_i2c == NULL || sc->sc_sfp_modstate != 1) - return; - - reg = 0x6E; - msgs[0].slave = 0x51 << 1; - msgs[0].flags = IIC_M_WR; - msgs[0].len = 1; - msgs[0].buf = ® - msgs[1].slave = 0x51 << 1; - msgs[1].flags = IIC_M_RD; - msgs[1].len = 1; - msgs[1].buf = &ddm_status; - - error = iicbus_request_bus(sc->sc_sfp_i2c, sc->sc_dev, IIC_INTRWAIT); - if (error != 0) - return; - error = iicbus_transfer(sc->sc_sfp_i2c, msgs, 2); - iicbus_release_bus(sc->sc_sfp_i2c, sc->sc_dev); - - if (error != 0) - return; - - /* Bit 1 = RX_LOS: 1 = no signal, 0 = signal present */ - link_up = (ddm_status & 0x02) == 0; - - if (link_up != sc->sc_sfp_phy_link) { - sc->sc_sfp_phy_link = link_up; - device_printf(sc->sc_dev, "SFP+ DDM: link %s\n", - link_up ? "up" : "down"); - if_link_state_change(sc->sc_ifnet, - link_up ? LINK_STATE_UP : LINK_STATE_DOWN); - } + sc->sc_sfp_phy_link = false; + sc->sc_sfp_phy_speed = 0; + if_link_state_change(sc->sc_ifnet, LINK_STATE_DOWN); } -static void -dtsec_sfp_insert_task(void *arg, int pending) -{ - struct dtsec_softc *sc = arg; - bool present, los; - - /* SFF-8472 T_serial: modules need up to 300ms after power-up - * before I2C EEPROM is accessible. */ - pause_sbt("sfpwait", SBT_1MS * 300, 0, C_PREL(2)); - - /* Read EEPROM (sleeps — runs in taskqueue thread context) */ - dtsec_sfp_read_eeprom(sc); - - /* - * Take the lock to commit state atomically. Re-check module - * presence under lock — the poll callout may have already - * processed a removal (modstate reset to 0) while we were - * reading the EEPROM. Only proceed if modstate is still -1 - * (probing, set by the poll that enqueued us). - */ - DTSEC_LOCK(sc); - - if (sc->sc_sfp_modstate != -1) { - /* Module was removed while we were reading EEPROM */ - DTSEC_UNLOCK(sc); - return; - } - - /* Verify module is still physically present */ - gpio_pin_is_active(sc->sc_sfp_moddef0, &present); - if (!present) { - sc->sc_sfp_modstate = 0; - memset(sc->sc_sfp_id, 0, sizeof(sc->sc_sfp_id)); - DTSEC_UNLOCK(sc); - return; - } - - /* Log module info */ - if (sc->sc_sfp_id[SFP_ID_OFFSET] != 0) - dtsec_sfp_log_module(sc); - - /* De-assert TX disable */ - if (sc->sc_sfp_txdis != NULL) - gpio_pin_set_active(sc->sc_sfp_txdis, false); - - sc->sc_sfp_modstate = 1; - - /* For copper PHY modules, probe the embedded PHY via I2C-MDIO. - * This starts auto-negotiation; the PHY poll task will track link. */ - if (sc->sc_sfp_id[SFP_CONNECTOR_OFFSET] == SFP_CONNECTOR_RJ45 && - sc->sc_sfp_i2c != NULL) { - sc->sc_sfp_los_prev = true; - if_link_state_change(sc->sc_ifnet, LINK_STATE_DOWN); - DTSEC_UNLOCK(sc); - dtsec_sfp_phy_probe(sc); - return; - } - - /* Check initial link state for fiber/DAC modules */ - if (sc->sc_sfp_los != NULL) { - gpio_pin_is_active(sc->sc_sfp_los, &los); - sc->sc_sfp_los_prev = los; - if_link_state_change(sc->sc_ifnet, - los ? LINK_STATE_DOWN : LINK_STATE_UP); - } else { - /* No LOS GPIO — assume link up when module present */ - sc->sc_sfp_los_prev = false; - if_link_state_change(sc->sc_ifnet, LINK_STATE_UP); - } - - DTSEC_UNLOCK(sc); -} - -static void -dtsec_sfp_poll(struct dtsec_softc *sc) -{ - bool present, los; - - DTSEC_LOCK_ASSERT(sc); - - if (sc->sc_sfp_moddef0 == NULL) - return; - - gpio_pin_is_active(sc->sc_sfp_moddef0, &present); - - if (present && sc->sc_sfp_modstate == 0) { - /* Module just inserted — defer EEPROM read to thread. - * Set modstate to -1 (probing) to prevent re-enqueue - * on the next tick before the task completes. */ - sc->sc_sfp_modstate = -1; - taskqueue_enqueue(taskqueue_thread, &sc->sc_sfp_task); - return; - } - - if (!present && sc->sc_sfp_modstate != 0) { - /* Module removed */ - if (sc->sc_sfp_txdis != NULL) - gpio_pin_set_active(sc->sc_sfp_txdis, true); - if_link_state_change(sc->sc_ifnet, LINK_STATE_UNKNOWN); - sc->sc_sfp_modstate = 0; - sc->sc_sfp_los_prev = true; - sc->sc_sfp_has_phy = false; - sc->sc_sfp_phy_proto = 0; - sc->sc_sfp_phy_link = false; - sc->sc_sfp_phy_speed = 0; - sc->sc_sfp_phy_id = 0; - memset(sc->sc_sfp_id, 0, sizeof(sc->sc_sfp_id)); - device_printf(sc->sc_dev, "SFP+ module removed\n"); - return; - } - - /* Steady state: PHY-based modules use I2C polling (deferred) */ - if (sc->sc_sfp_modstate == 1 && sc->sc_sfp_has_phy) { - taskqueue_enqueue(taskqueue_thread, &sc->sc_sfp_phy_task); - return; - } - - /* Steady state: copper modules without PHY — poll DDM RX_LOS */ - if (sc->sc_sfp_modstate == 1 && !sc->sc_sfp_has_phy && - sc->sc_sfp_id[SFP_CONNECTOR_OFFSET] == SFP_CONNECTOR_RJ45 && - sc->sc_sfp_i2c != NULL) { - taskqueue_enqueue(taskqueue_thread, &sc->sc_sfp_ddm_task); - return; - } - - /* Steady state: fiber/DAC modules poll LOS GPIO */ - if (sc->sc_sfp_modstate == 1 && sc->sc_sfp_los != NULL) { - gpio_pin_is_active(sc->sc_sfp_los, &los); - if (los != sc->sc_sfp_los_prev) { - sc->sc_sfp_los_prev = los; - if_link_state_change(sc->sc_ifnet, - los ? LINK_STATE_DOWN : LINK_STATE_UP); - } - } -} +const struct sfp_upstream_ops dtsec_sfp_ops = { + .module_insert = dtsec_sfp_module_insert, + .module_remove = dtsec_sfp_module_remove, + .link_up = dtsec_sfp_link_up, + .link_down = dtsec_sfp_link_down, +}; /** @} */ @@ -1598,29 +758,28 @@ dtsec_ifmedia_sts(if_t ifp, struct ifmediareq *ifmr) mii_pollstat(sc->sc_mii); ifmr->ifm_active = sc->sc_mii->mii_media_active; ifmr->ifm_status = sc->sc_mii->mii_media_status; - } else if (sc->sc_sfp_has_phy) { - /* SFP+ copper module with embedded PHY */ + } else if (sc->sc_sfp_dev != NULL) { + /* SFP+ — link state from sfp_fdt callbacks */ ifmr->ifm_active = IFM_ETHER | IFM_FDX; - switch (sc->sc_sfp_phy_speed) { - case 10000: ifmr->ifm_active |= IFM_10G_T; break; - case 5000: ifmr->ifm_active |= IFM_5000_T; break; - case 2500: ifmr->ifm_active |= IFM_2500_T; break; - case 1000: ifmr->ifm_active |= IFM_1000_T; break; - default: ifmr->ifm_active |= IFM_10G_T; break; + if (sc->sc_sfp_id[SFP_CONNECTOR_OFFSET] == + SFP_CONNECTOR_RJ45) { + /* Copper module — report speed */ + switch (sc->sc_sfp_phy_speed) { + case 10000: ifmr->ifm_active |= IFM_10G_T; break; + case 5000: ifmr->ifm_active |= IFM_5000_T; break; + case 2500: ifmr->ifm_active |= IFM_2500_T; break; + case 1000: ifmr->ifm_active |= IFM_1000_T; break; + default: ifmr->ifm_active |= IFM_10G_T; break; + } + } else { + ifmr->ifm_active |= IFM_10G_SR; } if (sc->sc_sfp_phy_link) ifmr->ifm_status = IFM_AVALID | IFM_ACTIVE; else ifmr->ifm_status = IFM_AVALID; - } else if (sc->sc_sfp_moddef0 != NULL) { - /* SFP port with GPIO-based status */ - ifmr->ifm_active = IFM_ETHER | IFM_10G_SR | IFM_FDX; - if (sc->sc_sfp_modstate != 0 && !sc->sc_sfp_los_prev) - ifmr->ifm_status = IFM_AVALID | IFM_ACTIVE; - else - ifmr->ifm_status = IFM_AVALID; } else { - /* 10G port with no SFP GPIOs — legacy always-up */ + /* 10G port with no SFP framework — legacy always-up */ ifmr->ifm_active = IFM_ETHER | IFM_10G_SR | IFM_FDX; ifmr->ifm_status = IFM_AVALID | IFM_ACTIVE; } @@ -1765,27 +924,16 @@ dtsec_sysctl_diag(SYSCTL_HANDLER_ARGS) (ifmode & 0x3) == 4 ? "RGMII" : "unknown", ifstat, ievent); } - /* SFP GPIO state */ - if (sc->sc_sfp_moddef0 != NULL) { - bool mod_present, los_active; - gpio_pin_is_active(sc->sc_sfp_moddef0, &mod_present); - printf("%s: SFP GPIO: MOD_DEF0=%s", + /* SFP state (managed by sfp_fdt) */ + if (sc->sc_sfp_dev != NULL) { + printf("%s: SFP: module=%s link=%s speed=%d\n", if_name(sc->sc_ifnet), - mod_present ? "present" : "absent"); - if (sc->sc_sfp_los != NULL) { - gpio_pin_is_active(sc->sc_sfp_los, &los_active); - printf(" LOS=%s", los_active ? "ACTIVE(no signal)" : "INACTIVE(signal OK)"); - } - if (sc->sc_sfp_txdis != NULL) { - bool txdis; - gpio_pin_is_active(sc->sc_sfp_txdis, &txdis); - printf(" TX_DIS=%s", txdis ? "ASSERTED(tx off)" : "DEASSERTED(tx on)"); - } - printf(" has_phy=%d modstate=%d los_prev=%d\n", - sc->sc_sfp_has_phy, sc->sc_sfp_modstate, - sc->sc_sfp_los_prev); - /* Read DDM status byte (A2h byte 110 = 0x6E) via I2C */ - if (sc->sc_sfp_i2c != NULL && mod_present) { + sc->sc_sfp_modpresent ? "present" : "absent", + sc->sc_sfp_phy_link ? "up" : "down", + sc->sc_sfp_phy_speed); + /* Read DDM status byte (A2h byte 110 = 0x6E) */ + if (sc->sc_sfp_i2c != NULL && + sc->sc_sfp_modpresent) { struct iic_msg msgs[2]; uint8_t reg = 0x6E; uint8_t ddm_status; @@ -1830,9 +978,7 @@ dtsec_sysctl_sfp_info(SYSCTL_HANDLER_ARGS) struct dtsec_softc *sc = (struct dtsec_softc *)arg1; char buf[48]; - DTSEC_LOCK(sc); - - if (sc->sc_sfp_modstate != 1) { + if (!sc->sc_sfp_modpresent) { strlcpy(buf, "empty", sizeof(buf)); } else { char vendor[SFP_VENDOR_LEN + 1]; @@ -1845,63 +991,9 @@ dtsec_sysctl_sfp_info(SYSCTL_HANDLER_ARGS) snprintf(buf, sizeof(buf), "%s %s", vendor, partnum); } - DTSEC_UNLOCK(sc); - return (sysctl_handle_string(oidp, buf, sizeof(buf), req)); } -static int -dtsec_sysctl_sfp_phy(SYSCTL_HANDLER_ARGS) -{ - struct dtsec_softc *sc = (struct dtsec_softc *)arg1; - char buf[64]; - - DTSEC_LOCK(sc); - - if (!sc->sc_sfp_has_phy) { - strlcpy(buf, "none", sizeof(buf)); - } else { - snprintf(buf, sizeof(buf), "OUI %06x model %02x rev %x %d Mbps", - (sc->sc_sfp_phy_id >> 10) & 0x3FFFFF, - (sc->sc_sfp_phy_id >> 4) & 0x3F, - sc->sc_sfp_phy_id & 0xF, - sc->sc_sfp_phy_speed); - } - - DTSEC_UNLOCK(sc); - - return (sysctl_handle_string(oidp, buf, sizeof(buf), req)); -} - -static int -dtsec_sysctl_sfp_txdis(SYSCTL_HANDLER_ARGS) -{ - struct dtsec_softc *sc = (struct dtsec_softc *)arg1; - int val = -1; - int error; - - if (sc->sc_sfp_txdis == NULL) - return (ENXIO); - - /* Read current state */ - if (req->newptr == NULL) { - bool active; - gpio_pin_is_active(sc->sc_sfp_txdis, &active); - val = active ? 1 : 0; - return (sysctl_handle_int(oidp, &val, 0, req)); - } - - error = sysctl_handle_int(oidp, &val, 0, req); - if (error || req->newptr == NULL) - return (error); - - gpio_pin_set_active(sc->sc_sfp_txdis, val != 0); - device_printf(sc->sc_dev, "TX_DISABLE manually %s\n", - val ? "ASSERTED" : "DEASSERTED"); - - return (0); -} - static uint64_t dtsec_get_counter(if_t ifp, ift_counter cnt) { @@ -1960,11 +1052,6 @@ dtsec_attach(device_t dev) /* Init callouts */ callout_init(&sc->sc_tick_callout, CALLOUT_MPSAFE); - /* Init SFP tasks */ - TASK_INIT(&sc->sc_sfp_task, 0, dtsec_sfp_insert_task, sc); - TASK_INIT(&sc->sc_sfp_phy_task, 0, dtsec_sfp_phy_poll_task, sc); - TASK_INIT(&sc->sc_sfp_ddm_task, 0, dtsec_sfp_ddm_poll_task, sc); - /* Read configuraton */ if ((error = fman_get_handle(parent, &sc->sc_fmh)) != 0) return (error); @@ -2092,7 +1179,7 @@ dtsec_attach(device_t dev) /* 10G ports: SFP leaves default LINK_STATE_UNKNOWN (no module), * non-SFP assumes always up (legacy) */ - if (sc->sc_phy_addr < 0 && sc->sc_sfp_moddef0 == NULL) + if (sc->sc_phy_addr < 0 && sc->sc_sfp_dev == NULL) if_link_state_change(ifp, LINK_STATE_UP); /* Add diagnostic sysctls */ @@ -2112,22 +1199,12 @@ dtsec_attach(device_t dev) sc, 0, dtsec_sysctl_diag, "I", "Write 1 to dump DQRR + BMan state to dmesg"); - if (sc->sc_sfp_moddef0 != NULL) { + if (sc->sc_sfp_dev != NULL) { SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "sfp_info", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0, dtsec_sysctl_sfp_info, "A", "SFP+ module vendor and part number"); - SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), - OID_AUTO, "sfp_phy", - CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, - sc, 0, dtsec_sysctl_sfp_phy, "A", - "SFP+ embedded PHY info (10GBASE-T modules)"); - SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), - OID_AUTO, "sfp_txdis", - CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, - sc, 0, dtsec_sysctl_sfp_txdis, "I", - "Write 0/1 to deassert/assert TX_DISABLE"); } } diff --git a/sys/dev/dpaa/if_dtsec.h b/sys/dev/dpaa/if_dtsec.h index f917914a779..c8f972fb109 100644 --- a/sys/dev/dpaa/if_dtsec.h +++ b/sys/dev/dpaa/if_dtsec.h @@ -30,7 +30,6 @@ #include "opt_dpaa.h" #include -#include /** * @group dTSEC common API. @@ -143,27 +142,13 @@ struct dtsec_softc { volatile int sc_ceetm_en; uint32_t sc_ceetm_dscp_fqid[64]; - /* SFP module management (10G ports only) */ - device_t sc_sfp_dev; /* sff driver instance */ - device_t sc_sfp_i2c; /* I2C bus for EEPROM */ - gpio_pin_t sc_sfp_moddef0; /* module detect GPIO */ - gpio_pin_t sc_sfp_los; /* loss-of-signal GPIO */ - gpio_pin_t sc_sfp_txdis; /* TX disable GPIO */ - int sc_sfp_modstate; /* 0=absent, 1=present */ - bool sc_sfp_los_prev; /* previous LOS for edge detect */ + /* SFP module management (10G ports only, via sfp_fdt callbacks) */ + device_t sc_sfp_dev; /* sfp_fdt driver instance */ + device_t sc_sfp_i2c; /* I2C bus (for sysctl diag) */ uint8_t sc_sfp_id[64]; /* EEPROM A0h base ID */ - struct task sc_sfp_task; /* deferred insert handler */ - - /* SFP embedded PHY (10GBASE-T copper modules) */ - bool sc_sfp_has_phy; /* PHY detected via I2C-MDIO */ -#define DTSEC_SFP_PHY_ROLLBALL 1 /* RollBall protocol at 0x51 */ -#define DTSEC_SFP_PHY_MDIOI2C 2 /* Standard I2C-MDIO at 0x56 */ - int sc_sfp_phy_proto; /* access protocol */ - uint32_t sc_sfp_phy_id; /* PHY OUI+model from DEVID1/2 */ - bool sc_sfp_phy_link; /* PHY link status */ - int sc_sfp_phy_speed; /* negotiated speed (Mbps) */ - struct task sc_sfp_phy_task; /* deferred PHY poll */ - struct task sc_sfp_ddm_task; /* deferred DDM poll */ + bool sc_sfp_modpresent; /* module present */ + bool sc_sfp_phy_link; /* link state */ + int sc_sfp_phy_speed; /* speed in Mbps */ }; /** @} */ @@ -217,4 +202,12 @@ int dtsec_miibus_writereg(device_t dev, int phy, int reg, void dtsec_miibus_statchg(device_t dev); /** @} */ +/** + * @group SFP upstream callbacks. + * @{ + */ +struct sfp_upstream_ops; +extern const struct sfp_upstream_ops dtsec_sfp_ops; +/** @} */ + #endif /* IF_DTSEC_H_ */ diff --git a/sys/dev/dpaa/if_dtsec_fdt.c b/sys/dev/dpaa/if_dtsec_fdt.c index 679271185c2..c85b9f498cd 100644 --- a/sys/dev/dpaa/if_dtsec_fdt.c +++ b/sys/dev/dpaa/if_dtsec_fdt.c @@ -49,9 +49,9 @@ #include #include -#include - #include "miibus_if.h" + +#include #include "sff_if.h" #include @@ -186,52 +186,24 @@ dtsec_fdt_attach(device_t dev) sc->sc_mdio = phy_dev; skip_phy: - /* Parse SFP phandle for 10G ports */ + /* Register with SFP framework for 10G ports */ if (sc->sc_eth_dev_type == ETH_10GSEC) { - phandle_t sfp_xref, sfp_node; + phandle_t sfp_xref; device_t sfp_dev; if (OF_getencprop(enet_node, "sfp", &sfp_xref, sizeof(sfp_xref)) > 0) { - sfp_node = OF_node_from_xref(sfp_xref); sfp_dev = OF_device_from_xref(sfp_xref); if (sfp_dev != NULL) { sc->sc_sfp_dev = sfp_dev; - /* Get I2C bus from sff driver */ - if (SFF_GET_I2C_BUS(sfp_dev, - &sc->sc_sfp_i2c) != 0) { - device_printf(dev, - "SFP: failed to get I2C bus\n"); - sc->sc_sfp_i2c = NULL; - } + /* Keep I2C bus handle for sysctl diag */ + SFF_GET_I2C_BUS(sfp_dev, &sc->sc_sfp_i2c); - /* Acquire GPIOs from SFP DT node */ - gpio_pin_get_by_ofw_property(dev, sfp_node, - "mod-def0-gpios", &sc->sc_sfp_moddef0); - gpio_pin_get_by_ofw_property(dev, sfp_node, - "los-gpios", &sc->sc_sfp_los); - gpio_pin_get_by_ofw_property(dev, sfp_node, - "tx-disable-gpios", &sc->sc_sfp_txdis); - - /* Configure TX disable as output, hold asserted - * until module detected. Without setflags the - * pin stays in INPUT mode and writes are - * silently ignored. */ - if (sc->sc_sfp_txdis != NULL) { - gpio_pin_setflags(sc->sc_sfp_txdis, - GPIO_PIN_OUTPUT); - gpio_pin_set_active(sc->sc_sfp_txdis, - true); - } - - if (sc->sc_sfp_moddef0 != NULL) - device_printf(dev, - "SFP+ cage detected (GPIOs OK)\n"); - else - device_printf(dev, - "SFP: no mod-def0 GPIO\n"); + /* Register to receive module/link events */ + SFF_REGISTER_UPSTREAM(sfp_dev, + &dtsec_sfp_ops, sc); } else { device_printf(dev, "SFP: sff driver not found\n"); diff --git a/sys/dev/sff/sff_if.m b/sys/dev/sff/sff_if.m index 823e557992c..0048114047c 100644 --- a/sys/dev/sff/sff_if.m +++ b/sys/dev/sff/sff_if.m @@ -26,6 +26,7 @@ # #include +#include INTERFACE sff; @@ -33,3 +34,14 @@ METHOD int get_i2c_bus { device_t dev; device_t *i2c_bus; }; + +# +# Register upstream MAC driver to receive module/link event callbacks. +# ops: function pointer table (sfp_upstream_ops from sfp_fdt.h) +# arg: opaque context passed to each callback (typically MAC softc) +# +METHOD int register_upstream { + device_t dev; + const struct sfp_upstream_ops *ops; + void *arg; +}; diff --git a/sys/dev/sff/sfp_fdt.c b/sys/dev/sff/sfp_fdt.c index e566d8ced78..fdedd84ba98 100644 --- a/sys/dev/sff/sfp_fdt.c +++ b/sys/dev/sff/sfp_fdt.c @@ -1,7 +1,8 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * - * Copyright © 2023 Dmitry Salychev + * Copyright (c) 2023 Dmitry Salychev + * Copyright (c) 2026 Mono Technologies Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,33 +27,1072 @@ */ /* - * Small Form Factor (SFF) Committee Pluggable (SFP) Transceiver (FDT-based). + * SFP/SFP+ transceiver management driver (FDT-based). + * + * Implements a state machine for SFP module hot-plug, EEPROM identification, + * embedded PHY management (RollBall and standard I2C-MDIO), and link + * monitoring. MAC drivers register upstream callbacks to receive module + * insert/remove and link up/down events. + * + * Inspired by Linux drivers/net/phy/sfp.c but simplified to a single + * state machine without phylink dependency. */ #include #include #include #include +#include +#include +#include +#include #include #include #include +#include +#include +#include +#include + +#include #include "sff_if.h" -struct sfp_fdt_softc { - phandle_t ofw_node; - phandle_t i2c_bus; +/* State machine states */ +#define SFP_ST_EMPTY 0 /* No module */ +#define SFP_ST_PROBE 1 /* Module detected, reading EEPROM */ +#define SFP_ST_PRESENT 2 /* EEPROM read, classifying */ +#define SFP_ST_PHY_PROBE 3 /* Probing embedded PHY (copper) */ +#define SFP_ST_PHY_AN 4 /* PHY found, polling link */ +#define SFP_ST_DDM_POLL 5 /* No PHY, polling DDM RX_LOS */ +#define SFP_ST_WAIT_LOS 6 /* Fiber/DAC: monitoring LOS GPIO */ +#define SFP_ST_LINK_UP 7 /* Link established */ - phandle_t mod_def; - phandle_t los; - phandle_t tx_fault; - phandle_t tx_disable; - phandle_t rx_rate; - phandle_t tx_rate; - uint32_t max_power; /* in mW */ +/* IEEE 802.3 Clause 45 MMD device numbers */ +#define MDIO_MMD_PMAPMD 1 +#define MDIO_MMD_AN 7 + +/* Standard C45 register offsets */ +#define MDIO_CTRL1 0 +#define MDIO_STAT1 1 +#define MDIO_DEVID1 2 +#define MDIO_DEVID2 3 +#define MDIO_PMA_EXTABLE 11 +#define MDIO_AN_10GBT_CTRL 32 +#define MDIO_AN_10GBT_STAT 33 + +/* STAT1 bits */ +#define MDIO_STAT1_LSTATUS (1 << 2) + +/* AN CTRL1 bits */ +#define MDIO_AN_CTRL1_XNP (1 << 13) +#define MDIO_AN_CTRL1_ENABLE (1 << 12) +#define MDIO_AN_CTRL1_RESTART (1 << 9) + +/* AN STAT1 bits */ +#define MDIO_AN_STAT1_COMPLETE (1 << 5) + +/* PMA EXTABLE bits */ +#define MDIO_PMA_EXTABLE_10GBT (1 << 2) +#define MDIO_PMA_EXTABLE_1000BT (1 << 5) +#define MDIO_PMA_EXTABLE_NBT (1 << 14) + +/* AN 10GBT_CTRL advertisement bits */ +#define MDIO_AN_10GBT_CTRL_ADV10G (1 << 12) +#define MDIO_AN_10GBT_CTRL_ADV5G (1 << 8) +#define MDIO_AN_10GBT_CTRL_ADV2_5G (1 << 7) + +/* AN 10GBT_STAT link partner bits */ +#define MDIO_AN_10GBT_STAT_LP10G (1 << 11) +#define MDIO_AN_10GBT_STAT_LP5G (1 << 6) +#define MDIO_AN_10GBT_STAT_LP2_5G (1 << 5) + +/* Standard I2C-MDIO bridge (SFF-8472) */ +#define MDIOI2C_I2C_ADDR 0x56 + +/* RollBall I2C-to-MDIO bridge */ +#define ROLLBALL_I2C_ADDR 0x51 +#define ROLLBALL_PAGE_REG 0x7F +#define ROLLBALL_PAGE 3 +#define ROLLBALL_PASSWORD_REG 0x7B +#define ROLLBALL_CMD_ADDR 0x80 +#define ROLLBALL_DATA_ADDR 0x81 +#define ROLLBALL_CMD_READ 0x02 +#define ROLLBALL_CMD_WRITE 0x01 +#define ROLLBALL_CMD_DONE 0x04 +#define ROLLBALL_POLL_RETRIES 20 +#define ROLLBALL_POLL_MS 20 + +/* PHY access protocol */ +#define SFP_PHY_ROLLBALL 1 +#define SFP_PHY_MDIOI2C 2 + +/* PHY boot retries (500ms each, up to 4.5s total) */ +#define SFP_PHY_BOOT_RETRIES 9 +#define SFP_PHY_BOOT_MS 500 + +struct sfp_fdt_softc { + device_t sc_dev; + phandle_t sc_node; + + /* I2C */ + phandle_t sc_i2c_phandle; + device_t sc_i2c; /* resolved iicbus device */ + + /* GPIOs */ + gpio_pin_t sc_moddef0; /* module detect (active low) */ + gpio_pin_t sc_los; /* loss of signal */ + gpio_pin_t sc_txdis; /* TX disable (output) */ + + /* State machine */ + struct mtx sc_mtx; + int sc_state; + uint8_t sc_id[64]; /* EEPROM A0h base ID cache */ + uint8_t sc_connector; + + /* PHY (copper modules) */ + bool sc_has_phy; + int sc_phy_proto; + uint32_t sc_phy_id; + bool sc_phy_link; + int sc_phy_speed; + int sc_phy_retries; + + /* Fiber/DAC LOS tracking */ + bool sc_los_prev; + + /* Upstream (MAC driver) */ + const struct sfp_upstream_ops *sc_upstream_ops; + void *sc_upstream_arg; + + /* Polling */ + struct task sc_sm_task; + struct callout sc_poll; }; +#define SFP_LOCK(sc) mtx_lock(&(sc)->sc_mtx) +#define SFP_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) + +/* Forward declarations */ +static void sfp_fdt_sm_task(void *arg, int pending); +static void sfp_fdt_poll_callout(void *arg); + +/* + * Lazily resolve I2C bus device. The I2C mux (pca954x) may attach + * after sfp_fdt, so we defer resolution until first use. + */ +static bool +sfp_fdt_resolve_i2c(struct sfp_fdt_softc *sc) +{ + device_t xdev; + + if (sc->sc_i2c != NULL) + return (true); + + xdev = OF_device_from_xref(OF_xref_from_node(sc->sc_i2c_phandle)); + if (xdev == NULL) + return (false); + + sc->sc_i2c = xdev; + return (true); +} + +/* + * ============================================================ + * I2C helpers + * ============================================================ + */ + +static int +sfp_fdt_i2c_read(struct sfp_fdt_softc *sc, uint8_t addr, uint8_t offset, + uint8_t *buf, int len) +{ + struct iic_msg msgs[2]; + int error; + + msgs[0].slave = addr << 1; + msgs[0].flags = IIC_M_WR; + msgs[0].len = 1; + msgs[0].buf = &offset; + msgs[1].slave = addr << 1; + msgs[1].flags = IIC_M_RD; + msgs[1].len = len; + msgs[1].buf = buf; + + error = iicbus_request_bus(sc->sc_i2c, sc->sc_dev, IIC_INTRWAIT); + if (error != 0) + return (error); + error = iicbus_transfer(sc->sc_i2c, msgs, 2); + iicbus_release_bus(sc->sc_i2c, sc->sc_dev); + + return (error); +} + +static int +sfp_fdt_i2c_write_raw(struct sfp_fdt_softc *sc, uint8_t addr, + uint8_t *buf, int len) +{ + struct iic_msg msg; + + msg.slave = addr << 1; + msg.flags = IIC_M_WR; + msg.len = len; + msg.buf = buf; + + return (iicbus_transfer(sc->sc_i2c, &msg, 1)); +} + +static int +sfp_fdt_i2c_read_raw(struct sfp_fdt_softc *sc, uint8_t addr, + uint8_t reg, uint8_t *buf, int len) +{ + struct iic_msg msgs[2]; + + msgs[0].slave = addr << 1; + msgs[0].flags = IIC_M_WR; + msgs[0].len = 1; + msgs[0].buf = ® + msgs[1].slave = addr << 1; + msgs[1].flags = IIC_M_RD; + msgs[1].len = len; + msgs[1].buf = buf; + + return (iicbus_transfer(sc->sc_i2c, msgs, 2)); +} + +/* + * ============================================================ + * EEPROM + * ============================================================ + */ + +static int +sfp_fdt_read_eeprom(struct sfp_fdt_softc *sc) +{ + int error; + + error = sfp_fdt_i2c_read(sc, SFP_EEPROM_ADDR, 0, + sc->sc_id, sizeof(sc->sc_id)); + if (error != 0) { + device_printf(sc->sc_dev, "SFP EEPROM read failed: %d\n", + error); + memset(sc->sc_id, 0, sizeof(sc->sc_id)); + } + return (error); +} + +static void +sfp_fdt_trim(char *dst, const uint8_t *src, int len) +{ + int i; + + memcpy(dst, src, len); + dst[len] = '\0'; + for (i = len - 1; i >= 0 && dst[i] == ' '; i--) + dst[i] = '\0'; +} + +static void +sfp_fdt_log_module(struct sfp_fdt_softc *sc) +{ + char vendor[SFP_VENDOR_LEN + 1]; + char partnum[SFP_PARTNUM_LEN + 1]; + uint8_t connector; + + sfp_fdt_trim(vendor, &sc->sc_id[SFP_VENDOR_OFFSET], SFP_VENDOR_LEN); + sfp_fdt_trim(partnum, &sc->sc_id[SFP_PARTNUM_OFFSET], SFP_PARTNUM_LEN); + connector = sc->sc_id[SFP_CONNECTOR_OFFSET]; + + device_printf(sc->sc_dev, + "SFP+ module: %s %s (connector 0x%02x%s)\n", + vendor, partnum, connector, + connector == SFP_CONNECTOR_RJ45 ? " RJ45" : ""); +} + +/* + * ============================================================ + * Standard I2C-MDIO (SFF-8472, address 0x56) + * ============================================================ + */ + +static int +mdioi2c_read(struct sfp_fdt_softc *sc, int devad, int reg) +{ + uint8_t addr[3], data[2]; + int error; + + addr[0] = 0x20 | (devad & 0x1F); + addr[1] = (reg >> 8) & 0xFF; + addr[2] = reg & 0xFF; + + error = iicbus_request_bus(sc->sc_i2c, sc->sc_dev, IIC_INTRWAIT); + if (error != 0) + return (-1); + + error = sfp_fdt_i2c_write_raw(sc, MDIOI2C_I2C_ADDR, addr, 3); + if (error == 0) { + struct iic_msg msg; + msg.slave = MDIOI2C_I2C_ADDR << 1; + msg.flags = IIC_M_RD; + msg.len = 2; + msg.buf = data; + error = iicbus_transfer(sc->sc_i2c, &msg, 1); + } + + iicbus_release_bus(sc->sc_i2c, sc->sc_dev); + + if (error != 0) + return (-1); + return ((data[0] << 8) | data[1]); +} + +static int +mdioi2c_write(struct sfp_fdt_softc *sc, int devad, int reg, int val) +{ + uint8_t buf[5]; + int error; + + buf[0] = devad & 0x1F; + buf[1] = (reg >> 8) & 0xFF; + buf[2] = reg & 0xFF; + buf[3] = (val >> 8) & 0xFF; + buf[4] = val & 0xFF; + + error = iicbus_request_bus(sc->sc_i2c, sc->sc_dev, IIC_INTRWAIT); + if (error != 0) + return (error); + error = sfp_fdt_i2c_write_raw(sc, MDIOI2C_I2C_ADDR, buf, 5); + iicbus_release_bus(sc->sc_i2c, sc->sc_dev); + + return (error); +} + +/* + * ============================================================ + * RollBall I2C-to-MDIO bridge (address 0x51) + * ============================================================ + */ + +/* Bus must already be acquired */ +static int +rollball_page_set(struct sfp_fdt_softc *sc, uint8_t *saved_page) +{ + uint8_t buf[2]; + int error; + + error = sfp_fdt_i2c_read_raw(sc, ROLLBALL_I2C_ADDR, + ROLLBALL_PAGE_REG, saved_page, 1); + if (error != 0) + return (error); + + buf[0] = ROLLBALL_PAGE_REG; + buf[1] = ROLLBALL_PAGE; + return (sfp_fdt_i2c_write_raw(sc, ROLLBALL_I2C_ADDR, buf, 2)); +} + +/* Bus must already be acquired */ +static int +rollball_page_restore(struct sfp_fdt_softc *sc, uint8_t saved_page) +{ + uint8_t buf[2] = { ROLLBALL_PAGE_REG, saved_page }; + + return (sfp_fdt_i2c_write_raw(sc, ROLLBALL_I2C_ADDR, buf, 2)); +} + +static int +rollball_init(struct sfp_fdt_softc *sc) +{ + uint8_t pw[] = { ROLLBALL_PASSWORD_REG, 0xFF, 0xFF, 0xFF, 0xFF }; + int error; + + error = iicbus_request_bus(sc->sc_i2c, sc->sc_dev, IIC_INTRWAIT); + if (error != 0) + return (error); + error = sfp_fdt_i2c_write_raw(sc, ROLLBALL_I2C_ADDR, pw, sizeof(pw)); + iicbus_release_bus(sc->sc_i2c, sc->sc_dev); + + return (error); +} + +static int +rollball_phy_read(struct sfp_fdt_softc *sc, int devad, int reg) +{ + uint8_t data_buf[4], cmd_buf[2], res[6]; + uint8_t saved_page; + int error, i; + + error = iicbus_request_bus(sc->sc_i2c, sc->sc_dev, IIC_INTRWAIT); + if (error != 0) + return (-1); + + error = rollball_page_set(sc, &saved_page); + if (error != 0) + goto out; + + /* Write devad + register address */ + data_buf[0] = ROLLBALL_DATA_ADDR; + data_buf[1] = devad; + data_buf[2] = (reg >> 8) & 0xFF; + data_buf[3] = reg & 0xFF; + error = sfp_fdt_i2c_write_raw(sc, ROLLBALL_I2C_ADDR, + data_buf, 4); + if (error != 0) + goto restore; + + /* Write read command */ + cmd_buf[0] = ROLLBALL_CMD_ADDR; + cmd_buf[1] = ROLLBALL_CMD_READ; + error = sfp_fdt_i2c_write_raw(sc, ROLLBALL_I2C_ADDR, + cmd_buf, 2); + if (error != 0) + goto restore; + + /* Restore page before polling */ + rollball_page_restore(sc, saved_page); + iicbus_release_bus(sc->sc_i2c, sc->sc_dev); + + /* Poll for completion */ + for (i = 0; i < ROLLBALL_POLL_RETRIES; i++) { + pause_sbt("rbpoll", SBT_1MS * ROLLBALL_POLL_MS, 0, C_PREL(2)); + + error = iicbus_request_bus(sc->sc_i2c, sc->sc_dev, + IIC_INTRWAIT); + if (error != 0) + return (-1); + + error = rollball_page_set(sc, &saved_page); + if (error != 0) { + iicbus_release_bus(sc->sc_i2c, sc->sc_dev); + return (-1); + } + + error = sfp_fdt_i2c_read_raw(sc, ROLLBALL_I2C_ADDR, + ROLLBALL_CMD_ADDR, res, 6); + + rollball_page_restore(sc, saved_page); + iicbus_release_bus(sc->sc_i2c, sc->sc_dev); + + if (error != 0) + return (-1); + + if (res[0] == ROLLBALL_CMD_DONE) + return ((res[4] << 8) | res[5]); + } + + return (-1); /* timeout */ + +restore: + rollball_page_restore(sc, saved_page); +out: + iicbus_release_bus(sc->sc_i2c, sc->sc_dev); + return (-1); +} + +static int +rollball_phy_write(struct sfp_fdt_softc *sc, int devad, int reg, int val) +{ + uint8_t data_buf[6], cmd_buf[2], status; + uint8_t saved_page; + int error, i; + + error = iicbus_request_bus(sc->sc_i2c, sc->sc_dev, IIC_INTRWAIT); + if (error != 0) + return (error); + + error = rollball_page_set(sc, &saved_page); + if (error != 0) + goto out; + + data_buf[0] = ROLLBALL_DATA_ADDR; + data_buf[1] = devad; + data_buf[2] = (reg >> 8) & 0xFF; + data_buf[3] = reg & 0xFF; + data_buf[4] = (val >> 8) & 0xFF; + data_buf[5] = val & 0xFF; + error = sfp_fdt_i2c_write_raw(sc, ROLLBALL_I2C_ADDR, + data_buf, 6); + if (error != 0) + goto restore; + + cmd_buf[0] = ROLLBALL_CMD_ADDR; + cmd_buf[1] = ROLLBALL_CMD_WRITE; + error = sfp_fdt_i2c_write_raw(sc, ROLLBALL_I2C_ADDR, + cmd_buf, 2); + if (error != 0) + goto restore; + + rollball_page_restore(sc, saved_page); + iicbus_release_bus(sc->sc_i2c, sc->sc_dev); + + /* Poll for completion */ + for (i = 0; i < ROLLBALL_POLL_RETRIES; i++) { + pause_sbt("rbpoll", SBT_1MS * ROLLBALL_POLL_MS, 0, C_PREL(2)); + + error = iicbus_request_bus(sc->sc_i2c, sc->sc_dev, + IIC_INTRWAIT); + if (error != 0) + return (error); + + error = rollball_page_set(sc, &saved_page); + if (error != 0) { + iicbus_release_bus(sc->sc_i2c, sc->sc_dev); + return (error); + } + + error = sfp_fdt_i2c_read_raw(sc, ROLLBALL_I2C_ADDR, + ROLLBALL_CMD_ADDR, &status, 1); + + rollball_page_restore(sc, saved_page); + iicbus_release_bus(sc->sc_i2c, sc->sc_dev); + + if (error != 0) + return (error); + + if (status == ROLLBALL_CMD_DONE) + return (0); + } + + return (ETIMEDOUT); + +restore: + rollball_page_restore(sc, saved_page); +out: + iicbus_release_bus(sc->sc_i2c, sc->sc_dev); + return (error); +} + +/* + * ============================================================ + * PHY register access — protocol dispatch + * ============================================================ + */ + +static int +sfp_phy_read(struct sfp_fdt_softc *sc, int devad, int reg) +{ + + if (sc->sc_phy_proto == SFP_PHY_MDIOI2C) + return (mdioi2c_read(sc, devad, reg)); + return (rollball_phy_read(sc, devad, reg)); +} + +static int +sfp_phy_write(struct sfp_fdt_softc *sc, int devad, int reg, int val) +{ + + if (sc->sc_phy_proto == SFP_PHY_MDIOI2C) + return (mdioi2c_write(sc, devad, reg, val)); + return (rollball_phy_write(sc, devad, reg, val)); +} + +/* + * ============================================================ + * PHY auto-negotiation and speed detection + * ============================================================ + */ + +static void +sfp_phy_config_aneg(struct sfp_fdt_softc *sc) +{ + int adv10g; + + /* Advertise 10G/5G/2.5G in register 7.32 */ + adv10g = MDIO_AN_10GBT_CTRL_ADV10G | + MDIO_AN_10GBT_CTRL_ADV5G | MDIO_AN_10GBT_CTRL_ADV2_5G; + sfp_phy_write(sc, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL, adv10g); + + /* Enable and restart AN with XNP (Extended Next Page). + * 10GBASE-T capability is exchanged via extended next pages — + * without XNP, only base-page speeds (1G and below) negotiate. */ + sfp_phy_write(sc, MDIO_MMD_AN, MDIO_CTRL1, + MDIO_AN_CTRL1_XNP | MDIO_AN_CTRL1_ENABLE | + MDIO_AN_CTRL1_RESTART); + + device_printf(sc->sc_dev, "SFP+ PHY: auto-negotiation started\n"); +} + +static int +sfp_phy_read_speed(struct sfp_fdt_softc *sc) +{ + int stat, lpa10g, ctrl1; + + stat = sfp_phy_read(sc, MDIO_MMD_AN, MDIO_STAT1); + if (stat < 0 || !(stat & MDIO_AN_STAT1_COMPLETE)) + return (0); + + lpa10g = sfp_phy_read(sc, MDIO_MMD_AN, MDIO_AN_10GBT_STAT); + if (lpa10g >= 0) { + if (lpa10g & MDIO_AN_10GBT_STAT_LP10G) + return (10000); + if (lpa10g & MDIO_AN_10GBT_STAT_LP5G) + return (5000); + if (lpa10g & MDIO_AN_10GBT_STAT_LP2_5G) + return (2500); + } + + /* PMA/PMD CTRL1 speed select: bit 13=10G, bit 6=1G */ + ctrl1 = sfp_phy_read(sc, MDIO_MMD_PMAPMD, MDIO_CTRL1); + if (ctrl1 >= 0) { + if (ctrl1 & (1 << 13)) + return (10000); + if (ctrl1 & (1 << 6)) + return (1000); + return (100); + } + + return (0); +} + +/* + * ============================================================ + * Upstream callback helpers + * ============================================================ + */ + +static void +sfp_fdt_notify_insert(struct sfp_fdt_softc *sc) +{ + + if (sc->sc_upstream_ops != NULL && + sc->sc_upstream_ops->module_insert != NULL) + sc->sc_upstream_ops->module_insert(sc->sc_upstream_arg, + sc->sc_id, sizeof(sc->sc_id)); +} + +static void +sfp_fdt_notify_remove(struct sfp_fdt_softc *sc) +{ + + if (sc->sc_upstream_ops != NULL && + sc->sc_upstream_ops->module_remove != NULL) + sc->sc_upstream_ops->module_remove(sc->sc_upstream_arg); +} + +static void +sfp_fdt_notify_link_up(struct sfp_fdt_softc *sc, int speed) +{ + + if (sc->sc_upstream_ops != NULL && + sc->sc_upstream_ops->link_up != NULL) + sc->sc_upstream_ops->link_up(sc->sc_upstream_arg, speed); +} + +static void +sfp_fdt_notify_link_down(struct sfp_fdt_softc *sc) +{ + + if (sc->sc_upstream_ops != NULL && + sc->sc_upstream_ops->link_down != NULL) + sc->sc_upstream_ops->link_down(sc->sc_upstream_arg); +} + +/* + * ============================================================ + * State machine transitions + * ============================================================ + */ + +/* EMPTY → PROBE: module just detected */ +static void +sfp_fdt_sm_insert(struct sfp_fdt_softc *sc) +{ + + device_printf(sc->sc_dev, "SFP+ module detected, probing...\n"); + + /* De-assert TX disable so module MCU can fully boot */ + if (sc->sc_txdis != NULL) + gpio_pin_set_active(sc->sc_txdis, false); + + sc->sc_state = SFP_ST_PROBE; +} + +/* PROBE: wait T_serial (300ms) then read EEPROM */ +static void +sfp_fdt_sm_probe(struct sfp_fdt_softc *sc) +{ + bool present; + + /* Ensure I2C bus is resolved (may have deferred from attach) */ + if (!sfp_fdt_resolve_i2c(sc)) { + device_printf(sc->sc_dev, + "SFP: I2C bus not available yet\n"); + sc->sc_state = SFP_ST_EMPTY; + if (sc->sc_txdis != NULL) + gpio_pin_set_active(sc->sc_txdis, true); + return; + } + + /* SFF-8472 T_serial: 300ms after power-up before EEPROM accessible */ + pause_sbt("sfpwait", SBT_1MS * 300, 0, C_PREL(2)); + + /* Re-check module presence after sleep */ + if (sc->sc_moddef0 != NULL) { + gpio_pin_is_active(sc->sc_moddef0, &present); + if (!present) { + sc->sc_state = SFP_ST_EMPTY; + return; + } + } + + if (sfp_fdt_read_eeprom(sc) != 0) { + /* EEPROM read failed — back to EMPTY */ + sc->sc_state = SFP_ST_EMPTY; + if (sc->sc_txdis != NULL) + gpio_pin_set_active(sc->sc_txdis, true); + return; + } + + sc->sc_connector = sc->sc_id[SFP_CONNECTOR_OFFSET]; + sfp_fdt_log_module(sc); + sfp_fdt_notify_insert(sc); + + sc->sc_state = SFP_ST_PRESENT; +} + +/* PRESENT: classify module → PHY_PROBE (copper) or WAIT_LOS (fiber) */ +static void +sfp_fdt_sm_present(struct sfp_fdt_softc *sc) +{ + + if (sc->sc_connector == SFP_CONNECTOR_RJ45) { + sc->sc_phy_retries = 0; + sc->sc_state = SFP_ST_PHY_PROBE; + } else { + /* Fiber or DAC — monitor LOS */ + sc->sc_los_prev = true; /* assume no signal initially */ + sc->sc_state = SFP_ST_WAIT_LOS; + } +} + +/* PHY_PROBE: probe embedded PHY via RollBall then I2C-MDIO */ +static void +sfp_fdt_sm_phy_probe(struct sfp_fdt_softc *sc) +{ + int id1, id2, retry; + uint32_t phy_id; + int extable; + + id1 = -1; + + /* Try RollBall first */ + sc->sc_phy_proto = SFP_PHY_ROLLBALL; + if (rollball_init(sc) == 0) { + for (retry = 0; retry < SFP_PHY_BOOT_RETRIES; retry++) { + pause_sbt("phyboot", SBT_1MS * SFP_PHY_BOOT_MS, + 0, C_PREL(2)); + + id1 = sfp_phy_read(sc, MDIO_MMD_PMAPMD, MDIO_DEVID1); + if (id1 > 0 && id1 != 0xFFFF) + break; + } + } + + /* Fallback to standard I2C-MDIO */ + if (id1 <= 0 || id1 == 0xFFFF) { + sc->sc_phy_proto = SFP_PHY_MDIOI2C; + id1 = sfp_phy_read(sc, MDIO_MMD_PMAPMD, MDIO_DEVID1); + } + + if (id1 <= 0 || id1 == 0xFFFF) { + device_printf(sc->sc_dev, + "SFP+ PHY: no C45 PHY detected " + "(tried RollBall and I2C-MDIO)\n"); + sc->sc_phy_proto = 0; + sc->sc_has_phy = false; + /* Fall back to DDM polling for copper without PHY */ + sc->sc_state = SFP_ST_DDM_POLL; + return; + } + + id2 = sfp_phy_read(sc, MDIO_MMD_PMAPMD, MDIO_DEVID2); + if (id2 < 0 || id2 == 0xFFFF) { + device_printf(sc->sc_dev, + "SFP+ PHY: DEVID1=0x%04x but DEVID2 read failed\n", + id1 & 0xFFFF); + sc->sc_phy_proto = 0; + sc->sc_has_phy = false; + sc->sc_state = SFP_ST_DDM_POLL; + return; + } + + phy_id = ((uint32_t)id1 << 16) | id2; + + device_printf(sc->sc_dev, + "SFP+ PHY detected via %s: ID %08x " + "(OUI %06x model %02x rev %01x)\n", + sc->sc_phy_proto == SFP_PHY_ROLLBALL ? "RollBall" : "I2C-MDIO", + phy_id, + (id1 << 6) | (id2 >> 10), + (id2 >> 4) & 0x3F, + id2 & 0x0F); + + extable = sfp_phy_read(sc, MDIO_MMD_PMAPMD, MDIO_PMA_EXTABLE); + if (extable >= 0) { + device_printf(sc->sc_dev, + "SFP+ PHY abilities: %s%s%s\n", + (extable & MDIO_PMA_EXTABLE_10GBT) ? "10GBASE-T " : "", + (extable & MDIO_PMA_EXTABLE_1000BT) ? "1000BASE-T " : "", + (extable & MDIO_PMA_EXTABLE_NBT) ? "NBASE-T" : ""); + } + + sc->sc_phy_id = phy_id; + sc->sc_has_phy = true; + sc->sc_phy_link = false; + sc->sc_phy_speed = 0; + + sfp_phy_config_aneg(sc); + + sc->sc_state = SFP_ST_PHY_AN; +} + +/* PHY_AN: poll PHY link status */ +static void +sfp_fdt_sm_phy_poll(struct sfp_fdt_softc *sc) +{ + int stat, speed; + bool link_up; + + if (!sc->sc_has_phy) + return; + + stat = sfp_phy_read(sc, MDIO_MMD_PMAPMD, MDIO_STAT1); + if (stat < 0) + return; + + link_up = (stat & MDIO_STAT1_LSTATUS) != 0; + + if (link_up != sc->sc_phy_link) { + sc->sc_phy_link = link_up; + + if (link_up) { + speed = sfp_phy_read_speed(sc); + sc->sc_phy_speed = speed; + if (speed > 0) + device_printf(sc->sc_dev, + "SFP+ PHY: link up at %d Mbps\n", speed); + else + device_printf(sc->sc_dev, + "SFP+ PHY: link up (speed unknown)\n"); + sfp_fdt_notify_link_up(sc, speed); + sc->sc_state = SFP_ST_LINK_UP; + } else { + sc->sc_phy_speed = 0; + device_printf(sc->sc_dev, "SFP+ PHY: link down\n"); + sfp_fdt_notify_link_down(sc); + } + } + + /* Keep polling for speed if link up but speed not yet known */ + if (link_up && sc->sc_phy_speed == 0) { + speed = sfp_phy_read_speed(sc); + if (speed > 0) { + sc->sc_phy_speed = speed; + device_printf(sc->sc_dev, + "SFP+ PHY: negotiated %d Mbps\n", speed); + } + } +} + +/* DDM_POLL: poll DDM RX_LOS for copper modules without PHY */ +static void +sfp_fdt_sm_ddm_poll(struct sfp_fdt_softc *sc) +{ + uint8_t ddm_status; + int error; + bool link_up; + + /* Read DDM status byte (A2h offset 0x6E, bit 1 = RX_LOS) */ + error = sfp_fdt_i2c_read(sc, SFP_DIAG_ADDR, 0x6E, + &ddm_status, 1); + if (error != 0) + return; + + link_up = (ddm_status & 0x02) == 0; + + if (link_up && sc->sc_state == SFP_ST_DDM_POLL) { + device_printf(sc->sc_dev, "SFP+ DDM: link up\n"); + sfp_fdt_notify_link_up(sc, 0); + sc->sc_state = SFP_ST_LINK_UP; + } +} + +/* WAIT_LOS: poll LOS GPIO for fiber/DAC modules */ +static void +sfp_fdt_sm_wait_los(struct sfp_fdt_softc *sc) +{ + bool los; + + if (sc->sc_los != NULL) { + gpio_pin_is_active(sc->sc_los, &los); + if (!los) { + /* LOS clear = signal present = link up */ + sc->sc_los_prev = false; + device_printf(sc->sc_dev, "SFP+ fiber: link up\n"); + sfp_fdt_notify_link_up(sc, 0); + sc->sc_state = SFP_ST_LINK_UP; + } + } else { + /* No LOS GPIO — assume link up when module present */ + sfp_fdt_notify_link_up(sc, 0); + sc->sc_state = SFP_ST_LINK_UP; + } +} + +/* LINK_UP: monitor for link loss */ +static void +sfp_fdt_sm_link_up(struct sfp_fdt_softc *sc) +{ + + if (sc->sc_has_phy) { + /* PHY-based: check PMA/PMD link status */ + int stat = sfp_phy_read(sc, MDIO_MMD_PMAPMD, MDIO_STAT1); + if (stat >= 0 && !(stat & MDIO_STAT1_LSTATUS)) { + sc->sc_phy_link = false; + sc->sc_phy_speed = 0; + device_printf(sc->sc_dev, "SFP+ PHY: link down\n"); + sfp_fdt_notify_link_down(sc); + sc->sc_state = SFP_ST_PHY_AN; + } else if (stat >= 0 && sc->sc_phy_speed == 0) { + /* Link up but speed unknown — keep trying */ + int speed = sfp_phy_read_speed(sc); + if (speed > 0) { + sc->sc_phy_speed = speed; + device_printf(sc->sc_dev, + "SFP+ PHY: negotiated %d Mbps\n", speed); + } + } + } else if (sc->sc_connector == SFP_CONNECTOR_RJ45) { + /* DDM-based copper: check RX_LOS */ + uint8_t ddm_status; + int error = sfp_fdt_i2c_read(sc, SFP_DIAG_ADDR, 0x6E, + &ddm_status, 1); + if (error == 0 && (ddm_status & 0x02)) { + device_printf(sc->sc_dev, "SFP+ DDM: link down\n"); + sfp_fdt_notify_link_down(sc); + sc->sc_state = SFP_ST_DDM_POLL; + } + } else if (sc->sc_los != NULL) { + /* Fiber/DAC: check LOS GPIO */ + bool los; + gpio_pin_is_active(sc->sc_los, &los); + if (los && !sc->sc_los_prev) { + sc->sc_los_prev = true; + device_printf(sc->sc_dev, "SFP+ fiber: link down\n"); + sfp_fdt_notify_link_down(sc); + sc->sc_state = SFP_ST_WAIT_LOS; + } else if (!los && sc->sc_los_prev) { + sc->sc_los_prev = false; + } + } +} + +/* Module removal — reset all state */ +static void +sfp_fdt_sm_remove(struct sfp_fdt_softc *sc) +{ + int prev_state; + + prev_state = sc->sc_state; + + /* Assert TX disable */ + if (sc->sc_txdis != NULL) + gpio_pin_set_active(sc->sc_txdis, true); + + /* Notify upstream if we had gotten past EEPROM read */ + if (prev_state >= SFP_ST_PRESENT) + sfp_fdt_notify_remove(sc); + + /* Notify link down if we were up */ + if (prev_state == SFP_ST_LINK_UP) + sfp_fdt_notify_link_down(sc); + + /* Reset state */ + sc->sc_state = SFP_ST_EMPTY; + sc->sc_connector = 0; + sc->sc_has_phy = false; + sc->sc_phy_proto = 0; + sc->sc_phy_id = 0; + sc->sc_phy_link = false; + sc->sc_phy_speed = 0; + sc->sc_los_prev = true; + memset(sc->sc_id, 0, sizeof(sc->sc_id)); + + device_printf(sc->sc_dev, "SFP+ module removed\n"); +} + +/* + * ============================================================ + * State machine task — runs in taskqueue_thread (sleepable) + * ============================================================ + */ + +static void +sfp_fdt_sm_task(void *arg, int pending) +{ + struct sfp_fdt_softc *sc = arg; + bool present; + + if (sc->sc_moddef0 == NULL) + return; + + /* Check module presence */ + gpio_pin_is_active(sc->sc_moddef0, &present); + + /* Handle removal from any state */ + if (!present && sc->sc_state != SFP_ST_EMPTY) { + sfp_fdt_sm_remove(sc); + return; + } + + switch (sc->sc_state) { + case SFP_ST_EMPTY: + if (present) + sfp_fdt_sm_insert(sc); + break; + case SFP_ST_PROBE: + sfp_fdt_sm_probe(sc); + break; + case SFP_ST_PRESENT: + sfp_fdt_sm_present(sc); + break; + case SFP_ST_PHY_PROBE: + sfp_fdt_sm_phy_probe(sc); + break; + case SFP_ST_PHY_AN: + sfp_fdt_sm_phy_poll(sc); + break; + case SFP_ST_DDM_POLL: + sfp_fdt_sm_ddm_poll(sc); + break; + case SFP_ST_WAIT_LOS: + sfp_fdt_sm_wait_los(sc); + break; + case SFP_ST_LINK_UP: + sfp_fdt_sm_link_up(sc); + break; + } +} + +/* + * 1Hz callout — enqueues state machine task to taskqueue_thread + * so all I2C and GPIO work happens in sleepable context. + */ +static void +sfp_fdt_poll_callout(void *arg) +{ + struct sfp_fdt_softc *sc = arg; + + taskqueue_enqueue(taskqueue_thread, &sc->sc_sm_task); + callout_reset(&sc->sc_poll, hz, sfp_fdt_poll_callout, sc); +} + +/* + * ============================================================ + * Device methods + * ============================================================ + */ + static int sfp_fdt_probe(device_t dev) { @@ -65,11 +1105,8 @@ sfp_fdt_probe(device_t dev) s = device_get_property(dev, "i2c-bus", &node, sizeof(node), DEVICE_PROP_HANDLE); - if (s == -1) { - device_printf(dev, "%s: '%s' has no 'i2c-bus' property, s %zd\n", - __func__, ofw_bus_get_name(dev), s); + if (s == -1) return (ENXIO); - } device_set_desc(dev, "Small Form-factor Pluggable Transceiver"); return (BUS_PROBE_DEFAULT); @@ -79,58 +1116,123 @@ static int sfp_fdt_attach(device_t dev) { struct sfp_fdt_softc *sc; + device_t xdev; ssize_t s; int error; sc = device_get_softc(dev); - sc->ofw_node = ofw_bus_get_node(dev); + sc->sc_dev = dev; + sc->sc_node = ofw_bus_get_node(dev); + sc->sc_state = SFP_ST_EMPTY; - s = device_get_property(dev, "i2c-bus", &sc->i2c_bus, - sizeof(sc->i2c_bus), DEVICE_PROP_HANDLE); + /* Get I2C bus phandle (resolved lazily on first use) */ + s = device_get_property(dev, "i2c-bus", &sc->sc_i2c_phandle, + sizeof(sc->sc_i2c_phandle), DEVICE_PROP_HANDLE); if (s == -1) { - device_printf(dev, "%s: cannot find 'i2c-bus' property: %zd\n", - __func__, s); + device_printf(dev, "cannot find 'i2c-bus' property\n"); return (ENXIO); } - /* Optional properties */ - (void)device_get_property(dev, "mod-def0-gpios", &sc->mod_def, - sizeof(sc->mod_def), DEVICE_PROP_HANDLE); - (void)device_get_property(dev, "los-gpios", &sc->los, sizeof(sc->los), - DEVICE_PROP_HANDLE); - (void)device_get_property(dev, "tx-fault-gpios", &sc->tx_fault, - sizeof(sc->tx_fault), DEVICE_PROP_HANDLE); - (void)device_get_property(dev, "tx-disable-gpios", &sc->tx_disable, - sizeof(sc->tx_disable), DEVICE_PROP_HANDLE); - (void)device_get_property(dev, "rate-select0-gpios", &sc->rx_rate, - sizeof(sc->rx_rate), DEVICE_PROP_HANDLE); - (void)device_get_property(dev, "rate-select1-gpios", &sc->tx_rate, - sizeof(sc->tx_rate), DEVICE_PROP_HANDLE); - (void)device_get_property(dev, "maximum-power-milliwatt", &sc->max_power, - sizeof(sc->max_power), DEVICE_PROP_UINT32); + /* Register xref FIRST so MAC drivers can find us even if + * I2C/GPIO aren't ready yet (they may attach later) */ + error = OF_device_register_xref(OF_xref_from_node(sc->sc_node), dev); + if (error != 0) { + device_printf(dev, "failed to register xref\n"); + return (error); + } - error = OF_device_register_xref(OF_xref_from_node(sc->ofw_node), dev); - if (error != 0) - device_printf(dev, "%s: failed to register xref %#x\n", - __func__, OF_xref_from_node(sc->ofw_node)); + /* Try to resolve I2C bus now; if not ready, resolve lazily */ + xdev = OF_device_from_xref(OF_xref_from_node(sc->sc_i2c_phandle)); + if (xdev != NULL) + sc->sc_i2c = xdev; - return (error); + /* Acquire GPIOs from DT (all optional) */ + gpio_pin_get_by_ofw_property(dev, sc->sc_node, + "mod-def0-gpios", &sc->sc_moddef0); + gpio_pin_get_by_ofw_property(dev, sc->sc_node, + "los-gpios", &sc->sc_los); + gpio_pin_get_by_ofw_property(dev, sc->sc_node, + "tx-disable-gpios", &sc->sc_txdis); + + /* TX disable must be output, initially asserted (no module) */ + if (sc->sc_txdis != NULL) { + gpio_pin_setflags(sc->sc_txdis, GPIO_PIN_OUTPUT); + gpio_pin_set_active(sc->sc_txdis, true); + } + + /* Init mutex, task, and callout */ + mtx_init(&sc->sc_mtx, device_get_nameunit(dev), + "SFP state", MTX_DEF); + TASK_INIT(&sc->sc_sm_task, 0, sfp_fdt_sm_task, sc); + callout_init(&sc->sc_poll, CALLOUT_MPSAFE); + + if (sc->sc_moddef0 != NULL) { + device_printf(dev, "SFP+ cage ready (GPIOs OK), " + "polling started\n"); + /* Start 1Hz poll */ + callout_reset(&sc->sc_poll, hz, sfp_fdt_poll_callout, sc); + } else { + device_printf(dev, "SFP: no mod-def0 GPIO, " + "hot-plug disabled\n"); + } + + return (0); +} + +static int +sfp_fdt_detach(device_t dev) +{ + struct sfp_fdt_softc *sc; + + sc = device_get_softc(dev); + + callout_drain(&sc->sc_poll); + taskqueue_drain(taskqueue_thread, &sc->sc_sm_task); + mtx_destroy(&sc->sc_mtx); + + if (sc->sc_txdis != NULL) + gpio_pin_release(sc->sc_txdis); + if (sc->sc_los != NULL) + gpio_pin_release(sc->sc_los); + if (sc->sc_moddef0 != NULL) + gpio_pin_release(sc->sc_moddef0); + + return (0); } static int sfp_fdt_get_i2c_bus(device_t dev, device_t *i2c_bus) { struct sfp_fdt_softc *sc; - device_t xdev; KASSERT(i2c_bus != NULL, ("%s: i2c_bus is NULL", __func__)); sc = device_get_softc(dev); - xdev = OF_device_from_xref(OF_xref_from_node(sc->i2c_bus)); - if (xdev == NULL) + if (!sfp_fdt_resolve_i2c(sc)) return (ENXIO); - *i2c_bus = xdev; + *i2c_bus = sc->sc_i2c; + return (0); +} + +static int +sfp_fdt_register_upstream(device_t dev, const struct sfp_upstream_ops *ops, + void *arg) +{ + struct sfp_fdt_softc *sc; + + sc = device_get_softc(dev); + + if (sc->sc_upstream_ops != NULL) { + device_printf(dev, "upstream already registered\n"); + return (EBUSY); + } + + sc->sc_upstream_ops = ops; + sc->sc_upstream_arg = arg; + + device_printf(dev, "upstream MAC driver registered\n"); + return (0); } @@ -138,9 +1240,11 @@ static device_method_t sfp_fdt_methods[] = { /* Device interface */ DEVMETHOD(device_probe, sfp_fdt_probe), DEVMETHOD(device_attach, sfp_fdt_attach), + DEVMETHOD(device_detach, sfp_fdt_detach), - /* SFF */ + /* SFF interface */ DEVMETHOD(sff_get_i2c_bus, sfp_fdt_get_i2c_bus), + DEVMETHOD(sff_register_upstream, sfp_fdt_register_upstream), DEVMETHOD_END }; diff --git a/sys/dev/sff/sfp_fdt.h b/sys/dev/sff/sfp_fdt.h new file mode 100644 index 00000000000..ae81257493d --- /dev/null +++ b/sys/dev/sff/sfp_fdt.h @@ -0,0 +1,78 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2026 Mono Technologies Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _SFP_FDT_H_ +#define _SFP_FDT_H_ + +/* + * SFP upstream operations — callbacks from sfp_fdt to MAC driver. + * MAC driver registers these via SFF_REGISTER_UPSTREAM(). + * All callbacks run in taskqueue_thread context (sleepable). + */ +struct sfp_upstream_ops { + /* + * Module inserted. Called after EEPROM read succeeds. + * id points to 64-byte SFP EEPROM A0h base ID data. + * Return 0 to accept, non-zero to reject the module. + */ + int (*module_insert)(void *arg, const uint8_t *id, int id_len); + + /* + * Module removed. Clean up any per-module state. + */ + void (*module_remove)(void *arg); + + /* + * Link came up. speed is in Mbps (10000, 5000, 2500, 1000). + * For fiber/DAC modules speed is 0 (unknown/fixed). + */ + void (*link_up)(void *arg, int speed); + + /* + * Link went down. + */ + void (*link_down)(void *arg); +}; + +/* SFF-8024 connector types */ +#define SFP_CONNECTOR_LC 0x07 +#define SFP_CONNECTOR_RJ45 0x22 + +/* SFF-8472 EEPROM A0h field offsets */ +#define SFP_ID_OFFSET 0 +#define SFP_CONNECTOR_OFFSET 2 +#define SFP_VENDOR_OFFSET 20 +#define SFP_VENDOR_LEN 16 +#define SFP_PARTNUM_OFFSET 40 +#define SFP_PARTNUM_LEN 16 + +/* I2C addresses */ +#define SFP_EEPROM_ADDR 0x50 /* EEPROM A0h page (7-bit) */ +#define SFP_DIAG_ADDR 0x51 /* A2h / RollBall (7-bit) */ +#define SFP_PHY_ADDR 0x56 /* Standard I2C-MDIO (7-bit) */ + +#endif /* _SFP_FDT_H_ */ diff --git a/sys/modules/sff/Makefile b/sys/modules/sff/Makefile index 96832070de6..dd05a7ea0b1 100644 --- a/sys/modules/sff/Makefile +++ b/sys/modules/sff/Makefile @@ -6,8 +6,9 @@ SRCS+= sff_if.c sff_if.h SRCS+= bus_if.h device_if.h .if !empty(OPT_FDT) -SRCS+= sfp_fdt.c \ - ofw_bus_if.h +SRCS+= sfp_fdt.c sfp_fdt.h \ + ofw_bus_if.h \ + gpio_if.h iicbus_if.h .endif .include