asix_common.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * ASIX AX8817X based USB 2.0 Ethernet Devices
  3. * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
  4. * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
  5. * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
  6. * Copyright (c) 2002-2003 TiVo Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include "asix.h"
  23. int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  24. u16 size, void *data)
  25. {
  26. void *buf;
  27. int err = -ENOMEM;
  28. netdev_dbg(dev->net, "asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
  29. cmd, value, index, size);
  30. buf = kmalloc(size, GFP_KERNEL);
  31. if (!buf)
  32. goto out;
  33. err = usb_control_msg(
  34. dev->udev,
  35. usb_rcvctrlpipe(dev->udev, 0),
  36. cmd,
  37. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  38. value,
  39. index,
  40. buf,
  41. size,
  42. USB_CTRL_GET_TIMEOUT);
  43. if (err == size)
  44. memcpy(data, buf, size);
  45. else if (err >= 0)
  46. err = -EINVAL;
  47. kfree(buf);
  48. out:
  49. return err;
  50. }
  51. int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  52. u16 size, void *data)
  53. {
  54. void *buf = NULL;
  55. int err = -ENOMEM;
  56. netdev_dbg(dev->net, "asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
  57. cmd, value, index, size);
  58. if (data) {
  59. buf = kmemdup(data, size, GFP_KERNEL);
  60. if (!buf)
  61. goto out;
  62. }
  63. err = usb_control_msg(
  64. dev->udev,
  65. usb_sndctrlpipe(dev->udev, 0),
  66. cmd,
  67. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  68. value,
  69. index,
  70. buf,
  71. size,
  72. USB_CTRL_SET_TIMEOUT);
  73. kfree(buf);
  74. out:
  75. return err;
  76. }
  77. static void asix_async_cmd_callback(struct urb *urb)
  78. {
  79. struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
  80. int status = urb->status;
  81. if (status < 0)
  82. printk(KERN_DEBUG "asix_async_cmd_callback() failed with %d",
  83. status);
  84. kfree(req);
  85. usb_free_urb(urb);
  86. }
  87. void asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  88. u16 size, void *data)
  89. {
  90. struct usb_ctrlrequest *req;
  91. int status;
  92. struct urb *urb;
  93. netdev_dbg(dev->net, "asix_write_cmd_async() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
  94. cmd, value, index, size);
  95. urb = usb_alloc_urb(0, GFP_ATOMIC);
  96. if (!urb) {
  97. netdev_err(dev->net, "Error allocating URB in write_cmd_async!\n");
  98. return;
  99. }
  100. req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
  101. if (!req) {
  102. netdev_err(dev->net, "Failed to allocate memory for control request\n");
  103. usb_free_urb(urb);
  104. return;
  105. }
  106. req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
  107. req->bRequest = cmd;
  108. req->wValue = cpu_to_le16(value);
  109. req->wIndex = cpu_to_le16(index);
  110. req->wLength = cpu_to_le16(size);
  111. usb_fill_control_urb(urb, dev->udev,
  112. usb_sndctrlpipe(dev->udev, 0),
  113. (void *)req, data, size,
  114. asix_async_cmd_callback, req);
  115. status = usb_submit_urb(urb, GFP_ATOMIC);
  116. if (status < 0) {
  117. netdev_err(dev->net, "Error submitting the control message: status=%d\n",
  118. status);
  119. kfree(req);
  120. usb_free_urb(urb);
  121. }
  122. }
  123. int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
  124. {
  125. int offset = 0;
  126. while (offset + sizeof(u32) < skb->len) {
  127. struct sk_buff *ax_skb;
  128. u16 size;
  129. u32 header = get_unaligned_le32(skb->data + offset);
  130. offset += sizeof(u32);
  131. /* get the packet length */
  132. size = (u16) (header & 0x7ff);
  133. if (size != ((~header >> 16) & 0x07ff)) {
  134. netdev_err(dev->net, "asix_rx_fixup() Bad Header Length\n");
  135. return 0;
  136. }
  137. if ((size > dev->net->mtu + ETH_HLEN + VLAN_HLEN) ||
  138. (size + offset > skb->len)) {
  139. netdev_err(dev->net, "asix_rx_fixup() Bad RX Length %d\n",
  140. size);
  141. return 0;
  142. }
  143. ax_skb = netdev_alloc_skb_ip_align(dev->net, size);
  144. if (!ax_skb)
  145. return 0;
  146. skb_put(ax_skb, size);
  147. memcpy(ax_skb->data, skb->data + offset, size);
  148. usbnet_skb_return(dev, ax_skb);
  149. offset += (size + 1) & 0xfffe;
  150. }
  151. if (skb->len != offset) {
  152. netdev_err(dev->net, "asix_rx_fixup() Bad SKB Length %d\n",
  153. skb->len);
  154. return 0;
  155. }
  156. return 1;
  157. }
  158. struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
  159. gfp_t flags)
  160. {
  161. int padlen;
  162. int headroom = skb_headroom(skb);
  163. int tailroom = skb_tailroom(skb);
  164. u32 packet_len;
  165. u32 padbytes = 0xffff0000;
  166. padlen = ((skb->len + 4) & (dev->maxpacket - 1)) ? 0 : 4;
  167. /* We need to push 4 bytes in front of frame (packet_len)
  168. * and maybe add 4 bytes after the end (if padlen is 4)
  169. *
  170. * Avoid skb_copy_expand() expensive call, using following rules :
  171. * - We are allowed to push 4 bytes in headroom if skb_header_cloned()
  172. * is false (and if we have 4 bytes of headroom)
  173. * - We are allowed to put 4 bytes at tail if skb_cloned()
  174. * is false (and if we have 4 bytes of tailroom)
  175. *
  176. * TCP packets for example are cloned, but skb_header_release()
  177. * was called in tcp stack, allowing us to use headroom for our needs.
  178. */
  179. if (!skb_header_cloned(skb) &&
  180. !(padlen && skb_cloned(skb)) &&
  181. headroom + tailroom >= 4 + padlen) {
  182. /* following should not happen, but better be safe */
  183. if (headroom < 4 ||
  184. tailroom < padlen) {
  185. skb->data = memmove(skb->head + 4, skb->data, skb->len);
  186. skb_set_tail_pointer(skb, skb->len);
  187. }
  188. } else {
  189. struct sk_buff *skb2;
  190. skb2 = skb_copy_expand(skb, 4, padlen, flags);
  191. dev_kfree_skb_any(skb);
  192. skb = skb2;
  193. if (!skb)
  194. return NULL;
  195. }
  196. packet_len = ((skb->len ^ 0x0000ffff) << 16) + skb->len;
  197. skb_push(skb, 4);
  198. cpu_to_le32s(&packet_len);
  199. skb_copy_to_linear_data(skb, &packet_len, sizeof(packet_len));
  200. if (padlen) {
  201. cpu_to_le32s(&padbytes);
  202. memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes));
  203. skb_put(skb, sizeof(padbytes));
  204. }
  205. return skb;
  206. }
  207. int asix_set_sw_mii(struct usbnet *dev)
  208. {
  209. int ret;
  210. ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
  211. if (ret < 0)
  212. netdev_err(dev->net, "Failed to enable software MII access\n");
  213. return ret;
  214. }
  215. int asix_set_hw_mii(struct usbnet *dev)
  216. {
  217. int ret;
  218. ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
  219. if (ret < 0)
  220. netdev_err(dev->net, "Failed to enable hardware MII access\n");
  221. return ret;
  222. }
  223. int asix_read_phy_addr(struct usbnet *dev, int internal)
  224. {
  225. int offset = (internal ? 1 : 0);
  226. u8 buf[2];
  227. int ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf);
  228. netdev_dbg(dev->net, "asix_get_phy_addr()\n");
  229. if (ret < 0) {
  230. netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret);
  231. goto out;
  232. }
  233. netdev_dbg(dev->net, "asix_get_phy_addr() returning 0x%04x\n",
  234. *((__le16 *)buf));
  235. ret = buf[offset];
  236. out:
  237. return ret;
  238. }
  239. int asix_get_phy_addr(struct usbnet *dev)
  240. {
  241. /* return the address of the internal phy */
  242. return asix_read_phy_addr(dev, 1);
  243. }
  244. int asix_sw_reset(struct usbnet *dev, u8 flags)
  245. {
  246. int ret;
  247. ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL);
  248. if (ret < 0)
  249. netdev_err(dev->net, "Failed to send software reset: %02x\n", ret);
  250. return ret;
  251. }
  252. u16 asix_read_rx_ctl(struct usbnet *dev)
  253. {
  254. __le16 v;
  255. int ret = asix_read_cmd(dev, AX_CMD_READ_RX_CTL, 0, 0, 2, &v);
  256. if (ret < 0) {
  257. netdev_err(dev->net, "Error reading RX_CTL register: %02x\n", ret);
  258. goto out;
  259. }
  260. ret = le16_to_cpu(v);
  261. out:
  262. return ret;
  263. }
  264. int asix_write_rx_ctl(struct usbnet *dev, u16 mode)
  265. {
  266. int ret;
  267. netdev_dbg(dev->net, "asix_write_rx_ctl() - mode = 0x%04x\n", mode);
  268. ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
  269. if (ret < 0)
  270. netdev_err(dev->net, "Failed to write RX_CTL mode to 0x%04x: %02x\n",
  271. mode, ret);
  272. return ret;
  273. }
  274. u16 asix_read_medium_status(struct usbnet *dev)
  275. {
  276. __le16 v;
  277. int ret = asix_read_cmd(dev, AX_CMD_READ_MEDIUM_STATUS, 0, 0, 2, &v);
  278. if (ret < 0) {
  279. netdev_err(dev->net, "Error reading Medium Status register: %02x\n",
  280. ret);
  281. return ret; /* TODO: callers not checking for error ret */
  282. }
  283. return le16_to_cpu(v);
  284. }
  285. int asix_write_medium_mode(struct usbnet *dev, u16 mode)
  286. {
  287. int ret;
  288. netdev_dbg(dev->net, "asix_write_medium_mode() - mode = 0x%04x\n", mode);
  289. ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
  290. if (ret < 0)
  291. netdev_err(dev->net, "Failed to write Medium Mode mode to 0x%04x: %02x\n",
  292. mode, ret);
  293. return ret;
  294. }
  295. int asix_write_gpio(struct usbnet *dev, u16 value, int sleep)
  296. {
  297. int ret;
  298. netdev_dbg(dev->net, "asix_write_gpio() - value = 0x%04x\n", value);
  299. ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS, value, 0, 0, NULL);
  300. if (ret < 0)
  301. netdev_err(dev->net, "Failed to write GPIO value 0x%04x: %02x\n",
  302. value, ret);
  303. if (sleep)
  304. msleep(sleep);
  305. return ret;
  306. }
  307. /*
  308. * AX88772 & AX88178 have a 16-bit RX_CTL value
  309. */
  310. void asix_set_multicast(struct net_device *net)
  311. {
  312. struct usbnet *dev = netdev_priv(net);
  313. struct asix_data *data = (struct asix_data *)&dev->data;
  314. u16 rx_ctl = AX_DEFAULT_RX_CTL;
  315. if (net->flags & IFF_PROMISC) {
  316. rx_ctl |= AX_RX_CTL_PRO;
  317. } else if (net->flags & IFF_ALLMULTI ||
  318. netdev_mc_count(net) > AX_MAX_MCAST) {
  319. rx_ctl |= AX_RX_CTL_AMALL;
  320. } else if (netdev_mc_empty(net)) {
  321. /* just broadcast and directed */
  322. } else {
  323. /* We use the 20 byte dev->data
  324. * for our 8 byte filter buffer
  325. * to avoid allocating memory that
  326. * is tricky to free later */
  327. struct netdev_hw_addr *ha;
  328. u32 crc_bits;
  329. memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
  330. /* Build the multicast hash filter. */
  331. netdev_for_each_mc_addr(ha, net) {
  332. crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
  333. data->multi_filter[crc_bits >> 3] |=
  334. 1 << (crc_bits & 7);
  335. }
  336. asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
  337. AX_MCAST_FILTER_SIZE, data->multi_filter);
  338. rx_ctl |= AX_RX_CTL_AM;
  339. }
  340. asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
  341. }
  342. int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
  343. {
  344. struct usbnet *dev = netdev_priv(netdev);
  345. __le16 res;
  346. mutex_lock(&dev->phy_mutex);
  347. asix_set_sw_mii(dev);
  348. asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
  349. (__u16)loc, 2, &res);
  350. asix_set_hw_mii(dev);
  351. mutex_unlock(&dev->phy_mutex);
  352. netdev_dbg(dev->net, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
  353. phy_id, loc, le16_to_cpu(res));
  354. return le16_to_cpu(res);
  355. }
  356. void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
  357. {
  358. struct usbnet *dev = netdev_priv(netdev);
  359. __le16 res = cpu_to_le16(val);
  360. netdev_dbg(dev->net, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n",
  361. phy_id, loc, val);
  362. mutex_lock(&dev->phy_mutex);
  363. asix_set_sw_mii(dev);
  364. asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, &res);
  365. asix_set_hw_mii(dev);
  366. mutex_unlock(&dev->phy_mutex);
  367. }
  368. void asix_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
  369. {
  370. struct usbnet *dev = netdev_priv(net);
  371. u8 opt;
  372. if (asix_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
  373. wolinfo->supported = 0;
  374. wolinfo->wolopts = 0;
  375. return;
  376. }
  377. wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
  378. wolinfo->wolopts = 0;
  379. if (opt & AX_MONITOR_LINK)
  380. wolinfo->wolopts |= WAKE_PHY;
  381. if (opt & AX_MONITOR_MAGIC)
  382. wolinfo->wolopts |= WAKE_MAGIC;
  383. }
  384. int asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
  385. {
  386. struct usbnet *dev = netdev_priv(net);
  387. u8 opt = 0;
  388. if (wolinfo->wolopts & WAKE_PHY)
  389. opt |= AX_MONITOR_LINK;
  390. if (wolinfo->wolopts & WAKE_MAGIC)
  391. opt |= AX_MONITOR_MAGIC;
  392. if (asix_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
  393. opt, 0, 0, NULL) < 0)
  394. return -EINVAL;
  395. return 0;
  396. }
  397. int asix_get_eeprom_len(struct net_device *net)
  398. {
  399. return AX_EEPROM_LEN;
  400. }
  401. int asix_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
  402. u8 *data)
  403. {
  404. struct usbnet *dev = netdev_priv(net);
  405. u16 *eeprom_buff;
  406. int first_word, last_word;
  407. int i;
  408. if (eeprom->len == 0)
  409. return -EINVAL;
  410. eeprom->magic = AX_EEPROM_MAGIC;
  411. first_word = eeprom->offset >> 1;
  412. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  413. eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
  414. GFP_KERNEL);
  415. if (!eeprom_buff)
  416. return -ENOMEM;
  417. /* ax8817x returns 2 bytes from eeprom on read */
  418. for (i = first_word; i <= last_word; i++) {
  419. if (asix_read_cmd(dev, AX_CMD_READ_EEPROM, i, 0, 2,
  420. &(eeprom_buff[i - first_word])) < 0) {
  421. kfree(eeprom_buff);
  422. return -EIO;
  423. }
  424. }
  425. memcpy(data, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
  426. kfree(eeprom_buff);
  427. return 0;
  428. }
  429. int asix_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
  430. u8 *data)
  431. {
  432. struct usbnet *dev = netdev_priv(net);
  433. u16 *eeprom_buff;
  434. int first_word, last_word;
  435. int i;
  436. int ret;
  437. netdev_dbg(net, "write EEPROM len %d, offset %d, magic 0x%x\n",
  438. eeprom->len, eeprom->offset, eeprom->magic);
  439. if (eeprom->len == 0)
  440. return -EINVAL;
  441. if (eeprom->magic != AX_EEPROM_MAGIC)
  442. return -EINVAL;
  443. first_word = eeprom->offset >> 1;
  444. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  445. eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
  446. GFP_KERNEL);
  447. if (!eeprom_buff)
  448. return -ENOMEM;
  449. /* align data to 16 bit boundaries, read the missing data from
  450. the EEPROM */
  451. if (eeprom->offset & 1) {
  452. ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, first_word, 0, 2,
  453. &(eeprom_buff[0]));
  454. if (ret < 0) {
  455. netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", first_word);
  456. goto free;
  457. }
  458. }
  459. if ((eeprom->offset + eeprom->len) & 1) {
  460. ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, last_word, 0, 2,
  461. &(eeprom_buff[last_word - first_word]));
  462. if (ret < 0) {
  463. netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", last_word);
  464. goto free;
  465. }
  466. }
  467. memcpy((u8 *)eeprom_buff + (eeprom->offset & 1), data, eeprom->len);
  468. /* write data to EEPROM */
  469. ret = asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0x0000, 0, 0, NULL);
  470. if (ret < 0) {
  471. netdev_err(net, "Failed to enable EEPROM write\n");
  472. goto free;
  473. }
  474. msleep(20);
  475. for (i = first_word; i <= last_word; i++) {
  476. netdev_dbg(net, "write to EEPROM at offset 0x%02x, data 0x%04x\n",
  477. i, eeprom_buff[i - first_word]);
  478. ret = asix_write_cmd(dev, AX_CMD_WRITE_EEPROM, i,
  479. eeprom_buff[i - first_word], 0, NULL);
  480. if (ret < 0) {
  481. netdev_err(net, "Failed to write EEPROM at offset 0x%02x.\n",
  482. i);
  483. goto free;
  484. }
  485. msleep(20);
  486. }
  487. ret = asix_write_cmd(dev, AX_CMD_WRITE_DISABLE, 0x0000, 0, 0, NULL);
  488. if (ret < 0) {
  489. netdev_err(net, "Failed to disable EEPROM write\n");
  490. goto free;
  491. }
  492. ret = 0;
  493. free:
  494. kfree(eeprom_buff);
  495. return ret;
  496. }
  497. void asix_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
  498. {
  499. /* Inherit standard device info */
  500. usbnet_get_drvinfo(net, info);
  501. strncpy (info->driver, DRIVER_NAME, sizeof info->driver);
  502. strncpy (info->version, DRIVER_VERSION, sizeof info->version);
  503. info->eedump_len = AX_EEPROM_LEN;
  504. }
  505. int asix_set_mac_address(struct net_device *net, void *p)
  506. {
  507. struct usbnet *dev = netdev_priv(net);
  508. struct asix_data *data = (struct asix_data *)&dev->data;
  509. struct sockaddr *addr = p;
  510. if (netif_running(net))
  511. return -EBUSY;
  512. if (!is_valid_ether_addr(addr->sa_data))
  513. return -EADDRNOTAVAIL;
  514. memcpy(net->dev_addr, addr->sa_data, ETH_ALEN);
  515. /* We use the 20 byte dev->data
  516. * for our 6 byte mac buffer
  517. * to avoid allocating memory that
  518. * is tricky to free later */
  519. memcpy(data->mac_addr, addr->sa_data, ETH_ALEN);
  520. asix_write_cmd_async(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
  521. data->mac_addr);
  522. return 0;
  523. }