X-Git-Url: http://git.rohieb.name/openwrt.git/blobdiff_plain/b710df9d9a6db01c5ed20dd7e41c5696f3ab944a..5e66606678426ebb01fbd81d6212fb6fff2f896c:/target/linux/generic-2.6/files/drivers/net/phy/rtl8366rb.c diff --git a/target/linux/generic-2.6/files/drivers/net/phy/rtl8366rb.c b/target/linux/generic-2.6/files/drivers/net/phy/rtl8366rb.c index dcc4d6c92..d453fa497 100644 --- a/target/linux/generic-2.6/files/drivers/net/phy/rtl8366rb.c +++ b/target/linux/generic-2.6/files/drivers/net/phy/rtl8366rb.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include "rtl8366_smi.h" @@ -26,7 +25,7 @@ #endif #define RTL8366S_DRIVER_DESC "Realtek RTL8366RB ethernet switch driver" -#define RTL8366S_DRIVER_VER "0.2.0" +#define RTL8366S_DRIVER_VER "0.2.2" #define RTL8366S_PHY_NO_MAX 4 #define RTL8366S_PHY_PAGE_MAX 7 @@ -148,8 +147,6 @@ struct rtl8366rb { struct device *parent; struct rtl8366_smi smi; - struct mii_bus *mii_bus; - int mii_irq[PHY_MAX_ADDR]; struct switch_dev dev; char buf[4096]; #ifdef CONFIG_RTL8366S_PHY_DEBUG_FS @@ -210,21 +207,26 @@ static struct mib_counter rtl8366rb_mib_counters[RTL8366S_MIB_COUNT] = { { 38, 2, "Dot3StatsSymbolErrors " }, { 40, 2, "Dot3InPauseFrames " }, { 42, 2, "Dot3ControlInUnknownOpcodes " }, - { 44, 2, "IfOutOctets " }, - { 46, 2, "Dot3StatsSingleCollisionFrames " }, - { 48, 2, "Dot3StatMultipleCollisionFrames " }, - { 50, 2, "Dot3sDeferredTransmissions " }, - { 52, 2, "Dot3StatsLateCollisions " }, - { 54, 2, "EtherStatsCollisions " }, - { 56, 2, "Dot3StatsExcessiveCollisions " }, - { 58, 2, "Dot3OutPauseFrames " }, - { 60, 2, "Dot1dBasePortDelayExceededDiscards" }, - { 62, 2, "Dot1dTpPortInDiscards " }, - { 64, 2, "IfOutUcastPkts " }, - { 66, 2, "IfOutMulticastPkts " }, - { 68, 2, "IfOutBroadcastPkts " }, + { 44, 4, "IfOutOctets " }, + { 48, 2, "Dot3StatsSingleCollisionFrames " }, + { 50, 2, "Dot3StatMultipleCollisionFrames " }, + { 52, 2, "Dot3sDeferredTransmissions " }, + { 54, 2, "Dot3StatsLateCollisions " }, + { 56, 2, "EtherStatsCollisions " }, + { 58, 2, "Dot3StatsExcessiveCollisions " }, + { 60, 2, "Dot3OutPauseFrames " }, + { 62, 2, "Dot1dBasePortDelayExceededDiscards" }, + { 64, 2, "Dot1dTpPortInDiscards " }, + { 66, 2, "IfOutUcastPkts " }, + { 68, 2, "IfOutMulticastPkts " }, + { 70, 2, "IfOutBroadcastPkts " }, }; +static inline struct rtl8366rb *smi_to_rtl8366rb(struct rtl8366_smi *smi) +{ + return container_of(smi, struct rtl8366rb, smi); +} + static inline struct rtl8366rb *sw_to_rtl8366rb(struct switch_dev *sw) { return container_of(sw, struct rtl8366rb, dev); @@ -954,30 +956,32 @@ static void rtl8366rb_debugfs_init(struct rtl8366rb *rtl) node = debugfs_create_x16("reg", S_IRUGO | S_IWUSR, root, &gl_dbg_reg); if (!node) { - dev_err(rtl->parent, "Creating debugfs file reg failed\n"); + dev_err(rtl->parent, "Creating debugfs file '%s' failed\n", + "reg"); return; } node = debugfs_create_file("val", S_IRUGO | S_IWUSR, root, rtl, &fops_rtl8366rb_regs); if (!node) { - dev_err(rtl->parent, "Creating debugfs file val failed\n"); + dev_err(rtl->parent, "Creating debugfs file '%s' failed\n", + "val"); return; } node = debugfs_create_file("vlan", S_IRUSR, root, rtl, &fops_rtl8366rb_vlan); if (!node) { - dev_err(rtl->parent, - "Creating debugfs file vlan failed\n"); + dev_err(rtl->parent, "Creating debugfs file '%s' failed\n", + "vlan"); return; } node = debugfs_create_file("mibs", S_IRUSR, root, rtl, &fops_rtl8366rb_mibs); if (!node) { - dev_err(rtl->parent, - "Creating debugfs file mibs failed\n"); + dev_err(rtl->parent, "Creating debugfs file '%s' failed\n", + "mibs"); return; } } @@ -1119,19 +1123,24 @@ static int rtl8366rb_sw_get_port_link(struct switch_dev *dev, if (val->port_vlan % 2) data = data >> 8; - len = snprintf(rtl->buf, sizeof(rtl->buf), - "port:%d link:%s speed:%s %s-duplex %s%s%s", - val->port_vlan, - (data & RTL8366S_PORT_STATUS_LINK_MASK) ? "up" : "down", - rtl8366rb_speed_str(data & + if (data & RTL8366S_PORT_STATUS_LINK_MASK) { + len = snprintf(rtl->buf, sizeof(rtl->buf), + "port:%d link:up speed:%s %s-duplex %s%s%s", + val->port_vlan, + rtl8366rb_speed_str(data & RTL8366S_PORT_STATUS_SPEED_MASK), - (data & RTL8366S_PORT_STATUS_DUPLEX_MASK) ? - "full" : "half", - (data & RTL8366S_PORT_STATUS_TXPAUSE_MASK) ? - "tx-pause ": "", - (data & RTL8366S_PORT_STATUS_RXPAUSE_MASK) ? - "rx-pause " : "", - (data & RTL8366S_PORT_STATUS_AN_MASK) ? "nway ": ""); + (data & RTL8366S_PORT_STATUS_DUPLEX_MASK) ? + "full" : "half", + (data & RTL8366S_PORT_STATUS_TXPAUSE_MASK) ? + "tx-pause ": "", + (data & RTL8366S_PORT_STATUS_RXPAUSE_MASK) ? + "rx-pause " : "", + (data & RTL8366S_PORT_STATUS_AN_MASK) ? + "nway ": ""); + } else { + len = snprintf(rtl->buf, sizeof(rtl->buf), "port:%d link: down", + val->port_vlan); + } val->value.s = rtl->buf; val->len = len; @@ -1493,7 +1502,7 @@ static void rtl8366rb_switch_cleanup(struct rtl8366rb *rtl) static int rtl8366rb_mii_read(struct mii_bus *bus, int addr, int reg) { - struct rtl8366rb *rtl = bus->priv; + struct rtl8366rb *rtl = smi_to_rtl8366rb(bus->priv); u32 val = 0; int err; @@ -1506,7 +1515,7 @@ static int rtl8366rb_mii_read(struct mii_bus *bus, int addr, int reg) static int rtl8366rb_mii_write(struct mii_bus *bus, int addr, int reg, u16 val) { - struct rtl8366rb *rtl = bus->priv; + struct rtl8366rb *rtl = smi_to_rtl8366rb(bus->priv); u32 t; int err; @@ -1517,63 +1526,33 @@ static int rtl8366rb_mii_write(struct mii_bus *bus, int addr, int reg, u16 val) return err; } -static int rtl8366rb_mii_init(struct rtl8366rb *rtl) +static int rtl8366rb_mii_bus_match(struct mii_bus *bus) { - int ret; - int i; + return (bus->read == rtl8366rb_mii_read && + bus->write == rtl8366rb_mii_write); +} - rtl->mii_bus = mdiobus_alloc(); - if (rtl->mii_bus == NULL) { - ret = -ENOMEM; - goto err; - } +static int rtl8366rb_setup(struct rtl8366rb *rtl) +{ + int ret; - rtl->mii_bus->priv = (void *) rtl; - rtl->mii_bus->name = "rtl8366-rtl"; - rtl->mii_bus->read = rtl8366rb_mii_read; - rtl->mii_bus->write = rtl8366rb_mii_write; - snprintf(rtl->mii_bus->id, MII_BUS_ID_SIZE, "%s", - dev_name(rtl->parent)); - rtl->mii_bus->parent = rtl->parent; - rtl->mii_bus->phy_mask = ~(0x1f); - rtl->mii_bus->irq = rtl->mii_irq; - for (i = 0; i < PHY_MAX_ADDR; i++) - rtl->mii_irq[i] = PHY_POLL; - - ret = mdiobus_register(rtl->mii_bus); + ret = rtl8366rb_reset_chip(rtl); if (ret) - goto err_free; + return ret; + rtl8366rb_debugfs_init(rtl); return 0; - - err_free: - mdiobus_free(rtl->mii_bus); - err: - return ret; -} - -static void rtl8366rb_mii_cleanup(struct rtl8366rb *rtl) -{ - mdiobus_unregister(rtl->mii_bus); - mdiobus_free(rtl->mii_bus); } -static int rtl8366rb_mii_bus_match(struct mii_bus *bus) +static int rtl8366rb_detect(struct rtl8366_smi *smi) { - return (bus->read == rtl8366rb_mii_read && - bus->write == rtl8366rb_mii_write); -} - -static int rtl8366rb_setup(struct rtl8366rb *rtl) -{ - struct rtl8366_smi *smi = &rtl->smi; u32 chip_id = 0; u32 chip_ver = 0; int ret; ret = rtl8366_smi_read_reg(smi, RTL8366S_CHIP_ID_REG, &chip_id); if (ret) { - dev_err(rtl->parent, "unable to read chip id\n"); + dev_err(smi->parent, "unable to read chip id\n"); return ret; } @@ -1581,28 +1560,29 @@ static int rtl8366rb_setup(struct rtl8366rb *rtl) case RTL8366S_CHIP_ID_8366: break; default: - dev_err(rtl->parent, "unknown chip id (%04x)\n", chip_id); + dev_err(smi->parent, "unknown chip id (%04x)\n", chip_id); return -ENODEV; } ret = rtl8366_smi_read_reg(smi, RTL8366S_CHIP_VERSION_CTRL_REG, &chip_ver); if (ret) { - dev_err(rtl->parent, "unable to read chip version\n"); + dev_err(smi->parent, "unable to read chip version\n"); return ret; } - dev_info(rtl->parent, "RTL%04x ver. %u chip found\n", + dev_info(smi->parent, "RTL%04x ver. %u chip found\n", chip_id, chip_ver & RTL8366S_CHIP_VERSION_MASK); - ret = rtl8366rb_reset_chip(rtl); - if (ret) - return ret; - - rtl8366rb_debugfs_init(rtl); return 0; } +static struct rtl8366_smi_ops rtl8366rb_smi_ops = { + .detect = rtl8366rb_detect, + .mii_read = rtl8366rb_mii_read, + .mii_write = rtl8366rb_mii_write, +}; + static int __init rtl8366rb_probe(struct platform_device *pdev) { static int rtl8366_smi_version_printed; @@ -1635,6 +1615,7 @@ static int __init rtl8366rb_probe(struct platform_device *pdev) smi->parent = &pdev->dev; smi->gpio_sda = pdata->gpio_sda; smi->gpio_sck = pdata->gpio_sck; + smi->ops = &rtl8366rb_smi_ops; err = rtl8366_smi_init(smi); if (err) @@ -1646,18 +1627,12 @@ static int __init rtl8366rb_probe(struct platform_device *pdev) if (err) goto err_clear_drvdata; - err = rtl8366rb_mii_init(rtl); - if (err) - goto err_clear_drvdata; - err = rtl8366rb_switch_init(rtl); if (err) - goto err_mii_cleanup; + goto err_clear_drvdata; return 0; - err_mii_cleanup: - rtl8366rb_mii_cleanup(rtl); err_clear_drvdata: platform_set_drvdata(pdev, NULL); rtl8366_smi_cleanup(smi); @@ -1700,7 +1675,6 @@ static int __devexit rtl8366rb_remove(struct platform_device *pdev) if (rtl) { rtl8366rb_switch_cleanup(rtl); rtl8366rb_debugfs_remove(rtl); - rtl8366rb_mii_cleanup(rtl); platform_set_drvdata(pdev, NULL); rtl8366_smi_cleanup(&rtl->smi); kfree(rtl);