developer | a414be4 | 2023-07-07 11:22:17 +0800 | [diff] [blame] | 1 | From 76314e98504e691f17a5d9d1362d476c534a5e0e Mon Sep 17 00:00:00 2001 |
| 2 | From: Bo-Cun Chen <bc-bocun.chen@mediatek.com> |
| 3 | Date: Fri, 7 Jul 2023 11:14:32 +0800 |
| 4 | Subject: [PATCH] 999-2727-net-phy-sfp-add-debug-info.patch |
| 5 | |
| 6 | --- |
| 7 | drivers/net/phy/phylink.c | 11 +++++++- |
| 8 | drivers/net/phy/sfp-bus.c | 3 +++ |
| 9 | drivers/net/phy/sfp.c | 51 +++++++++++++++++++++++++++++------ |
| 10 | include/linux/mdio/mdio-i2c.h | 16 +++++++++++ |
| 11 | 4 files changed, 72 insertions(+), 9 deletions(-) |
| 12 | |
| 13 | diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c |
| 14 | index 949e3b8..bb4cd28 100644 |
| 15 | --- a/drivers/net/phy/phylink.c |
| 16 | +++ b/drivers/net/phy/phylink.c |
| 17 | @@ -782,6 +782,15 @@ static void phylink_resolve(struct work_struct *w) |
| 18 | &link_state); |
| 19 | } |
| 20 | |
| 21 | + if (pl->phydev && !(link_state.link & pl->phy_state.link)) |
| 22 | + phylink_printk(KERN_DEBUG, pl, |
| 23 | + "resolve link status: system iface=%d, line iface=%d\n", |
| 24 | + link_state.link, pl->phy_state.link); |
| 25 | + else if (!link_state.link) |
| 26 | + phylink_printk(KERN_DEBUG, pl, |
| 27 | + "resolve link status: system iface=%d\n", |
| 28 | + link_state.link); |
| 29 | + |
| 30 | /* If we have a phy, the "up" state is the union of |
| 31 | * both the PHY and the MAC |
| 32 | */ |
| 33 | @@ -2084,7 +2093,7 @@ static int phylink_sfp_config(struct phylink *pl, u8 mode, |
| 34 | return ret; |
| 35 | } |
| 36 | |
| 37 | - phylink_dbg(pl, "requesting link mode %s/%s with support %*pb\n", |
| 38 | + phylink_info(pl, "requesting link mode %s/%s with support %*pb\n", |
| 39 | phylink_an_mode_str(mode), phy_modes(config.interface), |
| 40 | __ETHTOOL_LINK_MODE_MASK_NBITS, support); |
| 41 | |
| 42 | diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c |
| 43 | index 4be2440..bcf45dd 100644 |
| 44 | --- a/drivers/net/phy/sfp-bus.c |
| 45 | +++ b/drivers/net/phy/sfp-bus.c |
| 46 | @@ -279,6 +279,9 @@ void sfp_parse_support(struct sfp_bus *bus, const struct sfp_eeprom_id *id, |
| 47 | if (bus->sfp_quirk && bus->sfp_quirk->modes) |
| 48 | bus->sfp_quirk->modes(id, modes); |
| 49 | |
| 50 | + dev_info(bus->sfp_dev, "sfp: support mode %*pb\n", |
| 51 | + __ETHTOOL_LINK_MODE_MASK_NBITS, modes); |
| 52 | + |
| 53 | bitmap_or(support, support, modes, __ETHTOOL_LINK_MODE_MASK_NBITS); |
| 54 | } |
| 55 | EXPORT_SYMBOL_GPL(sfp_parse_support); |
| 56 | diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c |
| 57 | index 0fdf5d6..0c335b1 100644 |
| 58 | --- a/drivers/net/phy/sfp.c |
| 59 | +++ b/drivers/net/phy/sfp.c |
| 60 | @@ -480,7 +480,7 @@ static bool sfp_match(const char *qs, const char *str, size_t len) |
| 61 | return !strncmp(qs, str, len); |
| 62 | } |
| 63 | |
| 64 | -static const struct sfp_quirk *sfp_lookup_quirk(const struct sfp_eeprom_id *id) |
| 65 | +static const struct sfp_quirk *sfp_lookup_quirk(struct sfp *sfp, const struct sfp_eeprom_id *id) |
| 66 | { |
| 67 | const struct sfp_quirk *q; |
| 68 | unsigned int i; |
| 69 | @@ -493,8 +493,14 @@ static const struct sfp_quirk *sfp_lookup_quirk(const struct sfp_eeprom_id *id) |
| 70 | for (i = 0, q = sfp_quirks; i < ARRAY_SIZE(sfp_quirks); i++, q++) |
| 71 | if (sfp_match(q->vendor, id->base.vendor_name, vs) && |
| 72 | sfp_match(q->part, id->base.vendor_pn, ps) && |
| 73 | - sfp_match(q->revision, id->base.vendor_rev, rs)) |
| 74 | + sfp_match(q->revision, id->base.vendor_rev, rs)) { |
| 75 | + dev_info(sfp->dev, |
| 76 | + "module %.*s %.*s rev %.*s has been found in the quirk list\n", |
| 77 | + (int)sizeof(id->base.vendor_name), id->base.vendor_name, |
| 78 | + (int)sizeof(id->base.vendor_pn), id->base.vendor_pn, |
| 79 | + (int)sizeof(id->base.vendor_rev), id->base.vendor_rev); |
| 80 | return q; |
| 81 | + } |
| 82 | |
| 83 | return NULL; |
| 84 | } |
| 85 | @@ -1597,7 +1603,7 @@ static void sfp_hwmon_exit(struct sfp *sfp) |
| 86 | /* Helpers */ |
| 87 | static void sfp_module_tx_disable(struct sfp *sfp) |
| 88 | { |
| 89 | - dev_dbg(sfp->dev, "tx disable %u -> %u\n", |
| 90 | + dev_info(sfp->dev, "tx disable %u -> %u\n", |
| 91 | sfp->state & SFP_F_TX_DISABLE ? 1 : 0, 1); |
| 92 | sfp->state |= SFP_F_TX_DISABLE; |
| 93 | sfp_set_state(sfp, sfp->state); |
| 94 | @@ -1605,7 +1611,7 @@ static void sfp_module_tx_disable(struct sfp *sfp) |
| 95 | |
| 96 | static void sfp_module_tx_enable(struct sfp *sfp) |
| 97 | { |
| 98 | - dev_dbg(sfp->dev, "tx disable %u -> %u\n", |
| 99 | + dev_info(sfp->dev, "tx disable %u -> %u\n", |
| 100 | sfp->state & SFP_F_TX_DISABLE ? 1 : 0, 0); |
| 101 | sfp->state &= ~SFP_F_TX_DISABLE; |
| 102 | sfp_set_state(sfp, sfp->state); |
| 103 | @@ -1660,7 +1666,8 @@ static void sfp_sm_phy_detach(struct sfp *sfp) |
| 104 | static int sfp_sm_probe_phy(struct sfp *sfp, int addr, bool is_c45) |
| 105 | { |
| 106 | struct phy_device *phy; |
| 107 | - int err; |
| 108 | + int err, i; |
| 109 | + u32 id; |
| 110 | |
| 111 | phy = get_phy_device(sfp->i2c_mii, addr, is_c45); |
| 112 | if (phy == ERR_PTR(-ENODEV)) |
| 113 | @@ -1677,6 +1684,30 @@ static int sfp_sm_probe_phy(struct sfp *sfp, int addr, bool is_c45) |
| 114 | return err; |
| 115 | } |
| 116 | |
| 117 | + if (phy->is_c45) { |
| 118 | + for (i = 0; i < ARRAY_SIZE(phy->c45_ids.device_ids); i++) { |
| 119 | + id = phy->c45_ids.device_ids[i]; |
| 120 | + if (id == 0xffffffff) |
| 121 | + continue; |
| 122 | + |
| 123 | + dev_info(sfp->dev, |
| 124 | + "CL45 PHY device [0x%04x:0x%04x] found!\n", |
| 125 | + (id >> 16) & 0xffff, id & 0xffff); |
| 126 | + } |
| 127 | + } else { |
| 128 | + id = phy->phy_id; |
| 129 | + dev_info(sfp->dev, |
| 130 | + "CL22 PHY device [0x%04x:0x%04x] found!\n", |
| 131 | + (id >> 16) & 0xffff, id & 0xffff); |
| 132 | + } |
| 133 | + |
| 134 | + dev_info(sfp->dev, "CL%s PHY driver [%s] found!\n", |
| 135 | + phy->is_c45 ? "45" : "22", |
| 136 | + phy->drv ? phy->drv->name : "not"); |
| 137 | + |
| 138 | + dev_info(sfp->dev, "phy: support mode %*pb\n", |
| 139 | + __ETHTOOL_LINK_MODE_MASK_NBITS, phy->supported); |
| 140 | + |
| 141 | err = sfp_add_phy(sfp->sfp_bus, phy); |
| 142 | if (err) { |
| 143 | phy_device_remove(phy); |
| 144 | @@ -1779,6 +1810,10 @@ static int sfp_sm_add_mdio_bus(struct sfp *sfp) |
| 145 | static int sfp_sm_probe_for_phy(struct sfp *sfp) |
| 146 | { |
| 147 | int err = 0; |
| 148 | + struct phy_device *phy; |
| 149 | + |
| 150 | + dev_info(sfp->dev, "probing phy device through the [%s] protocol\n", |
| 151 | + mdio_i2c_proto_type(sfp->mdio_protocol)); |
| 152 | |
| 153 | switch (sfp->mdio_protocol) { |
| 154 | case MDIO_I2C_NONE: |
| 155 | @@ -2090,7 +2125,7 @@ static int sfp_sm_mod_probe(struct sfp *sfp, bool report) |
| 156 | else |
| 157 | sfp->mdio_protocol = MDIO_I2C_NONE; |
| 158 | |
| 159 | - sfp->quirk = sfp_lookup_quirk(&id); |
| 160 | + sfp->quirk = sfp_lookup_quirk(sfp, &id); |
| 161 | if (sfp->quirk && sfp->quirk->fixup) |
| 162 | sfp->quirk->fixup(sfp); |
| 163 | |
| 164 | @@ -2419,7 +2454,7 @@ static void sfp_sm_event(struct sfp *sfp, unsigned int event) |
| 165 | { |
| 166 | mutex_lock(&sfp->sm_mutex); |
| 167 | |
| 168 | - dev_dbg(sfp->dev, "SM: enter %s:%s:%s event %s\n", |
| 169 | + dev_info(sfp->dev, "SM: enter %s:%s:%s event %s\n", |
| 170 | mod_state_to_str(sfp->sm_mod_state), |
| 171 | dev_state_to_str(sfp->sm_dev_state), |
| 172 | sm_state_to_str(sfp->sm_state), |
| 173 | @@ -2429,7 +2464,7 @@ static void sfp_sm_event(struct sfp *sfp, unsigned int event) |
| 174 | sfp_sm_module(sfp, event); |
| 175 | sfp_sm_main(sfp, event); |
| 176 | |
| 177 | - dev_dbg(sfp->dev, "SM: exit %s:%s:%s\n", |
| 178 | + dev_info(sfp->dev, "SM: exit %s:%s:%s\n", |
| 179 | mod_state_to_str(sfp->sm_mod_state), |
| 180 | dev_state_to_str(sfp->sm_dev_state), |
| 181 | sm_state_to_str(sfp->sm_state)); |
| 182 | diff --git a/include/linux/mdio/mdio-i2c.h b/include/linux/mdio/mdio-i2c.h |
| 183 | index 1c21140..4bf833d 100644 |
| 184 | --- a/include/linux/mdio/mdio-i2c.h |
| 185 | +++ b/include/linux/mdio/mdio-i2c.h |
| 186 | @@ -18,6 +18,22 @@ enum mdio_i2c_proto { |
| 187 | MDIO_I2C_ROLLBALL, |
| 188 | }; |
| 189 | |
| 190 | +static inline const char *mdio_i2c_proto_type(int type) |
| 191 | +{ |
| 192 | + switch (type) { |
| 193 | + case MDIO_I2C_NONE: |
| 194 | + return "MDIO_I2C_NONE"; |
| 195 | + case MDIO_I2C_MARVELL_C22: |
| 196 | + return "MDIO_I2C_MARVELL_C22"; |
| 197 | + case MDIO_I2C_C45: |
| 198 | + return "MDIO_I2C_C45"; |
| 199 | + case MDIO_I2C_ROLLBALL: |
| 200 | + return "MDIO_I2C_ROLLBALL"; |
| 201 | + default: |
| 202 | + return "UNKNOWN"; |
| 203 | + } |
| 204 | +} |
| 205 | + |
| 206 | struct mii_bus *mdio_i2c_alloc(struct device *parent, struct i2c_adapter *i2c, |
| 207 | enum mdio_i2c_proto protocol); |
| 208 | |
| 209 | -- |
| 210 | 2.18.0 |
| 211 | |