| @@ -23,7 +23,7 @@ · 22 unmodified lines |
| 23 | | 23 | |
| 24 | static const struct { | 24 | static const struct { |
| 25 | char string[ETH_GSTRING_LEN]; | 25 | char string[ETH_GSTRING_LEN]; |
| 26 | } mib_names[TOTAL_SWITCH_COUNTER_NUM] = { | 26 | } mib_names[] = { |
| 27 | { "rx_hi" }, | 27 | { "rx_hi" }, |
| 28 | { "rx_undersize" }, | 28 | { "rx_undersize" }, |
| 29 | { "rx_fragments" }, | 29 | { "rx_fragments" }, |
| @@ -125,7 +125,7 @@ static void ksz8795_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, · 95 unmodified lines |
| 125 | u8 check; | 125 | u8 check; |
| 126 | int loop; | 126 | int loop; |
| 127 | | 127 | |
| 128 | ctrl_addr = addr + SWITCH_COUNTER_NUM * port; | 128 | ctrl_addr = addr + dev->reg_mib_cnt * port; |
| 129 | ctrl_addr |= IND_ACC_TABLE(TABLE_MIB | TABLE_READ); | 129 | ctrl_addr |= IND_ACC_TABLE(TABLE_MIB | TABLE_READ); |
| 130 | | 130 | |
| 131 | mutex_lock(&dev->alu_mutex); | 131 | mutex_lock(&dev->alu_mutex); |
| @@ -156,7 +156,7 @@ static void ksz8795_r_mib_pkt(struct ksz_device *dev, int port, u16 addr, · 24 unmodified lines |
| 156 | u8 check; | 156 | u8 check; |
| 157 | int loop; | 157 | int loop; |
| 158 | | 158 | |
| 159 | addr -= SWITCH_COUNTER_NUM; | 159 | addr -= dev->reg_mib_cnt; |
| 160 | ctrl_addr = (KS_MIB_TOTAL_RX_1 - KS_MIB_TOTAL_RX_0) * port; | 160 | ctrl_addr = (KS_MIB_TOTAL_RX_1 - KS_MIB_TOTAL_RX_0) * port; |
| 161 | ctrl_addr += addr + KS_MIB_TOTAL_RX_0; | 161 | ctrl_addr += addr + KS_MIB_TOTAL_RX_0; |
| 162 | ctrl_addr |= IND_ACC_TABLE(TABLE_MIB | TABLE_READ); | 162 | ctrl_addr |= IND_ACC_TABLE(TABLE_MIB | TABLE_READ); |
| @@ -418,8 +418,8 @@ static void ksz8795_r_vlan_entries(struct ksz_device *dev, u16 addr) · 255 unmodified lines |
| 418 | int i; | 418 | int i; |
| 419 | | 419 | |
| 420 | ksz8795_r_table(dev, TABLE_VLAN, addr, &data); | 420 | ksz8795_r_table(dev, TABLE_VLAN, addr, &data); |
| 421 | addr *= 4; | 421 | addr *= dev->phy_port_cnt; |
| 422 | for (i = 0; i < 4; i++) { | 422 | for (i = 0; i < dev->phy_port_cnt; i++) { |
| 423 | dev->vlan_cache[addr + i].table[0] = (u16)data; | 423 | dev->vlan_cache[addr + i].table[0] = (u16)data; |
| 424 | data >>= VLAN_TABLE_S; | 424 | data >>= VLAN_TABLE_S; |
| 425 | } | 425 | } |
| @@ -433,7 +433,7 @@ static void ksz8795_r_vlan_table(struct ksz_device *dev, u16 vid, u16 *vlan) · 7 unmodified lines |
| 433 | u64 buf; | 433 | u64 buf; |
| 434 | | 434 | |
| 435 | data = (u16 *)&buf; | 435 | data = (u16 *)&buf; |
| 436 | addr = vid / 4; | 436 | addr = vid / dev->phy_port_cnt; |
| 437 | index = vid & 3; | 437 | index = vid & 3; |
| 438 | ksz8795_r_table(dev, TABLE_VLAN, addr, &buf); | 438 | ksz8795_r_table(dev, TABLE_VLAN, addr, &buf); |
| 439 | *vlan = data[index]; | 439 | *vlan = data[index]; |
| @@ -447,7 +447,7 @@ static void ksz8795_w_vlan_table(struct ksz_device *dev, u16 vid, u16 vlan) · 7 unmodified lines |
| 447 | u64 buf; | 447 | u64 buf; |
| 448 | | 448 | |
| 449 | data = (u16 *)&buf; | 449 | data = (u16 *)&buf; |
| 450 | addr = vid / 4; | 450 | addr = vid / dev->phy_port_cnt; |
| 451 | index = vid & 3; | 451 | index = vid & 3; |
| 452 | ksz8795_r_table(dev, TABLE_VLAN, addr, &buf); | 452 | ksz8795_r_table(dev, TABLE_VLAN, addr, &buf); |
| 453 | data[index] = vlan; | 453 | data[index] = vlan; |
| @@ -654,9 +654,10 @@ static enum dsa_tag_protocol ksz8795_get_tag_protocol(struct dsa_switch *ds, · 200 unmodified lines |
| 654 | static void ksz8795_get_strings(struct dsa_switch *ds, int port, | 654 | static void ksz8795_get_strings(struct dsa_switch *ds, int port, |
| 655 | u32 stringset, uint8_t *buf) | 655 | u32 stringset, uint8_t *buf) |
| 656 | { | 656 | { |
| | 657 | struct ksz_device *dev = ds->priv; |
| 657 | int i; | 658 | int i; |
| 658 | | 659 | |
| 659 | for (i = 0; i < TOTAL_SWITCH_COUNTER_NUM; i++) { | 660 | for (i = 0; i < dev->mib_cnt; i++) { |
| 660 | memcpy(buf + i * ETH_GSTRING_LEN, mib_names[i].string, | 661 | memcpy(buf + i * ETH_GSTRING_LEN, mib_names[i].string, |
| 661 | ETH_GSTRING_LEN); | 662 | ETH_GSTRING_LEN); |
| 662 | } | 663 | } |
| @@ -691,12 +692,12 @@ static void ksz8795_port_stp_state_set(struct dsa_switch *ds, int port, · 28 unmodified lines |
| 691 | switch (state) { | 692 | switch (state) { |
| 692 | case BR_STATE_DISABLED: | 693 | case BR_STATE_DISABLED: |
| 693 | data |= PORT_LEARN_DISABLE; | 694 | data |= PORT_LEARN_DISABLE; |
| 694 | if (port < SWITCH_PORT_NUM) | 695 | if (port < dev->phy_port_cnt) |
| 695 | member = 0; | 696 | member = 0; |
| 696 | break; | 697 | break; |
| 697 | case BR_STATE_LISTENING: | 698 | case BR_STATE_LISTENING: |
| 698 | data |= (PORT_RX_ENABLE | PORT_LEARN_DISABLE); | 699 | data |= (PORT_RX_ENABLE | PORT_LEARN_DISABLE); |
| 699 | if (port < SWITCH_PORT_NUM && | 700 | if (port < dev->phy_port_cnt && |
| 700 | p->stp_state == BR_STATE_DISABLED) | 701 | p->stp_state == BR_STATE_DISABLED) |
| 701 | member = dev->host_mask | p->vid_member; | 702 | member = dev->host_mask | p->vid_member; |
| 702 | break; | 703 | break; |
| @@ -720,7 +721,7 @@ static void ksz8795_port_stp_state_set(struct dsa_switch *ds, int port, · 17 unmodified lines |
| 720 | break; | 721 | break; |
| 721 | case BR_STATE_BLOCKING: | 722 | case BR_STATE_BLOCKING: |
| 722 | data |= PORT_LEARN_DISABLE; | 723 | data |= PORT_LEARN_DISABLE; |
| 723 | if (port < SWITCH_PORT_NUM && | 724 | if (port < dev->phy_port_cnt && |
| 724 | p->stp_state == BR_STATE_DISABLED) | 725 | p->stp_state == BR_STATE_DISABLED) |
| 725 | member = dev->host_mask | p->vid_member; | 726 | member = dev->host_mask | p->vid_member; |
| 726 | break; | 727 | break; |
| @@ -750,17 +751,17 @@ static void ksz8795_port_stp_state_set(struct dsa_switch *ds, int port, · 23 unmodified lines |
| 750 | | 751 | |
| 751 | static void ksz8795_flush_dyn_mac_table(struct ksz_device *dev, int port) | 752 | static void ksz8795_flush_dyn_mac_table(struct ksz_device *dev, int port) |
| 752 | { | 753 | { |
| 753 | u8 learn[TOTAL_PORT_NUM]; | 754 | u8 learn[DSA_MAX_PORTS]; |
| 754 | int first, index, cnt; | 755 | int first, index, cnt; |
| 755 | struct ksz_port *p; | 756 | struct ksz_port *p; |
| 756 | | 757 | |
| 757 | if ((uint)port < TOTAL_PORT_NUM) { | 758 | if ((uint)port < dev->port_cnt) { |
| 758 | first = port; | 759 | first = port; |
| 759 | cnt = port + 1; | 760 | cnt = port + 1; |
| 760 | } else { | 761 | } else { |
| 761 | /* Flush all ports. */ | 762 | /* Flush all ports. */ |
| 762 | first = 0; | 763 | first = 0; |
| 763 | cnt = dev->mib_port_cnt; | 764 | cnt = dev->port_cnt; |
| 764 | } | 765 | } |
| 765 | for (index = first; index < cnt; index++) { | 766 | for (index = first; index < cnt; index++) { |
| 766 | p = &dev->ports[index]; | 767 | p = &dev->ports[index]; |
| @@ -992,8 +993,6 @@ static void ksz8795_config_cpu_port(struct dsa_switch *ds) · 225 unmodified lines |
| 992 | u8 remote; | 993 | u8 remote; |
| 993 | int i; | 994 | int i; |
| 994 | | 995 | |
| 995 | ds->num_ports = dev->port_cnt + 1; | | |
| 996 | | | |
| 997 | /* Switch marks the maximum frame with extra byte as oversize. */ | 996 | /* Switch marks the maximum frame with extra byte as oversize. */ |
| 998 | ksz_cfg(dev, REG_SW_CTRL_2, SW_LEGAL_PACKET_DISABLE, true); | 997 | ksz_cfg(dev, REG_SW_CTRL_2, SW_LEGAL_PACKET_DISABLE, true); |
| 999 | ksz_cfg(dev, S_TAIL_TAG_CTRL, SW_TAIL_TAG_ENABLE, true); | 998 | ksz_cfg(dev, S_TAIL_TAG_CTRL, SW_TAIL_TAG_ENABLE, true); |
| @@ -1005,7 +1004,7 @@ static void ksz8795_config_cpu_port(struct dsa_switch *ds) · 5 unmodified lines |
| 1005 | ksz8795_port_setup(dev, dev->cpu_port, true); | 1004 | ksz8795_port_setup(dev, dev->cpu_port, true); |
| 1006 | dev->member = dev->host_mask; | 1005 | dev->member = dev->host_mask; |
| 1007 | | 1006 | |
| 1008 | for (i = 0; i < SWITCH_PORT_NUM; i++) { | 1007 | for (i = 0; i < dev->phy_port_cnt; i++) { |
| 1009 | p = &dev->ports[i]; | 1008 | p = &dev->ports[i]; |
| 1010 | | 1009 | |
| 1011 | /* Initialize to non-zero so that ksz_cfg_port_member() will | 1010 | /* Initialize to non-zero so that ksz_cfg_port_member() will |
| @@ -1016,7 +1015,7 @@ static void ksz8795_config_cpu_port(struct dsa_switch *ds) · 4 unmodified lines |
| 1016 | ksz8795_port_stp_state_set(ds, i, BR_STATE_DISABLED); | 1015 | ksz8795_port_stp_state_set(ds, i, BR_STATE_DISABLED); |
| 1017 | | 1016 | |
| 1018 | /* Last port may be disabled. */ | 1017 | /* Last port may be disabled. */ |
| 1019 | if (i == dev->port_cnt) | 1018 | if (i == dev->phy_port_cnt) |
| 1020 | break; | 1019 | break; |
| 1021 | p->on = 1; | 1020 | p->on = 1; |
| 1022 | p->phy = 1; | 1021 | p->phy = 1; |
| @@ -1085,7 +1084,7 @@ static int ksz8795_setup(struct dsa_switch *ds) · 62 unmodified lines |
| 1085 | (BROADCAST_STORM_VALUE * | 1084 | (BROADCAST_STORM_VALUE * |
| 1086 | BROADCAST_STORM_PROT_RATE) / 100); | 1085 | BROADCAST_STORM_PROT_RATE) / 100); |
| 1087 | | 1086 | |
| 1088 | for (i = 0; i < VLAN_TABLE_ENTRIES; i++) | 1087 | for (i = 0; i < (dev->num_vlans / 4); i++) |
| 1089 | ksz8795_r_vlan_entries(dev, i); | 1088 | ksz8795_r_vlan_entries(dev, i); |
| 1090 | | 1089 | |
| 1091 | /* Setup STP address for STP operation. */ | 1090 | /* Setup STP address for STP operation. */ |
| @@ -1150,10 +1149,6 @@ static int ksz8795_switch_detect(struct ksz_device *dev) · 58 unmodified lines |
| 1150 | (id2 != CHIP_ID_94 && id2 != CHIP_ID_95)) | 1149 | (id2 != CHIP_ID_94 && id2 != CHIP_ID_95)) |
| 1151 | return -ENODEV; | 1150 | return -ENODEV; |
| 1152 | | 1151 | |
| 1153 | dev->mib_port_cnt = TOTAL_PORT_NUM; | | |
| 1154 | dev->phy_port_cnt = SWITCH_PORT_NUM; | | |
| 1155 | dev->port_cnt = SWITCH_PORT_NUM; | | |
| 1156 | | | |
| 1157 | if (id2 == CHIP_ID_95) { | 1152 | if (id2 == CHIP_ID_95) { |
| 1158 | u8 val; | 1153 | u8 val; |
| 1159 | | 1154 | |
| @@ -1162,17 +1157,12 @@ static int ksz8795_switch_detect(struct ksz_device *dev) · 2 unmodified lines |
| 1162 | if (val & PORT_FIBER_MODE) | 1157 | if (val & PORT_FIBER_MODE) |
| 1163 | id2 = 0x65; | 1158 | id2 = 0x65; |
| 1164 | } else if (id2 == CHIP_ID_94) { | 1159 | } else if (id2 == CHIP_ID_94) { |
| 1165 | dev->port_cnt--; | | |
| 1166 | dev->last_port = dev->port_cnt; | | |
| 1167 | id2 = 0x94; | 1160 | id2 = 0x94; |
| 1168 | } | 1161 | } |
| 1169 | id16 &= ~0xff; | 1162 | id16 &= ~0xff; |
| 1170 | id16 |= id2; | 1163 | id16 |= id2; |
| 1171 | dev->chip_id = id16; | 1164 | dev->chip_id = id16; |
| 1172 | | 1165 | |
| 1173 | dev->cpu_port = dev->mib_port_cnt - 1; | | |
| 1174 | dev->host_mask = BIT(dev->cpu_port); | | |
| 1175 | | | |
| 1176 | return 0; | 1166 | return 0; |
| 1177 | } | 1167 | } |
| 1178 | | 1168 | |
| @@ -1194,7 +1184,7 @@ static const struct ksz_chip_data ksz8795_switch_chips[] = { · 15 unmodified lines |
| 1194 | .num_alus = 0, | 1184 | .num_alus = 0, |
| 1195 | .num_statics = 8, | 1185 | .num_statics = 8, |
| 1196 | .cpu_ports = 0x10, /* can be configured as cpu port */ | 1186 | .cpu_ports = 0x10, /* can be configured as cpu port */ |
| 1197 | .port_cnt = 4, /* total physical port count */ | 1187 | .port_cnt = 5, /* total cpu and user ports */ |
| 1198 | }, | 1188 | }, |
| 1199 | { | 1189 | { |
| 1200 | .chip_id = 0x8794, | 1190 | .chip_id = 0x8794, |
| @@ -1203,7 +1193,7 @@ static const struct ksz_chip_data ksz8795_switch_chips[] = { · 2 unmodified lines |
| 1203 | .num_alus = 0, | 1193 | .num_alus = 0, |
| 1204 | .num_statics = 8, | 1194 | .num_statics = 8, |
| 1205 | .cpu_ports = 0x10, /* can be configured as cpu port */ | 1195 | .cpu_ports = 0x10, /* can be configured as cpu port */ |
| 1206 | .port_cnt = 3, /* total physical port count */ | 1196 | .port_cnt = 4, /* total cpu and user ports */ |
| 1207 | }, | 1197 | }, |
| 1208 | { | 1198 | { |
| 1209 | .chip_id = 0x8765, | 1199 | .chip_id = 0x8765, |
| @@ -1212,7 +1202,7 @@ static const struct ksz_chip_data ksz8795_switch_chips[] = { · 2 unmodified lines |
| 1212 | .num_alus = 0, | 1202 | .num_alus = 0, |
| 1213 | .num_statics = 8, | 1203 | .num_statics = 8, |
| 1214 | .cpu_ports = 0x10, /* can be configured as cpu port */ | 1204 | .cpu_ports = 0x10, /* can be configured as cpu port */ |
| 1215 | .port_cnt = 4, /* total physical port count */ | 1205 | .port_cnt = 5, /* total cpu and user ports */ |
| 1216 | }, | 1206 | }, |
| 1217 | }; | 1207 | }; |
| 1218 | | 1208 | |
| @@ -1244,27 +1234,32 @@ static int ksz8795_switch_init(struct ksz_device *dev) · 25 unmodified lines |
| 1244 | dev->port_mask = BIT(dev->port_cnt) - 1; | 1234 | dev->port_mask = BIT(dev->port_cnt) - 1; |
| 1245 | dev->port_mask |= dev->host_mask; | 1235 | dev->port_mask |= dev->host_mask; |
| 1246 | | 1236 | |
| 1247 | dev->reg_mib_cnt = SWITCH_COUNTER_NUM; | 1237 | dev->reg_mib_cnt = KSZ8795_COUNTER_NUM; |
| 1248 | dev->mib_cnt = TOTAL_SWITCH_COUNTER_NUM; | 1238 | dev->mib_cnt = ARRAY_SIZE(mib_names); |
| | 1239 | |
| | 1240 | dev->phy_port_cnt = dev->port_cnt - 1; |
| | 1241 | |
| | 1242 | dev->cpu_port = dev->port_cnt - 1; |
| | 1243 | dev->host_mask = BIT(dev->cpu_port); |
| 1249 | | 1244 | |
| 1250 | i = dev->mib_port_cnt; | 1245 | dev->ports = devm_kzalloc(dev->dev, |
| 1251 | dev->ports = devm_kzalloc(dev->dev, sizeof(struct ksz_port) * i, | 1246 | dev->port_cnt * sizeof(struct ksz_port), |
| 1252 | GFP_KERNEL); | 1247 | GFP_KERNEL); |
| 1253 | if (!dev->ports) | 1248 | if (!dev->ports) |
| 1254 | return -ENOMEM; | 1249 | return -ENOMEM; |
| 1255 | for (i = 0; i < dev->mib_port_cnt; i++) { | 1250 | for (i = 0; i < dev->port_cnt; i++) { |
| 1256 | mutex_init(&dev->ports[i].mib.cnt_mutex); | 1251 | mutex_init(&dev->ports[i].mib.cnt_mutex); |
| 1257 | dev->ports[i].mib.counters = | 1252 | dev->ports[i].mib.counters = |
| 1258 | devm_kzalloc(dev->dev, | 1253 | devm_kzalloc(dev->dev, |
| 1259 | sizeof(u64) * | 1254 | sizeof(u64) * |
| 1260 | (TOTAL_SWITCH_COUNTER_NUM + 1), | 1255 | (dev->mib_cnt + 1), |
| 1261 | GFP_KERNEL); | 1256 | GFP_KERNEL); |
| 1262 | if (!dev->ports[i].mib.counters) | 1257 | if (!dev->ports[i].mib.counters) |
| 1263 | return -ENOMEM; | 1258 | return -ENOMEM; |
| 1264 | } | 1259 | } |
| 1265 | | 1260 | |
| 1266 | /* set the real number of ports */ | 1261 | /* set the real number of ports */ |
| 1267 | dev->ds->num_ports = dev->port_cnt + 1; | 1262 | dev->ds->num_ports = dev->port_cnt; |
| 1268 | | 1263 | |
| 1269 | return 0; | 1264 | return 0; |
| 1270 | } | 1265 | } |