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