Skip to content

Commit 7fbb1a9

Browse files
ffainellidavem330
authored andcommitted
net: dsa: bcm_sf2: Move setup function at the far end
Re-order the bcm_sf2_sw_setup() function so that it is at the far end of the driver to avoid any kind of forward declarations. Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a468ef4 commit 7fbb1a9

File tree

1 file changed

+119
-119
lines changed

1 file changed

+119
-119
lines changed

drivers/net/dsa/bcm_sf2.c

Lines changed: 119 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,125 +1065,6 @@ static void bcm_sf2_mdio_unregister(struct bcm_sf2_priv *priv)
10651065
of_node_put(priv->master_mii_dn);
10661066
}
10671067

1068-
static int bcm_sf2_sw_setup(struct dsa_switch *ds)
1069-
{
1070-
const char *reg_names[BCM_SF2_REGS_NUM] = BCM_SF2_REGS_NAME;
1071-
struct bcm_sf2_priv *priv = ds_to_priv(ds);
1072-
struct device_node *dn;
1073-
void __iomem **base;
1074-
unsigned int port;
1075-
unsigned int i;
1076-
u32 reg, rev;
1077-
int ret;
1078-
1079-
spin_lock_init(&priv->indir_lock);
1080-
mutex_init(&priv->stats_mutex);
1081-
1082-
/* All the interesting properties are at the parent device_node
1083-
* level
1084-
*/
1085-
dn = ds->cd->of_node->parent;
1086-
bcm_sf2_identify_ports(priv, ds->cd->of_node);
1087-
1088-
priv->irq0 = irq_of_parse_and_map(dn, 0);
1089-
priv->irq1 = irq_of_parse_and_map(dn, 1);
1090-
1091-
base = &priv->core;
1092-
for (i = 0; i < BCM_SF2_REGS_NUM; i++) {
1093-
*base = of_iomap(dn, i);
1094-
if (*base == NULL) {
1095-
pr_err("unable to find register: %s\n", reg_names[i]);
1096-
ret = -ENOMEM;
1097-
goto out_unmap;
1098-
}
1099-
base++;
1100-
}
1101-
1102-
ret = bcm_sf2_sw_rst(priv);
1103-
if (ret) {
1104-
pr_err("unable to software reset switch: %d\n", ret);
1105-
goto out_unmap;
1106-
}
1107-
1108-
ret = bcm_sf2_mdio_register(ds);
1109-
if (ret) {
1110-
pr_err("failed to register MDIO bus\n");
1111-
goto out_unmap;
1112-
}
1113-
1114-
/* Disable all interrupts and request them */
1115-
bcm_sf2_intr_disable(priv);
1116-
1117-
ret = request_irq(priv->irq0, bcm_sf2_switch_0_isr, 0,
1118-
"switch_0", priv);
1119-
if (ret < 0) {
1120-
pr_err("failed to request switch_0 IRQ\n");
1121-
goto out_unmap;
1122-
}
1123-
1124-
ret = request_irq(priv->irq1, bcm_sf2_switch_1_isr, 0,
1125-
"switch_1", priv);
1126-
if (ret < 0) {
1127-
pr_err("failed to request switch_1 IRQ\n");
1128-
goto out_free_irq0;
1129-
}
1130-
1131-
/* Reset the MIB counters */
1132-
reg = core_readl(priv, CORE_GMNCFGCFG);
1133-
reg |= RST_MIB_CNT;
1134-
core_writel(priv, reg, CORE_GMNCFGCFG);
1135-
reg &= ~RST_MIB_CNT;
1136-
core_writel(priv, reg, CORE_GMNCFGCFG);
1137-
1138-
/* Get the maximum number of ports for this switch */
1139-
priv->hw_params.num_ports = core_readl(priv, CORE_IMP0_PRT_ID) + 1;
1140-
if (priv->hw_params.num_ports > DSA_MAX_PORTS)
1141-
priv->hw_params.num_ports = DSA_MAX_PORTS;
1142-
1143-
/* Assume a single GPHY setup if we can't read that property */
1144-
if (of_property_read_u32(dn, "brcm,num-gphy",
1145-
&priv->hw_params.num_gphy))
1146-
priv->hw_params.num_gphy = 1;
1147-
1148-
/* Enable all valid ports and disable those unused */
1149-
for (port = 0; port < priv->hw_params.num_ports; port++) {
1150-
/* IMP port receives special treatment */
1151-
if ((1 << port) & ds->enabled_port_mask)
1152-
bcm_sf2_port_setup(ds, port, NULL);
1153-
else if (dsa_is_cpu_port(ds, port))
1154-
bcm_sf2_imp_setup(ds, port);
1155-
else
1156-
bcm_sf2_port_disable(ds, port, NULL);
1157-
}
1158-
1159-
rev = reg_readl(priv, REG_SWITCH_REVISION);
1160-
priv->hw_params.top_rev = (rev >> SWITCH_TOP_REV_SHIFT) &
1161-
SWITCH_TOP_REV_MASK;
1162-
priv->hw_params.core_rev = (rev & SF2_REV_MASK);
1163-
1164-
rev = reg_readl(priv, REG_PHY_REVISION);
1165-
priv->hw_params.gphy_rev = rev & PHY_REVISION_MASK;
1166-
1167-
pr_info("Starfighter 2 top: %x.%02x, core: %x.%02x base: 0x%p, IRQs: %d, %d\n",
1168-
priv->hw_params.top_rev >> 8, priv->hw_params.top_rev & 0xff,
1169-
priv->hw_params.core_rev >> 8, priv->hw_params.core_rev & 0xff,
1170-
priv->core, priv->irq0, priv->irq1);
1171-
1172-
return 0;
1173-
1174-
out_free_irq0:
1175-
free_irq(priv->irq0, priv);
1176-
out_unmap:
1177-
base = &priv->core;
1178-
for (i = 0; i < BCM_SF2_REGS_NUM; i++) {
1179-
if (*base)
1180-
iounmap(*base);
1181-
base++;
1182-
}
1183-
bcm_sf2_mdio_unregister(priv);
1184-
return ret;
1185-
}
1186-
11871068
static int bcm_sf2_sw_set_addr(struct dsa_switch *ds, u8 *addr)
11881069
{
11891070
return 0;
@@ -1431,6 +1312,125 @@ static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port,
14311312
return p->ethtool_ops->set_wol(p, wol);
14321313
}
14331314

1315+
static int bcm_sf2_sw_setup(struct dsa_switch *ds)
1316+
{
1317+
const char *reg_names[BCM_SF2_REGS_NUM] = BCM_SF2_REGS_NAME;
1318+
struct bcm_sf2_priv *priv = ds_to_priv(ds);
1319+
struct device_node *dn;
1320+
void __iomem **base;
1321+
unsigned int port;
1322+
unsigned int i;
1323+
u32 reg, rev;
1324+
int ret;
1325+
1326+
spin_lock_init(&priv->indir_lock);
1327+
mutex_init(&priv->stats_mutex);
1328+
1329+
/* All the interesting properties are at the parent device_node
1330+
* level
1331+
*/
1332+
dn = ds->cd->of_node->parent;
1333+
bcm_sf2_identify_ports(priv, ds->cd->of_node);
1334+
1335+
priv->irq0 = irq_of_parse_and_map(dn, 0);
1336+
priv->irq1 = irq_of_parse_and_map(dn, 1);
1337+
1338+
base = &priv->core;
1339+
for (i = 0; i < BCM_SF2_REGS_NUM; i++) {
1340+
*base = of_iomap(dn, i);
1341+
if (*base == NULL) {
1342+
pr_err("unable to find register: %s\n", reg_names[i]);
1343+
ret = -ENOMEM;
1344+
goto out_unmap;
1345+
}
1346+
base++;
1347+
}
1348+
1349+
ret = bcm_sf2_sw_rst(priv);
1350+
if (ret) {
1351+
pr_err("unable to software reset switch: %d\n", ret);
1352+
goto out_unmap;
1353+
}
1354+
1355+
ret = bcm_sf2_mdio_register(ds);
1356+
if (ret) {
1357+
pr_err("failed to register MDIO bus\n");
1358+
goto out_unmap;
1359+
}
1360+
1361+
/* Disable all interrupts and request them */
1362+
bcm_sf2_intr_disable(priv);
1363+
1364+
ret = request_irq(priv->irq0, bcm_sf2_switch_0_isr, 0,
1365+
"switch_0", priv);
1366+
if (ret < 0) {
1367+
pr_err("failed to request switch_0 IRQ\n");
1368+
goto out_unmap;
1369+
}
1370+
1371+
ret = request_irq(priv->irq1, bcm_sf2_switch_1_isr, 0,
1372+
"switch_1", priv);
1373+
if (ret < 0) {
1374+
pr_err("failed to request switch_1 IRQ\n");
1375+
goto out_free_irq0;
1376+
}
1377+
1378+
/* Reset the MIB counters */
1379+
reg = core_readl(priv, CORE_GMNCFGCFG);
1380+
reg |= RST_MIB_CNT;
1381+
core_writel(priv, reg, CORE_GMNCFGCFG);
1382+
reg &= ~RST_MIB_CNT;
1383+
core_writel(priv, reg, CORE_GMNCFGCFG);
1384+
1385+
/* Get the maximum number of ports for this switch */
1386+
priv->hw_params.num_ports = core_readl(priv, CORE_IMP0_PRT_ID) + 1;
1387+
if (priv->hw_params.num_ports > DSA_MAX_PORTS)
1388+
priv->hw_params.num_ports = DSA_MAX_PORTS;
1389+
1390+
/* Assume a single GPHY setup if we can't read that property */
1391+
if (of_property_read_u32(dn, "brcm,num-gphy",
1392+
&priv->hw_params.num_gphy))
1393+
priv->hw_params.num_gphy = 1;
1394+
1395+
/* Enable all valid ports and disable those unused */
1396+
for (port = 0; port < priv->hw_params.num_ports; port++) {
1397+
/* IMP port receives special treatment */
1398+
if ((1 << port) & ds->enabled_port_mask)
1399+
bcm_sf2_port_setup(ds, port, NULL);
1400+
else if (dsa_is_cpu_port(ds, port))
1401+
bcm_sf2_imp_setup(ds, port);
1402+
else
1403+
bcm_sf2_port_disable(ds, port, NULL);
1404+
}
1405+
1406+
rev = reg_readl(priv, REG_SWITCH_REVISION);
1407+
priv->hw_params.top_rev = (rev >> SWITCH_TOP_REV_SHIFT) &
1408+
SWITCH_TOP_REV_MASK;
1409+
priv->hw_params.core_rev = (rev & SF2_REV_MASK);
1410+
1411+
rev = reg_readl(priv, REG_PHY_REVISION);
1412+
priv->hw_params.gphy_rev = rev & PHY_REVISION_MASK;
1413+
1414+
pr_info("Starfighter 2 top: %x.%02x, core: %x.%02x base: 0x%p, IRQs: %d, %d\n",
1415+
priv->hw_params.top_rev >> 8, priv->hw_params.top_rev & 0xff,
1416+
priv->hw_params.core_rev >> 8, priv->hw_params.core_rev & 0xff,
1417+
priv->core, priv->irq0, priv->irq1);
1418+
1419+
return 0;
1420+
1421+
out_free_irq0:
1422+
free_irq(priv->irq0, priv);
1423+
out_unmap:
1424+
base = &priv->core;
1425+
for (i = 0; i < BCM_SF2_REGS_NUM; i++) {
1426+
if (*base)
1427+
iounmap(*base);
1428+
base++;
1429+
}
1430+
bcm_sf2_mdio_unregister(priv);
1431+
return ret;
1432+
}
1433+
14341434
static struct dsa_switch_driver bcm_sf2_switch_driver = {
14351435
.tag_protocol = DSA_TAG_PROTO_BRCM,
14361436
.probe = bcm_sf2_sw_drv_probe,

0 commit comments

Comments
 (0)