net: dsa: microchip: move port memory allocation to ksz_common
ksz8795 and ksz9477 init function initializes the memory to dev->ports, mib counters and assigns the ds real number of ports. Since both the routines are same, moved the allocation of port memory to ksz_switch_register after init. Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
a530e6f220
commit
198b34783a
@ -1494,7 +1494,6 @@ static int ksz8_switch_detect(struct ksz_device *dev)
|
|||||||
static int ksz8_switch_init(struct ksz_device *dev)
|
static int ksz8_switch_init(struct ksz_device *dev)
|
||||||
{
|
{
|
||||||
struct ksz8 *ksz8 = dev->priv;
|
struct ksz8 *ksz8 = dev->priv;
|
||||||
int i;
|
|
||||||
|
|
||||||
dev->ds->ops = &ksz8_switch_ops;
|
dev->ds->ops = &ksz8_switch_ops;
|
||||||
|
|
||||||
@ -1513,25 +1512,6 @@ static int ksz8_switch_init(struct ksz_device *dev)
|
|||||||
ksz8->shifts = ksz8795_shifts;
|
ksz8->shifts = ksz8795_shifts;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->ports = devm_kzalloc(dev->dev,
|
|
||||||
dev->info->port_cnt * sizeof(struct ksz_port),
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (!dev->ports)
|
|
||||||
return -ENOMEM;
|
|
||||||
for (i = 0; i < dev->info->port_cnt; i++) {
|
|
||||||
mutex_init(&dev->ports[i].mib.cnt_mutex);
|
|
||||||
dev->ports[i].mib.counters =
|
|
||||||
devm_kzalloc(dev->dev,
|
|
||||||
sizeof(u64) *
|
|
||||||
(dev->info->mib_cnt + 1),
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (!dev->ports[i].mib.counters)
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set the real number of ports */
|
|
||||||
dev->ds->num_ports = dev->info->port_cnt;
|
|
||||||
|
|
||||||
/* We rely on software untagging on the CPU port, so that we
|
/* We rely on software untagging on the CPU port, so that we
|
||||||
* can support both tagged and untagged VLANs
|
* can support both tagged and untagged VLANs
|
||||||
*/
|
*/
|
||||||
|
@ -1432,32 +1432,10 @@ static int ksz9477_switch_detect(struct ksz_device *dev)
|
|||||||
|
|
||||||
static int ksz9477_switch_init(struct ksz_device *dev)
|
static int ksz9477_switch_init(struct ksz_device *dev)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
dev->ds->ops = &ksz9477_switch_ops;
|
dev->ds->ops = &ksz9477_switch_ops;
|
||||||
|
|
||||||
dev->port_mask = (1 << dev->info->port_cnt) - 1;
|
dev->port_mask = (1 << dev->info->port_cnt) - 1;
|
||||||
|
|
||||||
dev->ports = devm_kzalloc(dev->dev,
|
|
||||||
dev->info->port_cnt * sizeof(struct ksz_port),
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (!dev->ports)
|
|
||||||
return -ENOMEM;
|
|
||||||
for (i = 0; i < dev->info->port_cnt; i++) {
|
|
||||||
spin_lock_init(&dev->ports[i].mib.stats64_lock);
|
|
||||||
mutex_init(&dev->ports[i].mib.cnt_mutex);
|
|
||||||
dev->ports[i].mib.counters =
|
|
||||||
devm_kzalloc(dev->dev,
|
|
||||||
sizeof(u64) *
|
|
||||||
(dev->info->mib_cnt + 1),
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (!dev->ports[i].mib.counters)
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set the real number of ports */
|
|
||||||
dev->ds->num_ports = dev->info->port_cnt;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -844,6 +844,7 @@ int ksz_switch_register(struct ksz_device *dev,
|
|||||||
phy_interface_t interface;
|
phy_interface_t interface;
|
||||||
unsigned int port_num;
|
unsigned int port_num;
|
||||||
int ret;
|
int ret;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (dev->pdata)
|
if (dev->pdata)
|
||||||
dev->chip_id = dev->pdata->chip_id;
|
dev->chip_id = dev->pdata->chip_id;
|
||||||
@ -885,6 +886,26 @@ int ksz_switch_register(struct ksz_device *dev,
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
dev->ports = devm_kzalloc(dev->dev,
|
||||||
|
dev->info->port_cnt * sizeof(struct ksz_port),
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!dev->ports)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
for (i = 0; i < dev->info->port_cnt; i++) {
|
||||||
|
spin_lock_init(&dev->ports[i].mib.stats64_lock);
|
||||||
|
mutex_init(&dev->ports[i].mib.cnt_mutex);
|
||||||
|
dev->ports[i].mib.counters =
|
||||||
|
devm_kzalloc(dev->dev,
|
||||||
|
sizeof(u64) * (dev->info->mib_cnt + 1),
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!dev->ports[i].mib.counters)
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set the real number of ports */
|
||||||
|
dev->ds->num_ports = dev->info->port_cnt;
|
||||||
|
|
||||||
/* Host port interface will be self detected, or specifically set in
|
/* Host port interface will be self detected, or specifically set in
|
||||||
* device tree.
|
* device tree.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user