Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-phy-fixed_phy-improvements'

Heiner Kallweit says:

====================
net: phy: fixed_phy: improvements

This series contains a number of improvements.
No functional change intended.
====================

Link: https://patch.msgid.link/e81be066-cc23-4055-aed7-2fbc86da1ff7@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+61 -76
+61 -76
drivers/net/phy/fixed_phy.c
··· 23 23 24 24 #include "swphy.h" 25 25 26 - struct fixed_mdio_bus { 27 - struct mii_bus *mii_bus; 28 - struct list_head phys; 29 - }; 30 - 31 26 struct fixed_phy { 32 27 int addr; 33 28 struct phy_device *phydev; 34 29 struct fixed_phy_status status; 35 - bool no_carrier; 36 30 int (*link_update)(struct net_device *, struct fixed_phy_status *); 37 31 struct list_head node; 38 32 }; 39 33 40 - static struct fixed_mdio_bus platform_fmb = { 41 - .phys = LIST_HEAD_INIT(platform_fmb.phys), 42 - }; 34 + static struct mii_bus *fmb_mii_bus; 35 + static LIST_HEAD(fmb_phys); 36 + 37 + static struct fixed_phy *fixed_phy_find(int addr) 38 + { 39 + struct fixed_phy *fp; 40 + 41 + list_for_each_entry(fp, &fmb_phys, node) { 42 + if (fp->addr == addr) 43 + return fp; 44 + } 45 + 46 + return NULL; 47 + } 43 48 44 49 int fixed_phy_change_carrier(struct net_device *dev, bool new_carrier) 45 50 { 46 - struct fixed_mdio_bus *fmb = &platform_fmb; 47 51 struct phy_device *phydev = dev->phydev; 48 52 struct fixed_phy *fp; 49 53 50 54 if (!phydev || !phydev->mdio.bus) 51 55 return -EINVAL; 52 56 53 - list_for_each_entry(fp, &fmb->phys, node) { 54 - if (fp->addr == phydev->mdio.addr) { 55 - fp->no_carrier = !new_carrier; 56 - return 0; 57 - } 58 - } 59 - return -EINVAL; 57 + fp = fixed_phy_find(phydev->mdio.addr); 58 + if (!fp) 59 + return -EINVAL; 60 + 61 + fp->status.link = new_carrier; 62 + 63 + return 0; 60 64 } 61 65 EXPORT_SYMBOL_GPL(fixed_phy_change_carrier); 62 66 63 67 static int fixed_mdio_read(struct mii_bus *bus, int phy_addr, int reg_num) 64 68 { 65 - struct fixed_mdio_bus *fmb = bus->priv; 66 69 struct fixed_phy *fp; 67 70 68 - list_for_each_entry(fp, &fmb->phys, node) { 69 - if (fp->addr == phy_addr) { 70 - fp->status.link = !fp->no_carrier; 71 + fp = fixed_phy_find(phy_addr); 72 + if (!fp) 73 + return 0xffff; 71 74 72 - /* Issue callback if user registered it. */ 73 - if (fp->link_update) 74 - fp->link_update(fp->phydev->attached_dev, 75 - &fp->status); 75 + if (fp->link_update) 76 + fp->link_update(fp->phydev->attached_dev, &fp->status); 76 77 77 - return swphy_read_reg(reg_num, &fp->status); 78 - } 79 - } 80 - 81 - return 0xFFFF; 78 + return swphy_read_reg(reg_num, &fp->status); 82 79 } 83 80 84 81 static int fixed_mdio_write(struct mii_bus *bus, int phy_addr, int reg_num, ··· 93 96 int (*link_update)(struct net_device *, 94 97 struct fixed_phy_status *)) 95 98 { 96 - struct fixed_mdio_bus *fmb = &platform_fmb; 97 99 struct fixed_phy *fp; 98 100 99 101 if (!phydev || !phydev->mdio.bus) 100 102 return -EINVAL; 101 103 102 - list_for_each_entry(fp, &fmb->phys, node) { 103 - if (fp->addr == phydev->mdio.addr) { 104 - fp->link_update = link_update; 105 - fp->phydev = phydev; 106 - return 0; 107 - } 108 - } 104 + fp = fixed_phy_find(phydev->mdio.addr); 105 + if (!fp) 106 + return -ENOENT; 109 107 110 - return -ENOENT; 108 + fp->link_update = link_update; 109 + fp->phydev = phydev; 110 + 111 + return 0; 111 112 } 112 113 EXPORT_SYMBOL_GPL(fixed_phy_set_link_update); 113 114 114 - static int __fixed_phy_add(unsigned int irq, int phy_addr, 115 + static int __fixed_phy_add(int phy_addr, 115 116 const struct fixed_phy_status *status) 116 117 { 117 - int ret; 118 - struct fixed_mdio_bus *fmb = &platform_fmb; 119 118 struct fixed_phy *fp; 119 + int ret; 120 120 121 121 ret = swphy_validate_state(status); 122 122 if (ret < 0) ··· 123 129 if (!fp) 124 130 return -ENOMEM; 125 131 126 - if (irq != PHY_POLL) 127 - fmb->mii_bus->irq[phy_addr] = irq; 128 - 129 132 fp->addr = phy_addr; 130 133 fp->status = *status; 131 134 132 - list_add_tail(&fp->node, &fmb->phys); 135 + list_add_tail(&fp->node, &fmb_phys); 133 136 134 137 return 0; 135 138 } 136 139 137 140 void fixed_phy_add(const struct fixed_phy_status *status) 138 141 { 139 - __fixed_phy_add(PHY_POLL, 0, status); 142 + __fixed_phy_add(0, status); 140 143 } 141 144 EXPORT_SYMBOL_GPL(fixed_phy_add); 142 145 ··· 141 150 142 151 static void fixed_phy_del(int phy_addr) 143 152 { 144 - struct fixed_mdio_bus *fmb = &platform_fmb; 145 - struct fixed_phy *fp, *tmp; 153 + struct fixed_phy *fp; 146 154 147 - list_for_each_entry_safe(fp, tmp, &fmb->phys, node) { 148 - if (fp->addr == phy_addr) { 149 - list_del(&fp->node); 150 - kfree(fp); 151 - ida_free(&phy_fixed_ida, phy_addr); 152 - return; 153 - } 154 - } 155 + fp = fixed_phy_find(phy_addr); 156 + if (!fp) 157 + return; 158 + 159 + list_del(&fp->node); 160 + kfree(fp); 161 + ida_free(&phy_fixed_ida, phy_addr); 155 162 } 156 163 157 164 struct phy_device *fixed_phy_register(const struct fixed_phy_status *status, 158 165 struct device_node *np) 159 166 { 160 - struct fixed_mdio_bus *fmb = &platform_fmb; 161 167 struct phy_device *phy; 162 168 int phy_addr; 163 169 int ret; 164 170 165 - if (!fmb->mii_bus || fmb->mii_bus->state != MDIOBUS_REGISTERED) 171 + if (!fmb_mii_bus || fmb_mii_bus->state != MDIOBUS_REGISTERED) 166 172 return ERR_PTR(-EPROBE_DEFER); 167 173 168 174 /* Get the next available PHY address, up to PHY_MAX_ADDR */ ··· 167 179 if (phy_addr < 0) 168 180 return ERR_PTR(phy_addr); 169 181 170 - ret = __fixed_phy_add(PHY_POLL, phy_addr, status); 182 + ret = __fixed_phy_add(phy_addr, status); 171 183 if (ret < 0) { 172 184 ida_free(&phy_fixed_ida, phy_addr); 173 185 return ERR_PTR(ret); 174 186 } 175 187 176 - phy = get_phy_device(fmb->mii_bus, phy_addr, false); 188 + phy = get_phy_device(fmb_mii_bus, phy_addr, false); 177 189 if (IS_ERR(phy)) { 178 190 fixed_phy_del(phy_addr); 179 191 return ERR_PTR(-EINVAL); ··· 238 250 239 251 static int __init fixed_mdio_bus_init(void) 240 252 { 241 - struct fixed_mdio_bus *fmb = &platform_fmb; 242 253 int ret; 243 254 244 - fmb->mii_bus = mdiobus_alloc(); 245 - if (!fmb->mii_bus) 255 + fmb_mii_bus = mdiobus_alloc(); 256 + if (!fmb_mii_bus) 246 257 return -ENOMEM; 247 258 248 - snprintf(fmb->mii_bus->id, MII_BUS_ID_SIZE, "fixed-0"); 249 - fmb->mii_bus->name = "Fixed MDIO Bus"; 250 - fmb->mii_bus->priv = fmb; 251 - fmb->mii_bus->read = &fixed_mdio_read; 252 - fmb->mii_bus->write = &fixed_mdio_write; 253 - fmb->mii_bus->phy_mask = ~0; 259 + snprintf(fmb_mii_bus->id, MII_BUS_ID_SIZE, "fixed-0"); 260 + fmb_mii_bus->name = "Fixed MDIO Bus"; 261 + fmb_mii_bus->read = &fixed_mdio_read; 262 + fmb_mii_bus->write = &fixed_mdio_write; 263 + fmb_mii_bus->phy_mask = ~0; 254 264 255 - ret = mdiobus_register(fmb->mii_bus); 265 + ret = mdiobus_register(fmb_mii_bus); 256 266 if (ret) 257 267 goto err_mdiobus_alloc; 258 268 259 269 return 0; 260 270 261 271 err_mdiobus_alloc: 262 - mdiobus_free(fmb->mii_bus); 272 + mdiobus_free(fmb_mii_bus); 263 273 return ret; 264 274 } 265 275 module_init(fixed_mdio_bus_init); 266 276 267 277 static void __exit fixed_mdio_bus_exit(void) 268 278 { 269 - struct fixed_mdio_bus *fmb = &platform_fmb; 270 279 struct fixed_phy *fp, *tmp; 271 280 272 - mdiobus_unregister(fmb->mii_bus); 273 - mdiobus_free(fmb->mii_bus); 281 + mdiobus_unregister(fmb_mii_bus); 282 + mdiobus_free(fmb_mii_bus); 274 283 275 - list_for_each_entry_safe(fp, tmp, &fmb->phys, node) { 284 + list_for_each_entry_safe(fp, tmp, &fmb_phys, node) { 276 285 list_del(&fp->node); 277 286 kfree(fp); 278 287 }