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