1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/netdevice.h>
26#include <linux/ethtool.h>
27#include <linux/workqueue.h>
28#include <linux/mii.h>
29#include <linux/crc32.h>
30#include <linux/usb.h>
31#include <linux/usb/cdc.h>
32#include <linux/usb/usbnet.h>
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58static struct sk_buff *
59zaurus_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
60{
61 int padlen;
62 struct sk_buff *skb2;
63
64 padlen = 2;
65 if (!skb_cloned(skb)) {
66 int tailroom = skb_tailroom(skb);
67 if ((padlen + 4) <= tailroom)
68 goto done;
69 }
70 skb2 = skb_copy_expand(skb, 0, 4 + padlen, flags);
71 dev_kfree_skb_any(skb);
72 skb = skb2;
73 if (skb) {
74 u32 fcs;
75done:
76 fcs = crc32_le(~0, skb->data, skb->len);
77 fcs = ~fcs;
78
79 *skb_put (skb, 1) = fcs & 0xff;
80 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
81 *skb_put (skb, 1) = (fcs>>16) & 0xff;
82 *skb_put (skb, 1) = (fcs>>24) & 0xff;
83 }
84 return skb;
85}
86
87static int zaurus_bind(struct usbnet *dev, struct usb_interface *intf)
88{
89
90
91
92 dev->net->hard_header_len += 6;
93 dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu;
94 return usbnet_generic_cdc_bind(dev, intf);
95}
96
97
98static int always_connected (struct usbnet *dev)
99{
100 return 0;
101}
102
103static const struct driver_info zaurus_sl5x00_info = {
104 .description = "Sharp Zaurus SL-5x00",
105 .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_Z,
106 .check_connect = always_connected,
107 .bind = zaurus_bind,
108 .unbind = usbnet_cdc_unbind,
109 .tx_fixup = zaurus_tx_fixup,
110};
111#define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
112
113static const struct driver_info zaurus_pxa_info = {
114 .description = "Sharp Zaurus, PXA-2xx based",
115 .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_Z,
116 .check_connect = always_connected,
117 .bind = zaurus_bind,
118 .unbind = usbnet_cdc_unbind,
119 .tx_fixup = zaurus_tx_fixup,
120};
121#define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
122
123static const struct driver_info olympus_mxl_info = {
124 .description = "Olympus R1000",
125 .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_Z,
126 .check_connect = always_connected,
127 .bind = zaurus_bind,
128 .unbind = usbnet_cdc_unbind,
129 .tx_fixup = zaurus_tx_fixup,
130};
131#define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
132
133
134
135
136
137
138
139
140
141static const u8 safe_guid[16] = {
142 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
143 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
144};
145static const u8 blan_guid[16] = {
146 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70,
147 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37,
148};
149
150static int blan_mdlm_bind(struct usbnet *dev, struct usb_interface *intf)
151{
152 u8 *buf = intf->cur_altsetting->extra;
153 int len = intf->cur_altsetting->extralen;
154 struct usb_cdc_mdlm_desc *desc = NULL;
155 struct usb_cdc_mdlm_detail_desc *detail = NULL;
156
157 while (len > 3) {
158 if (buf [1] != USB_DT_CS_INTERFACE)
159 goto next_desc;
160
161
162
163
164 switch (buf [2]) {
165 case USB_CDC_MDLM_TYPE:
166 if (desc) {
167 dev_dbg(&intf->dev, "extra MDLM\n");
168 goto bad_desc;
169 }
170 desc = (void *) buf;
171 if (desc->bLength != sizeof *desc) {
172 dev_dbg(&intf->dev, "MDLM len %u\n",
173 desc->bLength);
174 goto bad_desc;
175 }
176
177 if (memcmp(&desc->bGUID, blan_guid, 16) &&
178 memcmp(&desc->bGUID, safe_guid, 16)) {
179
180 dev_dbg(&intf->dev, "MDLM guid\n");
181 goto bad_desc;
182 }
183 break;
184 case USB_CDC_MDLM_DETAIL_TYPE:
185 if (detail) {
186 dev_dbg(&intf->dev, "extra MDLM detail\n");
187 goto bad_desc;
188 }
189 detail = (void *) buf;
190 switch (detail->bGuidDescriptorType) {
191 case 0:
192 if (detail->bLength != (sizeof *detail + 2))
193 goto bad_detail;
194 break;
195 case 1:
196 if (detail->bLength != (sizeof *detail + 3))
197 goto bad_detail;
198 break;
199 default:
200 goto bad_detail;
201 }
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216 if ((detail->bDetailData[1] & ~0x02) != 0x01) {
217
218
219
220bad_detail:
221 dev_dbg(&intf->dev,
222 "bad MDLM detail, %d %d %d\n",
223 detail->bLength,
224 detail->bDetailData[0],
225 detail->bDetailData[2]);
226 goto bad_desc;
227 }
228
229
230 dev->net->hard_header_len += 6;
231 dev->rx_urb_size = dev->net->hard_header_len
232 + dev->net->mtu;
233 break;
234 }
235next_desc:
236 len -= buf [0];
237 buf += buf [0];
238 }
239
240 if (!desc || !detail) {
241 dev_dbg(&intf->dev, "missing cdc mdlm %s%sdescriptor\n",
242 desc ? "" : "func ",
243 detail ? "" : "detail ");
244 goto bad_desc;
245 }
246
247
248
249
250
251
252 return usbnet_get_endpoints(dev, intf);
253
254bad_desc:
255 dev_info(&dev->udev->dev, "unsupported MDLM descriptors\n");
256 return -ENODEV;
257}
258
259static const struct driver_info bogus_mdlm_info = {
260 .description = "pseudo-MDLM (BLAN) device",
261 .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_Z,
262 .check_connect = always_connected,
263 .tx_fixup = zaurus_tx_fixup,
264 .bind = blan_mdlm_bind,
265};
266
267static const struct usb_device_id products [] = {
268#define ZAURUS_MASTER_INTERFACE \
269 .bInterfaceClass = USB_CLASS_COMM, \
270 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
271 .bInterfaceProtocol = USB_CDC_PROTO_NONE
272
273
274{
275 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
276 | USB_DEVICE_ID_MATCH_DEVICE,
277 .idVendor = 0x04DD,
278 .idProduct = 0x8004,
279 ZAURUS_MASTER_INTERFACE,
280 .driver_info = ZAURUS_STRONGARM_INFO,
281},
282
283
284
285
286
287
288
289
290{
291 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
292 | USB_DEVICE_ID_MATCH_DEVICE,
293 .idVendor = 0x04DD,
294 .idProduct = 0x8005,
295 ZAURUS_MASTER_INTERFACE,
296 .driver_info = ZAURUS_PXA_INFO,
297}, {
298 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
299 | USB_DEVICE_ID_MATCH_DEVICE,
300 .idVendor = 0x04DD,
301 .idProduct = 0x8006,
302 ZAURUS_MASTER_INTERFACE,
303 .driver_info = ZAURUS_PXA_INFO,
304}, {
305 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
306 | USB_DEVICE_ID_MATCH_DEVICE,
307 .idVendor = 0x04DD,
308 .idProduct = 0x8007,
309 ZAURUS_MASTER_INTERFACE,
310 .driver_info = ZAURUS_PXA_INFO,
311}, {
312 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
313 | USB_DEVICE_ID_MATCH_DEVICE,
314 .idVendor = 0x04DD,
315 .idProduct = 0x9031,
316 ZAURUS_MASTER_INTERFACE,
317 .driver_info = ZAURUS_PXA_INFO,
318}, {
319
320 USB_DEVICE_AND_INTERFACE_INFO(0x04DD, 0x9031, USB_CLASS_COMM,
321 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
322 .driver_info = (unsigned long) &bogus_mdlm_info,
323}, {
324 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
325 | USB_DEVICE_ID_MATCH_DEVICE,
326 .idVendor = 0x04DD,
327 .idProduct = 0x9032,
328 ZAURUS_MASTER_INTERFACE,
329 .driver_info = ZAURUS_PXA_INFO,
330}, {
331 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
332 | USB_DEVICE_ID_MATCH_DEVICE,
333 .idVendor = 0x04DD,
334
335 .idProduct = 0x9050,
336 ZAURUS_MASTER_INTERFACE,
337 .driver_info = ZAURUS_PXA_INFO,
338},
339{
340
341 USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x6027, USB_CLASS_COMM,
342 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
343 .driver_info = (unsigned long) &bogus_mdlm_info,
344}, {
345
346 USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x6425, USB_CLASS_COMM,
347 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
348 .driver_info = (unsigned long) &bogus_mdlm_info,
349},
350
351
352
353
354{
355 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
356 | USB_DEVICE_ID_MATCH_DEVICE,
357 .idVendor = 0x07B4,
358 .idProduct = 0x0F02,
359 ZAURUS_MASTER_INTERFACE,
360 .driver_info = OLYMPUS_MXL_INFO,
361},
362
363
364{
365 USB_DEVICE_AND_INTERFACE_INFO(0x046d, 0xc11f, USB_CLASS_COMM,
366 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
367 .driver_info = (unsigned long) &bogus_mdlm_info,
368},
369 { },
370};
371MODULE_DEVICE_TABLE(usb, products);
372
373static struct usb_driver zaurus_driver = {
374 .name = "zaurus",
375 .id_table = products,
376 .probe = usbnet_probe,
377 .disconnect = usbnet_disconnect,
378 .suspend = usbnet_suspend,
379 .resume = usbnet_resume,
380 .disable_hub_initiated_lpm = 1,
381};
382
383module_usb_driver(zaurus_driver);
384
385MODULE_AUTHOR("Pavel Machek, David Brownell");
386MODULE_DESCRIPTION("Sharp Zaurus PDA, and compatible products");
387MODULE_LICENSE("GPL");
388