diff options
author | Ingo Molnar <mingo@elte.hu> | 2010-04-02 20:02:55 +0200 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-04-02 20:03:08 +0200 |
commit | c9494727cf293ae2ec66af57547a3e79c724fec2 (patch) | |
tree | 44ae197b64fa7530ee695a90ad31326dda06f1e1 /drivers/net/usb/asix.c | |
parent | 6427462bfa50f50dc6c088c07037264fcc73eca1 (diff) | |
parent | 42be79e37e264557f12860fa4cc84b4de3685954 (diff) |
Merge branch 'linus' into sched/core
Merge reason: update to latest upstream
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'drivers/net/usb/asix.c')
-rw-r--r-- | drivers/net/usb/asix.c | 147 |
1 files changed, 89 insertions, 58 deletions
diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c index a516185cbc9..9e05639435f 100644 --- a/drivers/net/usb/asix.c +++ b/drivers/net/usb/asix.c @@ -54,6 +54,7 @@ static const char driver_name [] = "asix"; #define AX_CMD_WRITE_IPG0 0x12 #define AX_CMD_WRITE_IPG1 0x13 #define AX_CMD_READ_NODE_ID 0x13 +#define AX_CMD_WRITE_NODE_ID 0x14 #define AX_CMD_WRITE_IPG2 0x14 #define AX_CMD_WRITE_MULTI_FILTER 0x16 #define AX88172_CMD_READ_NODE_ID 0x17 @@ -165,6 +166,7 @@ static const char driver_name [] = "asix"; /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */ struct asix_data { u8 multi_filter[AX_MCAST_FILTER_SIZE]; + u8 mac_addr[ETH_ALEN]; u8 phymode; u8 ledmode; u8 eeprom_len; @@ -184,8 +186,8 @@ static int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, void *buf; int err = -ENOMEM; - devdbg(dev,"asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d", - cmd, value, index, size); + netdev_dbg(dev->net, "asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n", + cmd, value, index, size); buf = kmalloc(size, GFP_KERNEL); if (!buf) @@ -217,8 +219,8 @@ static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, void *buf = NULL; int err = -ENOMEM; - devdbg(dev,"asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d", - cmd, value, index, size); + netdev_dbg(dev->net, "asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n", + cmd, value, index, size); if (data) { buf = kmalloc(size, GFP_KERNEL); @@ -264,15 +266,15 @@ asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index, int status; struct urb *urb; - devdbg(dev,"asix_write_cmd_async() cmd=0x%02x value=0x%04x index=0x%04x size=%d", - cmd, value, index, size); + netdev_dbg(dev->net, "asix_write_cmd_async() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n", + cmd, value, index, size); if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) { - deverr(dev, "Error allocating URB in write_cmd_async!"); + netdev_err(dev->net, "Error allocating URB in write_cmd_async!\n"); return; } if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) { - deverr(dev, "Failed to allocate memory for control request"); + netdev_err(dev->net, "Failed to allocate memory for control request\n"); usb_free_urb(urb); return; } @@ -289,8 +291,8 @@ asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index, asix_async_cmd_callback, req); if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { - deverr(dev, "Error submitting the control message: status=%d", - status); + netdev_err(dev->net, "Error submitting the control message: status=%d\n", + status); kfree(req); usb_free_urb(urb); } @@ -314,7 +316,7 @@ static int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb) while (skb->len > 0) { if ((short)(header & 0x0000ffff) != ~((short)((header & 0xffff0000) >> 16))) { - deverr(dev,"asix_rx_fixup() Bad Header Length"); + netdev_err(dev->net, "asix_rx_fixup() Bad Header Length\n"); } /* get the packet length */ size = (u16) (header & 0x0000ffff); @@ -322,7 +324,8 @@ static int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb) if ((skb->len) - ((size + 1) & 0xfffe) == 0) return 2; if (size > ETH_FRAME_LEN) { - deverr(dev,"asix_rx_fixup() Bad RX Length %d", size); + netdev_err(dev->net, "asix_rx_fixup() Bad RX Length %d\n", + size); return 0; } ax_skb = skb_clone(skb, GFP_ATOMIC); @@ -348,7 +351,8 @@ static int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb) } if (skb->len < 0) { - deverr(dev,"asix_rx_fixup() Bad SKB Length %d", skb->len); + netdev_err(dev->net, "asix_rx_fixup() Bad SKB Length %d\n", + skb->len); return 0; } return 1; @@ -409,7 +413,7 @@ static void asix_status(struct usbnet *dev, struct urb *urb) usbnet_defer_kevent (dev, EVENT_LINK_RESET ); } else netif_carrier_off(dev->net); - devdbg(dev, "Link Status is: %d", link); + netdev_dbg(dev->net, "Link Status is: %d\n", link); } } @@ -418,7 +422,7 @@ static inline int asix_set_sw_mii(struct usbnet *dev) int ret; ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL); if (ret < 0) - deverr(dev, "Failed to enable software MII access"); + netdev_err(dev->net, "Failed to enable software MII access\n"); return ret; } @@ -427,7 +431,7 @@ static inline int asix_set_hw_mii(struct usbnet *dev) int ret; ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL); if (ret < 0) - deverr(dev, "Failed to enable hardware MII access"); + netdev_err(dev->net, "Failed to enable hardware MII access\n"); return ret; } @@ -436,13 +440,14 @@ static inline int asix_get_phy_addr(struct usbnet *dev) u8 buf[2]; int ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf); - devdbg(dev, "asix_get_phy_addr()"); + netdev_dbg(dev->net, "asix_get_phy_addr()\n"); if (ret < 0) { - deverr(dev, "Error reading PHYID register: %02x", ret); + netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret); goto out; } - devdbg(dev, "asix_get_phy_addr() returning 0x%04x", *((__le16 *)buf)); + netdev_dbg(dev->net, "asix_get_phy_addr() returning 0x%04x\n", + *((__le16 *)buf)); ret = buf[1]; out: @@ -455,7 +460,7 @@ static int asix_sw_reset(struct usbnet *dev, u8 flags) ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL); if (ret < 0) - deverr(dev,"Failed to send software reset: %02x", ret); + netdev_err(dev->net, "Failed to send software reset: %02x\n", ret); return ret; } @@ -466,7 +471,7 @@ static u16 asix_read_rx_ctl(struct usbnet *dev) int ret = asix_read_cmd(dev, AX_CMD_READ_RX_CTL, 0, 0, 2, &v); if (ret < 0) { - deverr(dev, "Error reading RX_CTL register: %02x", ret); + netdev_err(dev->net, "Error reading RX_CTL register: %02x\n", ret); goto out; } ret = le16_to_cpu(v); @@ -478,11 +483,11 @@ static int asix_write_rx_ctl(struct usbnet *dev, u16 mode) { int ret; - devdbg(dev,"asix_write_rx_ctl() - mode = 0x%04x", mode); + netdev_dbg(dev->net, "asix_write_rx_ctl() - mode = 0x%04x\n", mode); ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL); if (ret < 0) - deverr(dev, "Failed to write RX_CTL mode to 0x%04x: %02x", - mode, ret); + netdev_err(dev->net, "Failed to write RX_CTL mode to 0x%04x: %02x\n", + mode, ret); return ret; } @@ -493,7 +498,8 @@ static u16 asix_read_medium_status(struct usbnet *dev) int ret = asix_read_cmd(dev, AX_CMD_READ_MEDIUM_STATUS, 0, 0, 2, &v); if (ret < 0) { - deverr(dev, "Error reading Medium Status register: %02x", ret); + netdev_err(dev->net, "Error reading Medium Status register: %02x\n", + ret); goto out; } ret = le16_to_cpu(v); @@ -505,11 +511,11 @@ static int asix_write_medium_mode(struct usbnet *dev, u16 mode) { int ret; - devdbg(dev,"asix_write_medium_mode() - mode = 0x%04x", mode); + netdev_dbg(dev->net, "asix_write_medium_mode() - mode = 0x%04x\n", mode); ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); if (ret < 0) - deverr(dev, "Failed to write Medium Mode mode to 0x%04x: %02x", - mode, ret); + netdev_err(dev->net, "Failed to write Medium Mode mode to 0x%04x: %02x\n", + mode, ret); return ret; } @@ -518,11 +524,11 @@ static int asix_write_gpio(struct usbnet *dev, u16 value, int sleep) { int ret; - devdbg(dev,"asix_write_gpio() - value = 0x%04x", value); + netdev_dbg(dev->net, "asix_write_gpio() - value = 0x%04x\n", value); ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS, value, 0, 0, NULL); if (ret < 0) - deverr(dev, "Failed to write GPIO value 0x%04x: %02x", - value, ret); + netdev_err(dev->net, "Failed to write GPIO value 0x%04x: %02x\n", + value, ret); if (sleep) msleep(sleep); @@ -542,29 +548,27 @@ static void asix_set_multicast(struct net_device *net) if (net->flags & IFF_PROMISC) { rx_ctl |= AX_RX_CTL_PRO; } else if (net->flags & IFF_ALLMULTI || - net->mc_count > AX_MAX_MCAST) { + netdev_mc_count(net) > AX_MAX_MCAST) { rx_ctl |= AX_RX_CTL_AMALL; - } else if (net->mc_count == 0) { + } else if (netdev_mc_empty(net)) { /* just broadcast and directed */ } else { /* We use the 20 byte dev->data * for our 8 byte filter buffer * to avoid allocating memory that * is tricky to free later */ - struct dev_mc_list *mc_list = net->mc_list; + struct dev_mc_list *mc_list; u32 crc_bits; - int i; memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE); /* Build the multicast hash filter. */ - for (i = 0; i < net->mc_count; i++) { + netdev_for_each_mc_addr(mc_list, net) { crc_bits = ether_crc(ETH_ALEN, mc_list->dmi_addr) >> 26; data->multi_filter[crc_bits >> 3] |= 1 << (crc_bits & 7); - mc_list = mc_list->next; } asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0, @@ -588,7 +592,8 @@ static int asix_mdio_read(struct net_device *netdev, int phy_id, int loc) asix_set_hw_mii(dev); mutex_unlock(&dev->phy_mutex); - devdbg(dev, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x", phy_id, loc, le16_to_cpu(res)); + netdev_dbg(dev->net, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n", + phy_id, loc, le16_to_cpu(res)); return le16_to_cpu(res); } @@ -599,7 +604,8 @@ asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) struct usbnet *dev = netdev_priv(netdev); __le16 res = cpu_to_le16(val); - devdbg(dev, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x", phy_id, loc, val); + netdev_dbg(dev->net, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n", + phy_id, loc, val); mutex_lock(&dev->phy_mutex); asix_set_sw_mii(dev); asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, &res); @@ -728,6 +734,30 @@ static int asix_ioctl (struct net_device *net, struct ifreq *rq, int cmd) return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); } +static int asix_set_mac_address(struct net_device *net, void *p) +{ + struct usbnet *dev = netdev_priv(net); + struct asix_data *data = (struct asix_data *)&dev->data; + struct sockaddr *addr = p; + + if (netif_running(net)) + return -EBUSY; + if (!is_valid_ether_addr(addr->sa_data)) + return -EADDRNOTAVAIL; + + memcpy(net->dev_addr, addr->sa_data, ETH_ALEN); + + /* We use the 20 byte dev->data + * for our 6 byte mac buffer + * to avoid allocating memory that + * is tricky to free later */ + memcpy(data->mac_addr, addr->sa_data, ETH_ALEN); + asix_write_cmd_async(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN, + data->mac_addr); + + return 0; +} + /* We need to override some ethtool_ops so we require our own structure so we don't interfere with other usbnet devices that may be connected at the same time. */ @@ -754,29 +784,27 @@ static void ax88172_set_multicast(struct net_device *net) if (net->flags & IFF_PROMISC) { rx_ctl |= 0x01; } else if (net->flags & IFF_ALLMULTI || - net->mc_count > AX_MAX_MCAST) { + netdev_mc_count(net) > AX_MAX_MCAST) { rx_ctl |= 0x02; - } else if (net->mc_count == 0) { + } else if (netdev_mc_empty(net)) { /* just broadcast and directed */ } else { /* We use the 20 byte dev->data * for our 8 byte filter buffer * to avoid allocating memory that * is tricky to free later */ - struct dev_mc_list *mc_list = net->mc_list; + struct dev_mc_list *mc_list; u32 crc_bits; - int i; memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE); /* Build the multicast hash filter. */ - for (i = 0; i < net->mc_count; i++) { + netdev_for_each_mc_addr(mc_list, net) { crc_bits = ether_crc(ETH_ALEN, mc_list->dmi_addr) >> 26; data->multi_filter[crc_bits >> 3] |= 1 << (crc_bits & 7); - mc_list = mc_list->next; } asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0, @@ -800,7 +828,8 @@ static int ax88172_link_reset(struct usbnet *dev) if (ecmd.duplex != DUPLEX_FULL) mode |= ~AX88172_MEDIUM_FD; - devdbg(dev, "ax88172_link_reset() speed: %d duplex: %d setting mode to 0x%04x", ecmd.speed, ecmd.duplex, mode); + netdev_dbg(dev->net, "ax88172_link_reset() speed: %d duplex: %d setting mode to 0x%04x\n", + ecmd.speed, ecmd.duplex, mode); asix_write_medium_mode(dev, mode); @@ -902,7 +931,8 @@ static int ax88772_link_reset(struct usbnet *dev) if (ecmd.duplex != DUPLEX_FULL) mode &= ~AX_MEDIUM_FD; - devdbg(dev, "ax88772_link_reset() speed: %d duplex: %d setting mode to 0x%04x", ecmd.speed, ecmd.duplex, mode); + netdev_dbg(dev->net, "ax88772_link_reset() speed: %d duplex: %d setting mode to 0x%04x\n", + ecmd.speed, ecmd.duplex, mode); asix_write_medium_mode(dev, mode); @@ -915,7 +945,7 @@ static const struct net_device_ops ax88772_netdev_ops = { .ndo_start_xmit = usbnet_start_xmit, .ndo_tx_timeout = usbnet_tx_timeout, .ndo_change_mtu = usbnet_change_mtu, - .ndo_set_mac_address = eth_mac_addr, + .ndo_set_mac_address = asix_set_mac_address, .ndo_validate_addr = eth_validate_addr, .ndo_do_ioctl = asix_ioctl, .ndo_set_multicast_list = asix_set_multicast, @@ -1059,10 +1089,10 @@ static int marvell_phy_init(struct usbnet *dev) struct asix_data *data = (struct asix_data *)&dev->data; u16 reg; - devdbg(dev,"marvell_phy_init()"); + netdev_dbg(dev->net, "marvell_phy_init()\n"); reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_MARVELL_STATUS); - devdbg(dev,"MII_MARVELL_STATUS = 0x%04x", reg); + netdev_dbg(dev->net, "MII_MARVELL_STATUS = 0x%04x\n", reg); asix_mdio_write(dev->net, dev->mii.phy_id, MII_MARVELL_CTRL, MARVELL_CTRL_RXDELAY | MARVELL_CTRL_TXDELAY); @@ -1070,7 +1100,7 @@ static int marvell_phy_init(struct usbnet *dev) if (data->ledmode) { reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_MARVELL_LED_CTRL); - devdbg(dev,"MII_MARVELL_LED_CTRL (1) = 0x%04x", reg); + netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (1) = 0x%04x\n", reg); reg &= 0xf8ff; reg |= (1 + 0x0100); @@ -1079,7 +1109,7 @@ static int marvell_phy_init(struct usbnet *dev) reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_MARVELL_LED_CTRL); - devdbg(dev,"MII_MARVELL_LED_CTRL (2) = 0x%04x", reg); + netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (2) = 0x%04x\n", reg); reg &= 0xfc0f; } @@ -1090,7 +1120,7 @@ static int marvell_led_status(struct usbnet *dev, u16 speed) { u16 reg = asix_mdio_read(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL); - devdbg(dev, "marvell_led_status() read 0x%04x", reg); + netdev_dbg(dev->net, "marvell_led_status() read 0x%04x\n", reg); /* Clear out the center LED bits - 0x03F0 */ reg &= 0xfc0f; @@ -1106,7 +1136,7 @@ static int marvell_led_status(struct usbnet *dev, u16 speed) reg |= 0x02f0; } - devdbg(dev, "marvell_led_status() writing 0x%04x", reg); + netdev_dbg(dev->net, "marvell_led_status() writing 0x%04x\n", reg); asix_mdio_write(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL, reg); return 0; @@ -1118,7 +1148,7 @@ static int ax88178_link_reset(struct usbnet *dev) struct ethtool_cmd ecmd; struct asix_data *data = (struct asix_data *)&dev->data; - devdbg(dev,"ax88178_link_reset()"); + netdev_dbg(dev->net, "ax88178_link_reset()\n"); mii_check_media(&dev->mii, 1, 1); mii_ethtool_gset(&dev->mii, &ecmd); @@ -1138,7 +1168,8 @@ static int ax88178_link_reset(struct usbnet *dev) else mode &= ~AX_MEDIUM_FD; - devdbg(dev, "ax88178_link_reset() speed: %d duplex: %d setting mode to 0x%04x", ecmd.speed, ecmd.duplex, mode); + netdev_dbg(dev->net, "ax88178_link_reset() speed: %d duplex: %d setting mode to 0x%04x\n", + ecmd.speed, ecmd.duplex, mode); asix_write_medium_mode(dev, mode); @@ -1188,7 +1219,7 @@ static int ax88178_change_mtu(struct net_device *net, int new_mtu) struct usbnet *dev = netdev_priv(net); int ll_mtu = new_mtu + net->hard_header_len + 4; - devdbg(dev, "ax88178_change_mtu() new_mtu=%d", new_mtu); + netdev_dbg(dev->net, "ax88178_change_mtu() new_mtu=%d\n", new_mtu); if (new_mtu <= 0 || ll_mtu > 16384) return -EINVAL; @@ -1208,7 +1239,7 @@ static const struct net_device_ops ax88178_netdev_ops = { .ndo_stop = usbnet_stop, .ndo_start_xmit = usbnet_start_xmit, .ndo_tx_timeout = usbnet_tx_timeout, - .ndo_set_mac_address = eth_mac_addr, + .ndo_set_mac_address = asix_set_mac_address, .ndo_validate_addr = eth_validate_addr, .ndo_set_multicast_list = asix_set_multicast, .ndo_do_ioctl = asix_ioctl, |