Skip to content

Commit 03b3be0

Browse files
fancerdavem330
authored andcommitted
net: pcs: xpcs: Split up xpcs_create() body to sub-functions
As an initial preparation before adding the fwnode-based DW XPCS device support let's split the xpcs_create() function code up to a set of the small sub-functions. Thus the xpcs_create() implementation will get to look simpler and turn to be more coherent. Further updates will just touch the new sub-functions a bit: add platform-specific device info, add the reference clock getting and enabling. The xpcs_create() method will now contain the next static methods calls: xpcs_create_data() - create the DW XPCS device descriptor, pre-initialize it' fields and increase the mdio device refcount-er; xpcs_init_id() - find XPCS ID instance and save it in the device descriptor; xpcs_init_iface() - find MAC/PCS interface descriptor and perform basic initialization specific to it: soft-reset, disable polling. The update doesn't imply any semantic change but merely makes the code looking simpler and more ready for adding new features support. Note the xpcs_destroy() has been moved to being defined below the xpcs_create_mdiodev() function as the driver now implies having the protagonist-then-antagonist functions definition order. Signed-off-by: Serge Semin <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f37bee9 commit 03b3be0

File tree

1 file changed

+69
-33
lines changed

1 file changed

+69
-33
lines changed

drivers/net/pcs/pcs-xpcs.c

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,72 +1365,99 @@ static const struct phylink_pcs_ops xpcs_phylink_ops = {
13651365
.pcs_link_up = xpcs_link_up,
13661366
};
13671367

1368-
static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev,
1369-
phy_interface_t interface)
1368+
static struct dw_xpcs *xpcs_create_data(struct mdio_device *mdiodev)
13701369
{
13711370
struct dw_xpcs *xpcs;
1372-
u32 xpcs_id;
1373-
int i, ret;
13741371

13751372
xpcs = kzalloc(sizeof(*xpcs), GFP_KERNEL);
13761373
if (!xpcs)
13771374
return ERR_PTR(-ENOMEM);
13781375

13791376
mdio_device_get(mdiodev);
13801377
xpcs->mdiodev = mdiodev;
1378+
xpcs->pcs.ops = &xpcs_phylink_ops;
1379+
xpcs->pcs.neg_mode = true;
1380+
xpcs->pcs.poll = true;
1381+
1382+
return xpcs;
1383+
}
1384+
1385+
static void xpcs_free_data(struct dw_xpcs *xpcs)
1386+
{
1387+
mdio_device_put(xpcs->mdiodev);
1388+
kfree(xpcs);
1389+
}
1390+
1391+
static int xpcs_init_id(struct dw_xpcs *xpcs)
1392+
{
1393+
u32 xpcs_id;
1394+
int i, ret;
13811395

13821396
xpcs_id = xpcs_get_id(xpcs);
13831397

13841398
for (i = 0; i < ARRAY_SIZE(xpcs_id_list); i++) {
13851399
const struct xpcs_id *entry = &xpcs_id_list[i];
1386-
const struct xpcs_compat *compat;
13871400

13881401
if ((xpcs_id & entry->mask) != entry->id)
13891402
continue;
13901403

13911404
xpcs->id = entry;
13921405

1393-
compat = xpcs_find_compat(entry, interface);
1394-
if (!compat) {
1395-
ret = -ENODEV;
1396-
goto out;
1397-
}
1406+
break;
1407+
}
13981408

1399-
ret = xpcs_dev_flag(xpcs);
1400-
if (ret)
1401-
goto out;
1409+
if (!xpcs->id)
1410+
return -ENODEV;
14021411

1403-
xpcs->pcs.ops = &xpcs_phylink_ops;
1404-
xpcs->pcs.neg_mode = true;
1412+
ret = xpcs_dev_flag(xpcs);
1413+
if (ret < 0)
1414+
return ret;
14051415

1406-
if (xpcs->dev_flag != DW_DEV_TXGBE) {
1407-
xpcs->pcs.poll = true;
1416+
return 0;
1417+
}
14081418

1409-
ret = xpcs_soft_reset(xpcs, compat);
1410-
if (ret)
1411-
goto out;
1412-
}
1419+
static int xpcs_init_iface(struct dw_xpcs *xpcs, phy_interface_t interface)
1420+
{
1421+
const struct xpcs_compat *compat;
14131422

1414-
return xpcs;
1423+
compat = xpcs_find_compat(xpcs->id, interface);
1424+
if (!compat)
1425+
return -EINVAL;
1426+
1427+
if (xpcs->dev_flag == DW_DEV_TXGBE) {
1428+
xpcs->pcs.poll = false;
1429+
return 0;
14151430
}
14161431

1417-
ret = -ENODEV;
1432+
return xpcs_soft_reset(xpcs, compat);
1433+
}
1434+
1435+
static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev,
1436+
phy_interface_t interface)
1437+
{
1438+
struct dw_xpcs *xpcs;
1439+
int ret;
1440+
1441+
xpcs = xpcs_create_data(mdiodev);
1442+
if (IS_ERR(xpcs))
1443+
return xpcs;
1444+
1445+
ret = xpcs_init_id(xpcs);
1446+
if (ret)
1447+
goto out;
1448+
1449+
ret = xpcs_init_iface(xpcs, interface);
1450+
if (ret)
1451+
goto out;
1452+
1453+
return xpcs;
14181454

14191455
out:
1420-
mdio_device_put(mdiodev);
1421-
kfree(xpcs);
1456+
xpcs_free_data(xpcs);
14221457

14231458
return ERR_PTR(ret);
14241459
}
14251460

1426-
void xpcs_destroy(struct dw_xpcs *xpcs)
1427-
{
1428-
if (xpcs)
1429-
mdio_device_put(xpcs->mdiodev);
1430-
kfree(xpcs);
1431-
}
1432-
EXPORT_SYMBOL_GPL(xpcs_destroy);
1433-
14341461
struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr,
14351462
phy_interface_t interface)
14361463
{
@@ -1455,5 +1482,14 @@ struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr,
14551482
}
14561483
EXPORT_SYMBOL_GPL(xpcs_create_mdiodev);
14571484

1485+
void xpcs_destroy(struct dw_xpcs *xpcs)
1486+
{
1487+
if (!xpcs)
1488+
return;
1489+
1490+
xpcs_free_data(xpcs);
1491+
}
1492+
EXPORT_SYMBOL_GPL(xpcs_destroy);
1493+
14581494
MODULE_DESCRIPTION("Synopsys DesignWare XPCS library");
14591495
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)