diff options
Diffstat (limited to 'drivers/net/usb/asix.c')
-rw-r--r-- | drivers/net/usb/asix.c | 148 |
1 files changed, 90 insertions, 58 deletions
diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c index a516185cbc9f..35f56fc82803 100644 --- a/drivers/net/usb/asix.c +++ b/drivers/net/usb/asix.c @@ -34,6 +34,7 @@ #include <linux/usb.h> #include <linux/crc32.h> #include <linux/usb/usbnet.h> +#include <linux/slab.h> #define DRIVER_VERSION "14-Jun-2006" static const char driver_name [] = "asix"; @@ -54,6 +55,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 +167,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 +187,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 +220,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 +267,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 +292,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 +317,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 +325,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 +352,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 +414,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 +423,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 +432,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 +441,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 +461,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 +472,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 +484,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 +499,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 +512,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 +525,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 +549,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 +593,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 +605,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 +735,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 +785,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 +829,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 +932,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 +946,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 +1090,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 +1101,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 +1110,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 +1121,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 +1137,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 +1149,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 +1169,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 +1220,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 +1240,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, |