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);
168 static int sierra_net_change_mtu(struct net_device *net, int new_mtu);
170 /* Our own net device operations structure */
171 static const struct net_device_ops sierra_net_device_ops = {
172 .ndo_open = usbnet_open,
173 .ndo_stop = usbnet_stop,
174 .ndo_start_xmit = usbnet_start_xmit,
175 .ndo_tx_timeout = usbnet_tx_timeout,
176 .ndo_change_mtu = sierra_net_change_mtu,
177 .ndo_set_mac_address = eth_mac_addr,
178 .ndo_validate_addr = eth_validate_addr,
181 /* get private data associated with passed in usbnet device */
182 static inline struct sierra_net_data *sierra_net_get_private(struct usbnet *dev)
184 return (struct sierra_net_data *)dev->data[0];
187 /* set private data associated with passed in usbnet device */
188 static inline void sierra_net_set_private(struct usbnet *dev,
189 struct sierra_net_data *priv)
191 dev->data[0] = (unsigned long)priv;
195 static inline int is_ip(struct sk_buff *skb)
197 return skb->protocol == cpu_to_be16(ETH_P_IP);
201 * check passed in packet and make sure that:
202 * - it is linear (no scatter/gather)
203 * - it is ethernet (mac_header properly set)
205 static int check_ethip_packet(struct sk_buff *skb, struct usbnet *dev)
207 skb_reset_mac_header(skb); /* ethernet header */
209 if (skb_is_nonlinear(skb)) {
210 netdev_err(dev->net, "Non linear buffer-dropping\n");
214 if (!pskb_may_pull(skb, ETH_HLEN))
216 skb->protocol = eth_hdr(skb)->h_proto;
221 static const u8 *save16bit(struct param *p, const u8 *datap)
224 p->word = get_unaligned_be16(datap);
225 return datap + sizeof(p->word);
228 static const u8 *save8bit(struct param *p, const u8 *datap)
232 return datap + sizeof(p->byte);
235 /*----------------------------------------------------------------------------*
237 *----------------------------------------------------------------------------*/
239 #define SIERRA_NET_HIP_HDR_LEN 4
240 /* Extended HIP header */
241 #define SIERRA_NET_HIP_EXT_HDR_LEN 6
245 struct param payload_len;
247 struct param msgspecific;
248 struct param extmsgid;
251 static int parse_hip(const u8 *buf, const u32 buflen, struct hip_hdr *hh)
253 const u8 *curp = buf;
256 if (buflen < SIERRA_NET_HIP_HDR_LEN)
259 curp = save16bit(&hh->payload_len, curp);
260 curp = save8bit(&hh->msgid, curp);
261 curp = save8bit(&hh->msgspecific, curp);
263 padded = hh->msgid.byte & 0x80;
264 hh->msgid.byte &= 0x7F; /* 7 bits */
266 hh->extmsgid.is_present = (hh->msgid.byte == SIERRA_NET_HIP_EXTENDEDID);
267 if (hh->extmsgid.is_present) {
268 if (buflen < SIERRA_NET_HIP_EXT_HDR_LEN)
271 hh->payload_len.word &= 0x3FFF; /* 14 bits */
273 curp = save16bit(&hh->extmsgid, curp);
274 hh->extmsgid.word &= 0x03FF; /* 10 bits */
276 hh->hdrlen = SIERRA_NET_HIP_EXT_HDR_LEN;
278 hh->payload_len.word &= 0x07FF; /* 11 bits */
279 hh->hdrlen = SIERRA_NET_HIP_HDR_LEN;
284 hh->payload_len.word--;
287 /* if real packet shorter than the claimed length */
288 if (buflen < (hh->hdrlen + hh->payload_len.word))
294 static void build_hip(u8 *buf, const u16 payloadlen,
295 struct sierra_net_data *priv)
297 /* the following doesn't have the full functionality. We
298 * currently build only one kind of header, so it is faster this way
300 put_unaligned_be16(payloadlen, buf);
301 memcpy(buf+2, priv->tx_hdr_template, sizeof(priv->tx_hdr_template));
303 /*----------------------------------------------------------------------------*
305 *----------------------------------------------------------------------------*/
307 static int sierra_net_send_cmd(struct usbnet *dev,
308 u8 *cmd, int cmdlen, const char * cmd_name)
310 struct sierra_net_data *priv = sierra_net_get_private(dev);
313 status = usbnet_write_cmd(dev, USB_CDC_SEND_ENCAPSULATED_COMMAND,
314 USB_DIR_OUT|USB_TYPE_CLASS|USB_RECIP_INTERFACE,
315 0, priv->ifnum, cmd, cmdlen);
317 if (status != cmdlen && status != -ENODEV)
318 netdev_err(dev->net, "Submit %s failed %d\n", cmd_name, status);
323 static int sierra_net_send_sync(struct usbnet *dev)
326 struct sierra_net_data *priv = sierra_net_get_private(dev);
328 dev_dbg(&dev->udev->dev, "%s", __func__);
330 status = sierra_net_send_cmd(dev, priv->sync_msg,
331 sizeof(priv->sync_msg), "SYNC");
336 static void sierra_net_set_ctx_index(struct sierra_net_data *priv, u8 ctx_ix)
338 dev_dbg(&(priv->usbnet->udev->dev), "%s %d", __func__, ctx_ix);
339 priv->tx_hdr_template[0] = 0x3F;
340 priv->tx_hdr_template[1] = ctx_ix;
341 *((__be16 *)&priv->tx_hdr_template[2]) =
342 cpu_to_be16(SIERRA_NET_HIP_EXT_IP_OUT_ID);
345 static inline int sierra_net_is_valid_addrlen(u8 len)
347 return len == sizeof(struct in_addr);
350 static int sierra_net_parse_lsi(struct usbnet *dev, char *data, int datalen)
352 struct lsi_umts *lsi = (struct lsi_umts *)data;
354 if (datalen < sizeof(struct lsi_umts)) {
355 netdev_err(dev->net, "%s: Data length %d, exp %Zu\n",
357 sizeof(struct lsi_umts));
361 if (lsi->length != cpu_to_be16(SIERRA_NET_LSI_UMTS_STATUS_LEN)) {
362 netdev_err(dev->net, "%s: LSI_UMTS_STATUS_LEN %d, exp %u\n",
363 __func__, be16_to_cpu(lsi->length),
364 (u32)SIERRA_NET_LSI_UMTS_STATUS_LEN);
368 /* Validate the protocol - only support UMTS for now */
369 if (lsi->protocol != SIERRA_NET_PROTOCOL_UMTS) {
370 netdev_err(dev->net, "Protocol unsupported, 0x%02x\n",
375 /* Validate the link type */
376 if (lsi->link_type != SIERRA_NET_AS_LINK_TYPE_IPv4) {
377 netdev_err(dev->net, "Link type unsupported: 0x%02x\n",
382 /* Validate the coverage */
383 if (lsi->coverage == SIERRA_NET_COVERAGE_NONE
384 || lsi->coverage == SIERRA_NET_COVERAGE_NOPACKET) {
385 netdev_err(dev->net, "No coverage, 0x%02x\n", lsi->coverage);
389 /* Validate the session state */
390 if (lsi->session_state == SIERRA_NET_SESSION_IDLE) {
391 netdev_err(dev->net, "Session idle, 0x%02x\n",
396 /* Set link_sense true */
400 static void sierra_net_handle_lsi(struct usbnet *dev, char *data,
403 struct sierra_net_data *priv = sierra_net_get_private(dev);
406 link_up = sierra_net_parse_lsi(dev, data + hh->hdrlen,
407 hh->payload_len.word);
409 netdev_err(dev->net, "Invalid LSI\n");
413 sierra_net_set_ctx_index(priv, hh->msgspecific.byte);
418 usbnet_link_change(dev, link_up, 0);
421 static void sierra_net_dosync(struct usbnet *dev)
424 struct sierra_net_data *priv = sierra_net_get_private(dev);
426 dev_dbg(&dev->udev->dev, "%s", __func__);
428 /* The SIERRA_NET_HIP_MSYNC_ID command appears to request that the
429 * firmware restart itself. After restarting, the modem will respond
430 * with the SIERRA_NET_HIP_RESTART_ID indication. The driver continues
431 * sending MSYNC commands every few seconds until it receives the
432 * RESTART event from the firmware
435 /* tell modem we are ready */
436 status = sierra_net_send_sync(dev);
439 "Send SYNC failed, status %d\n", status);
440 status = sierra_net_send_sync(dev);
443 "Send SYNC failed, status %d\n", status);
445 /* Now, start a timer and make sure we get the Restart Indication */
446 priv->sync_timer.function = sierra_sync_timer;
447 priv->sync_timer.data = (unsigned long) dev;
448 priv->sync_timer.expires = jiffies + SIERRA_NET_SYNCDELAY;
449 add_timer(&priv->sync_timer);
452 static void sierra_net_kevent(struct work_struct *work)
454 struct sierra_net_data *priv =
455 container_of(work, struct sierra_net_data, sierra_net_kevent);
456 struct usbnet *dev = priv->usbnet;
462 if (test_bit(SIERRA_NET_EVENT_RESP_AVAIL, &priv->kevent_flags)) {
463 clear_bit(SIERRA_NET_EVENT_RESP_AVAIL, &priv->kevent_flags);
465 /* Query the modem for the LSI message */
466 buf = kzalloc(SIERRA_NET_USBCTL_BUF_LEN, GFP_KERNEL);
471 len = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
472 USB_CDC_GET_ENCAPSULATED_RESPONSE,
473 USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE,
474 0, ifnum, buf, SIERRA_NET_USBCTL_BUF_LEN,
475 USB_CTRL_SET_TIMEOUT);
479 "usb_control_msg failed, status %d\n", len);
483 dev_dbg(&dev->udev->dev, "%s: Received status message,"
484 " %04x bytes", __func__, len);
486 err = parse_hip(buf, len, &hh);
488 netdev_err(dev->net, "%s: Bad packet,"
489 " parse result %d\n", __func__, err);
494 /* Validate packet length */
495 if (len != hh.hdrlen + hh.payload_len.word) {
496 netdev_err(dev->net, "%s: Bad packet, received"
497 " %d, expected %d\n", __func__, len,
498 hh.hdrlen + hh.payload_len.word);
503 /* Switch on received message types */
504 switch (hh.msgid.byte) {
505 case SIERRA_NET_HIP_LSI_UMTSID:
506 dev_dbg(&dev->udev->dev, "LSI for ctx:%d",
507 hh.msgspecific.byte);
508 sierra_net_handle_lsi(dev, buf, &hh);
510 case SIERRA_NET_HIP_RESTART_ID:
511 dev_dbg(&dev->udev->dev, "Restart reported: %d,"
512 " stopping sync timer",
513 hh.msgspecific.byte);
514 /* Got sync resp - stop timer & clear mask */
515 del_timer_sync(&priv->sync_timer);
516 clear_bit(SIERRA_NET_TIMER_EXPIRY,
517 &priv->kevent_flags);
519 case SIERRA_NET_HIP_HSYNC_ID:
520 dev_dbg(&dev->udev->dev, "SYNC received");
521 err = sierra_net_send_sync(dev);
524 "Send SYNC failed %d\n", err);
526 case SIERRA_NET_HIP_EXTENDEDID:
527 netdev_err(dev->net, "Unrecognized HIP msg, "
528 "extmsgid 0x%04x\n", hh.extmsgid.word);
530 case SIERRA_NET_HIP_RCGI:
534 netdev_err(dev->net, "Unrecognized HIP msg, "
535 "msgid 0x%02x\n", hh.msgid.byte);
541 /* The sync timer bit might be set */
542 if (test_bit(SIERRA_NET_TIMER_EXPIRY, &priv->kevent_flags)) {
543 clear_bit(SIERRA_NET_TIMER_EXPIRY, &priv->kevent_flags);
544 dev_dbg(&dev->udev->dev, "Deferred sync timer expiry");
545 sierra_net_dosync(priv->usbnet);
548 if (priv->kevent_flags)
549 dev_dbg(&dev->udev->dev, "sierra_net_kevent done, "
550 "kevent_flags = 0x%lx", priv->kevent_flags);
553 static void sierra_net_defer_kevent(struct usbnet *dev, int work)
555 struct sierra_net_data *priv = sierra_net_get_private(dev);
557 set_bit(work, &priv->kevent_flags);
558 schedule_work(&priv->sierra_net_kevent);
562 * Sync Retransmit Timer Handler. On expiry, kick the work queue
564 static void sierra_sync_timer(unsigned long syncdata)
566 struct usbnet *dev = (struct usbnet *)syncdata;
568 dev_dbg(&dev->udev->dev, "%s", __func__);
569 /* Kick the tasklet */
570 sierra_net_defer_kevent(dev, SIERRA_NET_TIMER_EXPIRY);
573 static void sierra_net_status(struct usbnet *dev, struct urb *urb)
575 struct usb_cdc_notification *event;
577 dev_dbg(&dev->udev->dev, "%s", __func__);
579 if (urb->actual_length < sizeof *event)
582 /* Add cases to handle other standard notifications. */
583 event = urb->transfer_buffer;
584 switch (event->bNotificationType) {
585 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
586 case USB_CDC_NOTIFY_SPEED_CHANGE:
587 /* USB 305 sends those */
589 case USB_CDC_NOTIFY_RESPONSE_AVAILABLE:
590 sierra_net_defer_kevent(dev, SIERRA_NET_EVENT_RESP_AVAIL);
593 netdev_err(dev->net, ": unexpected notification %02x!\n",
594 event->bNotificationType);
599 static void sierra_net_get_drvinfo(struct net_device *net,
600 struct ethtool_drvinfo *info)
602 /* Inherit standard device info */
603 usbnet_get_drvinfo(net, info);
604 strlcpy(info->driver, driver_name, sizeof(info->driver));
605 strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
608 static u32 sierra_net_get_link(struct net_device *net)
610 struct usbnet *dev = netdev_priv(net);
611 /* Report link is down whenever the interface is down */
612 return sierra_net_get_private(dev)->link_up && netif_running(net);
615 static const struct ethtool_ops sierra_net_ethtool_ops = {
616 .get_drvinfo = sierra_net_get_drvinfo,
617 .get_link = sierra_net_get_link,
618 .get_msglevel = usbnet_get_msglevel,
619 .set_msglevel = usbnet_set_msglevel,
620 .get_settings = usbnet_get_settings,
621 .set_settings = usbnet_set_settings,
622 .nway_reset = usbnet_nway_reset,
625 /* MTU can not be more than 1500 bytes, enforce it. */
626 static int sierra_net_change_mtu(struct net_device *net, int new_mtu)
628 if (new_mtu > SIERRA_NET_MAX_SUPPORTED_MTU)
631 return usbnet_change_mtu(net, new_mtu);
634 static int sierra_net_get_fw_attr(struct usbnet *dev, u16 *datap)
639 result = usbnet_read_cmd(dev,
640 /* _u8 vendor specific request */
641 SWI_USB_REQUEST_GET_FW_ATTR,
642 USB_DIR_IN | USB_TYPE_VENDOR, /* __u8 request type */
643 0x0000, /* __u16 value not used */
644 0x0000, /* __u16 index not used */
645 &attrdata, /* char *data */
646 sizeof(attrdata) /* __u16 size */
652 *datap = le16_to_cpu(attrdata);
657 * collects the bulk endpoints, the status endpoint.
659 static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
666 struct sierra_net_data *priv;
667 static const u8 sync_tmplate[sizeof(priv->sync_msg)] = {
668 0x00, 0x00, SIERRA_NET_HIP_MSYNC_ID, 0x00};
669 static const u8 shdwn_tmplate[sizeof(priv->shdwn_msg)] = {
670 0x00, 0x00, SIERRA_NET_HIP_SHUTD_ID, 0x00};
672 dev_dbg(&dev->udev->dev, "%s", __func__);
674 ifacenum = intf->cur_altsetting->desc.bInterfaceNumber;
675 numendpoints = intf->cur_altsetting->desc.bNumEndpoints;
676 /* We have three endpoints, bulk in and out, and a status */
677 if (numendpoints != 3) {
678 dev_err(&dev->udev->dev, "Expected 3 endpoints, found: %d",
682 /* Status endpoint set in usbnet_get_endpoints() */
684 status = usbnet_get_endpoints(dev, intf);
686 dev_err(&dev->udev->dev, "Error in usbnet_get_endpoints (%d)",
690 /* Initialize sierra private data */
691 priv = kzalloc(sizeof *priv, GFP_KERNEL);
696 priv->ifnum = ifacenum;
697 dev->net->netdev_ops = &sierra_net_device_ops;
699 /* change MAC addr to include, ifacenum, and to be unique */
700 dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
701 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
703 /* we will have to manufacture ethernet headers, prepare template */
704 eth = (struct ethhdr *)priv->ethr_hdr_tmpl;
705 memcpy(ð->h_dest, dev->net->dev_addr, ETH_ALEN);
706 eth->h_proto = cpu_to_be16(ETH_P_IP);
708 /* prepare shutdown message template */
709 memcpy(priv->shdwn_msg, shdwn_tmplate, sizeof(priv->shdwn_msg));
710 /* set context index initially to 0 - prepares tx hdr template */
711 sierra_net_set_ctx_index(priv, 0);
713 /* prepare sync message template */
714 memcpy(priv->sync_msg, sync_tmplate, sizeof(priv->sync_msg));
716 /* decrease the rx_urb_size and max_tx_size to 4k on USB 1.1 */
717 dev->rx_urb_size = SIERRA_NET_RX_URB_SIZE;
718 if (dev->udev->speed != USB_SPEED_HIGH)
719 dev->rx_urb_size = min_t(size_t, 4096, SIERRA_NET_RX_URB_SIZE);
721 dev->net->hard_header_len += SIERRA_NET_HIP_EXT_HDR_LEN;
722 dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
724 /* Set up the netdev */
725 dev->net->flags |= IFF_NOARP;
726 dev->net->ethtool_ops = &sierra_net_ethtool_ops;
727 netif_carrier_off(dev->net);
729 sierra_net_set_private(dev, priv);
731 priv->kevent_flags = 0;
733 /* Use the shared workqueue */
734 INIT_WORK(&priv->sierra_net_kevent, sierra_net_kevent);
736 /* Only need to do this once */
737 init_timer(&priv->sync_timer);
739 /* verify fw attributes */
740 status = sierra_net_get_fw_attr(dev, &fwattr);
741 dev_dbg(&dev->udev->dev, "Fw attr: %x\n", fwattr);
743 /* test whether firmware supports DHCP */
744 if (!(status == sizeof(fwattr) && (fwattr & SWI_GET_FW_ATTR_MASK))) {
745 /* found incompatible firmware version */
746 dev_err(&dev->udev->dev, "Incompatible driver and firmware"
755 static void sierra_net_unbind(struct usbnet *dev, struct usb_interface *intf)
758 struct sierra_net_data *priv = sierra_net_get_private(dev);
760 dev_dbg(&dev->udev->dev, "%s", __func__);
762 /* kill the timer and work */
763 del_timer_sync(&priv->sync_timer);
764 cancel_work_sync(&priv->sierra_net_kevent);
766 /* tell modem we are going away */
767 status = sierra_net_send_cmd(dev, priv->shdwn_msg,
768 sizeof(priv->shdwn_msg), "Shutdown");
771 "usb_control_msg failed, status %d\n", status);
773 usbnet_status_stop(dev);
775 sierra_net_set_private(dev, NULL);
779 static struct sk_buff *sierra_net_skb_clone(struct usbnet *dev,
780 struct sk_buff *skb, int len)
782 struct sk_buff *new_skb;
785 new_skb = skb_clone(skb, GFP_ATOMIC);
787 /* remove len bytes from original */
790 /* trim next packet to it's length */
792 skb_trim(new_skb, len);
794 if (netif_msg_rx_err(dev))
795 netdev_err(dev->net, "failed to get skb\n");
796 dev->net->stats.rx_dropped++;
802 /* ---------------------------- Receive data path ----------------------*/
803 static int sierra_net_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
807 struct sk_buff *new_skb;
809 dev_dbg(&dev->udev->dev, "%s", __func__);
811 /* could contain multiple packets */
812 while (likely(skb->len)) {
813 err = parse_hip(skb->data, skb->len, &hh);
815 if (netif_msg_rx_err(dev))
816 netdev_err(dev->net, "Invalid HIP header %d\n",
818 /* dev->net->stats.rx_errors incremented by caller */
819 dev->net->stats.rx_length_errors++;
823 /* Validate Extended HIP header */
824 if (!hh.extmsgid.is_present
825 || hh.extmsgid.word != SIERRA_NET_HIP_EXT_IP_IN_ID) {
826 if (netif_msg_rx_err(dev))
827 netdev_err(dev->net, "HIP/ETH: Invalid pkt\n");
829 dev->net->stats.rx_frame_errors++;
830 /* dev->net->stats.rx_errors incremented by caller */
834 skb_pull(skb, hh.hdrlen);
836 /* We are going to accept this packet, prepare it */
837 memcpy(skb->data, sierra_net_get_private(dev)->ethr_hdr_tmpl,
840 /* Last packet in batch handled by usbnet */
841 if (hh.payload_len.word == skb->len)
844 new_skb = sierra_net_skb_clone(dev, skb, hh.payload_len.word);
846 usbnet_skb_return(dev, new_skb);
853 /* ---------------------------- Transmit data path ----------------------*/
854 static struct sk_buff *sierra_net_tx_fixup(struct usbnet *dev,
855 struct sk_buff *skb, gfp_t flags)
857 struct sierra_net_data *priv = sierra_net_get_private(dev);
861 BUILD_BUG_ON(FIELD_SIZEOF(struct usbnet, data)
862 < sizeof(struct cdc_state));
864 dev_dbg(&dev->udev->dev, "%s", __func__);
865 if (priv->link_up && check_ethip_packet(skb, dev) && is_ip(skb)) {
866 /* enough head room as is? */
867 if (SIERRA_NET_HIP_EXT_HDR_LEN <= skb_headroom(skb)) {
868 /* Save the Eth/IP length and set up HIP hdr */
870 skb_push(skb, SIERRA_NET_HIP_EXT_HDR_LEN);
871 /* Handle ZLP issue */
872 need_tail = ((len + SIERRA_NET_HIP_EXT_HDR_LEN)
873 % dev->maxpacket == 0);
875 if (unlikely(skb_tailroom(skb) == 0)) {
876 netdev_err(dev->net, "tx_fixup:"
877 "no room for packet\n");
878 dev_kfree_skb_any(skb);
881 skb->data[skb->len] = 0;
886 build_hip(skb->data, len, priv);
890 * compensate in the future if necessary
892 netdev_err(dev->net, "tx_fixup: no room for HIP\n");
897 dev->net->stats.tx_carrier_errors++;
899 /* tx_dropped incremented by usbnet */
901 /* filter the packet out, release it */
902 dev_kfree_skb_any(skb);
906 static const struct driver_info sierra_net_info_direct_ip = {
907 .description = "Sierra Wireless USB-to-WWAN Modem",
908 .flags = FLAG_WWAN | FLAG_SEND_ZLP,
909 .bind = sierra_net_bind,
910 .unbind = sierra_net_unbind,
911 .status = sierra_net_status,
912 .rx_fixup = sierra_net_rx_fixup,
913 .tx_fixup = sierra_net_tx_fixup,
917 sierra_net_probe(struct usb_interface *udev, const struct usb_device_id *prod)
921 ret = usbnet_probe(udev, prod);
923 struct usbnet *dev = usb_get_intfdata(udev);
925 ret = usbnet_status_start(dev, GFP_KERNEL);
927 /* Interrupt URB now set up; initiate sync sequence */
928 sierra_net_dosync(dev);
934 #define DIRECT_IP_DEVICE(vend, prod) \
935 {USB_DEVICE_INTERFACE_NUMBER(vend, prod, 7), \
936 .driver_info = (unsigned long)&sierra_net_info_direct_ip}, \
937 {USB_DEVICE_INTERFACE_NUMBER(vend, prod, 10), \
938 .driver_info = (unsigned long)&sierra_net_info_direct_ip}, \
939 {USB_DEVICE_INTERFACE_NUMBER(vend, prod, 11), \
940 .driver_info = (unsigned long)&sierra_net_info_direct_ip}
942 static const struct usb_device_id products[] = {
943 DIRECT_IP_DEVICE(0x1199, 0x68A3), /* Sierra Wireless USB-to-WWAN modem */
944 DIRECT_IP_DEVICE(0x0F3D, 0x68A3), /* AT&T Direct IP modem */
945 DIRECT_IP_DEVICE(0x1199, 0x68AA), /* Sierra Wireless Direct IP LTE modem */
946 DIRECT_IP_DEVICE(0x0F3D, 0x68AA), /* AT&T Direct IP LTE modem */
950 MODULE_DEVICE_TABLE(usb, products);
952 /* We are based on usbnet, so let it handle the USB driver specifics */
953 static struct usb_driver sierra_net_driver = {
954 .name = "sierra_net",
955 .id_table = products,
956 .probe = sierra_net_probe,
957 .disconnect = usbnet_disconnect,
958 .suspend = usbnet_suspend,
959 .resume = usbnet_resume,
961 .disable_hub_initiated_lpm = 1,
964 module_usb_driver(sierra_net_driver);
966 MODULE_AUTHOR(DRIVER_AUTHOR);
967 MODULE_DESCRIPTION(DRIVER_DESC);
968 MODULE_VERSION(DRIVER_VERSION);
969 MODULE_LICENSE("GPL");