Skip to content

Commit

Permalink
net: dsa: microchip: remove usage of mib_port_count
Browse files Browse the repository at this point in the history
The variable mib_port_cnt has the same meaning as port_cnt.
This driver removes the extra variable and is using port_cnt
everywhere instead.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Michael Grzeschik authored and Jakub Kicinski committed Dec 3, 2020
1 parent 94374dd commit c9f4633
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
11 changes: 5 additions & 6 deletions drivers/net/dsa/microchip/ksz8795.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ static void ksz8795_flush_dyn_mac_table(struct ksz_device *dev, int port)
} else {
/* Flush all ports. */
first = 0;
cnt = dev->mib_port_cnt;
cnt = dev->port_cnt;
}
for (index = first; index < cnt; index++) {
p = &dev->ports[index];
Expand Down Expand Up @@ -1237,18 +1237,17 @@ static int ksz8795_switch_init(struct ksz_device *dev)
dev->reg_mib_cnt = KSZ8795_COUNTER_NUM;
dev->mib_cnt = ARRAY_SIZE(mib_names);

dev->mib_port_cnt = TOTAL_PORT_NUM;
dev->phy_port_cnt = dev->port_cnt - 1;

dev->cpu_port = dev->mib_port_cnt - 1;
dev->cpu_port = dev->port_cnt - 1;
dev->host_mask = BIT(dev->cpu_port);

i = dev->mib_port_cnt;
dev->ports = devm_kzalloc(dev->dev, sizeof(struct ksz_port) * i,
dev->ports = devm_kzalloc(dev->dev,
dev->port_cnt * sizeof(struct ksz_port),
GFP_KERNEL);
if (!dev->ports)
return -ENOMEM;
for (i = 0; i < dev->mib_port_cnt; i++) {
for (i = 0; i < dev->port_cnt; i++) {
mutex_init(&dev->ports[i].mib.cnt_mutex);
dev->ports[i].mib.counters =
devm_kzalloc(dev->dev,
Expand Down
12 changes: 5 additions & 7 deletions drivers/net/dsa/microchip/ksz9477.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port)
SW_FLUSH_OPTION_M << SW_FLUSH_OPTION_S,
SW_FLUSH_OPTION_DYN_MAC << SW_FLUSH_OPTION_S);

if (port < dev->mib_port_cnt) {
if (port < dev->port_cnt) {
/* flush individual port */
ksz_pread8(dev, port, P_STP_CTRL, &data);
if (!(data & PORT_LEARN_DISABLE))
Expand Down Expand Up @@ -1317,7 +1317,7 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds)

dev->member = dev->host_mask;

for (i = 0; i < dev->mib_port_cnt; i++) {
for (i = 0; i < dev->port_cnt; i++) {
if (i == dev->cpu_port)
continue;
p = &dev->ports[i];
Expand Down Expand Up @@ -1444,7 +1444,6 @@ static int ksz9477_switch_detect(struct ksz_device *dev)
return ret;

/* Number of ports can be reduced depending on chip. */
dev->mib_port_cnt = TOTAL_PORT_NUM;
dev->phy_port_cnt = 5;

/* Default capability is gigabit capable. */
Expand All @@ -1461,7 +1460,6 @@ static int ksz9477_switch_detect(struct ksz_device *dev)
/* Chip does not support gigabit. */
if (data8 & SW_QW_ABLE)
dev->features &= ~GBIT_SUPPORT;
dev->mib_port_cnt = 3;
dev->phy_port_cnt = 2;
} else {
dev_info(dev->dev, "Found KSZ9477 or compatible\n");
Expand Down Expand Up @@ -1564,12 +1562,12 @@ static int ksz9477_switch_init(struct ksz_device *dev)
dev->reg_mib_cnt = SWITCH_COUNTER_NUM;
dev->mib_cnt = TOTAL_SWITCH_COUNTER_NUM;

i = dev->mib_port_cnt;
dev->ports = devm_kzalloc(dev->dev, sizeof(struct ksz_port) * i,
dev->ports = devm_kzalloc(dev->dev,
dev->port_cnt * sizeof(struct ksz_port),
GFP_KERNEL);
if (!dev->ports)
return -ENOMEM;
for (i = 0; i < dev->mib_port_cnt; i++) {
for (i = 0; i < dev->port_cnt; i++) {
mutex_init(&dev->ports[i].mib.cnt_mutex);
dev->ports[i].mib.counters =
devm_kzalloc(dev->dev,
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/dsa/microchip/ksz_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void ksz_mib_read_work(struct work_struct *work)
struct ksz_port *p;
int i;

for (i = 0; i < dev->mib_port_cnt; i++) {
for (i = 0; i < dev->port_cnt; i++) {
if (dsa_is_unused_port(dev->ds, i))
continue;

Expand Down Expand Up @@ -103,7 +103,7 @@ void ksz_init_mib_timer(struct ksz_device *dev)

INIT_DELAYED_WORK(&dev->mib_read, ksz_mib_read_work);

for (i = 0; i < dev->mib_port_cnt; i++)
for (i = 0; i < dev->port_cnt; i++)
dev->dev_ops->port_init_cnt(dev, i);
}
EXPORT_SYMBOL_GPL(ksz_init_mib_timer);
Expand Down
1 change: 0 additions & 1 deletion drivers/net/dsa/microchip/ksz_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ struct ksz_device {
int port_cnt;
int reg_mib_cnt;
int mib_cnt;
int mib_port_cnt;
phy_interface_t compat_interface;
u32 regs_size;
bool phy_errata_9477;
Expand Down

0 comments on commit c9f4633

Please sign in to comment.