asix_common.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include "asix.h"
  22. int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  23. u16 size, void *data)
  24. {
  25. int ret;
  26. ret = usbnet_read_cmd(dev, cmd,
  27. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  28. value, index, data, size);
  29. if (ret != size && ret >= 0)
  30. return -EINVAL;
  31. return ret;
  32. }
  33. int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  34. u16 size, void *data)
  35. {
  36. return usbnet_write_cmd(dev, cmd,
  37. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  38. value, index, data, size);
  39. }
  40. void asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
  41. u16 size, void *data)
  42. {
  43. usbnet_write_cmd_async(dev, cmd,
  44. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  45. value, index, data, size);
  46. }
  47. int asix_rx_fixup_internal(struct usbnet *dev, struct sk_buff *skb,
  48. struct asix_rx_fixup_info *rx)
  49. {
  50. int offset = 0;
  51. u16 size;
  52. /* When an Ethernet frame spans multiple URB socket buffers,
  53. * do a sanity test for the Data header synchronisation.
  54. * Attempt to detect the situation of the previous socket buffer having
  55. * been truncated or a socket buffer was missing. These situations
  56. * cause a discontinuity in the data stream and therefore need to avoid
  57. * appending bad data to the end of the current netdev socket buffer.
  58. * Also avoid unnecessarily discarding a good current netdev socket
  59. * buffer.
  60. */
  61. if (rx->remaining && (rx->remaining + sizeof(u32) <= skb->len)) {
  62. offset = ((rx->remaining + 1) & 0xfffe);
  63. rx->header = get_unaligned_le32(skb->data + offset);
  64. offset = 0;
  65. size = (u16)(rx->header & 0x7ff);
  66. if (size != ((~rx->header >> 16) & 0x7ff)) {
  67. netdev_err(dev->net, "asix_rx_fixup() Data Header synchronisation was lost, remaining %d\n",
  68. rx->remaining);
  69. if (rx->ax_skb) {
  70. kfree_skb(rx->ax_skb);
  71. rx->ax_skb = NULL;
  72. /* Discard the incomplete netdev Ethernet frame
  73. * and assume the Data header is at the start of
  74. * the current URB socket buffer.
  75. */
  76. }
  77. rx->remaining = 0;
  78. }
  79. }
  80. while (offset + sizeof(u16) <= skb->len) {
  81. u16 copy_length;
  82. unsigned char *data;
  83. if (!rx->remaining) {
  84. if (skb->len - offset == sizeof(u16)) {
  85. rx->header = get_unaligned_le16(
  86. skb->data + offset);
  87. rx->split_head = true;
  88. offset += sizeof(u16);
  89. break;
  90. }
  91. if (rx->split_head == true) {
  92. rx->header |= (get_unaligned_le16(
  93. skb->data + offset) << 16);
  94. rx->split_head = false;
  95. offset += sizeof(u16);
  96. } else {
  97. rx->header = get_unaligned_le32(skb->data +
  98. offset);
  99. offset += sizeof(u32);
  100. }
  101. /* take frame length from Data header 32-bit word */
  102. size = (u16)(rx->header & 0x7ff);
  103. if (size != ((~rx->header >> 16) & 0x7ff)) {
  104. netdev_err(dev->net, "asix_rx_fixup() Bad Header Length 0x%x, offset %d\n",
  105. rx->header, offset);
  106. return 0;
  107. }
  108. if (size > dev->net->mtu + ETH_HLEN + VLAN_HLEN) {
  109. netdev_err(dev->net, "asix_rx_fixup() Bad RX Length %d\n",
  110. size);
  111. return 0;
  112. }
  113. /* Sometimes may fail to get a netdev socket buffer but
  114. * continue to process the URB socket buffer so that
  115. * synchronisation of the Ethernet frame Data header
  116. * word is maintained.
  117. */
  118. rx->ax_skb = netdev_alloc_skb_ip_align(dev->net, size);
  119. rx->remaining = size;
  120. }
  121. if (rx->remaining > skb->len - offset) {
  122. copy_length = skb->len - offset;
  123. rx->remaining -= copy_length;
  124. } else {
  125. copy_length = rx->remaining;
  126. rx->remaining = 0;
  127. }
  128. if (rx->ax_skb) {
  129. data = skb_put(rx->ax_skb, copy_length);
  130. memcpy(data, skb->data + offset, copy_length);
  131. if (!rx->remaining)
  132. usbnet_skb_return(dev, rx->ax_skb);
  133. }
  134. offset += (copy_length + 1) & 0xfffe;
  135. }
  136. if (skb->len != offset) {
  137. netdev_err(dev->net, "asix_rx_fixup() Bad SKB Length %d, %d\n",
  138. skb->len, offset);
  139. return 0;
  140. }
  141. return 1;
  142. }
  143. int asix_rx_fixup_common(struct usbnet *dev, struct sk_buff *skb)
  144. {
  145. struct asix_common_private *dp = dev->driver_priv;
  146. struct asix_rx_fixup_info *rx = &dp->rx_fixup_info;
  147. return asix_rx_fixup_internal(dev, skb, rx);
  148. }
  149. struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
  150. gfp_t flags)
  151. {
  152. int padlen;
  153. int headroom = skb_headroom(skb);
  154. int tailroom = skb_tailroom(skb);
  155. u32 packet_len;
  156. u32 padbytes = 0xffff0000;
  157. padlen = ((skb->len + 4) & (dev->maxpacket - 1)) ? 0 : 4;
  158. /* We need to push 4 bytes in front of frame (packet_len)
  159. * and maybe add 4 bytes after the end (if padlen is 4)
  160. *
  161. * Avoid skb_copy_expand() expensive call, using following rules :
  162. * - We are allowed to push 4 bytes in headroom if skb_header_cloned()
  163. * is false (and if we have 4 bytes of headroom)
  164. * - We are allowed to put 4 bytes at tail if skb_cloned()
  165. * is false (and if we have 4 bytes of tailroom)
  166. *
  167. * TCP packets for example are cloned, but skb_header_release()
  168. * was called in tcp stack, allowing us to use headroom for our needs.
  169. */
  170. if (!skb_header_cloned(skb) &&
  171. !(padlen && skb_cloned(skb)) &&
  172. headroom + tailroom >= 4 + padlen) {
  173. /* following should not happen, but better be safe */
  174. if (headroom < 4 ||
  175. tailroom < padlen) {
  176. skb->data = memmove(skb->head + 4, skb->data, skb->len);
  177. skb_set_tail_pointer(skb, skb->len);
  178. }
  179. } else {
  180. struct sk_buff *skb2;
  181. skb2 = skb_copy_expand(skb, 4, padlen, flags);
  182. dev_kfree_skb_any(skb);
  183. skb = skb2;
  184. if (!skb)
  185. return NULL;
  186. }
  187. packet_len = ((skb->len ^ 0x0000ffff) << 16) + skb->len;
  188. skb_push(skb, 4);
  189. cpu_to_le32s(&packet_len);
  190. skb_copy_to_linear_data(skb, &packet_len, sizeof(packet_len));
  191. if (padlen) {
  192. cpu_to_le32s(&padbytes);
  193. memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes));
  194. skb_put(skb, sizeof(padbytes));
  195. }
  196. usbnet_set_skb_tx_stats(skb, 1, 0);
  197. return skb;
  198. }
  199. int asix_set_sw_mii(struct usbnet *dev)
  200. {
  201. int ret;
  202. ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
  203. if (ret < 0)
  204. netdev_err(dev->net, "Failed to enable software MII access\n");
  205. return ret;
  206. }
  207. int asix_set_hw_mii(struct usbnet *dev)
  208. {
  209. int ret;
  210. ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
  211. if (ret < 0)
  212. netdev_err(dev->net, "Failed to enable hardware MII access\n");
  213. return ret;
  214. }
  215. int asix_read_phy_addr(struct usbnet *dev, int internal)
  216. {
  217. int offset = (internal ? 1 : 0);
  218. u8 buf[2];
  219. int ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf);
  220. netdev_dbg(dev->net, "asix_get_phy_addr()\n");
  221. if (ret < 0) {
  222. netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret);
  223. goto out;
  224. }
  225. netdev_dbg(dev->net, "asix_get_phy_addr() returning 0x%04x\n",
  226. *((__le16 *)buf));
  227. ret = buf[offset];
  228. out:
  229. return ret;
  230. }
  231. int asix_get_phy_addr(struct usbnet *dev)
  232. {
  233. /* return the address of the internal phy */
  234. return asix_read_phy_addr(dev, 1);
  235. }
  236. int asix_sw_reset(struct usbnet *dev, u8 flags)
  237. {
  238. int ret;
  239. ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL);
  240. if (ret < 0)
  241. netdev_err(dev->net, "Failed to send software reset: %02x\n", ret);
  242. return ret;
  243. }
  244. u16 asix_read_rx_ctl(struct usbnet *dev)
  245. {
  246. __le16 v;
  247. int ret = asix_read_cmd(dev, AX_CMD_READ_RX_CTL, 0, 0, 2, &v);
  248. if (ret < 0) {
  249. netdev_err(dev->net, "Error reading RX_CTL register: %02x\n", ret);
  250. goto out;
  251. }
  252. ret = le16_to_cpu(v);
  253. out:
  254. return ret;
  255. }
  256. int asix_write_rx_ctl(struct usbnet *dev, u16 mode)
  257. {
  258. int ret;
  259. netdev_dbg(dev->net, "asix_write_rx_ctl() - mode = 0x%04x\n", mode);
  260. ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
  261. if (ret < 0)
  262. netdev_err(dev->net, "Failed to write RX_CTL mode to 0x%04x: %02x\n",
  263. mode, ret);
  264. return ret;
  265. }
  266. u16 asix_read_medium_status(struct usbnet *dev)
  267. {
  268. __le16 v;
  269. int ret = asix_read_cmd(dev, AX_CMD_READ_MEDIUM_STATUS, 0, 0, 2, &v);
  270. if (ret < 0) {
  271. netdev_err(dev->net, "Error reading Medium Status register: %02x\n",
  272. ret);
  273. return ret; /* TODO: callers not checking for error ret */
  274. }
  275. return le16_to_cpu(v);
  276. }
  277. int asix_write_medium_mode(struct usbnet *dev, u16 mode)
  278. {
  279. int ret;
  280. netdev_dbg(dev->net, "asix_write_medium_mode() - mode = 0x%04x\n", mode);
  281. ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
  282. if (ret < 0)
  283. netdev_err(dev->net, "Failed to write Medium Mode mode to 0x%04x: %02x\n",
  284. mode, ret);
  285. return ret;
  286. }
  287. int asix_write_gpio(struct usbnet *dev, u16 value, int sleep)
  288. {
  289. int ret;
  290. netdev_dbg(dev->net, "asix_write_gpio() - value = 0x%04x\n", value);
  291. ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS, value, 0, 0, NULL);
  292. if (ret < 0)
  293. netdev_err(dev->net, "Failed to write GPIO value 0x%04x: %02x\n",
  294. value, ret);
  295. if (sleep)
  296. msleep(sleep);
  297. return ret;
  298. }
  299. /*
  300. * AX88772 & AX88178 have a 16-bit RX_CTL value
  301. */
  302. void asix_set_multicast(struct net_device *net)
  303. {
  304. struct usbnet *dev = netdev_priv(net);
  305. struct asix_data *data = (struct asix_data *)&dev->data;
  306. u16 rx_ctl = AX_DEFAULT_RX_CTL;
  307. if (net->flags & IFF_PROMISC) {
  308. rx_ctl |= AX_RX_CTL_PRO;
  309. } else if (net->flags & IFF_ALLMULTI ||
  310. netdev_mc_count(net) > AX_MAX_MCAST) {
  311. rx_ctl |= AX_RX_CTL_AMALL;
  312. } else if (netdev_mc_empty(net)) {
  313. /* just broadcast and directed */
  314. } else {
  315. /* We use the 20 byte dev->data
  316. * for our 8 byte filter buffer
  317. * to avoid allocating memory that
  318. * is tricky to free later */
  319. struct netdev_hw_addr *ha;
  320. u32 crc_bits;
  321. memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
  322. /* Build the multicast hash filter. */
  323. netdev_for_each_mc_addr(ha, net) {
  324. crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
  325. data->multi_filter[crc_bits >> 3] |=
  326. 1 << (crc_bits & 7);
  327. }
  328. asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
  329. AX_MCAST_FILTER_SIZE, data->multi_filter);
  330. rx_ctl |= AX_RX_CTL_AM;
  331. }
  332. asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
  333. }
  334. int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
  335. {
  336. struct usbnet *dev = netdev_priv(netdev);
  337. __le16 res;
  338. mutex_lock(&dev->phy_mutex);
  339. asix_set_sw_mii(dev);
  340. asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
  341. (__u16)loc, 2, &res);
  342. asix_set_hw_mii(dev);
  343. mutex_unlock(&dev->phy_mutex);
  344. netdev_dbg(dev->net, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
  345. phy_id, loc, le16_to_cpu(res));
  346. return le16_to_cpu(res);
  347. }
  348. void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
  349. {
  350. struct usbnet *dev = netdev_priv(netdev);
  351. __le16 res = cpu_to_le16(val);
  352. netdev_dbg(dev->net, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n",
  353. phy_id, loc, val);
  354. mutex_lock(&dev->phy_mutex);
  355. asix_set_sw_mii(dev);
  356. asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, &res);
  357. asix_set_hw_mii(dev);
  358. mutex_unlock(&dev->phy_mutex);
  359. }
  360. void asix_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
  361. {
  362. struct usbnet *dev = netdev_priv(net);
  363. u8 opt;
  364. if (asix_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
  365. wolinfo->supported = 0;
  366. wolinfo->wolopts = 0;
  367. return;
  368. }
  369. wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
  370. wolinfo->wolopts = 0;
  371. if (opt & AX_MONITOR_LINK)
  372. wolinfo->wolopts |= WAKE_PHY;
  373. if (opt & AX_MONITOR_MAGIC)
  374. wolinfo->wolopts |= WAKE_MAGIC;
  375. }
  376. int asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
  377. {
  378. struct usbnet *dev = netdev_priv(net);
  379. u8 opt = 0;
  380. if (wolinfo->wolopts & ~(WAKE_PHY | WAKE_MAGIC))
  381. return -EINVAL;
  382. if (wolinfo->wolopts & WAKE_PHY)
  383. opt |= AX_MONITOR_LINK;
  384. if (wolinfo->wolopts & WAKE_MAGIC)
  385. opt |= AX_MONITOR_MAGIC;
  386. if (asix_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
  387. opt, 0, 0, NULL) < 0)
  388. return -EINVAL;
  389. return 0;
  390. }
  391. int asix_get_eeprom_len(struct net_device *net)
  392. {
  393. return AX_EEPROM_LEN;
  394. }
  395. int asix_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
  396. u8 *data)
  397. {
  398. struct usbnet *dev = netdev_priv(net);
  399. u16 *eeprom_buff;
  400. int first_word, last_word;
  401. int i;
  402. if (eeprom->len == 0)
  403. return -EINVAL;
  404. eeprom->magic = AX_EEPROM_MAGIC;
  405. first_word = eeprom->offset >> 1;
  406. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  407. eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
  408. GFP_KERNEL);
  409. if (!eeprom_buff)
  410. return -ENOMEM;
  411. /* ax8817x returns 2 bytes from eeprom on read */
  412. for (i = first_word; i <= last_word; i++) {
  413. if (asix_read_cmd(dev, AX_CMD_READ_EEPROM, i, 0, 2,
  414. &(eeprom_buff[i - first_word])) < 0) {
  415. kfree(eeprom_buff);
  416. return -EIO;
  417. }
  418. }
  419. memcpy(data, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
  420. kfree(eeprom_buff);
  421. return 0;
  422. }
  423. int asix_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
  424. u8 *data)
  425. {
  426. struct usbnet *dev = netdev_priv(net);
  427. u16 *eeprom_buff;
  428. int first_word, last_word;
  429. int i;
  430. int ret;
  431. netdev_dbg(net, "write EEPROM len %d, offset %d, magic 0x%x\n",
  432. eeprom->len, eeprom->offset, eeprom->magic);
  433. if (eeprom->len == 0)
  434. return -EINVAL;
  435. if (eeprom->magic != AX_EEPROM_MAGIC)
  436. return -EINVAL;
  437. first_word = eeprom->offset >> 1;
  438. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  439. eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
  440. GFP_KERNEL);
  441. if (!eeprom_buff)
  442. return -ENOMEM;
  443. /* align data to 16 bit boundaries, read the missing data from
  444. the EEPROM */
  445. if (eeprom->offset & 1) {
  446. ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, first_word, 0, 2,
  447. &(eeprom_buff[0]));
  448. if (ret < 0) {
  449. netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", first_word);
  450. goto free;
  451. }
  452. }
  453. if ((eeprom->offset + eeprom->len) & 1) {
  454. ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, last_word, 0, 2,
  455. &(eeprom_buff[last_word - first_word]));
  456. if (ret < 0) {
  457. netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", last_word);
  458. goto free;
  459. }
  460. }
  461. memcpy((u8 *)eeprom_buff + (eeprom->offset & 1), data, eeprom->len);
  462. /* write data to EEPROM */
  463. ret = asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0x0000, 0, 0, NULL);
  464. if (ret < 0) {
  465. netdev_err(net, "Failed to enable EEPROM write\n");
  466. goto free;
  467. }
  468. msleep(20);
  469. for (i = first_word; i <= last_word; i++) {
  470. netdev_dbg(net, "write to EEPROM at offset 0x%02x, data 0x%04x\n",
  471. i, eeprom_buff[i - first_word]);
  472. ret = asix_write_cmd(dev, AX_CMD_WRITE_EEPROM, i,
  473. eeprom_buff[i - first_word], 0, NULL);
  474. if (ret < 0) {
  475. netdev_err(net, "Failed to write EEPROM at offset 0x%02x.\n",
  476. i);
  477. goto free;
  478. }
  479. msleep(20);
  480. }
  481. ret = asix_write_cmd(dev, AX_CMD_WRITE_DISABLE, 0x0000, 0, 0, NULL);
  482. if (ret < 0) {
  483. netdev_err(net, "Failed to disable EEPROM write\n");
  484. goto free;
  485. }
  486. ret = 0;
  487. free:
  488. kfree(eeprom_buff);
  489. return ret;
  490. }
  491. void asix_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
  492. {
  493. /* Inherit standard device info */
  494. usbnet_get_drvinfo(net, info);
  495. strlcpy(info->driver, DRIVER_NAME, sizeof(info->driver));
  496. strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
  497. }
  498. int asix_set_mac_address(struct net_device *net, void *p)
  499. {
  500. struct usbnet *dev = netdev_priv(net);
  501. struct asix_data *data = (struct asix_data *)&dev->data;
  502. struct sockaddr *addr = p;
  503. if (netif_running(net))
  504. return -EBUSY;
  505. if (!is_valid_ether_addr(addr->sa_data))
  506. return -EADDRNOTAVAIL;
  507. memcpy(net->dev_addr, addr->sa_data, ETH_ALEN);
  508. /* We use the 20 byte dev->data
  509. * for our 6 byte mac buffer
  510. * to avoid allocating memory that
  511. * is tricky to free later */
  512. memcpy(data->mac_addr, addr->sa_data, ETH_ALEN);
  513. asix_write_cmd_async(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
  514. data->mac_addr);
  515. return 0;
  516. }