2 * USB-to-WWAN Driver for Sierra Wireless modems
4 * Copyright (C) 2008, 2009, 2010 Paxton Smith, Matthew Safar, Rory Filer
5 * <linux@sierrawireless.com>
7 * Portions of this based on the cdc_ether driver by David Brownell (2003-2005)
8 * and Ole Andre Vadla Ravnas (ActiveSync) (2006).
10 * IMPORTANT DISCLAIMER: This driver is not commercially supported by
11 * Sierra Wireless. Use at your own risk.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 #define DRIVER_VERSION "v.2.0"
28 #define DRIVER_AUTHOR "Paxton Smith, Matthew Safar, Rory Filer"
29 #define DRIVER_DESC "USB-to-WWAN Driver for Sierra Wireless modems"
30 static const char driver_name[] = "sierra_net";
32 /* if defined debug messages enabled */
35 #include <linux/module.h>
36 #include <linux/etherdevice.h>
37 #include <linux/ethtool.h>
38 #include <linux/mii.h>
39 #include <linux/sched.h>
40 #include <linux/timer.h>
41 #include <linux/usb.h>
42 #include <linux/usb/cdc.h>
45 #include <asm/unaligned.h>
46 #include <linux/usb/usbnet.h>
48 #define SWI_USB_REQUEST_GET_FW_ATTR 0x06
49 #define SWI_GET_FW_ATTR_MASK 0x08
51 /* atomic counter partially included in MAC address to make sure 2 devices
52 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
54 static atomic_t iface_counter = ATOMIC_INIT(0);
57 * SYNC Timer Delay definition used to set the expiry time
59 #define SIERRA_NET_SYNCDELAY (2*HZ)
61 /* Max. MTU supported. The modem buffers are limited to 1500 */
62 #define SIERRA_NET_MAX_SUPPORTED_MTU 1500
64 /* The SIERRA_NET_USBCTL_BUF_LEN defines a buffer size allocated for control
65 * message reception ... and thus the max. received packet.
66 * (May be the cause for parse_hip returning -EINVAL)
68 #define SIERRA_NET_USBCTL_BUF_LEN 1024
70 /* Overriding the default usbnet rx_urb_size */
71 #define SIERRA_NET_RX_URB_SIZE (8 * 1024)
73 /* Private data structure */
74 struct sierra_net_data {
76 u8 ethr_hdr_tmpl[ETH_HLEN]; /* ethernet header template for rx'd pkts */
78 u16 link_up; /* air link up or down */
79 u8 tx_hdr_template[4]; /* part of HIP hdr for tx'd packets */
81 u8 sync_msg[4]; /* SYNC message */
82 u8 shdwn_msg[4]; /* Shutdown message */
84 /* Backpointer to the container */
85 struct usbnet *usbnet;
87 u8 ifnum; /* interface number */
89 /* Bit masks, must be a power of 2 */
90 #define SIERRA_NET_EVENT_RESP_AVAIL 0x01
91 #define SIERRA_NET_TIMER_EXPIRY 0x02
92 unsigned long kevent_flags;
93 struct work_struct sierra_net_kevent;
94 struct timer_list sync_timer; /* For retrying SYNC sequence */
107 /* HIP message type */
108 #define SIERRA_NET_HIP_EXTENDEDID 0x7F
109 #define SIERRA_NET_HIP_HSYNC_ID 0x60 /* Modem -> host */
110 #define SIERRA_NET_HIP_RESTART_ID 0x62 /* Modem -> host */
111 #define SIERRA_NET_HIP_MSYNC_ID 0x20 /* Host -> modem */
112 #define SIERRA_NET_HIP_SHUTD_ID 0x26 /* Host -> modem */
114 #define SIERRA_NET_HIP_EXT_IP_IN_ID 0x0202
115 #define SIERRA_NET_HIP_EXT_IP_OUT_ID 0x0002
117 /* 3G UMTS Link Sense Indication definitions */
118 #define SIERRA_NET_HIP_LSI_UMTSID 0x78
120 /* Reverse Channel Grant Indication HIP message */
121 #define SIERRA_NET_HIP_RCGI 0x64
123 /* LSI Protocol types */
124 #define SIERRA_NET_PROTOCOL_UMTS 0x01
126 #define SIERRA_NET_COVERAGE_NONE 0x00
127 #define SIERRA_NET_COVERAGE_NOPACKET 0x01
130 #define SIERRA_NET_SESSION_IDLE 0x00
132 #define SIERRA_NET_AS_LINK_TYPE_IPv4 0x00
138 /* eventually use a union for the rest - assume umts for now */
144 u8 pdp_addr_len; /* NW-supplied PDP address len */
145 u8 pdp_addr[16]; /* NW-supplied PDP address (bigendian)) */
147 u8 dns1_addr_len; /* NW-supplied 1st DNS address len (bigendian) */
148 u8 dns1_addr[16]; /* NW-supplied 1st DNS address */
149 u8 dns2_addr_len; /* NW-supplied 2nd DNS address len */
150 u8 dns2_addr[16]; /* NW-supplied 2nd DNS address (bigendian)*/
151 u8 wins1_addr_len; /* NW-supplied 1st Wins address len */
152 u8 wins1_addr[16]; /* NW-supplied 1st Wins address (bigendian)*/
153 u8 wins2_addr_len; /* NW-supplied 2nd Wins address len */
154 u8 wins2_addr[16]; /* NW-supplied 2nd Wins address (bigendian) */
156 u8 gw_addr_len; /* NW-supplied GW address len */
157 u8 gw_addr[16]; /* NW-supplied GW address (bigendian) */
161 #define SIERRA_NET_LSI_COMMON_LEN 4
162 #define SIERRA_NET_LSI_UMTS_LEN (sizeof(struct lsi_umts))
163 #define SIERRA_NET_LSI_UMTS_STATUS_LEN \
164 (SIERRA_NET_LSI_UMTS_LEN - SIERRA_NET_LSI_COMMON_LEN)
166 /* Forward definitions */
167 static void sierra_sync_timer(unsigned long syncdata);
169 /* Our own net device operations structure */
170 static const struct net_device_ops sierra_net_device_ops = {
171 .ndo_open = usbnet_open,
172 .ndo_stop = usbnet_stop,
173 .ndo_start_xmit = usbnet_start_xmit,
174 .ndo_tx_timeout = usbnet_tx_timeout,
175 .ndo_change_mtu = usbnet_change_mtu,
176 .ndo_set_mac_address = eth_mac_addr,
177 .ndo_validate_addr = eth_validate_addr,
180 /* get private data associated with passed in usbnet device */
181 static inline struct sierra_net_data *sierra_net_get_private(struct usbnet *dev)
183 return (struct sierra_net_data *)dev->data[0];
186 /* set private data associated with passed in usbnet device */
187 static inline void sierra_net_set_private(struct usbnet *dev,
188 struct sierra_net_data *priv)
190 dev->data[0] = (unsigned long)priv;
194 static inline int is_ip(struct sk_buff *skb)
196 return skb->protocol == cpu_to_be16(ETH_P_IP);
200 * check passed in packet and make sure that:
201 * - it is linear (no scatter/gather)
202 * - it is ethernet (mac_header properly set)
204 static int check_ethip_packet(struct sk_buff *skb, struct usbnet *dev)
206 skb_reset_mac_header(skb); /* ethernet header */
208 if (skb_is_nonlinear(skb)) {
209 netdev_err(dev->net, "Non linear buffer-dropping\n");
213 if (!pskb_may_pull(skb, ETH_HLEN))
215 skb->protocol = eth_hdr(skb)->h_proto;
220 static const u8 *save16bit(struct param *p, const u8 *datap)
223 p->word = get_unaligned_be16(datap);
224 return datap + sizeof(p->word);
227 static const u8 *save8bit(struct param *p, const u8 *datap)
231 return datap + sizeof(p->byte);
234 /*----------------------------------------------------------------------------*
236 *----------------------------------------------------------------------------*/
238 #define SIERRA_NET_HIP_HDR_LEN 4
239 /* Extended HIP header */
240 #define SIERRA_NET_HIP_EXT_HDR_LEN 6
244 struct param payload_len;
246 struct param msgspecific;
247 struct param extmsgid;
250 static int parse_hip(const u8 *buf, const u32 buflen, struct hip_hdr *hh)
252 const u8 *curp = buf;
255 if (buflen < SIERRA_NET_HIP_HDR_LEN)
258 curp = save16bit(&hh->payload_len, curp);
259 curp = save8bit(&hh->msgid, curp);
260 curp = save8bit(&hh->msgspecific, curp);
262 padded = hh->msgid.byte & 0x80;
263 hh->msgid.byte &= 0x7F; /* 7 bits */
265 hh->extmsgid.is_present = (hh->msgid.byte == SIERRA_NET_HIP_EXTENDEDID);
266 if (hh->extmsgid.is_present) {
267 if (buflen < SIERRA_NET_HIP_EXT_HDR_LEN)
270 hh->payload_len.word &= 0x3FFF; /* 14 bits */
272 curp = save16bit(&hh->extmsgid, curp);
273 hh->extmsgid.word &= 0x03FF; /* 10 bits */
275 hh->hdrlen = SIERRA_NET_HIP_EXT_HDR_LEN;
277 hh->payload_len.word &= 0x07FF; /* 11 bits */
278 hh->hdrlen = SIERRA_NET_HIP_HDR_LEN;
283 hh->payload_len.word--;
286 /* if real packet shorter than the claimed length */
287 if (buflen < (hh->hdrlen + hh->payload_len.word))
293 static void build_hip(u8 *buf, const u16 payloadlen,
294 struct sierra_net_data *priv)
296 /* the following doesn't have the full functionality. We
297 * currently build only one kind of header, so it is faster this way
299 put_unaligned_be16(payloadlen, buf);
300 memcpy(buf+2, priv->tx_hdr_template, sizeof(priv->tx_hdr_template));
302 /*----------------------------------------------------------------------------*
304 *----------------------------------------------------------------------------*/
306 static int sierra_net_send_cmd(struct usbnet *dev,
307 u8 *cmd, int cmdlen, const char * cmd_name)
309 struct sierra_net_data *priv = sierra_net_get_private(dev);
312 status = usbnet_write_cmd(dev, USB_CDC_SEND_ENCAPSULATED_COMMAND,
313 USB_DIR_OUT|USB_TYPE_CLASS|USB_RECIP_INTERFACE,
314 0, priv->ifnum, cmd, cmdlen);
316 if (status != cmdlen && status != -ENODEV)
317 netdev_err(dev->net, "Submit %s failed %d\n", cmd_name, status);
322 static int sierra_net_send_sync(struct usbnet *dev)
325 struct sierra_net_data *priv = sierra_net_get_private(dev);
327 dev_dbg(&dev->udev->dev, "%s", __func__);
329 status = sierra_net_send_cmd(dev, priv->sync_msg,
330 sizeof(priv->sync_msg), "SYNC");
335 static void sierra_net_set_ctx_index(struct sierra_net_data *priv, u8 ctx_ix)
337 dev_dbg(&(priv->usbnet->udev->dev), "%s %d", __func__, ctx_ix);
338 priv->tx_hdr_template[0] = 0x3F;
339 priv->tx_hdr_template[1] = ctx_ix;
340 *((__be16 *)&priv->tx_hdr_template[2]) =
341 cpu_to_be16(SIERRA_NET_HIP_EXT_IP_OUT_ID);
344 static inline int sierra_net_is_valid_addrlen(u8 len)
346 return len == sizeof(struct in_addr);
349 static int sierra_net_parse_lsi(struct usbnet *dev, char *data, int datalen)
351 struct lsi_umts *lsi = (struct lsi_umts *)data;
353 if (datalen < sizeof(struct lsi_umts)) {
354 netdev_err(dev->net, "%s: Data length %d, exp %Zu\n",
356 sizeof(struct lsi_umts));
360 if (lsi->length != cpu_to_be16(SIERRA_NET_LSI_UMTS_STATUS_LEN)) {
361 netdev_err(dev->net, "%s: LSI_UMTS_STATUS_LEN %d, exp %u\n",
362 __func__, be16_to_cpu(lsi->length),
363 (u32)SIERRA_NET_LSI_UMTS_STATUS_LEN);
367 /* Validate the protocol - only support UMTS for now */
368 if (lsi->protocol != SIERRA_NET_PROTOCOL_UMTS) {
369 netdev_err(dev->net, "Protocol unsupported, 0x%02x\n",
374 /* Validate the link type */
375 if (lsi->link_type != SIERRA_NET_AS_LINK_TYPE_IPv4) {
376 netdev_err(dev->net, "Link type unsupported: 0x%02x\n",
381 /* Validate the coverage */
382 if (lsi->coverage == SIERRA_NET_COVERAGE_NONE
383 || lsi->coverage == SIERRA_NET_COVERAGE_NOPACKET) {
384 netdev_err(dev->net, "No coverage, 0x%02x\n", lsi->coverage);
388 /* Validate the session state */
389 if (lsi->session_state == SIERRA_NET_SESSION_IDLE) {
390 netdev_err(dev->net, "Session idle, 0x%02x\n",
395 /* Set link_sense true */
399 static void sierra_net_handle_lsi(struct usbnet *dev, char *data,
402 struct sierra_net_data *priv = sierra_net_get_private(dev);
405 link_up = sierra_net_parse_lsi(dev, data + hh->hdrlen,
406 hh->payload_len.word);
408 netdev_err(dev->net, "Invalid LSI\n");
412 sierra_net_set_ctx_index(priv, hh->msgspecific.byte);
417 usbnet_link_change(dev, link_up, 0);
420 static void sierra_net_dosync(struct usbnet *dev)
423 struct sierra_net_data *priv = sierra_net_get_private(dev);
425 dev_dbg(&dev->udev->dev, "%s", __func__);
427 /* The SIERRA_NET_HIP_MSYNC_ID command appears to request that the
428 * firmware restart itself. After restarting, the modem will respond
429 * with the SIERRA_NET_HIP_RESTART_ID indication. The driver continues
430 * sending MSYNC commands every few seconds until it receives the
431 * RESTART event from the firmware
434 /* tell modem we are ready */
435 status = sierra_net_send_sync(dev);
438 "Send SYNC failed, status %d\n", status);
439 status = sierra_net_send_sync(dev);
442 "Send SYNC failed, status %d\n", status);
444 /* Now, start a timer and make sure we get the Restart Indication */
445 priv->sync_timer.function = sierra_sync_timer;
446 priv->sync_timer.data = (unsigned long) dev;
447 priv->sync_timer.expires = jiffies + SIERRA_NET_SYNCDELAY;
448 add_timer(&priv->sync_timer);
451 static void sierra_net_kevent(struct work_struct *work)
453 struct sierra_net_data *priv =
454 container_of(work, struct sierra_net_data, sierra_net_kevent);
455 struct usbnet *dev = priv->usbnet;
461 if (test_bit(SIERRA_NET_EVENT_RESP_AVAIL, &priv->kevent_flags)) {
462 clear_bit(SIERRA_NET_EVENT_RESP_AVAIL, &priv->kevent_flags);
464 /* Query the modem for the LSI message */
465 buf = kzalloc(SIERRA_NET_USBCTL_BUF_LEN, GFP_KERNEL);
470 len = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
471 USB_CDC_GET_ENCAPSULATED_RESPONSE,
472 USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE,
473 0, ifnum, buf, SIERRA_NET_USBCTL_BUF_LEN,
474 USB_CTRL_SET_TIMEOUT);
478 "usb_control_msg failed, status %d\n", len);
482 dev_dbg(&dev->udev->dev, "%s: Received status message,"
483 " %04x bytes", __func__, len);
485 err = parse_hip(buf, len, &hh);
487 netdev_err(dev->net, "%s: Bad packet,"
488 " parse result %d\n", __func__, err);
493 /* Validate packet length */
494 if (len != hh.hdrlen + hh.payload_len.word) {
495 netdev_err(dev->net, "%s: Bad packet, received"
496 " %d, expected %d\n", __func__, len,
497 hh.hdrlen + hh.payload_len.word);
502 /* Switch on received message types */
503 switch (hh.msgid.byte) {
504 case SIERRA_NET_HIP_LSI_UMTSID:
505 dev_dbg(&dev->udev->dev, "LSI for ctx:%d",
506 hh.msgspecific.byte);
507 sierra_net_handle_lsi(dev, buf, &hh);
509 case SIERRA_NET_HIP_RESTART_ID:
510 dev_dbg(&dev->udev->dev, "Restart reported: %d,"
511 " stopping sync timer",
512 hh.msgspecific.byte);
513 /* Got sync resp - stop timer & clear mask */
514 del_timer_sync(&priv->sync_timer);
515 clear_bit(SIERRA_NET_TIMER_EXPIRY,
516 &priv->kevent_flags);
518 case SIERRA_NET_HIP_HSYNC_ID:
519 dev_dbg(&dev->udev->dev, "SYNC received");
520 err = sierra_net_send_sync(dev);
523 "Send SYNC failed %d\n", err);
525 case SIERRA_NET_HIP_EXTENDEDID:
526 netdev_err(dev->net, "Unrecognized HIP msg, "
527 "extmsgid 0x%04x\n", hh.extmsgid.word);
529 case SIERRA_NET_HIP_RCGI:
533 netdev_err(dev->net, "Unrecognized HIP msg, "
534 "msgid 0x%02x\n", hh.msgid.byte);
540 /* The sync timer bit might be set */
541 if (test_bit(SIERRA_NET_TIMER_EXPIRY, &priv->kevent_flags)) {
542 clear_bit(SIERRA_NET_TIMER_EXPIRY, &priv->kevent_flags);
543 dev_dbg(&dev->udev->dev, "Deferred sync timer expiry");
544 sierra_net_dosync(priv->usbnet);
547 if (priv->kevent_flags)
548 dev_dbg(&dev->udev->dev, "sierra_net_kevent done, "
549 "kevent_flags = 0x%lx", priv->kevent_flags);
552 static void sierra_net_defer_kevent(struct usbnet *dev, int work)
554 struct sierra_net_data *priv = sierra_net_get_private(dev);
556 set_bit(work, &priv->kevent_flags);
557 schedule_work(&priv->sierra_net_kevent);
561 * Sync Retransmit Timer Handler. On expiry, kick the work queue
563 static void sierra_sync_timer(unsigned long syncdata)
565 struct usbnet *dev = (struct usbnet *)syncdata;
567 dev_dbg(&dev->udev->dev, "%s", __func__);
568 /* Kick the tasklet */
569 sierra_net_defer_kevent(dev, SIERRA_NET_TIMER_EXPIRY);
572 static void sierra_net_status(struct usbnet *dev, struct urb *urb)
574 struct usb_cdc_notification *event;
576 dev_dbg(&dev->udev->dev, "%s", __func__);
578 if (urb->actual_length < sizeof *event)
581 /* Add cases to handle other standard notifications. */
582 event = urb->transfer_buffer;
583 switch (event->bNotificationType) {
584 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
585 case USB_CDC_NOTIFY_SPEED_CHANGE:
586 /* USB 305 sends those */
588 case USB_CDC_NOTIFY_RESPONSE_AVAILABLE:
589 sierra_net_defer_kevent(dev, SIERRA_NET_EVENT_RESP_AVAIL);
592 netdev_err(dev->net, ": unexpected notification %02x!\n",
593 event->bNotificationType);
598 static void sierra_net_get_drvinfo(struct net_device *net,
599 struct ethtool_drvinfo *info)
601 /* Inherit standard device info */
602 usbnet_get_drvinfo(net, info);
603 strlcpy(info->driver, driver_name, sizeof(info->driver));
604 strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
607 static u32 sierra_net_get_link(struct net_device *net)
609 struct usbnet *dev = netdev_priv(net);
610 /* Report link is down whenever the interface is down */
611 return sierra_net_get_private(dev)->link_up && netif_running(net);
614 static const struct ethtool_ops sierra_net_ethtool_ops = {
615 .get_drvinfo = sierra_net_get_drvinfo,
616 .get_link = sierra_net_get_link,
617 .get_msglevel = usbnet_get_msglevel,
618 .set_msglevel = usbnet_set_msglevel,
619 .get_settings = usbnet_get_settings,
620 .set_settings = usbnet_set_settings,
621 .nway_reset = usbnet_nway_reset,
624 static int sierra_net_get_fw_attr(struct usbnet *dev, u16 *datap)
629 result = usbnet_read_cmd(dev,
630 /* _u8 vendor specific request */
631 SWI_USB_REQUEST_GET_FW_ATTR,
632 USB_DIR_IN | USB_TYPE_VENDOR, /* __u8 request type */
633 0x0000, /* __u16 value not used */
634 0x0000, /* __u16 index not used */
635 &attrdata, /* char *data */
636 sizeof(attrdata) /* __u16 size */
642 *datap = le16_to_cpu(attrdata);
647 * collects the bulk endpoints, the status endpoint.
649 static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
656 struct sierra_net_data *priv;
657 static const u8 sync_tmplate[sizeof(priv->sync_msg)] = {
658 0x00, 0x00, SIERRA_NET_HIP_MSYNC_ID, 0x00};
659 static const u8 shdwn_tmplate[sizeof(priv->shdwn_msg)] = {
660 0x00, 0x00, SIERRA_NET_HIP_SHUTD_ID, 0x00};
662 dev_dbg(&dev->udev->dev, "%s", __func__);
664 ifacenum = intf->cur_altsetting->desc.bInterfaceNumber;
665 numendpoints = intf->cur_altsetting->desc.bNumEndpoints;
666 /* We have three endpoints, bulk in and out, and a status */
667 if (numendpoints != 3) {
668 dev_err(&dev->udev->dev, "Expected 3 endpoints, found: %d",
672 /* Status endpoint set in usbnet_get_endpoints() */
674 status = usbnet_get_endpoints(dev, intf);
676 dev_err(&dev->udev->dev, "Error in usbnet_get_endpoints (%d)",
680 /* Initialize sierra private data */
681 priv = kzalloc(sizeof *priv, GFP_KERNEL);
686 priv->ifnum = ifacenum;
687 dev->net->netdev_ops = &sierra_net_device_ops;
689 /* change MAC addr to include, ifacenum, and to be unique */
690 dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
691 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
693 /* we will have to manufacture ethernet headers, prepare template */
694 eth = (struct ethhdr *)priv->ethr_hdr_tmpl;
695 memcpy(ð->h_dest, dev->net->dev_addr, ETH_ALEN);
696 eth->h_proto = cpu_to_be16(ETH_P_IP);
698 /* prepare shutdown message template */
699 memcpy(priv->shdwn_msg, shdwn_tmplate, sizeof(priv->shdwn_msg));
700 /* set context index initially to 0 - prepares tx hdr template */
701 sierra_net_set_ctx_index(priv, 0);
703 /* prepare sync message template */
704 memcpy(priv->sync_msg, sync_tmplate, sizeof(priv->sync_msg));
706 /* decrease the rx_urb_size and max_tx_size to 4k on USB 1.1 */
707 dev->rx_urb_size = SIERRA_NET_RX_URB_SIZE;
708 if (dev->udev->speed != USB_SPEED_HIGH)
709 dev->rx_urb_size = min_t(size_t, 4096, SIERRA_NET_RX_URB_SIZE);
711 dev->net->hard_header_len += SIERRA_NET_HIP_EXT_HDR_LEN;
712 dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
713 dev->net->max_mtu = SIERRA_NET_MAX_SUPPORTED_MTU;
715 /* Set up the netdev */
716 dev->net->flags |= IFF_NOARP;
717 dev->net->ethtool_ops = &sierra_net_ethtool_ops;
718 netif_carrier_off(dev->net);
720 sierra_net_set_private(dev, priv);
722 priv->kevent_flags = 0;
724 /* Use the shared workqueue */
725 INIT_WORK(&priv->sierra_net_kevent, sierra_net_kevent);
727 /* Only need to do this once */
728 init_timer(&priv->sync_timer);
730 /* verify fw attributes */
731 status = sierra_net_get_fw_attr(dev, &fwattr);
732 dev_dbg(&dev->udev->dev, "Fw attr: %x\n", fwattr);
734 /* test whether firmware supports DHCP */
735 if (!(status == sizeof(fwattr) && (fwattr & SWI_GET_FW_ATTR_MASK))) {
736 /* found incompatible firmware version */
737 dev_err(&dev->udev->dev, "Incompatible driver and firmware"
746 static void sierra_net_unbind(struct usbnet *dev, struct usb_interface *intf)
749 struct sierra_net_data *priv = sierra_net_get_private(dev);
751 dev_dbg(&dev->udev->dev, "%s", __func__);
753 /* kill the timer and work */
754 del_timer_sync(&priv->sync_timer);
755 cancel_work_sync(&priv->sierra_net_kevent);
757 /* tell modem we are going away */
758 status = sierra_net_send_cmd(dev, priv->shdwn_msg,
759 sizeof(priv->shdwn_msg), "Shutdown");
762 "usb_control_msg failed, status %d\n", status);
764 usbnet_status_stop(dev);
766 sierra_net_set_private(dev, NULL);
770 static struct sk_buff *sierra_net_skb_clone(struct usbnet *dev,
771 struct sk_buff *skb, int len)
773 struct sk_buff *new_skb;
776 new_skb = skb_clone(skb, GFP_ATOMIC);
778 /* remove len bytes from original */
781 /* trim next packet to it's length */
783 skb_trim(new_skb, len);
785 if (netif_msg_rx_err(dev))
786 netdev_err(dev->net, "failed to get skb\n");
787 dev->net->stats.rx_dropped++;
793 /* ---------------------------- Receive data path ----------------------*/
794 static int sierra_net_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
798 struct sk_buff *new_skb;
800 dev_dbg(&dev->udev->dev, "%s", __func__);
802 /* could contain multiple packets */
803 while (likely(skb->len)) {
804 err = parse_hip(skb->data, skb->len, &hh);
806 if (netif_msg_rx_err(dev))
807 netdev_err(dev->net, "Invalid HIP header %d\n",
809 /* dev->net->stats.rx_errors incremented by caller */
810 dev->net->stats.rx_length_errors++;
814 /* Validate Extended HIP header */
815 if (!hh.extmsgid.is_present
816 || hh.extmsgid.word != SIERRA_NET_HIP_EXT_IP_IN_ID) {
817 if (netif_msg_rx_err(dev))
818 netdev_err(dev->net, "HIP/ETH: Invalid pkt\n");
820 dev->net->stats.rx_frame_errors++;
821 /* dev->net->stats.rx_errors incremented by caller */
825 skb_pull(skb, hh.hdrlen);
827 /* We are going to accept this packet, prepare it */
828 memcpy(skb->data, sierra_net_get_private(dev)->ethr_hdr_tmpl,
831 /* Last packet in batch handled by usbnet */
832 if (hh.payload_len.word == skb->len)
835 new_skb = sierra_net_skb_clone(dev, skb, hh.payload_len.word);
837 usbnet_skb_return(dev, new_skb);
844 /* ---------------------------- Transmit data path ----------------------*/
845 static struct sk_buff *sierra_net_tx_fixup(struct usbnet *dev,
846 struct sk_buff *skb, gfp_t flags)
848 struct sierra_net_data *priv = sierra_net_get_private(dev);
852 BUILD_BUG_ON(FIELD_SIZEOF(struct usbnet, data)
853 < sizeof(struct cdc_state));
855 dev_dbg(&dev->udev->dev, "%s", __func__);
856 if (priv->link_up && check_ethip_packet(skb, dev) && is_ip(skb)) {
857 /* enough head room as is? */
858 if (SIERRA_NET_HIP_EXT_HDR_LEN <= skb_headroom(skb)) {
859 /* Save the Eth/IP length and set up HIP hdr */
861 skb_push(skb, SIERRA_NET_HIP_EXT_HDR_LEN);
862 /* Handle ZLP issue */
863 need_tail = ((len + SIERRA_NET_HIP_EXT_HDR_LEN)
864 % dev->maxpacket == 0);
866 if (unlikely(skb_tailroom(skb) == 0)) {
867 netdev_err(dev->net, "tx_fixup:"
868 "no room for packet\n");
869 dev_kfree_skb_any(skb);
872 skb->data[skb->len] = 0;
877 build_hip(skb->data, len, priv);
881 * compensate in the future if necessary
883 netdev_err(dev->net, "tx_fixup: no room for HIP\n");
888 dev->net->stats.tx_carrier_errors++;
890 /* tx_dropped incremented by usbnet */
892 /* filter the packet out, release it */
893 dev_kfree_skb_any(skb);
897 static const struct driver_info sierra_net_info_direct_ip = {
898 .description = "Sierra Wireless USB-to-WWAN Modem",
899 .flags = FLAG_WWAN | FLAG_SEND_ZLP,
900 .bind = sierra_net_bind,
901 .unbind = sierra_net_unbind,
902 .status = sierra_net_status,
903 .rx_fixup = sierra_net_rx_fixup,
904 .tx_fixup = sierra_net_tx_fixup,
908 sierra_net_probe(struct usb_interface *udev, const struct usb_device_id *prod)
912 ret = usbnet_probe(udev, prod);
914 struct usbnet *dev = usb_get_intfdata(udev);
916 ret = usbnet_status_start(dev, GFP_KERNEL);
918 /* Interrupt URB now set up; initiate sync sequence */
919 sierra_net_dosync(dev);
925 #define DIRECT_IP_DEVICE(vend, prod) \
926 {USB_DEVICE_INTERFACE_NUMBER(vend, prod, 7), \
927 .driver_info = (unsigned long)&sierra_net_info_direct_ip}, \
928 {USB_DEVICE_INTERFACE_NUMBER(vend, prod, 10), \
929 .driver_info = (unsigned long)&sierra_net_info_direct_ip}, \
930 {USB_DEVICE_INTERFACE_NUMBER(vend, prod, 11), \
931 .driver_info = (unsigned long)&sierra_net_info_direct_ip}
933 static const struct usb_device_id products[] = {
934 DIRECT_IP_DEVICE(0x1199, 0x68A3), /* Sierra Wireless USB-to-WWAN modem */
935 DIRECT_IP_DEVICE(0x0F3D, 0x68A3), /* AT&T Direct IP modem */
936 DIRECT_IP_DEVICE(0x1199, 0x68AA), /* Sierra Wireless Direct IP LTE modem */
937 DIRECT_IP_DEVICE(0x0F3D, 0x68AA), /* AT&T Direct IP LTE modem */
941 MODULE_DEVICE_TABLE(usb, products);
943 /* We are based on usbnet, so let it handle the USB driver specifics */
944 static struct usb_driver sierra_net_driver = {
945 .name = "sierra_net",
946 .id_table = products,
947 .probe = sierra_net_probe,
948 .disconnect = usbnet_disconnect,
949 .suspend = usbnet_suspend,
950 .resume = usbnet_resume,
952 .disable_hub_initiated_lpm = 1,
955 module_usb_driver(sierra_net_driver);
957 MODULE_AUTHOR(DRIVER_AUTHOR);
958 MODULE_DESCRIPTION(DRIVER_DESC);
959 MODULE_VERSION(DRIVER_VERSION);
960 MODULE_LICENSE("GPL");