]> git.ipfire.org Git - ipfire-2.x.git/blob - src/patches/backports-4.2.6-1-add_usbnet_modules.patch
correct wrong headline at hardwaregraphs.cgi
[ipfire-2.x.git] / src / patches / backports-4.2.6-1-add_usbnet_modules.patch
1 diff -Naur backports-4.2.6-1.org/drivers/net/usb/asix_common.c backports-4.2.6-1/drivers/net/usb/asix_common.c
2 --- backports-4.2.6-1.org/drivers/net/usb/asix_common.c 1970-01-01 01:00:00.000000000 +0100
3 +++ backports-4.2.6-1/drivers/net/usb/asix_common.c 2016-06-28 14:35:17.965307221 +0200
4 @@ -0,0 +1,584 @@
5 +/*
6 + * ASIX AX8817X based USB 2.0 Ethernet Devices
7 + * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
8 + * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
9 + * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
10 + * Copyright (c) 2002-2003 TiVo Inc.
11 + *
12 + * This program is free software; you can redistribute it and/or modify
13 + * it under the terms of the GNU General Public License as published by
14 + * the Free Software Foundation; either version 2 of the License, or
15 + * (at your option) any later version.
16 + *
17 + * This program is distributed in the hope that it will be useful,
18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 + * GNU General Public License for more details.
21 + *
22 + * You should have received a copy of the GNU General Public License
23 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 + */
25 +
26 +#include "asix.h"
27 +
28 +int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
29 + u16 size, void *data)
30 +{
31 + int ret;
32 + ret = usbnet_read_cmd(dev, cmd,
33 + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
34 + value, index, data, size);
35 +
36 + if (ret != size && ret >= 0)
37 + return -EINVAL;
38 + return ret;
39 +}
40 +
41 +int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
42 + u16 size, void *data)
43 +{
44 + return usbnet_write_cmd(dev, cmd,
45 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
46 + value, index, data, size);
47 +}
48 +
49 +void asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
50 + u16 size, void *data)
51 +{
52 + usbnet_write_cmd_async(dev, cmd,
53 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
54 + value, index, data, size);
55 +}
56 +
57 +int asix_rx_fixup_internal(struct usbnet *dev, struct sk_buff *skb,
58 + struct asix_rx_fixup_info *rx)
59 +{
60 + int offset = 0;
61 +
62 + while (offset + sizeof(u16) <= skb->len) {
63 + u16 remaining = 0;
64 + unsigned char *data;
65 +
66 + if (!rx->size) {
67 + if ((skb->len - offset == sizeof(u16)) ||
68 + rx->split_head) {
69 + if(!rx->split_head) {
70 + rx->header = get_unaligned_le16(
71 + skb->data + offset);
72 + rx->split_head = true;
73 + offset += sizeof(u16);
74 + break;
75 + } else {
76 + rx->header |= (get_unaligned_le16(
77 + skb->data + offset)
78 + << 16);
79 + rx->split_head = false;
80 + offset += sizeof(u16);
81 + }
82 + } else {
83 + rx->header = get_unaligned_le32(skb->data +
84 + offset);
85 + offset += sizeof(u32);
86 + }
87 +
88 + /* get the packet length */
89 + rx->size = (u16) (rx->header & 0x7ff);
90 + if (rx->size != ((~rx->header >> 16) & 0x7ff)) {
91 + netdev_err(dev->net, "asix_rx_fixup() Bad Header Length 0x%x, offset %d\n",
92 + rx->header, offset);
93 + rx->size = 0;
94 + return 0;
95 + }
96 + rx->ax_skb = netdev_alloc_skb_ip_align(dev->net,
97 + rx->size);
98 + if (!rx->ax_skb)
99 + return 0;
100 + }
101 +
102 + if (rx->size > dev->net->mtu + ETH_HLEN + VLAN_HLEN) {
103 + netdev_err(dev->net, "asix_rx_fixup() Bad RX Length %d\n",
104 + rx->size);
105 + kfree_skb(rx->ax_skb);
106 + rx->ax_skb = NULL;
107 + rx->size = 0U;
108 +
109 + return 0;
110 + }
111 +
112 + if (rx->size > skb->len - offset) {
113 + remaining = rx->size - (skb->len - offset);
114 + rx->size = skb->len - offset;
115 + }
116 +
117 + data = skb_put(rx->ax_skb, rx->size);
118 + memcpy(data, skb->data + offset, rx->size);
119 + if (!remaining)
120 + usbnet_skb_return(dev, rx->ax_skb);
121 +
122 + offset += (rx->size + 1) & 0xfffe;
123 + rx->size = remaining;
124 + }
125 +
126 + if (skb->len != offset) {
127 + netdev_err(dev->net, "asix_rx_fixup() Bad SKB Length %d, %d\n",
128 + skb->len, offset);
129 + return 0;
130 + }
131 +
132 + return 1;
133 +}
134 +
135 +int asix_rx_fixup_common(struct usbnet *dev, struct sk_buff *skb)
136 +{
137 + struct asix_common_private *dp = dev->driver_priv;
138 + struct asix_rx_fixup_info *rx = &dp->rx_fixup_info;
139 +
140 + return asix_rx_fixup_internal(dev, skb, rx);
141 +}
142 +
143 +struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
144 + gfp_t flags)
145 +{
146 + int padlen;
147 + int headroom = skb_headroom(skb);
148 + int tailroom = skb_tailroom(skb);
149 + u32 packet_len;
150 + u32 padbytes = 0xffff0000;
151 +
152 + padlen = ((skb->len + 4) & (dev->maxpacket - 1)) ? 0 : 4;
153 +
154 + /* We need to push 4 bytes in front of frame (packet_len)
155 + * and maybe add 4 bytes after the end (if padlen is 4)
156 + *
157 + * Avoid skb_copy_expand() expensive call, using following rules :
158 + * - We are allowed to push 4 bytes in headroom if skb_header_cloned()
159 + * is false (and if we have 4 bytes of headroom)
160 + * - We are allowed to put 4 bytes at tail if skb_cloned()
161 + * is false (and if we have 4 bytes of tailroom)
162 + *
163 + * TCP packets for example are cloned, but skb_header_release()
164 + * was called in tcp stack, allowing us to use headroom for our needs.
165 + */
166 + if (!skb_header_cloned(skb) &&
167 + !(padlen && skb_cloned(skb)) &&
168 + headroom + tailroom >= 4 + padlen) {
169 + /* following should not happen, but better be safe */
170 + if (headroom < 4 ||
171 + tailroom < padlen) {
172 + skb->data = memmove(skb->head + 4, skb->data, skb->len);
173 + skb_set_tail_pointer(skb, skb->len);
174 + }
175 + } else {
176 + struct sk_buff *skb2;
177 +
178 + skb2 = skb_copy_expand(skb, 4, padlen, flags);
179 + dev_kfree_skb_any(skb);
180 + skb = skb2;
181 + if (!skb)
182 + return NULL;
183 + }
184 +
185 + packet_len = ((skb->len ^ 0x0000ffff) << 16) + skb->len;
186 + skb_push(skb, 4);
187 + cpu_to_le32s(&packet_len);
188 + skb_copy_to_linear_data(skb, &packet_len, sizeof(packet_len));
189 +
190 + if (padlen) {
191 + cpu_to_le32s(&padbytes);
192 + memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes));
193 + skb_put(skb, sizeof(padbytes));
194 + }
195 +
196 + usbnet_set_skb_tx_stats(skb, 1, 0);
197 + return skb;
198 +}
199 +
200 +int asix_set_sw_mii(struct usbnet *dev)
201 +{
202 + int ret;
203 + ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
204 + if (ret < 0)
205 + netdev_err(dev->net, "Failed to enable software MII access\n");
206 + return ret;
207 +}
208 +
209 +int asix_set_hw_mii(struct usbnet *dev)
210 +{
211 + int ret;
212 + ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
213 + if (ret < 0)
214 + netdev_err(dev->net, "Failed to enable hardware MII access\n");
215 + return ret;
216 +}
217 +
218 +int asix_read_phy_addr(struct usbnet *dev, int internal)
219 +{
220 + int offset = (internal ? 1 : 0);
221 + u8 buf[2];
222 + int ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf);
223 +
224 + netdev_dbg(dev->net, "asix_get_phy_addr()\n");
225 +
226 + if (ret < 0) {
227 + netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret);
228 + goto out;
229 + }
230 + netdev_dbg(dev->net, "asix_get_phy_addr() returning 0x%04x\n",
231 + *((__le16 *)buf));
232 + ret = buf[offset];
233 +
234 +out:
235 + return ret;
236 +}
237 +
238 +int asix_get_phy_addr(struct usbnet *dev)
239 +{
240 + /* return the address of the internal phy */
241 + return asix_read_phy_addr(dev, 1);
242 +}
243 +
244 +
245 +int asix_sw_reset(struct usbnet *dev, u8 flags)
246 +{
247 + int ret;
248 +
249 + ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL);
250 + if (ret < 0)
251 + netdev_err(dev->net, "Failed to send software reset: %02x\n", ret);
252 +
253 + return ret;
254 +}
255 +
256 +u16 asix_read_rx_ctl(struct usbnet *dev)
257 +{
258 + __le16 v;
259 + int ret = asix_read_cmd(dev, AX_CMD_READ_RX_CTL, 0, 0, 2, &v);
260 +
261 + if (ret < 0) {
262 + netdev_err(dev->net, "Error reading RX_CTL register: %02x\n", ret);
263 + goto out;
264 + }
265 + ret = le16_to_cpu(v);
266 +out:
267 + return ret;
268 +}
269 +
270 +int asix_write_rx_ctl(struct usbnet *dev, u16 mode)
271 +{
272 + int ret;
273 +
274 + netdev_dbg(dev->net, "asix_write_rx_ctl() - mode = 0x%04x\n", mode);
275 + ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
276 + if (ret < 0)
277 + netdev_err(dev->net, "Failed to write RX_CTL mode to 0x%04x: %02x\n",
278 + mode, ret);
279 +
280 + return ret;
281 +}
282 +
283 +u16 asix_read_medium_status(struct usbnet *dev)
284 +{
285 + __le16 v;
286 + int ret = asix_read_cmd(dev, AX_CMD_READ_MEDIUM_STATUS, 0, 0, 2, &v);
287 +
288 + if (ret < 0) {
289 + netdev_err(dev->net, "Error reading Medium Status register: %02x\n",
290 + ret);
291 + return ret; /* TODO: callers not checking for error ret */
292 + }
293 +
294 + return le16_to_cpu(v);
295 +
296 +}
297 +
298 +int asix_write_medium_mode(struct usbnet *dev, u16 mode)
299 +{
300 + int ret;
301 +
302 + netdev_dbg(dev->net, "asix_write_medium_mode() - mode = 0x%04x\n", mode);
303 + ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
304 + if (ret < 0)
305 + netdev_err(dev->net, "Failed to write Medium Mode mode to 0x%04x: %02x\n",
306 + mode, ret);
307 +
308 + return ret;
309 +}
310 +
311 +int asix_write_gpio(struct usbnet *dev, u16 value, int sleep)
312 +{
313 + int ret;
314 +
315 + netdev_dbg(dev->net, "asix_write_gpio() - value = 0x%04x\n", value);
316 + ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS, value, 0, 0, NULL);
317 + if (ret < 0)
318 + netdev_err(dev->net, "Failed to write GPIO value 0x%04x: %02x\n",
319 + value, ret);
320 +
321 + if (sleep)
322 + msleep(sleep);
323 +
324 + return ret;
325 +}
326 +
327 +/*
328 + * AX88772 & AX88178 have a 16-bit RX_CTL value
329 + */
330 +void asix_set_multicast(struct net_device *net)
331 +{
332 + struct usbnet *dev = netdev_priv(net);
333 + struct asix_data *data = (struct asix_data *)&dev->data;
334 + u16 rx_ctl = AX_DEFAULT_RX_CTL;
335 +
336 + if (net->flags & IFF_PROMISC) {
337 + rx_ctl |= AX_RX_CTL_PRO;
338 + } else if (net->flags & IFF_ALLMULTI ||
339 + netdev_mc_count(net) > AX_MAX_MCAST) {
340 + rx_ctl |= AX_RX_CTL_AMALL;
341 + } else if (netdev_mc_empty(net)) {
342 + /* just broadcast and directed */
343 + } else {
344 + /* We use the 20 byte dev->data
345 + * for our 8 byte filter buffer
346 + * to avoid allocating memory that
347 + * is tricky to free later */
348 + struct netdev_hw_addr *ha;
349 + u32 crc_bits;
350 +
351 + memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
352 +
353 + /* Build the multicast hash filter. */
354 + netdev_for_each_mc_addr(ha, net) {
355 + crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
356 + data->multi_filter[crc_bits >> 3] |=
357 + 1 << (crc_bits & 7);
358 + }
359 +
360 + asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
361 + AX_MCAST_FILTER_SIZE, data->multi_filter);
362 +
363 + rx_ctl |= AX_RX_CTL_AM;
364 + }
365 +
366 + asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
367 +}
368 +
369 +int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
370 +{
371 + struct usbnet *dev = netdev_priv(netdev);
372 + __le16 res;
373 +
374 + mutex_lock(&dev->phy_mutex);
375 + asix_set_sw_mii(dev);
376 + asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
377 + (__u16)loc, 2, &res);
378 + asix_set_hw_mii(dev);
379 + mutex_unlock(&dev->phy_mutex);
380 +
381 + netdev_dbg(dev->net, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
382 + phy_id, loc, le16_to_cpu(res));
383 +
384 + return le16_to_cpu(res);
385 +}
386 +
387 +void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
388 +{
389 + struct usbnet *dev = netdev_priv(netdev);
390 + __le16 res = cpu_to_le16(val);
391 +
392 + netdev_dbg(dev->net, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n",
393 + phy_id, loc, val);
394 + mutex_lock(&dev->phy_mutex);
395 + asix_set_sw_mii(dev);
396 + asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, &res);
397 + asix_set_hw_mii(dev);
398 + mutex_unlock(&dev->phy_mutex);
399 +}
400 +
401 +void asix_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
402 +{
403 + struct usbnet *dev = netdev_priv(net);
404 + u8 opt;
405 +
406 + if (asix_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
407 + wolinfo->supported = 0;
408 + wolinfo->wolopts = 0;
409 + return;
410 + }
411 + wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
412 + wolinfo->wolopts = 0;
413 + if (opt & AX_MONITOR_LINK)
414 + wolinfo->wolopts |= WAKE_PHY;
415 + if (opt & AX_MONITOR_MAGIC)
416 + wolinfo->wolopts |= WAKE_MAGIC;
417 +}
418 +
419 +int asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
420 +{
421 + struct usbnet *dev = netdev_priv(net);
422 + u8 opt = 0;
423 +
424 + if (wolinfo->wolopts & WAKE_PHY)
425 + opt |= AX_MONITOR_LINK;
426 + if (wolinfo->wolopts & WAKE_MAGIC)
427 + opt |= AX_MONITOR_MAGIC;
428 +
429 + if (asix_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
430 + opt, 0, 0, NULL) < 0)
431 + return -EINVAL;
432 +
433 + return 0;
434 +}
435 +
436 +int asix_get_eeprom_len(struct net_device *net)
437 +{
438 + return AX_EEPROM_LEN;
439 +}
440 +
441 +int asix_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
442 + u8 *data)
443 +{
444 + struct usbnet *dev = netdev_priv(net);
445 + u16 *eeprom_buff;
446 + int first_word, last_word;
447 + int i;
448 +
449 + if (eeprom->len == 0)
450 + return -EINVAL;
451 +
452 + eeprom->magic = AX_EEPROM_MAGIC;
453 +
454 + first_word = eeprom->offset >> 1;
455 + last_word = (eeprom->offset + eeprom->len - 1) >> 1;
456 +
457 + eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
458 + GFP_KERNEL);
459 + if (!eeprom_buff)
460 + return -ENOMEM;
461 +
462 + /* ax8817x returns 2 bytes from eeprom on read */
463 + for (i = first_word; i <= last_word; i++) {
464 + if (asix_read_cmd(dev, AX_CMD_READ_EEPROM, i, 0, 2,
465 + &(eeprom_buff[i - first_word])) < 0) {
466 + kfree(eeprom_buff);
467 + return -EIO;
468 + }
469 + }
470 +
471 + memcpy(data, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
472 + kfree(eeprom_buff);
473 + return 0;
474 +}
475 +
476 +int asix_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
477 + u8 *data)
478 +{
479 + struct usbnet *dev = netdev_priv(net);
480 + u16 *eeprom_buff;
481 + int first_word, last_word;
482 + int i;
483 + int ret;
484 +
485 + netdev_dbg(net, "write EEPROM len %d, offset %d, magic 0x%x\n",
486 + eeprom->len, eeprom->offset, eeprom->magic);
487 +
488 + if (eeprom->len == 0)
489 + return -EINVAL;
490 +
491 + if (eeprom->magic != AX_EEPROM_MAGIC)
492 + return -EINVAL;
493 +
494 + first_word = eeprom->offset >> 1;
495 + last_word = (eeprom->offset + eeprom->len - 1) >> 1;
496 +
497 + eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
498 + GFP_KERNEL);
499 + if (!eeprom_buff)
500 + return -ENOMEM;
501 +
502 + /* align data to 16 bit boundaries, read the missing data from
503 + the EEPROM */
504 + if (eeprom->offset & 1) {
505 + ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, first_word, 0, 2,
506 + &(eeprom_buff[0]));
507 + if (ret < 0) {
508 + netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", first_word);
509 + goto free;
510 + }
511 + }
512 +
513 + if ((eeprom->offset + eeprom->len) & 1) {
514 + ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, last_word, 0, 2,
515 + &(eeprom_buff[last_word - first_word]));
516 + if (ret < 0) {
517 + netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", last_word);
518 + goto free;
519 + }
520 + }
521 +
522 + memcpy((u8 *)eeprom_buff + (eeprom->offset & 1), data, eeprom->len);
523 +
524 + /* write data to EEPROM */
525 + ret = asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0x0000, 0, 0, NULL);
526 + if (ret < 0) {
527 + netdev_err(net, "Failed to enable EEPROM write\n");
528 + goto free;
529 + }
530 + msleep(20);
531 +
532 + for (i = first_word; i <= last_word; i++) {
533 + netdev_dbg(net, "write to EEPROM at offset 0x%02x, data 0x%04x\n",
534 + i, eeprom_buff[i - first_word]);
535 + ret = asix_write_cmd(dev, AX_CMD_WRITE_EEPROM, i,
536 + eeprom_buff[i - first_word], 0, NULL);
537 + if (ret < 0) {
538 + netdev_err(net, "Failed to write EEPROM at offset 0x%02x.\n",
539 + i);
540 + goto free;
541 + }
542 + msleep(20);
543 + }
544 +
545 + ret = asix_write_cmd(dev, AX_CMD_WRITE_DISABLE, 0x0000, 0, 0, NULL);
546 + if (ret < 0) {
547 + netdev_err(net, "Failed to disable EEPROM write\n");
548 + goto free;
549 + }
550 +
551 + ret = 0;
552 +free:
553 + kfree(eeprom_buff);
554 + return ret;
555 +}
556 +
557 +void asix_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
558 +{
559 + /* Inherit standard device info */
560 + usbnet_get_drvinfo(net, info);
561 + strlcpy(info->driver, DRIVER_NAME, sizeof(info->driver));
562 + strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
563 + info->eedump_len = AX_EEPROM_LEN;
564 +}
565 +
566 +int asix_set_mac_address(struct net_device *net, void *p)
567 +{
568 + struct usbnet *dev = netdev_priv(net);
569 + struct asix_data *data = (struct asix_data *)&dev->data;
570 + struct sockaddr *addr = p;
571 +
572 + if (netif_running(net))
573 + return -EBUSY;
574 + if (!is_valid_ether_addr(addr->sa_data))
575 + return -EADDRNOTAVAIL;
576 +
577 + memcpy(net->dev_addr, addr->sa_data, ETH_ALEN);
578 +
579 + /* We use the 20 byte dev->data
580 + * for our 6 byte mac buffer
581 + * to avoid allocating memory that
582 + * is tricky to free later */
583 + memcpy(data->mac_addr, addr->sa_data, ETH_ALEN);
584 + asix_write_cmd_async(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
585 + data->mac_addr);
586 +
587 + return 0;
588 +}
589 diff -Naur backports-4.2.6-1.org/drivers/net/usb/asix_devices.c backports-4.2.6-1/drivers/net/usb/asix_devices.c
590 --- backports-4.2.6-1.org/drivers/net/usb/asix_devices.c 1970-01-01 01:00:00.000000000 +0100
591 +++ backports-4.2.6-1/drivers/net/usb/asix_devices.c 2016-06-28 14:35:17.965307221 +0200
592 @@ -0,0 +1,1107 @@
593 +/*
594 + * ASIX AX8817X based USB 2.0 Ethernet Devices
595 + * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
596 + * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
597 + * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
598 + * Copyright (c) 2002-2003 TiVo Inc.
599 + *
600 + * This program is free software; you can redistribute it and/or modify
601 + * it under the terms of the GNU General Public License as published by
602 + * the Free Software Foundation; either version 2 of the License, or
603 + * (at your option) any later version.
604 + *
605 + * This program is distributed in the hope that it will be useful,
606 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
607 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
608 + * GNU General Public License for more details.
609 + *
610 + * You should have received a copy of the GNU General Public License
611 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
612 + */
613 +
614 +#include "asix.h"
615 +
616 +#define PHY_MODE_MARVELL 0x0000
617 +#define MII_MARVELL_LED_CTRL 0x0018
618 +#define MII_MARVELL_STATUS 0x001b
619 +#define MII_MARVELL_CTRL 0x0014
620 +
621 +#define MARVELL_LED_MANUAL 0x0019
622 +
623 +#define MARVELL_STATUS_HWCFG 0x0004
624 +
625 +#define MARVELL_CTRL_TXDELAY 0x0002
626 +#define MARVELL_CTRL_RXDELAY 0x0080
627 +
628 +#define PHY_MODE_RTL8211CL 0x000C
629 +
630 +struct ax88172_int_data {
631 + __le16 res1;
632 + u8 link;
633 + __le16 res2;
634 + u8 status;
635 + __le16 res3;
636 +} __packed;
637 +
638 +static void asix_status(struct usbnet *dev, struct urb *urb)
639 +{
640 + struct ax88172_int_data *event;
641 + int link;
642 +
643 + if (urb->actual_length < 8)
644 + return;
645 +
646 + event = urb->transfer_buffer;
647 + link = event->link & 0x01;
648 + if (netif_carrier_ok(dev->net) != link) {
649 + usbnet_link_change(dev, link, 1);
650 + netdev_dbg(dev->net, "Link Status is: %d\n", link);
651 + }
652 +}
653 +
654 +static void asix_set_netdev_dev_addr(struct usbnet *dev, u8 *addr)
655 +{
656 + if (is_valid_ether_addr(addr)) {
657 + memcpy(dev->net->dev_addr, addr, ETH_ALEN);
658 + } else {
659 + netdev_info(dev->net, "invalid hw address, using random\n");
660 + eth_hw_addr_random(dev->net);
661 + }
662 +}
663 +
664 +/* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
665 +static u32 asix_get_phyid(struct usbnet *dev)
666 +{
667 + int phy_reg;
668 + u32 phy_id;
669 + int i;
670 +
671 + /* Poll for the rare case the FW or phy isn't ready yet. */
672 + for (i = 0; i < 100; i++) {
673 + phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID1);
674 + if (phy_reg != 0 && phy_reg != 0xFFFF)
675 + break;
676 + mdelay(1);
677 + }
678 +
679 + if (phy_reg <= 0 || phy_reg == 0xFFFF)
680 + return 0;
681 +
682 + phy_id = (phy_reg & 0xffff) << 16;
683 +
684 + phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID2);
685 + if (phy_reg < 0)
686 + return 0;
687 +
688 + phy_id |= (phy_reg & 0xffff);
689 +
690 + return phy_id;
691 +}
692 +
693 +static u32 asix_get_link(struct net_device *net)
694 +{
695 + struct usbnet *dev = netdev_priv(net);
696 +
697 + return mii_link_ok(&dev->mii);
698 +}
699 +
700 +static int asix_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
701 +{
702 + struct usbnet *dev = netdev_priv(net);
703 +
704 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
705 +}
706 +
707 +/* We need to override some ethtool_ops so we require our
708 + own structure so we don't interfere with other usbnet
709 + devices that may be connected at the same time. */
710 +static const struct ethtool_ops ax88172_ethtool_ops = {
711 + .get_drvinfo = asix_get_drvinfo,
712 + .get_link = asix_get_link,
713 + .get_msglevel = usbnet_get_msglevel,
714 + .set_msglevel = usbnet_set_msglevel,
715 + .get_wol = asix_get_wol,
716 + .set_wol = asix_set_wol,
717 + .get_eeprom_len = asix_get_eeprom_len,
718 + .get_eeprom = asix_get_eeprom,
719 + .set_eeprom = asix_set_eeprom,
720 + .get_settings = usbnet_get_settings,
721 + .set_settings = usbnet_set_settings,
722 + .nway_reset = usbnet_nway_reset,
723 +};
724 +
725 +static void ax88172_set_multicast(struct net_device *net)
726 +{
727 + struct usbnet *dev = netdev_priv(net);
728 + struct asix_data *data = (struct asix_data *)&dev->data;
729 + u8 rx_ctl = 0x8c;
730 +
731 + if (net->flags & IFF_PROMISC) {
732 + rx_ctl |= 0x01;
733 + } else if (net->flags & IFF_ALLMULTI ||
734 + netdev_mc_count(net) > AX_MAX_MCAST) {
735 + rx_ctl |= 0x02;
736 + } else if (netdev_mc_empty(net)) {
737 + /* just broadcast and directed */
738 + } else {
739 + /* We use the 20 byte dev->data
740 + * for our 8 byte filter buffer
741 + * to avoid allocating memory that
742 + * is tricky to free later */
743 + struct netdev_hw_addr *ha;
744 + u32 crc_bits;
745 +
746 + memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
747 +
748 + /* Build the multicast hash filter. */
749 + netdev_for_each_mc_addr(ha, net) {
750 + crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
751 + data->multi_filter[crc_bits >> 3] |=
752 + 1 << (crc_bits & 7);
753 + }
754 +
755 + asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
756 + AX_MCAST_FILTER_SIZE, data->multi_filter);
757 +
758 + rx_ctl |= 0x10;
759 + }
760 +
761 + asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
762 +}
763 +
764 +static int ax88172_link_reset(struct usbnet *dev)
765 +{
766 + u8 mode;
767 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
768 +
769 + mii_check_media(&dev->mii, 1, 1);
770 + mii_ethtool_gset(&dev->mii, &ecmd);
771 + mode = AX88172_MEDIUM_DEFAULT;
772 +
773 + if (ecmd.duplex != DUPLEX_FULL)
774 + mode |= ~AX88172_MEDIUM_FD;
775 +
776 + netdev_dbg(dev->net, "ax88172_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
777 + ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
778 +
779 + asix_write_medium_mode(dev, mode);
780 +
781 + return 0;
782 +}
783 +
784 +static const struct net_device_ops ax88172_netdev_ops = {
785 + .ndo_open = usbnet_open,
786 + .ndo_stop = usbnet_stop,
787 + .ndo_start_xmit = usbnet_start_xmit,
788 + .ndo_tx_timeout = usbnet_tx_timeout,
789 + .ndo_change_mtu = usbnet_change_mtu,
790 + .ndo_set_mac_address = eth_mac_addr,
791 + .ndo_validate_addr = eth_validate_addr,
792 + .ndo_do_ioctl = asix_ioctl,
793 + .ndo_set_rx_mode = ax88172_set_multicast,
794 +};
795 +
796 +static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
797 +{
798 + int ret = 0;
799 + u8 buf[ETH_ALEN];
800 + int i;
801 + unsigned long gpio_bits = dev->driver_info->data;
802 +
803 + usbnet_get_endpoints(dev,intf);
804 +
805 + /* Toggle the GPIOs in a manufacturer/model specific way */
806 + for (i = 2; i >= 0; i--) {
807 + ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS,
808 + (gpio_bits >> (i * 8)) & 0xff, 0, 0, NULL);
809 + if (ret < 0)
810 + goto out;
811 + msleep(5);
812 + }
813 +
814 + ret = asix_write_rx_ctl(dev, 0x80);
815 + if (ret < 0)
816 + goto out;
817 +
818 + /* Get the MAC address */
819 + ret = asix_read_cmd(dev, AX88172_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
820 + if (ret < 0) {
821 + netdev_dbg(dev->net, "read AX_CMD_READ_NODE_ID failed: %d\n",
822 + ret);
823 + goto out;
824 + }
825 +
826 + asix_set_netdev_dev_addr(dev, buf);
827 +
828 + /* Initialize MII structure */
829 + dev->mii.dev = dev->net;
830 + dev->mii.mdio_read = asix_mdio_read;
831 + dev->mii.mdio_write = asix_mdio_write;
832 + dev->mii.phy_id_mask = 0x3f;
833 + dev->mii.reg_num_mask = 0x1f;
834 + dev->mii.phy_id = asix_get_phy_addr(dev);
835 +
836 + dev->net->netdev_ops = &ax88172_netdev_ops;
837 + dev->net->ethtool_ops = &ax88172_ethtool_ops;
838 + dev->net->needed_headroom = 4; /* cf asix_tx_fixup() */
839 + dev->net->needed_tailroom = 4; /* cf asix_tx_fixup() */
840 +
841 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
842 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
843 + ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
844 + mii_nway_restart(&dev->mii);
845 +
846 + return 0;
847 +
848 +out:
849 + return ret;
850 +}
851 +
852 +static const struct ethtool_ops ax88772_ethtool_ops = {
853 + .get_drvinfo = asix_get_drvinfo,
854 + .get_link = asix_get_link,
855 + .get_msglevel = usbnet_get_msglevel,
856 + .set_msglevel = usbnet_set_msglevel,
857 + .get_wol = asix_get_wol,
858 + .set_wol = asix_set_wol,
859 + .get_eeprom_len = asix_get_eeprom_len,
860 + .get_eeprom = asix_get_eeprom,
861 + .set_eeprom = asix_set_eeprom,
862 + .get_settings = usbnet_get_settings,
863 + .set_settings = usbnet_set_settings,
864 + .nway_reset = usbnet_nway_reset,
865 +};
866 +
867 +static int ax88772_link_reset(struct usbnet *dev)
868 +{
869 + u16 mode;
870 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
871 +
872 + mii_check_media(&dev->mii, 1, 1);
873 + mii_ethtool_gset(&dev->mii, &ecmd);
874 + mode = AX88772_MEDIUM_DEFAULT;
875 +
876 + if (ethtool_cmd_speed(&ecmd) != SPEED_100)
877 + mode &= ~AX_MEDIUM_PS;
878 +
879 + if (ecmd.duplex != DUPLEX_FULL)
880 + mode &= ~AX_MEDIUM_FD;
881 +
882 + netdev_dbg(dev->net, "ax88772_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
883 + ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
884 +
885 + asix_write_medium_mode(dev, mode);
886 +
887 + return 0;
888 +}
889 +
890 +static int ax88772_reset(struct usbnet *dev)
891 +{
892 + struct asix_data *data = (struct asix_data *)&dev->data;
893 + int ret, embd_phy;
894 + u16 rx_ctl;
895 +
896 + ret = asix_write_gpio(dev,
897 + AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5);
898 + if (ret < 0)
899 + goto out;
900 +
901 + embd_phy = ((asix_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0);
902 +
903 + ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
904 + if (ret < 0) {
905 + netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
906 + goto out;
907 + }
908 +
909 + ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL);
910 + if (ret < 0)
911 + goto out;
912 +
913 + msleep(150);
914 +
915 + ret = asix_sw_reset(dev, AX_SWRESET_CLEAR);
916 + if (ret < 0)
917 + goto out;
918 +
919 + msleep(150);
920 +
921 + if (embd_phy) {
922 + ret = asix_sw_reset(dev, AX_SWRESET_IPRL);
923 + if (ret < 0)
924 + goto out;
925 + } else {
926 + ret = asix_sw_reset(dev, AX_SWRESET_PRTE);
927 + if (ret < 0)
928 + goto out;
929 + }
930 +
931 + msleep(150);
932 + rx_ctl = asix_read_rx_ctl(dev);
933 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after software reset\n", rx_ctl);
934 + ret = asix_write_rx_ctl(dev, 0x0000);
935 + if (ret < 0)
936 + goto out;
937 +
938 + rx_ctl = asix_read_rx_ctl(dev);
939 + netdev_dbg(dev->net, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
940 +
941 + ret = asix_sw_reset(dev, AX_SWRESET_PRL);
942 + if (ret < 0)
943 + goto out;
944 +
945 + msleep(150);
946 +
947 + ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL);
948 + if (ret < 0)
949 + goto out;
950 +
951 + msleep(150);
952 +
953 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
954 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
955 + ADVERTISE_ALL | ADVERTISE_CSMA);
956 + mii_nway_restart(&dev->mii);
957 +
958 + ret = asix_write_medium_mode(dev, AX88772_MEDIUM_DEFAULT);
959 + if (ret < 0)
960 + goto out;
961 +
962 + ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
963 + AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
964 + AX88772_IPG2_DEFAULT, 0, NULL);
965 + if (ret < 0) {
966 + netdev_dbg(dev->net, "Write IPG,IPG1,IPG2 failed: %d\n", ret);
967 + goto out;
968 + }
969 +
970 + /* Rewrite MAC address */
971 + memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
972 + ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
973 + data->mac_addr);
974 + if (ret < 0)
975 + goto out;
976 +
977 + /* Set RX_CTL to default values with 2k buffer, and enable cactus */
978 + ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
979 + if (ret < 0)
980 + goto out;
981 +
982 + rx_ctl = asix_read_rx_ctl(dev);
983 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after all initializations\n",
984 + rx_ctl);
985 +
986 + rx_ctl = asix_read_medium_status(dev);
987 + netdev_dbg(dev->net,
988 + "Medium Status is 0x%04x after all initializations\n",
989 + rx_ctl);
990 +
991 + return 0;
992 +
993 +out:
994 + return ret;
995 +
996 +}
997 +
998 +static const struct net_device_ops ax88772_netdev_ops = {
999 + .ndo_open = usbnet_open,
1000 + .ndo_stop = usbnet_stop,
1001 + .ndo_start_xmit = usbnet_start_xmit,
1002 + .ndo_tx_timeout = usbnet_tx_timeout,
1003 + .ndo_change_mtu = usbnet_change_mtu,
1004 + .ndo_set_mac_address = asix_set_mac_address,
1005 + .ndo_validate_addr = eth_validate_addr,
1006 + .ndo_do_ioctl = asix_ioctl,
1007 + .ndo_set_rx_mode = asix_set_multicast,
1008 +};
1009 +
1010 +static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
1011 +{
1012 + int ret, embd_phy, i;
1013 + u8 buf[ETH_ALEN];
1014 + u32 phyid;
1015 +
1016 + usbnet_get_endpoints(dev,intf);
1017 +
1018 + /* Get the MAC address */
1019 + if (dev->driver_info->data & FLAG_EEPROM_MAC) {
1020 + for (i = 0; i < (ETH_ALEN >> 1); i++) {
1021 + ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x04 + i,
1022 + 0, 2, buf + i * 2);
1023 + if (ret < 0)
1024 + break;
1025 + }
1026 + } else {
1027 + ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
1028 + 0, 0, ETH_ALEN, buf);
1029 + }
1030 +
1031 + if (ret < 0) {
1032 + netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
1033 + return ret;
1034 + }
1035 +
1036 + asix_set_netdev_dev_addr(dev, buf);
1037 +
1038 + /* Initialize MII structure */
1039 + dev->mii.dev = dev->net;
1040 + dev->mii.mdio_read = asix_mdio_read;
1041 + dev->mii.mdio_write = asix_mdio_write;
1042 + dev->mii.phy_id_mask = 0x1f;
1043 + dev->mii.reg_num_mask = 0x1f;
1044 + dev->mii.phy_id = asix_get_phy_addr(dev);
1045 +
1046 + dev->net->netdev_ops = &ax88772_netdev_ops;
1047 + dev->net->ethtool_ops = &ax88772_ethtool_ops;
1048 + dev->net->needed_headroom = 4; /* cf asix_tx_fixup() */
1049 + dev->net->needed_tailroom = 4; /* cf asix_tx_fixup() */
1050 +
1051 + embd_phy = ((dev->mii.phy_id & 0x1f) == 0x10 ? 1 : 0);
1052 +
1053 + /* Reset the PHY to normal operation mode */
1054 + ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
1055 + if (ret < 0) {
1056 + netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
1057 + return ret;
1058 + }
1059 +
1060 + ax88772_reset(dev);
1061 +
1062 + /* Read PHYID register *AFTER* the PHY was reset properly */
1063 + phyid = asix_get_phyid(dev);
1064 + netdev_dbg(dev->net, "PHYID=0x%08x\n", phyid);
1065 +
1066 + /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
1067 + if (dev->driver_info->flags & FLAG_FRAMING_AX) {
1068 + /* hard_mtu is still the default - the device does not support
1069 + jumbo eth frames */
1070 + dev->rx_urb_size = 2048;
1071 + }
1072 +
1073 + dev->driver_priv = kzalloc(sizeof(struct asix_common_private), GFP_KERNEL);
1074 + if (!dev->driver_priv)
1075 + return -ENOMEM;
1076 +
1077 + return 0;
1078 +}
1079 +
1080 +static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)
1081 +{
1082 + kfree(dev->driver_priv);
1083 +}
1084 +
1085 +static const struct ethtool_ops ax88178_ethtool_ops = {
1086 + .get_drvinfo = asix_get_drvinfo,
1087 + .get_link = asix_get_link,
1088 + .get_msglevel = usbnet_get_msglevel,
1089 + .set_msglevel = usbnet_set_msglevel,
1090 + .get_wol = asix_get_wol,
1091 + .set_wol = asix_set_wol,
1092 + .get_eeprom_len = asix_get_eeprom_len,
1093 + .get_eeprom = asix_get_eeprom,
1094 + .set_eeprom = asix_set_eeprom,
1095 + .get_settings = usbnet_get_settings,
1096 + .set_settings = usbnet_set_settings,
1097 + .nway_reset = usbnet_nway_reset,
1098 +};
1099 +
1100 +static int marvell_phy_init(struct usbnet *dev)
1101 +{
1102 + struct asix_data *data = (struct asix_data *)&dev->data;
1103 + u16 reg;
1104 +
1105 + netdev_dbg(dev->net, "marvell_phy_init()\n");
1106 +
1107 + reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_MARVELL_STATUS);
1108 + netdev_dbg(dev->net, "MII_MARVELL_STATUS = 0x%04x\n", reg);
1109 +
1110 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_MARVELL_CTRL,
1111 + MARVELL_CTRL_RXDELAY | MARVELL_CTRL_TXDELAY);
1112 +
1113 + if (data->ledmode) {
1114 + reg = asix_mdio_read(dev->net, dev->mii.phy_id,
1115 + MII_MARVELL_LED_CTRL);
1116 + netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (1) = 0x%04x\n", reg);
1117 +
1118 + reg &= 0xf8ff;
1119 + reg |= (1 + 0x0100);
1120 + asix_mdio_write(dev->net, dev->mii.phy_id,
1121 + MII_MARVELL_LED_CTRL, reg);
1122 +
1123 + reg = asix_mdio_read(dev->net, dev->mii.phy_id,
1124 + MII_MARVELL_LED_CTRL);
1125 + netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (2) = 0x%04x\n", reg);
1126 + reg &= 0xfc0f;
1127 + }
1128 +
1129 + return 0;
1130 +}
1131 +
1132 +static int rtl8211cl_phy_init(struct usbnet *dev)
1133 +{
1134 + struct asix_data *data = (struct asix_data *)&dev->data;
1135 +
1136 + netdev_dbg(dev->net, "rtl8211cl_phy_init()\n");
1137 +
1138 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0005);
1139 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x0c, 0);
1140 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x01,
1141 + asix_mdio_read (dev->net, dev->mii.phy_id, 0x01) | 0x0080);
1142 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
1143 +
1144 + if (data->ledmode == 12) {
1145 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0002);
1146 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x1a, 0x00cb);
1147 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
1148 + }
1149 +
1150 + return 0;
1151 +}
1152 +
1153 +static int marvell_led_status(struct usbnet *dev, u16 speed)
1154 +{
1155 + u16 reg = asix_mdio_read(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL);
1156 +
1157 + netdev_dbg(dev->net, "marvell_led_status() read 0x%04x\n", reg);
1158 +
1159 + /* Clear out the center LED bits - 0x03F0 */
1160 + reg &= 0xfc0f;
1161 +
1162 + switch (speed) {
1163 + case SPEED_1000:
1164 + reg |= 0x03e0;
1165 + break;
1166 + case SPEED_100:
1167 + reg |= 0x03b0;
1168 + break;
1169 + default:
1170 + reg |= 0x02f0;
1171 + }
1172 +
1173 + netdev_dbg(dev->net, "marvell_led_status() writing 0x%04x\n", reg);
1174 + asix_mdio_write(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL, reg);
1175 +
1176 + return 0;
1177 +}
1178 +
1179 +static int ax88178_reset(struct usbnet *dev)
1180 +{
1181 + struct asix_data *data = (struct asix_data *)&dev->data;
1182 + int ret;
1183 + __le16 eeprom;
1184 + u8 status;
1185 + int gpio0 = 0;
1186 + u32 phyid;
1187 +
1188 + asix_read_cmd(dev, AX_CMD_READ_GPIOS, 0, 0, 1, &status);
1189 + netdev_dbg(dev->net, "GPIO Status: 0x%04x\n", status);
1190 +
1191 + asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0, 0, 0, NULL);
1192 + asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x0017, 0, 2, &eeprom);
1193 + asix_write_cmd(dev, AX_CMD_WRITE_DISABLE, 0, 0, 0, NULL);
1194 +
1195 + netdev_dbg(dev->net, "EEPROM index 0x17 is 0x%04x\n", eeprom);
1196 +
1197 + if (eeprom == cpu_to_le16(0xffff)) {
1198 + data->phymode = PHY_MODE_MARVELL;
1199 + data->ledmode = 0;
1200 + gpio0 = 1;
1201 + } else {
1202 + data->phymode = le16_to_cpu(eeprom) & 0x7F;
1203 + data->ledmode = le16_to_cpu(eeprom) >> 8;
1204 + gpio0 = (le16_to_cpu(eeprom) & 0x80) ? 0 : 1;
1205 + }
1206 + netdev_dbg(dev->net, "GPIO0: %d, PhyMode: %d\n", gpio0, data->phymode);
1207 +
1208 + /* Power up external GigaPHY through AX88178 GPIO pin */
1209 + asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_1 | AX_GPIO_GPO1EN, 40);
1210 + if ((le16_to_cpu(eeprom) >> 8) != 1) {
1211 + asix_write_gpio(dev, 0x003c, 30);
1212 + asix_write_gpio(dev, 0x001c, 300);
1213 + asix_write_gpio(dev, 0x003c, 30);
1214 + } else {
1215 + netdev_dbg(dev->net, "gpio phymode == 1 path\n");
1216 + asix_write_gpio(dev, AX_GPIO_GPO1EN, 30);
1217 + asix_write_gpio(dev, AX_GPIO_GPO1EN | AX_GPIO_GPO_1, 30);
1218 + }
1219 +
1220 + /* Read PHYID register *AFTER* powering up PHY */
1221 + phyid = asix_get_phyid(dev);
1222 + netdev_dbg(dev->net, "PHYID=0x%08x\n", phyid);
1223 +
1224 + /* Set AX88178 to enable MII/GMII/RGMII interface for external PHY */
1225 + asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0, 0, 0, NULL);
1226 +
1227 + asix_sw_reset(dev, 0);
1228 + msleep(150);
1229 +
1230 + asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD);
1231 + msleep(150);
1232 +
1233 + asix_write_rx_ctl(dev, 0);
1234 +
1235 + if (data->phymode == PHY_MODE_MARVELL) {
1236 + marvell_phy_init(dev);
1237 + msleep(60);
1238 + } else if (data->phymode == PHY_MODE_RTL8211CL)
1239 + rtl8211cl_phy_init(dev);
1240 +
1241 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR,
1242 + BMCR_RESET | BMCR_ANENABLE);
1243 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
1244 + ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
1245 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000,
1246 + ADVERTISE_1000FULL);
1247 +
1248 + mii_nway_restart(&dev->mii);
1249 +
1250 + ret = asix_write_medium_mode(dev, AX88178_MEDIUM_DEFAULT);
1251 + if (ret < 0)
1252 + return ret;
1253 +
1254 + /* Rewrite MAC address */
1255 + memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
1256 + ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
1257 + data->mac_addr);
1258 + if (ret < 0)
1259 + return ret;
1260 +
1261 + ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
1262 + if (ret < 0)
1263 + return ret;
1264 +
1265 + return 0;
1266 +}
1267 +
1268 +static int ax88178_link_reset(struct usbnet *dev)
1269 +{
1270 + u16 mode;
1271 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
1272 + struct asix_data *data = (struct asix_data *)&dev->data;
1273 + u32 speed;
1274 +
1275 + netdev_dbg(dev->net, "ax88178_link_reset()\n");
1276 +
1277 + mii_check_media(&dev->mii, 1, 1);
1278 + mii_ethtool_gset(&dev->mii, &ecmd);
1279 + mode = AX88178_MEDIUM_DEFAULT;
1280 + speed = ethtool_cmd_speed(&ecmd);
1281 +
1282 + if (speed == SPEED_1000)
1283 + mode |= AX_MEDIUM_GM;
1284 + else if (speed == SPEED_100)
1285 + mode |= AX_MEDIUM_PS;
1286 + else
1287 + mode &= ~(AX_MEDIUM_PS | AX_MEDIUM_GM);
1288 +
1289 + mode |= AX_MEDIUM_ENCK;
1290 +
1291 + if (ecmd.duplex == DUPLEX_FULL)
1292 + mode |= AX_MEDIUM_FD;
1293 + else
1294 + mode &= ~AX_MEDIUM_FD;
1295 +
1296 + netdev_dbg(dev->net, "ax88178_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
1297 + speed, ecmd.duplex, mode);
1298 +
1299 + asix_write_medium_mode(dev, mode);
1300 +
1301 + if (data->phymode == PHY_MODE_MARVELL && data->ledmode)
1302 + marvell_led_status(dev, speed);
1303 +
1304 + return 0;
1305 +}
1306 +
1307 +static void ax88178_set_mfb(struct usbnet *dev)
1308 +{
1309 + u16 mfb = AX_RX_CTL_MFB_16384;
1310 + u16 rxctl;
1311 + u16 medium;
1312 + int old_rx_urb_size = dev->rx_urb_size;
1313 +
1314 + if (dev->hard_mtu < 2048) {
1315 + dev->rx_urb_size = 2048;
1316 + mfb = AX_RX_CTL_MFB_2048;
1317 + } else if (dev->hard_mtu < 4096) {
1318 + dev->rx_urb_size = 4096;
1319 + mfb = AX_RX_CTL_MFB_4096;
1320 + } else if (dev->hard_mtu < 8192) {
1321 + dev->rx_urb_size = 8192;
1322 + mfb = AX_RX_CTL_MFB_8192;
1323 + } else if (dev->hard_mtu < 16384) {
1324 + dev->rx_urb_size = 16384;
1325 + mfb = AX_RX_CTL_MFB_16384;
1326 + }
1327 +
1328 + rxctl = asix_read_rx_ctl(dev);
1329 + asix_write_rx_ctl(dev, (rxctl & ~AX_RX_CTL_MFB_16384) | mfb);
1330 +
1331 + medium = asix_read_medium_status(dev);
1332 + if (dev->net->mtu > 1500)
1333 + medium |= AX_MEDIUM_JFE;
1334 + else
1335 + medium &= ~AX_MEDIUM_JFE;
1336 + asix_write_medium_mode(dev, medium);
1337 +
1338 + if (dev->rx_urb_size > old_rx_urb_size)
1339 + usbnet_unlink_rx_urbs(dev);
1340 +}
1341 +
1342 +static int ax88178_change_mtu(struct net_device *net, int new_mtu)
1343 +{
1344 + struct usbnet *dev = netdev_priv(net);
1345 + int ll_mtu = new_mtu + net->hard_header_len + 4;
1346 +
1347 + netdev_dbg(dev->net, "ax88178_change_mtu() new_mtu=%d\n", new_mtu);
1348 +
1349 + if (new_mtu <= 0 || ll_mtu > 16384)
1350 + return -EINVAL;
1351 +
1352 + if ((ll_mtu % dev->maxpacket) == 0)
1353 + return -EDOM;
1354 +
1355 + net->mtu = new_mtu;
1356 + dev->hard_mtu = net->mtu + net->hard_header_len;
1357 + ax88178_set_mfb(dev);
1358 +
1359 + /* max qlen depend on hard_mtu and rx_urb_size */
1360 + usbnet_update_max_qlen(dev);
1361 +
1362 + return 0;
1363 +}
1364 +
1365 +static const struct net_device_ops ax88178_netdev_ops = {
1366 + .ndo_open = usbnet_open,
1367 + .ndo_stop = usbnet_stop,
1368 + .ndo_start_xmit = usbnet_start_xmit,
1369 + .ndo_tx_timeout = usbnet_tx_timeout,
1370 + .ndo_set_mac_address = asix_set_mac_address,
1371 + .ndo_validate_addr = eth_validate_addr,
1372 + .ndo_set_rx_mode = asix_set_multicast,
1373 + .ndo_do_ioctl = asix_ioctl,
1374 + .ndo_change_mtu = ax88178_change_mtu,
1375 +};
1376 +
1377 +static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
1378 +{
1379 + int ret;
1380 + u8 buf[ETH_ALEN];
1381 +
1382 + usbnet_get_endpoints(dev,intf);
1383 +
1384 + /* Get the MAC address */
1385 + ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
1386 + if (ret < 0) {
1387 + netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
1388 + return ret;
1389 + }
1390 +
1391 + asix_set_netdev_dev_addr(dev, buf);
1392 +
1393 + /* Initialize MII structure */
1394 + dev->mii.dev = dev->net;
1395 + dev->mii.mdio_read = asix_mdio_read;
1396 + dev->mii.mdio_write = asix_mdio_write;
1397 + dev->mii.phy_id_mask = 0x1f;
1398 + dev->mii.reg_num_mask = 0xff;
1399 + dev->mii.supports_gmii = 1;
1400 + dev->mii.phy_id = asix_get_phy_addr(dev);
1401 +
1402 + dev->net->netdev_ops = &ax88178_netdev_ops;
1403 + dev->net->ethtool_ops = &ax88178_ethtool_ops;
1404 +
1405 + /* Blink LEDS so users know driver saw dongle */
1406 + asix_sw_reset(dev, 0);
1407 + msleep(150);
1408 +
1409 + asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD);
1410 + msleep(150);
1411 +
1412 + /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
1413 + if (dev->driver_info->flags & FLAG_FRAMING_AX) {
1414 + /* hard_mtu is still the default - the device does not support
1415 + jumbo eth frames */
1416 + dev->rx_urb_size = 2048;
1417 + }
1418 +
1419 + dev->driver_priv = kzalloc(sizeof(struct asix_common_private), GFP_KERNEL);
1420 + if (!dev->driver_priv)
1421 + return -ENOMEM;
1422 +
1423 + return 0;
1424 +}
1425 +
1426 +static const struct driver_info ax8817x_info = {
1427 + .description = "ASIX AX8817x USB 2.0 Ethernet",
1428 + .bind = ax88172_bind,
1429 + .status = asix_status,
1430 + .link_reset = ax88172_link_reset,
1431 + .reset = ax88172_link_reset,
1432 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
1433 + .data = 0x00130103,
1434 +};
1435 +
1436 +static const struct driver_info dlink_dub_e100_info = {
1437 + .description = "DLink DUB-E100 USB Ethernet",
1438 + .bind = ax88172_bind,
1439 + .status = asix_status,
1440 + .link_reset = ax88172_link_reset,
1441 + .reset = ax88172_link_reset,
1442 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
1443 + .data = 0x009f9d9f,
1444 +};
1445 +
1446 +static const struct driver_info netgear_fa120_info = {
1447 + .description = "Netgear FA-120 USB Ethernet",
1448 + .bind = ax88172_bind,
1449 + .status = asix_status,
1450 + .link_reset = ax88172_link_reset,
1451 + .reset = ax88172_link_reset,
1452 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
1453 + .data = 0x00130103,
1454 +};
1455 +
1456 +static const struct driver_info hawking_uf200_info = {
1457 + .description = "Hawking UF200 USB Ethernet",
1458 + .bind = ax88172_bind,
1459 + .status = asix_status,
1460 + .link_reset = ax88172_link_reset,
1461 + .reset = ax88172_link_reset,
1462 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
1463 + .data = 0x001f1d1f,
1464 +};
1465 +
1466 +static const struct driver_info ax88772_info = {
1467 + .description = "ASIX AX88772 USB 2.0 Ethernet",
1468 + .bind = ax88772_bind,
1469 + .unbind = ax88772_unbind,
1470 + .status = asix_status,
1471 + .link_reset = ax88772_link_reset,
1472 + .reset = ax88772_link_reset,
1473 + .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR | FLAG_MULTI_PACKET,
1474 + .rx_fixup = asix_rx_fixup_common,
1475 + .tx_fixup = asix_tx_fixup,
1476 +};
1477 +
1478 +static const struct driver_info ax88772b_info = {
1479 + .description = "ASIX AX88772B USB 2.0 Ethernet",
1480 + .bind = ax88772_bind,
1481 + .unbind = ax88772_unbind,
1482 + .status = asix_status,
1483 + .link_reset = ax88772_link_reset,
1484 + .reset = ax88772_reset,
1485 + .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
1486 + FLAG_MULTI_PACKET,
1487 + .rx_fixup = asix_rx_fixup_common,
1488 + .tx_fixup = asix_tx_fixup,
1489 + .data = FLAG_EEPROM_MAC,
1490 +};
1491 +
1492 +static const struct driver_info ax88178_info = {
1493 + .description = "ASIX AX88178 USB 2.0 Ethernet",
1494 + .bind = ax88178_bind,
1495 + .unbind = ax88772_unbind,
1496 + .status = asix_status,
1497 + .link_reset = ax88178_link_reset,
1498 + .reset = ax88178_reset,
1499 + .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
1500 + FLAG_MULTI_PACKET,
1501 + .rx_fixup = asix_rx_fixup_common,
1502 + .tx_fixup = asix_tx_fixup,
1503 +};
1504 +
1505 +/*
1506 + * USBLINK 20F9 "USB 2.0 LAN" USB ethernet adapter, typically found in
1507 + * no-name packaging.
1508 + * USB device strings are:
1509 + * 1: Manufacturer: USBLINK
1510 + * 2: Product: HG20F9 USB2.0
1511 + * 3: Serial: 000003
1512 + * Appears to be compatible with Asix 88772B.
1513 + */
1514 +static const struct driver_info hg20f9_info = {
1515 + .description = "HG20F9 USB 2.0 Ethernet",
1516 + .bind = ax88772_bind,
1517 + .unbind = ax88772_unbind,
1518 + .status = asix_status,
1519 + .link_reset = ax88772_link_reset,
1520 + .reset = ax88772_reset,
1521 + .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
1522 + FLAG_MULTI_PACKET,
1523 + .rx_fixup = asix_rx_fixup_common,
1524 + .tx_fixup = asix_tx_fixup,
1525 + .data = FLAG_EEPROM_MAC,
1526 +};
1527 +
1528 +static const struct usb_device_id products [] = {
1529 +{
1530 + // Linksys USB200M
1531 + USB_DEVICE (0x077b, 0x2226),
1532 + .driver_info = (unsigned long) &ax8817x_info,
1533 +}, {
1534 + // Netgear FA120
1535 + USB_DEVICE (0x0846, 0x1040),
1536 + .driver_info = (unsigned long) &netgear_fa120_info,
1537 +}, {
1538 + // DLink DUB-E100
1539 + USB_DEVICE (0x2001, 0x1a00),
1540 + .driver_info = (unsigned long) &dlink_dub_e100_info,
1541 +}, {
1542 + // Intellinet, ST Lab USB Ethernet
1543 + USB_DEVICE (0x0b95, 0x1720),
1544 + .driver_info = (unsigned long) &ax8817x_info,
1545 +}, {
1546 + // Hawking UF200, TrendNet TU2-ET100
1547 + USB_DEVICE (0x07b8, 0x420a),
1548 + .driver_info = (unsigned long) &hawking_uf200_info,
1549 +}, {
1550 + // Billionton Systems, USB2AR
1551 + USB_DEVICE (0x08dd, 0x90ff),
1552 + .driver_info = (unsigned long) &ax8817x_info,
1553 +}, {
1554 + // ATEN UC210T
1555 + USB_DEVICE (0x0557, 0x2009),
1556 + .driver_info = (unsigned long) &ax8817x_info,
1557 +}, {
1558 + // Buffalo LUA-U2-KTX
1559 + USB_DEVICE (0x0411, 0x003d),
1560 + .driver_info = (unsigned long) &ax8817x_info,
1561 +}, {
1562 + // Buffalo LUA-U2-GT 10/100/1000
1563 + USB_DEVICE (0x0411, 0x006e),
1564 + .driver_info = (unsigned long) &ax88178_info,
1565 +}, {
1566 + // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
1567 + USB_DEVICE (0x6189, 0x182d),
1568 + .driver_info = (unsigned long) &ax8817x_info,
1569 +}, {
1570 + // Sitecom LN-031 "USB 2.0 10/100/1000 Ethernet adapter"
1571 + USB_DEVICE (0x0df6, 0x0056),
1572 + .driver_info = (unsigned long) &ax88178_info,
1573 +}, {
1574 + // Sitecom LN-028 "USB 2.0 10/100/1000 Ethernet adapter"
1575 + USB_DEVICE (0x0df6, 0x061c),
1576 + .driver_info = (unsigned long) &ax88178_info,
1577 +}, {
1578 + // corega FEther USB2-TX
1579 + USB_DEVICE (0x07aa, 0x0017),
1580 + .driver_info = (unsigned long) &ax8817x_info,
1581 +}, {
1582 + // Surecom EP-1427X-2
1583 + USB_DEVICE (0x1189, 0x0893),
1584 + .driver_info = (unsigned long) &ax8817x_info,
1585 +}, {
1586 + // goodway corp usb gwusb2e
1587 + USB_DEVICE (0x1631, 0x6200),
1588 + .driver_info = (unsigned long) &ax8817x_info,
1589 +}, {
1590 + // JVC MP-PRX1 Port Replicator
1591 + USB_DEVICE (0x04f1, 0x3008),
1592 + .driver_info = (unsigned long) &ax8817x_info,
1593 +}, {
1594 + // Lenovo U2L100P 10/100
1595 + USB_DEVICE (0x17ef, 0x7203),
1596 + .driver_info = (unsigned long) &ax88772_info,
1597 +}, {
1598 + // ASIX AX88772B 10/100
1599 + USB_DEVICE (0x0b95, 0x772b),
1600 + .driver_info = (unsigned long) &ax88772b_info,
1601 +}, {
1602 + // ASIX AX88772 10/100
1603 + USB_DEVICE (0x0b95, 0x7720),
1604 + .driver_info = (unsigned long) &ax88772_info,
1605 +}, {
1606 + // ASIX AX88178 10/100/1000
1607 + USB_DEVICE (0x0b95, 0x1780),
1608 + .driver_info = (unsigned long) &ax88178_info,
1609 +}, {
1610 + // Logitec LAN-GTJ/U2A
1611 + USB_DEVICE (0x0789, 0x0160),
1612 + .driver_info = (unsigned long) &ax88178_info,
1613 +}, {
1614 + // Linksys USB200M Rev 2
1615 + USB_DEVICE (0x13b1, 0x0018),
1616 + .driver_info = (unsigned long) &ax88772_info,
1617 +}, {
1618 + // 0Q0 cable ethernet
1619 + USB_DEVICE (0x1557, 0x7720),
1620 + .driver_info = (unsigned long) &ax88772_info,
1621 +}, {
1622 + // DLink DUB-E100 H/W Ver B1
1623 + USB_DEVICE (0x07d1, 0x3c05),
1624 + .driver_info = (unsigned long) &ax88772_info,
1625 +}, {
1626 + // DLink DUB-E100 H/W Ver B1 Alternate
1627 + USB_DEVICE (0x2001, 0x3c05),
1628 + .driver_info = (unsigned long) &ax88772_info,
1629 +}, {
1630 + // DLink DUB-E100 H/W Ver C1
1631 + USB_DEVICE (0x2001, 0x1a02),
1632 + .driver_info = (unsigned long) &ax88772_info,
1633 +}, {
1634 + // Linksys USB1000
1635 + USB_DEVICE (0x1737, 0x0039),
1636 + .driver_info = (unsigned long) &ax88178_info,
1637 +}, {
1638 + // IO-DATA ETG-US2
1639 + USB_DEVICE (0x04bb, 0x0930),
1640 + .driver_info = (unsigned long) &ax88178_info,
1641 +}, {
1642 + // Belkin F5D5055
1643 + USB_DEVICE(0x050d, 0x5055),
1644 + .driver_info = (unsigned long) &ax88178_info,
1645 +}, {
1646 + // Apple USB Ethernet Adapter
1647 + USB_DEVICE(0x05ac, 0x1402),
1648 + .driver_info = (unsigned long) &ax88772_info,
1649 +}, {
1650 + // Cables-to-Go USB Ethernet Adapter
1651 + USB_DEVICE(0x0b95, 0x772a),
1652 + .driver_info = (unsigned long) &ax88772_info,
1653 +}, {
1654 + // ABOCOM for pci
1655 + USB_DEVICE(0x14ea, 0xab11),
1656 + .driver_info = (unsigned long) &ax88178_info,
1657 +}, {
1658 + // ASIX 88772a
1659 + USB_DEVICE(0x0db0, 0xa877),
1660 + .driver_info = (unsigned long) &ax88772_info,
1661 +}, {
1662 + // Asus USB Ethernet Adapter
1663 + USB_DEVICE (0x0b95, 0x7e2b),
1664 + .driver_info = (unsigned long) &ax88772_info,
1665 +}, {
1666 + /* ASIX 88172a demo board */
1667 + USB_DEVICE(0x0b95, 0x172a),
1668 + .driver_info = (unsigned long) &ax88172a_info,
1669 +}, {
1670 + /*
1671 + * USBLINK HG20F9 "USB 2.0 LAN"
1672 + * Appears to have gazumped Linksys's manufacturer ID but
1673 + * doesn't (yet) conflict with any known Linksys product.
1674 + */
1675 + USB_DEVICE(0x066b, 0x20f9),
1676 + .driver_info = (unsigned long) &hg20f9_info,
1677 +},
1678 + { }, // END
1679 +};
1680 +MODULE_DEVICE_TABLE(usb, products);
1681 +
1682 +static struct usb_driver asix_driver = {
1683 + .name = DRIVER_NAME,
1684 + .id_table = products,
1685 + .probe = usbnet_probe,
1686 + .suspend = usbnet_suspend,
1687 + .resume = usbnet_resume,
1688 + .disconnect = usbnet_disconnect,
1689 + .supports_autosuspend = 1,
1690 + .disable_hub_initiated_lpm = 1,
1691 +};
1692 +
1693 +module_usb_driver(asix_driver);
1694 +
1695 +MODULE_AUTHOR("David Hollis");
1696 +MODULE_VERSION(DRIVER_VERSION);
1697 +MODULE_DESCRIPTION("ASIX AX8817X based USB 2.0 Ethernet Devices");
1698 +MODULE_LICENSE("GPL");
1699 +
1700 diff -Naur backports-4.2.6-1.org/drivers/net/usb/asix.h backports-4.2.6-1/drivers/net/usb/asix.h
1701 --- backports-4.2.6-1.org/drivers/net/usb/asix.h 1970-01-01 01:00:00.000000000 +0100
1702 +++ backports-4.2.6-1/drivers/net/usb/asix.h 2016-06-28 14:35:17.965307221 +0200
1703 @@ -0,0 +1,234 @@
1704 +/*
1705 + * ASIX AX8817X based USB 2.0 Ethernet Devices
1706 + * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
1707 + * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
1708 + * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
1709 + * Copyright (c) 2002-2003 TiVo Inc.
1710 + *
1711 + * This program is free software; you can redistribute it and/or modify
1712 + * it under the terms of the GNU General Public License as published by
1713 + * the Free Software Foundation; either version 2 of the License, or
1714 + * (at your option) any later version.
1715 + *
1716 + * This program is distributed in the hope that it will be useful,
1717 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1718 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1719 + * GNU General Public License for more details.
1720 + *
1721 + * You should have received a copy of the GNU General Public License
1722 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
1723 + */
1724 +
1725 +#ifndef _ASIX_H
1726 +#define _ASIX_H
1727 +
1728 +// #define DEBUG // error path messages, extra info
1729 +// #define VERBOSE // more; success messages
1730 +
1731 +#include <linux/module.h>
1732 +#include <linux/kmod.h>
1733 +#include <linux/netdevice.h>
1734 +#include <linux/etherdevice.h>
1735 +#include <linux/ethtool.h>
1736 +#include <linux/workqueue.h>
1737 +#include <linux/mii.h>
1738 +#include <linux/usb.h>
1739 +#include <linux/crc32.h>
1740 +#include <linux/usb/usbnet.h>
1741 +#include <linux/slab.h>
1742 +#include <linux/if_vlan.h>
1743 +
1744 +#define DRIVER_VERSION "22-Dec-2011"
1745 +#define DRIVER_NAME "asix"
1746 +
1747 +/* ASIX AX8817X based USB 2.0 Ethernet Devices */
1748 +
1749 +#define AX_CMD_SET_SW_MII 0x06
1750 +#define AX_CMD_READ_MII_REG 0x07
1751 +#define AX_CMD_WRITE_MII_REG 0x08
1752 +#define AX_CMD_SET_HW_MII 0x0a
1753 +#define AX_CMD_READ_EEPROM 0x0b
1754 +#define AX_CMD_WRITE_EEPROM 0x0c
1755 +#define AX_CMD_WRITE_ENABLE 0x0d
1756 +#define AX_CMD_WRITE_DISABLE 0x0e
1757 +#define AX_CMD_READ_RX_CTL 0x0f
1758 +#define AX_CMD_WRITE_RX_CTL 0x10
1759 +#define AX_CMD_READ_IPG012 0x11
1760 +#define AX_CMD_WRITE_IPG0 0x12
1761 +#define AX_CMD_WRITE_IPG1 0x13
1762 +#define AX_CMD_READ_NODE_ID 0x13
1763 +#define AX_CMD_WRITE_NODE_ID 0x14
1764 +#define AX_CMD_WRITE_IPG2 0x14
1765 +#define AX_CMD_WRITE_MULTI_FILTER 0x16
1766 +#define AX88172_CMD_READ_NODE_ID 0x17
1767 +#define AX_CMD_READ_PHY_ID 0x19
1768 +#define AX_CMD_READ_MEDIUM_STATUS 0x1a
1769 +#define AX_CMD_WRITE_MEDIUM_MODE 0x1b
1770 +#define AX_CMD_READ_MONITOR_MODE 0x1c
1771 +#define AX_CMD_WRITE_MONITOR_MODE 0x1d
1772 +#define AX_CMD_READ_GPIOS 0x1e
1773 +#define AX_CMD_WRITE_GPIOS 0x1f
1774 +#define AX_CMD_SW_RESET 0x20
1775 +#define AX_CMD_SW_PHY_STATUS 0x21
1776 +#define AX_CMD_SW_PHY_SELECT 0x22
1777 +
1778 +#define AX_PHY_SELECT_MASK (BIT(3) | BIT(2))
1779 +#define AX_PHY_SELECT_INTERNAL 0
1780 +#define AX_PHY_SELECT_EXTERNAL BIT(2)
1781 +
1782 +#define AX_MONITOR_MODE 0x01
1783 +#define AX_MONITOR_LINK 0x02
1784 +#define AX_MONITOR_MAGIC 0x04
1785 +#define AX_MONITOR_HSFS 0x10
1786 +
1787 +/* AX88172 Medium Status Register values */
1788 +#define AX88172_MEDIUM_FD 0x02
1789 +#define AX88172_MEDIUM_TX 0x04
1790 +#define AX88172_MEDIUM_FC 0x10
1791 +#define AX88172_MEDIUM_DEFAULT \
1792 + ( AX88172_MEDIUM_FD | AX88172_MEDIUM_TX | AX88172_MEDIUM_FC )
1793 +
1794 +#define AX_MCAST_FILTER_SIZE 8
1795 +#define AX_MAX_MCAST 64
1796 +
1797 +#define AX_SWRESET_CLEAR 0x00
1798 +#define AX_SWRESET_RR 0x01
1799 +#define AX_SWRESET_RT 0x02
1800 +#define AX_SWRESET_PRTE 0x04
1801 +#define AX_SWRESET_PRL 0x08
1802 +#define AX_SWRESET_BZ 0x10
1803 +#define AX_SWRESET_IPRL 0x20
1804 +#define AX_SWRESET_IPPD 0x40
1805 +
1806 +#define AX88772_IPG0_DEFAULT 0x15
1807 +#define AX88772_IPG1_DEFAULT 0x0c
1808 +#define AX88772_IPG2_DEFAULT 0x12
1809 +
1810 +/* AX88772 & AX88178 Medium Mode Register */
1811 +#define AX_MEDIUM_PF 0x0080
1812 +#define AX_MEDIUM_JFE 0x0040
1813 +#define AX_MEDIUM_TFC 0x0020
1814 +#define AX_MEDIUM_RFC 0x0010
1815 +#define AX_MEDIUM_ENCK 0x0008
1816 +#define AX_MEDIUM_AC 0x0004
1817 +#define AX_MEDIUM_FD 0x0002
1818 +#define AX_MEDIUM_GM 0x0001
1819 +#define AX_MEDIUM_SM 0x1000
1820 +#define AX_MEDIUM_SBP 0x0800
1821 +#define AX_MEDIUM_PS 0x0200
1822 +#define AX_MEDIUM_RE 0x0100
1823 +
1824 +#define AX88178_MEDIUM_DEFAULT \
1825 + (AX_MEDIUM_PS | AX_MEDIUM_FD | AX_MEDIUM_AC | \
1826 + AX_MEDIUM_RFC | AX_MEDIUM_TFC | AX_MEDIUM_JFE | \
1827 + AX_MEDIUM_RE)
1828 +
1829 +#define AX88772_MEDIUM_DEFAULT \
1830 + (AX_MEDIUM_FD | AX_MEDIUM_RFC | \
1831 + AX_MEDIUM_TFC | AX_MEDIUM_PS | \
1832 + AX_MEDIUM_AC | AX_MEDIUM_RE)
1833 +
1834 +/* AX88772 & AX88178 RX_CTL values */
1835 +#define AX_RX_CTL_SO 0x0080
1836 +#define AX_RX_CTL_AP 0x0020
1837 +#define AX_RX_CTL_AM 0x0010
1838 +#define AX_RX_CTL_AB 0x0008
1839 +#define AX_RX_CTL_SEP 0x0004
1840 +#define AX_RX_CTL_AMALL 0x0002
1841 +#define AX_RX_CTL_PRO 0x0001
1842 +#define AX_RX_CTL_MFB_2048 0x0000
1843 +#define AX_RX_CTL_MFB_4096 0x0100
1844 +#define AX_RX_CTL_MFB_8192 0x0200
1845 +#define AX_RX_CTL_MFB_16384 0x0300
1846 +
1847 +#define AX_DEFAULT_RX_CTL (AX_RX_CTL_SO | AX_RX_CTL_AB)
1848 +
1849 +/* GPIO 0 .. 2 toggles */
1850 +#define AX_GPIO_GPO0EN 0x01 /* GPIO0 Output enable */
1851 +#define AX_GPIO_GPO_0 0x02 /* GPIO0 Output value */
1852 +#define AX_GPIO_GPO1EN 0x04 /* GPIO1 Output enable */
1853 +#define AX_GPIO_GPO_1 0x08 /* GPIO1 Output value */
1854 +#define AX_GPIO_GPO2EN 0x10 /* GPIO2 Output enable */
1855 +#define AX_GPIO_GPO_2 0x20 /* GPIO2 Output value */
1856 +#define AX_GPIO_RESERVED 0x40 /* Reserved */
1857 +#define AX_GPIO_RSE 0x80 /* Reload serial EEPROM */
1858 +
1859 +#define AX_EEPROM_MAGIC 0xdeadbeef
1860 +#define AX_EEPROM_LEN 0x200
1861 +
1862 +/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
1863 +struct asix_data {
1864 + u8 multi_filter[AX_MCAST_FILTER_SIZE];
1865 + u8 mac_addr[ETH_ALEN];
1866 + u8 phymode;
1867 + u8 ledmode;
1868 + u8 res;
1869 +};
1870 +
1871 +struct asix_rx_fixup_info {
1872 + struct sk_buff *ax_skb;
1873 + u32 header;
1874 + u16 size;
1875 + bool split_head;
1876 +};
1877 +
1878 +struct asix_common_private {
1879 + struct asix_rx_fixup_info rx_fixup_info;
1880 +};
1881 +
1882 +extern const struct driver_info ax88172a_info;
1883 +
1884 +/* ASIX specific flags */
1885 +#define FLAG_EEPROM_MAC (1UL << 0) /* init device MAC from eeprom */
1886 +
1887 +int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
1888 + u16 size, void *data);
1889 +
1890 +int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
1891 + u16 size, void *data);
1892 +
1893 +void asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value,
1894 + u16 index, u16 size, void *data);
1895 +
1896 +int asix_rx_fixup_internal(struct usbnet *dev, struct sk_buff *skb,
1897 + struct asix_rx_fixup_info *rx);
1898 +int asix_rx_fixup_common(struct usbnet *dev, struct sk_buff *skb);
1899 +
1900 +struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
1901 + gfp_t flags);
1902 +
1903 +int asix_set_sw_mii(struct usbnet *dev);
1904 +int asix_set_hw_mii(struct usbnet *dev);
1905 +
1906 +int asix_read_phy_addr(struct usbnet *dev, int internal);
1907 +int asix_get_phy_addr(struct usbnet *dev);
1908 +
1909 +int asix_sw_reset(struct usbnet *dev, u8 flags);
1910 +
1911 +u16 asix_read_rx_ctl(struct usbnet *dev);
1912 +int asix_write_rx_ctl(struct usbnet *dev, u16 mode);
1913 +
1914 +u16 asix_read_medium_status(struct usbnet *dev);
1915 +int asix_write_medium_mode(struct usbnet *dev, u16 mode);
1916 +
1917 +int asix_write_gpio(struct usbnet *dev, u16 value, int sleep);
1918 +
1919 +void asix_set_multicast(struct net_device *net);
1920 +
1921 +int asix_mdio_read(struct net_device *netdev, int phy_id, int loc);
1922 +void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val);
1923 +
1924 +void asix_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo);
1925 +int asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo);
1926 +
1927 +int asix_get_eeprom_len(struct net_device *net);
1928 +int asix_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
1929 + u8 *data);
1930 +int asix_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
1931 + u8 *data);
1932 +
1933 +void asix_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info);
1934 +
1935 +int asix_set_mac_address(struct net_device *net, void *p);
1936 +
1937 +#endif /* _ASIX_H */
1938 diff -Naur backports-4.2.6-1.org/drivers/net/usb/ax88172a.c backports-4.2.6-1/drivers/net/usb/ax88172a.c
1939 --- backports-4.2.6-1.org/drivers/net/usb/ax88172a.c 1970-01-01 01:00:00.000000000 +0100
1940 +++ backports-4.2.6-1/drivers/net/usb/ax88172a.c 2016-06-28 14:35:17.965307221 +0200
1941 @@ -0,0 +1,422 @@
1942 +/*
1943 + * ASIX AX88172A based USB 2.0 Ethernet Devices
1944 + * Copyright (C) 2012 OMICRON electronics GmbH
1945 + *
1946 + * Supports external PHYs via phylib. Based on the driver for the
1947 + * AX88772. Original copyrights follow:
1948 + *
1949 + * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
1950 + * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
1951 + * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
1952 + * Copyright (c) 2002-2003 TiVo Inc.
1953 + *
1954 + * This program is free software; you can redistribute it and/or modify
1955 + * it under the terms of the GNU General Public License as published by
1956 + * the Free Software Foundation; either version 2 of the License, or
1957 + * (at your option) any later version.
1958 + *
1959 + * This program is distributed in the hope that it will be useful,
1960 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1961 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1962 + * GNU General Public License for more details.
1963 + *
1964 + * You should have received a copy of the GNU General Public License
1965 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
1966 + */
1967 +
1968 +#include "asix.h"
1969 +#include <linux/phy.h>
1970 +
1971 +struct ax88172a_private {
1972 + struct mii_bus *mdio;
1973 + struct phy_device *phydev;
1974 + char phy_name[20];
1975 + u16 phy_addr;
1976 + u16 oldmode;
1977 + int use_embdphy;
1978 + struct asix_rx_fixup_info rx_fixup_info;
1979 +};
1980 +
1981 +/* MDIO read and write wrappers for phylib */
1982 +static int asix_mdio_bus_read(struct mii_bus *bus, int phy_id, int regnum)
1983 +{
1984 + return asix_mdio_read(((struct usbnet *)bus->priv)->net, phy_id,
1985 + regnum);
1986 +}
1987 +
1988 +static int asix_mdio_bus_write(struct mii_bus *bus, int phy_id, int regnum,
1989 + u16 val)
1990 +{
1991 + asix_mdio_write(((struct usbnet *)bus->priv)->net, phy_id, regnum, val);
1992 + return 0;
1993 +}
1994 +
1995 +static int ax88172a_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
1996 +{
1997 + if (!netif_running(net))
1998 + return -EINVAL;
1999 +
2000 + if (!net->phydev)
2001 + return -ENODEV;
2002 +
2003 + return phy_mii_ioctl(net->phydev, rq, cmd);
2004 +}
2005 +
2006 +/* set MAC link settings according to information from phylib */
2007 +static void ax88172a_adjust_link(struct net_device *netdev)
2008 +{
2009 + struct phy_device *phydev = netdev->phydev;
2010 + struct usbnet *dev = netdev_priv(netdev);
2011 + struct ax88172a_private *priv = dev->driver_priv;
2012 + u16 mode = 0;
2013 +
2014 + if (phydev->link) {
2015 + mode = AX88772_MEDIUM_DEFAULT;
2016 +
2017 + if (phydev->duplex == DUPLEX_HALF)
2018 + mode &= ~AX_MEDIUM_FD;
2019 +
2020 + if (phydev->speed != SPEED_100)
2021 + mode &= ~AX_MEDIUM_PS;
2022 + }
2023 +
2024 + if (mode != priv->oldmode) {
2025 + asix_write_medium_mode(dev, mode);
2026 + priv->oldmode = mode;
2027 + netdev_dbg(netdev, "speed %u duplex %d, setting mode to 0x%04x\n",
2028 + phydev->speed, phydev->duplex, mode);
2029 + phy_print_status(phydev);
2030 + }
2031 +}
2032 +
2033 +static void ax88172a_status(struct usbnet *dev, struct urb *urb)
2034 +{
2035 + /* link changes are detected by polling the phy */
2036 +}
2037 +
2038 +/* use phylib infrastructure */
2039 +static int ax88172a_init_mdio(struct usbnet *dev)
2040 +{
2041 + struct ax88172a_private *priv = dev->driver_priv;
2042 + int ret, i;
2043 +
2044 + priv->mdio = mdiobus_alloc();
2045 + if (!priv->mdio) {
2046 + netdev_err(dev->net, "Could not allocate MDIO bus\n");
2047 + return -ENOMEM;
2048 + }
2049 +
2050 + priv->mdio->priv = (void *)dev;
2051 + priv->mdio->read = &asix_mdio_bus_read;
2052 + priv->mdio->write = &asix_mdio_bus_write;
2053 + priv->mdio->name = "Asix MDIO Bus";
2054 + /* mii bus name is usb-<usb bus number>-<usb device number> */
2055 + snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
2056 + dev->udev->bus->busnum, dev->udev->devnum);
2057 +
2058 + priv->mdio->irq = kzalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
2059 + if (!priv->mdio->irq) {
2060 + ret = -ENOMEM;
2061 + goto mfree;
2062 + }
2063 + for (i = 0; i < PHY_MAX_ADDR; i++)
2064 + priv->mdio->irq[i] = PHY_POLL;
2065 +
2066 + ret = mdiobus_register(priv->mdio);
2067 + if (ret) {
2068 + netdev_err(dev->net, "Could not register MDIO bus\n");
2069 + goto ifree;
2070 + }
2071 +
2072 + netdev_info(dev->net, "registered mdio bus %s\n", priv->mdio->id);
2073 + return 0;
2074 +
2075 +ifree:
2076 + kfree(priv->mdio->irq);
2077 +mfree:
2078 + mdiobus_free(priv->mdio);
2079 + return ret;
2080 +}
2081 +
2082 +static void ax88172a_remove_mdio(struct usbnet *dev)
2083 +{
2084 + struct ax88172a_private *priv = dev->driver_priv;
2085 +
2086 + netdev_info(dev->net, "deregistering mdio bus %s\n", priv->mdio->id);
2087 + mdiobus_unregister(priv->mdio);
2088 + kfree(priv->mdio->irq);
2089 + mdiobus_free(priv->mdio);
2090 +}
2091 +
2092 +static const struct net_device_ops ax88172a_netdev_ops = {
2093 + .ndo_open = usbnet_open,
2094 + .ndo_stop = usbnet_stop,
2095 + .ndo_start_xmit = usbnet_start_xmit,
2096 + .ndo_tx_timeout = usbnet_tx_timeout,
2097 + .ndo_change_mtu = usbnet_change_mtu,
2098 + .ndo_set_mac_address = asix_set_mac_address,
2099 + .ndo_validate_addr = eth_validate_addr,
2100 + .ndo_do_ioctl = ax88172a_ioctl,
2101 + .ndo_set_rx_mode = asix_set_multicast,
2102 +};
2103 +
2104 +static int ax88172a_get_settings(struct net_device *net,
2105 + struct ethtool_cmd *cmd)
2106 +{
2107 + if (!net->phydev)
2108 + return -ENODEV;
2109 +
2110 + return phy_ethtool_gset(net->phydev, cmd);
2111 +}
2112 +
2113 +static int ax88172a_set_settings(struct net_device *net,
2114 + struct ethtool_cmd *cmd)
2115 +{
2116 + if (!net->phydev)
2117 + return -ENODEV;
2118 +
2119 + return phy_ethtool_sset(net->phydev, cmd);
2120 +}
2121 +
2122 +static int ax88172a_nway_reset(struct net_device *net)
2123 +{
2124 + if (!net->phydev)
2125 + return -ENODEV;
2126 +
2127 + return phy_start_aneg(net->phydev);
2128 +}
2129 +
2130 +static const struct ethtool_ops ax88172a_ethtool_ops = {
2131 + .get_drvinfo = asix_get_drvinfo,
2132 + .get_link = usbnet_get_link,
2133 + .get_msglevel = usbnet_get_msglevel,
2134 + .set_msglevel = usbnet_set_msglevel,
2135 + .get_wol = asix_get_wol,
2136 + .set_wol = asix_set_wol,
2137 + .get_eeprom_len = asix_get_eeprom_len,
2138 + .get_eeprom = asix_get_eeprom,
2139 + .set_eeprom = asix_set_eeprom,
2140 + .get_settings = ax88172a_get_settings,
2141 + .set_settings = ax88172a_set_settings,
2142 + .nway_reset = ax88172a_nway_reset,
2143 +};
2144 +
2145 +static int ax88172a_reset_phy(struct usbnet *dev, int embd_phy)
2146 +{
2147 + int ret;
2148 +
2149 + ret = asix_sw_reset(dev, AX_SWRESET_IPPD);
2150 + if (ret < 0)
2151 + goto err;
2152 +
2153 + msleep(150);
2154 + ret = asix_sw_reset(dev, AX_SWRESET_CLEAR);
2155 + if (ret < 0)
2156 + goto err;
2157 +
2158 + msleep(150);
2159 +
2160 + ret = asix_sw_reset(dev, embd_phy ? AX_SWRESET_IPRL : AX_SWRESET_IPPD);
2161 + if (ret < 0)
2162 + goto err;
2163 +
2164 + return 0;
2165 +
2166 +err:
2167 + return ret;
2168 +}
2169 +
2170 +
2171 +static int ax88172a_bind(struct usbnet *dev, struct usb_interface *intf)
2172 +{
2173 + int ret;
2174 + u8 buf[ETH_ALEN];
2175 + struct ax88172a_private *priv;
2176 +
2177 + usbnet_get_endpoints(dev, intf);
2178 +
2179 + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
2180 + if (!priv)
2181 + return -ENOMEM;
2182 +
2183 + dev->driver_priv = priv;
2184 +
2185 + /* Get the MAC address */
2186 + ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
2187 + if (ret < 0) {
2188 + netdev_err(dev->net, "Failed to read MAC address: %d\n", ret);
2189 + goto free;
2190 + }
2191 + memcpy(dev->net->dev_addr, buf, ETH_ALEN);
2192 +
2193 + dev->net->netdev_ops = &ax88172a_netdev_ops;
2194 + dev->net->ethtool_ops = &ax88172a_ethtool_ops;
2195 +
2196 + /* are we using the internal or the external phy? */
2197 + ret = asix_read_cmd(dev, AX_CMD_SW_PHY_STATUS, 0, 0, 1, buf);
2198 + if (ret < 0) {
2199 + netdev_err(dev->net, "Failed to read software interface selection register: %d\n",
2200 + ret);
2201 + goto free;
2202 + }
2203 +
2204 + netdev_dbg(dev->net, "AX_CMD_SW_PHY_STATUS = 0x%02x\n", buf[0]);
2205 + switch (buf[0] & AX_PHY_SELECT_MASK) {
2206 + case AX_PHY_SELECT_INTERNAL:
2207 + netdev_dbg(dev->net, "use internal phy\n");
2208 + priv->use_embdphy = 1;
2209 + break;
2210 + case AX_PHY_SELECT_EXTERNAL:
2211 + netdev_dbg(dev->net, "use external phy\n");
2212 + priv->use_embdphy = 0;
2213 + break;
2214 + default:
2215 + netdev_err(dev->net, "Interface mode not supported by driver\n");
2216 + ret = -ENOTSUPP;
2217 + goto free;
2218 + }
2219 +
2220 + priv->phy_addr = asix_read_phy_addr(dev, priv->use_embdphy);
2221 + ax88172a_reset_phy(dev, priv->use_embdphy);
2222 +
2223 + /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
2224 + if (dev->driver_info->flags & FLAG_FRAMING_AX) {
2225 + /* hard_mtu is still the default - the device does not support
2226 + jumbo eth frames */
2227 + dev->rx_urb_size = 2048;
2228 + }
2229 +
2230 + /* init MDIO bus */
2231 + ret = ax88172a_init_mdio(dev);
2232 + if (ret)
2233 + goto free;
2234 +
2235 + return 0;
2236 +
2237 +free:
2238 + kfree(priv);
2239 + return ret;
2240 +}
2241 +
2242 +static int ax88172a_stop(struct usbnet *dev)
2243 +{
2244 + struct ax88172a_private *priv = dev->driver_priv;
2245 +
2246 + netdev_dbg(dev->net, "Stopping interface\n");
2247 +
2248 + if (priv->phydev) {
2249 + netdev_info(dev->net, "Disconnecting from phy %s\n",
2250 + priv->phy_name);
2251 + phy_stop(priv->phydev);
2252 + phy_disconnect(priv->phydev);
2253 + }
2254 +
2255 + return 0;
2256 +}
2257 +
2258 +static void ax88172a_unbind(struct usbnet *dev, struct usb_interface *intf)
2259 +{
2260 + struct ax88172a_private *priv = dev->driver_priv;
2261 +
2262 + ax88172a_remove_mdio(dev);
2263 + kfree(priv);
2264 +}
2265 +
2266 +static int ax88172a_reset(struct usbnet *dev)
2267 +{
2268 + struct asix_data *data = (struct asix_data *)&dev->data;
2269 + struct ax88172a_private *priv = dev->driver_priv;
2270 + int ret;
2271 + u16 rx_ctl;
2272 +
2273 + ax88172a_reset_phy(dev, priv->use_embdphy);
2274 +
2275 + msleep(150);
2276 + rx_ctl = asix_read_rx_ctl(dev);
2277 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after software reset\n", rx_ctl);
2278 + ret = asix_write_rx_ctl(dev, 0x0000);
2279 + if (ret < 0)
2280 + goto out;
2281 +
2282 + rx_ctl = asix_read_rx_ctl(dev);
2283 + netdev_dbg(dev->net, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
2284 +
2285 + msleep(150);
2286 +
2287 + ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
2288 + AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
2289 + AX88772_IPG2_DEFAULT, 0, NULL);
2290 + if (ret < 0) {
2291 + netdev_err(dev->net, "Write IPG,IPG1,IPG2 failed: %d\n", ret);
2292 + goto out;
2293 + }
2294 +
2295 + /* Rewrite MAC address */
2296 + memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
2297 + ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
2298 + data->mac_addr);
2299 + if (ret < 0)
2300 + goto out;
2301 +
2302 + /* Set RX_CTL to default values with 2k buffer, and enable cactus */
2303 + ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
2304 + if (ret < 0)
2305 + goto out;
2306 +
2307 + rx_ctl = asix_read_rx_ctl(dev);
2308 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after all initializations\n",
2309 + rx_ctl);
2310 +
2311 + rx_ctl = asix_read_medium_status(dev);
2312 + netdev_dbg(dev->net, "Medium Status is 0x%04x after all initializations\n",
2313 + rx_ctl);
2314 +
2315 + /* Connect to PHY */
2316 + snprintf(priv->phy_name, 20, PHY_ID_FMT,
2317 + priv->mdio->id, priv->phy_addr);
2318 +
2319 + priv->phydev = phy_connect(dev->net, priv->phy_name,
2320 + &ax88172a_adjust_link,
2321 + PHY_INTERFACE_MODE_MII);
2322 + if (IS_ERR(priv->phydev)) {
2323 + netdev_err(dev->net, "Could not connect to PHY device %s\n",
2324 + priv->phy_name);
2325 + ret = PTR_ERR(priv->phydev);
2326 + goto out;
2327 + }
2328 +
2329 + netdev_info(dev->net, "Connected to phy %s\n", priv->phy_name);
2330 +
2331 + /* During power-up, the AX88172A set the power down (BMCR_PDOWN)
2332 + * bit of the PHY. Bring the PHY up again.
2333 + */
2334 + genphy_resume(priv->phydev);
2335 + phy_start(priv->phydev);
2336 +
2337 + return 0;
2338 +
2339 +out:
2340 + return ret;
2341 +
2342 +}
2343 +
2344 +static int ax88172a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
2345 +{
2346 + struct ax88172a_private *dp = dev->driver_priv;
2347 + struct asix_rx_fixup_info *rx = &dp->rx_fixup_info;
2348 +
2349 + return asix_rx_fixup_internal(dev, skb, rx);
2350 +}
2351 +
2352 +const struct driver_info ax88172a_info = {
2353 + .description = "ASIX AX88172A USB 2.0 Ethernet",
2354 + .bind = ax88172a_bind,
2355 + .reset = ax88172a_reset,
2356 + .stop = ax88172a_stop,
2357 + .unbind = ax88172a_unbind,
2358 + .status = ax88172a_status,
2359 + .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
2360 + FLAG_MULTI_PACKET,
2361 + .rx_fixup = ax88172a_rx_fixup,
2362 + .tx_fixup = asix_tx_fixup,
2363 +};
2364 diff -Naur backports-4.2.6-1.org/drivers/net/usb/ax88179_178a.c backports-4.2.6-1/drivers/net/usb/ax88179_178a.c
2365 --- backports-4.2.6-1.org/drivers/net/usb/ax88179_178a.c 1970-01-01 01:00:00.000000000 +0100
2366 +++ backports-4.2.6-1/drivers/net/usb/ax88179_178a.c 2016-06-28 14:35:17.968640554 +0200
2367 @@ -0,0 +1,1756 @@
2368 +/*
2369 + * ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet Devices
2370 + *
2371 + * Copyright (C) 2011-2013 ASIX
2372 + *
2373 + * This program is free software; you can redistribute it and/or modify
2374 + * it under the terms of the GNU General Public License
2375 + * as published by the Free Software Foundation; either version 2
2376 + * of the License, or (at your option) any later version.
2377 + *
2378 + * This program is distributed in the hope that it will be useful,
2379 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2380 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2381 + * GNU General Public License for more details.
2382 + *
2383 + * You should have received a copy of the GNU General Public License
2384 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
2385 + */
2386 +
2387 +#include <linux/module.h>
2388 +#include <linux/etherdevice.h>
2389 +#include <linux/mii.h>
2390 +#include <linux/usb.h>
2391 +#include <linux/crc32.h>
2392 +#include <linux/usb/usbnet.h>
2393 +#include <uapi/linux/mdio.h>
2394 +#include <linux/mdio.h>
2395 +
2396 +#define AX88179_PHY_ID 0x03
2397 +#define AX_EEPROM_LEN 0x100
2398 +#define AX88179_EEPROM_MAGIC 0x17900b95
2399 +#define AX_MCAST_FLTSIZE 8
2400 +#define AX_MAX_MCAST 64
2401 +#define AX_INT_PPLS_LINK ((u32)BIT(16))
2402 +#define AX_RXHDR_L4_TYPE_MASK 0x1c
2403 +#define AX_RXHDR_L4_TYPE_UDP 4
2404 +#define AX_RXHDR_L4_TYPE_TCP 16
2405 +#define AX_RXHDR_L3CSUM_ERR 2
2406 +#define AX_RXHDR_L4CSUM_ERR 1
2407 +#define AX_RXHDR_CRC_ERR ((u32)BIT(29))
2408 +#define AX_RXHDR_DROP_ERR ((u32)BIT(31))
2409 +#define AX_ACCESS_MAC 0x01
2410 +#define AX_ACCESS_PHY 0x02
2411 +#define AX_ACCESS_EEPROM 0x04
2412 +#define AX_ACCESS_EFUS 0x05
2413 +#define AX_PAUSE_WATERLVL_HIGH 0x54
2414 +#define AX_PAUSE_WATERLVL_LOW 0x55
2415 +
2416 +#define PHYSICAL_LINK_STATUS 0x02
2417 + #define AX_USB_SS 0x04
2418 + #define AX_USB_HS 0x02
2419 +
2420 +#define GENERAL_STATUS 0x03
2421 +/* Check AX88179 version. UA1:Bit2 = 0, UA2:Bit2 = 1 */
2422 + #define AX_SECLD 0x04
2423 +
2424 +#define AX_SROM_ADDR 0x07
2425 +#define AX_SROM_CMD 0x0a
2426 + #define EEP_RD 0x04
2427 + #define EEP_BUSY 0x10
2428 +
2429 +#define AX_SROM_DATA_LOW 0x08
2430 +#define AX_SROM_DATA_HIGH 0x09
2431 +
2432 +#define AX_RX_CTL 0x0b
2433 + #define AX_RX_CTL_DROPCRCERR 0x0100
2434 + #define AX_RX_CTL_IPE 0x0200
2435 + #define AX_RX_CTL_START 0x0080
2436 + #define AX_RX_CTL_AP 0x0020
2437 + #define AX_RX_CTL_AM 0x0010
2438 + #define AX_RX_CTL_AB 0x0008
2439 + #define AX_RX_CTL_AMALL 0x0002
2440 + #define AX_RX_CTL_PRO 0x0001
2441 + #define AX_RX_CTL_STOP 0x0000
2442 +
2443 +#define AX_NODE_ID 0x10
2444 +#define AX_MULFLTARY 0x16
2445 +
2446 +#define AX_MEDIUM_STATUS_MODE 0x22
2447 + #define AX_MEDIUM_GIGAMODE 0x01
2448 + #define AX_MEDIUM_FULL_DUPLEX 0x02
2449 + #define AX_MEDIUM_EN_125MHZ 0x08
2450 + #define AX_MEDIUM_RXFLOW_CTRLEN 0x10
2451 + #define AX_MEDIUM_TXFLOW_CTRLEN 0x20
2452 + #define AX_MEDIUM_RECEIVE_EN 0x100
2453 + #define AX_MEDIUM_PS 0x200
2454 + #define AX_MEDIUM_JUMBO_EN 0x8040
2455 +
2456 +#define AX_MONITOR_MOD 0x24
2457 + #define AX_MONITOR_MODE_RWLC 0x02
2458 + #define AX_MONITOR_MODE_RWMP 0x04
2459 + #define AX_MONITOR_MODE_PMEPOL 0x20
2460 + #define AX_MONITOR_MODE_PMETYPE 0x40
2461 +
2462 +#define AX_GPIO_CTRL 0x25
2463 + #define AX_GPIO_CTRL_GPIO3EN 0x80
2464 + #define AX_GPIO_CTRL_GPIO2EN 0x40
2465 + #define AX_GPIO_CTRL_GPIO1EN 0x20
2466 +
2467 +#define AX_PHYPWR_RSTCTL 0x26
2468 + #define AX_PHYPWR_RSTCTL_BZ 0x0010
2469 + #define AX_PHYPWR_RSTCTL_IPRL 0x0020
2470 + #define AX_PHYPWR_RSTCTL_AT 0x1000
2471 +
2472 +#define AX_RX_BULKIN_QCTRL 0x2e
2473 +#define AX_CLK_SELECT 0x33
2474 + #define AX_CLK_SELECT_BCS 0x01
2475 + #define AX_CLK_SELECT_ACS 0x02
2476 + #define AX_CLK_SELECT_ULR 0x08
2477 +
2478 +#define AX_RXCOE_CTL 0x34
2479 + #define AX_RXCOE_IP 0x01
2480 + #define AX_RXCOE_TCP 0x02
2481 + #define AX_RXCOE_UDP 0x04
2482 + #define AX_RXCOE_TCPV6 0x20
2483 + #define AX_RXCOE_UDPV6 0x40
2484 +
2485 +#define AX_TXCOE_CTL 0x35
2486 + #define AX_TXCOE_IP 0x01
2487 + #define AX_TXCOE_TCP 0x02
2488 + #define AX_TXCOE_UDP 0x04
2489 + #define AX_TXCOE_TCPV6 0x20
2490 + #define AX_TXCOE_UDPV6 0x40
2491 +
2492 +#define AX_LEDCTRL 0x73
2493 +
2494 +#define GMII_PHY_PHYSR 0x11
2495 + #define GMII_PHY_PHYSR_SMASK 0xc000
2496 + #define GMII_PHY_PHYSR_GIGA 0x8000
2497 + #define GMII_PHY_PHYSR_100 0x4000
2498 + #define GMII_PHY_PHYSR_FULL 0x2000
2499 + #define GMII_PHY_PHYSR_LINK 0x400
2500 +
2501 +#define GMII_LED_ACT 0x1a
2502 + #define GMII_LED_ACTIVE_MASK 0xff8f
2503 + #define GMII_LED0_ACTIVE BIT(4)
2504 + #define GMII_LED1_ACTIVE BIT(5)
2505 + #define GMII_LED2_ACTIVE BIT(6)
2506 +
2507 +#define GMII_LED_LINK 0x1c
2508 + #define GMII_LED_LINK_MASK 0xf888
2509 + #define GMII_LED0_LINK_10 BIT(0)
2510 + #define GMII_LED0_LINK_100 BIT(1)
2511 + #define GMII_LED0_LINK_1000 BIT(2)
2512 + #define GMII_LED1_LINK_10 BIT(4)
2513 + #define GMII_LED1_LINK_100 BIT(5)
2514 + #define GMII_LED1_LINK_1000 BIT(6)
2515 + #define GMII_LED2_LINK_10 BIT(8)
2516 + #define GMII_LED2_LINK_100 BIT(9)
2517 + #define GMII_LED2_LINK_1000 BIT(10)
2518 + #define LED0_ACTIVE BIT(0)
2519 + #define LED0_LINK_10 BIT(1)
2520 + #define LED0_LINK_100 BIT(2)
2521 + #define LED0_LINK_1000 BIT(3)
2522 + #define LED0_FD BIT(4)
2523 + #define LED0_USB3_MASK 0x001f
2524 + #define LED1_ACTIVE BIT(5)
2525 + #define LED1_LINK_10 BIT(6)
2526 + #define LED1_LINK_100 BIT(7)
2527 + #define LED1_LINK_1000 BIT(8)
2528 + #define LED1_FD BIT(9)
2529 + #define LED1_USB3_MASK 0x03e0
2530 + #define LED2_ACTIVE BIT(10)
2531 + #define LED2_LINK_1000 BIT(13)
2532 + #define LED2_LINK_100 BIT(12)
2533 + #define LED2_LINK_10 BIT(11)
2534 + #define LED2_FD BIT(14)
2535 + #define LED_VALID BIT(15)
2536 + #define LED2_USB3_MASK 0x7c00
2537 +
2538 +#define GMII_PHYPAGE 0x1e
2539 +#define GMII_PHY_PAGE_SELECT 0x1f
2540 + #define GMII_PHY_PGSEL_EXT 0x0007
2541 + #define GMII_PHY_PGSEL_PAGE0 0x0000
2542 + #define GMII_PHY_PGSEL_PAGE3 0x0003
2543 + #define GMII_PHY_PGSEL_PAGE5 0x0005
2544 +
2545 +struct ax88179_data {
2546 + u8 eee_enabled;
2547 + u8 eee_active;
2548 + u16 rxctl;
2549 + u16 reserved;
2550 +};
2551 +
2552 +struct ax88179_int_data {
2553 + __le32 intdata1;
2554 + __le32 intdata2;
2555 +};
2556 +
2557 +static const struct {
2558 + unsigned char ctrl, timer_l, timer_h, size, ifg;
2559 +} AX88179_BULKIN_SIZE[] = {
2560 + {7, 0x4f, 0, 0x12, 0xff},
2561 + {7, 0x20, 3, 0x16, 0xff},
2562 + {7, 0xae, 7, 0x18, 0xff},
2563 + {7, 0xcc, 0x4c, 0x18, 8},
2564 +};
2565 +
2566 +static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
2567 + u16 size, void *data, int in_pm)
2568 +{
2569 + int ret;
2570 + int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
2571 +
2572 + BUG_ON(!dev);
2573 +
2574 + if (!in_pm)
2575 + fn = usbnet_read_cmd;
2576 + else
2577 + fn = usbnet_read_cmd_nopm;
2578 +
2579 + ret = fn(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2580 + value, index, data, size);
2581 +
2582 + if (unlikely(ret < 0))
2583 + netdev_warn(dev->net, "Failed to read reg index 0x%04x: %d\n",
2584 + index, ret);
2585 +
2586 + return ret;
2587 +}
2588 +
2589 +static int __ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
2590 + u16 size, void *data, int in_pm)
2591 +{
2592 + int ret;
2593 + int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
2594 +
2595 + BUG_ON(!dev);
2596 +
2597 + if (!in_pm)
2598 + fn = usbnet_write_cmd;
2599 + else
2600 + fn = usbnet_write_cmd_nopm;
2601 +
2602 + ret = fn(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2603 + value, index, data, size);
2604 +
2605 + if (unlikely(ret < 0))
2606 + netdev_warn(dev->net, "Failed to write reg index 0x%04x: %d\n",
2607 + index, ret);
2608 +
2609 + return ret;
2610 +}
2611 +
2612 +static void ax88179_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value,
2613 + u16 index, u16 size, void *data)
2614 +{
2615 + u16 buf;
2616 +
2617 + if (2 == size) {
2618 + buf = *((u16 *)data);
2619 + cpu_to_le16s(&buf);
2620 + usbnet_write_cmd_async(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR |
2621 + USB_RECIP_DEVICE, value, index, &buf,
2622 + size);
2623 + } else {
2624 + usbnet_write_cmd_async(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR |
2625 + USB_RECIP_DEVICE, value, index, data,
2626 + size);
2627 + }
2628 +}
2629 +
2630 +static int ax88179_read_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
2631 + u16 index, u16 size, void *data)
2632 +{
2633 + int ret;
2634 +
2635 + if (2 == size) {
2636 + u16 buf;
2637 + ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1);
2638 + le16_to_cpus(&buf);
2639 + *((u16 *)data) = buf;
2640 + } else if (4 == size) {
2641 + u32 buf;
2642 + ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1);
2643 + le32_to_cpus(&buf);
2644 + *((u32 *)data) = buf;
2645 + } else {
2646 + ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 1);
2647 + }
2648 +
2649 + return ret;
2650 +}
2651 +
2652 +static int ax88179_write_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
2653 + u16 index, u16 size, void *data)
2654 +{
2655 + int ret;
2656 +
2657 + if (2 == size) {
2658 + u16 buf;
2659 + buf = *((u16 *)data);
2660 + cpu_to_le16s(&buf);
2661 + ret = __ax88179_write_cmd(dev, cmd, value, index,
2662 + size, &buf, 1);
2663 + } else {
2664 + ret = __ax88179_write_cmd(dev, cmd, value, index,
2665 + size, data, 1);
2666 + }
2667 +
2668 + return ret;
2669 +}
2670 +
2671 +static int ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
2672 + u16 size, void *data)
2673 +{
2674 + int ret;
2675 +
2676 + if (2 == size) {
2677 + u16 buf;
2678 + ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0);
2679 + le16_to_cpus(&buf);
2680 + *((u16 *)data) = buf;
2681 + } else if (4 == size) {
2682 + u32 buf;
2683 + ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0);
2684 + le32_to_cpus(&buf);
2685 + *((u32 *)data) = buf;
2686 + } else {
2687 + ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 0);
2688 + }
2689 +
2690 + return ret;
2691 +}
2692 +
2693 +static int ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
2694 + u16 size, void *data)
2695 +{
2696 + int ret;
2697 +
2698 + if (2 == size) {
2699 + u16 buf;
2700 + buf = *((u16 *)data);
2701 + cpu_to_le16s(&buf);
2702 + ret = __ax88179_write_cmd(dev, cmd, value, index,
2703 + size, &buf, 0);
2704 + } else {
2705 + ret = __ax88179_write_cmd(dev, cmd, value, index,
2706 + size, data, 0);
2707 + }
2708 +
2709 + return ret;
2710 +}
2711 +
2712 +static void ax88179_status(struct usbnet *dev, struct urb *urb)
2713 +{
2714 + struct ax88179_int_data *event;
2715 + u32 link;
2716 +
2717 + if (urb->actual_length < 8)
2718 + return;
2719 +
2720 + event = urb->transfer_buffer;
2721 + le32_to_cpus((void *)&event->intdata1);
2722 +
2723 + link = (((__force u32)event->intdata1) & AX_INT_PPLS_LINK) >> 16;
2724 +
2725 + if (netif_carrier_ok(dev->net) != link) {
2726 + usbnet_link_change(dev, link, 1);
2727 + netdev_info(dev->net, "ax88179 - Link status is: %d\n", link);
2728 + }
2729 +}
2730 +
2731 +static int ax88179_mdio_read(struct net_device *netdev, int phy_id, int loc)
2732 +{
2733 + struct usbnet *dev = netdev_priv(netdev);
2734 + u16 res;
2735 +
2736 + ax88179_read_cmd(dev, AX_ACCESS_PHY, phy_id, (__u16)loc, 2, &res);
2737 + return res;
2738 +}
2739 +
2740 +static void ax88179_mdio_write(struct net_device *netdev, int phy_id, int loc,
2741 + int val)
2742 +{
2743 + struct usbnet *dev = netdev_priv(netdev);
2744 + u16 res = (u16) val;
2745 +
2746 + ax88179_write_cmd(dev, AX_ACCESS_PHY, phy_id, (__u16)loc, 2, &res);
2747 +}
2748 +
2749 +static inline int ax88179_phy_mmd_indirect(struct usbnet *dev, u16 prtad,
2750 + u16 devad)
2751 +{
2752 + u16 tmp16;
2753 + int ret;
2754 +
2755 + tmp16 = devad;
2756 + ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
2757 + MII_MMD_CTRL, 2, &tmp16);
2758 +
2759 + tmp16 = prtad;
2760 + ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
2761 + MII_MMD_DATA, 2, &tmp16);
2762 +
2763 + tmp16 = devad | MII_MMD_CTRL_NOINCR;
2764 + ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
2765 + MII_MMD_CTRL, 2, &tmp16);
2766 +
2767 + return ret;
2768 +}
2769 +
2770 +static int
2771 +ax88179_phy_read_mmd_indirect(struct usbnet *dev, u16 prtad, u16 devad)
2772 +{
2773 + int ret;
2774 + u16 tmp16;
2775 +
2776 + ax88179_phy_mmd_indirect(dev, prtad, devad);
2777 +
2778 + ret = ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
2779 + MII_MMD_DATA, 2, &tmp16);
2780 + if (ret < 0)
2781 + return ret;
2782 +
2783 + return tmp16;
2784 +}
2785 +
2786 +static int
2787 +ax88179_phy_write_mmd_indirect(struct usbnet *dev, u16 prtad, u16 devad,
2788 + u16 data)
2789 +{
2790 + int ret;
2791 +
2792 + ax88179_phy_mmd_indirect(dev, prtad, devad);
2793 +
2794 + ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
2795 + MII_MMD_DATA, 2, &data);
2796 +
2797 + if (ret < 0)
2798 + return ret;
2799 +
2800 + return 0;
2801 +}
2802 +
2803 +static int ax88179_suspend(struct usb_interface *intf, pm_message_t message)
2804 +{
2805 + struct usbnet *dev = usb_get_intfdata(intf);
2806 + u16 tmp16;
2807 + u8 tmp8;
2808 +
2809 + usbnet_suspend(intf, message);
2810 +
2811 + /* Disable RX path */
2812 + ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
2813 + 2, 2, &tmp16);
2814 + tmp16 &= ~AX_MEDIUM_RECEIVE_EN;
2815 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
2816 + 2, 2, &tmp16);
2817 +
2818 + /* Force bulk-in zero length */
2819 + ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
2820 + 2, 2, &tmp16);
2821 +
2822 + tmp16 |= AX_PHYPWR_RSTCTL_BZ | AX_PHYPWR_RSTCTL_IPRL;
2823 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
2824 + 2, 2, &tmp16);
2825 +
2826 + /* change clock */
2827 + tmp8 = 0;
2828 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
2829 +
2830 + /* Configure RX control register => stop operation */
2831 + tmp16 = AX_RX_CTL_STOP;
2832 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16);
2833 +
2834 + return 0;
2835 +}
2836 +
2837 +/* This function is used to enable the autodetach function. */
2838 +/* This function is determined by offset 0x43 of EEPROM */
2839 +static int ax88179_auto_detach(struct usbnet *dev, int in_pm)
2840 +{
2841 + u16 tmp16;
2842 + u8 tmp8;
2843 + int (*fnr)(struct usbnet *, u8, u16, u16, u16, void *);
2844 + int (*fnw)(struct usbnet *, u8, u16, u16, u16, void *);
2845 +
2846 + if (!in_pm) {
2847 + fnr = ax88179_read_cmd;
2848 + fnw = ax88179_write_cmd;
2849 + } else {
2850 + fnr = ax88179_read_cmd_nopm;
2851 + fnw = ax88179_write_cmd_nopm;
2852 + }
2853 +
2854 + if (fnr(dev, AX_ACCESS_EEPROM, 0x43, 1, 2, &tmp16) < 0)
2855 + return 0;
2856 +
2857 + if ((tmp16 == 0xFFFF) || (!(tmp16 & 0x0100)))
2858 + return 0;
2859 +
2860 + /* Enable Auto Detach bit */
2861 + tmp8 = 0;
2862 + fnr(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
2863 + tmp8 |= AX_CLK_SELECT_ULR;
2864 + fnw(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
2865 +
2866 + fnr(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16);
2867 + tmp16 |= AX_PHYPWR_RSTCTL_AT;
2868 + fnw(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16);
2869 +
2870 + return 0;
2871 +}
2872 +
2873 +static int ax88179_resume(struct usb_interface *intf)
2874 +{
2875 + struct usbnet *dev = usb_get_intfdata(intf);
2876 + u16 tmp16;
2877 + u8 tmp8;
2878 +
2879 + usbnet_link_change(dev, 0, 0);
2880 +
2881 + /* Power up ethernet PHY */
2882 + tmp16 = 0;
2883 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
2884 + 2, 2, &tmp16);
2885 + udelay(1000);
2886 +
2887 + tmp16 = AX_PHYPWR_RSTCTL_IPRL;
2888 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
2889 + 2, 2, &tmp16);
2890 + msleep(200);
2891 +
2892 + /* Ethernet PHY Auto Detach*/
2893 + ax88179_auto_detach(dev, 1);
2894 +
2895 + /* Enable clock */
2896 + ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
2897 + tmp8 |= AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS;
2898 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
2899 + msleep(100);
2900 +
2901 + /* Configure RX control register => start operation */
2902 + tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START |
2903 + AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB;
2904 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16);
2905 +
2906 + return usbnet_resume(intf);
2907 +}
2908 +
2909 +static void
2910 +ax88179_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
2911 +{
2912 + struct usbnet *dev = netdev_priv(net);
2913 + u8 opt;
2914 +
2915 + if (ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD,
2916 + 1, 1, &opt) < 0) {
2917 + wolinfo->supported = 0;
2918 + wolinfo->wolopts = 0;
2919 + return;
2920 + }
2921 +
2922 + wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
2923 + wolinfo->wolopts = 0;
2924 + if (opt & AX_MONITOR_MODE_RWLC)
2925 + wolinfo->wolopts |= WAKE_PHY;
2926 + if (opt & AX_MONITOR_MODE_RWMP)
2927 + wolinfo->wolopts |= WAKE_MAGIC;
2928 +}
2929 +
2930 +static int
2931 +ax88179_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
2932 +{
2933 + struct usbnet *dev = netdev_priv(net);
2934 + u8 opt = 0;
2935 +
2936 + if (wolinfo->wolopts & WAKE_PHY)
2937 + opt |= AX_MONITOR_MODE_RWLC;
2938 + if (wolinfo->wolopts & WAKE_MAGIC)
2939 + opt |= AX_MONITOR_MODE_RWMP;
2940 +
2941 + if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD,
2942 + 1, 1, &opt) < 0)
2943 + return -EINVAL;
2944 +
2945 + return 0;
2946 +}
2947 +
2948 +static int ax88179_get_eeprom_len(struct net_device *net)
2949 +{
2950 + return AX_EEPROM_LEN;
2951 +}
2952 +
2953 +static int
2954 +ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
2955 + u8 *data)
2956 +{
2957 + struct usbnet *dev = netdev_priv(net);
2958 + u16 *eeprom_buff;
2959 + int first_word, last_word;
2960 + int i, ret;
2961 +
2962 + if (eeprom->len == 0)
2963 + return -EINVAL;
2964 +
2965 + eeprom->magic = AX88179_EEPROM_MAGIC;
2966 +
2967 + first_word = eeprom->offset >> 1;
2968 + last_word = (eeprom->offset + eeprom->len - 1) >> 1;
2969 + eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
2970 + GFP_KERNEL);
2971 + if (!eeprom_buff)
2972 + return -ENOMEM;
2973 +
2974 + /* ax88179/178A returns 2 bytes from eeprom on read */
2975 + for (i = first_word; i <= last_word; i++) {
2976 + ret = __ax88179_read_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2,
2977 + &eeprom_buff[i - first_word],
2978 + 0);
2979 + if (ret < 0) {
2980 + kfree(eeprom_buff);
2981 + return -EIO;
2982 + }
2983 + }
2984 +
2985 + memcpy(data, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
2986 + kfree(eeprom_buff);
2987 + return 0;
2988 +}
2989 +
2990 +static int ax88179_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
2991 +{
2992 + struct usbnet *dev = netdev_priv(net);
2993 + return mii_ethtool_gset(&dev->mii, cmd);
2994 +}
2995 +
2996 +static int ax88179_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
2997 +{
2998 + struct usbnet *dev = netdev_priv(net);
2999 + return mii_ethtool_sset(&dev->mii, cmd);
3000 +}
3001 +
3002 +static int
3003 +ax88179_ethtool_get_eee(struct usbnet *dev, struct ethtool_eee *data)
3004 +{
3005 + int val;
3006 +
3007 + /* Get Supported EEE */
3008 + val = ax88179_phy_read_mmd_indirect(dev, MDIO_PCS_EEE_ABLE,
3009 + MDIO_MMD_PCS);
3010 + if (val < 0)
3011 + return val;
3012 + data->supported = mmd_eee_cap_to_ethtool_sup_t(val);
3013 +
3014 + /* Get advertisement EEE */
3015 + val = ax88179_phy_read_mmd_indirect(dev, MDIO_AN_EEE_ADV,
3016 + MDIO_MMD_AN);
3017 + if (val < 0)
3018 + return val;
3019 + data->advertised = mmd_eee_adv_to_ethtool_adv_t(val);
3020 +
3021 + /* Get LP advertisement EEE */
3022 + val = ax88179_phy_read_mmd_indirect(dev, MDIO_AN_EEE_LPABLE,
3023 + MDIO_MMD_AN);
3024 + if (val < 0)
3025 + return val;
3026 + data->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(val);
3027 +
3028 + return 0;
3029 +}
3030 +
3031 +static int
3032 +ax88179_ethtool_set_eee(struct usbnet *dev, struct ethtool_eee *data)
3033 +{
3034 + u16 tmp16 = ethtool_adv_to_mmd_eee_adv_t(data->advertised);
3035 +
3036 + return ax88179_phy_write_mmd_indirect(dev, MDIO_AN_EEE_ADV,
3037 + MDIO_MMD_AN, tmp16);
3038 +}
3039 +
3040 +static int ax88179_chk_eee(struct usbnet *dev)
3041 +{
3042 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
3043 + struct ax88179_data *priv = (struct ax88179_data *)dev->data;
3044 +
3045 + mii_ethtool_gset(&dev->mii, &ecmd);
3046 +
3047 + if (ecmd.duplex & DUPLEX_FULL) {
3048 + int eee_lp, eee_cap, eee_adv;
3049 + u32 lp, cap, adv, supported = 0;
3050 +
3051 + eee_cap = ax88179_phy_read_mmd_indirect(dev,
3052 + MDIO_PCS_EEE_ABLE,
3053 + MDIO_MMD_PCS);
3054 + if (eee_cap < 0) {
3055 + priv->eee_active = 0;
3056 + return false;
3057 + }
3058 +
3059 + cap = mmd_eee_cap_to_ethtool_sup_t(eee_cap);
3060 + if (!cap) {
3061 + priv->eee_active = 0;
3062 + return false;
3063 + }
3064 +
3065 + eee_lp = ax88179_phy_read_mmd_indirect(dev,
3066 + MDIO_AN_EEE_LPABLE,
3067 + MDIO_MMD_AN);
3068 + if (eee_lp < 0) {
3069 + priv->eee_active = 0;
3070 + return false;
3071 + }
3072 +
3073 + eee_adv = ax88179_phy_read_mmd_indirect(dev,
3074 + MDIO_AN_EEE_ADV,
3075 + MDIO_MMD_AN);
3076 +
3077 + if (eee_adv < 0) {
3078 + priv->eee_active = 0;
3079 + return false;
3080 + }
3081 +
3082 + adv = mmd_eee_adv_to_ethtool_adv_t(eee_adv);
3083 + lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp);
3084 + supported = (ecmd.speed == SPEED_1000) ?
3085 + SUPPORTED_1000baseT_Full :
3086 + SUPPORTED_100baseT_Full;
3087 +
3088 + if (!(lp & adv & supported)) {
3089 + priv->eee_active = 0;
3090 + return false;
3091 + }
3092 +
3093 + priv->eee_active = 1;
3094 + return true;
3095 + }
3096 +
3097 + priv->eee_active = 0;
3098 + return false;
3099 +}
3100 +
3101 +static void ax88179_disable_eee(struct usbnet *dev)
3102 +{
3103 + u16 tmp16;
3104 +
3105 + tmp16 = GMII_PHY_PGSEL_PAGE3;
3106 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3107 + GMII_PHY_PAGE_SELECT, 2, &tmp16);
3108 +
3109 + tmp16 = 0x3246;
3110 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3111 + MII_PHYADDR, 2, &tmp16);
3112 +
3113 + tmp16 = GMII_PHY_PGSEL_PAGE0;
3114 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3115 + GMII_PHY_PAGE_SELECT, 2, &tmp16);
3116 +}
3117 +
3118 +static void ax88179_enable_eee(struct usbnet *dev)
3119 +{
3120 + u16 tmp16;
3121 +
3122 + tmp16 = GMII_PHY_PGSEL_PAGE3;
3123 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3124 + GMII_PHY_PAGE_SELECT, 2, &tmp16);
3125 +
3126 + tmp16 = 0x3247;
3127 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3128 + MII_PHYADDR, 2, &tmp16);
3129 +
3130 + tmp16 = GMII_PHY_PGSEL_PAGE5;
3131 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3132 + GMII_PHY_PAGE_SELECT, 2, &tmp16);
3133 +
3134 + tmp16 = 0x0680;
3135 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3136 + MII_BMSR, 2, &tmp16);
3137 +
3138 + tmp16 = GMII_PHY_PGSEL_PAGE0;
3139 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3140 + GMII_PHY_PAGE_SELECT, 2, &tmp16);
3141 +}
3142 +
3143 +static int ax88179_get_eee(struct net_device *net, struct ethtool_eee *edata)
3144 +{
3145 + struct usbnet *dev = netdev_priv(net);
3146 + struct ax88179_data *priv = (struct ax88179_data *)dev->data;
3147 +
3148 + edata->eee_enabled = priv->eee_enabled;
3149 + edata->eee_active = priv->eee_active;
3150 +
3151 + return ax88179_ethtool_get_eee(dev, edata);
3152 +}
3153 +
3154 +static int ax88179_set_eee(struct net_device *net, struct ethtool_eee *edata)
3155 +{
3156 + struct usbnet *dev = netdev_priv(net);
3157 + struct ax88179_data *priv = (struct ax88179_data *)dev->data;
3158 + int ret = -EOPNOTSUPP;
3159 +
3160 + priv->eee_enabled = edata->eee_enabled;
3161 + if (!priv->eee_enabled) {
3162 + ax88179_disable_eee(dev);
3163 + } else {
3164 + priv->eee_enabled = ax88179_chk_eee(dev);
3165 + if (!priv->eee_enabled)
3166 + return -EOPNOTSUPP;
3167 +
3168 + ax88179_enable_eee(dev);
3169 + }
3170 +
3171 + ret = ax88179_ethtool_set_eee(dev, edata);
3172 + if (ret)
3173 + return ret;
3174 +
3175 + mii_nway_restart(&dev->mii);
3176 +
3177 + usbnet_link_change(dev, 0, 0);
3178 +
3179 + return ret;
3180 +}
3181 +
3182 +static int ax88179_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
3183 +{
3184 + struct usbnet *dev = netdev_priv(net);
3185 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
3186 +}
3187 +
3188 +static const struct ethtool_ops ax88179_ethtool_ops = {
3189 + .get_link = ethtool_op_get_link,
3190 + .get_msglevel = usbnet_get_msglevel,
3191 + .set_msglevel = usbnet_set_msglevel,
3192 + .get_wol = ax88179_get_wol,
3193 + .set_wol = ax88179_set_wol,
3194 + .get_eeprom_len = ax88179_get_eeprom_len,
3195 + .get_eeprom = ax88179_get_eeprom,
3196 + .get_settings = ax88179_get_settings,
3197 + .set_settings = ax88179_set_settings,
3198 + .get_eee = ax88179_get_eee,
3199 + .set_eee = ax88179_set_eee,
3200 + .nway_reset = usbnet_nway_reset,
3201 +};
3202 +
3203 +static void ax88179_set_multicast(struct net_device *net)
3204 +{
3205 + struct usbnet *dev = netdev_priv(net);
3206 + struct ax88179_data *data = (struct ax88179_data *)dev->data;
3207 + u8 *m_filter = ((u8 *)dev->data) + 12;
3208 +
3209 + data->rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_IPE);
3210 +
3211 + if (net->flags & IFF_PROMISC) {
3212 + data->rxctl |= AX_RX_CTL_PRO;
3213 + } else if (net->flags & IFF_ALLMULTI ||
3214 + netdev_mc_count(net) > AX_MAX_MCAST) {
3215 + data->rxctl |= AX_RX_CTL_AMALL;
3216 + } else if (netdev_mc_empty(net)) {
3217 + /* just broadcast and directed */
3218 + } else {
3219 + /* We use the 20 byte dev->data for our 8 byte filter buffer
3220 + * to avoid allocating memory that is tricky to free later
3221 + */
3222 + u32 crc_bits;
3223 + struct netdev_hw_addr *ha;
3224 +
3225 + memset(m_filter, 0, AX_MCAST_FLTSIZE);
3226 +
3227 + netdev_for_each_mc_addr(ha, net) {
3228 + crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
3229 + *(m_filter + (crc_bits >> 3)) |= (1 << (crc_bits & 7));
3230 + }
3231 +
3232 + ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_MULFLTARY,
3233 + AX_MCAST_FLTSIZE, AX_MCAST_FLTSIZE,
3234 + m_filter);
3235 +
3236 + data->rxctl |= AX_RX_CTL_AM;
3237 + }
3238 +
3239 + ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_RX_CTL,
3240 + 2, 2, &data->rxctl);
3241 +}
3242 +
3243 +static int
3244 +ax88179_set_features(struct net_device *net, netdev_features_t features)
3245 +{
3246 + u8 tmp;
3247 + struct usbnet *dev = netdev_priv(net);
3248 + netdev_features_t changed = net->features ^ features;
3249 +
3250 + if (changed & NETIF_F_IP_CSUM) {
3251 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp);
3252 + tmp ^= AX_TXCOE_TCP | AX_TXCOE_UDP;
3253 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp);
3254 + }
3255 +
3256 + if (changed & NETIF_F_IPV6_CSUM) {
3257 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp);
3258 + tmp ^= AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6;
3259 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp);
3260 + }
3261 +
3262 + if (changed & NETIF_F_RXCSUM) {
3263 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp);
3264 + tmp ^= AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
3265 + AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6;
3266 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp);
3267 + }
3268 +
3269 + return 0;
3270 +}
3271 +
3272 +static int ax88179_change_mtu(struct net_device *net, int new_mtu)
3273 +{
3274 + struct usbnet *dev = netdev_priv(net);
3275 + u16 tmp16;
3276 +
3277 + if (new_mtu <= 0 || new_mtu > 4088)
3278 + return -EINVAL;
3279 +
3280 + net->mtu = new_mtu;
3281 + dev->hard_mtu = net->mtu + net->hard_header_len;
3282 +
3283 + if (net->mtu > 1500) {
3284 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3285 + 2, 2, &tmp16);
3286 + tmp16 |= AX_MEDIUM_JUMBO_EN;
3287 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3288 + 2, 2, &tmp16);
3289 + } else {
3290 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3291 + 2, 2, &tmp16);
3292 + tmp16 &= ~AX_MEDIUM_JUMBO_EN;
3293 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3294 + 2, 2, &tmp16);
3295 + }
3296 +
3297 + /* max qlen depend on hard_mtu and rx_urb_size */
3298 + usbnet_update_max_qlen(dev);
3299 +
3300 + return 0;
3301 +}
3302 +
3303 +static int ax88179_set_mac_addr(struct net_device *net, void *p)
3304 +{
3305 + struct usbnet *dev = netdev_priv(net);
3306 + struct sockaddr *addr = p;
3307 + int ret;
3308 +
3309 + if (netif_running(net))
3310 + return -EBUSY;
3311 + if (!is_valid_ether_addr(addr->sa_data))
3312 + return -EADDRNOTAVAIL;
3313 +
3314 + memcpy(net->dev_addr, addr->sa_data, ETH_ALEN);
3315 +
3316 + /* Set the MAC address */
3317 + ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN,
3318 + ETH_ALEN, net->dev_addr);
3319 + if (ret < 0)
3320 + return ret;
3321 +
3322 + return 0;
3323 +}
3324 +
3325 +static const struct net_device_ops ax88179_netdev_ops = {
3326 + .ndo_open = usbnet_open,
3327 + .ndo_stop = usbnet_stop,
3328 + .ndo_start_xmit = usbnet_start_xmit,
3329 + .ndo_tx_timeout = usbnet_tx_timeout,
3330 + .ndo_change_mtu = ax88179_change_mtu,
3331 + .ndo_set_mac_address = ax88179_set_mac_addr,
3332 + .ndo_validate_addr = eth_validate_addr,
3333 + .ndo_do_ioctl = ax88179_ioctl,
3334 + .ndo_set_rx_mode = ax88179_set_multicast,
3335 + .ndo_set_features = ax88179_set_features,
3336 +};
3337 +
3338 +static int ax88179_check_eeprom(struct usbnet *dev)
3339 +{
3340 + u8 i, buf, eeprom[20];
3341 + u16 csum, delay = HZ / 10;
3342 + unsigned long jtimeout;
3343 +
3344 + /* Read EEPROM content */
3345 + for (i = 0; i < 6; i++) {
3346 + buf = i;
3347 + if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_ADDR,
3348 + 1, 1, &buf) < 0)
3349 + return -EINVAL;
3350 +
3351 + buf = EEP_RD;
3352 + if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD,
3353 + 1, 1, &buf) < 0)
3354 + return -EINVAL;
3355 +
3356 + jtimeout = jiffies + delay;
3357 + do {
3358 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD,
3359 + 1, 1, &buf);
3360 +
3361 + if (time_after(jiffies, jtimeout))
3362 + return -EINVAL;
3363 +
3364 + } while (buf & EEP_BUSY);
3365 +
3366 + __ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW,
3367 + 2, 2, &eeprom[i * 2], 0);
3368 +
3369 + if ((i == 0) && (eeprom[0] == 0xFF))
3370 + return -EINVAL;
3371 + }
3372 +
3373 + csum = eeprom[6] + eeprom[7] + eeprom[8] + eeprom[9];
3374 + csum = (csum >> 8) + (csum & 0xff);
3375 + if ((csum + eeprom[10]) != 0xff)
3376 + return -EINVAL;
3377 +
3378 + return 0;
3379 +}
3380 +
3381 +static int ax88179_check_efuse(struct usbnet *dev, u16 *ledmode)
3382 +{
3383 + u8 i;
3384 + u8 efuse[64];
3385 + u16 csum = 0;
3386 +
3387 + if (ax88179_read_cmd(dev, AX_ACCESS_EFUS, 0, 64, 64, efuse) < 0)
3388 + return -EINVAL;
3389 +
3390 + if (*efuse == 0xFF)
3391 + return -EINVAL;
3392 +
3393 + for (i = 0; i < 64; i++)
3394 + csum = csum + efuse[i];
3395 +
3396 + while (csum > 255)
3397 + csum = (csum & 0x00FF) + ((csum >> 8) & 0x00FF);
3398 +
3399 + if (csum != 0xFF)
3400 + return -EINVAL;
3401 +
3402 + *ledmode = (efuse[51] << 8) | efuse[52];
3403 +
3404 + return 0;
3405 +}
3406 +
3407 +static int ax88179_convert_old_led(struct usbnet *dev, u16 *ledvalue)
3408 +{
3409 + u16 led;
3410 +
3411 + /* Loaded the old eFuse LED Mode */
3412 + if (ax88179_read_cmd(dev, AX_ACCESS_EEPROM, 0x3C, 1, 2, &led) < 0)
3413 + return -EINVAL;
3414 +
3415 + led >>= 8;
3416 + switch (led) {
3417 + case 0xFF:
3418 + led = LED0_ACTIVE | LED1_LINK_10 | LED1_LINK_100 |
3419 + LED1_LINK_1000 | LED2_ACTIVE | LED2_LINK_10 |
3420 + LED2_LINK_100 | LED2_LINK_1000 | LED_VALID;
3421 + break;
3422 + case 0xFE:
3423 + led = LED0_ACTIVE | LED1_LINK_1000 | LED2_LINK_100 | LED_VALID;
3424 + break;
3425 + case 0xFD:
3426 + led = LED0_ACTIVE | LED1_LINK_1000 | LED2_LINK_100 |
3427 + LED2_LINK_10 | LED_VALID;
3428 + break;
3429 + case 0xFC:
3430 + led = LED0_ACTIVE | LED1_ACTIVE | LED1_LINK_1000 | LED2_ACTIVE |
3431 + LED2_LINK_100 | LED2_LINK_10 | LED_VALID;
3432 + break;
3433 + default:
3434 + led = LED0_ACTIVE | LED1_LINK_10 | LED1_LINK_100 |
3435 + LED1_LINK_1000 | LED2_ACTIVE | LED2_LINK_10 |
3436 + LED2_LINK_100 | LED2_LINK_1000 | LED_VALID;
3437 + break;
3438 + }
3439 +
3440 + *ledvalue = led;
3441 +
3442 + return 0;
3443 +}
3444 +
3445 +static int ax88179_led_setting(struct usbnet *dev)
3446 +{
3447 + u8 ledfd, value = 0;
3448 + u16 tmp, ledact, ledlink, ledvalue = 0, delay = HZ / 10;
3449 + unsigned long jtimeout;
3450 +
3451 + /* Check AX88179 version. UA1 or UA2*/
3452 + ax88179_read_cmd(dev, AX_ACCESS_MAC, GENERAL_STATUS, 1, 1, &value);
3453 +
3454 + if (!(value & AX_SECLD)) { /* UA1 */
3455 + value = AX_GPIO_CTRL_GPIO3EN | AX_GPIO_CTRL_GPIO2EN |
3456 + AX_GPIO_CTRL_GPIO1EN;
3457 + if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_GPIO_CTRL,
3458 + 1, 1, &value) < 0)
3459 + return -EINVAL;
3460 + }
3461 +
3462 + /* Check EEPROM */
3463 + if (!ax88179_check_eeprom(dev)) {
3464 + value = 0x42;
3465 + if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_ADDR,
3466 + 1, 1, &value) < 0)
3467 + return -EINVAL;
3468 +
3469 + value = EEP_RD;
3470 + if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD,
3471 + 1, 1, &value) < 0)
3472 + return -EINVAL;
3473 +
3474 + jtimeout = jiffies + delay;
3475 + do {
3476 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD,
3477 + 1, 1, &value);
3478 +
3479 + if (time_after(jiffies, jtimeout))
3480 + return -EINVAL;
3481 +
3482 + } while (value & EEP_BUSY);
3483 +
3484 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_HIGH,
3485 + 1, 1, &value);
3486 + ledvalue = (value << 8);
3487 +
3488 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW,
3489 + 1, 1, &value);
3490 + ledvalue |= value;
3491 +
3492 + /* load internal ROM for defaule setting */
3493 + if ((ledvalue == 0xFFFF) || ((ledvalue & LED_VALID) == 0))
3494 + ax88179_convert_old_led(dev, &ledvalue);
3495 +
3496 + } else if (!ax88179_check_efuse(dev, &ledvalue)) {
3497 + if ((ledvalue == 0xFFFF) || ((ledvalue & LED_VALID) == 0))
3498 + ax88179_convert_old_led(dev, &ledvalue);
3499 + } else {
3500 + ax88179_convert_old_led(dev, &ledvalue);
3501 + }
3502 +
3503 + tmp = GMII_PHY_PGSEL_EXT;
3504 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3505 + GMII_PHY_PAGE_SELECT, 2, &tmp);
3506 +
3507 + tmp = 0x2c;
3508 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3509 + GMII_PHYPAGE, 2, &tmp);
3510 +
3511 + ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3512 + GMII_LED_ACT, 2, &ledact);
3513 +
3514 + ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3515 + GMII_LED_LINK, 2, &ledlink);
3516 +
3517 + ledact &= GMII_LED_ACTIVE_MASK;
3518 + ledlink &= GMII_LED_LINK_MASK;
3519 +
3520 + if (ledvalue & LED0_ACTIVE)
3521 + ledact |= GMII_LED0_ACTIVE;
3522 +
3523 + if (ledvalue & LED1_ACTIVE)
3524 + ledact |= GMII_LED1_ACTIVE;
3525 +
3526 + if (ledvalue & LED2_ACTIVE)
3527 + ledact |= GMII_LED2_ACTIVE;
3528 +
3529 + if (ledvalue & LED0_LINK_10)
3530 + ledlink |= GMII_LED0_LINK_10;
3531 +
3532 + if (ledvalue & LED1_LINK_10)
3533 + ledlink |= GMII_LED1_LINK_10;
3534 +
3535 + if (ledvalue & LED2_LINK_10)
3536 + ledlink |= GMII_LED2_LINK_10;
3537 +
3538 + if (ledvalue & LED0_LINK_100)
3539 + ledlink |= GMII_LED0_LINK_100;
3540 +
3541 + if (ledvalue & LED1_LINK_100)
3542 + ledlink |= GMII_LED1_LINK_100;
3543 +
3544 + if (ledvalue & LED2_LINK_100)
3545 + ledlink |= GMII_LED2_LINK_100;
3546 +
3547 + if (ledvalue & LED0_LINK_1000)
3548 + ledlink |= GMII_LED0_LINK_1000;
3549 +
3550 + if (ledvalue & LED1_LINK_1000)
3551 + ledlink |= GMII_LED1_LINK_1000;
3552 +
3553 + if (ledvalue & LED2_LINK_1000)
3554 + ledlink |= GMII_LED2_LINK_1000;
3555 +
3556 + tmp = ledact;
3557 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3558 + GMII_LED_ACT, 2, &tmp);
3559 +
3560 + tmp = ledlink;
3561 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3562 + GMII_LED_LINK, 2, &tmp);
3563 +
3564 + tmp = GMII_PHY_PGSEL_PAGE0;
3565 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3566 + GMII_PHY_PAGE_SELECT, 2, &tmp);
3567 +
3568 + /* LED full duplex setting */
3569 + ledfd = 0;
3570 + if (ledvalue & LED0_FD)
3571 + ledfd |= 0x01;
3572 + else if ((ledvalue & LED0_USB3_MASK) == 0)
3573 + ledfd |= 0x02;
3574 +
3575 + if (ledvalue & LED1_FD)
3576 + ledfd |= 0x04;
3577 + else if ((ledvalue & LED1_USB3_MASK) == 0)
3578 + ledfd |= 0x08;
3579 +
3580 + if (ledvalue & LED2_FD)
3581 + ledfd |= 0x10;
3582 + else if ((ledvalue & LED2_USB3_MASK) == 0)
3583 + ledfd |= 0x20;
3584 +
3585 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_LEDCTRL, 1, 1, &ledfd);
3586 +
3587 + return 0;
3588 +}
3589 +
3590 +static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
3591 +{
3592 + u8 buf[5];
3593 + u16 *tmp16;
3594 + u8 *tmp;
3595 + struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data;
3596 + struct ethtool_eee eee_data;
3597 +
3598 + usbnet_get_endpoints(dev, intf);
3599 +
3600 + tmp16 = (u16 *)buf;
3601 + tmp = (u8 *)buf;
3602 +
3603 + memset(ax179_data, 0, sizeof(*ax179_data));
3604 +
3605 + /* Power up ethernet PHY */
3606 + *tmp16 = 0;
3607 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16);
3608 + *tmp16 = AX_PHYPWR_RSTCTL_IPRL;
3609 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16);
3610 + msleep(200);
3611 +
3612 + *tmp = AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS;
3613 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp);
3614 + msleep(100);
3615 +
3616 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN,
3617 + ETH_ALEN, dev->net->dev_addr);
3618 + memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);
3619 +
3620 + /* RX bulk configuration */
3621 + memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5);
3622 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp);
3623 +
3624 + dev->rx_urb_size = 1024 * 20;
3625 +
3626 + *tmp = 0x34;
3627 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp);
3628 +
3629 + *tmp = 0x52;
3630 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH,
3631 + 1, 1, tmp);
3632 +
3633 + dev->net->netdev_ops = &ax88179_netdev_ops;
3634 + dev->net->ethtool_ops = &ax88179_ethtool_ops;
3635 + dev->net->needed_headroom = 8;
3636 +
3637 + /* Initialize MII structure */
3638 + dev->mii.dev = dev->net;
3639 + dev->mii.mdio_read = ax88179_mdio_read;
3640 + dev->mii.mdio_write = ax88179_mdio_write;
3641 + dev->mii.phy_id_mask = 0xff;
3642 + dev->mii.reg_num_mask = 0xff;
3643 + dev->mii.phy_id = 0x03;
3644 + dev->mii.supports_gmii = 1;
3645 +
3646 + dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3647 + NETIF_F_RXCSUM;
3648 +
3649 + dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3650 + NETIF_F_RXCSUM;
3651 +
3652 + /* Enable checksum offload */
3653 + *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
3654 + AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6;
3655 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, tmp);
3656 +
3657 + *tmp = AX_TXCOE_IP | AX_TXCOE_TCP | AX_TXCOE_UDP |
3658 + AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6;
3659 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, tmp);
3660 +
3661 + /* Configure RX control register => start operation */
3662 + *tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START |
3663 + AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB;
3664 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16);
3665 +
3666 + *tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL |
3667 + AX_MONITOR_MODE_RWMP;
3668 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, tmp);
3669 +
3670 + /* Configure default medium type => giga */
3671 + *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
3672 + AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX |
3673 + AX_MEDIUM_GIGAMODE;
3674 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3675 + 2, 2, tmp16);
3676 +
3677 + ax88179_led_setting(dev);
3678 +
3679 + ax179_data->eee_enabled = 0;
3680 + ax179_data->eee_active = 0;
3681 +
3682 + ax88179_disable_eee(dev);
3683 +
3684 + ax88179_ethtool_get_eee(dev, &eee_data);
3685 + eee_data.advertised = 0;
3686 + ax88179_ethtool_set_eee(dev, &eee_data);
3687 +
3688 + /* Restart autoneg */
3689 + mii_nway_restart(&dev->mii);
3690 +
3691 + usbnet_link_change(dev, 0, 0);
3692 +
3693 + return 0;
3694 +}
3695 +
3696 +static void ax88179_unbind(struct usbnet *dev, struct usb_interface *intf)
3697 +{
3698 + u16 tmp16;
3699 +
3700 + /* Configure RX control register => stop operation */
3701 + tmp16 = AX_RX_CTL_STOP;
3702 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16);
3703 +
3704 + tmp16 = 0;
3705 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp16);
3706 +
3707 + /* Power down ethernet PHY */
3708 + tmp16 = 0;
3709 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16);
3710 +}
3711 +
3712 +static void
3713 +ax88179_rx_checksum(struct sk_buff *skb, u32 *pkt_hdr)
3714 +{
3715 + skb->ip_summed = CHECKSUM_NONE;
3716 +
3717 + /* checksum error bit is set */
3718 + if ((*pkt_hdr & AX_RXHDR_L3CSUM_ERR) ||
3719 + (*pkt_hdr & AX_RXHDR_L4CSUM_ERR))
3720 + return;
3721 +
3722 + /* It must be a TCP or UDP packet with a valid checksum */
3723 + if (((*pkt_hdr & AX_RXHDR_L4_TYPE_MASK) == AX_RXHDR_L4_TYPE_TCP) ||
3724 + ((*pkt_hdr & AX_RXHDR_L4_TYPE_MASK) == AX_RXHDR_L4_TYPE_UDP))
3725 + skb->ip_summed = CHECKSUM_UNNECESSARY;
3726 +}
3727 +
3728 +static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
3729 +{
3730 + struct sk_buff *ax_skb;
3731 + int pkt_cnt;
3732 + u32 rx_hdr;
3733 + u16 hdr_off;
3734 + u32 *pkt_hdr;
3735 +
3736 + /* This check is no longer done by usbnet */
3737 + if (skb->len < dev->net->hard_header_len)
3738 + return 0;
3739 +
3740 + skb_trim(skb, skb->len - 4);
3741 + memcpy(&rx_hdr, skb_tail_pointer(skb), 4);
3742 + le32_to_cpus(&rx_hdr);
3743 +
3744 + pkt_cnt = (u16)rx_hdr;
3745 + hdr_off = (u16)(rx_hdr >> 16);
3746 + pkt_hdr = (u32 *)(skb->data + hdr_off);
3747 +
3748 + while (pkt_cnt--) {
3749 + u16 pkt_len;
3750 +
3751 + le32_to_cpus(pkt_hdr);
3752 + pkt_len = (*pkt_hdr >> 16) & 0x1fff;
3753 +
3754 + /* Check CRC or runt packet */
3755 + if ((*pkt_hdr & AX_RXHDR_CRC_ERR) ||
3756 + (*pkt_hdr & AX_RXHDR_DROP_ERR)) {
3757 + skb_pull(skb, (pkt_len + 7) & 0xFFF8);
3758 + pkt_hdr++;
3759 + continue;
3760 + }
3761 +
3762 + if (pkt_cnt == 0) {
3763 + /* Skip IP alignment psudo header */
3764 + skb_pull(skb, 2);
3765 + skb->len = pkt_len;
3766 + skb_set_tail_pointer(skb, pkt_len);
3767 + skb->truesize = pkt_len + sizeof(struct sk_buff);
3768 + ax88179_rx_checksum(skb, pkt_hdr);
3769 + return 1;
3770 + }
3771 +
3772 + ax_skb = skb_clone(skb, GFP_ATOMIC);
3773 + if (ax_skb) {
3774 + ax_skb->len = pkt_len;
3775 + ax_skb->data = skb->data + 2;
3776 + skb_set_tail_pointer(ax_skb, pkt_len);
3777 + ax_skb->truesize = pkt_len + sizeof(struct sk_buff);
3778 + ax88179_rx_checksum(ax_skb, pkt_hdr);
3779 + usbnet_skb_return(dev, ax_skb);
3780 + } else {
3781 + return 0;
3782 + }
3783 +
3784 + skb_pull(skb, (pkt_len + 7) & 0xFFF8);
3785 + pkt_hdr++;
3786 + }
3787 + return 1;
3788 +}
3789 +
3790 +static struct sk_buff *
3791 +ax88179_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
3792 +{
3793 + u32 tx_hdr1, tx_hdr2;
3794 + int frame_size = dev->maxpacket;
3795 + int mss = skb_shinfo(skb)->gso_size;
3796 + int headroom;
3797 +
3798 + tx_hdr1 = skb->len;
3799 + tx_hdr2 = mss;
3800 + if (((skb->len + 8) % frame_size) == 0)
3801 + tx_hdr2 |= 0x80008000; /* Enable padding */
3802 +
3803 + headroom = skb_headroom(skb) - 8;
3804 +
3805 + if ((skb_header_cloned(skb) || headroom < 0) &&
3806 + pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) {
3807 + dev_kfree_skb_any(skb);
3808 + return NULL;
3809 + }
3810 +
3811 + skb_push(skb, 4);
3812 + cpu_to_le32s(&tx_hdr2);
3813 + skb_copy_to_linear_data(skb, &tx_hdr2, 4);
3814 +
3815 + skb_push(skb, 4);
3816 + cpu_to_le32s(&tx_hdr1);
3817 + skb_copy_to_linear_data(skb, &tx_hdr1, 4);
3818 +
3819 + return skb;
3820 +}
3821 +
3822 +static int ax88179_link_reset(struct usbnet *dev)
3823 +{
3824 + struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data;
3825 + u8 tmp[5], link_sts;
3826 + u16 mode, tmp16, delay = HZ / 10;
3827 + u32 tmp32 = 0x40000000;
3828 + unsigned long jtimeout;
3829 +
3830 + jtimeout = jiffies + delay;
3831 + while (tmp32 & 0x40000000) {
3832 + mode = 0;
3833 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &mode);
3834 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2,
3835 + &ax179_data->rxctl);
3836 +
3837 + /*link up, check the usb device control TX FIFO full or empty*/
3838 + ax88179_read_cmd(dev, 0x81, 0x8c, 0, 4, &tmp32);
3839 +
3840 + if (time_after(jiffies, jtimeout))
3841 + return 0;
3842 + }
3843 +
3844 + mode = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
3845 + AX_MEDIUM_RXFLOW_CTRLEN;
3846 +
3847 + ax88179_read_cmd(dev, AX_ACCESS_MAC, PHYSICAL_LINK_STATUS,
3848 + 1, 1, &link_sts);
3849 +
3850 + ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3851 + GMII_PHY_PHYSR, 2, &tmp16);
3852 +
3853 + if (!(tmp16 & GMII_PHY_PHYSR_LINK)) {
3854 + return 0;
3855 + } else if (GMII_PHY_PHYSR_GIGA == (tmp16 & GMII_PHY_PHYSR_SMASK)) {
3856 + mode |= AX_MEDIUM_GIGAMODE | AX_MEDIUM_EN_125MHZ;
3857 + if (dev->net->mtu > 1500)
3858 + mode |= AX_MEDIUM_JUMBO_EN;
3859 +
3860 + if (link_sts & AX_USB_SS)
3861 + memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5);
3862 + else if (link_sts & AX_USB_HS)
3863 + memcpy(tmp, &AX88179_BULKIN_SIZE[1], 5);
3864 + else
3865 + memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5);
3866 + } else if (GMII_PHY_PHYSR_100 == (tmp16 & GMII_PHY_PHYSR_SMASK)) {
3867 + mode |= AX_MEDIUM_PS;
3868 +
3869 + if (link_sts & (AX_USB_SS | AX_USB_HS))
3870 + memcpy(tmp, &AX88179_BULKIN_SIZE[2], 5);
3871 + else
3872 + memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5);
3873 + } else {
3874 + memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5);
3875 + }
3876 +
3877 + /* RX bulk configuration */
3878 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp);
3879 +
3880 + dev->rx_urb_size = (1024 * (tmp[3] + 2));
3881 +
3882 + if (tmp16 & GMII_PHY_PHYSR_FULL)
3883 + mode |= AX_MEDIUM_FULL_DUPLEX;
3884 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3885 + 2, 2, &mode);
3886 +
3887 + ax179_data->eee_enabled = ax88179_chk_eee(dev);
3888 +
3889 + netif_carrier_on(dev->net);
3890 +
3891 + return 0;
3892 +}
3893 +
3894 +static int ax88179_reset(struct usbnet *dev)
3895 +{
3896 + u8 buf[5];
3897 + u16 *tmp16;
3898 + u8 *tmp;
3899 + struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data;
3900 + struct ethtool_eee eee_data;
3901 +
3902 + tmp16 = (u16 *)buf;
3903 + tmp = (u8 *)buf;
3904 +
3905 + /* Power up ethernet PHY */
3906 + *tmp16 = 0;
3907 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16);
3908 +
3909 + *tmp16 = AX_PHYPWR_RSTCTL_IPRL;
3910 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16);
3911 + msleep(200);
3912 +
3913 + *tmp = AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS;
3914 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp);
3915 + msleep(100);
3916 +
3917 + /* Ethernet PHY Auto Detach*/
3918 + ax88179_auto_detach(dev, 0);
3919 +
3920 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, ETH_ALEN,
3921 + dev->net->dev_addr);
3922 + memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);
3923 +
3924 + /* RX bulk configuration */
3925 + memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5);
3926 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp);
3927 +
3928 + dev->rx_urb_size = 1024 * 20;
3929 +
3930 + *tmp = 0x34;
3931 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp);
3932 +
3933 + *tmp = 0x52;
3934 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH,
3935 + 1, 1, tmp);
3936 +
3937 + dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3938 + NETIF_F_RXCSUM;
3939 +
3940 + dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3941 + NETIF_F_RXCSUM;
3942 +
3943 + /* Enable checksum offload */
3944 + *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
3945 + AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6;
3946 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, tmp);
3947 +
3948 + *tmp = AX_TXCOE_IP | AX_TXCOE_TCP | AX_TXCOE_UDP |
3949 + AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6;
3950 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, tmp);
3951 +
3952 + /* Configure RX control register => start operation */
3953 + *tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START |
3954 + AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB;
3955 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16);
3956 +
3957 + *tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL |
3958 + AX_MONITOR_MODE_RWMP;
3959 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, tmp);
3960 +
3961 + /* Configure default medium type => giga */
3962 + *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
3963 + AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX |
3964 + AX_MEDIUM_GIGAMODE;
3965 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3966 + 2, 2, tmp16);
3967 +
3968 + ax88179_led_setting(dev);
3969 +
3970 + ax179_data->eee_enabled = 0;
3971 + ax179_data->eee_active = 0;
3972 +
3973 + ax88179_disable_eee(dev);
3974 +
3975 + ax88179_ethtool_get_eee(dev, &eee_data);
3976 + eee_data.advertised = 0;
3977 + ax88179_ethtool_set_eee(dev, &eee_data);
3978 +
3979 + /* Restart autoneg */
3980 + mii_nway_restart(&dev->mii);
3981 +
3982 + usbnet_link_change(dev, 0, 0);
3983 +
3984 + return 0;
3985 +}
3986 +
3987 +static int ax88179_stop(struct usbnet *dev)
3988 +{
3989 + u16 tmp16;
3990 +
3991 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3992 + 2, 2, &tmp16);
3993 + tmp16 &= ~AX_MEDIUM_RECEIVE_EN;
3994 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3995 + 2, 2, &tmp16);
3996 +
3997 + return 0;
3998 +}
3999 +
4000 +static const struct driver_info ax88179_info = {
4001 + .description = "ASIX AX88179 USB 3.0 Gigabit Ethernet",
4002 + .bind = ax88179_bind,
4003 + .unbind = ax88179_unbind,
4004 + .status = ax88179_status,
4005 + .link_reset = ax88179_link_reset,
4006 + .reset = ax88179_reset,
4007 + .stop = ax88179_stop,
4008 + .flags = FLAG_ETHER | FLAG_FRAMING_AX,
4009 + .rx_fixup = ax88179_rx_fixup,
4010 + .tx_fixup = ax88179_tx_fixup,
4011 +};
4012 +
4013 +static const struct driver_info ax88178a_info = {
4014 + .description = "ASIX AX88178A USB 2.0 Gigabit Ethernet",
4015 + .bind = ax88179_bind,
4016 + .unbind = ax88179_unbind,
4017 + .status = ax88179_status,
4018 + .link_reset = ax88179_link_reset,
4019 + .reset = ax88179_reset,
4020 + .stop = ax88179_stop,
4021 + .flags = FLAG_ETHER | FLAG_FRAMING_AX,
4022 + .rx_fixup = ax88179_rx_fixup,
4023 + .tx_fixup = ax88179_tx_fixup,
4024 +};
4025 +
4026 +static const struct driver_info dlink_dub1312_info = {
4027 + .description = "D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter",
4028 + .bind = ax88179_bind,
4029 + .unbind = ax88179_unbind,
4030 + .status = ax88179_status,
4031 + .link_reset = ax88179_link_reset,
4032 + .reset = ax88179_reset,
4033 + .stop = ax88179_stop,
4034 + .flags = FLAG_ETHER | FLAG_FRAMING_AX,
4035 + .rx_fixup = ax88179_rx_fixup,
4036 + .tx_fixup = ax88179_tx_fixup,
4037 +};
4038 +
4039 +static const struct driver_info sitecom_info = {
4040 + .description = "Sitecom USB 3.0 to Gigabit Adapter",
4041 + .bind = ax88179_bind,
4042 + .unbind = ax88179_unbind,
4043 + .status = ax88179_status,
4044 + .link_reset = ax88179_link_reset,
4045 + .reset = ax88179_reset,
4046 + .stop = ax88179_stop,
4047 + .flags = FLAG_ETHER | FLAG_FRAMING_AX,
4048 + .rx_fixup = ax88179_rx_fixup,
4049 + .tx_fixup = ax88179_tx_fixup,
4050 +};
4051 +
4052 +static const struct driver_info samsung_info = {
4053 + .description = "Samsung USB Ethernet Adapter",
4054 + .bind = ax88179_bind,
4055 + .unbind = ax88179_unbind,
4056 + .status = ax88179_status,
4057 + .link_reset = ax88179_link_reset,
4058 + .reset = ax88179_reset,
4059 + .stop = ax88179_stop,
4060 + .flags = FLAG_ETHER | FLAG_FRAMING_AX,
4061 + .rx_fixup = ax88179_rx_fixup,
4062 + .tx_fixup = ax88179_tx_fixup,
4063 +};
4064 +
4065 +static const struct driver_info lenovo_info = {
4066 + .description = "Lenovo OneLinkDock Gigabit LAN",
4067 + .bind = ax88179_bind,
4068 + .unbind = ax88179_unbind,
4069 + .status = ax88179_status,
4070 + .link_reset = ax88179_link_reset,
4071 + .reset = ax88179_reset,
4072 + .stop = ax88179_stop,
4073 + .flags = FLAG_ETHER | FLAG_FRAMING_AX,
4074 + .rx_fixup = ax88179_rx_fixup,
4075 + .tx_fixup = ax88179_tx_fixup,
4076 +};
4077 +
4078 +static const struct usb_device_id products[] = {
4079 +{
4080 + /* ASIX AX88179 10/100/1000 */
4081 + USB_DEVICE(0x0b95, 0x1790),
4082 + .driver_info = (unsigned long)&ax88179_info,
4083 +}, {
4084 + /* ASIX AX88178A 10/100/1000 */
4085 + USB_DEVICE(0x0b95, 0x178a),
4086 + .driver_info = (unsigned long)&ax88178a_info,
4087 +}, {
4088 + /* D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter */
4089 + USB_DEVICE(0x2001, 0x4a00),
4090 + .driver_info = (unsigned long)&dlink_dub1312_info,
4091 +}, {
4092 + /* Sitecom USB 3.0 to Gigabit Adapter */
4093 + USB_DEVICE(0x0df6, 0x0072),
4094 + .driver_info = (unsigned long)&sitecom_info,
4095 +}, {
4096 + /* Samsung USB Ethernet Adapter */
4097 + USB_DEVICE(0x04e8, 0xa100),
4098 + .driver_info = (unsigned long)&samsung_info,
4099 +}, {
4100 + /* Lenovo OneLinkDock Gigabit LAN */
4101 + USB_DEVICE(0x17ef, 0x304b),
4102 + .driver_info = (unsigned long)&lenovo_info,
4103 +},
4104 + { },
4105 +};
4106 +MODULE_DEVICE_TABLE(usb, products);
4107 +
4108 +static struct usb_driver ax88179_178a_driver = {
4109 + .name = "ax88179_178a",
4110 + .id_table = products,
4111 + .probe = usbnet_probe,
4112 + .suspend = ax88179_suspend,
4113 + .resume = ax88179_resume,
4114 + .reset_resume = ax88179_resume,
4115 + .disconnect = usbnet_disconnect,
4116 + .supports_autosuspend = 1,
4117 + .disable_hub_initiated_lpm = 1,
4118 +};
4119 +
4120 +module_usb_driver(ax88179_178a_driver);
4121 +
4122 +MODULE_DESCRIPTION("ASIX AX88179/178A based USB 3.0/2.0 Gigabit Ethernet Devices");
4123 +MODULE_LICENSE("GPL");
4124 diff -Naur backports-4.2.6-1.org/drivers/net/usb/catc.c backports-4.2.6-1/drivers/net/usb/catc.c
4125 --- backports-4.2.6-1.org/drivers/net/usb/catc.c 1970-01-01 01:00:00.000000000 +0100
4126 +++ backports-4.2.6-1/drivers/net/usb/catc.c 2016-06-28 14:35:17.975307221 +0200
4127 @@ -0,0 +1,965 @@
4128 +/*
4129 + * Copyright (c) 2001 Vojtech Pavlik
4130 + *
4131 + * CATC EL1210A NetMate USB Ethernet driver
4132 + *
4133 + * Sponsored by SuSE
4134 + *
4135 + * Based on the work of
4136 + * Donald Becker
4137 + *
4138 + * Old chipset support added by Simon Evans <spse@secret.org.uk> 2002
4139 + * - adds support for Belkin F5U011
4140 + */
4141 +
4142 +/*
4143 + * This program is free software; you can redistribute it and/or modify
4144 + * it under the terms of the GNU General Public License as published by
4145 + * the Free Software Foundation; either version 2 of the License, or
4146 + * (at your option) any later version.
4147 + *
4148 + * This program is distributed in the hope that it will be useful,
4149 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4150 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4151 + * GNU General Public License for more details.
4152 + *
4153 + * You should have received a copy of the GNU General Public License
4154 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
4155 + *
4156 + * Should you need to contact me, the author, you can do so either by
4157 + * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
4158 + * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
4159 + */
4160 +
4161 +#include <linux/module.h>
4162 +#include <linux/kernel.h>
4163 +#include <linux/string.h>
4164 +#include <linux/netdevice.h>
4165 +#include <linux/etherdevice.h>
4166 +#include <linux/skbuff.h>
4167 +#include <linux/spinlock.h>
4168 +#include <linux/ethtool.h>
4169 +#include <linux/crc32.h>
4170 +#include <linux/bitops.h>
4171 +#include <linux/gfp.h>
4172 +#include <asm/uaccess.h>
4173 +
4174 +#undef DEBUG
4175 +
4176 +#include <linux/usb.h>
4177 +
4178 +/*
4179 + * Version information.
4180 + */
4181 +
4182 +#define DRIVER_VERSION "v2.8"
4183 +#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@suse.cz>"
4184 +#define DRIVER_DESC "CATC EL1210A NetMate USB Ethernet driver"
4185 +#define SHORT_DRIVER_DESC "EL1210A NetMate USB Ethernet"
4186 +
4187 +MODULE_AUTHOR(DRIVER_AUTHOR);
4188 +MODULE_DESCRIPTION(DRIVER_DESC);
4189 +MODULE_LICENSE("GPL");
4190 +
4191 +static const char driver_name[] = "catc";
4192 +
4193 +/*
4194 + * Some defines.
4195 + */
4196 +
4197 +#define STATS_UPDATE (HZ) /* Time between stats updates */
4198 +#define TX_TIMEOUT (5*HZ) /* Max time the queue can be stopped */
4199 +#define PKT_SZ 1536 /* Max Ethernet packet size */
4200 +#define RX_MAX_BURST 15 /* Max packets per rx buffer (> 0, < 16) */
4201 +#define TX_MAX_BURST 15 /* Max full sized packets per tx buffer (> 0) */
4202 +#define CTRL_QUEUE 16 /* Max control requests in flight (power of two) */
4203 +#define RX_PKT_SZ 1600 /* Max size of receive packet for F5U011 */
4204 +
4205 +/*
4206 + * Control requests.
4207 + */
4208 +
4209 +enum control_requests {
4210 + ReadMem = 0xf1,
4211 + GetMac = 0xf2,
4212 + Reset = 0xf4,
4213 + SetMac = 0xf5,
4214 + SetRxMode = 0xf5, /* F5U011 only */
4215 + WriteROM = 0xf8,
4216 + SetReg = 0xfa,
4217 + GetReg = 0xfb,
4218 + WriteMem = 0xfc,
4219 + ReadROM = 0xfd,
4220 +};
4221 +
4222 +/*
4223 + * Registers.
4224 + */
4225 +
4226 +enum register_offsets {
4227 + TxBufCount = 0x20,
4228 + RxBufCount = 0x21,
4229 + OpModes = 0x22,
4230 + TxQed = 0x23,
4231 + RxQed = 0x24,
4232 + MaxBurst = 0x25,
4233 + RxUnit = 0x60,
4234 + EthStatus = 0x61,
4235 + StationAddr0 = 0x67,
4236 + EthStats = 0x69,
4237 + LEDCtrl = 0x81,
4238 +};
4239 +
4240 +enum eth_stats {
4241 + TxSingleColl = 0x00,
4242 + TxMultiColl = 0x02,
4243 + TxExcessColl = 0x04,
4244 + RxFramErr = 0x06,
4245 +};
4246 +
4247 +enum op_mode_bits {
4248 + Op3MemWaits = 0x03,
4249 + OpLenInclude = 0x08,
4250 + OpRxMerge = 0x10,
4251 + OpTxMerge = 0x20,
4252 + OpWin95bugfix = 0x40,
4253 + OpLoopback = 0x80,
4254 +};
4255 +
4256 +enum rx_filter_bits {
4257 + RxEnable = 0x01,
4258 + RxPolarity = 0x02,
4259 + RxForceOK = 0x04,
4260 + RxMultiCast = 0x08,
4261 + RxPromisc = 0x10,
4262 + AltRxPromisc = 0x20, /* F5U011 uses different bit */
4263 +};
4264 +
4265 +enum led_values {
4266 + LEDFast = 0x01,
4267 + LEDSlow = 0x02,
4268 + LEDFlash = 0x03,
4269 + LEDPulse = 0x04,
4270 + LEDLink = 0x08,
4271 +};
4272 +
4273 +enum link_status {
4274 + LinkNoChange = 0,
4275 + LinkGood = 1,
4276 + LinkBad = 2
4277 +};
4278 +
4279 +/*
4280 + * The catc struct.
4281 + */
4282 +
4283 +#define CTRL_RUNNING 0
4284 +#define RX_RUNNING 1
4285 +#define TX_RUNNING 2
4286 +
4287 +struct catc {
4288 + struct net_device *netdev;
4289 + struct usb_device *usbdev;
4290 +
4291 + unsigned long flags;
4292 +
4293 + unsigned int tx_ptr, tx_idx;
4294 + unsigned int ctrl_head, ctrl_tail;
4295 + spinlock_t tx_lock, ctrl_lock;
4296 +
4297 + u8 tx_buf[2][TX_MAX_BURST * (PKT_SZ + 2)];
4298 + u8 rx_buf[RX_MAX_BURST * (PKT_SZ + 2)];
4299 + u8 irq_buf[2];
4300 + u8 ctrl_buf[64];
4301 + struct usb_ctrlrequest ctrl_dr;
4302 +
4303 + struct timer_list timer;
4304 + u8 stats_buf[8];
4305 + u16 stats_vals[4];
4306 + unsigned long last_stats;
4307 +
4308 + u8 multicast[64];
4309 +
4310 + struct ctrl_queue {
4311 + u8 dir;
4312 + u8 request;
4313 + u16 value;
4314 + u16 index;
4315 + void *buf;
4316 + int len;
4317 + void (*callback)(struct catc *catc, struct ctrl_queue *q);
4318 + } ctrl_queue[CTRL_QUEUE];
4319 +
4320 + struct urb *tx_urb, *rx_urb, *irq_urb, *ctrl_urb;
4321 +
4322 + u8 is_f5u011; /* Set if device is an F5U011 */
4323 + u8 rxmode[2]; /* Used for F5U011 */
4324 + atomic_t recq_sz; /* Used for F5U011 - counter of waiting rx packets */
4325 +};
4326 +
4327 +/*
4328 + * Useful macros.
4329 + */
4330 +
4331 +#define catc_get_mac(catc, mac) catc_ctrl_msg(catc, USB_DIR_IN, GetMac, 0, 0, mac, 6)
4332 +#define catc_reset(catc) catc_ctrl_msg(catc, USB_DIR_OUT, Reset, 0, 0, NULL, 0)
4333 +#define catc_set_reg(catc, reg, val) catc_ctrl_msg(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0)
4334 +#define catc_get_reg(catc, reg, buf) catc_ctrl_msg(catc, USB_DIR_IN, GetReg, 0, reg, buf, 1)
4335 +#define catc_write_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size)
4336 +#define catc_read_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_IN, ReadMem, 0, addr, buf, size)
4337 +
4338 +#define f5u011_rxmode(catc, rxmode) catc_ctrl_msg(catc, USB_DIR_OUT, SetRxMode, 0, 1, rxmode, 2)
4339 +#define f5u011_rxmode_async(catc, rxmode) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 1, &rxmode, 2, NULL)
4340 +#define f5u011_mchash_async(catc, hash) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 2, &hash, 8, NULL)
4341 +
4342 +#define catc_set_reg_async(catc, reg, val) catc_ctrl_async(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0, NULL)
4343 +#define catc_get_reg_async(catc, reg, cb) catc_ctrl_async(catc, USB_DIR_IN, GetReg, 0, reg, NULL, 1, cb)
4344 +#define catc_write_mem_async(catc, addr, buf, size) catc_ctrl_async(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size, NULL)
4345 +
4346 +/*
4347 + * Receive routines.
4348 + */
4349 +
4350 +static void catc_rx_done(struct urb *urb)
4351 +{
4352 + struct catc *catc = urb->context;
4353 + u8 *pkt_start = urb->transfer_buffer;
4354 + struct sk_buff *skb;
4355 + int pkt_len, pkt_offset = 0;
4356 + int status = urb->status;
4357 +
4358 + if (!catc->is_f5u011) {
4359 + clear_bit(RX_RUNNING, &catc->flags);
4360 + pkt_offset = 2;
4361 + }
4362 +
4363 + if (status) {
4364 + dev_dbg(&urb->dev->dev, "rx_done, status %d, length %d\n",
4365 + status, urb->actual_length);
4366 + return;
4367 + }
4368 +
4369 + do {
4370 + if(!catc->is_f5u011) {
4371 + pkt_len = le16_to_cpup((__le16*)pkt_start);
4372 + if (pkt_len > urb->actual_length) {
4373 + catc->netdev->stats.rx_length_errors++;
4374 + catc->netdev->stats.rx_errors++;
4375 + break;
4376 + }
4377 + } else {
4378 + pkt_len = urb->actual_length;
4379 + }
4380 +
4381 + if (!(skb = dev_alloc_skb(pkt_len)))
4382 + return;
4383 +
4384 + skb_copy_to_linear_data(skb, pkt_start + pkt_offset, pkt_len);
4385 + skb_put(skb, pkt_len);
4386 +
4387 + skb->protocol = eth_type_trans(skb, catc->netdev);
4388 + netif_rx(skb);
4389 +
4390 + catc->netdev->stats.rx_packets++;
4391 + catc->netdev->stats.rx_bytes += pkt_len;
4392 +
4393 + /* F5U011 only does one packet per RX */
4394 + if (catc->is_f5u011)
4395 + break;
4396 + pkt_start += (((pkt_len + 1) >> 6) + 1) << 6;
4397 +
4398 + } while (pkt_start - (u8 *) urb->transfer_buffer < urb->actual_length);
4399 +
4400 + if (catc->is_f5u011) {
4401 + if (atomic_read(&catc->recq_sz)) {
4402 + int state;
4403 + atomic_dec(&catc->recq_sz);
4404 + netdev_dbg(catc->netdev, "getting extra packet\n");
4405 + urb->dev = catc->usbdev;
4406 + if ((state = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
4407 + netdev_dbg(catc->netdev,
4408 + "submit(rx_urb) status %d\n", state);
4409 + }
4410 + } else {
4411 + clear_bit(RX_RUNNING, &catc->flags);
4412 + }
4413 + }
4414 +}
4415 +
4416 +static void catc_irq_done(struct urb *urb)
4417 +{
4418 + struct catc *catc = urb->context;
4419 + u8 *data = urb->transfer_buffer;
4420 + int status = urb->status;
4421 + unsigned int hasdata = 0, linksts = LinkNoChange;
4422 + int res;
4423 +
4424 + if (!catc->is_f5u011) {
4425 + hasdata = data[1] & 0x80;
4426 + if (data[1] & 0x40)
4427 + linksts = LinkGood;
4428 + else if (data[1] & 0x20)
4429 + linksts = LinkBad;
4430 + } else {
4431 + hasdata = (unsigned int)(be16_to_cpup((__be16*)data) & 0x0fff);
4432 + if (data[0] == 0x90)
4433 + linksts = LinkGood;
4434 + else if (data[0] == 0xA0)
4435 + linksts = LinkBad;
4436 + }
4437 +
4438 + switch (status) {
4439 + case 0: /* success */
4440 + break;
4441 + case -ECONNRESET: /* unlink */
4442 + case -ENOENT:
4443 + case -ESHUTDOWN:
4444 + return;
4445 + /* -EPIPE: should clear the halt */
4446 + default: /* error */
4447 + dev_dbg(&urb->dev->dev,
4448 + "irq_done, status %d, data %02x %02x.\n",
4449 + status, data[0], data[1]);
4450 + goto resubmit;
4451 + }
4452 +
4453 + if (linksts == LinkGood) {
4454 + netif_carrier_on(catc->netdev);
4455 + netdev_dbg(catc->netdev, "link ok\n");
4456 + }
4457 +
4458 + if (linksts == LinkBad) {
4459 + netif_carrier_off(catc->netdev);
4460 + netdev_dbg(catc->netdev, "link bad\n");
4461 + }
4462 +
4463 + if (hasdata) {
4464 + if (test_and_set_bit(RX_RUNNING, &catc->flags)) {
4465 + if (catc->is_f5u011)
4466 + atomic_inc(&catc->recq_sz);
4467 + } else {
4468 + catc->rx_urb->dev = catc->usbdev;
4469 + if ((res = usb_submit_urb(catc->rx_urb, GFP_ATOMIC)) < 0) {
4470 + dev_err(&catc->usbdev->dev,
4471 + "submit(rx_urb) status %d\n", res);
4472 + }
4473 + }
4474 + }
4475 +resubmit:
4476 + res = usb_submit_urb (urb, GFP_ATOMIC);
4477 + if (res)
4478 + dev_err(&catc->usbdev->dev,
4479 + "can't resubmit intr, %s-%s, status %d\n",
4480 + catc->usbdev->bus->bus_name,
4481 + catc->usbdev->devpath, res);
4482 +}
4483 +
4484 +/*
4485 + * Transmit routines.
4486 + */
4487 +
4488 +static int catc_tx_run(struct catc *catc)
4489 +{
4490 + int status;
4491 +
4492 + if (catc->is_f5u011)
4493 + catc->tx_ptr = (catc->tx_ptr + 63) & ~63;
4494 +
4495 + catc->tx_urb->transfer_buffer_length = catc->tx_ptr;
4496 + catc->tx_urb->transfer_buffer = catc->tx_buf[catc->tx_idx];
4497 + catc->tx_urb->dev = catc->usbdev;
4498 +
4499 + if ((status = usb_submit_urb(catc->tx_urb, GFP_ATOMIC)) < 0)
4500 + dev_err(&catc->usbdev->dev, "submit(tx_urb), status %d\n",
4501 + status);
4502 +
4503 + catc->tx_idx = !catc->tx_idx;
4504 + catc->tx_ptr = 0;
4505 +
4506 + catc->netdev->trans_start = jiffies;
4507 + return status;
4508 +}
4509 +
4510 +static void catc_tx_done(struct urb *urb)
4511 +{
4512 + struct catc *catc = urb->context;
4513 + unsigned long flags;
4514 + int r, status = urb->status;
4515 +
4516 + if (status == -ECONNRESET) {
4517 + dev_dbg(&urb->dev->dev, "Tx Reset.\n");
4518 + urb->status = 0;
4519 + catc->netdev->trans_start = jiffies;
4520 + catc->netdev->stats.tx_errors++;
4521 + clear_bit(TX_RUNNING, &catc->flags);
4522 + netif_wake_queue(catc->netdev);
4523 + return;
4524 + }
4525 +
4526 + if (status) {
4527 + dev_dbg(&urb->dev->dev, "tx_done, status %d, length %d\n",
4528 + status, urb->actual_length);
4529 + return;
4530 + }
4531 +
4532 + spin_lock_irqsave(&catc->tx_lock, flags);
4533 +
4534 + if (catc->tx_ptr) {
4535 + r = catc_tx_run(catc);
4536 + if (unlikely(r < 0))
4537 + clear_bit(TX_RUNNING, &catc->flags);
4538 + } else {
4539 + clear_bit(TX_RUNNING, &catc->flags);
4540 + }
4541 +
4542 + netif_wake_queue(catc->netdev);
4543 +
4544 + spin_unlock_irqrestore(&catc->tx_lock, flags);
4545 +}
4546 +
4547 +static netdev_tx_t catc_start_xmit(struct sk_buff *skb,
4548 + struct net_device *netdev)
4549 +{
4550 + struct catc *catc = netdev_priv(netdev);
4551 + unsigned long flags;
4552 + int r = 0;
4553 + char *tx_buf;
4554 +
4555 + spin_lock_irqsave(&catc->tx_lock, flags);
4556 +
4557 + catc->tx_ptr = (((catc->tx_ptr - 1) >> 6) + 1) << 6;
4558 + tx_buf = catc->tx_buf[catc->tx_idx] + catc->tx_ptr;
4559 + if (catc->is_f5u011)
4560 + *(__be16 *)tx_buf = cpu_to_be16(skb->len);
4561 + else
4562 + *(__le16 *)tx_buf = cpu_to_le16(skb->len);
4563 + skb_copy_from_linear_data(skb, tx_buf + 2, skb->len);
4564 + catc->tx_ptr += skb->len + 2;
4565 +
4566 + if (!test_and_set_bit(TX_RUNNING, &catc->flags)) {
4567 + r = catc_tx_run(catc);
4568 + if (r < 0)
4569 + clear_bit(TX_RUNNING, &catc->flags);
4570 + }
4571 +
4572 + if ((catc->is_f5u011 && catc->tx_ptr) ||
4573 + (catc->tx_ptr >= ((TX_MAX_BURST - 1) * (PKT_SZ + 2))))
4574 + netif_stop_queue(netdev);
4575 +
4576 + spin_unlock_irqrestore(&catc->tx_lock, flags);
4577 +
4578 + if (r >= 0) {
4579 + catc->netdev->stats.tx_bytes += skb->len;
4580 + catc->netdev->stats.tx_packets++;
4581 + }
4582 +
4583 + dev_kfree_skb(skb);
4584 +
4585 + return NETDEV_TX_OK;
4586 +}
4587 +
4588 +static void catc_tx_timeout(struct net_device *netdev)
4589 +{
4590 + struct catc *catc = netdev_priv(netdev);
4591 +
4592 + dev_warn(&netdev->dev, "Transmit timed out.\n");
4593 + usb_unlink_urb(catc->tx_urb);
4594 +}
4595 +
4596 +/*
4597 + * Control messages.
4598 + */
4599 +
4600 +static int catc_ctrl_msg(struct catc *catc, u8 dir, u8 request, u16 value, u16 index, void *buf, int len)
4601 +{
4602 + int retval = usb_control_msg(catc->usbdev,
4603 + dir ? usb_rcvctrlpipe(catc->usbdev, 0) : usb_sndctrlpipe(catc->usbdev, 0),
4604 + request, 0x40 | dir, value, index, buf, len, 1000);
4605 + return retval < 0 ? retval : 0;
4606 +}
4607 +
4608 +static void catc_ctrl_run(struct catc *catc)
4609 +{
4610 + struct ctrl_queue *q = catc->ctrl_queue + catc->ctrl_tail;
4611 + struct usb_device *usbdev = catc->usbdev;
4612 + struct urb *urb = catc->ctrl_urb;
4613 + struct usb_ctrlrequest *dr = &catc->ctrl_dr;
4614 + int status;
4615 +
4616 + dr->bRequest = q->request;
4617 + dr->bRequestType = 0x40 | q->dir;
4618 + dr->wValue = cpu_to_le16(q->value);
4619 + dr->wIndex = cpu_to_le16(q->index);
4620 + dr->wLength = cpu_to_le16(q->len);
4621 +
4622 + urb->pipe = q->dir ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0);
4623 + urb->transfer_buffer_length = q->len;
4624 + urb->transfer_buffer = catc->ctrl_buf;
4625 + urb->setup_packet = (void *) dr;
4626 + urb->dev = usbdev;
4627 +
4628 + if (!q->dir && q->buf && q->len)
4629 + memcpy(catc->ctrl_buf, q->buf, q->len);
4630 +
4631 + if ((status = usb_submit_urb(catc->ctrl_urb, GFP_ATOMIC)))
4632 + dev_err(&catc->usbdev->dev, "submit(ctrl_urb) status %d\n",
4633 + status);
4634 +}
4635 +
4636 +static void catc_ctrl_done(struct urb *urb)
4637 +{
4638 + struct catc *catc = urb->context;
4639 + struct ctrl_queue *q;
4640 + unsigned long flags;
4641 + int status = urb->status;
4642 +
4643 + if (status)
4644 + dev_dbg(&urb->dev->dev, "ctrl_done, status %d, len %d.\n",
4645 + status, urb->actual_length);
4646 +
4647 + spin_lock_irqsave(&catc->ctrl_lock, flags);
4648 +
4649 + q = catc->ctrl_queue + catc->ctrl_tail;
4650 +
4651 + if (q->dir) {
4652 + if (q->buf && q->len)
4653 + memcpy(q->buf, catc->ctrl_buf, q->len);
4654 + else
4655 + q->buf = catc->ctrl_buf;
4656 + }
4657 +
4658 + if (q->callback)
4659 + q->callback(catc, q);
4660 +
4661 + catc->ctrl_tail = (catc->ctrl_tail + 1) & (CTRL_QUEUE - 1);
4662 +
4663 + if (catc->ctrl_head != catc->ctrl_tail)
4664 + catc_ctrl_run(catc);
4665 + else
4666 + clear_bit(CTRL_RUNNING, &catc->flags);
4667 +
4668 + spin_unlock_irqrestore(&catc->ctrl_lock, flags);
4669 +}
4670 +
4671 +static int catc_ctrl_async(struct catc *catc, u8 dir, u8 request, u16 value,
4672 + u16 index, void *buf, int len, void (*callback)(struct catc *catc, struct ctrl_queue *q))
4673 +{
4674 + struct ctrl_queue *q;
4675 + int retval = 0;
4676 + unsigned long flags;
4677 +
4678 + spin_lock_irqsave(&catc->ctrl_lock, flags);
4679 +
4680 + q = catc->ctrl_queue + catc->ctrl_head;
4681 +
4682 + q->dir = dir;
4683 + q->request = request;
4684 + q->value = value;
4685 + q->index = index;
4686 + q->buf = buf;
4687 + q->len = len;
4688 + q->callback = callback;
4689 +
4690 + catc->ctrl_head = (catc->ctrl_head + 1) & (CTRL_QUEUE - 1);
4691 +
4692 + if (catc->ctrl_head == catc->ctrl_tail) {
4693 + dev_err(&catc->usbdev->dev, "ctrl queue full\n");
4694 + catc->ctrl_tail = (catc->ctrl_tail + 1) & (CTRL_QUEUE - 1);
4695 + retval = -1;
4696 + }
4697 +
4698 + if (!test_and_set_bit(CTRL_RUNNING, &catc->flags))
4699 + catc_ctrl_run(catc);
4700 +
4701 + spin_unlock_irqrestore(&catc->ctrl_lock, flags);
4702 +
4703 + return retval;
4704 +}
4705 +
4706 +/*
4707 + * Statistics.
4708 + */
4709 +
4710 +static void catc_stats_done(struct catc *catc, struct ctrl_queue *q)
4711 +{
4712 + int index = q->index - EthStats;
4713 + u16 data, last;
4714 +
4715 + catc->stats_buf[index] = *((char *)q->buf);
4716 +
4717 + if (index & 1)
4718 + return;
4719 +
4720 + data = ((u16)catc->stats_buf[index] << 8) | catc->stats_buf[index + 1];
4721 + last = catc->stats_vals[index >> 1];
4722 +
4723 + switch (index) {
4724 + case TxSingleColl:
4725 + case TxMultiColl:
4726 + catc->netdev->stats.collisions += data - last;
4727 + break;
4728 + case TxExcessColl:
4729 + catc->netdev->stats.tx_aborted_errors += data - last;
4730 + catc->netdev->stats.tx_errors += data - last;
4731 + break;
4732 + case RxFramErr:
4733 + catc->netdev->stats.rx_frame_errors += data - last;
4734 + catc->netdev->stats.rx_errors += data - last;
4735 + break;
4736 + }
4737 +
4738 + catc->stats_vals[index >> 1] = data;
4739 +}
4740 +
4741 +static void catc_stats_timer(unsigned long data)
4742 +{
4743 + struct catc *catc = (void *) data;
4744 + int i;
4745 +
4746 + for (i = 0; i < 8; i++)
4747 + catc_get_reg_async(catc, EthStats + 7 - i, catc_stats_done);
4748 +
4749 + mod_timer(&catc->timer, jiffies + STATS_UPDATE);
4750 +}
4751 +
4752 +/*
4753 + * Receive modes. Broadcast, Multicast, Promisc.
4754 + */
4755 +
4756 +static void catc_multicast(unsigned char *addr, u8 *multicast)
4757 +{
4758 + u32 crc;
4759 +
4760 + crc = ether_crc_le(6, addr);
4761 + multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
4762 +}
4763 +
4764 +static void catc_set_multicast_list(struct net_device *netdev)
4765 +{
4766 + struct catc *catc = netdev_priv(netdev);
4767 + struct netdev_hw_addr *ha;
4768 + u8 broadcast[ETH_ALEN];
4769 + u8 rx = RxEnable | RxPolarity | RxMultiCast;
4770 +
4771 + eth_broadcast_addr(broadcast);
4772 + memset(catc->multicast, 0, 64);
4773 +
4774 + catc_multicast(broadcast, catc->multicast);
4775 + catc_multicast(netdev->dev_addr, catc->multicast);
4776 +
4777 + if (netdev->flags & IFF_PROMISC) {
4778 + memset(catc->multicast, 0xff, 64);
4779 + rx |= (!catc->is_f5u011) ? RxPromisc : AltRxPromisc;
4780 + }
4781 +
4782 + if (netdev->flags & IFF_ALLMULTI) {
4783 + memset(catc->multicast, 0xff, 64);
4784 + } else {
4785 + netdev_for_each_mc_addr(ha, netdev) {
4786 + u32 crc = ether_crc_le(6, ha->addr);
4787 + if (!catc->is_f5u011) {
4788 + catc->multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
4789 + } else {
4790 + catc->multicast[7-(crc >> 29)] |= 1 << ((crc >> 26) & 7);
4791 + }
4792 + }
4793 + }
4794 + if (!catc->is_f5u011) {
4795 + catc_set_reg_async(catc, RxUnit, rx);
4796 + catc_write_mem_async(catc, 0xfa80, catc->multicast, 64);
4797 + } else {
4798 + f5u011_mchash_async(catc, catc->multicast);
4799 + if (catc->rxmode[0] != rx) {
4800 + catc->rxmode[0] = rx;
4801 + netdev_dbg(catc->netdev,
4802 + "Setting RX mode to %2.2X %2.2X\n",
4803 + catc->rxmode[0], catc->rxmode[1]);
4804 + f5u011_rxmode_async(catc, catc->rxmode);
4805 + }
4806 + }
4807 +}
4808 +
4809 +static void catc_get_drvinfo(struct net_device *dev,
4810 + struct ethtool_drvinfo *info)
4811 +{
4812 + struct catc *catc = netdev_priv(dev);
4813 + strlcpy(info->driver, driver_name, sizeof(info->driver));
4814 + strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
4815 + usb_make_path(catc->usbdev, info->bus_info, sizeof(info->bus_info));
4816 +}
4817 +
4818 +static int catc_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
4819 +{
4820 + struct catc *catc = netdev_priv(dev);
4821 + if (!catc->is_f5u011)
4822 + return -EOPNOTSUPP;
4823 +
4824 + cmd->supported = SUPPORTED_10baseT_Half | SUPPORTED_TP;
4825 + cmd->advertising = ADVERTISED_10baseT_Half | ADVERTISED_TP;
4826 + ethtool_cmd_speed_set(cmd, SPEED_10);
4827 + cmd->duplex = DUPLEX_HALF;
4828 + cmd->port = PORT_TP;
4829 + cmd->phy_address = 0;
4830 + cmd->transceiver = XCVR_INTERNAL;
4831 + cmd->autoneg = AUTONEG_DISABLE;
4832 + cmd->maxtxpkt = 1;
4833 + cmd->maxrxpkt = 1;
4834 + return 0;
4835 +}
4836 +
4837 +static const struct ethtool_ops ops = {
4838 + .get_drvinfo = catc_get_drvinfo,
4839 + .get_settings = catc_get_settings,
4840 + .get_link = ethtool_op_get_link
4841 +};
4842 +
4843 +/*
4844 + * Open, close.
4845 + */
4846 +
4847 +static int catc_open(struct net_device *netdev)
4848 +{
4849 + struct catc *catc = netdev_priv(netdev);
4850 + int status;
4851 +
4852 + catc->irq_urb->dev = catc->usbdev;
4853 + if ((status = usb_submit_urb(catc->irq_urb, GFP_KERNEL)) < 0) {
4854 + dev_err(&catc->usbdev->dev, "submit(irq_urb) status %d\n",
4855 + status);
4856 + return -1;
4857 + }
4858 +
4859 + netif_start_queue(netdev);
4860 +
4861 + if (!catc->is_f5u011)
4862 + mod_timer(&catc->timer, jiffies + STATS_UPDATE);
4863 +
4864 + return 0;
4865 +}
4866 +
4867 +static int catc_stop(struct net_device *netdev)
4868 +{
4869 + struct catc *catc = netdev_priv(netdev);
4870 +
4871 + netif_stop_queue(netdev);
4872 +
4873 + if (!catc->is_f5u011)
4874 + del_timer_sync(&catc->timer);
4875 +
4876 + usb_kill_urb(catc->rx_urb);
4877 + usb_kill_urb(catc->tx_urb);
4878 + usb_kill_urb(catc->irq_urb);
4879 + usb_kill_urb(catc->ctrl_urb);
4880 +
4881 + return 0;
4882 +}
4883 +
4884 +static const struct net_device_ops catc_netdev_ops = {
4885 + .ndo_open = catc_open,
4886 + .ndo_stop = catc_stop,
4887 + .ndo_start_xmit = catc_start_xmit,
4888 +
4889 + .ndo_tx_timeout = catc_tx_timeout,
4890 + .ndo_set_rx_mode = catc_set_multicast_list,
4891 + .ndo_change_mtu = eth_change_mtu,
4892 + .ndo_set_mac_address = eth_mac_addr,
4893 + .ndo_validate_addr = eth_validate_addr,
4894 +};
4895 +
4896 +/*
4897 + * USB probe, disconnect.
4898 + */
4899 +
4900 +static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id)
4901 +{
4902 + struct device *dev = &intf->dev;
4903 + struct usb_device *usbdev = interface_to_usbdev(intf);
4904 + struct net_device *netdev;
4905 + struct catc *catc;
4906 + u8 broadcast[ETH_ALEN];
4907 + int i, pktsz;
4908 +
4909 + if (usb_set_interface(usbdev,
4910 + intf->altsetting->desc.bInterfaceNumber, 1)) {
4911 + dev_err(dev, "Can't set altsetting 1.\n");
4912 + return -EIO;
4913 + }
4914 +
4915 + netdev = alloc_etherdev(sizeof(struct catc));
4916 + if (!netdev)
4917 + return -ENOMEM;
4918 +
4919 + catc = netdev_priv(netdev);
4920 +
4921 + netdev->netdev_ops = &catc_netdev_ops;
4922 + netdev->watchdog_timeo = TX_TIMEOUT;
4923 + netdev->ethtool_ops = &ops;
4924 +
4925 + catc->usbdev = usbdev;
4926 + catc->netdev = netdev;
4927 +
4928 + spin_lock_init(&catc->tx_lock);
4929 + spin_lock_init(&catc->ctrl_lock);
4930 +
4931 + init_timer(&catc->timer);
4932 + catc->timer.data = (long) catc;
4933 + catc->timer.function = catc_stats_timer;
4934 +
4935 + catc->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
4936 + catc->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
4937 + catc->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
4938 + catc->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
4939 + if ((!catc->ctrl_urb) || (!catc->tx_urb) ||
4940 + (!catc->rx_urb) || (!catc->irq_urb)) {
4941 + dev_err(&intf->dev, "No free urbs available.\n");
4942 + usb_free_urb(catc->ctrl_urb);
4943 + usb_free_urb(catc->tx_urb);
4944 + usb_free_urb(catc->rx_urb);
4945 + usb_free_urb(catc->irq_urb);
4946 + free_netdev(netdev);
4947 + return -ENOMEM;
4948 + }
4949 +
4950 + /* The F5U011 has the same vendor/product as the netmate but a device version of 0x130 */
4951 + if (le16_to_cpu(usbdev->descriptor.idVendor) == 0x0423 &&
4952 + le16_to_cpu(usbdev->descriptor.idProduct) == 0xa &&
4953 + le16_to_cpu(catc->usbdev->descriptor.bcdDevice) == 0x0130) {
4954 + dev_dbg(dev, "Testing for f5u011\n");
4955 + catc->is_f5u011 = 1;
4956 + atomic_set(&catc->recq_sz, 0);
4957 + pktsz = RX_PKT_SZ;
4958 + } else {
4959 + pktsz = RX_MAX_BURST * (PKT_SZ + 2);
4960 + }
4961 +
4962 + usb_fill_control_urb(catc->ctrl_urb, usbdev, usb_sndctrlpipe(usbdev, 0),
4963 + NULL, NULL, 0, catc_ctrl_done, catc);
4964 +
4965 + usb_fill_bulk_urb(catc->tx_urb, usbdev, usb_sndbulkpipe(usbdev, 1),
4966 + NULL, 0, catc_tx_done, catc);
4967 +
4968 + usb_fill_bulk_urb(catc->rx_urb, usbdev, usb_rcvbulkpipe(usbdev, 1),
4969 + catc->rx_buf, pktsz, catc_rx_done, catc);
4970 +
4971 + usb_fill_int_urb(catc->irq_urb, usbdev, usb_rcvintpipe(usbdev, 2),
4972 + catc->irq_buf, 2, catc_irq_done, catc, 1);
4973 +
4974 + if (!catc->is_f5u011) {
4975 + dev_dbg(dev, "Checking memory size\n");
4976 +
4977 + i = 0x12345678;
4978 + catc_write_mem(catc, 0x7a80, &i, 4);
4979 + i = 0x87654321;
4980 + catc_write_mem(catc, 0xfa80, &i, 4);
4981 + catc_read_mem(catc, 0x7a80, &i, 4);
4982 +
4983 + switch (i) {
4984 + case 0x12345678:
4985 + catc_set_reg(catc, TxBufCount, 8);
4986 + catc_set_reg(catc, RxBufCount, 32);
4987 + dev_dbg(dev, "64k Memory\n");
4988 + break;
4989 + default:
4990 + dev_warn(&intf->dev,
4991 + "Couldn't detect memory size, assuming 32k\n");
4992 + case 0x87654321:
4993 + catc_set_reg(catc, TxBufCount, 4);
4994 + catc_set_reg(catc, RxBufCount, 16);
4995 + dev_dbg(dev, "32k Memory\n");
4996 + break;
4997 + }
4998 +
4999 + dev_dbg(dev, "Getting MAC from SEEROM.\n");
5000 +
5001 + catc_get_mac(catc, netdev->dev_addr);
5002 +
5003 + dev_dbg(dev, "Setting MAC into registers.\n");
5004 +
5005 + for (i = 0; i < 6; i++)
5006 + catc_set_reg(catc, StationAddr0 - i, netdev->dev_addr[i]);
5007 +
5008 + dev_dbg(dev, "Filling the multicast list.\n");
5009 +
5010 + eth_broadcast_addr(broadcast);
5011 + catc_multicast(broadcast, catc->multicast);
5012 + catc_multicast(netdev->dev_addr, catc->multicast);
5013 + catc_write_mem(catc, 0xfa80, catc->multicast, 64);
5014 +
5015 + dev_dbg(dev, "Clearing error counters.\n");
5016 +
5017 + for (i = 0; i < 8; i++)
5018 + catc_set_reg(catc, EthStats + i, 0);
5019 + catc->last_stats = jiffies;
5020 +
5021 + dev_dbg(dev, "Enabling.\n");
5022 +
5023 + catc_set_reg(catc, MaxBurst, RX_MAX_BURST);
5024 + catc_set_reg(catc, OpModes, OpTxMerge | OpRxMerge | OpLenInclude | Op3MemWaits);
5025 + catc_set_reg(catc, LEDCtrl, LEDLink);
5026 + catc_set_reg(catc, RxUnit, RxEnable | RxPolarity | RxMultiCast);
5027 + } else {
5028 + dev_dbg(dev, "Performing reset\n");
5029 + catc_reset(catc);
5030 + catc_get_mac(catc, netdev->dev_addr);
5031 +
5032 + dev_dbg(dev, "Setting RX Mode\n");
5033 + catc->rxmode[0] = RxEnable | RxPolarity | RxMultiCast;
5034 + catc->rxmode[1] = 0;
5035 + f5u011_rxmode(catc, catc->rxmode);
5036 + }
5037 + dev_dbg(dev, "Init done.\n");
5038 + printk(KERN_INFO "%s: %s USB Ethernet at usb-%s-%s, %pM.\n",
5039 + netdev->name, (catc->is_f5u011) ? "Belkin F5U011" : "CATC EL1210A NetMate",
5040 + usbdev->bus->bus_name, usbdev->devpath, netdev->dev_addr);
5041 + usb_set_intfdata(intf, catc);
5042 +
5043 + SET_NETDEV_DEV(netdev, &intf->dev);
5044 + if (register_netdev(netdev) != 0) {
5045 + usb_set_intfdata(intf, NULL);
5046 + usb_free_urb(catc->ctrl_urb);
5047 + usb_free_urb(catc->tx_urb);
5048 + usb_free_urb(catc->rx_urb);
5049 + usb_free_urb(catc->irq_urb);
5050 + free_netdev(netdev);
5051 + return -EIO;
5052 + }
5053 + return 0;
5054 +}
5055 +
5056 +static void catc_disconnect(struct usb_interface *intf)
5057 +{
5058 + struct catc *catc = usb_get_intfdata(intf);
5059 +
5060 + usb_set_intfdata(intf, NULL);
5061 + if (catc) {
5062 + unregister_netdev(catc->netdev);
5063 + usb_free_urb(catc->ctrl_urb);
5064 + usb_free_urb(catc->tx_urb);
5065 + usb_free_urb(catc->rx_urb);
5066 + usb_free_urb(catc->irq_urb);
5067 + free_netdev(catc->netdev);
5068 + }
5069 +}
5070 +
5071 +/*
5072 + * Module functions and tables.
5073 + */
5074 +
5075 +static struct usb_device_id catc_id_table [] = {
5076 + { USB_DEVICE(0x0423, 0xa) }, /* CATC Netmate, Belkin F5U011 */
5077 + { USB_DEVICE(0x0423, 0xc) }, /* CATC Netmate II, Belkin F5U111 */
5078 + { USB_DEVICE(0x08d1, 0x1) }, /* smartBridges smartNIC */
5079 + { }
5080 +};
5081 +
5082 +MODULE_DEVICE_TABLE(usb, catc_id_table);
5083 +
5084 +static struct usb_driver catc_driver = {
5085 + .name = driver_name,
5086 + .probe = catc_probe,
5087 + .disconnect = catc_disconnect,
5088 + .id_table = catc_id_table,
5089 + .disable_hub_initiated_lpm = 1,
5090 +};
5091 +
5092 +module_usb_driver(catc_driver);
5093 diff -Naur backports-4.2.6-1.org/drivers/net/usb/cdc_eem.c backports-4.2.6-1/drivers/net/usb/cdc_eem.c
5094 --- backports-4.2.6-1.org/drivers/net/usb/cdc_eem.c 1970-01-01 01:00:00.000000000 +0100
5095 +++ backports-4.2.6-1/drivers/net/usb/cdc_eem.c 2016-06-28 14:35:17.975307221 +0200
5096 @@ -0,0 +1,381 @@
5097 +/*
5098 + * USB CDC EEM network interface driver
5099 + * Copyright (C) 2009 Oberthur Technologies
5100 + * by Omar Laazimani, Olivier Condemine
5101 + *
5102 + * This program is free software; you can redistribute it and/or modify
5103 + * it under the terms of the GNU General Public License as published by
5104 + * the Free Software Foundation; either version 2 of the License, or
5105 + * (at your option) any later version.
5106 + *
5107 + * This program is distributed in the hope that it will be useful,
5108 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5109 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5110 + * GNU General Public License for more details.
5111 + *
5112 + * You should have received a copy of the GNU General Public License
5113 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
5114 + */
5115 +
5116 +#include <linux/module.h>
5117 +#include <linux/netdevice.h>
5118 +#include <linux/etherdevice.h>
5119 +#include <linux/ctype.h>
5120 +#include <linux/ethtool.h>
5121 +#include <linux/workqueue.h>
5122 +#include <linux/mii.h>
5123 +#include <linux/usb.h>
5124 +#include <linux/crc32.h>
5125 +#include <linux/usb/cdc.h>
5126 +#include <linux/usb/usbnet.h>
5127 +#include <linux/gfp.h>
5128 +#include <linux/if_vlan.h>
5129 +
5130 +
5131 +/*
5132 + * This driver is an implementation of the CDC "Ethernet Emulation
5133 + * Model" (EEM) specification, which encapsulates Ethernet frames
5134 + * for transport over USB using a simpler USB device model than the
5135 + * previous CDC "Ethernet Control Model" (ECM, or "CDC Ethernet").
5136 + *
5137 + * For details, see www.usb.org/developers/devclass_docs/CDC_EEM10.pdf
5138 + *
5139 + * This version has been tested with GIGAntIC WuaoW SIM Smart Card on 2.6.24,
5140 + * 2.6.27 and 2.6.30rc2 kernel.
5141 + * It has also been validated on Openmoko Om 2008.12 (based on 2.6.24 kernel).
5142 + * build on 23-April-2009
5143 + */
5144 +
5145 +#define EEM_HEAD 2 /* 2 byte header */
5146 +
5147 +/*-------------------------------------------------------------------------*/
5148 +
5149 +static void eem_linkcmd_complete(struct urb *urb)
5150 +{
5151 + dev_kfree_skb(urb->context);
5152 + usb_free_urb(urb);
5153 +}
5154 +
5155 +static void eem_linkcmd(struct usbnet *dev, struct sk_buff *skb)
5156 +{
5157 + struct urb *urb;
5158 + int status;
5159 +
5160 + urb = usb_alloc_urb(0, GFP_ATOMIC);
5161 + if (!urb)
5162 + goto fail;
5163 +
5164 + usb_fill_bulk_urb(urb, dev->udev, dev->out,
5165 + skb->data, skb->len, eem_linkcmd_complete, skb);
5166 +
5167 + status = usb_submit_urb(urb, GFP_ATOMIC);
5168 + if (status) {
5169 + usb_free_urb(urb);
5170 +fail:
5171 + dev_kfree_skb(skb);
5172 + netdev_warn(dev->net, "link cmd failure\n");
5173 + return;
5174 + }
5175 +}
5176 +
5177 +static int eem_bind(struct usbnet *dev, struct usb_interface *intf)
5178 +{
5179 + int status = 0;
5180 +
5181 + status = usbnet_get_endpoints(dev, intf);
5182 + if (status < 0) {
5183 + usb_set_intfdata(intf, NULL);
5184 + usb_driver_release_interface(driver_of(intf), intf);
5185 + return status;
5186 + }
5187 +
5188 + /* no jumbogram (16K) support for now */
5189 +
5190 + dev->net->hard_header_len += EEM_HEAD + ETH_FCS_LEN + VLAN_HLEN;
5191 + dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
5192 +
5193 + return 0;
5194 +}
5195 +
5196 +/*
5197 + * EEM permits packing multiple Ethernet frames into USB transfers
5198 + * (a "bundle"), but for TX we don't try to do that.
5199 + */
5200 +static struct sk_buff *eem_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
5201 + gfp_t flags)
5202 +{
5203 + struct sk_buff *skb2 = NULL;
5204 + u16 len = skb->len;
5205 + u32 crc = 0;
5206 + int padlen = 0;
5207 +
5208 + /* When ((len + EEM_HEAD + ETH_FCS_LEN) % dev->maxpacket) is
5209 + * zero, stick two bytes of zero length EEM packet on the end.
5210 + * Else the framework would add invalid single byte padding,
5211 + * since it can't know whether ZLPs will be handled right by
5212 + * all the relevant hardware and software.
5213 + */
5214 + if (!((len + EEM_HEAD + ETH_FCS_LEN) % dev->maxpacket))
5215 + padlen += 2;
5216 +
5217 + if (!skb_cloned(skb)) {
5218 + int headroom = skb_headroom(skb);
5219 + int tailroom = skb_tailroom(skb);
5220 +
5221 + if ((tailroom >= ETH_FCS_LEN + padlen) &&
5222 + (headroom >= EEM_HEAD))
5223 + goto done;
5224 +
5225 + if ((headroom + tailroom)
5226 + > (EEM_HEAD + ETH_FCS_LEN + padlen)) {
5227 + skb->data = memmove(skb->head +
5228 + EEM_HEAD,
5229 + skb->data,
5230 + skb->len);
5231 + skb_set_tail_pointer(skb, len);
5232 + goto done;
5233 + }
5234 + }
5235 +
5236 + skb2 = skb_copy_expand(skb, EEM_HEAD, ETH_FCS_LEN + padlen, flags);
5237 + if (!skb2)
5238 + return NULL;
5239 +
5240 + dev_kfree_skb_any(skb);
5241 + skb = skb2;
5242 +
5243 +done:
5244 + /* we don't use the "no Ethernet CRC" option */
5245 + crc = crc32_le(~0, skb->data, skb->len);
5246 + crc = ~crc;
5247 +
5248 + put_unaligned_le32(crc, skb_put(skb, 4));
5249 +
5250 + /* EEM packet header format:
5251 + * b0..13: length of ethernet frame
5252 + * b14: bmCRC (1 == valid Ethernet CRC)
5253 + * b15: bmType (0 == data)
5254 + */
5255 + len = skb->len;
5256 + put_unaligned_le16(BIT(14) | len, skb_push(skb, 2));
5257 +
5258 + /* Bundle a zero length EEM packet if needed */
5259 + if (padlen)
5260 + put_unaligned_le16(0, skb_put(skb, 2));
5261 +
5262 + return skb;
5263 +}
5264 +
5265 +static int eem_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
5266 +{
5267 + /*
5268 + * Our task here is to strip off framing, leaving skb with one
5269 + * data frame for the usbnet framework code to process. But we
5270 + * may have received multiple EEM payloads, or command payloads.
5271 + * So we must process _everything_ as if it's a header, except
5272 + * maybe the last data payload
5273 + *
5274 + * REVISIT the framework needs updating so that when we consume
5275 + * all payloads (the last or only message was a command, or a
5276 + * zero length EEM packet) that is not accounted as an rx_error.
5277 + */
5278 + do {
5279 + struct sk_buff *skb2 = NULL;
5280 + u16 header;
5281 + u16 len = 0;
5282 +
5283 + /* incomplete EEM header? */
5284 + if (skb->len < EEM_HEAD)
5285 + return 0;
5286 +
5287 + /*
5288 + * EEM packet header format:
5289 + * b0..14: EEM type dependent (Data or Command)
5290 + * b15: bmType
5291 + */
5292 + header = get_unaligned_le16(skb->data);
5293 + skb_pull(skb, EEM_HEAD);
5294 +
5295 + /*
5296 + * The bmType bit helps to denote when EEM
5297 + * packet is data or command :
5298 + * bmType = 0 : EEM data payload
5299 + * bmType = 1 : EEM (link) command
5300 + */
5301 + if (header & BIT(15)) {
5302 + u16 bmEEMCmd;
5303 +
5304 + /*
5305 + * EEM (link) command packet:
5306 + * b0..10: bmEEMCmdParam
5307 + * b11..13: bmEEMCmd
5308 + * b14: bmReserved (must be 0)
5309 + * b15: 1 (EEM command)
5310 + */
5311 + if (header & BIT(14)) {
5312 + netdev_dbg(dev->net, "reserved command %04x\n",
5313 + header);
5314 + continue;
5315 + }
5316 +
5317 + bmEEMCmd = (header >> 11) & 0x7;
5318 + switch (bmEEMCmd) {
5319 +
5320 + /* Responding to echo requests is mandatory. */
5321 + case 0: /* Echo command */
5322 + len = header & 0x7FF;
5323 +
5324 + /* bogus command? */
5325 + if (skb->len < len)
5326 + return 0;
5327 +
5328 + skb2 = skb_clone(skb, GFP_ATOMIC);
5329 + if (unlikely(!skb2))
5330 + goto next;
5331 + skb_trim(skb2, len);
5332 + put_unaligned_le16(BIT(15) | (1 << 11) | len,
5333 + skb_push(skb2, 2));
5334 + eem_linkcmd(dev, skb2);
5335 + break;
5336 +
5337 + /*
5338 + * Host may choose to ignore hints.
5339 + * - suspend: peripheral ready to suspend
5340 + * - response: suggest N millisec polling
5341 + * - response complete: suggest N sec polling
5342 + *
5343 + * Suspend is reported and maybe heeded.
5344 + */
5345 + case 2: /* Suspend hint */
5346 + usbnet_device_suggests_idle(dev);
5347 + continue;
5348 + case 3: /* Response hint */
5349 + case 4: /* Response complete hint */
5350 + continue;
5351 +
5352 + /*
5353 + * Hosts should never receive host-to-peripheral
5354 + * or reserved command codes; or responses to an
5355 + * echo command we didn't send.
5356 + */
5357 + case 1: /* Echo response */
5358 + case 5: /* Tickle */
5359 + default: /* reserved */
5360 + netdev_warn(dev->net,
5361 + "unexpected link command %d\n",
5362 + bmEEMCmd);
5363 + continue;
5364 + }
5365 +
5366 + } else {
5367 + u32 crc, crc2;
5368 + int is_last;
5369 +
5370 + /* zero length EEM packet? */
5371 + if (header == 0)
5372 + continue;
5373 +
5374 + /*
5375 + * EEM data packet header :
5376 + * b0..13: length of ethernet frame
5377 + * b14: bmCRC
5378 + * b15: 0 (EEM data)
5379 + */
5380 + len = header & 0x3FFF;
5381 +
5382 + /* bogus EEM payload? */
5383 + if (skb->len < len)
5384 + return 0;
5385 +
5386 + /* bogus ethernet frame? */
5387 + if (len < (ETH_HLEN + ETH_FCS_LEN))
5388 + goto next;
5389 +
5390 + /*
5391 + * Treat the last payload differently: framework
5392 + * code expects our "fixup" to have stripped off
5393 + * headers, so "skb" is a data packet (or error).
5394 + * Else if it's not the last payload, keep "skb"
5395 + * for further processing.
5396 + */
5397 + is_last = (len == skb->len);
5398 + if (is_last)
5399 + skb2 = skb;
5400 + else {
5401 + skb2 = skb_clone(skb, GFP_ATOMIC);
5402 + if (unlikely(!skb2))
5403 + return 0;
5404 + }
5405 +
5406 + /*
5407 + * The bmCRC helps to denote when the CRC field in
5408 + * the Ethernet frame contains a calculated CRC:
5409 + * bmCRC = 1 : CRC is calculated
5410 + * bmCRC = 0 : CRC = 0xDEADBEEF
5411 + */
5412 + if (header & BIT(14)) {
5413 + crc = get_unaligned_le32(skb2->data
5414 + + len - ETH_FCS_LEN);
5415 + crc2 = ~crc32_le(~0, skb2->data, skb2->len
5416 + - ETH_FCS_LEN);
5417 + } else {
5418 + crc = get_unaligned_be32(skb2->data
5419 + + len - ETH_FCS_LEN);
5420 + crc2 = 0xdeadbeef;
5421 + }
5422 + skb_trim(skb2, len - ETH_FCS_LEN);
5423 +
5424 + if (is_last)
5425 + return crc == crc2;
5426 +
5427 + if (unlikely(crc != crc2)) {
5428 + dev->net->stats.rx_errors++;
5429 + dev_kfree_skb_any(skb2);
5430 + } else
5431 + usbnet_skb_return(dev, skb2);
5432 + }
5433 +
5434 +next:
5435 + skb_pull(skb, len);
5436 + } while (skb->len);
5437 +
5438 + return 1;
5439 +}
5440 +
5441 +static const struct driver_info eem_info = {
5442 + .description = "CDC EEM Device",
5443 + .flags = FLAG_ETHER | FLAG_POINTTOPOINT,
5444 + .bind = eem_bind,
5445 + .rx_fixup = eem_rx_fixup,
5446 + .tx_fixup = eem_tx_fixup,
5447 +};
5448 +
5449 +/*-------------------------------------------------------------------------*/
5450 +
5451 +static const struct usb_device_id products[] = {
5452 +{
5453 + USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_EEM,
5454 + USB_CDC_PROTO_EEM),
5455 + .driver_info = (unsigned long) &eem_info,
5456 +},
5457 +{
5458 + /* EMPTY == end of list */
5459 +},
5460 +};
5461 +MODULE_DEVICE_TABLE(usb, products);
5462 +
5463 +static struct usb_driver eem_driver = {
5464 + .name = "cdc_eem",
5465 + .id_table = products,
5466 + .probe = usbnet_probe,
5467 + .disconnect = usbnet_disconnect,
5468 + .suspend = usbnet_suspend,
5469 + .resume = usbnet_resume,
5470 + .disable_hub_initiated_lpm = 1,
5471 +};
5472 +
5473 +module_usb_driver(eem_driver);
5474 +
5475 +MODULE_AUTHOR("Omar Laazimani <omar.oberthur@gmail.com>");
5476 +MODULE_DESCRIPTION("USB CDC EEM");
5477 +MODULE_LICENSE("GPL");
5478 diff -Naur backports-4.2.6-1.org/drivers/net/usb/cdc-phonet.c backports-4.2.6-1/drivers/net/usb/cdc-phonet.c
5479 --- backports-4.2.6-1.org/drivers/net/usb/cdc-phonet.c 1970-01-01 01:00:00.000000000 +0100
5480 +++ backports-4.2.6-1/drivers/net/usb/cdc-phonet.c 2016-06-28 14:35:17.975307221 +0200
5481 @@ -0,0 +1,466 @@
5482 +/*
5483 + * phonet.c -- USB CDC Phonet host driver
5484 + *
5485 + * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved.
5486 + *
5487 + * Author: Rémi Denis-Courmont
5488 + *
5489 + * This program is free software; you can redistribute it and/or
5490 + * modify it under the terms of the GNU General Public License
5491 + * version 2 as published by the Free Software Foundation.
5492 + *
5493 + * This program is distributed in the hope that it will be useful, but
5494 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5495 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5496 + * General Public License for more details.
5497 + *
5498 + * You should have received a copy of the GNU General Public License
5499 + * along with this program; if not, write to the Free Software
5500 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
5501 + * 02110-1301 USA
5502 + */
5503 +
5504 +#include <linux/kernel.h>
5505 +#include <linux/mm.h>
5506 +#include <linux/module.h>
5507 +#include <linux/gfp.h>
5508 +#include <linux/usb.h>
5509 +#include <linux/usb/cdc.h>
5510 +#include <linux/netdevice.h>
5511 +#include <linux/if_arp.h>
5512 +#include <linux/if_phonet.h>
5513 +#include <linux/phonet.h>
5514 +
5515 +#define PN_MEDIA_USB 0x1B
5516 +
5517 +static const unsigned rxq_size = 17;
5518 +
5519 +struct usbpn_dev {
5520 + struct net_device *dev;
5521 +
5522 + struct usb_interface *intf, *data_intf;
5523 + struct usb_device *usb;
5524 + unsigned int tx_pipe, rx_pipe;
5525 + u8 active_setting;
5526 + u8 disconnected;
5527 +
5528 + unsigned tx_queue;
5529 + spinlock_t tx_lock;
5530 +
5531 + spinlock_t rx_lock;
5532 + struct sk_buff *rx_skb;
5533 + struct urb *urbs[0];
5534 +};
5535 +
5536 +static void tx_complete(struct urb *req);
5537 +static void rx_complete(struct urb *req);
5538 +
5539 +/*
5540 + * Network device callbacks
5541 + */
5542 +static netdev_tx_t usbpn_xmit(struct sk_buff *skb, struct net_device *dev)
5543 +{
5544 + struct usbpn_dev *pnd = netdev_priv(dev);
5545 + struct urb *req = NULL;
5546 + unsigned long flags;
5547 + int err;
5548 +
5549 + if (skb->protocol != htons(ETH_P_PHONET))
5550 + goto drop;
5551 +
5552 + req = usb_alloc_urb(0, GFP_ATOMIC);
5553 + if (!req)
5554 + goto drop;
5555 + usb_fill_bulk_urb(req, pnd->usb, pnd->tx_pipe, skb->data, skb->len,
5556 + tx_complete, skb);
5557 + req->transfer_flags = URB_ZERO_PACKET;
5558 + err = usb_submit_urb(req, GFP_ATOMIC);
5559 + if (err) {
5560 + usb_free_urb(req);
5561 + goto drop;
5562 + }
5563 +
5564 + spin_lock_irqsave(&pnd->tx_lock, flags);
5565 + pnd->tx_queue++;
5566 + if (pnd->tx_queue >= dev->tx_queue_len)
5567 + netif_stop_queue(dev);
5568 + spin_unlock_irqrestore(&pnd->tx_lock, flags);
5569 + return NETDEV_TX_OK;
5570 +
5571 +drop:
5572 + dev_kfree_skb(skb);
5573 + dev->stats.tx_dropped++;
5574 + return NETDEV_TX_OK;
5575 +}
5576 +
5577 +static void tx_complete(struct urb *req)
5578 +{
5579 + struct sk_buff *skb = req->context;
5580 + struct net_device *dev = skb->dev;
5581 + struct usbpn_dev *pnd = netdev_priv(dev);
5582 + int status = req->status;
5583 +
5584 + switch (status) {
5585 + case 0:
5586 + dev->stats.tx_bytes += skb->len;
5587 + break;
5588 +
5589 + case -ENOENT:
5590 + case -ECONNRESET:
5591 + case -ESHUTDOWN:
5592 + dev->stats.tx_aborted_errors++;
5593 + default:
5594 + dev->stats.tx_errors++;
5595 + dev_dbg(&dev->dev, "TX error (%d)\n", status);
5596 + }
5597 + dev->stats.tx_packets++;
5598 +
5599 + spin_lock(&pnd->tx_lock);
5600 + pnd->tx_queue--;
5601 + netif_wake_queue(dev);
5602 + spin_unlock(&pnd->tx_lock);
5603 +
5604 + dev_kfree_skb_any(skb);
5605 + usb_free_urb(req);
5606 +}
5607 +
5608 +static int rx_submit(struct usbpn_dev *pnd, struct urb *req, gfp_t gfp_flags)
5609 +{
5610 + struct net_device *dev = pnd->dev;
5611 + struct page *page;
5612 + int err;
5613 +
5614 + page = __dev_alloc_page(gfp_flags | __GFP_NOMEMALLOC);
5615 + if (!page)
5616 + return -ENOMEM;
5617 +
5618 + usb_fill_bulk_urb(req, pnd->usb, pnd->rx_pipe, page_address(page),
5619 + PAGE_SIZE, rx_complete, dev);
5620 + req->transfer_flags = 0;
5621 + err = usb_submit_urb(req, gfp_flags);
5622 + if (unlikely(err)) {
5623 + dev_dbg(&dev->dev, "RX submit error (%d)\n", err);
5624 + put_page(page);
5625 + }
5626 + return err;
5627 +}
5628 +
5629 +static void rx_complete(struct urb *req)
5630 +{
5631 + struct net_device *dev = req->context;
5632 + struct usbpn_dev *pnd = netdev_priv(dev);
5633 + struct page *page = virt_to_page(req->transfer_buffer);
5634 + struct sk_buff *skb;
5635 + unsigned long flags;
5636 + int status = req->status;
5637 +
5638 + switch (status) {
5639 + case 0:
5640 + spin_lock_irqsave(&pnd->rx_lock, flags);
5641 + skb = pnd->rx_skb;
5642 + if (!skb) {
5643 + skb = pnd->rx_skb = netdev_alloc_skb(dev, 12);
5644 + if (likely(skb)) {
5645 + /* Can't use pskb_pull() on page in IRQ */
5646 + memcpy(skb_put(skb, 1), page_address(page), 1);
5647 + skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
5648 + page, 1, req->actual_length,
5649 + PAGE_SIZE);
5650 + page = NULL;
5651 + }
5652 + } else {
5653 + skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
5654 + page, 0, req->actual_length,
5655 + PAGE_SIZE);
5656 + page = NULL;
5657 + }
5658 + if (req->actual_length < PAGE_SIZE)
5659 + pnd->rx_skb = NULL; /* Last fragment */
5660 + else
5661 + skb = NULL;
5662 + spin_unlock_irqrestore(&pnd->rx_lock, flags);
5663 + if (skb) {
5664 + skb->protocol = htons(ETH_P_PHONET);
5665 + skb_reset_mac_header(skb);
5666 + __skb_pull(skb, 1);
5667 + skb->dev = dev;
5668 + dev->stats.rx_packets++;
5669 + dev->stats.rx_bytes += skb->len;
5670 +
5671 + netif_rx(skb);
5672 + }
5673 + goto resubmit;
5674 +
5675 + case -ENOENT:
5676 + case -ECONNRESET:
5677 + case -ESHUTDOWN:
5678 + req = NULL;
5679 + break;
5680 +
5681 + case -EOVERFLOW:
5682 + dev->stats.rx_over_errors++;
5683 + dev_dbg(&dev->dev, "RX overflow\n");
5684 + break;
5685 +
5686 + case -EILSEQ:
5687 + dev->stats.rx_crc_errors++;
5688 + break;
5689 + }
5690 +
5691 + dev->stats.rx_errors++;
5692 +resubmit:
5693 + if (page)
5694 + put_page(page);
5695 + if (req)
5696 + rx_submit(pnd, req, GFP_ATOMIC);
5697 +}
5698 +
5699 +static int usbpn_close(struct net_device *dev);
5700 +
5701 +static int usbpn_open(struct net_device *dev)
5702 +{
5703 + struct usbpn_dev *pnd = netdev_priv(dev);
5704 + int err;
5705 + unsigned i;
5706 + unsigned num = pnd->data_intf->cur_altsetting->desc.bInterfaceNumber;
5707 +
5708 + err = usb_set_interface(pnd->usb, num, pnd->active_setting);
5709 + if (err)
5710 + return err;
5711 +
5712 + for (i = 0; i < rxq_size; i++) {
5713 + struct urb *req = usb_alloc_urb(0, GFP_KERNEL);
5714 +
5715 + if (!req || rx_submit(pnd, req, GFP_KERNEL)) {
5716 + usb_free_urb(req);
5717 + usbpn_close(dev);
5718 + return -ENOMEM;
5719 + }
5720 + pnd->urbs[i] = req;
5721 + }
5722 +
5723 + netif_wake_queue(dev);
5724 + return 0;
5725 +}
5726 +
5727 +static int usbpn_close(struct net_device *dev)
5728 +{
5729 + struct usbpn_dev *pnd = netdev_priv(dev);
5730 + unsigned i;
5731 + unsigned num = pnd->data_intf->cur_altsetting->desc.bInterfaceNumber;
5732 +
5733 + netif_stop_queue(dev);
5734 +
5735 + for (i = 0; i < rxq_size; i++) {
5736 + struct urb *req = pnd->urbs[i];
5737 +
5738 + if (!req)
5739 + continue;
5740 + usb_kill_urb(req);
5741 + usb_free_urb(req);
5742 + pnd->urbs[i] = NULL;
5743 + }
5744 +
5745 + return usb_set_interface(pnd->usb, num, !pnd->active_setting);
5746 +}
5747 +
5748 +static int usbpn_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
5749 +{
5750 + struct if_phonet_req *req = (struct if_phonet_req *)ifr;
5751 +
5752 + switch (cmd) {
5753 + case SIOCPNGAUTOCONF:
5754 + req->ifr_phonet_autoconf.device = PN_DEV_PC;
5755 + return 0;
5756 + }
5757 + return -ENOIOCTLCMD;
5758 +}
5759 +
5760 +static int usbpn_set_mtu(struct net_device *dev, int new_mtu)
5761 +{
5762 + if ((new_mtu < PHONET_MIN_MTU) || (new_mtu > PHONET_MAX_MTU))
5763 + return -EINVAL;
5764 +
5765 + dev->mtu = new_mtu;
5766 + return 0;
5767 +}
5768 +
5769 +static const struct net_device_ops usbpn_ops = {
5770 + .ndo_open = usbpn_open,
5771 + .ndo_stop = usbpn_close,
5772 + .ndo_start_xmit = usbpn_xmit,
5773 + .ndo_do_ioctl = usbpn_ioctl,
5774 + .ndo_change_mtu = usbpn_set_mtu,
5775 +};
5776 +
5777 +static void usbpn_setup(struct net_device *dev)
5778 +{
5779 + dev->features = 0;
5780 + dev->netdev_ops = &usbpn_ops,
5781 + dev->header_ops = &phonet_header_ops;
5782 + dev->type = ARPHRD_PHONET;
5783 + dev->flags = IFF_POINTOPOINT | IFF_NOARP;
5784 + dev->mtu = PHONET_MAX_MTU;
5785 + dev->hard_header_len = 1;
5786 + dev->dev_addr[0] = PN_MEDIA_USB;
5787 + dev->addr_len = 1;
5788 + dev->tx_queue_len = 3;
5789 +
5790 + dev->destructor = free_netdev;
5791 +}
5792 +
5793 +/*
5794 + * USB driver callbacks
5795 + */
5796 +static struct usb_device_id usbpn_ids[] = {
5797 + {
5798 + .match_flags = USB_DEVICE_ID_MATCH_VENDOR
5799 + | USB_DEVICE_ID_MATCH_INT_CLASS
5800 + | USB_DEVICE_ID_MATCH_INT_SUBCLASS,
5801 + .idVendor = 0x0421, /* Nokia */
5802 + .bInterfaceClass = USB_CLASS_COMM,
5803 + .bInterfaceSubClass = 0xFE,
5804 + },
5805 + { },
5806 +};
5807 +
5808 +MODULE_DEVICE_TABLE(usb, usbpn_ids);
5809 +
5810 +static struct usb_driver usbpn_driver;
5811 +
5812 +static int usbpn_probe(struct usb_interface *intf, const struct usb_device_id *id)
5813 +{
5814 + static const char ifname[] = "usbpn%d";
5815 + const struct usb_cdc_union_desc *union_header = NULL;
5816 + const struct usb_host_interface *data_desc;
5817 + struct usb_interface *data_intf;
5818 + struct usb_device *usbdev = interface_to_usbdev(intf);
5819 + struct net_device *dev;
5820 + struct usbpn_dev *pnd;
5821 + u8 *data;
5822 + int phonet = 0;
5823 + int len, err;
5824 +
5825 + data = intf->altsetting->extra;
5826 + len = intf->altsetting->extralen;
5827 + while (len >= 3) {
5828 + u8 dlen = data[0];
5829 + if (dlen < 3)
5830 + return -EINVAL;
5831 +
5832 + /* bDescriptorType */
5833 + if (data[1] == USB_DT_CS_INTERFACE) {
5834 + /* bDescriptorSubType */
5835 + switch (data[2]) {
5836 + case USB_CDC_UNION_TYPE:
5837 + if (union_header || dlen < 5)
5838 + break;
5839 + union_header =
5840 + (struct usb_cdc_union_desc *)data;
5841 + break;
5842 + case 0xAB:
5843 + phonet = 1;
5844 + break;
5845 + }
5846 + }
5847 + data += dlen;
5848 + len -= dlen;
5849 + }
5850 +
5851 + if (!union_header || !phonet)
5852 + return -EINVAL;
5853 +
5854 + data_intf = usb_ifnum_to_if(usbdev, union_header->bSlaveInterface0);
5855 + if (data_intf == NULL)
5856 + return -ENODEV;
5857 + /* Data interface has one inactive and one active setting */
5858 + if (data_intf->num_altsetting != 2)
5859 + return -EINVAL;
5860 + if (data_intf->altsetting[0].desc.bNumEndpoints == 0 &&
5861 + data_intf->altsetting[1].desc.bNumEndpoints == 2)
5862 + data_desc = data_intf->altsetting + 1;
5863 + else
5864 + if (data_intf->altsetting[0].desc.bNumEndpoints == 2 &&
5865 + data_intf->altsetting[1].desc.bNumEndpoints == 0)
5866 + data_desc = data_intf->altsetting;
5867 + else
5868 + return -EINVAL;
5869 +
5870 + dev = alloc_netdev(sizeof(*pnd) + sizeof(pnd->urbs[0]) * rxq_size,
5871 + ifname, NET_NAME_UNKNOWN, usbpn_setup);
5872 + if (!dev)
5873 + return -ENOMEM;
5874 +
5875 + pnd = netdev_priv(dev);
5876 + SET_NETDEV_DEV(dev, &intf->dev);
5877 +
5878 + pnd->dev = dev;
5879 + pnd->usb = usbdev;
5880 + pnd->intf = intf;
5881 + pnd->data_intf = data_intf;
5882 + spin_lock_init(&pnd->tx_lock);
5883 + spin_lock_init(&pnd->rx_lock);
5884 + /* Endpoints */
5885 + if (usb_pipein(data_desc->endpoint[0].desc.bEndpointAddress)) {
5886 + pnd->rx_pipe = usb_rcvbulkpipe(usbdev,
5887 + data_desc->endpoint[0].desc.bEndpointAddress);
5888 + pnd->tx_pipe = usb_sndbulkpipe(usbdev,
5889 + data_desc->endpoint[1].desc.bEndpointAddress);
5890 + } else {
5891 + pnd->rx_pipe = usb_rcvbulkpipe(usbdev,
5892 + data_desc->endpoint[1].desc.bEndpointAddress);
5893 + pnd->tx_pipe = usb_sndbulkpipe(usbdev,
5894 + data_desc->endpoint[0].desc.bEndpointAddress);
5895 + }
5896 + pnd->active_setting = data_desc - data_intf->altsetting;
5897 +
5898 + err = usb_driver_claim_interface(&usbpn_driver, data_intf, pnd);
5899 + if (err)
5900 + goto out;
5901 +
5902 + /* Force inactive mode until the network device is brought UP */
5903 + usb_set_interface(usbdev, union_header->bSlaveInterface0,
5904 + !pnd->active_setting);
5905 + usb_set_intfdata(intf, pnd);
5906 +
5907 + err = register_netdev(dev);
5908 + if (err) {
5909 + usb_driver_release_interface(&usbpn_driver, data_intf);
5910 + goto out;
5911 + }
5912 +
5913 + dev_dbg(&dev->dev, "USB CDC Phonet device found\n");
5914 + return 0;
5915 +
5916 +out:
5917 + usb_set_intfdata(intf, NULL);
5918 + free_netdev(dev);
5919 + return err;
5920 +}
5921 +
5922 +static void usbpn_disconnect(struct usb_interface *intf)
5923 +{
5924 + struct usbpn_dev *pnd = usb_get_intfdata(intf);
5925 +
5926 + if (pnd->disconnected)
5927 + return;
5928 +
5929 + pnd->disconnected = 1;
5930 + usb_driver_release_interface(&usbpn_driver,
5931 + (pnd->intf == intf) ? pnd->data_intf : pnd->intf);
5932 + unregister_netdev(pnd->dev);
5933 +}
5934 +
5935 +static struct usb_driver usbpn_driver = {
5936 + .name = "cdc_phonet",
5937 + .probe = usbpn_probe,
5938 + .disconnect = usbpn_disconnect,
5939 + .id_table = usbpn_ids,
5940 + .disable_hub_initiated_lpm = 1,
5941 +};
5942 +
5943 +module_usb_driver(usbpn_driver);
5944 +
5945 +MODULE_AUTHOR("Remi Denis-Courmont");
5946 +MODULE_DESCRIPTION("USB CDC Phonet host interface");
5947 +MODULE_LICENSE("GPL");
5948 diff -Naur backports-4.2.6-1.org/drivers/net/usb/cdc_subset.c backports-4.2.6-1/drivers/net/usb/cdc_subset.c
5949 --- backports-4.2.6-1.org/drivers/net/usb/cdc_subset.c 1970-01-01 01:00:00.000000000 +0100
5950 +++ backports-4.2.6-1/drivers/net/usb/cdc_subset.c 2016-06-28 14:35:17.975307221 +0200
5951 @@ -0,0 +1,369 @@
5952 +/*
5953 + * Simple "CDC Subset" USB Networking Links
5954 + * Copyright (C) 2000-2005 by David Brownell
5955 + *
5956 + * This program is free software; you can redistribute it and/or modify
5957 + * it under the terms of the GNU General Public License as published by
5958 + * the Free Software Foundation; either version 2 of the License, or
5959 + * (at your option) any later version.
5960 + *
5961 + * This program is distributed in the hope that it will be useful,
5962 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5963 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5964 + * GNU General Public License for more details.
5965 + *
5966 + * You should have received a copy of the GNU General Public License
5967 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
5968 + */
5969 +
5970 +#include <linux/module.h>
5971 +#include <linux/kmod.h>
5972 +#include <linux/netdevice.h>
5973 +#include <linux/etherdevice.h>
5974 +#include <linux/ethtool.h>
5975 +#include <linux/workqueue.h>
5976 +#include <linux/mii.h>
5977 +#include <linux/usb.h>
5978 +#include <linux/usb/usbnet.h>
5979 +
5980 +
5981 +/*
5982 + * This supports simple USB network links that don't require any special
5983 + * framing or hardware control operations. The protocol used here is a
5984 + * strict subset of CDC Ethernet, with three basic differences reflecting
5985 + * the goal that almost any hardware should run it:
5986 + *
5987 + * - Minimal runtime control: one interface, no altsettings, and
5988 + * no vendor or class specific control requests. If a device is
5989 + * configured, it is allowed to exchange packets with the host.
5990 + * Fancier models would mean not working on some hardware.
5991 + *
5992 + * - Minimal manufacturing control: no IEEE "Organizationally
5993 + * Unique ID" required, or an EEPROMs to store one. Each host uses
5994 + * one random "locally assigned" Ethernet address instead, which can
5995 + * of course be overridden using standard tools like "ifconfig".
5996 + * (With 2^46 such addresses, same-net collisions are quite rare.)
5997 + *
5998 + * - There is no additional framing data for USB. Packets are written
5999 + * exactly as in CDC Ethernet, starting with an Ethernet header and
6000 + * terminated by a short packet. However, the host will never send a
6001 + * zero length packet; some systems can't handle those robustly.
6002 + *
6003 + * Anything that can transmit and receive USB bulk packets can implement
6004 + * this protocol. That includes both smart peripherals and quite a lot
6005 + * of "host-to-host" USB cables (which embed two devices back-to-back).
6006 + *
6007 + * Note that although Linux may use many of those host-to-host links
6008 + * with this "cdc_subset" framing, that doesn't mean there may not be a
6009 + * better approach. Handling the "other end unplugs/replugs" scenario
6010 + * well tends to require chip-specific vendor requests. Also, Windows
6011 + * peers at the other end of host-to-host cables may expect their own
6012 + * framing to be used rather than this "cdc_subset" model.
6013 + */
6014 +
6015 +#if defined(CONFIG_USB_EPSON2888) || defined(CONFIG_USB_ARMLINUX)
6016 +/* PDA style devices are always connected if present */
6017 +static int always_connected (struct usbnet *dev)
6018 +{
6019 + return 0;
6020 +}
6021 +#endif
6022 +
6023 +#ifdef CONFIG_USB_ALI_M5632
6024 +#define HAVE_HARDWARE
6025 +
6026 +/*-------------------------------------------------------------------------
6027 + *
6028 + * ALi M5632 driver ... does high speed
6029 + *
6030 + * NOTE that the MS-Windows drivers for this chip use some funky and
6031 + * (naturally) undocumented 7-byte prefix to each packet, so this is a
6032 + * case where we don't currently interoperate. Also, once you unplug
6033 + * one end of the cable, you need to replug the other end too ... since
6034 + * chip docs are unavailable, there's no way to reset the relevant state
6035 + * short of a power cycle.
6036 + *
6037 + *-------------------------------------------------------------------------*/
6038 +
6039 +static void m5632_recover(struct usbnet *dev)
6040 +{
6041 + struct usb_device *udev = dev->udev;
6042 + struct usb_interface *intf = dev->intf;
6043 + int r;
6044 +
6045 + r = usb_lock_device_for_reset(udev, intf);
6046 + if (r < 0)
6047 + return;
6048 +
6049 + usb_reset_device(udev);
6050 + usb_unlock_device(udev);
6051 +}
6052 +
6053 +static const struct driver_info ali_m5632_info = {
6054 + .description = "ALi M5632",
6055 + .flags = FLAG_POINTTOPOINT,
6056 + .recover = m5632_recover,
6057 +};
6058 +
6059 +#endif
6060 +
6061 +#ifdef CONFIG_USB_AN2720
6062 +#define HAVE_HARDWARE
6063 +
6064 +/*-------------------------------------------------------------------------
6065 + *
6066 + * AnchorChips 2720 driver ... http://www.cypress.com
6067 + *
6068 + * This doesn't seem to have a way to detect whether the peer is
6069 + * connected, or need any reset handshaking. It's got pretty big
6070 + * internal buffers (handles most of a frame's worth of data).
6071 + * Chip data sheets don't describe any vendor control messages.
6072 + *
6073 + *-------------------------------------------------------------------------*/
6074 +
6075 +static const struct driver_info an2720_info = {
6076 + .description = "AnchorChips/Cypress 2720",
6077 + .flags = FLAG_POINTTOPOINT,
6078 + // no reset available!
6079 + // no check_connect available!
6080 +
6081 + .in = 2, .out = 2, // direction distinguishes these
6082 +};
6083 +
6084 +#endif /* CONFIG_USB_AN2720 */
6085 +
6086 +\f
6087 +#ifdef CONFIG_USB_BELKIN
6088 +#define HAVE_HARDWARE
6089 +
6090 +/*-------------------------------------------------------------------------
6091 + *
6092 + * Belkin F5U104 ... two NetChip 2280 devices + Atmel AVR microcontroller
6093 + *
6094 + * ... also two eTEK designs, including one sold as "Advance USBNET"
6095 + *
6096 + *-------------------------------------------------------------------------*/
6097 +
6098 +static const struct driver_info belkin_info = {
6099 + .description = "Belkin, eTEK, or compatible",
6100 + .flags = FLAG_POINTTOPOINT,
6101 +};
6102 +
6103 +#endif /* CONFIG_USB_BELKIN */
6104 +
6105 +
6106 +\f
6107 +#ifdef CONFIG_USB_EPSON2888
6108 +#define HAVE_HARDWARE
6109 +
6110 +/*-------------------------------------------------------------------------
6111 + *
6112 + * EPSON USB clients
6113 + *
6114 + * This is the same idea as Linux PDAs (below) except the firmware in the
6115 + * device might not be Tux-powered. Epson provides reference firmware that
6116 + * implements this interface. Product developers can reuse or modify that
6117 + * code, such as by using their own product and vendor codes.
6118 + *
6119 + * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
6120 + *
6121 + *-------------------------------------------------------------------------*/
6122 +
6123 +static const struct driver_info epson2888_info = {
6124 + .description = "Epson USB Device",
6125 + .check_connect = always_connected,
6126 + .flags = FLAG_POINTTOPOINT,
6127 +
6128 + .in = 4, .out = 3,
6129 +};
6130 +
6131 +#endif /* CONFIG_USB_EPSON2888 */
6132 +
6133 +\f
6134 +/*-------------------------------------------------------------------------
6135 + *
6136 + * info from Jonathan McDowell <noodles@earth.li>
6137 + *
6138 + *-------------------------------------------------------------------------*/
6139 +#ifdef CONFIG_USB_KC2190
6140 +#define HAVE_HARDWARE
6141 +static const struct driver_info kc2190_info = {
6142 + .description = "KC Technology KC-190",
6143 + .flags = FLAG_POINTTOPOINT,
6144 +};
6145 +#endif /* CONFIG_USB_KC2190 */
6146 +
6147 +\f
6148 +#ifdef CONFIG_USB_ARMLINUX
6149 +#define HAVE_HARDWARE
6150 +
6151 +/*-------------------------------------------------------------------------
6152 + *
6153 + * Intel's SA-1100 chip integrates basic USB support, and is used
6154 + * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
6155 + * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
6156 + * network using minimal USB framing data.
6157 + *
6158 + * This describes the driver currently in standard ARM Linux kernels.
6159 + * The Zaurus uses a different driver (see later).
6160 + *
6161 + * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
6162 + * and different USB endpoint numbering than the SA1100 devices. The
6163 + * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
6164 + * so we rely on the endpoint descriptors.
6165 + *
6166 + *-------------------------------------------------------------------------*/
6167 +
6168 +static const struct driver_info linuxdev_info = {
6169 + .description = "Linux Device",
6170 + .check_connect = always_connected,
6171 + .flags = FLAG_POINTTOPOINT,
6172 +};
6173 +
6174 +static const struct driver_info yopy_info = {
6175 + .description = "Yopy",
6176 + .check_connect = always_connected,
6177 + .flags = FLAG_POINTTOPOINT,
6178 +};
6179 +
6180 +static const struct driver_info blob_info = {
6181 + .description = "Boot Loader OBject",
6182 + .check_connect = always_connected,
6183 + .flags = FLAG_POINTTOPOINT,
6184 +};
6185 +
6186 +#endif /* CONFIG_USB_ARMLINUX */
6187 +
6188 +\f
6189 +/*-------------------------------------------------------------------------*/
6190 +
6191 +#ifndef HAVE_HARDWARE
6192 +#warning You need to configure some hardware for this driver
6193 +#endif
6194 +
6195 +/*
6196 + * chip vendor names won't normally be on the cables, and
6197 + * may not be on the device.
6198 + */
6199 +
6200 +static const struct usb_device_id products [] = {
6201 +
6202 +#ifdef CONFIG_USB_ALI_M5632
6203 +{
6204 + USB_DEVICE (0x0402, 0x5632), // ALi defaults
6205 + .driver_info = (unsigned long) &ali_m5632_info,
6206 +},
6207 +{
6208 + USB_DEVICE (0x182d,0x207c), // SiteCom CN-124
6209 + .driver_info = (unsigned long) &ali_m5632_info,
6210 +},
6211 +#endif
6212 +
6213 +#ifdef CONFIG_USB_AN2720
6214 +{
6215 + USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
6216 + .driver_info = (unsigned long) &an2720_info,
6217 +}, {
6218 + USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
6219 + .driver_info = (unsigned long) &an2720_info,
6220 +},
6221 +#endif
6222 +
6223 +#ifdef CONFIG_USB_BELKIN
6224 +{
6225 + USB_DEVICE (0x050d, 0x0004), // Belkin
6226 + .driver_info = (unsigned long) &belkin_info,
6227 +}, {
6228 + USB_DEVICE (0x056c, 0x8100), // eTEK
6229 + .driver_info = (unsigned long) &belkin_info,
6230 +}, {
6231 + USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
6232 + .driver_info = (unsigned long) &belkin_info,
6233 +},
6234 +#endif
6235 +
6236 +#ifdef CONFIG_USB_EPSON2888
6237 +{
6238 + USB_DEVICE (0x0525, 0x2888), // EPSON USB client
6239 + .driver_info = (unsigned long) &epson2888_info,
6240 +},
6241 +#endif
6242 +
6243 +#ifdef CONFIG_USB_KC2190
6244 +{
6245 + USB_DEVICE (0x050f, 0x0190), // KC-190
6246 + .driver_info = (unsigned long) &kc2190_info,
6247 +},
6248 +#endif
6249 +
6250 +#ifdef CONFIG_USB_ARMLINUX
6251 +/*
6252 + * SA-1100 using standard ARM Linux kernels, or compatible.
6253 + * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
6254 + * The sa-1100 "usb-eth" driver handles the basic framing.
6255 + *
6256 + * PXA25x or PXA210 ... these use a "usb-eth" driver much like
6257 + * the sa1100 one, but hardware uses different endpoint numbers.
6258 + *
6259 + * Or the Linux "Ethernet" gadget on hardware that can't talk
6260 + * CDC Ethernet (e.g., no altsettings), in either of two modes:
6261 + * - acting just like the old "usb-eth" firmware, though
6262 + * the implementation is different
6263 + * - supporting RNDIS as the first/default configuration for
6264 + * MS-Windows interop; Linux needs to use the other config
6265 + */
6266 +{
6267 + // 1183 = 0x049F, both used as hex values?
6268 + // Compaq "Itsy" vendor/product id
6269 + USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible
6270 + .driver_info = (unsigned long) &linuxdev_info,
6271 +}, {
6272 + USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
6273 + .driver_info = (unsigned long) &yopy_info,
6274 +}, {
6275 + USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
6276 + .driver_info = (unsigned long) &blob_info,
6277 +}, {
6278 + USB_DEVICE (0x1286, 0x8001), // "blob" bootloader
6279 + .driver_info = (unsigned long) &blob_info,
6280 +}, {
6281 + // Linux Ethernet/RNDIS gadget, mostly on PXA, second config
6282 + // e.g. Gumstix, current OpenZaurus, ... or anything else
6283 + // that just enables this gadget option.
6284 + USB_DEVICE (0x0525, 0xa4a2),
6285 + .driver_info = (unsigned long) &linuxdev_info,
6286 +},
6287 +#endif
6288 +
6289 + { }, // END
6290 +};
6291 +MODULE_DEVICE_TABLE(usb, products);
6292 +
6293 +/*-------------------------------------------------------------------------*/
6294 +static int dummy_prereset(struct usb_interface *intf)
6295 +{
6296 + return 0;
6297 +}
6298 +
6299 +static int dummy_postreset(struct usb_interface *intf)
6300 +{
6301 + return 0;
6302 +}
6303 +
6304 +static struct usb_driver cdc_subset_driver = {
6305 + .name = "cdc_subset",
6306 + .probe = usbnet_probe,
6307 + .suspend = usbnet_suspend,
6308 + .resume = usbnet_resume,
6309 + .pre_reset = dummy_prereset,
6310 + .post_reset = dummy_postreset,
6311 + .disconnect = usbnet_disconnect,
6312 + .id_table = products,
6313 + .disable_hub_initiated_lpm = 1,
6314 +};
6315 +
6316 +module_usb_driver(cdc_subset_driver);
6317 +
6318 +MODULE_AUTHOR("David Brownell");
6319 +MODULE_DESCRIPTION("Simple 'CDC Subset' USB networking links");
6320 +MODULE_LICENSE("GPL");
6321 diff -Naur backports-4.2.6-1.org/drivers/net/usb/cx82310_eth.c backports-4.2.6-1/drivers/net/usb/cx82310_eth.c
6322 --- backports-4.2.6-1.org/drivers/net/usb/cx82310_eth.c 1970-01-01 01:00:00.000000000 +0100
6323 +++ backports-4.2.6-1/drivers/net/usb/cx82310_eth.c 2016-06-28 14:35:17.978640554 +0200
6324 @@ -0,0 +1,353 @@
6325 +/*
6326 + * Driver for USB ethernet port of Conexant CX82310-based ADSL routers
6327 + * Copyright (C) 2010 by Ondrej Zary
6328 + * some parts inspired by the cxacru driver
6329 + *
6330 + * This program is free software; you can redistribute it and/or modify
6331 + * it under the terms of the GNU General Public License as published by
6332 + * the Free Software Foundation; either version 2 of the License, or
6333 + * (at your option) any later version.
6334 + *
6335 + * This program is distributed in the hope that it will be useful,
6336 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6337 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6338 + * GNU General Public License for more details.
6339 + *
6340 + * You should have received a copy of the GNU General Public License
6341 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
6342 + */
6343 +
6344 +#include <linux/module.h>
6345 +#include <linux/netdevice.h>
6346 +#include <linux/etherdevice.h>
6347 +#include <linux/ethtool.h>
6348 +#include <linux/workqueue.h>
6349 +#include <linux/mii.h>
6350 +#include <linux/usb.h>
6351 +#include <linux/usb/usbnet.h>
6352 +
6353 +enum cx82310_cmd {
6354 + CMD_START = 0x84, /* no effect? */
6355 + CMD_STOP = 0x85, /* no effect? */
6356 + CMD_GET_STATUS = 0x90, /* returns nothing? */
6357 + CMD_GET_MAC_ADDR = 0x91, /* read MAC address */
6358 + CMD_GET_LINK_STATUS = 0x92, /* not useful, link is always up */
6359 + CMD_ETHERNET_MODE = 0x99, /* unknown, needed during init */
6360 +};
6361 +
6362 +enum cx82310_status {
6363 + STATUS_UNDEFINED,
6364 + STATUS_SUCCESS,
6365 + STATUS_ERROR,
6366 + STATUS_UNSUPPORTED,
6367 + STATUS_UNIMPLEMENTED,
6368 + STATUS_PARAMETER_ERROR,
6369 + STATUS_DBG_LOOPBACK,
6370 +};
6371 +
6372 +#define CMD_PACKET_SIZE 64
6373 +#define CMD_TIMEOUT 100
6374 +#define CMD_REPLY_RETRY 5
6375 +
6376 +#define CX82310_MTU 1514
6377 +#define CMD_EP 0x01
6378 +
6379 +/*
6380 + * execute control command
6381 + * - optionally send some data (command parameters)
6382 + * - optionally wait for the reply
6383 + * - optionally read some data from the reply
6384 + */
6385 +static int cx82310_cmd(struct usbnet *dev, enum cx82310_cmd cmd, bool reply,
6386 + u8 *wdata, int wlen, u8 *rdata, int rlen)
6387 +{
6388 + int actual_len, retries, ret;
6389 + struct usb_device *udev = dev->udev;
6390 + u8 *buf = kzalloc(CMD_PACKET_SIZE, GFP_KERNEL);
6391 +
6392 + if (!buf)
6393 + return -ENOMEM;
6394 +
6395 + /* create command packet */
6396 + buf[0] = cmd;
6397 + if (wdata)
6398 + memcpy(buf + 4, wdata, min_t(int, wlen, CMD_PACKET_SIZE - 4));
6399 +
6400 + /* send command packet */
6401 + ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, CMD_EP), buf,
6402 + CMD_PACKET_SIZE, &actual_len, CMD_TIMEOUT);
6403 + if (ret < 0) {
6404 + if (cmd != CMD_GET_LINK_STATUS)
6405 + dev_err(&dev->udev->dev, "send command %#x: error %d\n",
6406 + cmd, ret);
6407 + goto end;
6408 + }
6409 +
6410 + if (reply) {
6411 + /* wait for reply, retry if it's empty */
6412 + for (retries = 0; retries < CMD_REPLY_RETRY; retries++) {
6413 + ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, CMD_EP),
6414 + buf, CMD_PACKET_SIZE, &actual_len,
6415 + CMD_TIMEOUT);
6416 + if (ret < 0) {
6417 + if (cmd != CMD_GET_LINK_STATUS)
6418 + dev_err(&dev->udev->dev,
6419 + "reply receive error %d\n",
6420 + ret);
6421 + goto end;
6422 + }
6423 + if (actual_len > 0)
6424 + break;
6425 + }
6426 + if (actual_len == 0) {
6427 + dev_err(&dev->udev->dev, "no reply to command %#x\n",
6428 + cmd);
6429 + ret = -EIO;
6430 + goto end;
6431 + }
6432 + if (buf[0] != cmd) {
6433 + dev_err(&dev->udev->dev,
6434 + "got reply to command %#x, expected: %#x\n",
6435 + buf[0], cmd);
6436 + ret = -EIO;
6437 + goto end;
6438 + }
6439 + if (buf[1] != STATUS_SUCCESS) {
6440 + dev_err(&dev->udev->dev, "command %#x failed: %#x\n",
6441 + cmd, buf[1]);
6442 + ret = -EIO;
6443 + goto end;
6444 + }
6445 + if (rdata)
6446 + memcpy(rdata, buf + 4,
6447 + min_t(int, rlen, CMD_PACKET_SIZE - 4));
6448 + }
6449 +end:
6450 + kfree(buf);
6451 + return ret;
6452 +}
6453 +
6454 +#define partial_len data[0] /* length of partial packet data */
6455 +#define partial_rem data[1] /* remaining (missing) data length */
6456 +#define partial_data data[2] /* partial packet data */
6457 +
6458 +static int cx82310_bind(struct usbnet *dev, struct usb_interface *intf)
6459 +{
6460 + int ret;
6461 + char buf[15];
6462 + struct usb_device *udev = dev->udev;
6463 + u8 link[3];
6464 + int timeout = 50;
6465 +
6466 + /* avoid ADSL modems - continue only if iProduct is "USB NET CARD" */
6467 + if (usb_string(udev, udev->descriptor.iProduct, buf, sizeof(buf)) > 0
6468 + && strcmp(buf, "USB NET CARD")) {
6469 + dev_info(&udev->dev, "ignoring: probably an ADSL modem\n");
6470 + return -ENODEV;
6471 + }
6472 +
6473 + ret = usbnet_get_endpoints(dev, intf);
6474 + if (ret)
6475 + return ret;
6476 +
6477 + /*
6478 + * this must not include ethernet header as the device can send partial
6479 + * packets with no header (and sometimes even empty URBs)
6480 + */
6481 + dev->net->hard_header_len = 0;
6482 + /* we can send at most 1514 bytes of data (+ 2-byte header) per URB */
6483 + dev->hard_mtu = CX82310_MTU + 2;
6484 + /* we can receive URBs up to 4KB from the device */
6485 + dev->rx_urb_size = 4096;
6486 +
6487 + dev->partial_data = (unsigned long) kmalloc(dev->hard_mtu, GFP_KERNEL);
6488 + if (!dev->partial_data)
6489 + return -ENOMEM;
6490 +
6491 + /* wait for firmware to become ready (indicated by the link being up) */
6492 + while (--timeout) {
6493 + ret = cx82310_cmd(dev, CMD_GET_LINK_STATUS, true, NULL, 0,
6494 + link, sizeof(link));
6495 + /* the command can time out during boot - it's not an error */
6496 + if (!ret && link[0] == 1 && link[2] == 1)
6497 + break;
6498 + msleep(500);
6499 + }
6500 + if (!timeout) {
6501 + dev_err(&udev->dev, "firmware not ready in time\n");
6502 + return -ETIMEDOUT;
6503 + }
6504 +
6505 + /* enable ethernet mode (?) */
6506 + ret = cx82310_cmd(dev, CMD_ETHERNET_MODE, true, "\x01", 1, NULL, 0);
6507 + if (ret) {
6508 + dev_err(&udev->dev, "unable to enable ethernet mode: %d\n",
6509 + ret);
6510 + goto err;
6511 + }
6512 +
6513 + /* get the MAC address */
6514 + ret = cx82310_cmd(dev, CMD_GET_MAC_ADDR, true, NULL, 0,
6515 + dev->net->dev_addr, ETH_ALEN);
6516 + if (ret) {
6517 + dev_err(&udev->dev, "unable to read MAC address: %d\n", ret);
6518 + goto err;
6519 + }
6520 +
6521 + /* start (does not seem to have any effect?) */
6522 + ret = cx82310_cmd(dev, CMD_START, false, NULL, 0, NULL, 0);
6523 + if (ret)
6524 + goto err;
6525 +
6526 + return 0;
6527 +err:
6528 + kfree((void *)dev->partial_data);
6529 + return ret;
6530 +}
6531 +
6532 +static void cx82310_unbind(struct usbnet *dev, struct usb_interface *intf)
6533 +{
6534 + kfree((void *)dev->partial_data);
6535 +}
6536 +
6537 +/*
6538 + * RX is NOT easy - we can receive multiple packets per skb, each having 2-byte
6539 + * packet length at the beginning.
6540 + * The last packet might be incomplete (when it crosses the 4KB URB size),
6541 + * continuing in the next skb (without any headers).
6542 + * If a packet has odd length, there is one extra byte at the end (before next
6543 + * packet or at the end of the URB).
6544 + */
6545 +static int cx82310_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
6546 +{
6547 + int len;
6548 + struct sk_buff *skb2;
6549 +
6550 + /*
6551 + * If the last skb ended with an incomplete packet, this skb contains
6552 + * end of that packet at the beginning.
6553 + */
6554 + if (dev->partial_rem) {
6555 + len = dev->partial_len + dev->partial_rem;
6556 + skb2 = alloc_skb(len, GFP_ATOMIC);
6557 + if (!skb2)
6558 + return 0;
6559 + skb_put(skb2, len);
6560 + memcpy(skb2->data, (void *)dev->partial_data,
6561 + dev->partial_len);
6562 + memcpy(skb2->data + dev->partial_len, skb->data,
6563 + dev->partial_rem);
6564 + usbnet_skb_return(dev, skb2);
6565 + skb_pull(skb, (dev->partial_rem + 1) & ~1);
6566 + dev->partial_rem = 0;
6567 + if (skb->len < 2)
6568 + return 1;
6569 + }
6570 +
6571 + /* a skb can contain multiple packets */
6572 + while (skb->len > 1) {
6573 + /* first two bytes are packet length */
6574 + len = skb->data[0] | (skb->data[1] << 8);
6575 + skb_pull(skb, 2);
6576 +
6577 + /* if last packet in the skb, let usbnet to process it */
6578 + if (len == skb->len || len + 1 == skb->len) {
6579 + skb_trim(skb, len);
6580 + break;
6581 + }
6582 +
6583 + if (len > CX82310_MTU) {
6584 + dev_err(&dev->udev->dev, "RX packet too long: %d B\n",
6585 + len);
6586 + return 0;
6587 + }
6588 +
6589 + /* incomplete packet, save it for the next skb */
6590 + if (len > skb->len) {
6591 + dev->partial_len = skb->len;
6592 + dev->partial_rem = len - skb->len;
6593 + memcpy((void *)dev->partial_data, skb->data,
6594 + dev->partial_len);
6595 + skb_pull(skb, skb->len);
6596 + break;
6597 + }
6598 +
6599 + skb2 = alloc_skb(len, GFP_ATOMIC);
6600 + if (!skb2)
6601 + return 0;
6602 + skb_put(skb2, len);
6603 + memcpy(skb2->data, skb->data, len);
6604 + /* process the packet */
6605 + usbnet_skb_return(dev, skb2);
6606 +
6607 + skb_pull(skb, (len + 1) & ~1);
6608 + }
6609 +
6610 + /* let usbnet process the last packet */
6611 + return 1;
6612 +}
6613 +
6614 +/* TX is easy, just add 2 bytes of length at the beginning */
6615 +static struct sk_buff *cx82310_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
6616 + gfp_t flags)
6617 +{
6618 + int len = skb->len;
6619 +
6620 + if (skb_headroom(skb) < 2) {
6621 + struct sk_buff *skb2 = skb_copy_expand(skb, 2, 0, flags);
6622 + dev_kfree_skb_any(skb);
6623 + skb = skb2;
6624 + if (!skb)
6625 + return NULL;
6626 + }
6627 + skb_push(skb, 2);
6628 +
6629 + skb->data[0] = len;
6630 + skb->data[1] = len >> 8;
6631 +
6632 + return skb;
6633 +}
6634 +
6635 +
6636 +static const struct driver_info cx82310_info = {
6637 + .description = "Conexant CX82310 USB ethernet",
6638 + .flags = FLAG_ETHER,
6639 + .bind = cx82310_bind,
6640 + .unbind = cx82310_unbind,
6641 + .rx_fixup = cx82310_rx_fixup,
6642 + .tx_fixup = cx82310_tx_fixup,
6643 +};
6644 +
6645 +#define USB_DEVICE_CLASS(vend, prod, cl, sc, pr) \
6646 + .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
6647 + USB_DEVICE_ID_MATCH_DEV_INFO, \
6648 + .idVendor = (vend), \
6649 + .idProduct = (prod), \
6650 + .bDeviceClass = (cl), \
6651 + .bDeviceSubClass = (sc), \
6652 + .bDeviceProtocol = (pr)
6653 +
6654 +static const struct usb_device_id products[] = {
6655 + {
6656 + USB_DEVICE_CLASS(0x0572, 0xcb01, 0xff, 0, 0),
6657 + .driver_info = (unsigned long) &cx82310_info
6658 + },
6659 + { },
6660 +};
6661 +MODULE_DEVICE_TABLE(usb, products);
6662 +
6663 +static struct usb_driver cx82310_driver = {
6664 + .name = "cx82310_eth",
6665 + .id_table = products,
6666 + .probe = usbnet_probe,
6667 + .disconnect = usbnet_disconnect,
6668 + .suspend = usbnet_suspend,
6669 + .resume = usbnet_resume,
6670 + .disable_hub_initiated_lpm = 1,
6671 +};
6672 +
6673 +module_usb_driver(cx82310_driver);
6674 +
6675 +MODULE_AUTHOR("Ondrej Zary");
6676 +MODULE_DESCRIPTION("Conexant CX82310-based ADSL router USB ethernet driver");
6677 +MODULE_LICENSE("GPL");
6678 diff -Naur backports-4.2.6-1.org/drivers/net/usb/dm9601.c backports-4.2.6-1/drivers/net/usb/dm9601.c
6679 --- backports-4.2.6-1.org/drivers/net/usb/dm9601.c 1970-01-01 01:00:00.000000000 +0100
6680 +++ backports-4.2.6-1/drivers/net/usb/dm9601.c 2016-06-28 14:35:17.978640554 +0200
6681 @@ -0,0 +1,647 @@
6682 +/*
6683 + * Davicom DM96xx USB 10/100Mbps ethernet devices
6684 + *
6685 + * Peter Korsgaard <jacmet@sunsite.dk>
6686 + *
6687 + * This file is licensed under the terms of the GNU General Public License
6688 + * version 2. This program is licensed "as is" without any warranty of any
6689 + * kind, whether express or implied.
6690 + */
6691 +
6692 +//#define DEBUG
6693 +
6694 +#include <linux/module.h>
6695 +#include <linux/sched.h>
6696 +#include <linux/stddef.h>
6697 +#include <linux/netdevice.h>
6698 +#include <linux/etherdevice.h>
6699 +#include <linux/ethtool.h>
6700 +#include <linux/mii.h>
6701 +#include <linux/usb.h>
6702 +#include <linux/crc32.h>
6703 +#include <linux/usb/usbnet.h>
6704 +#include <linux/slab.h>
6705 +
6706 +/* datasheet:
6707 + http://ptm2.cc.utu.fi/ftp/network/cards/DM9601/From_NET/DM9601-DS-P01-930914.pdf
6708 +*/
6709 +
6710 +/* control requests */
6711 +#define DM_READ_REGS 0x00
6712 +#define DM_WRITE_REGS 0x01
6713 +#define DM_READ_MEMS 0x02
6714 +#define DM_WRITE_REG 0x03
6715 +#define DM_WRITE_MEMS 0x05
6716 +#define DM_WRITE_MEM 0x07
6717 +
6718 +/* registers */
6719 +#define DM_NET_CTRL 0x00
6720 +#define DM_RX_CTRL 0x05
6721 +#define DM_SHARED_CTRL 0x0b
6722 +#define DM_SHARED_ADDR 0x0c
6723 +#define DM_SHARED_DATA 0x0d /* low + high */
6724 +#define DM_PHY_ADDR 0x10 /* 6 bytes */
6725 +#define DM_MCAST_ADDR 0x16 /* 8 bytes */
6726 +#define DM_GPR_CTRL 0x1e
6727 +#define DM_GPR_DATA 0x1f
6728 +#define DM_CHIP_ID 0x2c
6729 +#define DM_MODE_CTRL 0x91 /* only on dm9620 */
6730 +
6731 +/* chip id values */
6732 +#define ID_DM9601 0
6733 +#define ID_DM9620 1
6734 +
6735 +#define DM_MAX_MCAST 64
6736 +#define DM_MCAST_SIZE 8
6737 +#define DM_EEPROM_LEN 256
6738 +#define DM_TX_OVERHEAD 2 /* 2 byte header */
6739 +#define DM_RX_OVERHEAD 7 /* 3 byte header + 4 byte crc tail */
6740 +#define DM_TIMEOUT 1000
6741 +
6742 +static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data)
6743 +{
6744 + int err;
6745 + err = usbnet_read_cmd(dev, DM_READ_REGS,
6746 + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
6747 + 0, reg, data, length);
6748 + if(err != length && err >= 0)
6749 + err = -EINVAL;
6750 + return err;
6751 +}
6752 +
6753 +static int dm_read_reg(struct usbnet *dev, u8 reg, u8 *value)
6754 +{
6755 + return dm_read(dev, reg, 1, value);
6756 +}
6757 +
6758 +static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data)
6759 +{
6760 + int err;
6761 + err = usbnet_write_cmd(dev, DM_WRITE_REGS,
6762 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
6763 + 0, reg, data, length);
6764 +
6765 + if (err >= 0 && err < length)
6766 + err = -EINVAL;
6767 + return err;
6768 +}
6769 +
6770 +static int dm_write_reg(struct usbnet *dev, u8 reg, u8 value)
6771 +{
6772 + return usbnet_write_cmd(dev, DM_WRITE_REG,
6773 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
6774 + value, reg, NULL, 0);
6775 +}
6776 +
6777 +static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)
6778 +{
6779 + usbnet_write_cmd_async(dev, DM_WRITE_REGS,
6780 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
6781 + 0, reg, data, length);
6782 +}
6783 +
6784 +static void dm_write_reg_async(struct usbnet *dev, u8 reg, u8 value)
6785 +{
6786 + usbnet_write_cmd_async(dev, DM_WRITE_REG,
6787 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
6788 + value, reg, NULL, 0);
6789 +}
6790 +
6791 +static int dm_read_shared_word(struct usbnet *dev, int phy, u8 reg, __le16 *value)
6792 +{
6793 + int ret, i;
6794 +
6795 + mutex_lock(&dev->phy_mutex);
6796 +
6797 + dm_write_reg(dev, DM_SHARED_ADDR, phy ? (reg | 0x40) : reg);
6798 + dm_write_reg(dev, DM_SHARED_CTRL, phy ? 0xc : 0x4);
6799 +
6800 + for (i = 0; i < DM_TIMEOUT; i++) {
6801 + u8 tmp = 0;
6802 +
6803 + udelay(1);
6804 + ret = dm_read_reg(dev, DM_SHARED_CTRL, &tmp);
6805 + if (ret < 0)
6806 + goto out;
6807 +
6808 + /* ready */
6809 + if ((tmp & 1) == 0)
6810 + break;
6811 + }
6812 +
6813 + if (i == DM_TIMEOUT) {
6814 + netdev_err(dev->net, "%s read timed out!\n", phy ? "phy" : "eeprom");
6815 + ret = -EIO;
6816 + goto out;
6817 + }
6818 +
6819 + dm_write_reg(dev, DM_SHARED_CTRL, 0x0);
6820 + ret = dm_read(dev, DM_SHARED_DATA, 2, value);
6821 +
6822 + netdev_dbg(dev->net, "read shared %d 0x%02x returned 0x%04x, %d\n",
6823 + phy, reg, *value, ret);
6824 +
6825 + out:
6826 + mutex_unlock(&dev->phy_mutex);
6827 + return ret;
6828 +}
6829 +
6830 +static int dm_write_shared_word(struct usbnet *dev, int phy, u8 reg, __le16 value)
6831 +{
6832 + int ret, i;
6833 +
6834 + mutex_lock(&dev->phy_mutex);
6835 +
6836 + ret = dm_write(dev, DM_SHARED_DATA, 2, &value);
6837 + if (ret < 0)
6838 + goto out;
6839 +
6840 + dm_write_reg(dev, DM_SHARED_ADDR, phy ? (reg | 0x40) : reg);
6841 + dm_write_reg(dev, DM_SHARED_CTRL, phy ? 0x1a : 0x12);
6842 +
6843 + for (i = 0; i < DM_TIMEOUT; i++) {
6844 + u8 tmp = 0;
6845 +
6846 + udelay(1);
6847 + ret = dm_read_reg(dev, DM_SHARED_CTRL, &tmp);
6848 + if (ret < 0)
6849 + goto out;
6850 +
6851 + /* ready */
6852 + if ((tmp & 1) == 0)
6853 + break;
6854 + }
6855 +
6856 + if (i == DM_TIMEOUT) {
6857 + netdev_err(dev->net, "%s write timed out!\n", phy ? "phy" : "eeprom");
6858 + ret = -EIO;
6859 + goto out;
6860 + }
6861 +
6862 + dm_write_reg(dev, DM_SHARED_CTRL, 0x0);
6863 +
6864 +out:
6865 + mutex_unlock(&dev->phy_mutex);
6866 + return ret;
6867 +}
6868 +
6869 +static int dm_read_eeprom_word(struct usbnet *dev, u8 offset, void *value)
6870 +{
6871 + return dm_read_shared_word(dev, 0, offset, value);
6872 +}
6873 +
6874 +
6875 +
6876 +static int dm9601_get_eeprom_len(struct net_device *dev)
6877 +{
6878 + return DM_EEPROM_LEN;
6879 +}
6880 +
6881 +static int dm9601_get_eeprom(struct net_device *net,
6882 + struct ethtool_eeprom *eeprom, u8 * data)
6883 +{
6884 + struct usbnet *dev = netdev_priv(net);
6885 + __le16 *ebuf = (__le16 *) data;
6886 + int i;
6887 +
6888 + /* access is 16bit */
6889 + if ((eeprom->offset % 2) || (eeprom->len % 2))
6890 + return -EINVAL;
6891 +
6892 + for (i = 0; i < eeprom->len / 2; i++) {
6893 + if (dm_read_eeprom_word(dev, eeprom->offset / 2 + i,
6894 + &ebuf[i]) < 0)
6895 + return -EINVAL;
6896 + }
6897 + return 0;
6898 +}
6899 +
6900 +static int dm9601_mdio_read(struct net_device *netdev, int phy_id, int loc)
6901 +{
6902 + struct usbnet *dev = netdev_priv(netdev);
6903 +
6904 + __le16 res;
6905 +
6906 + if (phy_id) {
6907 + netdev_dbg(dev->net, "Only internal phy supported\n");
6908 + return 0;
6909 + }
6910 +
6911 + dm_read_shared_word(dev, 1, loc, &res);
6912 +
6913 + netdev_dbg(dev->net,
6914 + "dm9601_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
6915 + phy_id, loc, le16_to_cpu(res));
6916 +
6917 + return le16_to_cpu(res);
6918 +}
6919 +
6920 +static void dm9601_mdio_write(struct net_device *netdev, int phy_id, int loc,
6921 + int val)
6922 +{
6923 + struct usbnet *dev = netdev_priv(netdev);
6924 + __le16 res = cpu_to_le16(val);
6925 +
6926 + if (phy_id) {
6927 + netdev_dbg(dev->net, "Only internal phy supported\n");
6928 + return;
6929 + }
6930 +
6931 + netdev_dbg(dev->net, "dm9601_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n",
6932 + phy_id, loc, val);
6933 +
6934 + dm_write_shared_word(dev, 1, loc, res);
6935 +}
6936 +
6937 +static void dm9601_get_drvinfo(struct net_device *net,
6938 + struct ethtool_drvinfo *info)
6939 +{
6940 + /* Inherit standard device info */
6941 + usbnet_get_drvinfo(net, info);
6942 + info->eedump_len = DM_EEPROM_LEN;
6943 +}
6944 +
6945 +static u32 dm9601_get_link(struct net_device *net)
6946 +{
6947 + struct usbnet *dev = netdev_priv(net);
6948 +
6949 + return mii_link_ok(&dev->mii);
6950 +}
6951 +
6952 +static int dm9601_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
6953 +{
6954 + struct usbnet *dev = netdev_priv(net);
6955 +
6956 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
6957 +}
6958 +
6959 +static const struct ethtool_ops dm9601_ethtool_ops = {
6960 + .get_drvinfo = dm9601_get_drvinfo,
6961 + .get_link = dm9601_get_link,
6962 + .get_msglevel = usbnet_get_msglevel,
6963 + .set_msglevel = usbnet_set_msglevel,
6964 + .get_eeprom_len = dm9601_get_eeprom_len,
6965 + .get_eeprom = dm9601_get_eeprom,
6966 + .get_settings = usbnet_get_settings,
6967 + .set_settings = usbnet_set_settings,
6968 + .nway_reset = usbnet_nway_reset,
6969 +};
6970 +
6971 +static void dm9601_set_multicast(struct net_device *net)
6972 +{
6973 + struct usbnet *dev = netdev_priv(net);
6974 + /* We use the 20 byte dev->data for our 8 byte filter buffer
6975 + * to avoid allocating memory that is tricky to free later */
6976 + u8 *hashes = (u8 *) & dev->data;
6977 + u8 rx_ctl = 0x31;
6978 +
6979 + memset(hashes, 0x00, DM_MCAST_SIZE);
6980 + hashes[DM_MCAST_SIZE - 1] |= 0x80; /* broadcast address */
6981 +
6982 + if (net->flags & IFF_PROMISC) {
6983 + rx_ctl |= 0x02;
6984 + } else if (net->flags & IFF_ALLMULTI ||
6985 + netdev_mc_count(net) > DM_MAX_MCAST) {
6986 + rx_ctl |= 0x08;
6987 + } else if (!netdev_mc_empty(net)) {
6988 + struct netdev_hw_addr *ha;
6989 +
6990 + netdev_for_each_mc_addr(ha, net) {
6991 + u32 crc = ether_crc(ETH_ALEN, ha->addr) >> 26;
6992 + hashes[crc >> 3] |= 1 << (crc & 0x7);
6993 + }
6994 + }
6995 +
6996 + dm_write_async(dev, DM_MCAST_ADDR, DM_MCAST_SIZE, hashes);
6997 + dm_write_reg_async(dev, DM_RX_CTRL, rx_ctl);
6998 +}
6999 +
7000 +static void __dm9601_set_mac_address(struct usbnet *dev)
7001 +{
7002 + dm_write_async(dev, DM_PHY_ADDR, ETH_ALEN, dev->net->dev_addr);
7003 +}
7004 +
7005 +static int dm9601_set_mac_address(struct net_device *net, void *p)
7006 +{
7007 + struct sockaddr *addr = p;
7008 + struct usbnet *dev = netdev_priv(net);
7009 +
7010 + if (!is_valid_ether_addr(addr->sa_data)) {
7011 + dev_err(&net->dev, "not setting invalid mac address %pM\n",
7012 + addr->sa_data);
7013 + return -EINVAL;
7014 + }
7015 +
7016 + memcpy(net->dev_addr, addr->sa_data, net->addr_len);
7017 + __dm9601_set_mac_address(dev);
7018 +
7019 + return 0;
7020 +}
7021 +
7022 +static const struct net_device_ops dm9601_netdev_ops = {
7023 + .ndo_open = usbnet_open,
7024 + .ndo_stop = usbnet_stop,
7025 + .ndo_start_xmit = usbnet_start_xmit,
7026 + .ndo_tx_timeout = usbnet_tx_timeout,
7027 + .ndo_change_mtu = usbnet_change_mtu,
7028 + .ndo_validate_addr = eth_validate_addr,
7029 + .ndo_do_ioctl = dm9601_ioctl,
7030 + .ndo_set_rx_mode = dm9601_set_multicast,
7031 + .ndo_set_mac_address = dm9601_set_mac_address,
7032 +};
7033 +
7034 +static int dm9601_bind(struct usbnet *dev, struct usb_interface *intf)
7035 +{
7036 + int ret;
7037 + u8 mac[ETH_ALEN], id;
7038 +
7039 + ret = usbnet_get_endpoints(dev, intf);
7040 + if (ret)
7041 + goto out;
7042 +
7043 + dev->net->netdev_ops = &dm9601_netdev_ops;
7044 + dev->net->ethtool_ops = &dm9601_ethtool_ops;
7045 + dev->net->hard_header_len += DM_TX_OVERHEAD;
7046 + dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
7047 +
7048 + /* dm9620/21a require room for 4 byte padding, even in dm9601
7049 + * mode, so we need +1 to be able to receive full size
7050 + * ethernet frames.
7051 + */
7052 + dev->rx_urb_size = dev->net->mtu + ETH_HLEN + DM_RX_OVERHEAD + 1;
7053 +
7054 + dev->mii.dev = dev->net;
7055 + dev->mii.mdio_read = dm9601_mdio_read;
7056 + dev->mii.mdio_write = dm9601_mdio_write;
7057 + dev->mii.phy_id_mask = 0x1f;
7058 + dev->mii.reg_num_mask = 0x1f;
7059 +
7060 + /* reset */
7061 + dm_write_reg(dev, DM_NET_CTRL, 1);
7062 + udelay(20);
7063 +
7064 + /* read MAC */
7065 + if (dm_read(dev, DM_PHY_ADDR, ETH_ALEN, mac) < 0) {
7066 + printk(KERN_ERR "Error reading MAC address\n");
7067 + ret = -ENODEV;
7068 + goto out;
7069 + }
7070 +
7071 + /*
7072 + * Overwrite the auto-generated address only with good ones.
7073 + */
7074 + if (is_valid_ether_addr(mac))
7075 + memcpy(dev->net->dev_addr, mac, ETH_ALEN);
7076 + else {
7077 + printk(KERN_WARNING
7078 + "dm9601: No valid MAC address in EEPROM, using %pM\n",
7079 + dev->net->dev_addr);
7080 + __dm9601_set_mac_address(dev);
7081 + }
7082 +
7083 + if (dm_read_reg(dev, DM_CHIP_ID, &id) < 0) {
7084 + netdev_err(dev->net, "Error reading chip ID\n");
7085 + ret = -ENODEV;
7086 + goto out;
7087 + }
7088 +
7089 + /* put dm9620 devices in dm9601 mode */
7090 + if (id == ID_DM9620) {
7091 + u8 mode;
7092 +
7093 + if (dm_read_reg(dev, DM_MODE_CTRL, &mode) < 0) {
7094 + netdev_err(dev->net, "Error reading MODE_CTRL\n");
7095 + ret = -ENODEV;
7096 + goto out;
7097 + }
7098 + dm_write_reg(dev, DM_MODE_CTRL, mode & 0x7f);
7099 + }
7100 +
7101 + /* power up phy */
7102 + dm_write_reg(dev, DM_GPR_CTRL, 1);
7103 + dm_write_reg(dev, DM_GPR_DATA, 0);
7104 +
7105 + /* receive broadcast packets */
7106 + dm9601_set_multicast(dev->net);
7107 +
7108 + dm9601_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
7109 + dm9601_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
7110 + ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
7111 + mii_nway_restart(&dev->mii);
7112 +
7113 +out:
7114 + return ret;
7115 +}
7116 +
7117 +static int dm9601_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
7118 +{
7119 + u8 status;
7120 + int len;
7121 +
7122 + /* format:
7123 + b1: rx status
7124 + b2: packet length (incl crc) low
7125 + b3: packet length (incl crc) high
7126 + b4..n-4: packet data
7127 + bn-3..bn: ethernet crc
7128 + */
7129 +
7130 + if (unlikely(skb->len < DM_RX_OVERHEAD)) {
7131 + dev_err(&dev->udev->dev, "unexpected tiny rx frame\n");
7132 + return 0;
7133 + }
7134 +
7135 + status = skb->data[0];
7136 + len = (skb->data[1] | (skb->data[2] << 8)) - 4;
7137 +
7138 + if (unlikely(status & 0xbf)) {
7139 + if (status & 0x01) dev->net->stats.rx_fifo_errors++;
7140 + if (status & 0x02) dev->net->stats.rx_crc_errors++;
7141 + if (status & 0x04) dev->net->stats.rx_frame_errors++;
7142 + if (status & 0x20) dev->net->stats.rx_missed_errors++;
7143 + if (status & 0x90) dev->net->stats.rx_length_errors++;
7144 + return 0;
7145 + }
7146 +
7147 + skb_pull(skb, 3);
7148 + skb_trim(skb, len);
7149 +
7150 + return 1;
7151 +}
7152 +
7153 +static struct sk_buff *dm9601_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
7154 + gfp_t flags)
7155 +{
7156 + int len, pad;
7157 +
7158 + /* format:
7159 + b1: packet length low
7160 + b2: packet length high
7161 + b3..n: packet data
7162 + */
7163 +
7164 + len = skb->len + DM_TX_OVERHEAD;
7165 +
7166 + /* workaround for dm962x errata with tx fifo getting out of
7167 + * sync if a USB bulk transfer retry happens right after a
7168 + * packet with odd / maxpacket length by adding up to 3 bytes
7169 + * padding.
7170 + */
7171 + while ((len & 1) || !(len % dev->maxpacket))
7172 + len++;
7173 +
7174 + len -= DM_TX_OVERHEAD; /* hw header doesn't count as part of length */
7175 + pad = len - skb->len;
7176 +
7177 + if (skb_headroom(skb) < DM_TX_OVERHEAD || skb_tailroom(skb) < pad) {
7178 + struct sk_buff *skb2;
7179 +
7180 + skb2 = skb_copy_expand(skb, DM_TX_OVERHEAD, pad, flags);
7181 + dev_kfree_skb_any(skb);
7182 + skb = skb2;
7183 + if (!skb)
7184 + return NULL;
7185 + }
7186 +
7187 + __skb_push(skb, DM_TX_OVERHEAD);
7188 +
7189 + if (pad) {
7190 + memset(skb->data + skb->len, 0, pad);
7191 + __skb_put(skb, pad);
7192 + }
7193 +
7194 + skb->data[0] = len;
7195 + skb->data[1] = len >> 8;
7196 +
7197 + return skb;
7198 +}
7199 +
7200 +static void dm9601_status(struct usbnet *dev, struct urb *urb)
7201 +{
7202 + int link;
7203 + u8 *buf;
7204 +
7205 + /* format:
7206 + b0: net status
7207 + b1: tx status 1
7208 + b2: tx status 2
7209 + b3: rx status
7210 + b4: rx overflow
7211 + b5: rx count
7212 + b6: tx count
7213 + b7: gpr
7214 + */
7215 +
7216 + if (urb->actual_length < 8)
7217 + return;
7218 +
7219 + buf = urb->transfer_buffer;
7220 +
7221 + link = !!(buf[0] & 0x40);
7222 + if (netif_carrier_ok(dev->net) != link) {
7223 + usbnet_link_change(dev, link, 1);
7224 + netdev_dbg(dev->net, "Link Status is: %d\n", link);
7225 + }
7226 +}
7227 +
7228 +static int dm9601_link_reset(struct usbnet *dev)
7229 +{
7230 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
7231 +
7232 + mii_check_media(&dev->mii, 1, 1);
7233 + mii_ethtool_gset(&dev->mii, &ecmd);
7234 +
7235 + netdev_dbg(dev->net, "link_reset() speed: %u duplex: %d\n",
7236 + ethtool_cmd_speed(&ecmd), ecmd.duplex);
7237 +
7238 + return 0;
7239 +}
7240 +
7241 +static const struct driver_info dm9601_info = {
7242 + .description = "Davicom DM96xx USB 10/100 Ethernet",
7243 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
7244 + .bind = dm9601_bind,
7245 + .rx_fixup = dm9601_rx_fixup,
7246 + .tx_fixup = dm9601_tx_fixup,
7247 + .status = dm9601_status,
7248 + .link_reset = dm9601_link_reset,
7249 + .reset = dm9601_link_reset,
7250 +};
7251 +
7252 +static const struct usb_device_id products[] = {
7253 + {
7254 + USB_DEVICE(0x07aa, 0x9601), /* Corega FEther USB-TXC */
7255 + .driver_info = (unsigned long)&dm9601_info,
7256 + },
7257 + {
7258 + USB_DEVICE(0x0a46, 0x9601), /* Davicom USB-100 */
7259 + .driver_info = (unsigned long)&dm9601_info,
7260 + },
7261 + {
7262 + USB_DEVICE(0x0a46, 0x6688), /* ZT6688 USB NIC */
7263 + .driver_info = (unsigned long)&dm9601_info,
7264 + },
7265 + {
7266 + USB_DEVICE(0x0a46, 0x0268), /* ShanTou ST268 USB NIC */
7267 + .driver_info = (unsigned long)&dm9601_info,
7268 + },
7269 + {
7270 + USB_DEVICE(0x0a46, 0x8515), /* ADMtek ADM8515 USB NIC */
7271 + .driver_info = (unsigned long)&dm9601_info,
7272 + },
7273 + {
7274 + USB_DEVICE(0x0a47, 0x9601), /* Hirose USB-100 */
7275 + .driver_info = (unsigned long)&dm9601_info,
7276 + },
7277 + {
7278 + USB_DEVICE(0x0fe6, 0x8101), /* DM9601 USB to Fast Ethernet Adapter */
7279 + .driver_info = (unsigned long)&dm9601_info,
7280 + },
7281 + {
7282 + USB_DEVICE(0x0fe6, 0x9700), /* DM9601 USB to Fast Ethernet Adapter */
7283 + .driver_info = (unsigned long)&dm9601_info,
7284 + },
7285 + {
7286 + USB_DEVICE(0x0a46, 0x9000), /* DM9000E */
7287 + .driver_info = (unsigned long)&dm9601_info,
7288 + },
7289 + {
7290 + USB_DEVICE(0x0a46, 0x9620), /* DM9620 USB to Fast Ethernet Adapter */
7291 + .driver_info = (unsigned long)&dm9601_info,
7292 + },
7293 + {
7294 + USB_DEVICE(0x0a46, 0x9621), /* DM9621A USB to Fast Ethernet Adapter */
7295 + .driver_info = (unsigned long)&dm9601_info,
7296 + },
7297 + {
7298 + USB_DEVICE(0x0a46, 0x9622), /* DM9622 USB to Fast Ethernet Adapter */
7299 + .driver_info = (unsigned long)&dm9601_info,
7300 + },
7301 + {
7302 + USB_DEVICE(0x0a46, 0x0269), /* DM962OA USB to Fast Ethernet Adapter */
7303 + .driver_info = (unsigned long)&dm9601_info,
7304 + },
7305 + {
7306 + USB_DEVICE(0x0a46, 0x1269), /* DM9621A USB to Fast Ethernet Adapter */
7307 + .driver_info = (unsigned long)&dm9601_info,
7308 + },
7309 + {}, // END
7310 +};
7311 +
7312 +MODULE_DEVICE_TABLE(usb, products);
7313 +
7314 +static struct usb_driver dm9601_driver = {
7315 + .name = "dm9601",
7316 + .id_table = products,
7317 + .probe = usbnet_probe,
7318 + .disconnect = usbnet_disconnect,
7319 + .suspend = usbnet_suspend,
7320 + .resume = usbnet_resume,
7321 + .disable_hub_initiated_lpm = 1,
7322 +};
7323 +
7324 +module_usb_driver(dm9601_driver);
7325 +
7326 +MODULE_AUTHOR("Peter Korsgaard <jacmet@sunsite.dk>");
7327 +MODULE_DESCRIPTION("Davicom DM96xx USB 10/100 ethernet devices");
7328 +MODULE_LICENSE("GPL");
7329 diff -Naur backports-4.2.6-1.org/drivers/net/usb/gl620a.c backports-4.2.6-1/drivers/net/usb/gl620a.c
7330 --- backports-4.2.6-1.org/drivers/net/usb/gl620a.c 1970-01-01 01:00:00.000000000 +0100
7331 +++ backports-4.2.6-1/drivers/net/usb/gl620a.c 2016-06-28 14:35:17.978640554 +0200
7332 @@ -0,0 +1,242 @@
7333 +/*
7334 + * GeneSys GL620USB-A based links
7335 + * Copyright (C) 2001 by Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
7336 + * Copyright (C) 2001 by Stanislav Brabec <utx@penguin.cz>
7337 + *
7338 + * This program is free software; you can redistribute it and/or modify
7339 + * it under the terms of the GNU General Public License as published by
7340 + * the Free Software Foundation; either version 2 of the License, or
7341 + * (at your option) any later version.
7342 + *
7343 + * This program is distributed in the hope that it will be useful,
7344 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7345 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7346 + * GNU General Public License for more details.
7347 + *
7348 + * You should have received a copy of the GNU General Public License
7349 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
7350 + */
7351 +
7352 +// #define DEBUG // error path messages, extra info
7353 +// #define VERBOSE // more; success messages
7354 +
7355 +#include <linux/module.h>
7356 +#include <linux/netdevice.h>
7357 +#include <linux/etherdevice.h>
7358 +#include <linux/ethtool.h>
7359 +#include <linux/workqueue.h>
7360 +#include <linux/mii.h>
7361 +#include <linux/usb.h>
7362 +#include <linux/usb/usbnet.h>
7363 +#include <linux/gfp.h>
7364 +
7365 +
7366 +/*
7367 + * GeneSys GL620USB-A (www.genesyslogic.com.tw)
7368 + *
7369 + * ... should partially interop with the Win32 driver for this hardware.
7370 + * The GeneSys docs imply there's some NDIS issue motivating this framing.
7371 + *
7372 + * Some info from GeneSys:
7373 + * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
7374 + * (Some cables, like the BAFO-100c, use the half duplex version.)
7375 + * - For the full duplex model, the low bit of the version code says
7376 + * which side is which ("left/right").
7377 + * - For the half duplex type, a control/interrupt handshake settles
7378 + * the transfer direction. (That's disabled here, partially coded.)
7379 + * A control URB would block until other side writes an interrupt.
7380 + *
7381 + * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
7382 + * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
7383 + */
7384 +
7385 +// control msg write command
7386 +#define GENELINK_CONNECT_WRITE 0xF0
7387 +// interrupt pipe index
7388 +#define GENELINK_INTERRUPT_PIPE 0x03
7389 +// interrupt read buffer size
7390 +#define INTERRUPT_BUFSIZE 0x08
7391 +// interrupt pipe interval value
7392 +#define GENELINK_INTERRUPT_INTERVAL 0x10
7393 +// max transmit packet number per transmit
7394 +#define GL_MAX_TRANSMIT_PACKETS 32
7395 +// max packet length
7396 +#define GL_MAX_PACKET_LEN 1514
7397 +// max receive buffer size
7398 +#define GL_RCV_BUF_SIZE \
7399 + (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
7400 +
7401 +struct gl_packet {
7402 + __le32 packet_length;
7403 + char packet_data [1];
7404 +};
7405 +
7406 +struct gl_header {
7407 + __le32 packet_count;
7408 + struct gl_packet packets;
7409 +};
7410 +
7411 +static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
7412 +{
7413 + struct gl_header *header;
7414 + struct gl_packet *packet;
7415 + struct sk_buff *gl_skb;
7416 + u32 size;
7417 + u32 count;
7418 +
7419 + /* This check is no longer done by usbnet */
7420 + if (skb->len < dev->net->hard_header_len)
7421 + return 0;
7422 +
7423 + header = (struct gl_header *) skb->data;
7424 +
7425 + // get the packet count of the received skb
7426 + count = le32_to_cpu(header->packet_count);
7427 + if (count > GL_MAX_TRANSMIT_PACKETS) {
7428 + netdev_dbg(dev->net,
7429 + "genelink: invalid received packet count %u\n",
7430 + count);
7431 + return 0;
7432 + }
7433 +
7434 + // set the current packet pointer to the first packet
7435 + packet = &header->packets;
7436 +
7437 + // decrement the length for the packet count size 4 bytes
7438 + skb_pull(skb, 4);
7439 +
7440 + while (count > 1) {
7441 + // get the packet length
7442 + size = le32_to_cpu(packet->packet_length);
7443 +
7444 + // this may be a broken packet
7445 + if (size > GL_MAX_PACKET_LEN) {
7446 + netdev_dbg(dev->net, "genelink: invalid rx length %d\n",
7447 + size);
7448 + return 0;
7449 + }
7450 +
7451 + // allocate the skb for the individual packet
7452 + gl_skb = alloc_skb(size, GFP_ATOMIC);
7453 + if (gl_skb) {
7454 +
7455 + // copy the packet data to the new skb
7456 + memcpy(skb_put(gl_skb, size),
7457 + packet->packet_data, size);
7458 + usbnet_skb_return(dev, gl_skb);
7459 + }
7460 +
7461 + // advance to the next packet
7462 + packet = (struct gl_packet *)&packet->packet_data[size];
7463 + count--;
7464 +
7465 + // shift the data pointer to the next gl_packet
7466 + skb_pull(skb, size + 4);
7467 + }
7468 +
7469 + // skip the packet length field 4 bytes
7470 + skb_pull(skb, 4);
7471 +
7472 + if (skb->len > GL_MAX_PACKET_LEN) {
7473 + netdev_dbg(dev->net, "genelink: invalid rx length %d\n",
7474 + skb->len);
7475 + return 0;
7476 + }
7477 + return 1;
7478 +}
7479 +
7480 +static struct sk_buff *
7481 +genelink_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
7482 +{
7483 + int padlen;
7484 + int length = skb->len;
7485 + int headroom = skb_headroom(skb);
7486 + int tailroom = skb_tailroom(skb);
7487 + __le32 *packet_count;
7488 + __le32 *packet_len;
7489 +
7490 + // FIXME: magic numbers, bleech
7491 + padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
7492 +
7493 + if ((!skb_cloned(skb))
7494 + && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
7495 + if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
7496 + skb->data = memmove(skb->head + (4 + 4*1),
7497 + skb->data, skb->len);
7498 + skb_set_tail_pointer(skb, skb->len);
7499 + }
7500 + } else {
7501 + struct sk_buff *skb2;
7502 + skb2 = skb_copy_expand(skb, (4 + 4*1) , padlen, flags);
7503 + dev_kfree_skb_any(skb);
7504 + skb = skb2;
7505 + if (!skb)
7506 + return NULL;
7507 + }
7508 +
7509 + // attach the packet count to the header
7510 + packet_count = (__le32 *) skb_push(skb, (4 + 4*1));
7511 + packet_len = packet_count + 1;
7512 +
7513 + *packet_count = cpu_to_le32(1);
7514 + *packet_len = cpu_to_le32(length);
7515 +
7516 + // add padding byte
7517 + if ((skb->len % dev->maxpacket) == 0)
7518 + skb_put(skb, 1);
7519 +
7520 + return skb;
7521 +}
7522 +
7523 +static int genelink_bind(struct usbnet *dev, struct usb_interface *intf)
7524 +{
7525 + dev->hard_mtu = GL_RCV_BUF_SIZE;
7526 + dev->net->hard_header_len += 4;
7527 + dev->in = usb_rcvbulkpipe(dev->udev, dev->driver_info->in);
7528 + dev->out = usb_sndbulkpipe(dev->udev, dev->driver_info->out);
7529 + return 0;
7530 +}
7531 +
7532 +static const struct driver_info genelink_info = {
7533 + .description = "Genesys GeneLink",
7534 + .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_GL | FLAG_NO_SETINT,
7535 + .bind = genelink_bind,
7536 + .rx_fixup = genelink_rx_fixup,
7537 + .tx_fixup = genelink_tx_fixup,
7538 +
7539 + .in = 1, .out = 2,
7540 +
7541 +#ifdef GENELINK_ACK
7542 + .check_connect =genelink_check_connect,
7543 +#endif
7544 +};
7545 +
7546 +static const struct usb_device_id products [] = {
7547 +
7548 +{
7549 + USB_DEVICE(0x05e3, 0x0502), // GL620USB-A
7550 + .driver_info = (unsigned long) &genelink_info,
7551 +},
7552 + /* NOT: USB_DEVICE(0x05e3, 0x0501), // GL620USB
7553 + * that's half duplex, not currently supported
7554 + */
7555 + { }, // END
7556 +};
7557 +MODULE_DEVICE_TABLE(usb, products);
7558 +
7559 +static struct usb_driver gl620a_driver = {
7560 + .name = "gl620a",
7561 + .id_table = products,
7562 + .probe = usbnet_probe,
7563 + .disconnect = usbnet_disconnect,
7564 + .suspend = usbnet_suspend,
7565 + .resume = usbnet_resume,
7566 + .disable_hub_initiated_lpm = 1,
7567 +};
7568 +
7569 +module_usb_driver(gl620a_driver);
7570 +
7571 +MODULE_AUTHOR("Jiun-Jie Huang");
7572 +MODULE_DESCRIPTION("GL620-USB-A Host-to-Host Link cables");
7573 +MODULE_LICENSE("GPL");
7574 +
7575 diff -Naur backports-4.2.6-1.org/drivers/net/usb/hso.c backports-4.2.6-1/drivers/net/usb/hso.c
7576 --- backports-4.2.6-1.org/drivers/net/usb/hso.c 1970-01-01 01:00:00.000000000 +0100
7577 +++ backports-4.2.6-1/drivers/net/usb/hso.c 2016-06-28 14:35:17.981973887 +0200
7578 @@ -0,0 +1,3322 @@
7579 +/******************************************************************************
7580 + *
7581 + * Driver for Option High Speed Mobile Devices.
7582 + *
7583 + * Copyright (C) 2008 Option International
7584 + * Filip Aben <f.aben@option.com>
7585 + * Denis Joseph Barrow <d.barow@option.com>
7586 + * Jan Dumon <j.dumon@option.com>
7587 + * Copyright (C) 2007 Andrew Bird (Sphere Systems Ltd)
7588 + * <ajb@spheresystems.co.uk>
7589 + * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de>
7590 + * Copyright (C) 2008 Novell, Inc.
7591 + *
7592 + * This program is free software; you can redistribute it and/or modify
7593 + * it under the terms of the GNU General Public License version 2 as
7594 + * published by the Free Software Foundation.
7595 + *
7596 + * This program is distributed in the hope that it will be useful,
7597 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7598 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7599 + * GNU General Public License for more details.
7600 + *
7601 + * You should have received a copy of the GNU General Public License
7602 + * along with this program; if not, write to the Free Software
7603 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
7604 + * USA
7605 + *
7606 + *
7607 + *****************************************************************************/
7608 +
7609 +/******************************************************************************
7610 + *
7611 + * Description of the device:
7612 + *
7613 + * Interface 0: Contains the IP network interface on the bulk end points.
7614 + * The multiplexed serial ports are using the interrupt and
7615 + * control endpoints.
7616 + * Interrupt contains a bitmap telling which multiplexed
7617 + * serialport needs servicing.
7618 + *
7619 + * Interface 1: Diagnostics port, uses bulk only, do not submit urbs until the
7620 + * port is opened, as this have a huge impact on the network port
7621 + * throughput.
7622 + *
7623 + * Interface 2: Standard modem interface - circuit switched interface, this
7624 + * can be used to make a standard ppp connection however it
7625 + * should not be used in conjunction with the IP network interface
7626 + * enabled for USB performance reasons i.e. if using this set
7627 + * ideally disable_net=1.
7628 + *
7629 + *****************************************************************************/
7630 +
7631 +#include <linux/sched.h>
7632 +#include <linux/slab.h>
7633 +#include <linux/init.h>
7634 +#include <linux/delay.h>
7635 +#include <linux/netdevice.h>
7636 +#include <linux/module.h>
7637 +#include <linux/ethtool.h>
7638 +#include <linux/usb.h>
7639 +#include <linux/tty.h>
7640 +#include <linux/tty_driver.h>
7641 +#include <linux/tty_flip.h>
7642 +#include <linux/kmod.h>
7643 +#include <linux/rfkill.h>
7644 +#include <linux/ip.h>
7645 +#include <linux/uaccess.h>
7646 +#include <linux/usb/cdc.h>
7647 +#include <net/arp.h>
7648 +#include <asm/byteorder.h>
7649 +#include <linux/serial_core.h>
7650 +#include <linux/serial.h>
7651 +#include <asm/local.h>
7652 +
7653 +#define MOD_AUTHOR "Option Wireless"
7654 +#define MOD_DESCRIPTION "USB High Speed Option driver"
7655 +#define MOD_LICENSE "GPL"
7656 +
7657 +#define HSO_MAX_NET_DEVICES 10
7658 +#define HSO__MAX_MTU 2048
7659 +#define DEFAULT_MTU 1500
7660 +#define DEFAULT_MRU 1500
7661 +
7662 +#define CTRL_URB_RX_SIZE 1024
7663 +#define CTRL_URB_TX_SIZE 64
7664 +
7665 +#define BULK_URB_RX_SIZE 4096
7666 +#define BULK_URB_TX_SIZE 8192
7667 +
7668 +#define MUX_BULK_RX_BUF_SIZE HSO__MAX_MTU
7669 +#define MUX_BULK_TX_BUF_SIZE HSO__MAX_MTU
7670 +#define MUX_BULK_RX_BUF_COUNT 4
7671 +#define USB_TYPE_OPTION_VENDOR 0x20
7672 +
7673 +/* These definitions are used with the struct hso_net flags element */
7674 +/* - use *_bit operations on it. (bit indices not values.) */
7675 +#define HSO_NET_RUNNING 0
7676 +
7677 +#define HSO_NET_TX_TIMEOUT (HZ*10)
7678 +
7679 +#define HSO_SERIAL_MAGIC 0x48534f31
7680 +
7681 +/* Number of ttys to handle */
7682 +#define HSO_SERIAL_TTY_MINORS 256
7683 +
7684 +#define MAX_RX_URBS 2
7685 +
7686 +/*****************************************************************************/
7687 +/* Debugging functions */
7688 +/*****************************************************************************/
7689 +#define D__(lvl_, fmt, arg...) \
7690 + do { \
7691 + printk(lvl_ "[%d:%s]: " fmt "\n", \
7692 + __LINE__, __func__, ## arg); \
7693 + } while (0)
7694 +
7695 +#define D_(lvl, args...) \
7696 + do { \
7697 + if (lvl & debug) \
7698 + D__(KERN_INFO, args); \
7699 + } while (0)
7700 +
7701 +#define D1(args...) D_(0x01, ##args)
7702 +#define D2(args...) D_(0x02, ##args)
7703 +#define D3(args...) D_(0x04, ##args)
7704 +#define D4(args...) D_(0x08, ##args)
7705 +#define D5(args...) D_(0x10, ##args)
7706 +
7707 +/*****************************************************************************/
7708 +/* Enumerators */
7709 +/*****************************************************************************/
7710 +enum pkt_parse_state {
7711 + WAIT_IP,
7712 + WAIT_DATA,
7713 + WAIT_SYNC
7714 +};
7715 +
7716 +/*****************************************************************************/
7717 +/* Structs */
7718 +/*****************************************************************************/
7719 +
7720 +struct hso_shared_int {
7721 + struct usb_endpoint_descriptor *intr_endp;
7722 + void *shared_intr_buf;
7723 + struct urb *shared_intr_urb;
7724 + struct usb_device *usb;
7725 + int use_count;
7726 + int ref_count;
7727 + struct mutex shared_int_lock;
7728 +};
7729 +
7730 +struct hso_net {
7731 + struct hso_device *parent;
7732 + struct net_device *net;
7733 + struct rfkill *rfkill;
7734 + char name[24];
7735 +
7736 + struct usb_endpoint_descriptor *in_endp;
7737 + struct usb_endpoint_descriptor *out_endp;
7738 +
7739 + struct urb *mux_bulk_rx_urb_pool[MUX_BULK_RX_BUF_COUNT];
7740 + struct urb *mux_bulk_tx_urb;
7741 + void *mux_bulk_rx_buf_pool[MUX_BULK_RX_BUF_COUNT];
7742 + void *mux_bulk_tx_buf;
7743 +
7744 + struct sk_buff *skb_rx_buf;
7745 + struct sk_buff *skb_tx_buf;
7746 +
7747 + enum pkt_parse_state rx_parse_state;
7748 + spinlock_t net_lock;
7749 +
7750 + unsigned short rx_buf_size;
7751 + unsigned short rx_buf_missing;
7752 + struct iphdr rx_ip_hdr;
7753 +
7754 + unsigned long flags;
7755 +};
7756 +
7757 +enum rx_ctrl_state{
7758 + RX_IDLE,
7759 + RX_SENT,
7760 + RX_PENDING
7761 +};
7762 +
7763 +#define BM_REQUEST_TYPE (0xa1)
7764 +#define B_NOTIFICATION (0x20)
7765 +#define W_VALUE (0x0)
7766 +#define W_LENGTH (0x2)
7767 +
7768 +#define B_OVERRUN (0x1<<6)
7769 +#define B_PARITY (0x1<<5)
7770 +#define B_FRAMING (0x1<<4)
7771 +#define B_RING_SIGNAL (0x1<<3)
7772 +#define B_BREAK (0x1<<2)
7773 +#define B_TX_CARRIER (0x1<<1)
7774 +#define B_RX_CARRIER (0x1<<0)
7775 +
7776 +struct hso_serial_state_notification {
7777 + u8 bmRequestType;
7778 + u8 bNotification;
7779 + u16 wValue;
7780 + u16 wIndex;
7781 + u16 wLength;
7782 + u16 UART_state_bitmap;
7783 +} __packed;
7784 +
7785 +struct hso_tiocmget {
7786 + struct mutex mutex;
7787 + wait_queue_head_t waitq;
7788 + int intr_completed;
7789 + struct usb_endpoint_descriptor *endp;
7790 + struct urb *urb;
7791 + struct hso_serial_state_notification serial_state_notification;
7792 + u16 prev_UART_state_bitmap;
7793 + struct uart_icount icount;
7794 +};
7795 +
7796 +
7797 +struct hso_serial {
7798 + struct hso_device *parent;
7799 + int magic;
7800 + u8 minor;
7801 +
7802 + struct hso_shared_int *shared_int;
7803 +
7804 + /* rx/tx urb could be either a bulk urb or a control urb depending
7805 + on which serial port it is used on. */
7806 + struct urb *rx_urb[MAX_RX_URBS];
7807 + u8 num_rx_urbs;
7808 + u8 *rx_data[MAX_RX_URBS];
7809 + u16 rx_data_length; /* should contain allocated length */
7810 +
7811 + struct urb *tx_urb;
7812 + u8 *tx_data;
7813 + u8 *tx_buffer;
7814 + u16 tx_data_length; /* should contain allocated length */
7815 + u16 tx_data_count;
7816 + u16 tx_buffer_count;
7817 + struct usb_ctrlrequest ctrl_req_tx;
7818 + struct usb_ctrlrequest ctrl_req_rx;
7819 +
7820 + struct usb_endpoint_descriptor *in_endp;
7821 + struct usb_endpoint_descriptor *out_endp;
7822 +
7823 + enum rx_ctrl_state rx_state;
7824 + u8 rts_state;
7825 + u8 dtr_state;
7826 + unsigned tx_urb_used:1;
7827 +
7828 + struct tty_port port;
7829 + /* from usb_serial_port */
7830 + spinlock_t serial_lock;
7831 +
7832 + int (*write_data) (struct hso_serial *serial);
7833 + struct hso_tiocmget *tiocmget;
7834 + /* Hacks required to get flow control
7835 + * working on the serial receive buffers
7836 + * so as not to drop characters on the floor.
7837 + */
7838 + int curr_rx_urb_idx;
7839 + u8 rx_urb_filled[MAX_RX_URBS];
7840 + struct tasklet_struct unthrottle_tasklet;
7841 +};
7842 +
7843 +struct hso_device {
7844 + union {
7845 + struct hso_serial *dev_serial;
7846 + struct hso_net *dev_net;
7847 + } port_data;
7848 +
7849 + u32 port_spec;
7850 +
7851 + u8 is_active;
7852 + u8 usb_gone;
7853 + struct work_struct async_get_intf;
7854 + struct work_struct async_put_intf;
7855 +
7856 + struct usb_device *usb;
7857 + struct usb_interface *interface;
7858 +
7859 + struct device *dev;
7860 + struct kref ref;
7861 + struct mutex mutex;
7862 +};
7863 +
7864 +/* Type of interface */
7865 +#define HSO_INTF_MASK 0xFF00
7866 +#define HSO_INTF_MUX 0x0100
7867 +#define HSO_INTF_BULK 0x0200
7868 +
7869 +/* Type of port */
7870 +#define HSO_PORT_MASK 0xFF
7871 +#define HSO_PORT_NO_PORT 0x0
7872 +#define HSO_PORT_CONTROL 0x1
7873 +#define HSO_PORT_APP 0x2
7874 +#define HSO_PORT_GPS 0x3
7875 +#define HSO_PORT_PCSC 0x4
7876 +#define HSO_PORT_APP2 0x5
7877 +#define HSO_PORT_GPS_CONTROL 0x6
7878 +#define HSO_PORT_MSD 0x7
7879 +#define HSO_PORT_VOICE 0x8
7880 +#define HSO_PORT_DIAG2 0x9
7881 +#define HSO_PORT_DIAG 0x10
7882 +#define HSO_PORT_MODEM 0x11
7883 +#define HSO_PORT_NETWORK 0x12
7884 +
7885 +/* Additional device info */
7886 +#define HSO_INFO_MASK 0xFF000000
7887 +#define HSO_INFO_CRC_BUG 0x01000000
7888 +
7889 +/*****************************************************************************/
7890 +/* Prototypes */
7891 +/*****************************************************************************/
7892 +/* Serial driver functions */
7893 +static int hso_serial_tiocmset(struct tty_struct *tty,
7894 + unsigned int set, unsigned int clear);
7895 +static void ctrl_callback(struct urb *urb);
7896 +static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial);
7897 +static void hso_kick_transmit(struct hso_serial *serial);
7898 +/* Helper functions */
7899 +static int hso_mux_submit_intr_urb(struct hso_shared_int *mux_int,
7900 + struct usb_device *usb, gfp_t gfp);
7901 +static void handle_usb_error(int status, const char *function,
7902 + struct hso_device *hso_dev);
7903 +static struct usb_endpoint_descriptor *hso_get_ep(struct usb_interface *intf,
7904 + int type, int dir);
7905 +static int hso_get_mux_ports(struct usb_interface *intf, unsigned char *ports);
7906 +static void hso_free_interface(struct usb_interface *intf);
7907 +static int hso_start_serial_device(struct hso_device *hso_dev, gfp_t flags);
7908 +static int hso_stop_serial_device(struct hso_device *hso_dev);
7909 +static int hso_start_net_device(struct hso_device *hso_dev);
7910 +static void hso_free_shared_int(struct hso_shared_int *shared_int);
7911 +static int hso_stop_net_device(struct hso_device *hso_dev);
7912 +static void hso_serial_ref_free(struct kref *ref);
7913 +static void hso_std_serial_read_bulk_callback(struct urb *urb);
7914 +static int hso_mux_serial_read(struct hso_serial *serial);
7915 +static void async_get_intf(struct work_struct *data);
7916 +static void async_put_intf(struct work_struct *data);
7917 +static int hso_put_activity(struct hso_device *hso_dev);
7918 +static int hso_get_activity(struct hso_device *hso_dev);
7919 +static void tiocmget_intr_callback(struct urb *urb);
7920 +/*****************************************************************************/
7921 +/* Helping functions */
7922 +/*****************************************************************************/
7923 +
7924 +/* #define DEBUG */
7925 +
7926 +static inline struct hso_net *dev2net(struct hso_device *hso_dev)
7927 +{
7928 + return hso_dev->port_data.dev_net;
7929 +}
7930 +
7931 +static inline struct hso_serial *dev2ser(struct hso_device *hso_dev)
7932 +{
7933 + return hso_dev->port_data.dev_serial;
7934 +}
7935 +
7936 +/* Debugging functions */
7937 +#ifdef DEBUG
7938 +static void dbg_dump(int line_count, const char *func_name, unsigned char *buf,
7939 + unsigned int len)
7940 +{
7941 + static char name[255];
7942 +
7943 + sprintf(name, "hso[%d:%s]", line_count, func_name);
7944 + print_hex_dump_bytes(name, DUMP_PREFIX_NONE, buf, len);
7945 +}
7946 +
7947 +#define DUMP(buf_, len_) \
7948 + dbg_dump(__LINE__, __func__, (unsigned char *)buf_, len_)
7949 +
7950 +#define DUMP1(buf_, len_) \
7951 + do { \
7952 + if (0x01 & debug) \
7953 + DUMP(buf_, len_); \
7954 + } while (0)
7955 +#else
7956 +#define DUMP(buf_, len_)
7957 +#define DUMP1(buf_, len_)
7958 +#endif
7959 +
7960 +/* module parameters */
7961 +static int debug;
7962 +static int tty_major;
7963 +static int disable_net;
7964 +
7965 +/* driver info */
7966 +static const char driver_name[] = "hso";
7967 +static const char tty_filename[] = "ttyHS";
7968 +static const char *version = __FILE__ ": " MOD_AUTHOR;
7969 +/* the usb driver itself (registered in hso_init) */
7970 +static struct usb_driver hso_driver;
7971 +/* serial structures */
7972 +static struct tty_driver *tty_drv;
7973 +static struct hso_device *serial_table[HSO_SERIAL_TTY_MINORS];
7974 +static struct hso_device *network_table[HSO_MAX_NET_DEVICES];
7975 +static spinlock_t serial_table_lock;
7976 +
7977 +static const s32 default_port_spec[] = {
7978 + HSO_INTF_MUX | HSO_PORT_NETWORK,
7979 + HSO_INTF_BULK | HSO_PORT_DIAG,
7980 + HSO_INTF_BULK | HSO_PORT_MODEM,
7981 + 0
7982 +};
7983 +
7984 +static const s32 icon321_port_spec[] = {
7985 + HSO_INTF_MUX | HSO_PORT_NETWORK,
7986 + HSO_INTF_BULK | HSO_PORT_DIAG2,
7987 + HSO_INTF_BULK | HSO_PORT_MODEM,
7988 + HSO_INTF_BULK | HSO_PORT_DIAG,
7989 + 0
7990 +};
7991 +
7992 +#define default_port_device(vendor, product) \
7993 + USB_DEVICE(vendor, product), \
7994 + .driver_info = (kernel_ulong_t)default_port_spec
7995 +
7996 +#define icon321_port_device(vendor, product) \
7997 + USB_DEVICE(vendor, product), \
7998 + .driver_info = (kernel_ulong_t)icon321_port_spec
7999 +
8000 +/* list of devices we support */
8001 +static const struct usb_device_id hso_ids[] = {
8002 + {default_port_device(0x0af0, 0x6711)},
8003 + {default_port_device(0x0af0, 0x6731)},
8004 + {default_port_device(0x0af0, 0x6751)},
8005 + {default_port_device(0x0af0, 0x6771)},
8006 + {default_port_device(0x0af0, 0x6791)},
8007 + {default_port_device(0x0af0, 0x6811)},
8008 + {default_port_device(0x0af0, 0x6911)},
8009 + {default_port_device(0x0af0, 0x6951)},
8010 + {default_port_device(0x0af0, 0x6971)},
8011 + {default_port_device(0x0af0, 0x7011)},
8012 + {default_port_device(0x0af0, 0x7031)},
8013 + {default_port_device(0x0af0, 0x7051)},
8014 + {default_port_device(0x0af0, 0x7071)},
8015 + {default_port_device(0x0af0, 0x7111)},
8016 + {default_port_device(0x0af0, 0x7211)},
8017 + {default_port_device(0x0af0, 0x7251)},
8018 + {default_port_device(0x0af0, 0x7271)},
8019 + {default_port_device(0x0af0, 0x7311)},
8020 + {default_port_device(0x0af0, 0xc031)}, /* Icon-Edge */
8021 + {icon321_port_device(0x0af0, 0xd013)}, /* Module HSxPA */
8022 + {icon321_port_device(0x0af0, 0xd031)}, /* Icon-321 */
8023 + {icon321_port_device(0x0af0, 0xd033)}, /* Icon-322 */
8024 + {USB_DEVICE(0x0af0, 0x7301)}, /* GE40x */
8025 + {USB_DEVICE(0x0af0, 0x7361)}, /* GE40x */
8026 + {USB_DEVICE(0x0af0, 0x7381)}, /* GE40x */
8027 + {USB_DEVICE(0x0af0, 0x7401)}, /* GI 0401 */
8028 + {USB_DEVICE(0x0af0, 0x7501)}, /* GTM 382 */
8029 + {USB_DEVICE(0x0af0, 0x7601)}, /* GE40x */
8030 + {USB_DEVICE(0x0af0, 0x7701)},
8031 + {USB_DEVICE(0x0af0, 0x7706)},
8032 + {USB_DEVICE(0x0af0, 0x7801)},
8033 + {USB_DEVICE(0x0af0, 0x7901)},
8034 + {USB_DEVICE(0x0af0, 0x7A01)},
8035 + {USB_DEVICE(0x0af0, 0x7A05)},
8036 + {USB_DEVICE(0x0af0, 0x8200)},
8037 + {USB_DEVICE(0x0af0, 0x8201)},
8038 + {USB_DEVICE(0x0af0, 0x8300)},
8039 + {USB_DEVICE(0x0af0, 0x8302)},
8040 + {USB_DEVICE(0x0af0, 0x8304)},
8041 + {USB_DEVICE(0x0af0, 0x8400)},
8042 + {USB_DEVICE(0x0af0, 0x8600)},
8043 + {USB_DEVICE(0x0af0, 0x8800)},
8044 + {USB_DEVICE(0x0af0, 0x8900)},
8045 + {USB_DEVICE(0x0af0, 0x9000)},
8046 + {USB_DEVICE(0x0af0, 0x9200)}, /* Option GTM671WFS */
8047 + {USB_DEVICE(0x0af0, 0xd035)},
8048 + {USB_DEVICE(0x0af0, 0xd055)},
8049 + {USB_DEVICE(0x0af0, 0xd155)},
8050 + {USB_DEVICE(0x0af0, 0xd255)},
8051 + {USB_DEVICE(0x0af0, 0xd057)},
8052 + {USB_DEVICE(0x0af0, 0xd157)},
8053 + {USB_DEVICE(0x0af0, 0xd257)},
8054 + {USB_DEVICE(0x0af0, 0xd357)},
8055 + {USB_DEVICE(0x0af0, 0xd058)},
8056 + {USB_DEVICE(0x0af0, 0xc100)},
8057 + {}
8058 +};
8059 +MODULE_DEVICE_TABLE(usb, hso_ids);
8060 +
8061 +/* Sysfs attribute */
8062 +static ssize_t hso_sysfs_show_porttype(struct device *dev,
8063 + struct device_attribute *attr,
8064 + char *buf)
8065 +{
8066 + struct hso_device *hso_dev = dev_get_drvdata(dev);
8067 + char *port_name;
8068 +
8069 + if (!hso_dev)
8070 + return 0;
8071 +
8072 + switch (hso_dev->port_spec & HSO_PORT_MASK) {
8073 + case HSO_PORT_CONTROL:
8074 + port_name = "Control";
8075 + break;
8076 + case HSO_PORT_APP:
8077 + port_name = "Application";
8078 + break;
8079 + case HSO_PORT_APP2:
8080 + port_name = "Application2";
8081 + break;
8082 + case HSO_PORT_GPS:
8083 + port_name = "GPS";
8084 + break;
8085 + case HSO_PORT_GPS_CONTROL:
8086 + port_name = "GPS Control";
8087 + break;
8088 + case HSO_PORT_PCSC:
8089 + port_name = "PCSC";
8090 + break;
8091 + case HSO_PORT_DIAG:
8092 + port_name = "Diagnostic";
8093 + break;
8094 + case HSO_PORT_DIAG2:
8095 + port_name = "Diagnostic2";
8096 + break;
8097 + case HSO_PORT_MODEM:
8098 + port_name = "Modem";
8099 + break;
8100 + case HSO_PORT_NETWORK:
8101 + port_name = "Network";
8102 + break;
8103 + default:
8104 + port_name = "Unknown";
8105 + break;
8106 + }
8107 +
8108 + return sprintf(buf, "%s\n", port_name);
8109 +}
8110 +static DEVICE_ATTR(hsotype, S_IRUGO, hso_sysfs_show_porttype, NULL);
8111 +
8112 +static struct attribute *hso_serial_dev_attrs[] = {
8113 + &dev_attr_hsotype.attr,
8114 + NULL
8115 +};
8116 +
8117 +ATTRIBUTE_GROUPS(hso_serial_dev);
8118 +
8119 +static int hso_urb_to_index(struct hso_serial *serial, struct urb *urb)
8120 +{
8121 + int idx;
8122 +
8123 + for (idx = 0; idx < serial->num_rx_urbs; idx++)
8124 + if (serial->rx_urb[idx] == urb)
8125 + return idx;
8126 + dev_err(serial->parent->dev, "hso_urb_to_index failed\n");
8127 + return -1;
8128 +}
8129 +
8130 +/* converts mux value to a port spec value */
8131 +static u32 hso_mux_to_port(int mux)
8132 +{
8133 + u32 result;
8134 +
8135 + switch (mux) {
8136 + case 0x1:
8137 + result = HSO_PORT_CONTROL;
8138 + break;
8139 + case 0x2:
8140 + result = HSO_PORT_APP;
8141 + break;
8142 + case 0x4:
8143 + result = HSO_PORT_PCSC;
8144 + break;
8145 + case 0x8:
8146 + result = HSO_PORT_GPS;
8147 + break;
8148 + case 0x10:
8149 + result = HSO_PORT_APP2;
8150 + break;
8151 + default:
8152 + result = HSO_PORT_NO_PORT;
8153 + }
8154 + return result;
8155 +}
8156 +
8157 +/* converts port spec value to a mux value */
8158 +static u32 hso_port_to_mux(int port)
8159 +{
8160 + u32 result;
8161 +
8162 + switch (port & HSO_PORT_MASK) {
8163 + case HSO_PORT_CONTROL:
8164 + result = 0x0;
8165 + break;
8166 + case HSO_PORT_APP:
8167 + result = 0x1;
8168 + break;
8169 + case HSO_PORT_PCSC:
8170 + result = 0x2;
8171 + break;
8172 + case HSO_PORT_GPS:
8173 + result = 0x3;
8174 + break;
8175 + case HSO_PORT_APP2:
8176 + result = 0x4;
8177 + break;
8178 + default:
8179 + result = 0x0;
8180 + }
8181 + return result;
8182 +}
8183 +
8184 +static struct hso_serial *get_serial_by_shared_int_and_type(
8185 + struct hso_shared_int *shared_int,
8186 + int mux)
8187 +{
8188 + int i, port;
8189 +
8190 + port = hso_mux_to_port(mux);
8191 +
8192 + for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
8193 + if (serial_table[i] &&
8194 + (dev2ser(serial_table[i])->shared_int == shared_int) &&
8195 + ((serial_table[i]->port_spec & HSO_PORT_MASK) == port)) {
8196 + return dev2ser(serial_table[i]);
8197 + }
8198 + }
8199 +
8200 + return NULL;
8201 +}
8202 +
8203 +static struct hso_serial *get_serial_by_index(unsigned index)
8204 +{
8205 + struct hso_serial *serial = NULL;
8206 + unsigned long flags;
8207 +
8208 + spin_lock_irqsave(&serial_table_lock, flags);
8209 + if (serial_table[index])
8210 + serial = dev2ser(serial_table[index]);
8211 + spin_unlock_irqrestore(&serial_table_lock, flags);
8212 +
8213 + return serial;
8214 +}
8215 +
8216 +static int get_free_serial_index(void)
8217 +{
8218 + int index;
8219 + unsigned long flags;
8220 +
8221 + spin_lock_irqsave(&serial_table_lock, flags);
8222 + for (index = 0; index < HSO_SERIAL_TTY_MINORS; index++) {
8223 + if (serial_table[index] == NULL) {
8224 + spin_unlock_irqrestore(&serial_table_lock, flags);
8225 + return index;
8226 + }
8227 + }
8228 + spin_unlock_irqrestore(&serial_table_lock, flags);
8229 +
8230 + printk(KERN_ERR "%s: no free serial devices in table\n", __func__);
8231 + return -1;
8232 +}
8233 +
8234 +static void set_serial_by_index(unsigned index, struct hso_serial *serial)
8235 +{
8236 + unsigned long flags;
8237 +
8238 + spin_lock_irqsave(&serial_table_lock, flags);
8239 + if (serial)
8240 + serial_table[index] = serial->parent;
8241 + else
8242 + serial_table[index] = NULL;
8243 + spin_unlock_irqrestore(&serial_table_lock, flags);
8244 +}
8245 +
8246 +static void handle_usb_error(int status, const char *function,
8247 + struct hso_device *hso_dev)
8248 +{
8249 + char *explanation;
8250 +
8251 + switch (status) {
8252 + case -ENODEV:
8253 + explanation = "no device";
8254 + break;
8255 + case -ENOENT:
8256 + explanation = "endpoint not enabled";
8257 + break;
8258 + case -EPIPE:
8259 + explanation = "endpoint stalled";
8260 + break;
8261 + case -ENOSPC:
8262 + explanation = "not enough bandwidth";
8263 + break;
8264 + case -ESHUTDOWN:
8265 + explanation = "device disabled";
8266 + break;
8267 + case -EHOSTUNREACH:
8268 + explanation = "device suspended";
8269 + break;
8270 + case -EINVAL:
8271 + case -EAGAIN:
8272 + case -EFBIG:
8273 + case -EMSGSIZE:
8274 + explanation = "internal error";
8275 + break;
8276 + case -EILSEQ:
8277 + case -EPROTO:
8278 + case -ETIME:
8279 + case -ETIMEDOUT:
8280 + explanation = "protocol error";
8281 + if (hso_dev)
8282 + usb_queue_reset_device(hso_dev->interface);
8283 + break;
8284 + default:
8285 + explanation = "unknown status";
8286 + break;
8287 + }
8288 +
8289 + /* log a meaningful explanation of an USB status */
8290 + D1("%s: received USB status - %s (%d)", function, explanation, status);
8291 +}
8292 +
8293 +/* Network interface functions */
8294 +
8295 +/* called when net interface is brought up by ifconfig */
8296 +static int hso_net_open(struct net_device *net)
8297 +{
8298 + struct hso_net *odev = netdev_priv(net);
8299 + unsigned long flags = 0;
8300 +
8301 + if (!odev) {
8302 + dev_err(&net->dev, "No net device !\n");
8303 + return -ENODEV;
8304 + }
8305 +
8306 + odev->skb_tx_buf = NULL;
8307 +
8308 + /* setup environment */
8309 + spin_lock_irqsave(&odev->net_lock, flags);
8310 + odev->rx_parse_state = WAIT_IP;
8311 + odev->rx_buf_size = 0;
8312 + odev->rx_buf_missing = sizeof(struct iphdr);
8313 + spin_unlock_irqrestore(&odev->net_lock, flags);
8314 +
8315 + /* We are up and running. */
8316 + set_bit(HSO_NET_RUNNING, &odev->flags);
8317 + hso_start_net_device(odev->parent);
8318 +
8319 + /* Tell the kernel we are ready to start receiving from it */
8320 + netif_start_queue(net);
8321 +
8322 + return 0;
8323 +}
8324 +
8325 +/* called when interface is brought down by ifconfig */
8326 +static int hso_net_close(struct net_device *net)
8327 +{
8328 + struct hso_net *odev = netdev_priv(net);
8329 +
8330 + /* we don't need the queue anymore */
8331 + netif_stop_queue(net);
8332 + /* no longer running */
8333 + clear_bit(HSO_NET_RUNNING, &odev->flags);
8334 +
8335 + hso_stop_net_device(odev->parent);
8336 +
8337 + /* done */
8338 + return 0;
8339 +}
8340 +
8341 +/* USB tells is xmit done, we should start the netqueue again */
8342 +static void write_bulk_callback(struct urb *urb)
8343 +{
8344 + struct hso_net *odev = urb->context;
8345 + int status = urb->status;
8346 +
8347 + /* Sanity check */
8348 + if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) {
8349 + dev_err(&urb->dev->dev, "%s: device not running\n", __func__);
8350 + return;
8351 + }
8352 +
8353 + /* Do we still have a valid kernel network device? */
8354 + if (!netif_device_present(odev->net)) {
8355 + dev_err(&urb->dev->dev, "%s: net device not present\n",
8356 + __func__);
8357 + return;
8358 + }
8359 +
8360 + /* log status, but don't act on it, we don't need to resubmit anything
8361 + * anyhow */
8362 + if (status)
8363 + handle_usb_error(status, __func__, odev->parent);
8364 +
8365 + hso_put_activity(odev->parent);
8366 +
8367 + /* Tell the network interface we are ready for another frame */
8368 + netif_wake_queue(odev->net);
8369 +}
8370 +
8371 +/* called by kernel when we need to transmit a packet */
8372 +static netdev_tx_t hso_net_start_xmit(struct sk_buff *skb,
8373 + struct net_device *net)
8374 +{
8375 + struct hso_net *odev = netdev_priv(net);
8376 + int result;
8377 +
8378 + /* Tell the kernel, "No more frames 'til we are done with this one." */
8379 + netif_stop_queue(net);
8380 + if (hso_get_activity(odev->parent) == -EAGAIN) {
8381 + odev->skb_tx_buf = skb;
8382 + return NETDEV_TX_OK;
8383 + }
8384 +
8385 + /* log if asked */
8386 + DUMP1(skb->data, skb->len);
8387 + /* Copy it from kernel memory to OUR memory */
8388 + memcpy(odev->mux_bulk_tx_buf, skb->data, skb->len);
8389 + D1("len: %d/%d", skb->len, MUX_BULK_TX_BUF_SIZE);
8390 +
8391 + /* Fill in the URB for shipping it out. */
8392 + usb_fill_bulk_urb(odev->mux_bulk_tx_urb,
8393 + odev->parent->usb,
8394 + usb_sndbulkpipe(odev->parent->usb,
8395 + odev->out_endp->
8396 + bEndpointAddress & 0x7F),
8397 + odev->mux_bulk_tx_buf, skb->len, write_bulk_callback,
8398 + odev);
8399 +
8400 + /* Deal with the Zero Length packet problem, I hope */
8401 + odev->mux_bulk_tx_urb->transfer_flags |= URB_ZERO_PACKET;
8402 +
8403 + /* Send the URB on its merry way. */
8404 + result = usb_submit_urb(odev->mux_bulk_tx_urb, GFP_ATOMIC);
8405 + if (result) {
8406 + dev_warn(&odev->parent->interface->dev,
8407 + "failed mux_bulk_tx_urb %d\n", result);
8408 + net->stats.tx_errors++;
8409 + netif_start_queue(net);
8410 + } else {
8411 + net->stats.tx_packets++;
8412 + net->stats.tx_bytes += skb->len;
8413 + }
8414 + dev_kfree_skb(skb);
8415 + /* we're done */
8416 + return NETDEV_TX_OK;
8417 +}
8418 +
8419 +static const struct ethtool_ops ops = {
8420 + .get_link = ethtool_op_get_link
8421 +};
8422 +
8423 +/* called when a packet did not ack after watchdogtimeout */
8424 +static void hso_net_tx_timeout(struct net_device *net)
8425 +{
8426 + struct hso_net *odev = netdev_priv(net);
8427 +
8428 + if (!odev)
8429 + return;
8430 +
8431 + /* Tell syslog we are hosed. */
8432 + dev_warn(&net->dev, "Tx timed out.\n");
8433 +
8434 + /* Tear the waiting frame off the list */
8435 + if (odev->mux_bulk_tx_urb &&
8436 + (odev->mux_bulk_tx_urb->status == -EINPROGRESS))
8437 + usb_unlink_urb(odev->mux_bulk_tx_urb);
8438 +
8439 + /* Update statistics */
8440 + net->stats.tx_errors++;
8441 +}
8442 +
8443 +/* make a real packet from the received USB buffer */
8444 +static void packetizeRx(struct hso_net *odev, unsigned char *ip_pkt,
8445 + unsigned int count, unsigned char is_eop)
8446 +{
8447 + unsigned short temp_bytes;
8448 + unsigned short buffer_offset = 0;
8449 + unsigned short frame_len;
8450 + unsigned char *tmp_rx_buf;
8451 +
8452 + /* log if needed */
8453 + D1("Rx %d bytes", count);
8454 + DUMP(ip_pkt, min(128, (int)count));
8455 +
8456 + while (count) {
8457 + switch (odev->rx_parse_state) {
8458 + case WAIT_IP:
8459 + /* waiting for IP header. */
8460 + /* wanted bytes - size of ip header */
8461 + temp_bytes =
8462 + (count <
8463 + odev->rx_buf_missing) ? count : odev->
8464 + rx_buf_missing;
8465 +
8466 + memcpy(((unsigned char *)(&odev->rx_ip_hdr)) +
8467 + odev->rx_buf_size, ip_pkt + buffer_offset,
8468 + temp_bytes);
8469 +
8470 + odev->rx_buf_size += temp_bytes;
8471 + buffer_offset += temp_bytes;
8472 + odev->rx_buf_missing -= temp_bytes;
8473 + count -= temp_bytes;
8474 +
8475 + if (!odev->rx_buf_missing) {
8476 + /* header is complete allocate an sk_buffer and
8477 + * continue to WAIT_DATA */
8478 + frame_len = ntohs(odev->rx_ip_hdr.tot_len);
8479 +
8480 + if ((frame_len > DEFAULT_MRU) ||
8481 + (frame_len < sizeof(struct iphdr))) {
8482 + dev_err(&odev->net->dev,
8483 + "Invalid frame (%d) length\n",
8484 + frame_len);
8485 + odev->rx_parse_state = WAIT_SYNC;
8486 + continue;
8487 + }
8488 + /* Allocate an sk_buff */
8489 + odev->skb_rx_buf = netdev_alloc_skb(odev->net,
8490 + frame_len);
8491 + if (!odev->skb_rx_buf) {
8492 + /* We got no receive buffer. */
8493 + D1("could not allocate memory");
8494 + odev->rx_parse_state = WAIT_SYNC;
8495 + continue;
8496 + }
8497 +
8498 + /* Copy what we got so far. make room for iphdr
8499 + * after tail. */
8500 + tmp_rx_buf =
8501 + skb_put(odev->skb_rx_buf,
8502 + sizeof(struct iphdr));
8503 + memcpy(tmp_rx_buf, (char *)&(odev->rx_ip_hdr),
8504 + sizeof(struct iphdr));
8505 +
8506 + /* ETH_HLEN */
8507 + odev->rx_buf_size = sizeof(struct iphdr);
8508 +
8509 + /* Filip actually use .tot_len */
8510 + odev->rx_buf_missing =
8511 + frame_len - sizeof(struct iphdr);
8512 + odev->rx_parse_state = WAIT_DATA;
8513 + }
8514 + break;
8515 +
8516 + case WAIT_DATA:
8517 + temp_bytes = (count < odev->rx_buf_missing)
8518 + ? count : odev->rx_buf_missing;
8519 +
8520 + /* Copy the rest of the bytes that are left in the
8521 + * buffer into the waiting sk_buf. */
8522 + /* Make room for temp_bytes after tail. */
8523 + tmp_rx_buf = skb_put(odev->skb_rx_buf, temp_bytes);
8524 + memcpy(tmp_rx_buf, ip_pkt + buffer_offset, temp_bytes);
8525 +
8526 + odev->rx_buf_missing -= temp_bytes;
8527 + count -= temp_bytes;
8528 + buffer_offset += temp_bytes;
8529 + odev->rx_buf_size += temp_bytes;
8530 + if (!odev->rx_buf_missing) {
8531 + /* Packet is complete. Inject into stack. */
8532 + /* We have IP packet here */
8533 + odev->skb_rx_buf->protocol = cpu_to_be16(ETH_P_IP);
8534 + skb_reset_mac_header(odev->skb_rx_buf);
8535 +
8536 + /* Ship it off to the kernel */
8537 + netif_rx(odev->skb_rx_buf);
8538 + /* No longer our buffer. */
8539 + odev->skb_rx_buf = NULL;
8540 +
8541 + /* update out statistics */
8542 + odev->net->stats.rx_packets++;
8543 +
8544 + odev->net->stats.rx_bytes += odev->rx_buf_size;
8545 +
8546 + odev->rx_buf_size = 0;
8547 + odev->rx_buf_missing = sizeof(struct iphdr);
8548 + odev->rx_parse_state = WAIT_IP;
8549 + }
8550 + break;
8551 +
8552 + case WAIT_SYNC:
8553 + D1(" W_S");
8554 + count = 0;
8555 + break;
8556 + default:
8557 + D1(" ");
8558 + count--;
8559 + break;
8560 + }
8561 + }
8562 +
8563 + /* Recovery mechanism for WAIT_SYNC state. */
8564 + if (is_eop) {
8565 + if (odev->rx_parse_state == WAIT_SYNC) {
8566 + odev->rx_parse_state = WAIT_IP;
8567 + odev->rx_buf_size = 0;
8568 + odev->rx_buf_missing = sizeof(struct iphdr);
8569 + }
8570 + }
8571 +}
8572 +
8573 +static void fix_crc_bug(struct urb *urb, __le16 max_packet_size)
8574 +{
8575 + static const u8 crc_check[4] = { 0xDE, 0xAD, 0xBE, 0xEF };
8576 + u32 rest = urb->actual_length % le16_to_cpu(max_packet_size);
8577 +
8578 + if (((rest == 5) || (rest == 6)) &&
8579 + !memcmp(((u8 *)urb->transfer_buffer) + urb->actual_length - 4,
8580 + crc_check, 4)) {
8581 + urb->actual_length -= 4;
8582 + }
8583 +}
8584 +
8585 +/* Moving data from usb to kernel (in interrupt state) */
8586 +static void read_bulk_callback(struct urb *urb)
8587 +{
8588 + struct hso_net *odev = urb->context;
8589 + struct net_device *net;
8590 + int result;
8591 + int status = urb->status;
8592 +
8593 + /* is al ok? (Filip: Who's Al ?) */
8594 + if (status) {
8595 + handle_usb_error(status, __func__, odev->parent);
8596 + return;
8597 + }
8598 +
8599 + /* Sanity check */
8600 + if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) {
8601 + D1("BULK IN callback but driver is not active!");
8602 + return;
8603 + }
8604 + usb_mark_last_busy(urb->dev);
8605 +
8606 + net = odev->net;
8607 +
8608 + if (!netif_device_present(net)) {
8609 + /* Somebody killed our network interface... */
8610 + return;
8611 + }
8612 +
8613 + if (odev->parent->port_spec & HSO_INFO_CRC_BUG)
8614 + fix_crc_bug(urb, odev->in_endp->wMaxPacketSize);
8615 +
8616 + /* do we even have a packet? */
8617 + if (urb->actual_length) {
8618 + /* Handle the IP stream, add header and push it onto network
8619 + * stack if the packet is complete. */
8620 + spin_lock(&odev->net_lock);
8621 + packetizeRx(odev, urb->transfer_buffer, urb->actual_length,
8622 + (urb->transfer_buffer_length >
8623 + urb->actual_length) ? 1 : 0);
8624 + spin_unlock(&odev->net_lock);
8625 + }
8626 +
8627 + /* We are done with this URB, resubmit it. Prep the USB to wait for
8628 + * another frame. Reuse same as received. */
8629 + usb_fill_bulk_urb(urb,
8630 + odev->parent->usb,
8631 + usb_rcvbulkpipe(odev->parent->usb,
8632 + odev->in_endp->
8633 + bEndpointAddress & 0x7F),
8634 + urb->transfer_buffer, MUX_BULK_RX_BUF_SIZE,
8635 + read_bulk_callback, odev);
8636 +
8637 + /* Give this to the USB subsystem so it can tell us when more data
8638 + * arrives. */
8639 + result = usb_submit_urb(urb, GFP_ATOMIC);
8640 + if (result)
8641 + dev_warn(&odev->parent->interface->dev,
8642 + "%s failed submit mux_bulk_rx_urb %d\n", __func__,
8643 + result);
8644 +}
8645 +
8646 +/* Serial driver functions */
8647 +
8648 +static void hso_init_termios(struct ktermios *termios)
8649 +{
8650 + /*
8651 + * The default requirements for this device are:
8652 + */
8653 + termios->c_iflag &=
8654 + ~(IGNBRK /* disable ignore break */
8655 + | BRKINT /* disable break causes interrupt */
8656 + | PARMRK /* disable mark parity errors */
8657 + | ISTRIP /* disable clear high bit of input characters */
8658 + | INLCR /* disable translate NL to CR */
8659 + | IGNCR /* disable ignore CR */
8660 + | ICRNL /* disable translate CR to NL */
8661 + | IXON); /* disable enable XON/XOFF flow control */
8662 +
8663 + /* disable postprocess output characters */
8664 + termios->c_oflag &= ~OPOST;
8665 +
8666 + termios->c_lflag &=
8667 + ~(ECHO /* disable echo input characters */
8668 + | ECHONL /* disable echo new line */
8669 + | ICANON /* disable erase, kill, werase, and rprnt
8670 + special characters */
8671 + | ISIG /* disable interrupt, quit, and suspend special
8672 + characters */
8673 + | IEXTEN); /* disable non-POSIX special characters */
8674 +
8675 + termios->c_cflag &=
8676 + ~(CSIZE /* no size */
8677 + | PARENB /* disable parity bit */
8678 + | CBAUD /* clear current baud rate */
8679 + | CBAUDEX); /* clear current buad rate */
8680 +
8681 + termios->c_cflag |= CS8; /* character size 8 bits */
8682 +
8683 + /* baud rate 115200 */
8684 + tty_termios_encode_baud_rate(termios, 115200, 115200);
8685 +}
8686 +
8687 +static void _hso_serial_set_termios(struct tty_struct *tty,
8688 + struct ktermios *old)
8689 +{
8690 + struct hso_serial *serial = tty->driver_data;
8691 +
8692 + if (!serial) {
8693 + printk(KERN_ERR "%s: no tty structures", __func__);
8694 + return;
8695 + }
8696 +
8697 + D4("port %d", serial->minor);
8698 +
8699 + /*
8700 + * Fix up unsupported bits
8701 + */
8702 + tty->termios.c_iflag &= ~IXON; /* disable enable XON/XOFF flow control */
8703 +
8704 + tty->termios.c_cflag &=
8705 + ~(CSIZE /* no size */
8706 + | PARENB /* disable parity bit */
8707 + | CBAUD /* clear current baud rate */
8708 + | CBAUDEX); /* clear current buad rate */
8709 +
8710 + tty->termios.c_cflag |= CS8; /* character size 8 bits */
8711 +
8712 + /* baud rate 115200 */
8713 + tty_encode_baud_rate(tty, 115200, 115200);
8714 +}
8715 +
8716 +static void hso_resubmit_rx_bulk_urb(struct hso_serial *serial, struct urb *urb)
8717 +{
8718 + int result;
8719 + /* We are done with this URB, resubmit it. Prep the USB to wait for
8720 + * another frame */
8721 + usb_fill_bulk_urb(urb, serial->parent->usb,
8722 + usb_rcvbulkpipe(serial->parent->usb,
8723 + serial->in_endp->
8724 + bEndpointAddress & 0x7F),
8725 + urb->transfer_buffer, serial->rx_data_length,
8726 + hso_std_serial_read_bulk_callback, serial);
8727 + /* Give this to the USB subsystem so it can tell us when more data
8728 + * arrives. */
8729 + result = usb_submit_urb(urb, GFP_ATOMIC);
8730 + if (result) {
8731 + dev_err(&urb->dev->dev, "%s failed submit serial rx_urb %d\n",
8732 + __func__, result);
8733 + }
8734 +}
8735 +
8736 +
8737 +
8738 +
8739 +static void put_rxbuf_data_and_resubmit_bulk_urb(struct hso_serial *serial)
8740 +{
8741 + int count;
8742 + struct urb *curr_urb;
8743 +
8744 + while (serial->rx_urb_filled[serial->curr_rx_urb_idx]) {
8745 + curr_urb = serial->rx_urb[serial->curr_rx_urb_idx];
8746 + count = put_rxbuf_data(curr_urb, serial);
8747 + if (count == -1)
8748 + return;
8749 + if (count == 0) {
8750 + serial->curr_rx_urb_idx++;
8751 + if (serial->curr_rx_urb_idx >= serial->num_rx_urbs)
8752 + serial->curr_rx_urb_idx = 0;
8753 + hso_resubmit_rx_bulk_urb(serial, curr_urb);
8754 + }
8755 + }
8756 +}
8757 +
8758 +static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
8759 +{
8760 + int count = 0;
8761 + struct urb *urb;
8762 +
8763 + urb = serial->rx_urb[0];
8764 + if (atomic_read(&serial->port.count) > 0) {
8765 + count = put_rxbuf_data(urb, serial);
8766 + if (count == -1)
8767 + return;
8768 + }
8769 + /* Re issue a read as long as we receive data. */
8770 +
8771 + if (count == 0 && ((urb->actual_length != 0) ||
8772 + (serial->rx_state == RX_PENDING))) {
8773 + serial->rx_state = RX_SENT;
8774 + hso_mux_serial_read(serial);
8775 + } else
8776 + serial->rx_state = RX_IDLE;
8777 +}
8778 +
8779 +
8780 +/* read callback for Diag and CS port */
8781 +static void hso_std_serial_read_bulk_callback(struct urb *urb)
8782 +{
8783 + struct hso_serial *serial = urb->context;
8784 + int status = urb->status;
8785 +
8786 + D4("\n--- Got serial_read_bulk callback %02x ---", status);
8787 +
8788 + /* sanity check */
8789 + if (!serial) {
8790 + D1("serial == NULL");
8791 + return;
8792 + }
8793 + if (status) {
8794 + handle_usb_error(status, __func__, serial->parent);
8795 + return;
8796 + }
8797 +
8798 + D1("Actual length = %d\n", urb->actual_length);
8799 + DUMP1(urb->transfer_buffer, urb->actual_length);
8800 +
8801 + /* Anyone listening? */
8802 + if (atomic_read(&serial->port.count) == 0)
8803 + return;
8804 +
8805 + if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
8806 + fix_crc_bug(urb, serial->in_endp->wMaxPacketSize);
8807 + /* Valid data, handle RX data */
8808 + spin_lock(&serial->serial_lock);
8809 + serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 1;
8810 + put_rxbuf_data_and_resubmit_bulk_urb(serial);
8811 + spin_unlock(&serial->serial_lock);
8812 +}
8813 +
8814 +/*
8815 + * This needs to be a tasklet otherwise we will
8816 + * end up recursively calling this function.
8817 + */
8818 +static void hso_unthrottle_tasklet(struct hso_serial *serial)
8819 +{
8820 + unsigned long flags;
8821 +
8822 + spin_lock_irqsave(&serial->serial_lock, flags);
8823 + if ((serial->parent->port_spec & HSO_INTF_MUX))
8824 + put_rxbuf_data_and_resubmit_ctrl_urb(serial);
8825 + else
8826 + put_rxbuf_data_and_resubmit_bulk_urb(serial);
8827 + spin_unlock_irqrestore(&serial->serial_lock, flags);
8828 +}
8829 +
8830 +static void hso_unthrottle(struct tty_struct *tty)
8831 +{
8832 + struct hso_serial *serial = tty->driver_data;
8833 +
8834 + tasklet_hi_schedule(&serial->unthrottle_tasklet);
8835 +}
8836 +
8837 +/* open the requested serial port */
8838 +static int hso_serial_open(struct tty_struct *tty, struct file *filp)
8839 +{
8840 + struct hso_serial *serial = get_serial_by_index(tty->index);
8841 + int result;
8842 +
8843 + /* sanity check */
8844 + if (serial == NULL || serial->magic != HSO_SERIAL_MAGIC) {
8845 + WARN_ON(1);
8846 + tty->driver_data = NULL;
8847 + D1("Failed to open port");
8848 + return -ENODEV;
8849 + }
8850 +
8851 + mutex_lock(&serial->parent->mutex);
8852 + result = usb_autopm_get_interface(serial->parent->interface);
8853 + if (result < 0)
8854 + goto err_out;
8855 +
8856 + D1("Opening %d", serial->minor);
8857 +
8858 + /* setup */
8859 + tty->driver_data = serial;
8860 + tty_port_tty_set(&serial->port, tty);
8861 +
8862 + /* check for port already opened, if not set the termios */
8863 + if (atomic_inc_return(&serial->port.count) == 1) {
8864 + serial->rx_state = RX_IDLE;
8865 + /* Force default termio settings */
8866 + _hso_serial_set_termios(tty, NULL);
8867 + tasklet_init(&serial->unthrottle_tasklet,
8868 + (void (*)(unsigned long))hso_unthrottle_tasklet,
8869 + (unsigned long)serial);
8870 + result = hso_start_serial_device(serial->parent, GFP_KERNEL);
8871 + if (result) {
8872 + hso_stop_serial_device(serial->parent);
8873 + atomic_dec(&serial->port.count);
8874 + } else {
8875 + kref_get(&serial->parent->ref);
8876 + }
8877 + } else {
8878 + D1("Port was already open");
8879 + }
8880 +
8881 + usb_autopm_put_interface(serial->parent->interface);
8882 +
8883 + /* done */
8884 + if (result)
8885 + hso_serial_tiocmset(tty, TIOCM_RTS | TIOCM_DTR, 0);
8886 +err_out:
8887 + mutex_unlock(&serial->parent->mutex);
8888 + return result;
8889 +}
8890 +
8891 +/* close the requested serial port */
8892 +static void hso_serial_close(struct tty_struct *tty, struct file *filp)
8893 +{
8894 + struct hso_serial *serial = tty->driver_data;
8895 + u8 usb_gone;
8896 +
8897 + D1("Closing serial port");
8898 +
8899 + /* Open failed, no close cleanup required */
8900 + if (serial == NULL)
8901 + return;
8902 +
8903 + mutex_lock(&serial->parent->mutex);
8904 + usb_gone = serial->parent->usb_gone;
8905 +
8906 + if (!usb_gone)
8907 + usb_autopm_get_interface(serial->parent->interface);
8908 +
8909 + /* reset the rts and dtr */
8910 + /* do the actual close */
8911 + atomic_dec(&serial->port.count);
8912 +
8913 + if (atomic_read(&serial->port.count) <= 0) {
8914 + atomic_set(&serial->port.count, 0);
8915 + tty_port_tty_set(&serial->port, NULL);
8916 + if (!usb_gone)
8917 + hso_stop_serial_device(serial->parent);
8918 + tasklet_kill(&serial->unthrottle_tasklet);
8919 + }
8920 +
8921 + if (!usb_gone)
8922 + usb_autopm_put_interface(serial->parent->interface);
8923 +
8924 + mutex_unlock(&serial->parent->mutex);
8925 +}
8926 +
8927 +/* close the requested serial port */
8928 +static int hso_serial_write(struct tty_struct *tty, const unsigned char *buf,
8929 + int count)
8930 +{
8931 + struct hso_serial *serial = tty->driver_data;
8932 + int space, tx_bytes;
8933 + unsigned long flags;
8934 +
8935 + /* sanity check */
8936 + if (serial == NULL) {
8937 + printk(KERN_ERR "%s: serial is NULL\n", __func__);
8938 + return -ENODEV;
8939 + }
8940 +
8941 + spin_lock_irqsave(&serial->serial_lock, flags);
8942 +
8943 + space = serial->tx_data_length - serial->tx_buffer_count;
8944 + tx_bytes = (count < space) ? count : space;
8945 +
8946 + if (!tx_bytes)
8947 + goto out;
8948 +
8949 + memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, tx_bytes);
8950 + serial->tx_buffer_count += tx_bytes;
8951 +
8952 +out:
8953 + spin_unlock_irqrestore(&serial->serial_lock, flags);
8954 +
8955 + hso_kick_transmit(serial);
8956 + /* done */
8957 + return tx_bytes;
8958 +}
8959 +
8960 +/* how much room is there for writing */
8961 +static int hso_serial_write_room(struct tty_struct *tty)
8962 +{
8963 + struct hso_serial *serial = tty->driver_data;
8964 + int room;
8965 + unsigned long flags;
8966 +
8967 + spin_lock_irqsave(&serial->serial_lock, flags);
8968 + room = serial->tx_data_length - serial->tx_buffer_count;
8969 + spin_unlock_irqrestore(&serial->serial_lock, flags);
8970 +
8971 + /* return free room */
8972 + return room;
8973 +}
8974 +
8975 +static void hso_serial_cleanup(struct tty_struct *tty)
8976 +{
8977 + struct hso_serial *serial = tty->driver_data;
8978 +
8979 + if (!serial)
8980 + return;
8981 +
8982 + kref_put(&serial->parent->ref, hso_serial_ref_free);
8983 +}
8984 +
8985 +/* setup the term */
8986 +static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
8987 +{
8988 + struct hso_serial *serial = tty->driver_data;
8989 + unsigned long flags;
8990 +
8991 + if (old)
8992 + D5("Termios called with: cflags new[%d] - old[%d]",
8993 + tty->termios.c_cflag, old->c_cflag);
8994 +
8995 + /* the actual setup */
8996 + spin_lock_irqsave(&serial->serial_lock, flags);
8997 + if (atomic_read(&serial->port.count))
8998 + _hso_serial_set_termios(tty, old);
8999 + else
9000 + tty->termios = *old;
9001 + spin_unlock_irqrestore(&serial->serial_lock, flags);
9002 +
9003 + /* done */
9004 +}
9005 +
9006 +/* how many characters in the buffer */
9007 +static int hso_serial_chars_in_buffer(struct tty_struct *tty)
9008 +{
9009 + struct hso_serial *serial = tty->driver_data;
9010 + int chars;
9011 + unsigned long flags;
9012 +
9013 + /* sanity check */
9014 + if (serial == NULL)
9015 + return 0;
9016 +
9017 + spin_lock_irqsave(&serial->serial_lock, flags);
9018 + chars = serial->tx_buffer_count;
9019 + spin_unlock_irqrestore(&serial->serial_lock, flags);
9020 +
9021 + return chars;
9022 +}
9023 +static int tiocmget_submit_urb(struct hso_serial *serial,
9024 + struct hso_tiocmget *tiocmget,
9025 + struct usb_device *usb)
9026 +{
9027 + int result;
9028 +
9029 + if (serial->parent->usb_gone)
9030 + return -ENODEV;
9031 + usb_fill_int_urb(tiocmget->urb, usb,
9032 + usb_rcvintpipe(usb,
9033 + tiocmget->endp->
9034 + bEndpointAddress & 0x7F),
9035 + &tiocmget->serial_state_notification,
9036 + sizeof(struct hso_serial_state_notification),
9037 + tiocmget_intr_callback, serial,
9038 + tiocmget->endp->bInterval);
9039 + result = usb_submit_urb(tiocmget->urb, GFP_ATOMIC);
9040 + if (result) {
9041 + dev_warn(&usb->dev, "%s usb_submit_urb failed %d\n", __func__,
9042 + result);
9043 + }
9044 + return result;
9045 +
9046 +}
9047 +
9048 +static void tiocmget_intr_callback(struct urb *urb)
9049 +{
9050 + struct hso_serial *serial = urb->context;
9051 + struct hso_tiocmget *tiocmget;
9052 + int status = urb->status;
9053 + u16 UART_state_bitmap, prev_UART_state_bitmap;
9054 + struct uart_icount *icount;
9055 + struct hso_serial_state_notification *serial_state_notification;
9056 + struct usb_device *usb;
9057 + struct usb_interface *interface;
9058 + int if_num;
9059 +
9060 + /* Sanity checks */
9061 + if (!serial)
9062 + return;
9063 + if (status) {
9064 + handle_usb_error(status, __func__, serial->parent);
9065 + return;
9066 + }
9067 +
9068 + /* tiocmget is only supported on HSO_PORT_MODEM */
9069 + tiocmget = serial->tiocmget;
9070 + if (!tiocmget)
9071 + return;
9072 + BUG_ON((serial->parent->port_spec & HSO_PORT_MASK) != HSO_PORT_MODEM);
9073 +
9074 + usb = serial->parent->usb;
9075 + interface = serial->parent->interface;
9076 +
9077 + if_num = interface->cur_altsetting->desc.bInterfaceNumber;
9078 +
9079 + /* wIndex should be the USB interface number of the port to which the
9080 + * notification applies, which should always be the Modem port.
9081 + */
9082 + serial_state_notification = &tiocmget->serial_state_notification;
9083 + if (serial_state_notification->bmRequestType != BM_REQUEST_TYPE ||
9084 + serial_state_notification->bNotification != B_NOTIFICATION ||
9085 + le16_to_cpu(serial_state_notification->wValue) != W_VALUE ||
9086 + le16_to_cpu(serial_state_notification->wIndex) != if_num ||
9087 + le16_to_cpu(serial_state_notification->wLength) != W_LENGTH) {
9088 + dev_warn(&usb->dev,
9089 + "hso received invalid serial state notification\n");
9090 + DUMP(serial_state_notification,
9091 + sizeof(struct hso_serial_state_notification));
9092 + } else {
9093 +
9094 + UART_state_bitmap = le16_to_cpu(serial_state_notification->
9095 + UART_state_bitmap);
9096 + prev_UART_state_bitmap = tiocmget->prev_UART_state_bitmap;
9097 + icount = &tiocmget->icount;
9098 + spin_lock(&serial->serial_lock);
9099 + if ((UART_state_bitmap & B_OVERRUN) !=
9100 + (prev_UART_state_bitmap & B_OVERRUN))
9101 + icount->parity++;
9102 + if ((UART_state_bitmap & B_PARITY) !=
9103 + (prev_UART_state_bitmap & B_PARITY))
9104 + icount->parity++;
9105 + if ((UART_state_bitmap & B_FRAMING) !=
9106 + (prev_UART_state_bitmap & B_FRAMING))
9107 + icount->frame++;
9108 + if ((UART_state_bitmap & B_RING_SIGNAL) &&
9109 + !(prev_UART_state_bitmap & B_RING_SIGNAL))
9110 + icount->rng++;
9111 + if ((UART_state_bitmap & B_BREAK) !=
9112 + (prev_UART_state_bitmap & B_BREAK))
9113 + icount->brk++;
9114 + if ((UART_state_bitmap & B_TX_CARRIER) !=
9115 + (prev_UART_state_bitmap & B_TX_CARRIER))
9116 + icount->dsr++;
9117 + if ((UART_state_bitmap & B_RX_CARRIER) !=
9118 + (prev_UART_state_bitmap & B_RX_CARRIER))
9119 + icount->dcd++;
9120 + tiocmget->prev_UART_state_bitmap = UART_state_bitmap;
9121 + spin_unlock(&serial->serial_lock);
9122 + tiocmget->intr_completed = 1;
9123 + wake_up_interruptible(&tiocmget->waitq);
9124 + }
9125 + memset(serial_state_notification, 0,
9126 + sizeof(struct hso_serial_state_notification));
9127 + tiocmget_submit_urb(serial,
9128 + tiocmget,
9129 + serial->parent->usb);
9130 +}
9131 +
9132 +/*
9133 + * next few functions largely stolen from drivers/serial/serial_core.c
9134 + */
9135 +/* Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
9136 + * - mask passed in arg for lines of interest
9137 + * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
9138 + * Caller should use TIOCGICOUNT to see which one it was
9139 + */
9140 +static int
9141 +hso_wait_modem_status(struct hso_serial *serial, unsigned long arg)
9142 +{
9143 + DECLARE_WAITQUEUE(wait, current);
9144 + struct uart_icount cprev, cnow;
9145 + struct hso_tiocmget *tiocmget;
9146 + int ret;
9147 +
9148 + tiocmget = serial->tiocmget;
9149 + if (!tiocmget)
9150 + return -ENOENT;
9151 + /*
9152 + * note the counters on entry
9153 + */
9154 + spin_lock_irq(&serial->serial_lock);
9155 + memcpy(&cprev, &tiocmget->icount, sizeof(struct uart_icount));
9156 + spin_unlock_irq(&serial->serial_lock);
9157 + add_wait_queue(&tiocmget->waitq, &wait);
9158 + for (;;) {
9159 + spin_lock_irq(&serial->serial_lock);
9160 + memcpy(&cnow, &tiocmget->icount, sizeof(struct uart_icount));
9161 + spin_unlock_irq(&serial->serial_lock);
9162 + set_current_state(TASK_INTERRUPTIBLE);
9163 + if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
9164 + ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
9165 + ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd))) {
9166 + ret = 0;
9167 + break;
9168 + }
9169 + schedule();
9170 + /* see if a signal did it */
9171 + if (signal_pending(current)) {
9172 + ret = -ERESTARTSYS;
9173 + break;
9174 + }
9175 + cprev = cnow;
9176 + }
9177 + __set_current_state(TASK_RUNNING);
9178 + remove_wait_queue(&tiocmget->waitq, &wait);
9179 +
9180 + return ret;
9181 +}
9182 +
9183 +/*
9184 + * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
9185 + * Return: write counters to the user passed counter struct
9186 + * NB: both 1->0 and 0->1 transitions are counted except for
9187 + * RI where only 0->1 is counted.
9188 + */
9189 +static int hso_get_count(struct tty_struct *tty,
9190 + struct serial_icounter_struct *icount)
9191 +{
9192 + struct uart_icount cnow;
9193 + struct hso_serial *serial = tty->driver_data;
9194 + struct hso_tiocmget *tiocmget = serial->tiocmget;
9195 +
9196 + memset(icount, 0, sizeof(struct serial_icounter_struct));
9197 +
9198 + if (!tiocmget)
9199 + return -ENOENT;
9200 + spin_lock_irq(&serial->serial_lock);
9201 + memcpy(&cnow, &tiocmget->icount, sizeof(struct uart_icount));
9202 + spin_unlock_irq(&serial->serial_lock);
9203 +
9204 + icount->cts = cnow.cts;
9205 + icount->dsr = cnow.dsr;
9206 + icount->rng = cnow.rng;
9207 + icount->dcd = cnow.dcd;
9208 + icount->rx = cnow.rx;
9209 + icount->tx = cnow.tx;
9210 + icount->frame = cnow.frame;
9211 + icount->overrun = cnow.overrun;
9212 + icount->parity = cnow.parity;
9213 + icount->brk = cnow.brk;
9214 + icount->buf_overrun = cnow.buf_overrun;
9215 +
9216 + return 0;
9217 +}
9218 +
9219 +
9220 +static int hso_serial_tiocmget(struct tty_struct *tty)
9221 +{
9222 + int retval;
9223 + struct hso_serial *serial = tty->driver_data;
9224 + struct hso_tiocmget *tiocmget;
9225 + u16 UART_state_bitmap;
9226 +
9227 + /* sanity check */
9228 + if (!serial) {
9229 + D1("no tty structures");
9230 + return -EINVAL;
9231 + }
9232 + spin_lock_irq(&serial->serial_lock);
9233 + retval = ((serial->rts_state) ? TIOCM_RTS : 0) |
9234 + ((serial->dtr_state) ? TIOCM_DTR : 0);
9235 + tiocmget = serial->tiocmget;
9236 + if (tiocmget) {
9237 +
9238 + UART_state_bitmap = le16_to_cpu(
9239 + tiocmget->prev_UART_state_bitmap);
9240 + if (UART_state_bitmap & B_RING_SIGNAL)
9241 + retval |= TIOCM_RNG;
9242 + if (UART_state_bitmap & B_RX_CARRIER)
9243 + retval |= TIOCM_CD;
9244 + if (UART_state_bitmap & B_TX_CARRIER)
9245 + retval |= TIOCM_DSR;
9246 + }
9247 + spin_unlock_irq(&serial->serial_lock);
9248 + return retval;
9249 +}
9250 +
9251 +static int hso_serial_tiocmset(struct tty_struct *tty,
9252 + unsigned int set, unsigned int clear)
9253 +{
9254 + int val = 0;
9255 + unsigned long flags;
9256 + int if_num;
9257 + struct hso_serial *serial = tty->driver_data;
9258 + struct usb_interface *interface;
9259 +
9260 + /* sanity check */
9261 + if (!serial) {
9262 + D1("no tty structures");
9263 + return -EINVAL;
9264 + }
9265 +
9266 + if ((serial->parent->port_spec & HSO_PORT_MASK) != HSO_PORT_MODEM)
9267 + return -EINVAL;
9268 +
9269 + interface = serial->parent->interface;
9270 + if_num = interface->cur_altsetting->desc.bInterfaceNumber;
9271 +
9272 + spin_lock_irqsave(&serial->serial_lock, flags);
9273 + if (set & TIOCM_RTS)
9274 + serial->rts_state = 1;
9275 + if (set & TIOCM_DTR)
9276 + serial->dtr_state = 1;
9277 +
9278 + if (clear & TIOCM_RTS)
9279 + serial->rts_state = 0;
9280 + if (clear & TIOCM_DTR)
9281 + serial->dtr_state = 0;
9282 +
9283 + if (serial->dtr_state)
9284 + val |= 0x01;
9285 + if (serial->rts_state)
9286 + val |= 0x02;
9287 +
9288 + spin_unlock_irqrestore(&serial->serial_lock, flags);
9289 +
9290 + return usb_control_msg(serial->parent->usb,
9291 + usb_rcvctrlpipe(serial->parent->usb, 0), 0x22,
9292 + 0x21, val, if_num, NULL, 0,
9293 + USB_CTRL_SET_TIMEOUT);
9294 +}
9295 +
9296 +static int hso_serial_ioctl(struct tty_struct *tty,
9297 + unsigned int cmd, unsigned long arg)
9298 +{
9299 + struct hso_serial *serial = tty->driver_data;
9300 + int ret = 0;
9301 + D4("IOCTL cmd: %d, arg: %ld", cmd, arg);
9302 +
9303 + if (!serial)
9304 + return -ENODEV;
9305 + switch (cmd) {
9306 + case TIOCMIWAIT:
9307 + ret = hso_wait_modem_status(serial, arg);
9308 + break;
9309 + default:
9310 + ret = -ENOIOCTLCMD;
9311 + break;
9312 + }
9313 + return ret;
9314 +}
9315 +
9316 +
9317 +/* starts a transmit */
9318 +static void hso_kick_transmit(struct hso_serial *serial)
9319 +{
9320 + u8 *temp;
9321 + unsigned long flags;
9322 + int res;
9323 +
9324 + spin_lock_irqsave(&serial->serial_lock, flags);
9325 + if (!serial->tx_buffer_count)
9326 + goto out;
9327 +
9328 + if (serial->tx_urb_used)
9329 + goto out;
9330 +
9331 + /* Wakeup USB interface if necessary */
9332 + if (hso_get_activity(serial->parent) == -EAGAIN)
9333 + goto out;
9334 +
9335 + /* Switch pointers around to avoid memcpy */
9336 + temp = serial->tx_buffer;
9337 + serial->tx_buffer = serial->tx_data;
9338 + serial->tx_data = temp;
9339 + serial->tx_data_count = serial->tx_buffer_count;
9340 + serial->tx_buffer_count = 0;
9341 +
9342 + /* If temp is set, it means we switched buffers */
9343 + if (temp && serial->write_data) {
9344 + res = serial->write_data(serial);
9345 + if (res >= 0)
9346 + serial->tx_urb_used = 1;
9347 + }
9348 +out:
9349 + spin_unlock_irqrestore(&serial->serial_lock, flags);
9350 +}
9351 +
9352 +/* make a request (for reading and writing data to muxed serial port) */
9353 +static int mux_device_request(struct hso_serial *serial, u8 type, u16 port,
9354 + struct urb *ctrl_urb,
9355 + struct usb_ctrlrequest *ctrl_req,
9356 + u8 *ctrl_urb_data, u32 size)
9357 +{
9358 + int result;
9359 + int pipe;
9360 +
9361 + /* Sanity check */
9362 + if (!serial || !ctrl_urb || !ctrl_req) {
9363 + printk(KERN_ERR "%s: Wrong arguments\n", __func__);
9364 + return -EINVAL;
9365 + }
9366 +
9367 + /* initialize */
9368 + ctrl_req->wValue = 0;
9369 + ctrl_req->wIndex = cpu_to_le16(hso_port_to_mux(port));
9370 + ctrl_req->wLength = cpu_to_le16(size);
9371 +
9372 + if (type == USB_CDC_GET_ENCAPSULATED_RESPONSE) {
9373 + /* Reading command */
9374 + ctrl_req->bRequestType = USB_DIR_IN |
9375 + USB_TYPE_OPTION_VENDOR |
9376 + USB_RECIP_INTERFACE;
9377 + ctrl_req->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE;
9378 + pipe = usb_rcvctrlpipe(serial->parent->usb, 0);
9379 + } else {
9380 + /* Writing command */
9381 + ctrl_req->bRequestType = USB_DIR_OUT |
9382 + USB_TYPE_OPTION_VENDOR |
9383 + USB_RECIP_INTERFACE;
9384 + ctrl_req->bRequest = USB_CDC_SEND_ENCAPSULATED_COMMAND;
9385 + pipe = usb_sndctrlpipe(serial->parent->usb, 0);
9386 + }
9387 + /* syslog */
9388 + D2("%s command (%02x) len: %d, port: %d",
9389 + type == USB_CDC_GET_ENCAPSULATED_RESPONSE ? "Read" : "Write",
9390 + ctrl_req->bRequestType, ctrl_req->wLength, port);
9391 +
9392 + /* Load ctrl urb */
9393 + ctrl_urb->transfer_flags = 0;
9394 + usb_fill_control_urb(ctrl_urb,
9395 + serial->parent->usb,
9396 + pipe,
9397 + (u8 *) ctrl_req,
9398 + ctrl_urb_data, size, ctrl_callback, serial);
9399 + /* Send it on merry way */
9400 + result = usb_submit_urb(ctrl_urb, GFP_ATOMIC);
9401 + if (result) {
9402 + dev_err(&ctrl_urb->dev->dev,
9403 + "%s failed submit ctrl_urb %d type %d\n", __func__,
9404 + result, type);
9405 + return result;
9406 + }
9407 +
9408 + /* done */
9409 + return size;
9410 +}
9411 +
9412 +/* called by intr_callback when read occurs */
9413 +static int hso_mux_serial_read(struct hso_serial *serial)
9414 +{
9415 + if (!serial)
9416 + return -EINVAL;
9417 +
9418 + /* clean data */
9419 + memset(serial->rx_data[0], 0, CTRL_URB_RX_SIZE);
9420 + /* make the request */
9421 +
9422 + if (serial->num_rx_urbs != 1) {
9423 + dev_err(&serial->parent->interface->dev,
9424 + "ERROR: mux'd reads with multiple buffers "
9425 + "not possible\n");
9426 + return 0;
9427 + }
9428 + return mux_device_request(serial,
9429 + USB_CDC_GET_ENCAPSULATED_RESPONSE,
9430 + serial->parent->port_spec & HSO_PORT_MASK,
9431 + serial->rx_urb[0],
9432 + &serial->ctrl_req_rx,
9433 + serial->rx_data[0], serial->rx_data_length);
9434 +}
9435 +
9436 +/* used for muxed serial port callback (muxed serial read) */
9437 +static void intr_callback(struct urb *urb)
9438 +{
9439 + struct hso_shared_int *shared_int = urb->context;
9440 + struct hso_serial *serial;
9441 + unsigned char *port_req;
9442 + int status = urb->status;
9443 + int i;
9444 +
9445 + usb_mark_last_busy(urb->dev);
9446 +
9447 + /* sanity check */
9448 + if (!shared_int)
9449 + return;
9450 +
9451 + /* status check */
9452 + if (status) {
9453 + handle_usb_error(status, __func__, NULL);
9454 + return;
9455 + }
9456 + D4("\n--- Got intr callback 0x%02X ---", status);
9457 +
9458 + /* what request? */
9459 + port_req = urb->transfer_buffer;
9460 + D4(" port_req = 0x%.2X\n", *port_req);
9461 + /* loop over all muxed ports to find the one sending this */
9462 + for (i = 0; i < 8; i++) {
9463 + /* max 8 channels on MUX */
9464 + if (*port_req & (1 << i)) {
9465 + serial = get_serial_by_shared_int_and_type(shared_int,
9466 + (1 << i));
9467 + if (serial != NULL) {
9468 + D1("Pending read interrupt on port %d\n", i);
9469 + spin_lock(&serial->serial_lock);
9470 + if (serial->rx_state == RX_IDLE &&
9471 + atomic_read(&serial->port.count) > 0) {
9472 + /* Setup and send a ctrl req read on
9473 + * port i */
9474 + if (!serial->rx_urb_filled[0]) {
9475 + serial->rx_state = RX_SENT;
9476 + hso_mux_serial_read(serial);
9477 + } else
9478 + serial->rx_state = RX_PENDING;
9479 + } else {
9480 + D1("Already a read pending on "
9481 + "port %d or port not open\n", i);
9482 + }
9483 + spin_unlock(&serial->serial_lock);
9484 + }
9485 + }
9486 + }
9487 + /* Resubmit interrupt urb */
9488 + hso_mux_submit_intr_urb(shared_int, urb->dev, GFP_ATOMIC);
9489 +}
9490 +
9491 +/* called for writing to muxed serial port */
9492 +static int hso_mux_serial_write_data(struct hso_serial *serial)
9493 +{
9494 + if (NULL == serial)
9495 + return -EINVAL;
9496 +
9497 + return mux_device_request(serial,
9498 + USB_CDC_SEND_ENCAPSULATED_COMMAND,
9499 + serial->parent->port_spec & HSO_PORT_MASK,
9500 + serial->tx_urb,
9501 + &serial->ctrl_req_tx,
9502 + serial->tx_data, serial->tx_data_count);
9503 +}
9504 +
9505 +/* write callback for Diag and CS port */
9506 +static void hso_std_serial_write_bulk_callback(struct urb *urb)
9507 +{
9508 + struct hso_serial *serial = urb->context;
9509 + int status = urb->status;
9510 +
9511 + /* sanity check */
9512 + if (!serial) {
9513 + D1("serial == NULL");
9514 + return;
9515 + }
9516 +
9517 + spin_lock(&serial->serial_lock);
9518 + serial->tx_urb_used = 0;
9519 + spin_unlock(&serial->serial_lock);
9520 + if (status) {
9521 + handle_usb_error(status, __func__, serial->parent);
9522 + return;
9523 + }
9524 + hso_put_activity(serial->parent);
9525 + tty_port_tty_wakeup(&serial->port);
9526 + hso_kick_transmit(serial);
9527 +
9528 + D1(" ");
9529 +}
9530 +
9531 +/* called for writing diag or CS serial port */
9532 +static int hso_std_serial_write_data(struct hso_serial *serial)
9533 +{
9534 + int count = serial->tx_data_count;
9535 + int result;
9536 +
9537 + usb_fill_bulk_urb(serial->tx_urb,
9538 + serial->parent->usb,
9539 + usb_sndbulkpipe(serial->parent->usb,
9540 + serial->out_endp->
9541 + bEndpointAddress & 0x7F),
9542 + serial->tx_data, serial->tx_data_count,
9543 + hso_std_serial_write_bulk_callback, serial);
9544 +
9545 + result = usb_submit_urb(serial->tx_urb, GFP_ATOMIC);
9546 + if (result) {
9547 + dev_warn(&serial->parent->usb->dev,
9548 + "Failed to submit urb - res %d\n", result);
9549 + return result;
9550 + }
9551 +
9552 + return count;
9553 +}
9554 +
9555 +/* callback after read or write on muxed serial port */
9556 +static void ctrl_callback(struct urb *urb)
9557 +{
9558 + struct hso_serial *serial = urb->context;
9559 + struct usb_ctrlrequest *req;
9560 + int status = urb->status;
9561 +
9562 + /* sanity check */
9563 + if (!serial)
9564 + return;
9565 +
9566 + spin_lock(&serial->serial_lock);
9567 + serial->tx_urb_used = 0;
9568 + spin_unlock(&serial->serial_lock);
9569 + if (status) {
9570 + handle_usb_error(status, __func__, serial->parent);
9571 + return;
9572 + }
9573 +
9574 + /* what request? */
9575 + req = (struct usb_ctrlrequest *)(urb->setup_packet);
9576 + D4("\n--- Got muxed ctrl callback 0x%02X ---", status);
9577 + D4("Actual length of urb = %d\n", urb->actual_length);
9578 + DUMP1(urb->transfer_buffer, urb->actual_length);
9579 +
9580 + if (req->bRequestType ==
9581 + (USB_DIR_IN | USB_TYPE_OPTION_VENDOR | USB_RECIP_INTERFACE)) {
9582 + /* response to a read command */
9583 + serial->rx_urb_filled[0] = 1;
9584 + spin_lock(&serial->serial_lock);
9585 + put_rxbuf_data_and_resubmit_ctrl_urb(serial);
9586 + spin_unlock(&serial->serial_lock);
9587 + } else {
9588 + hso_put_activity(serial->parent);
9589 + tty_port_tty_wakeup(&serial->port);
9590 + /* response to a write command */
9591 + hso_kick_transmit(serial);
9592 + }
9593 +}
9594 +
9595 +/* handle RX data for serial port */
9596 +static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial)
9597 +{
9598 + struct tty_struct *tty;
9599 + int count;
9600 +
9601 + /* Sanity check */
9602 + if (urb == NULL || serial == NULL) {
9603 + D1("serial = NULL");
9604 + return -2;
9605 + }
9606 +
9607 + tty = tty_port_tty_get(&serial->port);
9608 +
9609 + if (tty && test_bit(TTY_THROTTLED, &tty->flags)) {
9610 + tty_kref_put(tty);
9611 + return -1;
9612 + }
9613 +
9614 + /* Push data to tty */
9615 + D1("data to push to tty");
9616 + count = tty_buffer_request_room(&serial->port, urb->actual_length);
9617 + if (count >= urb->actual_length) {
9618 + tty_insert_flip_string(&serial->port, urb->transfer_buffer,
9619 + urb->actual_length);
9620 + tty_flip_buffer_push(&serial->port);
9621 + } else {
9622 + dev_warn(&serial->parent->usb->dev,
9623 + "dropping data, %d bytes lost\n", urb->actual_length);
9624 + }
9625 +
9626 + tty_kref_put(tty);
9627 +
9628 + serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0;
9629 +
9630 + return 0;
9631 +}
9632 +
9633 +
9634 +/* Base driver functions */
9635 +
9636 +static void hso_log_port(struct hso_device *hso_dev)
9637 +{
9638 + char *port_type;
9639 + char port_dev[20];
9640 +
9641 + switch (hso_dev->port_spec & HSO_PORT_MASK) {
9642 + case HSO_PORT_CONTROL:
9643 + port_type = "Control";
9644 + break;
9645 + case HSO_PORT_APP:
9646 + port_type = "Application";
9647 + break;
9648 + case HSO_PORT_GPS:
9649 + port_type = "GPS";
9650 + break;
9651 + case HSO_PORT_GPS_CONTROL:
9652 + port_type = "GPS control";
9653 + break;
9654 + case HSO_PORT_APP2:
9655 + port_type = "Application2";
9656 + break;
9657 + case HSO_PORT_PCSC:
9658 + port_type = "PCSC";
9659 + break;
9660 + case HSO_PORT_DIAG:
9661 + port_type = "Diagnostic";
9662 + break;
9663 + case HSO_PORT_DIAG2:
9664 + port_type = "Diagnostic2";
9665 + break;
9666 + case HSO_PORT_MODEM:
9667 + port_type = "Modem";
9668 + break;
9669 + case HSO_PORT_NETWORK:
9670 + port_type = "Network";
9671 + break;
9672 + default:
9673 + port_type = "Unknown";
9674 + break;
9675 + }
9676 + if ((hso_dev->port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) {
9677 + sprintf(port_dev, "%s", dev2net(hso_dev)->net->name);
9678 + } else
9679 + sprintf(port_dev, "/dev/%s%d", tty_filename,
9680 + dev2ser(hso_dev)->minor);
9681 +
9682 + dev_dbg(&hso_dev->interface->dev, "HSO: Found %s port %s\n",
9683 + port_type, port_dev);
9684 +}
9685 +
9686 +static int hso_start_net_device(struct hso_device *hso_dev)
9687 +{
9688 + int i, result = 0;
9689 + struct hso_net *hso_net = dev2net(hso_dev);
9690 +
9691 + if (!hso_net)
9692 + return -ENODEV;
9693 +
9694 + /* send URBs for all read buffers */
9695 + for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) {
9696 +
9697 + /* Prep a receive URB */
9698 + usb_fill_bulk_urb(hso_net->mux_bulk_rx_urb_pool[i],
9699 + hso_dev->usb,
9700 + usb_rcvbulkpipe(hso_dev->usb,
9701 + hso_net->in_endp->
9702 + bEndpointAddress & 0x7F),
9703 + hso_net->mux_bulk_rx_buf_pool[i],
9704 + MUX_BULK_RX_BUF_SIZE, read_bulk_callback,
9705 + hso_net);
9706 +
9707 + /* Put it out there so the device can send us stuff */
9708 + result = usb_submit_urb(hso_net->mux_bulk_rx_urb_pool[i],
9709 + GFP_NOIO);
9710 + if (result)
9711 + dev_warn(&hso_dev->usb->dev,
9712 + "%s failed mux_bulk_rx_urb[%d] %d\n", __func__,
9713 + i, result);
9714 + }
9715 +
9716 + return result;
9717 +}
9718 +
9719 +static int hso_stop_net_device(struct hso_device *hso_dev)
9720 +{
9721 + int i;
9722 + struct hso_net *hso_net = dev2net(hso_dev);
9723 +
9724 + if (!hso_net)
9725 + return -ENODEV;
9726 +
9727 + for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) {
9728 + if (hso_net->mux_bulk_rx_urb_pool[i])
9729 + usb_kill_urb(hso_net->mux_bulk_rx_urb_pool[i]);
9730 +
9731 + }
9732 + if (hso_net->mux_bulk_tx_urb)
9733 + usb_kill_urb(hso_net->mux_bulk_tx_urb);
9734 +
9735 + return 0;
9736 +}
9737 +
9738 +static int hso_start_serial_device(struct hso_device *hso_dev, gfp_t flags)
9739 +{
9740 + int i, result = 0;
9741 + struct hso_serial *serial = dev2ser(hso_dev);
9742 +
9743 + if (!serial)
9744 + return -ENODEV;
9745 +
9746 + /* If it is not the MUX port fill in and submit a bulk urb (already
9747 + * allocated in hso_serial_start) */
9748 + if (!(serial->parent->port_spec & HSO_INTF_MUX)) {
9749 + for (i = 0; i < serial->num_rx_urbs; i++) {
9750 + usb_fill_bulk_urb(serial->rx_urb[i],
9751 + serial->parent->usb,
9752 + usb_rcvbulkpipe(serial->parent->usb,
9753 + serial->in_endp->
9754 + bEndpointAddress &
9755 + 0x7F),
9756 + serial->rx_data[i],
9757 + serial->rx_data_length,
9758 + hso_std_serial_read_bulk_callback,
9759 + serial);
9760 + result = usb_submit_urb(serial->rx_urb[i], flags);
9761 + if (result) {
9762 + dev_warn(&serial->parent->usb->dev,
9763 + "Failed to submit urb - res %d\n",
9764 + result);
9765 + break;
9766 + }
9767 + }
9768 + } else {
9769 + mutex_lock(&serial->shared_int->shared_int_lock);
9770 + if (!serial->shared_int->use_count) {
9771 + result =
9772 + hso_mux_submit_intr_urb(serial->shared_int,
9773 + hso_dev->usb, flags);
9774 + }
9775 + serial->shared_int->use_count++;
9776 + mutex_unlock(&serial->shared_int->shared_int_lock);
9777 + }
9778 + if (serial->tiocmget)
9779 + tiocmget_submit_urb(serial,
9780 + serial->tiocmget,
9781 + serial->parent->usb);
9782 + return result;
9783 +}
9784 +
9785 +static int hso_stop_serial_device(struct hso_device *hso_dev)
9786 +{
9787 + int i;
9788 + struct hso_serial *serial = dev2ser(hso_dev);
9789 + struct hso_tiocmget *tiocmget;
9790 +
9791 + if (!serial)
9792 + return -ENODEV;
9793 +
9794 + for (i = 0; i < serial->num_rx_urbs; i++) {
9795 + if (serial->rx_urb[i]) {
9796 + usb_kill_urb(serial->rx_urb[i]);
9797 + serial->rx_urb_filled[i] = 0;
9798 + }
9799 + }
9800 + serial->curr_rx_urb_idx = 0;
9801 +
9802 + if (serial->tx_urb)
9803 + usb_kill_urb(serial->tx_urb);
9804 +
9805 + if (serial->shared_int) {
9806 + mutex_lock(&serial->shared_int->shared_int_lock);
9807 + if (serial->shared_int->use_count &&
9808 + (--serial->shared_int->use_count == 0)) {
9809 + struct urb *urb;
9810 +
9811 + urb = serial->shared_int->shared_intr_urb;
9812 + if (urb)
9813 + usb_kill_urb(urb);
9814 + }
9815 + mutex_unlock(&serial->shared_int->shared_int_lock);
9816 + }
9817 + tiocmget = serial->tiocmget;
9818 + if (tiocmget) {
9819 + wake_up_interruptible(&tiocmget->waitq);
9820 + usb_kill_urb(tiocmget->urb);
9821 + }
9822 +
9823 + return 0;
9824 +}
9825 +
9826 +static void hso_serial_tty_unregister(struct hso_serial *serial)
9827 +{
9828 + tty_unregister_device(tty_drv, serial->minor);
9829 +}
9830 +
9831 +static void hso_serial_common_free(struct hso_serial *serial)
9832 +{
9833 + int i;
9834 +
9835 + for (i = 0; i < serial->num_rx_urbs; i++) {
9836 + /* unlink and free RX URB */
9837 + usb_free_urb(serial->rx_urb[i]);
9838 + /* free the RX buffer */
9839 + kfree(serial->rx_data[i]);
9840 + }
9841 +
9842 + /* unlink and free TX URB */
9843 + usb_free_urb(serial->tx_urb);
9844 + kfree(serial->tx_buffer);
9845 + kfree(serial->tx_data);
9846 + tty_port_destroy(&serial->port);
9847 +}
9848 +
9849 +static int hso_serial_common_create(struct hso_serial *serial, int num_urbs,
9850 + int rx_size, int tx_size)
9851 +{
9852 + struct device *dev;
9853 + int minor;
9854 + int i;
9855 +
9856 + tty_port_init(&serial->port);
9857 +
9858 + minor = get_free_serial_index();
9859 + if (minor < 0)
9860 + goto exit;
9861 +
9862 + /* register our minor number */
9863 + serial->parent->dev = tty_port_register_device_attr(&serial->port,
9864 + tty_drv, minor, &serial->parent->interface->dev,
9865 + serial->parent, hso_serial_dev_groups);
9866 + dev = serial->parent->dev;
9867 +
9868 + /* fill in specific data for later use */
9869 + serial->minor = minor;
9870 + serial->magic = HSO_SERIAL_MAGIC;
9871 + spin_lock_init(&serial->serial_lock);
9872 + serial->num_rx_urbs = num_urbs;
9873 +
9874 + /* RX, allocate urb and initialize */
9875 +
9876 + /* prepare our RX buffer */
9877 + serial->rx_data_length = rx_size;
9878 + for (i = 0; i < serial->num_rx_urbs; i++) {
9879 + serial->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
9880 + if (!serial->rx_urb[i]) {
9881 + dev_err(dev, "Could not allocate urb?\n");
9882 + goto exit;
9883 + }
9884 + serial->rx_urb[i]->transfer_buffer = NULL;
9885 + serial->rx_urb[i]->transfer_buffer_length = 0;
9886 + serial->rx_data[i] = kzalloc(serial->rx_data_length,
9887 + GFP_KERNEL);
9888 + if (!serial->rx_data[i])
9889 + goto exit;
9890 + }
9891 +
9892 + /* TX, allocate urb and initialize */
9893 + serial->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
9894 + if (!serial->tx_urb) {
9895 + dev_err(dev, "Could not allocate urb?\n");
9896 + goto exit;
9897 + }
9898 + serial->tx_urb->transfer_buffer = NULL;
9899 + serial->tx_urb->transfer_buffer_length = 0;
9900 + /* prepare our TX buffer */
9901 + serial->tx_data_count = 0;
9902 + serial->tx_buffer_count = 0;
9903 + serial->tx_data_length = tx_size;
9904 + serial->tx_data = kzalloc(serial->tx_data_length, GFP_KERNEL);
9905 + if (!serial->tx_data)
9906 + goto exit;
9907 +
9908 + serial->tx_buffer = kzalloc(serial->tx_data_length, GFP_KERNEL);
9909 + if (!serial->tx_buffer)
9910 + goto exit;
9911 +
9912 + return 0;
9913 +exit:
9914 + hso_serial_tty_unregister(serial);
9915 + hso_serial_common_free(serial);
9916 + return -1;
9917 +}
9918 +
9919 +/* Creates a general hso device */
9920 +static struct hso_device *hso_create_device(struct usb_interface *intf,
9921 + int port_spec)
9922 +{
9923 + struct hso_device *hso_dev;
9924 +
9925 + hso_dev = kzalloc(sizeof(*hso_dev), GFP_ATOMIC);
9926 + if (!hso_dev)
9927 + return NULL;
9928 +
9929 + hso_dev->port_spec = port_spec;
9930 + hso_dev->usb = interface_to_usbdev(intf);
9931 + hso_dev->interface = intf;
9932 + kref_init(&hso_dev->ref);
9933 + mutex_init(&hso_dev->mutex);
9934 +
9935 + INIT_WORK(&hso_dev->async_get_intf, async_get_intf);
9936 + INIT_WORK(&hso_dev->async_put_intf, async_put_intf);
9937 +
9938 + return hso_dev;
9939 +}
9940 +
9941 +/* Removes a network device in the network device table */
9942 +static int remove_net_device(struct hso_device *hso_dev)
9943 +{
9944 + int i;
9945 +
9946 + for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
9947 + if (network_table[i] == hso_dev) {
9948 + network_table[i] = NULL;
9949 + break;
9950 + }
9951 + }
9952 + if (i == HSO_MAX_NET_DEVICES)
9953 + return -1;
9954 + return 0;
9955 +}
9956 +
9957 +/* Frees our network device */
9958 +static void hso_free_net_device(struct hso_device *hso_dev)
9959 +{
9960 + int i;
9961 + struct hso_net *hso_net = dev2net(hso_dev);
9962 +
9963 + if (!hso_net)
9964 + return;
9965 +
9966 + remove_net_device(hso_net->parent);
9967 +
9968 + if (hso_net->net)
9969 + unregister_netdev(hso_net->net);
9970 +
9971 + /* start freeing */
9972 + for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) {
9973 + usb_free_urb(hso_net->mux_bulk_rx_urb_pool[i]);
9974 + kfree(hso_net->mux_bulk_rx_buf_pool[i]);
9975 + hso_net->mux_bulk_rx_buf_pool[i] = NULL;
9976 + }
9977 + usb_free_urb(hso_net->mux_bulk_tx_urb);
9978 + kfree(hso_net->mux_bulk_tx_buf);
9979 + hso_net->mux_bulk_tx_buf = NULL;
9980 +
9981 + if (hso_net->net)
9982 + free_netdev(hso_net->net);
9983 +
9984 + kfree(hso_dev);
9985 +}
9986 +
9987 +static const struct net_device_ops hso_netdev_ops = {
9988 + .ndo_open = hso_net_open,
9989 + .ndo_stop = hso_net_close,
9990 + .ndo_start_xmit = hso_net_start_xmit,
9991 + .ndo_tx_timeout = hso_net_tx_timeout,
9992 +};
9993 +
9994 +/* initialize the network interface */
9995 +static void hso_net_init(struct net_device *net)
9996 +{
9997 + struct hso_net *hso_net = netdev_priv(net);
9998 +
9999 + D1("sizeof hso_net is %d", (int)sizeof(*hso_net));
10000 +
10001 + /* fill in the other fields */
10002 + net->netdev_ops = &hso_netdev_ops;
10003 + net->watchdog_timeo = HSO_NET_TX_TIMEOUT;
10004 + net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
10005 + net->type = ARPHRD_NONE;
10006 + net->mtu = DEFAULT_MTU - 14;
10007 + net->tx_queue_len = 10;
10008 + net->ethtool_ops = &ops;
10009 +
10010 + /* and initialize the semaphore */
10011 + spin_lock_init(&hso_net->net_lock);
10012 +}
10013 +
10014 +/* Adds a network device in the network device table */
10015 +static int add_net_device(struct hso_device *hso_dev)
10016 +{
10017 + int i;
10018 +
10019 + for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
10020 + if (network_table[i] == NULL) {
10021 + network_table[i] = hso_dev;
10022 + break;
10023 + }
10024 + }
10025 + if (i == HSO_MAX_NET_DEVICES)
10026 + return -1;
10027 + return 0;
10028 +}
10029 +
10030 +static int hso_rfkill_set_block(void *data, bool blocked)
10031 +{
10032 + struct hso_device *hso_dev = data;
10033 + int enabled = !blocked;
10034 + int rv;
10035 +
10036 + mutex_lock(&hso_dev->mutex);
10037 + if (hso_dev->usb_gone)
10038 + rv = 0;
10039 + else
10040 + rv = usb_control_msg(hso_dev->usb, usb_rcvctrlpipe(hso_dev->usb, 0),
10041 + enabled ? 0x82 : 0x81, 0x40, 0, 0, NULL, 0,
10042 + USB_CTRL_SET_TIMEOUT);
10043 + mutex_unlock(&hso_dev->mutex);
10044 + return rv;
10045 +}
10046 +
10047 +static const struct rfkill_ops hso_rfkill_ops = {
10048 + .set_block = hso_rfkill_set_block,
10049 +};
10050 +
10051 +/* Creates and sets up everything for rfkill */
10052 +static void hso_create_rfkill(struct hso_device *hso_dev,
10053 + struct usb_interface *interface)
10054 +{
10055 + struct hso_net *hso_net = dev2net(hso_dev);
10056 + struct device *dev = &hso_net->net->dev;
10057 + static u32 rfkill_counter;
10058 +
10059 + snprintf(hso_net->name, sizeof(hso_net->name), "hso-%d",
10060 + rfkill_counter++);
10061 +
10062 + hso_net->rfkill = rfkill_alloc(hso_net->name,
10063 + &interface_to_usbdev(interface)->dev,
10064 + RFKILL_TYPE_WWAN,
10065 + &hso_rfkill_ops, hso_dev);
10066 + if (!hso_net->rfkill) {
10067 + dev_err(dev, "%s - Out of memory\n", __func__);
10068 + return;
10069 + }
10070 + if (rfkill_register(hso_net->rfkill) < 0) {
10071 + rfkill_destroy(hso_net->rfkill);
10072 + hso_net->rfkill = NULL;
10073 + dev_err(dev, "%s - Failed to register rfkill\n", __func__);
10074 + return;
10075 + }
10076 +}
10077 +
10078 +static struct device_type hso_type = {
10079 + .name = "wwan",
10080 +};
10081 +
10082 +/* Creates our network device */
10083 +static struct hso_device *hso_create_net_device(struct usb_interface *interface,
10084 + int port_spec)
10085 +{
10086 + int result, i;
10087 + struct net_device *net;
10088 + struct hso_net *hso_net;
10089 + struct hso_device *hso_dev;
10090 +
10091 + hso_dev = hso_create_device(interface, port_spec);
10092 + if (!hso_dev)
10093 + return NULL;
10094 +
10095 + /* allocate our network device, then we can put in our private data */
10096 + /* call hso_net_init to do the basic initialization */
10097 + net = alloc_netdev(sizeof(struct hso_net), "hso%d", NET_NAME_UNKNOWN,
10098 + hso_net_init);
10099 + if (!net) {
10100 + dev_err(&interface->dev, "Unable to create ethernet device\n");
10101 + goto exit;
10102 + }
10103 +
10104 + hso_net = netdev_priv(net);
10105 +
10106 + hso_dev->port_data.dev_net = hso_net;
10107 + hso_net->net = net;
10108 + hso_net->parent = hso_dev;
10109 +
10110 + hso_net->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK,
10111 + USB_DIR_IN);
10112 + if (!hso_net->in_endp) {
10113 + dev_err(&interface->dev, "Can't find BULK IN endpoint\n");
10114 + goto exit;
10115 + }
10116 + hso_net->out_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK,
10117 + USB_DIR_OUT);
10118 + if (!hso_net->out_endp) {
10119 + dev_err(&interface->dev, "Can't find BULK OUT endpoint\n");
10120 + goto exit;
10121 + }
10122 + SET_NETDEV_DEV(net, &interface->dev);
10123 + SET_NETDEV_DEVTYPE(net, &hso_type);
10124 +
10125 + /* registering our net device */
10126 + result = register_netdev(net);
10127 + if (result) {
10128 + dev_err(&interface->dev, "Failed to register device\n");
10129 + goto exit;
10130 + }
10131 +
10132 + /* start allocating */
10133 + for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) {
10134 + hso_net->mux_bulk_rx_urb_pool[i] = usb_alloc_urb(0, GFP_KERNEL);
10135 + if (!hso_net->mux_bulk_rx_urb_pool[i]) {
10136 + dev_err(&interface->dev, "Could not allocate rx urb\n");
10137 + goto exit;
10138 + }
10139 + hso_net->mux_bulk_rx_buf_pool[i] = kzalloc(MUX_BULK_RX_BUF_SIZE,
10140 + GFP_KERNEL);
10141 + if (!hso_net->mux_bulk_rx_buf_pool[i])
10142 + goto exit;
10143 + }
10144 + hso_net->mux_bulk_tx_urb = usb_alloc_urb(0, GFP_KERNEL);
10145 + if (!hso_net->mux_bulk_tx_urb) {
10146 + dev_err(&interface->dev, "Could not allocate tx urb\n");
10147 + goto exit;
10148 + }
10149 + hso_net->mux_bulk_tx_buf = kzalloc(MUX_BULK_TX_BUF_SIZE, GFP_KERNEL);
10150 + if (!hso_net->mux_bulk_tx_buf)
10151 + goto exit;
10152 +
10153 + add_net_device(hso_dev);
10154 +
10155 + hso_log_port(hso_dev);
10156 +
10157 + hso_create_rfkill(hso_dev, interface);
10158 +
10159 + return hso_dev;
10160 +exit:
10161 + hso_free_net_device(hso_dev);
10162 + return NULL;
10163 +}
10164 +
10165 +static void hso_free_tiomget(struct hso_serial *serial)
10166 +{
10167 + struct hso_tiocmget *tiocmget;
10168 + if (!serial)
10169 + return;
10170 + tiocmget = serial->tiocmget;
10171 + if (tiocmget) {
10172 + usb_free_urb(tiocmget->urb);
10173 + tiocmget->urb = NULL;
10174 + serial->tiocmget = NULL;
10175 + kfree(tiocmget);
10176 + }
10177 +}
10178 +
10179 +/* Frees an AT channel ( goes for both mux and non-mux ) */
10180 +static void hso_free_serial_device(struct hso_device *hso_dev)
10181 +{
10182 + struct hso_serial *serial = dev2ser(hso_dev);
10183 +
10184 + if (!serial)
10185 + return;
10186 +
10187 + hso_serial_common_free(serial);
10188 +
10189 + if (serial->shared_int) {
10190 + mutex_lock(&serial->shared_int->shared_int_lock);
10191 + if (--serial->shared_int->ref_count == 0)
10192 + hso_free_shared_int(serial->shared_int);
10193 + else
10194 + mutex_unlock(&serial->shared_int->shared_int_lock);
10195 + }
10196 + hso_free_tiomget(serial);
10197 + kfree(serial);
10198 + kfree(hso_dev);
10199 +}
10200 +
10201 +/* Creates a bulk AT channel */
10202 +static struct hso_device *hso_create_bulk_serial_device(
10203 + struct usb_interface *interface, int port)
10204 +{
10205 + struct hso_device *hso_dev;
10206 + struct hso_serial *serial;
10207 + int num_urbs;
10208 + struct hso_tiocmget *tiocmget;
10209 +
10210 + hso_dev = hso_create_device(interface, port);
10211 + if (!hso_dev)
10212 + return NULL;
10213 +
10214 + serial = kzalloc(sizeof(*serial), GFP_KERNEL);
10215 + if (!serial)
10216 + goto exit;
10217 +
10218 + serial->parent = hso_dev;
10219 + hso_dev->port_data.dev_serial = serial;
10220 +
10221 + if ((port & HSO_PORT_MASK) == HSO_PORT_MODEM) {
10222 + num_urbs = 2;
10223 + serial->tiocmget = kzalloc(sizeof(struct hso_tiocmget),
10224 + GFP_KERNEL);
10225 + /* it isn't going to break our heart if serial->tiocmget
10226 + * allocation fails don't bother checking this.
10227 + */
10228 + if (serial->tiocmget) {
10229 + tiocmget = serial->tiocmget;
10230 + tiocmget->urb = usb_alloc_urb(0, GFP_KERNEL);
10231 + if (tiocmget->urb) {
10232 + mutex_init(&tiocmget->mutex);
10233 + init_waitqueue_head(&tiocmget->waitq);
10234 + tiocmget->endp = hso_get_ep(
10235 + interface,
10236 + USB_ENDPOINT_XFER_INT,
10237 + USB_DIR_IN);
10238 + } else
10239 + hso_free_tiomget(serial);
10240 + }
10241 + }
10242 + else
10243 + num_urbs = 1;
10244 +
10245 + if (hso_serial_common_create(serial, num_urbs, BULK_URB_RX_SIZE,
10246 + BULK_URB_TX_SIZE))
10247 + goto exit;
10248 +
10249 + serial->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK,
10250 + USB_DIR_IN);
10251 + if (!serial->in_endp) {
10252 + dev_err(&interface->dev, "Failed to find BULK IN ep\n");
10253 + goto exit2;
10254 + }
10255 +
10256 + if (!
10257 + (serial->out_endp =
10258 + hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT))) {
10259 + dev_err(&interface->dev, "Failed to find BULK IN ep\n");
10260 + goto exit2;
10261 + }
10262 +
10263 + serial->write_data = hso_std_serial_write_data;
10264 +
10265 + /* and record this serial */
10266 + set_serial_by_index(serial->minor, serial);
10267 +
10268 + /* setup the proc dirs and files if needed */
10269 + hso_log_port(hso_dev);
10270 +
10271 + /* done, return it */
10272 + return hso_dev;
10273 +
10274 +exit2:
10275 + hso_serial_tty_unregister(serial);
10276 + hso_serial_common_free(serial);
10277 +exit:
10278 + hso_free_tiomget(serial);
10279 + kfree(serial);
10280 + kfree(hso_dev);
10281 + return NULL;
10282 +}
10283 +
10284 +/* Creates a multiplexed AT channel */
10285 +static
10286 +struct hso_device *hso_create_mux_serial_device(struct usb_interface *interface,
10287 + int port,
10288 + struct hso_shared_int *mux)
10289 +{
10290 + struct hso_device *hso_dev;
10291 + struct hso_serial *serial;
10292 + int port_spec;
10293 +
10294 + port_spec = HSO_INTF_MUX;
10295 + port_spec &= ~HSO_PORT_MASK;
10296 +
10297 + port_spec |= hso_mux_to_port(port);
10298 + if ((port_spec & HSO_PORT_MASK) == HSO_PORT_NO_PORT)
10299 + return NULL;
10300 +
10301 + hso_dev = hso_create_device(interface, port_spec);
10302 + if (!hso_dev)
10303 + return NULL;
10304 +
10305 + serial = kzalloc(sizeof(*serial), GFP_KERNEL);
10306 + if (!serial)
10307 + goto exit;
10308 +
10309 + hso_dev->port_data.dev_serial = serial;
10310 + serial->parent = hso_dev;
10311 +
10312 + if (hso_serial_common_create
10313 + (serial, 1, CTRL_URB_RX_SIZE, CTRL_URB_TX_SIZE))
10314 + goto exit;
10315 +
10316 + serial->tx_data_length--;
10317 + serial->write_data = hso_mux_serial_write_data;
10318 +
10319 + serial->shared_int = mux;
10320 + mutex_lock(&serial->shared_int->shared_int_lock);
10321 + serial->shared_int->ref_count++;
10322 + mutex_unlock(&serial->shared_int->shared_int_lock);
10323 +
10324 + /* and record this serial */
10325 + set_serial_by_index(serial->minor, serial);
10326 +
10327 + /* setup the proc dirs and files if needed */
10328 + hso_log_port(hso_dev);
10329 +
10330 + /* done, return it */
10331 + return hso_dev;
10332 +
10333 +exit:
10334 + if (serial) {
10335 + tty_unregister_device(tty_drv, serial->minor);
10336 + kfree(serial);
10337 + }
10338 + kfree(hso_dev);
10339 + return NULL;
10340 +
10341 +}
10342 +
10343 +static void hso_free_shared_int(struct hso_shared_int *mux)
10344 +{
10345 + usb_free_urb(mux->shared_intr_urb);
10346 + kfree(mux->shared_intr_buf);
10347 + mutex_unlock(&mux->shared_int_lock);
10348 + kfree(mux);
10349 +}
10350 +
10351 +static
10352 +struct hso_shared_int *hso_create_shared_int(struct usb_interface *interface)
10353 +{
10354 + struct hso_shared_int *mux = kzalloc(sizeof(*mux), GFP_KERNEL);
10355 +
10356 + if (!mux)
10357 + return NULL;
10358 +
10359 + mux->intr_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_INT,
10360 + USB_DIR_IN);
10361 + if (!mux->intr_endp) {
10362 + dev_err(&interface->dev, "Can't find INT IN endpoint\n");
10363 + goto exit;
10364 + }
10365 +
10366 + mux->shared_intr_urb = usb_alloc_urb(0, GFP_KERNEL);
10367 + if (!mux->shared_intr_urb) {
10368 + dev_err(&interface->dev, "Could not allocate intr urb?\n");
10369 + goto exit;
10370 + }
10371 + mux->shared_intr_buf =
10372 + kzalloc(le16_to_cpu(mux->intr_endp->wMaxPacketSize),
10373 + GFP_KERNEL);
10374 + if (!mux->shared_intr_buf)
10375 + goto exit;
10376 +
10377 + mutex_init(&mux->shared_int_lock);
10378 +
10379 + return mux;
10380 +
10381 +exit:
10382 + kfree(mux->shared_intr_buf);
10383 + usb_free_urb(mux->shared_intr_urb);
10384 + kfree(mux);
10385 + return NULL;
10386 +}
10387 +
10388 +/* Gets the port spec for a certain interface */
10389 +static int hso_get_config_data(struct usb_interface *interface)
10390 +{
10391 + struct usb_device *usbdev = interface_to_usbdev(interface);
10392 + u8 *config_data = kmalloc(17, GFP_KERNEL);
10393 + u32 if_num = interface->cur_altsetting->desc.bInterfaceNumber;
10394 + s32 result;
10395 +
10396 + if (!config_data)
10397 + return -ENOMEM;
10398 + if (usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
10399 + 0x86, 0xC0, 0, 0, config_data, 17,
10400 + USB_CTRL_SET_TIMEOUT) != 0x11) {
10401 + kfree(config_data);
10402 + return -EIO;
10403 + }
10404 +
10405 + switch (config_data[if_num]) {
10406 + case 0x0:
10407 + result = 0;
10408 + break;
10409 + case 0x1:
10410 + result = HSO_PORT_DIAG;
10411 + break;
10412 + case 0x2:
10413 + result = HSO_PORT_GPS;
10414 + break;
10415 + case 0x3:
10416 + result = HSO_PORT_GPS_CONTROL;
10417 + break;
10418 + case 0x4:
10419 + result = HSO_PORT_APP;
10420 + break;
10421 + case 0x5:
10422 + result = HSO_PORT_APP2;
10423 + break;
10424 + case 0x6:
10425 + result = HSO_PORT_CONTROL;
10426 + break;
10427 + case 0x7:
10428 + result = HSO_PORT_NETWORK;
10429 + break;
10430 + case 0x8:
10431 + result = HSO_PORT_MODEM;
10432 + break;
10433 + case 0x9:
10434 + result = HSO_PORT_MSD;
10435 + break;
10436 + case 0xa:
10437 + result = HSO_PORT_PCSC;
10438 + break;
10439 + case 0xb:
10440 + result = HSO_PORT_VOICE;
10441 + break;
10442 + default:
10443 + result = 0;
10444 + }
10445 +
10446 + if (result)
10447 + result |= HSO_INTF_BULK;
10448 +
10449 + if (config_data[16] & 0x1)
10450 + result |= HSO_INFO_CRC_BUG;
10451 +
10452 + kfree(config_data);
10453 + return result;
10454 +}
10455 +
10456 +/* called once for each interface upon device insertion */
10457 +static int hso_probe(struct usb_interface *interface,
10458 + const struct usb_device_id *id)
10459 +{
10460 + int mux, i, if_num, port_spec;
10461 + unsigned char port_mask;
10462 + struct hso_device *hso_dev = NULL;
10463 + struct hso_shared_int *shared_int;
10464 + struct hso_device *tmp_dev = NULL;
10465 +
10466 + if (interface->cur_altsetting->desc.bInterfaceClass != 0xFF) {
10467 + dev_err(&interface->dev, "Not our interface\n");
10468 + return -ENODEV;
10469 + }
10470 +
10471 + if_num = interface->cur_altsetting->desc.bInterfaceNumber;
10472 +
10473 + /* Get the interface/port specification from either driver_info or from
10474 + * the device itself */
10475 + if (id->driver_info)
10476 + port_spec = ((u32 *)(id->driver_info))[if_num];
10477 + else
10478 + port_spec = hso_get_config_data(interface);
10479 +
10480 + /* Check if we need to switch to alt interfaces prior to port
10481 + * configuration */
10482 + if (interface->num_altsetting > 1)
10483 + usb_set_interface(interface_to_usbdev(interface), if_num, 1);
10484 + interface->needs_remote_wakeup = 1;
10485 +
10486 + /* Allocate new hso device(s) */
10487 + switch (port_spec & HSO_INTF_MASK) {
10488 + case HSO_INTF_MUX:
10489 + if ((port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) {
10490 + /* Create the network device */
10491 + if (!disable_net) {
10492 + hso_dev = hso_create_net_device(interface,
10493 + port_spec);
10494 + if (!hso_dev)
10495 + goto exit;
10496 + tmp_dev = hso_dev;
10497 + }
10498 + }
10499 +
10500 + if (hso_get_mux_ports(interface, &port_mask))
10501 + /* TODO: de-allocate everything */
10502 + goto exit;
10503 +
10504 + shared_int = hso_create_shared_int(interface);
10505 + if (!shared_int)
10506 + goto exit;
10507 +
10508 + for (i = 1, mux = 0; i < 0x100; i = i << 1, mux++) {
10509 + if (port_mask & i) {
10510 + hso_dev = hso_create_mux_serial_device(
10511 + interface, i, shared_int);
10512 + if (!hso_dev)
10513 + goto exit;
10514 + }
10515 + }
10516 +
10517 + if (tmp_dev)
10518 + hso_dev = tmp_dev;
10519 + break;
10520 +
10521 + case HSO_INTF_BULK:
10522 + /* It's a regular bulk interface */
10523 + if ((port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) {
10524 + if (!disable_net)
10525 + hso_dev =
10526 + hso_create_net_device(interface, port_spec);
10527 + } else {
10528 + hso_dev =
10529 + hso_create_bulk_serial_device(interface, port_spec);
10530 + }
10531 + if (!hso_dev)
10532 + goto exit;
10533 + break;
10534 + default:
10535 + goto exit;
10536 + }
10537 +
10538 + /* save our data pointer in this device */
10539 + usb_set_intfdata(interface, hso_dev);
10540 +
10541 + /* done */
10542 + return 0;
10543 +exit:
10544 + hso_free_interface(interface);
10545 + return -ENODEV;
10546 +}
10547 +
10548 +/* device removed, cleaning up */
10549 +static void hso_disconnect(struct usb_interface *interface)
10550 +{
10551 + hso_free_interface(interface);
10552 +
10553 + /* remove reference of our private data */
10554 + usb_set_intfdata(interface, NULL);
10555 +}
10556 +
10557 +static void async_get_intf(struct work_struct *data)
10558 +{
10559 + struct hso_device *hso_dev =
10560 + container_of(data, struct hso_device, async_get_intf);
10561 + usb_autopm_get_interface(hso_dev->interface);
10562 +}
10563 +
10564 +static void async_put_intf(struct work_struct *data)
10565 +{
10566 + struct hso_device *hso_dev =
10567 + container_of(data, struct hso_device, async_put_intf);
10568 + usb_autopm_put_interface(hso_dev->interface);
10569 +}
10570 +
10571 +static int hso_get_activity(struct hso_device *hso_dev)
10572 +{
10573 + if (hso_dev->usb->state == USB_STATE_SUSPENDED) {
10574 + if (!hso_dev->is_active) {
10575 + hso_dev->is_active = 1;
10576 + schedule_work(&hso_dev->async_get_intf);
10577 + }
10578 + }
10579 +
10580 + if (hso_dev->usb->state != USB_STATE_CONFIGURED)
10581 + return -EAGAIN;
10582 +
10583 + usb_mark_last_busy(hso_dev->usb);
10584 +
10585 + return 0;
10586 +}
10587 +
10588 +static int hso_put_activity(struct hso_device *hso_dev)
10589 +{
10590 + if (hso_dev->usb->state != USB_STATE_SUSPENDED) {
10591 + if (hso_dev->is_active) {
10592 + hso_dev->is_active = 0;
10593 + schedule_work(&hso_dev->async_put_intf);
10594 + return -EAGAIN;
10595 + }
10596 + }
10597 + hso_dev->is_active = 0;
10598 + return 0;
10599 +}
10600 +
10601 +/* called by kernel when we need to suspend device */
10602 +static int hso_suspend(struct usb_interface *iface, pm_message_t message)
10603 +{
10604 + int i, result;
10605 +
10606 + /* Stop all serial ports */
10607 + for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
10608 + if (serial_table[i] && (serial_table[i]->interface == iface)) {
10609 + result = hso_stop_serial_device(serial_table[i]);
10610 + if (result)
10611 + goto out;
10612 + }
10613 + }
10614 +
10615 + /* Stop all network ports */
10616 + for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
10617 + if (network_table[i] &&
10618 + (network_table[i]->interface == iface)) {
10619 + result = hso_stop_net_device(network_table[i]);
10620 + if (result)
10621 + goto out;
10622 + }
10623 + }
10624 +
10625 +out:
10626 + return 0;
10627 +}
10628 +
10629 +/* called by kernel when we need to resume device */
10630 +static int hso_resume(struct usb_interface *iface)
10631 +{
10632 + int i, result = 0;
10633 + struct hso_net *hso_net;
10634 +
10635 + /* Start all serial ports */
10636 + for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
10637 + if (serial_table[i] && (serial_table[i]->interface == iface)) {
10638 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
10639 + result =
10640 + hso_start_serial_device(serial_table[i], GFP_NOIO);
10641 + hso_kick_transmit(dev2ser(serial_table[i]));
10642 + if (result)
10643 + goto out;
10644 + }
10645 + }
10646 + }
10647 +
10648 + /* Start all network ports */
10649 + for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
10650 + if (network_table[i] &&
10651 + (network_table[i]->interface == iface)) {
10652 + hso_net = dev2net(network_table[i]);
10653 + if (hso_net->flags & IFF_UP) {
10654 + /* First transmit any lingering data,
10655 + then restart the device. */
10656 + if (hso_net->skb_tx_buf) {
10657 + dev_dbg(&iface->dev,
10658 + "Transmitting"
10659 + " lingering data\n");
10660 + hso_net_start_xmit(hso_net->skb_tx_buf,
10661 + hso_net->net);
10662 + hso_net->skb_tx_buf = NULL;
10663 + }
10664 + result = hso_start_net_device(network_table[i]);
10665 + if (result)
10666 + goto out;
10667 + }
10668 + }
10669 + }
10670 +
10671 +out:
10672 + return result;
10673 +}
10674 +
10675 +static void hso_serial_ref_free(struct kref *ref)
10676 +{
10677 + struct hso_device *hso_dev = container_of(ref, struct hso_device, ref);
10678 +
10679 + hso_free_serial_device(hso_dev);
10680 +}
10681 +
10682 +static void hso_free_interface(struct usb_interface *interface)
10683 +{
10684 + struct hso_serial *serial;
10685 + int i;
10686 +
10687 + for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
10688 + if (serial_table[i] &&
10689 + (serial_table[i]->interface == interface)) {
10690 + serial = dev2ser(serial_table[i]);
10691 + tty_port_tty_hangup(&serial->port, false);
10692 + mutex_lock(&serial->parent->mutex);
10693 + serial->parent->usb_gone = 1;
10694 + mutex_unlock(&serial->parent->mutex);
10695 + cancel_work_sync(&serial_table[i]->async_put_intf);
10696 + cancel_work_sync(&serial_table[i]->async_get_intf);
10697 + hso_serial_tty_unregister(serial);
10698 + kref_put(&serial_table[i]->ref, hso_serial_ref_free);
10699 + set_serial_by_index(i, NULL);
10700 + }
10701 + }
10702 +
10703 + for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
10704 + if (network_table[i] &&
10705 + (network_table[i]->interface == interface)) {
10706 + struct rfkill *rfk = dev2net(network_table[i])->rfkill;
10707 + /* hso_stop_net_device doesn't stop the net queue since
10708 + * traffic needs to start it again when suspended */
10709 + netif_stop_queue(dev2net(network_table[i])->net);
10710 + hso_stop_net_device(network_table[i]);
10711 + cancel_work_sync(&network_table[i]->async_put_intf);
10712 + cancel_work_sync(&network_table[i]->async_get_intf);
10713 + if (rfk) {
10714 + rfkill_unregister(rfk);
10715 + rfkill_destroy(rfk);
10716 + }
10717 + hso_free_net_device(network_table[i]);
10718 + }
10719 + }
10720 +}
10721 +
10722 +/* Helper functions */
10723 +
10724 +/* Get the endpoint ! */
10725 +static struct usb_endpoint_descriptor *hso_get_ep(struct usb_interface *intf,
10726 + int type, int dir)
10727 +{
10728 + int i;
10729 + struct usb_host_interface *iface = intf->cur_altsetting;
10730 + struct usb_endpoint_descriptor *endp;
10731 +
10732 + for (i = 0; i < iface->desc.bNumEndpoints; i++) {
10733 + endp = &iface->endpoint[i].desc;
10734 + if (((endp->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == dir) &&
10735 + (usb_endpoint_type(endp) == type))
10736 + return endp;
10737 + }
10738 +
10739 + return NULL;
10740 +}
10741 +
10742 +/* Get the byte that describes which ports are enabled */
10743 +static int hso_get_mux_ports(struct usb_interface *intf, unsigned char *ports)
10744 +{
10745 + int i;
10746 + struct usb_host_interface *iface = intf->cur_altsetting;
10747 +
10748 + if (iface->extralen == 3) {
10749 + *ports = iface->extra[2];
10750 + return 0;
10751 + }
10752 +
10753 + for (i = 0; i < iface->desc.bNumEndpoints; i++) {
10754 + if (iface->endpoint[i].extralen == 3) {
10755 + *ports = iface->endpoint[i].extra[2];
10756 + return 0;
10757 + }
10758 + }
10759 +
10760 + return -1;
10761 +}
10762 +
10763 +/* interrupt urb needs to be submitted, used for serial read of muxed port */
10764 +static int hso_mux_submit_intr_urb(struct hso_shared_int *shared_int,
10765 + struct usb_device *usb, gfp_t gfp)
10766 +{
10767 + int result;
10768 +
10769 + usb_fill_int_urb(shared_int->shared_intr_urb, usb,
10770 + usb_rcvintpipe(usb,
10771 + shared_int->intr_endp->bEndpointAddress & 0x7F),
10772 + shared_int->shared_intr_buf,
10773 + 1,
10774 + intr_callback, shared_int,
10775 + shared_int->intr_endp->bInterval);
10776 +
10777 + result = usb_submit_urb(shared_int->shared_intr_urb, gfp);
10778 + if (result)
10779 + dev_warn(&usb->dev, "%s failed mux_intr_urb %d\n", __func__,
10780 + result);
10781 +
10782 + return result;
10783 +}
10784 +
10785 +/* operations setup of the serial interface */
10786 +static const struct tty_operations hso_serial_ops = {
10787 + .open = hso_serial_open,
10788 + .close = hso_serial_close,
10789 + .write = hso_serial_write,
10790 + .write_room = hso_serial_write_room,
10791 + .cleanup = hso_serial_cleanup,
10792 + .ioctl = hso_serial_ioctl,
10793 + .set_termios = hso_serial_set_termios,
10794 + .chars_in_buffer = hso_serial_chars_in_buffer,
10795 + .tiocmget = hso_serial_tiocmget,
10796 + .tiocmset = hso_serial_tiocmset,
10797 + .get_icount = hso_get_count,
10798 + .unthrottle = hso_unthrottle
10799 +};
10800 +
10801 +static struct usb_driver hso_driver = {
10802 + .name = driver_name,
10803 + .probe = hso_probe,
10804 + .disconnect = hso_disconnect,
10805 + .id_table = hso_ids,
10806 + .suspend = hso_suspend,
10807 + .resume = hso_resume,
10808 + .reset_resume = hso_resume,
10809 + .supports_autosuspend = 1,
10810 + .disable_hub_initiated_lpm = 1,
10811 +};
10812 +
10813 +static int __init hso_init(void)
10814 +{
10815 + int i;
10816 + int result;
10817 +
10818 + /* put it in the log */
10819 + printk(KERN_INFO "hso: %s\n", version);
10820 +
10821 + /* Initialise the serial table semaphore and table */
10822 + spin_lock_init(&serial_table_lock);
10823 + for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++)
10824 + serial_table[i] = NULL;
10825 +
10826 + /* allocate our driver using the proper amount of supported minors */
10827 + tty_drv = alloc_tty_driver(HSO_SERIAL_TTY_MINORS);
10828 + if (!tty_drv)
10829 + return -ENOMEM;
10830 +
10831 + /* fill in all needed values */
10832 + tty_drv->driver_name = driver_name;
10833 + tty_drv->name = tty_filename;
10834 +
10835 + /* if major number is provided as parameter, use that one */
10836 + if (tty_major)
10837 + tty_drv->major = tty_major;
10838 +
10839 + tty_drv->minor_start = 0;
10840 + tty_drv->type = TTY_DRIVER_TYPE_SERIAL;
10841 + tty_drv->subtype = SERIAL_TYPE_NORMAL;
10842 + tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
10843 + tty_drv->init_termios = tty_std_termios;
10844 + hso_init_termios(&tty_drv->init_termios);
10845 + tty_set_operations(tty_drv, &hso_serial_ops);
10846 +
10847 + /* register the tty driver */
10848 + result = tty_register_driver(tty_drv);
10849 + if (result) {
10850 + printk(KERN_ERR "%s - tty_register_driver failed(%d)\n",
10851 + __func__, result);
10852 + goto err_free_tty;
10853 + }
10854 +
10855 + /* register this module as an usb driver */
10856 + result = usb_register(&hso_driver);
10857 + if (result) {
10858 + printk(KERN_ERR "Could not register hso driver? error: %d\n",
10859 + result);
10860 + goto err_unreg_tty;
10861 + }
10862 +
10863 + /* done */
10864 + return 0;
10865 +err_unreg_tty:
10866 + tty_unregister_driver(tty_drv);
10867 +err_free_tty:
10868 + put_tty_driver(tty_drv);
10869 + return result;
10870 +}
10871 +
10872 +static void __exit hso_exit(void)
10873 +{
10874 + printk(KERN_INFO "hso: unloaded\n");
10875 +
10876 + tty_unregister_driver(tty_drv);
10877 + put_tty_driver(tty_drv);
10878 + /* deregister the usb driver */
10879 + usb_deregister(&hso_driver);
10880 +}
10881 +
10882 +/* Module definitions */
10883 +module_init(hso_init);
10884 +module_exit(hso_exit);
10885 +
10886 +MODULE_AUTHOR(MOD_AUTHOR);
10887 +MODULE_DESCRIPTION(MOD_DESCRIPTION);
10888 +MODULE_LICENSE(MOD_LICENSE);
10889 +
10890 +/* change the debug level (eg: insmod hso.ko debug=0x04) */
10891 +MODULE_PARM_DESC(debug, "Level of debug [0x01 | 0x02 | 0x04 | 0x08 | 0x10]");
10892 +module_param(debug, int, S_IRUGO | S_IWUSR);
10893 +
10894 +/* set the major tty number (eg: insmod hso.ko tty_major=245) */
10895 +MODULE_PARM_DESC(tty_major, "Set the major tty number");
10896 +module_param(tty_major, int, S_IRUGO | S_IWUSR);
10897 +
10898 +/* disable network interface (eg: insmod hso.ko disable_net=1) */
10899 +MODULE_PARM_DESC(disable_net, "Disable the network interface");
10900 +module_param(disable_net, int, S_IRUGO | S_IWUSR);
10901 diff -Naur backports-4.2.6-1.org/drivers/net/usb/huawei_cdc_ncm.c backports-4.2.6-1/drivers/net/usb/huawei_cdc_ncm.c
10902 --- backports-4.2.6-1.org/drivers/net/usb/huawei_cdc_ncm.c 1970-01-01 01:00:00.000000000 +0100
10903 +++ backports-4.2.6-1/drivers/net/usb/huawei_cdc_ncm.c 2016-06-28 14:35:17.981973887 +0200
10904 @@ -0,0 +1,224 @@
10905 +/* huawei_cdc_ncm.c - handles Huawei devices using the CDC NCM protocol as
10906 + * transport layer.
10907 + * Copyright (C) 2013 Enrico Mioso <mrkiko.rs@gmail.com>
10908 + *
10909 + *
10910 + * ABSTRACT:
10911 + * This driver handles devices resembling the CDC NCM standard, but
10912 + * encapsulating another protocol inside it. An example are some Huawei 3G
10913 + * devices, exposing an embedded AT channel where you can set up the NCM
10914 + * connection.
10915 + * This code has been heavily inspired by the cdc_mbim.c driver, which is
10916 + * Copyright (c) 2012 Smith Micro Software, Inc.
10917 + * Copyright (c) 2012 Bjørn Mork <bjorn@mork.no>
10918 + *
10919 + * This program is free software; you can redistribute it and/or
10920 + * modify it under the terms of the GNU General Public License
10921 + * version 2 as published by the Free Software Foundation.
10922 + */
10923 +
10924 +#include <linux/module.h>
10925 +#include <linux/netdevice.h>
10926 +#include <linux/ethtool.h>
10927 +#include <linux/if_vlan.h>
10928 +#include <linux/ip.h>
10929 +#include <linux/mii.h>
10930 +#include <linux/usb.h>
10931 +#include <linux/usb/cdc.h>
10932 +#include <linux/usb/usbnet.h>
10933 +#include <linux/usb/cdc-wdm.h>
10934 +#include <linux/usb/cdc_ncm.h>
10935 +
10936 +/* Driver data */
10937 +struct huawei_cdc_ncm_state {
10938 + struct cdc_ncm_ctx *ctx;
10939 + atomic_t pmcount;
10940 + struct usb_driver *subdriver;
10941 + struct usb_interface *control;
10942 + struct usb_interface *data;
10943 +};
10944 +
10945 +static int huawei_cdc_ncm_manage_power(struct usbnet *usbnet_dev, int on)
10946 +{
10947 + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
10948 + int rv;
10949 +
10950 + if ((on && atomic_add_return(1, &drvstate->pmcount) == 1) ||
10951 + (!on && atomic_dec_and_test(&drvstate->pmcount))) {
10952 + rv = usb_autopm_get_interface(usbnet_dev->intf);
10953 + usbnet_dev->intf->needs_remote_wakeup = on;
10954 + if (!rv)
10955 + usb_autopm_put_interface(usbnet_dev->intf);
10956 + }
10957 + return 0;
10958 +}
10959 +
10960 +static int huawei_cdc_ncm_wdm_manage_power(struct usb_interface *intf,
10961 + int status)
10962 +{
10963 + struct usbnet *usbnet_dev = usb_get_intfdata(intf);
10964 +
10965 + /* can be called while disconnecting */
10966 + if (!usbnet_dev)
10967 + return 0;
10968 +
10969 + return huawei_cdc_ncm_manage_power(usbnet_dev, status);
10970 +}
10971 +
10972 +
10973 +static int huawei_cdc_ncm_bind(struct usbnet *usbnet_dev,
10974 + struct usb_interface *intf)
10975 +{
10976 + struct cdc_ncm_ctx *ctx;
10977 + struct usb_driver *subdriver = ERR_PTR(-ENODEV);
10978 + int ret = -ENODEV;
10979 + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
10980 + int drvflags = 0;
10981 +
10982 + /* altsetting should always be 1 for NCM devices - so we hard-coded
10983 + * it here. Some huawei devices will need the NDP part of the NCM package to
10984 + * be at the end of the frame.
10985 + */
10986 + drvflags |= CDC_NCM_FLAG_NDP_TO_END;
10987 + ret = cdc_ncm_bind_common(usbnet_dev, intf, 1, drvflags);
10988 + if (ret)
10989 + goto err;
10990 +
10991 + ctx = drvstate->ctx;
10992 +
10993 + if (usbnet_dev->status)
10994 + /* The wMaxCommand buffer must be big enough to hold
10995 + * any message from the modem. Experience has shown
10996 + * that some replies are more than 256 bytes long
10997 + */
10998 + subdriver = usb_cdc_wdm_register(ctx->control,
10999 + &usbnet_dev->status->desc,
11000 + 1024, /* wMaxCommand */
11001 + huawei_cdc_ncm_wdm_manage_power);
11002 + if (IS_ERR(subdriver)) {
11003 + ret = PTR_ERR(subdriver);
11004 + cdc_ncm_unbind(usbnet_dev, intf);
11005 + goto err;
11006 + }
11007 +
11008 + /* Prevent usbnet from using the status descriptor */
11009 + usbnet_dev->status = NULL;
11010 +
11011 + drvstate->subdriver = subdriver;
11012 +
11013 +err:
11014 + return ret;
11015 +}
11016 +
11017 +static void huawei_cdc_ncm_unbind(struct usbnet *usbnet_dev,
11018 + struct usb_interface *intf)
11019 +{
11020 + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
11021 + struct cdc_ncm_ctx *ctx = drvstate->ctx;
11022 +
11023 + if (drvstate->subdriver && drvstate->subdriver->disconnect)
11024 + drvstate->subdriver->disconnect(ctx->control);
11025 + drvstate->subdriver = NULL;
11026 +
11027 + cdc_ncm_unbind(usbnet_dev, intf);
11028 +}
11029 +
11030 +static int huawei_cdc_ncm_suspend(struct usb_interface *intf,
11031 + pm_message_t message)
11032 +{
11033 + int ret = 0;
11034 + struct usbnet *usbnet_dev = usb_get_intfdata(intf);
11035 + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
11036 + struct cdc_ncm_ctx *ctx = drvstate->ctx;
11037 +
11038 + if (ctx == NULL) {
11039 + ret = -ENODEV;
11040 + goto error;
11041 + }
11042 +
11043 + ret = usbnet_suspend(intf, message);
11044 + if (ret < 0)
11045 + goto error;
11046 +
11047 + if (intf == ctx->control &&
11048 + drvstate->subdriver &&
11049 + drvstate->subdriver->suspend)
11050 + ret = drvstate->subdriver->suspend(intf, message);
11051 + if (ret < 0)
11052 + usbnet_resume(intf);
11053 +
11054 +error:
11055 + return ret;
11056 +}
11057 +
11058 +static int huawei_cdc_ncm_resume(struct usb_interface *intf)
11059 +{
11060 + int ret = 0;
11061 + struct usbnet *usbnet_dev = usb_get_intfdata(intf);
11062 + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
11063 + bool callsub;
11064 + struct cdc_ncm_ctx *ctx = drvstate->ctx;
11065 +
11066 + /* should we call subdriver's resume function? */
11067 + callsub =
11068 + (intf == ctx->control &&
11069 + drvstate->subdriver &&
11070 + drvstate->subdriver->resume);
11071 +
11072 + if (callsub)
11073 + ret = drvstate->subdriver->resume(intf);
11074 + if (ret < 0)
11075 + goto err;
11076 + ret = usbnet_resume(intf);
11077 + if (ret < 0 && callsub)
11078 + drvstate->subdriver->suspend(intf, PMSG_SUSPEND);
11079 +err:
11080 + return ret;
11081 +}
11082 +
11083 +static const struct driver_info huawei_cdc_ncm_info = {
11084 + .description = "Huawei CDC NCM device",
11085 + .flags = FLAG_NO_SETINT | FLAG_MULTI_PACKET | FLAG_WWAN,
11086 + .bind = huawei_cdc_ncm_bind,
11087 + .unbind = huawei_cdc_ncm_unbind,
11088 + .manage_power = huawei_cdc_ncm_manage_power,
11089 + .rx_fixup = cdc_ncm_rx_fixup,
11090 + .tx_fixup = cdc_ncm_tx_fixup,
11091 +};
11092 +
11093 +static const struct usb_device_id huawei_cdc_ncm_devs[] = {
11094 + /* Huawei NCM devices disguised as vendor specific */
11095 + { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x16),
11096 + .driver_info = (unsigned long)&huawei_cdc_ncm_info,
11097 + },
11098 + { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x46),
11099 + .driver_info = (unsigned long)&huawei_cdc_ncm_info,
11100 + },
11101 + { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x76),
11102 + .driver_info = (unsigned long)&huawei_cdc_ncm_info,
11103 + },
11104 + { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x03, 0x16),
11105 + .driver_info = (unsigned long)&huawei_cdc_ncm_info,
11106 + },
11107 +
11108 + /* Terminating entry */
11109 + {
11110 + },
11111 +};
11112 +MODULE_DEVICE_TABLE(usb, huawei_cdc_ncm_devs);
11113 +
11114 +static struct usb_driver huawei_cdc_ncm_driver = {
11115 + .name = "huawei_cdc_ncm",
11116 + .id_table = huawei_cdc_ncm_devs,
11117 + .probe = usbnet_probe,
11118 + .disconnect = usbnet_disconnect,
11119 + .suspend = huawei_cdc_ncm_suspend,
11120 + .resume = huawei_cdc_ncm_resume,
11121 + .reset_resume = huawei_cdc_ncm_resume,
11122 + .supports_autosuspend = 1,
11123 + .disable_hub_initiated_lpm = 1,
11124 +};
11125 +module_usb_driver(huawei_cdc_ncm_driver);
11126 +MODULE_AUTHOR("Enrico Mioso <mrkiko.rs@gmail.com>");
11127 +MODULE_DESCRIPTION("USB CDC NCM host driver with encapsulated protocol support");
11128 +MODULE_LICENSE("GPL");
11129 diff -Naur backports-4.2.6-1.org/drivers/net/usb/int51x1.c backports-4.2.6-1/drivers/net/usb/int51x1.c
11130 --- backports-4.2.6-1.org/drivers/net/usb/int51x1.c 1970-01-01 01:00:00.000000000 +0100
11131 +++ backports-4.2.6-1/drivers/net/usb/int51x1.c 2016-06-28 14:35:17.985307220 +0200
11132 @@ -0,0 +1,199 @@
11133 +/*
11134 + * Copyright (c) 2009 Peter Holik
11135 + *
11136 + * Intellon usb PLC (Powerline Communications) usb net driver
11137 + *
11138 + * http://www.tandel.be/downloads/INT51X1_Datasheet.pdf
11139 + *
11140 + * Based on the work of Jan 'RedBully' Seiffert
11141 + */
11142 +
11143 +/*
11144 + * This program is free software; you can redistribute it and/or modify
11145 + * it under the terms of the GNU General Public License as published by
11146 + * the Free Software Foundation; either version 2 of the License, or.
11147 + * (at your option) any later version.
11148 + *
11149 + * This program is distributed in the hope that it will be useful,
11150 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11151 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11152 + * GNU General Public License for more details.
11153 + *
11154 + * You should have received a copy of the GNU General Public License
11155 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
11156 + */
11157 +
11158 +#include <linux/module.h>
11159 +#include <linux/ctype.h>
11160 +#include <linux/netdevice.h>
11161 +#include <linux/etherdevice.h>
11162 +#include <linux/ethtool.h>
11163 +#include <linux/slab.h>
11164 +#include <linux/mii.h>
11165 +#include <linux/usb.h>
11166 +#include <linux/usb/usbnet.h>
11167 +
11168 +#define INT51X1_VENDOR_ID 0x09e1
11169 +#define INT51X1_PRODUCT_ID 0x5121
11170 +
11171 +#define INT51X1_HEADER_SIZE 2 /* 2 byte header */
11172 +
11173 +#define PACKET_TYPE_PROMISCUOUS (1 << 0)
11174 +#define PACKET_TYPE_ALL_MULTICAST (1 << 1) /* no filter */
11175 +#define PACKET_TYPE_DIRECTED (1 << 2)
11176 +#define PACKET_TYPE_BROADCAST (1 << 3)
11177 +#define PACKET_TYPE_MULTICAST (1 << 4) /* filtered */
11178 +
11179 +#define SET_ETHERNET_PACKET_FILTER 0x43
11180 +
11181 +static int int51x1_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
11182 +{
11183 + int len;
11184 +
11185 + if (!(pskb_may_pull(skb, INT51X1_HEADER_SIZE))) {
11186 + netdev_err(dev->net, "unexpected tiny rx frame\n");
11187 + return 0;
11188 + }
11189 +
11190 + len = le16_to_cpu(*(__le16 *)&skb->data[skb->len - 2]);
11191 +
11192 + skb_trim(skb, len);
11193 +
11194 + return 1;
11195 +}
11196 +
11197 +static struct sk_buff *int51x1_tx_fixup(struct usbnet *dev,
11198 + struct sk_buff *skb, gfp_t flags)
11199 +{
11200 + int pack_len = skb->len;
11201 + int pack_with_header_len = pack_len + INT51X1_HEADER_SIZE;
11202 + int headroom = skb_headroom(skb);
11203 + int tailroom = skb_tailroom(skb);
11204 + int need_tail = 0;
11205 + __le16 *len;
11206 +
11207 + /* if packet and our header is smaler than 64 pad to 64 (+ ZLP) */
11208 + if ((pack_with_header_len) < dev->maxpacket)
11209 + need_tail = dev->maxpacket - pack_with_header_len + 1;
11210 + /*
11211 + * usbnet would send a ZLP if packetlength mod urbsize == 0 for us,
11212 + * but we need to know ourself, because this would add to the length
11213 + * we send down to the device...
11214 + */
11215 + else if (!(pack_with_header_len % dev->maxpacket))
11216 + need_tail = 1;
11217 +
11218 + if (!skb_cloned(skb) &&
11219 + (headroom + tailroom >= need_tail + INT51X1_HEADER_SIZE)) {
11220 + if (headroom < INT51X1_HEADER_SIZE || tailroom < need_tail) {
11221 + skb->data = memmove(skb->head + INT51X1_HEADER_SIZE,
11222 + skb->data, skb->len);
11223 + skb_set_tail_pointer(skb, skb->len);
11224 + }
11225 + } else {
11226 + struct sk_buff *skb2;
11227 +
11228 + skb2 = skb_copy_expand(skb,
11229 + INT51X1_HEADER_SIZE,
11230 + need_tail,
11231 + flags);
11232 + dev_kfree_skb_any(skb);
11233 + if (!skb2)
11234 + return NULL;
11235 + skb = skb2;
11236 + }
11237 +
11238 + pack_len += need_tail;
11239 + pack_len &= 0x07ff;
11240 +
11241 + len = (__le16 *) __skb_push(skb, INT51X1_HEADER_SIZE);
11242 + *len = cpu_to_le16(pack_len);
11243 +
11244 + if(need_tail)
11245 + memset(__skb_put(skb, need_tail), 0, need_tail);
11246 +
11247 + return skb;
11248 +}
11249 +
11250 +static void int51x1_set_multicast(struct net_device *netdev)
11251 +{
11252 + struct usbnet *dev = netdev_priv(netdev);
11253 + u16 filter = PACKET_TYPE_DIRECTED | PACKET_TYPE_BROADCAST;
11254 +
11255 + if (netdev->flags & IFF_PROMISC) {
11256 + /* do not expect to see traffic of other PLCs */
11257 + filter |= PACKET_TYPE_PROMISCUOUS;
11258 + netdev_info(dev->net, "promiscuous mode enabled\n");
11259 + } else if (!netdev_mc_empty(netdev) ||
11260 + (netdev->flags & IFF_ALLMULTI)) {
11261 + filter |= PACKET_TYPE_ALL_MULTICAST;
11262 + netdev_dbg(dev->net, "receive all multicast enabled\n");
11263 + } else {
11264 + /* ~PROMISCUOUS, ~MULTICAST */
11265 + netdev_dbg(dev->net, "receive own packets only\n");
11266 + }
11267 +
11268 + usbnet_write_cmd_async(dev, SET_ETHERNET_PACKET_FILTER,
11269 + USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
11270 + filter, 0, NULL, 0);
11271 +}
11272 +
11273 +static const struct net_device_ops int51x1_netdev_ops = {
11274 + .ndo_open = usbnet_open,
11275 + .ndo_stop = usbnet_stop,
11276 + .ndo_start_xmit = usbnet_start_xmit,
11277 + .ndo_tx_timeout = usbnet_tx_timeout,
11278 + .ndo_change_mtu = usbnet_change_mtu,
11279 + .ndo_set_mac_address = eth_mac_addr,
11280 + .ndo_validate_addr = eth_validate_addr,
11281 + .ndo_set_rx_mode = int51x1_set_multicast,
11282 +};
11283 +
11284 +static int int51x1_bind(struct usbnet *dev, struct usb_interface *intf)
11285 +{
11286 + int status = usbnet_get_ethernet_addr(dev, 3);
11287 +
11288 + if (status)
11289 + return status;
11290 +
11291 + dev->net->hard_header_len += INT51X1_HEADER_SIZE;
11292 + dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
11293 + dev->net->netdev_ops = &int51x1_netdev_ops;
11294 +
11295 + return usbnet_get_endpoints(dev, intf);
11296 +}
11297 +
11298 +static const struct driver_info int51x1_info = {
11299 + .description = "Intellon usb powerline adapter",
11300 + .bind = int51x1_bind,
11301 + .rx_fixup = int51x1_rx_fixup,
11302 + .tx_fixup = int51x1_tx_fixup,
11303 + .in = 1,
11304 + .out = 2,
11305 + .flags = FLAG_ETHER,
11306 +};
11307 +
11308 +static const struct usb_device_id products[] = {
11309 + {
11310 + USB_DEVICE(INT51X1_VENDOR_ID, INT51X1_PRODUCT_ID),
11311 + .driver_info = (unsigned long) &int51x1_info,
11312 + },
11313 + {},
11314 +};
11315 +MODULE_DEVICE_TABLE(usb, products);
11316 +
11317 +static struct usb_driver int51x1_driver = {
11318 + .name = "int51x1",
11319 + .id_table = products,
11320 + .probe = usbnet_probe,
11321 + .disconnect = usbnet_disconnect,
11322 + .suspend = usbnet_suspend,
11323 + .resume = usbnet_resume,
11324 + .disable_hub_initiated_lpm = 1,
11325 +};
11326 +
11327 +module_usb_driver(int51x1_driver);
11328 +
11329 +MODULE_AUTHOR("Peter Holik");
11330 +MODULE_DESCRIPTION("Intellon usb powerline adapter");
11331 +MODULE_LICENSE("GPL");
11332 diff -Naur backports-4.2.6-1.org/drivers/net/usb/ipheth.c backports-4.2.6-1/drivers/net/usb/ipheth.c
11333 --- backports-4.2.6-1.org/drivers/net/usb/ipheth.c 1970-01-01 01:00:00.000000000 +0100
11334 +++ backports-4.2.6-1/drivers/net/usb/ipheth.c 2016-06-28 14:35:17.985307220 +0200
11335 @@ -0,0 +1,588 @@
11336 +/*
11337 + * ipheth.c - Apple iPhone USB Ethernet driver
11338 + *
11339 + * Copyright (c) 2009 Diego Giagio <diego@giagio.com>
11340 + * All rights reserved.
11341 + *
11342 + * Redistribution and use in source and binary forms, with or without
11343 + * modification, are permitted provided that the following conditions
11344 + * are met:
11345 + * 1. Redistributions of source code must retain the above copyright
11346 + * notice, this list of conditions and the following disclaimer.
11347 + * 2. Redistributions in binary form must reproduce the above copyright
11348 + * notice, this list of conditions and the following disclaimer in the
11349 + * documentation and/or other materials provided with the distribution.
11350 + * 3. Neither the name of GIAGIO.COM nor the names of its contributors
11351 + * may be used to endorse or promote products derived from this software
11352 + * without specific prior written permission.
11353 + *
11354 + * Alternatively, provided that this notice is retained in full, this
11355 + * software may be distributed under the terms of the GNU General
11356 + * Public License ("GPL") version 2, in which case the provisions of the
11357 + * GPL apply INSTEAD OF those given above.
11358 + *
11359 + * The provided data structures and external interfaces from this code
11360 + * are not restricted to be used by modules with a GPL compatible license.
11361 + *
11362 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11363 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11364 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11365 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
11366 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11367 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11368 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11369 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11370 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
11371 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
11372 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
11373 + * DAMAGE.
11374 + *
11375 + *
11376 + * Attention: iPhone device must be paired, otherwise it won't respond to our
11377 + * driver. For more info: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
11378 + *
11379 + */
11380 +
11381 +#include <linux/kernel.h>
11382 +#include <linux/errno.h>
11383 +#include <linux/slab.h>
11384 +#include <linux/module.h>
11385 +#include <linux/netdevice.h>
11386 +#include <linux/etherdevice.h>
11387 +#include <linux/ethtool.h>
11388 +#include <linux/usb.h>
11389 +#include <linux/workqueue.h>
11390 +
11391 +#define USB_VENDOR_APPLE 0x05ac
11392 +#define USB_PRODUCT_IPHONE 0x1290
11393 +#define USB_PRODUCT_IPHONE_3G 0x1292
11394 +#define USB_PRODUCT_IPHONE_3GS 0x1294
11395 +#define USB_PRODUCT_IPHONE_4 0x1297
11396 +#define USB_PRODUCT_IPAD 0x129a
11397 +#define USB_PRODUCT_IPAD_2 0x12a2
11398 +#define USB_PRODUCT_IPAD_3 0x12a6
11399 +#define USB_PRODUCT_IPAD_MINI 0x12ab
11400 +#define USB_PRODUCT_IPHONE_4_VZW 0x129c
11401 +#define USB_PRODUCT_IPHONE_4S 0x12a0
11402 +#define USB_PRODUCT_IPHONE_5 0x12a8
11403 +
11404 +#define IPHETH_USBINTF_CLASS 255
11405 +#define IPHETH_USBINTF_SUBCLASS 253
11406 +#define IPHETH_USBINTF_PROTO 1
11407 +
11408 +#define IPHETH_BUF_SIZE 1516
11409 +#define IPHETH_IP_ALIGN 2 /* padding at front of URB */
11410 +#define IPHETH_TX_TIMEOUT (5 * HZ)
11411 +
11412 +#define IPHETH_INTFNUM 2
11413 +#define IPHETH_ALT_INTFNUM 1
11414 +
11415 +#define IPHETH_CTRL_ENDP 0x00
11416 +#define IPHETH_CTRL_BUF_SIZE 0x40
11417 +#define IPHETH_CTRL_TIMEOUT (5 * HZ)
11418 +
11419 +#define IPHETH_CMD_GET_MACADDR 0x00
11420 +#define IPHETH_CMD_CARRIER_CHECK 0x45
11421 +
11422 +#define IPHETH_CARRIER_CHECK_TIMEOUT round_jiffies_relative(1 * HZ)
11423 +#define IPHETH_CARRIER_ON 0x04
11424 +
11425 +static struct usb_device_id ipheth_table[] = {
11426 + { USB_DEVICE_AND_INTERFACE_INFO(
11427 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE,
11428 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11429 + IPHETH_USBINTF_PROTO) },
11430 + { USB_DEVICE_AND_INTERFACE_INFO(
11431 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_3G,
11432 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11433 + IPHETH_USBINTF_PROTO) },
11434 + { USB_DEVICE_AND_INTERFACE_INFO(
11435 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_3GS,
11436 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11437 + IPHETH_USBINTF_PROTO) },
11438 + { USB_DEVICE_AND_INTERFACE_INFO(
11439 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_4,
11440 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11441 + IPHETH_USBINTF_PROTO) },
11442 + { USB_DEVICE_AND_INTERFACE_INFO(
11443 + USB_VENDOR_APPLE, USB_PRODUCT_IPAD,
11444 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11445 + IPHETH_USBINTF_PROTO) },
11446 + { USB_DEVICE_AND_INTERFACE_INFO(
11447 + USB_VENDOR_APPLE, USB_PRODUCT_IPAD_2,
11448 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11449 + IPHETH_USBINTF_PROTO) },
11450 + { USB_DEVICE_AND_INTERFACE_INFO(
11451 + USB_VENDOR_APPLE, USB_PRODUCT_IPAD_3,
11452 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11453 + IPHETH_USBINTF_PROTO) },
11454 + { USB_DEVICE_AND_INTERFACE_INFO(
11455 + USB_VENDOR_APPLE, USB_PRODUCT_IPAD_MINI,
11456 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11457 + IPHETH_USBINTF_PROTO) },
11458 + { USB_DEVICE_AND_INTERFACE_INFO(
11459 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_4_VZW,
11460 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11461 + IPHETH_USBINTF_PROTO) },
11462 + { USB_DEVICE_AND_INTERFACE_INFO(
11463 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_4S,
11464 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11465 + IPHETH_USBINTF_PROTO) },
11466 + { USB_DEVICE_AND_INTERFACE_INFO(
11467 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_5,
11468 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11469 + IPHETH_USBINTF_PROTO) },
11470 + { }
11471 +};
11472 +MODULE_DEVICE_TABLE(usb, ipheth_table);
11473 +
11474 +struct ipheth_device {
11475 + struct usb_device *udev;
11476 + struct usb_interface *intf;
11477 + struct net_device *net;
11478 + struct sk_buff *tx_skb;
11479 + struct urb *tx_urb;
11480 + struct urb *rx_urb;
11481 + unsigned char *tx_buf;
11482 + unsigned char *rx_buf;
11483 + unsigned char *ctrl_buf;
11484 + u8 bulk_in;
11485 + u8 bulk_out;
11486 + struct delayed_work carrier_work;
11487 +};
11488 +
11489 +static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags);
11490 +
11491 +static int ipheth_alloc_urbs(struct ipheth_device *iphone)
11492 +{
11493 + struct urb *tx_urb = NULL;
11494 + struct urb *rx_urb = NULL;
11495 + u8 *tx_buf = NULL;
11496 + u8 *rx_buf = NULL;
11497 +
11498 + tx_urb = usb_alloc_urb(0, GFP_KERNEL);
11499 + if (tx_urb == NULL)
11500 + goto error_nomem;
11501 +
11502 + rx_urb = usb_alloc_urb(0, GFP_KERNEL);
11503 + if (rx_urb == NULL)
11504 + goto free_tx_urb;
11505 +
11506 + tx_buf = usb_alloc_coherent(iphone->udev, IPHETH_BUF_SIZE,
11507 + GFP_KERNEL, &tx_urb->transfer_dma);
11508 + if (tx_buf == NULL)
11509 + goto free_rx_urb;
11510 +
11511 + rx_buf = usb_alloc_coherent(iphone->udev, IPHETH_BUF_SIZE,
11512 + GFP_KERNEL, &rx_urb->transfer_dma);
11513 + if (rx_buf == NULL)
11514 + goto free_tx_buf;
11515 +
11516 +
11517 + iphone->tx_urb = tx_urb;
11518 + iphone->rx_urb = rx_urb;
11519 + iphone->tx_buf = tx_buf;
11520 + iphone->rx_buf = rx_buf;
11521 + return 0;
11522 +
11523 +free_tx_buf:
11524 + usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, tx_buf,
11525 + tx_urb->transfer_dma);
11526 +free_rx_urb:
11527 + usb_free_urb(rx_urb);
11528 +free_tx_urb:
11529 + usb_free_urb(tx_urb);
11530 +error_nomem:
11531 + return -ENOMEM;
11532 +}
11533 +
11534 +static void ipheth_free_urbs(struct ipheth_device *iphone)
11535 +{
11536 + usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, iphone->rx_buf,
11537 + iphone->rx_urb->transfer_dma);
11538 + usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, iphone->tx_buf,
11539 + iphone->tx_urb->transfer_dma);
11540 + usb_free_urb(iphone->rx_urb);
11541 + usb_free_urb(iphone->tx_urb);
11542 +}
11543 +
11544 +static void ipheth_kill_urbs(struct ipheth_device *dev)
11545 +{
11546 + usb_kill_urb(dev->tx_urb);
11547 + usb_kill_urb(dev->rx_urb);
11548 +}
11549 +
11550 +static void ipheth_rcvbulk_callback(struct urb *urb)
11551 +{
11552 + struct ipheth_device *dev;
11553 + struct sk_buff *skb;
11554 + int status;
11555 + char *buf;
11556 + int len;
11557 +
11558 + dev = urb->context;
11559 + if (dev == NULL)
11560 + return;
11561 +
11562 + status = urb->status;
11563 + switch (status) {
11564 + case -ENOENT:
11565 + case -ECONNRESET:
11566 + case -ESHUTDOWN:
11567 + return;
11568 + case 0:
11569 + break;
11570 + default:
11571 + dev_err(&dev->intf->dev, "%s: urb status: %d\n",
11572 + __func__, status);
11573 + return;
11574 + }
11575 +
11576 + if (urb->actual_length <= IPHETH_IP_ALIGN) {
11577 + dev->net->stats.rx_length_errors++;
11578 + return;
11579 + }
11580 + len = urb->actual_length - IPHETH_IP_ALIGN;
11581 + buf = urb->transfer_buffer + IPHETH_IP_ALIGN;
11582 +
11583 + skb = dev_alloc_skb(len);
11584 + if (!skb) {
11585 + dev_err(&dev->intf->dev, "%s: dev_alloc_skb: -ENOMEM\n",
11586 + __func__);
11587 + dev->net->stats.rx_dropped++;
11588 + return;
11589 + }
11590 +
11591 + memcpy(skb_put(skb, len), buf, len);
11592 + skb->dev = dev->net;
11593 + skb->protocol = eth_type_trans(skb, dev->net);
11594 +
11595 + dev->net->stats.rx_packets++;
11596 + dev->net->stats.rx_bytes += len;
11597 +
11598 + netif_rx(skb);
11599 + ipheth_rx_submit(dev, GFP_ATOMIC);
11600 +}
11601 +
11602 +static void ipheth_sndbulk_callback(struct urb *urb)
11603 +{
11604 + struct ipheth_device *dev;
11605 + int status = urb->status;
11606 +
11607 + dev = urb->context;
11608 + if (dev == NULL)
11609 + return;
11610 +
11611 + if (status != 0 &&
11612 + status != -ENOENT &&
11613 + status != -ECONNRESET &&
11614 + status != -ESHUTDOWN)
11615 + dev_err(&dev->intf->dev, "%s: urb status: %d\n",
11616 + __func__, status);
11617 +
11618 + dev_kfree_skb_irq(dev->tx_skb);
11619 + netif_wake_queue(dev->net);
11620 +}
11621 +
11622 +static int ipheth_carrier_set(struct ipheth_device *dev)
11623 +{
11624 + struct usb_device *udev = dev->udev;
11625 + int retval;
11626 +
11627 + retval = usb_control_msg(udev,
11628 + usb_rcvctrlpipe(udev, IPHETH_CTRL_ENDP),
11629 + IPHETH_CMD_CARRIER_CHECK, /* request */
11630 + 0xc0, /* request type */
11631 + 0x00, /* value */
11632 + 0x02, /* index */
11633 + dev->ctrl_buf, IPHETH_CTRL_BUF_SIZE,
11634 + IPHETH_CTRL_TIMEOUT);
11635 + if (retval < 0) {
11636 + dev_err(&dev->intf->dev, "%s: usb_control_msg: %d\n",
11637 + __func__, retval);
11638 + return retval;
11639 + }
11640 +
11641 + if (dev->ctrl_buf[0] == IPHETH_CARRIER_ON)
11642 + netif_carrier_on(dev->net);
11643 + else
11644 + netif_carrier_off(dev->net);
11645 +
11646 + return 0;
11647 +}
11648 +
11649 +static void ipheth_carrier_check_work(struct work_struct *work)
11650 +{
11651 + struct ipheth_device *dev = container_of(work, struct ipheth_device,
11652 + carrier_work.work);
11653 +
11654 + ipheth_carrier_set(dev);
11655 + schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);
11656 +}
11657 +
11658 +static int ipheth_get_macaddr(struct ipheth_device *dev)
11659 +{
11660 + struct usb_device *udev = dev->udev;
11661 + struct net_device *net = dev->net;
11662 + int retval;
11663 +
11664 + retval = usb_control_msg(udev,
11665 + usb_rcvctrlpipe(udev, IPHETH_CTRL_ENDP),
11666 + IPHETH_CMD_GET_MACADDR, /* request */
11667 + 0xc0, /* request type */
11668 + 0x00, /* value */
11669 + 0x02, /* index */
11670 + dev->ctrl_buf,
11671 + IPHETH_CTRL_BUF_SIZE,
11672 + IPHETH_CTRL_TIMEOUT);
11673 + if (retval < 0) {
11674 + dev_err(&dev->intf->dev, "%s: usb_control_msg: %d\n",
11675 + __func__, retval);
11676 + } else if (retval < ETH_ALEN) {
11677 + dev_err(&dev->intf->dev,
11678 + "%s: usb_control_msg: short packet: %d bytes\n",
11679 + __func__, retval);
11680 + retval = -EINVAL;
11681 + } else {
11682 + memcpy(net->dev_addr, dev->ctrl_buf, ETH_ALEN);
11683 + retval = 0;
11684 + }
11685 +
11686 + return retval;
11687 +}
11688 +
11689 +static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags)
11690 +{
11691 + struct usb_device *udev = dev->udev;
11692 + int retval;
11693 +
11694 + usb_fill_bulk_urb(dev->rx_urb, udev,
11695 + usb_rcvbulkpipe(udev, dev->bulk_in),
11696 + dev->rx_buf, IPHETH_BUF_SIZE,
11697 + ipheth_rcvbulk_callback,
11698 + dev);
11699 + dev->rx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
11700 +
11701 + retval = usb_submit_urb(dev->rx_urb, mem_flags);
11702 + if (retval)
11703 + dev_err(&dev->intf->dev, "%s: usb_submit_urb: %d\n",
11704 + __func__, retval);
11705 + return retval;
11706 +}
11707 +
11708 +static int ipheth_open(struct net_device *net)
11709 +{
11710 + struct ipheth_device *dev = netdev_priv(net);
11711 + struct usb_device *udev = dev->udev;
11712 + int retval = 0;
11713 +
11714 + usb_set_interface(udev, IPHETH_INTFNUM, IPHETH_ALT_INTFNUM);
11715 +
11716 + retval = ipheth_carrier_set(dev);
11717 + if (retval)
11718 + return retval;
11719 +
11720 + retval = ipheth_rx_submit(dev, GFP_KERNEL);
11721 + if (retval)
11722 + return retval;
11723 +
11724 + schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);
11725 + netif_start_queue(net);
11726 + return retval;
11727 +}
11728 +
11729 +static int ipheth_close(struct net_device *net)
11730 +{
11731 + struct ipheth_device *dev = netdev_priv(net);
11732 +
11733 + cancel_delayed_work_sync(&dev->carrier_work);
11734 + netif_stop_queue(net);
11735 + return 0;
11736 +}
11737 +
11738 +static int ipheth_tx(struct sk_buff *skb, struct net_device *net)
11739 +{
11740 + struct ipheth_device *dev = netdev_priv(net);
11741 + struct usb_device *udev = dev->udev;
11742 + int retval;
11743 +
11744 + /* Paranoid */
11745 + if (skb->len > IPHETH_BUF_SIZE) {
11746 + WARN(1, "%s: skb too large: %d bytes\n", __func__, skb->len);
11747 + dev->net->stats.tx_dropped++;
11748 + dev_kfree_skb_irq(skb);
11749 + return NETDEV_TX_OK;
11750 + }
11751 +
11752 + memcpy(dev->tx_buf, skb->data, skb->len);
11753 + if (skb->len < IPHETH_BUF_SIZE)
11754 + memset(dev->tx_buf + skb->len, 0, IPHETH_BUF_SIZE - skb->len);
11755 +
11756 + usb_fill_bulk_urb(dev->tx_urb, udev,
11757 + usb_sndbulkpipe(udev, dev->bulk_out),
11758 + dev->tx_buf, IPHETH_BUF_SIZE,
11759 + ipheth_sndbulk_callback,
11760 + dev);
11761 + dev->tx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
11762 +
11763 + retval = usb_submit_urb(dev->tx_urb, GFP_ATOMIC);
11764 + if (retval) {
11765 + dev_err(&dev->intf->dev, "%s: usb_submit_urb: %d\n",
11766 + __func__, retval);
11767 + dev->net->stats.tx_errors++;
11768 + dev_kfree_skb_irq(skb);
11769 + } else {
11770 + dev->tx_skb = skb;
11771 +
11772 + dev->net->stats.tx_packets++;
11773 + dev->net->stats.tx_bytes += skb->len;
11774 + netif_stop_queue(net);
11775 + }
11776 +
11777 + return NETDEV_TX_OK;
11778 +}
11779 +
11780 +static void ipheth_tx_timeout(struct net_device *net)
11781 +{
11782 + struct ipheth_device *dev = netdev_priv(net);
11783 +
11784 + dev_err(&dev->intf->dev, "%s: TX timeout\n", __func__);
11785 + dev->net->stats.tx_errors++;
11786 + usb_unlink_urb(dev->tx_urb);
11787 +}
11788 +
11789 +static u32 ipheth_ethtool_op_get_link(struct net_device *net)
11790 +{
11791 + struct ipheth_device *dev = netdev_priv(net);
11792 + return netif_carrier_ok(dev->net);
11793 +}
11794 +
11795 +static const struct ethtool_ops ops = {
11796 + .get_link = ipheth_ethtool_op_get_link
11797 +};
11798 +
11799 +static const struct net_device_ops ipheth_netdev_ops = {
11800 + .ndo_open = ipheth_open,
11801 + .ndo_stop = ipheth_close,
11802 + .ndo_start_xmit = ipheth_tx,
11803 + .ndo_tx_timeout = ipheth_tx_timeout,
11804 +};
11805 +
11806 +static int ipheth_probe(struct usb_interface *intf,
11807 + const struct usb_device_id *id)
11808 +{
11809 + struct usb_device *udev = interface_to_usbdev(intf);
11810 + struct usb_host_interface *hintf;
11811 + struct usb_endpoint_descriptor *endp;
11812 + struct ipheth_device *dev;
11813 + struct net_device *netdev;
11814 + int i;
11815 + int retval;
11816 +
11817 + netdev = alloc_etherdev(sizeof(struct ipheth_device));
11818 + if (!netdev)
11819 + return -ENOMEM;
11820 +
11821 + netdev->netdev_ops = &ipheth_netdev_ops;
11822 + netdev->watchdog_timeo = IPHETH_TX_TIMEOUT;
11823 + strcpy(netdev->name, "eth%d");
11824 +
11825 + dev = netdev_priv(netdev);
11826 + dev->udev = udev;
11827 + dev->net = netdev;
11828 + dev->intf = intf;
11829 +
11830 + /* Set up endpoints */
11831 + hintf = usb_altnum_to_altsetting(intf, IPHETH_ALT_INTFNUM);
11832 + if (hintf == NULL) {
11833 + retval = -ENODEV;
11834 + dev_err(&intf->dev, "Unable to find alternate settings interface\n");
11835 + goto err_endpoints;
11836 + }
11837 +
11838 + for (i = 0; i < hintf->desc.bNumEndpoints; i++) {
11839 + endp = &hintf->endpoint[i].desc;
11840 + if (usb_endpoint_is_bulk_in(endp))
11841 + dev->bulk_in = endp->bEndpointAddress;
11842 + else if (usb_endpoint_is_bulk_out(endp))
11843 + dev->bulk_out = endp->bEndpointAddress;
11844 + }
11845 + if (!(dev->bulk_in && dev->bulk_out)) {
11846 + retval = -ENODEV;
11847 + dev_err(&intf->dev, "Unable to find endpoints\n");
11848 + goto err_endpoints;
11849 + }
11850 +
11851 + dev->ctrl_buf = kmalloc(IPHETH_CTRL_BUF_SIZE, GFP_KERNEL);
11852 + if (dev->ctrl_buf == NULL) {
11853 + retval = -ENOMEM;
11854 + goto err_alloc_ctrl_buf;
11855 + }
11856 +
11857 + retval = ipheth_get_macaddr(dev);
11858 + if (retval)
11859 + goto err_get_macaddr;
11860 +
11861 + INIT_DELAYED_WORK(&dev->carrier_work, ipheth_carrier_check_work);
11862 +
11863 + retval = ipheth_alloc_urbs(dev);
11864 + if (retval) {
11865 + dev_err(&intf->dev, "error allocating urbs: %d\n", retval);
11866 + goto err_alloc_urbs;
11867 + }
11868 +
11869 + usb_set_intfdata(intf, dev);
11870 +
11871 + SET_NETDEV_DEV(netdev, &intf->dev);
11872 + netdev->ethtool_ops = &ops;
11873 +
11874 + retval = register_netdev(netdev);
11875 + if (retval) {
11876 + dev_err(&intf->dev, "error registering netdev: %d\n", retval);
11877 + retval = -EIO;
11878 + goto err_register_netdev;
11879 + }
11880 +
11881 + dev_info(&intf->dev, "Apple iPhone USB Ethernet device attached\n");
11882 + return 0;
11883 +
11884 +err_register_netdev:
11885 + ipheth_free_urbs(dev);
11886 +err_alloc_urbs:
11887 +err_get_macaddr:
11888 +err_alloc_ctrl_buf:
11889 + kfree(dev->ctrl_buf);
11890 +err_endpoints:
11891 + free_netdev(netdev);
11892 + return retval;
11893 +}
11894 +
11895 +static void ipheth_disconnect(struct usb_interface *intf)
11896 +{
11897 + struct ipheth_device *dev;
11898 +
11899 + dev = usb_get_intfdata(intf);
11900 + if (dev != NULL) {
11901 + unregister_netdev(dev->net);
11902 + ipheth_kill_urbs(dev);
11903 + ipheth_free_urbs(dev);
11904 + kfree(dev->ctrl_buf);
11905 + free_netdev(dev->net);
11906 + }
11907 + usb_set_intfdata(intf, NULL);
11908 + dev_info(&intf->dev, "Apple iPhone USB Ethernet now disconnected\n");
11909 +}
11910 +
11911 +static struct usb_driver ipheth_driver = {
11912 + .name = "ipheth",
11913 + .probe = ipheth_probe,
11914 + .disconnect = ipheth_disconnect,
11915 + .id_table = ipheth_table,
11916 + .disable_hub_initiated_lpm = 1,
11917 +};
11918 +
11919 +module_usb_driver(ipheth_driver);
11920 +
11921 +MODULE_AUTHOR("Diego Giagio <diego@giagio.com>");
11922 +MODULE_DESCRIPTION("Apple iPhone USB Ethernet driver");
11923 +MODULE_LICENSE("Dual BSD/GPL");
11924 diff -Naur backports-4.2.6-1.org/drivers/net/usb/kalmia.c backports-4.2.6-1/drivers/net/usb/kalmia.c
11925 --- backports-4.2.6-1.org/drivers/net/usb/kalmia.c 1970-01-01 01:00:00.000000000 +0100
11926 +++ backports-4.2.6-1/drivers/net/usb/kalmia.c 2016-06-28 14:35:17.985307220 +0200
11927 @@ -0,0 +1,366 @@
11928 +/*
11929 + * USB network interface driver for Samsung Kalmia based LTE USB modem like the
11930 + * Samsung GT-B3730 and GT-B3710.
11931 + *
11932 + * Copyright (C) 2011 Marius Bjoernstad Kotsbak <marius@kotsbak.com>
11933 + *
11934 + * Sponsored by Quicklink Video Distribution Services Ltd.
11935 + *
11936 + * Based on the cdc_eem module.
11937 + *
11938 + * This program is free software; you can redistribute it and/or modify
11939 + * it under the terms of the GNU General Public License as published by
11940 + * the Free Software Foundation; either version 2 of the License, or
11941 + * (at your option) any later version.
11942 + */
11943 +
11944 +#include <linux/module.h>
11945 +#include <linux/netdevice.h>
11946 +#include <linux/etherdevice.h>
11947 +#include <linux/ctype.h>
11948 +#include <linux/ethtool.h>
11949 +#include <linux/workqueue.h>
11950 +#include <linux/mii.h>
11951 +#include <linux/usb.h>
11952 +#include <linux/crc32.h>
11953 +#include <linux/usb/cdc.h>
11954 +#include <linux/usb/usbnet.h>
11955 +#include <linux/gfp.h>
11956 +
11957 +/*
11958 + * The Samsung Kalmia based LTE USB modems have a CDC ACM port for modem control
11959 + * handled by the "option" module and an ethernet data port handled by this
11960 + * module.
11961 + *
11962 + * The stick must first be switched into modem mode by usb_modeswitch
11963 + * or similar tool. Then the modem gets sent two initialization packets by
11964 + * this module, which gives the MAC address of the device. User space can then
11965 + * connect the modem using AT commands through the ACM port and then use
11966 + * DHCP on the network interface exposed by this module. Network packets are
11967 + * sent to and from the modem in a proprietary format discovered after watching
11968 + * the behavior of the windows driver for the modem.
11969 + *
11970 + * More information about the use of the modem is available in usb_modeswitch
11971 + * forum and the project page:
11972 + *
11973 + * http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
11974 + * https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
11975 + */
11976 +
11977 +/* #define DEBUG */
11978 +/* #define VERBOSE */
11979 +
11980 +#define KALMIA_HEADER_LENGTH 6
11981 +#define KALMIA_ALIGN_SIZE 4
11982 +#define KALMIA_USB_TIMEOUT 10000
11983 +
11984 +/*-------------------------------------------------------------------------*/
11985 +
11986 +static int
11987 +kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
11988 + u8 *buffer, u8 expected_len)
11989 +{
11990 + int act_len;
11991 + int status;
11992 +
11993 + netdev_dbg(dev->net, "Sending init packet");
11994 +
11995 + status = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 0x02),
11996 + init_msg, init_msg_len, &act_len, KALMIA_USB_TIMEOUT);
11997 + if (status != 0) {
11998 + netdev_err(dev->net,
11999 + "Error sending init packet. Status %i, length %i\n",
12000 + status, act_len);
12001 + return status;
12002 + }
12003 + else if (act_len != init_msg_len) {
12004 + netdev_err(dev->net,
12005 + "Did not send all of init packet. Bytes sent: %i",
12006 + act_len);
12007 + }
12008 + else {
12009 + netdev_dbg(dev->net, "Successfully sent init packet.");
12010 + }
12011 +
12012 + status = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, 0x81),
12013 + buffer, expected_len, &act_len, KALMIA_USB_TIMEOUT);
12014 +
12015 + if (status != 0)
12016 + netdev_err(dev->net,
12017 + "Error receiving init result. Status %i, length %i\n",
12018 + status, act_len);
12019 + else if (act_len != expected_len)
12020 + netdev_err(dev->net, "Unexpected init result length: %i\n",
12021 + act_len);
12022 +
12023 + return status;
12024 +}
12025 +
12026 +static int
12027 +kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
12028 +{
12029 + static const char init_msg_1[] =
12030 + { 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
12031 + 0x00, 0x00 };
12032 + static const char init_msg_2[] =
12033 + { 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
12034 + 0x00, 0x00 };
12035 + static const int buflen = 28;
12036 + char *usb_buf;
12037 + int status;
12038 +
12039 + usb_buf = kmalloc(buflen, GFP_DMA | GFP_KERNEL);
12040 + if (!usb_buf)
12041 + return -ENOMEM;
12042 +
12043 + memcpy(usb_buf, init_msg_1, 12);
12044 + status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_1)
12045 + / sizeof(init_msg_1[0]), usb_buf, 24);
12046 + if (status != 0)
12047 + return status;
12048 +
12049 + memcpy(usb_buf, init_msg_2, 12);
12050 + status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_2)
12051 + / sizeof(init_msg_2[0]), usb_buf, 28);
12052 + if (status != 0)
12053 + return status;
12054 +
12055 + memcpy(ethernet_addr, usb_buf + 10, ETH_ALEN);
12056 +
12057 + kfree(usb_buf);
12058 + return status;
12059 +}
12060 +
12061 +static int
12062 +kalmia_bind(struct usbnet *dev, struct usb_interface *intf)
12063 +{
12064 + int status;
12065 + u8 ethernet_addr[ETH_ALEN];
12066 +
12067 + /* Don't bind to AT command interface */
12068 + if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
12069 + return -EINVAL;
12070 +
12071 + dev->in = usb_rcvbulkpipe(dev->udev, 0x81 & USB_ENDPOINT_NUMBER_MASK);
12072 + dev->out = usb_sndbulkpipe(dev->udev, 0x02 & USB_ENDPOINT_NUMBER_MASK);
12073 + dev->status = NULL;
12074 +
12075 + dev->net->hard_header_len += KALMIA_HEADER_LENGTH;
12076 + dev->hard_mtu = 1400;
12077 + dev->rx_urb_size = dev->hard_mtu * 10; // Found as optimal after testing
12078 +
12079 + status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr);
12080 +
12081 + if (status < 0) {
12082 + usb_set_intfdata(intf, NULL);
12083 + usb_driver_release_interface(driver_of(intf), intf);
12084 + return status;
12085 + }
12086 +
12087 + memcpy(dev->net->dev_addr, ethernet_addr, ETH_ALEN);
12088 +
12089 + return status;
12090 +}
12091 +
12092 +static struct sk_buff *
12093 +kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
12094 +{
12095 + struct sk_buff *skb2 = NULL;
12096 + u16 content_len;
12097 + unsigned char *header_start;
12098 + unsigned char ether_type_1, ether_type_2;
12099 + u8 remainder, padlen = 0;
12100 +
12101 + if (!skb_cloned(skb)) {
12102 + int headroom = skb_headroom(skb);
12103 + int tailroom = skb_tailroom(skb);
12104 +
12105 + if ((tailroom >= KALMIA_ALIGN_SIZE) && (headroom
12106 + >= KALMIA_HEADER_LENGTH))
12107 + goto done;
12108 +
12109 + if ((headroom + tailroom) > (KALMIA_HEADER_LENGTH
12110 + + KALMIA_ALIGN_SIZE)) {
12111 + skb->data = memmove(skb->head + KALMIA_HEADER_LENGTH,
12112 + skb->data, skb->len);
12113 + skb_set_tail_pointer(skb, skb->len);
12114 + goto done;
12115 + }
12116 + }
12117 +
12118 + skb2 = skb_copy_expand(skb, KALMIA_HEADER_LENGTH,
12119 + KALMIA_ALIGN_SIZE, flags);
12120 + if (!skb2)
12121 + return NULL;
12122 +
12123 + dev_kfree_skb_any(skb);
12124 + skb = skb2;
12125 +
12126 +done:
12127 + header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
12128 + ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
12129 + ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
12130 +
12131 + netdev_dbg(dev->net, "Sending etherType: %02x%02x", ether_type_1,
12132 + ether_type_2);
12133 +
12134 + /* According to empiric data for data packages */
12135 + header_start[0] = 0x57;
12136 + header_start[1] = 0x44;
12137 + content_len = skb->len - KALMIA_HEADER_LENGTH;
12138 +
12139 + put_unaligned_le16(content_len, &header_start[2]);
12140 + header_start[4] = ether_type_1;
12141 + header_start[5] = ether_type_2;
12142 +
12143 + /* Align to 4 bytes by padding with zeros */
12144 + remainder = skb->len % KALMIA_ALIGN_SIZE;
12145 + if (remainder > 0) {
12146 + padlen = KALMIA_ALIGN_SIZE - remainder;
12147 + memset(skb_put(skb, padlen), 0, padlen);
12148 + }
12149 +
12150 + netdev_dbg(dev->net,
12151 + "Sending package with length %i and padding %i. Header: %6phC.",
12152 + content_len, padlen, header_start);
12153 +
12154 + return skb;
12155 +}
12156 +
12157 +static int
12158 +kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
12159 +{
12160 + /*
12161 + * Our task here is to strip off framing, leaving skb with one
12162 + * data frame for the usbnet framework code to process.
12163 + */
12164 + static const u8 HEADER_END_OF_USB_PACKET[] =
12165 + { 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
12166 + static const u8 EXPECTED_UNKNOWN_HEADER_1[] =
12167 + { 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
12168 + static const u8 EXPECTED_UNKNOWN_HEADER_2[] =
12169 + { 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
12170 + int i = 0;
12171 +
12172 + /* incomplete header? */
12173 + if (skb->len < KALMIA_HEADER_LENGTH)
12174 + return 0;
12175 +
12176 + do {
12177 + struct sk_buff *skb2 = NULL;
12178 + u8 *header_start;
12179 + u16 usb_packet_length, ether_packet_length;
12180 + int is_last;
12181 +
12182 + header_start = skb->data;
12183 +
12184 + if (unlikely(header_start[0] != 0x57 || header_start[1] != 0x44)) {
12185 + if (!memcmp(header_start, EXPECTED_UNKNOWN_HEADER_1,
12186 + sizeof(EXPECTED_UNKNOWN_HEADER_1)) || !memcmp(
12187 + header_start, EXPECTED_UNKNOWN_HEADER_2,
12188 + sizeof(EXPECTED_UNKNOWN_HEADER_2))) {
12189 + netdev_dbg(dev->net,
12190 + "Received expected unknown frame header: %6phC. Package length: %i\n",
12191 + header_start,
12192 + skb->len - KALMIA_HEADER_LENGTH);
12193 + }
12194 + else {
12195 + netdev_err(dev->net,
12196 + "Received unknown frame header: %6phC. Package length: %i\n",
12197 + header_start,
12198 + skb->len - KALMIA_HEADER_LENGTH);
12199 + return 0;
12200 + }
12201 + }
12202 + else
12203 + netdev_dbg(dev->net,
12204 + "Received header: %6phC. Package length: %i\n",
12205 + header_start, skb->len - KALMIA_HEADER_LENGTH);
12206 +
12207 + /* subtract start header and end header */
12208 + usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
12209 + ether_packet_length = get_unaligned_le16(&header_start[2]);
12210 + skb_pull(skb, KALMIA_HEADER_LENGTH);
12211 +
12212 + /* Some small packets misses end marker */
12213 + if (usb_packet_length < ether_packet_length) {
12214 + ether_packet_length = usb_packet_length
12215 + + KALMIA_HEADER_LENGTH;
12216 + is_last = true;
12217 + }
12218 + else {
12219 + netdev_dbg(dev->net, "Correct package length #%i", i
12220 + + 1);
12221 +
12222 + is_last = (memcmp(skb->data + ether_packet_length,
12223 + HEADER_END_OF_USB_PACKET,
12224 + sizeof(HEADER_END_OF_USB_PACKET)) == 0);
12225 + if (!is_last) {
12226 + header_start = skb->data + ether_packet_length;
12227 + netdev_dbg(dev->net,
12228 + "End header: %6phC. Package length: %i\n",
12229 + header_start,
12230 + skb->len - KALMIA_HEADER_LENGTH);
12231 + }
12232 + }
12233 +
12234 + if (is_last) {
12235 + skb2 = skb;
12236 + }
12237 + else {
12238 + skb2 = skb_clone(skb, GFP_ATOMIC);
12239 + if (unlikely(!skb2))
12240 + return 0;
12241 + }
12242 +
12243 + skb_trim(skb2, ether_packet_length);
12244 +
12245 + if (is_last) {
12246 + return 1;
12247 + }
12248 + else {
12249 + usbnet_skb_return(dev, skb2);
12250 + skb_pull(skb, ether_packet_length);
12251 + }
12252 +
12253 + i++;
12254 + }
12255 + while (skb->len);
12256 +
12257 + return 1;
12258 +}
12259 +
12260 +static const struct driver_info kalmia_info = {
12261 + .description = "Samsung Kalmia LTE USB dongle",
12262 + .flags = FLAG_WWAN,
12263 + .bind = kalmia_bind,
12264 + .rx_fixup = kalmia_rx_fixup,
12265 + .tx_fixup = kalmia_tx_fixup
12266 +};
12267 +
12268 +/*-------------------------------------------------------------------------*/
12269 +
12270 +static const struct usb_device_id products[] = {
12271 + /* The unswitched USB ID, to get the module auto loaded: */
12272 + { USB_DEVICE(0x04e8, 0x689a) },
12273 + /* The stick swithed into modem (by e.g. usb_modeswitch): */
12274 + { USB_DEVICE(0x04e8, 0x6889),
12275 + .driver_info = (unsigned long) &kalmia_info, },
12276 + { /* EMPTY == end of list */} };
12277 +MODULE_DEVICE_TABLE( usb, products);
12278 +
12279 +static struct usb_driver kalmia_driver = {
12280 + .name = "kalmia",
12281 + .id_table = products,
12282 + .probe = usbnet_probe,
12283 + .disconnect = usbnet_disconnect,
12284 + .suspend = usbnet_suspend,
12285 + .resume = usbnet_resume,
12286 + .disable_hub_initiated_lpm = 1,
12287 +};
12288 +
12289 +module_usb_driver(kalmia_driver);
12290 +
12291 +MODULE_AUTHOR("Marius Bjoernstad Kotsbak <marius@kotsbak.com>");
12292 +MODULE_DESCRIPTION("Samsung Kalmia USB network driver");
12293 +MODULE_LICENSE("GPL");
12294 diff -Naur backports-4.2.6-1.org/drivers/net/usb/kaweth.c backports-4.2.6-1/drivers/net/usb/kaweth.c
12295 --- backports-4.2.6-1.org/drivers/net/usb/kaweth.c 1970-01-01 01:00:00.000000000 +0100
12296 +++ backports-4.2.6-1/drivers/net/usb/kaweth.c 2016-06-28 14:35:17.988640553 +0200
12297 @@ -0,0 +1,1331 @@
12298 +/****************************************************************
12299 + *
12300 + * kaweth.c - driver for KL5KUSB101 based USB->Ethernet
12301 + *
12302 + * (c) 2000 Interlan Communications
12303 + * (c) 2000 Stephane Alnet
12304 + * (C) 2001 Brad Hards
12305 + * (C) 2002 Oliver Neukum
12306 + *
12307 + * Original author: The Zapman <zapman@interlan.net>
12308 + * Inspired by, and much credit goes to Michael Rothwell
12309 + * <rothwell@interlan.net> for the test equipment, help, and patience
12310 + * Based off of (and with thanks to) Petko Manolov's pegaus.c driver.
12311 + * Also many thanks to Joel Silverman and Ed Surprenant at Kawasaki
12312 + * for providing the firmware and driver resources.
12313 + *
12314 + * This program is free software; you can redistribute it and/or
12315 + * modify it under the terms of the GNU General Public License as
12316 + * published by the Free Software Foundation; either version 2, or
12317 + * (at your option) any later version.
12318 + *
12319 + * This program is distributed in the hope that it will be useful,
12320 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12321 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12322 + * GNU General Public License for more details.
12323 + *
12324 + * You should have received a copy of the GNU General Public License
12325 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
12326 + *
12327 + ****************************************************************/
12328 +
12329 +/* TODO:
12330 + * Develop test procedures for USB net interfaces
12331 + * Run test procedures
12332 + * Fix bugs from previous two steps
12333 + * Snoop other OSs for any tricks we're not doing
12334 + * Reduce arbitrary timeouts
12335 + * Smart multicast support
12336 + * Temporary MAC change support
12337 + * Tunable SOFs parameter - ioctl()?
12338 + * Ethernet stats collection
12339 + * Code formatting improvements
12340 + */
12341 +
12342 +#include <linux/module.h>
12343 +#include <linux/slab.h>
12344 +#include <linux/string.h>
12345 +#include <linux/delay.h>
12346 +#include <linux/netdevice.h>
12347 +#include <linux/etherdevice.h>
12348 +#include <linux/usb.h>
12349 +#include <linux/types.h>
12350 +#include <linux/ethtool.h>
12351 +#include <linux/dma-mapping.h>
12352 +#include <linux/wait.h>
12353 +#include <linux/firmware.h>
12354 +#include <asm/uaccess.h>
12355 +#include <asm/byteorder.h>
12356 +
12357 +#undef DEBUG
12358 +
12359 +#define KAWETH_MTU 1514
12360 +#define KAWETH_BUF_SIZE 1664
12361 +#define KAWETH_TX_TIMEOUT (5 * HZ)
12362 +#define KAWETH_SCRATCH_SIZE 32
12363 +#define KAWETH_FIRMWARE_BUF_SIZE 4096
12364 +#define KAWETH_CONTROL_TIMEOUT (30000)
12365 +
12366 +#define KAWETH_STATUS_BROKEN 0x0000001
12367 +#define KAWETH_STATUS_CLOSING 0x0000002
12368 +#define KAWETH_STATUS_SUSPENDING 0x0000004
12369 +
12370 +#define KAWETH_STATUS_BLOCKED (KAWETH_STATUS_CLOSING | KAWETH_STATUS_SUSPENDING)
12371 +
12372 +#define KAWETH_PACKET_FILTER_PROMISCUOUS 0x01
12373 +#define KAWETH_PACKET_FILTER_ALL_MULTICAST 0x02
12374 +#define KAWETH_PACKET_FILTER_DIRECTED 0x04
12375 +#define KAWETH_PACKET_FILTER_BROADCAST 0x08
12376 +#define KAWETH_PACKET_FILTER_MULTICAST 0x10
12377 +
12378 +/* Table 7 */
12379 +#define KAWETH_COMMAND_GET_ETHERNET_DESC 0x00
12380 +#define KAWETH_COMMAND_MULTICAST_FILTERS 0x01
12381 +#define KAWETH_COMMAND_SET_PACKET_FILTER 0x02
12382 +#define KAWETH_COMMAND_STATISTICS 0x03
12383 +#define KAWETH_COMMAND_SET_TEMP_MAC 0x06
12384 +#define KAWETH_COMMAND_GET_TEMP_MAC 0x07
12385 +#define KAWETH_COMMAND_SET_URB_SIZE 0x08
12386 +#define KAWETH_COMMAND_SET_SOFS_WAIT 0x09
12387 +#define KAWETH_COMMAND_SCAN 0xFF
12388 +
12389 +#define KAWETH_SOFS_TO_WAIT 0x05
12390 +
12391 +#define INTBUFFERSIZE 4
12392 +
12393 +#define STATE_OFFSET 0
12394 +#define STATE_MASK 0x40
12395 +#define STATE_SHIFT 5
12396 +
12397 +#define IS_BLOCKED(s) (s & KAWETH_STATUS_BLOCKED)
12398 +
12399 +
12400 +MODULE_AUTHOR("Michael Zappe <zapman@interlan.net>, Stephane Alnet <stephane@u-picardie.fr>, Brad Hards <bhards@bigpond.net.au> and Oliver Neukum <oliver@neukum.org>");
12401 +MODULE_DESCRIPTION("KL5USB101 USB Ethernet driver");
12402 +MODULE_LICENSE("GPL");
12403 +MODULE_FIRMWARE("kaweth/new_code.bin");
12404 +MODULE_FIRMWARE("kaweth/new_code_fix.bin");
12405 +MODULE_FIRMWARE("kaweth/trigger_code.bin");
12406 +MODULE_FIRMWARE("kaweth/trigger_code_fix.bin");
12407 +
12408 +static const char driver_name[] = "kaweth";
12409 +
12410 +static int kaweth_probe(
12411 + struct usb_interface *intf,
12412 + const struct usb_device_id *id /* from id_table */
12413 + );
12414 +static void kaweth_disconnect(struct usb_interface *intf);
12415 +static int kaweth_internal_control_msg(struct usb_device *usb_dev,
12416 + unsigned int pipe,
12417 + struct usb_ctrlrequest *cmd, void *data,
12418 + int len, int timeout);
12419 +static int kaweth_suspend(struct usb_interface *intf, pm_message_t message);
12420 +static int kaweth_resume(struct usb_interface *intf);
12421 +
12422 +/****************************************************************
12423 + * usb_device_id
12424 + ****************************************************************/
12425 +static struct usb_device_id usb_klsi_table[] = {
12426 + { USB_DEVICE(0x03e8, 0x0008) }, /* AOX Endpoints USB Ethernet */
12427 + { USB_DEVICE(0x04bb, 0x0901) }, /* I-O DATA USB-ET/T */
12428 + { USB_DEVICE(0x0506, 0x03e8) }, /* 3Com 3C19250 */
12429 + { USB_DEVICE(0x0506, 0x11f8) }, /* 3Com 3C460 */
12430 + { USB_DEVICE(0x0557, 0x2002) }, /* ATEN USB Ethernet */
12431 + { USB_DEVICE(0x0557, 0x4000) }, /* D-Link DSB-650C */
12432 + { USB_DEVICE(0x0565, 0x0002) }, /* Peracom Enet */
12433 + { USB_DEVICE(0x0565, 0x0003) }, /* Optus@Home UEP1045A */
12434 + { USB_DEVICE(0x0565, 0x0005) }, /* Peracom Enet2 */
12435 + { USB_DEVICE(0x05e9, 0x0008) }, /* KLSI KL5KUSB101B */
12436 + { USB_DEVICE(0x05e9, 0x0009) }, /* KLSI KL5KUSB101B (Board change) */
12437 + { USB_DEVICE(0x066b, 0x2202) }, /* Linksys USB10T */
12438 + { USB_DEVICE(0x06e1, 0x0008) }, /* ADS USB-10BT */
12439 + { USB_DEVICE(0x06e1, 0x0009) }, /* ADS USB-10BT */
12440 + { USB_DEVICE(0x0707, 0x0100) }, /* SMC 2202USB */
12441 + { USB_DEVICE(0x07aa, 0x0001) }, /* Correga K.K. */
12442 + { USB_DEVICE(0x07b8, 0x4000) }, /* D-Link DU-E10 */
12443 + { USB_DEVICE(0x07c9, 0xb010) }, /* Allied Telesyn AT-USB10 USB Ethernet Adapter */
12444 + { USB_DEVICE(0x0846, 0x1001) }, /* NetGear EA-101 */
12445 + { USB_DEVICE(0x0846, 0x1002) }, /* NetGear EA-101 */
12446 + { USB_DEVICE(0x085a, 0x0008) }, /* PortGear Ethernet Adapter */
12447 + { USB_DEVICE(0x085a, 0x0009) }, /* PortGear Ethernet Adapter */
12448 + { USB_DEVICE(0x087d, 0x5704) }, /* Jaton USB Ethernet Device Adapter */
12449 + { USB_DEVICE(0x0951, 0x0008) }, /* Kingston Technology USB Ethernet Adapter */
12450 + { USB_DEVICE(0x095a, 0x3003) }, /* Portsmith Express Ethernet Adapter */
12451 + { USB_DEVICE(0x10bd, 0x1427) }, /* ASANTE USB To Ethernet Adapter */
12452 + { USB_DEVICE(0x1342, 0x0204) }, /* Mobility USB-Ethernet Adapter */
12453 + { USB_DEVICE(0x13d2, 0x0400) }, /* Shark Pocket Adapter */
12454 + { USB_DEVICE(0x1485, 0x0001) }, /* Silicom U2E */
12455 + { USB_DEVICE(0x1485, 0x0002) }, /* Psion Dacom Gold Port Ethernet */
12456 + { USB_DEVICE(0x1645, 0x0005) }, /* Entrega E45 */
12457 + { USB_DEVICE(0x1645, 0x0008) }, /* Entrega USB Ethernet Adapter */
12458 + { USB_DEVICE(0x1645, 0x8005) }, /* PortGear Ethernet Adapter */
12459 + { USB_DEVICE(0x1668, 0x0323) }, /* Actiontec USB Ethernet */
12460 + { USB_DEVICE(0x2001, 0x4000) }, /* D-link DSB-650C */
12461 + {} /* Null terminator */
12462 +};
12463 +
12464 +MODULE_DEVICE_TABLE (usb, usb_klsi_table);
12465 +
12466 +/****************************************************************
12467 + * kaweth_driver
12468 + ****************************************************************/
12469 +static struct usb_driver kaweth_driver = {
12470 + .name = driver_name,
12471 + .probe = kaweth_probe,
12472 + .disconnect = kaweth_disconnect,
12473 + .suspend = kaweth_suspend,
12474 + .resume = kaweth_resume,
12475 + .id_table = usb_klsi_table,
12476 + .supports_autosuspend = 1,
12477 + .disable_hub_initiated_lpm = 1,
12478 +};
12479 +
12480 +typedef __u8 eth_addr_t[6];
12481 +
12482 +/****************************************************************
12483 + * usb_eth_dev
12484 + ****************************************************************/
12485 +struct usb_eth_dev {
12486 + char *name;
12487 + __u16 vendor;
12488 + __u16 device;
12489 + void *pdata;
12490 +};
12491 +
12492 +/****************************************************************
12493 + * kaweth_ethernet_configuration
12494 + * Refer Table 8
12495 + ****************************************************************/
12496 +struct kaweth_ethernet_configuration
12497 +{
12498 + __u8 size;
12499 + __u8 reserved1;
12500 + __u8 reserved2;
12501 + eth_addr_t hw_addr;
12502 + __u32 statistics_mask;
12503 + __le16 segment_size;
12504 + __u16 max_multicast_filters;
12505 + __u8 reserved3;
12506 +} __packed;
12507 +
12508 +/****************************************************************
12509 + * kaweth_device
12510 + ****************************************************************/
12511 +struct kaweth_device
12512 +{
12513 + spinlock_t device_lock;
12514 +
12515 + __u32 status;
12516 + int end;
12517 + int suspend_lowmem_rx;
12518 + int suspend_lowmem_ctrl;
12519 + int linkstate;
12520 + int opened;
12521 + struct delayed_work lowmem_work;
12522 +
12523 + struct usb_device *dev;
12524 + struct usb_interface *intf;
12525 + struct net_device *net;
12526 + wait_queue_head_t term_wait;
12527 +
12528 + struct urb *rx_urb;
12529 + struct urb *tx_urb;
12530 + struct urb *irq_urb;
12531 +
12532 + dma_addr_t intbufferhandle;
12533 + __u8 *intbuffer;
12534 + dma_addr_t rxbufferhandle;
12535 + __u8 *rx_buf;
12536 +
12537 +
12538 + struct sk_buff *tx_skb;
12539 +
12540 + __u8 *firmware_buf;
12541 + __u8 scratch[KAWETH_SCRATCH_SIZE];
12542 + __u16 packet_filter_bitmap;
12543 +
12544 + struct kaweth_ethernet_configuration configuration;
12545 +
12546 + struct net_device_stats stats;
12547 +};
12548 +
12549 +/****************************************************************
12550 + * kaweth_control
12551 + ****************************************************************/
12552 +static int kaweth_control(struct kaweth_device *kaweth,
12553 + unsigned int pipe,
12554 + __u8 request,
12555 + __u8 requesttype,
12556 + __u16 value,
12557 + __u16 index,
12558 + void *data,
12559 + __u16 size,
12560 + int timeout)
12561 +{
12562 + struct usb_ctrlrequest *dr;
12563 + int retval;
12564 +
12565 + netdev_dbg(kaweth->net, "kaweth_control()\n");
12566 +
12567 + if(in_interrupt()) {
12568 + netdev_dbg(kaweth->net, "in_interrupt()\n");
12569 + return -EBUSY;
12570 + }
12571 +
12572 + dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
12573 + if (!dr)
12574 + return -ENOMEM;
12575 +
12576 + dr->bRequestType = requesttype;
12577 + dr->bRequest = request;
12578 + dr->wValue = cpu_to_le16(value);
12579 + dr->wIndex = cpu_to_le16(index);
12580 + dr->wLength = cpu_to_le16(size);
12581 +
12582 + retval = kaweth_internal_control_msg(kaweth->dev,
12583 + pipe,
12584 + dr,
12585 + data,
12586 + size,
12587 + timeout);
12588 +
12589 + kfree(dr);
12590 + return retval;
12591 +}
12592 +
12593 +/****************************************************************
12594 + * kaweth_read_configuration
12595 + ****************************************************************/
12596 +static int kaweth_read_configuration(struct kaweth_device *kaweth)
12597 +{
12598 + int retval;
12599 +
12600 + netdev_dbg(kaweth->net, "Reading kaweth configuration\n");
12601 +
12602 + retval = kaweth_control(kaweth,
12603 + usb_rcvctrlpipe(kaweth->dev, 0),
12604 + KAWETH_COMMAND_GET_ETHERNET_DESC,
12605 + USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE,
12606 + 0,
12607 + 0,
12608 + (void *)&kaweth->configuration,
12609 + sizeof(kaweth->configuration),
12610 + KAWETH_CONTROL_TIMEOUT);
12611 +
12612 + return retval;
12613 +}
12614 +
12615 +/****************************************************************
12616 + * kaweth_set_urb_size
12617 + ****************************************************************/
12618 +static int kaweth_set_urb_size(struct kaweth_device *kaweth, __u16 urb_size)
12619 +{
12620 + int retval;
12621 +
12622 + netdev_dbg(kaweth->net, "Setting URB size to %d\n", (unsigned)urb_size);
12623 +
12624 + retval = kaweth_control(kaweth,
12625 + usb_sndctrlpipe(kaweth->dev, 0),
12626 + KAWETH_COMMAND_SET_URB_SIZE,
12627 + USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
12628 + urb_size,
12629 + 0,
12630 + (void *)&kaweth->scratch,
12631 + 0,
12632 + KAWETH_CONTROL_TIMEOUT);
12633 +
12634 + return retval;
12635 +}
12636 +
12637 +/****************************************************************
12638 + * kaweth_set_sofs_wait
12639 + ****************************************************************/
12640 +static int kaweth_set_sofs_wait(struct kaweth_device *kaweth, __u16 sofs_wait)
12641 +{
12642 + int retval;
12643 +
12644 + netdev_dbg(kaweth->net, "Set SOFS wait to %d\n", (unsigned)sofs_wait);
12645 +
12646 + retval = kaweth_control(kaweth,
12647 + usb_sndctrlpipe(kaweth->dev, 0),
12648 + KAWETH_COMMAND_SET_SOFS_WAIT,
12649 + USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
12650 + sofs_wait,
12651 + 0,
12652 + (void *)&kaweth->scratch,
12653 + 0,
12654 + KAWETH_CONTROL_TIMEOUT);
12655 +
12656 + return retval;
12657 +}
12658 +
12659 +/****************************************************************
12660 + * kaweth_set_receive_filter
12661 + ****************************************************************/
12662 +static int kaweth_set_receive_filter(struct kaweth_device *kaweth,
12663 + __u16 receive_filter)
12664 +{
12665 + int retval;
12666 +
12667 + netdev_dbg(kaweth->net, "Set receive filter to %d\n",
12668 + (unsigned)receive_filter);
12669 +
12670 + retval = kaweth_control(kaweth,
12671 + usb_sndctrlpipe(kaweth->dev, 0),
12672 + KAWETH_COMMAND_SET_PACKET_FILTER,
12673 + USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
12674 + receive_filter,
12675 + 0,
12676 + (void *)&kaweth->scratch,
12677 + 0,
12678 + KAWETH_CONTROL_TIMEOUT);
12679 +
12680 + return retval;
12681 +}
12682 +
12683 +/****************************************************************
12684 + * kaweth_download_firmware
12685 + ****************************************************************/
12686 +static int kaweth_download_firmware(struct kaweth_device *kaweth,
12687 + const char *fwname,
12688 + __u8 interrupt,
12689 + __u8 type)
12690 +{
12691 + const struct firmware *fw;
12692 + int data_len;
12693 + int ret;
12694 +
12695 + ret = request_firmware(&fw, fwname, &kaweth->dev->dev);
12696 + if (ret) {
12697 + dev_err(&kaweth->intf->dev, "Firmware request failed\n");
12698 + return ret;
12699 + }
12700 +
12701 + if (fw->size > KAWETH_FIRMWARE_BUF_SIZE) {
12702 + dev_err(&kaweth->intf->dev, "Firmware too big: %zu\n",
12703 + fw->size);
12704 + release_firmware(fw);
12705 + return -ENOSPC;
12706 + }
12707 + data_len = fw->size;
12708 + memcpy(kaweth->firmware_buf, fw->data, fw->size);
12709 +
12710 + release_firmware(fw);
12711 +
12712 + kaweth->firmware_buf[2] = (data_len & 0xFF) - 7;
12713 + kaweth->firmware_buf[3] = data_len >> 8;
12714 + kaweth->firmware_buf[4] = type;
12715 + kaweth->firmware_buf[5] = interrupt;
12716 +
12717 + netdev_dbg(kaweth->net, "High: %i, Low:%i\n", kaweth->firmware_buf[3],
12718 + kaweth->firmware_buf[2]);
12719 +
12720 + netdev_dbg(kaweth->net,
12721 + "Downloading firmware at %p to kaweth device at %p\n",
12722 + kaweth->firmware_buf, kaweth);
12723 + netdev_dbg(kaweth->net, "Firmware length: %d\n", data_len);
12724 +
12725 + return kaweth_control(kaweth,
12726 + usb_sndctrlpipe(kaweth->dev, 0),
12727 + KAWETH_COMMAND_SCAN,
12728 + USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
12729 + 0,
12730 + 0,
12731 + (void *)kaweth->firmware_buf,
12732 + data_len,
12733 + KAWETH_CONTROL_TIMEOUT);
12734 +}
12735 +
12736 +/****************************************************************
12737 + * kaweth_trigger_firmware
12738 + ****************************************************************/
12739 +static int kaweth_trigger_firmware(struct kaweth_device *kaweth,
12740 + __u8 interrupt)
12741 +{
12742 + kaweth->firmware_buf[0] = 0xB6;
12743 + kaweth->firmware_buf[1] = 0xC3;
12744 + kaweth->firmware_buf[2] = 0x01;
12745 + kaweth->firmware_buf[3] = 0x00;
12746 + kaweth->firmware_buf[4] = 0x06;
12747 + kaweth->firmware_buf[5] = interrupt;
12748 + kaweth->firmware_buf[6] = 0x00;
12749 + kaweth->firmware_buf[7] = 0x00;
12750 +
12751 + netdev_dbg(kaweth->net, "Triggering firmware\n");
12752 +
12753 + return kaweth_control(kaweth,
12754 + usb_sndctrlpipe(kaweth->dev, 0),
12755 + KAWETH_COMMAND_SCAN,
12756 + USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
12757 + 0,
12758 + 0,
12759 + (void *)kaweth->firmware_buf,
12760 + 8,
12761 + KAWETH_CONTROL_TIMEOUT);
12762 +}
12763 +
12764 +/****************************************************************
12765 + * kaweth_reset
12766 + ****************************************************************/
12767 +static int kaweth_reset(struct kaweth_device *kaweth)
12768 +{
12769 + int result;
12770 +
12771 + netdev_dbg(kaweth->net, "kaweth_reset(%p)\n", kaweth);
12772 + result = usb_reset_configuration(kaweth->dev);
12773 + mdelay(10);
12774 +
12775 + netdev_dbg(kaweth->net, "kaweth_reset() returns %d.\n", result);
12776 +
12777 + return result;
12778 +}
12779 +
12780 +static void kaweth_usb_receive(struct urb *);
12781 +static int kaweth_resubmit_rx_urb(struct kaweth_device *, gfp_t);
12782 +
12783 +/****************************************************************
12784 + int_callback
12785 +*****************************************************************/
12786 +
12787 +static void kaweth_resubmit_int_urb(struct kaweth_device *kaweth, gfp_t mf)
12788 +{
12789 + int status;
12790 +
12791 + status = usb_submit_urb (kaweth->irq_urb, mf);
12792 + if (unlikely(status == -ENOMEM)) {
12793 + kaweth->suspend_lowmem_ctrl = 1;
12794 + schedule_delayed_work(&kaweth->lowmem_work, HZ/4);
12795 + } else {
12796 + kaweth->suspend_lowmem_ctrl = 0;
12797 + }
12798 +
12799 + if (status)
12800 + dev_err(&kaweth->intf->dev,
12801 + "can't resubmit intr, %s-%s, status %d\n",
12802 + kaweth->dev->bus->bus_name,
12803 + kaweth->dev->devpath, status);
12804 +}
12805 +
12806 +static void int_callback(struct urb *u)
12807 +{
12808 + struct kaweth_device *kaweth = u->context;
12809 + int act_state;
12810 + int status = u->status;
12811 +
12812 + switch (status) {
12813 + case 0: /* success */
12814 + break;
12815 + case -ECONNRESET: /* unlink */
12816 + case -ENOENT:
12817 + case -ESHUTDOWN:
12818 + return;
12819 + /* -EPIPE: should clear the halt */
12820 + default: /* error */
12821 + goto resubmit;
12822 + }
12823 +
12824 + /* we check the link state to report changes */
12825 + if (kaweth->linkstate != (act_state = ( kaweth->intbuffer[STATE_OFFSET] | STATE_MASK) >> STATE_SHIFT)) {
12826 + if (act_state)
12827 + netif_carrier_on(kaweth->net);
12828 + else
12829 + netif_carrier_off(kaweth->net);
12830 +
12831 + kaweth->linkstate = act_state;
12832 + }
12833 +resubmit:
12834 + kaweth_resubmit_int_urb(kaweth, GFP_ATOMIC);
12835 +}
12836 +
12837 +static void kaweth_resubmit_tl(struct work_struct *work)
12838 +{
12839 + struct kaweth_device *kaweth =
12840 + container_of(work, struct kaweth_device, lowmem_work.work);
12841 +
12842 + if (IS_BLOCKED(kaweth->status))
12843 + return;
12844 +
12845 + if (kaweth->suspend_lowmem_rx)
12846 + kaweth_resubmit_rx_urb(kaweth, GFP_NOIO);
12847 +
12848 + if (kaweth->suspend_lowmem_ctrl)
12849 + kaweth_resubmit_int_urb(kaweth, GFP_NOIO);
12850 +}
12851 +
12852 +
12853 +/****************************************************************
12854 + * kaweth_resubmit_rx_urb
12855 + ****************************************************************/
12856 +static int kaweth_resubmit_rx_urb(struct kaweth_device *kaweth,
12857 + gfp_t mem_flags)
12858 +{
12859 + int result;
12860 +
12861 + usb_fill_bulk_urb(kaweth->rx_urb,
12862 + kaweth->dev,
12863 + usb_rcvbulkpipe(kaweth->dev, 1),
12864 + kaweth->rx_buf,
12865 + KAWETH_BUF_SIZE,
12866 + kaweth_usb_receive,
12867 + kaweth);
12868 + kaweth->rx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
12869 + kaweth->rx_urb->transfer_dma = kaweth->rxbufferhandle;
12870 +
12871 + if((result = usb_submit_urb(kaweth->rx_urb, mem_flags))) {
12872 + if (result == -ENOMEM) {
12873 + kaweth->suspend_lowmem_rx = 1;
12874 + schedule_delayed_work(&kaweth->lowmem_work, HZ/4);
12875 + }
12876 + dev_err(&kaweth->intf->dev, "resubmitting rx_urb %d failed\n",
12877 + result);
12878 + } else {
12879 + kaweth->suspend_lowmem_rx = 0;
12880 + }
12881 +
12882 + return result;
12883 +}
12884 +
12885 +static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth);
12886 +
12887 +/****************************************************************
12888 + * kaweth_usb_receive
12889 + ****************************************************************/
12890 +static void kaweth_usb_receive(struct urb *urb)
12891 +{
12892 + struct device *dev = &urb->dev->dev;
12893 + struct kaweth_device *kaweth = urb->context;
12894 + struct net_device *net = kaweth->net;
12895 + int status = urb->status;
12896 +
12897 + int count = urb->actual_length;
12898 + int count2 = urb->transfer_buffer_length;
12899 +
12900 + __u16 pkt_len = le16_to_cpup((__le16 *)kaweth->rx_buf);
12901 +
12902 + struct sk_buff *skb;
12903 +
12904 + if (unlikely(status == -EPIPE)) {
12905 + kaweth->stats.rx_errors++;
12906 + kaweth->end = 1;
12907 + wake_up(&kaweth->term_wait);
12908 + dev_dbg(dev, "Status was -EPIPE.\n");
12909 + return;
12910 + }
12911 + if (unlikely(status == -ECONNRESET || status == -ESHUTDOWN)) {
12912 + /* we are killed - set a flag and wake the disconnect handler */
12913 + kaweth->end = 1;
12914 + wake_up(&kaweth->term_wait);
12915 + dev_dbg(dev, "Status was -ECONNRESET or -ESHUTDOWN.\n");
12916 + return;
12917 + }
12918 + if (unlikely(status == -EPROTO || status == -ETIME ||
12919 + status == -EILSEQ)) {
12920 + kaweth->stats.rx_errors++;
12921 + dev_dbg(dev, "Status was -EPROTO, -ETIME, or -EILSEQ.\n");
12922 + return;
12923 + }
12924 + if (unlikely(status == -EOVERFLOW)) {
12925 + kaweth->stats.rx_errors++;
12926 + dev_dbg(dev, "Status was -EOVERFLOW.\n");
12927 + }
12928 + spin_lock(&kaweth->device_lock);
12929 + if (IS_BLOCKED(kaweth->status)) {
12930 + spin_unlock(&kaweth->device_lock);
12931 + return;
12932 + }
12933 + spin_unlock(&kaweth->device_lock);
12934 +
12935 + if(status && status != -EREMOTEIO && count != 1) {
12936 + dev_err(&kaweth->intf->dev,
12937 + "%s RX status: %d count: %d packet_len: %d\n",
12938 + net->name, status, count, (int)pkt_len);
12939 + kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
12940 + return;
12941 + }
12942 +
12943 + if(kaweth->net && (count > 2)) {
12944 + if(pkt_len > (count - 2)) {
12945 + dev_err(&kaweth->intf->dev,
12946 + "Packet length too long for USB frame (pkt_len: %x, count: %x)\n",
12947 + pkt_len, count);
12948 + dev_err(&kaweth->intf->dev, "Packet len & 2047: %x\n",
12949 + pkt_len & 2047);
12950 + dev_err(&kaweth->intf->dev, "Count 2: %x\n", count2);
12951 + kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
12952 + return;
12953 + }
12954 +
12955 + if(!(skb = dev_alloc_skb(pkt_len+2))) {
12956 + kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
12957 + return;
12958 + }
12959 +
12960 + skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
12961 +
12962 + skb_copy_to_linear_data(skb, kaweth->rx_buf + 2, pkt_len);
12963 +
12964 + skb_put(skb, pkt_len);
12965 +
12966 + skb->protocol = eth_type_trans(skb, net);
12967 +
12968 + netif_rx(skb);
12969 +
12970 + kaweth->stats.rx_packets++;
12971 + kaweth->stats.rx_bytes += pkt_len;
12972 + }
12973 +
12974 + kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
12975 +}
12976 +
12977 +/****************************************************************
12978 + * kaweth_open
12979 + ****************************************************************/
12980 +static int kaweth_open(struct net_device *net)
12981 +{
12982 + struct kaweth_device *kaweth = netdev_priv(net);
12983 + int res;
12984 +
12985 + netdev_dbg(kaweth->net, "Opening network device.\n");
12986 +
12987 + res = usb_autopm_get_interface(kaweth->intf);
12988 + if (res) {
12989 + dev_err(&kaweth->intf->dev, "Interface cannot be resumed.\n");
12990 + return -EIO;
12991 + }
12992 + res = kaweth_resubmit_rx_urb(kaweth, GFP_KERNEL);
12993 + if (res)
12994 + goto err_out;
12995 +
12996 + usb_fill_int_urb(
12997 + kaweth->irq_urb,
12998 + kaweth->dev,
12999 + usb_rcvintpipe(kaweth->dev, 3),
13000 + kaweth->intbuffer,
13001 + INTBUFFERSIZE,
13002 + int_callback,
13003 + kaweth,
13004 + 250); /* overriding the descriptor */
13005 + kaweth->irq_urb->transfer_dma = kaweth->intbufferhandle;
13006 + kaweth->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
13007 +
13008 + res = usb_submit_urb(kaweth->irq_urb, GFP_KERNEL);
13009 + if (res) {
13010 + usb_kill_urb(kaweth->rx_urb);
13011 + goto err_out;
13012 + }
13013 + kaweth->opened = 1;
13014 +
13015 + netif_start_queue(net);
13016 +
13017 + kaweth_async_set_rx_mode(kaweth);
13018 + return 0;
13019 +
13020 +err_out:
13021 + usb_autopm_put_interface(kaweth->intf);
13022 + return -EIO;
13023 +}
13024 +
13025 +/****************************************************************
13026 + * kaweth_kill_urbs
13027 + ****************************************************************/
13028 +static void kaweth_kill_urbs(struct kaweth_device *kaweth)
13029 +{
13030 + usb_kill_urb(kaweth->irq_urb);
13031 + usb_kill_urb(kaweth->rx_urb);
13032 + usb_kill_urb(kaweth->tx_urb);
13033 +
13034 + cancel_delayed_work_sync(&kaweth->lowmem_work);
13035 +
13036 + /* a scheduled work may have resubmitted,
13037 + we hit them again */
13038 + usb_kill_urb(kaweth->irq_urb);
13039 + usb_kill_urb(kaweth->rx_urb);
13040 +}
13041 +
13042 +/****************************************************************
13043 + * kaweth_close
13044 + ****************************************************************/
13045 +static int kaweth_close(struct net_device *net)
13046 +{
13047 + struct kaweth_device *kaweth = netdev_priv(net);
13048 +
13049 + netif_stop_queue(net);
13050 + kaweth->opened = 0;
13051 +
13052 + kaweth->status |= KAWETH_STATUS_CLOSING;
13053 +
13054 + kaweth_kill_urbs(kaweth);
13055 +
13056 + kaweth->status &= ~KAWETH_STATUS_CLOSING;
13057 +
13058 + usb_autopm_put_interface(kaweth->intf);
13059 +
13060 + return 0;
13061 +}
13062 +
13063 +static u32 kaweth_get_link(struct net_device *dev)
13064 +{
13065 + struct kaweth_device *kaweth = netdev_priv(dev);
13066 +
13067 + return kaweth->linkstate;
13068 +}
13069 +
13070 +static const struct ethtool_ops ops = {
13071 + .get_link = kaweth_get_link
13072 +};
13073 +
13074 +/****************************************************************
13075 + * kaweth_usb_transmit_complete
13076 + ****************************************************************/
13077 +static void kaweth_usb_transmit_complete(struct urb *urb)
13078 +{
13079 + struct kaweth_device *kaweth = urb->context;
13080 + struct sk_buff *skb = kaweth->tx_skb;
13081 + int status = urb->status;
13082 +
13083 + if (unlikely(status != 0))
13084 + if (status != -ENOENT)
13085 + dev_dbg(&urb->dev->dev, "%s: TX status %d.\n",
13086 + kaweth->net->name, status);
13087 +
13088 + netif_wake_queue(kaweth->net);
13089 + dev_kfree_skb_irq(skb);
13090 +}
13091 +
13092 +/****************************************************************
13093 + * kaweth_start_xmit
13094 + ****************************************************************/
13095 +static netdev_tx_t kaweth_start_xmit(struct sk_buff *skb,
13096 + struct net_device *net)
13097 +{
13098 + struct kaweth_device *kaweth = netdev_priv(net);
13099 + __le16 *private_header;
13100 +
13101 + int res;
13102 +
13103 + spin_lock_irq(&kaweth->device_lock);
13104 +
13105 + kaweth_async_set_rx_mode(kaweth);
13106 + netif_stop_queue(net);
13107 + if (IS_BLOCKED(kaweth->status)) {
13108 + goto skip;
13109 + }
13110 +
13111 + /* We now decide whether we can put our special header into the sk_buff */
13112 + if (skb_cloned(skb) || skb_headroom(skb) < 2) {
13113 + /* no such luck - we make our own */
13114 + struct sk_buff *copied_skb;
13115 + copied_skb = skb_copy_expand(skb, 2, 0, GFP_ATOMIC);
13116 + dev_kfree_skb_irq(skb);
13117 + skb = copied_skb;
13118 + if (!copied_skb) {
13119 + kaweth->stats.tx_errors++;
13120 + netif_start_queue(net);
13121 + spin_unlock_irq(&kaweth->device_lock);
13122 + return NETDEV_TX_OK;
13123 + }
13124 + }
13125 +
13126 + private_header = (__le16 *)__skb_push(skb, 2);
13127 + *private_header = cpu_to_le16(skb->len-2);
13128 + kaweth->tx_skb = skb;
13129 +
13130 + usb_fill_bulk_urb(kaweth->tx_urb,
13131 + kaweth->dev,
13132 + usb_sndbulkpipe(kaweth->dev, 2),
13133 + private_header,
13134 + skb->len,
13135 + kaweth_usb_transmit_complete,
13136 + kaweth);
13137 + kaweth->end = 0;
13138 +
13139 + if((res = usb_submit_urb(kaweth->tx_urb, GFP_ATOMIC)))
13140 + {
13141 + dev_warn(&net->dev, "kaweth failed tx_urb %d\n", res);
13142 +skip:
13143 + kaweth->stats.tx_errors++;
13144 +
13145 + netif_start_queue(net);
13146 + dev_kfree_skb_irq(skb);
13147 + }
13148 + else
13149 + {
13150 + kaweth->stats.tx_packets++;
13151 + kaweth->stats.tx_bytes += skb->len;
13152 + }
13153 +
13154 + spin_unlock_irq(&kaweth->device_lock);
13155 +
13156 + return NETDEV_TX_OK;
13157 +}
13158 +
13159 +/****************************************************************
13160 + * kaweth_set_rx_mode
13161 + ****************************************************************/
13162 +static void kaweth_set_rx_mode(struct net_device *net)
13163 +{
13164 + struct kaweth_device *kaweth = netdev_priv(net);
13165 +
13166 + __u16 packet_filter_bitmap = KAWETH_PACKET_FILTER_DIRECTED |
13167 + KAWETH_PACKET_FILTER_BROADCAST |
13168 + KAWETH_PACKET_FILTER_MULTICAST;
13169 +
13170 + netdev_dbg(net, "Setting Rx mode to %d\n", packet_filter_bitmap);
13171 +
13172 + netif_stop_queue(net);
13173 +
13174 + if (net->flags & IFF_PROMISC) {
13175 + packet_filter_bitmap |= KAWETH_PACKET_FILTER_PROMISCUOUS;
13176 + }
13177 + else if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI)) {
13178 + packet_filter_bitmap |= KAWETH_PACKET_FILTER_ALL_MULTICAST;
13179 + }
13180 +
13181 + kaweth->packet_filter_bitmap = packet_filter_bitmap;
13182 + netif_wake_queue(net);
13183 +}
13184 +
13185 +/****************************************************************
13186 + * kaweth_async_set_rx_mode
13187 + ****************************************************************/
13188 +static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth)
13189 +{
13190 + int result;
13191 + __u16 packet_filter_bitmap = kaweth->packet_filter_bitmap;
13192 +
13193 + kaweth->packet_filter_bitmap = 0;
13194 + if (packet_filter_bitmap == 0)
13195 + return;
13196 +
13197 + if (in_interrupt())
13198 + return;
13199 +
13200 + result = kaweth_control(kaweth,
13201 + usb_sndctrlpipe(kaweth->dev, 0),
13202 + KAWETH_COMMAND_SET_PACKET_FILTER,
13203 + USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
13204 + packet_filter_bitmap,
13205 + 0,
13206 + (void *)&kaweth->scratch,
13207 + 0,
13208 + KAWETH_CONTROL_TIMEOUT);
13209 +
13210 + if(result < 0) {
13211 + dev_err(&kaweth->intf->dev, "Failed to set Rx mode: %d\n",
13212 + result);
13213 + }
13214 + else {
13215 + netdev_dbg(kaweth->net, "Set Rx mode to %d\n",
13216 + packet_filter_bitmap);
13217 + }
13218 +}
13219 +
13220 +/****************************************************************
13221 + * kaweth_netdev_stats
13222 + ****************************************************************/
13223 +static struct net_device_stats *kaweth_netdev_stats(struct net_device *dev)
13224 +{
13225 + struct kaweth_device *kaweth = netdev_priv(dev);
13226 + return &kaweth->stats;
13227 +}
13228 +
13229 +/****************************************************************
13230 + * kaweth_tx_timeout
13231 + ****************************************************************/
13232 +static void kaweth_tx_timeout(struct net_device *net)
13233 +{
13234 + struct kaweth_device *kaweth = netdev_priv(net);
13235 +
13236 + dev_warn(&net->dev, "%s: Tx timed out. Resetting.\n", net->name);
13237 + kaweth->stats.tx_errors++;
13238 + net->trans_start = jiffies;
13239 +
13240 + usb_unlink_urb(kaweth->tx_urb);
13241 +}
13242 +
13243 +/****************************************************************
13244 + * kaweth_suspend
13245 + ****************************************************************/
13246 +static int kaweth_suspend(struct usb_interface *intf, pm_message_t message)
13247 +{
13248 + struct kaweth_device *kaweth = usb_get_intfdata(intf);
13249 + unsigned long flags;
13250 +
13251 + dev_dbg(&intf->dev, "Suspending device\n");
13252 + spin_lock_irqsave(&kaweth->device_lock, flags);
13253 + kaweth->status |= KAWETH_STATUS_SUSPENDING;
13254 + spin_unlock_irqrestore(&kaweth->device_lock, flags);
13255 +
13256 + kaweth_kill_urbs(kaweth);
13257 + return 0;
13258 +}
13259 +
13260 +/****************************************************************
13261 + * kaweth_resume
13262 + ****************************************************************/
13263 +static int kaweth_resume(struct usb_interface *intf)
13264 +{
13265 + struct kaweth_device *kaweth = usb_get_intfdata(intf);
13266 + unsigned long flags;
13267 +
13268 + dev_dbg(&intf->dev, "Resuming device\n");
13269 + spin_lock_irqsave(&kaweth->device_lock, flags);
13270 + kaweth->status &= ~KAWETH_STATUS_SUSPENDING;
13271 + spin_unlock_irqrestore(&kaweth->device_lock, flags);
13272 +
13273 + if (!kaweth->opened)
13274 + return 0;
13275 + kaweth_resubmit_rx_urb(kaweth, GFP_NOIO);
13276 + kaweth_resubmit_int_urb(kaweth, GFP_NOIO);
13277 +
13278 + return 0;
13279 +}
13280 +
13281 +/****************************************************************
13282 + * kaweth_probe
13283 + ****************************************************************/
13284 +
13285 +
13286 +static const struct net_device_ops kaweth_netdev_ops = {
13287 + .ndo_open = kaweth_open,
13288 + .ndo_stop = kaweth_close,
13289 + .ndo_start_xmit = kaweth_start_xmit,
13290 + .ndo_tx_timeout = kaweth_tx_timeout,
13291 + .ndo_set_rx_mode = kaweth_set_rx_mode,
13292 + .ndo_get_stats = kaweth_netdev_stats,
13293 + .ndo_change_mtu = eth_change_mtu,
13294 + .ndo_set_mac_address = eth_mac_addr,
13295 + .ndo_validate_addr = eth_validate_addr,
13296 +};
13297 +
13298 +static int kaweth_probe(
13299 + struct usb_interface *intf,
13300 + const struct usb_device_id *id /* from id_table */
13301 + )
13302 +{
13303 + struct device *dev = &intf->dev;
13304 + struct usb_device *udev = interface_to_usbdev(intf);
13305 + struct kaweth_device *kaweth;
13306 + struct net_device *netdev;
13307 + const eth_addr_t bcast_addr = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
13308 + int result = 0;
13309 +
13310 + dev_dbg(dev,
13311 + "Kawasaki Device Probe (Device number:%d): 0x%4.4x:0x%4.4x:0x%4.4x\n",
13312 + udev->devnum, le16_to_cpu(udev->descriptor.idVendor),
13313 + le16_to_cpu(udev->descriptor.idProduct),
13314 + le16_to_cpu(udev->descriptor.bcdDevice));
13315 +
13316 + dev_dbg(dev, "Device at %p\n", udev);
13317 +
13318 + dev_dbg(dev, "Descriptor length: %x type: %x\n",
13319 + (int)udev->descriptor.bLength,
13320 + (int)udev->descriptor.bDescriptorType);
13321 +
13322 + netdev = alloc_etherdev(sizeof(*kaweth));
13323 + if (!netdev)
13324 + return -ENOMEM;
13325 +
13326 + kaweth = netdev_priv(netdev);
13327 + kaweth->dev = udev;
13328 + kaweth->net = netdev;
13329 +
13330 + spin_lock_init(&kaweth->device_lock);
13331 + init_waitqueue_head(&kaweth->term_wait);
13332 +
13333 + dev_dbg(dev, "Resetting.\n");
13334 +
13335 + kaweth_reset(kaweth);
13336 +
13337 + /*
13338 + * If high byte of bcdDevice is nonzero, firmware is already
13339 + * downloaded. Don't try to do it again, or we'll hang the device.
13340 + */
13341 +
13342 + if (le16_to_cpu(udev->descriptor.bcdDevice) >> 8) {
13343 + dev_info(dev, "Firmware present in device.\n");
13344 + } else {
13345 + /* Download the firmware */
13346 + dev_info(dev, "Downloading firmware...\n");
13347 + kaweth->firmware_buf = (__u8 *)__get_free_page(GFP_KERNEL);
13348 + if ((result = kaweth_download_firmware(kaweth,
13349 + "kaweth/new_code.bin",
13350 + 100,
13351 + 2)) < 0) {
13352 + dev_err(dev, "Error downloading firmware (%d)\n",
13353 + result);
13354 + goto err_fw;
13355 + }
13356 +
13357 + if ((result = kaweth_download_firmware(kaweth,
13358 + "kaweth/new_code_fix.bin",
13359 + 100,
13360 + 3)) < 0) {
13361 + dev_err(dev, "Error downloading firmware fix (%d)\n",
13362 + result);
13363 + goto err_fw;
13364 + }
13365 +
13366 + if ((result = kaweth_download_firmware(kaweth,
13367 + "kaweth/trigger_code.bin",
13368 + 126,
13369 + 2)) < 0) {
13370 + dev_err(dev, "Error downloading trigger code (%d)\n",
13371 + result);
13372 + goto err_fw;
13373 +
13374 + }
13375 +
13376 + if ((result = kaweth_download_firmware(kaweth,
13377 + "kaweth/trigger_code_fix.bin",
13378 + 126,
13379 + 3)) < 0) {
13380 + dev_err(dev, "Error downloading trigger code fix (%d)\n", result);
13381 + goto err_fw;
13382 + }
13383 +
13384 +
13385 + if ((result = kaweth_trigger_firmware(kaweth, 126)) < 0) {
13386 + dev_err(dev, "Error triggering firmware (%d)\n", result);
13387 + goto err_fw;
13388 + }
13389 +
13390 + /* Device will now disappear for a moment... */
13391 + dev_info(dev, "Firmware loaded. I'll be back...\n");
13392 +err_fw:
13393 + free_page((unsigned long)kaweth->firmware_buf);
13394 + free_netdev(netdev);
13395 + return -EIO;
13396 + }
13397 +
13398 + result = kaweth_read_configuration(kaweth);
13399 +
13400 + if(result < 0) {
13401 + dev_err(dev, "Error reading configuration (%d), no net device created\n", result);
13402 + goto err_free_netdev;
13403 + }
13404 +
13405 + dev_info(dev, "Statistics collection: %x\n", kaweth->configuration.statistics_mask);
13406 + dev_info(dev, "Multicast filter limit: %x\n", kaweth->configuration.max_multicast_filters & ((1 << 15) - 1));
13407 + dev_info(dev, "MTU: %d\n", le16_to_cpu(kaweth->configuration.segment_size));
13408 + dev_info(dev, "Read MAC address %pM\n", kaweth->configuration.hw_addr);
13409 +
13410 + if(!memcmp(&kaweth->configuration.hw_addr,
13411 + &bcast_addr,
13412 + sizeof(bcast_addr))) {
13413 + dev_err(dev, "Firmware not functioning properly, no net device created\n");
13414 + goto err_free_netdev;
13415 + }
13416 +
13417 + if(kaweth_set_urb_size(kaweth, KAWETH_BUF_SIZE) < 0) {
13418 + dev_dbg(dev, "Error setting URB size\n");
13419 + goto err_free_netdev;
13420 + }
13421 +
13422 + if(kaweth_set_sofs_wait(kaweth, KAWETH_SOFS_TO_WAIT) < 0) {
13423 + dev_err(dev, "Error setting SOFS wait\n");
13424 + goto err_free_netdev;
13425 + }
13426 +
13427 + result = kaweth_set_receive_filter(kaweth,
13428 + KAWETH_PACKET_FILTER_DIRECTED |
13429 + KAWETH_PACKET_FILTER_BROADCAST |
13430 + KAWETH_PACKET_FILTER_MULTICAST);
13431 +
13432 + if(result < 0) {
13433 + dev_err(dev, "Error setting receive filter\n");
13434 + goto err_free_netdev;
13435 + }
13436 +
13437 + dev_dbg(dev, "Initializing net device.\n");
13438 +
13439 + kaweth->intf = intf;
13440 +
13441 + kaweth->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
13442 + if (!kaweth->tx_urb)
13443 + goto err_free_netdev;
13444 + kaweth->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
13445 + if (!kaweth->rx_urb)
13446 + goto err_only_tx;
13447 + kaweth->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
13448 + if (!kaweth->irq_urb)
13449 + goto err_tx_and_rx;
13450 +
13451 + kaweth->intbuffer = usb_alloc_coherent( kaweth->dev,
13452 + INTBUFFERSIZE,
13453 + GFP_KERNEL,
13454 + &kaweth->intbufferhandle);
13455 + if (!kaweth->intbuffer)
13456 + goto err_tx_and_rx_and_irq;
13457 + kaweth->rx_buf = usb_alloc_coherent( kaweth->dev,
13458 + KAWETH_BUF_SIZE,
13459 + GFP_KERNEL,
13460 + &kaweth->rxbufferhandle);
13461 + if (!kaweth->rx_buf)
13462 + goto err_all_but_rxbuf;
13463 +
13464 + memcpy(netdev->broadcast, &bcast_addr, sizeof(bcast_addr));
13465 + memcpy(netdev->dev_addr, &kaweth->configuration.hw_addr,
13466 + sizeof(kaweth->configuration.hw_addr));
13467 +
13468 + netdev->netdev_ops = &kaweth_netdev_ops;
13469 + netdev->watchdog_timeo = KAWETH_TX_TIMEOUT;
13470 + netdev->mtu = le16_to_cpu(kaweth->configuration.segment_size);
13471 + netdev->ethtool_ops = &ops;
13472 +
13473 + /* kaweth is zeroed as part of alloc_netdev */
13474 + INIT_DELAYED_WORK(&kaweth->lowmem_work, kaweth_resubmit_tl);
13475 + usb_set_intfdata(intf, kaweth);
13476 +
13477 +#if 0
13478 +// dma_supported() is deeply broken on almost all architectures
13479 + if (dma_supported (dev, 0xffffffffffffffffULL))
13480 + kaweth->net->features |= NETIF_F_HIGHDMA;
13481 +#endif
13482 +
13483 + SET_NETDEV_DEV(netdev, dev);
13484 + if (register_netdev(netdev) != 0) {
13485 + dev_err(dev, "Error registering netdev.\n");
13486 + goto err_intfdata;
13487 + }
13488 +
13489 + dev_info(dev, "kaweth interface created at %s\n",
13490 + kaweth->net->name);
13491 +
13492 + dev_dbg(dev, "Kaweth probe returning.\n");
13493 +
13494 + return 0;
13495 +
13496 +err_intfdata:
13497 + usb_set_intfdata(intf, NULL);
13498 + usb_free_coherent(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle);
13499 +err_all_but_rxbuf:
13500 + usb_free_coherent(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle);
13501 +err_tx_and_rx_and_irq:
13502 + usb_free_urb(kaweth->irq_urb);
13503 +err_tx_and_rx:
13504 + usb_free_urb(kaweth->rx_urb);
13505 +err_only_tx:
13506 + usb_free_urb(kaweth->tx_urb);
13507 +err_free_netdev:
13508 + free_netdev(netdev);
13509 +
13510 + return -EIO;
13511 +}
13512 +
13513 +/****************************************************************
13514 + * kaweth_disconnect
13515 + ****************************************************************/
13516 +static void kaweth_disconnect(struct usb_interface *intf)
13517 +{
13518 + struct kaweth_device *kaweth = usb_get_intfdata(intf);
13519 + struct net_device *netdev;
13520 +
13521 + dev_info(&intf->dev, "Unregistering\n");
13522 +
13523 + usb_set_intfdata(intf, NULL);
13524 + if (!kaweth) {
13525 + dev_warn(&intf->dev, "unregistering non-existent device\n");
13526 + return;
13527 + }
13528 + netdev = kaweth->net;
13529 +
13530 + netdev_dbg(kaweth->net, "Unregistering net device\n");
13531 + unregister_netdev(netdev);
13532 +
13533 + usb_free_urb(kaweth->rx_urb);
13534 + usb_free_urb(kaweth->tx_urb);
13535 + usb_free_urb(kaweth->irq_urb);
13536 +
13537 + usb_free_coherent(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle);
13538 + usb_free_coherent(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle);
13539 +
13540 + free_netdev(netdev);
13541 +}
13542 +
13543 +
13544 +// FIXME this completion stuff is a modified clone of
13545 +// an OLD version of some stuff in usb.c ...
13546 +struct usb_api_data {
13547 + wait_queue_head_t wqh;
13548 + int done;
13549 +};
13550 +
13551 +/*-------------------------------------------------------------------*
13552 + * completion handler for compatibility wrappers (sync control/bulk) *
13553 + *-------------------------------------------------------------------*/
13554 +static void usb_api_blocking_completion(struct urb *urb)
13555 +{
13556 + struct usb_api_data *awd = (struct usb_api_data *)urb->context;
13557 +
13558 + awd->done=1;
13559 + wake_up(&awd->wqh);
13560 +}
13561 +
13562 +/*-------------------------------------------------------------------*
13563 + * COMPATIBILITY STUFF *
13564 + *-------------------------------------------------------------------*/
13565 +
13566 +// Starts urb and waits for completion or timeout
13567 +static int usb_start_wait_urb(struct urb *urb, int timeout, int* actual_length)
13568 +{
13569 + struct usb_api_data awd;
13570 + int status;
13571 +
13572 + init_waitqueue_head(&awd.wqh);
13573 + awd.done = 0;
13574 +
13575 + urb->context = &awd;
13576 + status = usb_submit_urb(urb, GFP_ATOMIC);
13577 + if (status) {
13578 + // something went wrong
13579 + usb_free_urb(urb);
13580 + return status;
13581 + }
13582 +
13583 + if (!wait_event_timeout(awd.wqh, awd.done, timeout)) {
13584 + // timeout
13585 + dev_warn(&urb->dev->dev, "usb_control/bulk_msg: timeout\n");
13586 + usb_kill_urb(urb); // remove urb safely
13587 + status = -ETIMEDOUT;
13588 + }
13589 + else {
13590 + status = urb->status;
13591 + }
13592 +
13593 + if (actual_length) {
13594 + *actual_length = urb->actual_length;
13595 + }
13596 +
13597 + usb_free_urb(urb);
13598 + return status;
13599 +}
13600 +
13601 +/*-------------------------------------------------------------------*/
13602 +// returns status (negative) or length (positive)
13603 +static int kaweth_internal_control_msg(struct usb_device *usb_dev,
13604 + unsigned int pipe,
13605 + struct usb_ctrlrequest *cmd, void *data,
13606 + int len, int timeout)
13607 +{
13608 + struct urb *urb;
13609 + int retv;
13610 + int length = 0; /* shut up GCC */
13611 +
13612 + urb = usb_alloc_urb(0, GFP_ATOMIC);
13613 + if (!urb)
13614 + return -ENOMEM;
13615 +
13616 + usb_fill_control_urb(urb, usb_dev, pipe, (unsigned char*)cmd, data,
13617 + len, usb_api_blocking_completion, NULL);
13618 +
13619 + retv = usb_start_wait_urb(urb, timeout, &length);
13620 + if (retv < 0) {
13621 + return retv;
13622 + }
13623 + else {
13624 + return length;
13625 + }
13626 +}
13627 +
13628 +module_usb_driver(kaweth_driver);
13629 diff -Naur backports-4.2.6-1.org/drivers/net/usb/Kconfig backports-4.2.6-1/drivers/net/usb/Kconfig
13630 --- backports-4.2.6-1.org/drivers/net/usb/Kconfig 2015-11-15 22:19:40.000000000 +0100
13631 +++ backports-4.2.6-1/drivers/net/usb/Kconfig 2016-06-28 14:35:17.991973886 +0200
13632 @@ -13,7 +13,6 @@
13633 if USB_NET_DRIVERS
13634
13635 config USB_CATC
13636 - depends on n
13637 tristate "USB CATC NetMate-based Ethernet device support"
13638 depends on m
13639 depends on CRC32
13640 @@ -34,7 +33,6 @@
13641 module will be called catc.
13642
13643 config USB_KAWETH
13644 - depends on n
13645 tristate "USB KLSI KL5USB101-based ethernet device support"
13646 depends on m
13647 ---help---
13648 @@ -75,7 +73,6 @@
13649 module will be called kaweth.
13650
13651 config USB_PEGASUS
13652 - depends on n
13653 tristate "USB Pegasus/Pegasus-II based ethernet device support"
13654 depends on m
13655 select BPAUTO_MII
13656 @@ -92,7 +89,6 @@
13657 module will be called pegasus.
13658
13659 config USB_RTL8150
13660 - depends on n
13661 tristate "USB RTL8150 based ethernet device support"
13662 depends on m
13663 select BPAUTO_MII
13664 @@ -105,7 +101,6 @@
13665 module will be called rtl8150.
13666
13667 config USB_RTL8152
13668 - depends on n
13669 tristate "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters"
13670 depends on m
13671 select BPAUTO_MII
13672 @@ -153,7 +148,6 @@
13673 module will be called usbnet.
13674
13675 config USB_NET_AX8817X
13676 - depends on n
13677 tristate "ASIX AX88xxx Based USB 2.0 Ethernet Adapters"
13678 depends on m
13679 depends on USB_USBNET
13680 @@ -184,7 +178,6 @@
13681 what other networking devices you have in use.
13682
13683 config USB_NET_AX88179_178A
13684 - depends on n
13685 tristate "ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet"
13686 depends on m
13687 depends on USB_USBNET
13688 @@ -233,7 +226,6 @@
13689 name is used instead.
13690
13691 config USB_NET_CDC_EEM
13692 - depends on n
13693 tristate "CDC EEM support"
13694 depends on m
13695 depends on USB_USBNET
13696 @@ -269,7 +261,6 @@
13697 * Ericsson F5521gw Mobile Broadband Module
13698
13699 config USB_NET_HUAWEI_CDC_NCM
13700 - depends on n
13701 tristate "Huawei NCM embedded AT channel support"
13702 depends on m
13703 depends on USB_USBNET
13704 @@ -305,7 +296,6 @@
13705 module will be called cdc_mbim.
13706
13707 config USB_NET_DM9601
13708 - depends on n
13709 tristate "Davicom DM96xx based USB 10/100 ethernet devices"
13710 depends on m
13711 depends on USB_USBNET
13712 @@ -315,7 +305,6 @@
13713 based USB 10/100 Ethernet adapters.
13714
13715 config USB_NET_SR9700
13716 - depends on n
13717 tristate "CoreChip-sz SR9700 based USB 1.1 10/100 ethernet devices"
13718 depends on m
13719 depends on USB_USBNET
13720 @@ -325,7 +314,6 @@
13721 10/100 Ethernet adapters.
13722
13723 config USB_NET_SR9800
13724 - depends on n
13725 tristate "CoreChip-sz SR9800 based USB 2.0 10/100 ethernet devices"
13726 depends on m
13727 depends on USB_USBNET
13728 @@ -342,7 +330,6 @@
13729 module will be called sr9800.
13730
13731 config USB_NET_SMSC75XX
13732 - depends on n
13733 tristate "SMSC LAN75XX based USB 2.0 gigabit ethernet devices"
13734 depends on m
13735 depends on USB_USBNET
13736 @@ -354,7 +341,6 @@
13737 Gigabit Ethernet adapters.
13738
13739 config USB_NET_SMSC95XX
13740 - depends on n
13741 tristate "SMSC LAN95XX based USB 2.0 10/100 ethernet devices"
13742 depends on m
13743 depends on USB_USBNET
13744 @@ -366,7 +352,6 @@
13745 10/100 Ethernet adapters.
13746
13747 config USB_NET_GL620A
13748 - depends on n
13749 tristate "GeneSys GL620USB-A based cables"
13750 depends on m
13751 depends on USB_USBNET
13752 @@ -377,7 +362,6 @@
13753 Note that the half-duplex "GL620USB" is not supported.
13754
13755 config USB_NET_NET1080
13756 - depends on n
13757 tristate "NetChip 1080 based cables (Laplink, ...)"
13758 depends on m
13759 default y
13760 @@ -388,7 +372,6 @@
13761 optionally with LEDs that indicate traffic
13762
13763 config USB_NET_PLUSB
13764 - depends on n
13765 tristate "Prolific PL-2301/2302/25A1 based cables"
13766 depends on m
13767 # if the handshake/init/reset problems, from original 'plusb',
13768 @@ -399,7 +382,6 @@
13769 with one of these chips.
13770
13771 config USB_NET_MCS7830
13772 - depends on n
13773 tristate "MosChip MCS7830 based Ethernet adapters"
13774 depends on m
13775 depends on USB_USBNET
13776 @@ -425,7 +407,6 @@
13777 (and for) Microsoft; it isn't an "Open" ecosystem or market.
13778
13779 config USB_NET_CDC_SUBSET
13780 - depends on n
13781 tristate "Simple USB Network Links (CDC Ethernet subset)"
13782 depends on m
13783 depends on USB_USBNET
13784 @@ -497,7 +478,6 @@
13785 with one of these chips.
13786
13787 config USB_NET_ZAURUS
13788 - depends on n
13789 tristate "Sharp Zaurus (stock ROMs) and compatible"
13790 depends on m
13791 depends on USB_USBNET
13792 @@ -517,7 +497,6 @@
13793 some cases CDC MDLM) protocol, not "g_ether".
13794
13795 config USB_NET_CX82310_ETH
13796 - depends on n
13797 tristate "Conexant CX82310 USB ethernet port"
13798 depends on m
13799 depends on USB_USBNET
13800 @@ -527,7 +506,6 @@
13801 it will not work with ADSL modems (use cxacru driver instead).
13802
13803 config USB_NET_KALMIA
13804 - depends on n
13805 tristate "Samsung Kalmia based LTE USB modem"
13806 depends on m
13807 depends on USB_USBNET
13808 @@ -562,7 +540,6 @@
13809 module will be called qmi_wwan.
13810
13811 config USB_HSO
13812 - depends on n
13813 tristate "Option USB High Speed Mobile Devices"
13814 depends on m
13815 depends on USB && RFKILL && TTY
13816 @@ -575,7 +552,6 @@
13817 module will be called hso.
13818
13819 config USB_NET_INT51X1
13820 - depends on n
13821 tristate "Intellon PLC based usb adapter"
13822 depends on m
13823 depends on USB_USBNET
13824 @@ -585,7 +561,6 @@
13825 INT51x1/INT5200 chip, like the "devolo dLan duo".
13826
13827 config USB_CDC_PHONET
13828 - depends on n
13829 tristate "CDC Phonet support"
13830 depends on m
13831 depends on PHONET
13832 @@ -595,7 +570,6 @@
13833 "PC suite" USB profile.
13834
13835 config USB_IPHETH
13836 - depends on n
13837 tristate "Apple iPhone USB Ethernet driver"
13838 depends on m
13839 default n
13840 @@ -619,11 +593,10 @@
13841 module will be called sierra_net.
13842
13843 config USB_VL600
13844 - depends on n
13845 tristate "LG VL600 modem dongle"
13846 depends on m
13847 depends on USB_NET_CDCETHER && TTY
13848 - select USB_ACM
13849 +# depends on USB_ACM
13850 help
13851 Select this if you want to use an LG Electronics 4G/LTE usb modem
13852 called VL600. This driver only handles the ethernet
13853 diff -Naur backports-4.2.6-1.org/drivers/net/usb/Kconfig.orig backports-4.2.6-1/drivers/net/usb/Kconfig.orig
13854 --- backports-4.2.6-1.org/drivers/net/usb/Kconfig.orig 1970-01-01 01:00:00.000000000 +0100
13855 +++ backports-4.2.6-1/drivers/net/usb/Kconfig.orig 2016-06-28 14:35:17.991973886 +0200
13856 @@ -0,0 +1,638 @@
13857 +#
13858 +# USB Network devices configuration
13859 +#
13860 +comment "Host-side USB support is needed for USB Network Adapter support"
13861 + depends on !USB && NET
13862 +
13863 +menuconfig USB_NET_DRIVERS
13864 + tristate "USB Network Adapters"
13865 + depends on m
13866 + default USB if USB
13867 + depends on USB && NET
13868 +
13869 +if USB_NET_DRIVERS
13870 +
13871 +config USB_CATC
13872 + depends on n
13873 + tristate "USB CATC NetMate-based Ethernet device support"
13874 + depends on m
13875 + depends on CRC32
13876 + ---help---
13877 + Say Y if you want to use one of the following 10Mbps USB Ethernet
13878 + device based on the EL1210A chip. Supported devices are:
13879 + Belkin F5U011
13880 + Belkin F5U111
13881 + CATC NetMate
13882 + CATC NetMate II
13883 + smartBridges smartNIC
13884 +
13885 + This driver makes the adapter appear as a normal Ethernet interface,
13886 + typically on eth0, if it is the only ethernet device, or perhaps on
13887 + eth1, if you have a PCI or ISA ethernet card installed.
13888 +
13889 + To compile this driver as a module, choose M here: the
13890 + module will be called catc.
13891 +
13892 +config USB_KAWETH
13893 + depends on n
13894 + tristate "USB KLSI KL5USB101-based ethernet device support"
13895 + depends on m
13896 + ---help---
13897 + Say Y here if you want to use one of the following 10Mbps only
13898 + USB Ethernet adapters based on the KLSI KL5KUSB101B chipset:
13899 + 3Com 3C19250
13900 + ADS USB-10BT
13901 + ATEN USB Ethernet
13902 + ASANTE USB To Ethernet Adapter
13903 + AOX Endpoints USB Ethernet
13904 + Correga K.K.
13905 + D-Link DSB-650C and DU-E10
13906 + Entrega / Portgear E45
13907 + I-O DATA USB-ET/T
13908 + Jaton USB Ethernet Device Adapter
13909 + Kingston Technology USB Ethernet Adapter
13910 + Linksys USB10T
13911 + Mobility USB-Ethernet Adapter
13912 + NetGear EA-101
13913 + Peracom Enet and Enet2
13914 + Portsmith Express Ethernet Adapter
13915 + Shark Pocket Adapter
13916 + SMC 2202USB
13917 + Sony Vaio port extender
13918 +
13919 + This driver is likely to work with most 10Mbps only USB Ethernet
13920 + adapters, including some "no brand" devices. It does NOT work on
13921 + SmartBridges smartNIC or on Belkin F5U111 devices - you should use
13922 + the CATC NetMate driver for those. If you are not sure which one
13923 + you need, select both, and the correct one should be selected for
13924 + you.
13925 +
13926 + This driver makes the adapter appear as a normal Ethernet interface,
13927 + typically on eth0, if it is the only ethernet device, or perhaps on
13928 + eth1, if you have a PCI or ISA ethernet card installed.
13929 +
13930 + To compile this driver as a module, choose M here: the
13931 + module will be called kaweth.
13932 +
13933 +config USB_PEGASUS
13934 + depends on n
13935 + tristate "USB Pegasus/Pegasus-II based ethernet device support"
13936 + depends on m
13937 + select BPAUTO_MII
13938 + ---help---
13939 + Say Y here if you know you have Pegasus or Pegasus-II based adapter.
13940 + If in doubt then look at <file:drivers/net/usb/pegasus.h> for the
13941 + complete list of supported devices.
13942 +
13943 + If your particular adapter is not in the list and you are _sure_ it
13944 + is Pegasus or Pegasus II based then send me
13945 + <petkan@users.sourceforge.net> vendor and device IDs.
13946 +
13947 + To compile this driver as a module, choose M here: the
13948 + module will be called pegasus.
13949 +
13950 +config USB_RTL8150
13951 + depends on n
13952 + tristate "USB RTL8150 based ethernet device support"
13953 + depends on m
13954 + select BPAUTO_MII
13955 + help
13956 + Say Y here if you have RTL8150 based usb-ethernet adapter.
13957 + Send me <petkan@users.sourceforge.net> any comments you may have.
13958 + You can also check for updates at <http://pegasus2.sourceforge.net/>.
13959 +
13960 + To compile this driver as a module, choose M here: the
13961 + module will be called rtl8150.
13962 +
13963 +config USB_RTL8152
13964 + depends on n
13965 + tristate "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters"
13966 + depends on m
13967 + select BPAUTO_MII
13968 + help
13969 + This option adds support for Realtek RTL8152 based USB 2.0
13970 + 10/100 Ethernet adapters and RTL8153 based USB 3.0 10/100/1000
13971 + Ethernet adapters.
13972 +
13973 + To compile this driver as a module, choose M here: the
13974 + module will be called r8152.
13975 +
13976 +config USB_USBNET
13977 + tristate "Multi-purpose USB Networking Framework"
13978 + depends on m
13979 + select BPAUTO_MII
13980 + ---help---
13981 + This driver supports several kinds of network links over USB,
13982 + with "minidrivers" built around a common network driver core
13983 + that supports deep queues for efficient transfers. (This gives
13984 + better performance with small packets and at high speeds).
13985 +
13986 + The USB host runs "usbnet", and the other end of the link might be:
13987 +
13988 + - Another USB host, when using USB "network" or "data transfer"
13989 + cables. These are often used to network laptops to PCs, like
13990 + "Laplink" parallel cables or some motherboards. These rely
13991 + on specialized chips from many suppliers.
13992 +
13993 + - An intelligent USB gadget, perhaps embedding a Linux system.
13994 + These include PDAs running Linux (iPaq, Yopy, Zaurus, and
13995 + others), and devices that interoperate using the standard
13996 + CDC-Ethernet specification (including many cable modems).
13997 +
13998 + - Network adapter hardware (like those for 10/100 Ethernet) which
13999 + uses this driver framework.
14000 +
14001 + The link will appear with a name like "usb0", when the link is
14002 + a two-node link, or "eth0" for most CDC-Ethernet devices. Those
14003 + two-node links are most easily managed with Ethernet Bridging
14004 + (CONFIG_BRIDGE) instead of routing.
14005 +
14006 + For more information see <http://www.linux-usb.org/usbnet/>.
14007 +
14008 + To compile this driver as a module, choose M here: the
14009 + module will be called usbnet.
14010 +
14011 +config USB_NET_AX8817X
14012 + depends on n
14013 + tristate "ASIX AX88xxx Based USB 2.0 Ethernet Adapters"
14014 + depends on m
14015 + depends on USB_USBNET
14016 + depends on CRC32
14017 + depends on PHYLIB
14018 + default y
14019 + help
14020 + This option adds support for ASIX AX88xxx based USB 2.0
14021 + 10/100 Ethernet adapters.
14022 +
14023 + This driver should work with at least the following devices:
14024 + * Aten UC210T
14025 + * ASIX AX88172
14026 + * Billionton Systems, USB2AR
14027 + * Buffalo LUA-U2-KTX
14028 + * Corega FEther USB2-TX
14029 + * D-Link DUB-E100
14030 + * Hawking UF200
14031 + * Linksys USB200M
14032 + * Netgear FA120
14033 + * Sitecom LN-029
14034 + * Sitecom LN-028
14035 + * Intellinet USB 2.0 Ethernet
14036 + * ST Lab USB 2.0 Ethernet
14037 + * TrendNet TU2-ET100
14038 +
14039 + This driver creates an interface named "ethX", where X depends on
14040 + what other networking devices you have in use.
14041 +
14042 +config USB_NET_AX88179_178A
14043 + depends on n
14044 + tristate "ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet"
14045 + depends on m
14046 + depends on USB_USBNET
14047 + depends on CRC32
14048 + depends on PHYLIB
14049 + default y
14050 + help
14051 + This option adds support for ASIX AX88179 based USB 3.0/2.0
14052 + to Gigabit Ethernet adapters.
14053 +
14054 + This driver should work with at least the following devices:
14055 + * ASIX AX88179
14056 + * ASIX AX88178A
14057 + * Sitcomm LN-032
14058 +
14059 + This driver creates an interface named "ethX", where X depends on
14060 + what other networking devices you have in use.
14061 +
14062 +config USB_NET_CDCETHER
14063 + tristate "CDC Ethernet support (smart devices such as cable modems)"
14064 + depends on m
14065 + depends on USB_USBNET
14066 + default y
14067 + help
14068 + This option supports devices conforming to the Communication Device
14069 + Class (CDC) Ethernet Control Model, a specification that's easy to
14070 + implement in device firmware. The CDC specifications are available
14071 + from <http://www.usb.org/>.
14072 +
14073 + CDC Ethernet is an implementation option for DOCSIS cable modems
14074 + that support USB connectivity, used for non-Microsoft USB hosts.
14075 + The Linux-USB CDC Ethernet Gadget driver is an open implementation.
14076 + This driver should work with at least the following devices:
14077 +
14078 + * Dell Wireless 5530 HSPA
14079 + * Ericsson PipeRider (all variants)
14080 + * Ericsson Mobile Broadband Module (all variants)
14081 + * Motorola (DM100 and SB4100)
14082 + * Broadcom Cable Modem (reference design)
14083 + * Toshiba (PCX1100U and F3507g/F3607gw)
14084 + * ...
14085 +
14086 + This driver creates an interface named "ethX", where X depends on
14087 + what other networking devices you have in use. However, if the
14088 + IEEE 802 "local assignment" bit is set in the address, a "usbX"
14089 + name is used instead.
14090 +
14091 +config USB_NET_CDC_EEM
14092 + depends on n
14093 + tristate "CDC EEM support"
14094 + depends on m
14095 + depends on USB_USBNET
14096 + help
14097 + This option supports devices conforming to the Communication Device
14098 + Class (CDC) Ethernet Emulation Model, a specification that's easy to
14099 + implement in device firmware. The CDC EEM specifications are available
14100 + from <http://www.usb.org/>.
14101 +
14102 + This driver creates an interface named "ethX", where X depends on
14103 + what other networking devices you have in use. However, if the
14104 + IEEE 802 "local assignment" bit is set in the address, a "usbX"
14105 + name is used instead.
14106 +
14107 +config USB_NET_CDC_NCM
14108 + tristate "CDC NCM support"
14109 + depends on m
14110 + depends on USB_USBNET
14111 + default y
14112 + help
14113 + This driver provides support for CDC NCM (Network Control Model
14114 + Device USB Class Specification). The CDC NCM specification is
14115 + available from <http://www.usb.org/>.
14116 +
14117 + Say "y" to link the driver statically, or "m" to build a
14118 + dynamically linked module.
14119 +
14120 + This driver should work with at least the following devices:
14121 + * ST-Ericsson M700 LTE FDD/TDD Mobile Broadband Modem (ref. design)
14122 + * ST-Ericsson M5730 HSPA+ Mobile Broadband Modem (reference design)
14123 + * ST-Ericsson M570 HSPA+ Mobile Broadband Modem (reference design)
14124 + * ST-Ericsson M343 HSPA Mobile Broadband Modem (reference design)
14125 + * Ericsson F5521gw Mobile Broadband Module
14126 +
14127 +config USB_NET_HUAWEI_CDC_NCM
14128 + depends on n
14129 + tristate "Huawei NCM embedded AT channel support"
14130 + depends on m
14131 + depends on USB_USBNET
14132 + select USB_WDM
14133 + select USB_NET_CDC_NCM
14134 + help
14135 + This driver supports huawei-style NCM devices, that use NCM as a
14136 + transport for other protocols, usually an embedded AT channel.
14137 + Good examples are:
14138 + * Huawei E3131
14139 + * Huawei E3251
14140 +
14141 + To compile this driver as a module, choose M here: the module will be
14142 + called huawei_cdc_ncm.ko.
14143 +
14144 +config USB_NET_CDC_MBIM
14145 + tristate "CDC MBIM support"
14146 + depends on m
14147 + depends on USB_USBNET
14148 + select USB_WDM
14149 + select USB_NET_CDC_NCM
14150 + help
14151 + This driver provides support for CDC MBIM (Mobile Broadband
14152 + Interface Model) devices. The CDC MBIM specification is
14153 + available from <http://www.usb.org/>.
14154 +
14155 + MBIM devices require configuration using the management
14156 + protocol defined by the MBIM specification. This driver
14157 + provides unfiltered access to the MBIM control channel
14158 + through the associated /dev/cdc-wdmx character device.
14159 +
14160 + To compile this driver as a module, choose M here: the
14161 + module will be called cdc_mbim.
14162 +
14163 +config USB_NET_DM9601
14164 + depends on n
14165 + tristate "Davicom DM96xx based USB 10/100 ethernet devices"
14166 + depends on m
14167 + depends on USB_USBNET
14168 + depends on CRC32
14169 + help
14170 + This option adds support for Davicom DM9601/DM9620/DM9621A
14171 + based USB 10/100 Ethernet adapters.
14172 +
14173 +config USB_NET_SR9700
14174 + depends on n
14175 + tristate "CoreChip-sz SR9700 based USB 1.1 10/100 ethernet devices"
14176 + depends on m
14177 + depends on USB_USBNET
14178 + depends on CRC32
14179 + help
14180 + This option adds support for CoreChip-sz SR9700 based USB 1.1
14181 + 10/100 Ethernet adapters.
14182 +
14183 +config USB_NET_SR9800
14184 + depends on n
14185 + tristate "CoreChip-sz SR9800 based USB 2.0 10/100 ethernet devices"
14186 + depends on m
14187 + depends on USB_USBNET
14188 + depends on CRC32
14189 + ---help---
14190 + Say Y if you want to use one of the following 100Mbps USB Ethernet
14191 + device based on the CoreChip-sz SR9800 chip.
14192 +
14193 + This driver makes the adapter appear as a normal Ethernet interface,
14194 + typically on eth0, if it is the only ethernet device, or perhaps on
14195 + eth1, if you have a PCI or ISA ethernet card installed.
14196 +
14197 + To compile this driver as a module, choose M here: the
14198 + module will be called sr9800.
14199 +
14200 +config USB_NET_SMSC75XX
14201 + depends on n
14202 + tristate "SMSC LAN75XX based USB 2.0 gigabit ethernet devices"
14203 + depends on m
14204 + depends on USB_USBNET
14205 + depends on BITREVERSE
14206 + depends on CRC16
14207 + depends on CRC32
14208 + help
14209 + This option adds support for SMSC LAN75XX based USB 2.0
14210 + Gigabit Ethernet adapters.
14211 +
14212 +config USB_NET_SMSC95XX
14213 + depends on n
14214 + tristate "SMSC LAN95XX based USB 2.0 10/100 ethernet devices"
14215 + depends on m
14216 + depends on USB_USBNET
14217 + depends on BITREVERSE
14218 + depends on CRC16
14219 + depends on CRC32
14220 + help
14221 + This option adds support for SMSC LAN95XX based USB 2.0
14222 + 10/100 Ethernet adapters.
14223 +
14224 +config USB_NET_GL620A
14225 + depends on n
14226 + tristate "GeneSys GL620USB-A based cables"
14227 + depends on m
14228 + depends on USB_USBNET
14229 + help
14230 + Choose this option if you're using a host-to-host cable,
14231 + or PC2PC motherboard, with this chip.
14232 +
14233 + Note that the half-duplex "GL620USB" is not supported.
14234 +
14235 +config USB_NET_NET1080
14236 + depends on n
14237 + tristate "NetChip 1080 based cables (Laplink, ...)"
14238 + depends on m
14239 + default y
14240 + depends on USB_USBNET
14241 + help
14242 + Choose this option if you're using a host-to-host cable based
14243 + on this design: one NetChip 1080 chip and supporting logic,
14244 + optionally with LEDs that indicate traffic
14245 +
14246 +config USB_NET_PLUSB
14247 + depends on n
14248 + tristate "Prolific PL-2301/2302/25A1 based cables"
14249 + depends on m
14250 + # if the handshake/init/reset problems, from original 'plusb',
14251 + # are ever resolved ... then remove "experimental"
14252 + depends on USB_USBNET
14253 + help
14254 + Choose this option if you're using a host-to-host cable
14255 + with one of these chips.
14256 +
14257 +config USB_NET_MCS7830
14258 + depends on n
14259 + tristate "MosChip MCS7830 based Ethernet adapters"
14260 + depends on m
14261 + depends on USB_USBNET
14262 + help
14263 + Choose this option if you're using a 10/100 Ethernet USB2
14264 + adapter based on the MosChip 7830 controller. This includes
14265 + adapters marketed under the DeLOCK brand.
14266 +
14267 +config USB_NET_RNDIS_HOST
14268 + tristate "Host for RNDIS and ActiveSync devices"
14269 + depends on m
14270 + depends on USB_USBNET
14271 + select USB_NET_CDCETHER
14272 + help
14273 + This option enables hosting "Remote NDIS" USB networking links,
14274 + as encouraged by Microsoft (instead of CDC Ethernet!) for use in
14275 + various devices that may only support this protocol. A variant
14276 + of this protocol (with even less public documentation) seems to
14277 + be at the root of Microsoft's "ActiveSync" too.
14278 +
14279 + Avoid using this protocol unless you have no better options.
14280 + The protocol specification is incomplete, and is controlled by
14281 + (and for) Microsoft; it isn't an "Open" ecosystem or market.
14282 +
14283 +config USB_NET_CDC_SUBSET
14284 + depends on n
14285 + tristate "Simple USB Network Links (CDC Ethernet subset)"
14286 + depends on m
14287 + depends on USB_USBNET
14288 + default y
14289 + help
14290 + This driver module supports USB network devices that can work
14291 + without any device-specific information. Select it if you have
14292 + one of these drivers.
14293 +
14294 + Note that while many USB host-to-host cables can work in this mode,
14295 + that may mean not being able to talk to Win32 systems or more
14296 + commonly not being able to handle certain events (like replugging
14297 + the host on the other end) very well. Also, these devices will
14298 + not generally have permanently assigned Ethernet addresses.
14299 +
14300 +config USB_ALI_M5632
14301 + bool "ALi M5632 based 'USB 2.0 Data Link' cables"
14302 + depends on USB_NET_CDC_SUBSET
14303 + help
14304 + Choose this option if you're using a host-to-host cable
14305 + based on this design, which supports USB 2.0 high speed.
14306 +
14307 +config USB_AN2720
14308 + bool "AnchorChips 2720 based cables (Xircom PGUNET, ...)"
14309 + depends on USB_NET_CDC_SUBSET
14310 + help
14311 + Choose this option if you're using a host-to-host cable
14312 + based on this design. Note that AnchorChips is now a
14313 + Cypress brand.
14314 +
14315 +config USB_BELKIN
14316 + bool "eTEK based host-to-host cables (Advance, Belkin, ...)"
14317 + depends on USB_NET_CDC_SUBSET
14318 + default y
14319 + help
14320 + Choose this option if you're using a host-to-host cable
14321 + based on this design: two NetChip 2890 chips and an Atmel
14322 + microcontroller, with LEDs that indicate traffic.
14323 +
14324 +config USB_ARMLINUX
14325 + bool "Embedded ARM Linux links (iPaq, ...)"
14326 + depends on USB_NET_CDC_SUBSET
14327 + default y
14328 + help
14329 + Choose this option to support the "usb-eth" networking driver
14330 + used by most of the ARM Linux community with device controllers
14331 + such as the SA-11x0 and PXA-25x UDCs, or the tftp capabilities
14332 + in some PXA versions of the "blob" boot loader.
14333 +
14334 + Linux-based "Gumstix" PXA-25x based systems use this protocol
14335 + to talk with other Linux systems.
14336 +
14337 + Although the ROMs shipped with Sharp Zaurus products use a
14338 + different link level framing protocol, you can have them use
14339 + this simpler protocol by installing a different kernel.
14340 +
14341 +config USB_EPSON2888
14342 + bool "Epson 2888 based firmware (DEVELOPMENT)"
14343 + depends on USB_NET_CDC_SUBSET
14344 + help
14345 + Choose this option to support the usb networking links used
14346 + by some sample firmware from Epson.
14347 +
14348 +config USB_KC2190
14349 + bool "KT Technology KC2190 based cables (InstaNet)"
14350 + depends on USB_NET_CDC_SUBSET
14351 + help
14352 + Choose this option if you're using a host-to-host cable
14353 + with one of these chips.
14354 +
14355 +config USB_NET_ZAURUS
14356 + depends on n
14357 + tristate "Sharp Zaurus (stock ROMs) and compatible"
14358 + depends on m
14359 + depends on USB_USBNET
14360 + select USB_NET_CDCETHER
14361 + depends on CRC32
14362 + default y
14363 + help
14364 + Choose this option to support the usb networking links used by
14365 + Zaurus models like the SL-5000D, SL-5500, SL-5600, A-300, B-500.
14366 + This also supports some related device firmware, as used in some
14367 + PDAs from Olympus and some cell phones from Motorola.
14368 +
14369 + If you install an alternate image, such as the Linux 2.6 based
14370 + versions of OpenZaurus, you should no longer need to support this
14371 + protocol. Only the "eth-fd" or "net_fd" drivers in these devices
14372 + really need this non-conformant variant of CDC Ethernet (or in
14373 + some cases CDC MDLM) protocol, not "g_ether".
14374 +
14375 +config USB_NET_CX82310_ETH
14376 + depends on n
14377 + tristate "Conexant CX82310 USB ethernet port"
14378 + depends on m
14379 + depends on USB_USBNET
14380 + help
14381 + Choose this option if you're using a Conexant CX82310-based ADSL
14382 + router with USB ethernet port. This driver is for routers only,
14383 + it will not work with ADSL modems (use cxacru driver instead).
14384 +
14385 +config USB_NET_KALMIA
14386 + depends on n
14387 + tristate "Samsung Kalmia based LTE USB modem"
14388 + depends on m
14389 + depends on USB_USBNET
14390 + help
14391 + Choose this option if you have a Samsung Kalmia based USB modem
14392 + as Samsung GT-B3730.
14393 +
14394 + To compile this driver as a module, choose M here: the
14395 + module will be called kalmia.
14396 +
14397 +config USB_NET_QMI_WWAN
14398 + tristate "QMI WWAN driver for Qualcomm MSM based 3G and LTE modems"
14399 + depends on m
14400 + depends on USB_USBNET
14401 + select USB_WDM
14402 + help
14403 + Support WWAN LTE/3G devices based on Qualcomm Mobile Data Modem
14404 + (MDM) chipsets. Examples of such devices are
14405 + * Huawei E392/E398
14406 +
14407 + This driver will only drive the ethernet part of the chips.
14408 + The devices require additional configuration to be usable.
14409 + Multiple management interfaces with linux drivers are
14410 + available:
14411 +
14412 + * option: AT commands on /dev/ttyUSBx
14413 + * cdc-wdm: Qualcomm MSM Interface (QMI) protocol on /dev/cdc-wdmx
14414 +
14415 + A modem manager with support for QMI is recommended.
14416 +
14417 + To compile this driver as a module, choose M here: the
14418 + module will be called qmi_wwan.
14419 +
14420 +config USB_HSO
14421 + depends on n
14422 + tristate "Option USB High Speed Mobile Devices"
14423 + depends on m
14424 + depends on USB && RFKILL && TTY
14425 + default n
14426 + help
14427 + Choose this option if you have an Option HSDPA/HSUPA card.
14428 + These cards support downlink speeds of 7.2Mbps or greater.
14429 +
14430 + To compile this driver as a module, choose M here: the
14431 + module will be called hso.
14432 +
14433 +config USB_NET_INT51X1
14434 + depends on n
14435 + tristate "Intellon PLC based usb adapter"
14436 + depends on m
14437 + depends on USB_USBNET
14438 + help
14439 + Choose this option if you're using a 14Mb USB-based PLC
14440 + (Powerline Communications) solution with an Intellon
14441 + INT51x1/INT5200 chip, like the "devolo dLan duo".
14442 +
14443 +config USB_CDC_PHONET
14444 + depends on n
14445 + tristate "CDC Phonet support"
14446 + depends on m
14447 + depends on PHONET
14448 + help
14449 + Choose this option to support the Phonet interface to a Nokia
14450 + cellular modem, as found on most Nokia handsets with the
14451 + "PC suite" USB profile.
14452 +
14453 +config USB_IPHETH
14454 + depends on n
14455 + tristate "Apple iPhone USB Ethernet driver"
14456 + depends on m
14457 + default n
14458 + ---help---
14459 + Module used to share Internet connection (tethering) from your
14460 + iPhone (Original, 3G and 3GS) to your system.
14461 + Note that you need userspace libraries and programs that are needed
14462 + to pair your device with your system and that understand the iPhone
14463 + protocol.
14464 +
14465 + For more information: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
14466 +
14467 +config USB_SIERRA_NET
14468 + tristate "USB-to-WWAN Driver for Sierra Wireless modems"
14469 + depends on m
14470 + depends on USB_USBNET
14471 + help
14472 + Choose this option if you have a Sierra Wireless USB-to-WWAN device.
14473 +
14474 + To compile this driver as a module, choose M here: the
14475 + module will be called sierra_net.
14476 +
14477 +config USB_VL600
14478 + depends on n
14479 + tristate "LG VL600 modem dongle"
14480 + depends on m
14481 + depends on USB_NET_CDCETHER && TTY
14482 + select USB_ACM
14483 + help
14484 + Select this if you want to use an LG Electronics 4G/LTE usb modem
14485 + called VL600. This driver only handles the ethernet
14486 + interface exposed by the modem firmware. To establish a connection
14487 + you will first need a userspace program that sends the right
14488 + command to the modem through its CDC ACM port, and most
14489 + likely also a DHCP client. See this thread about using the
14490 + 4G modem from Verizon:
14491 +
14492 + http://ubuntuforums.org/showpost.php?p=10589647&postcount=17
14493 +
14494 +endif # USB_NET_DRIVERS
14495 diff -Naur backports-4.2.6-1.org/drivers/net/usb/lg-vl600.c backports-4.2.6-1/drivers/net/usb/lg-vl600.c
14496 --- backports-4.2.6-1.org/drivers/net/usb/lg-vl600.c 1970-01-01 01:00:00.000000000 +0100
14497 +++ backports-4.2.6-1/drivers/net/usb/lg-vl600.c 2016-06-28 14:35:17.991973886 +0200
14498 @@ -0,0 +1,353 @@
14499 +/*
14500 + * Ethernet interface part of the LG VL600 LTE modem (4G dongle)
14501 + *
14502 + * Copyright (C) 2011 Intel Corporation
14503 + * Author: Andrzej Zaborowski <balrogg@gmail.com>
14504 + *
14505 + * This program is free software; you can redistribute it and/or modify
14506 + * it under the terms of the GNU General Public License as published by
14507 + * the Free Software Foundation; either version 2 of the License, or
14508 + * (at your option) any later version.
14509 + *
14510 + * This program is distributed in the hope that it will be useful,
14511 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14512 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14513 + * GNU General Public License for more details.
14514 + *
14515 + * You should have received a copy of the GNU General Public License
14516 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
14517 + */
14518 +#include <linux/etherdevice.h>
14519 +#include <linux/ethtool.h>
14520 +#include <linux/mii.h>
14521 +#include <linux/usb.h>
14522 +#include <linux/usb/cdc.h>
14523 +#include <linux/usb/usbnet.h>
14524 +#include <linux/if_ether.h>
14525 +#include <linux/if_arp.h>
14526 +#include <linux/inetdevice.h>
14527 +#include <linux/module.h>
14528 +
14529 +/*
14530 + * The device has a CDC ACM port for modem control (it claims to be
14531 + * CDC ACM anyway) and a CDC Ethernet port for actual network data.
14532 + * It will however ignore data on both ports that is not encapsulated
14533 + * in a specific way, any data returned is also encapsulated the same
14534 + * way. The headers don't seem to follow any popular standard.
14535 + *
14536 + * This driver adds and strips these headers from the ethernet frames
14537 + * sent/received from the CDC Ethernet port. The proprietary header
14538 + * replaces the standard ethernet header in a packet so only actual
14539 + * ethernet frames are allowed. The headers allow some form of
14540 + * multiplexing by using non standard values of the .h_proto field.
14541 + * Windows/Mac drivers do send a couple of such frames to the device
14542 + * during initialisation, with protocol set to 0x0906 or 0x0b06 and (what
14543 + * seems to be) a flag in the .dummy_flags. This doesn't seem necessary
14544 + * for modem operation but can possibly be used for GPS or other funcitons.
14545 + */
14546 +
14547 +struct vl600_frame_hdr {
14548 + __le32 len;
14549 + __le32 serial;
14550 + __le32 pkt_cnt;
14551 + __le32 dummy_flags;
14552 + __le32 dummy;
14553 + __le32 magic;
14554 +} __attribute__((packed));
14555 +
14556 +struct vl600_pkt_hdr {
14557 + __le32 dummy[2];
14558 + __le32 len;
14559 + __be16 h_proto;
14560 +} __attribute__((packed));
14561 +
14562 +struct vl600_state {
14563 + struct sk_buff *current_rx_buf;
14564 +};
14565 +
14566 +static int vl600_bind(struct usbnet *dev, struct usb_interface *intf)
14567 +{
14568 + int ret;
14569 + struct vl600_state *s = kzalloc(sizeof(struct vl600_state), GFP_KERNEL);
14570 +
14571 + if (!s)
14572 + return -ENOMEM;
14573 +
14574 + ret = usbnet_cdc_bind(dev, intf);
14575 + if (ret) {
14576 + kfree(s);
14577 + return ret;
14578 + }
14579 +
14580 + dev->driver_priv = s;
14581 +
14582 + /* ARP packets don't go through, but they're also of no use. The
14583 + * subnet has only two hosts anyway: us and the gateway / DHCP
14584 + * server (probably simulated by modem firmware or network operator)
14585 + * whose address changes everytime we connect to the intarwebz and
14586 + * who doesn't bother answering ARP requests either. So hardware
14587 + * addresses have no meaning, the destination and the source of every
14588 + * packet depend only on whether it is on the IN or OUT endpoint. */
14589 + dev->net->flags |= IFF_NOARP;
14590 + /* IPv6 NDP relies on multicast. Enable it by default. */
14591 + dev->net->flags |= IFF_MULTICAST;
14592 +
14593 + return ret;
14594 +}
14595 +
14596 +static void vl600_unbind(struct usbnet *dev, struct usb_interface *intf)
14597 +{
14598 + struct vl600_state *s = dev->driver_priv;
14599 +
14600 + if (s->current_rx_buf)
14601 + dev_kfree_skb(s->current_rx_buf);
14602 +
14603 + kfree(s);
14604 +
14605 + return usbnet_cdc_unbind(dev, intf);
14606 +}
14607 +
14608 +static int vl600_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
14609 +{
14610 + struct vl600_frame_hdr *frame;
14611 + struct vl600_pkt_hdr *packet;
14612 + struct ethhdr *ethhdr;
14613 + int packet_len, count;
14614 + struct sk_buff *buf = skb;
14615 + struct sk_buff *clone;
14616 + struct vl600_state *s = dev->driver_priv;
14617 +
14618 + /* Frame lengths are generally 4B multiplies but every couple of
14619 + * hours there's an odd number of bytes sized yet correct frame,
14620 + * so don't require this. */
14621 +
14622 + /* Allow a packet (or multiple packets batched together) to be
14623 + * split across many frames. We don't allow a new batch to
14624 + * begin in the same frame another one is ending however, and no
14625 + * leading or trailing pad bytes. */
14626 + if (s->current_rx_buf) {
14627 + frame = (struct vl600_frame_hdr *) s->current_rx_buf->data;
14628 + if (skb->len + s->current_rx_buf->len >
14629 + le32_to_cpup(&frame->len)) {
14630 + netif_err(dev, ifup, dev->net, "Fragment too long\n");
14631 + dev->net->stats.rx_length_errors++;
14632 + goto error;
14633 + }
14634 +
14635 + buf = s->current_rx_buf;
14636 + memcpy(skb_put(buf, skb->len), skb->data, skb->len);
14637 + } else if (skb->len < 4) {
14638 + netif_err(dev, ifup, dev->net, "Frame too short\n");
14639 + dev->net->stats.rx_length_errors++;
14640 + goto error;
14641 + }
14642 +
14643 + frame = (struct vl600_frame_hdr *) buf->data;
14644 + /* Yes, check that frame->magic == 0x53544448 (or 0x44544d48),
14645 + * otherwise we may run out of memory w/a bad packet */
14646 + if (ntohl(frame->magic) != 0x53544448 &&
14647 + ntohl(frame->magic) != 0x44544d48)
14648 + goto error;
14649 +
14650 + if (buf->len < sizeof(*frame) ||
14651 + buf->len != le32_to_cpup(&frame->len)) {
14652 + /* Save this fragment for later assembly */
14653 + if (s->current_rx_buf)
14654 + return 0;
14655 +
14656 + s->current_rx_buf = skb_copy_expand(skb, 0,
14657 + le32_to_cpup(&frame->len), GFP_ATOMIC);
14658 + if (!s->current_rx_buf) {
14659 + netif_err(dev, ifup, dev->net, "Reserving %i bytes "
14660 + "for packet assembly failed.\n",
14661 + le32_to_cpup(&frame->len));
14662 + dev->net->stats.rx_errors++;
14663 + }
14664 +
14665 + return 0;
14666 + }
14667 +
14668 + count = le32_to_cpup(&frame->pkt_cnt);
14669 +
14670 + skb_pull(buf, sizeof(*frame));
14671 +
14672 + while (count--) {
14673 + if (buf->len < sizeof(*packet)) {
14674 + netif_err(dev, ifup, dev->net, "Packet too short\n");
14675 + goto error;
14676 + }
14677 +
14678 + packet = (struct vl600_pkt_hdr *) buf->data;
14679 + packet_len = sizeof(*packet) + le32_to_cpup(&packet->len);
14680 + if (packet_len > buf->len) {
14681 + netif_err(dev, ifup, dev->net,
14682 + "Bad packet length stored in header\n");
14683 + goto error;
14684 + }
14685 +
14686 + /* Packet header is same size as the ethernet header
14687 + * (sizeof(*packet) == sizeof(*ethhdr)), additionally
14688 + * the h_proto field is in the same place so we just leave it
14689 + * alone and fill in the remaining fields.
14690 + */
14691 + ethhdr = (struct ethhdr *) skb->data;
14692 + if (be16_to_cpup(&ethhdr->h_proto) == ETH_P_ARP &&
14693 + buf->len > 0x26) {
14694 + /* Copy the addresses from packet contents */
14695 + memcpy(ethhdr->h_source,
14696 + &buf->data[sizeof(*ethhdr) + 0x8],
14697 + ETH_ALEN);
14698 + memcpy(ethhdr->h_dest,
14699 + &buf->data[sizeof(*ethhdr) + 0x12],
14700 + ETH_ALEN);
14701 + } else {
14702 + eth_zero_addr(ethhdr->h_source);
14703 + memcpy(ethhdr->h_dest, dev->net->dev_addr, ETH_ALEN);
14704 +
14705 + /* Inbound IPv6 packets have an IPv4 ethertype (0x800)
14706 + * for some reason. Peek at the L3 header to check
14707 + * for IPv6 packets, and set the ethertype to IPv6
14708 + * (0x86dd) so Linux can understand it.
14709 + */
14710 + if ((buf->data[sizeof(*ethhdr)] & 0xf0) == 0x60)
14711 + ethhdr->h_proto = htons(ETH_P_IPV6);
14712 + }
14713 +
14714 + if (count) {
14715 + /* Not the last packet in this batch */
14716 + clone = skb_clone(buf, GFP_ATOMIC);
14717 + if (!clone)
14718 + goto error;
14719 +
14720 + skb_trim(clone, packet_len);
14721 + usbnet_skb_return(dev, clone);
14722 +
14723 + skb_pull(buf, (packet_len + 3) & ~3);
14724 + } else {
14725 + skb_trim(buf, packet_len);
14726 +
14727 + if (s->current_rx_buf) {
14728 + usbnet_skb_return(dev, buf);
14729 + s->current_rx_buf = NULL;
14730 + return 0;
14731 + }
14732 +
14733 + return 1;
14734 + }
14735 + }
14736 +
14737 +error:
14738 + if (s->current_rx_buf) {
14739 + dev_kfree_skb_any(s->current_rx_buf);
14740 + s->current_rx_buf = NULL;
14741 + }
14742 + dev->net->stats.rx_errors++;
14743 + return 0;
14744 +}
14745 +
14746 +static struct sk_buff *vl600_tx_fixup(struct usbnet *dev,
14747 + struct sk_buff *skb, gfp_t flags)
14748 +{
14749 + struct sk_buff *ret;
14750 + struct vl600_frame_hdr *frame;
14751 + struct vl600_pkt_hdr *packet;
14752 + static uint32_t serial = 1;
14753 + int orig_len = skb->len - sizeof(struct ethhdr);
14754 + int full_len = (skb->len + sizeof(struct vl600_frame_hdr) + 3) & ~3;
14755 +
14756 + frame = (struct vl600_frame_hdr *) skb->data;
14757 + if (skb->len > sizeof(*frame) && skb->len == le32_to_cpup(&frame->len))
14758 + return skb; /* Already encapsulated? */
14759 +
14760 + if (skb->len < sizeof(struct ethhdr))
14761 + /* Drop, device can only deal with ethernet packets */
14762 + return NULL;
14763 +
14764 + if (!skb_cloned(skb)) {
14765 + int headroom = skb_headroom(skb);
14766 + int tailroom = skb_tailroom(skb);
14767 +
14768 + if (tailroom >= full_len - skb->len - sizeof(*frame) &&
14769 + headroom >= sizeof(*frame))
14770 + /* There's enough head and tail room */
14771 + goto encapsulate;
14772 +
14773 + if (headroom + tailroom + skb->len >= full_len) {
14774 + /* There's enough total room, just readjust */
14775 + skb->data = memmove(skb->head + sizeof(*frame),
14776 + skb->data, skb->len);
14777 + skb_set_tail_pointer(skb, skb->len);
14778 + goto encapsulate;
14779 + }
14780 + }
14781 +
14782 + /* Alloc a new skb with the required size */
14783 + ret = skb_copy_expand(skb, sizeof(struct vl600_frame_hdr), full_len -
14784 + skb->len - sizeof(struct vl600_frame_hdr), flags);
14785 + dev_kfree_skb_any(skb);
14786 + if (!ret)
14787 + return ret;
14788 + skb = ret;
14789 +
14790 +encapsulate:
14791 + /* Packet header is same size as ethernet packet header
14792 + * (sizeof(*packet) == sizeof(struct ethhdr)), additionally the
14793 + * h_proto field is in the same place so we just leave it alone and
14794 + * overwrite the remaining fields.
14795 + */
14796 + packet = (struct vl600_pkt_hdr *) skb->data;
14797 + /* The VL600 wants IPv6 packets to have an IPv4 ethertype
14798 + * Since this modem only supports IPv4 and IPv6, just set all
14799 + * frames to 0x0800 (ETH_P_IP)
14800 + */
14801 + packet->h_proto = htons(ETH_P_IP);
14802 + memset(&packet->dummy, 0, sizeof(packet->dummy));
14803 + packet->len = cpu_to_le32(orig_len);
14804 +
14805 + frame = (struct vl600_frame_hdr *) skb_push(skb, sizeof(*frame));
14806 + memset(frame, 0, sizeof(*frame));
14807 + frame->len = cpu_to_le32(full_len);
14808 + frame->serial = cpu_to_le32(serial++);
14809 + frame->pkt_cnt = cpu_to_le32(1);
14810 +
14811 + if (skb->len < full_len) /* Pad */
14812 + skb_put(skb, full_len - skb->len);
14813 +
14814 + return skb;
14815 +}
14816 +
14817 +static const struct driver_info vl600_info = {
14818 + .description = "LG VL600 modem",
14819 + .flags = FLAG_RX_ASSEMBLE | FLAG_WWAN,
14820 + .bind = vl600_bind,
14821 + .unbind = vl600_unbind,
14822 + .status = usbnet_cdc_status,
14823 + .rx_fixup = vl600_rx_fixup,
14824 + .tx_fixup = vl600_tx_fixup,
14825 +};
14826 +
14827 +static const struct usb_device_id products[] = {
14828 + {
14829 + USB_DEVICE_AND_INTERFACE_INFO(0x1004, 0x61aa, USB_CLASS_COMM,
14830 + USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
14831 + .driver_info = (unsigned long) &vl600_info,
14832 + },
14833 + {}, /* End */
14834 +};
14835 +MODULE_DEVICE_TABLE(usb, products);
14836 +
14837 +static struct usb_driver lg_vl600_driver = {
14838 + .name = "lg-vl600",
14839 + .id_table = products,
14840 + .probe = usbnet_probe,
14841 + .disconnect = usbnet_disconnect,
14842 + .suspend = usbnet_suspend,
14843 + .resume = usbnet_resume,
14844 + .disable_hub_initiated_lpm = 1,
14845 +};
14846 +
14847 +module_usb_driver(lg_vl600_driver);
14848 +
14849 +MODULE_AUTHOR("Anrzej Zaborowski");
14850 +MODULE_DESCRIPTION("LG-VL600 modem's ethernet link");
14851 +MODULE_LICENSE("GPL");
14852 diff -Naur backports-4.2.6-1.org/drivers/net/usb/Makefile backports-4.2.6-1/drivers/net/usb/Makefile
14853 --- backports-4.2.6-1.org/drivers/net/usb/Makefile 2015-11-15 22:19:40.000000000 +0100
14854 +++ backports-4.2.6-1/drivers/net/usb/Makefile 2016-06-28 14:35:17.991973886 +0200
14855 @@ -1,39 +1,40 @@
14856 #
14857 # Makefile for USB Network drivers
14858 #
14859 -#
14860 -#obj-$(CPTCFG_USB_CATC) += catc.o
14861 -#obj-$(CPTCFG_USB_KAWETH) += kaweth.o
14862 -#obj-$(CPTCFG_USB_PEGASUS) += pegasus.o
14863 -#obj-$(CPTCFG_USB_RTL8150) += rtl8150.o
14864 -#obj-$(CPTCFG_USB_RTL8152) += r8152.o
14865 -#obj-$(CPTCFG_USB_HSO) += hso.o
14866 -#obj-$(CPTCFG_USB_NET_AX8817X) += asix.o
14867 -#obj-$(CPTCFG_USB_NET_AX88179_178A) += ax88179_178a.o
14868 +
14869 +obj-$(CPTCFG_USB_CATC) += catc.o
14870 +obj-$(CPTCFG_USB_KAWETH) += kaweth.o
14871 +obj-$(CPTCFG_USB_PEGASUS) += pegasus.o
14872 +obj-$(CPTCFG_USB_RTL8150) += rtl8150.o
14873 +obj-$(CPTCFG_USB_RTL8152) += r8152.o
14874 +obj-$(CPTCFG_USB_HSO) += hso.o
14875 +obj-$(CPTCFG_USB_NET_AX8817X) += asix.o
14876 +asix-y := asix_devices.o asix_common.o ax88172a.o
14877 +obj-$(CPTCFG_USB_NET_AX88179_178A) += ax88179_178a.o
14878 obj-$(CPTCFG_USB_NET_CDCETHER) += cdc_ether.o
14879 -#obj-$(CPTCFG_USB_NET_CDC_EEM) += cdc_eem.o
14880 -#obj-$(CPTCFG_USB_NET_DM9601) += dm9601.o
14881 -#obj-$(CPTCFG_USB_NET_SR9700) += sr9700.o
14882 -#obj-$(CPTCFG_USB_NET_SR9800) += sr9800.o
14883 -#obj-$(CPTCFG_USB_NET_SMSC75XX) += smsc75xx.o
14884 -#obj-$(CPTCFG_USB_NET_SMSC95XX) += smsc95xx.o
14885 -#obj-$(CPTCFG_USB_NET_GL620A) += gl620a.o
14886 -#obj-$(CPTCFG_USB_NET_NET1080) += net1080.o
14887 -#obj-$(CPTCFG_USB_NET_PLUSB) += plusb.o
14888 +obj-$(CPTCFG_USB_NET_CDC_EEM) += cdc_eem.o
14889 +obj-$(CPTCFG_USB_NET_DM9601) += dm9601.o
14890 +obj-$(CPTCFG_USB_NET_SR9700) += sr9700.o
14891 +obj-$(CPTCFG_USB_NET_SR9800) += sr9800.o
14892 +obj-$(CPTCFG_USB_NET_SMSC75XX) += smsc75xx.o
14893 +obj-$(CPTCFG_USB_NET_SMSC95XX) += smsc95xx.o
14894 +obj-$(CPTCFG_USB_NET_GL620A) += gl620a.o
14895 +obj-$(CPTCFG_USB_NET_NET1080) += net1080.o
14896 +obj-$(CPTCFG_USB_NET_PLUSB) += plusb.o
14897 obj-$(CPTCFG_USB_NET_RNDIS_HOST) += rndis_host.o
14898 -#obj-$(CPTCFG_USB_NET_CDC_SUBSET) += cdc_subset.o
14899 -#obj-$(CPTCFG_USB_NET_ZAURUS) += zaurus.o
14900 -#obj-$(CPTCFG_USB_NET_MCS7830) += mcs7830.o
14901 +obj-$(CPTCFG_USB_NET_CDC_SUBSET) += cdc_subset.o
14902 +obj-$(CPTCFG_USB_NET_ZAURUS) += zaurus.o
14903 +obj-$(CPTCFG_USB_NET_MCS7830) += mcs7830.o
14904 obj-$(CPTCFG_USB_USBNET) += usbnet.o
14905 -#obj-$(CPTCFG_USB_NET_INT51X1) += int51x1.o
14906 -#obj-$(CPTCFG_USB_CDC_PHONET) += cdc-phonet.o
14907 -#obj-$(CPTCFG_USB_NET_KALMIA) += kalmia.o
14908 -#obj-$(CPTCFG_USB_IPHETH) += ipheth.o
14909 +obj-$(CPTCFG_USB_NET_INT51X1) += int51x1.o
14910 +obj-$(CPTCFG_USB_CDC_PHONET) += cdc-phonet.o
14911 +obj-$(CPTCFG_USB_NET_KALMIA) += kalmia.o
14912 +obj-$(CPTCFG_USB_IPHETH) += ipheth.o
14913 obj-$(CPTCFG_USB_SIERRA_NET) += sierra_net.o
14914 -#obj-$(CPTCFG_USB_NET_CX82310_ETH) += cx82310_eth.o
14915 +obj-$(CPTCFG_USB_NET_CX82310_ETH) += cx82310_eth.o
14916 obj-$(CPTCFG_USB_NET_CDC_NCM) += cdc_ncm.o
14917 -#obj-$(CPTCFG_USB_NET_HUAWEI_CDC_NCM) += huawei_cdc_ncm.o
14918 -#obj-$(CPTCFG_USB_VL600) += lg-vl600.o
14919 +obj-$(CPTCFG_USB_NET_HUAWEI_CDC_NCM) += huawei_cdc_ncm.o
14920 +obj-$(CPTCFG_USB_VL600) += lg-vl600.o
14921 obj-$(CPTCFG_USB_NET_QMI_WWAN) += qmi_wwan.o
14922 obj-$(CPTCFG_USB_NET_CDC_MBIM) += cdc_mbim.o
14923
14924 diff -Naur backports-4.2.6-1.org/drivers/net/usb/mcs7830.c backports-4.2.6-1/drivers/net/usb/mcs7830.c
14925 --- backports-4.2.6-1.org/drivers/net/usb/mcs7830.c 1970-01-01 01:00:00.000000000 +0100
14926 +++ backports-4.2.6-1/drivers/net/usb/mcs7830.c 2016-06-28 14:35:17.995307218 +0200
14927 @@ -0,0 +1,643 @@
14928 +/*
14929 + * MOSCHIP MCS7830 based (7730/7830/7832) USB 2.0 Ethernet Devices
14930 + *
14931 + * based on usbnet.c, asix.c and the vendor provided mcs7830 driver
14932 + *
14933 + * Copyright (C) 2010 Andreas Mohr <andi@lisas.de>
14934 + * Copyright (C) 2006 Arnd Bergmann <arnd@arndb.de>
14935 + * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
14936 + * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
14937 + * Copyright (c) 2002-2003 TiVo Inc.
14938 + *
14939 + * Definitions gathered from MOSCHIP, Data Sheet_7830DA.pdf (thanks!).
14940 + *
14941 + * 2010-12-19: add 7832 USB PID ("functionality same as MCS7830"),
14942 + * per active notification by manufacturer
14943 + *
14944 + * TODO:
14945 + * - support HIF_REG_CONFIG_SLEEPMODE/HIF_REG_CONFIG_TXENABLE (via autopm?)
14946 + * - implement ethtool_ops get_pauseparam/set_pauseparam
14947 + * via HIF_REG_PAUSE_THRESHOLD (>= revision C only!)
14948 + * - implement get_eeprom/[set_eeprom]
14949 + * - switch PHY on/off on ifup/ifdown (perhaps in usbnet.c, via MII)
14950 + * - mcs7830_get_regs() handling is weird: for rev 2 we return 32 regs,
14951 + * can access only ~ 24, remaining user buffer is uninitialized garbage
14952 + * - anything else?
14953 + *
14954 + *
14955 + * This program is free software; you can redistribute it and/or modify
14956 + * it under the terms of the GNU General Public License as published by
14957 + * the Free Software Foundation; either version 2 of the License, or
14958 + * (at your option) any later version.
14959 + *
14960 + * This program is distributed in the hope that it will be useful,
14961 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14962 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14963 + * GNU General Public License for more details.
14964 + *
14965 + * You should have received a copy of the GNU General Public License
14966 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
14967 + */
14968 +
14969 +#include <linux/crc32.h>
14970 +#include <linux/etherdevice.h>
14971 +#include <linux/ethtool.h>
14972 +#include <linux/mii.h>
14973 +#include <linux/module.h>
14974 +#include <linux/netdevice.h>
14975 +#include <linux/slab.h>
14976 +#include <linux/usb.h>
14977 +#include <linux/usb/usbnet.h>
14978 +
14979 +/* requests */
14980 +#define MCS7830_RD_BMREQ (USB_DIR_IN | USB_TYPE_VENDOR | \
14981 + USB_RECIP_DEVICE)
14982 +#define MCS7830_WR_BMREQ (USB_DIR_OUT | USB_TYPE_VENDOR | \
14983 + USB_RECIP_DEVICE)
14984 +#define MCS7830_RD_BREQ 0x0E
14985 +#define MCS7830_WR_BREQ 0x0D
14986 +
14987 +#define MCS7830_CTRL_TIMEOUT 1000
14988 +#define MCS7830_MAX_MCAST 64
14989 +
14990 +#define MCS7830_VENDOR_ID 0x9710
14991 +#define MCS7832_PRODUCT_ID 0x7832
14992 +#define MCS7830_PRODUCT_ID 0x7830
14993 +#define MCS7730_PRODUCT_ID 0x7730
14994 +
14995 +#define SITECOM_VENDOR_ID 0x0DF6
14996 +#define LN_030_PRODUCT_ID 0x0021
14997 +
14998 +#define MCS7830_MII_ADVERTISE (ADVERTISE_PAUSE_CAP | ADVERTISE_100FULL | \
14999 + ADVERTISE_100HALF | ADVERTISE_10FULL | \
15000 + ADVERTISE_10HALF | ADVERTISE_CSMA)
15001 +
15002 +/* HIF_REG_XX corresponding index value */
15003 +enum {
15004 + HIF_REG_MULTICAST_HASH = 0x00,
15005 + HIF_REG_PACKET_GAP1 = 0x08,
15006 + HIF_REG_PACKET_GAP2 = 0x09,
15007 + HIF_REG_PHY_DATA = 0x0a,
15008 + HIF_REG_PHY_CMD1 = 0x0c,
15009 + HIF_REG_PHY_CMD1_READ = 0x40,
15010 + HIF_REG_PHY_CMD1_WRITE = 0x20,
15011 + HIF_REG_PHY_CMD1_PHYADDR = 0x01,
15012 + HIF_REG_PHY_CMD2 = 0x0d,
15013 + HIF_REG_PHY_CMD2_PEND_FLAG_BIT = 0x80,
15014 + HIF_REG_PHY_CMD2_READY_FLAG_BIT = 0x40,
15015 + HIF_REG_CONFIG = 0x0e,
15016 + /* hmm, spec sez: "R/W", "Except bit 3" (likely TXENABLE). */
15017 + HIF_REG_CONFIG_CFG = 0x80,
15018 + HIF_REG_CONFIG_SPEED100 = 0x40,
15019 + HIF_REG_CONFIG_FULLDUPLEX_ENABLE = 0x20,
15020 + HIF_REG_CONFIG_RXENABLE = 0x10,
15021 + HIF_REG_CONFIG_TXENABLE = 0x08,
15022 + HIF_REG_CONFIG_SLEEPMODE = 0x04,
15023 + HIF_REG_CONFIG_ALLMULTICAST = 0x02,
15024 + HIF_REG_CONFIG_PROMISCUOUS = 0x01,
15025 + HIF_REG_ETHERNET_ADDR = 0x0f,
15026 + HIF_REG_FRAME_DROP_COUNTER = 0x15, /* 0..ff; reset: 0 */
15027 + HIF_REG_PAUSE_THRESHOLD = 0x16,
15028 + HIF_REG_PAUSE_THRESHOLD_DEFAULT = 0,
15029 +};
15030 +
15031 +/* Trailing status byte in Ethernet Rx frame */
15032 +enum {
15033 + MCS7830_RX_SHORT_FRAME = 0x01, /* < 64 bytes */
15034 + MCS7830_RX_LENGTH_ERROR = 0x02, /* framelen != Ethernet length field */
15035 + MCS7830_RX_ALIGNMENT_ERROR = 0x04, /* non-even number of nibbles */
15036 + MCS7830_RX_CRC_ERROR = 0x08,
15037 + MCS7830_RX_LARGE_FRAME = 0x10, /* > 1518 bytes */
15038 + MCS7830_RX_FRAME_CORRECT = 0x20, /* frame is correct */
15039 + /* [7:6] reserved */
15040 +};
15041 +
15042 +struct mcs7830_data {
15043 + u8 multi_filter[8];
15044 + u8 config;
15045 +};
15046 +
15047 +static const char driver_name[] = "MOSCHIP usb-ethernet driver";
15048 +
15049 +static int mcs7830_get_reg(struct usbnet *dev, u16 index, u16 size, void *data)
15050 +{
15051 + return usbnet_read_cmd(dev, MCS7830_RD_BREQ, MCS7830_RD_BMREQ,
15052 + 0x0000, index, data, size);
15053 +}
15054 +
15055 +static int mcs7830_set_reg(struct usbnet *dev, u16 index, u16 size, const void *data)
15056 +{
15057 + return usbnet_write_cmd(dev, MCS7830_WR_BREQ, MCS7830_WR_BMREQ,
15058 + 0x0000, index, data, size);
15059 +}
15060 +
15061 +static void mcs7830_set_reg_async(struct usbnet *dev, u16 index, u16 size, void *data)
15062 +{
15063 + usbnet_write_cmd_async(dev, MCS7830_WR_BREQ, MCS7830_WR_BMREQ,
15064 + 0x0000, index, data, size);
15065 +}
15066 +
15067 +static int mcs7830_hif_get_mac_address(struct usbnet *dev, unsigned char *addr)
15068 +{
15069 + int ret = mcs7830_get_reg(dev, HIF_REG_ETHERNET_ADDR, ETH_ALEN, addr);
15070 + if (ret < 0)
15071 + return ret;
15072 + return 0;
15073 +}
15074 +
15075 +static int mcs7830_hif_set_mac_address(struct usbnet *dev, unsigned char *addr)
15076 +{
15077 + int ret = mcs7830_set_reg(dev, HIF_REG_ETHERNET_ADDR, ETH_ALEN, addr);
15078 +
15079 + if (ret < 0)
15080 + return ret;
15081 + return 0;
15082 +}
15083 +
15084 +static int mcs7830_set_mac_address(struct net_device *netdev, void *p)
15085 +{
15086 + int ret;
15087 + struct usbnet *dev = netdev_priv(netdev);
15088 + struct sockaddr *addr = p;
15089 +
15090 + if (netif_running(netdev))
15091 + return -EBUSY;
15092 +
15093 + if (!is_valid_ether_addr(addr->sa_data))
15094 + return -EADDRNOTAVAIL;
15095 +
15096 + ret = mcs7830_hif_set_mac_address(dev, addr->sa_data);
15097 +
15098 + if (ret < 0)
15099 + return ret;
15100 +
15101 + /* it worked --> adopt it on netdev side */
15102 + memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
15103 +
15104 + return 0;
15105 +}
15106 +
15107 +static int mcs7830_read_phy(struct usbnet *dev, u8 index)
15108 +{
15109 + int ret;
15110 + int i;
15111 + __le16 val;
15112 +
15113 + u8 cmd[2] = {
15114 + HIF_REG_PHY_CMD1_READ | HIF_REG_PHY_CMD1_PHYADDR,
15115 + HIF_REG_PHY_CMD2_PEND_FLAG_BIT | index,
15116 + };
15117 +
15118 + mutex_lock(&dev->phy_mutex);
15119 + /* write the MII command */
15120 + ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
15121 + if (ret < 0)
15122 + goto out;
15123 +
15124 + /* wait for the data to become valid, should be within < 1ms */
15125 + for (i = 0; i < 10; i++) {
15126 + ret = mcs7830_get_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
15127 + if ((ret < 0) || (cmd[1] & HIF_REG_PHY_CMD2_READY_FLAG_BIT))
15128 + break;
15129 + ret = -EIO;
15130 + msleep(1);
15131 + }
15132 + if (ret < 0)
15133 + goto out;
15134 +
15135 + /* read actual register contents */
15136 + ret = mcs7830_get_reg(dev, HIF_REG_PHY_DATA, 2, &val);
15137 + if (ret < 0)
15138 + goto out;
15139 + ret = le16_to_cpu(val);
15140 + dev_dbg(&dev->udev->dev, "read PHY reg %02x: %04x (%d tries)\n",
15141 + index, val, i);
15142 +out:
15143 + mutex_unlock(&dev->phy_mutex);
15144 + return ret;
15145 +}
15146 +
15147 +static int mcs7830_write_phy(struct usbnet *dev, u8 index, u16 val)
15148 +{
15149 + int ret;
15150 + int i;
15151 + __le16 le_val;
15152 +
15153 + u8 cmd[2] = {
15154 + HIF_REG_PHY_CMD1_WRITE | HIF_REG_PHY_CMD1_PHYADDR,
15155 + HIF_REG_PHY_CMD2_PEND_FLAG_BIT | (index & 0x1F),
15156 + };
15157 +
15158 + mutex_lock(&dev->phy_mutex);
15159 +
15160 + /* write the new register contents */
15161 + le_val = cpu_to_le16(val);
15162 + ret = mcs7830_set_reg(dev, HIF_REG_PHY_DATA, 2, &le_val);
15163 + if (ret < 0)
15164 + goto out;
15165 +
15166 + /* write the MII command */
15167 + ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
15168 + if (ret < 0)
15169 + goto out;
15170 +
15171 + /* wait for the command to be accepted by the PHY */
15172 + for (i = 0; i < 10; i++) {
15173 + ret = mcs7830_get_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
15174 + if ((ret < 0) || (cmd[1] & HIF_REG_PHY_CMD2_READY_FLAG_BIT))
15175 + break;
15176 + ret = -EIO;
15177 + msleep(1);
15178 + }
15179 + if (ret < 0)
15180 + goto out;
15181 +
15182 + ret = 0;
15183 + dev_dbg(&dev->udev->dev, "write PHY reg %02x: %04x (%d tries)\n",
15184 + index, val, i);
15185 +out:
15186 + mutex_unlock(&dev->phy_mutex);
15187 + return ret;
15188 +}
15189 +
15190 +/*
15191 + * This algorithm comes from the original mcs7830 version 1.4 driver,
15192 + * not sure if it is needed.
15193 + */
15194 +static int mcs7830_set_autoneg(struct usbnet *dev, int ptrUserPhyMode)
15195 +{
15196 + int ret;
15197 + /* Enable all media types */
15198 + ret = mcs7830_write_phy(dev, MII_ADVERTISE, MCS7830_MII_ADVERTISE);
15199 +
15200 + /* First reset BMCR */
15201 + if (!ret)
15202 + ret = mcs7830_write_phy(dev, MII_BMCR, 0x0000);
15203 + /* Enable Auto Neg */
15204 + if (!ret)
15205 + ret = mcs7830_write_phy(dev, MII_BMCR, BMCR_ANENABLE);
15206 + /* Restart Auto Neg (Keep the Enable Auto Neg Bit Set) */
15207 + if (!ret)
15208 + ret = mcs7830_write_phy(dev, MII_BMCR,
15209 + BMCR_ANENABLE | BMCR_ANRESTART );
15210 + return ret;
15211 +}
15212 +
15213 +
15214 +/*
15215 + * if we can read register 22, the chip revision is C or higher
15216 + */
15217 +static int mcs7830_get_rev(struct usbnet *dev)
15218 +{
15219 + u8 dummy[2];
15220 + int ret;
15221 + ret = mcs7830_get_reg(dev, HIF_REG_FRAME_DROP_COUNTER, 2, dummy);
15222 + if (ret > 0)
15223 + return 2; /* Rev C or later */
15224 + return 1; /* earlier revision */
15225 +}
15226 +
15227 +/*
15228 + * On rev. C we need to set the pause threshold
15229 + */
15230 +static void mcs7830_rev_C_fixup(struct usbnet *dev)
15231 +{
15232 + u8 pause_threshold = HIF_REG_PAUSE_THRESHOLD_DEFAULT;
15233 + int retry;
15234 +
15235 + for (retry = 0; retry < 2; retry++) {
15236 + if (mcs7830_get_rev(dev) == 2) {
15237 + dev_info(&dev->udev->dev, "applying rev.C fixup\n");
15238 + mcs7830_set_reg(dev, HIF_REG_PAUSE_THRESHOLD,
15239 + 1, &pause_threshold);
15240 + }
15241 + msleep(1);
15242 + }
15243 +}
15244 +
15245 +static int mcs7830_mdio_read(struct net_device *netdev, int phy_id,
15246 + int location)
15247 +{
15248 + struct usbnet *dev = netdev_priv(netdev);
15249 + return mcs7830_read_phy(dev, location);
15250 +}
15251 +
15252 +static void mcs7830_mdio_write(struct net_device *netdev, int phy_id,
15253 + int location, int val)
15254 +{
15255 + struct usbnet *dev = netdev_priv(netdev);
15256 + mcs7830_write_phy(dev, location, val);
15257 +}
15258 +
15259 +static int mcs7830_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
15260 +{
15261 + struct usbnet *dev = netdev_priv(net);
15262 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
15263 +}
15264 +
15265 +static inline struct mcs7830_data *mcs7830_get_data(struct usbnet *dev)
15266 +{
15267 + return (struct mcs7830_data *)&dev->data;
15268 +}
15269 +
15270 +static void mcs7830_hif_update_multicast_hash(struct usbnet *dev)
15271 +{
15272 + struct mcs7830_data *data = mcs7830_get_data(dev);
15273 + mcs7830_set_reg_async(dev, HIF_REG_MULTICAST_HASH,
15274 + sizeof data->multi_filter,
15275 + data->multi_filter);
15276 +}
15277 +
15278 +static void mcs7830_hif_update_config(struct usbnet *dev)
15279 +{
15280 + /* implementation specific to data->config
15281 + (argument needs to be heap-based anyway - USB DMA!) */
15282 + struct mcs7830_data *data = mcs7830_get_data(dev);
15283 + mcs7830_set_reg_async(dev, HIF_REG_CONFIG, 1, &data->config);
15284 +}
15285 +
15286 +static void mcs7830_data_set_multicast(struct net_device *net)
15287 +{
15288 + struct usbnet *dev = netdev_priv(net);
15289 + struct mcs7830_data *data = mcs7830_get_data(dev);
15290 +
15291 + memset(data->multi_filter, 0, sizeof data->multi_filter);
15292 +
15293 + data->config = HIF_REG_CONFIG_TXENABLE;
15294 +
15295 + /* this should not be needed, but it doesn't work otherwise */
15296 + data->config |= HIF_REG_CONFIG_ALLMULTICAST;
15297 +
15298 + if (net->flags & IFF_PROMISC) {
15299 + data->config |= HIF_REG_CONFIG_PROMISCUOUS;
15300 + } else if (net->flags & IFF_ALLMULTI ||
15301 + netdev_mc_count(net) > MCS7830_MAX_MCAST) {
15302 + data->config |= HIF_REG_CONFIG_ALLMULTICAST;
15303 + } else if (netdev_mc_empty(net)) {
15304 + /* just broadcast and directed */
15305 + } else {
15306 + /* We use the 20 byte dev->data
15307 + * for our 8 byte filter buffer
15308 + * to avoid allocating memory that
15309 + * is tricky to free later */
15310 + struct netdev_hw_addr *ha;
15311 + u32 crc_bits;
15312 +
15313 + /* Build the multicast hash filter. */
15314 + netdev_for_each_mc_addr(ha, net) {
15315 + crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
15316 + data->multi_filter[crc_bits >> 3] |= 1 << (crc_bits & 7);
15317 + }
15318 + }
15319 +}
15320 +
15321 +static int mcs7830_apply_base_config(struct usbnet *dev)
15322 +{
15323 + int ret;
15324 +
15325 + /* re-configure known MAC (suspend case etc.) */
15326 + ret = mcs7830_hif_set_mac_address(dev, dev->net->dev_addr);
15327 + if (ret) {
15328 + dev_info(&dev->udev->dev, "Cannot set MAC address\n");
15329 + goto out;
15330 + }
15331 +
15332 + /* Set up PHY */
15333 + ret = mcs7830_set_autoneg(dev, 0);
15334 + if (ret) {
15335 + dev_info(&dev->udev->dev, "Cannot set autoneg\n");
15336 + goto out;
15337 + }
15338 +
15339 + mcs7830_hif_update_multicast_hash(dev);
15340 + mcs7830_hif_update_config(dev);
15341 +
15342 + mcs7830_rev_C_fixup(dev);
15343 + ret = 0;
15344 +out:
15345 + return ret;
15346 +}
15347 +
15348 +/* credits go to asix_set_multicast */
15349 +static void mcs7830_set_multicast(struct net_device *net)
15350 +{
15351 + struct usbnet *dev = netdev_priv(net);
15352 +
15353 + mcs7830_data_set_multicast(net);
15354 +
15355 + mcs7830_hif_update_multicast_hash(dev);
15356 + mcs7830_hif_update_config(dev);
15357 +}
15358 +
15359 +static int mcs7830_get_regs_len(struct net_device *net)
15360 +{
15361 + struct usbnet *dev = netdev_priv(net);
15362 +
15363 + switch (mcs7830_get_rev(dev)) {
15364 + case 1:
15365 + return 21;
15366 + case 2:
15367 + return 32;
15368 + }
15369 + return 0;
15370 +}
15371 +
15372 +static void mcs7830_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *drvinfo)
15373 +{
15374 + usbnet_get_drvinfo(net, drvinfo);
15375 + drvinfo->regdump_len = mcs7830_get_regs_len(net);
15376 +}
15377 +
15378 +static void mcs7830_get_regs(struct net_device *net, struct ethtool_regs *regs, void *data)
15379 +{
15380 + struct usbnet *dev = netdev_priv(net);
15381 +
15382 + regs->version = mcs7830_get_rev(dev);
15383 + mcs7830_get_reg(dev, 0, regs->len, data);
15384 +}
15385 +
15386 +static const struct ethtool_ops mcs7830_ethtool_ops = {
15387 + .get_drvinfo = mcs7830_get_drvinfo,
15388 + .get_regs_len = mcs7830_get_regs_len,
15389 + .get_regs = mcs7830_get_regs,
15390 +
15391 + /* common usbnet calls */
15392 + .get_link = usbnet_get_link,
15393 + .get_msglevel = usbnet_get_msglevel,
15394 + .set_msglevel = usbnet_set_msglevel,
15395 + .get_settings = usbnet_get_settings,
15396 + .set_settings = usbnet_set_settings,
15397 + .nway_reset = usbnet_nway_reset,
15398 +};
15399 +
15400 +static const struct net_device_ops mcs7830_netdev_ops = {
15401 + .ndo_open = usbnet_open,
15402 + .ndo_stop = usbnet_stop,
15403 + .ndo_start_xmit = usbnet_start_xmit,
15404 + .ndo_tx_timeout = usbnet_tx_timeout,
15405 + .ndo_change_mtu = usbnet_change_mtu,
15406 + .ndo_validate_addr = eth_validate_addr,
15407 + .ndo_do_ioctl = mcs7830_ioctl,
15408 + .ndo_set_rx_mode = mcs7830_set_multicast,
15409 + .ndo_set_mac_address = mcs7830_set_mac_address,
15410 +};
15411 +
15412 +static int mcs7830_bind(struct usbnet *dev, struct usb_interface *udev)
15413 +{
15414 + struct net_device *net = dev->net;
15415 + int ret;
15416 + int retry;
15417 +
15418 + /* Initial startup: Gather MAC address setting from EEPROM */
15419 + ret = -EINVAL;
15420 + for (retry = 0; retry < 5 && ret; retry++)
15421 + ret = mcs7830_hif_get_mac_address(dev, net->dev_addr);
15422 + if (ret) {
15423 + dev_warn(&dev->udev->dev, "Cannot read MAC address\n");
15424 + goto out;
15425 + }
15426 +
15427 + mcs7830_data_set_multicast(net);
15428 +
15429 + ret = mcs7830_apply_base_config(dev);
15430 + if (ret)
15431 + goto out;
15432 +
15433 + net->ethtool_ops = &mcs7830_ethtool_ops;
15434 + net->netdev_ops = &mcs7830_netdev_ops;
15435 +
15436 + /* reserve space for the status byte on rx */
15437 + dev->rx_urb_size = ETH_FRAME_LEN + 1;
15438 +
15439 + dev->mii.mdio_read = mcs7830_mdio_read;
15440 + dev->mii.mdio_write = mcs7830_mdio_write;
15441 + dev->mii.dev = net;
15442 + dev->mii.phy_id_mask = 0x3f;
15443 + dev->mii.reg_num_mask = 0x1f;
15444 + dev->mii.phy_id = *((u8 *) net->dev_addr + 1);
15445 +
15446 + ret = usbnet_get_endpoints(dev, udev);
15447 +out:
15448 + return ret;
15449 +}
15450 +
15451 +/* The chip always appends a status byte that we need to strip */
15452 +static int mcs7830_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
15453 +{
15454 + u8 status;
15455 +
15456 + /* This check is no longer done by usbnet */
15457 + if (skb->len < dev->net->hard_header_len) {
15458 + dev_err(&dev->udev->dev, "unexpected tiny rx frame\n");
15459 + return 0;
15460 + }
15461 +
15462 + skb_trim(skb, skb->len - 1);
15463 + status = skb->data[skb->len];
15464 +
15465 + if (status != MCS7830_RX_FRAME_CORRECT) {
15466 + dev_dbg(&dev->udev->dev, "rx fixup status %x\n", status);
15467 +
15468 + /* hmm, perhaps usbnet.c already sees a globally visible
15469 + frame error and increments rx_errors on its own already? */
15470 + dev->net->stats.rx_errors++;
15471 +
15472 + if (status & (MCS7830_RX_SHORT_FRAME
15473 + |MCS7830_RX_LENGTH_ERROR
15474 + |MCS7830_RX_LARGE_FRAME))
15475 + dev->net->stats.rx_length_errors++;
15476 + if (status & MCS7830_RX_ALIGNMENT_ERROR)
15477 + dev->net->stats.rx_frame_errors++;
15478 + if (status & MCS7830_RX_CRC_ERROR)
15479 + dev->net->stats.rx_crc_errors++;
15480 + }
15481 +
15482 + return skb->len > 0;
15483 +}
15484 +
15485 +static void mcs7830_status(struct usbnet *dev, struct urb *urb)
15486 +{
15487 + u8 *buf = urb->transfer_buffer;
15488 + bool link, link_changed;
15489 +
15490 + if (urb->actual_length < 16)
15491 + return;
15492 +
15493 + link = !(buf[1] == 0x20);
15494 + link_changed = netif_carrier_ok(dev->net) != link;
15495 + if (link_changed) {
15496 + usbnet_link_change(dev, link, 0);
15497 + netdev_dbg(dev->net, "Link Status is: %d\n", link);
15498 + }
15499 +}
15500 +
15501 +static const struct driver_info moschip_info = {
15502 + .description = "MOSCHIP 7830/7832/7730 usb-NET adapter",
15503 + .bind = mcs7830_bind,
15504 + .rx_fixup = mcs7830_rx_fixup,
15505 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
15506 + .status = mcs7830_status,
15507 + .in = 1,
15508 + .out = 2,
15509 +};
15510 +
15511 +static const struct driver_info sitecom_info = {
15512 + .description = "Sitecom LN-30 usb-NET adapter",
15513 + .bind = mcs7830_bind,
15514 + .rx_fixup = mcs7830_rx_fixup,
15515 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
15516 + .status = mcs7830_status,
15517 + .in = 1,
15518 + .out = 2,
15519 +};
15520 +
15521 +static const struct usb_device_id products[] = {
15522 + {
15523 + USB_DEVICE(MCS7830_VENDOR_ID, MCS7832_PRODUCT_ID),
15524 + .driver_info = (unsigned long) &moschip_info,
15525 + },
15526 + {
15527 + USB_DEVICE(MCS7830_VENDOR_ID, MCS7830_PRODUCT_ID),
15528 + .driver_info = (unsigned long) &moschip_info,
15529 + },
15530 + {
15531 + USB_DEVICE(MCS7830_VENDOR_ID, MCS7730_PRODUCT_ID),
15532 + .driver_info = (unsigned long) &moschip_info,
15533 + },
15534 + {
15535 + USB_DEVICE(SITECOM_VENDOR_ID, LN_030_PRODUCT_ID),
15536 + .driver_info = (unsigned long) &sitecom_info,
15537 + },
15538 + {},
15539 +};
15540 +MODULE_DEVICE_TABLE(usb, products);
15541 +
15542 +static int mcs7830_reset_resume (struct usb_interface *intf)
15543 +{
15544 + /* YES, this function is successful enough that ethtool -d
15545 + does show same output pre-/post-suspend */
15546 +
15547 + struct usbnet *dev = usb_get_intfdata(intf);
15548 +
15549 + mcs7830_apply_base_config(dev);
15550 +
15551 + usbnet_resume(intf);
15552 +
15553 + return 0;
15554 +}
15555 +
15556 +static struct usb_driver mcs7830_driver = {
15557 + .name = driver_name,
15558 + .id_table = products,
15559 + .probe = usbnet_probe,
15560 + .disconnect = usbnet_disconnect,
15561 + .suspend = usbnet_suspend,
15562 + .resume = usbnet_resume,
15563 + .reset_resume = mcs7830_reset_resume,
15564 + .disable_hub_initiated_lpm = 1,
15565 +};
15566 +
15567 +module_usb_driver(mcs7830_driver);
15568 +
15569 +MODULE_DESCRIPTION("USB to network adapter MCS7830)");
15570 +MODULE_LICENSE("GPL");
15571 diff -Naur backports-4.2.6-1.org/drivers/net/usb/net1080.c backports-4.2.6-1/drivers/net/usb/net1080.c
15572 --- backports-4.2.6-1.org/drivers/net/usb/net1080.c 1970-01-01 01:00:00.000000000 +0100
15573 +++ backports-4.2.6-1/drivers/net/usb/net1080.c 2016-06-28 14:35:17.995307218 +0200
15574 @@ -0,0 +1,544 @@
15575 +/*
15576 + * Net1080 based USB host-to-host cables
15577 + * Copyright (C) 2000-2005 by David Brownell
15578 + *
15579 + * This program is free software; you can redistribute it and/or modify
15580 + * it under the terms of the GNU General Public License as published by
15581 + * the Free Software Foundation; either version 2 of the License, or
15582 + * (at your option) any later version.
15583 + *
15584 + * This program is distributed in the hope that it will be useful,
15585 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15586 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15587 + * GNU General Public License for more details.
15588 + *
15589 + * You should have received a copy of the GNU General Public License
15590 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
15591 + */
15592 +
15593 +// #define DEBUG // error path messages, extra info
15594 +// #define VERBOSE // more; success messages
15595 +
15596 +#include <linux/module.h>
15597 +#include <linux/netdevice.h>
15598 +#include <linux/etherdevice.h>
15599 +#include <linux/ethtool.h>
15600 +#include <linux/workqueue.h>
15601 +#include <linux/mii.h>
15602 +#include <linux/usb.h>
15603 +#include <linux/usb/usbnet.h>
15604 +#include <linux/slab.h>
15605 +
15606 +#include <asm/unaligned.h>
15607 +
15608 +
15609 +/*
15610 + * Netchip 1080 driver ... http://www.netchip.com
15611 + * (Sept 2004: End-of-life announcement has been sent.)
15612 + * Used in (some) LapLink cables
15613 + */
15614 +
15615 +#define frame_errors data[1]
15616 +
15617 +/*
15618 + * NetChip framing of ethernet packets, supporting additional error
15619 + * checks for links that may drop bulk packets from inside messages.
15620 + * Odd USB length == always short read for last usb packet.
15621 + * - nc_header
15622 + * - Ethernet header (14 bytes)
15623 + * - payload
15624 + * - (optional padding byte, if needed so length becomes odd)
15625 + * - nc_trailer
15626 + *
15627 + * This framing is to be avoided for non-NetChip devices.
15628 + */
15629 +
15630 +struct nc_header { // packed:
15631 + __le16 hdr_len; // sizeof nc_header (LE, all)
15632 + __le16 packet_len; // payload size (including ethhdr)
15633 + __le16 packet_id; // detects dropped packets
15634 +#define MIN_HEADER 6
15635 +
15636 + // all else is optional, and must start with:
15637 + // __le16 vendorId; // from usb-if
15638 + // __le16 productId;
15639 +} __packed;
15640 +
15641 +#define PAD_BYTE ((unsigned char)0xAC)
15642 +
15643 +struct nc_trailer {
15644 + __le16 packet_id;
15645 +} __packed;
15646 +
15647 +// packets may use FLAG_FRAMING_NC and optional pad
15648 +#define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
15649 + + sizeof (struct ethhdr) \
15650 + + (mtu) \
15651 + + 1 \
15652 + + sizeof (struct nc_trailer))
15653 +
15654 +#define MIN_FRAMED FRAMED_SIZE(0)
15655 +
15656 +/* packets _could_ be up to 64KB... */
15657 +#define NC_MAX_PACKET 32767
15658 +
15659 +
15660 +/*
15661 + * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
15662 + * before the hardware drops it. If that's done, the driver will need to
15663 + * frame network packets to guard against the dropped USB packets. The win32
15664 + * driver sets this for both sides of the link.
15665 + */
15666 +#define NC_READ_TTL_MS ((u8)255) // ms
15667 +
15668 +/*
15669 + * We ignore most registers and EEPROM contents.
15670 + */
15671 +#define REG_USBCTL ((u8)0x04)
15672 +#define REG_TTL ((u8)0x10)
15673 +#define REG_STATUS ((u8)0x11)
15674 +
15675 +/*
15676 + * Vendor specific requests to read/write data
15677 + */
15678 +#define REQUEST_REGISTER ((u8)0x10)
15679 +#define REQUEST_EEPROM ((u8)0x11)
15680 +
15681 +static int
15682 +nc_vendor_read(struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
15683 +{
15684 + int status = usbnet_read_cmd(dev, req,
15685 + USB_DIR_IN | USB_TYPE_VENDOR |
15686 + USB_RECIP_DEVICE,
15687 + 0, regnum, retval_ptr,
15688 + sizeof *retval_ptr);
15689 + if (status > 0)
15690 + status = 0;
15691 + if (!status)
15692 + le16_to_cpus(retval_ptr);
15693 + return status;
15694 +}
15695 +
15696 +static inline int
15697 +nc_register_read(struct usbnet *dev, u8 regnum, u16 *retval_ptr)
15698 +{
15699 + return nc_vendor_read(dev, REQUEST_REGISTER, regnum, retval_ptr);
15700 +}
15701 +
15702 +// no retval ... can become async, usable in_interrupt()
15703 +static void
15704 +nc_vendor_write(struct usbnet *dev, u8 req, u8 regnum, u16 value)
15705 +{
15706 + usbnet_write_cmd(dev, req,
15707 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
15708 + value, regnum, NULL, 0);
15709 +}
15710 +
15711 +static inline void
15712 +nc_register_write(struct usbnet *dev, u8 regnum, u16 value)
15713 +{
15714 + nc_vendor_write(dev, REQUEST_REGISTER, regnum, value);
15715 +}
15716 +
15717 +
15718 +#if 0
15719 +static void nc_dump_registers(struct usbnet *dev)
15720 +{
15721 + u8 reg;
15722 + u16 *vp = kmalloc(sizeof (u16));
15723 +
15724 + if (!vp)
15725 + return;
15726 +
15727 + netdev_dbg(dev->net, "registers:\n");
15728 + for (reg = 0; reg < 0x20; reg++) {
15729 + int retval;
15730 +
15731 + // reading some registers is trouble
15732 + if (reg >= 0x08 && reg <= 0xf)
15733 + continue;
15734 + if (reg >= 0x12 && reg <= 0x1e)
15735 + continue;
15736 +
15737 + retval = nc_register_read(dev, reg, vp);
15738 + if (retval < 0)
15739 + netdev_dbg(dev->net, "reg [0x%x] ==> error %d\n",
15740 + reg, retval);
15741 + else
15742 + netdev_dbg(dev->net, "reg [0x%x] = 0x%x\n", reg, *vp);
15743 + }
15744 + kfree(vp);
15745 +}
15746 +#endif
15747 +
15748 +
15749 +/*-------------------------------------------------------------------------*/
15750 +
15751 +/*
15752 + * Control register
15753 + */
15754 +
15755 +#define USBCTL_WRITABLE_MASK 0x1f0f
15756 +// bits 15-13 reserved, r/o
15757 +#define USBCTL_ENABLE_LANG (1 << 12)
15758 +#define USBCTL_ENABLE_MFGR (1 << 11)
15759 +#define USBCTL_ENABLE_PROD (1 << 10)
15760 +#define USBCTL_ENABLE_SERIAL (1 << 9)
15761 +#define USBCTL_ENABLE_DEFAULTS (1 << 8)
15762 +// bits 7-4 reserved, r/o
15763 +#define USBCTL_FLUSH_OTHER (1 << 3)
15764 +#define USBCTL_FLUSH_THIS (1 << 2)
15765 +#define USBCTL_DISCONN_OTHER (1 << 1)
15766 +#define USBCTL_DISCONN_THIS (1 << 0)
15767 +
15768 +static inline void nc_dump_usbctl(struct usbnet *dev, u16 usbctl)
15769 +{
15770 + netif_dbg(dev, link, dev->net,
15771 + "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s; this%s%s; other%s%s; r/o 0x%x\n",
15772 + dev->udev->bus->bus_name, dev->udev->devpath,
15773 + usbctl,
15774 + (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",
15775 + (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",
15776 + (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",
15777 + (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",
15778 + (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",
15779 +
15780 + (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",
15781 + (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",
15782 +
15783 + (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",
15784 + (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",
15785 +
15786 + usbctl & ~USBCTL_WRITABLE_MASK);
15787 +}
15788 +
15789 +/*-------------------------------------------------------------------------*/
15790 +
15791 +/*
15792 + * Status register
15793 + */
15794 +
15795 +#define STATUS_PORT_A (1 << 15)
15796 +
15797 +#define STATUS_CONN_OTHER (1 << 14)
15798 +#define STATUS_SUSPEND_OTHER (1 << 13)
15799 +#define STATUS_MAILBOX_OTHER (1 << 12)
15800 +#define STATUS_PACKETS_OTHER(n) (((n) >> 8) & 0x03)
15801 +
15802 +#define STATUS_CONN_THIS (1 << 6)
15803 +#define STATUS_SUSPEND_THIS (1 << 5)
15804 +#define STATUS_MAILBOX_THIS (1 << 4)
15805 +#define STATUS_PACKETS_THIS(n) (((n) >> 0) & 0x03)
15806 +
15807 +#define STATUS_UNSPEC_MASK 0x0c8c
15808 +#define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
15809 +
15810 +
15811 +static inline void nc_dump_status(struct usbnet *dev, u16 status)
15812 +{
15813 + netif_dbg(dev, link, dev->net,
15814 + "net1080 %s-%s status 0x%x: this (%c) PKT=%d%s%s%s; other PKT=%d%s%s%s; unspec 0x%x\n",
15815 + dev->udev->bus->bus_name, dev->udev->devpath,
15816 + status,
15817 +
15818 + // XXX the packet counts don't seem right
15819 + // (1 at reset, not 0); maybe UNSPEC too
15820 +
15821 + (status & STATUS_PORT_A) ? 'A' : 'B',
15822 + STATUS_PACKETS_THIS(status),
15823 + (status & STATUS_CONN_THIS) ? " CON" : "",
15824 + (status & STATUS_SUSPEND_THIS) ? " SUS" : "",
15825 + (status & STATUS_MAILBOX_THIS) ? " MBOX" : "",
15826 +
15827 + STATUS_PACKETS_OTHER(status),
15828 + (status & STATUS_CONN_OTHER) ? " CON" : "",
15829 + (status & STATUS_SUSPEND_OTHER) ? " SUS" : "",
15830 + (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",
15831 +
15832 + status & STATUS_UNSPEC_MASK);
15833 +}
15834 +
15835 +/*-------------------------------------------------------------------------*/
15836 +
15837 +/*
15838 + * TTL register
15839 + */
15840 +
15841 +#define TTL_THIS(ttl) (0x00ff & ttl)
15842 +#define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
15843 +#define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
15844 +
15845 +static inline void nc_dump_ttl(struct usbnet *dev, u16 ttl)
15846 +{
15847 + netif_dbg(dev, link, dev->net, "net1080 %s-%s ttl 0x%x this = %d, other = %d\n",
15848 + dev->udev->bus->bus_name, dev->udev->devpath,
15849 + ttl, TTL_THIS(ttl), TTL_OTHER(ttl));
15850 +}
15851 +
15852 +/*-------------------------------------------------------------------------*/
15853 +
15854 +static int net1080_reset(struct usbnet *dev)
15855 +{
15856 + u16 usbctl, status, ttl;
15857 + u16 vp;
15858 + int retval;
15859 +
15860 + // nc_dump_registers(dev);
15861 +
15862 + if ((retval = nc_register_read(dev, REG_STATUS, &vp)) < 0) {
15863 + netdev_dbg(dev->net, "can't read %s-%s status: %d\n",
15864 + dev->udev->bus->bus_name, dev->udev->devpath, retval);
15865 + goto done;
15866 + }
15867 + status = vp;
15868 + nc_dump_status(dev, status);
15869 +
15870 + if ((retval = nc_register_read(dev, REG_USBCTL, &vp)) < 0) {
15871 + netdev_dbg(dev->net, "can't read USBCTL, %d\n", retval);
15872 + goto done;
15873 + }
15874 + usbctl = vp;
15875 + nc_dump_usbctl(dev, usbctl);
15876 +
15877 + nc_register_write(dev, REG_USBCTL,
15878 + USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
15879 +
15880 + if ((retval = nc_register_read(dev, REG_TTL, &vp)) < 0) {
15881 + netdev_dbg(dev->net, "can't read TTL, %d\n", retval);
15882 + goto done;
15883 + }
15884 + ttl = vp;
15885 + // nc_dump_ttl(dev, ttl);
15886 +
15887 + nc_register_write(dev, REG_TTL,
15888 + MK_TTL(NC_READ_TTL_MS, TTL_OTHER(ttl)) );
15889 + netdev_dbg(dev->net, "assigned TTL, %d ms\n", NC_READ_TTL_MS);
15890 +
15891 + netif_info(dev, link, dev->net, "port %c, peer %sconnected\n",
15892 + (status & STATUS_PORT_A) ? 'A' : 'B',
15893 + (status & STATUS_CONN_OTHER) ? "" : "dis");
15894 + retval = 0;
15895 +
15896 +done:
15897 + return retval;
15898 +}
15899 +
15900 +static int net1080_check_connect(struct usbnet *dev)
15901 +{
15902 + int retval;
15903 + u16 status;
15904 + u16 vp;
15905 +
15906 + retval = nc_register_read(dev, REG_STATUS, &vp);
15907 + status = vp;
15908 + if (retval != 0) {
15909 + netdev_dbg(dev->net, "net1080_check_conn read - %d\n", retval);
15910 + return retval;
15911 + }
15912 + if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
15913 + return -ENOLINK;
15914 + return 0;
15915 +}
15916 +
15917 +static void nc_ensure_sync(struct usbnet *dev)
15918 +{
15919 + if (++dev->frame_errors <= 5)
15920 + return;
15921 +
15922 + if (usbnet_write_cmd_async(dev, REQUEST_REGISTER,
15923 + USB_DIR_OUT | USB_TYPE_VENDOR |
15924 + USB_RECIP_DEVICE,
15925 + USBCTL_FLUSH_THIS |
15926 + USBCTL_FLUSH_OTHER,
15927 + REG_USBCTL, NULL, 0))
15928 + return;
15929 +
15930 + netif_dbg(dev, rx_err, dev->net,
15931 + "flush net1080; too many framing errors\n");
15932 + dev->frame_errors = 0;
15933 +}
15934 +
15935 +static int net1080_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
15936 +{
15937 + struct nc_header *header;
15938 + struct nc_trailer *trailer;
15939 + u16 hdr_len, packet_len;
15940 +
15941 + /* This check is no longer done by usbnet */
15942 + if (skb->len < dev->net->hard_header_len)
15943 + return 0;
15944 +
15945 + if (!(skb->len & 0x01)) {
15946 + netdev_dbg(dev->net, "rx framesize %d range %d..%d mtu %d\n",
15947 + skb->len, dev->net->hard_header_len, dev->hard_mtu,
15948 + dev->net->mtu);
15949 + dev->net->stats.rx_frame_errors++;
15950 + nc_ensure_sync(dev);
15951 + return 0;
15952 + }
15953 +
15954 + header = (struct nc_header *) skb->data;
15955 + hdr_len = le16_to_cpup(&header->hdr_len);
15956 + packet_len = le16_to_cpup(&header->packet_len);
15957 + if (FRAMED_SIZE(packet_len) > NC_MAX_PACKET) {
15958 + dev->net->stats.rx_frame_errors++;
15959 + netdev_dbg(dev->net, "packet too big, %d\n", packet_len);
15960 + nc_ensure_sync(dev);
15961 + return 0;
15962 + } else if (hdr_len < MIN_HEADER) {
15963 + dev->net->stats.rx_frame_errors++;
15964 + netdev_dbg(dev->net, "header too short, %d\n", hdr_len);
15965 + nc_ensure_sync(dev);
15966 + return 0;
15967 + } else if (hdr_len > MIN_HEADER) {
15968 + // out of band data for us?
15969 + netdev_dbg(dev->net, "header OOB, %d bytes\n", hdr_len - MIN_HEADER);
15970 + nc_ensure_sync(dev);
15971 + // switch (vendor/product ids) { ... }
15972 + }
15973 + skb_pull(skb, hdr_len);
15974 +
15975 + trailer = (struct nc_trailer *)
15976 + (skb->data + skb->len - sizeof *trailer);
15977 + skb_trim(skb, skb->len - sizeof *trailer);
15978 +
15979 + if ((packet_len & 0x01) == 0) {
15980 + if (skb->data [packet_len] != PAD_BYTE) {
15981 + dev->net->stats.rx_frame_errors++;
15982 + netdev_dbg(dev->net, "bad pad\n");
15983 + return 0;
15984 + }
15985 + skb_trim(skb, skb->len - 1);
15986 + }
15987 + if (skb->len != packet_len) {
15988 + dev->net->stats.rx_frame_errors++;
15989 + netdev_dbg(dev->net, "bad packet len %d (expected %d)\n",
15990 + skb->len, packet_len);
15991 + nc_ensure_sync(dev);
15992 + return 0;
15993 + }
15994 + if (header->packet_id != get_unaligned(&trailer->packet_id)) {
15995 + dev->net->stats.rx_fifo_errors++;
15996 + netdev_dbg(dev->net, "(2+ dropped) rx packet_id mismatch 0x%x 0x%x\n",
15997 + le16_to_cpu(header->packet_id),
15998 + le16_to_cpu(trailer->packet_id));
15999 + return 0;
16000 + }
16001 +#if 0
16002 + netdev_dbg(dev->net, "frame <rx h %d p %d id %d\n", header->hdr_len,
16003 + header->packet_len, header->packet_id);
16004 +#endif
16005 + dev->frame_errors = 0;
16006 + return 1;
16007 +}
16008 +
16009 +static struct sk_buff *
16010 +net1080_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
16011 +{
16012 + struct sk_buff *skb2;
16013 + struct nc_header *header = NULL;
16014 + struct nc_trailer *trailer = NULL;
16015 + int padlen = sizeof (struct nc_trailer);
16016 + int len = skb->len;
16017 +
16018 + if (!((len + padlen + sizeof (struct nc_header)) & 0x01))
16019 + padlen++;
16020 + if (!skb_cloned(skb)) {
16021 + int headroom = skb_headroom(skb);
16022 + int tailroom = skb_tailroom(skb);
16023 +
16024 + if (padlen <= tailroom &&
16025 + sizeof(struct nc_header) <= headroom)
16026 + /* There's enough head and tail room */
16027 + goto encapsulate;
16028 +
16029 + if ((sizeof (struct nc_header) + padlen) <
16030 + (headroom + tailroom)) {
16031 + /* There's enough total room, so just readjust */
16032 + skb->data = memmove(skb->head
16033 + + sizeof (struct nc_header),
16034 + skb->data, skb->len);
16035 + skb_set_tail_pointer(skb, len);
16036 + goto encapsulate;
16037 + }
16038 + }
16039 +
16040 + /* Create a new skb to use with the correct size */
16041 + skb2 = skb_copy_expand(skb,
16042 + sizeof (struct nc_header),
16043 + padlen,
16044 + flags);
16045 + dev_kfree_skb_any(skb);
16046 + if (!skb2)
16047 + return skb2;
16048 + skb = skb2;
16049 +
16050 +encapsulate:
16051 + /* header first */
16052 + header = (struct nc_header *) skb_push(skb, sizeof *header);
16053 + header->hdr_len = cpu_to_le16(sizeof (*header));
16054 + header->packet_len = cpu_to_le16(len);
16055 + header->packet_id = cpu_to_le16((u16)dev->xid++);
16056 +
16057 + /* maybe pad; then trailer */
16058 + if (!((skb->len + sizeof *trailer) & 0x01))
16059 + *skb_put(skb, 1) = PAD_BYTE;
16060 + trailer = (struct nc_trailer *) skb_put(skb, sizeof *trailer);
16061 + put_unaligned(header->packet_id, &trailer->packet_id);
16062 +#if 0
16063 + netdev_dbg(dev->net, "frame >tx h %d p %d id %d\n",
16064 + header->hdr_len, header->packet_len,
16065 + header->packet_id);
16066 +#endif
16067 + return skb;
16068 +}
16069 +
16070 +static int net1080_bind(struct usbnet *dev, struct usb_interface *intf)
16071 +{
16072 + unsigned extra = sizeof (struct nc_header)
16073 + + 1
16074 + + sizeof (struct nc_trailer);
16075 +
16076 + dev->net->hard_header_len += extra;
16077 + dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu;
16078 + dev->hard_mtu = NC_MAX_PACKET;
16079 + return usbnet_get_endpoints (dev, intf);
16080 +}
16081 +
16082 +static const struct driver_info net1080_info = {
16083 + .description = "NetChip TurboCONNECT",
16084 + .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_NC,
16085 + .bind = net1080_bind,
16086 + .reset = net1080_reset,
16087 + .check_connect = net1080_check_connect,
16088 + .rx_fixup = net1080_rx_fixup,
16089 + .tx_fixup = net1080_tx_fixup,
16090 +};
16091 +
16092 +static const struct usb_device_id products [] = {
16093 +{
16094 + USB_DEVICE(0x0525, 0x1080), // NetChip ref design
16095 + .driver_info = (unsigned long) &net1080_info,
16096 +}, {
16097 + USB_DEVICE(0x06D0, 0x0622), // Laplink Gold
16098 + .driver_info = (unsigned long) &net1080_info,
16099 +},
16100 + { }, // END
16101 +};
16102 +MODULE_DEVICE_TABLE(usb, products);
16103 +
16104 +static struct usb_driver net1080_driver = {
16105 + .name = "net1080",
16106 + .id_table = products,
16107 + .probe = usbnet_probe,
16108 + .disconnect = usbnet_disconnect,
16109 + .suspend = usbnet_suspend,
16110 + .resume = usbnet_resume,
16111 + .disable_hub_initiated_lpm = 1,
16112 +};
16113 +
16114 +module_usb_driver(net1080_driver);
16115 +
16116 +MODULE_AUTHOR("David Brownell");
16117 +MODULE_DESCRIPTION("NetChip 1080 based USB Host-to-Host Links");
16118 +MODULE_LICENSE("GPL");
16119 diff -Naur backports-4.2.6-1.org/drivers/net/usb/pegasus.c backports-4.2.6-1/drivers/net/usb/pegasus.c
16120 --- backports-4.2.6-1.org/drivers/net/usb/pegasus.c 1970-01-01 01:00:00.000000000 +0100
16121 +++ backports-4.2.6-1/drivers/net/usb/pegasus.c 2016-06-28 14:35:17.995307218 +0200
16122 @@ -0,0 +1,1335 @@
16123 +/*
16124 + * Copyright (c) 1999-2013 Petko Manolov (petkan@nucleusys.com)
16125 + *
16126 + * This program is free software; you can redistribute it and/or modify
16127 + * it under the terms of the GNU General Public License version 2 as
16128 + * published by the Free Software Foundation.
16129 + *
16130 + * ChangeLog:
16131 + * .... Most of the time spent on reading sources & docs.
16132 + * v0.2.x First official release for the Linux kernel.
16133 + * v0.3.0 Beutified and structured, some bugs fixed.
16134 + * v0.3.x URBifying bulk requests and bugfixing. First relatively
16135 + * stable release. Still can touch device's registers only
16136 + * from top-halves.
16137 + * v0.4.0 Control messages remained unurbified are now URBs.
16138 + * Now we can touch the HW at any time.
16139 + * v0.4.9 Control urbs again use process context to wait. Argh...
16140 + * Some long standing bugs (enable_net_traffic) fixed.
16141 + * Also nasty trick about resubmiting control urb from
16142 + * interrupt context used. Please let me know how it
16143 + * behaves. Pegasus II support added since this version.
16144 + * TODO: suppressing HCD warnings spewage on disconnect.
16145 + * v0.4.13 Ethernet address is now set at probe(), not at open()
16146 + * time as this seems to break dhcpd.
16147 + * v0.5.0 branch to 2.5.x kernels
16148 + * v0.5.1 ethtool support added
16149 + * v0.5.5 rx socket buffers are in a pool and the their allocation
16150 + * is out of the interrupt routine.
16151 + * ...
16152 + * v0.9.3 simplified [get|set]_register(s), async update registers
16153 + * logic revisited, receive skb_pool removed.
16154 + */
16155 +
16156 +#include <linux/sched.h>
16157 +#include <linux/slab.h>
16158 +#include <linux/init.h>
16159 +#include <linux/delay.h>
16160 +#include <linux/netdevice.h>
16161 +#include <linux/etherdevice.h>
16162 +#include <linux/ethtool.h>
16163 +#include <linux/mii.h>
16164 +#include <linux/usb.h>
16165 +#include <linux/module.h>
16166 +#include <asm/byteorder.h>
16167 +#include <asm/uaccess.h>
16168 +#include "pegasus.h"
16169 +
16170 +/*
16171 + * Version Information
16172 + */
16173 +#define DRIVER_VERSION "v0.9.3 (2013/04/25)"
16174 +#define DRIVER_AUTHOR "Petko Manolov <petkan@nucleusys.com>"
16175 +#define DRIVER_DESC "Pegasus/Pegasus II USB Ethernet driver"
16176 +
16177 +static const char driver_name[] = "pegasus";
16178 +
16179 +#undef PEGASUS_WRITE_EEPROM
16180 +#define BMSR_MEDIA (BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | \
16181 + BMSR_100FULL | BMSR_ANEGCAPABLE)
16182 +
16183 +static bool loopback;
16184 +static bool mii_mode;
16185 +static char *devid;
16186 +
16187 +static struct usb_eth_dev usb_dev_id[] = {
16188 +#define PEGASUS_DEV(pn, vid, pid, flags) \
16189 + {.name = pn, .vendor = vid, .device = pid, .private = flags},
16190 +#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
16191 + PEGASUS_DEV(pn, vid, pid, flags)
16192 +#include "pegasus.h"
16193 +#undef PEGASUS_DEV
16194 +#undef PEGASUS_DEV_CLASS
16195 + {NULL, 0, 0, 0},
16196 + {NULL, 0, 0, 0}
16197 +};
16198 +
16199 +static struct usb_device_id pegasus_ids[] = {
16200 +#define PEGASUS_DEV(pn, vid, pid, flags) \
16201 + {.match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = vid, .idProduct = pid},
16202 +/*
16203 + * The Belkin F8T012xx1 bluetooth adaptor has the same vendor and product
16204 + * IDs as the Belkin F5D5050, so we need to teach the pegasus driver to
16205 + * ignore adaptors belonging to the "Wireless" class 0xE0. For this one
16206 + * case anyway, seeing as the pegasus is for "Wired" adaptors.
16207 + */
16208 +#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
16209 + {.match_flags = (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_CLASS), \
16210 + .idVendor = vid, .idProduct = pid, .bDeviceClass = dclass},
16211 +#include "pegasus.h"
16212 +#undef PEGASUS_DEV
16213 +#undef PEGASUS_DEV_CLASS
16214 + {},
16215 + {}
16216 +};
16217 +
16218 +MODULE_AUTHOR(DRIVER_AUTHOR);
16219 +MODULE_DESCRIPTION(DRIVER_DESC);
16220 +MODULE_LICENSE("GPL");
16221 +module_param(loopback, bool, 0);
16222 +module_param(mii_mode, bool, 0);
16223 +module_param(devid, charp, 0);
16224 +MODULE_PARM_DESC(loopback, "Enable MAC loopback mode (bit 0)");
16225 +MODULE_PARM_DESC(mii_mode, "Enable HomePNA mode (bit 0),default=MII mode = 0");
16226 +MODULE_PARM_DESC(devid, "The format is: 'DEV_name:VendorID:DeviceID:Flags'");
16227 +
16228 +/* use ethtool to change the level for any given device */
16229 +static int msg_level = -1;
16230 +module_param(msg_level, int, 0);
16231 +MODULE_PARM_DESC(msg_level, "Override default message level");
16232 +
16233 +MODULE_DEVICE_TABLE(usb, pegasus_ids);
16234 +static const struct net_device_ops pegasus_netdev_ops;
16235 +
16236 +/*****/
16237 +
16238 +static void async_ctrl_callback(struct urb *urb)
16239 +{
16240 + struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
16241 + int status = urb->status;
16242 +
16243 + if (status < 0)
16244 + dev_dbg(&urb->dev->dev, "%s failed with %d", __func__, status);
16245 + kfree(req);
16246 + usb_free_urb(urb);
16247 +}
16248 +
16249 +static int get_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data)
16250 +{
16251 + int ret;
16252 +
16253 + ret = usb_control_msg(pegasus->usb, usb_rcvctrlpipe(pegasus->usb, 0),
16254 + PEGASUS_REQ_GET_REGS, PEGASUS_REQT_READ, 0,
16255 + indx, data, size, 1000);
16256 + if (ret < 0)
16257 + netif_dbg(pegasus, drv, pegasus->net,
16258 + "%s returned %d\n", __func__, ret);
16259 + return ret;
16260 +}
16261 +
16262 +static int set_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data)
16263 +{
16264 + int ret;
16265 +
16266 + ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0),
16267 + PEGASUS_REQ_SET_REGS, PEGASUS_REQT_WRITE, 0,
16268 + indx, data, size, 100);
16269 + if (ret < 0)
16270 + netif_dbg(pegasus, drv, pegasus->net,
16271 + "%s returned %d\n", __func__, ret);
16272 + return ret;
16273 +}
16274 +
16275 +static int set_register(pegasus_t *pegasus, __u16 indx, __u8 data)
16276 +{
16277 + int ret;
16278 +
16279 + ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0),
16280 + PEGASUS_REQ_SET_REG, PEGASUS_REQT_WRITE, data,
16281 + indx, &data, 1, 1000);
16282 + if (ret < 0)
16283 + netif_dbg(pegasus, drv, pegasus->net,
16284 + "%s returned %d\n", __func__, ret);
16285 + return ret;
16286 +}
16287 +
16288 +static int update_eth_regs_async(pegasus_t *pegasus)
16289 +{
16290 + int ret = -ENOMEM;
16291 + struct urb *async_urb;
16292 + struct usb_ctrlrequest *req;
16293 +
16294 + req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
16295 + if (req == NULL)
16296 + return ret;
16297 +
16298 + async_urb = usb_alloc_urb(0, GFP_ATOMIC);
16299 + if (async_urb == NULL) {
16300 + kfree(req);
16301 + return ret;
16302 + }
16303 + req->bRequestType = PEGASUS_REQT_WRITE;
16304 + req->bRequest = PEGASUS_REQ_SET_REGS;
16305 + req->wValue = cpu_to_le16(0);
16306 + req->wIndex = cpu_to_le16(EthCtrl0);
16307 + req->wLength = cpu_to_le16(3);
16308 +
16309 + usb_fill_control_urb(async_urb, pegasus->usb,
16310 + usb_sndctrlpipe(pegasus->usb, 0), (void *)req,
16311 + pegasus->eth_regs, 3, async_ctrl_callback, req);
16312 +
16313 + ret = usb_submit_urb(async_urb, GFP_ATOMIC);
16314 + if (ret) {
16315 + if (ret == -ENODEV)
16316 + netif_device_detach(pegasus->net);
16317 + netif_err(pegasus, drv, pegasus->net,
16318 + "%s returned %d\n", __func__, ret);
16319 + }
16320 + return ret;
16321 +}
16322 +
16323 +static int __mii_op(pegasus_t *p, __u8 phy, __u8 indx, __u16 *regd, __u8 cmd)
16324 +{
16325 + int i;
16326 + __u8 data[4] = { phy, 0, 0, indx };
16327 + __le16 regdi;
16328 + int ret = -ETIMEDOUT;
16329 +
16330 + if (cmd & PHY_WRITE) {
16331 + __le16 *t = (__le16 *) & data[1];
16332 + *t = cpu_to_le16(*regd);
16333 + }
16334 + set_register(p, PhyCtrl, 0);
16335 + set_registers(p, PhyAddr, sizeof(data), data);
16336 + set_register(p, PhyCtrl, (indx | cmd));
16337 + for (i = 0; i < REG_TIMEOUT; i++) {
16338 + ret = get_registers(p, PhyCtrl, 1, data);
16339 + if (ret < 0)
16340 + goto fail;
16341 + if (data[0] & PHY_DONE)
16342 + break;
16343 + }
16344 + if (i >= REG_TIMEOUT)
16345 + goto fail;
16346 + if (cmd & PHY_READ) {
16347 + ret = get_registers(p, PhyData, 2, &regdi);
16348 + *regd = le16_to_cpu(regdi);
16349 + return ret;
16350 + }
16351 + return 0;
16352 +fail:
16353 + netif_dbg(p, drv, p->net, "%s failed\n", __func__);
16354 + return ret;
16355 +}
16356 +
16357 +/* Returns non-negative int on success, error on failure */
16358 +static int read_mii_word(pegasus_t *pegasus, __u8 phy, __u8 indx, __u16 *regd)
16359 +{
16360 + return __mii_op(pegasus, phy, indx, regd, PHY_READ);
16361 +}
16362 +
16363 +/* Returns zero on success, error on failure */
16364 +static int write_mii_word(pegasus_t *pegasus, __u8 phy, __u8 indx, __u16 *regd)
16365 +{
16366 + return __mii_op(pegasus, phy, indx, regd, PHY_WRITE);
16367 +}
16368 +
16369 +static int mdio_read(struct net_device *dev, int phy_id, int loc)
16370 +{
16371 + pegasus_t *pegasus = netdev_priv(dev);
16372 + u16 res;
16373 +
16374 + read_mii_word(pegasus, phy_id, loc, &res);
16375 + return (int)res;
16376 +}
16377 +
16378 +static void mdio_write(struct net_device *dev, int phy_id, int loc, int val)
16379 +{
16380 + pegasus_t *pegasus = netdev_priv(dev);
16381 + u16 data = val;
16382 +
16383 + write_mii_word(pegasus, phy_id, loc, &data);
16384 +}
16385 +
16386 +static int read_eprom_word(pegasus_t *pegasus, __u8 index, __u16 *retdata)
16387 +{
16388 + int i;
16389 + __u8 tmp;
16390 + __le16 retdatai;
16391 + int ret;
16392 +
16393 + set_register(pegasus, EpromCtrl, 0);
16394 + set_register(pegasus, EpromOffset, index);
16395 + set_register(pegasus, EpromCtrl, EPROM_READ);
16396 +
16397 + for (i = 0; i < REG_TIMEOUT; i++) {
16398 + ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
16399 + if (tmp & EPROM_DONE)
16400 + break;
16401 + if (ret == -ESHUTDOWN)
16402 + goto fail;
16403 + }
16404 + if (i >= REG_TIMEOUT)
16405 + goto fail;
16406 +
16407 + ret = get_registers(pegasus, EpromData, 2, &retdatai);
16408 + *retdata = le16_to_cpu(retdatai);
16409 + return ret;
16410 +
16411 +fail:
16412 + netif_warn(pegasus, drv, pegasus->net, "%s failed\n", __func__);
16413 + return -ETIMEDOUT;
16414 +}
16415 +
16416 +#ifdef PEGASUS_WRITE_EEPROM
16417 +static inline void enable_eprom_write(pegasus_t *pegasus)
16418 +{
16419 + __u8 tmp;
16420 +
16421 + get_registers(pegasus, EthCtrl2, 1, &tmp);
16422 + set_register(pegasus, EthCtrl2, tmp | EPROM_WR_ENABLE);
16423 +}
16424 +
16425 +static inline void disable_eprom_write(pegasus_t *pegasus)
16426 +{
16427 + __u8 tmp;
16428 +
16429 + get_registers(pegasus, EthCtrl2, 1, &tmp);
16430 + set_register(pegasus, EpromCtrl, 0);
16431 + set_register(pegasus, EthCtrl2, tmp & ~EPROM_WR_ENABLE);
16432 +}
16433 +
16434 +static int write_eprom_word(pegasus_t *pegasus, __u8 index, __u16 data)
16435 +{
16436 + int i;
16437 + __u8 tmp, d[4] = { 0x3f, 0, 0, EPROM_WRITE };
16438 + int ret;
16439 + __le16 le_data = cpu_to_le16(data);
16440 +
16441 + set_registers(pegasus, EpromOffset, 4, d);
16442 + enable_eprom_write(pegasus);
16443 + set_register(pegasus, EpromOffset, index);
16444 + set_registers(pegasus, EpromData, 2, &le_data);
16445 + set_register(pegasus, EpromCtrl, EPROM_WRITE);
16446 +
16447 + for (i = 0; i < REG_TIMEOUT; i++) {
16448 + ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
16449 + if (ret == -ESHUTDOWN)
16450 + goto fail;
16451 + if (tmp & EPROM_DONE)
16452 + break;
16453 + }
16454 + disable_eprom_write(pegasus);
16455 + if (i >= REG_TIMEOUT)
16456 + goto fail;
16457 +
16458 + return ret;
16459 +
16460 +fail:
16461 + netif_warn(pegasus, drv, pegasus->net, "%s failed\n", __func__);
16462 + return -ETIMEDOUT;
16463 +}
16464 +#endif /* PEGASUS_WRITE_EEPROM */
16465 +
16466 +static inline void get_node_id(pegasus_t *pegasus, __u8 *id)
16467 +{
16468 + int i;
16469 + __u16 w16;
16470 +
16471 + for (i = 0; i < 3; i++) {
16472 + read_eprom_word(pegasus, i, &w16);
16473 + ((__le16 *) id)[i] = cpu_to_le16(w16);
16474 + }
16475 +}
16476 +
16477 +static void set_ethernet_addr(pegasus_t *pegasus)
16478 +{
16479 + __u8 node_id[6];
16480 +
16481 + if (pegasus->features & PEGASUS_II) {
16482 + get_registers(pegasus, 0x10, sizeof(node_id), node_id);
16483 + } else {
16484 + get_node_id(pegasus, node_id);
16485 + set_registers(pegasus, EthID, sizeof(node_id), node_id);
16486 + }
16487 + memcpy(pegasus->net->dev_addr, node_id, sizeof(node_id));
16488 +}
16489 +
16490 +static inline int reset_mac(pegasus_t *pegasus)
16491 +{
16492 + __u8 data = 0x8;
16493 + int i;
16494 +
16495 + set_register(pegasus, EthCtrl1, data);
16496 + for (i = 0; i < REG_TIMEOUT; i++) {
16497 + get_registers(pegasus, EthCtrl1, 1, &data);
16498 + if (~data & 0x08) {
16499 + if (loopback)
16500 + break;
16501 + if (mii_mode && (pegasus->features & HAS_HOME_PNA))
16502 + set_register(pegasus, Gpio1, 0x34);
16503 + else
16504 + set_register(pegasus, Gpio1, 0x26);
16505 + set_register(pegasus, Gpio0, pegasus->features);
16506 + set_register(pegasus, Gpio0, DEFAULT_GPIO_SET);
16507 + break;
16508 + }
16509 + }
16510 + if (i == REG_TIMEOUT)
16511 + return -ETIMEDOUT;
16512 +
16513 + if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
16514 + usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
16515 + set_register(pegasus, Gpio0, 0x24);
16516 + set_register(pegasus, Gpio0, 0x26);
16517 + }
16518 + if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_ELCON) {
16519 + __u16 auxmode;
16520 + read_mii_word(pegasus, 3, 0x1b, &auxmode);
16521 + auxmode |= 4;
16522 + write_mii_word(pegasus, 3, 0x1b, &auxmode);
16523 + }
16524 +
16525 + return 0;
16526 +}
16527 +
16528 +static int enable_net_traffic(struct net_device *dev, struct usb_device *usb)
16529 +{
16530 + __u16 linkpart;
16531 + __u8 data[4];
16532 + pegasus_t *pegasus = netdev_priv(dev);
16533 + int ret;
16534 +
16535 + read_mii_word(pegasus, pegasus->phy, MII_LPA, &linkpart);
16536 + data[0] = 0xc9;
16537 + data[1] = 0;
16538 + if (linkpart & (ADVERTISE_100FULL | ADVERTISE_10FULL))
16539 + data[1] |= 0x20; /* set full duplex */
16540 + if (linkpart & (ADVERTISE_100FULL | ADVERTISE_100HALF))
16541 + data[1] |= 0x10; /* set 100 Mbps */
16542 + if (mii_mode)
16543 + data[1] = 0;
16544 + data[2] = loopback ? 0x09 : 0x01;
16545 +
16546 + memcpy(pegasus->eth_regs, data, sizeof(data));
16547 + ret = set_registers(pegasus, EthCtrl0, 3, data);
16548 +
16549 + if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
16550 + usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS2 ||
16551 + usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
16552 + u16 auxmode;
16553 + read_mii_word(pegasus, 0, 0x1b, &auxmode);
16554 + auxmode |= 4;
16555 + write_mii_word(pegasus, 0, 0x1b, &auxmode);
16556 + }
16557 +
16558 + return ret;
16559 +}
16560 +
16561 +static void read_bulk_callback(struct urb *urb)
16562 +{
16563 + pegasus_t *pegasus = urb->context;
16564 + struct net_device *net;
16565 + int rx_status, count = urb->actual_length;
16566 + int status = urb->status;
16567 + u8 *buf = urb->transfer_buffer;
16568 + __u16 pkt_len;
16569 +
16570 + if (!pegasus)
16571 + return;
16572 +
16573 + net = pegasus->net;
16574 + if (!netif_device_present(net) || !netif_running(net))
16575 + return;
16576 +
16577 + switch (status) {
16578 + case 0:
16579 + break;
16580 + case -ETIME:
16581 + netif_dbg(pegasus, rx_err, net, "reset MAC\n");
16582 + pegasus->flags &= ~PEGASUS_RX_BUSY;
16583 + break;
16584 + case -EPIPE: /* stall, or disconnect from TT */
16585 + /* FIXME schedule work to clear the halt */
16586 + netif_warn(pegasus, rx_err, net, "no rx stall recovery\n");
16587 + return;
16588 + case -ENOENT:
16589 + case -ECONNRESET:
16590 + case -ESHUTDOWN:
16591 + netif_dbg(pegasus, ifdown, net, "rx unlink, %d\n", status);
16592 + return;
16593 + default:
16594 + netif_dbg(pegasus, rx_err, net, "RX status %d\n", status);
16595 + goto goon;
16596 + }
16597 +
16598 + if (!count || count < 4)
16599 + goto goon;
16600 +
16601 + rx_status = buf[count - 2];
16602 + if (rx_status & 0x1e) {
16603 + netif_dbg(pegasus, rx_err, net,
16604 + "RX packet error %x\n", rx_status);
16605 + pegasus->stats.rx_errors++;
16606 + if (rx_status & 0x06) /* long or runt */
16607 + pegasus->stats.rx_length_errors++;
16608 + if (rx_status & 0x08)
16609 + pegasus->stats.rx_crc_errors++;
16610 + if (rx_status & 0x10) /* extra bits */
16611 + pegasus->stats.rx_frame_errors++;
16612 + goto goon;
16613 + }
16614 + if (pegasus->chip == 0x8513) {
16615 + pkt_len = le32_to_cpu(*(__le32 *)urb->transfer_buffer);
16616 + pkt_len &= 0x0fff;
16617 + pegasus->rx_skb->data += 2;
16618 + } else {
16619 + pkt_len = buf[count - 3] << 8;
16620 + pkt_len += buf[count - 4];
16621 + pkt_len &= 0xfff;
16622 + pkt_len -= 8;
16623 + }
16624 +
16625 + /*
16626 + * If the packet is unreasonably long, quietly drop it rather than
16627 + * kernel panicing by calling skb_put.
16628 + */
16629 + if (pkt_len > PEGASUS_MTU)
16630 + goto goon;
16631 +
16632 + /*
16633 + * at this point we are sure pegasus->rx_skb != NULL
16634 + * so we go ahead and pass up the packet.
16635 + */
16636 + skb_put(pegasus->rx_skb, pkt_len);
16637 + pegasus->rx_skb->protocol = eth_type_trans(pegasus->rx_skb, net);
16638 + netif_rx(pegasus->rx_skb);
16639 + pegasus->stats.rx_packets++;
16640 + pegasus->stats.rx_bytes += pkt_len;
16641 +
16642 + if (pegasus->flags & PEGASUS_UNPLUG)
16643 + return;
16644 +
16645 + pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net, PEGASUS_MTU,
16646 + GFP_ATOMIC);
16647 +
16648 + if (pegasus->rx_skb == NULL)
16649 + goto tl_sched;
16650 +goon:
16651 + usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
16652 + usb_rcvbulkpipe(pegasus->usb, 1),
16653 + pegasus->rx_skb->data, PEGASUS_MTU + 8,
16654 + read_bulk_callback, pegasus);
16655 + rx_status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC);
16656 + if (rx_status == -ENODEV)
16657 + netif_device_detach(pegasus->net);
16658 + else if (rx_status) {
16659 + pegasus->flags |= PEGASUS_RX_URB_FAIL;
16660 + goto tl_sched;
16661 + } else {
16662 + pegasus->flags &= ~PEGASUS_RX_URB_FAIL;
16663 + }
16664 +
16665 + return;
16666 +
16667 +tl_sched:
16668 + tasklet_schedule(&pegasus->rx_tl);
16669 +}
16670 +
16671 +static void rx_fixup(unsigned long data)
16672 +{
16673 + pegasus_t *pegasus;
16674 + int status;
16675 +
16676 + pegasus = (pegasus_t *) data;
16677 + if (pegasus->flags & PEGASUS_UNPLUG)
16678 + return;
16679 +
16680 + if (pegasus->flags & PEGASUS_RX_URB_FAIL)
16681 + if (pegasus->rx_skb)
16682 + goto try_again;
16683 + if (pegasus->rx_skb == NULL)
16684 + pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net,
16685 + PEGASUS_MTU,
16686 + GFP_ATOMIC);
16687 + if (pegasus->rx_skb == NULL) {
16688 + netif_warn(pegasus, rx_err, pegasus->net, "low on memory\n");
16689 + tasklet_schedule(&pegasus->rx_tl);
16690 + return;
16691 + }
16692 + usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
16693 + usb_rcvbulkpipe(pegasus->usb, 1),
16694 + pegasus->rx_skb->data, PEGASUS_MTU + 8,
16695 + read_bulk_callback, pegasus);
16696 +try_again:
16697 + status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC);
16698 + if (status == -ENODEV)
16699 + netif_device_detach(pegasus->net);
16700 + else if (status) {
16701 + pegasus->flags |= PEGASUS_RX_URB_FAIL;
16702 + tasklet_schedule(&pegasus->rx_tl);
16703 + } else {
16704 + pegasus->flags &= ~PEGASUS_RX_URB_FAIL;
16705 + }
16706 +}
16707 +
16708 +static void write_bulk_callback(struct urb *urb)
16709 +{
16710 + pegasus_t *pegasus = urb->context;
16711 + struct net_device *net;
16712 + int status = urb->status;
16713 +
16714 + if (!pegasus)
16715 + return;
16716 +
16717 + net = pegasus->net;
16718 +
16719 + if (!netif_device_present(net) || !netif_running(net))
16720 + return;
16721 +
16722 + switch (status) {
16723 + case -EPIPE:
16724 + /* FIXME schedule_work() to clear the tx halt */
16725 + netif_stop_queue(net);
16726 + netif_warn(pegasus, tx_err, net, "no tx stall recovery\n");
16727 + return;
16728 + case -ENOENT:
16729 + case -ECONNRESET:
16730 + case -ESHUTDOWN:
16731 + netif_dbg(pegasus, ifdown, net, "tx unlink, %d\n", status);
16732 + return;
16733 + default:
16734 + netif_info(pegasus, tx_err, net, "TX status %d\n", status);
16735 + /* FALL THROUGH */
16736 + case 0:
16737 + break;
16738 + }
16739 +
16740 + net->trans_start = jiffies; /* prevent tx timeout */
16741 + netif_wake_queue(net);
16742 +}
16743 +
16744 +static void intr_callback(struct urb *urb)
16745 +{
16746 + pegasus_t *pegasus = urb->context;
16747 + struct net_device *net;
16748 + int res, status = urb->status;
16749 +
16750 + if (!pegasus)
16751 + return;
16752 + net = pegasus->net;
16753 +
16754 + switch (status) {
16755 + case 0:
16756 + break;
16757 + case -ECONNRESET: /* unlink */
16758 + case -ENOENT:
16759 + case -ESHUTDOWN:
16760 + return;
16761 + default:
16762 + /* some Pegasus-I products report LOTS of data
16763 + * toggle errors... avoid log spamming
16764 + */
16765 + netif_dbg(pegasus, timer, net, "intr status %d\n", status);
16766 + }
16767 +
16768 + if (urb->actual_length >= 6) {
16769 + u8 *d = urb->transfer_buffer;
16770 +
16771 + /* byte 0 == tx_status1, reg 2B */
16772 + if (d[0] & (TX_UNDERRUN|EXCESSIVE_COL
16773 + |LATE_COL|JABBER_TIMEOUT)) {
16774 + pegasus->stats.tx_errors++;
16775 + if (d[0] & TX_UNDERRUN)
16776 + pegasus->stats.tx_fifo_errors++;
16777 + if (d[0] & (EXCESSIVE_COL | JABBER_TIMEOUT))
16778 + pegasus->stats.tx_aborted_errors++;
16779 + if (d[0] & LATE_COL)
16780 + pegasus->stats.tx_window_errors++;
16781 + }
16782 +
16783 + /* d[5].LINK_STATUS lies on some adapters.
16784 + * d[0].NO_CARRIER kicks in only with failed TX.
16785 + * ... so monitoring with MII may be safest.
16786 + */
16787 +
16788 + /* bytes 3-4 == rx_lostpkt, reg 2E/2F */
16789 + pegasus->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4];
16790 + }
16791 +
16792 + res = usb_submit_urb(urb, GFP_ATOMIC);
16793 + if (res == -ENODEV)
16794 + netif_device_detach(pegasus->net);
16795 + if (res)
16796 + netif_err(pegasus, timer, net,
16797 + "can't resubmit interrupt urb, %d\n", res);
16798 +}
16799 +
16800 +static void pegasus_tx_timeout(struct net_device *net)
16801 +{
16802 + pegasus_t *pegasus = netdev_priv(net);
16803 + netif_warn(pegasus, timer, net, "tx timeout\n");
16804 + usb_unlink_urb(pegasus->tx_urb);
16805 + pegasus->stats.tx_errors++;
16806 +}
16807 +
16808 +static netdev_tx_t pegasus_start_xmit(struct sk_buff *skb,
16809 + struct net_device *net)
16810 +{
16811 + pegasus_t *pegasus = netdev_priv(net);
16812 + int count = ((skb->len + 2) & 0x3f) ? skb->len + 2 : skb->len + 3;
16813 + int res;
16814 + __u16 l16 = skb->len;
16815 +
16816 + netif_stop_queue(net);
16817 +
16818 + ((__le16 *) pegasus->tx_buff)[0] = cpu_to_le16(l16);
16819 + skb_copy_from_linear_data(skb, pegasus->tx_buff + 2, skb->len);
16820 + usb_fill_bulk_urb(pegasus->tx_urb, pegasus->usb,
16821 + usb_sndbulkpipe(pegasus->usb, 2),
16822 + pegasus->tx_buff, count,
16823 + write_bulk_callback, pegasus);
16824 + if ((res = usb_submit_urb(pegasus->tx_urb, GFP_ATOMIC))) {
16825 + netif_warn(pegasus, tx_err, net, "fail tx, %d\n", res);
16826 + switch (res) {
16827 + case -EPIPE: /* stall, or disconnect from TT */
16828 + /* cleanup should already have been scheduled */
16829 + break;
16830 + case -ENODEV: /* disconnect() upcoming */
16831 + case -EPERM:
16832 + netif_device_detach(pegasus->net);
16833 + break;
16834 + default:
16835 + pegasus->stats.tx_errors++;
16836 + netif_start_queue(net);
16837 + }
16838 + } else {
16839 + pegasus->stats.tx_packets++;
16840 + pegasus->stats.tx_bytes += skb->len;
16841 + }
16842 + dev_kfree_skb(skb);
16843 +
16844 + return NETDEV_TX_OK;
16845 +}
16846 +
16847 +static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev)
16848 +{
16849 + return &((pegasus_t *) netdev_priv(dev))->stats;
16850 +}
16851 +
16852 +static inline void disable_net_traffic(pegasus_t *pegasus)
16853 +{
16854 + __le16 tmp = cpu_to_le16(0);
16855 +
16856 + set_registers(pegasus, EthCtrl0, sizeof(tmp), &tmp);
16857 +}
16858 +
16859 +static inline void get_interrupt_interval(pegasus_t *pegasus)
16860 +{
16861 + u16 data;
16862 + u8 interval;
16863 +
16864 + read_eprom_word(pegasus, 4, &data);
16865 + interval = data >> 8;
16866 + if (pegasus->usb->speed != USB_SPEED_HIGH) {
16867 + if (interval < 0x80) {
16868 + netif_info(pegasus, timer, pegasus->net,
16869 + "intr interval changed from %ums to %ums\n",
16870 + interval, 0x80);
16871 + interval = 0x80;
16872 + data = (data & 0x00FF) | ((u16)interval << 8);
16873 +#ifdef PEGASUS_WRITE_EEPROM
16874 + write_eprom_word(pegasus, 4, data);
16875 +#endif
16876 + }
16877 + }
16878 + pegasus->intr_interval = interval;
16879 +}
16880 +
16881 +static void set_carrier(struct net_device *net)
16882 +{
16883 + pegasus_t *pegasus = netdev_priv(net);
16884 + u16 tmp;
16885 +
16886 + if (read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp))
16887 + return;
16888 +
16889 + if (tmp & BMSR_LSTATUS)
16890 + netif_carrier_on(net);
16891 + else
16892 + netif_carrier_off(net);
16893 +}
16894 +
16895 +static void free_all_urbs(pegasus_t *pegasus)
16896 +{
16897 + usb_free_urb(pegasus->intr_urb);
16898 + usb_free_urb(pegasus->tx_urb);
16899 + usb_free_urb(pegasus->rx_urb);
16900 +}
16901 +
16902 +static void unlink_all_urbs(pegasus_t *pegasus)
16903 +{
16904 + usb_kill_urb(pegasus->intr_urb);
16905 + usb_kill_urb(pegasus->tx_urb);
16906 + usb_kill_urb(pegasus->rx_urb);
16907 +}
16908 +
16909 +static int alloc_urbs(pegasus_t *pegasus)
16910 +{
16911 + int res = -ENOMEM;
16912 +
16913 + pegasus->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
16914 + if (!pegasus->rx_urb) {
16915 + return res;
16916 + }
16917 + pegasus->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
16918 + if (!pegasus->tx_urb) {
16919 + usb_free_urb(pegasus->rx_urb);
16920 + return res;
16921 + }
16922 + pegasus->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
16923 + if (!pegasus->intr_urb) {
16924 + usb_free_urb(pegasus->tx_urb);
16925 + usb_free_urb(pegasus->rx_urb);
16926 + return res;
16927 + }
16928 +
16929 + return 0;
16930 +}
16931 +
16932 +static int pegasus_open(struct net_device *net)
16933 +{
16934 + pegasus_t *pegasus = netdev_priv(net);
16935 + int res=-ENOMEM;
16936 +
16937 + if (pegasus->rx_skb == NULL)
16938 + pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net,
16939 + PEGASUS_MTU,
16940 + GFP_KERNEL);
16941 + if (!pegasus->rx_skb)
16942 + goto exit;
16943 +
16944 + res = set_registers(pegasus, EthID, 6, net->dev_addr);
16945 +
16946 + usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
16947 + usb_rcvbulkpipe(pegasus->usb, 1),
16948 + pegasus->rx_skb->data, PEGASUS_MTU + 8,
16949 + read_bulk_callback, pegasus);
16950 + if ((res = usb_submit_urb(pegasus->rx_urb, GFP_KERNEL))) {
16951 + if (res == -ENODEV)
16952 + netif_device_detach(pegasus->net);
16953 + netif_dbg(pegasus, ifup, net, "failed rx_urb, %d\n", res);
16954 + goto exit;
16955 + }
16956 +
16957 + usb_fill_int_urb(pegasus->intr_urb, pegasus->usb,
16958 + usb_rcvintpipe(pegasus->usb, 3),
16959 + pegasus->intr_buff, sizeof(pegasus->intr_buff),
16960 + intr_callback, pegasus, pegasus->intr_interval);
16961 + if ((res = usb_submit_urb(pegasus->intr_urb, GFP_KERNEL))) {
16962 + if (res == -ENODEV)
16963 + netif_device_detach(pegasus->net);
16964 + netif_dbg(pegasus, ifup, net, "failed intr_urb, %d\n", res);
16965 + usb_kill_urb(pegasus->rx_urb);
16966 + goto exit;
16967 + }
16968 + res = enable_net_traffic(net, pegasus->usb);
16969 + if (res < 0) {
16970 + netif_dbg(pegasus, ifup, net,
16971 + "can't enable_net_traffic() - %d\n", res);
16972 + res = -EIO;
16973 + usb_kill_urb(pegasus->rx_urb);
16974 + usb_kill_urb(pegasus->intr_urb);
16975 + goto exit;
16976 + }
16977 + set_carrier(net);
16978 + netif_start_queue(net);
16979 + netif_dbg(pegasus, ifup, net, "open\n");
16980 + res = 0;
16981 +exit:
16982 + return res;
16983 +}
16984 +
16985 +static int pegasus_close(struct net_device *net)
16986 +{
16987 + pegasus_t *pegasus = netdev_priv(net);
16988 +
16989 + netif_stop_queue(net);
16990 + if (!(pegasus->flags & PEGASUS_UNPLUG))
16991 + disable_net_traffic(pegasus);
16992 + tasklet_kill(&pegasus->rx_tl);
16993 + unlink_all_urbs(pegasus);
16994 +
16995 + return 0;
16996 +}
16997 +
16998 +static void pegasus_get_drvinfo(struct net_device *dev,
16999 + struct ethtool_drvinfo *info)
17000 +{
17001 + pegasus_t *pegasus = netdev_priv(dev);
17002 +
17003 + strlcpy(info->driver, driver_name, sizeof(info->driver));
17004 + strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
17005 + usb_make_path(pegasus->usb, info->bus_info, sizeof(info->bus_info));
17006 +}
17007 +
17008 +/* also handles three patterns of some kind in hardware */
17009 +#define WOL_SUPPORTED (WAKE_MAGIC|WAKE_PHY)
17010 +
17011 +static void
17012 +pegasus_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
17013 +{
17014 + pegasus_t *pegasus = netdev_priv(dev);
17015 +
17016 + wol->supported = WAKE_MAGIC | WAKE_PHY;
17017 + wol->wolopts = pegasus->wolopts;
17018 +}
17019 +
17020 +static int
17021 +pegasus_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
17022 +{
17023 + pegasus_t *pegasus = netdev_priv(dev);
17024 + u8 reg78 = 0x04;
17025 + int ret;
17026 +
17027 + if (wol->wolopts & ~WOL_SUPPORTED)
17028 + return -EINVAL;
17029 +
17030 + if (wol->wolopts & WAKE_MAGIC)
17031 + reg78 |= 0x80;
17032 + if (wol->wolopts & WAKE_PHY)
17033 + reg78 |= 0x40;
17034 + /* FIXME this 0x10 bit still needs to get set in the chip... */
17035 + if (wol->wolopts)
17036 + pegasus->eth_regs[0] |= 0x10;
17037 + else
17038 + pegasus->eth_regs[0] &= ~0x10;
17039 + pegasus->wolopts = wol->wolopts;
17040 +
17041 + ret = set_register(pegasus, WakeupControl, reg78);
17042 + if (!ret)
17043 + ret = device_set_wakeup_enable(&pegasus->usb->dev,
17044 + wol->wolopts);
17045 + return ret;
17046 +}
17047 +
17048 +static inline void pegasus_reset_wol(struct net_device *dev)
17049 +{
17050 + struct ethtool_wolinfo wol;
17051 +
17052 + memset(&wol, 0, sizeof wol);
17053 + (void) pegasus_set_wol(dev, &wol);
17054 +}
17055 +
17056 +static int
17057 +pegasus_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
17058 +{
17059 + pegasus_t *pegasus;
17060 +
17061 + pegasus = netdev_priv(dev);
17062 + mii_ethtool_gset(&pegasus->mii, ecmd);
17063 + return 0;
17064 +}
17065 +
17066 +static int
17067 +pegasus_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
17068 +{
17069 + pegasus_t *pegasus = netdev_priv(dev);
17070 + return mii_ethtool_sset(&pegasus->mii, ecmd);
17071 +}
17072 +
17073 +static int pegasus_nway_reset(struct net_device *dev)
17074 +{
17075 + pegasus_t *pegasus = netdev_priv(dev);
17076 + return mii_nway_restart(&pegasus->mii);
17077 +}
17078 +
17079 +static u32 pegasus_get_link(struct net_device *dev)
17080 +{
17081 + pegasus_t *pegasus = netdev_priv(dev);
17082 + return mii_link_ok(&pegasus->mii);
17083 +}
17084 +
17085 +static u32 pegasus_get_msglevel(struct net_device *dev)
17086 +{
17087 + pegasus_t *pegasus = netdev_priv(dev);
17088 + return pegasus->msg_enable;
17089 +}
17090 +
17091 +static void pegasus_set_msglevel(struct net_device *dev, u32 v)
17092 +{
17093 + pegasus_t *pegasus = netdev_priv(dev);
17094 + pegasus->msg_enable = v;
17095 +}
17096 +
17097 +static const struct ethtool_ops ops = {
17098 + .get_drvinfo = pegasus_get_drvinfo,
17099 + .get_settings = pegasus_get_settings,
17100 + .set_settings = pegasus_set_settings,
17101 + .nway_reset = pegasus_nway_reset,
17102 + .get_link = pegasus_get_link,
17103 + .get_msglevel = pegasus_get_msglevel,
17104 + .set_msglevel = pegasus_set_msglevel,
17105 + .get_wol = pegasus_get_wol,
17106 + .set_wol = pegasus_set_wol,
17107 +};
17108 +
17109 +static int pegasus_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
17110 +{
17111 + __u16 *data = (__u16 *) &rq->ifr_ifru;
17112 + pegasus_t *pegasus = netdev_priv(net);
17113 + int res;
17114 +
17115 + switch (cmd) {
17116 + case SIOCDEVPRIVATE:
17117 + data[0] = pegasus->phy;
17118 + case SIOCDEVPRIVATE + 1:
17119 + read_mii_word(pegasus, data[0], data[1] & 0x1f, &data[3]);
17120 + res = 0;
17121 + break;
17122 + case SIOCDEVPRIVATE + 2:
17123 + if (!capable(CAP_NET_ADMIN))
17124 + return -EPERM;
17125 + write_mii_word(pegasus, pegasus->phy, data[1] & 0x1f, &data[2]);
17126 + res = 0;
17127 + break;
17128 + default:
17129 + res = -EOPNOTSUPP;
17130 + }
17131 + return res;
17132 +}
17133 +
17134 +static void pegasus_set_multicast(struct net_device *net)
17135 +{
17136 + pegasus_t *pegasus = netdev_priv(net);
17137 +
17138 + if (net->flags & IFF_PROMISC) {
17139 + pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS;
17140 + netif_info(pegasus, link, net, "Promiscuous mode enabled\n");
17141 + } else if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI)) {
17142 + pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST;
17143 + pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
17144 + netif_dbg(pegasus, link, net, "set allmulti\n");
17145 + } else {
17146 + pegasus->eth_regs[EthCtrl0] &= ~RX_MULTICAST;
17147 + pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
17148 + }
17149 + update_eth_regs_async(pegasus);
17150 +}
17151 +
17152 +static __u8 mii_phy_probe(pegasus_t *pegasus)
17153 +{
17154 + int i;
17155 + __u16 tmp;
17156 +
17157 + for (i = 0; i < 32; i++) {
17158 + read_mii_word(pegasus, i, MII_BMSR, &tmp);
17159 + if (tmp == 0 || tmp == 0xffff || (tmp & BMSR_MEDIA) == 0)
17160 + continue;
17161 + else
17162 + return i;
17163 + }
17164 +
17165 + return 0xff;
17166 +}
17167 +
17168 +static inline void setup_pegasus_II(pegasus_t *pegasus)
17169 +{
17170 + __u8 data = 0xa5;
17171 +
17172 + set_register(pegasus, Reg1d, 0);
17173 + set_register(pegasus, Reg7b, 1);
17174 + mdelay(100);
17175 + if ((pegasus->features & HAS_HOME_PNA) && mii_mode)
17176 + set_register(pegasus, Reg7b, 0);
17177 + else
17178 + set_register(pegasus, Reg7b, 2);
17179 +
17180 + set_register(pegasus, 0x83, data);
17181 + get_registers(pegasus, 0x83, 1, &data);
17182 +
17183 + if (data == 0xa5)
17184 + pegasus->chip = 0x8513;
17185 + else
17186 + pegasus->chip = 0;
17187 +
17188 + set_register(pegasus, 0x80, 0xc0);
17189 + set_register(pegasus, 0x83, 0xff);
17190 + set_register(pegasus, 0x84, 0x01);
17191 +
17192 + if (pegasus->features & HAS_HOME_PNA && mii_mode)
17193 + set_register(pegasus, Reg81, 6);
17194 + else
17195 + set_register(pegasus, Reg81, 2);
17196 +}
17197 +
17198 +
17199 +static int pegasus_count;
17200 +static struct workqueue_struct *pegasus_workqueue;
17201 +#define CARRIER_CHECK_DELAY (2 * HZ)
17202 +
17203 +static void check_carrier(struct work_struct *work)
17204 +{
17205 + pegasus_t *pegasus = container_of(work, pegasus_t, carrier_check.work);
17206 + set_carrier(pegasus->net);
17207 + if (!(pegasus->flags & PEGASUS_UNPLUG)) {
17208 + queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
17209 + CARRIER_CHECK_DELAY);
17210 + }
17211 +}
17212 +
17213 +static int pegasus_blacklisted(struct usb_device *udev)
17214 +{
17215 + struct usb_device_descriptor *udd = &udev->descriptor;
17216 +
17217 + /* Special quirk to keep the driver from handling the Belkin Bluetooth
17218 + * dongle which happens to have the same ID.
17219 + */
17220 + if ((udd->idVendor == cpu_to_le16(VENDOR_BELKIN)) &&
17221 + (udd->idProduct == cpu_to_le16(0x0121)) &&
17222 + (udd->bDeviceClass == USB_CLASS_WIRELESS_CONTROLLER) &&
17223 + (udd->bDeviceProtocol == 1))
17224 + return 1;
17225 +
17226 + return 0;
17227 +}
17228 +
17229 +/* we rely on probe() and remove() being serialized so we
17230 + * don't need extra locking on pegasus_count.
17231 + */
17232 +static void pegasus_dec_workqueue(void)
17233 +{
17234 + pegasus_count--;
17235 + if (pegasus_count == 0) {
17236 + destroy_workqueue(pegasus_workqueue);
17237 + pegasus_workqueue = NULL;
17238 + }
17239 +}
17240 +
17241 +static int pegasus_probe(struct usb_interface *intf,
17242 + const struct usb_device_id *id)
17243 +{
17244 + struct usb_device *dev = interface_to_usbdev(intf);
17245 + struct net_device *net;
17246 + pegasus_t *pegasus;
17247 + int dev_index = id - pegasus_ids;
17248 + int res = -ENOMEM;
17249 +
17250 + if (pegasus_blacklisted(dev))
17251 + return -ENODEV;
17252 +
17253 + if (pegasus_count == 0) {
17254 + pegasus_workqueue = create_singlethread_workqueue("pegasus");
17255 + if (!pegasus_workqueue)
17256 + return -ENOMEM;
17257 + }
17258 + pegasus_count++;
17259 +
17260 + net = alloc_etherdev(sizeof(struct pegasus));
17261 + if (!net)
17262 + goto out;
17263 +
17264 + pegasus = netdev_priv(net);
17265 + pegasus->dev_index = dev_index;
17266 +
17267 + res = alloc_urbs(pegasus);
17268 + if (res < 0) {
17269 + dev_err(&intf->dev, "can't allocate %s\n", "urbs");
17270 + goto out1;
17271 + }
17272 +
17273 + tasklet_init(&pegasus->rx_tl, rx_fixup, (unsigned long) pegasus);
17274 +
17275 + INIT_DELAYED_WORK(&pegasus->carrier_check, check_carrier);
17276 +
17277 + pegasus->intf = intf;
17278 + pegasus->usb = dev;
17279 + pegasus->net = net;
17280 +
17281 +
17282 + net->watchdog_timeo = PEGASUS_TX_TIMEOUT;
17283 + net->netdev_ops = &pegasus_netdev_ops;
17284 + net->ethtool_ops = &ops;
17285 + pegasus->mii.dev = net;
17286 + pegasus->mii.mdio_read = mdio_read;
17287 + pegasus->mii.mdio_write = mdio_write;
17288 + pegasus->mii.phy_id_mask = 0x1f;
17289 + pegasus->mii.reg_num_mask = 0x1f;
17290 + pegasus->msg_enable = netif_msg_init(msg_level, NETIF_MSG_DRV
17291 + | NETIF_MSG_PROBE | NETIF_MSG_LINK);
17292 +
17293 + pegasus->features = usb_dev_id[dev_index].private;
17294 + get_interrupt_interval(pegasus);
17295 + if (reset_mac(pegasus)) {
17296 + dev_err(&intf->dev, "can't reset MAC\n");
17297 + res = -EIO;
17298 + goto out2;
17299 + }
17300 + set_ethernet_addr(pegasus);
17301 + if (pegasus->features & PEGASUS_II) {
17302 + dev_info(&intf->dev, "setup Pegasus II specific registers\n");
17303 + setup_pegasus_II(pegasus);
17304 + }
17305 + pegasus->phy = mii_phy_probe(pegasus);
17306 + if (pegasus->phy == 0xff) {
17307 + dev_warn(&intf->dev, "can't locate MII phy, using default\n");
17308 + pegasus->phy = 1;
17309 + }
17310 + pegasus->mii.phy_id = pegasus->phy;
17311 + usb_set_intfdata(intf, pegasus);
17312 + SET_NETDEV_DEV(net, &intf->dev);
17313 + pegasus_reset_wol(net);
17314 + res = register_netdev(net);
17315 + if (res)
17316 + goto out3;
17317 + queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
17318 + CARRIER_CHECK_DELAY);
17319 + dev_info(&intf->dev, "%s, %s, %pM\n", net->name,
17320 + usb_dev_id[dev_index].name, net->dev_addr);
17321 + return 0;
17322 +
17323 +out3:
17324 + usb_set_intfdata(intf, NULL);
17325 +out2:
17326 + free_all_urbs(pegasus);
17327 +out1:
17328 + free_netdev(net);
17329 +out:
17330 + pegasus_dec_workqueue();
17331 + return res;
17332 +}
17333 +
17334 +static void pegasus_disconnect(struct usb_interface *intf)
17335 +{
17336 + struct pegasus *pegasus = usb_get_intfdata(intf);
17337 +
17338 + usb_set_intfdata(intf, NULL);
17339 + if (!pegasus) {
17340 + dev_dbg(&intf->dev, "unregistering non-bound device?\n");
17341 + return;
17342 + }
17343 +
17344 + pegasus->flags |= PEGASUS_UNPLUG;
17345 + cancel_delayed_work(&pegasus->carrier_check);
17346 + unregister_netdev(pegasus->net);
17347 + unlink_all_urbs(pegasus);
17348 + free_all_urbs(pegasus);
17349 + if (pegasus->rx_skb != NULL) {
17350 + dev_kfree_skb(pegasus->rx_skb);
17351 + pegasus->rx_skb = NULL;
17352 + }
17353 + free_netdev(pegasus->net);
17354 + pegasus_dec_workqueue();
17355 +}
17356 +
17357 +static int pegasus_suspend(struct usb_interface *intf, pm_message_t message)
17358 +{
17359 + struct pegasus *pegasus = usb_get_intfdata(intf);
17360 +
17361 + netif_device_detach(pegasus->net);
17362 + cancel_delayed_work(&pegasus->carrier_check);
17363 + if (netif_running(pegasus->net)) {
17364 + usb_kill_urb(pegasus->rx_urb);
17365 + usb_kill_urb(pegasus->intr_urb);
17366 + }
17367 + return 0;
17368 +}
17369 +
17370 +static int pegasus_resume(struct usb_interface *intf)
17371 +{
17372 + struct pegasus *pegasus = usb_get_intfdata(intf);
17373 +
17374 + netif_device_attach(pegasus->net);
17375 + if (netif_running(pegasus->net)) {
17376 + pegasus->rx_urb->status = 0;
17377 + pegasus->rx_urb->actual_length = 0;
17378 + read_bulk_callback(pegasus->rx_urb);
17379 +
17380 + pegasus->intr_urb->status = 0;
17381 + pegasus->intr_urb->actual_length = 0;
17382 + intr_callback(pegasus->intr_urb);
17383 + }
17384 + queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
17385 + CARRIER_CHECK_DELAY);
17386 + return 0;
17387 +}
17388 +
17389 +static const struct net_device_ops pegasus_netdev_ops = {
17390 + .ndo_open = pegasus_open,
17391 + .ndo_stop = pegasus_close,
17392 + .ndo_do_ioctl = pegasus_ioctl,
17393 + .ndo_start_xmit = pegasus_start_xmit,
17394 + .ndo_set_rx_mode = pegasus_set_multicast,
17395 + .ndo_get_stats = pegasus_netdev_stats,
17396 + .ndo_tx_timeout = pegasus_tx_timeout,
17397 + .ndo_change_mtu = eth_change_mtu,
17398 + .ndo_set_mac_address = eth_mac_addr,
17399 + .ndo_validate_addr = eth_validate_addr,
17400 +};
17401 +
17402 +static struct usb_driver pegasus_driver = {
17403 + .name = driver_name,
17404 + .probe = pegasus_probe,
17405 + .disconnect = pegasus_disconnect,
17406 + .id_table = pegasus_ids,
17407 + .suspend = pegasus_suspend,
17408 + .resume = pegasus_resume,
17409 + .disable_hub_initiated_lpm = 1,
17410 +};
17411 +
17412 +static void __init parse_id(char *id)
17413 +{
17414 + unsigned int vendor_id = 0, device_id = 0, flags = 0, i = 0;
17415 + char *token, *name = NULL;
17416 +
17417 + if ((token = strsep(&id, ":")) != NULL)
17418 + name = token;
17419 + /* name now points to a null terminated string*/
17420 + if ((token = strsep(&id, ":")) != NULL)
17421 + vendor_id = simple_strtoul(token, NULL, 16);
17422 + if ((token = strsep(&id, ":")) != NULL)
17423 + device_id = simple_strtoul(token, NULL, 16);
17424 + flags = simple_strtoul(id, NULL, 16);
17425 + pr_info("%s: new device %s, vendor ID 0x%04x, device ID 0x%04x, flags: 0x%x\n",
17426 + driver_name, name, vendor_id, device_id, flags);
17427 +
17428 + if (vendor_id > 0x10000 || vendor_id == 0)
17429 + return;
17430 + if (device_id > 0x10000 || device_id == 0)
17431 + return;
17432 +
17433 + for (i = 0; usb_dev_id[i].name; i++);
17434 + usb_dev_id[i].name = name;
17435 + usb_dev_id[i].vendor = vendor_id;
17436 + usb_dev_id[i].device = device_id;
17437 + usb_dev_id[i].private = flags;
17438 + pegasus_ids[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
17439 + pegasus_ids[i].idVendor = vendor_id;
17440 + pegasus_ids[i].idProduct = device_id;
17441 +}
17442 +
17443 +static int __init pegasus_init(void)
17444 +{
17445 + pr_info("%s: %s, " DRIVER_DESC "\n", driver_name, DRIVER_VERSION);
17446 + if (devid)
17447 + parse_id(devid);
17448 + return usb_register(&pegasus_driver);
17449 +}
17450 +
17451 +static void __exit pegasus_exit(void)
17452 +{
17453 + usb_deregister(&pegasus_driver);
17454 +}
17455 +
17456 +module_init(pegasus_init);
17457 +module_exit(pegasus_exit);
17458 diff -Naur backports-4.2.6-1.org/drivers/net/usb/pegasus.h backports-4.2.6-1/drivers/net/usb/pegasus.h
17459 --- backports-4.2.6-1.org/drivers/net/usb/pegasus.h 1970-01-01 01:00:00.000000000 +0100
17460 +++ backports-4.2.6-1/drivers/net/usb/pegasus.h 2016-06-28 14:35:17.998640551 +0200
17461 @@ -0,0 +1,308 @@
17462 +/*
17463 + * Copyright (c) 1999-2013 Petko Manolov (petkan@nucleusys.com)
17464 + *
17465 + * This program is free software; you can redistribute it and/or modify
17466 + * it under the terms of the GNU General Public License version 2 as published
17467 + * by the Free Software Foundation.
17468 + */
17469 +
17470 +
17471 +#ifndef PEGASUS_DEV
17472 +
17473 +#define PEGASUS_II 0x80000000
17474 +#define HAS_HOME_PNA 0x40000000
17475 +
17476 +#define PEGASUS_MTU 1536
17477 +
17478 +#define EPROM_WRITE 0x01
17479 +#define EPROM_READ 0x02
17480 +#define EPROM_DONE 0x04
17481 +#define EPROM_WR_ENABLE 0x10
17482 +#define EPROM_LOAD 0x20
17483 +
17484 +#define PHY_DONE 0x80
17485 +#define PHY_READ 0x40
17486 +#define PHY_WRITE 0x20
17487 +#define DEFAULT_GPIO_RESET 0x24
17488 +#define DEFAULT_GPIO_SET 0x26
17489 +
17490 +#define PEGASUS_PRESENT 0x00000001
17491 +#define PEGASUS_TX_BUSY 0x00000004
17492 +#define PEGASUS_RX_BUSY 0x00000008
17493 +#define CTRL_URB_RUNNING 0x00000010
17494 +#define CTRL_URB_SLEEP 0x00000020
17495 +#define PEGASUS_UNPLUG 0x00000040
17496 +#define PEGASUS_RX_URB_FAIL 0x00000080
17497 +
17498 +#define RX_MULTICAST 2
17499 +#define RX_PROMISCUOUS 4
17500 +
17501 +#define REG_TIMEOUT (HZ)
17502 +#define PEGASUS_TX_TIMEOUT (HZ*10)
17503 +
17504 +#define TX_UNDERRUN 0x80
17505 +#define EXCESSIVE_COL 0x40
17506 +#define LATE_COL 0x20
17507 +#define NO_CARRIER 0x10
17508 +#define LOSS_CARRIER 0x08
17509 +#define JABBER_TIMEOUT 0x04
17510 +
17511 +#define LINK_STATUS 0x01
17512 +
17513 +#define PEGASUS_REQT_READ 0xc0
17514 +#define PEGASUS_REQT_WRITE 0x40
17515 +#define PEGASUS_REQ_GET_REGS 0xf0
17516 +#define PEGASUS_REQ_SET_REGS 0xf1
17517 +#define PEGASUS_REQ_SET_REG PEGASUS_REQ_SET_REGS
17518 +
17519 +enum pegasus_registers {
17520 + EthCtrl0 = 0,
17521 + EthCtrl1 = 1,
17522 + EthCtrl2 = 2,
17523 + EthID = 0x10,
17524 + Reg1d = 0x1d,
17525 + EpromOffset = 0x20,
17526 + EpromData = 0x21, /* 0x21 low, 0x22 high byte */
17527 + EpromCtrl = 0x23,
17528 + PhyAddr = 0x25,
17529 + PhyData = 0x26, /* 0x26 low, 0x27 high byte */
17530 + PhyCtrl = 0x28,
17531 + UsbStst = 0x2a,
17532 + EthTxStat0 = 0x2b,
17533 + EthTxStat1 = 0x2c,
17534 + EthRxStat = 0x2d,
17535 + WakeupControl = 0x78,
17536 + Reg7b = 0x7b,
17537 + Gpio0 = 0x7e,
17538 + Gpio1 = 0x7f,
17539 + Reg81 = 0x81,
17540 +};
17541 +
17542 +
17543 +typedef struct pegasus {
17544 + struct usb_device *usb;
17545 + struct usb_interface *intf;
17546 + struct net_device *net;
17547 + struct net_device_stats stats;
17548 + struct mii_if_info mii;
17549 + unsigned flags;
17550 + unsigned features;
17551 + u32 msg_enable;
17552 + u32 wolopts;
17553 + int dev_index;
17554 + int intr_interval;
17555 + struct tasklet_struct rx_tl;
17556 + struct delayed_work carrier_check;
17557 + struct urb *rx_urb, *tx_urb, *intr_urb;
17558 + struct sk_buff *rx_skb;
17559 + int chip;
17560 + unsigned char intr_buff[8];
17561 + __u8 tx_buff[PEGASUS_MTU];
17562 + __u8 eth_regs[4];
17563 + __u8 phy;
17564 + __u8 gpio_res;
17565 +} pegasus_t;
17566 +
17567 +
17568 +struct usb_eth_dev {
17569 + char *name;
17570 + __u16 vendor;
17571 + __u16 device;
17572 + __u32 private; /* LSB is gpio reset value */
17573 +};
17574 +
17575 +#define VENDOR_3COM 0x0506
17576 +#define VENDOR_ABOCOM 0x07b8
17577 +#define VENDOR_ACCTON 0x083a
17578 +#define VENDOR_ADMTEK 0x07a6
17579 +#define VENDOR_AEILAB 0x3334
17580 +#define VENDOR_ALLIEDTEL 0x07c9
17581 +#define VENDOR_ATEN 0x0557
17582 +#define VENDOR_BELKIN 0x050d
17583 +#define VENDOR_BILLIONTON 0x08dd
17584 +#define VENDOR_COMPAQ 0x049f
17585 +#define VENDOR_COREGA 0x07aa
17586 +#define VENDOR_DLINK 0x2001
17587 +#define VENDOR_ELCON 0x0db7
17588 +#define VENDOR_ELECOM 0x056e
17589 +#define VENDOR_ELSA 0x05cc
17590 +#define VENDOR_GIGABYTE 0x1044
17591 +#define VENDOR_HAWKING 0x0e66
17592 +#define VENDOR_HP 0x03f0
17593 +#define VENDOR_IODATA 0x04bb
17594 +#define VENDOR_KINGSTON 0x0951
17595 +#define VENDOR_LANEED 0x056e
17596 +#define VENDOR_LINKSYS 0x066b
17597 +#define VENDOR_LINKSYS2 0x077b
17598 +#define VENDOR_MELCO 0x0411
17599 +#define VENDOR_MICROSOFT 0x045e
17600 +#define VENDOR_MOBILITY 0x1342
17601 +#define VENDOR_NETGEAR 0x0846
17602 +#define VENDOR_OCT 0x0b39
17603 +#define VENDOR_SMARTBRIDGES 0x08d1
17604 +#define VENDOR_SMC 0x0707
17605 +#define VENDOR_SOHOWARE 0x15e8
17606 +#define VENDOR_SIEMENS 0x067c
17607 +
17608 +
17609 +#else /* PEGASUS_DEV */
17610 +
17611 +PEGASUS_DEV("3Com USB Ethernet 3C460B", VENDOR_3COM, 0x4601,
17612 + DEFAULT_GPIO_RESET | PEGASUS_II)
17613 +PEGASUS_DEV("ATEN USB Ethernet UC-110T", VENDOR_ATEN, 0x2007,
17614 + DEFAULT_GPIO_RESET | PEGASUS_II)
17615 +PEGASUS_DEV("USB HPNA/Ethernet", VENDOR_ABOCOM, 0x110c,
17616 + DEFAULT_GPIO_RESET | PEGASUS_II | HAS_HOME_PNA)
17617 +PEGASUS_DEV("USB HPNA/Ethernet", VENDOR_ABOCOM, 0x4104,
17618 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17619 +PEGASUS_DEV("USB HPNA/Ethernet", VENDOR_ABOCOM, 0x4004,
17620 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17621 +PEGASUS_DEV("USB HPNA/Ethernet", VENDOR_ABOCOM, 0x4007,
17622 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17623 +PEGASUS_DEV("USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x4102,
17624 + DEFAULT_GPIO_RESET | PEGASUS_II)
17625 +PEGASUS_DEV("USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x4002,
17626 + DEFAULT_GPIO_RESET)
17627 +PEGASUS_DEV("USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x400b,
17628 + DEFAULT_GPIO_RESET | PEGASUS_II)
17629 +PEGASUS_DEV("USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x400c,
17630 + DEFAULT_GPIO_RESET | PEGASUS_II)
17631 +PEGASUS_DEV("USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0xabc1,
17632 + DEFAULT_GPIO_RESET)
17633 +PEGASUS_DEV("USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x200c,
17634 + DEFAULT_GPIO_RESET | PEGASUS_II)
17635 +PEGASUS_DEV("Accton USB 10/100 Ethernet Adapter", VENDOR_ACCTON, 0x1046,
17636 + DEFAULT_GPIO_RESET)
17637 +PEGASUS_DEV("SpeedStream USB 10/100 Ethernet", VENDOR_ACCTON, 0x5046,
17638 + DEFAULT_GPIO_RESET | PEGASUS_II)
17639 +PEGASUS_DEV("Philips USB 10/100 Ethernet", VENDOR_ACCTON, 0xb004,
17640 + DEFAULT_GPIO_RESET | PEGASUS_II)
17641 +PEGASUS_DEV("ADMtek ADM8511 \"Pegasus II\" USB Ethernet",
17642 + VENDOR_ADMTEK, 0x8511,
17643 + DEFAULT_GPIO_RESET | PEGASUS_II | HAS_HOME_PNA)
17644 +PEGASUS_DEV("ADMtek ADM8513 \"Pegasus II\" USB Ethernet",
17645 + VENDOR_ADMTEK, 0x8513,
17646 + DEFAULT_GPIO_RESET | PEGASUS_II)
17647 +PEGASUS_DEV("ADMtek ADM8515 \"Pegasus II\" USB-2.0 Ethernet",
17648 + VENDOR_ADMTEK, 0x8515,
17649 + DEFAULT_GPIO_RESET | PEGASUS_II)
17650 +PEGASUS_DEV("ADMtek AN986 \"Pegasus\" USB Ethernet (evaluation board)",
17651 + VENDOR_ADMTEK, 0x0986,
17652 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17653 +PEGASUS_DEV("AN986A USB MAC", VENDOR_ADMTEK, 1986,
17654 + DEFAULT_GPIO_RESET | PEGASUS_II)
17655 +PEGASUS_DEV("AEI USB Fast Ethernet Adapter", VENDOR_AEILAB, 0x1701,
17656 + DEFAULT_GPIO_RESET | PEGASUS_II)
17657 +PEGASUS_DEV("Allied Telesyn Int. AT-USB100", VENDOR_ALLIEDTEL, 0xb100,
17658 + DEFAULT_GPIO_RESET | PEGASUS_II)
17659 +/*
17660 + * Distinguish between this Belkin adaptor and the Belkin bluetooth adaptors
17661 + * with the same product IDs by checking the device class too.
17662 + */
17663 +PEGASUS_DEV_CLASS("Belkin F5D5050 USB Ethernet", VENDOR_BELKIN, 0x0121, 0x00,
17664 + DEFAULT_GPIO_RESET | PEGASUS_II)
17665 +PEGASUS_DEV("Belkin F5U122 10/100 USB Ethernet", VENDOR_BELKIN, 0x0122,
17666 + DEFAULT_GPIO_RESET | PEGASUS_II)
17667 +PEGASUS_DEV("Billionton USB-100", VENDOR_BILLIONTON, 0x0986,
17668 + DEFAULT_GPIO_RESET)
17669 +PEGASUS_DEV("Billionton USBLP-100", VENDOR_BILLIONTON, 0x0987,
17670 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17671 +PEGASUS_DEV("iPAQ Networking 10/100 USB", VENDOR_COMPAQ, 0x8511,
17672 + DEFAULT_GPIO_RESET | PEGASUS_II)
17673 +PEGASUS_DEV("Billionton USBEL-100", VENDOR_BILLIONTON, 0x0988,
17674 + DEFAULT_GPIO_RESET)
17675 +PEGASUS_DEV("Billionton USBE-100", VENDOR_BILLIONTON, 0x8511,
17676 + DEFAULT_GPIO_RESET | PEGASUS_II)
17677 +PEGASUS_DEV("Corega FEther USB-TX", VENDOR_COREGA, 0x0004,
17678 + DEFAULT_GPIO_RESET)
17679 +PEGASUS_DEV("Corega FEther USB-TXS", VENDOR_COREGA, 0x000d,
17680 + DEFAULT_GPIO_RESET | PEGASUS_II)
17681 +PEGASUS_DEV("D-Link DSB-650TX", VENDOR_DLINK, 0x4001,
17682 + DEFAULT_GPIO_RESET)
17683 +PEGASUS_DEV("D-Link DSB-650TX", VENDOR_DLINK, 0x4002,
17684 + DEFAULT_GPIO_RESET)
17685 +PEGASUS_DEV("D-Link DSB-650TX", VENDOR_DLINK, 0x4102,
17686 + DEFAULT_GPIO_RESET | PEGASUS_II)
17687 +PEGASUS_DEV("D-Link DSB-650TX", VENDOR_DLINK, 0x400b,
17688 + DEFAULT_GPIO_RESET | PEGASUS_II)
17689 +PEGASUS_DEV("D-Link DSB-650TX", VENDOR_DLINK, 0x200c,
17690 + DEFAULT_GPIO_RESET | PEGASUS_II)
17691 +PEGASUS_DEV("D-Link DSB-650TX(PNA)", VENDOR_DLINK, 0x4003,
17692 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17693 +PEGASUS_DEV("D-Link DSB-650", VENDOR_DLINK, 0xabc1,
17694 + DEFAULT_GPIO_RESET)
17695 +PEGASUS_DEV("GOLDPFEIL USB Adapter", VENDOR_ELCON, 0x0002,
17696 + DEFAULT_GPIO_RESET | PEGASUS_II | HAS_HOME_PNA)
17697 +PEGASUS_DEV("ELECOM USB Ethernet LD-USB20", VENDOR_ELECOM, 0x4010,
17698 + DEFAULT_GPIO_RESET | PEGASUS_II)
17699 +PEGASUS_DEV("EasiDock Ethernet", VENDOR_MOBILITY, 0x0304,
17700 + DEFAULT_GPIO_RESET)
17701 +PEGASUS_DEV("Elsa Micolink USB2Ethernet", VENDOR_ELSA, 0x3000,
17702 + DEFAULT_GPIO_RESET)
17703 +PEGASUS_DEV("GIGABYTE GN-BR402W Wireless Router", VENDOR_GIGABYTE, 0x8002,
17704 + DEFAULT_GPIO_RESET)
17705 +PEGASUS_DEV("Hawking UF100 10/100 Ethernet", VENDOR_HAWKING, 0x400c,
17706 + DEFAULT_GPIO_RESET | PEGASUS_II)
17707 +PEGASUS_DEV("HP hn210c Ethernet USB", VENDOR_HP, 0x811c,
17708 + DEFAULT_GPIO_RESET | PEGASUS_II)
17709 +PEGASUS_DEV("IO DATA USB ET/TX", VENDOR_IODATA, 0x0904,
17710 + DEFAULT_GPIO_RESET)
17711 +PEGASUS_DEV("IO DATA USB ET/TX-S", VENDOR_IODATA, 0x0913,
17712 + DEFAULT_GPIO_RESET | PEGASUS_II)
17713 +PEGASUS_DEV("IO DATA USB ETX-US2", VENDOR_IODATA, 0x093a,
17714 + DEFAULT_GPIO_RESET | PEGASUS_II)
17715 +PEGASUS_DEV("Kingston KNU101TX Ethernet", VENDOR_KINGSTON, 0x000a,
17716 + DEFAULT_GPIO_RESET)
17717 +PEGASUS_DEV("LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x4002,
17718 + DEFAULT_GPIO_RESET)
17719 +PEGASUS_DEV("LANEED USB Ethernet LD-USBL/TX", VENDOR_LANEED, 0x4005,
17720 + DEFAULT_GPIO_RESET | PEGASUS_II)
17721 +PEGASUS_DEV("LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x400b,
17722 + DEFAULT_GPIO_RESET | PEGASUS_II)
17723 +PEGASUS_DEV("LANEED USB Ethernet LD-USB/T", VENDOR_LANEED, 0xabc1,
17724 + DEFAULT_GPIO_RESET)
17725 +PEGASUS_DEV("LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x200c,
17726 + DEFAULT_GPIO_RESET | PEGASUS_II)
17727 +PEGASUS_DEV("Linksys USB10TX", VENDOR_LINKSYS, 0x2202,
17728 + DEFAULT_GPIO_RESET)
17729 +PEGASUS_DEV("Linksys USB100TX", VENDOR_LINKSYS, 0x2203,
17730 + DEFAULT_GPIO_RESET)
17731 +PEGASUS_DEV("Linksys USB100TX", VENDOR_LINKSYS, 0x2204,
17732 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17733 +PEGASUS_DEV("Linksys USB10T Ethernet Adapter", VENDOR_LINKSYS, 0x2206,
17734 + DEFAULT_GPIO_RESET | PEGASUS_II)
17735 +PEGASUS_DEV("Linksys USBVPN1", VENDOR_LINKSYS2, 0x08b4,
17736 + DEFAULT_GPIO_RESET)
17737 +PEGASUS_DEV("Linksys USB USB100TX", VENDOR_LINKSYS, 0x400b,
17738 + DEFAULT_GPIO_RESET | PEGASUS_II)
17739 +PEGASUS_DEV("Linksys USB10TX", VENDOR_LINKSYS, 0x200c,
17740 + DEFAULT_GPIO_RESET | PEGASUS_II)
17741 +PEGASUS_DEV("MELCO/BUFFALO LUA-TX", VENDOR_MELCO, 0x0001,
17742 + DEFAULT_GPIO_RESET)
17743 +PEGASUS_DEV("MELCO/BUFFALO LUA-TX", VENDOR_MELCO, 0x0005,
17744 + DEFAULT_GPIO_RESET)
17745 +PEGASUS_DEV("MELCO/BUFFALO LUA2-TX", VENDOR_MELCO, 0x0009,
17746 + DEFAULT_GPIO_RESET | PEGASUS_II)
17747 +PEGASUS_DEV("Microsoft MN-110", VENDOR_MICROSOFT, 0x007a,
17748 + DEFAULT_GPIO_RESET | PEGASUS_II)
17749 +PEGASUS_DEV("NETGEAR FA101", VENDOR_NETGEAR, 0x1020,
17750 + DEFAULT_GPIO_RESET | PEGASUS_II)
17751 +PEGASUS_DEV("OCT Inc.", VENDOR_OCT, 0x0109,
17752 + DEFAULT_GPIO_RESET | PEGASUS_II)
17753 +PEGASUS_DEV("OCT USB TO Ethernet", VENDOR_OCT, 0x0901,
17754 + DEFAULT_GPIO_RESET | PEGASUS_II)
17755 +PEGASUS_DEV("smartNIC 2 PnP Adapter", VENDOR_SMARTBRIDGES, 0x0003,
17756 + DEFAULT_GPIO_RESET | PEGASUS_II)
17757 +PEGASUS_DEV("SMC 202 USB Ethernet", VENDOR_SMC, 0x0200,
17758 + DEFAULT_GPIO_RESET)
17759 +PEGASUS_DEV("SMC 2206 USB Ethernet", VENDOR_SMC, 0x0201,
17760 + DEFAULT_GPIO_RESET | PEGASUS_II)
17761 +PEGASUS_DEV("SOHOware NUB100 Ethernet", VENDOR_SOHOWARE, 0x9100,
17762 + DEFAULT_GPIO_RESET)
17763 +PEGASUS_DEV("SOHOware NUB110 Ethernet", VENDOR_SOHOWARE, 0x9110,
17764 + DEFAULT_GPIO_RESET | PEGASUS_II)
17765 +PEGASUS_DEV("SpeedStream USB 10/100 Ethernet", VENDOR_SIEMENS, 0x1001,
17766 + DEFAULT_GPIO_RESET | PEGASUS_II)
17767 +
17768 +
17769 +#endif /* PEGASUS_DEV */
17770 diff -Naur backports-4.2.6-1.org/drivers/net/usb/plusb.c backports-4.2.6-1/drivers/net/usb/plusb.c
17771 --- backports-4.2.6-1.org/drivers/net/usb/plusb.c 1970-01-01 01:00:00.000000000 +0100
17772 +++ backports-4.2.6-1/drivers/net/usb/plusb.c 2016-06-28 14:35:17.998640551 +0200
17773 @@ -0,0 +1,162 @@
17774 +/*
17775 + * PL-2301/2302 USB host-to-host link cables
17776 + * Copyright (C) 2000-2005 by David Brownell
17777 + *
17778 + * This program is free software; you can redistribute it and/or modify
17779 + * it under the terms of the GNU General Public License as published by
17780 + * the Free Software Foundation; either version 2 of the License, or
17781 + * (at your option) any later version.
17782 + *
17783 + * This program is distributed in the hope that it will be useful,
17784 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17785 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17786 + * GNU General Public License for more details.
17787 + *
17788 + * You should have received a copy of the GNU General Public License
17789 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
17790 + */
17791 +
17792 +// #define DEBUG // error path messages, extra info
17793 +// #define VERBOSE // more; success messages
17794 +
17795 +#include <linux/module.h>
17796 +#include <linux/netdevice.h>
17797 +#include <linux/etherdevice.h>
17798 +#include <linux/ethtool.h>
17799 +#include <linux/workqueue.h>
17800 +#include <linux/mii.h>
17801 +#include <linux/usb.h>
17802 +#include <linux/usb/usbnet.h>
17803 +
17804 +
17805 +/*
17806 + * Prolific PL-2301/PL-2302 driver ... http://www.prolific.com.tw/
17807 + *
17808 + * The protocol and handshaking used here should be bug-compatible
17809 + * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
17810 + *
17811 + * HEADS UP: this handshaking isn't all that robust. This driver
17812 + * gets confused easily if you unplug one end of the cable then
17813 + * try to connect it again; you'll need to restart both ends. The
17814 + * "naplink" software (used by some PlayStation/2 deveopers) does
17815 + * the handshaking much better! Also, sometimes this hardware
17816 + * seems to get wedged under load. Prolific docs are weak, and
17817 + * don't identify differences between PL2301 and PL2302, much less
17818 + * anything to explain the different PL2302 versions observed.
17819 + *
17820 + * NOTE: pl2501 has several modes, including pl2301 and pl2302
17821 + * compatibility. Some docs suggest the difference between 2301
17822 + * and 2302 is only to make MS-Windows use a different driver...
17823 + *
17824 + * pl25a1 glue based on patch from Tony Gibbs. Prolific "docs" on
17825 + * this chip are as usual incomplete about what control messages
17826 + * are supported.
17827 + */
17828 +
17829 +/*
17830 + * Bits 0-4 can be used for software handshaking; they're set from
17831 + * one end, cleared from the other, "read" with the interrupt byte.
17832 + */
17833 +#define PL_S_EN (1<<7) /* (feature only) suspend enable */
17834 +/* reserved bit -- rx ready (6) ? */
17835 +#define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
17836 +#define PL_RESET_OUT (1<<4) /* reset output pipe */
17837 +#define PL_RESET_IN (1<<3) /* reset input pipe */
17838 +#define PL_TX_C (1<<2) /* transmission complete */
17839 +#define PL_TX_REQ (1<<1) /* transmission received */
17840 +#define PL_PEER_E (1<<0) /* peer exists */
17841 +
17842 +static inline int
17843 +pl_vendor_req(struct usbnet *dev, u8 req, u8 val, u8 index)
17844 +{
17845 + return usbnet_read_cmd(dev, req,
17846 + USB_DIR_IN | USB_TYPE_VENDOR |
17847 + USB_RECIP_DEVICE,
17848 + val, index, NULL, 0);
17849 +}
17850 +
17851 +static inline int
17852 +pl_clear_QuickLink_features(struct usbnet *dev, int val)
17853 +{
17854 + return pl_vendor_req(dev, 1, (u8) val, 0);
17855 +}
17856 +
17857 +static inline int
17858 +pl_set_QuickLink_features(struct usbnet *dev, int val)
17859 +{
17860 + return pl_vendor_req(dev, 3, (u8) val, 0);
17861 +}
17862 +
17863 +static int pl_reset(struct usbnet *dev)
17864 +{
17865 + int status;
17866 +
17867 + /* some units seem to need this reset, others reject it utterly.
17868 + * FIXME be more like "naplink" or windows drivers.
17869 + */
17870 + status = pl_set_QuickLink_features(dev,
17871 + PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
17872 + if (status != 0 && netif_msg_probe(dev))
17873 + netif_dbg(dev, link, dev->net, "pl_reset --> %d\n", status);
17874 + return 0;
17875 +}
17876 +
17877 +static const struct driver_info prolific_info = {
17878 + .description = "Prolific PL-2301/PL-2302/PL-25A1",
17879 + .flags = FLAG_POINTTOPOINT | FLAG_NO_SETINT,
17880 + /* some PL-2302 versions seem to fail usb_set_interface() */
17881 + .reset = pl_reset,
17882 +};
17883 +
17884 +
17885 +/*-------------------------------------------------------------------------*/
17886 +
17887 +/*
17888 + * Proilific's name won't normally be on the cables, and
17889 + * may not be on the device.
17890 + */
17891 +
17892 +static const struct usb_device_id products [] = {
17893 +
17894 +/* full speed cables */
17895 +{
17896 + USB_DEVICE(0x067b, 0x0000), // PL-2301
17897 + .driver_info = (unsigned long) &prolific_info,
17898 +}, {
17899 + USB_DEVICE(0x067b, 0x0001), // PL-2302
17900 + .driver_info = (unsigned long) &prolific_info,
17901 +},
17902 +
17903 +/* high speed cables */
17904 +{
17905 + USB_DEVICE(0x067b, 0x25a1), /* PL-25A1, no eeprom */
17906 + .driver_info = (unsigned long) &prolific_info,
17907 +}, {
17908 + USB_DEVICE(0x050d, 0x258a), /* Belkin F5U258/F5U279 (PL-25A1) */
17909 + .driver_info = (unsigned long) &prolific_info,
17910 +}, {
17911 + USB_DEVICE(0x3923, 0x7825), /* National Instruments USB
17912 + * Host-to-Host Cable
17913 + */
17914 + .driver_info = (unsigned long) &prolific_info,
17915 +},
17916 +
17917 + { }, // END
17918 +};
17919 +MODULE_DEVICE_TABLE(usb, products);
17920 +
17921 +static struct usb_driver plusb_driver = {
17922 + .name = "plusb",
17923 + .id_table = products,
17924 + .probe = usbnet_probe,
17925 + .disconnect = usbnet_disconnect,
17926 + .suspend = usbnet_suspend,
17927 + .resume = usbnet_resume,
17928 + .disable_hub_initiated_lpm = 1,
17929 +};
17930 +
17931 +module_usb_driver(plusb_driver);
17932 +
17933 +MODULE_AUTHOR("David Brownell");
17934 +MODULE_DESCRIPTION("Prolific PL-2301/2302/25A1 USB Host to Host Link Driver");
17935 +MODULE_LICENSE("GPL");
17936 diff -Naur backports-4.2.6-1.org/drivers/net/usb/r8152.c backports-4.2.6-1/drivers/net/usb/r8152.c
17937 --- backports-4.2.6-1.org/drivers/net/usb/r8152.c 1970-01-01 01:00:00.000000000 +0100
17938 +++ backports-4.2.6-1/drivers/net/usb/r8152.c 2016-06-28 14:45:32.005250978 +0200
17939 @@ -0,0 +1,2856 @@
17940 +/*
17941 + * Copyright (c) 2014 Realtek Semiconductor Corp. All rights reserved.
17942 + *
17943 + * This program is free software; you can redistribute it and/or
17944 + * modify it under the terms of the GNU General Public License
17945 + * version 2 as published by the Free Software Foundation.
17946 + *
17947 + */
17948 +
17949 +#include <linux/signal.h>
17950 +#include <linux/slab.h>
17951 +#include <linux/module.h>
17952 +#include <linux/netdevice.h>
17953 +#include <linux/etherdevice.h>
17954 +#include <linux/mii.h>
17955 +#include <linux/ethtool.h>
17956 +#include <linux/usb.h>
17957 +#include <linux/crc32.h>
17958 +#include <linux/if_vlan.h>
17959 +#include <linux/uaccess.h>
17960 +#include <linux/list.h>
17961 +#include <linux/ip.h>
17962 +#include <linux/ipv6.h>
17963 +
17964 +/* Version Information */
17965 +#define DRIVER_VERSION "v1.04.0 (2014/01/15)"
17966 +#define DRIVER_AUTHOR "Realtek linux nic maintainers <nic_swsd@realtek.com>"
17967 +#define DRIVER_DESC "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters"
17968 +#define MODULENAME "r8152"
17969 +
17970 +#define R8152_PHY_ID 32
17971 +
17972 +#define PLA_IDR 0xc000
17973 +#define PLA_RCR 0xc010
17974 +#define PLA_RMS 0xc016
17975 +#define PLA_RXFIFO_CTRL0 0xc0a0
17976 +#define PLA_RXFIFO_CTRL1 0xc0a4
17977 +#define PLA_RXFIFO_CTRL2 0xc0a8
17978 +#define PLA_FMC 0xc0b4
17979 +#define PLA_CFG_WOL 0xc0b6
17980 +#define PLA_TEREDO_CFG 0xc0bc
17981 +#define PLA_MAR 0xcd00
17982 +#define PLA_BACKUP 0xd000
17983 +#define PAL_BDC_CR 0xd1a0
17984 +#define PLA_TEREDO_TIMER 0xd2cc
17985 +#define PLA_REALWOW_TIMER 0xd2e8
17986 +#define PLA_LEDSEL 0xdd90
17987 +#define PLA_LED_FEATURE 0xdd92
17988 +#define PLA_PHYAR 0xde00
17989 +#define PLA_BOOT_CTRL 0xe004
17990 +#define PLA_GPHY_INTR_IMR 0xe022
17991 +#define PLA_EEE_CR 0xe040
17992 +#define PLA_EEEP_CR 0xe080
17993 +#define PLA_MAC_PWR_CTRL 0xe0c0
17994 +#define PLA_MAC_PWR_CTRL2 0xe0ca
17995 +#define PLA_MAC_PWR_CTRL3 0xe0cc
17996 +#define PLA_MAC_PWR_CTRL4 0xe0ce
17997 +#define PLA_WDT6_CTRL 0xe428
17998 +#define PLA_TCR0 0xe610
17999 +#define PLA_TCR1 0xe612
18000 +#define PLA_TXFIFO_CTRL 0xe618
18001 +#define PLA_RSTTELLY 0xe800
18002 +#define PLA_CR 0xe813
18003 +#define PLA_CRWECR 0xe81c
18004 +#define PLA_CONFIG5 0xe822
18005 +#define PLA_PHY_PWR 0xe84c
18006 +#define PLA_OOB_CTRL 0xe84f
18007 +#define PLA_CPCR 0xe854
18008 +#define PLA_MISC_0 0xe858
18009 +#define PLA_MISC_1 0xe85a
18010 +#define PLA_OCP_GPHY_BASE 0xe86c
18011 +#define PLA_TELLYCNT 0xe890
18012 +#define PLA_SFF_STS_7 0xe8de
18013 +#define PLA_PHYSTATUS 0xe908
18014 +#define PLA_BP_BA 0xfc26
18015 +#define PLA_BP_0 0xfc28
18016 +#define PLA_BP_1 0xfc2a
18017 +#define PLA_BP_2 0xfc2c
18018 +#define PLA_BP_3 0xfc2e
18019 +#define PLA_BP_4 0xfc30
18020 +#define PLA_BP_5 0xfc32
18021 +#define PLA_BP_6 0xfc34
18022 +#define PLA_BP_7 0xfc36
18023 +#define PLA_BP_EN 0xfc38
18024 +
18025 +#define USB_U2P3_CTRL 0xb460
18026 +#define USB_DEV_STAT 0xb808
18027 +#define USB_USB_CTRL 0xd406
18028 +#define USB_PHY_CTRL 0xd408
18029 +#define USB_TX_AGG 0xd40a
18030 +#define USB_RX_BUF_TH 0xd40c
18031 +#define USB_USB_TIMER 0xd428
18032 +#define USB_RX_EARLY_AGG 0xd42c
18033 +#define USB_PM_CTRL_STATUS 0xd432
18034 +#define USB_TX_DMA 0xd434
18035 +#define USB_TOLERANCE 0xd490
18036 +#define USB_LPM_CTRL 0xd41a
18037 +#define USB_UPS_CTRL 0xd800
18038 +#define USB_MISC_0 0xd81a
18039 +#define USB_POWER_CUT 0xd80a
18040 +#define USB_AFE_CTRL2 0xd824
18041 +#define USB_WDT11_CTRL 0xe43c
18042 +#define USB_BP_BA 0xfc26
18043 +#define USB_BP_0 0xfc28
18044 +#define USB_BP_1 0xfc2a
18045 +#define USB_BP_2 0xfc2c
18046 +#define USB_BP_3 0xfc2e
18047 +#define USB_BP_4 0xfc30
18048 +#define USB_BP_5 0xfc32
18049 +#define USB_BP_6 0xfc34
18050 +#define USB_BP_7 0xfc36
18051 +#define USB_BP_EN 0xfc38
18052 +
18053 +/* OCP Registers */
18054 +#define OCP_ALDPS_CONFIG 0x2010
18055 +#define OCP_EEE_CONFIG1 0x2080
18056 +#define OCP_EEE_CONFIG2 0x2092
18057 +#define OCP_EEE_CONFIG3 0x2094
18058 +#define OCP_BASE_MII 0xa400
18059 +#define OCP_EEE_AR 0xa41a
18060 +#define OCP_EEE_DATA 0xa41c
18061 +#define OCP_PHY_STATUS 0xa420
18062 +#define OCP_POWER_CFG 0xa430
18063 +#define OCP_EEE_CFG 0xa432
18064 +#define OCP_SRAM_ADDR 0xa436
18065 +#define OCP_SRAM_DATA 0xa438
18066 +#define OCP_DOWN_SPEED 0xa442
18067 +#define OCP_EEE_CFG2 0xa5d0
18068 +#define OCP_ADC_CFG 0xbc06
18069 +
18070 +/* SRAM Register */
18071 +#define SRAM_LPF_CFG 0x8012
18072 +#define SRAM_10M_AMP1 0x8080
18073 +#define SRAM_10M_AMP2 0x8082
18074 +#define SRAM_IMPEDANCE 0x8084
18075 +
18076 +/* PLA_RCR */
18077 +#define RCR_AAP 0x00000001
18078 +#define RCR_APM 0x00000002
18079 +#define RCR_AM 0x00000004
18080 +#define RCR_AB 0x00000008
18081 +#define RCR_ACPT_ALL (RCR_AAP | RCR_APM | RCR_AM | RCR_AB)
18082 +
18083 +/* PLA_RXFIFO_CTRL0 */
18084 +#define RXFIFO_THR1_NORMAL 0x00080002
18085 +#define RXFIFO_THR1_OOB 0x01800003
18086 +
18087 +/* PLA_RXFIFO_CTRL1 */
18088 +#define RXFIFO_THR2_FULL 0x00000060
18089 +#define RXFIFO_THR2_HIGH 0x00000038
18090 +#define RXFIFO_THR2_OOB 0x0000004a
18091 +#define RXFIFO_THR2_NORMAL 0x00a0
18092 +
18093 +/* PLA_RXFIFO_CTRL2 */
18094 +#define RXFIFO_THR3_FULL 0x00000078
18095 +#define RXFIFO_THR3_HIGH 0x00000048
18096 +#define RXFIFO_THR3_OOB 0x0000005a
18097 +#define RXFIFO_THR3_NORMAL 0x0110
18098 +
18099 +/* PLA_TXFIFO_CTRL */
18100 +#define TXFIFO_THR_NORMAL 0x00400008
18101 +#define TXFIFO_THR_NORMAL2 0x01000008
18102 +
18103 +/* PLA_FMC */
18104 +#define FMC_FCR_MCU_EN 0x0001
18105 +
18106 +/* PLA_EEEP_CR */
18107 +#define EEEP_CR_EEEP_TX 0x0002
18108 +
18109 +/* PLA_WDT6_CTRL */
18110 +#define WDT6_SET_MODE 0x0010
18111 +
18112 +/* PLA_TCR0 */
18113 +#define TCR0_TX_EMPTY 0x0800
18114 +#define TCR0_AUTO_FIFO 0x0080
18115 +
18116 +/* PLA_TCR1 */
18117 +#define VERSION_MASK 0x7cf0
18118 +
18119 +/* PLA_CR */
18120 +#define CR_RST 0x10
18121 +#define CR_RE 0x08
18122 +#define CR_TE 0x04
18123 +
18124 +/* PLA_CRWECR */
18125 +#define CRWECR_NORAML 0x00
18126 +#define CRWECR_CONFIG 0xc0
18127 +
18128 +/* PLA_OOB_CTRL */
18129 +#define NOW_IS_OOB 0x80
18130 +#define TXFIFO_EMPTY 0x20
18131 +#define RXFIFO_EMPTY 0x10
18132 +#define LINK_LIST_READY 0x02
18133 +#define DIS_MCU_CLROOB 0x01
18134 +#define FIFO_EMPTY (TXFIFO_EMPTY | RXFIFO_EMPTY)
18135 +
18136 +/* PLA_MISC_1 */
18137 +#define RXDY_GATED_EN 0x0008
18138 +
18139 +/* PLA_SFF_STS_7 */
18140 +#define RE_INIT_LL 0x8000
18141 +#define MCU_BORW_EN 0x4000
18142 +
18143 +/* PLA_CPCR */
18144 +#define CPCR_RX_VLAN 0x0040
18145 +
18146 +/* PLA_CFG_WOL */
18147 +#define MAGIC_EN 0x0001
18148 +
18149 +/* PLA_TEREDO_CFG */
18150 +#define TEREDO_SEL 0x8000
18151 +#define TEREDO_WAKE_MASK 0x7f00
18152 +#define TEREDO_RS_EVENT_MASK 0x00fe
18153 +#define OOB_TEREDO_EN 0x0001
18154 +
18155 +/* PAL_BDC_CR */
18156 +#define ALDPS_PROXY_MODE 0x0001
18157 +
18158 +/* PLA_CONFIG5 */
18159 +#define LAN_WAKE_EN 0x0002
18160 +
18161 +/* PLA_LED_FEATURE */
18162 +#define LED_MODE_MASK 0x0700
18163 +
18164 +/* PLA_PHY_PWR */
18165 +#define TX_10M_IDLE_EN 0x0080
18166 +#define PFM_PWM_SWITCH 0x0040
18167 +
18168 +/* PLA_MAC_PWR_CTRL */
18169 +#define D3_CLK_GATED_EN 0x00004000
18170 +#define MCU_CLK_RATIO 0x07010f07
18171 +#define MCU_CLK_RATIO_MASK 0x0f0f0f0f
18172 +#define ALDPS_SPDWN_RATIO 0x0f87
18173 +
18174 +/* PLA_MAC_PWR_CTRL2 */
18175 +#define EEE_SPDWN_RATIO 0x8007
18176 +
18177 +/* PLA_MAC_PWR_CTRL3 */
18178 +#define PKT_AVAIL_SPDWN_EN 0x0100
18179 +#define SUSPEND_SPDWN_EN 0x0004
18180 +#define U1U2_SPDWN_EN 0x0002
18181 +#define L1_SPDWN_EN 0x0001
18182 +
18183 +/* PLA_MAC_PWR_CTRL4 */
18184 +#define PWRSAVE_SPDWN_EN 0x1000
18185 +#define RXDV_SPDWN_EN 0x0800
18186 +#define TX10MIDLE_EN 0x0100
18187 +#define TP100_SPDWN_EN 0x0020
18188 +#define TP500_SPDWN_EN 0x0010
18189 +#define TP1000_SPDWN_EN 0x0008
18190 +#define EEE_SPDWN_EN 0x0001
18191 +
18192 +/* PLA_GPHY_INTR_IMR */
18193 +#define GPHY_STS_MSK 0x0001
18194 +#define SPEED_DOWN_MSK 0x0002
18195 +#define SPDWN_RXDV_MSK 0x0004
18196 +#define SPDWN_LINKCHG_MSK 0x0008
18197 +
18198 +/* PLA_PHYAR */
18199 +#define PHYAR_FLAG 0x80000000
18200 +
18201 +/* PLA_EEE_CR */
18202 +#define EEE_RX_EN 0x0001
18203 +#define EEE_TX_EN 0x0002
18204 +
18205 +/* PLA_BOOT_CTRL */
18206 +#define AUTOLOAD_DONE 0x0002
18207 +
18208 +/* USB_DEV_STAT */
18209 +#define STAT_SPEED_MASK 0x0006
18210 +#define STAT_SPEED_HIGH 0x0000
18211 +#define STAT_SPEED_FULL 0x0001
18212 +
18213 +/* USB_TX_AGG */
18214 +#define TX_AGG_MAX_THRESHOLD 0x03
18215 +
18216 +/* USB_RX_BUF_TH */
18217 +#define RX_THR_SUPPER 0x0c350180
18218 +#define RX_THR_HIGH 0x7a120180
18219 +#define RX_THR_SLOW 0xffff0180
18220 +
18221 +/* USB_TX_DMA */
18222 +#define TEST_MODE_DISABLE 0x00000001
18223 +#define TX_SIZE_ADJUST1 0x00000100
18224 +
18225 +/* USB_UPS_CTRL */
18226 +#define POWER_CUT 0x0100
18227 +
18228 +/* USB_PM_CTRL_STATUS */
18229 +#define RESUME_INDICATE 0x0001
18230 +
18231 +/* USB_USB_CTRL */
18232 +#define RX_AGG_DISABLE 0x0010
18233 +
18234 +/* USB_U2P3_CTRL */
18235 +#define U2P3_ENABLE 0x0001
18236 +
18237 +/* USB_POWER_CUT */
18238 +#define PWR_EN 0x0001
18239 +#define PHASE2_EN 0x0008
18240 +
18241 +/* USB_MISC_0 */
18242 +#define PCUT_STATUS 0x0001
18243 +
18244 +/* USB_RX_EARLY_AGG */
18245 +#define EARLY_AGG_SUPPER 0x0e832981
18246 +#define EARLY_AGG_HIGH 0x0e837a12
18247 +#define EARLY_AGG_SLOW 0x0e83ffff
18248 +
18249 +/* USB_WDT11_CTRL */
18250 +#define TIMER11_EN 0x0001
18251 +
18252 +/* USB_LPM_CTRL */
18253 +#define LPM_TIMER_MASK 0x0c
18254 +#define LPM_TIMER_500MS 0x04 /* 500 ms */
18255 +#define LPM_TIMER_500US 0x0c /* 500 us */
18256 +
18257 +/* USB_AFE_CTRL2 */
18258 +#define SEN_VAL_MASK 0xf800
18259 +#define SEN_VAL_NORMAL 0xa000
18260 +#define SEL_RXIDLE 0x0100
18261 +
18262 +/* OCP_ALDPS_CONFIG */
18263 +#define ENPWRSAVE 0x8000
18264 +#define ENPDNPS 0x0200
18265 +#define LINKENA 0x0100
18266 +#define DIS_SDSAVE 0x0010
18267 +
18268 +/* OCP_PHY_STATUS */
18269 +#define PHY_STAT_MASK 0x0007
18270 +#define PHY_STAT_LAN_ON 3
18271 +#define PHY_STAT_PWRDN 5
18272 +
18273 +/* OCP_POWER_CFG */
18274 +#define EEE_CLKDIV_EN 0x8000
18275 +#define EN_ALDPS 0x0004
18276 +#define EN_10M_PLLOFF 0x0001
18277 +
18278 +/* OCP_EEE_CONFIG1 */
18279 +#define RG_TXLPI_MSK_HFDUP 0x8000
18280 +#define RG_MATCLR_EN 0x4000
18281 +#define EEE_10_CAP 0x2000
18282 +#define EEE_NWAY_EN 0x1000
18283 +#define TX_QUIET_EN 0x0200
18284 +#define RX_QUIET_EN 0x0100
18285 +#define SDRISETIME 0x0010 /* bit 4 ~ 6 */
18286 +#define RG_RXLPI_MSK_HFDUP 0x0008
18287 +#define SDFALLTIME 0x0007 /* bit 0 ~ 2 */
18288 +
18289 +/* OCP_EEE_CONFIG2 */
18290 +#define RG_LPIHYS_NUM 0x7000 /* bit 12 ~ 15 */
18291 +#define RG_DACQUIET_EN 0x0400
18292 +#define RG_LDVQUIET_EN 0x0200
18293 +#define RG_CKRSEL 0x0020
18294 +#define RG_EEEPRG_EN 0x0010
18295 +
18296 +/* OCP_EEE_CONFIG3 */
18297 +#define FST_SNR_EYE_R 0x1500 /* bit 7 ~ 15 */
18298 +#define RG_LFS_SEL 0x0060 /* bit 6 ~ 5 */
18299 +#define MSK_PH 0x0006 /* bit 0 ~ 3 */
18300 +
18301 +/* OCP_EEE_AR */
18302 +/* bit[15:14] function */
18303 +#define FUN_ADDR 0x0000
18304 +#define FUN_DATA 0x4000
18305 +/* bit[4:0] device addr */
18306 +#define DEVICE_ADDR 0x0007
18307 +
18308 +/* OCP_EEE_DATA */
18309 +#define EEE_ADDR 0x003C
18310 +#define EEE_DATA 0x0002
18311 +
18312 +/* OCP_EEE_CFG */
18313 +#define CTAP_SHORT_EN 0x0040
18314 +#define EEE10_EN 0x0010
18315 +
18316 +/* OCP_DOWN_SPEED */
18317 +#define EN_10M_BGOFF 0x0080
18318 +
18319 +/* OCP_EEE_CFG2 */
18320 +#define MY1000_EEE 0x0004
18321 +#define MY100_EEE 0x0002
18322 +
18323 +/* OCP_ADC_CFG */
18324 +#define CKADSEL_L 0x0100
18325 +#define ADC_EN 0x0080
18326 +#define EN_EMI_L 0x0040
18327 +
18328 +/* SRAM_LPF_CFG */
18329 +#define LPF_AUTO_TUNE 0x8000
18330 +
18331 +/* SRAM_10M_AMP1 */
18332 +#define GDAC_IB_UPALL 0x0008
18333 +
18334 +/* SRAM_10M_AMP2 */
18335 +#define AMP_DN 0x0200
18336 +
18337 +/* SRAM_IMPEDANCE */
18338 +#define RX_DRIVING_MASK 0x6000
18339 +
18340 +enum rtl_register_content {
18341 + _1000bps = 0x10,
18342 + _100bps = 0x08,
18343 + _10bps = 0x04,
18344 + LINK_STATUS = 0x02,
18345 + FULL_DUP = 0x01,
18346 +};
18347 +
18348 +#define RTL8152_MAX_TX 10
18349 +#define RTL8152_MAX_RX 10
18350 +#define INTBUFSIZE 2
18351 +#define CRC_SIZE 4
18352 +#define TX_ALIGN 4
18353 +#define RX_ALIGN 8
18354 +
18355 +#define INTR_LINK 0x0004
18356 +
18357 +#define RTL8152_REQT_READ 0xc0
18358 +#define RTL8152_REQT_WRITE 0x40
18359 +#define RTL8152_REQ_GET_REGS 0x05
18360 +#define RTL8152_REQ_SET_REGS 0x05
18361 +
18362 +#define BYTE_EN_DWORD 0xff
18363 +#define BYTE_EN_WORD 0x33
18364 +#define BYTE_EN_BYTE 0x11
18365 +#define BYTE_EN_SIX_BYTES 0x3f
18366 +#define BYTE_EN_START_MASK 0x0f
18367 +#define BYTE_EN_END_MASK 0xf0
18368 +
18369 +#define RTL8152_RMS (VLAN_ETH_FRAME_LEN + VLAN_HLEN)
18370 +#define RTL8152_TX_TIMEOUT (HZ)
18371 +
18372 +/* rtl8152 flags */
18373 +enum rtl8152_flags {
18374 + RTL8152_UNPLUG = 0,
18375 + RTL8152_SET_RX_MODE,
18376 + WORK_ENABLE,
18377 + RTL8152_LINK_CHG,
18378 +};
18379 +
18380 +/* Define these values to match your device */
18381 +#define VENDOR_ID_REALTEK 0x0bda
18382 +#define PRODUCT_ID_RTL8152 0x8152
18383 +#define PRODUCT_ID_RTL8153 0x8153
18384 +
18385 +#define VENDOR_ID_SAMSUNG 0x04e8
18386 +#define PRODUCT_ID_SAMSUNG 0xa101
18387 +
18388 +#define VENDOR_ID_LENOVO 0x17ef
18389 +#define PRODUCT_ID_LENOVO 0x7205
18390 +
18391 +#define VENDOR_ID_NVIDIA 0x0955
18392 +#define PRODUCT_ID_NVIDIA 0x09ff
18393 +
18394 +
18395 +#define MCU_TYPE_PLA 0x0100
18396 +#define MCU_TYPE_USB 0x0000
18397 +
18398 +struct rx_desc {
18399 + __le32 opts1;
18400 +#define RX_LEN_MASK 0x7fff
18401 + __le32 opts2;
18402 + __le32 opts3;
18403 + __le32 opts4;
18404 + __le32 opts5;
18405 + __le32 opts6;
18406 +};
18407 +
18408 +struct tx_desc {
18409 + __le32 opts1;
18410 +#define TX_FS (1 << 31) /* First segment of a packet */
18411 +#define TX_LS (1 << 30) /* Final segment of a packet */
18412 +#define TX_LEN_MASK 0x3ffff
18413 +
18414 + __le32 opts2;
18415 +#define UDP_CS (1 << 31) /* Calculate UDP/IP checksum */
18416 +#define TCP_CS (1 << 30) /* Calculate TCP/IP checksum */
18417 +#define IPV4_CS (1 << 29) /* Calculate IPv4 checksum */
18418 +#define IPV6_CS (1 << 28) /* Calculate IPv6 checksum */
18419 +};
18420 +
18421 +struct r8152;
18422 +
18423 +struct rx_agg {
18424 + struct list_head list;
18425 + struct urb *urb;
18426 + struct r8152 *context;
18427 + void *buffer;
18428 + void *head;
18429 +};
18430 +
18431 +struct tx_agg {
18432 + struct list_head list;
18433 + struct urb *urb;
18434 + struct r8152 *context;
18435 + void *buffer;
18436 + void *head;
18437 + u32 skb_num;
18438 + u32 skb_len;
18439 +};
18440 +
18441 +struct r8152 {
18442 + unsigned long flags;
18443 + struct usb_device *udev;
18444 + struct tasklet_struct tl;
18445 + struct usb_interface *intf;
18446 + struct net_device *netdev;
18447 + struct urb *intr_urb;
18448 + struct tx_agg tx_info[RTL8152_MAX_TX];
18449 + struct rx_agg rx_info[RTL8152_MAX_RX];
18450 + struct list_head rx_done, tx_free;
18451 + struct sk_buff_head tx_queue;
18452 + spinlock_t rx_lock, tx_lock;
18453 + struct delayed_work schedule;
18454 + struct mii_if_info mii;
18455 +
18456 + struct rtl_ops {
18457 + void (*init)(struct r8152 *);
18458 + int (*enable)(struct r8152 *);
18459 + void (*disable)(struct r8152 *);
18460 + void (*down)(struct r8152 *);
18461 + void (*unload)(struct r8152 *);
18462 + } __no_const rtl_ops;
18463 +
18464 + int intr_interval;
18465 + u32 msg_enable;
18466 + u32 tx_qlen;
18467 + u16 ocp_base;
18468 + u8 *intr_buff;
18469 + u8 version;
18470 + u8 speed;
18471 +};
18472 +
18473 +enum rtl_version {
18474 + RTL_VER_UNKNOWN = 0,
18475 + RTL_VER_01,
18476 + RTL_VER_02,
18477 + RTL_VER_03,
18478 + RTL_VER_04,
18479 + RTL_VER_05,
18480 + RTL_VER_MAX
18481 +};
18482 +
18483 +/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
18484 + * The RTL chips use a 64 element hash table based on the Ethernet CRC.
18485 + */
18486 +static const int multicast_filter_limit = 32;
18487 +static unsigned int rx_buf_sz = 16384;
18488 +
18489 +static
18490 +int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
18491 +{
18492 + int ret;
18493 + void *tmp;
18494 +
18495 + tmp = kmalloc(size, GFP_KERNEL);
18496 + if (!tmp)
18497 + return -ENOMEM;
18498 +
18499 + ret = usb_control_msg(tp->udev, usb_rcvctrlpipe(tp->udev, 0),
18500 + RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,
18501 + value, index, tmp, size, 500);
18502 +
18503 + memcpy(data, tmp, size);
18504 + kfree(tmp);
18505 +
18506 + return ret;
18507 +}
18508 +
18509 +static
18510 +int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
18511 +{
18512 + int ret;
18513 + void *tmp;
18514 +
18515 + tmp = kmalloc(size, GFP_KERNEL);
18516 + if (!tmp)
18517 + return -ENOMEM;
18518 +
18519 + memcpy(tmp, data, size);
18520 +
18521 + ret = usb_control_msg(tp->udev, usb_sndctrlpipe(tp->udev, 0),
18522 + RTL8152_REQ_SET_REGS, RTL8152_REQT_WRITE,
18523 + value, index, tmp, size, 500);
18524 +
18525 + kfree(tmp);
18526 + return ret;
18527 +}
18528 +
18529 +static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size,
18530 + void *data, u16 type)
18531 +{
18532 + u16 limit = 64;
18533 + int ret = 0;
18534 +
18535 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
18536 + return -ENODEV;
18537 +
18538 + /* both size and indix must be 4 bytes align */
18539 + if ((size & 3) || !size || (index & 3) || !data)
18540 + return -EPERM;
18541 +
18542 + if ((u32)index + (u32)size > 0xffff)
18543 + return -EPERM;
18544 +
18545 + while (size) {
18546 + if (size > limit) {
18547 + ret = get_registers(tp, index, type, limit, data);
18548 + if (ret < 0)
18549 + break;
18550 +
18551 + index += limit;
18552 + data += limit;
18553 + size -= limit;
18554 + } else {
18555 + ret = get_registers(tp, index, type, size, data);
18556 + if (ret < 0)
18557 + break;
18558 +
18559 + index += size;
18560 + data += size;
18561 + size = 0;
18562 + break;
18563 + }
18564 + }
18565 +
18566 + return ret;
18567 +}
18568 +
18569 +static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
18570 + u16 size, void *data, u16 type)
18571 +{
18572 + int ret;
18573 + u16 byteen_start, byteen_end, byen;
18574 + u16 limit = 512;
18575 +
18576 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
18577 + return -ENODEV;
18578 +
18579 + /* both size and indix must be 4 bytes align */
18580 + if ((size & 3) || !size || (index & 3) || !data)
18581 + return -EPERM;
18582 +
18583 + if ((u32)index + (u32)size > 0xffff)
18584 + return -EPERM;
18585 +
18586 + byteen_start = byteen & BYTE_EN_START_MASK;
18587 + byteen_end = byteen & BYTE_EN_END_MASK;
18588 +
18589 + byen = byteen_start | (byteen_start << 4);
18590 + ret = set_registers(tp, index, type | byen, 4, data);
18591 + if (ret < 0)
18592 + goto error1;
18593 +
18594 + index += 4;
18595 + data += 4;
18596 + size -= 4;
18597 +
18598 + if (size) {
18599 + size -= 4;
18600 +
18601 + while (size) {
18602 + if (size > limit) {
18603 + ret = set_registers(tp, index,
18604 + type | BYTE_EN_DWORD,
18605 + limit, data);
18606 + if (ret < 0)
18607 + goto error1;
18608 +
18609 + index += limit;
18610 + data += limit;
18611 + size -= limit;
18612 + } else {
18613 + ret = set_registers(tp, index,
18614 + type | BYTE_EN_DWORD,
18615 + size, data);
18616 + if (ret < 0)
18617 + goto error1;
18618 +
18619 + index += size;
18620 + data += size;
18621 + size = 0;
18622 + break;
18623 + }
18624 + }
18625 +
18626 + byen = byteen_end | (byteen_end >> 4);
18627 + ret = set_registers(tp, index, type | byen, 4, data);
18628 + if (ret < 0)
18629 + goto error1;
18630 + }
18631 +
18632 +error1:
18633 + return ret;
18634 +}
18635 +
18636 +static inline
18637 +int pla_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data)
18638 +{
18639 + return generic_ocp_read(tp, index, size, data, MCU_TYPE_PLA);
18640 +}
18641 +
18642 +static inline
18643 +int pla_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data)
18644 +{
18645 + return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_PLA);
18646 +}
18647 +
18648 +static inline
18649 +int usb_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data)
18650 +{
18651 + return generic_ocp_read(tp, index, size, data, MCU_TYPE_USB);
18652 +}
18653 +
18654 +static inline
18655 +int usb_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data)
18656 +{
18657 + return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_USB);
18658 +}
18659 +
18660 +static u32 ocp_read_dword(struct r8152 *tp, u16 type, u16 index)
18661 +{
18662 + __le32 data;
18663 +
18664 + generic_ocp_read(tp, index, sizeof(data), &data, type);
18665 +
18666 + return __le32_to_cpu(data);
18667 +}
18668 +
18669 +static void ocp_write_dword(struct r8152 *tp, u16 type, u16 index, u32 data)
18670 +{
18671 + __le32 tmp = __cpu_to_le32(data);
18672 +
18673 + generic_ocp_write(tp, index, BYTE_EN_DWORD, sizeof(tmp), &tmp, type);
18674 +}
18675 +
18676 +static u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index)
18677 +{
18678 + u32 data;
18679 + __le32 tmp;
18680 + u8 shift = index & 2;
18681 +
18682 + index &= ~3;
18683 +
18684 + generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
18685 +
18686 + data = __le32_to_cpu(tmp);
18687 + data >>= (shift * 8);
18688 + data &= 0xffff;
18689 +
18690 + return (u16)data;
18691 +}
18692 +
18693 +static void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data)
18694 +{
18695 + u32 mask = 0xffff;
18696 + __le32 tmp;
18697 + u16 byen = BYTE_EN_WORD;
18698 + u8 shift = index & 2;
18699 +
18700 + data &= mask;
18701 +
18702 + if (index & 2) {
18703 + byen <<= shift;
18704 + mask <<= (shift * 8);
18705 + data <<= (shift * 8);
18706 + index &= ~3;
18707 + }
18708 +
18709 + generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
18710 +
18711 + data |= __le32_to_cpu(tmp) & ~mask;
18712 + tmp = __cpu_to_le32(data);
18713 +
18714 + generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type);
18715 +}
18716 +
18717 +static u8 ocp_read_byte(struct r8152 *tp, u16 type, u16 index)
18718 +{
18719 + u32 data;
18720 + __le32 tmp;
18721 + u8 shift = index & 3;
18722 +
18723 + index &= ~3;
18724 +
18725 + generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
18726 +
18727 + data = __le32_to_cpu(tmp);
18728 + data >>= (shift * 8);
18729 + data &= 0xff;
18730 +
18731 + return (u8)data;
18732 +}
18733 +
18734 +static void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data)
18735 +{
18736 + u32 mask = 0xff;
18737 + __le32 tmp;
18738 + u16 byen = BYTE_EN_BYTE;
18739 + u8 shift = index & 3;
18740 +
18741 + data &= mask;
18742 +
18743 + if (index & 3) {
18744 + byen <<= shift;
18745 + mask <<= (shift * 8);
18746 + data <<= (shift * 8);
18747 + index &= ~3;
18748 + }
18749 +
18750 + generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
18751 +
18752 + data |= __le32_to_cpu(tmp) & ~mask;
18753 + tmp = __cpu_to_le32(data);
18754 +
18755 + generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type);
18756 +}
18757 +
18758 +static u16 ocp_reg_read(struct r8152 *tp, u16 addr)
18759 +{
18760 + u16 ocp_base, ocp_index;
18761 +
18762 + ocp_base = addr & 0xf000;
18763 + if (ocp_base != tp->ocp_base) {
18764 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base);
18765 + tp->ocp_base = ocp_base;
18766 + }
18767 +
18768 + ocp_index = (addr & 0x0fff) | 0xb000;
18769 + return ocp_read_word(tp, MCU_TYPE_PLA, ocp_index);
18770 +}
18771 +
18772 +static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
18773 +{
18774 + u16 ocp_base, ocp_index;
18775 +
18776 + ocp_base = addr & 0xf000;
18777 + if (ocp_base != tp->ocp_base) {
18778 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base);
18779 + tp->ocp_base = ocp_base;
18780 + }
18781 +
18782 + ocp_index = (addr & 0x0fff) | 0xb000;
18783 + ocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data);
18784 +}
18785 +
18786 +static inline void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)
18787 +{
18788 + ocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value);
18789 +}
18790 +
18791 +static inline int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)
18792 +{
18793 + return ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2);
18794 +}
18795 +
18796 +static void sram_write(struct r8152 *tp, u16 addr, u16 data)
18797 +{
18798 + ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
18799 + ocp_reg_write(tp, OCP_SRAM_DATA, data);
18800 +}
18801 +
18802 +static u16 sram_read(struct r8152 *tp, u16 addr)
18803 +{
18804 + ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
18805 + return ocp_reg_read(tp, OCP_SRAM_DATA);
18806 +}
18807 +
18808 +static int read_mii_word(struct net_device *netdev, int phy_id, int reg)
18809 +{
18810 + struct r8152 *tp = netdev_priv(netdev);
18811 +
18812 + if (phy_id != R8152_PHY_ID)
18813 + return -EINVAL;
18814 +
18815 + return r8152_mdio_read(tp, reg);
18816 +}
18817 +
18818 +static
18819 +void write_mii_word(struct net_device *netdev, int phy_id, int reg, int val)
18820 +{
18821 + struct r8152 *tp = netdev_priv(netdev);
18822 +
18823 + if (phy_id != R8152_PHY_ID)
18824 + return;
18825 +
18826 + r8152_mdio_write(tp, reg, val);
18827 +}
18828 +
18829 +static
18830 +int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags);
18831 +
18832 +static inline void set_ethernet_addr(struct r8152 *tp)
18833 +{
18834 + struct net_device *dev = tp->netdev;
18835 + u8 node_id[8] = {0};
18836 +
18837 + if (pla_ocp_read(tp, PLA_IDR, sizeof(node_id), node_id) < 0)
18838 + netif_notice(tp, probe, dev, "inet addr fail\n");
18839 + else {
18840 + memcpy(dev->dev_addr, node_id, dev->addr_len);
18841 + memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
18842 + }
18843 +}
18844 +
18845 +static int rtl8152_set_mac_address(struct net_device *netdev, void *p)
18846 +{
18847 + struct r8152 *tp = netdev_priv(netdev);
18848 + struct sockaddr *addr = p;
18849 +
18850 + if (!is_valid_ether_addr(addr->sa_data))
18851 + return -EADDRNOTAVAIL;
18852 +
18853 + memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
18854 +
18855 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG);
18856 + pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, addr->sa_data);
18857 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
18858 +
18859 + return 0;
18860 +}
18861 +
18862 +static struct net_device_stats *rtl8152_get_stats(struct net_device *dev)
18863 +{
18864 + return &dev->stats;
18865 +}
18866 +
18867 +static void read_bulk_callback(struct urb *urb)
18868 +{
18869 + struct net_device *netdev;
18870 + unsigned long flags;
18871 + int status = urb->status;
18872 + struct rx_agg *agg;
18873 + struct r8152 *tp;
18874 + int result;
18875 +
18876 + agg = urb->context;
18877 + if (!agg)
18878 + return;
18879 +
18880 + tp = agg->context;
18881 + if (!tp)
18882 + return;
18883 +
18884 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
18885 + return;
18886 +
18887 + if (!test_bit(WORK_ENABLE, &tp->flags))
18888 + return;
18889 +
18890 + netdev = tp->netdev;
18891 +
18892 + /* When link down, the driver would cancel all bulks. */
18893 + /* This avoid the re-submitting bulk */
18894 + if (!netif_carrier_ok(netdev))
18895 + return;
18896 +
18897 + switch (status) {
18898 + case 0:
18899 + if (urb->actual_length < ETH_ZLEN)
18900 + break;
18901 +
18902 + spin_lock_irqsave(&tp->rx_lock, flags);
18903 + list_add_tail(&agg->list, &tp->rx_done);
18904 + spin_unlock_irqrestore(&tp->rx_lock, flags);
18905 + tasklet_schedule(&tp->tl);
18906 + return;
18907 + case -ESHUTDOWN:
18908 + set_bit(RTL8152_UNPLUG, &tp->flags);
18909 + netif_device_detach(tp->netdev);
18910 + return;
18911 + case -ENOENT:
18912 + return; /* the urb is in unlink state */
18913 + case -ETIME:
18914 + if (net_ratelimit())
18915 + netdev_warn(netdev, "maybe reset is needed?\n");
18916 + break;
18917 + default:
18918 + if (net_ratelimit())
18919 + netdev_warn(netdev, "Rx status %d\n", status);
18920 + break;
18921 + }
18922 +
18923 + result = r8152_submit_rx(tp, agg, GFP_ATOMIC);
18924 + if (result == -ENODEV) {
18925 + netif_device_detach(tp->netdev);
18926 + } else if (result) {
18927 + spin_lock_irqsave(&tp->rx_lock, flags);
18928 + list_add_tail(&agg->list, &tp->rx_done);
18929 + spin_unlock_irqrestore(&tp->rx_lock, flags);
18930 + tasklet_schedule(&tp->tl);
18931 + }
18932 +}
18933 +
18934 +static void write_bulk_callback(struct urb *urb)
18935 +{
18936 + struct net_device_stats *stats;
18937 + unsigned long flags;
18938 + struct tx_agg *agg;
18939 + struct r8152 *tp;
18940 + int status = urb->status;
18941 +
18942 + agg = urb->context;
18943 + if (!agg)
18944 + return;
18945 +
18946 + tp = agg->context;
18947 + if (!tp)
18948 + return;
18949 +
18950 + stats = rtl8152_get_stats(tp->netdev);
18951 + if (status) {
18952 + if (net_ratelimit())
18953 + netdev_warn(tp->netdev, "Tx status %d\n", status);
18954 + stats->tx_errors += agg->skb_num;
18955 + } else {
18956 + stats->tx_packets += agg->skb_num;
18957 + stats->tx_bytes += agg->skb_len;
18958 + }
18959 +
18960 + spin_lock_irqsave(&tp->tx_lock, flags);
18961 + list_add_tail(&agg->list, &tp->tx_free);
18962 + spin_unlock_irqrestore(&tp->tx_lock, flags);
18963 +
18964 + if (!netif_carrier_ok(tp->netdev))
18965 + return;
18966 +
18967 + if (!test_bit(WORK_ENABLE, &tp->flags))
18968 + return;
18969 +
18970 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
18971 + return;
18972 +
18973 + if (!skb_queue_empty(&tp->tx_queue))
18974 + tasklet_schedule(&tp->tl);
18975 +}
18976 +
18977 +static void intr_callback(struct urb *urb)
18978 +{
18979 + struct r8152 *tp;
18980 + __le16 *d;
18981 + int status = urb->status;
18982 + int res;
18983 +
18984 + tp = urb->context;
18985 + if (!tp)
18986 + return;
18987 +
18988 + if (!test_bit(WORK_ENABLE, &tp->flags))
18989 + return;
18990 +
18991 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
18992 + return;
18993 +
18994 + switch (status) {
18995 + case 0: /* success */
18996 + break;
18997 + case -ECONNRESET: /* unlink */
18998 + case -ESHUTDOWN:
18999 + netif_device_detach(tp->netdev);
19000 + case -ENOENT:
19001 + return;
19002 + case -EOVERFLOW:
19003 + netif_info(tp, intr, tp->netdev, "intr status -EOVERFLOW\n");
19004 + goto resubmit;
19005 + /* -EPIPE: should clear the halt */
19006 + default:
19007 + netif_info(tp, intr, tp->netdev, "intr status %d\n", status);
19008 + goto resubmit;
19009 + }
19010 +
19011 + d = urb->transfer_buffer;
19012 + if (INTR_LINK & __le16_to_cpu(d[0])) {
19013 + if (!(tp->speed & LINK_STATUS)) {
19014 + set_bit(RTL8152_LINK_CHG, &tp->flags);
19015 + schedule_delayed_work(&tp->schedule, 0);
19016 + }
19017 + } else {
19018 + if (tp->speed & LINK_STATUS) {
19019 + set_bit(RTL8152_LINK_CHG, &tp->flags);
19020 + schedule_delayed_work(&tp->schedule, 0);
19021 + }
19022 + }
19023 +
19024 +resubmit:
19025 + res = usb_submit_urb(urb, GFP_ATOMIC);
19026 + if (res == -ENODEV)
19027 + netif_device_detach(tp->netdev);
19028 + else if (res)
19029 + netif_err(tp, intr, tp->netdev,
19030 + "can't resubmit intr, status %d\n", res);
19031 +}
19032 +
19033 +static inline void *rx_agg_align(void *data)
19034 +{
19035 + return (void *)ALIGN((uintptr_t)data, RX_ALIGN);
19036 +}
19037 +
19038 +static inline void *tx_agg_align(void *data)
19039 +{
19040 + return (void *)ALIGN((uintptr_t)data, TX_ALIGN);
19041 +}
19042 +
19043 +static void free_all_mem(struct r8152 *tp)
19044 +{
19045 + int i;
19046 +
19047 + for (i = 0; i < RTL8152_MAX_RX; i++) {
19048 + usb_free_urb(tp->rx_info[i].urb);
19049 + tp->rx_info[i].urb = NULL;
19050 +
19051 + kfree(tp->rx_info[i].buffer);
19052 + tp->rx_info[i].buffer = NULL;
19053 + tp->rx_info[i].head = NULL;
19054 + }
19055 +
19056 + for (i = 0; i < RTL8152_MAX_TX; i++) {
19057 + usb_free_urb(tp->tx_info[i].urb);
19058 + tp->tx_info[i].urb = NULL;
19059 +
19060 + kfree(tp->tx_info[i].buffer);
19061 + tp->tx_info[i].buffer = NULL;
19062 + tp->tx_info[i].head = NULL;
19063 + }
19064 +
19065 + usb_free_urb(tp->intr_urb);
19066 + tp->intr_urb = NULL;
19067 +
19068 + kfree(tp->intr_buff);
19069 + tp->intr_buff = NULL;
19070 +}
19071 +
19072 +static int alloc_all_mem(struct r8152 *tp)
19073 +{
19074 + struct net_device *netdev = tp->netdev;
19075 + struct usb_interface *intf = tp->intf;
19076 + struct usb_host_interface *alt = intf->cur_altsetting;
19077 + struct usb_host_endpoint *ep_intr = alt->endpoint + 2;
19078 + struct urb *urb;
19079 + int node, i;
19080 + u8 *buf;
19081 +
19082 + node = netdev->dev.parent ? dev_to_node(netdev->dev.parent) : -1;
19083 +
19084 + spin_lock_init(&tp->rx_lock);
19085 + spin_lock_init(&tp->tx_lock);
19086 + INIT_LIST_HEAD(&tp->rx_done);
19087 + INIT_LIST_HEAD(&tp->tx_free);
19088 + skb_queue_head_init(&tp->tx_queue);
19089 +
19090 + for (i = 0; i < RTL8152_MAX_RX; i++) {
19091 + buf = kmalloc_node(rx_buf_sz, GFP_KERNEL, node);
19092 + if (!buf)
19093 + goto err1;
19094 +
19095 + if (buf != rx_agg_align(buf)) {
19096 + kfree(buf);
19097 + buf = kmalloc_node(rx_buf_sz + RX_ALIGN, GFP_KERNEL,
19098 + node);
19099 + if (!buf)
19100 + goto err1;
19101 + }
19102 +
19103 + urb = usb_alloc_urb(0, GFP_KERNEL);
19104 + if (!urb) {
19105 + kfree(buf);
19106 + goto err1;
19107 + }
19108 +
19109 + INIT_LIST_HEAD(&tp->rx_info[i].list);
19110 + tp->rx_info[i].context = tp;
19111 + tp->rx_info[i].urb = urb;
19112 + tp->rx_info[i].buffer = buf;
19113 + tp->rx_info[i].head = rx_agg_align(buf);
19114 + }
19115 +
19116 + for (i = 0; i < RTL8152_MAX_TX; i++) {
19117 + buf = kmalloc_node(rx_buf_sz, GFP_KERNEL, node);
19118 + if (!buf)
19119 + goto err1;
19120 +
19121 + if (buf != tx_agg_align(buf)) {
19122 + kfree(buf);
19123 + buf = kmalloc_node(rx_buf_sz + TX_ALIGN, GFP_KERNEL,
19124 + node);
19125 + if (!buf)
19126 + goto err1;
19127 + }
19128 +
19129 + urb = usb_alloc_urb(0, GFP_KERNEL);
19130 + if (!urb) {
19131 + kfree(buf);
19132 + goto err1;
19133 + }
19134 +
19135 + INIT_LIST_HEAD(&tp->tx_info[i].list);
19136 + tp->tx_info[i].context = tp;
19137 + tp->tx_info[i].urb = urb;
19138 + tp->tx_info[i].buffer = buf;
19139 + tp->tx_info[i].head = tx_agg_align(buf);
19140 +
19141 + list_add_tail(&tp->tx_info[i].list, &tp->tx_free);
19142 + }
19143 +
19144 + tp->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
19145 + if (!tp->intr_urb)
19146 + goto err1;
19147 +
19148 + tp->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL);
19149 + if (!tp->intr_buff)
19150 + goto err1;
19151 +
19152 + tp->intr_interval = (int)ep_intr->desc.bInterval;
19153 + usb_fill_int_urb(tp->intr_urb, tp->udev, usb_rcvintpipe(tp->udev, 3),
19154 + tp->intr_buff, INTBUFSIZE, intr_callback,
19155 + tp, tp->intr_interval);
19156 +
19157 + return 0;
19158 +
19159 +err1:
19160 + free_all_mem(tp);
19161 + return -ENOMEM;
19162 +}
19163 +
19164 +static struct tx_agg *r8152_get_tx_agg(struct r8152 *tp)
19165 +{
19166 + struct tx_agg *agg = NULL;
19167 + unsigned long flags;
19168 +
19169 + spin_lock_irqsave(&tp->tx_lock, flags);
19170 + if (!list_empty(&tp->tx_free)) {
19171 + struct list_head *cursor;
19172 +
19173 + cursor = tp->tx_free.next;
19174 + list_del_init(cursor);
19175 + agg = list_entry(cursor, struct tx_agg, list);
19176 + }
19177 + spin_unlock_irqrestore(&tp->tx_lock, flags);
19178 +
19179 + return agg;
19180 +}
19181 +
19182 +static void
19183 +r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc, struct sk_buff *skb)
19184 +{
19185 + memset(desc, 0, sizeof(*desc));
19186 +
19187 + desc->opts1 = cpu_to_le32((skb->len & TX_LEN_MASK) | TX_FS | TX_LS);
19188 +
19189 + if (skb->ip_summed == CHECKSUM_PARTIAL) {
19190 + __be16 protocol;
19191 + u8 ip_protocol;
19192 + u32 opts2 = 0;
19193 +
19194 + if (skb->protocol == htons(ETH_P_8021Q))
19195 + protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
19196 + else
19197 + protocol = skb->protocol;
19198 +
19199 + switch (protocol) {
19200 + case htons(ETH_P_IP):
19201 + opts2 |= IPV4_CS;
19202 + ip_protocol = ip_hdr(skb)->protocol;
19203 + break;
19204 +
19205 + case htons(ETH_P_IPV6):
19206 + opts2 |= IPV6_CS;
19207 + ip_protocol = ipv6_hdr(skb)->nexthdr;
19208 + break;
19209 +
19210 + default:
19211 + ip_protocol = IPPROTO_RAW;
19212 + break;
19213 + }
19214 +
19215 + if (ip_protocol == IPPROTO_TCP) {
19216 + opts2 |= TCP_CS;
19217 + opts2 |= (skb_transport_offset(skb) & 0x7fff) << 17;
19218 + } else if (ip_protocol == IPPROTO_UDP) {
19219 + opts2 |= UDP_CS;
19220 + } else {
19221 + WARN_ON_ONCE(1);
19222 + }
19223 +
19224 + desc->opts2 = cpu_to_le32(opts2);
19225 + }
19226 +}
19227 +
19228 +static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg)
19229 +{
19230 + int remain;
19231 + u8 *tx_data;
19232 +
19233 + tx_data = agg->head;
19234 + agg->skb_num = agg->skb_len = 0;
19235 + remain = rx_buf_sz;
19236 +
19237 + while (remain >= ETH_ZLEN + sizeof(struct tx_desc)) {
19238 + struct tx_desc *tx_desc;
19239 + struct sk_buff *skb;
19240 + unsigned int len;
19241 +
19242 + skb = skb_dequeue(&tp->tx_queue);
19243 + if (!skb)
19244 + break;
19245 +
19246 + remain -= sizeof(*tx_desc);
19247 + len = skb->len;
19248 + if (remain < len) {
19249 + skb_queue_head(&tp->tx_queue, skb);
19250 + break;
19251 + }
19252 +
19253 + tx_data = tx_agg_align(tx_data);
19254 + tx_desc = (struct tx_desc *)tx_data;
19255 + tx_data += sizeof(*tx_desc);
19256 +
19257 + r8152_tx_csum(tp, tx_desc, skb);
19258 + memcpy(tx_data, skb->data, len);
19259 + agg->skb_num++;
19260 + agg->skb_len += len;
19261 + dev_kfree_skb_any(skb);
19262 +
19263 + tx_data += len;
19264 + remain = rx_buf_sz - (int)(tx_agg_align(tx_data) - agg->head);
19265 + }
19266 +
19267 + netif_tx_lock(tp->netdev);
19268 +
19269 + if (netif_queue_stopped(tp->netdev) &&
19270 + skb_queue_len(&tp->tx_queue) < tp->tx_qlen)
19271 + netif_wake_queue(tp->netdev);
19272 +
19273 + netif_tx_unlock(tp->netdev);
19274 +
19275 + usb_fill_bulk_urb(agg->urb, tp->udev, usb_sndbulkpipe(tp->udev, 2),
19276 + agg->head, (int)(tx_data - (u8 *)agg->head),
19277 + (usb_complete_t)write_bulk_callback, agg);
19278 +
19279 + return usb_submit_urb(agg->urb, GFP_ATOMIC);
19280 +}
19281 +
19282 +static void rx_bottom(struct r8152 *tp)
19283 +{
19284 + unsigned long flags;
19285 + struct list_head *cursor, *next;
19286 +
19287 + spin_lock_irqsave(&tp->rx_lock, flags);
19288 + list_for_each_safe(cursor, next, &tp->rx_done) {
19289 + struct rx_desc *rx_desc;
19290 + struct rx_agg *agg;
19291 + int len_used = 0;
19292 + struct urb *urb;
19293 + u8 *rx_data;
19294 + int ret;
19295 +
19296 + list_del_init(cursor);
19297 + spin_unlock_irqrestore(&tp->rx_lock, flags);
19298 +
19299 + agg = list_entry(cursor, struct rx_agg, list);
19300 + urb = agg->urb;
19301 + if (urb->actual_length < ETH_ZLEN)
19302 + goto submit;
19303 +
19304 + rx_desc = agg->head;
19305 + rx_data = agg->head;
19306 + len_used += sizeof(struct rx_desc);
19307 +
19308 + while (urb->actual_length > len_used) {
19309 + struct net_device *netdev = tp->netdev;
19310 + struct net_device_stats *stats;
19311 + unsigned int pkt_len;
19312 + struct sk_buff *skb;
19313 +
19314 + pkt_len = le32_to_cpu(rx_desc->opts1) & RX_LEN_MASK;
19315 + if (pkt_len < ETH_ZLEN)
19316 + break;
19317 +
19318 + len_used += pkt_len;
19319 + if (urb->actual_length < len_used)
19320 + break;
19321 +
19322 + stats = rtl8152_get_stats(netdev);
19323 +
19324 + pkt_len -= CRC_SIZE;
19325 + rx_data += sizeof(struct rx_desc);
19326 +
19327 + skb = netdev_alloc_skb_ip_align(netdev, pkt_len);
19328 + if (!skb) {
19329 + stats->rx_dropped++;
19330 + break;
19331 + }
19332 + memcpy(skb->data, rx_data, pkt_len);
19333 + skb_put(skb, pkt_len);
19334 + skb->protocol = eth_type_trans(skb, netdev);
19335 + netif_rx(skb);
19336 + stats->rx_packets++;
19337 + stats->rx_bytes += pkt_len;
19338 +
19339 + rx_data = rx_agg_align(rx_data + pkt_len + CRC_SIZE);
19340 + rx_desc = (struct rx_desc *)rx_data;
19341 + len_used = (int)(rx_data - (u8 *)agg->head);
19342 + len_used += sizeof(struct rx_desc);
19343 + }
19344 +
19345 +submit:
19346 + ret = r8152_submit_rx(tp, agg, GFP_ATOMIC);
19347 + spin_lock_irqsave(&tp->rx_lock, flags);
19348 + if (ret && ret != -ENODEV) {
19349 + list_add_tail(&agg->list, next);
19350 + tasklet_schedule(&tp->tl);
19351 + }
19352 + }
19353 + spin_unlock_irqrestore(&tp->rx_lock, flags);
19354 +}
19355 +
19356 +static void tx_bottom(struct r8152 *tp)
19357 +{
19358 + int res;
19359 +
19360 + do {
19361 + struct tx_agg *agg;
19362 +
19363 + if (skb_queue_empty(&tp->tx_queue))
19364 + break;
19365 +
19366 + agg = r8152_get_tx_agg(tp);
19367 + if (!agg)
19368 + break;
19369 +
19370 + res = r8152_tx_agg_fill(tp, agg);
19371 + if (res) {
19372 + struct net_device_stats *stats;
19373 + struct net_device *netdev;
19374 + unsigned long flags;
19375 +
19376 + netdev = tp->netdev;
19377 + stats = rtl8152_get_stats(netdev);
19378 +
19379 + if (res == -ENODEV) {
19380 + netif_device_detach(netdev);
19381 + } else {
19382 + netif_warn(tp, tx_err, netdev,
19383 + "failed tx_urb %d\n", res);
19384 + stats->tx_dropped += agg->skb_num;
19385 + spin_lock_irqsave(&tp->tx_lock, flags);
19386 + list_add_tail(&agg->list, &tp->tx_free);
19387 + spin_unlock_irqrestore(&tp->tx_lock, flags);
19388 + }
19389 + }
19390 + } while (res == 0);
19391 +}
19392 +
19393 +static void bottom_half(unsigned long data)
19394 +{
19395 + struct r8152 *tp;
19396 +
19397 + tp = (struct r8152 *)data;
19398 +
19399 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
19400 + return;
19401 +
19402 + if (!test_bit(WORK_ENABLE, &tp->flags))
19403 + return;
19404 +
19405 + /* When link down, the driver would cancel all bulks. */
19406 + /* This avoid the re-submitting bulk */
19407 + if (!netif_carrier_ok(tp->netdev))
19408 + return;
19409 +
19410 + rx_bottom(tp);
19411 + tx_bottom(tp);
19412 +}
19413 +
19414 +static
19415 +int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags)
19416 +{
19417 + usb_fill_bulk_urb(agg->urb, tp->udev, usb_rcvbulkpipe(tp->udev, 1),
19418 + agg->head, rx_buf_sz,
19419 + (usb_complete_t)read_bulk_callback, agg);
19420 +
19421 + return usb_submit_urb(agg->urb, mem_flags);
19422 +}
19423 +
19424 +static void rtl8152_tx_timeout(struct net_device *netdev)
19425 +{
19426 + struct r8152 *tp = netdev_priv(netdev);
19427 + int i;
19428 +
19429 + netif_warn(tp, tx_err, netdev, "Tx timeout\n");
19430 + for (i = 0; i < RTL8152_MAX_TX; i++)
19431 + usb_unlink_urb(tp->tx_info[i].urb);
19432 +}
19433 +
19434 +static void rtl8152_set_rx_mode(struct net_device *netdev)
19435 +{
19436 + struct r8152 *tp = netdev_priv(netdev);
19437 +
19438 + if (tp->speed & LINK_STATUS) {
19439 + set_bit(RTL8152_SET_RX_MODE, &tp->flags);
19440 + schedule_delayed_work(&tp->schedule, 0);
19441 + }
19442 +}
19443 +
19444 +static void _rtl8152_set_rx_mode(struct net_device *netdev)
19445 +{
19446 + struct r8152 *tp = netdev_priv(netdev);
19447 + u32 mc_filter[2]; /* Multicast hash filter */
19448 + __le32 tmp[2];
19449 + u32 ocp_data;
19450 +
19451 + clear_bit(RTL8152_SET_RX_MODE, &tp->flags);
19452 + netif_stop_queue(netdev);
19453 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
19454 + ocp_data &= ~RCR_ACPT_ALL;
19455 + ocp_data |= RCR_AB | RCR_APM;
19456 +
19457 + if (netdev->flags & IFF_PROMISC) {
19458 + /* Unconditionally log net taps. */
19459 + netif_notice(tp, link, netdev, "Promiscuous mode enabled\n");
19460 + ocp_data |= RCR_AM | RCR_AAP;
19461 + mc_filter[1] = mc_filter[0] = 0xffffffff;
19462 + } else if ((netdev_mc_count(netdev) > multicast_filter_limit) ||
19463 + (netdev->flags & IFF_ALLMULTI)) {
19464 + /* Too many to filter perfectly -- accept all multicasts. */
19465 + ocp_data |= RCR_AM;
19466 + mc_filter[1] = mc_filter[0] = 0xffffffff;
19467 + } else {
19468 + struct netdev_hw_addr *ha;
19469 +
19470 + mc_filter[1] = mc_filter[0] = 0;
19471 + netdev_for_each_mc_addr(ha, netdev) {
19472 + int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
19473 + mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
19474 + ocp_data |= RCR_AM;
19475 + }
19476 + }
19477 +
19478 + tmp[0] = __cpu_to_le32(swab32(mc_filter[1]));
19479 + tmp[1] = __cpu_to_le32(swab32(mc_filter[0]));
19480 +
19481 + pla_ocp_write(tp, PLA_MAR, BYTE_EN_DWORD, sizeof(tmp), tmp);
19482 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
19483 + netif_wake_queue(netdev);
19484 +}
19485 +
19486 +static netdev_tx_t rtl8152_start_xmit(struct sk_buff *skb,
19487 + struct net_device *netdev)
19488 +{
19489 + struct r8152 *tp = netdev_priv(netdev);
19490 +
19491 + skb_tx_timestamp(skb);
19492 +
19493 + skb_queue_tail(&tp->tx_queue, skb);
19494 +
19495 + if (list_empty(&tp->tx_free) &&
19496 + skb_queue_len(&tp->tx_queue) > tp->tx_qlen)
19497 + netif_stop_queue(netdev);
19498 +
19499 + if (!list_empty(&tp->tx_free))
19500 + tasklet_schedule(&tp->tl);
19501 +
19502 + return NETDEV_TX_OK;
19503 +}
19504 +
19505 +static void r8152b_reset_packet_filter(struct r8152 *tp)
19506 +{
19507 + u32 ocp_data;
19508 +
19509 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_FMC);
19510 + ocp_data &= ~FMC_FCR_MCU_EN;
19511 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_FMC, ocp_data);
19512 + ocp_data |= FMC_FCR_MCU_EN;
19513 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_FMC, ocp_data);
19514 +}
19515 +
19516 +static void rtl8152_nic_reset(struct r8152 *tp)
19517 +{
19518 + int i;
19519 +
19520 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, CR_RST);
19521 +
19522 + for (i = 0; i < 1000; i++) {
19523 + if (!(ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR) & CR_RST))
19524 + break;
19525 + udelay(100);
19526 + }
19527 +}
19528 +
19529 +static void set_tx_qlen(struct r8152 *tp)
19530 +{
19531 + struct net_device *netdev = tp->netdev;
19532 +
19533 + tp->tx_qlen = rx_buf_sz / (netdev->mtu + VLAN_ETH_HLEN + VLAN_HLEN +
19534 + sizeof(struct tx_desc));
19535 +}
19536 +
19537 +static inline u8 rtl8152_get_speed(struct r8152 *tp)
19538 +{
19539 + return ocp_read_byte(tp, MCU_TYPE_PLA, PLA_PHYSTATUS);
19540 +}
19541 +
19542 +static void rtl_set_eee_plus(struct r8152 *tp)
19543 +{
19544 + u32 ocp_data;
19545 + u8 speed;
19546 +
19547 + speed = rtl8152_get_speed(tp);
19548 + if (speed & _10bps) {
19549 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR);
19550 + ocp_data |= EEEP_CR_EEEP_TX;
19551 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR, ocp_data);
19552 + } else {
19553 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR);
19554 + ocp_data &= ~EEEP_CR_EEEP_TX;
19555 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR, ocp_data);
19556 + }
19557 +}
19558 +
19559 +static int rtl_enable(struct r8152 *tp)
19560 +{
19561 + u32 ocp_data;
19562 + int i, ret;
19563 +
19564 + r8152b_reset_packet_filter(tp);
19565 +
19566 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR);
19567 + ocp_data |= CR_RE | CR_TE;
19568 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, ocp_data);
19569 +
19570 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
19571 + ocp_data &= ~RXDY_GATED_EN;
19572 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
19573 +
19574 + INIT_LIST_HEAD(&tp->rx_done);
19575 + ret = 0;
19576 + for (i = 0; i < RTL8152_MAX_RX; i++) {
19577 + INIT_LIST_HEAD(&tp->rx_info[i].list);
19578 + ret |= r8152_submit_rx(tp, &tp->rx_info[i], GFP_KERNEL);
19579 + }
19580 +
19581 + return ret;
19582 +}
19583 +
19584 +static int rtl8152_enable(struct r8152 *tp)
19585 +{
19586 + set_tx_qlen(tp);
19587 + rtl_set_eee_plus(tp);
19588 +
19589 + return rtl_enable(tp);
19590 +}
19591 +
19592 +static void r8153_set_rx_agg(struct r8152 *tp)
19593 +{
19594 + u8 speed;
19595 +
19596 + speed = rtl8152_get_speed(tp);
19597 + if (speed & _1000bps) {
19598 + if (tp->udev->speed == USB_SPEED_SUPER) {
19599 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH,
19600 + RX_THR_SUPPER);
19601 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_EARLY_AGG,
19602 + EARLY_AGG_SUPPER);
19603 + } else {
19604 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH,
19605 + RX_THR_HIGH);
19606 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_EARLY_AGG,
19607 + EARLY_AGG_HIGH);
19608 + }
19609 + } else {
19610 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_SLOW);
19611 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_EARLY_AGG,
19612 + EARLY_AGG_SLOW);
19613 + }
19614 +}
19615 +
19616 +static int rtl8153_enable(struct r8152 *tp)
19617 +{
19618 + set_tx_qlen(tp);
19619 + rtl_set_eee_plus(tp);
19620 + r8153_set_rx_agg(tp);
19621 +
19622 + return rtl_enable(tp);
19623 +}
19624 +
19625 +static void rtl8152_disable(struct r8152 *tp)
19626 +{
19627 + struct net_device_stats *stats = rtl8152_get_stats(tp->netdev);
19628 + struct sk_buff *skb;
19629 + u32 ocp_data;
19630 + int i;
19631 +
19632 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
19633 + ocp_data &= ~RCR_ACPT_ALL;
19634 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
19635 +
19636 + while ((skb = skb_dequeue(&tp->tx_queue))) {
19637 + dev_kfree_skb(skb);
19638 + stats->tx_dropped++;
19639 + }
19640 +
19641 + for (i = 0; i < RTL8152_MAX_TX; i++)
19642 + usb_kill_urb(tp->tx_info[i].urb);
19643 +
19644 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
19645 + ocp_data |= RXDY_GATED_EN;
19646 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
19647 +
19648 + for (i = 0; i < 1000; i++) {
19649 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19650 + if ((ocp_data & FIFO_EMPTY) == FIFO_EMPTY)
19651 + break;
19652 + mdelay(1);
19653 + }
19654 +
19655 + for (i = 0; i < 1000; i++) {
19656 + if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0) & TCR0_TX_EMPTY)
19657 + break;
19658 + mdelay(1);
19659 + }
19660 +
19661 + for (i = 0; i < RTL8152_MAX_RX; i++)
19662 + usb_kill_urb(tp->rx_info[i].urb);
19663 +
19664 + rtl8152_nic_reset(tp);
19665 +}
19666 +
19667 +static void r8152b_exit_oob(struct r8152 *tp)
19668 +{
19669 + u32 ocp_data;
19670 + int i;
19671 +
19672 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
19673 + ocp_data &= ~RCR_ACPT_ALL;
19674 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
19675 +
19676 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
19677 + ocp_data |= RXDY_GATED_EN;
19678 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
19679 +
19680 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
19681 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, 0x00);
19682 +
19683 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19684 + ocp_data &= ~NOW_IS_OOB;
19685 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
19686 +
19687 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
19688 + ocp_data &= ~MCU_BORW_EN;
19689 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
19690 +
19691 + for (i = 0; i < 1000; i++) {
19692 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19693 + if (ocp_data & LINK_LIST_READY)
19694 + break;
19695 + mdelay(1);
19696 + }
19697 +
19698 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
19699 + ocp_data |= RE_INIT_LL;
19700 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
19701 +
19702 + for (i = 0; i < 1000; i++) {
19703 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19704 + if (ocp_data & LINK_LIST_READY)
19705 + break;
19706 + mdelay(1);
19707 + }
19708 +
19709 + rtl8152_nic_reset(tp);
19710 +
19711 + /* rx share fifo credit full threshold */
19712 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_NORMAL);
19713 +
19714 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_DEV_STAT);
19715 + ocp_data &= STAT_SPEED_MASK;
19716 + if (ocp_data == STAT_SPEED_FULL) {
19717 + /* rx share fifo credit near full threshold */
19718 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1,
19719 + RXFIFO_THR2_FULL);
19720 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2,
19721 + RXFIFO_THR3_FULL);
19722 + } else {
19723 + /* rx share fifo credit near full threshold */
19724 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1,
19725 + RXFIFO_THR2_HIGH);
19726 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2,
19727 + RXFIFO_THR3_HIGH);
19728 + }
19729 +
19730 + /* TX share fifo free credit full threshold */
19731 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, TXFIFO_THR_NORMAL);
19732 +
19733 + ocp_write_byte(tp, MCU_TYPE_USB, USB_TX_AGG, TX_AGG_MAX_THRESHOLD);
19734 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_HIGH);
19735 + ocp_write_dword(tp, MCU_TYPE_USB, USB_TX_DMA,
19736 + TEST_MODE_DISABLE | TX_SIZE_ADJUST1);
19737 +
19738 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR);
19739 + ocp_data &= ~CPCR_RX_VLAN;
19740 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data);
19741 +
19742 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);
19743 +
19744 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0);
19745 + ocp_data |= TCR0_AUTO_FIFO;
19746 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR0, ocp_data);
19747 +}
19748 +
19749 +static void r8152b_enter_oob(struct r8152 *tp)
19750 +{
19751 + u32 ocp_data;
19752 + int i;
19753 +
19754 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19755 + ocp_data &= ~NOW_IS_OOB;
19756 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
19757 +
19758 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_OOB);
19759 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_OOB);
19760 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_OOB);
19761 +
19762 + rtl8152_disable(tp);
19763 +
19764 + for (i = 0; i < 1000; i++) {
19765 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19766 + if (ocp_data & LINK_LIST_READY)
19767 + break;
19768 + mdelay(1);
19769 + }
19770 +
19771 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
19772 + ocp_data |= RE_INIT_LL;
19773 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
19774 +
19775 + for (i = 0; i < 1000; i++) {
19776 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19777 + if (ocp_data & LINK_LIST_READY)
19778 + break;
19779 + mdelay(1);
19780 + }
19781 +
19782 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);
19783 +
19784 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL);
19785 + ocp_data |= MAGIC_EN;
19786 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL, ocp_data);
19787 +
19788 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR);
19789 + ocp_data |= CPCR_RX_VLAN;
19790 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data);
19791 +
19792 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PAL_BDC_CR);
19793 + ocp_data |= ALDPS_PROXY_MODE;
19794 + ocp_write_word(tp, MCU_TYPE_PLA, PAL_BDC_CR, ocp_data);
19795 +
19796 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19797 + ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB;
19798 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
19799 +
19800 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG5, LAN_WAKE_EN);
19801 +
19802 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
19803 + ocp_data &= ~RXDY_GATED_EN;
19804 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
19805 +
19806 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
19807 + ocp_data |= RCR_APM | RCR_AM | RCR_AB;
19808 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
19809 +}
19810 +
19811 +static void r8152b_disable_aldps(struct r8152 *tp)
19812 +{
19813 + ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPDNPS | LINKENA | DIS_SDSAVE);
19814 + msleep(20);
19815 +}
19816 +
19817 +static inline void r8152b_enable_aldps(struct r8152 *tp)
19818 +{
19819 + ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPWRSAVE | ENPDNPS |
19820 + LINKENA | DIS_SDSAVE);
19821 +}
19822 +
19823 +static void r8153_hw_phy_cfg(struct r8152 *tp)
19824 +{
19825 + u32 ocp_data;
19826 + u16 data;
19827 +
19828 + ocp_reg_write(tp, OCP_ADC_CFG, CKADSEL_L | ADC_EN | EN_EMI_L);
19829 + r8152_mdio_write(tp, MII_BMCR, BMCR_ANENABLE);
19830 +
19831 + if (tp->version == RTL_VER_03) {
19832 + data = ocp_reg_read(tp, OCP_EEE_CFG);
19833 + data &= ~CTAP_SHORT_EN;
19834 + ocp_reg_write(tp, OCP_EEE_CFG, data);
19835 + }
19836 +
19837 + data = ocp_reg_read(tp, OCP_POWER_CFG);
19838 + data |= EEE_CLKDIV_EN;
19839 + ocp_reg_write(tp, OCP_POWER_CFG, data);
19840 +
19841 + data = ocp_reg_read(tp, OCP_DOWN_SPEED);
19842 + data |= EN_10M_BGOFF;
19843 + ocp_reg_write(tp, OCP_DOWN_SPEED, data);
19844 + data = ocp_reg_read(tp, OCP_POWER_CFG);
19845 + data |= EN_10M_PLLOFF;
19846 + ocp_reg_write(tp, OCP_POWER_CFG, data);
19847 + data = sram_read(tp, SRAM_IMPEDANCE);
19848 + data &= ~RX_DRIVING_MASK;
19849 + sram_write(tp, SRAM_IMPEDANCE, data);
19850 +
19851 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR);
19852 + ocp_data |= PFM_PWM_SWITCH;
19853 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data);
19854 +
19855 + data = sram_read(tp, SRAM_LPF_CFG);
19856 + data |= LPF_AUTO_TUNE;
19857 + sram_write(tp, SRAM_LPF_CFG, data);
19858 +
19859 + data = sram_read(tp, SRAM_10M_AMP1);
19860 + data |= GDAC_IB_UPALL;
19861 + sram_write(tp, SRAM_10M_AMP1, data);
19862 + data = sram_read(tp, SRAM_10M_AMP2);
19863 + data |= AMP_DN;
19864 + sram_write(tp, SRAM_10M_AMP2, data);
19865 +}
19866 +
19867 +static void r8153_u1u2en(struct r8152 *tp, int enable)
19868 +{
19869 + u8 u1u2[8];
19870 +
19871 + if (enable)
19872 + memset(u1u2, 0xff, sizeof(u1u2));
19873 + else
19874 + memset(u1u2, 0x00, sizeof(u1u2));
19875 +
19876 + usb_ocp_write(tp, USB_TOLERANCE, BYTE_EN_SIX_BYTES, sizeof(u1u2), u1u2);
19877 +}
19878 +
19879 +static void r8153_u2p3en(struct r8152 *tp, int enable)
19880 +{
19881 + u32 ocp_data;
19882 +
19883 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL);
19884 + if (enable)
19885 + ocp_data |= U2P3_ENABLE;
19886 + else
19887 + ocp_data &= ~U2P3_ENABLE;
19888 + ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data);
19889 +}
19890 +
19891 +static void r8153_power_cut_en(struct r8152 *tp, int enable)
19892 +{
19893 + u32 ocp_data;
19894 +
19895 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_POWER_CUT);
19896 + if (enable)
19897 + ocp_data |= PWR_EN | PHASE2_EN;
19898 + else
19899 + ocp_data &= ~(PWR_EN | PHASE2_EN);
19900 + ocp_write_word(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data);
19901 +
19902 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0);
19903 + ocp_data &= ~PCUT_STATUS;
19904 + ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data);
19905 +}
19906 +
19907 +static void r8153_teredo_off(struct r8152 *tp)
19908 +{
19909 + u32 ocp_data;
19910 +
19911 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG);
19912 + ocp_data &= ~(TEREDO_SEL | TEREDO_RS_EVENT_MASK | OOB_TEREDO_EN);
19913 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data);
19914 +
19915 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_WDT6_CTRL, WDT6_SET_MODE);
19916 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_REALWOW_TIMER, 0);
19917 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TEREDO_TIMER, 0);
19918 +}
19919 +
19920 +static void r8153_first_init(struct r8152 *tp)
19921 +{
19922 + u32 ocp_data;
19923 + int i;
19924 +
19925 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
19926 + ocp_data |= RXDY_GATED_EN;
19927 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
19928 +
19929 + r8153_teredo_off(tp);
19930 +
19931 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
19932 + ocp_data &= ~RCR_ACPT_ALL;
19933 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
19934 +
19935 + r8153_hw_phy_cfg(tp);
19936 +
19937 + rtl8152_nic_reset(tp);
19938 +
19939 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19940 + ocp_data &= ~NOW_IS_OOB;
19941 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
19942 +
19943 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
19944 + ocp_data &= ~MCU_BORW_EN;
19945 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
19946 +
19947 + for (i = 0; i < 1000; i++) {
19948 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19949 + if (ocp_data & LINK_LIST_READY)
19950 + break;
19951 + mdelay(1);
19952 + }
19953 +
19954 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
19955 + ocp_data |= RE_INIT_LL;
19956 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
19957 +
19958 + for (i = 0; i < 1000; i++) {
19959 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19960 + if (ocp_data & LINK_LIST_READY)
19961 + break;
19962 + mdelay(1);
19963 + }
19964 +
19965 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR);
19966 + ocp_data &= ~CPCR_RX_VLAN;
19967 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data);
19968 +
19969 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);
19970 +
19971 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0);
19972 + ocp_data |= TCR0_AUTO_FIFO;
19973 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR0, ocp_data);
19974 +
19975 + rtl8152_nic_reset(tp);
19976 +
19977 + /* rx share fifo credit full threshold */
19978 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_NORMAL);
19979 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_NORMAL);
19980 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_NORMAL);
19981 + /* TX share fifo free credit full threshold */
19982 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, TXFIFO_THR_NORMAL2);
19983 +
19984 + /* rx aggregation */
19985 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
19986 + ocp_data &= ~RX_AGG_DISABLE;
19987 + ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data);
19988 +}
19989 +
19990 +static void r8153_enter_oob(struct r8152 *tp)
19991 +{
19992 + u32 ocp_data;
19993 + int i;
19994 +
19995 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19996 + ocp_data &= ~NOW_IS_OOB;
19997 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
19998 +
19999 + rtl8152_disable(tp);
20000 +
20001 + for (i = 0; i < 1000; i++) {
20002 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
20003 + if (ocp_data & LINK_LIST_READY)
20004 + break;
20005 + mdelay(1);
20006 + }
20007 +
20008 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
20009 + ocp_data |= RE_INIT_LL;
20010 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
20011 +
20012 + for (i = 0; i < 1000; i++) {
20013 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
20014 + if (ocp_data & LINK_LIST_READY)
20015 + break;
20016 + mdelay(1);
20017 + }
20018 +
20019 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);
20020 +
20021 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL);
20022 + ocp_data |= MAGIC_EN;
20023 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL, ocp_data);
20024 +
20025 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG);
20026 + ocp_data &= ~TEREDO_WAKE_MASK;
20027 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data);
20028 +
20029 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR);
20030 + ocp_data |= CPCR_RX_VLAN;
20031 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data);
20032 +
20033 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PAL_BDC_CR);
20034 + ocp_data |= ALDPS_PROXY_MODE;
20035 + ocp_write_word(tp, MCU_TYPE_PLA, PAL_BDC_CR, ocp_data);
20036 +
20037 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
20038 + ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB;
20039 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
20040 +
20041 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG5, LAN_WAKE_EN);
20042 +
20043 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
20044 + ocp_data &= ~RXDY_GATED_EN;
20045 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
20046 +
20047 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
20048 + ocp_data |= RCR_APM | RCR_AM | RCR_AB;
20049 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
20050 +}
20051 +
20052 +static void r8153_disable_aldps(struct r8152 *tp)
20053 +{
20054 + u16 data;
20055 +
20056 + data = ocp_reg_read(tp, OCP_POWER_CFG);
20057 + data &= ~EN_ALDPS;
20058 + ocp_reg_write(tp, OCP_POWER_CFG, data);
20059 + msleep(20);
20060 +}
20061 +
20062 +static void r8153_enable_aldps(struct r8152 *tp)
20063 +{
20064 + u16 data;
20065 +
20066 + data = ocp_reg_read(tp, OCP_POWER_CFG);
20067 + data |= EN_ALDPS;
20068 + ocp_reg_write(tp, OCP_POWER_CFG, data);
20069 +}
20070 +
20071 +static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex)
20072 +{
20073 + u16 bmcr, anar, gbcr;
20074 + int ret = 0;
20075 +
20076 + cancel_delayed_work_sync(&tp->schedule);
20077 + anar = r8152_mdio_read(tp, MII_ADVERTISE);
20078 + anar &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL |
20079 + ADVERTISE_100HALF | ADVERTISE_100FULL);
20080 + if (tp->mii.supports_gmii) {
20081 + gbcr = r8152_mdio_read(tp, MII_CTRL1000);
20082 + gbcr &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
20083 + } else {
20084 + gbcr = 0;
20085 + }
20086 +
20087 + if (autoneg == AUTONEG_DISABLE) {
20088 + if (speed == SPEED_10) {
20089 + bmcr = 0;
20090 + anar |= ADVERTISE_10HALF | ADVERTISE_10FULL;
20091 + } else if (speed == SPEED_100) {
20092 + bmcr = BMCR_SPEED100;
20093 + anar |= ADVERTISE_100HALF | ADVERTISE_100FULL;
20094 + } else if (speed == SPEED_1000 && tp->mii.supports_gmii) {
20095 + bmcr = BMCR_SPEED1000;
20096 + gbcr |= ADVERTISE_1000FULL | ADVERTISE_1000HALF;
20097 + } else {
20098 + ret = -EINVAL;
20099 + goto out;
20100 + }
20101 +
20102 + if (duplex == DUPLEX_FULL)
20103 + bmcr |= BMCR_FULLDPLX;
20104 + } else {
20105 + if (speed == SPEED_10) {
20106 + if (duplex == DUPLEX_FULL)
20107 + anar |= ADVERTISE_10HALF | ADVERTISE_10FULL;
20108 + else
20109 + anar |= ADVERTISE_10HALF;
20110 + } else if (speed == SPEED_100) {
20111 + if (duplex == DUPLEX_FULL) {
20112 + anar |= ADVERTISE_10HALF | ADVERTISE_10FULL;
20113 + anar |= ADVERTISE_100HALF | ADVERTISE_100FULL;
20114 + } else {
20115 + anar |= ADVERTISE_10HALF;
20116 + anar |= ADVERTISE_100HALF;
20117 + }
20118 + } else if (speed == SPEED_1000 && tp->mii.supports_gmii) {
20119 + if (duplex == DUPLEX_FULL) {
20120 + anar |= ADVERTISE_10HALF | ADVERTISE_10FULL;
20121 + anar |= ADVERTISE_100HALF | ADVERTISE_100FULL;
20122 + gbcr |= ADVERTISE_1000FULL | ADVERTISE_1000HALF;
20123 + } else {
20124 + anar |= ADVERTISE_10HALF;
20125 + anar |= ADVERTISE_100HALF;
20126 + gbcr |= ADVERTISE_1000HALF;
20127 + }
20128 + } else {
20129 + ret = -EINVAL;
20130 + goto out;
20131 + }
20132 +
20133 + bmcr = BMCR_ANENABLE | BMCR_ANRESTART;
20134 + }
20135 +
20136 + if (tp->mii.supports_gmii)
20137 + r8152_mdio_write(tp, MII_CTRL1000, gbcr);
20138 +
20139 + r8152_mdio_write(tp, MII_ADVERTISE, anar);
20140 + r8152_mdio_write(tp, MII_BMCR, bmcr);
20141 +
20142 +out:
20143 +
20144 + return ret;
20145 +}
20146 +
20147 +static void rtl8152_down(struct r8152 *tp)
20148 +{
20149 + u32 ocp_data;
20150 +
20151 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL);
20152 + ocp_data &= ~POWER_CUT;
20153 + ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data);
20154 +
20155 + r8152b_disable_aldps(tp);
20156 + r8152b_enter_oob(tp);
20157 + r8152b_enable_aldps(tp);
20158 +}
20159 +
20160 +static void rtl8153_down(struct r8152 *tp)
20161 +{
20162 + r8153_u1u2en(tp, 0);
20163 + r8153_power_cut_en(tp, 0);
20164 + r8153_disable_aldps(tp);
20165 + r8153_enter_oob(tp);
20166 + r8153_enable_aldps(tp);
20167 +}
20168 +
20169 +static void set_carrier(struct r8152 *tp)
20170 +{
20171 + struct net_device *netdev = tp->netdev;
20172 + u8 speed;
20173 +
20174 + clear_bit(RTL8152_LINK_CHG, &tp->flags);
20175 + speed = rtl8152_get_speed(tp);
20176 +
20177 + if (speed & LINK_STATUS) {
20178 + if (!(tp->speed & LINK_STATUS)) {
20179 + tp->rtl_ops.enable(tp);
20180 + set_bit(RTL8152_SET_RX_MODE, &tp->flags);
20181 + netif_carrier_on(netdev);
20182 + }
20183 + } else {
20184 + if (tp->speed & LINK_STATUS) {
20185 + netif_carrier_off(netdev);
20186 + tasklet_disable(&tp->tl);
20187 + tp->rtl_ops.disable(tp);
20188 + tasklet_enable(&tp->tl);
20189 + }
20190 + }
20191 + tp->speed = speed;
20192 +}
20193 +
20194 +static void rtl_work_func_t(struct work_struct *work)
20195 +{
20196 + struct r8152 *tp = container_of(work, struct r8152, schedule.work);
20197 +
20198 + if (!test_bit(WORK_ENABLE, &tp->flags))
20199 + goto out1;
20200 +
20201 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
20202 + goto out1;
20203 +
20204 + if (test_bit(RTL8152_LINK_CHG, &tp->flags))
20205 + set_carrier(tp);
20206 +
20207 + if (test_bit(RTL8152_SET_RX_MODE, &tp->flags))
20208 + _rtl8152_set_rx_mode(tp->netdev);
20209 +
20210 +out1:
20211 + return;
20212 +}
20213 +
20214 +static int rtl8152_open(struct net_device *netdev)
20215 +{
20216 + struct r8152 *tp = netdev_priv(netdev);
20217 + int res = 0;
20218 +
20219 + rtl8152_set_speed(tp, AUTONEG_ENABLE,
20220 + tp->mii.supports_gmii ? SPEED_1000 : SPEED_100,
20221 + DUPLEX_FULL);
20222 + tp->speed = 0;
20223 + netif_carrier_off(netdev);
20224 + netif_start_queue(netdev);
20225 + set_bit(WORK_ENABLE, &tp->flags);
20226 + res = usb_submit_urb(tp->intr_urb, GFP_KERNEL);
20227 + if (res) {
20228 + if (res == -ENODEV)
20229 + netif_device_detach(tp->netdev);
20230 + netif_warn(tp, ifup, netdev, "intr_urb submit failed: %d\n",
20231 + res);
20232 + }
20233 +
20234 +
20235 + return res;
20236 +}
20237 +
20238 +static int rtl8152_close(struct net_device *netdev)
20239 +{
20240 + struct r8152 *tp = netdev_priv(netdev);
20241 + int res = 0;
20242 +
20243 + clear_bit(WORK_ENABLE, &tp->flags);
20244 + usb_kill_urb(tp->intr_urb);
20245 + cancel_delayed_work_sync(&tp->schedule);
20246 + netif_stop_queue(netdev);
20247 + tasklet_disable(&tp->tl);
20248 + tp->rtl_ops.disable(tp);
20249 + tasklet_enable(&tp->tl);
20250 +
20251 + return res;
20252 +}
20253 +
20254 +static void rtl_clear_bp(struct r8152 *tp)
20255 +{
20256 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_0, 0);
20257 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_2, 0);
20258 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_4, 0);
20259 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_6, 0);
20260 + ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_0, 0);
20261 + ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_2, 0);
20262 + ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_4, 0);
20263 + ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_6, 0);
20264 + mdelay(3);
20265 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_BA, 0);
20266 + ocp_write_word(tp, MCU_TYPE_USB, USB_BP_BA, 0);
20267 +}
20268 +
20269 +static void r8153_clear_bp(struct r8152 *tp)
20270 +{
20271 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0);
20272 + ocp_write_byte(tp, MCU_TYPE_USB, USB_BP_EN, 0);
20273 + rtl_clear_bp(tp);
20274 +}
20275 +
20276 +static void r8152b_enable_eee(struct r8152 *tp)
20277 +{
20278 + u32 ocp_data;
20279 +
20280 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEE_CR);
20281 + ocp_data |= EEE_RX_EN | EEE_TX_EN;
20282 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_CR, ocp_data);
20283 + ocp_reg_write(tp, OCP_EEE_CONFIG1, RG_TXLPI_MSK_HFDUP | RG_MATCLR_EN |
20284 + EEE_10_CAP | EEE_NWAY_EN |
20285 + TX_QUIET_EN | RX_QUIET_EN |
20286 + SDRISETIME | RG_RXLPI_MSK_HFDUP |
20287 + SDFALLTIME);
20288 + ocp_reg_write(tp, OCP_EEE_CONFIG2, RG_LPIHYS_NUM | RG_DACQUIET_EN |
20289 + RG_LDVQUIET_EN | RG_CKRSEL |
20290 + RG_EEEPRG_EN);
20291 + ocp_reg_write(tp, OCP_EEE_CONFIG3, FST_SNR_EYE_R | RG_LFS_SEL | MSK_PH);
20292 + ocp_reg_write(tp, OCP_EEE_AR, FUN_ADDR | DEVICE_ADDR);
20293 + ocp_reg_write(tp, OCP_EEE_DATA, EEE_ADDR);
20294 + ocp_reg_write(tp, OCP_EEE_AR, FUN_DATA | DEVICE_ADDR);
20295 + ocp_reg_write(tp, OCP_EEE_DATA, EEE_DATA);
20296 + ocp_reg_write(tp, OCP_EEE_AR, 0x0000);
20297 +}
20298 +
20299 +static void r8153_enable_eee(struct r8152 *tp)
20300 +{
20301 + u32 ocp_data;
20302 + u16 data;
20303 +
20304 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEE_CR);
20305 + ocp_data |= EEE_RX_EN | EEE_TX_EN;
20306 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_CR, ocp_data);
20307 + data = ocp_reg_read(tp, OCP_EEE_CFG);
20308 + data |= EEE10_EN;
20309 + ocp_reg_write(tp, OCP_EEE_CFG, data);
20310 + data = ocp_reg_read(tp, OCP_EEE_CFG2);
20311 + data |= MY1000_EEE | MY100_EEE;
20312 + ocp_reg_write(tp, OCP_EEE_CFG2, data);
20313 +}
20314 +
20315 +static void r8152b_enable_fc(struct r8152 *tp)
20316 +{
20317 + u16 anar;
20318 +
20319 + anar = r8152_mdio_read(tp, MII_ADVERTISE);
20320 + anar |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
20321 + r8152_mdio_write(tp, MII_ADVERTISE, anar);
20322 +}
20323 +
20324 +static void r8152b_hw_phy_cfg(struct r8152 *tp)
20325 +{
20326 + r8152_mdio_write(tp, MII_BMCR, BMCR_ANENABLE);
20327 + r8152b_disable_aldps(tp);
20328 +}
20329 +
20330 +static void r8152b_init(struct r8152 *tp)
20331 +{
20332 + u32 ocp_data;
20333 + int i;
20334 +
20335 + rtl_clear_bp(tp);
20336 +
20337 + if (tp->version == RTL_VER_01) {
20338 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE);
20339 + ocp_data &= ~LED_MODE_MASK;
20340 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data);
20341 + }
20342 +
20343 + r8152b_hw_phy_cfg(tp);
20344 +
20345 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL);
20346 + ocp_data &= ~POWER_CUT;
20347 + ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data);
20348 +
20349 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS);
20350 + ocp_data &= ~RESUME_INDICATE;
20351 + ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data);
20352 +
20353 + r8152b_exit_oob(tp);
20354 +
20355 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR);
20356 + ocp_data |= TX_10M_IDLE_EN | PFM_PWM_SWITCH;
20357 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data);
20358 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL);
20359 + ocp_data &= ~MCU_CLK_RATIO_MASK;
20360 + ocp_data |= MCU_CLK_RATIO | D3_CLK_GATED_EN;
20361 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, ocp_data);
20362 + ocp_data = GPHY_STS_MSK | SPEED_DOWN_MSK |
20363 + SPDWN_RXDV_MSK | SPDWN_LINKCHG_MSK;
20364 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_GPHY_INTR_IMR, ocp_data);
20365 +
20366 + r8152b_enable_eee(tp);
20367 + r8152b_enable_aldps(tp);
20368 + r8152b_enable_fc(tp);
20369 +
20370 + r8152_mdio_write(tp, MII_BMCR, BMCR_RESET | BMCR_ANENABLE |
20371 + BMCR_ANRESTART);
20372 + for (i = 0; i < 100; i++) {
20373 + udelay(100);
20374 + if (!(r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET))
20375 + break;
20376 + }
20377 +
20378 + /* enable rx aggregation */
20379 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
20380 + ocp_data &= ~RX_AGG_DISABLE;
20381 + ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data);
20382 +}
20383 +
20384 +static void r8153_init(struct r8152 *tp)
20385 +{
20386 + u32 ocp_data;
20387 + int i;
20388 +
20389 + r8153_u1u2en(tp, 0);
20390 +
20391 + for (i = 0; i < 500; i++) {
20392 + if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
20393 + AUTOLOAD_DONE)
20394 + break;
20395 + msleep(20);
20396 + }
20397 +
20398 + for (i = 0; i < 500; i++) {
20399 + ocp_data = ocp_reg_read(tp, OCP_PHY_STATUS) & PHY_STAT_MASK;
20400 + if (ocp_data == PHY_STAT_LAN_ON || ocp_data == PHY_STAT_PWRDN)
20401 + break;
20402 + msleep(20);
20403 + }
20404 +
20405 + r8153_u2p3en(tp, 0);
20406 +
20407 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL);
20408 + ocp_data &= ~TIMER11_EN;
20409 + ocp_write_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL, ocp_data);
20410 +
20411 + r8153_clear_bp(tp);
20412 +
20413 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE);
20414 + ocp_data &= ~LED_MODE_MASK;
20415 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data);
20416 +
20417 + ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL);
20418 + ocp_data &= ~LPM_TIMER_MASK;
20419 + if (tp->udev->speed == USB_SPEED_SUPER)
20420 + ocp_data |= LPM_TIMER_500US;
20421 + else
20422 + ocp_data |= LPM_TIMER_500MS;
20423 + ocp_write_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL, ocp_data);
20424 +
20425 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2);
20426 + ocp_data &= ~SEN_VAL_MASK;
20427 + ocp_data |= SEN_VAL_NORMAL | SEL_RXIDLE;
20428 + ocp_write_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2, ocp_data);
20429 +
20430 + r8153_power_cut_en(tp, 0);
20431 + r8153_u1u2en(tp, 1);
20432 +
20433 + r8153_first_init(tp);
20434 +
20435 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, ALDPS_SPDWN_RATIO);
20436 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, EEE_SPDWN_RATIO);
20437 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,
20438 + PKT_AVAIL_SPDWN_EN | SUSPEND_SPDWN_EN |
20439 + U1U2_SPDWN_EN | L1_SPDWN_EN);
20440 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,
20441 + PWRSAVE_SPDWN_EN | RXDV_SPDWN_EN | TX10MIDLE_EN |
20442 + TP100_SPDWN_EN | TP500_SPDWN_EN | TP1000_SPDWN_EN |
20443 + EEE_SPDWN_EN);
20444 +
20445 + r8153_enable_eee(tp);
20446 + r8153_enable_aldps(tp);
20447 + r8152b_enable_fc(tp);
20448 +
20449 + r8152_mdio_write(tp, MII_BMCR, BMCR_RESET | BMCR_ANENABLE |
20450 + BMCR_ANRESTART);
20451 +}
20452 +
20453 +static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message)
20454 +{
20455 + struct r8152 *tp = usb_get_intfdata(intf);
20456 +
20457 + netif_device_detach(tp->netdev);
20458 +
20459 + if (netif_running(tp->netdev)) {
20460 + clear_bit(WORK_ENABLE, &tp->flags);
20461 + usb_kill_urb(tp->intr_urb);
20462 + cancel_delayed_work_sync(&tp->schedule);
20463 + tasklet_disable(&tp->tl);
20464 + }
20465 +
20466 + tp->rtl_ops.down(tp);
20467 +
20468 + return 0;
20469 +}
20470 +
20471 +static int rtl8152_resume(struct usb_interface *intf)
20472 +{
20473 + struct r8152 *tp = usb_get_intfdata(intf);
20474 +
20475 + tp->rtl_ops.init(tp);
20476 + netif_device_attach(tp->netdev);
20477 + if (netif_running(tp->netdev)) {
20478 + rtl8152_set_speed(tp, AUTONEG_ENABLE,
20479 + tp->mii.supports_gmii ? SPEED_1000 : SPEED_100,
20480 + DUPLEX_FULL);
20481 + tp->speed = 0;
20482 + netif_carrier_off(tp->netdev);
20483 + set_bit(WORK_ENABLE, &tp->flags);
20484 + usb_submit_urb(tp->intr_urb, GFP_KERNEL);
20485 + tasklet_enable(&tp->tl);
20486 + }
20487 +
20488 + return 0;
20489 +}
20490 +
20491 +static void rtl8152_get_drvinfo(struct net_device *netdev,
20492 + struct ethtool_drvinfo *info)
20493 +{
20494 + struct r8152 *tp = netdev_priv(netdev);
20495 +
20496 + strncpy(info->driver, MODULENAME, ETHTOOL_BUSINFO_LEN);
20497 + strncpy(info->version, DRIVER_VERSION, ETHTOOL_BUSINFO_LEN);
20498 + usb_make_path(tp->udev, info->bus_info, sizeof(info->bus_info));
20499 +}
20500 +
20501 +static
20502 +int rtl8152_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
20503 +{
20504 + struct r8152 *tp = netdev_priv(netdev);
20505 +
20506 + if (!tp->mii.mdio_read)
20507 + return -EOPNOTSUPP;
20508 +
20509 + return mii_ethtool_gset(&tp->mii, cmd);
20510 +}
20511 +
20512 +static int rtl8152_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
20513 +{
20514 + struct r8152 *tp = netdev_priv(dev);
20515 +
20516 + return rtl8152_set_speed(tp, cmd->autoneg, cmd->speed, cmd->duplex);
20517 +}
20518 +
20519 +static struct ethtool_ops ops = {
20520 + .get_drvinfo = rtl8152_get_drvinfo,
20521 + .get_settings = rtl8152_get_settings,
20522 + .set_settings = rtl8152_set_settings,
20523 + .get_link = ethtool_op_get_link,
20524 +};
20525 +
20526 +static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
20527 +{
20528 + struct r8152 *tp = netdev_priv(netdev);
20529 + struct mii_ioctl_data *data = if_mii(rq);
20530 + int res = 0;
20531 +
20532 + switch (cmd) {
20533 + case SIOCGMIIPHY:
20534 + data->phy_id = R8152_PHY_ID; /* Internal PHY */
20535 + break;
20536 +
20537 + case SIOCGMIIREG:
20538 + data->val_out = r8152_mdio_read(tp, data->reg_num);
20539 + break;
20540 +
20541 + case SIOCSMIIREG:
20542 + if (!capable(CAP_NET_ADMIN)) {
20543 + res = -EPERM;
20544 + break;
20545 + }
20546 + r8152_mdio_write(tp, data->reg_num, data->val_in);
20547 + break;
20548 +
20549 + default:
20550 + res = -EOPNOTSUPP;
20551 + }
20552 +
20553 + return res;
20554 +}
20555 +
20556 +static const struct net_device_ops rtl8152_netdev_ops = {
20557 + .ndo_open = rtl8152_open,
20558 + .ndo_stop = rtl8152_close,
20559 + .ndo_do_ioctl = rtl8152_ioctl,
20560 + .ndo_start_xmit = rtl8152_start_xmit,
20561 + .ndo_tx_timeout = rtl8152_tx_timeout,
20562 + .ndo_set_rx_mode = rtl8152_set_rx_mode,
20563 + .ndo_set_mac_address = rtl8152_set_mac_address,
20564 +
20565 + .ndo_change_mtu = eth_change_mtu,
20566 + .ndo_validate_addr = eth_validate_addr,
20567 +};
20568 +
20569 +static void r8152b_get_version(struct r8152 *tp)
20570 +{
20571 + u32 ocp_data;
20572 + u16 version;
20573 +
20574 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR1);
20575 + version = (u16)(ocp_data & VERSION_MASK);
20576 +
20577 + switch (version) {
20578 + case 0x4c00:
20579 + tp->version = RTL_VER_01;
20580 + break;
20581 + case 0x4c10:
20582 + tp->version = RTL_VER_02;
20583 + break;
20584 + case 0x5c00:
20585 + tp->version = RTL_VER_03;
20586 + tp->mii.supports_gmii = 1;
20587 + break;
20588 + case 0x5c10:
20589 + tp->version = RTL_VER_04;
20590 + tp->mii.supports_gmii = 1;
20591 + break;
20592 + case 0x5c20:
20593 + tp->version = RTL_VER_05;
20594 + tp->mii.supports_gmii = 1;
20595 + break;
20596 + default:
20597 + netif_info(tp, probe, tp->netdev,
20598 + "Unknown version 0x%04x\n", version);
20599 + break;
20600 + }
20601 +}
20602 +
20603 +static void rtl8152_unload(struct r8152 *tp)
20604 +{
20605 + u32 ocp_data;
20606 +
20607 + if (tp->version != RTL_VER_01) {
20608 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL);
20609 + ocp_data |= POWER_CUT;
20610 + ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data);
20611 + }
20612 +
20613 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS);
20614 + ocp_data &= ~RESUME_INDICATE;
20615 + ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data);
20616 +}
20617 +
20618 +static void rtl8153_unload(struct r8152 *tp)
20619 +{
20620 + r8153_power_cut_en(tp, 1);
20621 +}
20622 +
20623 +static int rtl_ops_init(struct r8152 *tp, const struct usb_device_id *id)
20624 +{
20625 + struct rtl_ops *ops = &tp->rtl_ops;
20626 + int ret = -ENODEV;
20627 +
20628 + switch (id->idVendor) {
20629 + case VENDOR_ID_REALTEK:
20630 + switch (id->idProduct) {
20631 + case PRODUCT_ID_RTL8152:
20632 + ops->init = r8152b_init;
20633 + ops->enable = rtl8152_enable;
20634 + ops->disable = rtl8152_disable;
20635 + ops->down = rtl8152_down;
20636 + ops->unload = rtl8152_unload;
20637 + ret = 0;
20638 + break;
20639 + case PRODUCT_ID_RTL8153:
20640 + ops->init = r8153_init;
20641 + ops->enable = rtl8153_enable;
20642 + ops->disable = rtl8152_disable;
20643 + ops->down = rtl8153_down;
20644 + ops->unload = rtl8153_unload;
20645 + ret = 0;
20646 + break;
20647 + default:
20648 + break;
20649 + }
20650 + break;
20651 +
20652 + case VENDOR_ID_SAMSUNG:
20653 + switch (id->idProduct) {
20654 + case PRODUCT_ID_SAMSUNG:
20655 + ops->init = r8153_init;
20656 + ops->enable = rtl8153_enable;
20657 + ops->disable = rtl8152_disable;
20658 + ops->down = rtl8153_down;
20659 + ops->unload = rtl8153_unload;
20660 + ret = 0;
20661 + break;
20662 + default:
20663 + break;
20664 + }
20665 + break;
20666 +
20667 + default:
20668 + break;
20669 + }
20670 +
20671 + if (ret)
20672 + netif_err(tp, probe, tp->netdev, "Unknown Device\n");
20673 +
20674 + return ret;
20675 +}
20676 +
20677 +static int rtl8152_probe(struct usb_interface *intf,
20678 + const struct usb_device_id *id)
20679 +{
20680 + struct usb_device *udev = interface_to_usbdev(intf);
20681 + struct r8152 *tp;
20682 + struct net_device *netdev;
20683 + int ret;
20684 +
20685 + if (udev->actconfig->desc.bConfigurationValue != 1) {
20686 + usb_driver_set_configuration(udev, 1);
20687 + return -ENODEV;
20688 + }
20689 +
20690 + usb_reset_device(udev);
20691 + netdev = alloc_etherdev(sizeof(struct r8152));
20692 + if (!netdev) {
20693 + dev_err(&intf->dev, "Out of memory\n");
20694 + return -ENOMEM;
20695 + }
20696 +
20697 + SET_NETDEV_DEV(netdev, &intf->dev);
20698 + tp = netdev_priv(netdev);
20699 + tp->msg_enable = 0x7FFF;
20700 +
20701 + tp->udev = udev;
20702 + tp->netdev = netdev;
20703 + tp->intf = intf;
20704 +
20705 + ret = rtl_ops_init(tp, id);
20706 + if (ret)
20707 + goto out;
20708 +
20709 + tasklet_init(&tp->tl, bottom_half, (unsigned long)tp);
20710 + INIT_DELAYED_WORK(&tp->schedule, rtl_work_func_t);
20711 +
20712 + netdev->netdev_ops = &rtl8152_netdev_ops;
20713 + netdev->watchdog_timeo = RTL8152_TX_TIMEOUT;
20714 +
20715 + netdev->features |= NETIF_F_IP_CSUM;
20716 + netdev->hw_features = NETIF_F_IP_CSUM;
20717 + SET_ETHTOOL_OPS(netdev, &ops);
20718 +
20719 + tp->mii.dev = netdev;
20720 + tp->mii.mdio_read = read_mii_word;
20721 + tp->mii.mdio_write = write_mii_word;
20722 + tp->mii.phy_id_mask = 0x3f;
20723 + tp->mii.reg_num_mask = 0x1f;
20724 + tp->mii.phy_id = R8152_PHY_ID;
20725 + tp->mii.supports_gmii = 0;
20726 +
20727 + r8152b_get_version(tp);
20728 + tp->rtl_ops.init(tp);
20729 + set_ethernet_addr(tp);
20730 +
20731 + ret = alloc_all_mem(tp);
20732 + if (ret)
20733 + goto out;
20734 +
20735 + usb_set_intfdata(intf, tp);
20736 +
20737 + ret = register_netdev(netdev);
20738 + if (ret != 0) {
20739 + netif_err(tp, probe, netdev, "couldn't register the device\n");
20740 + goto out1;
20741 + }
20742 +
20743 + netif_info(tp, probe, netdev, "%s\n", DRIVER_VERSION);
20744 +
20745 + return 0;
20746 +
20747 +out1:
20748 + usb_set_intfdata(intf, NULL);
20749 +out:
20750 + free_netdev(netdev);
20751 + return ret;
20752 +}
20753 +
20754 +static void rtl8152_disconnect(struct usb_interface *intf)
20755 +{
20756 + struct r8152 *tp = usb_get_intfdata(intf);
20757 +
20758 + usb_set_intfdata(intf, NULL);
20759 + if (tp) {
20760 + set_bit(RTL8152_UNPLUG, &tp->flags);
20761 + tasklet_kill(&tp->tl);
20762 + unregister_netdev(tp->netdev);
20763 + tp->rtl_ops.unload(tp);
20764 + free_all_mem(tp);
20765 + free_netdev(tp->netdev);
20766 + }
20767 +}
20768 +
20769 +/* table of devices that work with this driver */
20770 +static struct usb_device_id rtl8152_table[] = {
20771 + {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8152)},
20772 + {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8153)},
20773 + {USB_DEVICE(VENDOR_ID_SAMSUNG, PRODUCT_ID_SAMSUNG)},
20774 + {USB_DEVICE(VENDOR_ID_LENOVO, PRODUCT_ID_LENOVO)},
20775 + {USB_DEVICE(VENDOR_ID_NVIDIA, PRODUCT_ID_NVIDIA)},
20776 + {}
20777 +};
20778 +
20779 +MODULE_DEVICE_TABLE(usb, rtl8152_table);
20780 +
20781 +static struct usb_driver rtl8152_driver = {
20782 + .name = MODULENAME,
20783 + .id_table = rtl8152_table,
20784 + .probe = rtl8152_probe,
20785 + .disconnect = rtl8152_disconnect,
20786 + .suspend = rtl8152_suspend,
20787 + .resume = rtl8152_resume,
20788 + .reset_resume = rtl8152_resume,
20789 +};
20790 +
20791 +module_usb_driver(rtl8152_driver);
20792 +
20793 +MODULE_AUTHOR(DRIVER_AUTHOR);
20794 +MODULE_DESCRIPTION(DRIVER_DESC);
20795 +MODULE_LICENSE("GPL");
20796 diff -Naur backports-4.2.6-1.org/drivers/net/usb/rtl8150.c backports-4.2.6-1/drivers/net/usb/rtl8150.c
20797 --- backports-4.2.6-1.org/drivers/net/usb/rtl8150.c 1970-01-01 01:00:00.000000000 +0100
20798 +++ backports-4.2.6-1/drivers/net/usb/rtl8150.c 2016-06-28 14:35:18.001973885 +0200
20799 @@ -0,0 +1,949 @@
20800 +/*
20801 + * Copyright (c) 2002 Petko Manolov (petkan@users.sourceforge.net)
20802 + *
20803 + * This program is free software; you can redistribute it and/or
20804 + * modify it under the terms of the GNU General Public License
20805 + * version 2 as published by the Free Software Foundation.
20806 + */
20807 +
20808 +#include <linux/signal.h>
20809 +#include <linux/slab.h>
20810 +#include <linux/module.h>
20811 +#include <linux/netdevice.h>
20812 +#include <linux/etherdevice.h>
20813 +#include <linux/mii.h>
20814 +#include <linux/ethtool.h>
20815 +#include <linux/usb.h>
20816 +#include <asm/uaccess.h>
20817 +
20818 +/* Version Information */
20819 +#define DRIVER_VERSION "v0.6.2 (2004/08/27)"
20820 +#define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
20821 +#define DRIVER_DESC "rtl8150 based usb-ethernet driver"
20822 +
20823 +#define IDR 0x0120
20824 +#define MAR 0x0126
20825 +#define CR 0x012e
20826 +#define TCR 0x012f
20827 +#define RCR 0x0130
20828 +#define TSR 0x0132
20829 +#define RSR 0x0133
20830 +#define CON0 0x0135
20831 +#define CON1 0x0136
20832 +#define MSR 0x0137
20833 +#define PHYADD 0x0138
20834 +#define PHYDAT 0x0139
20835 +#define PHYCNT 0x013b
20836 +#define GPPC 0x013d
20837 +#define BMCR 0x0140
20838 +#define BMSR 0x0142
20839 +#define ANAR 0x0144
20840 +#define ANLP 0x0146
20841 +#define AER 0x0148
20842 +#define CSCR 0x014C /* This one has the link status */
20843 +#define CSCR_LINK_STATUS (1 << 3)
20844 +
20845 +#define IDR_EEPROM 0x1202
20846 +
20847 +#define PHY_READ 0
20848 +#define PHY_WRITE 0x20
20849 +#define PHY_GO 0x40
20850 +
20851 +#define MII_TIMEOUT 10
20852 +#define INTBUFSIZE 8
20853 +
20854 +#define RTL8150_REQT_READ 0xc0
20855 +#define RTL8150_REQT_WRITE 0x40
20856 +#define RTL8150_REQ_GET_REGS 0x05
20857 +#define RTL8150_REQ_SET_REGS 0x05
20858 +
20859 +
20860 +/* Transmit status register errors */
20861 +#define TSR_ECOL (1<<5)
20862 +#define TSR_LCOL (1<<4)
20863 +#define TSR_LOSS_CRS (1<<3)
20864 +#define TSR_JBR (1<<2)
20865 +#define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
20866 +/* Receive status register errors */
20867 +#define RSR_CRC (1<<2)
20868 +#define RSR_FAE (1<<1)
20869 +#define RSR_ERRORS (RSR_CRC | RSR_FAE)
20870 +
20871 +/* Media status register definitions */
20872 +#define MSR_DUPLEX (1<<4)
20873 +#define MSR_SPEED (1<<3)
20874 +#define MSR_LINK (1<<2)
20875 +
20876 +/* Interrupt pipe data */
20877 +#define INT_TSR 0x00
20878 +#define INT_RSR 0x01
20879 +#define INT_MSR 0x02
20880 +#define INT_WAKSR 0x03
20881 +#define INT_TXOK_CNT 0x04
20882 +#define INT_RXLOST_CNT 0x05
20883 +#define INT_CRERR_CNT 0x06
20884 +#define INT_COL_CNT 0x07
20885 +
20886 +
20887 +#define RTL8150_MTU 1540
20888 +#define RTL8150_TX_TIMEOUT (HZ)
20889 +#define RX_SKB_POOL_SIZE 4
20890 +
20891 +/* rtl8150 flags */
20892 +#define RTL8150_HW_CRC 0
20893 +#define RX_REG_SET 1
20894 +#define RTL8150_UNPLUG 2
20895 +#define RX_URB_FAIL 3
20896 +
20897 +/* Define these values to match your device */
20898 +#define VENDOR_ID_REALTEK 0x0bda
20899 +#define VENDOR_ID_MELCO 0x0411
20900 +#define VENDOR_ID_MICRONET 0x3980
20901 +#define VENDOR_ID_LONGSHINE 0x07b8
20902 +#define VENDOR_ID_OQO 0x1557
20903 +#define VENDOR_ID_ZYXEL 0x0586
20904 +
20905 +#define PRODUCT_ID_RTL8150 0x8150
20906 +#define PRODUCT_ID_LUAKTX 0x0012
20907 +#define PRODUCT_ID_LCS8138TX 0x401a
20908 +#define PRODUCT_ID_SP128AR 0x0003
20909 +#define PRODUCT_ID_PRESTIGE 0x401a
20910 +
20911 +#undef EEPROM_WRITE
20912 +
20913 +/* table of devices that work with this driver */
20914 +static struct usb_device_id rtl8150_table[] = {
20915 + {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8150)},
20916 + {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)},
20917 + {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)},
20918 + {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)},
20919 + {USB_DEVICE(VENDOR_ID_OQO, PRODUCT_ID_RTL8150)},
20920 + {USB_DEVICE(VENDOR_ID_ZYXEL, PRODUCT_ID_PRESTIGE)},
20921 + {}
20922 +};
20923 +
20924 +MODULE_DEVICE_TABLE(usb, rtl8150_table);
20925 +
20926 +struct rtl8150 {
20927 + unsigned long flags;
20928 + struct usb_device *udev;
20929 + struct tasklet_struct tl;
20930 + struct net_device *netdev;
20931 + struct urb *rx_urb, *tx_urb, *intr_urb;
20932 + struct sk_buff *tx_skb, *rx_skb;
20933 + struct sk_buff *rx_skb_pool[RX_SKB_POOL_SIZE];
20934 + spinlock_t rx_pool_lock;
20935 + struct usb_ctrlrequest dr;
20936 + int intr_interval;
20937 + u8 *intr_buff;
20938 + u8 phy;
20939 +};
20940 +
20941 +typedef struct rtl8150 rtl8150_t;
20942 +
20943 +struct async_req {
20944 + struct usb_ctrlrequest dr;
20945 + u16 rx_creg;
20946 +};
20947 +
20948 +static const char driver_name [] = "rtl8150";
20949 +
20950 +/*
20951 +**
20952 +** device related part of the code
20953 +**
20954 +*/
20955 +static int get_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
20956 +{
20957 + return usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
20958 + RTL8150_REQ_GET_REGS, RTL8150_REQT_READ,
20959 + indx, 0, data, size, 500);
20960 +}
20961 +
20962 +static int set_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
20963 +{
20964 + return usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
20965 + RTL8150_REQ_SET_REGS, RTL8150_REQT_WRITE,
20966 + indx, 0, data, size, 500);
20967 +}
20968 +
20969 +static void async_set_reg_cb(struct urb *urb)
20970 +{
20971 + struct async_req *req = (struct async_req *)urb->context;
20972 + int status = urb->status;
20973 +
20974 + if (status < 0)
20975 + dev_dbg(&urb->dev->dev, "%s failed with %d", __func__, status);
20976 + kfree(req);
20977 + usb_free_urb(urb);
20978 +}
20979 +
20980 +static int async_set_registers(rtl8150_t *dev, u16 indx, u16 size, u16 reg)
20981 +{
20982 + int res = -ENOMEM;
20983 + struct urb *async_urb;
20984 + struct async_req *req;
20985 +
20986 + req = kmalloc(sizeof(struct async_req), GFP_ATOMIC);
20987 + if (req == NULL)
20988 + return res;
20989 + async_urb = usb_alloc_urb(0, GFP_ATOMIC);
20990 + if (async_urb == NULL) {
20991 + kfree(req);
20992 + return res;
20993 + }
20994 + req->rx_creg = cpu_to_le16(reg);
20995 + req->dr.bRequestType = RTL8150_REQT_WRITE;
20996 + req->dr.bRequest = RTL8150_REQ_SET_REGS;
20997 + req->dr.wIndex = 0;
20998 + req->dr.wValue = cpu_to_le16(indx);
20999 + req->dr.wLength = cpu_to_le16(size);
21000 + usb_fill_control_urb(async_urb, dev->udev,
21001 + usb_sndctrlpipe(dev->udev, 0), (void *)&req->dr,
21002 + &req->rx_creg, size, async_set_reg_cb, req);
21003 + res = usb_submit_urb(async_urb, GFP_ATOMIC);
21004 + if (res) {
21005 + if (res == -ENODEV)
21006 + netif_device_detach(dev->netdev);
21007 + dev_err(&dev->udev->dev, "%s failed with %d\n", __func__, res);
21008 + }
21009 + return res;
21010 +}
21011 +
21012 +static int read_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 * reg)
21013 +{
21014 + int i;
21015 + u8 data[3], tmp;
21016 +
21017 + data[0] = phy;
21018 + data[1] = data[2] = 0;
21019 + tmp = indx | PHY_READ | PHY_GO;
21020 + i = 0;
21021 +
21022 + set_registers(dev, PHYADD, sizeof(data), data);
21023 + set_registers(dev, PHYCNT, 1, &tmp);
21024 + do {
21025 + get_registers(dev, PHYCNT, 1, data);
21026 + } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
21027 +
21028 + if (i <= MII_TIMEOUT) {
21029 + get_registers(dev, PHYDAT, 2, data);
21030 + *reg = data[0] | (data[1] << 8);
21031 + return 0;
21032 + } else
21033 + return 1;
21034 +}
21035 +
21036 +static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)
21037 +{
21038 + int i;
21039 + u8 data[3], tmp;
21040 +
21041 + data[0] = phy;
21042 + data[1] = reg & 0xff;
21043 + data[2] = (reg >> 8) & 0xff;
21044 + tmp = indx | PHY_WRITE | PHY_GO;
21045 + i = 0;
21046 +
21047 + set_registers(dev, PHYADD, sizeof(data), data);
21048 + set_registers(dev, PHYCNT, 1, &tmp);
21049 + do {
21050 + get_registers(dev, PHYCNT, 1, data);
21051 + } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
21052 +
21053 + if (i <= MII_TIMEOUT)
21054 + return 0;
21055 + else
21056 + return 1;
21057 +}
21058 +
21059 +static inline void set_ethernet_addr(rtl8150_t * dev)
21060 +{
21061 + u8 node_id[6];
21062 +
21063 + get_registers(dev, IDR, sizeof(node_id), node_id);
21064 + memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id));
21065 +}
21066 +
21067 +static int rtl8150_set_mac_address(struct net_device *netdev, void *p)
21068 +{
21069 + struct sockaddr *addr = p;
21070 + rtl8150_t *dev = netdev_priv(netdev);
21071 +
21072 + if (netif_running(netdev))
21073 + return -EBUSY;
21074 +
21075 + memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
21076 + netdev_dbg(netdev, "Setting MAC address to %pM\n", netdev->dev_addr);
21077 + /* Set the IDR registers. */
21078 + set_registers(dev, IDR, netdev->addr_len, netdev->dev_addr);
21079 +#ifdef EEPROM_WRITE
21080 + {
21081 + int i;
21082 + u8 cr;
21083 + /* Get the CR contents. */
21084 + get_registers(dev, CR, 1, &cr);
21085 + /* Set the WEPROM bit (eeprom write enable). */
21086 + cr |= 0x20;
21087 + set_registers(dev, CR, 1, &cr);
21088 + /* Write the MAC address into eeprom. Eeprom writes must be word-sized,
21089 + so we need to split them up. */
21090 + for (i = 0; i * 2 < netdev->addr_len; i++) {
21091 + set_registers(dev, IDR_EEPROM + (i * 2), 2,
21092 + netdev->dev_addr + (i * 2));
21093 + }
21094 + /* Clear the WEPROM bit (preventing accidental eeprom writes). */
21095 + cr &= 0xdf;
21096 + set_registers(dev, CR, 1, &cr);
21097 + }
21098 +#endif
21099 + return 0;
21100 +}
21101 +
21102 +static int rtl8150_reset(rtl8150_t * dev)
21103 +{
21104 + u8 data = 0x10;
21105 + int i = HZ;
21106 +
21107 + set_registers(dev, CR, 1, &data);
21108 + do {
21109 + get_registers(dev, CR, 1, &data);
21110 + } while ((data & 0x10) && --i);
21111 +
21112 + return (i > 0) ? 1 : 0;
21113 +}
21114 +
21115 +static int alloc_all_urbs(rtl8150_t * dev)
21116 +{
21117 + dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
21118 + if (!dev->rx_urb)
21119 + return 0;
21120 + dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
21121 + if (!dev->tx_urb) {
21122 + usb_free_urb(dev->rx_urb);
21123 + return 0;
21124 + }
21125 + dev->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
21126 + if (!dev->intr_urb) {
21127 + usb_free_urb(dev->rx_urb);
21128 + usb_free_urb(dev->tx_urb);
21129 + return 0;
21130 + }
21131 +
21132 + return 1;
21133 +}
21134 +
21135 +static void free_all_urbs(rtl8150_t * dev)
21136 +{
21137 + usb_free_urb(dev->rx_urb);
21138 + usb_free_urb(dev->tx_urb);
21139 + usb_free_urb(dev->intr_urb);
21140 +}
21141 +
21142 +static void unlink_all_urbs(rtl8150_t * dev)
21143 +{
21144 + usb_kill_urb(dev->rx_urb);
21145 + usb_kill_urb(dev->tx_urb);
21146 + usb_kill_urb(dev->intr_urb);
21147 +}
21148 +
21149 +static inline struct sk_buff *pull_skb(rtl8150_t *dev)
21150 +{
21151 + struct sk_buff *skb;
21152 + int i;
21153 +
21154 + for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
21155 + if (dev->rx_skb_pool[i]) {
21156 + skb = dev->rx_skb_pool[i];
21157 + dev->rx_skb_pool[i] = NULL;
21158 + return skb;
21159 + }
21160 + }
21161 + return NULL;
21162 +}
21163 +
21164 +static void read_bulk_callback(struct urb *urb)
21165 +{
21166 + rtl8150_t *dev;
21167 + unsigned pkt_len, res;
21168 + struct sk_buff *skb;
21169 + struct net_device *netdev;
21170 + u16 rx_stat;
21171 + int status = urb->status;
21172 + int result;
21173 +
21174 + dev = urb->context;
21175 + if (!dev)
21176 + return;
21177 + if (test_bit(RTL8150_UNPLUG, &dev->flags))
21178 + return;
21179 + netdev = dev->netdev;
21180 + if (!netif_device_present(netdev))
21181 + return;
21182 +
21183 + switch (status) {
21184 + case 0:
21185 + break;
21186 + case -ENOENT:
21187 + return; /* the urb is in unlink state */
21188 + case -ETIME:
21189 + if (printk_ratelimit())
21190 + dev_warn(&urb->dev->dev, "may be reset is needed?..\n");
21191 + goto goon;
21192 + default:
21193 + if (printk_ratelimit())
21194 + dev_warn(&urb->dev->dev, "Rx status %d\n", status);
21195 + goto goon;
21196 + }
21197 +
21198 + if (!dev->rx_skb)
21199 + goto resched;
21200 + /* protect against short packets (tell me why we got some?!?) */
21201 + if (urb->actual_length < 4)
21202 + goto goon;
21203 +
21204 + res = urb->actual_length;
21205 + rx_stat = le16_to_cpu(*(__le16 *)(urb->transfer_buffer + res - 4));
21206 + pkt_len = res - 4;
21207 +
21208 + skb_put(dev->rx_skb, pkt_len);
21209 + dev->rx_skb->protocol = eth_type_trans(dev->rx_skb, netdev);
21210 + netif_rx(dev->rx_skb);
21211 + netdev->stats.rx_packets++;
21212 + netdev->stats.rx_bytes += pkt_len;
21213 +
21214 + spin_lock(&dev->rx_pool_lock);
21215 + skb = pull_skb(dev);
21216 + spin_unlock(&dev->rx_pool_lock);
21217 + if (!skb)
21218 + goto resched;
21219 +
21220 + dev->rx_skb = skb;
21221 +goon:
21222 + usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
21223 + dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
21224 + result = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
21225 + if (result == -ENODEV)
21226 + netif_device_detach(dev->netdev);
21227 + else if (result) {
21228 + set_bit(RX_URB_FAIL, &dev->flags);
21229 + goto resched;
21230 + } else {
21231 + clear_bit(RX_URB_FAIL, &dev->flags);
21232 + }
21233 +
21234 + return;
21235 +resched:
21236 + tasklet_schedule(&dev->tl);
21237 +}
21238 +
21239 +static void write_bulk_callback(struct urb *urb)
21240 +{
21241 + rtl8150_t *dev;
21242 + int status = urb->status;
21243 +
21244 + dev = urb->context;
21245 + if (!dev)
21246 + return;
21247 + dev_kfree_skb_irq(dev->tx_skb);
21248 + if (!netif_device_present(dev->netdev))
21249 + return;
21250 + if (status)
21251 + dev_info(&urb->dev->dev, "%s: Tx status %d\n",
21252 + dev->netdev->name, status);
21253 + dev->netdev->trans_start = jiffies;
21254 + netif_wake_queue(dev->netdev);
21255 +}
21256 +
21257 +static void intr_callback(struct urb *urb)
21258 +{
21259 + rtl8150_t *dev;
21260 + __u8 *d;
21261 + int status = urb->status;
21262 + int res;
21263 +
21264 + dev = urb->context;
21265 + if (!dev)
21266 + return;
21267 + switch (status) {
21268 + case 0: /* success */
21269 + break;
21270 + case -ECONNRESET: /* unlink */
21271 + case -ENOENT:
21272 + case -ESHUTDOWN:
21273 + return;
21274 + /* -EPIPE: should clear the halt */
21275 + default:
21276 + dev_info(&urb->dev->dev, "%s: intr status %d\n",
21277 + dev->netdev->name, status);
21278 + goto resubmit;
21279 + }
21280 +
21281 + d = urb->transfer_buffer;
21282 + if (d[0] & TSR_ERRORS) {
21283 + dev->netdev->stats.tx_errors++;
21284 + if (d[INT_TSR] & (TSR_ECOL | TSR_JBR))
21285 + dev->netdev->stats.tx_aborted_errors++;
21286 + if (d[INT_TSR] & TSR_LCOL)
21287 + dev->netdev->stats.tx_window_errors++;
21288 + if (d[INT_TSR] & TSR_LOSS_CRS)
21289 + dev->netdev->stats.tx_carrier_errors++;
21290 + }
21291 + /* Report link status changes to the network stack */
21292 + if ((d[INT_MSR] & MSR_LINK) == 0) {
21293 + if (netif_carrier_ok(dev->netdev)) {
21294 + netif_carrier_off(dev->netdev);
21295 + netdev_dbg(dev->netdev, "%s: LINK LOST\n", __func__);
21296 + }
21297 + } else {
21298 + if (!netif_carrier_ok(dev->netdev)) {
21299 + netif_carrier_on(dev->netdev);
21300 + netdev_dbg(dev->netdev, "%s: LINK CAME BACK\n", __func__);
21301 + }
21302 + }
21303 +
21304 +resubmit:
21305 + res = usb_submit_urb (urb, GFP_ATOMIC);
21306 + if (res == -ENODEV)
21307 + netif_device_detach(dev->netdev);
21308 + else if (res)
21309 + dev_err(&dev->udev->dev,
21310 + "can't resubmit intr, %s-%s/input0, status %d\n",
21311 + dev->udev->bus->bus_name, dev->udev->devpath, res);
21312 +}
21313 +
21314 +static int rtl8150_suspend(struct usb_interface *intf, pm_message_t message)
21315 +{
21316 + rtl8150_t *dev = usb_get_intfdata(intf);
21317 +
21318 + netif_device_detach(dev->netdev);
21319 +
21320 + if (netif_running(dev->netdev)) {
21321 + usb_kill_urb(dev->rx_urb);
21322 + usb_kill_urb(dev->intr_urb);
21323 + }
21324 + return 0;
21325 +}
21326 +
21327 +static int rtl8150_resume(struct usb_interface *intf)
21328 +{
21329 + rtl8150_t *dev = usb_get_intfdata(intf);
21330 +
21331 + netif_device_attach(dev->netdev);
21332 + if (netif_running(dev->netdev)) {
21333 + dev->rx_urb->status = 0;
21334 + dev->rx_urb->actual_length = 0;
21335 + read_bulk_callback(dev->rx_urb);
21336 +
21337 + dev->intr_urb->status = 0;
21338 + dev->intr_urb->actual_length = 0;
21339 + intr_callback(dev->intr_urb);
21340 + }
21341 + return 0;
21342 +}
21343 +
21344 +/*
21345 +**
21346 +** network related part of the code
21347 +**
21348 +*/
21349 +
21350 +static void fill_skb_pool(rtl8150_t *dev)
21351 +{
21352 + struct sk_buff *skb;
21353 + int i;
21354 +
21355 + for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
21356 + if (dev->rx_skb_pool[i])
21357 + continue;
21358 + skb = dev_alloc_skb(RTL8150_MTU + 2);
21359 + if (!skb) {
21360 + return;
21361 + }
21362 + skb_reserve(skb, 2);
21363 + dev->rx_skb_pool[i] = skb;
21364 + }
21365 +}
21366 +
21367 +static void free_skb_pool(rtl8150_t *dev)
21368 +{
21369 + int i;
21370 +
21371 + for (i = 0; i < RX_SKB_POOL_SIZE; i++)
21372 + if (dev->rx_skb_pool[i])
21373 + dev_kfree_skb(dev->rx_skb_pool[i]);
21374 +}
21375 +
21376 +static void rx_fixup(unsigned long data)
21377 +{
21378 + struct rtl8150 *dev = (struct rtl8150 *)data;
21379 + struct sk_buff *skb;
21380 + int status;
21381 +
21382 + spin_lock_irq(&dev->rx_pool_lock);
21383 + fill_skb_pool(dev);
21384 + spin_unlock_irq(&dev->rx_pool_lock);
21385 + if (test_bit(RX_URB_FAIL, &dev->flags))
21386 + if (dev->rx_skb)
21387 + goto try_again;
21388 + spin_lock_irq(&dev->rx_pool_lock);
21389 + skb = pull_skb(dev);
21390 + spin_unlock_irq(&dev->rx_pool_lock);
21391 + if (skb == NULL)
21392 + goto tlsched;
21393 + dev->rx_skb = skb;
21394 + usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
21395 + dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
21396 +try_again:
21397 + status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
21398 + if (status == -ENODEV) {
21399 + netif_device_detach(dev->netdev);
21400 + } else if (status) {
21401 + set_bit(RX_URB_FAIL, &dev->flags);
21402 + goto tlsched;
21403 + } else {
21404 + clear_bit(RX_URB_FAIL, &dev->flags);
21405 + }
21406 +
21407 + return;
21408 +tlsched:
21409 + tasklet_schedule(&dev->tl);
21410 +}
21411 +
21412 +static int enable_net_traffic(rtl8150_t * dev)
21413 +{
21414 + u8 cr, tcr, rcr, msr;
21415 +
21416 + if (!rtl8150_reset(dev)) {
21417 + dev_warn(&dev->udev->dev, "device reset failed\n");
21418 + }
21419 + /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
21420 + rcr = 0x9e;
21421 + tcr = 0xd8;
21422 + cr = 0x0c;
21423 + if (!(rcr & 0x80))
21424 + set_bit(RTL8150_HW_CRC, &dev->flags);
21425 + set_registers(dev, RCR, 1, &rcr);
21426 + set_registers(dev, TCR, 1, &tcr);
21427 + set_registers(dev, CR, 1, &cr);
21428 + get_registers(dev, MSR, 1, &msr);
21429 +
21430 + return 0;
21431 +}
21432 +
21433 +static void disable_net_traffic(rtl8150_t * dev)
21434 +{
21435 + u8 cr;
21436 +
21437 + get_registers(dev, CR, 1, &cr);
21438 + cr &= 0xf3;
21439 + set_registers(dev, CR, 1, &cr);
21440 +}
21441 +
21442 +static void rtl8150_tx_timeout(struct net_device *netdev)
21443 +{
21444 + rtl8150_t *dev = netdev_priv(netdev);
21445 + dev_warn(&netdev->dev, "Tx timeout.\n");
21446 + usb_unlink_urb(dev->tx_urb);
21447 + netdev->stats.tx_errors++;
21448 +}
21449 +
21450 +static void rtl8150_set_multicast(struct net_device *netdev)
21451 +{
21452 + rtl8150_t *dev = netdev_priv(netdev);
21453 + u16 rx_creg = 0x9e;
21454 +
21455 + netif_stop_queue(netdev);
21456 + if (netdev->flags & IFF_PROMISC) {
21457 + rx_creg |= 0x0001;
21458 + dev_info(&netdev->dev, "%s: promiscuous mode\n", netdev->name);
21459 + } else if (!netdev_mc_empty(netdev) ||
21460 + (netdev->flags & IFF_ALLMULTI)) {
21461 + rx_creg &= 0xfffe;
21462 + rx_creg |= 0x0002;
21463 + dev_info(&netdev->dev, "%s: allmulti set\n", netdev->name);
21464 + } else {
21465 + /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
21466 + rx_creg &= 0x00fc;
21467 + }
21468 + async_set_registers(dev, RCR, sizeof(rx_creg), rx_creg);
21469 + netif_wake_queue(netdev);
21470 +}
21471 +
21472 +static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb,
21473 + struct net_device *netdev)
21474 +{
21475 + rtl8150_t *dev = netdev_priv(netdev);
21476 + int count, res;
21477 +
21478 + netif_stop_queue(netdev);
21479 + count = (skb->len < 60) ? 60 : skb->len;
21480 + count = (count & 0x3f) ? count : count + 1;
21481 + dev->tx_skb = skb;
21482 + usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2),
21483 + skb->data, count, write_bulk_callback, dev);
21484 + if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) {
21485 + /* Can we get/handle EPIPE here? */
21486 + if (res == -ENODEV)
21487 + netif_device_detach(dev->netdev);
21488 + else {
21489 + dev_warn(&netdev->dev, "failed tx_urb %d\n", res);
21490 + netdev->stats.tx_errors++;
21491 + netif_start_queue(netdev);
21492 + }
21493 + } else {
21494 + netdev->stats.tx_packets++;
21495 + netdev->stats.tx_bytes += skb->len;
21496 + netdev->trans_start = jiffies;
21497 + }
21498 +
21499 + return NETDEV_TX_OK;
21500 +}
21501 +
21502 +
21503 +static void set_carrier(struct net_device *netdev)
21504 +{
21505 + rtl8150_t *dev = netdev_priv(netdev);
21506 + short tmp;
21507 +
21508 + get_registers(dev, CSCR, 2, &tmp);
21509 + if (tmp & CSCR_LINK_STATUS)
21510 + netif_carrier_on(netdev);
21511 + else
21512 + netif_carrier_off(netdev);
21513 +}
21514 +
21515 +static int rtl8150_open(struct net_device *netdev)
21516 +{
21517 + rtl8150_t *dev = netdev_priv(netdev);
21518 + int res;
21519 +
21520 + if (dev->rx_skb == NULL)
21521 + dev->rx_skb = pull_skb(dev);
21522 + if (!dev->rx_skb)
21523 + return -ENOMEM;
21524 +
21525 + set_registers(dev, IDR, 6, netdev->dev_addr);
21526 +
21527 + usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
21528 + dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
21529 + if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL))) {
21530 + if (res == -ENODEV)
21531 + netif_device_detach(dev->netdev);
21532 + dev_warn(&netdev->dev, "rx_urb submit failed: %d\n", res);
21533 + return res;
21534 + }
21535 + usb_fill_int_urb(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3),
21536 + dev->intr_buff, INTBUFSIZE, intr_callback,
21537 + dev, dev->intr_interval);
21538 + if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL))) {
21539 + if (res == -ENODEV)
21540 + netif_device_detach(dev->netdev);
21541 + dev_warn(&netdev->dev, "intr_urb submit failed: %d\n", res);
21542 + usb_kill_urb(dev->rx_urb);
21543 + return res;
21544 + }
21545 + enable_net_traffic(dev);
21546 + set_carrier(netdev);
21547 + netif_start_queue(netdev);
21548 +
21549 + return res;
21550 +}
21551 +
21552 +static int rtl8150_close(struct net_device *netdev)
21553 +{
21554 + rtl8150_t *dev = netdev_priv(netdev);
21555 +
21556 + netif_stop_queue(netdev);
21557 + if (!test_bit(RTL8150_UNPLUG, &dev->flags))
21558 + disable_net_traffic(dev);
21559 + unlink_all_urbs(dev);
21560 +
21561 + return 0;
21562 +}
21563 +
21564 +static void rtl8150_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)
21565 +{
21566 + rtl8150_t *dev = netdev_priv(netdev);
21567 +
21568 + strlcpy(info->driver, driver_name, sizeof(info->driver));
21569 + strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
21570 + usb_make_path(dev->udev, info->bus_info, sizeof(info->bus_info));
21571 +}
21572 +
21573 +static int rtl8150_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
21574 +{
21575 + rtl8150_t *dev = netdev_priv(netdev);
21576 + short lpa, bmcr;
21577 +
21578 + ecmd->supported = (SUPPORTED_10baseT_Half |
21579 + SUPPORTED_10baseT_Full |
21580 + SUPPORTED_100baseT_Half |
21581 + SUPPORTED_100baseT_Full |
21582 + SUPPORTED_Autoneg |
21583 + SUPPORTED_TP | SUPPORTED_MII);
21584 + ecmd->port = PORT_TP;
21585 + ecmd->transceiver = XCVR_INTERNAL;
21586 + ecmd->phy_address = dev->phy;
21587 + get_registers(dev, BMCR, 2, &bmcr);
21588 + get_registers(dev, ANLP, 2, &lpa);
21589 + if (bmcr & BMCR_ANENABLE) {
21590 + u32 speed = ((lpa & (LPA_100HALF | LPA_100FULL)) ?
21591 + SPEED_100 : SPEED_10);
21592 + ethtool_cmd_speed_set(ecmd, speed);
21593 + ecmd->autoneg = AUTONEG_ENABLE;
21594 + if (speed == SPEED_100)
21595 + ecmd->duplex = (lpa & LPA_100FULL) ?
21596 + DUPLEX_FULL : DUPLEX_HALF;
21597 + else
21598 + ecmd->duplex = (lpa & LPA_10FULL) ?
21599 + DUPLEX_FULL : DUPLEX_HALF;
21600 + } else {
21601 + ecmd->autoneg = AUTONEG_DISABLE;
21602 + ethtool_cmd_speed_set(ecmd, ((bmcr & BMCR_SPEED100) ?
21603 + SPEED_100 : SPEED_10));
21604 + ecmd->duplex = (bmcr & BMCR_FULLDPLX) ?
21605 + DUPLEX_FULL : DUPLEX_HALF;
21606 + }
21607 + return 0;
21608 +}
21609 +
21610 +static const struct ethtool_ops ops = {
21611 + .get_drvinfo = rtl8150_get_drvinfo,
21612 + .get_settings = rtl8150_get_settings,
21613 + .get_link = ethtool_op_get_link
21614 +};
21615 +
21616 +static int rtl8150_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
21617 +{
21618 + rtl8150_t *dev = netdev_priv(netdev);
21619 + u16 *data = (u16 *) & rq->ifr_ifru;
21620 + int res = 0;
21621 +
21622 + switch (cmd) {
21623 + case SIOCDEVPRIVATE:
21624 + data[0] = dev->phy;
21625 + case SIOCDEVPRIVATE + 1:
21626 + read_mii_word(dev, dev->phy, (data[1] & 0x1f), &data[3]);
21627 + break;
21628 + case SIOCDEVPRIVATE + 2:
21629 + if (!capable(CAP_NET_ADMIN))
21630 + return -EPERM;
21631 + write_mii_word(dev, dev->phy, (data[1] & 0x1f), data[2]);
21632 + break;
21633 + default:
21634 + res = -EOPNOTSUPP;
21635 + }
21636 +
21637 + return res;
21638 +}
21639 +
21640 +static const struct net_device_ops rtl8150_netdev_ops = {
21641 + .ndo_open = rtl8150_open,
21642 + .ndo_stop = rtl8150_close,
21643 + .ndo_do_ioctl = rtl8150_ioctl,
21644 + .ndo_start_xmit = rtl8150_start_xmit,
21645 + .ndo_tx_timeout = rtl8150_tx_timeout,
21646 + .ndo_set_rx_mode = rtl8150_set_multicast,
21647 + .ndo_set_mac_address = rtl8150_set_mac_address,
21648 +
21649 + .ndo_change_mtu = eth_change_mtu,
21650 + .ndo_validate_addr = eth_validate_addr,
21651 +};
21652 +
21653 +static int rtl8150_probe(struct usb_interface *intf,
21654 + const struct usb_device_id *id)
21655 +{
21656 + struct usb_device *udev = interface_to_usbdev(intf);
21657 + rtl8150_t *dev;
21658 + struct net_device *netdev;
21659 +
21660 + netdev = alloc_etherdev(sizeof(rtl8150_t));
21661 + if (!netdev)
21662 + return -ENOMEM;
21663 +
21664 + dev = netdev_priv(netdev);
21665 +
21666 + dev->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL);
21667 + if (!dev->intr_buff) {
21668 + free_netdev(netdev);
21669 + return -ENOMEM;
21670 + }
21671 +
21672 + tasklet_init(&dev->tl, rx_fixup, (unsigned long)dev);
21673 + spin_lock_init(&dev->rx_pool_lock);
21674 +
21675 + dev->udev = udev;
21676 + dev->netdev = netdev;
21677 + netdev->netdev_ops = &rtl8150_netdev_ops;
21678 + netdev->watchdog_timeo = RTL8150_TX_TIMEOUT;
21679 + netdev->ethtool_ops = &ops;
21680 + dev->intr_interval = 100; /* 100ms */
21681 +
21682 + if (!alloc_all_urbs(dev)) {
21683 + dev_err(&intf->dev, "out of memory\n");
21684 + goto out;
21685 + }
21686 + if (!rtl8150_reset(dev)) {
21687 + dev_err(&intf->dev, "couldn't reset the device\n");
21688 + goto out1;
21689 + }
21690 + fill_skb_pool(dev);
21691 + set_ethernet_addr(dev);
21692 +
21693 + usb_set_intfdata(intf, dev);
21694 + SET_NETDEV_DEV(netdev, &intf->dev);
21695 + if (register_netdev(netdev) != 0) {
21696 + dev_err(&intf->dev, "couldn't register the device\n");
21697 + goto out2;
21698 + }
21699 +
21700 + dev_info(&intf->dev, "%s: rtl8150 is detected\n", netdev->name);
21701 +
21702 + return 0;
21703 +
21704 +out2:
21705 + usb_set_intfdata(intf, NULL);
21706 + free_skb_pool(dev);
21707 +out1:
21708 + free_all_urbs(dev);
21709 +out:
21710 + kfree(dev->intr_buff);
21711 + free_netdev(netdev);
21712 + return -EIO;
21713 +}
21714 +
21715 +static void rtl8150_disconnect(struct usb_interface *intf)
21716 +{
21717 + rtl8150_t *dev = usb_get_intfdata(intf);
21718 +
21719 + usb_set_intfdata(intf, NULL);
21720 + if (dev) {
21721 + set_bit(RTL8150_UNPLUG, &dev->flags);
21722 + tasklet_kill(&dev->tl);
21723 + unregister_netdev(dev->netdev);
21724 + unlink_all_urbs(dev);
21725 + free_all_urbs(dev);
21726 + free_skb_pool(dev);
21727 + if (dev->rx_skb)
21728 + dev_kfree_skb(dev->rx_skb);
21729 + kfree(dev->intr_buff);
21730 + free_netdev(dev->netdev);
21731 + }
21732 +}
21733 +
21734 +static struct usb_driver rtl8150_driver = {
21735 + .name = driver_name,
21736 + .probe = rtl8150_probe,
21737 + .disconnect = rtl8150_disconnect,
21738 + .id_table = rtl8150_table,
21739 + .suspend = rtl8150_suspend,
21740 + .resume = rtl8150_resume,
21741 + .disable_hub_initiated_lpm = 1,
21742 +};
21743 +
21744 +module_usb_driver(rtl8150_driver);
21745 +
21746 +MODULE_AUTHOR(DRIVER_AUTHOR);
21747 +MODULE_DESCRIPTION(DRIVER_DESC);
21748 +MODULE_LICENSE("GPL");
21749 diff -Naur backports-4.2.6-1.org/drivers/net/usb/smsc75xx.c backports-4.2.6-1/drivers/net/usb/smsc75xx.c
21750 --- backports-4.2.6-1.org/drivers/net/usb/smsc75xx.c 1970-01-01 01:00:00.000000000 +0100
21751 +++ backports-4.2.6-1/drivers/net/usb/smsc75xx.c 2016-06-28 14:35:18.008640551 +0200
21752 @@ -0,0 +1,2286 @@
21753 + /***************************************************************************
21754 + *
21755 + * Copyright (C) 2007-2010 SMSC
21756 + *
21757 + * This program is free software; you can redistribute it and/or
21758 + * modify it under the terms of the GNU General Public License
21759 + * as published by the Free Software Foundation; either version 2
21760 + * of the License, or (at your option) any later version.
21761 + *
21762 + * This program is distributed in the hope that it will be useful,
21763 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21764 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21765 + * GNU General Public License for more details.
21766 + *
21767 + * You should have received a copy of the GNU General Public License
21768 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
21769 + *
21770 + *****************************************************************************/
21771 +
21772 +#include <linux/module.h>
21773 +#include <linux/kmod.h>
21774 +#include <linux/netdevice.h>
21775 +#include <linux/etherdevice.h>
21776 +#include <linux/ethtool.h>
21777 +#include <linux/mii.h>
21778 +#include <linux/usb.h>
21779 +#include <linux/bitrev.h>
21780 +#include <linux/crc16.h>
21781 +#include <linux/crc32.h>
21782 +#include <linux/usb/usbnet.h>
21783 +#include <linux/slab.h>
21784 +#include "smsc75xx.h"
21785 +
21786 +#define SMSC_CHIPNAME "smsc75xx"
21787 +#define SMSC_DRIVER_VERSION "1.0.0"
21788 +#define HS_USB_PKT_SIZE (512)
21789 +#define FS_USB_PKT_SIZE (64)
21790 +#define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE)
21791 +#define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE)
21792 +#define DEFAULT_BULK_IN_DELAY (0x00002000)
21793 +#define MAX_SINGLE_PACKET_SIZE (9000)
21794 +#define LAN75XX_EEPROM_MAGIC (0x7500)
21795 +#define EEPROM_MAC_OFFSET (0x01)
21796 +#define DEFAULT_TX_CSUM_ENABLE (true)
21797 +#define DEFAULT_RX_CSUM_ENABLE (true)
21798 +#define SMSC75XX_INTERNAL_PHY_ID (1)
21799 +#define SMSC75XX_TX_OVERHEAD (8)
21800 +#define MAX_RX_FIFO_SIZE (20 * 1024)
21801 +#define MAX_TX_FIFO_SIZE (12 * 1024)
21802 +#define USB_VENDOR_ID_SMSC (0x0424)
21803 +#define USB_PRODUCT_ID_LAN7500 (0x7500)
21804 +#define USB_PRODUCT_ID_LAN7505 (0x7505)
21805 +#define RXW_PADDING 2
21806 +#define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \
21807 + WAKE_MCAST | WAKE_ARP | WAKE_MAGIC)
21808 +
21809 +#define SUSPEND_SUSPEND0 (0x01)
21810 +#define SUSPEND_SUSPEND1 (0x02)
21811 +#define SUSPEND_SUSPEND2 (0x04)
21812 +#define SUSPEND_SUSPEND3 (0x08)
21813 +#define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
21814 + SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
21815 +
21816 +struct smsc75xx_priv {
21817 + struct usbnet *dev;
21818 + u32 rfe_ctl;
21819 + u32 wolopts;
21820 + u32 multicast_hash_table[DP_SEL_VHF_HASH_LEN];
21821 + struct mutex dataport_mutex;
21822 + spinlock_t rfe_ctl_lock;
21823 + struct work_struct set_multicast;
21824 + u8 suspend_flags;
21825 +};
21826 +
21827 +struct usb_context {
21828 + struct usb_ctrlrequest req;
21829 + struct usbnet *dev;
21830 +};
21831 +
21832 +static bool turbo_mode = true;
21833 +module_param(turbo_mode, bool, 0644);
21834 +MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
21835 +
21836 +static int __must_check __smsc75xx_read_reg(struct usbnet *dev, u32 index,
21837 + u32 *data, int in_pm)
21838 +{
21839 + u32 buf;
21840 + int ret;
21841 + int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
21842 +
21843 + BUG_ON(!dev);
21844 +
21845 + if (!in_pm)
21846 + fn = usbnet_read_cmd;
21847 + else
21848 + fn = usbnet_read_cmd_nopm;
21849 +
21850 + ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN
21851 + | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
21852 + 0, index, &buf, 4);
21853 + if (unlikely(ret < 0))
21854 + netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n",
21855 + index, ret);
21856 +
21857 + le32_to_cpus(&buf);
21858 + *data = buf;
21859 +
21860 + return ret;
21861 +}
21862 +
21863 +static int __must_check __smsc75xx_write_reg(struct usbnet *dev, u32 index,
21864 + u32 data, int in_pm)
21865 +{
21866 + u32 buf;
21867 + int ret;
21868 + int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
21869 +
21870 + BUG_ON(!dev);
21871 +
21872 + if (!in_pm)
21873 + fn = usbnet_write_cmd;
21874 + else
21875 + fn = usbnet_write_cmd_nopm;
21876 +
21877 + buf = data;
21878 + cpu_to_le32s(&buf);
21879 +
21880 + ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT
21881 + | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
21882 + 0, index, &buf, 4);
21883 + if (unlikely(ret < 0))
21884 + netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n",
21885 + index, ret);
21886 +
21887 + return ret;
21888 +}
21889 +
21890 +static int __must_check smsc75xx_read_reg_nopm(struct usbnet *dev, u32 index,
21891 + u32 *data)
21892 +{
21893 + return __smsc75xx_read_reg(dev, index, data, 1);
21894 +}
21895 +
21896 +static int __must_check smsc75xx_write_reg_nopm(struct usbnet *dev, u32 index,
21897 + u32 data)
21898 +{
21899 + return __smsc75xx_write_reg(dev, index, data, 1);
21900 +}
21901 +
21902 +static int __must_check smsc75xx_read_reg(struct usbnet *dev, u32 index,
21903 + u32 *data)
21904 +{
21905 + return __smsc75xx_read_reg(dev, index, data, 0);
21906 +}
21907 +
21908 +static int __must_check smsc75xx_write_reg(struct usbnet *dev, u32 index,
21909 + u32 data)
21910 +{
21911 + return __smsc75xx_write_reg(dev, index, data, 0);
21912 +}
21913 +
21914 +/* Loop until the read is completed with timeout
21915 + * called with phy_mutex held */
21916 +static __must_check int __smsc75xx_phy_wait_not_busy(struct usbnet *dev,
21917 + int in_pm)
21918 +{
21919 + unsigned long start_time = jiffies;
21920 + u32 val;
21921 + int ret;
21922 +
21923 + do {
21924 + ret = __smsc75xx_read_reg(dev, MII_ACCESS, &val, in_pm);
21925 + if (ret < 0) {
21926 + netdev_warn(dev->net, "Error reading MII_ACCESS\n");
21927 + return ret;
21928 + }
21929 +
21930 + if (!(val & MII_ACCESS_BUSY))
21931 + return 0;
21932 + } while (!time_after(jiffies, start_time + HZ));
21933 +
21934 + return -EIO;
21935 +}
21936 +
21937 +static int __smsc75xx_mdio_read(struct net_device *netdev, int phy_id, int idx,
21938 + int in_pm)
21939 +{
21940 + struct usbnet *dev = netdev_priv(netdev);
21941 + u32 val, addr;
21942 + int ret;
21943 +
21944 + mutex_lock(&dev->phy_mutex);
21945 +
21946 + /* confirm MII not busy */
21947 + ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
21948 + if (ret < 0) {
21949 + netdev_warn(dev->net, "MII is busy in smsc75xx_mdio_read\n");
21950 + goto done;
21951 + }
21952 +
21953 + /* set the address, index & direction (read from PHY) */
21954 + phy_id &= dev->mii.phy_id_mask;
21955 + idx &= dev->mii.reg_num_mask;
21956 + addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR)
21957 + | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR)
21958 + | MII_ACCESS_READ | MII_ACCESS_BUSY;
21959 + ret = __smsc75xx_write_reg(dev, MII_ACCESS, addr, in_pm);
21960 + if (ret < 0) {
21961 + netdev_warn(dev->net, "Error writing MII_ACCESS\n");
21962 + goto done;
21963 + }
21964 +
21965 + ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
21966 + if (ret < 0) {
21967 + netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx);
21968 + goto done;
21969 + }
21970 +
21971 + ret = __smsc75xx_read_reg(dev, MII_DATA, &val, in_pm);
21972 + if (ret < 0) {
21973 + netdev_warn(dev->net, "Error reading MII_DATA\n");
21974 + goto done;
21975 + }
21976 +
21977 + ret = (u16)(val & 0xFFFF);
21978 +
21979 +done:
21980 + mutex_unlock(&dev->phy_mutex);
21981 + return ret;
21982 +}
21983 +
21984 +static void __smsc75xx_mdio_write(struct net_device *netdev, int phy_id,
21985 + int idx, int regval, int in_pm)
21986 +{
21987 + struct usbnet *dev = netdev_priv(netdev);
21988 + u32 val, addr;
21989 + int ret;
21990 +
21991 + mutex_lock(&dev->phy_mutex);
21992 +
21993 + /* confirm MII not busy */
21994 + ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
21995 + if (ret < 0) {
21996 + netdev_warn(dev->net, "MII is busy in smsc75xx_mdio_write\n");
21997 + goto done;
21998 + }
21999 +
22000 + val = regval;
22001 + ret = __smsc75xx_write_reg(dev, MII_DATA, val, in_pm);
22002 + if (ret < 0) {
22003 + netdev_warn(dev->net, "Error writing MII_DATA\n");
22004 + goto done;
22005 + }
22006 +
22007 + /* set the address, index & direction (write to PHY) */
22008 + phy_id &= dev->mii.phy_id_mask;
22009 + idx &= dev->mii.reg_num_mask;
22010 + addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR)
22011 + | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR)
22012 + | MII_ACCESS_WRITE | MII_ACCESS_BUSY;
22013 + ret = __smsc75xx_write_reg(dev, MII_ACCESS, addr, in_pm);
22014 + if (ret < 0) {
22015 + netdev_warn(dev->net, "Error writing MII_ACCESS\n");
22016 + goto done;
22017 + }
22018 +
22019 + ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
22020 + if (ret < 0) {
22021 + netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx);
22022 + goto done;
22023 + }
22024 +
22025 +done:
22026 + mutex_unlock(&dev->phy_mutex);
22027 +}
22028 +
22029 +static int smsc75xx_mdio_read_nopm(struct net_device *netdev, int phy_id,
22030 + int idx)
22031 +{
22032 + return __smsc75xx_mdio_read(netdev, phy_id, idx, 1);
22033 +}
22034 +
22035 +static void smsc75xx_mdio_write_nopm(struct net_device *netdev, int phy_id,
22036 + int idx, int regval)
22037 +{
22038 + __smsc75xx_mdio_write(netdev, phy_id, idx, regval, 1);
22039 +}
22040 +
22041 +static int smsc75xx_mdio_read(struct net_device *netdev, int phy_id, int idx)
22042 +{
22043 + return __smsc75xx_mdio_read(netdev, phy_id, idx, 0);
22044 +}
22045 +
22046 +static void smsc75xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
22047 + int regval)
22048 +{
22049 + __smsc75xx_mdio_write(netdev, phy_id, idx, regval, 0);
22050 +}
22051 +
22052 +static int smsc75xx_wait_eeprom(struct usbnet *dev)
22053 +{
22054 + unsigned long start_time = jiffies;
22055 + u32 val;
22056 + int ret;
22057 +
22058 + do {
22059 + ret = smsc75xx_read_reg(dev, E2P_CMD, &val);
22060 + if (ret < 0) {
22061 + netdev_warn(dev->net, "Error reading E2P_CMD\n");
22062 + return ret;
22063 + }
22064 +
22065 + if (!(val & E2P_CMD_BUSY) || (val & E2P_CMD_TIMEOUT))
22066 + break;
22067 + udelay(40);
22068 + } while (!time_after(jiffies, start_time + HZ));
22069 +
22070 + if (val & (E2P_CMD_TIMEOUT | E2P_CMD_BUSY)) {
22071 + netdev_warn(dev->net, "EEPROM read operation timeout\n");
22072 + return -EIO;
22073 + }
22074 +
22075 + return 0;
22076 +}
22077 +
22078 +static int smsc75xx_eeprom_confirm_not_busy(struct usbnet *dev)
22079 +{
22080 + unsigned long start_time = jiffies;
22081 + u32 val;
22082 + int ret;
22083 +
22084 + do {
22085 + ret = smsc75xx_read_reg(dev, E2P_CMD, &val);
22086 + if (ret < 0) {
22087 + netdev_warn(dev->net, "Error reading E2P_CMD\n");
22088 + return ret;
22089 + }
22090 +
22091 + if (!(val & E2P_CMD_BUSY))
22092 + return 0;
22093 +
22094 + udelay(40);
22095 + } while (!time_after(jiffies, start_time + HZ));
22096 +
22097 + netdev_warn(dev->net, "EEPROM is busy\n");
22098 + return -EIO;
22099 +}
22100 +
22101 +static int smsc75xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
22102 + u8 *data)
22103 +{
22104 + u32 val;
22105 + int i, ret;
22106 +
22107 + BUG_ON(!dev);
22108 + BUG_ON(!data);
22109 +
22110 + ret = smsc75xx_eeprom_confirm_not_busy(dev);
22111 + if (ret)
22112 + return ret;
22113 +
22114 + for (i = 0; i < length; i++) {
22115 + val = E2P_CMD_BUSY | E2P_CMD_READ | (offset & E2P_CMD_ADDR);
22116 + ret = smsc75xx_write_reg(dev, E2P_CMD, val);
22117 + if (ret < 0) {
22118 + netdev_warn(dev->net, "Error writing E2P_CMD\n");
22119 + return ret;
22120 + }
22121 +
22122 + ret = smsc75xx_wait_eeprom(dev);
22123 + if (ret < 0)
22124 + return ret;
22125 +
22126 + ret = smsc75xx_read_reg(dev, E2P_DATA, &val);
22127 + if (ret < 0) {
22128 + netdev_warn(dev->net, "Error reading E2P_DATA\n");
22129 + return ret;
22130 + }
22131 +
22132 + data[i] = val & 0xFF;
22133 + offset++;
22134 + }
22135 +
22136 + return 0;
22137 +}
22138 +
22139 +static int smsc75xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
22140 + u8 *data)
22141 +{
22142 + u32 val;
22143 + int i, ret;
22144 +
22145 + BUG_ON(!dev);
22146 + BUG_ON(!data);
22147 +
22148 + ret = smsc75xx_eeprom_confirm_not_busy(dev);
22149 + if (ret)
22150 + return ret;
22151 +
22152 + /* Issue write/erase enable command */
22153 + val = E2P_CMD_BUSY | E2P_CMD_EWEN;
22154 + ret = smsc75xx_write_reg(dev, E2P_CMD, val);
22155 + if (ret < 0) {
22156 + netdev_warn(dev->net, "Error writing E2P_CMD\n");
22157 + return ret;
22158 + }
22159 +
22160 + ret = smsc75xx_wait_eeprom(dev);
22161 + if (ret < 0)
22162 + return ret;
22163 +
22164 + for (i = 0; i < length; i++) {
22165 +
22166 + /* Fill data register */
22167 + val = data[i];
22168 + ret = smsc75xx_write_reg(dev, E2P_DATA, val);
22169 + if (ret < 0) {
22170 + netdev_warn(dev->net, "Error writing E2P_DATA\n");
22171 + return ret;
22172 + }
22173 +
22174 + /* Send "write" command */
22175 + val = E2P_CMD_BUSY | E2P_CMD_WRITE | (offset & E2P_CMD_ADDR);
22176 + ret = smsc75xx_write_reg(dev, E2P_CMD, val);
22177 + if (ret < 0) {
22178 + netdev_warn(dev->net, "Error writing E2P_CMD\n");
22179 + return ret;
22180 + }
22181 +
22182 + ret = smsc75xx_wait_eeprom(dev);
22183 + if (ret < 0)
22184 + return ret;
22185 +
22186 + offset++;
22187 + }
22188 +
22189 + return 0;
22190 +}
22191 +
22192 +static int smsc75xx_dataport_wait_not_busy(struct usbnet *dev)
22193 +{
22194 + int i, ret;
22195 +
22196 + for (i = 0; i < 100; i++) {
22197 + u32 dp_sel;
22198 + ret = smsc75xx_read_reg(dev, DP_SEL, &dp_sel);
22199 + if (ret < 0) {
22200 + netdev_warn(dev->net, "Error reading DP_SEL\n");
22201 + return ret;
22202 + }
22203 +
22204 + if (dp_sel & DP_SEL_DPRDY)
22205 + return 0;
22206 +
22207 + udelay(40);
22208 + }
22209 +
22210 + netdev_warn(dev->net, "smsc75xx_dataport_wait_not_busy timed out\n");
22211 +
22212 + return -EIO;
22213 +}
22214 +
22215 +static int smsc75xx_dataport_write(struct usbnet *dev, u32 ram_select, u32 addr,
22216 + u32 length, u32 *buf)
22217 +{
22218 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
22219 + u32 dp_sel;
22220 + int i, ret;
22221 +
22222 + mutex_lock(&pdata->dataport_mutex);
22223 +
22224 + ret = smsc75xx_dataport_wait_not_busy(dev);
22225 + if (ret < 0) {
22226 + netdev_warn(dev->net, "smsc75xx_dataport_write busy on entry\n");
22227 + goto done;
22228 + }
22229 +
22230 + ret = smsc75xx_read_reg(dev, DP_SEL, &dp_sel);
22231 + if (ret < 0) {
22232 + netdev_warn(dev->net, "Error reading DP_SEL\n");
22233 + goto done;
22234 + }
22235 +
22236 + dp_sel &= ~DP_SEL_RSEL;
22237 + dp_sel |= ram_select;
22238 + ret = smsc75xx_write_reg(dev, DP_SEL, dp_sel);
22239 + if (ret < 0) {
22240 + netdev_warn(dev->net, "Error writing DP_SEL\n");
22241 + goto done;
22242 + }
22243 +
22244 + for (i = 0; i < length; i++) {
22245 + ret = smsc75xx_write_reg(dev, DP_ADDR, addr + i);
22246 + if (ret < 0) {
22247 + netdev_warn(dev->net, "Error writing DP_ADDR\n");
22248 + goto done;
22249 + }
22250 +
22251 + ret = smsc75xx_write_reg(dev, DP_DATA, buf[i]);
22252 + if (ret < 0) {
22253 + netdev_warn(dev->net, "Error writing DP_DATA\n");
22254 + goto done;
22255 + }
22256 +
22257 + ret = smsc75xx_write_reg(dev, DP_CMD, DP_CMD_WRITE);
22258 + if (ret < 0) {
22259 + netdev_warn(dev->net, "Error writing DP_CMD\n");
22260 + goto done;
22261 + }
22262 +
22263 + ret = smsc75xx_dataport_wait_not_busy(dev);
22264 + if (ret < 0) {
22265 + netdev_warn(dev->net, "smsc75xx_dataport_write timeout\n");
22266 + goto done;
22267 + }
22268 + }
22269 +
22270 +done:
22271 + mutex_unlock(&pdata->dataport_mutex);
22272 + return ret;
22273 +}
22274 +
22275 +/* returns hash bit number for given MAC address */
22276 +static u32 smsc75xx_hash(char addr[ETH_ALEN])
22277 +{
22278 + return (ether_crc(ETH_ALEN, addr) >> 23) & 0x1ff;
22279 +}
22280 +
22281 +static void smsc75xx_deferred_multicast_write(struct work_struct *param)
22282 +{
22283 + struct smsc75xx_priv *pdata =
22284 + container_of(param, struct smsc75xx_priv, set_multicast);
22285 + struct usbnet *dev = pdata->dev;
22286 + int ret;
22287 +
22288 + netif_dbg(dev, drv, dev->net, "deferred multicast write 0x%08x\n",
22289 + pdata->rfe_ctl);
22290 +
22291 + smsc75xx_dataport_write(dev, DP_SEL_VHF, DP_SEL_VHF_VLAN_LEN,
22292 + DP_SEL_VHF_HASH_LEN, pdata->multicast_hash_table);
22293 +
22294 + ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
22295 + if (ret < 0)
22296 + netdev_warn(dev->net, "Error writing RFE_CRL\n");
22297 +}
22298 +
22299 +static void smsc75xx_set_multicast(struct net_device *netdev)
22300 +{
22301 + struct usbnet *dev = netdev_priv(netdev);
22302 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
22303 + unsigned long flags;
22304 + int i;
22305 +
22306 + spin_lock_irqsave(&pdata->rfe_ctl_lock, flags);
22307 +
22308 + pdata->rfe_ctl &=
22309 + ~(RFE_CTL_AU | RFE_CTL_AM | RFE_CTL_DPF | RFE_CTL_MHF);
22310 + pdata->rfe_ctl |= RFE_CTL_AB;
22311 +
22312 + for (i = 0; i < DP_SEL_VHF_HASH_LEN; i++)
22313 + pdata->multicast_hash_table[i] = 0;
22314 +
22315 + if (dev->net->flags & IFF_PROMISC) {
22316 + netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n");
22317 + pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_AU;
22318 + } else if (dev->net->flags & IFF_ALLMULTI) {
22319 + netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n");
22320 + pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_DPF;
22321 + } else if (!netdev_mc_empty(dev->net)) {
22322 + struct netdev_hw_addr *ha;
22323 +
22324 + netif_dbg(dev, drv, dev->net, "receive multicast hash filter\n");
22325 +
22326 + pdata->rfe_ctl |= RFE_CTL_MHF | RFE_CTL_DPF;
22327 +
22328 + netdev_for_each_mc_addr(ha, netdev) {
22329 + u32 bitnum = smsc75xx_hash(ha->addr);
22330 + pdata->multicast_hash_table[bitnum / 32] |=
22331 + (1 << (bitnum % 32));
22332 + }
22333 + } else {
22334 + netif_dbg(dev, drv, dev->net, "receive own packets only\n");
22335 + pdata->rfe_ctl |= RFE_CTL_DPF;
22336 + }
22337 +
22338 + spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags);
22339 +
22340 + /* defer register writes to a sleepable context */
22341 + schedule_work(&pdata->set_multicast);
22342 +}
22343 +
22344 +static int smsc75xx_update_flowcontrol(struct usbnet *dev, u8 duplex,
22345 + u16 lcladv, u16 rmtadv)
22346 +{
22347 + u32 flow = 0, fct_flow = 0;
22348 + int ret;
22349 +
22350 + if (duplex == DUPLEX_FULL) {
22351 + u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
22352 +
22353 + if (cap & FLOW_CTRL_TX) {
22354 + flow = (FLOW_TX_FCEN | 0xFFFF);
22355 + /* set fct_flow thresholds to 20% and 80% */
22356 + fct_flow = (8 << 8) | 32;
22357 + }
22358 +
22359 + if (cap & FLOW_CTRL_RX)
22360 + flow |= FLOW_RX_FCEN;
22361 +
22362 + netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n",
22363 + (cap & FLOW_CTRL_RX ? "enabled" : "disabled"),
22364 + (cap & FLOW_CTRL_TX ? "enabled" : "disabled"));
22365 + } else {
22366 + netif_dbg(dev, link, dev->net, "half duplex\n");
22367 + }
22368 +
22369 + ret = smsc75xx_write_reg(dev, FLOW, flow);
22370 + if (ret < 0) {
22371 + netdev_warn(dev->net, "Error writing FLOW\n");
22372 + return ret;
22373 + }
22374 +
22375 + ret = smsc75xx_write_reg(dev, FCT_FLOW, fct_flow);
22376 + if (ret < 0) {
22377 + netdev_warn(dev->net, "Error writing FCT_FLOW\n");
22378 + return ret;
22379 + }
22380 +
22381 + return 0;
22382 +}
22383 +
22384 +static int smsc75xx_link_reset(struct usbnet *dev)
22385 +{
22386 + struct mii_if_info *mii = &dev->mii;
22387 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
22388 + u16 lcladv, rmtadv;
22389 + int ret;
22390 +
22391 + /* write to clear phy interrupt status */
22392 + smsc75xx_mdio_write(dev->net, mii->phy_id, PHY_INT_SRC,
22393 + PHY_INT_SRC_CLEAR_ALL);
22394 +
22395 + ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL);
22396 + if (ret < 0) {
22397 + netdev_warn(dev->net, "Error writing INT_STS\n");
22398 + return ret;
22399 + }
22400 +
22401 + mii_check_media(mii, 1, 1);
22402 + mii_ethtool_gset(&dev->mii, &ecmd);
22403 + lcladv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE);
22404 + rmtadv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_LPA);
22405 +
22406 + netif_dbg(dev, link, dev->net, "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n",
22407 + ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv);
22408 +
22409 + return smsc75xx_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv);
22410 +}
22411 +
22412 +static void smsc75xx_status(struct usbnet *dev, struct urb *urb)
22413 +{
22414 + u32 intdata;
22415 +
22416 + if (urb->actual_length != 4) {
22417 + netdev_warn(dev->net, "unexpected urb length %d\n",
22418 + urb->actual_length);
22419 + return;
22420 + }
22421 +
22422 + memcpy(&intdata, urb->transfer_buffer, 4);
22423 + le32_to_cpus(&intdata);
22424 +
22425 + netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
22426 +
22427 + if (intdata & INT_ENP_PHY_INT)
22428 + usbnet_defer_kevent(dev, EVENT_LINK_RESET);
22429 + else
22430 + netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n",
22431 + intdata);
22432 +}
22433 +
22434 +static int smsc75xx_ethtool_get_eeprom_len(struct net_device *net)
22435 +{
22436 + return MAX_EEPROM_SIZE;
22437 +}
22438 +
22439 +static int smsc75xx_ethtool_get_eeprom(struct net_device *netdev,
22440 + struct ethtool_eeprom *ee, u8 *data)
22441 +{
22442 + struct usbnet *dev = netdev_priv(netdev);
22443 +
22444 + ee->magic = LAN75XX_EEPROM_MAGIC;
22445 +
22446 + return smsc75xx_read_eeprom(dev, ee->offset, ee->len, data);
22447 +}
22448 +
22449 +static int smsc75xx_ethtool_set_eeprom(struct net_device *netdev,
22450 + struct ethtool_eeprom *ee, u8 *data)
22451 +{
22452 + struct usbnet *dev = netdev_priv(netdev);
22453 +
22454 + if (ee->magic != LAN75XX_EEPROM_MAGIC) {
22455 + netdev_warn(dev->net, "EEPROM: magic value mismatch: 0x%x\n",
22456 + ee->magic);
22457 + return -EINVAL;
22458 + }
22459 +
22460 + return smsc75xx_write_eeprom(dev, ee->offset, ee->len, data);
22461 +}
22462 +
22463 +static void smsc75xx_ethtool_get_wol(struct net_device *net,
22464 + struct ethtool_wolinfo *wolinfo)
22465 +{
22466 + struct usbnet *dev = netdev_priv(net);
22467 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
22468 +
22469 + wolinfo->supported = SUPPORTED_WAKE;
22470 + wolinfo->wolopts = pdata->wolopts;
22471 +}
22472 +
22473 +static int smsc75xx_ethtool_set_wol(struct net_device *net,
22474 + struct ethtool_wolinfo *wolinfo)
22475 +{
22476 + struct usbnet *dev = netdev_priv(net);
22477 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
22478 + int ret;
22479 +
22480 + pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE;
22481 +
22482 + ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts);
22483 + if (ret < 0)
22484 + netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret);
22485 +
22486 + return ret;
22487 +}
22488 +
22489 +static const struct ethtool_ops smsc75xx_ethtool_ops = {
22490 + .get_link = usbnet_get_link,
22491 + .nway_reset = usbnet_nway_reset,
22492 + .get_drvinfo = usbnet_get_drvinfo,
22493 + .get_msglevel = usbnet_get_msglevel,
22494 + .set_msglevel = usbnet_set_msglevel,
22495 + .get_settings = usbnet_get_settings,
22496 + .set_settings = usbnet_set_settings,
22497 + .get_eeprom_len = smsc75xx_ethtool_get_eeprom_len,
22498 + .get_eeprom = smsc75xx_ethtool_get_eeprom,
22499 + .set_eeprom = smsc75xx_ethtool_set_eeprom,
22500 + .get_wol = smsc75xx_ethtool_get_wol,
22501 + .set_wol = smsc75xx_ethtool_set_wol,
22502 +};
22503 +
22504 +static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
22505 +{
22506 + struct usbnet *dev = netdev_priv(netdev);
22507 +
22508 + if (!netif_running(netdev))
22509 + return -EINVAL;
22510 +
22511 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
22512 +}
22513 +
22514 +static void smsc75xx_init_mac_address(struct usbnet *dev)
22515 +{
22516 + /* try reading mac address from EEPROM */
22517 + if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
22518 + dev->net->dev_addr) == 0) {
22519 + if (is_valid_ether_addr(dev->net->dev_addr)) {
22520 + /* eeprom values are valid so use them */
22521 + netif_dbg(dev, ifup, dev->net,
22522 + "MAC address read from EEPROM\n");
22523 + return;
22524 + }
22525 + }
22526 +
22527 + /* no eeprom, or eeprom values are invalid. generate random MAC */
22528 + eth_hw_addr_random(dev->net);
22529 + netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
22530 +}
22531 +
22532 +static int smsc75xx_set_mac_address(struct usbnet *dev)
22533 +{
22534 + u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 |
22535 + dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24;
22536 + u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8;
22537 +
22538 + int ret = smsc75xx_write_reg(dev, RX_ADDRH, addr_hi);
22539 + if (ret < 0) {
22540 + netdev_warn(dev->net, "Failed to write RX_ADDRH: %d\n", ret);
22541 + return ret;
22542 + }
22543 +
22544 + ret = smsc75xx_write_reg(dev, RX_ADDRL, addr_lo);
22545 + if (ret < 0) {
22546 + netdev_warn(dev->net, "Failed to write RX_ADDRL: %d\n", ret);
22547 + return ret;
22548 + }
22549 +
22550 + addr_hi |= ADDR_FILTX_FB_VALID;
22551 + ret = smsc75xx_write_reg(dev, ADDR_FILTX, addr_hi);
22552 + if (ret < 0) {
22553 + netdev_warn(dev->net, "Failed to write ADDR_FILTX: %d\n", ret);
22554 + return ret;
22555 + }
22556 +
22557 + ret = smsc75xx_write_reg(dev, ADDR_FILTX + 4, addr_lo);
22558 + if (ret < 0)
22559 + netdev_warn(dev->net, "Failed to write ADDR_FILTX+4: %d\n", ret);
22560 +
22561 + return ret;
22562 +}
22563 +
22564 +static int smsc75xx_phy_initialize(struct usbnet *dev)
22565 +{
22566 + int bmcr, ret, timeout = 0;
22567 +
22568 + /* Initialize MII structure */
22569 + dev->mii.dev = dev->net;
22570 + dev->mii.mdio_read = smsc75xx_mdio_read;
22571 + dev->mii.mdio_write = smsc75xx_mdio_write;
22572 + dev->mii.phy_id_mask = 0x1f;
22573 + dev->mii.reg_num_mask = 0x1f;
22574 + dev->mii.supports_gmii = 1;
22575 + dev->mii.phy_id = SMSC75XX_INTERNAL_PHY_ID;
22576 +
22577 + /* reset phy and wait for reset to complete */
22578 + smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
22579 +
22580 + do {
22581 + msleep(10);
22582 + bmcr = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR);
22583 + if (bmcr < 0) {
22584 + netdev_warn(dev->net, "Error reading MII_BMCR\n");
22585 + return bmcr;
22586 + }
22587 + timeout++;
22588 + } while ((bmcr & BMCR_RESET) && (timeout < 100));
22589 +
22590 + if (timeout >= 100) {
22591 + netdev_warn(dev->net, "timeout on PHY Reset\n");
22592 + return -EIO;
22593 + }
22594 +
22595 + smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
22596 + ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
22597 + ADVERTISE_PAUSE_ASYM);
22598 + smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000,
22599 + ADVERTISE_1000FULL);
22600 +
22601 + /* read and write to clear phy interrupt status */
22602 + ret = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC);
22603 + if (ret < 0) {
22604 + netdev_warn(dev->net, "Error reading PHY_INT_SRC\n");
22605 + return ret;
22606 + }
22607 +
22608 + smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_SRC, 0xffff);
22609 +
22610 + smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK,
22611 + PHY_INT_MASK_DEFAULT);
22612 + mii_nway_restart(&dev->mii);
22613 +
22614 + netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n");
22615 + return 0;
22616 +}
22617 +
22618 +static int smsc75xx_set_rx_max_frame_length(struct usbnet *dev, int size)
22619 +{
22620 + int ret = 0;
22621 + u32 buf;
22622 + bool rxenabled;
22623 +
22624 + ret = smsc75xx_read_reg(dev, MAC_RX, &buf);
22625 + if (ret < 0) {
22626 + netdev_warn(dev->net, "Failed to read MAC_RX: %d\n", ret);
22627 + return ret;
22628 + }
22629 +
22630 + rxenabled = ((buf & MAC_RX_RXEN) != 0);
22631 +
22632 + if (rxenabled) {
22633 + buf &= ~MAC_RX_RXEN;
22634 + ret = smsc75xx_write_reg(dev, MAC_RX, buf);
22635 + if (ret < 0) {
22636 + netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
22637 + return ret;
22638 + }
22639 + }
22640 +
22641 + /* add 4 to size for FCS */
22642 + buf &= ~MAC_RX_MAX_SIZE;
22643 + buf |= (((size + 4) << MAC_RX_MAX_SIZE_SHIFT) & MAC_RX_MAX_SIZE);
22644 +
22645 + ret = smsc75xx_write_reg(dev, MAC_RX, buf);
22646 + if (ret < 0) {
22647 + netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
22648 + return ret;
22649 + }
22650 +
22651 + if (rxenabled) {
22652 + buf |= MAC_RX_RXEN;
22653 + ret = smsc75xx_write_reg(dev, MAC_RX, buf);
22654 + if (ret < 0) {
22655 + netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
22656 + return ret;
22657 + }
22658 + }
22659 +
22660 + return 0;
22661 +}
22662 +
22663 +static int smsc75xx_change_mtu(struct net_device *netdev, int new_mtu)
22664 +{
22665 + struct usbnet *dev = netdev_priv(netdev);
22666 + int ret;
22667 +
22668 + if (new_mtu > MAX_SINGLE_PACKET_SIZE)
22669 + return -EINVAL;
22670 +
22671 + ret = smsc75xx_set_rx_max_frame_length(dev, new_mtu + ETH_HLEN);
22672 + if (ret < 0) {
22673 + netdev_warn(dev->net, "Failed to set mac rx frame length\n");
22674 + return ret;
22675 + }
22676 +
22677 + return usbnet_change_mtu(netdev, new_mtu);
22678 +}
22679 +
22680 +/* Enable or disable Rx checksum offload engine */
22681 +static int smsc75xx_set_features(struct net_device *netdev,
22682 + netdev_features_t features)
22683 +{
22684 + struct usbnet *dev = netdev_priv(netdev);
22685 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
22686 + unsigned long flags;
22687 + int ret;
22688 +
22689 + spin_lock_irqsave(&pdata->rfe_ctl_lock, flags);
22690 +
22691 + if (features & NETIF_F_RXCSUM)
22692 + pdata->rfe_ctl |= RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM;
22693 + else
22694 + pdata->rfe_ctl &= ~(RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM);
22695 +
22696 + spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags);
22697 + /* it's racing here! */
22698 +
22699 + ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
22700 + if (ret < 0)
22701 + netdev_warn(dev->net, "Error writing RFE_CTL\n");
22702 +
22703 + return ret;
22704 +}
22705 +
22706 +static int smsc75xx_wait_ready(struct usbnet *dev, int in_pm)
22707 +{
22708 + int timeout = 0;
22709 +
22710 + do {
22711 + u32 buf;
22712 + int ret;
22713 +
22714 + ret = __smsc75xx_read_reg(dev, PMT_CTL, &buf, in_pm);
22715 +
22716 + if (ret < 0) {
22717 + netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n", ret);
22718 + return ret;
22719 + }
22720 +
22721 + if (buf & PMT_CTL_DEV_RDY)
22722 + return 0;
22723 +
22724 + msleep(10);
22725 + timeout++;
22726 + } while (timeout < 100);
22727 +
22728 + netdev_warn(dev->net, "timeout waiting for device ready\n");
22729 + return -EIO;
22730 +}
22731 +
22732 +static int smsc75xx_reset(struct usbnet *dev)
22733 +{
22734 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
22735 + u32 buf;
22736 + int ret = 0, timeout;
22737 +
22738 + netif_dbg(dev, ifup, dev->net, "entering smsc75xx_reset\n");
22739 +
22740 + ret = smsc75xx_wait_ready(dev, 0);
22741 + if (ret < 0) {
22742 + netdev_warn(dev->net, "device not ready in smsc75xx_reset\n");
22743 + return ret;
22744 + }
22745 +
22746 + ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
22747 + if (ret < 0) {
22748 + netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
22749 + return ret;
22750 + }
22751 +
22752 + buf |= HW_CFG_LRST;
22753 +
22754 + ret = smsc75xx_write_reg(dev, HW_CFG, buf);
22755 + if (ret < 0) {
22756 + netdev_warn(dev->net, "Failed to write HW_CFG: %d\n", ret);
22757 + return ret;
22758 + }
22759 +
22760 + timeout = 0;
22761 + do {
22762 + msleep(10);
22763 + ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
22764 + if (ret < 0) {
22765 + netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
22766 + return ret;
22767 + }
22768 + timeout++;
22769 + } while ((buf & HW_CFG_LRST) && (timeout < 100));
22770 +
22771 + if (timeout >= 100) {
22772 + netdev_warn(dev->net, "timeout on completion of Lite Reset\n");
22773 + return -EIO;
22774 + }
22775 +
22776 + netif_dbg(dev, ifup, dev->net, "Lite reset complete, resetting PHY\n");
22777 +
22778 + ret = smsc75xx_read_reg(dev, PMT_CTL, &buf);
22779 + if (ret < 0) {
22780 + netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n", ret);
22781 + return ret;
22782 + }
22783 +
22784 + buf |= PMT_CTL_PHY_RST;
22785 +
22786 + ret = smsc75xx_write_reg(dev, PMT_CTL, buf);
22787 + if (ret < 0) {
22788 + netdev_warn(dev->net, "Failed to write PMT_CTL: %d\n", ret);
22789 + return ret;
22790 + }
22791 +
22792 + timeout = 0;
22793 + do {
22794 + msleep(10);
22795 + ret = smsc75xx_read_reg(dev, PMT_CTL, &buf);
22796 + if (ret < 0) {
22797 + netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n", ret);
22798 + return ret;
22799 + }
22800 + timeout++;
22801 + } while ((buf & PMT_CTL_PHY_RST) && (timeout < 100));
22802 +
22803 + if (timeout >= 100) {
22804 + netdev_warn(dev->net, "timeout waiting for PHY Reset\n");
22805 + return -EIO;
22806 + }
22807 +
22808 + netif_dbg(dev, ifup, dev->net, "PHY reset complete\n");
22809 +
22810 + ret = smsc75xx_set_mac_address(dev);
22811 + if (ret < 0) {
22812 + netdev_warn(dev->net, "Failed to set mac address\n");
22813 + return ret;
22814 + }
22815 +
22816 + netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n",
22817 + dev->net->dev_addr);
22818 +
22819 + ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
22820 + if (ret < 0) {
22821 + netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
22822 + return ret;
22823 + }
22824 +
22825 + netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n",
22826 + buf);
22827 +
22828 + buf |= HW_CFG_BIR;
22829 +
22830 + ret = smsc75xx_write_reg(dev, HW_CFG, buf);
22831 + if (ret < 0) {
22832 + netdev_warn(dev->net, "Failed to write HW_CFG: %d\n", ret);
22833 + return ret;
22834 + }
22835 +
22836 + ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
22837 + if (ret < 0) {
22838 + netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
22839 + return ret;
22840 + }
22841 +
22842 + netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG after writing HW_CFG_BIR: 0x%08x\n",
22843 + buf);
22844 +
22845 + if (!turbo_mode) {
22846 + buf = 0;
22847 + dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
22848 + } else if (dev->udev->speed == USB_SPEED_HIGH) {
22849 + buf = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
22850 + dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
22851 + } else {
22852 + buf = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
22853 + dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
22854 + }
22855 +
22856 + netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n",
22857 + (ulong)dev->rx_urb_size);
22858 +
22859 + ret = smsc75xx_write_reg(dev, BURST_CAP, buf);
22860 + if (ret < 0) {
22861 + netdev_warn(dev->net, "Failed to write BURST_CAP: %d\n", ret);
22862 + return ret;
22863 + }
22864 +
22865 + ret = smsc75xx_read_reg(dev, BURST_CAP, &buf);
22866 + if (ret < 0) {
22867 + netdev_warn(dev->net, "Failed to read BURST_CAP: %d\n", ret);
22868 + return ret;
22869 + }
22870 +
22871 + netif_dbg(dev, ifup, dev->net,
22872 + "Read Value from BURST_CAP after writing: 0x%08x\n", buf);
22873 +
22874 + ret = smsc75xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY);
22875 + if (ret < 0) {
22876 + netdev_warn(dev->net, "Failed to write BULK_IN_DLY: %d\n", ret);
22877 + return ret;
22878 + }
22879 +
22880 + ret = smsc75xx_read_reg(dev, BULK_IN_DLY, &buf);
22881 + if (ret < 0) {
22882 + netdev_warn(dev->net, "Failed to read BULK_IN_DLY: %d\n", ret);
22883 + return ret;
22884 + }
22885 +
22886 + netif_dbg(dev, ifup, dev->net,
22887 + "Read Value from BULK_IN_DLY after writing: 0x%08x\n", buf);
22888 +
22889 + if (turbo_mode) {
22890 + ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
22891 + if (ret < 0) {
22892 + netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
22893 + return ret;
22894 + }
22895 +
22896 + netif_dbg(dev, ifup, dev->net, "HW_CFG: 0x%08x\n", buf);
22897 +
22898 + buf |= (HW_CFG_MEF | HW_CFG_BCE);
22899 +
22900 + ret = smsc75xx_write_reg(dev, HW_CFG, buf);
22901 + if (ret < 0) {
22902 + netdev_warn(dev->net, "Failed to write HW_CFG: %d\n", ret);
22903 + return ret;
22904 + }
22905 +
22906 + ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
22907 + if (ret < 0) {
22908 + netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
22909 + return ret;
22910 + }
22911 +
22912 + netif_dbg(dev, ifup, dev->net, "HW_CFG: 0x%08x\n", buf);
22913 + }
22914 +
22915 + /* set FIFO sizes */
22916 + buf = (MAX_RX_FIFO_SIZE - 512) / 512;
22917 + ret = smsc75xx_write_reg(dev, FCT_RX_FIFO_END, buf);
22918 + if (ret < 0) {
22919 + netdev_warn(dev->net, "Failed to write FCT_RX_FIFO_END: %d\n", ret);
22920 + return ret;
22921 + }
22922 +
22923 + netif_dbg(dev, ifup, dev->net, "FCT_RX_FIFO_END set to 0x%08x\n", buf);
22924 +
22925 + buf = (MAX_TX_FIFO_SIZE - 512) / 512;
22926 + ret = smsc75xx_write_reg(dev, FCT_TX_FIFO_END, buf);
22927 + if (ret < 0) {
22928 + netdev_warn(dev->net, "Failed to write FCT_TX_FIFO_END: %d\n", ret);
22929 + return ret;
22930 + }
22931 +
22932 + netif_dbg(dev, ifup, dev->net, "FCT_TX_FIFO_END set to 0x%08x\n", buf);
22933 +
22934 + ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL);
22935 + if (ret < 0) {
22936 + netdev_warn(dev->net, "Failed to write INT_STS: %d\n", ret);
22937 + return ret;
22938 + }
22939 +
22940 + ret = smsc75xx_read_reg(dev, ID_REV, &buf);
22941 + if (ret < 0) {
22942 + netdev_warn(dev->net, "Failed to read ID_REV: %d\n", ret);
22943 + return ret;
22944 + }
22945 +
22946 + netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", buf);
22947 +
22948 + ret = smsc75xx_read_reg(dev, E2P_CMD, &buf);
22949 + if (ret < 0) {
22950 + netdev_warn(dev->net, "Failed to read E2P_CMD: %d\n", ret);
22951 + return ret;
22952 + }
22953 +
22954 + /* only set default GPIO/LED settings if no EEPROM is detected */
22955 + if (!(buf & E2P_CMD_LOADED)) {
22956 + ret = smsc75xx_read_reg(dev, LED_GPIO_CFG, &buf);
22957 + if (ret < 0) {
22958 + netdev_warn(dev->net, "Failed to read LED_GPIO_CFG: %d\n", ret);
22959 + return ret;
22960 + }
22961 +
22962 + buf &= ~(LED_GPIO_CFG_LED2_FUN_SEL | LED_GPIO_CFG_LED10_FUN_SEL);
22963 + buf |= LED_GPIO_CFG_LEDGPIO_EN | LED_GPIO_CFG_LED2_FUN_SEL;
22964 +
22965 + ret = smsc75xx_write_reg(dev, LED_GPIO_CFG, buf);
22966 + if (ret < 0) {
22967 + netdev_warn(dev->net, "Failed to write LED_GPIO_CFG: %d\n", ret);
22968 + return ret;
22969 + }
22970 + }
22971 +
22972 + ret = smsc75xx_write_reg(dev, FLOW, 0);
22973 + if (ret < 0) {
22974 + netdev_warn(dev->net, "Failed to write FLOW: %d\n", ret);
22975 + return ret;
22976 + }
22977 +
22978 + ret = smsc75xx_write_reg(dev, FCT_FLOW, 0);
22979 + if (ret < 0) {
22980 + netdev_warn(dev->net, "Failed to write FCT_FLOW: %d\n", ret);
22981 + return ret;
22982 + }
22983 +
22984 + /* Don't need rfe_ctl_lock during initialisation */
22985 + ret = smsc75xx_read_reg(dev, RFE_CTL, &pdata->rfe_ctl);
22986 + if (ret < 0) {
22987 + netdev_warn(dev->net, "Failed to read RFE_CTL: %d\n", ret);
22988 + return ret;
22989 + }
22990 +
22991 + pdata->rfe_ctl |= RFE_CTL_AB | RFE_CTL_DPF;
22992 +
22993 + ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
22994 + if (ret < 0) {
22995 + netdev_warn(dev->net, "Failed to write RFE_CTL: %d\n", ret);
22996 + return ret;
22997 + }
22998 +
22999 + ret = smsc75xx_read_reg(dev, RFE_CTL, &pdata->rfe_ctl);
23000 + if (ret < 0) {
23001 + netdev_warn(dev->net, "Failed to read RFE_CTL: %d\n", ret);
23002 + return ret;
23003 + }
23004 +
23005 + netif_dbg(dev, ifup, dev->net, "RFE_CTL set to 0x%08x\n",
23006 + pdata->rfe_ctl);
23007 +
23008 + /* Enable or disable checksum offload engines */
23009 + smsc75xx_set_features(dev->net, dev->net->features);
23010 +
23011 + smsc75xx_set_multicast(dev->net);
23012 +
23013 + ret = smsc75xx_phy_initialize(dev);
23014 + if (ret < 0) {
23015 + netdev_warn(dev->net, "Failed to initialize PHY: %d\n", ret);
23016 + return ret;
23017 + }
23018 +
23019 + ret = smsc75xx_read_reg(dev, INT_EP_CTL, &buf);
23020 + if (ret < 0) {
23021 + netdev_warn(dev->net, "Failed to read INT_EP_CTL: %d\n", ret);
23022 + return ret;
23023 + }
23024 +
23025 + /* enable PHY interrupts */
23026 + buf |= INT_ENP_PHY_INT;
23027 +
23028 + ret = smsc75xx_write_reg(dev, INT_EP_CTL, buf);
23029 + if (ret < 0) {
23030 + netdev_warn(dev->net, "Failed to write INT_EP_CTL: %d\n", ret);
23031 + return ret;
23032 + }
23033 +
23034 + /* allow mac to detect speed and duplex from phy */
23035 + ret = smsc75xx_read_reg(dev, MAC_CR, &buf);
23036 + if (ret < 0) {
23037 + netdev_warn(dev->net, "Failed to read MAC_CR: %d\n", ret);
23038 + return ret;
23039 + }
23040 +
23041 + buf |= (MAC_CR_ADD | MAC_CR_ASD);
23042 + ret = smsc75xx_write_reg(dev, MAC_CR, buf);
23043 + if (ret < 0) {
23044 + netdev_warn(dev->net, "Failed to write MAC_CR: %d\n", ret);
23045 + return ret;
23046 + }
23047 +
23048 + ret = smsc75xx_read_reg(dev, MAC_TX, &buf);
23049 + if (ret < 0) {
23050 + netdev_warn(dev->net, "Failed to read MAC_TX: %d\n", ret);
23051 + return ret;
23052 + }
23053 +
23054 + buf |= MAC_TX_TXEN;
23055 +
23056 + ret = smsc75xx_write_reg(dev, MAC_TX, buf);
23057 + if (ret < 0) {
23058 + netdev_warn(dev->net, "Failed to write MAC_TX: %d\n", ret);
23059 + return ret;
23060 + }
23061 +
23062 + netif_dbg(dev, ifup, dev->net, "MAC_TX set to 0x%08x\n", buf);
23063 +
23064 + ret = smsc75xx_read_reg(dev, FCT_TX_CTL, &buf);
23065 + if (ret < 0) {
23066 + netdev_warn(dev->net, "Failed to read FCT_TX_CTL: %d\n", ret);
23067 + return ret;
23068 + }
23069 +
23070 + buf |= FCT_TX_CTL_EN;
23071 +
23072 + ret = smsc75xx_write_reg(dev, FCT_TX_CTL, buf);
23073 + if (ret < 0) {
23074 + netdev_warn(dev->net, "Failed to write FCT_TX_CTL: %d\n", ret);
23075 + return ret;
23076 + }
23077 +
23078 + netif_dbg(dev, ifup, dev->net, "FCT_TX_CTL set to 0x%08x\n", buf);
23079 +
23080 + ret = smsc75xx_set_rx_max_frame_length(dev, dev->net->mtu + ETH_HLEN);
23081 + if (ret < 0) {
23082 + netdev_warn(dev->net, "Failed to set max rx frame length\n");
23083 + return ret;
23084 + }
23085 +
23086 + ret = smsc75xx_read_reg(dev, MAC_RX, &buf);
23087 + if (ret < 0) {
23088 + netdev_warn(dev->net, "Failed to read MAC_RX: %d\n", ret);
23089 + return ret;
23090 + }
23091 +
23092 + buf |= MAC_RX_RXEN;
23093 +
23094 + ret = smsc75xx_write_reg(dev, MAC_RX, buf);
23095 + if (ret < 0) {
23096 + netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
23097 + return ret;
23098 + }
23099 +
23100 + netif_dbg(dev, ifup, dev->net, "MAC_RX set to 0x%08x\n", buf);
23101 +
23102 + ret = smsc75xx_read_reg(dev, FCT_RX_CTL, &buf);
23103 + if (ret < 0) {
23104 + netdev_warn(dev->net, "Failed to read FCT_RX_CTL: %d\n", ret);
23105 + return ret;
23106 + }
23107 +
23108 + buf |= FCT_RX_CTL_EN;
23109 +
23110 + ret = smsc75xx_write_reg(dev, FCT_RX_CTL, buf);
23111 + if (ret < 0) {
23112 + netdev_warn(dev->net, "Failed to write FCT_RX_CTL: %d\n", ret);
23113 + return ret;
23114 + }
23115 +
23116 + netif_dbg(dev, ifup, dev->net, "FCT_RX_CTL set to 0x%08x\n", buf);
23117 +
23118 + netif_dbg(dev, ifup, dev->net, "smsc75xx_reset, return 0\n");
23119 + return 0;
23120 +}
23121 +
23122 +static const struct net_device_ops smsc75xx_netdev_ops = {
23123 + .ndo_open = usbnet_open,
23124 + .ndo_stop = usbnet_stop,
23125 + .ndo_start_xmit = usbnet_start_xmit,
23126 + .ndo_tx_timeout = usbnet_tx_timeout,
23127 + .ndo_change_mtu = smsc75xx_change_mtu,
23128 + .ndo_set_mac_address = eth_mac_addr,
23129 + .ndo_validate_addr = eth_validate_addr,
23130 + .ndo_do_ioctl = smsc75xx_ioctl,
23131 + .ndo_set_rx_mode = smsc75xx_set_multicast,
23132 + .ndo_set_features = smsc75xx_set_features,
23133 +};
23134 +
23135 +static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf)
23136 +{
23137 + struct smsc75xx_priv *pdata = NULL;
23138 + int ret;
23139 +
23140 + printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
23141 +
23142 + ret = usbnet_get_endpoints(dev, intf);
23143 + if (ret < 0) {
23144 + netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret);
23145 + return ret;
23146 + }
23147 +
23148 + dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc75xx_priv),
23149 + GFP_KERNEL);
23150 +
23151 + pdata = (struct smsc75xx_priv *)(dev->data[0]);
23152 + if (!pdata)
23153 + return -ENOMEM;
23154 +
23155 + pdata->dev = dev;
23156 +
23157 + spin_lock_init(&pdata->rfe_ctl_lock);
23158 + mutex_init(&pdata->dataport_mutex);
23159 +
23160 + INIT_WORK(&pdata->set_multicast, smsc75xx_deferred_multicast_write);
23161 +
23162 + if (DEFAULT_TX_CSUM_ENABLE)
23163 + dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
23164 +
23165 + if (DEFAULT_RX_CSUM_ENABLE)
23166 + dev->net->features |= NETIF_F_RXCSUM;
23167 +
23168 + dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
23169 + NETIF_F_RXCSUM;
23170 +
23171 + ret = smsc75xx_wait_ready(dev, 0);
23172 + if (ret < 0) {
23173 + netdev_warn(dev->net, "device not ready in smsc75xx_bind\n");
23174 + return ret;
23175 + }
23176 +
23177 + smsc75xx_init_mac_address(dev);
23178 +
23179 + /* Init all registers */
23180 + ret = smsc75xx_reset(dev);
23181 + if (ret < 0) {
23182 + netdev_warn(dev->net, "smsc75xx_reset error %d\n", ret);
23183 + return ret;
23184 + }
23185 +
23186 + dev->net->netdev_ops = &smsc75xx_netdev_ops;
23187 + dev->net->ethtool_ops = &smsc75xx_ethtool_ops;
23188 + dev->net->flags |= IFF_MULTICAST;
23189 + dev->net->hard_header_len += SMSC75XX_TX_OVERHEAD;
23190 + dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
23191 + return 0;
23192 +}
23193 +
23194 +static void smsc75xx_unbind(struct usbnet *dev, struct usb_interface *intf)
23195 +{
23196 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23197 + if (pdata) {
23198 + netif_dbg(dev, ifdown, dev->net, "free pdata\n");
23199 + kfree(pdata);
23200 + pdata = NULL;
23201 + dev->data[0] = 0;
23202 + }
23203 +}
23204 +
23205 +static u16 smsc_crc(const u8 *buffer, size_t len)
23206 +{
23207 + return bitrev16(crc16(0xFFFF, buffer, len));
23208 +}
23209 +
23210 +static int smsc75xx_write_wuff(struct usbnet *dev, int filter, u32 wuf_cfg,
23211 + u32 wuf_mask1)
23212 +{
23213 + int cfg_base = WUF_CFGX + filter * 4;
23214 + int mask_base = WUF_MASKX + filter * 16;
23215 + int ret;
23216 +
23217 + ret = smsc75xx_write_reg(dev, cfg_base, wuf_cfg);
23218 + if (ret < 0) {
23219 + netdev_warn(dev->net, "Error writing WUF_CFGX\n");
23220 + return ret;
23221 + }
23222 +
23223 + ret = smsc75xx_write_reg(dev, mask_base, wuf_mask1);
23224 + if (ret < 0) {
23225 + netdev_warn(dev->net, "Error writing WUF_MASKX\n");
23226 + return ret;
23227 + }
23228 +
23229 + ret = smsc75xx_write_reg(dev, mask_base + 4, 0);
23230 + if (ret < 0) {
23231 + netdev_warn(dev->net, "Error writing WUF_MASKX\n");
23232 + return ret;
23233 + }
23234 +
23235 + ret = smsc75xx_write_reg(dev, mask_base + 8, 0);
23236 + if (ret < 0) {
23237 + netdev_warn(dev->net, "Error writing WUF_MASKX\n");
23238 + return ret;
23239 + }
23240 +
23241 + ret = smsc75xx_write_reg(dev, mask_base + 12, 0);
23242 + if (ret < 0) {
23243 + netdev_warn(dev->net, "Error writing WUF_MASKX\n");
23244 + return ret;
23245 + }
23246 +
23247 + return 0;
23248 +}
23249 +
23250 +static int smsc75xx_enter_suspend0(struct usbnet *dev)
23251 +{
23252 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23253 + u32 val;
23254 + int ret;
23255 +
23256 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23257 + if (ret < 0) {
23258 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23259 + return ret;
23260 + }
23261 +
23262 + val &= (~(PMT_CTL_SUS_MODE | PMT_CTL_PHY_RST));
23263 + val |= PMT_CTL_SUS_MODE_0 | PMT_CTL_WOL_EN | PMT_CTL_WUPS;
23264 +
23265 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23266 + if (ret < 0) {
23267 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23268 + return ret;
23269 + }
23270 +
23271 + pdata->suspend_flags |= SUSPEND_SUSPEND0;
23272 +
23273 + return 0;
23274 +}
23275 +
23276 +static int smsc75xx_enter_suspend1(struct usbnet *dev)
23277 +{
23278 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23279 + u32 val;
23280 + int ret;
23281 +
23282 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23283 + if (ret < 0) {
23284 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23285 + return ret;
23286 + }
23287 +
23288 + val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST);
23289 + val |= PMT_CTL_SUS_MODE_1;
23290 +
23291 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23292 + if (ret < 0) {
23293 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23294 + return ret;
23295 + }
23296 +
23297 + /* clear wol status, enable energy detection */
23298 + val &= ~PMT_CTL_WUPS;
23299 + val |= (PMT_CTL_WUPS_ED | PMT_CTL_ED_EN);
23300 +
23301 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23302 + if (ret < 0) {
23303 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23304 + return ret;
23305 + }
23306 +
23307 + pdata->suspend_flags |= SUSPEND_SUSPEND1;
23308 +
23309 + return 0;
23310 +}
23311 +
23312 +static int smsc75xx_enter_suspend2(struct usbnet *dev)
23313 +{
23314 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23315 + u32 val;
23316 + int ret;
23317 +
23318 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23319 + if (ret < 0) {
23320 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23321 + return ret;
23322 + }
23323 +
23324 + val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST);
23325 + val |= PMT_CTL_SUS_MODE_2;
23326 +
23327 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23328 + if (ret < 0) {
23329 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23330 + return ret;
23331 + }
23332 +
23333 + pdata->suspend_flags |= SUSPEND_SUSPEND2;
23334 +
23335 + return 0;
23336 +}
23337 +
23338 +static int smsc75xx_enter_suspend3(struct usbnet *dev)
23339 +{
23340 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23341 + u32 val;
23342 + int ret;
23343 +
23344 + ret = smsc75xx_read_reg_nopm(dev, FCT_RX_CTL, &val);
23345 + if (ret < 0) {
23346 + netdev_warn(dev->net, "Error reading FCT_RX_CTL\n");
23347 + return ret;
23348 + }
23349 +
23350 + if (val & FCT_RX_CTL_RXUSED) {
23351 + netdev_dbg(dev->net, "rx fifo not empty in autosuspend\n");
23352 + return -EBUSY;
23353 + }
23354 +
23355 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23356 + if (ret < 0) {
23357 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23358 + return ret;
23359 + }
23360 +
23361 + val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST);
23362 + val |= PMT_CTL_SUS_MODE_3 | PMT_CTL_RES_CLR_WKP_EN;
23363 +
23364 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23365 + if (ret < 0) {
23366 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23367 + return ret;
23368 + }
23369 +
23370 + /* clear wol status */
23371 + val &= ~PMT_CTL_WUPS;
23372 + val |= PMT_CTL_WUPS_WOL;
23373 +
23374 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23375 + if (ret < 0) {
23376 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23377 + return ret;
23378 + }
23379 +
23380 + pdata->suspend_flags |= SUSPEND_SUSPEND3;
23381 +
23382 + return 0;
23383 +}
23384 +
23385 +static int smsc75xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask)
23386 +{
23387 + struct mii_if_info *mii = &dev->mii;
23388 + int ret;
23389 +
23390 + netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n");
23391 +
23392 + /* read to clear */
23393 + ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC);
23394 + if (ret < 0) {
23395 + netdev_warn(dev->net, "Error reading PHY_INT_SRC\n");
23396 + return ret;
23397 + }
23398 +
23399 + /* enable interrupt source */
23400 + ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK);
23401 + if (ret < 0) {
23402 + netdev_warn(dev->net, "Error reading PHY_INT_MASK\n");
23403 + return ret;
23404 + }
23405 +
23406 + ret |= mask;
23407 +
23408 + smsc75xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret);
23409 +
23410 + return 0;
23411 +}
23412 +
23413 +static int smsc75xx_link_ok_nopm(struct usbnet *dev)
23414 +{
23415 + struct mii_if_info *mii = &dev->mii;
23416 + int ret;
23417 +
23418 + /* first, a dummy read, needed to latch some MII phys */
23419 + ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
23420 + if (ret < 0) {
23421 + netdev_warn(dev->net, "Error reading MII_BMSR\n");
23422 + return ret;
23423 + }
23424 +
23425 + ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
23426 + if (ret < 0) {
23427 + netdev_warn(dev->net, "Error reading MII_BMSR\n");
23428 + return ret;
23429 + }
23430 +
23431 + return !!(ret & BMSR_LSTATUS);
23432 +}
23433 +
23434 +static int smsc75xx_autosuspend(struct usbnet *dev, u32 link_up)
23435 +{
23436 + int ret;
23437 +
23438 + if (!netif_running(dev->net)) {
23439 + /* interface is ifconfig down so fully power down hw */
23440 + netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n");
23441 + return smsc75xx_enter_suspend2(dev);
23442 + }
23443 +
23444 + if (!link_up) {
23445 + /* link is down so enter EDPD mode */
23446 + netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n");
23447 +
23448 + /* enable PHY wakeup events for if cable is attached */
23449 + ret = smsc75xx_enable_phy_wakeup_interrupts(dev,
23450 + PHY_INT_MASK_ANEG_COMP);
23451 + if (ret < 0) {
23452 + netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
23453 + return ret;
23454 + }
23455 +
23456 + netdev_info(dev->net, "entering SUSPEND1 mode\n");
23457 + return smsc75xx_enter_suspend1(dev);
23458 + }
23459 +
23460 + /* enable PHY wakeup events so we remote wakeup if cable is pulled */
23461 + ret = smsc75xx_enable_phy_wakeup_interrupts(dev,
23462 + PHY_INT_MASK_LINK_DOWN);
23463 + if (ret < 0) {
23464 + netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
23465 + return ret;
23466 + }
23467 +
23468 + netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n");
23469 + return smsc75xx_enter_suspend3(dev);
23470 +}
23471 +
23472 +static int smsc75xx_suspend(struct usb_interface *intf, pm_message_t message)
23473 +{
23474 + struct usbnet *dev = usb_get_intfdata(intf);
23475 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23476 + u32 val, link_up;
23477 + int ret;
23478 +
23479 + ret = usbnet_suspend(intf, message);
23480 + if (ret < 0) {
23481 + netdev_warn(dev->net, "usbnet_suspend error\n");
23482 + return ret;
23483 + }
23484 +
23485 + if (pdata->suspend_flags) {
23486 + netdev_warn(dev->net, "error during last resume\n");
23487 + pdata->suspend_flags = 0;
23488 + }
23489 +
23490 + /* determine if link is up using only _nopm functions */
23491 + link_up = smsc75xx_link_ok_nopm(dev);
23492 +
23493 + if (message.event == PM_EVENT_AUTO_SUSPEND) {
23494 + ret = smsc75xx_autosuspend(dev, link_up);
23495 + goto done;
23496 + }
23497 +
23498 + /* if we get this far we're not autosuspending */
23499 + /* if no wol options set, or if link is down and we're not waking on
23500 + * PHY activity, enter lowest power SUSPEND2 mode
23501 + */
23502 + if (!(pdata->wolopts & SUPPORTED_WAKE) ||
23503 + !(link_up || (pdata->wolopts & WAKE_PHY))) {
23504 + netdev_info(dev->net, "entering SUSPEND2 mode\n");
23505 +
23506 + /* disable energy detect (link up) & wake up events */
23507 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23508 + if (ret < 0) {
23509 + netdev_warn(dev->net, "Error reading WUCSR\n");
23510 + goto done;
23511 + }
23512 +
23513 + val &= ~(WUCSR_MPEN | WUCSR_WUEN);
23514 +
23515 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23516 + if (ret < 0) {
23517 + netdev_warn(dev->net, "Error writing WUCSR\n");
23518 + goto done;
23519 + }
23520 +
23521 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23522 + if (ret < 0) {
23523 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23524 + goto done;
23525 + }
23526 +
23527 + val &= ~(PMT_CTL_ED_EN | PMT_CTL_WOL_EN);
23528 +
23529 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23530 + if (ret < 0) {
23531 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23532 + goto done;
23533 + }
23534 +
23535 + ret = smsc75xx_enter_suspend2(dev);
23536 + goto done;
23537 + }
23538 +
23539 + if (pdata->wolopts & WAKE_PHY) {
23540 + ret = smsc75xx_enable_phy_wakeup_interrupts(dev,
23541 + (PHY_INT_MASK_ANEG_COMP | PHY_INT_MASK_LINK_DOWN));
23542 + if (ret < 0) {
23543 + netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
23544 + goto done;
23545 + }
23546 +
23547 + /* if link is down then configure EDPD and enter SUSPEND1,
23548 + * otherwise enter SUSPEND0 below
23549 + */
23550 + if (!link_up) {
23551 + struct mii_if_info *mii = &dev->mii;
23552 + netdev_info(dev->net, "entering SUSPEND1 mode\n");
23553 +
23554 + /* enable energy detect power-down mode */
23555 + ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id,
23556 + PHY_MODE_CTRL_STS);
23557 + if (ret < 0) {
23558 + netdev_warn(dev->net, "Error reading PHY_MODE_CTRL_STS\n");
23559 + goto done;
23560 + }
23561 +
23562 + ret |= MODE_CTRL_STS_EDPWRDOWN;
23563 +
23564 + smsc75xx_mdio_write_nopm(dev->net, mii->phy_id,
23565 + PHY_MODE_CTRL_STS, ret);
23566 +
23567 + /* enter SUSPEND1 mode */
23568 + ret = smsc75xx_enter_suspend1(dev);
23569 + goto done;
23570 + }
23571 + }
23572 +
23573 + if (pdata->wolopts & (WAKE_MCAST | WAKE_ARP)) {
23574 + int i, filter = 0;
23575 +
23576 + /* disable all filters */
23577 + for (i = 0; i < WUF_NUM; i++) {
23578 + ret = smsc75xx_write_reg_nopm(dev, WUF_CFGX + i * 4, 0);
23579 + if (ret < 0) {
23580 + netdev_warn(dev->net, "Error writing WUF_CFGX\n");
23581 + goto done;
23582 + }
23583 + }
23584 +
23585 + if (pdata->wolopts & WAKE_MCAST) {
23586 + const u8 mcast[] = {0x01, 0x00, 0x5E};
23587 + netdev_info(dev->net, "enabling multicast detection\n");
23588 +
23589 + val = WUF_CFGX_EN | WUF_CFGX_ATYPE_MULTICAST
23590 + | smsc_crc(mcast, 3);
23591 + ret = smsc75xx_write_wuff(dev, filter++, val, 0x0007);
23592 + if (ret < 0) {
23593 + netdev_warn(dev->net, "Error writing wakeup filter\n");
23594 + goto done;
23595 + }
23596 + }
23597 +
23598 + if (pdata->wolopts & WAKE_ARP) {
23599 + const u8 arp[] = {0x08, 0x06};
23600 + netdev_info(dev->net, "enabling ARP detection\n");
23601 +
23602 + val = WUF_CFGX_EN | WUF_CFGX_ATYPE_ALL | (0x0C << 16)
23603 + | smsc_crc(arp, 2);
23604 + ret = smsc75xx_write_wuff(dev, filter++, val, 0x0003);
23605 + if (ret < 0) {
23606 + netdev_warn(dev->net, "Error writing wakeup filter\n");
23607 + goto done;
23608 + }
23609 + }
23610 +
23611 + /* clear any pending pattern match packet status */
23612 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23613 + if (ret < 0) {
23614 + netdev_warn(dev->net, "Error reading WUCSR\n");
23615 + goto done;
23616 + }
23617 +
23618 + val |= WUCSR_WUFR;
23619 +
23620 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23621 + if (ret < 0) {
23622 + netdev_warn(dev->net, "Error writing WUCSR\n");
23623 + goto done;
23624 + }
23625 +
23626 + netdev_info(dev->net, "enabling packet match detection\n");
23627 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23628 + if (ret < 0) {
23629 + netdev_warn(dev->net, "Error reading WUCSR\n");
23630 + goto done;
23631 + }
23632 +
23633 + val |= WUCSR_WUEN;
23634 +
23635 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23636 + if (ret < 0) {
23637 + netdev_warn(dev->net, "Error writing WUCSR\n");
23638 + goto done;
23639 + }
23640 + } else {
23641 + netdev_info(dev->net, "disabling packet match detection\n");
23642 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23643 + if (ret < 0) {
23644 + netdev_warn(dev->net, "Error reading WUCSR\n");
23645 + goto done;
23646 + }
23647 +
23648 + val &= ~WUCSR_WUEN;
23649 +
23650 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23651 + if (ret < 0) {
23652 + netdev_warn(dev->net, "Error writing WUCSR\n");
23653 + goto done;
23654 + }
23655 + }
23656 +
23657 + /* disable magic, bcast & unicast wakeup sources */
23658 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23659 + if (ret < 0) {
23660 + netdev_warn(dev->net, "Error reading WUCSR\n");
23661 + goto done;
23662 + }
23663 +
23664 + val &= ~(WUCSR_MPEN | WUCSR_BCST_EN | WUCSR_PFDA_EN);
23665 +
23666 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23667 + if (ret < 0) {
23668 + netdev_warn(dev->net, "Error writing WUCSR\n");
23669 + goto done;
23670 + }
23671 +
23672 + if (pdata->wolopts & WAKE_PHY) {
23673 + netdev_info(dev->net, "enabling PHY wakeup\n");
23674 +
23675 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23676 + if (ret < 0) {
23677 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23678 + goto done;
23679 + }
23680 +
23681 + /* clear wol status, enable energy detection */
23682 + val &= ~PMT_CTL_WUPS;
23683 + val |= (PMT_CTL_WUPS_ED | PMT_CTL_ED_EN);
23684 +
23685 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23686 + if (ret < 0) {
23687 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23688 + goto done;
23689 + }
23690 + }
23691 +
23692 + if (pdata->wolopts & WAKE_MAGIC) {
23693 + netdev_info(dev->net, "enabling magic packet wakeup\n");
23694 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23695 + if (ret < 0) {
23696 + netdev_warn(dev->net, "Error reading WUCSR\n");
23697 + goto done;
23698 + }
23699 +
23700 + /* clear any pending magic packet status */
23701 + val |= WUCSR_MPR | WUCSR_MPEN;
23702 +
23703 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23704 + if (ret < 0) {
23705 + netdev_warn(dev->net, "Error writing WUCSR\n");
23706 + goto done;
23707 + }
23708 + }
23709 +
23710 + if (pdata->wolopts & WAKE_BCAST) {
23711 + netdev_info(dev->net, "enabling broadcast detection\n");
23712 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23713 + if (ret < 0) {
23714 + netdev_warn(dev->net, "Error reading WUCSR\n");
23715 + goto done;
23716 + }
23717 +
23718 + val |= WUCSR_BCAST_FR | WUCSR_BCST_EN;
23719 +
23720 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23721 + if (ret < 0) {
23722 + netdev_warn(dev->net, "Error writing WUCSR\n");
23723 + goto done;
23724 + }
23725 + }
23726 +
23727 + if (pdata->wolopts & WAKE_UCAST) {
23728 + netdev_info(dev->net, "enabling unicast detection\n");
23729 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23730 + if (ret < 0) {
23731 + netdev_warn(dev->net, "Error reading WUCSR\n");
23732 + goto done;
23733 + }
23734 +
23735 + val |= WUCSR_WUFR | WUCSR_PFDA_EN;
23736 +
23737 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23738 + if (ret < 0) {
23739 + netdev_warn(dev->net, "Error writing WUCSR\n");
23740 + goto done;
23741 + }
23742 + }
23743 +
23744 + /* enable receiver to enable frame reception */
23745 + ret = smsc75xx_read_reg_nopm(dev, MAC_RX, &val);
23746 + if (ret < 0) {
23747 + netdev_warn(dev->net, "Failed to read MAC_RX: %d\n", ret);
23748 + goto done;
23749 + }
23750 +
23751 + val |= MAC_RX_RXEN;
23752 +
23753 + ret = smsc75xx_write_reg_nopm(dev, MAC_RX, val);
23754 + if (ret < 0) {
23755 + netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
23756 + goto done;
23757 + }
23758 +
23759 + /* some wol options are enabled, so enter SUSPEND0 */
23760 + netdev_info(dev->net, "entering SUSPEND0 mode\n");
23761 + ret = smsc75xx_enter_suspend0(dev);
23762 +
23763 +done:
23764 + /*
23765 + * TODO: resume() might need to handle the suspend failure
23766 + * in system sleep
23767 + */
23768 + if (ret && PMSG_IS_AUTO(message))
23769 + usbnet_resume(intf);
23770 + return ret;
23771 +}
23772 +
23773 +static int smsc75xx_resume(struct usb_interface *intf)
23774 +{
23775 + struct usbnet *dev = usb_get_intfdata(intf);
23776 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23777 + u8 suspend_flags = pdata->suspend_flags;
23778 + int ret;
23779 + u32 val;
23780 +
23781 + netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags);
23782 +
23783 + /* do this first to ensure it's cleared even in error case */
23784 + pdata->suspend_flags = 0;
23785 +
23786 + if (suspend_flags & SUSPEND_ALLMODES) {
23787 + /* Disable wakeup sources */
23788 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23789 + if (ret < 0) {
23790 + netdev_warn(dev->net, "Error reading WUCSR\n");
23791 + return ret;
23792 + }
23793 +
23794 + val &= ~(WUCSR_WUEN | WUCSR_MPEN | WUCSR_PFDA_EN
23795 + | WUCSR_BCST_EN);
23796 +
23797 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23798 + if (ret < 0) {
23799 + netdev_warn(dev->net, "Error writing WUCSR\n");
23800 + return ret;
23801 + }
23802 +
23803 + /* clear wake-up status */
23804 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23805 + if (ret < 0) {
23806 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23807 + return ret;
23808 + }
23809 +
23810 + val &= ~PMT_CTL_WOL_EN;
23811 + val |= PMT_CTL_WUPS;
23812 +
23813 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23814 + if (ret < 0) {
23815 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23816 + return ret;
23817 + }
23818 + }
23819 +
23820 + if (suspend_flags & SUSPEND_SUSPEND2) {
23821 + netdev_info(dev->net, "resuming from SUSPEND2\n");
23822 +
23823 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23824 + if (ret < 0) {
23825 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23826 + return ret;
23827 + }
23828 +
23829 + val |= PMT_CTL_PHY_PWRUP;
23830 +
23831 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23832 + if (ret < 0) {
23833 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23834 + return ret;
23835 + }
23836 + }
23837 +
23838 + ret = smsc75xx_wait_ready(dev, 1);
23839 + if (ret < 0) {
23840 + netdev_warn(dev->net, "device not ready in smsc75xx_resume\n");
23841 + return ret;
23842 + }
23843 +
23844 + return usbnet_resume(intf);
23845 +}
23846 +
23847 +static void smsc75xx_rx_csum_offload(struct usbnet *dev, struct sk_buff *skb,
23848 + u32 rx_cmd_a, u32 rx_cmd_b)
23849 +{
23850 + if (!(dev->net->features & NETIF_F_RXCSUM) ||
23851 + unlikely(rx_cmd_a & RX_CMD_A_LCSM)) {
23852 + skb->ip_summed = CHECKSUM_NONE;
23853 + } else {
23854 + skb->csum = ntohs((u16)(rx_cmd_b >> RX_CMD_B_CSUM_SHIFT));
23855 + skb->ip_summed = CHECKSUM_COMPLETE;
23856 + }
23857 +}
23858 +
23859 +static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
23860 +{
23861 + /* This check is no longer done by usbnet */
23862 + if (skb->len < dev->net->hard_header_len)
23863 + return 0;
23864 +
23865 + while (skb->len > 0) {
23866 + u32 rx_cmd_a, rx_cmd_b, align_count, size;
23867 + struct sk_buff *ax_skb;
23868 + unsigned char *packet;
23869 +
23870 + memcpy(&rx_cmd_a, skb->data, sizeof(rx_cmd_a));
23871 + le32_to_cpus(&rx_cmd_a);
23872 + skb_pull(skb, 4);
23873 +
23874 + memcpy(&rx_cmd_b, skb->data, sizeof(rx_cmd_b));
23875 + le32_to_cpus(&rx_cmd_b);
23876 + skb_pull(skb, 4 + RXW_PADDING);
23877 +
23878 + packet = skb->data;
23879 +
23880 + /* get the packet length */
23881 + size = (rx_cmd_a & RX_CMD_A_LEN) - RXW_PADDING;
23882 + align_count = (4 - ((size + RXW_PADDING) % 4)) % 4;
23883 +
23884 + if (unlikely(rx_cmd_a & RX_CMD_A_RED)) {
23885 + netif_dbg(dev, rx_err, dev->net,
23886 + "Error rx_cmd_a=0x%08x\n", rx_cmd_a);
23887 + dev->net->stats.rx_errors++;
23888 + dev->net->stats.rx_dropped++;
23889 +
23890 + if (rx_cmd_a & RX_CMD_A_FCS)
23891 + dev->net->stats.rx_crc_errors++;
23892 + else if (rx_cmd_a & (RX_CMD_A_LONG | RX_CMD_A_RUNT))
23893 + dev->net->stats.rx_frame_errors++;
23894 + } else {
23895 + /* MAX_SINGLE_PACKET_SIZE + 4(CRC) + 2(COE) + 4(Vlan) */
23896 + if (unlikely(size > (MAX_SINGLE_PACKET_SIZE + ETH_HLEN + 12))) {
23897 + netif_dbg(dev, rx_err, dev->net,
23898 + "size err rx_cmd_a=0x%08x\n",
23899 + rx_cmd_a);
23900 + return 0;
23901 + }
23902 +
23903 + /* last frame in this batch */
23904 + if (skb->len == size) {
23905 + smsc75xx_rx_csum_offload(dev, skb, rx_cmd_a,
23906 + rx_cmd_b);
23907 +
23908 + skb_trim(skb, skb->len - 4); /* remove fcs */
23909 + skb->truesize = size + sizeof(struct sk_buff);
23910 +
23911 + return 1;
23912 + }
23913 +
23914 + ax_skb = skb_clone(skb, GFP_ATOMIC);
23915 + if (unlikely(!ax_skb)) {
23916 + netdev_warn(dev->net, "Error allocating skb\n");
23917 + return 0;
23918 + }
23919 +
23920 + ax_skb->len = size;
23921 + ax_skb->data = packet;
23922 + skb_set_tail_pointer(ax_skb, size);
23923 +
23924 + smsc75xx_rx_csum_offload(dev, ax_skb, rx_cmd_a,
23925 + rx_cmd_b);
23926 +
23927 + skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
23928 + ax_skb->truesize = size + sizeof(struct sk_buff);
23929 +
23930 + usbnet_skb_return(dev, ax_skb);
23931 + }
23932 +
23933 + skb_pull(skb, size);
23934 +
23935 + /* padding bytes before the next frame starts */
23936 + if (skb->len)
23937 + skb_pull(skb, align_count);
23938 + }
23939 +
23940 + if (unlikely(skb->len < 0)) {
23941 + netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len);
23942 + return 0;
23943 + }
23944 +
23945 + return 1;
23946 +}
23947 +
23948 +static struct sk_buff *smsc75xx_tx_fixup(struct usbnet *dev,
23949 + struct sk_buff *skb, gfp_t flags)
23950 +{
23951 + u32 tx_cmd_a, tx_cmd_b;
23952 +
23953 + if (skb_headroom(skb) < SMSC75XX_TX_OVERHEAD) {
23954 + struct sk_buff *skb2 =
23955 + skb_copy_expand(skb, SMSC75XX_TX_OVERHEAD, 0, flags);
23956 + dev_kfree_skb_any(skb);
23957 + skb = skb2;
23958 + if (!skb)
23959 + return NULL;
23960 + }
23961 +
23962 + tx_cmd_a = (u32)(skb->len & TX_CMD_A_LEN) | TX_CMD_A_FCS;
23963 +
23964 + if (skb->ip_summed == CHECKSUM_PARTIAL)
23965 + tx_cmd_a |= TX_CMD_A_IPE | TX_CMD_A_TPE;
23966 +
23967 + if (skb_is_gso(skb)) {
23968 + u16 mss = max(skb_shinfo(skb)->gso_size, TX_MSS_MIN);
23969 + tx_cmd_b = (mss << TX_CMD_B_MSS_SHIFT) & TX_CMD_B_MSS;
23970 +
23971 + tx_cmd_a |= TX_CMD_A_LSO;
23972 + } else {
23973 + tx_cmd_b = 0;
23974 + }
23975 +
23976 + skb_push(skb, 4);
23977 + cpu_to_le32s(&tx_cmd_b);
23978 + memcpy(skb->data, &tx_cmd_b, 4);
23979 +
23980 + skb_push(skb, 4);
23981 + cpu_to_le32s(&tx_cmd_a);
23982 + memcpy(skb->data, &tx_cmd_a, 4);
23983 +
23984 + return skb;
23985 +}
23986 +
23987 +static int smsc75xx_manage_power(struct usbnet *dev, int on)
23988 +{
23989 + dev->intf->needs_remote_wakeup = on;
23990 + return 0;
23991 +}
23992 +
23993 +static const struct driver_info smsc75xx_info = {
23994 + .description = "smsc75xx USB 2.0 Gigabit Ethernet",
23995 + .bind = smsc75xx_bind,
23996 + .unbind = smsc75xx_unbind,
23997 + .link_reset = smsc75xx_link_reset,
23998 + .reset = smsc75xx_reset,
23999 + .rx_fixup = smsc75xx_rx_fixup,
24000 + .tx_fixup = smsc75xx_tx_fixup,
24001 + .status = smsc75xx_status,
24002 + .manage_power = smsc75xx_manage_power,
24003 + .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
24004 +};
24005 +
24006 +static const struct usb_device_id products[] = {
24007 + {
24008 + /* SMSC7500 USB Gigabit Ethernet Device */
24009 + USB_DEVICE(USB_VENDOR_ID_SMSC, USB_PRODUCT_ID_LAN7500),
24010 + .driver_info = (unsigned long) &smsc75xx_info,
24011 + },
24012 + {
24013 + /* SMSC7500 USB Gigabit Ethernet Device */
24014 + USB_DEVICE(USB_VENDOR_ID_SMSC, USB_PRODUCT_ID_LAN7505),
24015 + .driver_info = (unsigned long) &smsc75xx_info,
24016 + },
24017 + { }, /* END */
24018 +};
24019 +MODULE_DEVICE_TABLE(usb, products);
24020 +
24021 +static struct usb_driver smsc75xx_driver = {
24022 + .name = SMSC_CHIPNAME,
24023 + .id_table = products,
24024 + .probe = usbnet_probe,
24025 + .suspend = smsc75xx_suspend,
24026 + .resume = smsc75xx_resume,
24027 + .reset_resume = smsc75xx_resume,
24028 + .disconnect = usbnet_disconnect,
24029 + .disable_hub_initiated_lpm = 1,
24030 + .supports_autosuspend = 1,
24031 +};
24032 +
24033 +module_usb_driver(smsc75xx_driver);
24034 +
24035 +MODULE_AUTHOR("Nancy Lin");
24036 +MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
24037 +MODULE_DESCRIPTION("SMSC75XX USB 2.0 Gigabit Ethernet Devices");
24038 +MODULE_LICENSE("GPL");
24039 diff -Naur backports-4.2.6-1.org/drivers/net/usb/smsc75xx.h backports-4.2.6-1/drivers/net/usb/smsc75xx.h
24040 --- backports-4.2.6-1.org/drivers/net/usb/smsc75xx.h 1970-01-01 01:00:00.000000000 +0100
24041 +++ backports-4.2.6-1/drivers/net/usb/smsc75xx.h 2016-06-28 14:35:18.008640551 +0200
24042 @@ -0,0 +1,421 @@
24043 + /***************************************************************************
24044 + *
24045 + * Copyright (C) 2007-2010 SMSC
24046 + *
24047 + * This program is free software; you can redistribute it and/or
24048 + * modify it under the terms of the GNU General Public License
24049 + * as published by the Free Software Foundation; either version 2
24050 + * of the License, or (at your option) any later version.
24051 + *
24052 + * This program is distributed in the hope that it will be useful,
24053 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24054 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24055 + * GNU General Public License for more details.
24056 + *
24057 + * You should have received a copy of the GNU General Public License
24058 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
24059 + *
24060 + *****************************************************************************/
24061 +
24062 +#ifndef _SMSC75XX_H
24063 +#define _SMSC75XX_H
24064 +
24065 +/* Tx command words */
24066 +#define TX_CMD_A_LSO (0x08000000)
24067 +#define TX_CMD_A_IPE (0x04000000)
24068 +#define TX_CMD_A_TPE (0x02000000)
24069 +#define TX_CMD_A_IVTG (0x01000000)
24070 +#define TX_CMD_A_RVTG (0x00800000)
24071 +#define TX_CMD_A_FCS (0x00400000)
24072 +#define TX_CMD_A_LEN (0x000FFFFF)
24073 +
24074 +#define TX_CMD_B_MSS (0x3FFF0000)
24075 +#define TX_CMD_B_MSS_SHIFT (16)
24076 +#define TX_MSS_MIN ((u16)8)
24077 +#define TX_CMD_B_VTAG (0x0000FFFF)
24078 +
24079 +/* Rx command words */
24080 +#define RX_CMD_A_ICE (0x80000000)
24081 +#define RX_CMD_A_TCE (0x40000000)
24082 +#define RX_CMD_A_IPV (0x20000000)
24083 +#define RX_CMD_A_PID (0x18000000)
24084 +#define RX_CMD_A_PID_NIP (0x00000000)
24085 +#define RX_CMD_A_PID_TCP (0x08000000)
24086 +#define RX_CMD_A_PID_UDP (0x10000000)
24087 +#define RX_CMD_A_PID_PP (0x18000000)
24088 +#define RX_CMD_A_PFF (0x04000000)
24089 +#define RX_CMD_A_BAM (0x02000000)
24090 +#define RX_CMD_A_MAM (0x01000000)
24091 +#define RX_CMD_A_FVTG (0x00800000)
24092 +#define RX_CMD_A_RED (0x00400000)
24093 +#define RX_CMD_A_RWT (0x00200000)
24094 +#define RX_CMD_A_RUNT (0x00100000)
24095 +#define RX_CMD_A_LONG (0x00080000)
24096 +#define RX_CMD_A_RXE (0x00040000)
24097 +#define RX_CMD_A_DRB (0x00020000)
24098 +#define RX_CMD_A_FCS (0x00010000)
24099 +#define RX_CMD_A_UAM (0x00008000)
24100 +#define RX_CMD_A_LCSM (0x00004000)
24101 +#define RX_CMD_A_LEN (0x00003FFF)
24102 +
24103 +#define RX_CMD_B_CSUM (0xFFFF0000)
24104 +#define RX_CMD_B_CSUM_SHIFT (16)
24105 +#define RX_CMD_B_VTAG (0x0000FFFF)
24106 +
24107 +/* SCSRs */
24108 +#define ID_REV (0x0000)
24109 +
24110 +#define FPGA_REV (0x0004)
24111 +
24112 +#define BOND_CTL (0x0008)
24113 +
24114 +#define INT_STS (0x000C)
24115 +#define INT_STS_RDFO_INT (0x00400000)
24116 +#define INT_STS_TXE_INT (0x00200000)
24117 +#define INT_STS_MACRTO_INT (0x00100000)
24118 +#define INT_STS_TX_DIS_INT (0x00080000)
24119 +#define INT_STS_RX_DIS_INT (0x00040000)
24120 +#define INT_STS_PHY_INT_ (0x00020000)
24121 +#define INT_STS_MAC_ERR_INT (0x00008000)
24122 +#define INT_STS_TDFU (0x00004000)
24123 +#define INT_STS_TDFO (0x00002000)
24124 +#define INT_STS_GPIOS (0x00000FFF)
24125 +#define INT_STS_CLEAR_ALL (0xFFFFFFFF)
24126 +
24127 +#define HW_CFG (0x0010)
24128 +#define HW_CFG_SMDET_STS (0x00008000)
24129 +#define HW_CFG_SMDET_EN (0x00004000)
24130 +#define HW_CFG_EEM (0x00002000)
24131 +#define HW_CFG_RST_PROTECT (0x00001000)
24132 +#define HW_CFG_PORT_SWAP (0x00000800)
24133 +#define HW_CFG_PHY_BOOST (0x00000600)
24134 +#define HW_CFG_PHY_BOOST_NORMAL (0x00000000)
24135 +#define HW_CFG_PHY_BOOST_4 (0x00002000)
24136 +#define HW_CFG_PHY_BOOST_8 (0x00004000)
24137 +#define HW_CFG_PHY_BOOST_12 (0x00006000)
24138 +#define HW_CFG_LEDB (0x00000100)
24139 +#define HW_CFG_BIR (0x00000080)
24140 +#define HW_CFG_SBP (0x00000040)
24141 +#define HW_CFG_IME (0x00000020)
24142 +#define HW_CFG_MEF (0x00000010)
24143 +#define HW_CFG_ETC (0x00000008)
24144 +#define HW_CFG_BCE (0x00000004)
24145 +#define HW_CFG_LRST (0x00000002)
24146 +#define HW_CFG_SRST (0x00000001)
24147 +
24148 +#define PMT_CTL (0x0014)
24149 +#define PMT_CTL_PHY_PWRUP (0x00000400)
24150 +#define PMT_CTL_RES_CLR_WKP_EN (0x00000100)
24151 +#define PMT_CTL_DEV_RDY (0x00000080)
24152 +#define PMT_CTL_SUS_MODE (0x00000060)
24153 +#define PMT_CTL_SUS_MODE_0 (0x00000000)
24154 +#define PMT_CTL_SUS_MODE_1 (0x00000020)
24155 +#define PMT_CTL_SUS_MODE_2 (0x00000040)
24156 +#define PMT_CTL_SUS_MODE_3 (0x00000060)
24157 +#define PMT_CTL_PHY_RST (0x00000010)
24158 +#define PMT_CTL_WOL_EN (0x00000008)
24159 +#define PMT_CTL_ED_EN (0x00000004)
24160 +#define PMT_CTL_WUPS (0x00000003)
24161 +#define PMT_CTL_WUPS_NO (0x00000000)
24162 +#define PMT_CTL_WUPS_ED (0x00000001)
24163 +#define PMT_CTL_WUPS_WOL (0x00000002)
24164 +#define PMT_CTL_WUPS_MULTI (0x00000003)
24165 +
24166 +#define LED_GPIO_CFG (0x0018)
24167 +#define LED_GPIO_CFG_LED2_FUN_SEL (0x80000000)
24168 +#define LED_GPIO_CFG_LED10_FUN_SEL (0x40000000)
24169 +#define LED_GPIO_CFG_LEDGPIO_EN (0x0000F000)
24170 +#define LED_GPIO_CFG_LEDGPIO_EN_0 (0x00001000)
24171 +#define LED_GPIO_CFG_LEDGPIO_EN_1 (0x00002000)
24172 +#define LED_GPIO_CFG_LEDGPIO_EN_2 (0x00004000)
24173 +#define LED_GPIO_CFG_LEDGPIO_EN_3 (0x00008000)
24174 +#define LED_GPIO_CFG_GPBUF (0x00000F00)
24175 +#define LED_GPIO_CFG_GPBUF_0 (0x00000100)
24176 +#define LED_GPIO_CFG_GPBUF_1 (0x00000200)
24177 +#define LED_GPIO_CFG_GPBUF_2 (0x00000400)
24178 +#define LED_GPIO_CFG_GPBUF_3 (0x00000800)
24179 +#define LED_GPIO_CFG_GPDIR (0x000000F0)
24180 +#define LED_GPIO_CFG_GPDIR_0 (0x00000010)
24181 +#define LED_GPIO_CFG_GPDIR_1 (0x00000020)
24182 +#define LED_GPIO_CFG_GPDIR_2 (0x00000040)
24183 +#define LED_GPIO_CFG_GPDIR_3 (0x00000080)
24184 +#define LED_GPIO_CFG_GPDATA (0x0000000F)
24185 +#define LED_GPIO_CFG_GPDATA_0 (0x00000001)
24186 +#define LED_GPIO_CFG_GPDATA_1 (0x00000002)
24187 +#define LED_GPIO_CFG_GPDATA_2 (0x00000004)
24188 +#define LED_GPIO_CFG_GPDATA_3 (0x00000008)
24189 +
24190 +#define GPIO_CFG (0x001C)
24191 +#define GPIO_CFG_SHIFT (24)
24192 +#define GPIO_CFG_GPEN (0xFF000000)
24193 +#define GPIO_CFG_GPBUF (0x00FF0000)
24194 +#define GPIO_CFG_GPDIR (0x0000FF00)
24195 +#define GPIO_CFG_GPDATA (0x000000FF)
24196 +
24197 +#define GPIO_WAKE (0x0020)
24198 +#define GPIO_WAKE_PHY_LINKUP_EN (0x80000000)
24199 +#define GPIO_WAKE_POL (0x0FFF0000)
24200 +#define GPIO_WAKE_POL_SHIFT (16)
24201 +#define GPIO_WAKE_WK (0x00000FFF)
24202 +
24203 +#define DP_SEL (0x0024)
24204 +#define DP_SEL_DPRDY (0x80000000)
24205 +#define DP_SEL_RSEL (0x0000000F)
24206 +#define DP_SEL_URX (0x00000000)
24207 +#define DP_SEL_VHF (0x00000001)
24208 +#define DP_SEL_VHF_HASH_LEN (16)
24209 +#define DP_SEL_VHF_VLAN_LEN (128)
24210 +#define DP_SEL_LSO_HEAD (0x00000002)
24211 +#define DP_SEL_FCT_RX (0x00000003)
24212 +#define DP_SEL_FCT_TX (0x00000004)
24213 +#define DP_SEL_DESCRIPTOR (0x00000005)
24214 +#define DP_SEL_WOL (0x00000006)
24215 +
24216 +#define DP_CMD (0x0028)
24217 +#define DP_CMD_WRITE (0x01)
24218 +#define DP_CMD_READ (0x00)
24219 +
24220 +#define DP_ADDR (0x002C)
24221 +
24222 +#define DP_DATA (0x0030)
24223 +
24224 +#define BURST_CAP (0x0034)
24225 +#define BURST_CAP_MASK (0x0000000F)
24226 +
24227 +#define INT_EP_CTL (0x0038)
24228 +#define INT_EP_CTL_INTEP_ON (0x80000000)
24229 +#define INT_EP_CTL_RDFO_EN (0x00400000)
24230 +#define INT_EP_CTL_TXE_EN (0x00200000)
24231 +#define INT_EP_CTL_MACROTO_EN (0x00100000)
24232 +#define INT_EP_CTL_TX_DIS_EN (0x00080000)
24233 +#define INT_EP_CTL_RX_DIS_EN (0x00040000)
24234 +#define INT_EP_CTL_PHY_EN_ (0x00020000)
24235 +#define INT_EP_CTL_MAC_ERR_EN (0x00008000)
24236 +#define INT_EP_CTL_TDFU_EN (0x00004000)
24237 +#define INT_EP_CTL_TDFO_EN (0x00002000)
24238 +#define INT_EP_CTL_RX_FIFO_EN (0x00001000)
24239 +#define INT_EP_CTL_GPIOX_EN (0x00000FFF)
24240 +
24241 +#define BULK_IN_DLY (0x003C)
24242 +#define BULK_IN_DLY_MASK (0xFFFF)
24243 +
24244 +#define E2P_CMD (0x0040)
24245 +#define E2P_CMD_BUSY (0x80000000)
24246 +#define E2P_CMD_MASK (0x70000000)
24247 +#define E2P_CMD_READ (0x00000000)
24248 +#define E2P_CMD_EWDS (0x10000000)
24249 +#define E2P_CMD_EWEN (0x20000000)
24250 +#define E2P_CMD_WRITE (0x30000000)
24251 +#define E2P_CMD_WRAL (0x40000000)
24252 +#define E2P_CMD_ERASE (0x50000000)
24253 +#define E2P_CMD_ERAL (0x60000000)
24254 +#define E2P_CMD_RELOAD (0x70000000)
24255 +#define E2P_CMD_TIMEOUT (0x00000400)
24256 +#define E2P_CMD_LOADED (0x00000200)
24257 +#define E2P_CMD_ADDR (0x000001FF)
24258 +
24259 +#define MAX_EEPROM_SIZE (512)
24260 +
24261 +#define E2P_DATA (0x0044)
24262 +#define E2P_DATA_MASK_ (0x000000FF)
24263 +
24264 +#define RFE_CTL (0x0060)
24265 +#define RFE_CTL_TCPUDP_CKM (0x00001000)
24266 +#define RFE_CTL_IP_CKM (0x00000800)
24267 +#define RFE_CTL_AB (0x00000400)
24268 +#define RFE_CTL_AM (0x00000200)
24269 +#define RFE_CTL_AU (0x00000100)
24270 +#define RFE_CTL_VS (0x00000080)
24271 +#define RFE_CTL_UF (0x00000040)
24272 +#define RFE_CTL_VF (0x00000020)
24273 +#define RFE_CTL_SPF (0x00000010)
24274 +#define RFE_CTL_MHF (0x00000008)
24275 +#define RFE_CTL_DHF (0x00000004)
24276 +#define RFE_CTL_DPF (0x00000002)
24277 +#define RFE_CTL_RST_RF (0x00000001)
24278 +
24279 +#define VLAN_TYPE (0x0064)
24280 +#define VLAN_TYPE_MASK (0x0000FFFF)
24281 +
24282 +#define FCT_RX_CTL (0x0090)
24283 +#define FCT_RX_CTL_EN (0x80000000)
24284 +#define FCT_RX_CTL_RST (0x40000000)
24285 +#define FCT_RX_CTL_SBF (0x02000000)
24286 +#define FCT_RX_CTL_OVERFLOW (0x01000000)
24287 +#define FCT_RX_CTL_FRM_DROP (0x00800000)
24288 +#define FCT_RX_CTL_RX_NOT_EMPTY (0x00400000)
24289 +#define FCT_RX_CTL_RX_EMPTY (0x00200000)
24290 +#define FCT_RX_CTL_RX_DISABLED (0x00100000)
24291 +#define FCT_RX_CTL_RXUSED (0x0000FFFF)
24292 +
24293 +#define FCT_TX_CTL (0x0094)
24294 +#define FCT_TX_CTL_EN (0x80000000)
24295 +#define FCT_TX_CTL_RST (0x40000000)
24296 +#define FCT_TX_CTL_TX_NOT_EMPTY (0x00400000)
24297 +#define FCT_TX_CTL_TX_EMPTY (0x00200000)
24298 +#define FCT_TX_CTL_TX_DISABLED (0x00100000)
24299 +#define FCT_TX_CTL_TXUSED (0x0000FFFF)
24300 +
24301 +#define FCT_RX_FIFO_END (0x0098)
24302 +#define FCT_RX_FIFO_END_MASK (0x0000007F)
24303 +
24304 +#define FCT_TX_FIFO_END (0x009C)
24305 +#define FCT_TX_FIFO_END_MASK (0x0000003F)
24306 +
24307 +#define FCT_FLOW (0x00A0)
24308 +#define FCT_FLOW_THRESHOLD_OFF (0x00007F00)
24309 +#define FCT_FLOW_THRESHOLD_OFF_SHIFT (8)
24310 +#define FCT_FLOW_THRESHOLD_ON (0x0000007F)
24311 +
24312 +/* MAC CSRs */
24313 +#define MAC_CR (0x100)
24314 +#define MAC_CR_ADP (0x00002000)
24315 +#define MAC_CR_ADD (0x00001000)
24316 +#define MAC_CR_ASD (0x00000800)
24317 +#define MAC_CR_INT_LOOP (0x00000400)
24318 +#define MAC_CR_BOLMT (0x000000C0)
24319 +#define MAC_CR_FDPX (0x00000008)
24320 +#define MAC_CR_CFG (0x00000006)
24321 +#define MAC_CR_CFG_10 (0x00000000)
24322 +#define MAC_CR_CFG_100 (0x00000002)
24323 +#define MAC_CR_CFG_1000 (0x00000004)
24324 +#define MAC_CR_RST (0x00000001)
24325 +
24326 +#define MAC_RX (0x104)
24327 +#define MAC_RX_MAX_SIZE (0x3FFF0000)
24328 +#define MAC_RX_MAX_SIZE_SHIFT (16)
24329 +#define MAC_RX_FCS_STRIP (0x00000010)
24330 +#define MAC_RX_FSE (0x00000004)
24331 +#define MAC_RX_RXD (0x00000002)
24332 +#define MAC_RX_RXEN (0x00000001)
24333 +
24334 +#define MAC_TX (0x108)
24335 +#define MAC_TX_BFCS (0x00000004)
24336 +#define MAC_TX_TXD (0x00000002)
24337 +#define MAC_TX_TXEN (0x00000001)
24338 +
24339 +#define FLOW (0x10C)
24340 +#define FLOW_FORCE_FC (0x80000000)
24341 +#define FLOW_TX_FCEN (0x40000000)
24342 +#define FLOW_RX_FCEN (0x20000000)
24343 +#define FLOW_FPF (0x10000000)
24344 +#define FLOW_PAUSE_TIME (0x0000FFFF)
24345 +
24346 +#define RAND_SEED (0x110)
24347 +#define RAND_SEED_MASK (0x0000FFFF)
24348 +
24349 +#define ERR_STS (0x114)
24350 +#define ERR_STS_FCS_ERR (0x00000100)
24351 +#define ERR_STS_LFRM_ERR (0x00000080)
24352 +#define ERR_STS_RUNT_ERR (0x00000040)
24353 +#define ERR_STS_COLLISION_ERR (0x00000010)
24354 +#define ERR_STS_ALIGN_ERR (0x00000008)
24355 +#define ERR_STS_URUN_ERR (0x00000004)
24356 +
24357 +#define RX_ADDRH (0x118)
24358 +#define RX_ADDRH_MASK (0x0000FFFF)
24359 +
24360 +#define RX_ADDRL (0x11C)
24361 +
24362 +#define MII_ACCESS (0x120)
24363 +#define MII_ACCESS_PHY_ADDR (0x0000F800)
24364 +#define MII_ACCESS_PHY_ADDR_SHIFT (11)
24365 +#define MII_ACCESS_REG_ADDR (0x000007C0)
24366 +#define MII_ACCESS_REG_ADDR_SHIFT (6)
24367 +#define MII_ACCESS_READ (0x00000000)
24368 +#define MII_ACCESS_WRITE (0x00000002)
24369 +#define MII_ACCESS_BUSY (0x00000001)
24370 +
24371 +#define MII_DATA (0x124)
24372 +#define MII_DATA_MASK (0x0000FFFF)
24373 +
24374 +#define WUCSR (0x140)
24375 +#define WUCSR_PFDA_FR (0x00000080)
24376 +#define WUCSR_WUFR (0x00000040)
24377 +#define WUCSR_MPR (0x00000020)
24378 +#define WUCSR_BCAST_FR (0x00000010)
24379 +#define WUCSR_PFDA_EN (0x00000008)
24380 +#define WUCSR_WUEN (0x00000004)
24381 +#define WUCSR_MPEN (0x00000002)
24382 +#define WUCSR_BCST_EN (0x00000001)
24383 +
24384 +#define WUF_CFGX (0x144)
24385 +#define WUF_CFGX_EN (0x80000000)
24386 +#define WUF_CFGX_ATYPE (0x03000000)
24387 +#define WUF_CFGX_ATYPE_UNICAST (0x00000000)
24388 +#define WUF_CFGX_ATYPE_MULTICAST (0x02000000)
24389 +#define WUF_CFGX_ATYPE_ALL (0x03000000)
24390 +#define WUF_CFGX_PATTERN_OFFSET (0x007F0000)
24391 +#define WUF_CFGX_PATTERN_OFFSET_SHIFT (16)
24392 +#define WUF_CFGX_CRC16 (0x0000FFFF)
24393 +#define WUF_NUM (8)
24394 +
24395 +#define WUF_MASKX (0x170)
24396 +#define WUF_MASKX_AVALID (0x80000000)
24397 +#define WUF_MASKX_ATYPE (0x40000000)
24398 +
24399 +#define ADDR_FILTX (0x300)
24400 +#define ADDR_FILTX_FB_VALID (0x80000000)
24401 +#define ADDR_FILTX_FB_TYPE (0x40000000)
24402 +#define ADDR_FILTX_FB_ADDRHI (0x0000FFFF)
24403 +#define ADDR_FILTX_SB_ADDRLO (0xFFFFFFFF)
24404 +
24405 +#define WUCSR2 (0x500)
24406 +#define WUCSR2_NS_RCD (0x00000040)
24407 +#define WUCSR2_ARP_RCD (0x00000020)
24408 +#define WUCSR2_TCPSYN_RCD (0x00000010)
24409 +#define WUCSR2_NS_OFFLOAD (0x00000004)
24410 +#define WUCSR2_ARP_OFFLOAD (0x00000002)
24411 +#define WUCSR2_TCPSYN_OFFLOAD (0x00000001)
24412 +
24413 +#define WOL_FIFO_STS (0x504)
24414 +
24415 +#define IPV6_ADDRX (0x510)
24416 +
24417 +#define IPV4_ADDRX (0x590)
24418 +
24419 +
24420 +/* Vendor-specific PHY Definitions */
24421 +
24422 +/* Mode Control/Status Register */
24423 +#define PHY_MODE_CTRL_STS (17)
24424 +#define MODE_CTRL_STS_EDPWRDOWN ((u16)0x2000)
24425 +#define MODE_CTRL_STS_ENERGYON ((u16)0x0002)
24426 +
24427 +#define PHY_INT_SRC (29)
24428 +#define PHY_INT_SRC_ENERGY_ON ((u16)0x0080)
24429 +#define PHY_INT_SRC_ANEG_COMP ((u16)0x0040)
24430 +#define PHY_INT_SRC_REMOTE_FAULT ((u16)0x0020)
24431 +#define PHY_INT_SRC_LINK_DOWN ((u16)0x0010)
24432 +#define PHY_INT_SRC_CLEAR_ALL ((u16)0xffff)
24433 +
24434 +#define PHY_INT_MASK (30)
24435 +#define PHY_INT_MASK_ENERGY_ON ((u16)0x0080)
24436 +#define PHY_INT_MASK_ANEG_COMP ((u16)0x0040)
24437 +#define PHY_INT_MASK_REMOTE_FAULT ((u16)0x0020)
24438 +#define PHY_INT_MASK_LINK_DOWN ((u16)0x0010)
24439 +#define PHY_INT_MASK_DEFAULT (PHY_INT_MASK_ANEG_COMP | \
24440 + PHY_INT_MASK_LINK_DOWN)
24441 +
24442 +#define PHY_SPECIAL (31)
24443 +#define PHY_SPECIAL_SPD ((u16)0x001C)
24444 +#define PHY_SPECIAL_SPD_10HALF ((u16)0x0004)
24445 +#define PHY_SPECIAL_SPD_10FULL ((u16)0x0014)
24446 +#define PHY_SPECIAL_SPD_100HALF ((u16)0x0008)
24447 +#define PHY_SPECIAL_SPD_100FULL ((u16)0x0018)
24448 +
24449 +/* USB Vendor Requests */
24450 +#define USB_VENDOR_REQUEST_WRITE_REGISTER 0xA0
24451 +#define USB_VENDOR_REQUEST_READ_REGISTER 0xA1
24452 +#define USB_VENDOR_REQUEST_GET_STATS 0xA2
24453 +
24454 +/* Interrupt Endpoint status word bitfields */
24455 +#define INT_ENP_RDFO_INT ((u32)BIT(22))
24456 +#define INT_ENP_TXE_INT ((u32)BIT(21))
24457 +#define INT_ENP_TX_DIS_INT ((u32)BIT(19))
24458 +#define INT_ENP_RX_DIS_INT ((u32)BIT(18))
24459 +#define INT_ENP_PHY_INT ((u32)BIT(17))
24460 +#define INT_ENP_MAC_ERR_INT ((u32)BIT(15))
24461 +#define INT_ENP_RX_FIFO_DATA_INT ((u32)BIT(12))
24462 +
24463 +#endif /* _SMSC75XX_H */
24464 diff -Naur backports-4.2.6-1.org/drivers/net/usb/smsc95xx.c backports-4.2.6-1/drivers/net/usb/smsc95xx.c
24465 --- backports-4.2.6-1.org/drivers/net/usb/smsc95xx.c 1970-01-01 01:00:00.000000000 +0100
24466 +++ backports-4.2.6-1/drivers/net/usb/smsc95xx.c 2016-06-28 14:35:18.011973884 +0200
24467 @@ -0,0 +1,2032 @@
24468 + /***************************************************************************
24469 + *
24470 + * Copyright (C) 2007-2008 SMSC
24471 + *
24472 + * This program is free software; you can redistribute it and/or
24473 + * modify it under the terms of the GNU General Public License
24474 + * as published by the Free Software Foundation; either version 2
24475 + * of the License, or (at your option) any later version.
24476 + *
24477 + * This program is distributed in the hope that it will be useful,
24478 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24479 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24480 + * GNU General Public License for more details.
24481 + *
24482 + * You should have received a copy of the GNU General Public License
24483 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
24484 + *
24485 + *****************************************************************************/
24486 +
24487 +#include <linux/module.h>
24488 +#include <linux/kmod.h>
24489 +#include <linux/netdevice.h>
24490 +#include <linux/etherdevice.h>
24491 +#include <linux/ethtool.h>
24492 +#include <linux/mii.h>
24493 +#include <linux/usb.h>
24494 +#include <linux/bitrev.h>
24495 +#include <linux/crc16.h>
24496 +#include <linux/crc32.h>
24497 +#include <linux/usb/usbnet.h>
24498 +#include <linux/slab.h>
24499 +#include "smsc95xx.h"
24500 +
24501 +#define SMSC_CHIPNAME "smsc95xx"
24502 +#define SMSC_DRIVER_VERSION "1.0.4"
24503 +#define HS_USB_PKT_SIZE (512)
24504 +#define FS_USB_PKT_SIZE (64)
24505 +#define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE)
24506 +#define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE)
24507 +#define DEFAULT_BULK_IN_DELAY (0x00002000)
24508 +#define MAX_SINGLE_PACKET_SIZE (2048)
24509 +#define LAN95XX_EEPROM_MAGIC (0x9500)
24510 +#define EEPROM_MAC_OFFSET (0x01)
24511 +#define DEFAULT_TX_CSUM_ENABLE (true)
24512 +#define DEFAULT_RX_CSUM_ENABLE (true)
24513 +#define SMSC95XX_INTERNAL_PHY_ID (1)
24514 +#define SMSC95XX_TX_OVERHEAD (8)
24515 +#define SMSC95XX_TX_OVERHEAD_CSUM (12)
24516 +#define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \
24517 + WAKE_MCAST | WAKE_ARP | WAKE_MAGIC)
24518 +
24519 +#define FEATURE_8_WAKEUP_FILTERS (0x01)
24520 +#define FEATURE_PHY_NLP_CROSSOVER (0x02)
24521 +#define FEATURE_REMOTE_WAKEUP (0x04)
24522 +
24523 +#define SUSPEND_SUSPEND0 (0x01)
24524 +#define SUSPEND_SUSPEND1 (0x02)
24525 +#define SUSPEND_SUSPEND2 (0x04)
24526 +#define SUSPEND_SUSPEND3 (0x08)
24527 +#define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
24528 + SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
24529 +
24530 +struct smsc95xx_priv {
24531 + u32 mac_cr;
24532 + u32 hash_hi;
24533 + u32 hash_lo;
24534 + u32 wolopts;
24535 + spinlock_t mac_cr_lock;
24536 + u8 features;
24537 + u8 suspend_flags;
24538 +};
24539 +
24540 +static bool turbo_mode = true;
24541 +module_param(turbo_mode, bool, 0644);
24542 +MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
24543 +
24544 +static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
24545 + u32 *data, int in_pm)
24546 +{
24547 + u32 buf;
24548 + int ret;
24549 + int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
24550 +
24551 + BUG_ON(!dev);
24552 +
24553 + if (!in_pm)
24554 + fn = usbnet_read_cmd;
24555 + else
24556 + fn = usbnet_read_cmd_nopm;
24557 +
24558 + ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN
24559 + | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
24560 + 0, index, &buf, 4);
24561 + if (unlikely(ret < 0))
24562 + netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n",
24563 + index, ret);
24564 +
24565 + le32_to_cpus(&buf);
24566 + *data = buf;
24567 +
24568 + return ret;
24569 +}
24570 +
24571 +static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index,
24572 + u32 data, int in_pm)
24573 +{
24574 + u32 buf;
24575 + int ret;
24576 + int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
24577 +
24578 + BUG_ON(!dev);
24579 +
24580 + if (!in_pm)
24581 + fn = usbnet_write_cmd;
24582 + else
24583 + fn = usbnet_write_cmd_nopm;
24584 +
24585 + buf = data;
24586 + cpu_to_le32s(&buf);
24587 +
24588 + ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT
24589 + | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
24590 + 0, index, &buf, 4);
24591 + if (unlikely(ret < 0))
24592 + netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n",
24593 + index, ret);
24594 +
24595 + return ret;
24596 +}
24597 +
24598 +static int __must_check smsc95xx_read_reg_nopm(struct usbnet *dev, u32 index,
24599 + u32 *data)
24600 +{
24601 + return __smsc95xx_read_reg(dev, index, data, 1);
24602 +}
24603 +
24604 +static int __must_check smsc95xx_write_reg_nopm(struct usbnet *dev, u32 index,
24605 + u32 data)
24606 +{
24607 + return __smsc95xx_write_reg(dev, index, data, 1);
24608 +}
24609 +
24610 +static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index,
24611 + u32 *data)
24612 +{
24613 + return __smsc95xx_read_reg(dev, index, data, 0);
24614 +}
24615 +
24616 +static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index,
24617 + u32 data)
24618 +{
24619 + return __smsc95xx_write_reg(dev, index, data, 0);
24620 +}
24621 +
24622 +/* Loop until the read is completed with timeout
24623 + * called with phy_mutex held */
24624 +static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev,
24625 + int in_pm)
24626 +{
24627 + unsigned long start_time = jiffies;
24628 + u32 val;
24629 + int ret;
24630 +
24631 + do {
24632 + ret = __smsc95xx_read_reg(dev, MII_ADDR, &val, in_pm);
24633 + if (ret < 0) {
24634 + netdev_warn(dev->net, "Error reading MII_ACCESS\n");
24635 + return ret;
24636 + }
24637 +
24638 + if (!(val & MII_BUSY_))
24639 + return 0;
24640 + } while (!time_after(jiffies, start_time + HZ));
24641 +
24642 + return -EIO;
24643 +}
24644 +
24645 +static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx,
24646 + int in_pm)
24647 +{
24648 + struct usbnet *dev = netdev_priv(netdev);
24649 + u32 val, addr;
24650 + int ret;
24651 +
24652 + mutex_lock(&dev->phy_mutex);
24653 +
24654 + /* confirm MII not busy */
24655 + ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
24656 + if (ret < 0) {
24657 + netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_read\n");
24658 + goto done;
24659 + }
24660 +
24661 + /* set the address, index & direction (read from PHY) */
24662 + phy_id &= dev->mii.phy_id_mask;
24663 + idx &= dev->mii.reg_num_mask;
24664 + addr = (phy_id << 11) | (idx << 6) | MII_READ_ | MII_BUSY_;
24665 + ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
24666 + if (ret < 0) {
24667 + netdev_warn(dev->net, "Error writing MII_ADDR\n");
24668 + goto done;
24669 + }
24670 +
24671 + ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
24672 + if (ret < 0) {
24673 + netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx);
24674 + goto done;
24675 + }
24676 +
24677 + ret = __smsc95xx_read_reg(dev, MII_DATA, &val, in_pm);
24678 + if (ret < 0) {
24679 + netdev_warn(dev->net, "Error reading MII_DATA\n");
24680 + goto done;
24681 + }
24682 +
24683 + ret = (u16)(val & 0xFFFF);
24684 +
24685 +done:
24686 + mutex_unlock(&dev->phy_mutex);
24687 + return ret;
24688 +}
24689 +
24690 +static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id,
24691 + int idx, int regval, int in_pm)
24692 +{
24693 + struct usbnet *dev = netdev_priv(netdev);
24694 + u32 val, addr;
24695 + int ret;
24696 +
24697 + mutex_lock(&dev->phy_mutex);
24698 +
24699 + /* confirm MII not busy */
24700 + ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
24701 + if (ret < 0) {
24702 + netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_write\n");
24703 + goto done;
24704 + }
24705 +
24706 + val = regval;
24707 + ret = __smsc95xx_write_reg(dev, MII_DATA, val, in_pm);
24708 + if (ret < 0) {
24709 + netdev_warn(dev->net, "Error writing MII_DATA\n");
24710 + goto done;
24711 + }
24712 +
24713 + /* set the address, index & direction (write to PHY) */
24714 + phy_id &= dev->mii.phy_id_mask;
24715 + idx &= dev->mii.reg_num_mask;
24716 + addr = (phy_id << 11) | (idx << 6) | MII_WRITE_ | MII_BUSY_;
24717 + ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
24718 + if (ret < 0) {
24719 + netdev_warn(dev->net, "Error writing MII_ADDR\n");
24720 + goto done;
24721 + }
24722 +
24723 + ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
24724 + if (ret < 0) {
24725 + netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx);
24726 + goto done;
24727 + }
24728 +
24729 +done:
24730 + mutex_unlock(&dev->phy_mutex);
24731 +}
24732 +
24733 +static int smsc95xx_mdio_read_nopm(struct net_device *netdev, int phy_id,
24734 + int idx)
24735 +{
24736 + return __smsc95xx_mdio_read(netdev, phy_id, idx, 1);
24737 +}
24738 +
24739 +static void smsc95xx_mdio_write_nopm(struct net_device *netdev, int phy_id,
24740 + int idx, int regval)
24741 +{
24742 + __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 1);
24743 +}
24744 +
24745 +static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx)
24746 +{
24747 + return __smsc95xx_mdio_read(netdev, phy_id, idx, 0);
24748 +}
24749 +
24750 +static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
24751 + int regval)
24752 +{
24753 + __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 0);
24754 +}
24755 +
24756 +static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev)
24757 +{
24758 + unsigned long start_time = jiffies;
24759 + u32 val;
24760 + int ret;
24761 +
24762 + do {
24763 + ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
24764 + if (ret < 0) {
24765 + netdev_warn(dev->net, "Error reading E2P_CMD\n");
24766 + return ret;
24767 + }
24768 +
24769 + if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_))
24770 + break;
24771 + udelay(40);
24772 + } while (!time_after(jiffies, start_time + HZ));
24773 +
24774 + if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) {
24775 + netdev_warn(dev->net, "EEPROM read operation timeout\n");
24776 + return -EIO;
24777 + }
24778 +
24779 + return 0;
24780 +}
24781 +
24782 +static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev)
24783 +{
24784 + unsigned long start_time = jiffies;
24785 + u32 val;
24786 + int ret;
24787 +
24788 + do {
24789 + ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
24790 + if (ret < 0) {
24791 + netdev_warn(dev->net, "Error reading E2P_CMD\n");
24792 + return ret;
24793 + }
24794 +
24795 + if (!(val & E2P_CMD_BUSY_))
24796 + return 0;
24797 +
24798 + udelay(40);
24799 + } while (!time_after(jiffies, start_time + HZ));
24800 +
24801 + netdev_warn(dev->net, "EEPROM is busy\n");
24802 + return -EIO;
24803 +}
24804 +
24805 +static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
24806 + u8 *data)
24807 +{
24808 + u32 val;
24809 + int i, ret;
24810 +
24811 + BUG_ON(!dev);
24812 + BUG_ON(!data);
24813 +
24814 + ret = smsc95xx_eeprom_confirm_not_busy(dev);
24815 + if (ret)
24816 + return ret;
24817 +
24818 + for (i = 0; i < length; i++) {
24819 + val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_);
24820 + ret = smsc95xx_write_reg(dev, E2P_CMD, val);
24821 + if (ret < 0) {
24822 + netdev_warn(dev->net, "Error writing E2P_CMD\n");
24823 + return ret;
24824 + }
24825 +
24826 + ret = smsc95xx_wait_eeprom(dev);
24827 + if (ret < 0)
24828 + return ret;
24829 +
24830 + ret = smsc95xx_read_reg(dev, E2P_DATA, &val);
24831 + if (ret < 0) {
24832 + netdev_warn(dev->net, "Error reading E2P_DATA\n");
24833 + return ret;
24834 + }
24835 +
24836 + data[i] = val & 0xFF;
24837 + offset++;
24838 + }
24839 +
24840 + return 0;
24841 +}
24842 +
24843 +static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
24844 + u8 *data)
24845 +{
24846 + u32 val;
24847 + int i, ret;
24848 +
24849 + BUG_ON(!dev);
24850 + BUG_ON(!data);
24851 +
24852 + ret = smsc95xx_eeprom_confirm_not_busy(dev);
24853 + if (ret)
24854 + return ret;
24855 +
24856 + /* Issue write/erase enable command */
24857 + val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_;
24858 + ret = smsc95xx_write_reg(dev, E2P_CMD, val);
24859 + if (ret < 0) {
24860 + netdev_warn(dev->net, "Error writing E2P_DATA\n");
24861 + return ret;
24862 + }
24863 +
24864 + ret = smsc95xx_wait_eeprom(dev);
24865 + if (ret < 0)
24866 + return ret;
24867 +
24868 + for (i = 0; i < length; i++) {
24869 +
24870 + /* Fill data register */
24871 + val = data[i];
24872 + ret = smsc95xx_write_reg(dev, E2P_DATA, val);
24873 + if (ret < 0) {
24874 + netdev_warn(dev->net, "Error writing E2P_DATA\n");
24875 + return ret;
24876 + }
24877 +
24878 + /* Send "write" command */
24879 + val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_);
24880 + ret = smsc95xx_write_reg(dev, E2P_CMD, val);
24881 + if (ret < 0) {
24882 + netdev_warn(dev->net, "Error writing E2P_CMD\n");
24883 + return ret;
24884 + }
24885 +
24886 + ret = smsc95xx_wait_eeprom(dev);
24887 + if (ret < 0)
24888 + return ret;
24889 +
24890 + offset++;
24891 + }
24892 +
24893 + return 0;
24894 +}
24895 +
24896 +static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index,
24897 + u32 data)
24898 +{
24899 + const u16 size = 4;
24900 + u32 buf;
24901 + int ret;
24902 +
24903 + buf = data;
24904 + cpu_to_le32s(&buf);
24905 +
24906 + ret = usbnet_write_cmd_async(dev, USB_VENDOR_REQUEST_WRITE_REGISTER,
24907 + USB_DIR_OUT | USB_TYPE_VENDOR |
24908 + USB_RECIP_DEVICE,
24909 + 0, index, &buf, size);
24910 + if (ret < 0)
24911 + netdev_warn(dev->net, "Error write async cmd, sts=%d\n",
24912 + ret);
24913 + return ret;
24914 +}
24915 +
24916 +/* returns hash bit number for given MAC address
24917 + * example:
24918 + * 01 00 5E 00 00 01 -> returns bit number 31 */
24919 +static unsigned int smsc95xx_hash(char addr[ETH_ALEN])
24920 +{
24921 + return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f;
24922 +}
24923 +
24924 +static void smsc95xx_set_multicast(struct net_device *netdev)
24925 +{
24926 + struct usbnet *dev = netdev_priv(netdev);
24927 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
24928 + unsigned long flags;
24929 + int ret;
24930 +
24931 + pdata->hash_hi = 0;
24932 + pdata->hash_lo = 0;
24933 +
24934 + spin_lock_irqsave(&pdata->mac_cr_lock, flags);
24935 +
24936 + if (dev->net->flags & IFF_PROMISC) {
24937 + netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n");
24938 + pdata->mac_cr |= MAC_CR_PRMS_;
24939 + pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
24940 + } else if (dev->net->flags & IFF_ALLMULTI) {
24941 + netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n");
24942 + pdata->mac_cr |= MAC_CR_MCPAS_;
24943 + pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_);
24944 + } else if (!netdev_mc_empty(dev->net)) {
24945 + struct netdev_hw_addr *ha;
24946 +
24947 + pdata->mac_cr |= MAC_CR_HPFILT_;
24948 + pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
24949 +
24950 + netdev_for_each_mc_addr(ha, netdev) {
24951 + u32 bitnum = smsc95xx_hash(ha->addr);
24952 + u32 mask = 0x01 << (bitnum & 0x1F);
24953 + if (bitnum & 0x20)
24954 + pdata->hash_hi |= mask;
24955 + else
24956 + pdata->hash_lo |= mask;
24957 + }
24958 +
24959 + netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n",
24960 + pdata->hash_hi, pdata->hash_lo);
24961 + } else {
24962 + netif_dbg(dev, drv, dev->net, "receive own packets only\n");
24963 + pdata->mac_cr &=
24964 + ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
24965 + }
24966 +
24967 + spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
24968 +
24969 + /* Initiate async writes, as we can't wait for completion here */
24970 + ret = smsc95xx_write_reg_async(dev, HASHH, pdata->hash_hi);
24971 + if (ret < 0)
24972 + netdev_warn(dev->net, "failed to initiate async write to HASHH\n");
24973 +
24974 + ret = smsc95xx_write_reg_async(dev, HASHL, pdata->hash_lo);
24975 + if (ret < 0)
24976 + netdev_warn(dev->net, "failed to initiate async write to HASHL\n");
24977 +
24978 + ret = smsc95xx_write_reg_async(dev, MAC_CR, pdata->mac_cr);
24979 + if (ret < 0)
24980 + netdev_warn(dev->net, "failed to initiate async write to MAC_CR\n");
24981 +}
24982 +
24983 +static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex,
24984 + u16 lcladv, u16 rmtadv)
24985 +{
24986 + u32 flow, afc_cfg = 0;
24987 +
24988 + int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg);
24989 + if (ret < 0)
24990 + return ret;
24991 +
24992 + if (duplex == DUPLEX_FULL) {
24993 + u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
24994 +
24995 + if (cap & FLOW_CTRL_RX)
24996 + flow = 0xFFFF0002;
24997 + else
24998 + flow = 0;
24999 +
25000 + if (cap & FLOW_CTRL_TX)
25001 + afc_cfg |= 0xF;
25002 + else
25003 + afc_cfg &= ~0xF;
25004 +
25005 + netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n",
25006 + cap & FLOW_CTRL_RX ? "enabled" : "disabled",
25007 + cap & FLOW_CTRL_TX ? "enabled" : "disabled");
25008 + } else {
25009 + netif_dbg(dev, link, dev->net, "half duplex\n");
25010 + flow = 0;
25011 + afc_cfg |= 0xF;
25012 + }
25013 +
25014 + ret = smsc95xx_write_reg(dev, FLOW, flow);
25015 + if (ret < 0)
25016 + return ret;
25017 +
25018 + return smsc95xx_write_reg(dev, AFC_CFG, afc_cfg);
25019 +}
25020 +
25021 +static int smsc95xx_link_reset(struct usbnet *dev)
25022 +{
25023 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25024 + struct mii_if_info *mii = &dev->mii;
25025 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
25026 + unsigned long flags;
25027 + u16 lcladv, rmtadv;
25028 + int ret;
25029 +
25030 + /* clear interrupt status */
25031 + ret = smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC);
25032 + if (ret < 0)
25033 + return ret;
25034 +
25035 + ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
25036 + if (ret < 0)
25037 + return ret;
25038 +
25039 + mii_check_media(mii, 1, 1);
25040 + mii_ethtool_gset(&dev->mii, &ecmd);
25041 + lcladv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE);
25042 + rmtadv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_LPA);
25043 +
25044 + netif_dbg(dev, link, dev->net,
25045 + "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n",
25046 + ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv);
25047 +
25048 + spin_lock_irqsave(&pdata->mac_cr_lock, flags);
25049 + if (ecmd.duplex != DUPLEX_FULL) {
25050 + pdata->mac_cr &= ~MAC_CR_FDPX_;
25051 + pdata->mac_cr |= MAC_CR_RCVOWN_;
25052 + } else {
25053 + pdata->mac_cr &= ~MAC_CR_RCVOWN_;
25054 + pdata->mac_cr |= MAC_CR_FDPX_;
25055 + }
25056 + spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
25057 +
25058 + ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
25059 + if (ret < 0)
25060 + return ret;
25061 +
25062 + ret = smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv);
25063 + if (ret < 0)
25064 + netdev_warn(dev->net, "Error updating PHY flow control\n");
25065 +
25066 + return ret;
25067 +}
25068 +
25069 +static void smsc95xx_status(struct usbnet *dev, struct urb *urb)
25070 +{
25071 + u32 intdata;
25072 +
25073 + if (urb->actual_length != 4) {
25074 + netdev_warn(dev->net, "unexpected urb length %d\n",
25075 + urb->actual_length);
25076 + return;
25077 + }
25078 +
25079 + memcpy(&intdata, urb->transfer_buffer, 4);
25080 + le32_to_cpus(&intdata);
25081 +
25082 + netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
25083 +
25084 + if (intdata & INT_ENP_PHY_INT_)
25085 + usbnet_defer_kevent(dev, EVENT_LINK_RESET);
25086 + else
25087 + netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n",
25088 + intdata);
25089 +}
25090 +
25091 +/* Enable or disable Tx & Rx checksum offload engines */
25092 +static int smsc95xx_set_features(struct net_device *netdev,
25093 + netdev_features_t features)
25094 +{
25095 + struct usbnet *dev = netdev_priv(netdev);
25096 + u32 read_buf;
25097 + int ret;
25098 +
25099 + ret = smsc95xx_read_reg(dev, COE_CR, &read_buf);
25100 + if (ret < 0)
25101 + return ret;
25102 +
25103 + if (features & NETIF_F_HW_CSUM)
25104 + read_buf |= Tx_COE_EN_;
25105 + else
25106 + read_buf &= ~Tx_COE_EN_;
25107 +
25108 + if (features & NETIF_F_RXCSUM)
25109 + read_buf |= Rx_COE_EN_;
25110 + else
25111 + read_buf &= ~Rx_COE_EN_;
25112 +
25113 + ret = smsc95xx_write_reg(dev, COE_CR, read_buf);
25114 + if (ret < 0)
25115 + return ret;
25116 +
25117 + netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf);
25118 + return 0;
25119 +}
25120 +
25121 +static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net)
25122 +{
25123 + return MAX_EEPROM_SIZE;
25124 +}
25125 +
25126 +static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev,
25127 + struct ethtool_eeprom *ee, u8 *data)
25128 +{
25129 + struct usbnet *dev = netdev_priv(netdev);
25130 +
25131 + ee->magic = LAN95XX_EEPROM_MAGIC;
25132 +
25133 + return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data);
25134 +}
25135 +
25136 +static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev,
25137 + struct ethtool_eeprom *ee, u8 *data)
25138 +{
25139 + struct usbnet *dev = netdev_priv(netdev);
25140 +
25141 + if (ee->magic != LAN95XX_EEPROM_MAGIC) {
25142 + netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n",
25143 + ee->magic);
25144 + return -EINVAL;
25145 + }
25146 +
25147 + return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data);
25148 +}
25149 +
25150 +static int smsc95xx_ethtool_getregslen(struct net_device *netdev)
25151 +{
25152 + /* all smsc95xx registers */
25153 + return COE_CR - ID_REV + sizeof(u32);
25154 +}
25155 +
25156 +static void
25157 +smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs,
25158 + void *buf)
25159 +{
25160 + struct usbnet *dev = netdev_priv(netdev);
25161 + unsigned int i, j;
25162 + int retval;
25163 + u32 *data = buf;
25164 +
25165 + retval = smsc95xx_read_reg(dev, ID_REV, &regs->version);
25166 + if (retval < 0) {
25167 + netdev_warn(netdev, "REGS: cannot read ID_REV\n");
25168 + return;
25169 + }
25170 +
25171 + for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) {
25172 + retval = smsc95xx_read_reg(dev, i, &data[j]);
25173 + if (retval < 0) {
25174 + netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i);
25175 + return;
25176 + }
25177 + }
25178 +}
25179 +
25180 +static void smsc95xx_ethtool_get_wol(struct net_device *net,
25181 + struct ethtool_wolinfo *wolinfo)
25182 +{
25183 + struct usbnet *dev = netdev_priv(net);
25184 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25185 +
25186 + wolinfo->supported = SUPPORTED_WAKE;
25187 + wolinfo->wolopts = pdata->wolopts;
25188 +}
25189 +
25190 +static int smsc95xx_ethtool_set_wol(struct net_device *net,
25191 + struct ethtool_wolinfo *wolinfo)
25192 +{
25193 + struct usbnet *dev = netdev_priv(net);
25194 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25195 + int ret;
25196 +
25197 + pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE;
25198 +
25199 + ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts);
25200 + if (ret < 0)
25201 + netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret);
25202 +
25203 + return ret;
25204 +}
25205 +
25206 +static const struct ethtool_ops smsc95xx_ethtool_ops = {
25207 + .get_link = usbnet_get_link,
25208 + .nway_reset = usbnet_nway_reset,
25209 + .get_drvinfo = usbnet_get_drvinfo,
25210 + .get_msglevel = usbnet_get_msglevel,
25211 + .set_msglevel = usbnet_set_msglevel,
25212 + .get_settings = usbnet_get_settings,
25213 + .set_settings = usbnet_set_settings,
25214 + .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len,
25215 + .get_eeprom = smsc95xx_ethtool_get_eeprom,
25216 + .set_eeprom = smsc95xx_ethtool_set_eeprom,
25217 + .get_regs_len = smsc95xx_ethtool_getregslen,
25218 + .get_regs = smsc95xx_ethtool_getregs,
25219 + .get_wol = smsc95xx_ethtool_get_wol,
25220 + .set_wol = smsc95xx_ethtool_set_wol,
25221 +};
25222 +
25223 +static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
25224 +{
25225 + struct usbnet *dev = netdev_priv(netdev);
25226 +
25227 + if (!netif_running(netdev))
25228 + return -EINVAL;
25229 +
25230 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
25231 +}
25232 +
25233 +static void smsc95xx_init_mac_address(struct usbnet *dev)
25234 +{
25235 + /* try reading mac address from EEPROM */
25236 + if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
25237 + dev->net->dev_addr) == 0) {
25238 + if (is_valid_ether_addr(dev->net->dev_addr)) {
25239 + /* eeprom values are valid so use them */
25240 + netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n");
25241 + return;
25242 + }
25243 + }
25244 +
25245 + /* no eeprom, or eeprom values are invalid. generate random MAC */
25246 + eth_hw_addr_random(dev->net);
25247 + netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
25248 +}
25249 +
25250 +static int smsc95xx_set_mac_address(struct usbnet *dev)
25251 +{
25252 + u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 |
25253 + dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24;
25254 + u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8;
25255 + int ret;
25256 +
25257 + ret = smsc95xx_write_reg(dev, ADDRL, addr_lo);
25258 + if (ret < 0)
25259 + return ret;
25260 +
25261 + return smsc95xx_write_reg(dev, ADDRH, addr_hi);
25262 +}
25263 +
25264 +/* starts the TX path */
25265 +static int smsc95xx_start_tx_path(struct usbnet *dev)
25266 +{
25267 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25268 + unsigned long flags;
25269 + int ret;
25270 +
25271 + /* Enable Tx at MAC */
25272 + spin_lock_irqsave(&pdata->mac_cr_lock, flags);
25273 + pdata->mac_cr |= MAC_CR_TXEN_;
25274 + spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
25275 +
25276 + ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
25277 + if (ret < 0)
25278 + return ret;
25279 +
25280 + /* Enable Tx at SCSRs */
25281 + return smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_);
25282 +}
25283 +
25284 +/* Starts the Receive path */
25285 +static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm)
25286 +{
25287 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25288 + unsigned long flags;
25289 +
25290 + spin_lock_irqsave(&pdata->mac_cr_lock, flags);
25291 + pdata->mac_cr |= MAC_CR_RXEN_;
25292 + spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
25293 +
25294 + return __smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr, in_pm);
25295 +}
25296 +
25297 +static int smsc95xx_phy_initialize(struct usbnet *dev)
25298 +{
25299 + int bmcr, ret, timeout = 0;
25300 +
25301 + /* Initialize MII structure */
25302 + dev->mii.dev = dev->net;
25303 + dev->mii.mdio_read = smsc95xx_mdio_read;
25304 + dev->mii.mdio_write = smsc95xx_mdio_write;
25305 + dev->mii.phy_id_mask = 0x1f;
25306 + dev->mii.reg_num_mask = 0x1f;
25307 + dev->mii.phy_id = SMSC95XX_INTERNAL_PHY_ID;
25308 +
25309 + /* reset phy and wait for reset to complete */
25310 + smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
25311 +
25312 + do {
25313 + msleep(10);
25314 + bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR);
25315 + timeout++;
25316 + } while ((bmcr & BMCR_RESET) && (timeout < 100));
25317 +
25318 + if (timeout >= 100) {
25319 + netdev_warn(dev->net, "timeout on PHY Reset");
25320 + return -EIO;
25321 + }
25322 +
25323 + smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
25324 + ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
25325 + ADVERTISE_PAUSE_ASYM);
25326 +
25327 + /* read to clear */
25328 + ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC);
25329 + if (ret < 0) {
25330 + netdev_warn(dev->net, "Failed to read PHY_INT_SRC during init\n");
25331 + return ret;
25332 + }
25333 +
25334 + smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK,
25335 + PHY_INT_MASK_DEFAULT_);
25336 + mii_nway_restart(&dev->mii);
25337 +
25338 + netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n");
25339 + return 0;
25340 +}
25341 +
25342 +static int smsc95xx_reset(struct usbnet *dev)
25343 +{
25344 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25345 + u32 read_buf, write_buf, burst_cap;
25346 + int ret = 0, timeout;
25347 +
25348 + netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n");
25349 +
25350 + ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_);
25351 + if (ret < 0)
25352 + return ret;
25353 +
25354 + timeout = 0;
25355 + do {
25356 + msleep(10);
25357 + ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
25358 + if (ret < 0)
25359 + return ret;
25360 + timeout++;
25361 + } while ((read_buf & HW_CFG_LRST_) && (timeout < 100));
25362 +
25363 + if (timeout >= 100) {
25364 + netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n");
25365 + return ret;
25366 + }
25367 +
25368 + ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_);
25369 + if (ret < 0)
25370 + return ret;
25371 +
25372 + timeout = 0;
25373 + do {
25374 + msleep(10);
25375 + ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf);
25376 + if (ret < 0)
25377 + return ret;
25378 + timeout++;
25379 + } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100));
25380 +
25381 + if (timeout >= 100) {
25382 + netdev_warn(dev->net, "timeout waiting for PHY Reset\n");
25383 + return ret;
25384 + }
25385 +
25386 + ret = smsc95xx_set_mac_address(dev);
25387 + if (ret < 0)
25388 + return ret;
25389 +
25390 + netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n",
25391 + dev->net->dev_addr);
25392 +
25393 + ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
25394 + if (ret < 0)
25395 + return ret;
25396 +
25397 + netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n",
25398 + read_buf);
25399 +
25400 + read_buf |= HW_CFG_BIR_;
25401 +
25402 + ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
25403 + if (ret < 0)
25404 + return ret;
25405 +
25406 + ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
25407 + if (ret < 0)
25408 + return ret;
25409 +
25410 + netif_dbg(dev, ifup, dev->net,
25411 + "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n",
25412 + read_buf);
25413 +
25414 + if (!turbo_mode) {
25415 + burst_cap = 0;
25416 + dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
25417 + } else if (dev->udev->speed == USB_SPEED_HIGH) {
25418 + burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
25419 + dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
25420 + } else {
25421 + burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
25422 + dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
25423 + }
25424 +
25425 + netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n",
25426 + (ulong)dev->rx_urb_size);
25427 +
25428 + ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
25429 + if (ret < 0)
25430 + return ret;
25431 +
25432 + ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf);
25433 + if (ret < 0)
25434 + return ret;
25435 +
25436 + netif_dbg(dev, ifup, dev->net,
25437 + "Read Value from BURST_CAP after writing: 0x%08x\n",
25438 + read_buf);
25439 +
25440 + ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY);
25441 + if (ret < 0)
25442 + return ret;
25443 +
25444 + ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf);
25445 + if (ret < 0)
25446 + return ret;
25447 +
25448 + netif_dbg(dev, ifup, dev->net,
25449 + "Read Value from BULK_IN_DLY after writing: 0x%08x\n",
25450 + read_buf);
25451 +
25452 + ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
25453 + if (ret < 0)
25454 + return ret;
25455 +
25456 + netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG: 0x%08x\n",
25457 + read_buf);
25458 +
25459 + if (turbo_mode)
25460 + read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_);
25461 +
25462 + read_buf &= ~HW_CFG_RXDOFF_;
25463 +
25464 + /* set Rx data offset=2, Make IP header aligns on word boundary. */
25465 + read_buf |= NET_IP_ALIGN << 9;
25466 +
25467 + ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
25468 + if (ret < 0)
25469 + return ret;
25470 +
25471 + ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
25472 + if (ret < 0)
25473 + return ret;
25474 +
25475 + netif_dbg(dev, ifup, dev->net,
25476 + "Read Value from HW_CFG after writing: 0x%08x\n", read_buf);
25477 +
25478 + ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
25479 + if (ret < 0)
25480 + return ret;
25481 +
25482 + ret = smsc95xx_read_reg(dev, ID_REV, &read_buf);
25483 + if (ret < 0)
25484 + return ret;
25485 + netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf);
25486 +
25487 + /* Configure GPIO pins as LED outputs */
25488 + write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED |
25489 + LED_GPIO_CFG_FDX_LED;
25490 + ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf);
25491 + if (ret < 0)
25492 + return ret;
25493 +
25494 + /* Init Tx */
25495 + ret = smsc95xx_write_reg(dev, FLOW, 0);
25496 + if (ret < 0)
25497 + return ret;
25498 +
25499 + ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT);
25500 + if (ret < 0)
25501 + return ret;
25502 +
25503 + /* Don't need mac_cr_lock during initialisation */
25504 + ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr);
25505 + if (ret < 0)
25506 + return ret;
25507 +
25508 + /* Init Rx */
25509 + /* Set Vlan */
25510 + ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q);
25511 + if (ret < 0)
25512 + return ret;
25513 +
25514 + /* Enable or disable checksum offload engines */
25515 + ret = smsc95xx_set_features(dev->net, dev->net->features);
25516 + if (ret < 0) {
25517 + netdev_warn(dev->net, "Failed to set checksum offload features\n");
25518 + return ret;
25519 + }
25520 +
25521 + smsc95xx_set_multicast(dev->net);
25522 +
25523 + ret = smsc95xx_phy_initialize(dev);
25524 + if (ret < 0) {
25525 + netdev_warn(dev->net, "Failed to init PHY\n");
25526 + return ret;
25527 + }
25528 +
25529 + ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
25530 + if (ret < 0)
25531 + return ret;
25532 +
25533 + /* enable PHY interrupts */
25534 + read_buf |= INT_EP_CTL_PHY_INT_;
25535 +
25536 + ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf);
25537 + if (ret < 0)
25538 + return ret;
25539 +
25540 + ret = smsc95xx_start_tx_path(dev);
25541 + if (ret < 0) {
25542 + netdev_warn(dev->net, "Failed to start TX path\n");
25543 + return ret;
25544 + }
25545 +
25546 + ret = smsc95xx_start_rx_path(dev, 0);
25547 + if (ret < 0) {
25548 + netdev_warn(dev->net, "Failed to start RX path\n");
25549 + return ret;
25550 + }
25551 +
25552 + netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n");
25553 + return 0;
25554 +}
25555 +
25556 +static const struct net_device_ops smsc95xx_netdev_ops = {
25557 + .ndo_open = usbnet_open,
25558 + .ndo_stop = usbnet_stop,
25559 + .ndo_start_xmit = usbnet_start_xmit,
25560 + .ndo_tx_timeout = usbnet_tx_timeout,
25561 + .ndo_change_mtu = usbnet_change_mtu,
25562 + .ndo_set_mac_address = eth_mac_addr,
25563 + .ndo_validate_addr = eth_validate_addr,
25564 + .ndo_do_ioctl = smsc95xx_ioctl,
25565 + .ndo_set_rx_mode = smsc95xx_set_multicast,
25566 + .ndo_set_features = smsc95xx_set_features,
25567 +};
25568 +
25569 +static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
25570 +{
25571 + struct smsc95xx_priv *pdata = NULL;
25572 + u32 val;
25573 + int ret;
25574 +
25575 + printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
25576 +
25577 + ret = usbnet_get_endpoints(dev, intf);
25578 + if (ret < 0) {
25579 + netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret);
25580 + return ret;
25581 + }
25582 +
25583 + dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv),
25584 + GFP_KERNEL);
25585 +
25586 + pdata = (struct smsc95xx_priv *)(dev->data[0]);
25587 + if (!pdata)
25588 + return -ENOMEM;
25589 +
25590 + spin_lock_init(&pdata->mac_cr_lock);
25591 +
25592 + if (DEFAULT_TX_CSUM_ENABLE)
25593 + dev->net->features |= NETIF_F_HW_CSUM;
25594 + if (DEFAULT_RX_CSUM_ENABLE)
25595 + dev->net->features |= NETIF_F_RXCSUM;
25596 +
25597 + dev->net->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
25598 +
25599 + smsc95xx_init_mac_address(dev);
25600 +
25601 + /* Init all registers */
25602 + ret = smsc95xx_reset(dev);
25603 +
25604 + /* detect device revision as different features may be available */
25605 + ret = smsc95xx_read_reg(dev, ID_REV, &val);
25606 + if (ret < 0)
25607 + return ret;
25608 + val >>= 16;
25609 +
25610 + if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9530_) ||
25611 + (val == ID_REV_CHIP_ID_89530_) || (val == ID_REV_CHIP_ID_9730_))
25612 + pdata->features = (FEATURE_8_WAKEUP_FILTERS |
25613 + FEATURE_PHY_NLP_CROSSOVER |
25614 + FEATURE_REMOTE_WAKEUP);
25615 + else if (val == ID_REV_CHIP_ID_9512_)
25616 + pdata->features = FEATURE_8_WAKEUP_FILTERS;
25617 +
25618 + dev->net->netdev_ops = &smsc95xx_netdev_ops;
25619 + dev->net->ethtool_ops = &smsc95xx_ethtool_ops;
25620 + dev->net->flags |= IFF_MULTICAST;
25621 + dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM;
25622 + dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
25623 + return 0;
25624 +}
25625 +
25626 +static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)
25627 +{
25628 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25629 + if (pdata) {
25630 + netif_dbg(dev, ifdown, dev->net, "free pdata\n");
25631 + kfree(pdata);
25632 + pdata = NULL;
25633 + dev->data[0] = 0;
25634 + }
25635 +}
25636 +
25637 +static u32 smsc_crc(const u8 *buffer, size_t len, int filter)
25638 +{
25639 + u32 crc = bitrev16(crc16(0xFFFF, buffer, len));
25640 + return crc << ((filter % 2) * 16);
25641 +}
25642 +
25643 +static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask)
25644 +{
25645 + struct mii_if_info *mii = &dev->mii;
25646 + int ret;
25647 +
25648 + netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n");
25649 +
25650 + /* read to clear */
25651 + ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC);
25652 + if (ret < 0)
25653 + return ret;
25654 +
25655 + /* enable interrupt source */
25656 + ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK);
25657 + if (ret < 0)
25658 + return ret;
25659 +
25660 + ret |= mask;
25661 +
25662 + smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret);
25663 +
25664 + return 0;
25665 +}
25666 +
25667 +static int smsc95xx_link_ok_nopm(struct usbnet *dev)
25668 +{
25669 + struct mii_if_info *mii = &dev->mii;
25670 + int ret;
25671 +
25672 + /* first, a dummy read, needed to latch some MII phys */
25673 + ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
25674 + if (ret < 0)
25675 + return ret;
25676 +
25677 + ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
25678 + if (ret < 0)
25679 + return ret;
25680 +
25681 + return !!(ret & BMSR_LSTATUS);
25682 +}
25683 +
25684 +static int smsc95xx_enter_suspend0(struct usbnet *dev)
25685 +{
25686 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25687 + u32 val;
25688 + int ret;
25689 +
25690 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
25691 + if (ret < 0)
25692 + return ret;
25693 +
25694 + val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_));
25695 + val |= PM_CTL_SUS_MODE_0;
25696 +
25697 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25698 + if (ret < 0)
25699 + return ret;
25700 +
25701 + /* clear wol status */
25702 + val &= ~PM_CTL_WUPS_;
25703 + val |= PM_CTL_WUPS_WOL_;
25704 +
25705 + /* enable energy detection */
25706 + if (pdata->wolopts & WAKE_PHY)
25707 + val |= PM_CTL_WUPS_ED_;
25708 +
25709 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25710 + if (ret < 0)
25711 + return ret;
25712 +
25713 + /* read back PM_CTRL */
25714 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
25715 + if (ret < 0)
25716 + return ret;
25717 +
25718 + pdata->suspend_flags |= SUSPEND_SUSPEND0;
25719 +
25720 + return 0;
25721 +}
25722 +
25723 +static int smsc95xx_enter_suspend1(struct usbnet *dev)
25724 +{
25725 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25726 + struct mii_if_info *mii = &dev->mii;
25727 + u32 val;
25728 + int ret;
25729 +
25730 + /* reconfigure link pulse detection timing for
25731 + * compatibility with non-standard link partners
25732 + */
25733 + if (pdata->features & FEATURE_PHY_NLP_CROSSOVER)
25734 + smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_EDPD_CONFIG,
25735 + PHY_EDPD_CONFIG_DEFAULT);
25736 +
25737 + /* enable energy detect power-down mode */
25738 + ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS);
25739 + if (ret < 0)
25740 + return ret;
25741 +
25742 + ret |= MODE_CTRL_STS_EDPWRDOWN_;
25743 +
25744 + smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS, ret);
25745 +
25746 + /* enter SUSPEND1 mode */
25747 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
25748 + if (ret < 0)
25749 + return ret;
25750 +
25751 + val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
25752 + val |= PM_CTL_SUS_MODE_1;
25753 +
25754 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25755 + if (ret < 0)
25756 + return ret;
25757 +
25758 + /* clear wol status, enable energy detection */
25759 + val &= ~PM_CTL_WUPS_;
25760 + val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_);
25761 +
25762 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25763 + if (ret < 0)
25764 + return ret;
25765 +
25766 + pdata->suspend_flags |= SUSPEND_SUSPEND1;
25767 +
25768 + return 0;
25769 +}
25770 +
25771 +static int smsc95xx_enter_suspend2(struct usbnet *dev)
25772 +{
25773 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25774 + u32 val;
25775 + int ret;
25776 +
25777 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
25778 + if (ret < 0)
25779 + return ret;
25780 +
25781 + val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
25782 + val |= PM_CTL_SUS_MODE_2;
25783 +
25784 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25785 + if (ret < 0)
25786 + return ret;
25787 +
25788 + pdata->suspend_flags |= SUSPEND_SUSPEND2;
25789 +
25790 + return 0;
25791 +}
25792 +
25793 +static int smsc95xx_enter_suspend3(struct usbnet *dev)
25794 +{
25795 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25796 + u32 val;
25797 + int ret;
25798 +
25799 + ret = smsc95xx_read_reg_nopm(dev, RX_FIFO_INF, &val);
25800 + if (ret < 0)
25801 + return ret;
25802 +
25803 + if (val & 0xFFFF) {
25804 + netdev_info(dev->net, "rx fifo not empty in autosuspend\n");
25805 + return -EBUSY;
25806 + }
25807 +
25808 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
25809 + if (ret < 0)
25810 + return ret;
25811 +
25812 + val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
25813 + val |= PM_CTL_SUS_MODE_3 | PM_CTL_RES_CLR_WKP_STS;
25814 +
25815 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25816 + if (ret < 0)
25817 + return ret;
25818 +
25819 + /* clear wol status */
25820 + val &= ~PM_CTL_WUPS_;
25821 + val |= PM_CTL_WUPS_WOL_;
25822 +
25823 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25824 + if (ret < 0)
25825 + return ret;
25826 +
25827 + pdata->suspend_flags |= SUSPEND_SUSPEND3;
25828 +
25829 + return 0;
25830 +}
25831 +
25832 +static int smsc95xx_autosuspend(struct usbnet *dev, u32 link_up)
25833 +{
25834 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25835 + int ret;
25836 +
25837 + if (!netif_running(dev->net)) {
25838 + /* interface is ifconfig down so fully power down hw */
25839 + netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n");
25840 + return smsc95xx_enter_suspend2(dev);
25841 + }
25842 +
25843 + if (!link_up) {
25844 + /* link is down so enter EDPD mode, but only if device can
25845 + * reliably resume from it. This check should be redundant
25846 + * as current FEATURE_REMOTE_WAKEUP parts also support
25847 + * FEATURE_PHY_NLP_CROSSOVER but it's included for clarity */
25848 + if (!(pdata->features & FEATURE_PHY_NLP_CROSSOVER)) {
25849 + netdev_warn(dev->net, "EDPD not supported\n");
25850 + return -EBUSY;
25851 + }
25852 +
25853 + netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n");
25854 +
25855 + /* enable PHY wakeup events for if cable is attached */
25856 + ret = smsc95xx_enable_phy_wakeup_interrupts(dev,
25857 + PHY_INT_MASK_ANEG_COMP_);
25858 + if (ret < 0) {
25859 + netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
25860 + return ret;
25861 + }
25862 +
25863 + netdev_info(dev->net, "entering SUSPEND1 mode\n");
25864 + return smsc95xx_enter_suspend1(dev);
25865 + }
25866 +
25867 + /* enable PHY wakeup events so we remote wakeup if cable is pulled */
25868 + ret = smsc95xx_enable_phy_wakeup_interrupts(dev,
25869 + PHY_INT_MASK_LINK_DOWN_);
25870 + if (ret < 0) {
25871 + netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
25872 + return ret;
25873 + }
25874 +
25875 + netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n");
25876 + return smsc95xx_enter_suspend3(dev);
25877 +}
25878 +
25879 +static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)
25880 +{
25881 + struct usbnet *dev = usb_get_intfdata(intf);
25882 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25883 + u32 val, link_up;
25884 + int ret;
25885 +
25886 + ret = usbnet_suspend(intf, message);
25887 + if (ret < 0) {
25888 + netdev_warn(dev->net, "usbnet_suspend error\n");
25889 + return ret;
25890 + }
25891 +
25892 + if (pdata->suspend_flags) {
25893 + netdev_warn(dev->net, "error during last resume\n");
25894 + pdata->suspend_flags = 0;
25895 + }
25896 +
25897 + /* determine if link is up using only _nopm functions */
25898 + link_up = smsc95xx_link_ok_nopm(dev);
25899 +
25900 + if (message.event == PM_EVENT_AUTO_SUSPEND &&
25901 + (pdata->features & FEATURE_REMOTE_WAKEUP)) {
25902 + ret = smsc95xx_autosuspend(dev, link_up);
25903 + goto done;
25904 + }
25905 +
25906 + /* if we get this far we're not autosuspending */
25907 + /* if no wol options set, or if link is down and we're not waking on
25908 + * PHY activity, enter lowest power SUSPEND2 mode
25909 + */
25910 + if (!(pdata->wolopts & SUPPORTED_WAKE) ||
25911 + !(link_up || (pdata->wolopts & WAKE_PHY))) {
25912 + netdev_info(dev->net, "entering SUSPEND2 mode\n");
25913 +
25914 + /* disable energy detect (link up) & wake up events */
25915 + ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
25916 + if (ret < 0)
25917 + goto done;
25918 +
25919 + val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_);
25920 +
25921 + ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
25922 + if (ret < 0)
25923 + goto done;
25924 +
25925 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
25926 + if (ret < 0)
25927 + goto done;
25928 +
25929 + val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_);
25930 +
25931 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25932 + if (ret < 0)
25933 + goto done;
25934 +
25935 + ret = smsc95xx_enter_suspend2(dev);
25936 + goto done;
25937 + }
25938 +
25939 + if (pdata->wolopts & WAKE_PHY) {
25940 + ret = smsc95xx_enable_phy_wakeup_interrupts(dev,
25941 + (PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_LINK_DOWN_));
25942 + if (ret < 0) {
25943 + netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
25944 + goto done;
25945 + }
25946 +
25947 + /* if link is down then configure EDPD and enter SUSPEND1,
25948 + * otherwise enter SUSPEND0 below
25949 + */
25950 + if (!link_up) {
25951 + netdev_info(dev->net, "entering SUSPEND1 mode\n");
25952 + ret = smsc95xx_enter_suspend1(dev);
25953 + goto done;
25954 + }
25955 + }
25956 +
25957 + if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
25958 + u32 *filter_mask = kzalloc(sizeof(u32) * 32, GFP_KERNEL);
25959 + u32 command[2];
25960 + u32 offset[2];
25961 + u32 crc[4];
25962 + int wuff_filter_count =
25963 + (pdata->features & FEATURE_8_WAKEUP_FILTERS) ?
25964 + LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM;
25965 + int i, filter = 0;
25966 +
25967 + if (!filter_mask) {
25968 + netdev_warn(dev->net, "Unable to allocate filter_mask\n");
25969 + ret = -ENOMEM;
25970 + goto done;
25971 + }
25972 +
25973 + memset(command, 0, sizeof(command));
25974 + memset(offset, 0, sizeof(offset));
25975 + memset(crc, 0, sizeof(crc));
25976 +
25977 + if (pdata->wolopts & WAKE_BCAST) {
25978 + const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
25979 + netdev_info(dev->net, "enabling broadcast detection\n");
25980 + filter_mask[filter * 4] = 0x003F;
25981 + filter_mask[filter * 4 + 1] = 0x00;
25982 + filter_mask[filter * 4 + 2] = 0x00;
25983 + filter_mask[filter * 4 + 3] = 0x00;
25984 + command[filter/4] |= 0x05UL << ((filter % 4) * 8);
25985 + offset[filter/4] |= 0x00 << ((filter % 4) * 8);
25986 + crc[filter/2] |= smsc_crc(bcast, 6, filter);
25987 + filter++;
25988 + }
25989 +
25990 + if (pdata->wolopts & WAKE_MCAST) {
25991 + const u8 mcast[] = {0x01, 0x00, 0x5E};
25992 + netdev_info(dev->net, "enabling multicast detection\n");
25993 + filter_mask[filter * 4] = 0x0007;
25994 + filter_mask[filter * 4 + 1] = 0x00;
25995 + filter_mask[filter * 4 + 2] = 0x00;
25996 + filter_mask[filter * 4 + 3] = 0x00;
25997 + command[filter/4] |= 0x09UL << ((filter % 4) * 8);
25998 + offset[filter/4] |= 0x00 << ((filter % 4) * 8);
25999 + crc[filter/2] |= smsc_crc(mcast, 3, filter);
26000 + filter++;
26001 + }
26002 +
26003 + if (pdata->wolopts & WAKE_ARP) {
26004 + const u8 arp[] = {0x08, 0x06};
26005 + netdev_info(dev->net, "enabling ARP detection\n");
26006 + filter_mask[filter * 4] = 0x0003;
26007 + filter_mask[filter * 4 + 1] = 0x00;
26008 + filter_mask[filter * 4 + 2] = 0x00;
26009 + filter_mask[filter * 4 + 3] = 0x00;
26010 + command[filter/4] |= 0x05UL << ((filter % 4) * 8);
26011 + offset[filter/4] |= 0x0C << ((filter % 4) * 8);
26012 + crc[filter/2] |= smsc_crc(arp, 2, filter);
26013 + filter++;
26014 + }
26015 +
26016 + if (pdata->wolopts & WAKE_UCAST) {
26017 + netdev_info(dev->net, "enabling unicast detection\n");
26018 + filter_mask[filter * 4] = 0x003F;
26019 + filter_mask[filter * 4 + 1] = 0x00;
26020 + filter_mask[filter * 4 + 2] = 0x00;
26021 + filter_mask[filter * 4 + 3] = 0x00;
26022 + command[filter/4] |= 0x01UL << ((filter % 4) * 8);
26023 + offset[filter/4] |= 0x00 << ((filter % 4) * 8);
26024 + crc[filter/2] |= smsc_crc(dev->net->dev_addr, ETH_ALEN, filter);
26025 + filter++;
26026 + }
26027 +
26028 + for (i = 0; i < (wuff_filter_count * 4); i++) {
26029 + ret = smsc95xx_write_reg_nopm(dev, WUFF, filter_mask[i]);
26030 + if (ret < 0) {
26031 + kfree(filter_mask);
26032 + goto done;
26033 + }
26034 + }
26035 + kfree(filter_mask);
26036 +
26037 + for (i = 0; i < (wuff_filter_count / 4); i++) {
26038 + ret = smsc95xx_write_reg_nopm(dev, WUFF, command[i]);
26039 + if (ret < 0)
26040 + goto done;
26041 + }
26042 +
26043 + for (i = 0; i < (wuff_filter_count / 4); i++) {
26044 + ret = smsc95xx_write_reg_nopm(dev, WUFF, offset[i]);
26045 + if (ret < 0)
26046 + goto done;
26047 + }
26048 +
26049 + for (i = 0; i < (wuff_filter_count / 2); i++) {
26050 + ret = smsc95xx_write_reg_nopm(dev, WUFF, crc[i]);
26051 + if (ret < 0)
26052 + goto done;
26053 + }
26054 +
26055 + /* clear any pending pattern match packet status */
26056 + ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
26057 + if (ret < 0)
26058 + goto done;
26059 +
26060 + val |= WUCSR_WUFR_;
26061 +
26062 + ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
26063 + if (ret < 0)
26064 + goto done;
26065 + }
26066 +
26067 + if (pdata->wolopts & WAKE_MAGIC) {
26068 + /* clear any pending magic packet status */
26069 + ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
26070 + if (ret < 0)
26071 + goto done;
26072 +
26073 + val |= WUCSR_MPR_;
26074 +
26075 + ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
26076 + if (ret < 0)
26077 + goto done;
26078 + }
26079 +
26080 + /* enable/disable wakeup sources */
26081 + ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
26082 + if (ret < 0)
26083 + goto done;
26084 +
26085 + if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
26086 + netdev_info(dev->net, "enabling pattern match wakeup\n");
26087 + val |= WUCSR_WAKE_EN_;
26088 + } else {
26089 + netdev_info(dev->net, "disabling pattern match wakeup\n");
26090 + val &= ~WUCSR_WAKE_EN_;
26091 + }
26092 +
26093 + if (pdata->wolopts & WAKE_MAGIC) {
26094 + netdev_info(dev->net, "enabling magic packet wakeup\n");
26095 + val |= WUCSR_MPEN_;
26096 + } else {
26097 + netdev_info(dev->net, "disabling magic packet wakeup\n");
26098 + val &= ~WUCSR_MPEN_;
26099 + }
26100 +
26101 + ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
26102 + if (ret < 0)
26103 + goto done;
26104 +
26105 + /* enable wol wakeup source */
26106 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
26107 + if (ret < 0)
26108 + goto done;
26109 +
26110 + val |= PM_CTL_WOL_EN_;
26111 +
26112 + /* phy energy detect wakeup source */
26113 + if (pdata->wolopts & WAKE_PHY)
26114 + val |= PM_CTL_ED_EN_;
26115 +
26116 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
26117 + if (ret < 0)
26118 + goto done;
26119 +
26120 + /* enable receiver to enable frame reception */
26121 + smsc95xx_start_rx_path(dev, 1);
26122 +
26123 + /* some wol options are enabled, so enter SUSPEND0 */
26124 + netdev_info(dev->net, "entering SUSPEND0 mode\n");
26125 + ret = smsc95xx_enter_suspend0(dev);
26126 +
26127 +done:
26128 + /*
26129 + * TODO: resume() might need to handle the suspend failure
26130 + * in system sleep
26131 + */
26132 + if (ret && PMSG_IS_AUTO(message))
26133 + usbnet_resume(intf);
26134 + return ret;
26135 +}
26136 +
26137 +static int smsc95xx_resume(struct usb_interface *intf)
26138 +{
26139 + struct usbnet *dev = usb_get_intfdata(intf);
26140 + struct smsc95xx_priv *pdata;
26141 + u8 suspend_flags;
26142 + int ret;
26143 + u32 val;
26144 +
26145 + BUG_ON(!dev);
26146 + pdata = (struct smsc95xx_priv *)(dev->data[0]);
26147 + suspend_flags = pdata->suspend_flags;
26148 +
26149 + netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags);
26150 +
26151 + /* do this first to ensure it's cleared even in error case */
26152 + pdata->suspend_flags = 0;
26153 +
26154 + if (suspend_flags & SUSPEND_ALLMODES) {
26155 + /* clear wake-up sources */
26156 + ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
26157 + if (ret < 0)
26158 + return ret;
26159 +
26160 + val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_);
26161 +
26162 + ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
26163 + if (ret < 0)
26164 + return ret;
26165 +
26166 + /* clear wake-up status */
26167 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
26168 + if (ret < 0)
26169 + return ret;
26170 +
26171 + val &= ~PM_CTL_WOL_EN_;
26172 + val |= PM_CTL_WUPS_;
26173 +
26174 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
26175 + if (ret < 0)
26176 + return ret;
26177 + }
26178 +
26179 + ret = usbnet_resume(intf);
26180 + if (ret < 0)
26181 + netdev_warn(dev->net, "usbnet_resume error\n");
26182 +
26183 + return ret;
26184 +}
26185 +
26186 +static int smsc95xx_reset_resume(struct usb_interface *intf)
26187 +{
26188 + struct usbnet *dev = usb_get_intfdata(intf);
26189 + int ret;
26190 +
26191 + ret = smsc95xx_reset(dev);
26192 + if (ret < 0)
26193 + return ret;
26194 +
26195 + return smsc95xx_resume(intf);
26196 +}
26197 +
26198 +static void smsc95xx_rx_csum_offload(struct sk_buff *skb)
26199 +{
26200 + skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2);
26201 + skb->ip_summed = CHECKSUM_COMPLETE;
26202 + skb_trim(skb, skb->len - 2);
26203 +}
26204 +
26205 +static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
26206 +{
26207 + /* This check is no longer done by usbnet */
26208 + if (skb->len < dev->net->hard_header_len)
26209 + return 0;
26210 +
26211 + while (skb->len > 0) {
26212 + u32 header, align_count;
26213 + struct sk_buff *ax_skb;
26214 + unsigned char *packet;
26215 + u16 size;
26216 +
26217 + memcpy(&header, skb->data, sizeof(header));
26218 + le32_to_cpus(&header);
26219 + skb_pull(skb, 4 + NET_IP_ALIGN);
26220 + packet = skb->data;
26221 +
26222 + /* get the packet length */
26223 + size = (u16)((header & RX_STS_FL_) >> 16);
26224 + align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4;
26225 +
26226 + if (unlikely(header & RX_STS_ES_)) {
26227 + netif_dbg(dev, rx_err, dev->net,
26228 + "Error header=0x%08x\n", header);
26229 + dev->net->stats.rx_errors++;
26230 + dev->net->stats.rx_dropped++;
26231 +
26232 + if (header & RX_STS_CRC_) {
26233 + dev->net->stats.rx_crc_errors++;
26234 + } else {
26235 + if (header & (RX_STS_TL_ | RX_STS_RF_))
26236 + dev->net->stats.rx_frame_errors++;
26237 +
26238 + if ((header & RX_STS_LE_) &&
26239 + (!(header & RX_STS_FT_)))
26240 + dev->net->stats.rx_length_errors++;
26241 + }
26242 + } else {
26243 + /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */
26244 + if (unlikely(size > (ETH_FRAME_LEN + 12))) {
26245 + netif_dbg(dev, rx_err, dev->net,
26246 + "size err header=0x%08x\n", header);
26247 + return 0;
26248 + }
26249 +
26250 + /* last frame in this batch */
26251 + if (skb->len == size) {
26252 + if (dev->net->features & NETIF_F_RXCSUM)
26253 + smsc95xx_rx_csum_offload(skb);
26254 + skb_trim(skb, skb->len - 4); /* remove fcs */
26255 + skb->truesize = size + sizeof(struct sk_buff);
26256 +
26257 + return 1;
26258 + }
26259 +
26260 + ax_skb = skb_clone(skb, GFP_ATOMIC);
26261 + if (unlikely(!ax_skb)) {
26262 + netdev_warn(dev->net, "Error allocating skb\n");
26263 + return 0;
26264 + }
26265 +
26266 + ax_skb->len = size;
26267 + ax_skb->data = packet;
26268 + skb_set_tail_pointer(ax_skb, size);
26269 +
26270 + if (dev->net->features & NETIF_F_RXCSUM)
26271 + smsc95xx_rx_csum_offload(ax_skb);
26272 + skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
26273 + ax_skb->truesize = size + sizeof(struct sk_buff);
26274 +
26275 + usbnet_skb_return(dev, ax_skb);
26276 + }
26277 +
26278 + skb_pull(skb, size);
26279 +
26280 + /* padding bytes before the next frame starts */
26281 + if (skb->len)
26282 + skb_pull(skb, align_count);
26283 + }
26284 +
26285 + if (unlikely(skb->len < 0)) {
26286 + netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len);
26287 + return 0;
26288 + }
26289 +
26290 + return 1;
26291 +}
26292 +
26293 +static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb)
26294 +{
26295 + u16 low_16 = (u16)skb_checksum_start_offset(skb);
26296 + u16 high_16 = low_16 + skb->csum_offset;
26297 + return (high_16 << 16) | low_16;
26298 +}
26299 +
26300 +static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev,
26301 + struct sk_buff *skb, gfp_t flags)
26302 +{
26303 + bool csum = skb->ip_summed == CHECKSUM_PARTIAL;
26304 + int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD;
26305 + u32 tx_cmd_a, tx_cmd_b;
26306 +
26307 + /* We do not advertise SG, so skbs should be already linearized */
26308 + BUG_ON(skb_shinfo(skb)->nr_frags);
26309 +
26310 + if (skb_headroom(skb) < overhead) {
26311 + struct sk_buff *skb2 = skb_copy_expand(skb,
26312 + overhead, 0, flags);
26313 + dev_kfree_skb_any(skb);
26314 + skb = skb2;
26315 + if (!skb)
26316 + return NULL;
26317 + }
26318 +
26319 + if (csum) {
26320 + if (skb->len <= 45) {
26321 + /* workaround - hardware tx checksum does not work
26322 + * properly with extremely small packets */
26323 + long csstart = skb_checksum_start_offset(skb);
26324 + __wsum calc = csum_partial(skb->data + csstart,
26325 + skb->len - csstart, 0);
26326 + *((__sum16 *)(skb->data + csstart
26327 + + skb->csum_offset)) = csum_fold(calc);
26328 +
26329 + csum = false;
26330 + } else {
26331 + u32 csum_preamble = smsc95xx_calc_csum_preamble(skb);
26332 + skb_push(skb, 4);
26333 + cpu_to_le32s(&csum_preamble);
26334 + memcpy(skb->data, &csum_preamble, 4);
26335 + }
26336 + }
26337 +
26338 + skb_push(skb, 4);
26339 + tx_cmd_b = (u32)(skb->len - 4);
26340 + if (csum)
26341 + tx_cmd_b |= TX_CMD_B_CSUM_ENABLE;
26342 + cpu_to_le32s(&tx_cmd_b);
26343 + memcpy(skb->data, &tx_cmd_b, 4);
26344 +
26345 + skb_push(skb, 4);
26346 + tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ |
26347 + TX_CMD_A_LAST_SEG_;
26348 + cpu_to_le32s(&tx_cmd_a);
26349 + memcpy(skb->data, &tx_cmd_a, 4);
26350 +
26351 + return skb;
26352 +}
26353 +
26354 +static int smsc95xx_manage_power(struct usbnet *dev, int on)
26355 +{
26356 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
26357 +
26358 + dev->intf->needs_remote_wakeup = on;
26359 +
26360 + if (pdata->features & FEATURE_REMOTE_WAKEUP)
26361 + return 0;
26362 +
26363 + /* this chip revision isn't capable of remote wakeup */
26364 + netdev_info(dev->net, "hardware isn't capable of remote wakeup\n");
26365 +
26366 + if (on)
26367 + usb_autopm_get_interface_no_resume(dev->intf);
26368 + else
26369 + usb_autopm_put_interface(dev->intf);
26370 +
26371 + return 0;
26372 +}
26373 +
26374 +static const struct driver_info smsc95xx_info = {
26375 + .description = "smsc95xx USB 2.0 Ethernet",
26376 + .bind = smsc95xx_bind,
26377 + .unbind = smsc95xx_unbind,
26378 + .link_reset = smsc95xx_link_reset,
26379 + .reset = smsc95xx_reset,
26380 + .rx_fixup = smsc95xx_rx_fixup,
26381 + .tx_fixup = smsc95xx_tx_fixup,
26382 + .status = smsc95xx_status,
26383 + .manage_power = smsc95xx_manage_power,
26384 + .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
26385 +};
26386 +
26387 +static const struct usb_device_id products[] = {
26388 + {
26389 + /* SMSC9500 USB Ethernet Device */
26390 + USB_DEVICE(0x0424, 0x9500),
26391 + .driver_info = (unsigned long) &smsc95xx_info,
26392 + },
26393 + {
26394 + /* SMSC9505 USB Ethernet Device */
26395 + USB_DEVICE(0x0424, 0x9505),
26396 + .driver_info = (unsigned long) &smsc95xx_info,
26397 + },
26398 + {
26399 + /* SMSC9500A USB Ethernet Device */
26400 + USB_DEVICE(0x0424, 0x9E00),
26401 + .driver_info = (unsigned long) &smsc95xx_info,
26402 + },
26403 + {
26404 + /* SMSC9505A USB Ethernet Device */
26405 + USB_DEVICE(0x0424, 0x9E01),
26406 + .driver_info = (unsigned long) &smsc95xx_info,
26407 + },
26408 + {
26409 + /* SMSC9512/9514 USB Hub & Ethernet Device */
26410 + USB_DEVICE(0x0424, 0xec00),
26411 + .driver_info = (unsigned long) &smsc95xx_info,
26412 + },
26413 + {
26414 + /* SMSC9500 USB Ethernet Device (SAL10) */
26415 + USB_DEVICE(0x0424, 0x9900),
26416 + .driver_info = (unsigned long) &smsc95xx_info,
26417 + },
26418 + {
26419 + /* SMSC9505 USB Ethernet Device (SAL10) */
26420 + USB_DEVICE(0x0424, 0x9901),
26421 + .driver_info = (unsigned long) &smsc95xx_info,
26422 + },
26423 + {
26424 + /* SMSC9500A USB Ethernet Device (SAL10) */
26425 + USB_DEVICE(0x0424, 0x9902),
26426 + .driver_info = (unsigned long) &smsc95xx_info,
26427 + },
26428 + {
26429 + /* SMSC9505A USB Ethernet Device (SAL10) */
26430 + USB_DEVICE(0x0424, 0x9903),
26431 + .driver_info = (unsigned long) &smsc95xx_info,
26432 + },
26433 + {
26434 + /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */
26435 + USB_DEVICE(0x0424, 0x9904),
26436 + .driver_info = (unsigned long) &smsc95xx_info,
26437 + },
26438 + {
26439 + /* SMSC9500A USB Ethernet Device (HAL) */
26440 + USB_DEVICE(0x0424, 0x9905),
26441 + .driver_info = (unsigned long) &smsc95xx_info,
26442 + },
26443 + {
26444 + /* SMSC9505A USB Ethernet Device (HAL) */
26445 + USB_DEVICE(0x0424, 0x9906),
26446 + .driver_info = (unsigned long) &smsc95xx_info,
26447 + },
26448 + {
26449 + /* SMSC9500 USB Ethernet Device (Alternate ID) */
26450 + USB_DEVICE(0x0424, 0x9907),
26451 + .driver_info = (unsigned long) &smsc95xx_info,
26452 + },
26453 + {
26454 + /* SMSC9500A USB Ethernet Device (Alternate ID) */
26455 + USB_DEVICE(0x0424, 0x9908),
26456 + .driver_info = (unsigned long) &smsc95xx_info,
26457 + },
26458 + {
26459 + /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */
26460 + USB_DEVICE(0x0424, 0x9909),
26461 + .driver_info = (unsigned long) &smsc95xx_info,
26462 + },
26463 + {
26464 + /* SMSC LAN9530 USB Ethernet Device */
26465 + USB_DEVICE(0x0424, 0x9530),
26466 + .driver_info = (unsigned long) &smsc95xx_info,
26467 + },
26468 + {
26469 + /* SMSC LAN9730 USB Ethernet Device */
26470 + USB_DEVICE(0x0424, 0x9730),
26471 + .driver_info = (unsigned long) &smsc95xx_info,
26472 + },
26473 + {
26474 + /* SMSC LAN89530 USB Ethernet Device */
26475 + USB_DEVICE(0x0424, 0x9E08),
26476 + .driver_info = (unsigned long) &smsc95xx_info,
26477 + },
26478 + { }, /* END */
26479 +};
26480 +MODULE_DEVICE_TABLE(usb, products);
26481 +
26482 +static struct usb_driver smsc95xx_driver = {
26483 + .name = "smsc95xx",
26484 + .id_table = products,
26485 + .probe = usbnet_probe,
26486 + .suspend = smsc95xx_suspend,
26487 + .resume = smsc95xx_resume,
26488 + .reset_resume = smsc95xx_reset_resume,
26489 + .disconnect = usbnet_disconnect,
26490 + .disable_hub_initiated_lpm = 1,
26491 + .supports_autosuspend = 1,
26492 +};
26493 +
26494 +module_usb_driver(smsc95xx_driver);
26495 +
26496 +MODULE_AUTHOR("Nancy Lin");
26497 +MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
26498 +MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices");
26499 +MODULE_LICENSE("GPL");
26500 diff -Naur backports-4.2.6-1.org/drivers/net/usb/smsc95xx.h backports-4.2.6-1/drivers/net/usb/smsc95xx.h
26501 --- backports-4.2.6-1.org/drivers/net/usb/smsc95xx.h 1970-01-01 01:00:00.000000000 +0100
26502 +++ backports-4.2.6-1/drivers/net/usb/smsc95xx.h 2016-06-28 14:35:18.011973884 +0200
26503 @@ -0,0 +1,290 @@
26504 + /***************************************************************************
26505 + *
26506 + * Copyright (C) 2007-2008 SMSC
26507 + *
26508 + * This program is free software; you can redistribute it and/or
26509 + * modify it under the terms of the GNU General Public License
26510 + * as published by the Free Software Foundation; either version 2
26511 + * of the License, or (at your option) any later version.
26512 + *
26513 + * This program is distributed in the hope that it will be useful,
26514 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26515 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26516 + * GNU General Public License for more details.
26517 + *
26518 + * You should have received a copy of the GNU General Public License
26519 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
26520 + *
26521 + *****************************************************************************/
26522 +
26523 +#ifndef _SMSC95XX_H
26524 +#define _SMSC95XX_H
26525 +
26526 +/* Tx command words */
26527 +#define TX_CMD_A_DATA_OFFSET_ (0x001F0000)
26528 +#define TX_CMD_A_FIRST_SEG_ (0x00002000)
26529 +#define TX_CMD_A_LAST_SEG_ (0x00001000)
26530 +#define TX_CMD_A_BUF_SIZE_ (0x000007FF)
26531 +
26532 +#define TX_CMD_B_CSUM_ENABLE (0x00004000)
26533 +#define TX_CMD_B_ADD_CRC_DISABLE_ (0x00002000)
26534 +#define TX_CMD_B_DISABLE_PADDING_ (0x00001000)
26535 +#define TX_CMD_B_PKT_BYTE_LENGTH_ (0x000007FF)
26536 +
26537 +/* Rx status word */
26538 +#define RX_STS_FF_ (0x40000000) /* Filter Fail */
26539 +#define RX_STS_FL_ (0x3FFF0000) /* Frame Length */
26540 +#define RX_STS_ES_ (0x00008000) /* Error Summary */
26541 +#define RX_STS_BF_ (0x00002000) /* Broadcast Frame */
26542 +#define RX_STS_LE_ (0x00001000) /* Length Error */
26543 +#define RX_STS_RF_ (0x00000800) /* Runt Frame */
26544 +#define RX_STS_MF_ (0x00000400) /* Multicast Frame */
26545 +#define RX_STS_TL_ (0x00000080) /* Frame too long */
26546 +#define RX_STS_CS_ (0x00000040) /* Collision Seen */
26547 +#define RX_STS_FT_ (0x00000020) /* Frame Type */
26548 +#define RX_STS_RW_ (0x00000010) /* Receive Watchdog */
26549 +#define RX_STS_ME_ (0x00000008) /* Mii Error */
26550 +#define RX_STS_DB_ (0x00000004) /* Dribbling */
26551 +#define RX_STS_CRC_ (0x00000002) /* CRC Error */
26552 +
26553 +/* SCSRs */
26554 +#define ID_REV (0x00)
26555 +#define ID_REV_CHIP_ID_MASK_ (0xFFFF0000)
26556 +#define ID_REV_CHIP_REV_MASK_ (0x0000FFFF)
26557 +#define ID_REV_CHIP_ID_9500_ (0x9500)
26558 +#define ID_REV_CHIP_ID_9500A_ (0x9E00)
26559 +#define ID_REV_CHIP_ID_9512_ (0xEC00)
26560 +#define ID_REV_CHIP_ID_9530_ (0x9530)
26561 +#define ID_REV_CHIP_ID_89530_ (0x9E08)
26562 +#define ID_REV_CHIP_ID_9730_ (0x9730)
26563 +
26564 +#define INT_STS (0x08)
26565 +#define INT_STS_TX_STOP_ (0x00020000)
26566 +#define INT_STS_RX_STOP_ (0x00010000)
26567 +#define INT_STS_PHY_INT_ (0x00008000)
26568 +#define INT_STS_TXE_ (0x00004000)
26569 +#define INT_STS_TDFU_ (0x00002000)
26570 +#define INT_STS_TDFO_ (0x00001000)
26571 +#define INT_STS_RXDF_ (0x00000800)
26572 +#define INT_STS_GPIOS_ (0x000007FF)
26573 +#define INT_STS_CLEAR_ALL_ (0xFFFFFFFF)
26574 +
26575 +#define RX_CFG (0x0C)
26576 +#define RX_FIFO_FLUSH_ (0x00000001)
26577 +
26578 +#define TX_CFG (0x10)
26579 +#define TX_CFG_ON_ (0x00000004)
26580 +#define TX_CFG_STOP_ (0x00000002)
26581 +#define TX_CFG_FIFO_FLUSH_ (0x00000001)
26582 +
26583 +#define HW_CFG (0x14)
26584 +#define HW_CFG_BIR_ (0x00001000)
26585 +#define HW_CFG_LEDB_ (0x00000800)
26586 +#define HW_CFG_RXDOFF_ (0x00000600)
26587 +#define HW_CFG_DRP_ (0x00000040)
26588 +#define HW_CFG_MEF_ (0x00000020)
26589 +#define HW_CFG_LRST_ (0x00000008)
26590 +#define HW_CFG_PSEL_ (0x00000004)
26591 +#define HW_CFG_BCE_ (0x00000002)
26592 +#define HW_CFG_SRST_ (0x00000001)
26593 +
26594 +#define RX_FIFO_INF (0x18)
26595 +
26596 +#define PM_CTRL (0x20)
26597 +#define PM_CTL_RES_CLR_WKP_STS (0x00000200)
26598 +#define PM_CTL_DEV_RDY_ (0x00000080)
26599 +#define PM_CTL_SUS_MODE_ (0x00000060)
26600 +#define PM_CTL_SUS_MODE_0 (0x00000000)
26601 +#define PM_CTL_SUS_MODE_1 (0x00000020)
26602 +#define PM_CTL_SUS_MODE_2 (0x00000040)
26603 +#define PM_CTL_SUS_MODE_3 (0x00000060)
26604 +#define PM_CTL_PHY_RST_ (0x00000010)
26605 +#define PM_CTL_WOL_EN_ (0x00000008)
26606 +#define PM_CTL_ED_EN_ (0x00000004)
26607 +#define PM_CTL_WUPS_ (0x00000003)
26608 +#define PM_CTL_WUPS_NO_ (0x00000000)
26609 +#define PM_CTL_WUPS_ED_ (0x00000001)
26610 +#define PM_CTL_WUPS_WOL_ (0x00000002)
26611 +#define PM_CTL_WUPS_MULTI_ (0x00000003)
26612 +
26613 +#define LED_GPIO_CFG (0x24)
26614 +#define LED_GPIO_CFG_SPD_LED (0x01000000)
26615 +#define LED_GPIO_CFG_LNK_LED (0x00100000)
26616 +#define LED_GPIO_CFG_FDX_LED (0x00010000)
26617 +
26618 +#define GPIO_CFG (0x28)
26619 +
26620 +#define AFC_CFG (0x2C)
26621 +
26622 +/* Hi watermark = 15.5Kb (~10 mtu pkts) */
26623 +/* low watermark = 3k (~2 mtu pkts) */
26624 +/* backpressure duration = ~ 350us */
26625 +/* Apply FC on any frame. */
26626 +#define AFC_CFG_DEFAULT (0x00F830A1)
26627 +
26628 +#define E2P_CMD (0x30)
26629 +#define E2P_CMD_BUSY_ (0x80000000)
26630 +#define E2P_CMD_MASK_ (0x70000000)
26631 +#define E2P_CMD_READ_ (0x00000000)
26632 +#define E2P_CMD_EWDS_ (0x10000000)
26633 +#define E2P_CMD_EWEN_ (0x20000000)
26634 +#define E2P_CMD_WRITE_ (0x30000000)
26635 +#define E2P_CMD_WRAL_ (0x40000000)
26636 +#define E2P_CMD_ERASE_ (0x50000000)
26637 +#define E2P_CMD_ERAL_ (0x60000000)
26638 +#define E2P_CMD_RELOAD_ (0x70000000)
26639 +#define E2P_CMD_TIMEOUT_ (0x00000400)
26640 +#define E2P_CMD_LOADED_ (0x00000200)
26641 +#define E2P_CMD_ADDR_ (0x000001FF)
26642 +
26643 +#define MAX_EEPROM_SIZE (512)
26644 +
26645 +#define E2P_DATA (0x34)
26646 +#define E2P_DATA_MASK_ (0x000000FF)
26647 +
26648 +#define BURST_CAP (0x38)
26649 +
26650 +#define GPIO_WAKE (0x64)
26651 +
26652 +#define INT_EP_CTL (0x68)
26653 +#define INT_EP_CTL_INTEP_ (0x80000000)
26654 +#define INT_EP_CTL_MACRTO_ (0x00080000)
26655 +#define INT_EP_CTL_TX_STOP_ (0x00020000)
26656 +#define INT_EP_CTL_RX_STOP_ (0x00010000)
26657 +#define INT_EP_CTL_PHY_INT_ (0x00008000)
26658 +#define INT_EP_CTL_TXE_ (0x00004000)
26659 +#define INT_EP_CTL_TDFU_ (0x00002000)
26660 +#define INT_EP_CTL_TDFO_ (0x00001000)
26661 +#define INT_EP_CTL_RXDF_ (0x00000800)
26662 +#define INT_EP_CTL_GPIOS_ (0x000007FF)
26663 +
26664 +#define BULK_IN_DLY (0x6C)
26665 +
26666 +/* MAC CSRs */
26667 +#define MAC_CR (0x100)
26668 +#define MAC_CR_RXALL_ (0x80000000)
26669 +#define MAC_CR_RCVOWN_ (0x00800000)
26670 +#define MAC_CR_LOOPBK_ (0x00200000)
26671 +#define MAC_CR_FDPX_ (0x00100000)
26672 +#define MAC_CR_MCPAS_ (0x00080000)
26673 +#define MAC_CR_PRMS_ (0x00040000)
26674 +#define MAC_CR_INVFILT_ (0x00020000)
26675 +#define MAC_CR_PASSBAD_ (0x00010000)
26676 +#define MAC_CR_HFILT_ (0x00008000)
26677 +#define MAC_CR_HPFILT_ (0x00002000)
26678 +#define MAC_CR_LCOLL_ (0x00001000)
26679 +#define MAC_CR_BCAST_ (0x00000800)
26680 +#define MAC_CR_DISRTY_ (0x00000400)
26681 +#define MAC_CR_PADSTR_ (0x00000100)
26682 +#define MAC_CR_BOLMT_MASK (0x000000C0)
26683 +#define MAC_CR_DFCHK_ (0x00000020)
26684 +#define MAC_CR_TXEN_ (0x00000008)
26685 +#define MAC_CR_RXEN_ (0x00000004)
26686 +
26687 +#define ADDRH (0x104)
26688 +
26689 +#define ADDRL (0x108)
26690 +
26691 +#define HASHH (0x10C)
26692 +
26693 +#define HASHL (0x110)
26694 +
26695 +#define MII_ADDR (0x114)
26696 +#define MII_WRITE_ (0x02)
26697 +#define MII_BUSY_ (0x01)
26698 +#define MII_READ_ (0x00) /* ~of MII Write bit */
26699 +
26700 +#define MII_DATA (0x118)
26701 +
26702 +#define FLOW (0x11C)
26703 +#define FLOW_FCPT_ (0xFFFF0000)
26704 +#define FLOW_FCPASS_ (0x00000004)
26705 +#define FLOW_FCEN_ (0x00000002)
26706 +#define FLOW_FCBSY_ (0x00000001)
26707 +
26708 +#define VLAN1 (0x120)
26709 +
26710 +#define VLAN2 (0x124)
26711 +
26712 +#define WUFF (0x128)
26713 +#define LAN9500_WUFF_NUM (4)
26714 +#define LAN9500A_WUFF_NUM (8)
26715 +
26716 +#define WUCSR (0x12C)
26717 +#define WUCSR_WFF_PTR_RST_ (0x80000000)
26718 +#define WUCSR_GUE_ (0x00000200)
26719 +#define WUCSR_WUFR_ (0x00000040)
26720 +#define WUCSR_MPR_ (0x00000020)
26721 +#define WUCSR_WAKE_EN_ (0x00000004)
26722 +#define WUCSR_MPEN_ (0x00000002)
26723 +
26724 +#define COE_CR (0x130)
26725 +#define Tx_COE_EN_ (0x00010000)
26726 +#define Rx_COE_MODE_ (0x00000002)
26727 +#define Rx_COE_EN_ (0x00000001)
26728 +
26729 +/* Vendor-specific PHY Definitions */
26730 +
26731 +/* EDPD NLP / crossover time configuration (LAN9500A only) */
26732 +#define PHY_EDPD_CONFIG (16)
26733 +#define PHY_EDPD_CONFIG_TX_NLP_EN_ ((u16)0x8000)
26734 +#define PHY_EDPD_CONFIG_TX_NLP_1000_ ((u16)0x0000)
26735 +#define PHY_EDPD_CONFIG_TX_NLP_768_ ((u16)0x2000)
26736 +#define PHY_EDPD_CONFIG_TX_NLP_512_ ((u16)0x4000)
26737 +#define PHY_EDPD_CONFIG_TX_NLP_256_ ((u16)0x6000)
26738 +#define PHY_EDPD_CONFIG_RX_1_NLP_ ((u16)0x1000)
26739 +#define PHY_EDPD_CONFIG_RX_NLP_64_ ((u16)0x0000)
26740 +#define PHY_EDPD_CONFIG_RX_NLP_256_ ((u16)0x0400)
26741 +#define PHY_EDPD_CONFIG_RX_NLP_512_ ((u16)0x0800)
26742 +#define PHY_EDPD_CONFIG_RX_NLP_1000_ ((u16)0x0C00)
26743 +#define PHY_EDPD_CONFIG_EXT_CROSSOVER_ ((u16)0x0001)
26744 +#define PHY_EDPD_CONFIG_DEFAULT (PHY_EDPD_CONFIG_TX_NLP_EN_ | \
26745 + PHY_EDPD_CONFIG_TX_NLP_768_ | \
26746 + PHY_EDPD_CONFIG_RX_1_NLP_)
26747 +
26748 +/* Mode Control/Status Register */
26749 +#define PHY_MODE_CTRL_STS (17)
26750 +#define MODE_CTRL_STS_EDPWRDOWN_ ((u16)0x2000)
26751 +#define MODE_CTRL_STS_ENERGYON_ ((u16)0x0002)
26752 +
26753 +#define SPECIAL_CTRL_STS (27)
26754 +#define SPECIAL_CTRL_STS_OVRRD_AMDIX_ ((u16)0x8000)
26755 +#define SPECIAL_CTRL_STS_AMDIX_ENABLE_ ((u16)0x4000)
26756 +#define SPECIAL_CTRL_STS_AMDIX_STATE_ ((u16)0x2000)
26757 +
26758 +#define PHY_INT_SRC (29)
26759 +#define PHY_INT_SRC_ENERGY_ON_ ((u16)0x0080)
26760 +#define PHY_INT_SRC_ANEG_COMP_ ((u16)0x0040)
26761 +#define PHY_INT_SRC_REMOTE_FAULT_ ((u16)0x0020)
26762 +#define PHY_INT_SRC_LINK_DOWN_ ((u16)0x0010)
26763 +
26764 +#define PHY_INT_MASK (30)
26765 +#define PHY_INT_MASK_ENERGY_ON_ ((u16)0x0080)
26766 +#define PHY_INT_MASK_ANEG_COMP_ ((u16)0x0040)
26767 +#define PHY_INT_MASK_REMOTE_FAULT_ ((u16)0x0020)
26768 +#define PHY_INT_MASK_LINK_DOWN_ ((u16)0x0010)
26769 +#define PHY_INT_MASK_DEFAULT_ (PHY_INT_MASK_ANEG_COMP_ | \
26770 + PHY_INT_MASK_LINK_DOWN_)
26771 +
26772 +#define PHY_SPECIAL (31)
26773 +#define PHY_SPECIAL_SPD_ ((u16)0x001C)
26774 +#define PHY_SPECIAL_SPD_10HALF_ ((u16)0x0004)
26775 +#define PHY_SPECIAL_SPD_10FULL_ ((u16)0x0014)
26776 +#define PHY_SPECIAL_SPD_100HALF_ ((u16)0x0008)
26777 +#define PHY_SPECIAL_SPD_100FULL_ ((u16)0x0018)
26778 +
26779 +/* USB Vendor Requests */
26780 +#define USB_VENDOR_REQUEST_WRITE_REGISTER 0xA0
26781 +#define USB_VENDOR_REQUEST_READ_REGISTER 0xA1
26782 +#define USB_VENDOR_REQUEST_GET_STATS 0xA2
26783 +
26784 +/* Interrupt Endpoint status word bitfields */
26785 +#define INT_ENP_TX_STOP_ ((u32)BIT(17))
26786 +#define INT_ENP_RX_STOP_ ((u32)BIT(16))
26787 +#define INT_ENP_PHY_INT_ ((u32)BIT(15))
26788 +#define INT_ENP_TXE_ ((u32)BIT(14))
26789 +#define INT_ENP_TDFU_ ((u32)BIT(13))
26790 +#define INT_ENP_TDFO_ ((u32)BIT(12))
26791 +#define INT_ENP_RXDF_ ((u32)BIT(11))
26792 +
26793 +#endif /* _SMSC95XX_H */
26794 diff -Naur backports-4.2.6-1.org/drivers/net/usb/sr9700.c backports-4.2.6-1/drivers/net/usb/sr9700.c
26795 --- backports-4.2.6-1.org/drivers/net/usb/sr9700.c 1970-01-01 01:00:00.000000000 +0100
26796 +++ backports-4.2.6-1/drivers/net/usb/sr9700.c 2016-06-28 14:35:18.011973884 +0200
26797 @@ -0,0 +1,559 @@
26798 +/*
26799 + * CoreChip-sz SR9700 one chip USB 1.1 Ethernet Devices
26800 + *
26801 + * Author : Liu Junliang <liujunliang_ljl@163.com>
26802 + *
26803 + * Based on dm9601.c
26804 + *
26805 + * This file is licensed under the terms of the GNU General Public License
26806 + * version 2. This program is licensed "as is" without any warranty of any
26807 + * kind, whether express or implied.
26808 + */
26809 +
26810 +#include <linux/module.h>
26811 +#include <linux/sched.h>
26812 +#include <linux/stddef.h>
26813 +#include <linux/netdevice.h>
26814 +#include <linux/etherdevice.h>
26815 +#include <linux/ethtool.h>
26816 +#include <linux/mii.h>
26817 +#include <linux/usb.h>
26818 +#include <linux/crc32.h>
26819 +#include <linux/usb/usbnet.h>
26820 +
26821 +#include "sr9700.h"
26822 +
26823 +static int sr_read(struct usbnet *dev, u8 reg, u16 length, void *data)
26824 +{
26825 + int err;
26826 +
26827 + err = usbnet_read_cmd(dev, SR_RD_REGS, SR_REQ_RD_REG, 0, reg, data,
26828 + length);
26829 + if ((err != length) && (err >= 0))
26830 + err = -EINVAL;
26831 + return err;
26832 +}
26833 +
26834 +static int sr_write(struct usbnet *dev, u8 reg, u16 length, void *data)
26835 +{
26836 + int err;
26837 +
26838 + err = usbnet_write_cmd(dev, SR_WR_REGS, SR_REQ_WR_REG, 0, reg, data,
26839 + length);
26840 + if ((err >= 0) && (err < length))
26841 + err = -EINVAL;
26842 + return err;
26843 +}
26844 +
26845 +static int sr_read_reg(struct usbnet *dev, u8 reg, u8 *value)
26846 +{
26847 + return sr_read(dev, reg, 1, value);
26848 +}
26849 +
26850 +static int sr_write_reg(struct usbnet *dev, u8 reg, u8 value)
26851 +{
26852 + return usbnet_write_cmd(dev, SR_WR_REGS, SR_REQ_WR_REG,
26853 + value, reg, NULL, 0);
26854 +}
26855 +
26856 +static void sr_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)
26857 +{
26858 + usbnet_write_cmd_async(dev, SR_WR_REGS, SR_REQ_WR_REG,
26859 + 0, reg, data, length);
26860 +}
26861 +
26862 +static void sr_write_reg_async(struct usbnet *dev, u8 reg, u8 value)
26863 +{
26864 + usbnet_write_cmd_async(dev, SR_WR_REGS, SR_REQ_WR_REG,
26865 + value, reg, NULL, 0);
26866 +}
26867 +
26868 +static int wait_phy_eeprom_ready(struct usbnet *dev, int phy)
26869 +{
26870 + int i;
26871 +
26872 + for (i = 0; i < SR_SHARE_TIMEOUT; i++) {
26873 + u8 tmp = 0;
26874 + int ret;
26875 +
26876 + udelay(1);
26877 + ret = sr_read_reg(dev, SR_EPCR, &tmp);
26878 + if (ret < 0)
26879 + return ret;
26880 +
26881 + /* ready */
26882 + if (!(tmp & EPCR_ERRE))
26883 + return 0;
26884 + }
26885 +
26886 + netdev_err(dev->net, "%s write timed out!\n", phy ? "phy" : "eeprom");
26887 +
26888 + return -EIO;
26889 +}
26890 +
26891 +static int sr_share_read_word(struct usbnet *dev, int phy, u8 reg,
26892 + __le16 *value)
26893 +{
26894 + int ret;
26895 +
26896 + mutex_lock(&dev->phy_mutex);
26897 +
26898 + sr_write_reg(dev, SR_EPAR, phy ? (reg | EPAR_PHY_ADR) : reg);
26899 + sr_write_reg(dev, SR_EPCR, phy ? (EPCR_EPOS | EPCR_ERPRR) : EPCR_ERPRR);
26900 +
26901 + ret = wait_phy_eeprom_ready(dev, phy);
26902 + if (ret < 0)
26903 + goto out_unlock;
26904 +
26905 + sr_write_reg(dev, SR_EPCR, 0x0);
26906 + ret = sr_read(dev, SR_EPDR, 2, value);
26907 +
26908 + netdev_dbg(dev->net, "read shared %d 0x%02x returned 0x%04x, %d\n",
26909 + phy, reg, *value, ret);
26910 +
26911 +out_unlock:
26912 + mutex_unlock(&dev->phy_mutex);
26913 + return ret;
26914 +}
26915 +
26916 +static int sr_share_write_word(struct usbnet *dev, int phy, u8 reg,
26917 + __le16 value)
26918 +{
26919 + int ret;
26920 +
26921 + mutex_lock(&dev->phy_mutex);
26922 +
26923 + ret = sr_write(dev, SR_EPDR, 2, &value);
26924 + if (ret < 0)
26925 + goto out_unlock;
26926 +
26927 + sr_write_reg(dev, SR_EPAR, phy ? (reg | EPAR_PHY_ADR) : reg);
26928 + sr_write_reg(dev, SR_EPCR, phy ? (EPCR_WEP | EPCR_EPOS | EPCR_ERPRW) :
26929 + (EPCR_WEP | EPCR_ERPRW));
26930 +
26931 + ret = wait_phy_eeprom_ready(dev, phy);
26932 + if (ret < 0)
26933 + goto out_unlock;
26934 +
26935 + sr_write_reg(dev, SR_EPCR, 0x0);
26936 +
26937 +out_unlock:
26938 + mutex_unlock(&dev->phy_mutex);
26939 + return ret;
26940 +}
26941 +
26942 +static int sr_read_eeprom_word(struct usbnet *dev, u8 offset, void *value)
26943 +{
26944 + return sr_share_read_word(dev, 0, offset, value);
26945 +}
26946 +
26947 +static int sr9700_get_eeprom_len(struct net_device *netdev)
26948 +{
26949 + return SR_EEPROM_LEN;
26950 +}
26951 +
26952 +static int sr9700_get_eeprom(struct net_device *netdev,
26953 + struct ethtool_eeprom *eeprom, u8 *data)
26954 +{
26955 + struct usbnet *dev = netdev_priv(netdev);
26956 + __le16 *buf = (__le16 *)data;
26957 + int ret = 0;
26958 + int i;
26959 +
26960 + /* access is 16bit */
26961 + if ((eeprom->offset & 0x01) || (eeprom->len & 0x01))
26962 + return -EINVAL;
26963 +
26964 + for (i = 0; i < eeprom->len / 2; i++) {
26965 + ret = sr_read_eeprom_word(dev, eeprom->offset / 2 + i, buf + i);
26966 + if (ret < 0)
26967 + break;
26968 + }
26969 +
26970 + return ret;
26971 +}
26972 +
26973 +static int sr_mdio_read(struct net_device *netdev, int phy_id, int loc)
26974 +{
26975 + struct usbnet *dev = netdev_priv(netdev);
26976 + __le16 res;
26977 + int rc = 0;
26978 +
26979 + if (phy_id) {
26980 + netdev_dbg(netdev, "Only internal phy supported\n");
26981 + return 0;
26982 + }
26983 +
26984 + /* Access NSR_LINKST bit for link status instead of MII_BMSR */
26985 + if (loc == MII_BMSR) {
26986 + u8 value;
26987 +
26988 + sr_read_reg(dev, SR_NSR, &value);
26989 + if (value & NSR_LINKST)
26990 + rc = 1;
26991 + }
26992 + sr_share_read_word(dev, 1, loc, &res);
26993 + if (rc == 1)
26994 + res = le16_to_cpu(res) | BMSR_LSTATUS;
26995 + else
26996 + res = le16_to_cpu(res) & ~BMSR_LSTATUS;
26997 +
26998 + netdev_dbg(netdev, "sr_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
26999 + phy_id, loc, res);
27000 +
27001 + return res;
27002 +}
27003 +
27004 +static void sr_mdio_write(struct net_device *netdev, int phy_id, int loc,
27005 + int val)
27006 +{
27007 + struct usbnet *dev = netdev_priv(netdev);
27008 + __le16 res = cpu_to_le16(val);
27009 +
27010 + if (phy_id) {
27011 + netdev_dbg(netdev, "Only internal phy supported\n");
27012 + return;
27013 + }
27014 +
27015 + netdev_dbg(netdev, "sr_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n",
27016 + phy_id, loc, val);
27017 +
27018 + sr_share_write_word(dev, 1, loc, res);
27019 +}
27020 +
27021 +static u32 sr9700_get_link(struct net_device *netdev)
27022 +{
27023 + struct usbnet *dev = netdev_priv(netdev);
27024 + u8 value = 0;
27025 + int rc = 0;
27026 +
27027 + /* Get the Link Status directly */
27028 + sr_read_reg(dev, SR_NSR, &value);
27029 + if (value & NSR_LINKST)
27030 + rc = 1;
27031 +
27032 + return rc;
27033 +}
27034 +
27035 +static int sr9700_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
27036 +{
27037 + struct usbnet *dev = netdev_priv(netdev);
27038 +
27039 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
27040 +}
27041 +
27042 +static const struct ethtool_ops sr9700_ethtool_ops = {
27043 + .get_drvinfo = usbnet_get_drvinfo,
27044 + .get_link = sr9700_get_link,
27045 + .get_msglevel = usbnet_get_msglevel,
27046 + .set_msglevel = usbnet_set_msglevel,
27047 + .get_eeprom_len = sr9700_get_eeprom_len,
27048 + .get_eeprom = sr9700_get_eeprom,
27049 + .get_settings = usbnet_get_settings,
27050 + .set_settings = usbnet_set_settings,
27051 + .nway_reset = usbnet_nway_reset,
27052 +};
27053 +
27054 +static void sr9700_set_multicast(struct net_device *netdev)
27055 +{
27056 + struct usbnet *dev = netdev_priv(netdev);
27057 + /* We use the 20 byte dev->data for our 8 byte filter buffer
27058 + * to avoid allocating memory that is tricky to free later
27059 + */
27060 + u8 *hashes = (u8 *)&dev->data;
27061 + /* rx_ctl setting : enable, disable_long, disable_crc */
27062 + u8 rx_ctl = RCR_RXEN | RCR_DIS_CRC | RCR_DIS_LONG;
27063 +
27064 + memset(hashes, 0x00, SR_MCAST_SIZE);
27065 + /* broadcast address */
27066 + hashes[SR_MCAST_SIZE - 1] |= SR_MCAST_ADDR_FLAG;
27067 + if (netdev->flags & IFF_PROMISC) {
27068 + rx_ctl |= RCR_PRMSC;
27069 + } else if (netdev->flags & IFF_ALLMULTI ||
27070 + netdev_mc_count(netdev) > SR_MCAST_MAX) {
27071 + rx_ctl |= RCR_RUNT;
27072 + } else if (!netdev_mc_empty(netdev)) {
27073 + struct netdev_hw_addr *ha;
27074 +
27075 + netdev_for_each_mc_addr(ha, netdev) {
27076 + u32 crc = ether_crc(ETH_ALEN, ha->addr) >> 26;
27077 + hashes[crc >> 3] |= 1 << (crc & 0x7);
27078 + }
27079 + }
27080 +
27081 + sr_write_async(dev, SR_MAR, SR_MCAST_SIZE, hashes);
27082 + sr_write_reg_async(dev, SR_RCR, rx_ctl);
27083 +}
27084 +
27085 +static int sr9700_set_mac_address(struct net_device *netdev, void *p)
27086 +{
27087 + struct usbnet *dev = netdev_priv(netdev);
27088 + struct sockaddr *addr = p;
27089 +
27090 + if (!is_valid_ether_addr(addr->sa_data)) {
27091 + netdev_err(netdev, "not setting invalid mac address %pM\n",
27092 + addr->sa_data);
27093 + return -EINVAL;
27094 + }
27095 +
27096 + memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
27097 + sr_write_async(dev, SR_PAR, 6, netdev->dev_addr);
27098 +
27099 + return 0;
27100 +}
27101 +
27102 +static const struct net_device_ops sr9700_netdev_ops = {
27103 + .ndo_open = usbnet_open,
27104 + .ndo_stop = usbnet_stop,
27105 + .ndo_start_xmit = usbnet_start_xmit,
27106 + .ndo_tx_timeout = usbnet_tx_timeout,
27107 + .ndo_change_mtu = usbnet_change_mtu,
27108 + .ndo_validate_addr = eth_validate_addr,
27109 + .ndo_do_ioctl = sr9700_ioctl,
27110 + .ndo_set_rx_mode = sr9700_set_multicast,
27111 + .ndo_set_mac_address = sr9700_set_mac_address,
27112 +};
27113 +
27114 +static int sr9700_bind(struct usbnet *dev, struct usb_interface *intf)
27115 +{
27116 + struct net_device *netdev;
27117 + struct mii_if_info *mii;
27118 + int ret;
27119 +
27120 + ret = usbnet_get_endpoints(dev, intf);
27121 + if (ret)
27122 + goto out;
27123 +
27124 + netdev = dev->net;
27125 +
27126 + netdev->netdev_ops = &sr9700_netdev_ops;
27127 + netdev->ethtool_ops = &sr9700_ethtool_ops;
27128 + netdev->hard_header_len += SR_TX_OVERHEAD;
27129 + dev->hard_mtu = netdev->mtu + netdev->hard_header_len;
27130 + /* bulkin buffer is preferably not less than 3K */
27131 + dev->rx_urb_size = 3072;
27132 +
27133 + mii = &dev->mii;
27134 + mii->dev = netdev;
27135 + mii->mdio_read = sr_mdio_read;
27136 + mii->mdio_write = sr_mdio_write;
27137 + mii->phy_id_mask = 0x1f;
27138 + mii->reg_num_mask = 0x1f;
27139 +
27140 + sr_write_reg(dev, SR_NCR, NCR_RST);
27141 + udelay(20);
27142 +
27143 + /* read MAC
27144 + * After Chip Power on, the Chip will reload the MAC from
27145 + * EEPROM automatically to PAR. In case there is no EEPROM externally,
27146 + * a default MAC address is stored in PAR for making chip work properly.
27147 + */
27148 + if (sr_read(dev, SR_PAR, ETH_ALEN, netdev->dev_addr) < 0) {
27149 + netdev_err(netdev, "Error reading MAC address\n");
27150 + ret = -ENODEV;
27151 + goto out;
27152 + }
27153 +
27154 + /* power up and reset phy */
27155 + sr_write_reg(dev, SR_PRR, PRR_PHY_RST);
27156 + /* at least 10ms, here 20ms for safe */
27157 + mdelay(20);
27158 + sr_write_reg(dev, SR_PRR, 0);
27159 + /* at least 1ms, here 2ms for reading right register */
27160 + udelay(2 * 1000);
27161 +
27162 + /* receive broadcast packets */
27163 + sr9700_set_multicast(netdev);
27164 +
27165 + sr_mdio_write(netdev, mii->phy_id, MII_BMCR, BMCR_RESET);
27166 + sr_mdio_write(netdev, mii->phy_id, MII_ADVERTISE, ADVERTISE_ALL |
27167 + ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
27168 + mii_nway_restart(mii);
27169 +
27170 +out:
27171 + return ret;
27172 +}
27173 +
27174 +static int sr9700_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
27175 +{
27176 + struct sk_buff *sr_skb;
27177 + int len;
27178 +
27179 + /* skb content (packets) format :
27180 + * p0 p1 p2 ...... pm
27181 + * / \
27182 + * / \
27183 + * / \
27184 + * / \
27185 + * p0b0 p0b1 p0b2 p0b3 ...... p0b(n-4) p0b(n-3)...p0bn
27186 + *
27187 + * p0 : packet 0
27188 + * p0b0 : packet 0 byte 0
27189 + *
27190 + * b0: rx status
27191 + * b1: packet length (incl crc) low
27192 + * b2: packet length (incl crc) high
27193 + * b3..n-4: packet data
27194 + * bn-3..bn: ethernet packet crc
27195 + */
27196 + if (unlikely(skb->len < SR_RX_OVERHEAD)) {
27197 + netdev_err(dev->net, "unexpected tiny rx frame\n");
27198 + return 0;
27199 + }
27200 +
27201 + /* one skb may contains multiple packets */
27202 + while (skb->len > SR_RX_OVERHEAD) {
27203 + if (skb->data[0] != 0x40)
27204 + return 0;
27205 +
27206 + /* ignore the CRC length */
27207 + len = (skb->data[1] | (skb->data[2] << 8)) - 4;
27208 +
27209 + if (len > ETH_FRAME_LEN)
27210 + return 0;
27211 +
27212 + /* the last packet of current skb */
27213 + if (skb->len == (len + SR_RX_OVERHEAD)) {
27214 + skb_pull(skb, 3);
27215 + skb->len = len;
27216 + skb_set_tail_pointer(skb, len);
27217 + skb->truesize = len + sizeof(struct sk_buff);
27218 + return 2;
27219 + }
27220 +
27221 + /* skb_clone is used for address align */
27222 + sr_skb = skb_clone(skb, GFP_ATOMIC);
27223 + if (!sr_skb)
27224 + return 0;
27225 +
27226 + sr_skb->len = len;
27227 + sr_skb->data = skb->data + 3;
27228 + skb_set_tail_pointer(sr_skb, len);
27229 + sr_skb->truesize = len + sizeof(struct sk_buff);
27230 + usbnet_skb_return(dev, sr_skb);
27231 +
27232 + skb_pull(skb, len + SR_RX_OVERHEAD);
27233 + };
27234 +
27235 + return 0;
27236 +}
27237 +
27238 +static struct sk_buff *sr9700_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
27239 + gfp_t flags)
27240 +{
27241 + int len;
27242 +
27243 + /* SR9700 can only send out one ethernet packet at once.
27244 + *
27245 + * b0 b1 b2 b3 ...... b(n-4) b(n-3)...bn
27246 + *
27247 + * b0: rx status
27248 + * b1: packet length (incl crc) low
27249 + * b2: packet length (incl crc) high
27250 + * b3..n-4: packet data
27251 + * bn-3..bn: ethernet packet crc
27252 + */
27253 +
27254 + len = skb->len;
27255 +
27256 + if (skb_headroom(skb) < SR_TX_OVERHEAD) {
27257 + struct sk_buff *skb2;
27258 +
27259 + skb2 = skb_copy_expand(skb, SR_TX_OVERHEAD, 0, flags);
27260 + dev_kfree_skb_any(skb);
27261 + skb = skb2;
27262 + if (!skb)
27263 + return NULL;
27264 + }
27265 +
27266 + __skb_push(skb, SR_TX_OVERHEAD);
27267 +
27268 + /* usbnet adds padding if length is a multiple of packet size
27269 + * if so, adjust length value in header
27270 + */
27271 + if ((skb->len % dev->maxpacket) == 0)
27272 + len++;
27273 +
27274 + skb->data[0] = len;
27275 + skb->data[1] = len >> 8;
27276 +
27277 + return skb;
27278 +}
27279 +
27280 +static void sr9700_status(struct usbnet *dev, struct urb *urb)
27281 +{
27282 + int link;
27283 + u8 *buf;
27284 +
27285 + /* format:
27286 + b0: net status
27287 + b1: tx status 1
27288 + b2: tx status 2
27289 + b3: rx status
27290 + b4: rx overflow
27291 + b5: rx count
27292 + b6: tx count
27293 + b7: gpr
27294 + */
27295 +
27296 + if (urb->actual_length < 8)
27297 + return;
27298 +
27299 + buf = urb->transfer_buffer;
27300 +
27301 + link = !!(buf[0] & 0x40);
27302 + if (netif_carrier_ok(dev->net) != link) {
27303 + usbnet_link_change(dev, link, 1);
27304 + netdev_dbg(dev->net, "Link Status is: %d\n", link);
27305 + }
27306 +}
27307 +
27308 +static int sr9700_link_reset(struct usbnet *dev)
27309 +{
27310 + struct ethtool_cmd ecmd;
27311 +
27312 + mii_check_media(&dev->mii, 1, 1);
27313 + mii_ethtool_gset(&dev->mii, &ecmd);
27314 +
27315 + netdev_dbg(dev->net, "link_reset() speed: %d duplex: %d\n",
27316 + ecmd.speed, ecmd.duplex);
27317 +
27318 + return 0;
27319 +}
27320 +
27321 +static const struct driver_info sr9700_driver_info = {
27322 + .description = "CoreChip SR9700 USB Ethernet",
27323 + .flags = FLAG_ETHER,
27324 + .bind = sr9700_bind,
27325 + .rx_fixup = sr9700_rx_fixup,
27326 + .tx_fixup = sr9700_tx_fixup,
27327 + .status = sr9700_status,
27328 + .link_reset = sr9700_link_reset,
27329 + .reset = sr9700_link_reset,
27330 +};
27331 +
27332 +static const struct usb_device_id products[] = {
27333 + {
27334 + USB_DEVICE(0x0fe6, 0x9700), /* SR9700 device */
27335 + .driver_info = (unsigned long)&sr9700_driver_info,
27336 + },
27337 + {}, /* END */
27338 +};
27339 +
27340 +MODULE_DEVICE_TABLE(usb, products);
27341 +
27342 +static struct usb_driver sr9700_usb_driver = {
27343 + .name = "sr9700",
27344 + .id_table = products,
27345 + .probe = usbnet_probe,
27346 + .disconnect = usbnet_disconnect,
27347 + .suspend = usbnet_suspend,
27348 + .resume = usbnet_resume,
27349 + .disable_hub_initiated_lpm = 1,
27350 +};
27351 +
27352 +module_usb_driver(sr9700_usb_driver);
27353 +
27354 +MODULE_AUTHOR("liujl <liujunliang_ljl@163.com>");
27355 +MODULE_DESCRIPTION("SR9700 one chip USB 1.1 USB to Ethernet device from http://www.corechip-sz.com/");
27356 +MODULE_LICENSE("GPL");
27357 diff -Naur backports-4.2.6-1.org/drivers/net/usb/sr9700.h backports-4.2.6-1/drivers/net/usb/sr9700.h
27358 --- backports-4.2.6-1.org/drivers/net/usb/sr9700.h 1970-01-01 01:00:00.000000000 +0100
27359 +++ backports-4.2.6-1/drivers/net/usb/sr9700.h 2016-06-28 14:35:18.011973884 +0200
27360 @@ -0,0 +1,173 @@
27361 +/*
27362 + * CoreChip-sz SR9700 one chip USB 1.1 Ethernet Devices
27363 + *
27364 + * Author : Liu Junliang <liujunliang_ljl@163.com>
27365 + *
27366 + * This program is free software; you can redistribute it and/or
27367 + * modify it under the terms of the GNU General Public License
27368 + * version 2 as published by the Free Software Foundation.
27369 + */
27370 +
27371 +#ifndef _SR9700_H
27372 +#define _SR9700_H
27373 +
27374 +/* sr9700 spec. register table on Linux platform */
27375 +
27376 +/* Network Control Reg */
27377 +#define SR_NCR 0x00
27378 +#define NCR_RST (1 << 0)
27379 +#define NCR_LBK (3 << 1)
27380 +#define NCR_FDX (1 << 3)
27381 +#define NCR_WAKEEN (1 << 6)
27382 +/* Network Status Reg */
27383 +#define SR_NSR 0x01
27384 +#define NSR_RXRDY (1 << 0)
27385 +#define NSR_RXOV (1 << 1)
27386 +#define NSR_TX1END (1 << 2)
27387 +#define NSR_TX2END (1 << 3)
27388 +#define NSR_TXFULL (1 << 4)
27389 +#define NSR_WAKEST (1 << 5)
27390 +#define NSR_LINKST (1 << 6)
27391 +#define NSR_SPEED (1 << 7)
27392 +/* Tx Control Reg */
27393 +#define SR_TCR 0x02
27394 +#define TCR_CRC_DIS (1 << 1)
27395 +#define TCR_PAD_DIS (1 << 2)
27396 +#define TCR_LC_CARE (1 << 3)
27397 +#define TCR_CRS_CARE (1 << 4)
27398 +#define TCR_EXCECM (1 << 5)
27399 +#define TCR_LF_EN (1 << 6)
27400 +/* Tx Status Reg for Packet Index 1 */
27401 +#define SR_TSR1 0x03
27402 +#define TSR1_EC (1 << 2)
27403 +#define TSR1_COL (1 << 3)
27404 +#define TSR1_LC (1 << 4)
27405 +#define TSR1_NC (1 << 5)
27406 +#define TSR1_LOC (1 << 6)
27407 +#define TSR1_TLF (1 << 7)
27408 +/* Tx Status Reg for Packet Index 2 */
27409 +#define SR_TSR2 0x04
27410 +#define TSR2_EC (1 << 2)
27411 +#define TSR2_COL (1 << 3)
27412 +#define TSR2_LC (1 << 4)
27413 +#define TSR2_NC (1 << 5)
27414 +#define TSR2_LOC (1 << 6)
27415 +#define TSR2_TLF (1 << 7)
27416 +/* Rx Control Reg*/
27417 +#define SR_RCR 0x05
27418 +#define RCR_RXEN (1 << 0)
27419 +#define RCR_PRMSC (1 << 1)
27420 +#define RCR_RUNT (1 << 2)
27421 +#define RCR_ALL (1 << 3)
27422 +#define RCR_DIS_CRC (1 << 4)
27423 +#define RCR_DIS_LONG (1 << 5)
27424 +/* Rx Status Reg */
27425 +#define SR_RSR 0x06
27426 +#define RSR_AE (1 << 2)
27427 +#define RSR_MF (1 << 6)
27428 +#define RSR_RF (1 << 7)
27429 +/* Rx Overflow Counter Reg */
27430 +#define SR_ROCR 0x07
27431 +#define ROCR_ROC (0x7F << 0)
27432 +#define ROCR_RXFU (1 << 7)
27433 +/* Back Pressure Threshold Reg */
27434 +#define SR_BPTR 0x08
27435 +#define BPTR_JPT (0x0F << 0)
27436 +#define BPTR_BPHW (0x0F << 4)
27437 +/* Flow Control Threshold Reg */
27438 +#define SR_FCTR 0x09
27439 +#define FCTR_LWOT (0x0F << 0)
27440 +#define FCTR_HWOT (0x0F << 4)
27441 +/* rx/tx Flow Control Reg */
27442 +#define SR_FCR 0x0A
27443 +#define FCR_FLCE (1 << 0)
27444 +#define FCR_BKPA (1 << 4)
27445 +#define FCR_TXPEN (1 << 5)
27446 +#define FCR_TXPF (1 << 6)
27447 +#define FCR_TXP0 (1 << 7)
27448 +/* Eeprom & Phy Control Reg */
27449 +#define SR_EPCR 0x0B
27450 +#define EPCR_ERRE (1 << 0)
27451 +#define EPCR_ERPRW (1 << 1)
27452 +#define EPCR_ERPRR (1 << 2)
27453 +#define EPCR_EPOS (1 << 3)
27454 +#define EPCR_WEP (1 << 4)
27455 +/* Eeprom & Phy Address Reg */
27456 +#define SR_EPAR 0x0C
27457 +#define EPAR_EROA (0x3F << 0)
27458 +#define EPAR_PHY_ADR_MASK (0x03 << 6)
27459 +#define EPAR_PHY_ADR (0x01 << 6)
27460 +/* Eeprom & Phy Data Reg */
27461 +#define SR_EPDR 0x0D /* 0x0D ~ 0x0E for Data Reg Low & High */
27462 +/* Wakeup Control Reg */
27463 +#define SR_WCR 0x0F
27464 +#define WCR_MAGICST (1 << 0)
27465 +#define WCR_LINKST (1 << 2)
27466 +#define WCR_MAGICEN (1 << 3)
27467 +#define WCR_LINKEN (1 << 5)
27468 +/* Physical Address Reg */
27469 +#define SR_PAR 0x10 /* 0x10 ~ 0x15 6 bytes for PAR */
27470 +/* Multicast Address Reg */
27471 +#define SR_MAR 0x16 /* 0x16 ~ 0x1D 8 bytes for MAR */
27472 +/* 0x1e unused */
27473 +/* Phy Reset Reg */
27474 +#define SR_PRR 0x1F
27475 +#define PRR_PHY_RST (1 << 0)
27476 +/* Tx sdram Write Pointer Address Low */
27477 +#define SR_TWPAL 0x20
27478 +/* Tx sdram Write Pointer Address High */
27479 +#define SR_TWPAH 0x21
27480 +/* Tx sdram Read Pointer Address Low */
27481 +#define SR_TRPAL 0x22
27482 +/* Tx sdram Read Pointer Address High */
27483 +#define SR_TRPAH 0x23
27484 +/* Rx sdram Write Pointer Address Low */
27485 +#define SR_RWPAL 0x24
27486 +/* Rx sdram Write Pointer Address High */
27487 +#define SR_RWPAH 0x25
27488 +/* Rx sdram Read Pointer Address Low */
27489 +#define SR_RRPAL 0x26
27490 +/* Rx sdram Read Pointer Address High */
27491 +#define SR_RRPAH 0x27
27492 +/* Vendor ID register */
27493 +#define SR_VID 0x28 /* 0x28 ~ 0x29 2 bytes for VID */
27494 +/* Product ID register */
27495 +#define SR_PID 0x2A /* 0x2A ~ 0x2B 2 bytes for PID */
27496 +/* CHIP Revision register */
27497 +#define SR_CHIPR 0x2C
27498 +/* 0x2D --> 0xEF unused */
27499 +/* USB Device Address */
27500 +#define SR_USBDA 0xF0
27501 +#define USBDA_USBFA (0x7F << 0)
27502 +/* RX packet Counter Reg */
27503 +#define SR_RXC 0xF1
27504 +/* Tx packet Counter & USB Status Reg */
27505 +#define SR_TXC_USBS 0xF2
27506 +#define TXC_USBS_TXC0 (1 << 0)
27507 +#define TXC_USBS_TXC1 (1 << 1)
27508 +#define TXC_USBS_TXC2 (1 << 2)
27509 +#define TXC_USBS_EP1RDY (1 << 5)
27510 +#define TXC_USBS_SUSFLAG (1 << 6)
27511 +#define TXC_USBS_RXFAULT (1 << 7)
27512 +/* USB Control register */
27513 +#define SR_USBC 0xF4
27514 +#define USBC_EP3NAK (1 << 4)
27515 +#define USBC_EP3ACK (1 << 5)
27516 +
27517 +/* Register access commands and flags */
27518 +#define SR_RD_REGS 0x00
27519 +#define SR_WR_REGS 0x01
27520 +#define SR_WR_REG 0x03
27521 +#define SR_REQ_RD_REG (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
27522 +#define SR_REQ_WR_REG (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
27523 +
27524 +/* parameters */
27525 +#define SR_SHARE_TIMEOUT 1000
27526 +#define SR_EEPROM_LEN 256
27527 +#define SR_MCAST_SIZE 8
27528 +#define SR_MCAST_ADDR_FLAG 0x80
27529 +#define SR_MCAST_MAX 64
27530 +#define SR_TX_OVERHEAD 2 /* 2bytes header */
27531 +#define SR_RX_OVERHEAD 7 /* 3bytes header + 4crc tail */
27532 +
27533 +#endif /* _SR9700_H */
27534 diff -Naur backports-4.2.6-1.org/drivers/net/usb/sr9800.c backports-4.2.6-1/drivers/net/usb/sr9800.c
27535 --- backports-4.2.6-1.org/drivers/net/usb/sr9800.c 1970-01-01 01:00:00.000000000 +0100
27536 +++ backports-4.2.6-1/drivers/net/usb/sr9800.c 2016-06-28 14:35:18.015307217 +0200
27537 @@ -0,0 +1,875 @@
27538 +/* CoreChip-sz SR9800 one chip USB 2.0 Ethernet Devices
27539 + *
27540 + * Author : Liu Junliang <liujunliang_ljl@163.com>
27541 + *
27542 + * Based on asix_common.c, asix_devices.c
27543 + *
27544 + * This file is licensed under the terms of the GNU General Public License
27545 + * version 2. This program is licensed "as is" without any warranty of any
27546 + * kind, whether express or implied.*
27547 + */
27548 +
27549 +#include <linux/module.h>
27550 +#include <linux/kmod.h>
27551 +#include <linux/init.h>
27552 +#include <linux/netdevice.h>
27553 +#include <linux/etherdevice.h>
27554 +#include <linux/ethtool.h>
27555 +#include <linux/workqueue.h>
27556 +#include <linux/mii.h>
27557 +#include <linux/usb.h>
27558 +#include <linux/crc32.h>
27559 +#include <linux/usb/usbnet.h>
27560 +#include <linux/slab.h>
27561 +#include <linux/if_vlan.h>
27562 +
27563 +#include "sr9800.h"
27564 +
27565 +static int sr_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
27566 + u16 size, void *data)
27567 +{
27568 + int err;
27569 +
27570 + err = usbnet_read_cmd(dev, cmd, SR_REQ_RD_REG, value, index,
27571 + data, size);
27572 + if ((err != size) && (err >= 0))
27573 + err = -EINVAL;
27574 +
27575 + return err;
27576 +}
27577 +
27578 +static int sr_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
27579 + u16 size, void *data)
27580 +{
27581 + int err;
27582 +
27583 + err = usbnet_write_cmd(dev, cmd, SR_REQ_WR_REG, value, index,
27584 + data, size);
27585 + if ((err != size) && (err >= 0))
27586 + err = -EINVAL;
27587 +
27588 + return err;
27589 +}
27590 +
27591 +static void
27592 +sr_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
27593 + u16 size, void *data)
27594 +{
27595 + usbnet_write_cmd_async(dev, cmd, SR_REQ_WR_REG, value, index, data,
27596 + size);
27597 +}
27598 +
27599 +static int sr_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
27600 +{
27601 + int offset = 0;
27602 +
27603 + /* This check is no longer done by usbnet */
27604 + if (skb->len < dev->net->hard_header_len)
27605 + return 0;
27606 +
27607 + while (offset + sizeof(u32) < skb->len) {
27608 + struct sk_buff *sr_skb;
27609 + u16 size;
27610 + u32 header = get_unaligned_le32(skb->data + offset);
27611 +
27612 + offset += sizeof(u32);
27613 + /* get the packet length */
27614 + size = (u16) (header & 0x7ff);
27615 + if (size != ((~header >> 16) & 0x07ff)) {
27616 + netdev_err(dev->net, "%s : Bad Header Length\n",
27617 + __func__);
27618 + return 0;
27619 + }
27620 +
27621 + if ((size > dev->net->mtu + ETH_HLEN + VLAN_HLEN) ||
27622 + (size + offset > skb->len)) {
27623 + netdev_err(dev->net, "%s : Bad RX Length %d\n",
27624 + __func__, size);
27625 + return 0;
27626 + }
27627 + sr_skb = netdev_alloc_skb_ip_align(dev->net, size);
27628 + if (!sr_skb)
27629 + return 0;
27630 +
27631 + skb_put(sr_skb, size);
27632 + memcpy(sr_skb->data, skb->data + offset, size);
27633 + usbnet_skb_return(dev, sr_skb);
27634 +
27635 + offset += (size + 1) & 0xfffe;
27636 + }
27637 +
27638 + if (skb->len != offset) {
27639 + netdev_err(dev->net, "%s : Bad SKB Length %d\n", __func__,
27640 + skb->len);
27641 + return 0;
27642 + }
27643 +
27644 + return 1;
27645 +}
27646 +
27647 +static struct sk_buff *sr_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
27648 + gfp_t flags)
27649 +{
27650 + int headroom = skb_headroom(skb);
27651 + int tailroom = skb_tailroom(skb);
27652 + u32 padbytes = 0xffff0000;
27653 + u32 packet_len;
27654 + int padlen;
27655 +
27656 + padlen = ((skb->len + 4) % (dev->maxpacket - 1)) ? 0 : 4;
27657 +
27658 + if ((!skb_cloned(skb)) && ((headroom + tailroom) >= (4 + padlen))) {
27659 + if ((headroom < 4) || (tailroom < padlen)) {
27660 + skb->data = memmove(skb->head + 4, skb->data,
27661 + skb->len);
27662 + skb_set_tail_pointer(skb, skb->len);
27663 + }
27664 + } else {
27665 + struct sk_buff *skb2;
27666 + skb2 = skb_copy_expand(skb, 4, padlen, flags);
27667 + dev_kfree_skb_any(skb);
27668 + skb = skb2;
27669 + if (!skb)
27670 + return NULL;
27671 + }
27672 +
27673 + skb_push(skb, 4);
27674 + packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
27675 + cpu_to_le32s(&packet_len);
27676 + skb_copy_to_linear_data(skb, &packet_len, sizeof(packet_len));
27677 +
27678 + if (padlen) {
27679 + cpu_to_le32s(&padbytes);
27680 + memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes));
27681 + skb_put(skb, sizeof(padbytes));
27682 + }
27683 +
27684 + usbnet_set_skb_tx_stats(skb, 1, 0);
27685 + return skb;
27686 +}
27687 +
27688 +static void sr_status(struct usbnet *dev, struct urb *urb)
27689 +{
27690 + struct sr9800_int_data *event;
27691 + int link;
27692 +
27693 + if (urb->actual_length < 8)
27694 + return;
27695 +
27696 + event = urb->transfer_buffer;
27697 + link = event->link & 0x01;
27698 + if (netif_carrier_ok(dev->net) != link) {
27699 + usbnet_link_change(dev, link, 1);
27700 + netdev_dbg(dev->net, "Link Status is: %d\n", link);
27701 + }
27702 +
27703 + return;
27704 +}
27705 +
27706 +static inline int sr_set_sw_mii(struct usbnet *dev)
27707 +{
27708 + int ret;
27709 +
27710 + ret = sr_write_cmd(dev, SR_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
27711 + if (ret < 0)
27712 + netdev_err(dev->net, "Failed to enable software MII access\n");
27713 + return ret;
27714 +}
27715 +
27716 +static inline int sr_set_hw_mii(struct usbnet *dev)
27717 +{
27718 + int ret;
27719 +
27720 + ret = sr_write_cmd(dev, SR_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
27721 + if (ret < 0)
27722 + netdev_err(dev->net, "Failed to enable hardware MII access\n");
27723 + return ret;
27724 +}
27725 +
27726 +static inline int sr_get_phy_addr(struct usbnet *dev)
27727 +{
27728 + u8 buf[2];
27729 + int ret;
27730 +
27731 + ret = sr_read_cmd(dev, SR_CMD_READ_PHY_ID, 0, 0, 2, buf);
27732 + if (ret < 0) {
27733 + netdev_err(dev->net, "%s : Error reading PHYID register:%02x\n",
27734 + __func__, ret);
27735 + goto out;
27736 + }
27737 + netdev_dbg(dev->net, "%s : returning 0x%04x\n", __func__,
27738 + *((__le16 *)buf));
27739 +
27740 + ret = buf[1];
27741 +
27742 +out:
27743 + return ret;
27744 +}
27745 +
27746 +static int sr_sw_reset(struct usbnet *dev, u8 flags)
27747 +{
27748 + int ret;
27749 +
27750 + ret = sr_write_cmd(dev, SR_CMD_SW_RESET, flags, 0, 0, NULL);
27751 + if (ret < 0)
27752 + netdev_err(dev->net, "Failed to send software reset:%02x\n",
27753 + ret);
27754 +
27755 + return ret;
27756 +}
27757 +
27758 +static u16 sr_read_rx_ctl(struct usbnet *dev)
27759 +{
27760 + __le16 v;
27761 + int ret;
27762 +
27763 + ret = sr_read_cmd(dev, SR_CMD_READ_RX_CTL, 0, 0, 2, &v);
27764 + if (ret < 0) {
27765 + netdev_err(dev->net, "Error reading RX_CTL register:%02x\n",
27766 + ret);
27767 + goto out;
27768 + }
27769 +
27770 + ret = le16_to_cpu(v);
27771 +out:
27772 + return ret;
27773 +}
27774 +
27775 +static int sr_write_rx_ctl(struct usbnet *dev, u16 mode)
27776 +{
27777 + int ret;
27778 +
27779 + netdev_dbg(dev->net, "%s : mode = 0x%04x\n", __func__, mode);
27780 + ret = sr_write_cmd(dev, SR_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
27781 + if (ret < 0)
27782 + netdev_err(dev->net,
27783 + "Failed to write RX_CTL mode to 0x%04x:%02x\n",
27784 + mode, ret);
27785 +
27786 + return ret;
27787 +}
27788 +
27789 +static u16 sr_read_medium_status(struct usbnet *dev)
27790 +{
27791 + __le16 v;
27792 + int ret;
27793 +
27794 + ret = sr_read_cmd(dev, SR_CMD_READ_MEDIUM_STATUS, 0, 0, 2, &v);
27795 + if (ret < 0) {
27796 + netdev_err(dev->net,
27797 + "Error reading Medium Status register:%02x\n", ret);
27798 + return ret; /* TODO: callers not checking for error ret */
27799 + }
27800 +
27801 + return le16_to_cpu(v);
27802 +}
27803 +
27804 +static int sr_write_medium_mode(struct usbnet *dev, u16 mode)
27805 +{
27806 + int ret;
27807 +
27808 + netdev_dbg(dev->net, "%s : mode = 0x%04x\n", __func__, mode);
27809 + ret = sr_write_cmd(dev, SR_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
27810 + if (ret < 0)
27811 + netdev_err(dev->net,
27812 + "Failed to write Medium Mode mode to 0x%04x:%02x\n",
27813 + mode, ret);
27814 + return ret;
27815 +}
27816 +
27817 +static int sr_write_gpio(struct usbnet *dev, u16 value, int sleep)
27818 +{
27819 + int ret;
27820 +
27821 + netdev_dbg(dev->net, "%s : value = 0x%04x\n", __func__, value);
27822 + ret = sr_write_cmd(dev, SR_CMD_WRITE_GPIOS, value, 0, 0, NULL);
27823 + if (ret < 0)
27824 + netdev_err(dev->net, "Failed to write GPIO value 0x%04x:%02x\n",
27825 + value, ret);
27826 + if (sleep)
27827 + msleep(sleep);
27828 +
27829 + return ret;
27830 +}
27831 +
27832 +/* SR9800 have a 16-bit RX_CTL value */
27833 +static void sr_set_multicast(struct net_device *net)
27834 +{
27835 + struct usbnet *dev = netdev_priv(net);
27836 + struct sr_data *data = (struct sr_data *)&dev->data;
27837 + u16 rx_ctl = SR_DEFAULT_RX_CTL;
27838 +
27839 + if (net->flags & IFF_PROMISC) {
27840 + rx_ctl |= SR_RX_CTL_PRO;
27841 + } else if (net->flags & IFF_ALLMULTI ||
27842 + netdev_mc_count(net) > SR_MAX_MCAST) {
27843 + rx_ctl |= SR_RX_CTL_AMALL;
27844 + } else if (netdev_mc_empty(net)) {
27845 + /* just broadcast and directed */
27846 + } else {
27847 + /* We use the 20 byte dev->data
27848 + * for our 8 byte filter buffer
27849 + * to avoid allocating memory that
27850 + * is tricky to free later
27851 + */
27852 + struct netdev_hw_addr *ha;
27853 + u32 crc_bits;
27854 +
27855 + memset(data->multi_filter, 0, SR_MCAST_FILTER_SIZE);
27856 +
27857 + /* Build the multicast hash filter. */
27858 + netdev_for_each_mc_addr(ha, net) {
27859 + crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
27860 + data->multi_filter[crc_bits >> 3] |=
27861 + 1 << (crc_bits & 7);
27862 + }
27863 +
27864 + sr_write_cmd_async(dev, SR_CMD_WRITE_MULTI_FILTER, 0, 0,
27865 + SR_MCAST_FILTER_SIZE, data->multi_filter);
27866 +
27867 + rx_ctl |= SR_RX_CTL_AM;
27868 + }
27869 +
27870 + sr_write_cmd_async(dev, SR_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
27871 +}
27872 +
27873 +static int sr_mdio_read(struct net_device *net, int phy_id, int loc)
27874 +{
27875 + struct usbnet *dev = netdev_priv(net);
27876 + __le16 res;
27877 +
27878 + mutex_lock(&dev->phy_mutex);
27879 + sr_set_sw_mii(dev);
27880 + sr_read_cmd(dev, SR_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, &res);
27881 + sr_set_hw_mii(dev);
27882 + mutex_unlock(&dev->phy_mutex);
27883 +
27884 + netdev_dbg(dev->net,
27885 + "%s : phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n", __func__,
27886 + phy_id, loc, le16_to_cpu(res));
27887 +
27888 + return le16_to_cpu(res);
27889 +}
27890 +
27891 +static void
27892 +sr_mdio_write(struct net_device *net, int phy_id, int loc, int val)
27893 +{
27894 + struct usbnet *dev = netdev_priv(net);
27895 + __le16 res = cpu_to_le16(val);
27896 +
27897 + netdev_dbg(dev->net,
27898 + "%s : phy_id=0x%02x, loc=0x%02x, val=0x%04x\n", __func__,
27899 + phy_id, loc, val);
27900 + mutex_lock(&dev->phy_mutex);
27901 + sr_set_sw_mii(dev);
27902 + sr_write_cmd(dev, SR_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, &res);
27903 + sr_set_hw_mii(dev);
27904 + mutex_unlock(&dev->phy_mutex);
27905 +}
27906 +
27907 +/* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
27908 +static u32 sr_get_phyid(struct usbnet *dev)
27909 +{
27910 + int phy_reg;
27911 + u32 phy_id;
27912 + int i;
27913 +
27914 + /* Poll for the rare case the FW or phy isn't ready yet. */
27915 + for (i = 0; i < 100; i++) {
27916 + phy_reg = sr_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID1);
27917 + if (phy_reg != 0 && phy_reg != 0xFFFF)
27918 + break;
27919 + mdelay(1);
27920 + }
27921 +
27922 + if (phy_reg <= 0 || phy_reg == 0xFFFF)
27923 + return 0;
27924 +
27925 + phy_id = (phy_reg & 0xffff) << 16;
27926 +
27927 + phy_reg = sr_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID2);
27928 + if (phy_reg < 0)
27929 + return 0;
27930 +
27931 + phy_id |= (phy_reg & 0xffff);
27932 +
27933 + return phy_id;
27934 +}
27935 +
27936 +static void
27937 +sr_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
27938 +{
27939 + struct usbnet *dev = netdev_priv(net);
27940 + u8 opt;
27941 +
27942 + if (sr_read_cmd(dev, SR_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
27943 + wolinfo->supported = 0;
27944 + wolinfo->wolopts = 0;
27945 + return;
27946 + }
27947 + wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
27948 + wolinfo->wolopts = 0;
27949 + if (opt & SR_MONITOR_LINK)
27950 + wolinfo->wolopts |= WAKE_PHY;
27951 + if (opt & SR_MONITOR_MAGIC)
27952 + wolinfo->wolopts |= WAKE_MAGIC;
27953 +}
27954 +
27955 +static int
27956 +sr_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
27957 +{
27958 + struct usbnet *dev = netdev_priv(net);
27959 + u8 opt = 0;
27960 +
27961 + if (wolinfo->wolopts & WAKE_PHY)
27962 + opt |= SR_MONITOR_LINK;
27963 + if (wolinfo->wolopts & WAKE_MAGIC)
27964 + opt |= SR_MONITOR_MAGIC;
27965 +
27966 + if (sr_write_cmd(dev, SR_CMD_WRITE_MONITOR_MODE,
27967 + opt, 0, 0, NULL) < 0)
27968 + return -EINVAL;
27969 +
27970 + return 0;
27971 +}
27972 +
27973 +static int sr_get_eeprom_len(struct net_device *net)
27974 +{
27975 + struct usbnet *dev = netdev_priv(net);
27976 + struct sr_data *data = (struct sr_data *)&dev->data;
27977 +
27978 + return data->eeprom_len;
27979 +}
27980 +
27981 +static int sr_get_eeprom(struct net_device *net,
27982 + struct ethtool_eeprom *eeprom, u8 *data)
27983 +{
27984 + struct usbnet *dev = netdev_priv(net);
27985 + __le16 *ebuf = (__le16 *)data;
27986 + int ret;
27987 + int i;
27988 +
27989 + /* Crude hack to ensure that we don't overwrite memory
27990 + * if an odd length is supplied
27991 + */
27992 + if (eeprom->len % 2)
27993 + return -EINVAL;
27994 +
27995 + eeprom->magic = SR_EEPROM_MAGIC;
27996 +
27997 + /* sr9800 returns 2 bytes from eeprom on read */
27998 + for (i = 0; i < eeprom->len / 2; i++) {
27999 + ret = sr_read_cmd(dev, SR_CMD_READ_EEPROM, eeprom->offset + i,
28000 + 0, 2, &ebuf[i]);
28001 + if (ret < 0)
28002 + return -EINVAL;
28003 + }
28004 + return 0;
28005 +}
28006 +
28007 +static void sr_get_drvinfo(struct net_device *net,
28008 + struct ethtool_drvinfo *info)
28009 +{
28010 + struct usbnet *dev = netdev_priv(net);
28011 + struct sr_data *data = (struct sr_data *)&dev->data;
28012 +
28013 + /* Inherit standard device info */
28014 + usbnet_get_drvinfo(net, info);
28015 + strncpy(info->driver, DRIVER_NAME, sizeof(info->driver));
28016 + strncpy(info->version, DRIVER_VERSION, sizeof(info->version));
28017 + info->eedump_len = data->eeprom_len;
28018 +}
28019 +
28020 +static u32 sr_get_link(struct net_device *net)
28021 +{
28022 + struct usbnet *dev = netdev_priv(net);
28023 +
28024 + return mii_link_ok(&dev->mii);
28025 +}
28026 +
28027 +static int sr_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
28028 +{
28029 + struct usbnet *dev = netdev_priv(net);
28030 +
28031 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
28032 +}
28033 +
28034 +static int sr_set_mac_address(struct net_device *net, void *p)
28035 +{
28036 + struct usbnet *dev = netdev_priv(net);
28037 + struct sr_data *data = (struct sr_data *)&dev->data;
28038 + struct sockaddr *addr = p;
28039 +
28040 + if (netif_running(net))
28041 + return -EBUSY;
28042 + if (!is_valid_ether_addr(addr->sa_data))
28043 + return -EADDRNOTAVAIL;
28044 +
28045 + memcpy(net->dev_addr, addr->sa_data, ETH_ALEN);
28046 +
28047 + /* We use the 20 byte dev->data
28048 + * for our 6 byte mac buffer
28049 + * to avoid allocating memory that
28050 + * is tricky to free later
28051 + */
28052 + memcpy(data->mac_addr, addr->sa_data, ETH_ALEN);
28053 + sr_write_cmd_async(dev, SR_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
28054 + data->mac_addr);
28055 +
28056 + return 0;
28057 +}
28058 +
28059 +static const struct ethtool_ops sr9800_ethtool_ops = {
28060 + .get_drvinfo = sr_get_drvinfo,
28061 + .get_link = sr_get_link,
28062 + .get_msglevel = usbnet_get_msglevel,
28063 + .set_msglevel = usbnet_set_msglevel,
28064 + .get_wol = sr_get_wol,
28065 + .set_wol = sr_set_wol,
28066 + .get_eeprom_len = sr_get_eeprom_len,
28067 + .get_eeprom = sr_get_eeprom,
28068 + .get_settings = usbnet_get_settings,
28069 + .set_settings = usbnet_set_settings,
28070 + .nway_reset = usbnet_nway_reset,
28071 +};
28072 +
28073 +static int sr9800_link_reset(struct usbnet *dev)
28074 +{
28075 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
28076 + u16 mode;
28077 +
28078 + mii_check_media(&dev->mii, 1, 1);
28079 + mii_ethtool_gset(&dev->mii, &ecmd);
28080 + mode = SR9800_MEDIUM_DEFAULT;
28081 +
28082 + if (ethtool_cmd_speed(&ecmd) != SPEED_100)
28083 + mode &= ~SR_MEDIUM_PS;
28084 +
28085 + if (ecmd.duplex != DUPLEX_FULL)
28086 + mode &= ~SR_MEDIUM_FD;
28087 +
28088 + netdev_dbg(dev->net, "%s : speed: %u duplex: %d mode: 0x%04x\n",
28089 + __func__, ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
28090 +
28091 + sr_write_medium_mode(dev, mode);
28092 +
28093 + return 0;
28094 +}
28095 +
28096 +
28097 +static int sr9800_set_default_mode(struct usbnet *dev)
28098 +{
28099 + u16 rx_ctl;
28100 + int ret;
28101 +
28102 + sr_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
28103 + sr_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
28104 + ADVERTISE_ALL | ADVERTISE_CSMA);
28105 + mii_nway_restart(&dev->mii);
28106 +
28107 + ret = sr_write_medium_mode(dev, SR9800_MEDIUM_DEFAULT);
28108 + if (ret < 0)
28109 + goto out;
28110 +
28111 + ret = sr_write_cmd(dev, SR_CMD_WRITE_IPG012,
28112 + SR9800_IPG0_DEFAULT | SR9800_IPG1_DEFAULT,
28113 + SR9800_IPG2_DEFAULT, 0, NULL);
28114 + if (ret < 0) {
28115 + netdev_dbg(dev->net, "Write IPG,IPG1,IPG2 failed: %d\n", ret);
28116 + goto out;
28117 + }
28118 +
28119 + /* Set RX_CTL to default values with 2k buffer, and enable cactus */
28120 + ret = sr_write_rx_ctl(dev, SR_DEFAULT_RX_CTL);
28121 + if (ret < 0)
28122 + goto out;
28123 +
28124 + rx_ctl = sr_read_rx_ctl(dev);
28125 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after all initializations\n",
28126 + rx_ctl);
28127 +
28128 + rx_ctl = sr_read_medium_status(dev);
28129 + netdev_dbg(dev->net, "Medium Status:0x%04x after all initializations\n",
28130 + rx_ctl);
28131 +
28132 + return 0;
28133 +out:
28134 + return ret;
28135 +}
28136 +
28137 +static int sr9800_reset(struct usbnet *dev)
28138 +{
28139 + struct sr_data *data = (struct sr_data *)&dev->data;
28140 + int ret, embd_phy;
28141 + u16 rx_ctl;
28142 +
28143 + ret = sr_write_gpio(dev,
28144 + SR_GPIO_RSE | SR_GPIO_GPO_2 | SR_GPIO_GPO2EN, 5);
28145 + if (ret < 0)
28146 + goto out;
28147 +
28148 + embd_phy = ((sr_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0);
28149 +
28150 + ret = sr_write_cmd(dev, SR_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
28151 + if (ret < 0) {
28152 + netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
28153 + goto out;
28154 + }
28155 +
28156 + ret = sr_sw_reset(dev, SR_SWRESET_IPPD | SR_SWRESET_PRL);
28157 + if (ret < 0)
28158 + goto out;
28159 +
28160 + msleep(150);
28161 +
28162 + ret = sr_sw_reset(dev, SR_SWRESET_CLEAR);
28163 + if (ret < 0)
28164 + goto out;
28165 +
28166 + msleep(150);
28167 +
28168 + if (embd_phy) {
28169 + ret = sr_sw_reset(dev, SR_SWRESET_IPRL);
28170 + if (ret < 0)
28171 + goto out;
28172 + } else {
28173 + ret = sr_sw_reset(dev, SR_SWRESET_PRTE);
28174 + if (ret < 0)
28175 + goto out;
28176 + }
28177 +
28178 + msleep(150);
28179 + rx_ctl = sr_read_rx_ctl(dev);
28180 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after software reset\n", rx_ctl);
28181 + ret = sr_write_rx_ctl(dev, 0x0000);
28182 + if (ret < 0)
28183 + goto out;
28184 +
28185 + rx_ctl = sr_read_rx_ctl(dev);
28186 + netdev_dbg(dev->net, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
28187 +
28188 + ret = sr_sw_reset(dev, SR_SWRESET_PRL);
28189 + if (ret < 0)
28190 + goto out;
28191 +
28192 + msleep(150);
28193 +
28194 + ret = sr_sw_reset(dev, SR_SWRESET_IPRL | SR_SWRESET_PRL);
28195 + if (ret < 0)
28196 + goto out;
28197 +
28198 + msleep(150);
28199 +
28200 + ret = sr9800_set_default_mode(dev);
28201 + if (ret < 0)
28202 + goto out;
28203 +
28204 + /* Rewrite MAC address */
28205 + memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
28206 + ret = sr_write_cmd(dev, SR_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
28207 + data->mac_addr);
28208 + if (ret < 0)
28209 + goto out;
28210 +
28211 + return 0;
28212 +
28213 +out:
28214 + return ret;
28215 +}
28216 +
28217 +static const struct net_device_ops sr9800_netdev_ops = {
28218 + .ndo_open = usbnet_open,
28219 + .ndo_stop = usbnet_stop,
28220 + .ndo_start_xmit = usbnet_start_xmit,
28221 + .ndo_tx_timeout = usbnet_tx_timeout,
28222 + .ndo_change_mtu = usbnet_change_mtu,
28223 + .ndo_set_mac_address = sr_set_mac_address,
28224 + .ndo_validate_addr = eth_validate_addr,
28225 + .ndo_do_ioctl = sr_ioctl,
28226 + .ndo_set_rx_mode = sr_set_multicast,
28227 +};
28228 +
28229 +static int sr9800_phy_powerup(struct usbnet *dev)
28230 +{
28231 + int ret;
28232 +
28233 + /* set the embedded Ethernet PHY in power-down state */
28234 + ret = sr_sw_reset(dev, SR_SWRESET_IPPD | SR_SWRESET_IPRL);
28235 + if (ret < 0) {
28236 + netdev_err(dev->net, "Failed to power down PHY : %d\n", ret);
28237 + return ret;
28238 + }
28239 + msleep(20);
28240 +
28241 + /* set the embedded Ethernet PHY in power-up state */
28242 + ret = sr_sw_reset(dev, SR_SWRESET_IPRL);
28243 + if (ret < 0) {
28244 + netdev_err(dev->net, "Failed to reset PHY: %d\n", ret);
28245 + return ret;
28246 + }
28247 + msleep(600);
28248 +
28249 + /* set the embedded Ethernet PHY in reset state */
28250 + ret = sr_sw_reset(dev, SR_SWRESET_CLEAR);
28251 + if (ret < 0) {
28252 + netdev_err(dev->net, "Failed to power up PHY: %d\n", ret);
28253 + return ret;
28254 + }
28255 + msleep(20);
28256 +
28257 + /* set the embedded Ethernet PHY in power-up state */
28258 + ret = sr_sw_reset(dev, SR_SWRESET_IPRL);
28259 + if (ret < 0) {
28260 + netdev_err(dev->net, "Failed to reset PHY: %d\n", ret);
28261 + return ret;
28262 + }
28263 +
28264 + return 0;
28265 +}
28266 +
28267 +static int sr9800_bind(struct usbnet *dev, struct usb_interface *intf)
28268 +{
28269 + struct sr_data *data = (struct sr_data *)&dev->data;
28270 + u16 led01_mux, led23_mux;
28271 + int ret, embd_phy;
28272 + u32 phyid;
28273 + u16 rx_ctl;
28274 +
28275 + data->eeprom_len = SR9800_EEPROM_LEN;
28276 +
28277 + usbnet_get_endpoints(dev, intf);
28278 +
28279 + /* LED Setting Rule :
28280 + * AABB:CCDD
28281 + * AA : MFA0(LED0)
28282 + * BB : MFA1(LED1)
28283 + * CC : MFA2(LED2), Reserved for SR9800
28284 + * DD : MFA3(LED3), Reserved for SR9800
28285 + */
28286 + led01_mux = (SR_LED_MUX_LINK_ACTIVE << 8) | SR_LED_MUX_LINK;
28287 + led23_mux = (SR_LED_MUX_LINK_ACTIVE << 8) | SR_LED_MUX_TX_ACTIVE;
28288 + ret = sr_write_cmd(dev, SR_CMD_LED_MUX, led01_mux, led23_mux, 0, NULL);
28289 + if (ret < 0) {
28290 + netdev_err(dev->net, "set LINK LED failed : %d\n", ret);
28291 + goto out;
28292 + }
28293 +
28294 + /* Get the MAC address */
28295 + ret = sr_read_cmd(dev, SR_CMD_READ_NODE_ID, 0, 0, ETH_ALEN,
28296 + dev->net->dev_addr);
28297 + if (ret < 0) {
28298 + netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
28299 + return ret;
28300 + }
28301 + netdev_dbg(dev->net, "mac addr : %pM\n", dev->net->dev_addr);
28302 +
28303 + /* Initialize MII structure */
28304 + dev->mii.dev = dev->net;
28305 + dev->mii.mdio_read = sr_mdio_read;
28306 + dev->mii.mdio_write = sr_mdio_write;
28307 + dev->mii.phy_id_mask = 0x1f;
28308 + dev->mii.reg_num_mask = 0x1f;
28309 + dev->mii.phy_id = sr_get_phy_addr(dev);
28310 +
28311 + dev->net->netdev_ops = &sr9800_netdev_ops;
28312 + dev->net->ethtool_ops = &sr9800_ethtool_ops;
28313 +
28314 + embd_phy = ((dev->mii.phy_id & 0x1f) == 0x10 ? 1 : 0);
28315 + /* Reset the PHY to normal operation mode */
28316 + ret = sr_write_cmd(dev, SR_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
28317 + if (ret < 0) {
28318 + netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
28319 + return ret;
28320 + }
28321 +
28322 + /* Init PHY routine */
28323 + ret = sr9800_phy_powerup(dev);
28324 + if (ret < 0)
28325 + goto out;
28326 +
28327 + rx_ctl = sr_read_rx_ctl(dev);
28328 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after software reset\n", rx_ctl);
28329 + ret = sr_write_rx_ctl(dev, 0x0000);
28330 + if (ret < 0)
28331 + goto out;
28332 +
28333 + rx_ctl = sr_read_rx_ctl(dev);
28334 + netdev_dbg(dev->net, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
28335 +
28336 + /* Read PHYID register *AFTER* the PHY was reset properly */
28337 + phyid = sr_get_phyid(dev);
28338 + netdev_dbg(dev->net, "PHYID=0x%08x\n", phyid);
28339 +
28340 + /* medium mode setting */
28341 + ret = sr9800_set_default_mode(dev);
28342 + if (ret < 0)
28343 + goto out;
28344 +
28345 + if (dev->udev->speed == USB_SPEED_HIGH) {
28346 + ret = sr_write_cmd(dev, SR_CMD_BULKIN_SIZE,
28347 + SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_4K].byte_cnt,
28348 + SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_4K].threshold,
28349 + 0, NULL);
28350 + if (ret < 0) {
28351 + netdev_err(dev->net, "Reset RX_CTL failed: %d\n", ret);
28352 + goto out;
28353 + }
28354 + dev->rx_urb_size =
28355 + SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_4K].size;
28356 + } else {
28357 + ret = sr_write_cmd(dev, SR_CMD_BULKIN_SIZE,
28358 + SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_2K].byte_cnt,
28359 + SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_2K].threshold,
28360 + 0, NULL);
28361 + if (ret < 0) {
28362 + netdev_err(dev->net, "Reset RX_CTL failed: %d\n", ret);
28363 + goto out;
28364 + }
28365 + dev->rx_urb_size =
28366 + SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_2K].size;
28367 + }
28368 + netdev_dbg(dev->net, "%s : setting rx_urb_size with : %zu\n", __func__,
28369 + dev->rx_urb_size);
28370 + return 0;
28371 +
28372 +out:
28373 + return ret;
28374 +}
28375 +
28376 +static const struct driver_info sr9800_driver_info = {
28377 + .description = "CoreChip SR9800 USB 2.0 Ethernet",
28378 + .bind = sr9800_bind,
28379 + .status = sr_status,
28380 + .link_reset = sr9800_link_reset,
28381 + .reset = sr9800_reset,
28382 + .flags = DRIVER_FLAG,
28383 + .rx_fixup = sr_rx_fixup,
28384 + .tx_fixup = sr_tx_fixup,
28385 +};
28386 +
28387 +static const struct usb_device_id products[] = {
28388 + {
28389 + USB_DEVICE(0x0fe6, 0x9800), /* SR9800 Device */
28390 + .driver_info = (unsigned long) &sr9800_driver_info,
28391 + },
28392 + {}, /* END */
28393 +};
28394 +
28395 +MODULE_DEVICE_TABLE(usb, products);
28396 +
28397 +static struct usb_driver sr_driver = {
28398 + .name = DRIVER_NAME,
28399 + .id_table = products,
28400 + .probe = usbnet_probe,
28401 + .suspend = usbnet_suspend,
28402 + .resume = usbnet_resume,
28403 + .disconnect = usbnet_disconnect,
28404 + .supports_autosuspend = 1,
28405 +};
28406 +
28407 +module_usb_driver(sr_driver);
28408 +
28409 +MODULE_AUTHOR("Liu Junliang <liujunliang_ljl@163.com");
28410 +MODULE_VERSION(DRIVER_VERSION);
28411 +MODULE_DESCRIPTION("SR9800 USB 2.0 USB2NET Dev : http://www.corechip-sz.com");
28412 +MODULE_LICENSE("GPL");
28413 diff -Naur backports-4.2.6-1.org/drivers/net/usb/sr9800.h backports-4.2.6-1/drivers/net/usb/sr9800.h
28414 --- backports-4.2.6-1.org/drivers/net/usb/sr9800.h 1970-01-01 01:00:00.000000000 +0100
28415 +++ backports-4.2.6-1/drivers/net/usb/sr9800.h 2016-06-28 14:35:18.015307217 +0200
28416 @@ -0,0 +1,202 @@
28417 +/* CoreChip-sz SR9800 one chip USB 2.0 Ethernet Devices
28418 + *
28419 + * Author : Liu Junliang <liujunliang_ljl@163.com>
28420 + *
28421 + * This file is licensed under the terms of the GNU General Public License
28422 + * version 2. This program is licensed "as is" without any warranty of any
28423 + * kind, whether express or implied.
28424 + */
28425 +
28426 +#ifndef _SR9800_H
28427 +#define _SR9800_H
28428 +
28429 +/* SR9800 spec. command table on Linux Platform */
28430 +
28431 +/* command : Software Station Management Control Reg */
28432 +#define SR_CMD_SET_SW_MII 0x06
28433 +/* command : PHY Read Reg */
28434 +#define SR_CMD_READ_MII_REG 0x07
28435 +/* command : PHY Write Reg */
28436 +#define SR_CMD_WRITE_MII_REG 0x08
28437 +/* command : Hardware Station Management Control Reg */
28438 +#define SR_CMD_SET_HW_MII 0x0a
28439 +/* command : SROM Read Reg */
28440 +#define SR_CMD_READ_EEPROM 0x0b
28441 +/* command : SROM Write Reg */
28442 +#define SR_CMD_WRITE_EEPROM 0x0c
28443 +/* command : SROM Write Enable Reg */
28444 +#define SR_CMD_WRITE_ENABLE 0x0d
28445 +/* command : SROM Write Disable Reg */
28446 +#define SR_CMD_WRITE_DISABLE 0x0e
28447 +/* command : RX Control Read Reg */
28448 +#define SR_CMD_READ_RX_CTL 0x0f
28449 +#define SR_RX_CTL_PRO (1 << 0)
28450 +#define SR_RX_CTL_AMALL (1 << 1)
28451 +#define SR_RX_CTL_SEP (1 << 2)
28452 +#define SR_RX_CTL_AB (1 << 3)
28453 +#define SR_RX_CTL_AM (1 << 4)
28454 +#define SR_RX_CTL_AP (1 << 5)
28455 +#define SR_RX_CTL_ARP (1 << 6)
28456 +#define SR_RX_CTL_SO (1 << 7)
28457 +#define SR_RX_CTL_RH1M (1 << 8)
28458 +#define SR_RX_CTL_RH2M (1 << 9)
28459 +#define SR_RX_CTL_RH3M (1 << 10)
28460 +/* command : RX Control Write Reg */
28461 +#define SR_CMD_WRITE_RX_CTL 0x10
28462 +/* command : IPG0/IPG1/IPG2 Control Read Reg */
28463 +#define SR_CMD_READ_IPG012 0x11
28464 +/* command : IPG0/IPG1/IPG2 Control Write Reg */
28465 +#define SR_CMD_WRITE_IPG012 0x12
28466 +/* command : Node ID Read Reg */
28467 +#define SR_CMD_READ_NODE_ID 0x13
28468 +/* command : Node ID Write Reg */
28469 +#define SR_CMD_WRITE_NODE_ID 0x14
28470 +/* command : Multicast Filter Array Read Reg */
28471 +#define SR_CMD_READ_MULTI_FILTER 0x15
28472 +/* command : Multicast Filter Array Write Reg */
28473 +#define SR_CMD_WRITE_MULTI_FILTER 0x16
28474 +/* command : Eth/HomePNA PHY Address Reg */
28475 +#define SR_CMD_READ_PHY_ID 0x19
28476 +/* command : Medium Status Read Reg */
28477 +#define SR_CMD_READ_MEDIUM_STATUS 0x1a
28478 +#define SR_MONITOR_LINK (1 << 1)
28479 +#define SR_MONITOR_MAGIC (1 << 2)
28480 +#define SR_MONITOR_HSFS (1 << 4)
28481 +/* command : Medium Status Write Reg */
28482 +#define SR_CMD_WRITE_MEDIUM_MODE 0x1b
28483 +#define SR_MEDIUM_GM (1 << 0)
28484 +#define SR_MEDIUM_FD (1 << 1)
28485 +#define SR_MEDIUM_AC (1 << 2)
28486 +#define SR_MEDIUM_ENCK (1 << 3)
28487 +#define SR_MEDIUM_RFC (1 << 4)
28488 +#define SR_MEDIUM_TFC (1 << 5)
28489 +#define SR_MEDIUM_JFE (1 << 6)
28490 +#define SR_MEDIUM_PF (1 << 7)
28491 +#define SR_MEDIUM_RE (1 << 8)
28492 +#define SR_MEDIUM_PS (1 << 9)
28493 +#define SR_MEDIUM_RSV (1 << 10)
28494 +#define SR_MEDIUM_SBP (1 << 11)
28495 +#define SR_MEDIUM_SM (1 << 12)
28496 +/* command : Monitor Mode Status Read Reg */
28497 +#define SR_CMD_READ_MONITOR_MODE 0x1c
28498 +/* command : Monitor Mode Status Write Reg */
28499 +#define SR_CMD_WRITE_MONITOR_MODE 0x1d
28500 +/* command : GPIO Status Read Reg */
28501 +#define SR_CMD_READ_GPIOS 0x1e
28502 +#define SR_GPIO_GPO0EN (1 << 0) /* GPIO0 Output enable */
28503 +#define SR_GPIO_GPO_0 (1 << 1) /* GPIO0 Output value */
28504 +#define SR_GPIO_GPO1EN (1 << 2) /* GPIO1 Output enable */
28505 +#define SR_GPIO_GPO_1 (1 << 3) /* GPIO1 Output value */
28506 +#define SR_GPIO_GPO2EN (1 << 4) /* GPIO2 Output enable */
28507 +#define SR_GPIO_GPO_2 (1 << 5) /* GPIO2 Output value */
28508 +#define SR_GPIO_RESERVED (1 << 6) /* Reserved */
28509 +#define SR_GPIO_RSE (1 << 7) /* Reload serial EEPROM */
28510 +/* command : GPIO Status Write Reg */
28511 +#define SR_CMD_WRITE_GPIOS 0x1f
28512 +/* command : Eth PHY Power and Reset Control Reg */
28513 +#define SR_CMD_SW_RESET 0x20
28514 +#define SR_SWRESET_CLEAR 0x00
28515 +#define SR_SWRESET_RR (1 << 0)
28516 +#define SR_SWRESET_RT (1 << 1)
28517 +#define SR_SWRESET_PRTE (1 << 2)
28518 +#define SR_SWRESET_PRL (1 << 3)
28519 +#define SR_SWRESET_BZ (1 << 4)
28520 +#define SR_SWRESET_IPRL (1 << 5)
28521 +#define SR_SWRESET_IPPD (1 << 6)
28522 +/* command : Software Interface Selection Status Read Reg */
28523 +#define SR_CMD_SW_PHY_STATUS 0x21
28524 +/* command : Software Interface Selection Status Write Reg */
28525 +#define SR_CMD_SW_PHY_SELECT 0x22
28526 +/* command : BULK in Buffer Size Reg */
28527 +#define SR_CMD_BULKIN_SIZE 0x2A
28528 +/* command : LED_MUX Control Reg */
28529 +#define SR_CMD_LED_MUX 0x70
28530 +#define SR_LED_MUX_TX_ACTIVE (1 << 0)
28531 +#define SR_LED_MUX_RX_ACTIVE (1 << 1)
28532 +#define SR_LED_MUX_COLLISION (1 << 2)
28533 +#define SR_LED_MUX_DUP_COL (1 << 3)
28534 +#define SR_LED_MUX_DUP (1 << 4)
28535 +#define SR_LED_MUX_SPEED (1 << 5)
28536 +#define SR_LED_MUX_LINK_ACTIVE (1 << 6)
28537 +#define SR_LED_MUX_LINK (1 << 7)
28538 +
28539 +/* Register Access Flags */
28540 +#define SR_REQ_RD_REG (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
28541 +#define SR_REQ_WR_REG (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
28542 +
28543 +/* Multicast Filter Array size & Max Number */
28544 +#define SR_MCAST_FILTER_SIZE 8
28545 +#define SR_MAX_MCAST 64
28546 +
28547 +/* IPG0/1/2 Default Value */
28548 +#define SR9800_IPG0_DEFAULT 0x15
28549 +#define SR9800_IPG1_DEFAULT 0x0c
28550 +#define SR9800_IPG2_DEFAULT 0x12
28551 +
28552 +/* Medium Status Default Mode */
28553 +#define SR9800_MEDIUM_DEFAULT \
28554 + (SR_MEDIUM_FD | SR_MEDIUM_RFC | \
28555 + SR_MEDIUM_TFC | SR_MEDIUM_PS | \
28556 + SR_MEDIUM_AC | SR_MEDIUM_RE)
28557 +
28558 +/* RX Control Default Setting */
28559 +#define SR_DEFAULT_RX_CTL \
28560 + (SR_RX_CTL_SO | SR_RX_CTL_AB | SR_RX_CTL_RH1M)
28561 +
28562 +/* EEPROM Magic Number & EEPROM Size */
28563 +#define SR_EEPROM_MAGIC 0xdeadbeef
28564 +#define SR9800_EEPROM_LEN 0xff
28565 +
28566 +/* SR9800 Driver Version and Driver Name */
28567 +#define DRIVER_VERSION "11-Nov-2013"
28568 +#define DRIVER_NAME "CoreChips"
28569 +#define DRIVER_FLAG \
28570 + (FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR | FLAG_MULTI_PACKET)
28571 +
28572 +/* SR9800 BULKIN Buffer Size */
28573 +#define SR9800_MAX_BULKIN_2K 0
28574 +#define SR9800_MAX_BULKIN_4K 1
28575 +#define SR9800_MAX_BULKIN_6K 2
28576 +#define SR9800_MAX_BULKIN_8K 3
28577 +#define SR9800_MAX_BULKIN_16K 4
28578 +#define SR9800_MAX_BULKIN_20K 5
28579 +#define SR9800_MAX_BULKIN_24K 6
28580 +#define SR9800_MAX_BULKIN_32K 7
28581 +
28582 +struct {unsigned short size, byte_cnt, threshold; } SR9800_BULKIN_SIZE[] = {
28583 + /* 2k */
28584 + {2048, 0x8000, 0x8001},
28585 + /* 4k */
28586 + {4096, 0x8100, 0x8147},
28587 + /* 6k */
28588 + {6144, 0x8200, 0x81EB},
28589 + /* 8k */
28590 + {8192, 0x8300, 0x83D7},
28591 + /* 16 */
28592 + {16384, 0x8400, 0x851E},
28593 + /* 20k */
28594 + {20480, 0x8500, 0x8666},
28595 + /* 24k */
28596 + {24576, 0x8600, 0x87AE},
28597 + /* 32k */
28598 + {32768, 0x8700, 0x8A3D},
28599 +};
28600 +
28601 +/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
28602 +struct sr_data {
28603 + u8 multi_filter[SR_MCAST_FILTER_SIZE];
28604 + u8 mac_addr[ETH_ALEN];
28605 + u8 phymode;
28606 + u8 ledmode;
28607 + u8 eeprom_len;
28608 +};
28609 +
28610 +struct sr9800_int_data {
28611 + __le16 res1;
28612 + u8 link;
28613 + __le16 res2;
28614 + u8 status;
28615 + __le16 res3;
28616 +} __packed;
28617 +
28618 +#endif /* _SR9800_H */
28619 diff -Naur backports-4.2.6-1.org/drivers/net/usb/zaurus.c backports-4.2.6-1/drivers/net/usb/zaurus.c
28620 --- backports-4.2.6-1.org/drivers/net/usb/zaurus.c 1970-01-01 01:00:00.000000000 +0100
28621 +++ backports-4.2.6-1/drivers/net/usb/zaurus.c 2016-06-28 14:35:18.015307217 +0200
28622 @@ -0,0 +1,385 @@
28623 +/*
28624 + * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
28625 + * Copyright (C) 2002-2005 by David Brownell
28626 + *
28627 + * This program is free software; you can redistribute it and/or modify
28628 + * it under the terms of the GNU General Public License as published by
28629 + * the Free Software Foundation; either version 2 of the License, or
28630 + * (at your option) any later version.
28631 + *
28632 + * This program is distributed in the hope that it will be useful,
28633 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28634 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28635 + * GNU General Public License for more details.
28636 + *
28637 + * You should have received a copy of the GNU General Public License
28638 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
28639 + */
28640 +
28641 +// #define DEBUG // error path messages, extra info
28642 +// #define VERBOSE // more; success messages
28643 +
28644 +#include <linux/module.h>
28645 +#include <linux/netdevice.h>
28646 +#include <linux/ethtool.h>
28647 +#include <linux/workqueue.h>
28648 +#include <linux/mii.h>
28649 +#include <linux/crc32.h>
28650 +#include <linux/usb.h>
28651 +#include <linux/usb/cdc.h>
28652 +#include <linux/usb/usbnet.h>
28653 +
28654 +
28655 +/*
28656 + * All known Zaurii lie about their standards conformance. At least
28657 + * the earliest SA-1100 models lie by saying they support CDC Ethernet.
28658 + * Some later models (especially PXA-25x and PXA-27x based ones) lie
28659 + * and say they support CDC MDLM (for access to cell phone modems).
28660 + *
28661 + * There are non-Zaurus products that use these same protocols too.
28662 + *
28663 + * The annoying thing is that at the same time Sharp was developing
28664 + * that annoying standards-breaking software, the Linux community had
28665 + * a simple "CDC Subset" working reliably on the same SA-1100 hardware.
28666 + * That is, the same functionality but not violating standards.
28667 + *
28668 + * The CDC Ethernet nonconformance points are troublesome to hosts
28669 + * with a true CDC Ethernet implementation:
28670 + * - Framing appends a CRC, which the spec says drivers "must not" do;
28671 + * - Transfers data in altsetting zero, instead of altsetting 1;
28672 + * - All these peripherals use the same ethernet address.
28673 + *
28674 + * The CDC MDLM nonconformance is less immediately troublesome, since all
28675 + * MDLM implementations are quasi-proprietary anyway.
28676 + */
28677 +
28678 +static struct sk_buff *
28679 +zaurus_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
28680 +{
28681 + int padlen;
28682 + struct sk_buff *skb2;
28683 +
28684 + padlen = 2;
28685 + if (!skb_cloned(skb)) {
28686 + int tailroom = skb_tailroom(skb);
28687 + if ((padlen + 4) <= tailroom)
28688 + goto done;
28689 + }
28690 + skb2 = skb_copy_expand(skb, 0, 4 + padlen, flags);
28691 + dev_kfree_skb_any(skb);
28692 + skb = skb2;
28693 + if (skb) {
28694 + u32 fcs;
28695 +done:
28696 + fcs = crc32_le(~0, skb->data, skb->len);
28697 + fcs = ~fcs;
28698 +
28699 + *skb_put (skb, 1) = fcs & 0xff;
28700 + *skb_put (skb, 1) = (fcs>> 8) & 0xff;
28701 + *skb_put (skb, 1) = (fcs>>16) & 0xff;
28702 + *skb_put (skb, 1) = (fcs>>24) & 0xff;
28703 + }
28704 + return skb;
28705 +}
28706 +
28707 +static int zaurus_bind(struct usbnet *dev, struct usb_interface *intf)
28708 +{
28709 + /* Belcarra's funky framing has other options; mostly
28710 + * TRAILERS (!) with 4 bytes CRC, and maybe 2 pad bytes.
28711 + */
28712 + dev->net->hard_header_len += 6;
28713 + dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu;
28714 + return usbnet_generic_cdc_bind(dev, intf);
28715 +}
28716 +
28717 +/* PDA style devices are always connected if present */
28718 +static int always_connected (struct usbnet *dev)
28719 +{
28720 + return 0;
28721 +}
28722 +
28723 +static const struct driver_info zaurus_sl5x00_info = {
28724 + .description = "Sharp Zaurus SL-5x00",
28725 + .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_Z,
28726 + .check_connect = always_connected,
28727 + .bind = zaurus_bind,
28728 + .unbind = usbnet_cdc_unbind,
28729 + .tx_fixup = zaurus_tx_fixup,
28730 +};
28731 +#define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
28732 +
28733 +static const struct driver_info zaurus_pxa_info = {
28734 + .description = "Sharp Zaurus, PXA-2xx based",
28735 + .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_Z,
28736 + .check_connect = always_connected,
28737 + .bind = zaurus_bind,
28738 + .unbind = usbnet_cdc_unbind,
28739 + .tx_fixup = zaurus_tx_fixup,
28740 +};
28741 +#define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
28742 +
28743 +static const struct driver_info olympus_mxl_info = {
28744 + .description = "Olympus R1000",
28745 + .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_Z,
28746 + .check_connect = always_connected,
28747 + .bind = zaurus_bind,
28748 + .unbind = usbnet_cdc_unbind,
28749 + .tx_fixup = zaurus_tx_fixup,
28750 +};
28751 +#define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
28752 +
28753 +
28754 +/* Some more recent products using Lineo/Belcarra code will wrongly claim
28755 + * CDC MDLM conformance. They aren't conformant: data endpoints live
28756 + * in the control interface, there's no data interface, and it's not used
28757 + * to talk to a cell phone radio. But at least we can detect these two
28758 + * pseudo-classes, rather than growing this product list with entries for
28759 + * each new nonconformant product (sigh).
28760 + */
28761 +static const u8 safe_guid[16] = {
28762 + 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
28763 + 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
28764 +};
28765 +static const u8 blan_guid[16] = {
28766 + 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70,
28767 + 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37,
28768 +};
28769 +
28770 +static int blan_mdlm_bind(struct usbnet *dev, struct usb_interface *intf)
28771 +{
28772 + u8 *buf = intf->cur_altsetting->extra;
28773 + int len = intf->cur_altsetting->extralen;
28774 + struct usb_cdc_mdlm_desc *desc = NULL;
28775 + struct usb_cdc_mdlm_detail_desc *detail = NULL;
28776 +
28777 + while (len > 3) {
28778 + if (buf [1] != USB_DT_CS_INTERFACE)
28779 + goto next_desc;
28780 +
28781 + /* use bDescriptorSubType, and just verify that we get a
28782 + * "BLAN" (or "SAFE") descriptor.
28783 + */
28784 + switch (buf [2]) {
28785 + case USB_CDC_MDLM_TYPE:
28786 + if (desc) {
28787 + dev_dbg(&intf->dev, "extra MDLM\n");
28788 + goto bad_desc;
28789 + }
28790 + desc = (void *) buf;
28791 + if (desc->bLength != sizeof *desc) {
28792 + dev_dbg(&intf->dev, "MDLM len %u\n",
28793 + desc->bLength);
28794 + goto bad_desc;
28795 + }
28796 + /* expect bcdVersion 1.0, ignore */
28797 + if (memcmp(&desc->bGUID, blan_guid, 16) &&
28798 + memcmp(&desc->bGUID, safe_guid, 16)) {
28799 + /* hey, this one might _really_ be MDLM! */
28800 + dev_dbg(&intf->dev, "MDLM guid\n");
28801 + goto bad_desc;
28802 + }
28803 + break;
28804 + case USB_CDC_MDLM_DETAIL_TYPE:
28805 + if (detail) {
28806 + dev_dbg(&intf->dev, "extra MDLM detail\n");
28807 + goto bad_desc;
28808 + }
28809 + detail = (void *) buf;
28810 + switch (detail->bGuidDescriptorType) {
28811 + case 0: /* "SAFE" */
28812 + if (detail->bLength != (sizeof *detail + 2))
28813 + goto bad_detail;
28814 + break;
28815 + case 1: /* "BLAN" */
28816 + if (detail->bLength != (sizeof *detail + 3))
28817 + goto bad_detail;
28818 + break;
28819 + default:
28820 + goto bad_detail;
28821 + }
28822 +
28823 + /* assuming we either noticed BLAN already, or will
28824 + * find it soon, there are some data bytes here:
28825 + * - bmNetworkCapabilities (unused)
28826 + * - bmDataCapabilities (bits, see below)
28827 + * - bPad (ignored, for PADAFTER -- BLAN-only)
28828 + * bits are:
28829 + * - 0x01 -- Zaurus framing (add CRC)
28830 + * - 0x02 -- PADBEFORE (CRC includes some padding)
28831 + * - 0x04 -- PADAFTER (some padding after CRC)
28832 + * - 0x08 -- "fermat" packet mangling (for hw bugs)
28833 + * the PADBEFORE appears not to matter; we interop
28834 + * with devices that use it and those that don't.
28835 + */
28836 + if ((detail->bDetailData[1] & ~0x02) != 0x01) {
28837 + /* bmDataCapabilities == 0 would be fine too,
28838 + * but framing is minidriver-coupled for now.
28839 + */
28840 +bad_detail:
28841 + dev_dbg(&intf->dev,
28842 + "bad MDLM detail, %d %d %d\n",
28843 + detail->bLength,
28844 + detail->bDetailData[0],
28845 + detail->bDetailData[2]);
28846 + goto bad_desc;
28847 + }
28848 +
28849 + /* same extra framing as for non-BLAN mode */
28850 + dev->net->hard_header_len += 6;
28851 + dev->rx_urb_size = dev->net->hard_header_len
28852 + + dev->net->mtu;
28853 + break;
28854 + }
28855 +next_desc:
28856 + len -= buf [0]; /* bLength */
28857 + buf += buf [0];
28858 + }
28859 +
28860 + if (!desc || !detail) {
28861 + dev_dbg(&intf->dev, "missing cdc mdlm %s%sdescriptor\n",
28862 + desc ? "" : "func ",
28863 + detail ? "" : "detail ");
28864 + goto bad_desc;
28865 + }
28866 +
28867 + /* There's probably a CDC Ethernet descriptor there, but we can't
28868 + * rely on the Ethernet address it provides since not all vendors
28869 + * bother to make it unique. Likewise there's no point in tracking
28870 + * of the CDC event notifications.
28871 + */
28872 + return usbnet_get_endpoints(dev, intf);
28873 +
28874 +bad_desc:
28875 + dev_info(&dev->udev->dev, "unsupported MDLM descriptors\n");
28876 + return -ENODEV;
28877 +}
28878 +
28879 +static const struct driver_info bogus_mdlm_info = {
28880 + .description = "pseudo-MDLM (BLAN) device",
28881 + .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_Z,
28882 + .check_connect = always_connected,
28883 + .tx_fixup = zaurus_tx_fixup,
28884 + .bind = blan_mdlm_bind,
28885 +};
28886 +
28887 +static const struct usb_device_id products [] = {
28888 +#define ZAURUS_MASTER_INTERFACE \
28889 + .bInterfaceClass = USB_CLASS_COMM, \
28890 + .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
28891 + .bInterfaceProtocol = USB_CDC_PROTO_NONE
28892 +
28893 +/* SA-1100 based Sharp Zaurus ("collie"), or compatible. */
28894 +{
28895 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28896 + | USB_DEVICE_ID_MATCH_DEVICE,
28897 + .idVendor = 0x04DD,
28898 + .idProduct = 0x8004,
28899 + ZAURUS_MASTER_INTERFACE,
28900 + .driver_info = ZAURUS_STRONGARM_INFO,
28901 +},
28902 +
28903 +/* PXA-2xx based models are also lying-about-cdc. If you add any
28904 + * more devices that claim to be CDC Ethernet, make sure they get
28905 + * added to the blacklist in cdc_ether too.
28906 + *
28907 + * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries,
28908 + * unlike the older ones with 2.4 "embedix" kernels.
28909 + */
28910 +{
28911 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28912 + | USB_DEVICE_ID_MATCH_DEVICE,
28913 + .idVendor = 0x04DD,
28914 + .idProduct = 0x8005, /* A-300 */
28915 + ZAURUS_MASTER_INTERFACE,
28916 + .driver_info = ZAURUS_PXA_INFO,
28917 +}, {
28918 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28919 + | USB_DEVICE_ID_MATCH_DEVICE,
28920 + .idVendor = 0x04DD,
28921 + .idProduct = 0x8006, /* B-500/SL-5600 */
28922 + ZAURUS_MASTER_INTERFACE,
28923 + .driver_info = ZAURUS_PXA_INFO,
28924 +}, {
28925 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28926 + | USB_DEVICE_ID_MATCH_DEVICE,
28927 + .idVendor = 0x04DD,
28928 + .idProduct = 0x8007, /* C-700 */
28929 + ZAURUS_MASTER_INTERFACE,
28930 + .driver_info = ZAURUS_PXA_INFO,
28931 +}, {
28932 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28933 + | USB_DEVICE_ID_MATCH_DEVICE,
28934 + .idVendor = 0x04DD,
28935 + .idProduct = 0x9031, /* C-750 C-760 */
28936 + ZAURUS_MASTER_INTERFACE,
28937 + .driver_info = ZAURUS_PXA_INFO,
28938 +}, {
28939 + /* C-750/C-760/C-860/SL-C3000 PDA in MDLM mode */
28940 + USB_DEVICE_AND_INTERFACE_INFO(0x04DD, 0x9031, USB_CLASS_COMM,
28941 + USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
28942 + .driver_info = (unsigned long) &bogus_mdlm_info,
28943 +}, {
28944 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28945 + | USB_DEVICE_ID_MATCH_DEVICE,
28946 + .idVendor = 0x04DD,
28947 + .idProduct = 0x9032, /* SL-6000 */
28948 + ZAURUS_MASTER_INTERFACE,
28949 + .driver_info = ZAURUS_PXA_INFO,
28950 +}, {
28951 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28952 + | USB_DEVICE_ID_MATCH_DEVICE,
28953 + .idVendor = 0x04DD,
28954 + /* reported with some C860 units */
28955 + .idProduct = 0x9050, /* C-860 */
28956 + ZAURUS_MASTER_INTERFACE,
28957 + .driver_info = ZAURUS_PXA_INFO,
28958 +},
28959 +{
28960 + /* Motorola Rokr E6 */
28961 + USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x6027, USB_CLASS_COMM,
28962 + USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
28963 + .driver_info = (unsigned long) &bogus_mdlm_info,
28964 +}, {
28965 + /* Motorola MOTOMAGX phones */
28966 + USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x6425, USB_CLASS_COMM,
28967 + USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
28968 + .driver_info = (unsigned long) &bogus_mdlm_info,
28969 +},
28970 +
28971 +/* Olympus has some models with a Zaurus-compatible option.
28972 + * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
28973 + */
28974 +{
28975 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28976 + | USB_DEVICE_ID_MATCH_DEVICE,
28977 + .idVendor = 0x07B4,
28978 + .idProduct = 0x0F02, /* R-1000 */
28979 + ZAURUS_MASTER_INTERFACE,
28980 + .driver_info = OLYMPUS_MXL_INFO,
28981 +},
28982 +
28983 +/* Logitech Harmony 900 - uses the pseudo-MDLM (BLAN) driver */
28984 +{
28985 + USB_DEVICE_AND_INTERFACE_INFO(0x046d, 0xc11f, USB_CLASS_COMM,
28986 + USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
28987 + .driver_info = (unsigned long) &bogus_mdlm_info,
28988 +},
28989 + { }, // END
28990 +};
28991 +MODULE_DEVICE_TABLE(usb, products);
28992 +
28993 +static struct usb_driver zaurus_driver = {
28994 + .name = "zaurus",
28995 + .id_table = products,
28996 + .probe = usbnet_probe,
28997 + .disconnect = usbnet_disconnect,
28998 + .suspend = usbnet_suspend,
28999 + .resume = usbnet_resume,
29000 + .disable_hub_initiated_lpm = 1,
29001 +};
29002 +
29003 +module_usb_driver(zaurus_driver);
29004 +
29005 +MODULE_AUTHOR("Pavel Machek, David Brownell");
29006 +MODULE_DESCRIPTION("Sharp Zaurus PDA, and compatible products");
29007 +MODULE_LICENSE("GPL");