aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/net
diff options
context:
space:
mode:
authorDavid Hollis <dhollis@davehollis.com>2006-03-28 20:15:42 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-04-14 14:12:25 -0400
commit48b1be6ac080c3bb5ad3e529d8816953507790ab (patch)
treefa98953652478127067380c23e1ed7cd91a65a8b /drivers/usb/net
parent9fc4831cc3e063019079581ff5062f9790d9b0c7 (diff)
[PATCH] USB: Rename ax8817x_func() to asix_func() and add utility functions to reduce bloat
Now that the ASIX code is supporting more than just the AX88172 devices, make the utility function names more generic: ax8817x_func -> asix_func. Functions that are chip specific now indicate as such: ax88772_func. Additionally, pull some common routines used in initialization and such into simple functions to reduce the verbosity of certain functions such as the bind() routines and to make the error handling consistent across the board. Signed-off-by: David Hollis <dhollis@davehollis.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/net')
-rw-r--r--drivers/usb/net/asix.c327
1 files changed, 163 insertions, 164 deletions
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c
index 3094970615c..12b599a0b53 100644
--- a/drivers/usb/net/asix.c
+++ b/drivers/usb/net/asix.c
@@ -37,7 +37,6 @@
37 37
38#include "usbnet.h" 38#include "usbnet.h"
39 39
40
41/* ASIX AX8817X based USB 2.0 Ethernet Devices */ 40/* ASIX AX8817X based USB 2.0 Ethernet Devices */
42 41
43#define AX_CMD_SET_SW_MII 0x06 42#define AX_CMD_SET_SW_MII 0x06
@@ -109,7 +108,7 @@
109#define AX_EEPROM_MAGIC 0xdeadbeef 108#define AX_EEPROM_MAGIC 0xdeadbeef
110 109
111/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */ 110/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
112struct ax8817x_data { 111struct asix_data {
113 u8 multi_filter[AX_MCAST_FILTER_SIZE]; 112 u8 multi_filter[AX_MCAST_FILTER_SIZE];
114}; 113};
115 114
@@ -121,7 +120,7 @@ struct ax88172_int_data {
121 u16 res3; 120 u16 res3;
122} __attribute__ ((packed)); 121} __attribute__ ((packed));
123 122
124static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 123static int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
125 u16 size, void *data) 124 u16 size, void *data)
126{ 125{
127 return usb_control_msg( 126 return usb_control_msg(
@@ -136,7 +135,7 @@ static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
136 USB_CTRL_GET_TIMEOUT); 135 USB_CTRL_GET_TIMEOUT);
137} 136}
138 137
139static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 138static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
140 u16 size, void *data) 139 u16 size, void *data)
141{ 140{
142 return usb_control_msg( 141 return usb_control_msg(
@@ -151,19 +150,80 @@ static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
151 USB_CTRL_SET_TIMEOUT); 150 USB_CTRL_SET_TIMEOUT);
152} 151}
153 152
154static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs) 153static void asix_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
155{ 154{
156 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; 155 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
157 156
158 if (urb->status < 0) 157 if (urb->status < 0)
159 printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d", 158 printk(KERN_DEBUG "asix_async_cmd_callback() failed with %d",
160 urb->status); 159 urb->status);
161 160
162 kfree(req); 161 kfree(req);
163 usb_free_urb(urb); 162 usb_free_urb(urb);
164} 163}
165 164
166static void ax8817x_status(struct usbnet *dev, struct urb *urb) 165static inline int asix_set_sw_mii(struct usbnet *dev)
166{
167 int ret;
168 ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
169 if (ret < 0)
170 devdbg(dev, "Failed to enable software MII access");
171 return ret;
172}
173
174static inline int asix_set_hw_mii(struct usbnet *dev)
175{
176 int ret;
177 ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
178 if (ret < 0)
179 devdbg(dev, "Failed to enable hardware MII access");
180 return ret;
181}
182
183static inline int asix_get_phyid(struct usbnet *dev)
184{
185 int ret = 0;
186 void *buf;
187
188 buf = kmalloc(2, GFP_KERNEL);
189 if (!buf)
190 goto out1;
191
192 if ((ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID,
193 0, 0, 2, buf)) < 2) {
194 devdbg(dev, "Error reading PHYID register: %02x", ret);
195 goto out2;
196 }
197 ret = *((u8 *)buf + 1);
198out2:
199 kfree(buf);
200out1:
201 return ret;
202}
203
204static int asix_sw_reset(struct usbnet *dev, u8 flags)
205{
206 int ret;
207
208 ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL);
209 if (ret < 0)
210 devdbg(dev,"Failed to send software reset: %02x", ret);
211
212 return ret;
213}
214
215static int asix_write_rx_ctl(struct usbnet *dev, u16 mode)
216{
217 int ret;
218
219 ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
220 if (ret < 0)
221 devdbg(dev, "Failed to write RX_CTL mode: %02x", ret);
222
223 return ret;
224}
225
226static void asix_status(struct usbnet *dev, struct urb *urb)
167{ 227{
168 struct ax88172_int_data *event; 228 struct ax88172_int_data *event;
169 int link; 229 int link;
@@ -179,12 +239,12 @@ static void ax8817x_status(struct usbnet *dev, struct urb *urb)
179 usbnet_defer_kevent (dev, EVENT_LINK_RESET ); 239 usbnet_defer_kevent (dev, EVENT_LINK_RESET );
180 } else 240 } else
181 netif_carrier_off(dev->net); 241 netif_carrier_off(dev->net);
182 devdbg(dev, "ax8817x - Link Status is: %d", link); 242 devdbg(dev, "Link Status is: %d", link);
183 } 243 }
184} 244}
185 245
186static void 246static void
187ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index, 247asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
188 u16 size, void *data) 248 u16 size, void *data)
189{ 249{
190 struct usb_ctrlrequest *req; 250 struct usb_ctrlrequest *req;
@@ -211,7 +271,7 @@ ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
211 usb_fill_control_urb(urb, dev->udev, 271 usb_fill_control_urb(urb, dev->udev,
212 usb_sndctrlpipe(dev->udev, 0), 272 usb_sndctrlpipe(dev->udev, 0),
213 (void *)req, data, size, 273 (void *)req, data, size,
214 ax8817x_async_cmd_callback, req); 274 asix_async_cmd_callback, req);
215 275
216 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 276 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
217 deverr(dev, "Error submitting the control message: status=%d", 277 deverr(dev, "Error submitting the control message: status=%d",
@@ -221,10 +281,10 @@ ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
221 } 281 }
222} 282}
223 283
224static void ax8817x_set_multicast(struct net_device *net) 284static void asix_set_multicast(struct net_device *net)
225{ 285{
226 struct usbnet *dev = netdev_priv(net); 286 struct usbnet *dev = netdev_priv(net);
227 struct ax8817x_data *data = (struct ax8817x_data *)&dev->data; 287 struct asix_data *data = (struct asix_data *)&dev->data;
228 u8 rx_ctl = 0x8c; 288 u8 rx_ctl = 0x8c;
229 289
230 if (net->flags & IFF_PROMISC) { 290 if (net->flags & IFF_PROMISC) {
@@ -255,53 +315,51 @@ static void ax8817x_set_multicast(struct net_device *net)
255 mc_list = mc_list->next; 315 mc_list = mc_list->next;
256 } 316 }
257 317
258 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0, 318 asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
259 AX_MCAST_FILTER_SIZE, data->multi_filter); 319 AX_MCAST_FILTER_SIZE, data->multi_filter);
260 320
261 rx_ctl |= 0x10; 321 rx_ctl |= 0x10;
262 } 322 }
263 323
264 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL); 324 asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
265} 325}
266 326
267static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc) 327static int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
268{ 328{
269 struct usbnet *dev = netdev_priv(netdev); 329 struct usbnet *dev = netdev_priv(netdev);
270 u16 res; 330 u16 res;
271 u8 buf[1];
272 331
273 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); 332 asix_set_sw_mii(dev);
274 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, 333 asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
275 (__u16)loc, 2, (u16 *)&res); 334 (__u16)loc, 2, (u16 *)&res);
276 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); 335 asix_set_hw_mii(dev);
277 336
278 return res & 0xffff; 337 return res & 0xffff;
279} 338}
280 339
281/* same as above, but converts resulting value to cpu byte order */ 340/* same as above, but converts resulting value to cpu byte order */
282static int ax8817x_mdio_read_le(struct net_device *netdev, int phy_id, int loc) 341static int asix_mdio_read_le(struct net_device *netdev, int phy_id, int loc)
283{ 342{
284 return le16_to_cpu(ax8817x_mdio_read(netdev,phy_id, loc)); 343 return le16_to_cpu(asix_mdio_read(netdev,phy_id, loc));
285} 344}
286 345
287static void 346static void
288ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) 347asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
289{ 348{
290 struct usbnet *dev = netdev_priv(netdev); 349 struct usbnet *dev = netdev_priv(netdev);
291 u16 res = val; 350 u16 res = val;
292 u8 buf[1];
293 351
294 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); 352 asix_set_sw_mii(dev);
295 ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, 353 asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id,
296 (__u16)loc, 2, (u16 *)&res); 354 (__u16)loc, 2, (u16 *)&res);
297 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); 355 asix_set_hw_mii(dev);
298} 356}
299 357
300/* same as above, but converts new value to le16 byte order before writing */ 358/* same as above, but converts new value to le16 byte order before writing */
301static void 359static void
302ax8817x_mdio_write_le(struct net_device *netdev, int phy_id, int loc, int val) 360asix_mdio_write_le(struct net_device *netdev, int phy_id, int loc, int val)
303{ 361{
304 ax8817x_mdio_write( netdev, phy_id, loc, cpu_to_le16(val) ); 362 asix_mdio_write( netdev, phy_id, loc, cpu_to_le16(val) );
305} 363}
306 364
307static int ax88172_link_reset(struct usbnet *dev) 365static int ax88172_link_reset(struct usbnet *dev)
@@ -312,23 +370,23 @@ static int ax88172_link_reset(struct usbnet *dev)
312 u8 mode; 370 u8 mode;
313 371
314 mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN; 372 mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN;
315 lpa = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA); 373 lpa = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA);
316 adv = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE); 374 adv = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE);
317 res = mii_nway_result(lpa|adv); 375 res = mii_nway_result(lpa|adv);
318 if (res & LPA_DUPLEX) 376 if (res & LPA_DUPLEX)
319 mode |= AX_MEDIUM_FULL_DUPLEX; 377 mode |= AX_MEDIUM_FULL_DUPLEX;
320 ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); 378 asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
321 379
322 return 0; 380 return 0;
323} 381}
324 382
325static void 383static void
326ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) 384asix_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
327{ 385{
328 struct usbnet *dev = netdev_priv(net); 386 struct usbnet *dev = netdev_priv(net);
329 u8 opt; 387 u8 opt;
330 388
331 if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) { 389 if (asix_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
332 wolinfo->supported = 0; 390 wolinfo->supported = 0;
333 wolinfo->wolopts = 0; 391 wolinfo->wolopts = 0;
334 return; 392 return;
@@ -344,7 +402,7 @@ ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
344} 402}
345 403
346static int 404static int
347ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) 405asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
348{ 406{
349 struct usbnet *dev = netdev_priv(net); 407 struct usbnet *dev = netdev_priv(net);
350 u8 opt = 0; 408 u8 opt = 0;
@@ -357,19 +415,19 @@ ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
357 if (opt != 0) 415 if (opt != 0)
358 opt |= AX_MONITOR_MODE; 416 opt |= AX_MONITOR_MODE;
359 417
360 if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE, 418 if (asix_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
361 opt, 0, 0, &buf) < 0) 419 opt, 0, 0, &buf) < 0)
362 return -EINVAL; 420 return -EINVAL;
363 421
364 return 0; 422 return 0;
365} 423}
366 424
367static int ax8817x_get_eeprom_len(struct net_device *net) 425static int asix_get_eeprom_len(struct net_device *net)
368{ 426{
369 return AX_EEPROM_LEN; 427 return AX_EEPROM_LEN;
370} 428}
371 429
372static int ax8817x_get_eeprom(struct net_device *net, 430static int asix_get_eeprom(struct net_device *net,
373 struct ethtool_eeprom *eeprom, u8 *data) 431 struct ethtool_eeprom *eeprom, u8 *data)
374{ 432{
375 struct usbnet *dev = netdev_priv(net); 433 struct usbnet *dev = netdev_priv(net);
@@ -386,14 +444,14 @@ static int ax8817x_get_eeprom(struct net_device *net,
386 444
387 /* ax8817x returns 2 bytes from eeprom on read */ 445 /* ax8817x returns 2 bytes from eeprom on read */
388 for (i=0; i < eeprom->len / 2; i++) { 446 for (i=0; i < eeprom->len / 2; i++) {
389 if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM, 447 if (asix_read_cmd(dev, AX_CMD_READ_EEPROM,
390 eeprom->offset + i, 0, 2, &ebuf[i]) < 0) 448 eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
391 return -EINVAL; 449 return -EINVAL;
392 } 450 }
393 return 0; 451 return 0;
394} 452}
395 453
396static void ax8817x_get_drvinfo (struct net_device *net, 454static void asix_get_drvinfo (struct net_device *net,
397 struct ethtool_drvinfo *info) 455 struct ethtool_drvinfo *info)
398{ 456{
399 /* Inherit standard device info */ 457 /* Inherit standard device info */
@@ -401,14 +459,14 @@ static void ax8817x_get_drvinfo (struct net_device *net,
401 info->eedump_len = 0x3e; 459 info->eedump_len = 0x3e;
402} 460}
403 461
404static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd) 462static int asix_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
405{ 463{
406 struct usbnet *dev = netdev_priv(net); 464 struct usbnet *dev = netdev_priv(net);
407 465
408 return mii_ethtool_gset(&dev->mii,cmd); 466 return mii_ethtool_gset(&dev->mii,cmd);
409} 467}
410 468
411static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd) 469static int asix_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
412{ 470{
413 struct usbnet *dev = netdev_priv(net); 471 struct usbnet *dev = netdev_priv(net);
414 472
@@ -418,27 +476,27 @@ static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
418/* We need to override some ethtool_ops so we require our 476/* We need to override some ethtool_ops so we require our
419 own structure so we don't interfere with other usbnet 477 own structure so we don't interfere with other usbnet
420 devices that may be connected at the same time. */ 478 devices that may be connected at the same time. */
421static struct ethtool_ops ax8817x_ethtool_ops = { 479static struct ethtool_ops ax88172_ethtool_ops = {
422 .get_drvinfo = ax8817x_get_drvinfo, 480 .get_drvinfo = asix_get_drvinfo,
423 .get_link = ethtool_op_get_link, 481 .get_link = ethtool_op_get_link,
424 .get_msglevel = usbnet_get_msglevel, 482 .get_msglevel = usbnet_get_msglevel,
425 .set_msglevel = usbnet_set_msglevel, 483 .set_msglevel = usbnet_set_msglevel,
426 .get_wol = ax8817x_get_wol, 484 .get_wol = asix_get_wol,
427 .set_wol = ax8817x_set_wol, 485 .set_wol = asix_set_wol,
428 .get_eeprom_len = ax8817x_get_eeprom_len, 486 .get_eeprom_len = asix_get_eeprom_len,
429 .get_eeprom = ax8817x_get_eeprom, 487 .get_eeprom = asix_get_eeprom,
430 .get_settings = ax8817x_get_settings, 488 .get_settings = asix_get_settings,
431 .set_settings = ax8817x_set_settings, 489 .set_settings = asix_set_settings,
432}; 490};
433 491
434static int ax8817x_ioctl (struct net_device *net, struct ifreq *rq, int cmd) 492static int asix_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
435{ 493{
436 struct usbnet *dev = netdev_priv(net); 494 struct usbnet *dev = netdev_priv(net);
437 495
438 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); 496 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
439} 497}
440 498
441static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf) 499static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
442{ 500{
443 int ret = 0; 501 int ret = 0;
444 void *buf; 502 void *buf;
@@ -455,55 +513,39 @@ static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
455 513
456 /* Toggle the GPIOs in a manufacturer/model specific way */ 514 /* Toggle the GPIOs in a manufacturer/model specific way */
457 for (i = 2; i >= 0; i--) { 515 for (i = 2; i >= 0; i--) {
458 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, 516 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS,
459 (gpio_bits >> (i * 8)) & 0xff, 0, 0, 517 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
460 buf)) < 0) 518 buf)) < 0)
461 goto out2; 519 goto out2;
462 msleep(5); 520 msleep(5);
463 } 521 }
464 522
465 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 523 if ((ret = asix_write_rx_ctl(dev,0x80)) < 0)
466 0x80, 0, 0, buf)) < 0) {
467 dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
468 goto out2; 524 goto out2;
469 }
470 525
471 /* Get the MAC address */ 526 /* Get the MAC address */
472 memset(buf, 0, ETH_ALEN); 527 memset(buf, 0, ETH_ALEN);
473 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 528 if ((ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
474 0, 0, 6, buf)) < 0) { 529 0, 0, 6, buf)) < 0) {
475 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret); 530 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
476 goto out2; 531 goto out2;
477 } 532 }
478 memcpy(dev->net->dev_addr, buf, ETH_ALEN); 533 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
479 534
480 /* Get the PHY id */
481 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID,
482 0, 0, 2, buf)) < 0) {
483 dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
484 goto out2;
485 } else if (ret < 2) {
486 /* this should always return 2 bytes */
487 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x",
488 ret);
489 ret = -EIO;
490 goto out2;
491 }
492
493 /* Initialize MII structure */ 535 /* Initialize MII structure */
494 dev->mii.dev = dev->net; 536 dev->mii.dev = dev->net;
495 dev->mii.mdio_read = ax8817x_mdio_read; 537 dev->mii.mdio_read = asix_mdio_read;
496 dev->mii.mdio_write = ax8817x_mdio_write; 538 dev->mii.mdio_write = asix_mdio_write;
497 dev->mii.phy_id_mask = 0x3f; 539 dev->mii.phy_id_mask = 0x3f;
498 dev->mii.reg_num_mask = 0x1f; 540 dev->mii.reg_num_mask = 0x1f;
499 dev->mii.phy_id = *((u8 *)buf + 1); 541 dev->mii.phy_id = asix_get_phyid(dev);
500 dev->net->do_ioctl = ax8817x_ioctl; 542 dev->net->do_ioctl = asix_ioctl;
501 543
502 dev->net->set_multicast_list = ax8817x_set_multicast; 544 dev->net->set_multicast_list = asix_set_multicast;
503 dev->net->ethtool_ops = &ax8817x_ethtool_ops; 545 dev->net->ethtool_ops = &ax88172_ethtool_ops;
504 546
505 ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); 547 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
506 ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE, 548 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE,
507 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); 549 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
508 mii_nway_restart(&dev->mii); 550 mii_nway_restart(&dev->mii);
509 551
@@ -515,16 +557,16 @@ out1:
515} 557}
516 558
517static struct ethtool_ops ax88772_ethtool_ops = { 559static struct ethtool_ops ax88772_ethtool_ops = {
518 .get_drvinfo = ax8817x_get_drvinfo, 560 .get_drvinfo = asix_get_drvinfo,
519 .get_link = ethtool_op_get_link, 561 .get_link = ethtool_op_get_link,
520 .get_msglevel = usbnet_get_msglevel, 562 .get_msglevel = usbnet_get_msglevel,
521 .set_msglevel = usbnet_set_msglevel, 563 .set_msglevel = usbnet_set_msglevel,
522 .get_wol = ax8817x_get_wol, 564 .get_wol = asix_get_wol,
523 .set_wol = ax8817x_set_wol, 565 .set_wol = asix_set_wol,
524 .get_eeprom_len = ax8817x_get_eeprom_len, 566 .get_eeprom_len = asix_get_eeprom_len,
525 .get_eeprom = ax8817x_get_eeprom, 567 .get_eeprom = asix_get_eeprom,
526 .get_settings = ax8817x_get_settings, 568 .get_settings = asix_get_settings,
527 .set_settings = ax8817x_set_settings, 569 .set_settings = asix_set_settings,
528}; 570};
529 571
530static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) 572static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
@@ -541,62 +583,45 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
541 goto out1; 583 goto out1;
542 } 584 }
543 585
544 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, 586 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS,
545 0x00B0, 0, 0, buf)) < 0) 587 0x00B0, 0, 0, buf)) < 0)
546 goto out2; 588 goto out2;
547 589
548 msleep(5); 590 msleep(5);
549 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 591 if ((ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT,
550 0x0001, 0, 0, buf)) < 0) { 592 0x0001, 0, 0, buf)) < 0) {
551 dbg("Select PHY #1 failed: %d", ret); 593 dbg("Select PHY #1 failed: %d", ret);
552 goto out2; 594 goto out2;
553 } 595 }
554 596
555 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD, 597 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPPD)) < 0)
556 0, 0, buf)) < 0) {
557 dbg("Failed to power down internal PHY: %d", ret);
558 goto out2; 598 goto out2;
559 }
560 599
561 msleep(150); 600 msleep(150);
562 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, 601 if ((ret = asix_sw_reset(dev, AX_SWRESET_CLEAR)) < 0)
563 0, 0, buf)) < 0) {
564 dbg("Failed to perform software reset: %d", ret);
565 goto out2; 602 goto out2;
566 }
567 603
568 msleep(150); 604 msleep(150);
569 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, 605 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL)) < 0)
570 AX_SWRESET_IPRL | AX_SWRESET_PRL,
571 0, 0, buf)) < 0) {
572 dbg("Failed to set Internal/External PHY reset control: %d",
573 ret);
574 goto out2; 606 goto out2;
575 }
576 607
577 msleep(150); 608 msleep(150);
578 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 609 if ((ret = asix_write_rx_ctl(dev, 0x00)) < 0)
579 0x0000, 0, 0, buf)) < 0) {
580 dbg("Failed to reset RX_CTL: %d", ret);
581 goto out2; 610 goto out2;
582 }
583 611
584 /* Get the MAC address */ 612 /* Get the MAC address */
585 memset(buf, 0, ETH_ALEN); 613 memset(buf, 0, ETH_ALEN);
586 if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, 614 if ((ret = asix_read_cmd(dev, AX88772_CMD_READ_NODE_ID,
587 0, 0, ETH_ALEN, buf)) < 0) { 615 0, 0, ETH_ALEN, buf)) < 0) {
588 dbg("Failed to read MAC address: %d", ret); 616 dbg("Failed to read MAC address: %d", ret);
589 goto out2; 617 goto out2;
590 } 618 }
591 memcpy(dev->net->dev_addr, buf, ETH_ALEN); 619 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
592 620
593 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 621 if ((ret = asix_set_sw_mii(dev)) < 0)
594 0, 0, 0, buf)) < 0) {
595 dbg("Enabling software MII failed: %d", ret);
596 goto out2; 622 goto out2;
597 }
598 623
599 if (((ret = ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, 624 if (((ret = asix_read_cmd(dev, AX_CMD_READ_MII_REG,
600 0x0010, 2, 2, buf)) < 0) 625 0x0010, 2, 2, buf)) < 0)
601 || (*((u16 *)buf) != 0x003b)) { 626 || (*((u16 *)buf) != 0x003b)) {
602 dbg("Read PHY register 2 must be 0x3b00: %d", ret); 627 dbg("Read PHY register 2 must be 0x3b00: %d", ret);
@@ -605,74 +630,49 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
605 630
606 /* Initialize MII structure */ 631 /* Initialize MII structure */
607 dev->mii.dev = dev->net; 632 dev->mii.dev = dev->net;
608 dev->mii.mdio_read = ax8817x_mdio_read; 633 dev->mii.mdio_read = asix_mdio_read;
609 dev->mii.mdio_write = ax8817x_mdio_write; 634 dev->mii.mdio_write = asix_mdio_write;
610 dev->mii.phy_id_mask = 0xff; 635 dev->mii.phy_id_mask = 0xff;
611 dev->mii.reg_num_mask = 0xff; 636 dev->mii.reg_num_mask = 0xff;
612 dev->net->do_ioctl = ax8817x_ioctl; 637 dev->net->do_ioctl = asix_ioctl;
638 dev->mii.phy_id = asix_get_phyid(dev);
613 639
614 /* Get the PHY id */ 640 if ((ret = asix_sw_reset(dev, AX_SWRESET_PRL)) < 0)
615 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID,
616 0, 0, 2, buf)) < 0) {
617 dbg("Error reading PHY ID: %02x", ret);
618 goto out2; 641 goto out2;
619 } else if (ret < 2) {
620 /* this should always return 2 bytes */
621 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x",
622 ret);
623 ret = -EIO;
624 goto out2;
625 }
626 dev->mii.phy_id = *((u8 *)buf + 1);
627 642
628 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL,
629 0, 0, buf)) < 0) {
630 dbg("Set external PHY reset pin level: %d", ret);
631 goto out2;
632 }
633 msleep(150); 643 msleep(150);
634 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, 644
635 AX_SWRESET_IPRL | AX_SWRESET_PRL, 645 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL)) < 0)
636 0, 0, buf)) < 0) {
637 dbg("Set Internal/External PHY reset control: %d", ret);
638 goto out2; 646 goto out2;
639 }
640 msleep(150);
641 647
648 msleep(150);
642 649
643 dev->net->set_multicast_list = ax8817x_set_multicast; 650 dev->net->set_multicast_list = asix_set_multicast;
644 dev->net->ethtool_ops = &ax88772_ethtool_ops; 651 dev->net->ethtool_ops = &ax88772_ethtool_ops;
645 652
646 ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); 653 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
647 ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE, 654 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE,
648 ADVERTISE_ALL | ADVERTISE_CSMA); 655 ADVERTISE_ALL | ADVERTISE_CSMA);
649 mii_nway_restart(&dev->mii); 656 mii_nway_restart(&dev->mii);
650 657
651 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, 658 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE,
652 AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) { 659 AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) {
653 dbg("Write medium mode register: %d", ret); 660 dbg("Write medium mode register: %d", ret);
654 goto out2; 661 goto out2;
655 } 662 }
656 663
657 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, 664 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
658 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT, 665 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
659 AX88772_IPG2_DEFAULT, 0, buf)) < 0) { 666 AX88772_IPG2_DEFAULT, 0, buf)) < 0) {
660 dbg("Write IPG,IPG1,IPG2 failed: %d", ret); 667 dbg("Write IPG,IPG1,IPG2 failed: %d", ret);
661 goto out2; 668 goto out2;
662 } 669 }
663 if ((ret = 670 if ((ret = asix_set_hw_mii(dev)) < 0)
664 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) {
665 dbg("Failed to set hardware MII: %02x", ret);
666 goto out2; 671 goto out2;
667 }
668 672
669 /* Set RX_CTL to default values with 2k buffer, and enable cactus */ 673 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
670 if ((ret = 674 if ((ret = asix_write_rx_ctl(dev, 0x0088)) < 0)
671 ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0,
672 buf)) < 0) {
673 dbg("Reset RX_CTL failed: %d", ret);
674 goto out2; 675 goto out2;
675 }
676 676
677 kfree(buf); 677 kfree(buf);
678 678
@@ -794,23 +794,23 @@ static int ax88772_link_reset(struct usbnet *dev)
794 u16 mode; 794 u16 mode;
795 795
796 mode = AX88772_MEDIUM_DEFAULT; 796 mode = AX88772_MEDIUM_DEFAULT;
797 lpa = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA); 797 lpa = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA);
798 adv = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE); 798 adv = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE);
799 res = mii_nway_result(lpa|adv); 799 res = mii_nway_result(lpa|adv);
800 800
801 if ((res & LPA_DUPLEX) == 0) 801 if ((res & LPA_DUPLEX) == 0)
802 mode &= ~AX88772_MEDIUM_FULL_DUPLEX; 802 mode &= ~AX88772_MEDIUM_FULL_DUPLEX;
803 if ((res & LPA_100) == 0) 803 if ((res & LPA_100) == 0)
804 mode &= ~AX88772_MEDIUM_100MB; 804 mode &= ~AX88772_MEDIUM_100MB;
805 ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); 805 asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
806 806
807 return 0; 807 return 0;
808} 808}
809 809
810static const struct driver_info ax8817x_info = { 810static const struct driver_info ax8817x_info = {
811 .description = "ASIX AX8817x USB 2.0 Ethernet", 811 .description = "ASIX AX8817x USB 2.0 Ethernet",
812 .bind = ax8817x_bind, 812 .bind = ax88172_bind,
813 .status = ax8817x_status, 813 .status = asix_status,
814 .link_reset = ax88172_link_reset, 814 .link_reset = ax88172_link_reset,
815 .reset = ax88172_link_reset, 815 .reset = ax88172_link_reset,
816 .flags = FLAG_ETHER, 816 .flags = FLAG_ETHER,
@@ -819,8 +819,8 @@ static const struct driver_info ax8817x_info = {
819 819
820static const struct driver_info dlink_dub_e100_info = { 820static const struct driver_info dlink_dub_e100_info = {
821 .description = "DLink DUB-E100 USB Ethernet", 821 .description = "DLink DUB-E100 USB Ethernet",
822 .bind = ax8817x_bind, 822 .bind = ax88172_bind,
823 .status = ax8817x_status, 823 .status = asix_status,
824 .link_reset = ax88172_link_reset, 824 .link_reset = ax88172_link_reset,
825 .reset = ax88172_link_reset, 825 .reset = ax88172_link_reset,
826 .flags = FLAG_ETHER, 826 .flags = FLAG_ETHER,
@@ -829,8 +829,8 @@ static const struct driver_info dlink_dub_e100_info = {
829 829
830static const struct driver_info netgear_fa120_info = { 830static const struct driver_info netgear_fa120_info = {
831 .description = "Netgear FA-120 USB Ethernet", 831 .description = "Netgear FA-120 USB Ethernet",
832 .bind = ax8817x_bind, 832 .bind = ax88172_bind,
833 .status = ax8817x_status, 833 .status = asix_status,
834 .link_reset = ax88172_link_reset, 834 .link_reset = ax88172_link_reset,
835 .reset = ax88172_link_reset, 835 .reset = ax88172_link_reset,
836 .flags = FLAG_ETHER, 836 .flags = FLAG_ETHER,
@@ -839,8 +839,8 @@ static const struct driver_info netgear_fa120_info = {
839 839
840static const struct driver_info hawking_uf200_info = { 840static const struct driver_info hawking_uf200_info = {
841 .description = "Hawking UF200 USB Ethernet", 841 .description = "Hawking UF200 USB Ethernet",
842 .bind = ax8817x_bind, 842 .bind = ax88172_bind,
843 .status = ax8817x_status, 843 .status = asix_status,
844 .link_reset = ax88172_link_reset, 844 .link_reset = ax88172_link_reset,
845 .reset = ax88172_link_reset, 845 .reset = ax88172_link_reset,
846 .flags = FLAG_ETHER, 846 .flags = FLAG_ETHER,
@@ -850,13 +850,12 @@ static const struct driver_info hawking_uf200_info = {
850static const struct driver_info ax88772_info = { 850static const struct driver_info ax88772_info = {
851 .description = "ASIX AX88772 USB 2.0 Ethernet", 851 .description = "ASIX AX88772 USB 2.0 Ethernet",
852 .bind = ax88772_bind, 852 .bind = ax88772_bind,
853 .status = ax8817x_status, 853 .status = asix_status,
854 .link_reset = ax88772_link_reset, 854 .link_reset = ax88772_link_reset,
855 .reset = ax88772_link_reset, 855 .reset = ax88772_link_reset,
856 .flags = FLAG_ETHER | FLAG_FRAMING_AX, 856 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
857 .rx_fixup = ax88772_rx_fixup, 857 .rx_fixup = ax88772_rx_fixup,
858 .tx_fixup = ax88772_tx_fixup, 858 .tx_fixup = ax88772_tx_fixup,
859 .data = 0x00130103,
860}; 859};
861 860
862static const struct usb_device_id products [] = { 861static const struct usb_device_id products [] = {