Lines Matching refs:dev

166 static int b53_do_vlan_op(struct b53_device *dev, u8 op)
170 b53_write8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], VTA_START_CMD | op);
175 b53_read8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], &vta);
185 static void b53_set_vlan_entry(struct b53_device *dev, u16 vid, u16 members,
188 if (is5325(dev)) {
194 if (dev->core_rev >= 3)
200 b53_write32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, entry);
201 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid |
203 } else if (is5365(dev)) {
210 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, entry);
211 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid |
214 b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid);
215 b53_write32(dev, B53_ARLIO_PAGE, dev->vta_regs[2],
218 b53_do_vlan_op(dev, VTA_CMD_WRITE);
222 void b53_set_forwarding(struct b53_device *dev, int enable)
226 b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
233 b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
236 static void b53_enable_vlan(struct b53_device *dev, int enable)
240 b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
241 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, &vc0);
242 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, &vc1);
244 if (is5325(dev) || is5365(dev)) {
245 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4);
246 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, &vc5);
247 } else if (is63xx(dev)) {
248 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, &vc4);
249 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, &vc5);
251 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, &vc4);
252 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, &vc5);
264 if (is5325(dev))
267 if (is5325(dev) || is5365(dev))
270 if (!is5325(dev) && !is5365(dev)) {
271 if (dev->allow_vid_4095)
282 if (is5325(dev) || is5365(dev))
287 if (is5325(dev) || is5365(dev))
290 if (!is5325(dev) && !is5365(dev))
294 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, vc0);
295 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, vc1);
297 if (is5325(dev) || is5365(dev)) {
299 if (is5325(dev) && enable)
300 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3,
303 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0);
305 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, vc4);
306 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, vc5);
307 } else if (is63xx(dev)) {
308 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3_63XX, 0);
309 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, vc4);
310 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, vc5);
312 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0);
313 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, vc4);
314 b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, vc5);
317 b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
320 static int b53_set_jumbo(struct b53_device *dev, int enable, int allow_10_100)
325 if (is5325(dev) || is5365(dev))
329 port_mask = dev->enabled_ports;
335 b53_write32(dev, B53_JUMBO_PAGE, dev->jumbo_pm_reg, port_mask);
336 return b53_write16(dev, B53_JUMBO_PAGE, dev->jumbo_size_reg, max_size);
339 static int b53_flush_arl(struct b53_device *dev)
343 b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL,
349 b53_read8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL,
363 static void b53_enable_ports(struct b53_device *dev)
367 b53_for_each_port(dev, i) {
375 if (dev->enable_vlan || is_cpu_port(dev, i))
377 else if (is531x5(dev) || is5301x(dev))
379 pvlan_mask = BIT(dev->sw_dev.cpu_port);
384 if ((is5325(dev) || is5365(dev)) && i == B53_CPU_PORT_25)
387 if (dev->chip_id == BCM5398_DEVICE_ID && (i == 6 || i == 7))
397 b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i),
401 if (!is63xx(dev) && !(is5301x(dev) && i == 6))
402 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(i),
407 static void b53_enable_mib(struct b53_device *dev)
411 b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc);
415 b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc);
418 static int b53_apply(struct b53_device *dev)
423 if (is5325(dev) || is5365(dev)) {
424 for (i = 1; i < dev->sw_dev.vlans; i++)
425 b53_set_vlan_entry(dev, i, 0, 0);
427 b53_do_vlan_op(dev, VTA_CMD_CLEAR);
430 b53_enable_vlan(dev, dev->enable_vlan);
433 if (dev->enable_vlan) {
434 for (i = 0; i < dev->sw_dev.vlans; i++) {
435 struct b53_vlan *vlan = &dev->vlans[i];
440 b53_set_vlan_entry(dev, i, vlan->members, vlan->untag);
443 b53_for_each_port(dev, i)
444 b53_write16(dev, B53_VLAN_PAGE,
446 dev->ports[i].pvid);
448 b53_for_each_port(dev, i)
449 b53_write16(dev, B53_VLAN_PAGE,
454 b53_enable_ports(dev);
456 if (!is5325(dev) && !is5365(dev))
457 b53_set_jumbo(dev, dev->enable_jumbo, 1);
462 static void b53_switch_reset_gpio(struct b53_device *dev)
464 int gpio = dev->reset_gpio;
478 dev->current_page = 0xff;
481 static int b53_switch_reset(struct b53_device *dev)
483 u8 cpu_port = dev->sw_dev.cpu_port;
486 b53_switch_reset_gpio(dev);
488 if (is539x(dev)) {
489 b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83);
490 b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00);
493 b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
499 b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
500 b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
509 b53_enable_ports(dev);
512 if (is5325(dev)) {
515 b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
519 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
521 b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
529 } else if (is531x5(dev) && cpu_port == B53_CPU_PORT) {
532 b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
534 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
537 } else if (is5301x(dev)) {
541 b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
548 b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
556 b53_read8(dev, B53_CTRL_PAGE, po_reg, &gmii_po);
562 b53_write8(dev, B53_CTRL_PAGE, po_reg, gmii_po);
566 b53_enable_mib(dev);
568 return b53_flush_arl(dev);
575 static int b53_global_get_vlan_enable(struct switch_dev *dev,
579 struct b53_device *priv = sw_to_b53(dev);
586 static int b53_global_set_vlan_enable(struct switch_dev *dev,
590 struct b53_device *priv = sw_to_b53(dev);
597 static int b53_global_get_jumbo_enable(struct switch_dev *dev,
601 struct b53_device *priv = sw_to_b53(dev);
608 static int b53_global_set_jumbo_enable(struct switch_dev *dev,
612 struct b53_device *priv = sw_to_b53(dev);
619 static int b53_global_get_4095_enable(struct switch_dev *dev,
623 struct b53_device *priv = sw_to_b53(dev);
630 static int b53_global_set_4095_enable(struct switch_dev *dev,
634 struct b53_device *priv = sw_to_b53(dev);
641 static int b53_global_get_ports(struct switch_dev *dev,
645 struct b53_device *priv = sw_to_b53(dev);
654 static int b53_port_get_pvid(struct switch_dev *dev, int port, int *val)
656 struct b53_device *priv = sw_to_b53(dev);
663 static int b53_port_set_pvid(struct switch_dev *dev, int port, int val)
665 struct b53_device *priv = sw_to_b53(dev);
677 static int b53_vlan_get_ports(struct switch_dev *dev, struct switch_val *val)
679 struct b53_device *priv = sw_to_b53(dev);
689 for (i = 0; i < dev->ports; i++) {
707 static int b53_vlan_set_ports(struct switch_dev *dev, struct switch_val *val)
709 struct b53_device *priv = sw_to_b53(dev);
741 static int b53_port_get_link(struct switch_dev *dev, int port,
744 struct b53_device *priv = sw_to_b53(dev);
800 struct b53_device *dev = sw_to_b53(sw_dev);
806 if (is63xx(dev))
812 if (!(BIT(port) & dev->enabled_ports))
816 (is5325(dev) || is5365(dev)))
825 static int b53_phy_read16(struct switch_dev *dev, int addr, u8 reg, u16 *value)
827 struct b53_device *priv = sw_to_b53(dev);
835 static int b53_phy_write16(struct switch_dev *dev, int addr, u8 reg, u16 value)
837 struct b53_device *priv = sw_to_b53(dev);
845 static int b53_global_reset_switch(struct switch_dev *dev)
847 struct b53_device *priv = sw_to_b53(dev);
854 memset(priv->vlans, 0, sizeof(*priv->vlans) * dev->vlans);
855 memset(priv->ports, 0, sizeof(*priv->ports) * dev->ports);
860 static int b53_global_apply_config(struct switch_dev *dev)
862 struct b53_device *priv = sw_to_b53(dev);
876 static int b53_global_reset_mib(struct switch_dev *dev,
880 struct b53_device *priv = sw_to_b53(dev);
897 struct b53_device *dev = sw_to_b53(sw_dev);
902 if (!(BIT(port) & dev->enabled_ports))
905 if (is5365(dev)) {
910 } else if (is63xx(dev)) {
916 dev->buf[0] = 0;
922 b53_read64(dev, B53_MIB_PAGE(port), mibs->offset, &val);
926 b53_read32(dev, B53_MIB_PAGE(port), mibs->offset,
931 len += snprintf(dev->buf + len, B53_BUF_SIZE - len,
936 val->value.s = dev->buf;
1310 static int b53_switch_init(struct b53_device *dev)
1312 struct switch_dev *sw_dev = &dev->sw_dev;
1319 if (chip->chip_id == dev->chip_id) {
1323 if (!dev->enabled_ports)
1324 dev->enabled_ports = chip->enabled_ports;
1325 dev->duplex_reg = chip->duplex_reg;
1326 dev->vta_regs[0] = chip->vta_regs[0];
1327 dev->vta_regs[1] = chip->vta_regs[1];
1328 dev->vta_regs[2] = chip->vta_regs[2];
1329 dev->jumbo_pm_reg = chip->jumbo_pm_reg;
1341 if (is5325(dev)) {
1344 b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4);
1353 dev->enabled_ports &= ~BIT(4);
1364 } else if (dev->chip_id == BCM53115_DEVICE_ID) {
1367 b53_read48(dev, B53_STAT_PAGE, B53_STRAP_VALUE, &strap_value);
1375 dev->enabled_ports |= BIT(sw_dev->cpu_port);
1377 dev->ports = devm_kzalloc(dev->dev,
1380 if (!dev->ports)
1383 dev->vlans = devm_kzalloc(dev->dev,
1386 if (!dev->vlans)
1389 dev->buf = devm_kzalloc(dev->dev, B53_BUF_SIZE, GFP_KERNEL);
1390 if (!dev->buf)
1393 dev->reset_gpio = b53_switch_get_reset_gpio(dev);
1394 if (dev->reset_gpio >= 0) {
1395 ret = devm_gpio_request_one(dev->dev, dev->reset_gpio,
1401 return b53_switch_reset(dev);
1407 struct b53_device *dev;
1409 dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL);
1410 if (!dev)
1413 dev->dev = base;
1414 dev->ops = ops;
1415 dev->priv = priv;
1416 mutex_init(&dev->reg_mutex);
1418 return dev;
1422 int b53_switch_detect(struct b53_device *dev)
1429 ret = b53_read8(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id8);
1444 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf);
1445 b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp);
1448 dev->chip_id = BCM5325_DEVICE_ID;
1450 dev->chip_id = BCM5365_DEVICE_ID;
1455 dev->chip_id = id8;
1458 ret = b53_read32(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id32);
1471 dev->chip_id = id32;
1480 if (dev->chip_id == BCM5325_DEVICE_ID)
1481 return b53_read8(dev, B53_STAT_PAGE, B53_REV_ID_25,
1482 &dev->core_rev);
1484 return b53_read8(dev, B53_MGMT_PAGE, B53_REV_ID,
1485 &dev->core_rev);
1489 int b53_switch_register(struct b53_device *dev)
1493 if (dev->pdata) {
1494 dev->chip_id = dev->pdata->chip_id;
1495 dev->enabled_ports = dev->pdata->enabled_ports;
1496 dev->sw_dev.alias = dev->pdata->alias;
1499 if (!dev->chip_id && b53_switch_detect(dev))
1502 ret = b53_switch_init(dev);
1506 pr_info("found switch: %s, rev %i\n", dev->sw_dev.name, dev->core_rev);
1508 return register_switch(&dev->sw_dev, NULL);