Linux Audio

Check our new training course

Open-source upstreaming

Need help get the support for your hardware in upstream Linux?
Loading...
v3.15
  1/*
  2 * USB-to-WWAN Driver for Sierra Wireless modems
  3 *
  4 * Copyright (C) 2008, 2009, 2010 Paxton Smith, Matthew Safar, Rory Filer
  5 *                          <linux@sierrawireless.com>
  6 *
  7 * Portions of this based on the cdc_ether driver by David Brownell (2003-2005)
  8 * and Ole Andre Vadla Ravnas (ActiveSync) (2006).
  9 *
 10 * IMPORTANT DISCLAIMER: This driver is not commercially supported by
 11 * Sierra Wireless. Use at your own risk.
 12 *
 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.
 17 *
 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.
 22 *
 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/>.
 
 25 */
 26
 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"
 30static const char driver_name[] = "sierra_net";
 31
 32/* if defined debug messages enabled */
 33/*#define	DEBUG*/
 34
 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>
 43#include <net/ip.h>
 44#include <net/udp.h>
 45#include <asm/unaligned.h>
 46#include <linux/usb/usbnet.h>
 47
 48#define SWI_USB_REQUEST_GET_FW_ATTR	0x06
 49#define SWI_GET_FW_ATTR_MASK		0x08
 50
 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
 53 */
 54static	atomic_t iface_counter = ATOMIC_INIT(0);
 55
 56/*
 57 * SYNC Timer Delay definition used to set the expiry time
 58 */
 59#define SIERRA_NET_SYNCDELAY (2*HZ)
 60
 61/* Max. MTU supported. The modem buffers are limited to 1500 */
 62#define SIERRA_NET_MAX_SUPPORTED_MTU	1500
 63
 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)
 67 */
 68#define SIERRA_NET_USBCTL_BUF_LEN	1024
 69
 70/* Overriding the default usbnet rx_urb_size */
 71#define SIERRA_NET_RX_URB_SIZE		(8 * 1024)
 
 
 
 
 
 
 
 
 72
 73/* Private data structure */
 74struct sierra_net_data {
 75
 76	u8 ethr_hdr_tmpl[ETH_HLEN]; /* ethernet header template for rx'd pkts */
 77
 78	u16 link_up;		/* air link up or down */
 79	u8 tx_hdr_template[4];	/* part of HIP hdr for tx'd packets */
 80
 81	u8 sync_msg[4];		/* SYNC message */
 82	u8 shdwn_msg[4];	/* Shutdown message */
 83
 84	/* Backpointer to the container */
 85	struct usbnet *usbnet;
 86
 87	u8 ifnum;	/* interface number */
 88
 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 */
 95};
 96
 97struct param {
 98	int is_present;
 99	union {
100		void  *ptr;
101		u32    dword;
102		u16    word;
103		u8     byte;
104	};
105};
106
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 */
113
114#define SIERRA_NET_HIP_EXT_IP_IN_ID   0x0202
115#define SIERRA_NET_HIP_EXT_IP_OUT_ID  0x0002
116
117/* 3G UMTS Link Sense Indication definitions */
118#define SIERRA_NET_HIP_LSI_UMTSID	0x78
119
120/* Reverse Channel Grant Indication HIP message */
121#define SIERRA_NET_HIP_RCGI		0x64
122
123/* LSI Protocol types */
124#define SIERRA_NET_PROTOCOL_UMTS      0x01
125/* LSI Coverage */
126#define SIERRA_NET_COVERAGE_NONE      0x00
127#define SIERRA_NET_COVERAGE_NOPACKET  0x01
128
129/* LSI Session */
130#define SIERRA_NET_SESSION_IDLE       0x00
131/* LSI Link types */
132#define SIERRA_NET_AS_LINK_TYPE_IPv4  0x00
133
134struct lsi_umts {
135	u8 protocol;
136	u8 unused1;
137	__be16 length;
138	/* eventually use a union for the rest - assume umts for now */
139	u8 coverage;
140	u8 unused2[41];
141	u8 session_state;
142	u8 unused3[33];
143	u8 link_type;
144	u8 pdp_addr_len; /* NW-supplied PDP address len */
145	u8 pdp_addr[16]; /* NW-supplied PDP address (bigendian)) */
146	u8 unused4[23];
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) */
155	u8 unused5[4];
156	u8 gw_addr_len; /* NW-supplied GW address len */
157	u8 gw_addr[16]; /* NW-supplied GW address (bigendian) */
158	u8 reserved[8];
159} __packed;
160
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)
165
166/* Forward definitions */
167static void sierra_sync_timer(unsigned long syncdata);
168static int sierra_net_change_mtu(struct net_device *net, int new_mtu);
169
170/* Our own net device operations structure */
171static 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,
179};
180
181/* get private data associated with passed in usbnet device */
182static inline struct sierra_net_data *sierra_net_get_private(struct usbnet *dev)
183{
184	return (struct sierra_net_data *)dev->data[0];
185}
186
187/* set private data associated with passed in usbnet device */
188static inline void sierra_net_set_private(struct usbnet *dev,
189			struct sierra_net_data *priv)
190{
191	dev->data[0] = (unsigned long)priv;
192}
193
194/* is packet IPv4 */
195static inline int is_ip(struct sk_buff *skb)
196{
197	return skb->protocol == cpu_to_be16(ETH_P_IP);
198}
199
200/*
201 * check passed in packet and make sure that:
202 *  - it is linear (no scatter/gather)
203 *  - it is ethernet (mac_header properly set)
204 */
205static int check_ethip_packet(struct sk_buff *skb, struct usbnet *dev)
206{
207	skb_reset_mac_header(skb); /* ethernet header */
208
209	if (skb_is_nonlinear(skb)) {
210		netdev_err(dev->net, "Non linear buffer-dropping\n");
211		return 0;
212	}
213
214	if (!pskb_may_pull(skb, ETH_HLEN))
215		return 0;
216	skb->protocol = eth_hdr(skb)->h_proto;
217
218	return 1;
219}
220
221static const u8 *save16bit(struct param *p, const u8 *datap)
222{
223	p->is_present = 1;
224	p->word = get_unaligned_be16(datap);
225	return datap + sizeof(p->word);
226}
227
228static const u8 *save8bit(struct param *p, const u8 *datap)
229{
230	p->is_present = 1;
231	p->byte = *datap;
232	return datap + sizeof(p->byte);
233}
234
235/*----------------------------------------------------------------------------*
236 *                              BEGIN HIP                                     *
237 *----------------------------------------------------------------------------*/
238/* HIP header */
239#define SIERRA_NET_HIP_HDR_LEN 4
240/* Extended HIP header */
241#define SIERRA_NET_HIP_EXT_HDR_LEN 6
242
243struct hip_hdr {
244	int    hdrlen;
245	struct param payload_len;
246	struct param msgid;
247	struct param msgspecific;
248	struct param extmsgid;
249};
250
251static int parse_hip(const u8 *buf, const u32 buflen, struct hip_hdr *hh)
252{
253	const u8 *curp = buf;
254	int    padded;
255
256	if (buflen < SIERRA_NET_HIP_HDR_LEN)
257		return -EPROTO;
258
259	curp = save16bit(&hh->payload_len, curp);
260	curp = save8bit(&hh->msgid, curp);
261	curp = save8bit(&hh->msgspecific, curp);
262
263	padded = hh->msgid.byte & 0x80;
264	hh->msgid.byte &= 0x7F;			/* 7 bits */
265
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)
269			return -EPROTO;
270
271		hh->payload_len.word &= 0x3FFF; /* 14 bits */
272
273		curp = save16bit(&hh->extmsgid, curp);
274		hh->extmsgid.word &= 0x03FF;	/* 10 bits */
275
276		hh->hdrlen = SIERRA_NET_HIP_EXT_HDR_LEN;
277	} else {
278		hh->payload_len.word &= 0x07FF;	/* 11 bits */
279		hh->hdrlen = SIERRA_NET_HIP_HDR_LEN;
280	}
281
282	if (padded) {
283		hh->hdrlen++;
284		hh->payload_len.word--;
285	}
286
287	/* if real packet shorter than the claimed length */
288	if (buflen < (hh->hdrlen + hh->payload_len.word))
289		return -EINVAL;
290
291	return 0;
292}
293
294static void build_hip(u8 *buf, const u16 payloadlen,
295		struct sierra_net_data *priv)
296{
297	/* the following doesn't have the full functionality. We
298	 * currently build only one kind of header, so it is faster this way
299	 */
300	put_unaligned_be16(payloadlen, buf);
301	memcpy(buf+2, priv->tx_hdr_template, sizeof(priv->tx_hdr_template));
302}
303/*----------------------------------------------------------------------------*
304 *                              END HIP                                       *
305 *----------------------------------------------------------------------------*/
306
307static int sierra_net_send_cmd(struct usbnet *dev,
308		u8 *cmd, int cmdlen, const char * cmd_name)
309{
310	struct sierra_net_data *priv = sierra_net_get_private(dev);
311	int  status;
312
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);
 
316
317	if (status != cmdlen && status != -ENODEV)
318		netdev_err(dev->net, "Submit %s failed %d\n", cmd_name, status);
319
320	return status;
321}
322
323static int sierra_net_send_sync(struct usbnet *dev)
324{
325	int  status;
326	struct sierra_net_data *priv = sierra_net_get_private(dev);
327
328	dev_dbg(&dev->udev->dev, "%s", __func__);
329
330	status = sierra_net_send_cmd(dev, priv->sync_msg,
331			sizeof(priv->sync_msg), "SYNC");
332
333	return status;
334}
335
336static void sierra_net_set_ctx_index(struct sierra_net_data *priv, u8 ctx_ix)
337{
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);
343}
344
345static inline int sierra_net_is_valid_addrlen(u8 len)
346{
347	return len == sizeof(struct in_addr);
348}
349
350static int sierra_net_parse_lsi(struct usbnet *dev, char *data, int datalen)
351{
352	struct lsi_umts *lsi = (struct lsi_umts *)data;
353
354	if (datalen < sizeof(struct lsi_umts)) {
355		netdev_err(dev->net, "%s: Data length %d, exp %Zu\n",
356				__func__, datalen,
357				sizeof(struct lsi_umts));
358		return -1;
359	}
360
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);
365		return -1;
366	}
367
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",
371			lsi->protocol);
372		return -1;
373	}
374
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",
378			lsi->link_type);
379		return -1;
380	}
381
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);
386		return 0;
387	}
388
389	/* Validate the session state */
390	if (lsi->session_state == SIERRA_NET_SESSION_IDLE) {
391		netdev_err(dev->net, "Session idle, 0x%02x\n",
392			lsi->session_state);
393		return 0;
394	}
395
396	/* Set link_sense true */
397	return 1;
398}
399
400static void sierra_net_handle_lsi(struct usbnet *dev, char *data,
401		struct hip_hdr	*hh)
402{
403	struct sierra_net_data *priv = sierra_net_get_private(dev);
404	int link_up;
405
406	link_up = sierra_net_parse_lsi(dev, data + hh->hdrlen,
407					hh->payload_len.word);
408	if (link_up < 0) {
409		netdev_err(dev->net, "Invalid LSI\n");
410		return;
411	}
412	if (link_up) {
413		sierra_net_set_ctx_index(priv, hh->msgspecific.byte);
414		priv->link_up = 1;
 
415	} else {
416		priv->link_up = 0;
 
417	}
418	usbnet_link_change(dev, link_up, 0);
419}
420
421static void sierra_net_dosync(struct usbnet *dev)
422{
423	int status;
424	struct sierra_net_data *priv = sierra_net_get_private(dev);
425
426	dev_dbg(&dev->udev->dev, "%s", __func__);
427
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
433	 */
434
435	/* tell modem we are ready */
436	status = sierra_net_send_sync(dev);
437	if (status < 0)
438		netdev_err(dev->net,
439			"Send SYNC failed, status %d\n", status);
440	status = sierra_net_send_sync(dev);
441	if (status < 0)
442		netdev_err(dev->net,
443			"Send SYNC failed, status %d\n", status);
444
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);
450}
451
452static void sierra_net_kevent(struct work_struct *work)
453{
454	struct sierra_net_data *priv =
455		container_of(work, struct sierra_net_data, sierra_net_kevent);
456	struct usbnet *dev = priv->usbnet;
457	int  len;
458	int  err;
459	u8  *buf;
460	u8   ifnum;
461
462	if (test_bit(SIERRA_NET_EVENT_RESP_AVAIL, &priv->kevent_flags)) {
463		clear_bit(SIERRA_NET_EVENT_RESP_AVAIL, &priv->kevent_flags);
464
465		/* Query the modem for the LSI message */
466		buf = kzalloc(SIERRA_NET_USBCTL_BUF_LEN, GFP_KERNEL);
467		if (!buf)
 
 
468			return;
469
470		ifnum = priv->ifnum;
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);
476
477		if (len < 0) {
478			netdev_err(dev->net,
479				"usb_control_msg failed, status %d\n", len);
480		} else {
481			struct hip_hdr	hh;
482
483			dev_dbg(&dev->udev->dev, "%s: Received status message,"
484				" %04x bytes", __func__, len);
485
486			err = parse_hip(buf, len, &hh);
487			if (err) {
488				netdev_err(dev->net, "%s: Bad packet,"
489					" parse result %d\n", __func__, err);
490				kfree(buf);
491				return;
492			}
493
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);
499				kfree(buf);
500				return;
501			}
502
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);
509				break;
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);
518				break;
519			case SIERRA_NET_HIP_HSYNC_ID:
520				dev_dbg(&dev->udev->dev, "SYNC received");
521				err = sierra_net_send_sync(dev);
522				if (err < 0)
523					netdev_err(dev->net,
524						"Send SYNC failed %d\n", err);
525				break;
526			case SIERRA_NET_HIP_EXTENDEDID:
527				netdev_err(dev->net, "Unrecognized HIP msg, "
528					"extmsgid 0x%04x\n", hh.extmsgid.word);
529				break;
530			case SIERRA_NET_HIP_RCGI:
531				/* Ignored */
532				break;
533			default:
534				netdev_err(dev->net, "Unrecognized HIP msg, "
535					"msgid 0x%02x\n", hh.msgid.byte);
536				break;
537			}
538		}
539		kfree(buf);
540	}
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);
546	}
547
548	if (priv->kevent_flags)
549		dev_dbg(&dev->udev->dev, "sierra_net_kevent done, "
550			"kevent_flags = 0x%lx", priv->kevent_flags);
551}
552
553static void sierra_net_defer_kevent(struct usbnet *dev, int work)
554{
555	struct sierra_net_data *priv = sierra_net_get_private(dev);
556
557	set_bit(work, &priv->kevent_flags);
558	schedule_work(&priv->sierra_net_kevent);
559}
560
561/*
562 * Sync Retransmit Timer Handler. On expiry, kick the work queue
563 */
564static void sierra_sync_timer(unsigned long syncdata)
565{
566	struct usbnet *dev = (struct usbnet *)syncdata;
567
568	dev_dbg(&dev->udev->dev, "%s", __func__);
569	/* Kick the tasklet */
570	sierra_net_defer_kevent(dev, SIERRA_NET_TIMER_EXPIRY);
571}
572
573static void sierra_net_status(struct usbnet *dev, struct urb *urb)
574{
575	struct usb_cdc_notification *event;
576
577	dev_dbg(&dev->udev->dev, "%s", __func__);
578
579	if (urb->actual_length < sizeof *event)
580		return;
581
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 */
588		break;
589	case USB_CDC_NOTIFY_RESPONSE_AVAILABLE:
590		sierra_net_defer_kevent(dev, SIERRA_NET_EVENT_RESP_AVAIL);
591		break;
592	default:
593		netdev_err(dev->net, ": unexpected notification %02x!\n",
594				event->bNotificationType);
595		break;
596	}
597}
598
599static void sierra_net_get_drvinfo(struct net_device *net,
600		struct ethtool_drvinfo *info)
601{
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));
606}
607
608static u32 sierra_net_get_link(struct net_device *net)
609{
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);
613}
614
615static 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,
623};
624
625/* MTU can not be more than 1500 bytes, enforce it. */
626static int sierra_net_change_mtu(struct net_device *net, int new_mtu)
627{
628	if (new_mtu > SIERRA_NET_MAX_SUPPORTED_MTU)
629		return -EINVAL;
630
631	return usbnet_change_mtu(net, new_mtu);
632}
633
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
634static int sierra_net_get_fw_attr(struct usbnet *dev, u16 *datap)
635{
636	int result = 0;
637	__le16 attrdata;
 
 
 
 
638
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 */
647				);
 
 
648
649	if (result < 0)
 
650		return -EIO;
 
 
 
651
652	*datap = le16_to_cpu(attrdata);
653	return result;
654}
655
656/*
657 * collects the bulk endpoints, the status endpoint.
658 */
659static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
660{
661	u8	ifacenum;
662	u8	numendpoints;
663	u16	fwattr = 0;
664	int	status;
665	struct ethhdr *eth;
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};
671
 
 
 
672	dev_dbg(&dev->udev->dev, "%s", __func__);
673
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",
679			numendpoints);
680		return -ENODEV;
681	}
682	/* Status endpoint set in usbnet_get_endpoints() */
683	dev->status = NULL;
684	status = usbnet_get_endpoints(dev, intf);
685	if (status < 0) {
686		dev_err(&dev->udev->dev, "Error in usbnet_get_endpoints (%d)",
687			status);
688		return -ENODEV;
689	}
690	/* Initialize sierra private data */
691	priv = kzalloc(sizeof *priv, GFP_KERNEL);
692	if (!priv)
 
693		return -ENOMEM;
 
694
695	priv->usbnet = dev;
696	priv->ifnum = ifacenum;
697	dev->net->netdev_ops = &sierra_net_device_ops;
698
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;
702
703	/* we will have to manufacture ethernet headers, prepare template */
704	eth = (struct ethhdr *)priv->ethr_hdr_tmpl;
705	memcpy(&eth->h_dest, dev->net->dev_addr, ETH_ALEN);
706	eth->h_proto = cpu_to_be16(ETH_P_IP);
707
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);
712
713	/* prepare sync message template */
714	memcpy(priv->sync_msg, sync_tmplate, sizeof(priv->sync_msg));
715
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);
720
721	dev->net->hard_header_len += SIERRA_NET_HIP_EXT_HDR_LEN;
722	dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
723
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);
728
729	sierra_net_set_private(dev, priv);
730
731	priv->kevent_flags = 0;
732
733	/* Use the shared workqueue */
734	INIT_WORK(&priv->sierra_net_kevent, sierra_net_kevent);
735
736	/* Only need to do this once */
737	init_timer(&priv->sync_timer);
738
739	/* verify fw attributes */
740	status = sierra_net_get_fw_attr(dev, &fwattr);
741	dev_dbg(&dev->udev->dev, "Fw attr: %x\n", fwattr);
742
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"
747			" versions\n");
748		kfree(priv);
749		return -ENODEV;
750	}
 
 
 
 
 
751
752	return 0;
753}
754
755static void sierra_net_unbind(struct usbnet *dev, struct usb_interface *intf)
756{
757	int status;
758	struct sierra_net_data *priv = sierra_net_get_private(dev);
759
760	dev_dbg(&dev->udev->dev, "%s", __func__);
761
762	/* kill the timer and work */
763	del_timer_sync(&priv->sync_timer);
764	cancel_work_sync(&priv->sierra_net_kevent);
765
766	/* tell modem we are going away */
767	status = sierra_net_send_cmd(dev, priv->shdwn_msg,
768			sizeof(priv->shdwn_msg), "Shutdown");
769	if (status < 0)
770		netdev_err(dev->net,
771			"usb_control_msg failed, status %d\n", status);
772
773	usbnet_status_stop(dev);
774
775	sierra_net_set_private(dev, NULL);
 
776	kfree(priv);
777}
778
779static struct sk_buff *sierra_net_skb_clone(struct usbnet *dev,
780		struct sk_buff *skb, int len)
781{
782	struct sk_buff *new_skb;
783
784	/* clone skb */
785	new_skb = skb_clone(skb, GFP_ATOMIC);
786
787	/* remove len bytes from original */
788	skb_pull(skb, len);
789
790	/* trim next packet to it's length */
791	if (new_skb) {
792		skb_trim(new_skb, len);
793	} else {
794		if (netif_msg_rx_err(dev))
795			netdev_err(dev->net, "failed to get skb\n");
796		dev->net->stats.rx_dropped++;
797	}
798
799	return new_skb;
800}
801
802/* ---------------------------- Receive data path ----------------------*/
803static int sierra_net_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
804{
805	int err;
806	struct hip_hdr  hh;
807	struct sk_buff *new_skb;
808
809	dev_dbg(&dev->udev->dev, "%s", __func__);
810
811	/* could contain multiple packets */
812	while (likely(skb->len)) {
813		err = parse_hip(skb->data, skb->len, &hh);
814		if (err) {
815			if (netif_msg_rx_err(dev))
816				netdev_err(dev->net, "Invalid HIP header %d\n",
817					err);
818			/* dev->net->stats.rx_errors incremented by caller */
819			dev->net->stats.rx_length_errors++;
820			return 0;
821		}
822
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");
828
829			dev->net->stats.rx_frame_errors++;
830			/* dev->net->stats.rx_errors incremented by caller */
831			return 0;
832		}
833
834		skb_pull(skb, hh.hdrlen);
835
836		/* We are going to accept this packet, prepare it */
837		memcpy(skb->data, sierra_net_get_private(dev)->ethr_hdr_tmpl,
838			ETH_HLEN);
839
840		/* Last packet in batch handled by usbnet */
841		if (hh.payload_len.word == skb->len)
842			return 1;
843
844		new_skb = sierra_net_skb_clone(dev, skb, hh.payload_len.word);
845		if (new_skb)
846			usbnet_skb_return(dev, new_skb);
847
848	} /* while */
849
850	return 0;
851}
852
853/* ---------------------------- Transmit data path ----------------------*/
854static struct sk_buff *sierra_net_tx_fixup(struct usbnet *dev,
855					   struct sk_buff *skb, gfp_t flags)
856{
857	struct sierra_net_data *priv = sierra_net_get_private(dev);
858	u16 len;
859	bool need_tail;
860
861	BUILD_BUG_ON(FIELD_SIZEOF(struct usbnet, data)
862				< sizeof(struct cdc_state));
863
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 */
869			len = skb->len;
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);
874			if (need_tail) {
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);
879					return NULL;
880				} else {
881					skb->data[skb->len] = 0;
882					__skb_put(skb, 1);
883					len = len + 1;
884				}
885			}
886			build_hip(skb->data, len, priv);
887			return skb;
888		} else {
889			/*
890			 * compensate in the future if necessary
891			 */
892			netdev_err(dev->net, "tx_fixup: no room for HIP\n");
893		} /* headroom */
894	}
895
896	if (!priv->link_up)
897		dev->net->stats.tx_carrier_errors++;
898
899	/* tx_dropped incremented by usbnet */
900
901	/* filter the packet out, release it  */
902	dev_kfree_skb_any(skb);
903	return NULL;
904}
905
 
 
 
 
 
 
 
 
 
906static 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,
 
914};
915
916static int
917sierra_net_probe(struct usb_interface *udev, const struct usb_device_id *prod)
918{
919	int ret;
920
921	ret = usbnet_probe(udev, prod);
922	if (ret == 0) {
923		struct usbnet *dev = usb_get_intfdata(udev);
924
925		ret = usbnet_status_start(dev, GFP_KERNEL);
926		if (ret == 0) {
927			/* Interrupt URB now set up; initiate sync sequence */
928			sierra_net_dosync(dev);
929		}
930	}
931	return ret;
932}
933
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}
941
942static 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 */
 
 
 
 
947
948	{}, /* last item */
949};
950MODULE_DEVICE_TABLE(usb, products);
951
952/* We are based on usbnet, so let it handle the USB driver specifics */
953static 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,
960	.no_dynamic_id = 1,
961	.disable_hub_initiated_lpm = 1,
962};
963
964module_usb_driver(sierra_net_driver);
965
966MODULE_AUTHOR(DRIVER_AUTHOR);
967MODULE_DESCRIPTION(DRIVER_DESC);
968MODULE_VERSION(DRIVER_VERSION);
969MODULE_LICENSE("GPL");
v3.5.6
  1/*
  2 * USB-to-WWAN Driver for Sierra Wireless modems
  3 *
  4 * Copyright (C) 2008, 2009, 2010 Paxton Smith, Matthew Safar, Rory Filer
  5 *                          <linux@sierrawireless.com>
  6 *
  7 * Portions of this based on the cdc_ether driver by David Brownell (2003-2005)
  8 * and Ole Andre Vadla Ravnas (ActiveSync) (2006).
  9 *
 10 * IMPORTANT DISCLAIMER: This driver is not commercially supported by
 11 * Sierra Wireless. Use at your own risk.
 12 *
 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.
 17 *
 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.
 22 *
 23 * You should have received a copy of the GNU General Public License
 24 * along with this program; if not, write to the Free Software
 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 26 */
 27
 28#define DRIVER_VERSION "v.2.0"
 29#define DRIVER_AUTHOR "Paxton Smith, Matthew Safar, Rory Filer"
 30#define DRIVER_DESC "USB-to-WWAN Driver for Sierra Wireless modems"
 31static const char driver_name[] = "sierra_net";
 32
 33/* if defined debug messages enabled */
 34/*#define	DEBUG*/
 35
 36#include <linux/module.h>
 37#include <linux/etherdevice.h>
 38#include <linux/ethtool.h>
 39#include <linux/mii.h>
 40#include <linux/sched.h>
 41#include <linux/timer.h>
 42#include <linux/usb.h>
 43#include <linux/usb/cdc.h>
 44#include <net/ip.h>
 45#include <net/udp.h>
 46#include <asm/unaligned.h>
 47#include <linux/usb/usbnet.h>
 48
 49#define SWI_USB_REQUEST_GET_FW_ATTR	0x06
 50#define SWI_GET_FW_ATTR_MASK		0x08
 51
 52/* atomic counter partially included in MAC address to make sure 2 devices
 53 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
 54 */
 55static	atomic_t iface_counter = ATOMIC_INIT(0);
 56
 57/*
 58 * SYNC Timer Delay definition used to set the expiry time
 59 */
 60#define SIERRA_NET_SYNCDELAY (2*HZ)
 61
 62/* Max. MTU supported. The modem buffers are limited to 1500 */
 63#define SIERRA_NET_MAX_SUPPORTED_MTU	1500
 64
 65/* The SIERRA_NET_USBCTL_BUF_LEN defines a buffer size allocated for control
 66 * message reception ... and thus the max. received packet.
 67 * (May be the cause for parse_hip returning -EINVAL)
 68 */
 69#define SIERRA_NET_USBCTL_BUF_LEN	1024
 70
 71/* list of interface numbers - used for constructing interface lists */
 72struct sierra_net_iface_info {
 73	const u32 infolen;	/* number of interface numbers on list */
 74	const u8  *ifaceinfo;	/* pointer to the array holding the numbers */
 75};
 76
 77struct sierra_net_info_data {
 78	u16 rx_urb_size;
 79	struct sierra_net_iface_info whitelist;
 80};
 81
 82/* Private data structure */
 83struct sierra_net_data {
 84
 85	u8 ethr_hdr_tmpl[ETH_HLEN]; /* ethernet header template for rx'd pkts */
 86
 87	u16 link_up;		/* air link up or down */
 88	u8 tx_hdr_template[4];	/* part of HIP hdr for tx'd packets */
 89
 90	u8 sync_msg[4];		/* SYNC message */
 91	u8 shdwn_msg[4];	/* Shutdown message */
 92
 93	/* Backpointer to the container */
 94	struct usbnet *usbnet;
 95
 96	u8 ifnum;	/* interface number */
 97
 98/* Bit masks, must be a power of 2 */
 99#define SIERRA_NET_EVENT_RESP_AVAIL    0x01
100#define SIERRA_NET_TIMER_EXPIRY        0x02
101	unsigned long kevent_flags;
102	struct work_struct sierra_net_kevent;
103	struct timer_list sync_timer; /* For retrying SYNC sequence */
104};
105
106struct param {
107	int is_present;
108	union {
109		void  *ptr;
110		u32    dword;
111		u16    word;
112		u8     byte;
113	};
114};
115
116/* HIP message type */
117#define SIERRA_NET_HIP_EXTENDEDID	0x7F
118#define SIERRA_NET_HIP_HSYNC_ID		0x60	/* Modem -> host */
119#define SIERRA_NET_HIP_RESTART_ID	0x62	/* Modem -> host */
120#define SIERRA_NET_HIP_MSYNC_ID		0x20	/* Host -> modem */
121#define SIERRA_NET_HIP_SHUTD_ID		0x26	/* Host -> modem */
122
123#define SIERRA_NET_HIP_EXT_IP_IN_ID   0x0202
124#define SIERRA_NET_HIP_EXT_IP_OUT_ID  0x0002
125
126/* 3G UMTS Link Sense Indication definitions */
127#define SIERRA_NET_HIP_LSI_UMTSID	0x78
128
129/* Reverse Channel Grant Indication HIP message */
130#define SIERRA_NET_HIP_RCGI		0x64
131
132/* LSI Protocol types */
133#define SIERRA_NET_PROTOCOL_UMTS      0x01
134/* LSI Coverage */
135#define SIERRA_NET_COVERAGE_NONE      0x00
136#define SIERRA_NET_COVERAGE_NOPACKET  0x01
137
138/* LSI Session */
139#define SIERRA_NET_SESSION_IDLE       0x00
140/* LSI Link types */
141#define SIERRA_NET_AS_LINK_TYPE_IPv4  0x00
142
143struct lsi_umts {
144	u8 protocol;
145	u8 unused1;
146	__be16 length;
147	/* eventually use a union for the rest - assume umts for now */
148	u8 coverage;
149	u8 unused2[41];
150	u8 session_state;
151	u8 unused3[33];
152	u8 link_type;
153	u8 pdp_addr_len; /* NW-supplied PDP address len */
154	u8 pdp_addr[16]; /* NW-supplied PDP address (bigendian)) */
155	u8 unused4[23];
156	u8 dns1_addr_len; /* NW-supplied 1st DNS address len (bigendian) */
157	u8 dns1_addr[16]; /* NW-supplied 1st DNS address */
158	u8 dns2_addr_len; /* NW-supplied 2nd DNS address len */
159	u8 dns2_addr[16]; /* NW-supplied 2nd DNS address (bigendian)*/
160	u8 wins1_addr_len; /* NW-supplied 1st Wins address len */
161	u8 wins1_addr[16]; /* NW-supplied 1st Wins address (bigendian)*/
162	u8 wins2_addr_len; /* NW-supplied 2nd Wins address len */
163	u8 wins2_addr[16]; /* NW-supplied 2nd Wins address (bigendian) */
164	u8 unused5[4];
165	u8 gw_addr_len; /* NW-supplied GW address len */
166	u8 gw_addr[16]; /* NW-supplied GW address (bigendian) */
167	u8 reserved[8];
168} __packed;
169
170#define SIERRA_NET_LSI_COMMON_LEN      4
171#define SIERRA_NET_LSI_UMTS_LEN        (sizeof(struct lsi_umts))
172#define SIERRA_NET_LSI_UMTS_STATUS_LEN \
173	(SIERRA_NET_LSI_UMTS_LEN - SIERRA_NET_LSI_COMMON_LEN)
174
175/* Forward definitions */
176static void sierra_sync_timer(unsigned long syncdata);
177static int sierra_net_change_mtu(struct net_device *net, int new_mtu);
178
179/* Our own net device operations structure */
180static const struct net_device_ops sierra_net_device_ops = {
181	.ndo_open               = usbnet_open,
182	.ndo_stop               = usbnet_stop,
183	.ndo_start_xmit         = usbnet_start_xmit,
184	.ndo_tx_timeout         = usbnet_tx_timeout,
185	.ndo_change_mtu         = sierra_net_change_mtu,
186	.ndo_set_mac_address    = eth_mac_addr,
187	.ndo_validate_addr      = eth_validate_addr,
188};
189
190/* get private data associated with passed in usbnet device */
191static inline struct sierra_net_data *sierra_net_get_private(struct usbnet *dev)
192{
193	return (struct sierra_net_data *)dev->data[0];
194}
195
196/* set private data associated with passed in usbnet device */
197static inline void sierra_net_set_private(struct usbnet *dev,
198			struct sierra_net_data *priv)
199{
200	dev->data[0] = (unsigned long)priv;
201}
202
203/* is packet IPv4 */
204static inline int is_ip(struct sk_buff *skb)
205{
206	return skb->protocol == cpu_to_be16(ETH_P_IP);
207}
208
209/*
210 * check passed in packet and make sure that:
211 *  - it is linear (no scatter/gather)
212 *  - it is ethernet (mac_header properly set)
213 */
214static int check_ethip_packet(struct sk_buff *skb, struct usbnet *dev)
215{
216	skb_reset_mac_header(skb); /* ethernet header */
217
218	if (skb_is_nonlinear(skb)) {
219		netdev_err(dev->net, "Non linear buffer-dropping\n");
220		return 0;
221	}
222
223	if (!pskb_may_pull(skb, ETH_HLEN))
224		return 0;
225	skb->protocol = eth_hdr(skb)->h_proto;
226
227	return 1;
228}
229
230static const u8 *save16bit(struct param *p, const u8 *datap)
231{
232	p->is_present = 1;
233	p->word = get_unaligned_be16(datap);
234	return datap + sizeof(p->word);
235}
236
237static const u8 *save8bit(struct param *p, const u8 *datap)
238{
239	p->is_present = 1;
240	p->byte = *datap;
241	return datap + sizeof(p->byte);
242}
243
244/*----------------------------------------------------------------------------*
245 *                              BEGIN HIP                                     *
246 *----------------------------------------------------------------------------*/
247/* HIP header */
248#define SIERRA_NET_HIP_HDR_LEN 4
249/* Extended HIP header */
250#define SIERRA_NET_HIP_EXT_HDR_LEN 6
251
252struct hip_hdr {
253	int    hdrlen;
254	struct param payload_len;
255	struct param msgid;
256	struct param msgspecific;
257	struct param extmsgid;
258};
259
260static int parse_hip(const u8 *buf, const u32 buflen, struct hip_hdr *hh)
261{
262	const u8 *curp = buf;
263	int    padded;
264
265	if (buflen < SIERRA_NET_HIP_HDR_LEN)
266		return -EPROTO;
267
268	curp = save16bit(&hh->payload_len, curp);
269	curp = save8bit(&hh->msgid, curp);
270	curp = save8bit(&hh->msgspecific, curp);
271
272	padded = hh->msgid.byte & 0x80;
273	hh->msgid.byte &= 0x7F;			/* 7 bits */
274
275	hh->extmsgid.is_present = (hh->msgid.byte == SIERRA_NET_HIP_EXTENDEDID);
276	if (hh->extmsgid.is_present) {
277		if (buflen < SIERRA_NET_HIP_EXT_HDR_LEN)
278			return -EPROTO;
279
280		hh->payload_len.word &= 0x3FFF; /* 14 bits */
281
282		curp = save16bit(&hh->extmsgid, curp);
283		hh->extmsgid.word &= 0x03FF;	/* 10 bits */
284
285		hh->hdrlen = SIERRA_NET_HIP_EXT_HDR_LEN;
286	} else {
287		hh->payload_len.word &= 0x07FF;	/* 11 bits */
288		hh->hdrlen = SIERRA_NET_HIP_HDR_LEN;
289	}
290
291	if (padded) {
292		hh->hdrlen++;
293		hh->payload_len.word--;
294	}
295
296	/* if real packet shorter than the claimed length */
297	if (buflen < (hh->hdrlen + hh->payload_len.word))
298		return -EINVAL;
299
300	return 0;
301}
302
303static void build_hip(u8 *buf, const u16 payloadlen,
304		struct sierra_net_data *priv)
305{
306	/* the following doesn't have the full functionality. We
307	 * currently build only one kind of header, so it is faster this way
308	 */
309	put_unaligned_be16(payloadlen, buf);
310	memcpy(buf+2, priv->tx_hdr_template, sizeof(priv->tx_hdr_template));
311}
312/*----------------------------------------------------------------------------*
313 *                              END HIP                                       *
314 *----------------------------------------------------------------------------*/
315
316static int sierra_net_send_cmd(struct usbnet *dev,
317		u8 *cmd, int cmdlen, const char * cmd_name)
318{
319	struct sierra_net_data *priv = sierra_net_get_private(dev);
320	int  status;
321
322	status = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
323			USB_CDC_SEND_ENCAPSULATED_COMMAND,
324			USB_DIR_OUT|USB_TYPE_CLASS|USB_RECIP_INTERFACE,	0,
325			priv->ifnum, cmd, cmdlen, USB_CTRL_SET_TIMEOUT);
326
327	if (status != cmdlen && status != -ENODEV)
328		netdev_err(dev->net, "Submit %s failed %d\n", cmd_name, status);
329
330	return status;
331}
332
333static int sierra_net_send_sync(struct usbnet *dev)
334{
335	int  status;
336	struct sierra_net_data *priv = sierra_net_get_private(dev);
337
338	dev_dbg(&dev->udev->dev, "%s", __func__);
339
340	status = sierra_net_send_cmd(dev, priv->sync_msg,
341			sizeof(priv->sync_msg), "SYNC");
342
343	return status;
344}
345
346static void sierra_net_set_ctx_index(struct sierra_net_data *priv, u8 ctx_ix)
347{
348	dev_dbg(&(priv->usbnet->udev->dev), "%s %d", __func__, ctx_ix);
349	priv->tx_hdr_template[0] = 0x3F;
350	priv->tx_hdr_template[1] = ctx_ix;
351	*((u16 *)&priv->tx_hdr_template[2]) =
352		cpu_to_be16(SIERRA_NET_HIP_EXT_IP_OUT_ID);
353}
354
355static inline int sierra_net_is_valid_addrlen(u8 len)
356{
357	return len == sizeof(struct in_addr);
358}
359
360static int sierra_net_parse_lsi(struct usbnet *dev, char *data, int datalen)
361{
362	struct lsi_umts *lsi = (struct lsi_umts *)data;
363
364	if (datalen < sizeof(struct lsi_umts)) {
365		netdev_err(dev->net, "%s: Data length %d, exp %Zu\n",
366				__func__, datalen,
367				sizeof(struct lsi_umts));
368		return -1;
369	}
370
371	if (lsi->length != cpu_to_be16(SIERRA_NET_LSI_UMTS_STATUS_LEN)) {
372		netdev_err(dev->net, "%s: LSI_UMTS_STATUS_LEN %d, exp %u\n",
373				__func__, be16_to_cpu(lsi->length),
374				(u32)SIERRA_NET_LSI_UMTS_STATUS_LEN);
375		return -1;
376	}
377
378	/* Validate the protocol  - only support UMTS for now */
379	if (lsi->protocol != SIERRA_NET_PROTOCOL_UMTS) {
380		netdev_err(dev->net, "Protocol unsupported, 0x%02x\n",
381			lsi->protocol);
382		return -1;
383	}
384
385	/* Validate the link type */
386	if (lsi->link_type != SIERRA_NET_AS_LINK_TYPE_IPv4) {
387		netdev_err(dev->net, "Link type unsupported: 0x%02x\n",
388			lsi->link_type);
389		return -1;
390	}
391
392	/* Validate the coverage */
393	if (lsi->coverage == SIERRA_NET_COVERAGE_NONE
394	   || lsi->coverage == SIERRA_NET_COVERAGE_NOPACKET) {
395		netdev_err(dev->net, "No coverage, 0x%02x\n", lsi->coverage);
396		return 0;
397	}
398
399	/* Validate the session state */
400	if (lsi->session_state == SIERRA_NET_SESSION_IDLE) {
401		netdev_err(dev->net, "Session idle, 0x%02x\n",
402			lsi->session_state);
403		return 0;
404	}
405
406	/* Set link_sense true */
407	return 1;
408}
409
410static void sierra_net_handle_lsi(struct usbnet *dev, char *data,
411		struct hip_hdr	*hh)
412{
413	struct sierra_net_data *priv = sierra_net_get_private(dev);
414	int link_up;
415
416	link_up = sierra_net_parse_lsi(dev, data + hh->hdrlen,
417					hh->payload_len.word);
418	if (link_up < 0) {
419		netdev_err(dev->net, "Invalid LSI\n");
420		return;
421	}
422	if (link_up) {
423		sierra_net_set_ctx_index(priv, hh->msgspecific.byte);
424		priv->link_up = 1;
425		netif_carrier_on(dev->net);
426	} else {
427		priv->link_up = 0;
428		netif_carrier_off(dev->net);
429	}
 
430}
431
432static void sierra_net_dosync(struct usbnet *dev)
433{
434	int status;
435	struct sierra_net_data *priv = sierra_net_get_private(dev);
436
437	dev_dbg(&dev->udev->dev, "%s", __func__);
438
 
 
 
 
 
 
 
439	/* tell modem we are ready */
440	status = sierra_net_send_sync(dev);
441	if (status < 0)
442		netdev_err(dev->net,
443			"Send SYNC failed, status %d\n", status);
444	status = sierra_net_send_sync(dev);
445	if (status < 0)
446		netdev_err(dev->net,
447			"Send SYNC failed, status %d\n", status);
448
449	/* Now, start a timer and make sure we get the Restart Indication */
450	priv->sync_timer.function = sierra_sync_timer;
451	priv->sync_timer.data = (unsigned long) dev;
452	priv->sync_timer.expires = jiffies + SIERRA_NET_SYNCDELAY;
453	add_timer(&priv->sync_timer);
454}
455
456static void sierra_net_kevent(struct work_struct *work)
457{
458	struct sierra_net_data *priv =
459		container_of(work, struct sierra_net_data, sierra_net_kevent);
460	struct usbnet *dev = priv->usbnet;
461	int  len;
462	int  err;
463	u8  *buf;
464	u8   ifnum;
465
466	if (test_bit(SIERRA_NET_EVENT_RESP_AVAIL, &priv->kevent_flags)) {
467		clear_bit(SIERRA_NET_EVENT_RESP_AVAIL, &priv->kevent_flags);
468
469		/* Query the modem for the LSI message */
470		buf = kzalloc(SIERRA_NET_USBCTL_BUF_LEN, GFP_KERNEL);
471		if (!buf) {
472			netdev_err(dev->net,
473				"failed to allocate buf for LS msg\n");
474			return;
475		}
476		ifnum = priv->ifnum;
477		len = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
478				USB_CDC_GET_ENCAPSULATED_RESPONSE,
479				USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE,
480				0, ifnum, buf, SIERRA_NET_USBCTL_BUF_LEN,
481				USB_CTRL_SET_TIMEOUT);
482
483		if (len < 0) {
484			netdev_err(dev->net,
485				"usb_control_msg failed, status %d\n", len);
486		} else {
487			struct hip_hdr	hh;
488
489			dev_dbg(&dev->udev->dev, "%s: Received status message,"
490				" %04x bytes", __func__, len);
491
492			err = parse_hip(buf, len, &hh);
493			if (err) {
494				netdev_err(dev->net, "%s: Bad packet,"
495					" parse result %d\n", __func__, err);
496				kfree(buf);
497				return;
498			}
499
500			/* Validate packet length */
501			if (len != hh.hdrlen + hh.payload_len.word) {
502				netdev_err(dev->net, "%s: Bad packet, received"
503					" %d, expected %d\n",	__func__, len,
504					hh.hdrlen + hh.payload_len.word);
505				kfree(buf);
506				return;
507			}
508
509			/* Switch on received message types */
510			switch (hh.msgid.byte) {
511			case SIERRA_NET_HIP_LSI_UMTSID:
512				dev_dbg(&dev->udev->dev, "LSI for ctx:%d",
513					hh.msgspecific.byte);
514				sierra_net_handle_lsi(dev, buf, &hh);
515				break;
516			case SIERRA_NET_HIP_RESTART_ID:
517				dev_dbg(&dev->udev->dev, "Restart reported: %d,"
518						" stopping sync timer",
519						hh.msgspecific.byte);
520				/* Got sync resp - stop timer & clear mask */
521				del_timer_sync(&priv->sync_timer);
522				clear_bit(SIERRA_NET_TIMER_EXPIRY,
523					  &priv->kevent_flags);
524				break;
525			case SIERRA_NET_HIP_HSYNC_ID:
526				dev_dbg(&dev->udev->dev, "SYNC received");
527				err = sierra_net_send_sync(dev);
528				if (err < 0)
529					netdev_err(dev->net,
530						"Send SYNC failed %d\n", err);
531				break;
532			case SIERRA_NET_HIP_EXTENDEDID:
533				netdev_err(dev->net, "Unrecognized HIP msg, "
534					"extmsgid 0x%04x\n", hh.extmsgid.word);
535				break;
536			case SIERRA_NET_HIP_RCGI:
537				/* Ignored */
538				break;
539			default:
540				netdev_err(dev->net, "Unrecognized HIP msg, "
541					"msgid 0x%02x\n", hh.msgid.byte);
542				break;
543			}
544		}
545		kfree(buf);
546	}
547	/* The sync timer bit might be set */
548	if (test_bit(SIERRA_NET_TIMER_EXPIRY, &priv->kevent_flags)) {
549		clear_bit(SIERRA_NET_TIMER_EXPIRY, &priv->kevent_flags);
550		dev_dbg(&dev->udev->dev, "Deferred sync timer expiry");
551		sierra_net_dosync(priv->usbnet);
552	}
553
554	if (priv->kevent_flags)
555		dev_dbg(&dev->udev->dev, "sierra_net_kevent done, "
556			"kevent_flags = 0x%lx", priv->kevent_flags);
557}
558
559static void sierra_net_defer_kevent(struct usbnet *dev, int work)
560{
561	struct sierra_net_data *priv = sierra_net_get_private(dev);
562
563	set_bit(work, &priv->kevent_flags);
564	schedule_work(&priv->sierra_net_kevent);
565}
566
567/*
568 * Sync Retransmit Timer Handler. On expiry, kick the work queue
569 */
570void sierra_sync_timer(unsigned long syncdata)
571{
572	struct usbnet *dev = (struct usbnet *)syncdata;
573
574	dev_dbg(&dev->udev->dev, "%s", __func__);
575	/* Kick the tasklet */
576	sierra_net_defer_kevent(dev, SIERRA_NET_TIMER_EXPIRY);
577}
578
579static void sierra_net_status(struct usbnet *dev, struct urb *urb)
580{
581	struct usb_cdc_notification *event;
582
583	dev_dbg(&dev->udev->dev, "%s", __func__);
584
585	if (urb->actual_length < sizeof *event)
586		return;
587
588	/* Add cases to handle other standard notifications. */
589	event = urb->transfer_buffer;
590	switch (event->bNotificationType) {
591	case USB_CDC_NOTIFY_NETWORK_CONNECTION:
592	case USB_CDC_NOTIFY_SPEED_CHANGE:
593		/* USB 305 sends those */
594		break;
595	case USB_CDC_NOTIFY_RESPONSE_AVAILABLE:
596		sierra_net_defer_kevent(dev, SIERRA_NET_EVENT_RESP_AVAIL);
597		break;
598	default:
599		netdev_err(dev->net, ": unexpected notification %02x!\n",
600				event->bNotificationType);
601		break;
602	}
603}
604
605static void sierra_net_get_drvinfo(struct net_device *net,
606		struct ethtool_drvinfo *info)
607{
608	/* Inherit standard device info */
609	usbnet_get_drvinfo(net, info);
610	strncpy(info->driver, driver_name, sizeof info->driver);
611	strncpy(info->version, DRIVER_VERSION, sizeof info->version);
612}
613
614static u32 sierra_net_get_link(struct net_device *net)
615{
616	struct usbnet *dev = netdev_priv(net);
617	/* Report link is down whenever the interface is down */
618	return sierra_net_get_private(dev)->link_up && netif_running(net);
619}
620
621static const struct ethtool_ops sierra_net_ethtool_ops = {
622	.get_drvinfo = sierra_net_get_drvinfo,
623	.get_link = sierra_net_get_link,
624	.get_msglevel = usbnet_get_msglevel,
625	.set_msglevel = usbnet_set_msglevel,
626	.get_settings = usbnet_get_settings,
627	.set_settings = usbnet_set_settings,
628	.nway_reset = usbnet_nway_reset,
629};
630
631/* MTU can not be more than 1500 bytes, enforce it. */
632static int sierra_net_change_mtu(struct net_device *net, int new_mtu)
633{
634	if (new_mtu > SIERRA_NET_MAX_SUPPORTED_MTU)
635		return -EINVAL;
636
637	return usbnet_change_mtu(net, new_mtu);
638}
639
640static int is_whitelisted(const u8 ifnum,
641			const struct sierra_net_iface_info *whitelist)
642{
643	if (whitelist) {
644		const u8 *list = whitelist->ifaceinfo;
645		int i;
646
647		for (i = 0; i < whitelist->infolen; i++) {
648			if (list[i] == ifnum)
649				return 1;
650		}
651	}
652	return 0;
653}
654
655static int sierra_net_get_fw_attr(struct usbnet *dev, u16 *datap)
656{
657	int result = 0;
658	u16 *attrdata;
659
660	attrdata = kmalloc(sizeof(*attrdata), GFP_KERNEL);
661	if (!attrdata)
662		return -ENOMEM;
663
664	result = usb_control_msg(
665			dev->udev,
666			usb_rcvctrlpipe(dev->udev, 0),
667			/* _u8 vendor specific request */
668			SWI_USB_REQUEST_GET_FW_ATTR,
669			USB_DIR_IN | USB_TYPE_VENDOR,	/* __u8 request type */
670			0x0000,		/* __u16 value not used */
671			0x0000,		/* __u16 index  not used */
672			attrdata,	/* char *data */
673			sizeof(*attrdata),		/* __u16 size */
674			USB_CTRL_SET_TIMEOUT);	/* int timeout */
675
676	if (result < 0) {
677		kfree(attrdata);
678		return -EIO;
679	}
680
681	*datap = *attrdata;
682
683	kfree(attrdata);
684	return result;
685}
686
687/*
688 * collects the bulk endpoints, the status endpoint.
689 */
690static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
691{
692	u8	ifacenum;
693	u8	numendpoints;
694	u16	fwattr = 0;
695	int	status;
696	struct ethhdr *eth;
697	struct sierra_net_data *priv;
698	static const u8 sync_tmplate[sizeof(priv->sync_msg)] = {
699		0x00, 0x00, SIERRA_NET_HIP_MSYNC_ID, 0x00};
700	static const u8 shdwn_tmplate[sizeof(priv->shdwn_msg)] = {
701		0x00, 0x00, SIERRA_NET_HIP_SHUTD_ID, 0x00};
702
703	struct sierra_net_info_data *data =
704			(struct sierra_net_info_data *)dev->driver_info->data;
705
706	dev_dbg(&dev->udev->dev, "%s", __func__);
707
708	ifacenum = intf->cur_altsetting->desc.bInterfaceNumber;
709	/* We only accept certain interfaces */
710	if (!is_whitelisted(ifacenum, &data->whitelist)) {
711		dev_dbg(&dev->udev->dev, "Ignoring interface: %d", ifacenum);
712		return -ENODEV;
713	}
714	numendpoints = intf->cur_altsetting->desc.bNumEndpoints;
715	/* We have three endpoints, bulk in and out, and a status */
716	if (numendpoints != 3) {
717		dev_err(&dev->udev->dev, "Expected 3 endpoints, found: %d",
718			numendpoints);
719		return -ENODEV;
720	}
721	/* Status endpoint set in usbnet_get_endpoints() */
722	dev->status = NULL;
723	status = usbnet_get_endpoints(dev, intf);
724	if (status < 0) {
725		dev_err(&dev->udev->dev, "Error in usbnet_get_endpoints (%d)",
726			status);
727		return -ENODEV;
728	}
729	/* Initialize sierra private data */
730	priv = kzalloc(sizeof *priv, GFP_KERNEL);
731	if (!priv) {
732		dev_err(&dev->udev->dev, "No memory");
733		return -ENOMEM;
734	}
735
736	priv->usbnet = dev;
737	priv->ifnum = ifacenum;
738	dev->net->netdev_ops = &sierra_net_device_ops;
739
740	/* change MAC addr to include, ifacenum, and to be unique */
741	dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
742	dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
743
744	/* we will have to manufacture ethernet headers, prepare template */
745	eth = (struct ethhdr *)priv->ethr_hdr_tmpl;
746	memcpy(&eth->h_dest, dev->net->dev_addr, ETH_ALEN);
747	eth->h_proto = cpu_to_be16(ETH_P_IP);
748
749	/* prepare shutdown message template */
750	memcpy(priv->shdwn_msg, shdwn_tmplate, sizeof(priv->shdwn_msg));
751	/* set context index initially to 0 - prepares tx hdr template */
752	sierra_net_set_ctx_index(priv, 0);
753
 
 
 
754	/* decrease the rx_urb_size and max_tx_size to 4k on USB 1.1 */
755	dev->rx_urb_size  = data->rx_urb_size;
756	if (dev->udev->speed != USB_SPEED_HIGH)
757		dev->rx_urb_size  = min_t(size_t, 4096, data->rx_urb_size);
758
759	dev->net->hard_header_len += SIERRA_NET_HIP_EXT_HDR_LEN;
760	dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
761
762	/* Set up the netdev */
763	dev->net->flags |= IFF_NOARP;
764	dev->net->ethtool_ops = &sierra_net_ethtool_ops;
765	netif_carrier_off(dev->net);
766
767	sierra_net_set_private(dev, priv);
768
769	priv->kevent_flags = 0;
770
771	/* Use the shared workqueue */
772	INIT_WORK(&priv->sierra_net_kevent, sierra_net_kevent);
773
774	/* Only need to do this once */
775	init_timer(&priv->sync_timer);
776
777	/* verify fw attributes */
778	status = sierra_net_get_fw_attr(dev, &fwattr);
779	dev_dbg(&dev->udev->dev, "Fw attr: %x\n", fwattr);
780
781	/* test whether firmware supports DHCP */
782	if (!(status == sizeof(fwattr) && (fwattr & SWI_GET_FW_ATTR_MASK))) {
783		/* found incompatible firmware version */
784		dev_err(&dev->udev->dev, "Incompatible driver and firmware"
785			" versions\n");
786		kfree(priv);
787		return -ENODEV;
788	}
789	/* prepare sync message from template */
790	memcpy(priv->sync_msg, sync_tmplate, sizeof(priv->sync_msg));
791
792	/* initiate the sync sequence */
793	sierra_net_dosync(dev);
794
795	return 0;
796}
797
798static void sierra_net_unbind(struct usbnet *dev, struct usb_interface *intf)
799{
800	int status;
801	struct sierra_net_data *priv = sierra_net_get_private(dev);
802
803	dev_dbg(&dev->udev->dev, "%s", __func__);
804
805	/* kill the timer and work */
806	del_timer_sync(&priv->sync_timer);
807	cancel_work_sync(&priv->sierra_net_kevent);
808
809	/* tell modem we are going away */
810	status = sierra_net_send_cmd(dev, priv->shdwn_msg,
811			sizeof(priv->shdwn_msg), "Shutdown");
812	if (status < 0)
813		netdev_err(dev->net,
814			"usb_control_msg failed, status %d\n", status);
815
 
 
816	sierra_net_set_private(dev, NULL);
817
818	kfree(priv);
819}
820
821static struct sk_buff *sierra_net_skb_clone(struct usbnet *dev,
822		struct sk_buff *skb, int len)
823{
824	struct sk_buff *new_skb;
825
826	/* clone skb */
827	new_skb = skb_clone(skb, GFP_ATOMIC);
828
829	/* remove len bytes from original */
830	skb_pull(skb, len);
831
832	/* trim next packet to it's length */
833	if (new_skb) {
834		skb_trim(new_skb, len);
835	} else {
836		if (netif_msg_rx_err(dev))
837			netdev_err(dev->net, "failed to get skb\n");
838		dev->net->stats.rx_dropped++;
839	}
840
841	return new_skb;
842}
843
844/* ---------------------------- Receive data path ----------------------*/
845static int sierra_net_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
846{
847	int err;
848	struct hip_hdr  hh;
849	struct sk_buff *new_skb;
850
851	dev_dbg(&dev->udev->dev, "%s", __func__);
852
853	/* could contain multiple packets */
854	while (likely(skb->len)) {
855		err = parse_hip(skb->data, skb->len, &hh);
856		if (err) {
857			if (netif_msg_rx_err(dev))
858				netdev_err(dev->net, "Invalid HIP header %d\n",
859					err);
860			/* dev->net->stats.rx_errors incremented by caller */
861			dev->net->stats.rx_length_errors++;
862			return 0;
863		}
864
865		/* Validate Extended HIP header */
866		if (!hh.extmsgid.is_present
867		    || hh.extmsgid.word != SIERRA_NET_HIP_EXT_IP_IN_ID) {
868			if (netif_msg_rx_err(dev))
869				netdev_err(dev->net, "HIP/ETH: Invalid pkt\n");
870
871			dev->net->stats.rx_frame_errors++;
872			/* dev->net->stats.rx_errors incremented by caller */;
873			return 0;
874		}
875
876		skb_pull(skb, hh.hdrlen);
877
878		/* We are going to accept this packet, prepare it */
879		memcpy(skb->data, sierra_net_get_private(dev)->ethr_hdr_tmpl,
880			ETH_HLEN);
881
882		/* Last packet in batch handled by usbnet */
883		if (hh.payload_len.word == skb->len)
884			return 1;
885
886		new_skb = sierra_net_skb_clone(dev, skb, hh.payload_len.word);
887		if (new_skb)
888			usbnet_skb_return(dev, new_skb);
889
890	} /* while */
891
892	return 0;
893}
894
895/* ---------------------------- Transmit data path ----------------------*/
896struct sk_buff *sierra_net_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
897		gfp_t flags)
898{
899	struct sierra_net_data *priv = sierra_net_get_private(dev);
900	u16 len;
901	bool need_tail;
902
903	BUILD_BUG_ON(FIELD_SIZEOF(struct usbnet, data)
904				< sizeof(struct cdc_state));
905
906	dev_dbg(&dev->udev->dev, "%s", __func__);
907	if (priv->link_up && check_ethip_packet(skb, dev) && is_ip(skb)) {
908		/* enough head room as is? */
909		if (SIERRA_NET_HIP_EXT_HDR_LEN <= skb_headroom(skb)) {
910			/* Save the Eth/IP length and set up HIP hdr */
911			len = skb->len;
912			skb_push(skb, SIERRA_NET_HIP_EXT_HDR_LEN);
913			/* Handle ZLP issue */
914			need_tail = ((len + SIERRA_NET_HIP_EXT_HDR_LEN)
915				% dev->maxpacket == 0);
916			if (need_tail) {
917				if (unlikely(skb_tailroom(skb) == 0)) {
918					netdev_err(dev->net, "tx_fixup:"
919						"no room for packet\n");
920					dev_kfree_skb_any(skb);
921					return NULL;
922				} else {
923					skb->data[skb->len] = 0;
924					__skb_put(skb, 1);
925					len = len + 1;
926				}
927			}
928			build_hip(skb->data, len, priv);
929			return skb;
930		} else {
931			/*
932			 * compensate in the future if necessary
933			 */
934			netdev_err(dev->net, "tx_fixup: no room for HIP\n");
935		} /* headroom */
936	}
937
938	if (!priv->link_up)
939		dev->net->stats.tx_carrier_errors++;
940
941	/* tx_dropped incremented by usbnet */
942
943	/* filter the packet out, release it  */
944	dev_kfree_skb_any(skb);
945	return NULL;
946}
947
948static const u8 sierra_net_ifnum_list[] = { 7, 10, 11 };
949static const struct sierra_net_info_data sierra_net_info_data_direct_ip = {
950	.rx_urb_size = 8 * 1024,
951	.whitelist = {
952		.infolen = ARRAY_SIZE(sierra_net_ifnum_list),
953		.ifaceinfo = sierra_net_ifnum_list
954	}
955};
956
957static const struct driver_info sierra_net_info_direct_ip = {
958	.description = "Sierra Wireless USB-to-WWAN Modem",
959	.flags = FLAG_WWAN | FLAG_SEND_ZLP,
960	.bind = sierra_net_bind,
961	.unbind = sierra_net_unbind,
962	.status = sierra_net_status,
963	.rx_fixup = sierra_net_rx_fixup,
964	.tx_fixup = sierra_net_tx_fixup,
965	.data = (unsigned long)&sierra_net_info_data_direct_ip,
966};
967
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
968static const struct usb_device_id products[] = {
969	{USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless USB-to-WWAN modem */
970	.driver_info = (unsigned long) &sierra_net_info_direct_ip},
971	{USB_DEVICE(0x0F3D, 0x68A3), /* AT&T Direct IP modem */
972	.driver_info = (unsigned long) &sierra_net_info_direct_ip},
973	{USB_DEVICE(0x1199, 0x68AA), /* Sierra Wireless Direct IP LTE modem */
974	.driver_info = (unsigned long) &sierra_net_info_direct_ip},
975	{USB_DEVICE(0x0F3D, 0x68AA), /* AT&T Direct IP LTE modem */
976	.driver_info = (unsigned long) &sierra_net_info_direct_ip},
977
978	{}, /* last item */
979};
980MODULE_DEVICE_TABLE(usb, products);
981
982/* We are based on usbnet, so let it handle the USB driver specifics */
983static struct usb_driver sierra_net_driver = {
984	.name = "sierra_net",
985	.id_table = products,
986	.probe = usbnet_probe,
987	.disconnect = usbnet_disconnect,
988	.suspend = usbnet_suspend,
989	.resume = usbnet_resume,
990	.no_dynamic_id = 1,
991	.disable_hub_initiated_lpm = 1,
992};
993
994module_usb_driver(sierra_net_driver);
995
996MODULE_AUTHOR(DRIVER_AUTHOR);
997MODULE_DESCRIPTION(DRIVER_DESC);
998MODULE_VERSION(DRIVER_VERSION);
999MODULE_LICENSE("GPL");