Skip to content

Commit

Permalink
phylib: Support registering a bunch of drivers
Browse files Browse the repository at this point in the history
If registering of one of them fails, all already registered drivers
of this module will be unregistered.

Use the new register/unregister functions in all drivers
registering more than one driver.

amd.c, realtek.c: Simplify: directly return registration result.

Tested with broadcom.c
All others compile-tested.

Signed-off-by: Christian Hohnstaedt <chohnstaedt@innominate.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Christian Hohnstaedt authored and David S. Miller committed Jul 9, 2012
1 parent 567990c commit d5bf907
Show file tree
Hide file tree
Showing 16 changed files with 159 additions and 431 deletions.
8 changes: 1 addition & 7 deletions drivers/net/phy/amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,7 @@ static struct phy_driver am79c_driver = {

static int __init am79c_init(void)
{
int ret;

ret = phy_driver_register(&am79c_driver);
if (ret)
return ret;

return 0;
return phy_driver_register(&am79c_driver);
}

static void __exit am79c_exit(void)
Expand Down
31 changes: 9 additions & 22 deletions drivers/net/phy/bcm63xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ static int bcm63xx_config_intr(struct phy_device *phydev)
return err;
}

static struct phy_driver bcm63xx_1_driver = {
static struct phy_driver bcm63xx_driver[] = {
{
.phy_id = 0x00406000,
.phy_id_mask = 0xfffffc00,
.name = "Broadcom BCM63XX (1)",
Expand All @@ -84,10 +85,8 @@ static struct phy_driver bcm63xx_1_driver = {
.ack_interrupt = bcm63xx_ack_interrupt,
.config_intr = bcm63xx_config_intr,
.driver = { .owner = THIS_MODULE },
};

/* same phy as above, with just a different OUI */
static struct phy_driver bcm63xx_2_driver = {
}, {
/* same phy as above, with just a different OUI */
.phy_id = 0x002bdc00,
.phy_id_mask = 0xfffffc00,
.name = "Broadcom BCM63XX (2)",
Expand All @@ -99,30 +98,18 @@ static struct phy_driver bcm63xx_2_driver = {
.ack_interrupt = bcm63xx_ack_interrupt,
.config_intr = bcm63xx_config_intr,
.driver = { .owner = THIS_MODULE },
};
} };

static int __init bcm63xx_phy_init(void)
{
int ret;

ret = phy_driver_register(&bcm63xx_1_driver);
if (ret)
goto out_63xx_1;
ret = phy_driver_register(&bcm63xx_2_driver);
if (ret)
goto out_63xx_2;
return ret;

out_63xx_2:
phy_driver_unregister(&bcm63xx_1_driver);
out_63xx_1:
return ret;
return phy_drivers_register(bcm63xx_driver,
ARRAY_SIZE(bcm63xx_driver));
}

static void __exit bcm63xx_phy_exit(void)
{
phy_driver_unregister(&bcm63xx_1_driver);
phy_driver_unregister(&bcm63xx_2_driver);
phy_drivers_unregister(bcm63xx_driver,
ARRAY_SIZE(bcm63xx_driver));
}

module_init(bcm63xx_phy_init);
Expand Down
24 changes: 8 additions & 16 deletions drivers/net/phy/bcm87xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ static int bcm8727_match_phy_device(struct phy_device *phydev)
return phydev->c45_ids.device_ids[4] == PHY_ID_BCM8727;
}

static struct phy_driver bcm8706_driver = {
static struct phy_driver bcm87xx_driver[] = {
{
.phy_id = PHY_ID_BCM8706,
.phy_id_mask = 0xffffffff,
.name = "Broadcom BCM8706",
Expand All @@ -200,9 +201,7 @@ static struct phy_driver bcm8706_driver = {
.did_interrupt = bcm87xx_did_interrupt,
.match_phy_device = bcm8706_match_phy_device,
.driver = { .owner = THIS_MODULE },
};

static struct phy_driver bcm8727_driver = {
}, {
.phy_id = PHY_ID_BCM8727,
.phy_id_mask = 0xffffffff,
.name = "Broadcom BCM8727",
Expand All @@ -215,25 +214,18 @@ static struct phy_driver bcm8727_driver = {
.did_interrupt = bcm87xx_did_interrupt,
.match_phy_device = bcm8727_match_phy_device,
.driver = { .owner = THIS_MODULE },
};
} };

static int __init bcm87xx_init(void)
{
int ret;

ret = phy_driver_register(&bcm8706_driver);
if (ret)
goto err;

ret = phy_driver_register(&bcm8727_driver);
err:
return ret;
return phy_drivers_register(bcm87xx_driver,
ARRAY_SIZE(bcm87xx_driver));
}
module_init(bcm87xx_init);

static void __exit bcm87xx_exit(void)
{
phy_driver_unregister(&bcm8706_driver);
phy_driver_unregister(&bcm8727_driver);
phy_drivers_unregister(bcm87xx_driver,
ARRAY_SIZE(bcm87xx_driver));
}
module_exit(bcm87xx_exit);
119 changes: 17 additions & 102 deletions drivers/net/phy/broadcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,8 @@ static int brcm_fet_config_intr(struct phy_device *phydev)
return err;
}

static struct phy_driver bcm5411_driver = {
static struct phy_driver broadcom_drivers[] = {
{
.phy_id = PHY_ID_BCM5411,
.phy_id_mask = 0xfffffff0,
.name = "Broadcom BCM5411",
Expand All @@ -695,9 +696,7 @@ static struct phy_driver bcm5411_driver = {
.ack_interrupt = bcm54xx_ack_interrupt,
.config_intr = bcm54xx_config_intr,
.driver = { .owner = THIS_MODULE },
};

static struct phy_driver bcm5421_driver = {
}, {
.phy_id = PHY_ID_BCM5421,
.phy_id_mask = 0xfffffff0,
.name = "Broadcom BCM5421",
Expand All @@ -710,9 +709,7 @@ static struct phy_driver bcm5421_driver = {
.ack_interrupt = bcm54xx_ack_interrupt,
.config_intr = bcm54xx_config_intr,
.driver = { .owner = THIS_MODULE },
};

static struct phy_driver bcm5461_driver = {
}, {
.phy_id = PHY_ID_BCM5461,
.phy_id_mask = 0xfffffff0,
.name = "Broadcom BCM5461",
Expand All @@ -725,9 +722,7 @@ static struct phy_driver bcm5461_driver = {
.ack_interrupt = bcm54xx_ack_interrupt,
.config_intr = bcm54xx_config_intr,
.driver = { .owner = THIS_MODULE },
};

static struct phy_driver bcm5464_driver = {
}, {
.phy_id = PHY_ID_BCM5464,
.phy_id_mask = 0xfffffff0,
.name = "Broadcom BCM5464",
Expand All @@ -740,9 +735,7 @@ static struct phy_driver bcm5464_driver = {
.ack_interrupt = bcm54xx_ack_interrupt,
.config_intr = bcm54xx_config_intr,
.driver = { .owner = THIS_MODULE },
};

static struct phy_driver bcm5481_driver = {
}, {
.phy_id = PHY_ID_BCM5481,
.phy_id_mask = 0xfffffff0,
.name = "Broadcom BCM5481",
Expand All @@ -755,9 +748,7 @@ static struct phy_driver bcm5481_driver = {
.ack_interrupt = bcm54xx_ack_interrupt,
.config_intr = bcm54xx_config_intr,
.driver = { .owner = THIS_MODULE },
};

static struct phy_driver bcm5482_driver = {
}, {
.phy_id = PHY_ID_BCM5482,
.phy_id_mask = 0xfffffff0,
.name = "Broadcom BCM5482",
Expand All @@ -770,9 +761,7 @@ static struct phy_driver bcm5482_driver = {
.ack_interrupt = bcm54xx_ack_interrupt,
.config_intr = bcm54xx_config_intr,
.driver = { .owner = THIS_MODULE },
};

static struct phy_driver bcm50610_driver = {
}, {
.phy_id = PHY_ID_BCM50610,
.phy_id_mask = 0xfffffff0,
.name = "Broadcom BCM50610",
Expand All @@ -785,9 +774,7 @@ static struct phy_driver bcm50610_driver = {
.ack_interrupt = bcm54xx_ack_interrupt,
.config_intr = bcm54xx_config_intr,
.driver = { .owner = THIS_MODULE },
};

static struct phy_driver bcm50610m_driver = {
}, {
.phy_id = PHY_ID_BCM50610M,
.phy_id_mask = 0xfffffff0,
.name = "Broadcom BCM50610M",
Expand All @@ -800,9 +787,7 @@ static struct phy_driver bcm50610m_driver = {
.ack_interrupt = bcm54xx_ack_interrupt,
.config_intr = bcm54xx_config_intr,
.driver = { .owner = THIS_MODULE },
};

static struct phy_driver bcm57780_driver = {
}, {
.phy_id = PHY_ID_BCM57780,
.phy_id_mask = 0xfffffff0,
.name = "Broadcom BCM57780",
Expand All @@ -815,9 +800,7 @@ static struct phy_driver bcm57780_driver = {
.ack_interrupt = bcm54xx_ack_interrupt,
.config_intr = bcm54xx_config_intr,
.driver = { .owner = THIS_MODULE },
};

static struct phy_driver bcmac131_driver = {
}, {
.phy_id = PHY_ID_BCMAC131,
.phy_id_mask = 0xfffffff0,
.name = "Broadcom BCMAC131",
Expand All @@ -830,9 +813,7 @@ static struct phy_driver bcmac131_driver = {
.ack_interrupt = brcm_fet_ack_interrupt,
.config_intr = brcm_fet_config_intr,
.driver = { .owner = THIS_MODULE },
};

static struct phy_driver bcm5241_driver = {
}, {
.phy_id = PHY_ID_BCM5241,
.phy_id_mask = 0xfffffff0,
.name = "Broadcom BCM5241",
Expand All @@ -845,84 +826,18 @@ static struct phy_driver bcm5241_driver = {
.ack_interrupt = brcm_fet_ack_interrupt,
.config_intr = brcm_fet_config_intr,
.driver = { .owner = THIS_MODULE },
};
} };

static int __init broadcom_init(void)
{
int ret;

ret = phy_driver_register(&bcm5411_driver);
if (ret)
goto out_5411;
ret = phy_driver_register(&bcm5421_driver);
if (ret)
goto out_5421;
ret = phy_driver_register(&bcm5461_driver);
if (ret)
goto out_5461;
ret = phy_driver_register(&bcm5464_driver);
if (ret)
goto out_5464;
ret = phy_driver_register(&bcm5481_driver);
if (ret)
goto out_5481;
ret = phy_driver_register(&bcm5482_driver);
if (ret)
goto out_5482;
ret = phy_driver_register(&bcm50610_driver);
if (ret)
goto out_50610;
ret = phy_driver_register(&bcm50610m_driver);
if (ret)
goto out_50610m;
ret = phy_driver_register(&bcm57780_driver);
if (ret)
goto out_57780;
ret = phy_driver_register(&bcmac131_driver);
if (ret)
goto out_ac131;
ret = phy_driver_register(&bcm5241_driver);
if (ret)
goto out_5241;
return ret;

out_5241:
phy_driver_unregister(&bcmac131_driver);
out_ac131:
phy_driver_unregister(&bcm57780_driver);
out_57780:
phy_driver_unregister(&bcm50610m_driver);
out_50610m:
phy_driver_unregister(&bcm50610_driver);
out_50610:
phy_driver_unregister(&bcm5482_driver);
out_5482:
phy_driver_unregister(&bcm5481_driver);
out_5481:
phy_driver_unregister(&bcm5464_driver);
out_5464:
phy_driver_unregister(&bcm5461_driver);
out_5461:
phy_driver_unregister(&bcm5421_driver);
out_5421:
phy_driver_unregister(&bcm5411_driver);
out_5411:
return ret;
return phy_drivers_register(broadcom_drivers,
ARRAY_SIZE(broadcom_drivers));
}

static void __exit broadcom_exit(void)
{
phy_driver_unregister(&bcm5241_driver);
phy_driver_unregister(&bcmac131_driver);
phy_driver_unregister(&bcm57780_driver);
phy_driver_unregister(&bcm50610m_driver);
phy_driver_unregister(&bcm50610_driver);
phy_driver_unregister(&bcm5482_driver);
phy_driver_unregister(&bcm5481_driver);
phy_driver_unregister(&bcm5464_driver);
phy_driver_unregister(&bcm5461_driver);
phy_driver_unregister(&bcm5421_driver);
phy_driver_unregister(&bcm5411_driver);
phy_drivers_unregister(broadcom_drivers,
ARRAY_SIZE(broadcom_drivers));
}

module_init(broadcom_init);
Expand Down
35 changes: 10 additions & 25 deletions drivers/net/phy/cicada.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ static int cis820x_config_intr(struct phy_device *phydev)
}

/* Cicada 8201, a.k.a Vitesse VSC8201 */
static struct phy_driver cis8201_driver = {
static struct phy_driver cis820x_driver[] = {
{
.phy_id = 0x000fc410,
.name = "Cicada Cis8201",
.phy_id_mask = 0x000ffff0,
Expand All @@ -113,11 +114,8 @@ static struct phy_driver cis8201_driver = {
.read_status = &genphy_read_status,
.ack_interrupt = &cis820x_ack_interrupt,
.config_intr = &cis820x_config_intr,
.driver = { .owner = THIS_MODULE,},
};

/* Cicada 8204 */
static struct phy_driver cis8204_driver = {
.driver = { .owner = THIS_MODULE,},
}, {
.phy_id = 0x000fc440,
.name = "Cicada Cis8204",
.phy_id_mask = 0x000fffc0,
Expand All @@ -128,32 +126,19 @@ static struct phy_driver cis8204_driver = {
.read_status = &genphy_read_status,
.ack_interrupt = &cis820x_ack_interrupt,
.config_intr = &cis820x_config_intr,
.driver = { .owner = THIS_MODULE,},
};
.driver = { .owner = THIS_MODULE,},
} };

static int __init cicada_init(void)
{
int ret;

ret = phy_driver_register(&cis8204_driver);
if (ret)
goto err1;

ret = phy_driver_register(&cis8201_driver);
if (ret)
goto err2;
return 0;

err2:
phy_driver_unregister(&cis8204_driver);
err1:
return ret;
return phy_drivers_register(cis820x_driver,
ARRAY_SIZE(cis820x_driver));
}

static void __exit cicada_exit(void)
{
phy_driver_unregister(&cis8204_driver);
phy_driver_unregister(&cis8201_driver);
phy_drivers_unregister(cis820x_driver,
ARRAY_SIZE(cis820x_driver));
}

module_init(cicada_init);
Expand Down
Loading

0 comments on commit d5bf907

Please sign in to comment.