This source file includes following definitions.
- sierra_net_get_private
- sierra_net_set_private
- is_ip
- check_ethip_packet
- save16bit
- save8bit
- parse_hip
- build_hip
- sierra_net_send_cmd
- sierra_net_send_sync
- sierra_net_set_ctx_index
- sierra_net_is_valid_addrlen
- sierra_net_parse_lsi
- sierra_net_handle_lsi
- sierra_net_dosync
- sierra_net_kevent
- sierra_net_defer_kevent
- sierra_sync_timer
- sierra_net_status
- sierra_net_get_drvinfo
- sierra_net_get_link
- sierra_net_get_fw_attr
- sierra_net_bind
- sierra_net_unbind
- sierra_net_skb_clone
- sierra_net_rx_fixup
- sierra_net_tx_fixup
- sierra_net_probe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #define DRIVER_VERSION "v.2.0"
16 #define DRIVER_AUTHOR "Paxton Smith, Matthew Safar, Rory Filer"
17 #define DRIVER_DESC "USB-to-WWAN Driver for Sierra Wireless modems"
18 static const char driver_name[] = "sierra_net";
19
20
21
22
23 #include <linux/module.h>
24 #include <linux/etherdevice.h>
25 #include <linux/ethtool.h>
26 #include <linux/mii.h>
27 #include <linux/sched.h>
28 #include <linux/timer.h>
29 #include <linux/usb.h>
30 #include <linux/usb/cdc.h>
31 #include <net/ip.h>
32 #include <net/udp.h>
33 #include <asm/unaligned.h>
34 #include <linux/usb/usbnet.h>
35
36 #define SWI_USB_REQUEST_GET_FW_ATTR 0x06
37 #define SWI_GET_FW_ATTR_MASK 0x08
38
39
40
41
42 static atomic_t iface_counter = ATOMIC_INIT(0);
43
44
45
46
47 #define SIERRA_NET_SYNCDELAY (2*HZ)
48
49
50 #define SIERRA_NET_MAX_SUPPORTED_MTU 1500
51
52
53
54
55
56 #define SIERRA_NET_USBCTL_BUF_LEN 1024
57
58
59 #define SIERRA_NET_RX_URB_SIZE (8 * 1024)
60
61
62 struct sierra_net_data {
63
64 u16 link_up;
65 u8 tx_hdr_template[4];
66
67 u8 sync_msg[4];
68 u8 shdwn_msg[4];
69
70
71 struct usbnet *usbnet;
72
73 u8 ifnum;
74
75
76 #define SIERRA_NET_EVENT_RESP_AVAIL 0x01
77 #define SIERRA_NET_TIMER_EXPIRY 0x02
78 unsigned long kevent_flags;
79 struct work_struct sierra_net_kevent;
80 struct timer_list sync_timer;
81 };
82
83 struct param {
84 int is_present;
85 union {
86 void *ptr;
87 u32 dword;
88 u16 word;
89 u8 byte;
90 };
91 };
92
93
94 #define SIERRA_NET_HIP_EXTENDEDID 0x7F
95 #define SIERRA_NET_HIP_HSYNC_ID 0x60
96 #define SIERRA_NET_HIP_RESTART_ID 0x62
97 #define SIERRA_NET_HIP_MSYNC_ID 0x20
98 #define SIERRA_NET_HIP_SHUTD_ID 0x26
99
100 #define SIERRA_NET_HIP_EXT_IP_IN_ID 0x0202
101 #define SIERRA_NET_HIP_EXT_IP_OUT_ID 0x0002
102
103
104 #define SIERRA_NET_HIP_LSI_UMTSID 0x78
105
106
107 #define SIERRA_NET_HIP_RCGI 0x64
108
109
110 #define SIERRA_NET_PROTOCOL_UMTS 0x01
111 #define SIERRA_NET_PROTOCOL_UMTS_DS 0x04
112
113 #define SIERRA_NET_COVERAGE_NONE 0x00
114 #define SIERRA_NET_COVERAGE_NOPACKET 0x01
115
116
117 #define SIERRA_NET_SESSION_IDLE 0x00
118
119 #define SIERRA_NET_AS_LINK_TYPE_IPV4 0x00
120 #define SIERRA_NET_AS_LINK_TYPE_IPV6 0x02
121
122 struct lsi_umts {
123 u8 protocol;
124 u8 unused1;
125 __be16 length;
126
127 u8 coverage;
128 u8 network_len;
129 u8 network[40];
130 u8 session_state;
131 u8 unused3[33];
132 } __packed;
133
134 struct lsi_umts_single {
135 struct lsi_umts lsi;
136 u8 link_type;
137 u8 pdp_addr_len;
138 u8 pdp_addr[16];
139 u8 unused4[23];
140 u8 dns1_addr_len;
141 u8 dns1_addr[16];
142 u8 dns2_addr_len;
143 u8 dns2_addr[16];
144 u8 wins1_addr_len;
145 u8 wins1_addr[16];
146 u8 wins2_addr_len;
147 u8 wins2_addr[16];
148 u8 unused5[4];
149 u8 gw_addr_len;
150 u8 gw_addr[16];
151 u8 reserved[8];
152 } __packed;
153
154 struct lsi_umts_dual {
155 struct lsi_umts lsi;
156 u8 pdp_addr4_len;
157 u8 pdp_addr4[4];
158 u8 pdp_addr6_len;
159 u8 pdp_addr6[16];
160 u8 unused4[23];
161 u8 dns1_addr4_len;
162 u8 dns1_addr4[4];
163 u8 dns1_addr6_len;
164 u8 dns1_addr6[16];
165 u8 dns2_addr4_len;
166 u8 dns2_addr4[4];
167 u8 dns2_addr6_len;
168 u8 dns2_addr6[16];
169 u8 unused5[68];
170 } __packed;
171
172 #define SIERRA_NET_LSI_COMMON_LEN 4
173 #define SIERRA_NET_LSI_UMTS_LEN (sizeof(struct lsi_umts_single))
174 #define SIERRA_NET_LSI_UMTS_STATUS_LEN \
175 (SIERRA_NET_LSI_UMTS_LEN - SIERRA_NET_LSI_COMMON_LEN)
176 #define SIERRA_NET_LSI_UMTS_DS_LEN (sizeof(struct lsi_umts_dual))
177 #define SIERRA_NET_LSI_UMTS_DS_STATUS_LEN \
178 (SIERRA_NET_LSI_UMTS_DS_LEN - SIERRA_NET_LSI_COMMON_LEN)
179
180
181 static const struct net_device_ops sierra_net_device_ops = {
182 .ndo_open = usbnet_open,
183 .ndo_stop = usbnet_stop,
184 .ndo_start_xmit = usbnet_start_xmit,
185 .ndo_tx_timeout = usbnet_tx_timeout,
186 .ndo_change_mtu = usbnet_change_mtu,
187 .ndo_get_stats64 = usbnet_get_stats64,
188 .ndo_set_mac_address = eth_mac_addr,
189 .ndo_validate_addr = eth_validate_addr,
190 };
191
192
193 static inline struct sierra_net_data *sierra_net_get_private(struct usbnet *dev)
194 {
195 return (struct sierra_net_data *)dev->data[0];
196 }
197
198
199 static inline void sierra_net_set_private(struct usbnet *dev,
200 struct sierra_net_data *priv)
201 {
202 dev->data[0] = (unsigned long)priv;
203 }
204
205
206 static inline int is_ip(struct sk_buff *skb)
207 {
208 return skb->protocol == cpu_to_be16(ETH_P_IP) ||
209 skb->protocol == cpu_to_be16(ETH_P_IPV6);
210 }
211
212
213
214
215
216
217 static int check_ethip_packet(struct sk_buff *skb, struct usbnet *dev)
218 {
219 skb_reset_mac_header(skb);
220
221 if (skb_is_nonlinear(skb)) {
222 netdev_err(dev->net, "Non linear buffer-dropping\n");
223 return 0;
224 }
225
226 if (!pskb_may_pull(skb, ETH_HLEN))
227 return 0;
228 skb->protocol = eth_hdr(skb)->h_proto;
229
230 return 1;
231 }
232
233 static const u8 *save16bit(struct param *p, const u8 *datap)
234 {
235 p->is_present = 1;
236 p->word = get_unaligned_be16(datap);
237 return datap + sizeof(p->word);
238 }
239
240 static const u8 *save8bit(struct param *p, const u8 *datap)
241 {
242 p->is_present = 1;
243 p->byte = *datap;
244 return datap + sizeof(p->byte);
245 }
246
247
248
249
250
251 #define SIERRA_NET_HIP_HDR_LEN 4
252
253 #define SIERRA_NET_HIP_EXT_HDR_LEN 6
254
255 struct hip_hdr {
256 int hdrlen;
257 struct param payload_len;
258 struct param msgid;
259 struct param msgspecific;
260 struct param extmsgid;
261 };
262
263 static int parse_hip(const u8 *buf, const u32 buflen, struct hip_hdr *hh)
264 {
265 const u8 *curp = buf;
266 int padded;
267
268 if (buflen < SIERRA_NET_HIP_HDR_LEN)
269 return -EPROTO;
270
271 curp = save16bit(&hh->payload_len, curp);
272 curp = save8bit(&hh->msgid, curp);
273 curp = save8bit(&hh->msgspecific, curp);
274
275 padded = hh->msgid.byte & 0x80;
276 hh->msgid.byte &= 0x7F;
277
278 hh->extmsgid.is_present = (hh->msgid.byte == SIERRA_NET_HIP_EXTENDEDID);
279 if (hh->extmsgid.is_present) {
280 if (buflen < SIERRA_NET_HIP_EXT_HDR_LEN)
281 return -EPROTO;
282
283 hh->payload_len.word &= 0x3FFF;
284
285 curp = save16bit(&hh->extmsgid, curp);
286 hh->extmsgid.word &= 0x03FF;
287
288 hh->hdrlen = SIERRA_NET_HIP_EXT_HDR_LEN;
289 } else {
290 hh->payload_len.word &= 0x07FF;
291 hh->hdrlen = SIERRA_NET_HIP_HDR_LEN;
292 }
293
294 if (padded) {
295 hh->hdrlen++;
296 hh->payload_len.word--;
297 }
298
299
300 if (buflen < (hh->hdrlen + hh->payload_len.word))
301 return -EINVAL;
302
303 return 0;
304 }
305
306 static void build_hip(u8 *buf, const u16 payloadlen,
307 struct sierra_net_data *priv)
308 {
309
310
311
312 put_unaligned_be16(payloadlen, buf);
313 memcpy(buf+2, priv->tx_hdr_template, sizeof(priv->tx_hdr_template));
314 }
315
316
317
318
319 static int sierra_net_send_cmd(struct usbnet *dev,
320 u8 *cmd, int cmdlen, const char * cmd_name)
321 {
322 struct sierra_net_data *priv = sierra_net_get_private(dev);
323 int status;
324
325 status = usbnet_write_cmd(dev, USB_CDC_SEND_ENCAPSULATED_COMMAND,
326 USB_DIR_OUT|USB_TYPE_CLASS|USB_RECIP_INTERFACE,
327 0, priv->ifnum, cmd, cmdlen);
328
329 if (status != cmdlen && status != -ENODEV)
330 netdev_err(dev->net, "Submit %s failed %d\n", cmd_name, status);
331
332 return status;
333 }
334
335 static int sierra_net_send_sync(struct usbnet *dev)
336 {
337 int status;
338 struct sierra_net_data *priv = sierra_net_get_private(dev);
339
340 dev_dbg(&dev->udev->dev, "%s", __func__);
341
342 status = sierra_net_send_cmd(dev, priv->sync_msg,
343 sizeof(priv->sync_msg), "SYNC");
344
345 return status;
346 }
347
348 static void sierra_net_set_ctx_index(struct sierra_net_data *priv, u8 ctx_ix)
349 {
350 dev_dbg(&(priv->usbnet->udev->dev), "%s %d", __func__, ctx_ix);
351 priv->tx_hdr_template[0] = 0x3F;
352 priv->tx_hdr_template[1] = ctx_ix;
353 *((__be16 *)&priv->tx_hdr_template[2]) =
354 cpu_to_be16(SIERRA_NET_HIP_EXT_IP_OUT_ID);
355 }
356
357 static inline int sierra_net_is_valid_addrlen(u8 len)
358 {
359 return len == sizeof(struct in_addr);
360 }
361
362 static int sierra_net_parse_lsi(struct usbnet *dev, char *data, int datalen)
363 {
364 struct lsi_umts *lsi = (struct lsi_umts *)data;
365 u32 expected_length;
366
367 if (datalen < sizeof(struct lsi_umts_single)) {
368 netdev_err(dev->net, "%s: Data length %d, exp >= %zu\n",
369 __func__, datalen, sizeof(struct lsi_umts_single));
370 return -1;
371 }
372
373
374 if (lsi->session_state == SIERRA_NET_SESSION_IDLE) {
375 netdev_err(dev->net, "Session idle, 0x%02x\n",
376 lsi->session_state);
377 return 0;
378 }
379
380
381 if (lsi->protocol == SIERRA_NET_PROTOCOL_UMTS) {
382 struct lsi_umts_single *single = (struct lsi_umts_single *)lsi;
383
384
385 if (single->link_type != SIERRA_NET_AS_LINK_TYPE_IPV4 &&
386 single->link_type != SIERRA_NET_AS_LINK_TYPE_IPV6) {
387 netdev_err(dev->net, "Link type unsupported: 0x%02x\n",
388 single->link_type);
389 return -1;
390 }
391 expected_length = SIERRA_NET_LSI_UMTS_STATUS_LEN;
392 } else if (lsi->protocol == SIERRA_NET_PROTOCOL_UMTS_DS) {
393 expected_length = SIERRA_NET_LSI_UMTS_DS_STATUS_LEN;
394 } else {
395 netdev_err(dev->net, "Protocol unsupported, 0x%02x\n",
396 lsi->protocol);
397 return -1;
398 }
399
400 if (be16_to_cpu(lsi->length) != expected_length) {
401 netdev_err(dev->net, "%s: LSI_UMTS_STATUS_LEN %d, exp %u\n",
402 __func__, be16_to_cpu(lsi->length), expected_length);
403 return -1;
404 }
405
406
407 if (lsi->coverage == SIERRA_NET_COVERAGE_NONE ||
408 lsi->coverage == SIERRA_NET_COVERAGE_NOPACKET) {
409 netdev_err(dev->net, "No coverage, 0x%02x\n", lsi->coverage);
410 return 0;
411 }
412
413
414 return 1;
415 }
416
417 static void sierra_net_handle_lsi(struct usbnet *dev, char *data,
418 struct hip_hdr *hh)
419 {
420 struct sierra_net_data *priv = sierra_net_get_private(dev);
421 int link_up;
422
423 link_up = sierra_net_parse_lsi(dev, data + hh->hdrlen,
424 hh->payload_len.word);
425 if (link_up < 0) {
426 netdev_err(dev->net, "Invalid LSI\n");
427 return;
428 }
429 if (link_up) {
430 sierra_net_set_ctx_index(priv, hh->msgspecific.byte);
431 priv->link_up = 1;
432 } else {
433 priv->link_up = 0;
434 }
435 usbnet_link_change(dev, link_up, 0);
436 }
437
438 static void sierra_net_dosync(struct usbnet *dev)
439 {
440 int status;
441 struct sierra_net_data *priv = sierra_net_get_private(dev);
442
443 dev_dbg(&dev->udev->dev, "%s", __func__);
444
445
446
447
448
449
450
451
452
453 status = sierra_net_send_sync(dev);
454 if (status < 0)
455 netdev_err(dev->net,
456 "Send SYNC failed, status %d\n", status);
457 status = sierra_net_send_sync(dev);
458 if (status < 0)
459 netdev_err(dev->net,
460 "Send SYNC failed, status %d\n", status);
461
462
463 priv->sync_timer.expires = jiffies + SIERRA_NET_SYNCDELAY;
464 add_timer(&priv->sync_timer);
465 }
466
467 static void sierra_net_kevent(struct work_struct *work)
468 {
469 struct sierra_net_data *priv =
470 container_of(work, struct sierra_net_data, sierra_net_kevent);
471 struct usbnet *dev = priv->usbnet;
472 int len;
473 int err;
474 u8 *buf;
475 u8 ifnum;
476
477 if (test_bit(SIERRA_NET_EVENT_RESP_AVAIL, &priv->kevent_flags)) {
478 clear_bit(SIERRA_NET_EVENT_RESP_AVAIL, &priv->kevent_flags);
479
480
481 buf = kzalloc(SIERRA_NET_USBCTL_BUF_LEN, GFP_KERNEL);
482 if (!buf)
483 return;
484
485 ifnum = priv->ifnum;
486 len = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
487 USB_CDC_GET_ENCAPSULATED_RESPONSE,
488 USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE,
489 0, ifnum, buf, SIERRA_NET_USBCTL_BUF_LEN,
490 USB_CTRL_SET_TIMEOUT);
491
492 if (len < 0) {
493 netdev_err(dev->net,
494 "usb_control_msg failed, status %d\n", len);
495 } else {
496 struct hip_hdr hh;
497
498 dev_dbg(&dev->udev->dev, "%s: Received status message,"
499 " %04x bytes", __func__, len);
500
501 err = parse_hip(buf, len, &hh);
502 if (err) {
503 netdev_err(dev->net, "%s: Bad packet,"
504 " parse result %d\n", __func__, err);
505 kfree(buf);
506 return;
507 }
508
509
510 if (len != hh.hdrlen + hh.payload_len.word) {
511 netdev_err(dev->net, "%s: Bad packet, received"
512 " %d, expected %d\n", __func__, len,
513 hh.hdrlen + hh.payload_len.word);
514 kfree(buf);
515 return;
516 }
517
518
519 switch (hh.msgid.byte) {
520 case SIERRA_NET_HIP_LSI_UMTSID:
521 dev_dbg(&dev->udev->dev, "LSI for ctx:%d",
522 hh.msgspecific.byte);
523 sierra_net_handle_lsi(dev, buf, &hh);
524 break;
525 case SIERRA_NET_HIP_RESTART_ID:
526 dev_dbg(&dev->udev->dev, "Restart reported: %d,"
527 " stopping sync timer",
528 hh.msgspecific.byte);
529
530 del_timer_sync(&priv->sync_timer);
531 clear_bit(SIERRA_NET_TIMER_EXPIRY,
532 &priv->kevent_flags);
533 break;
534 case SIERRA_NET_HIP_HSYNC_ID:
535 dev_dbg(&dev->udev->dev, "SYNC received");
536 err = sierra_net_send_sync(dev);
537 if (err < 0)
538 netdev_err(dev->net,
539 "Send SYNC failed %d\n", err);
540 break;
541 case SIERRA_NET_HIP_EXTENDEDID:
542 netdev_err(dev->net, "Unrecognized HIP msg, "
543 "extmsgid 0x%04x\n", hh.extmsgid.word);
544 break;
545 case SIERRA_NET_HIP_RCGI:
546
547 break;
548 default:
549 netdev_err(dev->net, "Unrecognized HIP msg, "
550 "msgid 0x%02x\n", hh.msgid.byte);
551 break;
552 }
553 }
554 kfree(buf);
555 }
556
557 if (test_bit(SIERRA_NET_TIMER_EXPIRY, &priv->kevent_flags)) {
558 clear_bit(SIERRA_NET_TIMER_EXPIRY, &priv->kevent_flags);
559 dev_dbg(&dev->udev->dev, "Deferred sync timer expiry");
560 sierra_net_dosync(priv->usbnet);
561 }
562
563 if (priv->kevent_flags)
564 dev_dbg(&dev->udev->dev, "sierra_net_kevent done, "
565 "kevent_flags = 0x%lx", priv->kevent_flags);
566 }
567
568 static void sierra_net_defer_kevent(struct usbnet *dev, int work)
569 {
570 struct sierra_net_data *priv = sierra_net_get_private(dev);
571
572 set_bit(work, &priv->kevent_flags);
573 schedule_work(&priv->sierra_net_kevent);
574 }
575
576
577
578
579 static void sierra_sync_timer(struct timer_list *t)
580 {
581 struct sierra_net_data *priv = from_timer(priv, t, sync_timer);
582 struct usbnet *dev = priv->usbnet;
583
584 dev_dbg(&dev->udev->dev, "%s", __func__);
585
586 sierra_net_defer_kevent(dev, SIERRA_NET_TIMER_EXPIRY);
587 }
588
589 static void sierra_net_status(struct usbnet *dev, struct urb *urb)
590 {
591 struct usb_cdc_notification *event;
592
593 dev_dbg(&dev->udev->dev, "%s", __func__);
594
595 if (urb->actual_length < sizeof *event)
596 return;
597
598
599 event = urb->transfer_buffer;
600 switch (event->bNotificationType) {
601 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
602 case USB_CDC_NOTIFY_SPEED_CHANGE:
603
604 break;
605 case USB_CDC_NOTIFY_RESPONSE_AVAILABLE:
606 sierra_net_defer_kevent(dev, SIERRA_NET_EVENT_RESP_AVAIL);
607 break;
608 default:
609 netdev_err(dev->net, ": unexpected notification %02x!\n",
610 event->bNotificationType);
611 break;
612 }
613 }
614
615 static void sierra_net_get_drvinfo(struct net_device *net,
616 struct ethtool_drvinfo *info)
617 {
618
619 usbnet_get_drvinfo(net, info);
620 strlcpy(info->driver, driver_name, sizeof(info->driver));
621 strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
622 }
623
624 static u32 sierra_net_get_link(struct net_device *net)
625 {
626 struct usbnet *dev = netdev_priv(net);
627
628 return sierra_net_get_private(dev)->link_up && netif_running(net);
629 }
630
631 static const struct ethtool_ops sierra_net_ethtool_ops = {
632 .get_drvinfo = sierra_net_get_drvinfo,
633 .get_link = sierra_net_get_link,
634 .get_msglevel = usbnet_get_msglevel,
635 .set_msglevel = usbnet_set_msglevel,
636 .nway_reset = usbnet_nway_reset,
637 .get_link_ksettings = usbnet_get_link_ksettings,
638 .set_link_ksettings = usbnet_set_link_ksettings,
639 };
640
641 static int sierra_net_get_fw_attr(struct usbnet *dev, u16 *datap)
642 {
643 int result = 0;
644 __le16 attrdata;
645
646 result = usbnet_read_cmd(dev,
647
648 SWI_USB_REQUEST_GET_FW_ATTR,
649 USB_DIR_IN | USB_TYPE_VENDOR,
650 0x0000,
651 0x0000,
652 &attrdata,
653 sizeof(attrdata)
654 );
655
656 if (result < 0)
657 return -EIO;
658
659 *datap = le16_to_cpu(attrdata);
660 return result;
661 }
662
663
664
665
666 static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
667 {
668 u8 ifacenum;
669 u8 numendpoints;
670 u16 fwattr = 0;
671 int status;
672 struct sierra_net_data *priv;
673 static const u8 sync_tmplate[sizeof(priv->sync_msg)] = {
674 0x00, 0x00, SIERRA_NET_HIP_MSYNC_ID, 0x00};
675 static const u8 shdwn_tmplate[sizeof(priv->shdwn_msg)] = {
676 0x00, 0x00, SIERRA_NET_HIP_SHUTD_ID, 0x00};
677
678 dev_dbg(&dev->udev->dev, "%s", __func__);
679
680 ifacenum = intf->cur_altsetting->desc.bInterfaceNumber;
681 numendpoints = intf->cur_altsetting->desc.bNumEndpoints;
682
683 if (numendpoints != 3) {
684 dev_err(&dev->udev->dev, "Expected 3 endpoints, found: %d",
685 numendpoints);
686 return -ENODEV;
687 }
688
689 dev->status = NULL;
690 status = usbnet_get_endpoints(dev, intf);
691 if (status < 0) {
692 dev_err(&dev->udev->dev, "Error in usbnet_get_endpoints (%d)",
693 status);
694 return -ENODEV;
695 }
696
697 priv = kzalloc(sizeof *priv, GFP_KERNEL);
698 if (!priv)
699 return -ENOMEM;
700
701 priv->usbnet = dev;
702 priv->ifnum = ifacenum;
703 dev->net->netdev_ops = &sierra_net_device_ops;
704
705
706 dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
707 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
708
709
710 memcpy(priv->shdwn_msg, shdwn_tmplate, sizeof(priv->shdwn_msg));
711
712 sierra_net_set_ctx_index(priv, 0);
713
714
715 memcpy(priv->sync_msg, sync_tmplate, sizeof(priv->sync_msg));
716
717
718 dev->rx_urb_size = SIERRA_NET_RX_URB_SIZE;
719 if (dev->udev->speed != USB_SPEED_HIGH)
720 dev->rx_urb_size = min_t(size_t, 4096, SIERRA_NET_RX_URB_SIZE);
721
722 dev->net->hard_header_len += SIERRA_NET_HIP_EXT_HDR_LEN;
723 dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
724 dev->net->max_mtu = SIERRA_NET_MAX_SUPPORTED_MTU;
725
726
727 dev->net->flags |= IFF_NOARP;
728 dev->net->ethtool_ops = &sierra_net_ethtool_ops;
729 netif_carrier_off(dev->net);
730
731 sierra_net_set_private(dev, priv);
732
733 priv->kevent_flags = 0;
734
735
736 INIT_WORK(&priv->sierra_net_kevent, sierra_net_kevent);
737
738
739 timer_setup(&priv->sync_timer, sierra_sync_timer, 0);
740
741
742 status = sierra_net_get_fw_attr(dev, &fwattr);
743 dev_dbg(&dev->udev->dev, "Fw attr: %x\n", fwattr);
744
745
746 if (!(status == sizeof(fwattr) && (fwattr & SWI_GET_FW_ATTR_MASK))) {
747
748 dev_err(&dev->udev->dev, "Incompatible driver and firmware"
749 " versions\n");
750 kfree(priv);
751 return -ENODEV;
752 }
753
754 return 0;
755 }
756
757 static void sierra_net_unbind(struct usbnet *dev, struct usb_interface *intf)
758 {
759 int status;
760 struct sierra_net_data *priv = sierra_net_get_private(dev);
761
762 dev_dbg(&dev->udev->dev, "%s", __func__);
763
764
765 del_timer_sync(&priv->sync_timer);
766 cancel_work_sync(&priv->sierra_net_kevent);
767
768
769 status = sierra_net_send_cmd(dev, priv->shdwn_msg,
770 sizeof(priv->shdwn_msg), "Shutdown");
771 if (status < 0)
772 netdev_err(dev->net,
773 "usb_control_msg failed, status %d\n", status);
774
775 usbnet_status_stop(dev);
776
777 sierra_net_set_private(dev, NULL);
778 kfree(priv);
779 }
780
781 static struct sk_buff *sierra_net_skb_clone(struct usbnet *dev,
782 struct sk_buff *skb, int len)
783 {
784 struct sk_buff *new_skb;
785
786
787 new_skb = skb_clone(skb, GFP_ATOMIC);
788
789
790 skb_pull(skb, len);
791
792
793 if (new_skb) {
794 skb_trim(new_skb, len);
795 } else {
796 if (netif_msg_rx_err(dev))
797 netdev_err(dev->net, "failed to get skb\n");
798 dev->net->stats.rx_dropped++;
799 }
800
801 return new_skb;
802 }
803
804
805 static int sierra_net_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
806 {
807 int err;
808 struct hip_hdr hh;
809 struct sk_buff *new_skb;
810
811 dev_dbg(&dev->udev->dev, "%s", __func__);
812
813
814 while (likely(skb->len)) {
815 err = parse_hip(skb->data, skb->len, &hh);
816 if (err) {
817 if (netif_msg_rx_err(dev))
818 netdev_err(dev->net, "Invalid HIP header %d\n",
819 err);
820
821 dev->net->stats.rx_length_errors++;
822 return 0;
823 }
824
825
826 if (!hh.extmsgid.is_present
827 || hh.extmsgid.word != SIERRA_NET_HIP_EXT_IP_IN_ID) {
828 if (netif_msg_rx_err(dev))
829 netdev_err(dev->net, "HIP/ETH: Invalid pkt\n");
830
831 dev->net->stats.rx_frame_errors++;
832
833 return 0;
834 }
835
836 skb_pull(skb, hh.hdrlen);
837
838
839
840
841 skb_reset_mac_header(skb);
842 if (eth_hdr(skb)->h_proto != cpu_to_be16(ETH_P_IPV6))
843 eth_hdr(skb)->h_proto = cpu_to_be16(ETH_P_IP);
844 eth_zero_addr(eth_hdr(skb)->h_source);
845 memcpy(eth_hdr(skb)->h_dest, dev->net->dev_addr, ETH_ALEN);
846
847
848 if (hh.payload_len.word == skb->len)
849 return 1;
850
851 new_skb = sierra_net_skb_clone(dev, skb, hh.payload_len.word);
852 if (new_skb)
853 usbnet_skb_return(dev, new_skb);
854
855 }
856
857 return 0;
858 }
859
860
861 static struct sk_buff *sierra_net_tx_fixup(struct usbnet *dev,
862 struct sk_buff *skb, gfp_t flags)
863 {
864 struct sierra_net_data *priv = sierra_net_get_private(dev);
865 u16 len;
866 bool need_tail;
867
868 BUILD_BUG_ON(FIELD_SIZEOF(struct usbnet, data)
869 < sizeof(struct cdc_state));
870
871 dev_dbg(&dev->udev->dev, "%s", __func__);
872 if (priv->link_up && check_ethip_packet(skb, dev) && is_ip(skb)) {
873
874 if (SIERRA_NET_HIP_EXT_HDR_LEN <= skb_headroom(skb)) {
875
876 len = skb->len;
877 skb_push(skb, SIERRA_NET_HIP_EXT_HDR_LEN);
878
879 need_tail = ((len + SIERRA_NET_HIP_EXT_HDR_LEN)
880 % dev->maxpacket == 0);
881 if (need_tail) {
882 if (unlikely(skb_tailroom(skb) == 0)) {
883 netdev_err(dev->net, "tx_fixup:"
884 "no room for packet\n");
885 dev_kfree_skb_any(skb);
886 return NULL;
887 } else {
888 skb->data[skb->len] = 0;
889 __skb_put(skb, 1);
890 len = len + 1;
891 }
892 }
893 build_hip(skb->data, len, priv);
894 return skb;
895 } else {
896
897
898
899 netdev_err(dev->net, "tx_fixup: no room for HIP\n");
900 }
901 }
902
903 if (!priv->link_up)
904 dev->net->stats.tx_carrier_errors++;
905
906
907
908
909 dev_kfree_skb_any(skb);
910 return NULL;
911 }
912
913 static const struct driver_info sierra_net_info_direct_ip = {
914 .description = "Sierra Wireless USB-to-WWAN Modem",
915 .flags = FLAG_WWAN | FLAG_SEND_ZLP,
916 .bind = sierra_net_bind,
917 .unbind = sierra_net_unbind,
918 .status = sierra_net_status,
919 .rx_fixup = sierra_net_rx_fixup,
920 .tx_fixup = sierra_net_tx_fixup,
921 };
922
923 static int
924 sierra_net_probe(struct usb_interface *udev, const struct usb_device_id *prod)
925 {
926 int ret;
927
928 ret = usbnet_probe(udev, prod);
929 if (ret == 0) {
930 struct usbnet *dev = usb_get_intfdata(udev);
931
932 ret = usbnet_status_start(dev, GFP_KERNEL);
933 if (ret == 0) {
934
935 sierra_net_dosync(dev);
936 }
937 }
938 return ret;
939 }
940
941 #define DIRECT_IP_DEVICE(vend, prod) \
942 {USB_DEVICE_INTERFACE_NUMBER(vend, prod, 7), \
943 .driver_info = (unsigned long)&sierra_net_info_direct_ip}, \
944 {USB_DEVICE_INTERFACE_NUMBER(vend, prod, 10), \
945 .driver_info = (unsigned long)&sierra_net_info_direct_ip}, \
946 {USB_DEVICE_INTERFACE_NUMBER(vend, prod, 11), \
947 .driver_info = (unsigned long)&sierra_net_info_direct_ip}
948
949 static const struct usb_device_id products[] = {
950 DIRECT_IP_DEVICE(0x1199, 0x68A3),
951 DIRECT_IP_DEVICE(0x0F3D, 0x68A3),
952 DIRECT_IP_DEVICE(0x1199, 0x68AA),
953 DIRECT_IP_DEVICE(0x0F3D, 0x68AA),
954
955 {},
956 };
957 MODULE_DEVICE_TABLE(usb, products);
958
959
960 static struct usb_driver sierra_net_driver = {
961 .name = "sierra_net",
962 .id_table = products,
963 .probe = sierra_net_probe,
964 .disconnect = usbnet_disconnect,
965 .suspend = usbnet_suspend,
966 .resume = usbnet_resume,
967 .no_dynamic_id = 1,
968 .disable_hub_initiated_lpm = 1,
969 };
970
971 module_usb_driver(sierra_net_driver);
972
973 MODULE_AUTHOR(DRIVER_AUTHOR);
974 MODULE_DESCRIPTION(DRIVER_DESC);
975 MODULE_VERSION(DRIVER_VERSION);
976 MODULE_LICENSE("GPL");