blob: 4973e147bc79ea441e6a48875cfa00c60cc15d3a [file] [log] [blame]
matthieu castetb72458a2005-11-07 23:27:13 +01001/*-
2 * Copyright (c) 2003, 2004
3 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
4 *
5 * Copyright (c) 2005 Matthieu Castet <castet.matthieu@free.fr>
6 *
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * BSD license below:
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice unmodified, this list of conditions, and the following
18 * disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * GPL license :
36 * This program is free software; you can redistribute it and/or
37 * modify it under the terms of the GNU General Public License
38 * as published by the Free Software Foundation; either version 2
39 * of the License, or (at your option) any later version.
40 *
41 * This program is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU General Public License for more details.
45 *
46 * You should have received a copy of the GNU General Public License
47 * along with this program; if not, write to the Free Software
48 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
49 *
50 *
51 * HISTORY : some part of the code was base on ueagle 1.3 BSD driver,
52 * Damien Bergamini agree to put his code under a DUAL GPL/BSD license.
53 *
54 * The rest of the code was was rewritten from scratch.
55 */
56
57#include <linux/module.h>
58#include <linux/moduleparam.h>
59#include <linux/init.h>
60#include <linux/crc32.h>
61#include <linux/usb.h>
62#include <linux/firmware.h>
63#include <linux/ctype.h>
Randy Dunlap5371f802007-02-16 01:47:33 -080064#include <linux/sched.h>
matthieu castetb72458a2005-11-07 23:27:13 +010065#include <linux/kthread.h>
66#include <linux/version.h>
Arjan van de Venab3c81f2006-01-13 15:52:55 +010067#include <linux/mutex.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080068#include <linux/freezer.h>
69
matthieu castetb72458a2005-11-07 23:27:13 +010070#include <asm/unaligned.h>
71
72#include "usbatm.h"
73
matthieu casteta7a0c9c2006-10-03 21:44:11 +020074#define EAGLEUSBVERSION "ueagle 1.4"
matthieu castetb72458a2005-11-07 23:27:13 +010075
76
77/*
78 * Debug macros
79 */
80#define uea_dbg(usb_dev, format, args...) \
81 do { \
82 if (debug >= 1) \
83 dev_dbg(&(usb_dev)->dev, \
84 "[ueagle-atm dbg] %s: " format, \
85 __FUNCTION__, ##args); \
matthieu casteta7a0c9c2006-10-03 21:44:11 +020086 } while (0)
matthieu castetb72458a2005-11-07 23:27:13 +010087
88#define uea_vdbg(usb_dev, format, args...) \
89 do { \
90 if (debug >= 2) \
91 dev_dbg(&(usb_dev)->dev, \
92 "[ueagle-atm vdbg] " format, ##args); \
matthieu casteta7a0c9c2006-10-03 21:44:11 +020093 } while (0)
matthieu castetb72458a2005-11-07 23:27:13 +010094
95#define uea_enters(usb_dev) \
96 uea_vdbg(usb_dev, "entering %s\n", __FUNCTION__)
97
98#define uea_leaves(usb_dev) \
99 uea_vdbg(usb_dev, "leaving %s\n", __FUNCTION__)
100
101#define uea_err(usb_dev, format,args...) \
102 dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args)
103
104#define uea_warn(usb_dev, format,args...) \
105 dev_warn(&(usb_dev)->dev ,"[Ueagle-atm] " format, ##args)
106
107#define uea_info(usb_dev, format,args...) \
108 dev_info(&(usb_dev)->dev ,"[ueagle-atm] " format, ##args)
109
110struct uea_cmvs {
111 u32 address;
112 u16 offset;
113 u32 data;
114} __attribute__ ((packed));
115
116struct uea_softc {
117 struct usb_device *usb_dev;
118 struct usbatm_data *usbatm;
119
120 int modem_index;
121 unsigned int driver_info;
122
123 int booting;
124 int reset;
125
126 wait_queue_head_t sync_q;
127
128 struct task_struct *kthread;
129 u32 data;
130 wait_queue_head_t cmv_ack_wait;
131 int cmv_ack;
132
133 struct work_struct task;
134 u16 pageno;
135 u16 ovl;
136
137 const struct firmware *dsp_firm;
138 struct urb *urb_int;
139
140 u8 cmv_function;
141 u16 cmv_idx;
142 u32 cmv_address;
143 u16 cmv_offset;
144
145 /* keep in sync with eaglectl */
146 struct uea_stats {
147 struct {
148 u32 state;
149 u32 flags;
150 u32 mflags;
151 u32 vidcpe;
152 u32 vidco;
153 u32 dsrate;
154 u32 usrate;
155 u32 dsunc;
156 u32 usunc;
157 u32 dscorr;
158 u32 uscorr;
159 u32 txflow;
160 u32 rxflow;
161 u32 usattenuation;
162 u32 dsattenuation;
163 u32 dsmargin;
164 u32 usmargin;
165 u32 firmid;
166 } phy;
167 } stats;
168};
169
170/*
171 * Elsa IDs
172 */
173#define ELSA_VID 0x05CC
174#define ELSA_PID_PSTFIRM 0x3350
175#define ELSA_PID_PREFIRM 0x3351
176
177/*
178 * Sagem USB IDs
179 */
180#define EAGLE_VID 0x1110
181#define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
182#define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
183
184#define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
185#define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
186
187#define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
188#define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
189
190/*
191 * Eagle III Pid
192 */
193#define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
194#define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
195
196/*
197 * USR USB IDs
198 */
199#define USR_VID 0x0BAF
200#define MILLER_A_PID_PREFIRM 0x00F2
201#define MILLER_A_PID_PSTFIRM 0x00F1
202#define MILLER_B_PID_PREFIRM 0x00FA
203#define MILLER_B_PID_PSTFIRM 0x00F9
204#define HEINEKEN_A_PID_PREFIRM 0x00F6
205#define HEINEKEN_A_PID_PSTFIRM 0x00F5
206#define HEINEKEN_B_PID_PREFIRM 0x00F8
207#define HEINEKEN_B_PID_PSTFIRM 0x00F7
208
209#define PREFIRM 0
210#define PSTFIRM (1<<7)
211enum {
212 ADI930 = 0,
213 EAGLE_I,
214 EAGLE_II,
215 EAGLE_III
216};
217
218/* macros for both struct usb_device_id and struct uea_softc */
219#define UEA_IS_PREFIRM(x) \
220 (!((x)->driver_info & PSTFIRM))
221#define UEA_CHIP_VERSION(x) \
222 ((x)->driver_info & 0xf)
223
matthieu casteta7a0c9c2006-10-03 21:44:11 +0200224#define IS_ISDN(usb_dev) \
225 (le16_to_cpu((usb_dev)->descriptor.bcdDevice) & 0x80)
matthieu castetb72458a2005-11-07 23:27:13 +0100226
227#define INS_TO_USBDEV(ins) ins->usb_dev
228
229#define GET_STATUS(data) \
230 ((data >> 8) & 0xf)
231#define IS_OPERATIONAL(sc) \
232 (GET_STATUS(sc->stats.phy.state) == 2)
233
234/*
235 * Set of macros to handle unaligned data in the firmware blob.
236 * The FW_GET_BYTE() macro is provided only for consistency.
237 */
238
239#define FW_GET_BYTE(p) *((__u8 *) (p))
240#define FW_GET_WORD(p) le16_to_cpu(get_unaligned((__le16 *) (p)))
241#define FW_GET_LONG(p) le32_to_cpu(get_unaligned((__le32 *) (p)))
242
243#define FW_DIR "ueagle-atm/"
244#define NB_MODEM 4
245
246#define BULK_TIMEOUT 300
247#define CTRL_TIMEOUT 1000
248
matthieu castet22fcceb2006-04-02 18:44:20 +0200249#define ACK_TIMEOUT msecs_to_jiffies(3000)
matthieu castetb72458a2005-11-07 23:27:13 +0100250
251#define UEA_INTR_IFACE_NO 0
252#define UEA_US_IFACE_NO 1
253#define UEA_DS_IFACE_NO 2
254
255#define FASTEST_ISO_INTF 8
256
257#define UEA_BULK_DATA_PIPE 0x02
258#define UEA_IDMA_PIPE 0x04
259#define UEA_INTR_PIPE 0x04
260#define UEA_ISO_DATA_PIPE 0x08
261
262#define UEA_SET_BLOCK 0x0001
263#define UEA_SET_MODE 0x0003
264#define UEA_SET_2183_DATA 0x0004
265#define UEA_SET_TIMEOUT 0x0011
266
267#define UEA_LOOPBACK_OFF 0x0002
268#define UEA_LOOPBACK_ON 0x0003
269#define UEA_BOOT_IDMA 0x0006
270#define UEA_START_RESET 0x0007
271#define UEA_END_RESET 0x0008
272
273#define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
274#define UEA_MPTX_START (0x3fce | 0x4000)
275#define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
276#define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
277
278/* structure describing a block within a DSP page */
279struct block_info {
280 __le16 wHdr;
281#define UEA_BIHDR 0xabcd
282 __le16 wAddress;
283 __le16 wSize;
284 __le16 wOvlOffset;
285 __le16 wOvl; /* overlay */
286 __le16 wLast;
287} __attribute__ ((packed));
288#define BLOCK_INFO_SIZE 12
289
290/* structure representing a CMV (Configuration and Management Variable) */
291struct cmv {
292 __le16 wPreamble;
293#define PREAMBLE 0x535c
294 __u8 bDirection;
295#define MODEMTOHOST 0x01
296#define HOSTTOMODEM 0x10
297 __u8 bFunction;
298#define FUNCTION_TYPE(f) ((f) >> 4)
299#define MEMACCESS 0x1
300#define ADSLDIRECTIVE 0x7
301
302#define FUNCTION_SUBTYPE(f) ((f) & 0x0f)
303/* for MEMACCESS */
304#define REQUESTREAD 0x0
305#define REQUESTWRITE 0x1
306#define REPLYREAD 0x2
307#define REPLYWRITE 0x3
308/* for ADSLDIRECTIVE */
309#define KERNELREADY 0x0
310#define MODEMREADY 0x1
311
312#define MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
313 __le16 wIndex;
314 __le32 dwSymbolicAddress;
315#define MAKESA(a, b, c, d) \
316 (((c) & 0xff) << 24 | \
317 ((d) & 0xff) << 16 | \
318 ((a) & 0xff) << 8 | \
319 ((b) & 0xff))
matthieu castet2a99b502006-04-02 18:43:53 +0200320#define GETSA1(a) ((a >> 8) & 0xff)
321#define GETSA2(a) (a & 0xff)
322#define GETSA3(a) ((a >> 24) & 0xff)
323#define GETSA4(a) ((a >> 16) & 0xff)
matthieu castetb72458a2005-11-07 23:27:13 +0100324
325#define SA_CNTL MAKESA('C', 'N', 'T', 'L')
326#define SA_DIAG MAKESA('D', 'I', 'A', 'G')
327#define SA_INFO MAKESA('I', 'N', 'F', 'O')
328#define SA_OPTN MAKESA('O', 'P', 'T', 'N')
329#define SA_RATE MAKESA('R', 'A', 'T', 'E')
330#define SA_STAT MAKESA('S', 'T', 'A', 'T')
331 __le16 wOffsetAddress;
332 __le32 dwData;
333} __attribute__ ((packed));
334#define CMV_SIZE 16
335
336/* structure representing swap information */
337struct swap_info {
338 __u8 bSwapPageNo;
339 __u8 bOvl; /* overlay */
340} __attribute__ ((packed));
341
342/* structure representing interrupt data */
343struct intr_pkt {
344 __u8 bType;
345 __u8 bNotification;
346 __le16 wValue;
347 __le16 wIndex;
348 __le16 wLength;
349 __le16 wInterrupt;
350#define INT_LOADSWAPPAGE 0x0001
351#define INT_INCOMINGCMV 0x0002
352 union {
353 struct {
354 struct swap_info swapinfo;
355 __le16 wDataSize;
356 } __attribute__ ((packed)) s1;
357
358 struct {
359 struct cmv cmv;
360 __le16 wDataSize;
361 } __attribute__ ((packed)) s2;
362 } __attribute__ ((packed)) u;
363#define bSwapPageNo u.s1.swapinfo.bSwapPageNo
364#define bOvl u.s1.swapinfo.bOvl
365} __attribute__ ((packed));
366#define INTR_PKT_SIZE 28
367
368static struct usb_driver uea_driver;
Arjan van de Venab3c81f2006-01-13 15:52:55 +0100369static DEFINE_MUTEX(uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +0100370static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III"};
371
372static int modem_index;
373static unsigned int debug;
matthieu castet3c9666c2006-01-18 07:38:19 +0100374static int use_iso[NB_MODEM] = {[0 ... (NB_MODEM - 1)] = 1};
matthieu castetb72458a2005-11-07 23:27:13 +0100375static int sync_wait[NB_MODEM];
376static char *cmv_file[NB_MODEM];
377
378module_param(debug, uint, 0644);
379MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
matthieu castet3c9666c2006-01-18 07:38:19 +0100380module_param_array(use_iso, bool, NULL, 0644);
381MODULE_PARM_DESC(use_iso, "use isochronous usb pipe for incoming traffic");
matthieu castetb72458a2005-11-07 23:27:13 +0100382module_param_array(sync_wait, bool, NULL, 0644);
383MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
384module_param_array(cmv_file, charp, NULL, 0644);
385MODULE_PARM_DESC(cmv_file,
386 "file name with configuration and management variables");
387
388#define UPDATE_ATM_STAT(type, val) \
389 do { \
390 if (sc->usbatm->atm_dev) \
391 sc->usbatm->atm_dev->type = val; \
392 } while (0)
393
394/* Firmware loading */
395#define LOAD_INTERNAL 0xA0
396#define F8051_USBCS 0x7f92
397
398/**
399 * uea_send_modem_cmd - Send a command for pre-firmware devices.
400 */
401static int uea_send_modem_cmd(struct usb_device *usb,
402 u16 addr, u16 size, u8 * buff)
403{
404 int ret = -ENOMEM;
405 u8 *xfer_buff;
406
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +0200407 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +0100408 if (xfer_buff) {
matthieu castetb72458a2005-11-07 23:27:13 +0100409 ret = usb_control_msg(usb,
410 usb_sndctrlpipe(usb, 0),
411 LOAD_INTERNAL,
412 USB_DIR_OUT | USB_TYPE_VENDOR |
413 USB_RECIP_DEVICE, addr, 0, xfer_buff,
414 size, CTRL_TIMEOUT);
415 kfree(xfer_buff);
416 }
417
418 if (ret < 0)
419 return ret;
420
421 return (ret == size) ? 0 : -EIO;
422}
423
424static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *context)
425{
426 struct usb_device *usb = context;
427 u8 *pfw, value;
428 u32 crc = 0;
429 int ret, size;
430
431 uea_enters(usb);
432 if (!fw_entry) {
433 uea_err(usb, "firmware is not available\n");
434 goto err;
435 }
436
437 pfw = fw_entry->data;
438 size = fw_entry->size;
matthieu castet8d7802e2005-11-08 00:02:30 +0100439 if (size < 4)
440 goto err_fw_corrupted;
matthieu castetb72458a2005-11-07 23:27:13 +0100441
442 crc = FW_GET_LONG(pfw);
443 pfw += 4;
444 size -= 4;
matthieu castet8d7802e2005-11-08 00:02:30 +0100445 if (crc32_be(0, pfw, size) != crc)
446 goto err_fw_corrupted;
matthieu castetb72458a2005-11-07 23:27:13 +0100447
448 /*
449 * Start to upload formware : send reset
450 */
451 value = 1;
452 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
453
454 if (ret < 0) {
455 uea_err(usb, "modem reset failed with error %d\n", ret);
456 goto err;
457 }
458
matthieu castet8d7802e2005-11-08 00:02:30 +0100459 while (size > 3) {
matthieu castetb72458a2005-11-07 23:27:13 +0100460 u8 len = FW_GET_BYTE(pfw);
461 u16 add = FW_GET_WORD(pfw + 1);
matthieu castet8d7802e2005-11-08 00:02:30 +0100462
463 size -= len + 3;
464 if (size < 0)
465 goto err_fw_corrupted;
466
matthieu castetb72458a2005-11-07 23:27:13 +0100467 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
468 if (ret < 0) {
469 uea_err(usb, "uploading firmware data failed "
470 "with error %d\n", ret);
471 goto err;
472 }
473 pfw += len + 3;
matthieu castetb72458a2005-11-07 23:27:13 +0100474 }
475
matthieu castet8d7802e2005-11-08 00:02:30 +0100476 if (size != 0)
477 goto err_fw_corrupted;
478
matthieu castetb72458a2005-11-07 23:27:13 +0100479 /*
480 * Tell the modem we finish : de-assert reset
481 */
482 value = 0;
483 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
484 if (ret < 0)
485 uea_err(usb, "modem de-assert failed with error %d\n", ret);
486 else
487 uea_info(usb, "firmware uploaded\n");
488
matthieu castet8d7802e2005-11-08 00:02:30 +0100489 uea_leaves(usb);
490 return;
491
492err_fw_corrupted:
493 uea_err(usb, "firmware is corrupted\n");
matthieu castetb72458a2005-11-07 23:27:13 +0100494err:
495 uea_leaves(usb);
496}
497
498/**
499 * uea_load_firmware - Load usb firmware for pre-firmware devices.
500 */
501static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
502{
503 int ret;
504 char *fw_name = FW_DIR "eagle.fw";
505
506 uea_enters(usb);
507 uea_info(usb, "pre-firmware device, uploading firmware\n");
508
509 switch (ver) {
510 case ADI930:
511 fw_name = FW_DIR "adi930.fw";
512 break;
513 case EAGLE_I:
514 fw_name = FW_DIR "eagleI.fw";
515 break;
516 case EAGLE_II:
517 fw_name = FW_DIR "eagleII.fw";
518 break;
519 case EAGLE_III:
520 fw_name = FW_DIR "eagleIII.fw";
521 break;
522 }
523
524 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware);
525 if (ret)
526 uea_err(usb, "firmware %s is not available\n", fw_name);
527 else
528 uea_info(usb, "loading firmware %s\n", fw_name);
529
530 uea_leaves(usb);
531 return ret;
532}
533
534/* modem management : dsp firmware, send/read CMV, monitoring statistic
535 */
536
537/*
538 * Make sure that the DSP code provided is safe to use.
539 */
540static int check_dsp(u8 *dsp, unsigned int len)
541{
542 u8 pagecount, blockcount;
543 u16 blocksize;
544 u32 pageoffset;
545 unsigned int i, j, p, pp;
546
matthieu castetb72458a2005-11-07 23:27:13 +0100547 pagecount = FW_GET_BYTE(dsp);
548 p = 1;
549
550 /* enough space for page offsets? */
551 if (p + 4 * pagecount > len)
552 return 1;
553
554 for (i = 0; i < pagecount; i++) {
555
556 pageoffset = FW_GET_LONG(dsp + p);
557 p += 4;
558
559 if (pageoffset == 0)
560 continue;
561
562 /* enough space for blockcount? */
563 if (pageoffset >= len)
564 return 1;
565
566 pp = pageoffset;
567 blockcount = FW_GET_BYTE(dsp + pp);
568 pp += 1;
569
570 for (j = 0; j < blockcount; j++) {
571
572 /* enough space for block header? */
573 if (pp + 4 > len)
574 return 1;
575
576 pp += 2; /* skip blockaddr */
577 blocksize = FW_GET_WORD(dsp + pp);
578 pp += 2;
579
580 /* enough space for block data? */
581 if (pp + blocksize > len)
582 return 1;
583
584 pp += blocksize;
585 }
586 }
587
588 return 0;
589}
590
591/*
592 * send data to the idma pipe
593 * */
594static int uea_idma_write(struct uea_softc *sc, void *data, u32 size)
595{
596 int ret = -ENOMEM;
597 u8 *xfer_buff;
598 int bytes_read;
599
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +0200600 xfer_buff = kmemdup(data, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +0100601 if (!xfer_buff) {
602 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
603 return ret;
604 }
605
matthieu castetb72458a2005-11-07 23:27:13 +0100606 ret = usb_bulk_msg(sc->usb_dev,
607 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
608 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
609
610 kfree(xfer_buff);
611 if (ret < 0)
612 return ret;
613 if (size != bytes_read) {
614 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
615 bytes_read);
616 return -EIO;
617 }
618
619 return 0;
620}
621
622static int request_dsp(struct uea_softc *sc)
623{
624 int ret;
625 char *dsp_name;
626
627 if (UEA_CHIP_VERSION(sc) == ADI930) {
matthieu casteta7a0c9c2006-10-03 21:44:11 +0200628 if (IS_ISDN(sc->usb_dev))
matthieu castetb72458a2005-11-07 23:27:13 +0100629 dsp_name = FW_DIR "DSP9i.bin";
630 else
631 dsp_name = FW_DIR "DSP9p.bin";
632 } else {
matthieu casteta7a0c9c2006-10-03 21:44:11 +0200633 if (IS_ISDN(sc->usb_dev))
matthieu castetb72458a2005-11-07 23:27:13 +0100634 dsp_name = FW_DIR "DSPei.bin";
635 else
636 dsp_name = FW_DIR "DSPep.bin";
637 }
638
matthieu castete40abaf2006-01-18 07:38:37 +0100639 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
matthieu castetb72458a2005-11-07 23:27:13 +0100640 if (ret < 0) {
641 uea_err(INS_TO_USBDEV(sc),
642 "requesting firmware %s failed with error %d\n",
643 dsp_name, ret);
644 return ret;
645 }
646
647 if (check_dsp(sc->dsp_firm->data, sc->dsp_firm->size)) {
648 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
649 dsp_name);
650 release_firmware(sc->dsp_firm);
651 sc->dsp_firm = NULL;
652 return -EILSEQ;
653 }
654
655 return 0;
656}
657
658/*
659 * The uea_load_page() function must be called within a process context
660 */
David Howellsc4028952006-11-22 14:57:56 +0000661static void uea_load_page(struct work_struct *work)
matthieu castetb72458a2005-11-07 23:27:13 +0100662{
David Howellsc4028952006-11-22 14:57:56 +0000663 struct uea_softc *sc = container_of(work, struct uea_softc, task);
matthieu castetb72458a2005-11-07 23:27:13 +0100664 u16 pageno = sc->pageno;
665 u16 ovl = sc->ovl;
666 struct block_info bi;
667
668 u8 *p;
669 u8 pagecount, blockcount;
670 u16 blockaddr, blocksize;
671 u32 pageoffset;
672 int i;
673
674 /* reload firmware when reboot start and it's loaded already */
675 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
676 release_firmware(sc->dsp_firm);
677 sc->dsp_firm = NULL;
678 }
679
680 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
681 return;
682
683 p = sc->dsp_firm->data;
684 pagecount = FW_GET_BYTE(p);
685 p += 1;
686
687 if (pageno >= pagecount)
688 goto bad1;
689
690 p += 4 * pageno;
691 pageoffset = FW_GET_LONG(p);
692
693 if (pageoffset == 0)
694 goto bad1;
695
696 p = sc->dsp_firm->data + pageoffset;
697 blockcount = FW_GET_BYTE(p);
698 p += 1;
699
700 uea_dbg(INS_TO_USBDEV(sc),
701 "sending %u blocks for DSP page %u\n", blockcount, pageno);
702
703 bi.wHdr = cpu_to_le16(UEA_BIHDR);
704 bi.wOvl = cpu_to_le16(ovl);
705 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
706
707 for (i = 0; i < blockcount; i++) {
708 blockaddr = FW_GET_WORD(p);
709 p += 2;
710
711 blocksize = FW_GET_WORD(p);
712 p += 2;
713
714 bi.wSize = cpu_to_le16(blocksize);
715 bi.wAddress = cpu_to_le16(blockaddr);
716 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
717
718 /* send block info through the IDMA pipe */
719 if (uea_idma_write(sc, &bi, BLOCK_INFO_SIZE))
720 goto bad2;
721
722 /* send block data through the IDMA pipe */
723 if (uea_idma_write(sc, p, blocksize))
724 goto bad2;
725
726 p += blocksize;
727 }
728
729 return;
730
731bad2:
732 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
733 return;
734bad1:
matthieu castet2a99b502006-04-02 18:43:53 +0200735 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
matthieu castetb72458a2005-11-07 23:27:13 +0100736}
737
738static inline void wake_up_cmv_ack(struct uea_softc *sc)
739{
matthieu castet2a99b502006-04-02 18:43:53 +0200740 BUG_ON(sc->cmv_ack);
matthieu castetb72458a2005-11-07 23:27:13 +0100741 sc->cmv_ack = 1;
742 wake_up(&sc->cmv_ack_wait);
743}
744
745static inline int wait_cmv_ack(struct uea_softc *sc)
746{
matthieu castet531a39b2006-10-03 21:49:29 +0200747 int ret = wait_event_interruptible_timeout(sc->cmv_ack_wait,
matthieu castetb72458a2005-11-07 23:27:13 +0100748 sc->cmv_ack, ACK_TIMEOUT);
749 sc->cmv_ack = 0;
750
matthieu castet2a99b502006-04-02 18:43:53 +0200751 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
752 jiffies_to_msecs(ret));
753
matthieu castetb72458a2005-11-07 23:27:13 +0100754 if (ret < 0)
755 return ret;
756
757 return (ret == 0) ? -ETIMEDOUT : 0;
matthieu castetb72458a2005-11-07 23:27:13 +0100758}
759
760#define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
761
762static int uea_request(struct uea_softc *sc,
763 u16 value, u16 index, u16 size, void *data)
764{
765 u8 *xfer_buff;
766 int ret = -ENOMEM;
767
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +0200768 xfer_buff = kmemdup(data, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +0100769 if (!xfer_buff) {
770 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
771 return ret;
772 }
matthieu castetb72458a2005-11-07 23:27:13 +0100773
774 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
775 UCDC_SEND_ENCAPSULATED_COMMAND,
776 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
777 value, index, xfer_buff, size, CTRL_TIMEOUT);
778
779 kfree(xfer_buff);
780 if (ret < 0) {
781 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
782 return ret;
783 }
784
785 if (ret != size) {
786 uea_err(INS_TO_USBDEV(sc),
787 "usb_control_msg send only %d bytes (instead of %d)\n",
788 ret, size);
789 return -EIO;
790 }
791
792 return 0;
793}
794
795static int uea_cmv(struct uea_softc *sc,
796 u8 function, u32 address, u16 offset, u32 data)
797{
798 struct cmv cmv;
799 int ret;
800
matthieu castet2a99b502006-04-02 18:43:53 +0200801 uea_enters(INS_TO_USBDEV(sc));
802 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
803 "offset : 0x%04x, data : 0x%08x\n",
804 FUNCTION_TYPE(function), FUNCTION_SUBTYPE(function),
805 GETSA1(address), GETSA2(address), GETSA3(address),
806 GETSA4(address), offset, data);
matthieu castetb72458a2005-11-07 23:27:13 +0100807 /* we send a request, but we expect a reply */
808 sc->cmv_function = function | 0x2;
809 sc->cmv_idx++;
810 sc->cmv_address = address;
811 sc->cmv_offset = offset;
812
813 cmv.wPreamble = cpu_to_le16(PREAMBLE);
814 cmv.bDirection = HOSTTOMODEM;
815 cmv.bFunction = function;
816 cmv.wIndex = cpu_to_le16(sc->cmv_idx);
817 put_unaligned(cpu_to_le32(address), &cmv.dwSymbolicAddress);
818 cmv.wOffsetAddress = cpu_to_le16(offset);
819 put_unaligned(cpu_to_le32(data >> 16 | data << 16), &cmv.dwData);
820
821 ret = uea_request(sc, UEA_SET_BLOCK, UEA_MPTX_START, CMV_SIZE, &cmv);
822 if (ret < 0)
823 return ret;
matthieu castet2a99b502006-04-02 18:43:53 +0200824 ret = wait_cmv_ack(sc);
825 uea_leaves(INS_TO_USBDEV(sc));
826 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +0100827}
828
829static inline int uea_read_cmv(struct uea_softc *sc,
830 u32 address, u16 offset, u32 *data)
831{
832 int ret = uea_cmv(sc, MAKEFUNCTION(MEMACCESS, REQUESTREAD),
833 address, offset, 0);
834 if (ret < 0)
835 uea_err(INS_TO_USBDEV(sc),
836 "reading cmv failed with error %d\n", ret);
837 else
838 *data = sc->data;
839
840 return ret;
841}
842
843static inline int uea_write_cmv(struct uea_softc *sc,
844 u32 address, u16 offset, u32 data)
845{
846 int ret = uea_cmv(sc, MAKEFUNCTION(MEMACCESS, REQUESTWRITE),
847 address, offset, data);
848 if (ret < 0)
849 uea_err(INS_TO_USBDEV(sc),
850 "writing cmv failed with error %d\n", ret);
851
852 return ret;
853}
854
855/*
856 * Monitor the modem and update the stat
857 * return 0 if everything is ok
858 * return < 0 if an error occurs (-EAGAIN reboot needed)
859 */
860static int uea_stat(struct uea_softc *sc)
861{
862 u32 data;
863 int ret;
864
865 uea_enters(INS_TO_USBDEV(sc));
866 data = sc->stats.phy.state;
867
868 ret = uea_read_cmv(sc, SA_STAT, 0, &sc->stats.phy.state);
869 if (ret < 0)
870 return ret;
871
872 switch (GET_STATUS(sc->stats.phy.state)) {
873 case 0: /* not yet synchronized */
874 uea_dbg(INS_TO_USBDEV(sc),
875 "modem not yet synchronized\n");
876 return 0;
877
878 case 1: /* initialization */
879 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
880 return 0;
881
882 case 2: /* operational */
883 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
884 break;
885
886 case 3: /* fail ... */
matthieu casteta7a0c9c2006-10-03 21:44:11 +0200887 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
888 " (may be try other cmv/dsp)\n");
matthieu castetb72458a2005-11-07 23:27:13 +0100889 return -EAGAIN;
890
891 case 4 ... 6: /* test state */
892 uea_warn(INS_TO_USBDEV(sc),
893 "modem in test mode - not supported\n");
894 return -EAGAIN;
895
896 case 7: /* fast-retain ... */
897 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
898 return 0;
899 default:
900 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
901 GET_STATUS(sc->stats.phy.state));
902 return -EAGAIN;
903 }
904
905 if (GET_STATUS(data) != 2) {
906 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
907 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
908
909 /* release the dsp firmware as it is not needed until
910 * the next failure
911 */
912 if (sc->dsp_firm) {
913 release_firmware(sc->dsp_firm);
914 sc->dsp_firm = NULL;
915 }
matthieu castetb72458a2005-11-07 23:27:13 +0100916 }
917
918 /* always update it as atm layer could not be init when we switch to
919 * operational state
920 */
921 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
922
923 /* wake up processes waiting for synchronization */
924 wake_up(&sc->sync_q);
925
926 ret = uea_read_cmv(sc, SA_DIAG, 2, &sc->stats.phy.flags);
927 if (ret < 0)
928 return ret;
929 sc->stats.phy.mflags |= sc->stats.phy.flags;
930
931 /* in case of a flags ( for example delineation LOSS (& 0x10)),
932 * we check the status again in order to detect the failure earlier
933 */
934 if (sc->stats.phy.flags) {
matthieu castet2a99b502006-04-02 18:43:53 +0200935 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
matthieu castetb72458a2005-11-07 23:27:13 +0100936 sc->stats.phy.flags);
937 return 0;
938 }
939
940 ret = uea_read_cmv(sc, SA_RATE, 0, &data);
941 if (ret < 0)
942 return ret;
943
944 /* in bulk mode the modem have problem with high rate
945 * changing internal timing could improve things, but the
946 * value is misterious.
947 * ADI930 don't support it (-EPIPE error).
948 */
949 if (UEA_CHIP_VERSION(sc) != ADI930
matthieu castet3c9666c2006-01-18 07:38:19 +0100950 && !use_iso[sc->modem_index]
matthieu castetb72458a2005-11-07 23:27:13 +0100951 && sc->stats.phy.dsrate != (data >> 16) * 32) {
952 /* Original timming from ADI(used in windows driver)
953 * 0x20ffff>>16 * 32 = 32 * 32 = 1Mbits
954 */
955 u16 timeout = (data <= 0x20ffff) ? 0 : 1;
956 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
957 uea_info(INS_TO_USBDEV(sc),
958 "setting new timeout %d%s\n", timeout,
959 ret < 0?" failed":"");
960 }
961 sc->stats.phy.dsrate = (data >> 16) * 32;
962 sc->stats.phy.usrate = (data & 0xffff) * 32;
963 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
964
965 ret = uea_read_cmv(sc, SA_DIAG, 23, &data);
966 if (ret < 0)
967 return ret;
968 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
969
970 ret = uea_read_cmv(sc, SA_DIAG, 47, &data);
971 if (ret < 0)
972 return ret;
973 sc->stats.phy.usattenuation = (data & 0xff) / 2;
974
975 ret = uea_read_cmv(sc, SA_DIAG, 25, &sc->stats.phy.dsmargin);
976 if (ret < 0)
977 return ret;
978
979 ret = uea_read_cmv(sc, SA_DIAG, 49, &sc->stats.phy.usmargin);
980 if (ret < 0)
981 return ret;
982
983 ret = uea_read_cmv(sc, SA_DIAG, 51, &sc->stats.phy.rxflow);
984 if (ret < 0)
985 return ret;
986
987 ret = uea_read_cmv(sc, SA_DIAG, 52, &sc->stats.phy.txflow);
988 if (ret < 0)
989 return ret;
990
991 ret = uea_read_cmv(sc, SA_DIAG, 54, &sc->stats.phy.dsunc);
992 if (ret < 0)
993 return ret;
994
995 /* only for atu-c */
996 ret = uea_read_cmv(sc, SA_DIAG, 58, &sc->stats.phy.usunc);
997 if (ret < 0)
998 return ret;
999
1000 ret = uea_read_cmv(sc, SA_DIAG, 53, &sc->stats.phy.dscorr);
1001 if (ret < 0)
1002 return ret;
1003
1004 /* only for atu-c */
1005 ret = uea_read_cmv(sc, SA_DIAG, 57, &sc->stats.phy.uscorr);
1006 if (ret < 0)
1007 return ret;
1008
1009 ret = uea_read_cmv(sc, SA_INFO, 8, &sc->stats.phy.vidco);
1010 if (ret < 0)
1011 return ret;
1012
1013 ret = uea_read_cmv(sc, SA_INFO, 13, &sc->stats.phy.vidcpe);
1014 if (ret < 0)
1015 return ret;
1016
1017 return 0;
1018}
1019
1020static int request_cmvs(struct uea_softc *sc,
1021 struct uea_cmvs **cmvs, const struct firmware **fw)
1022{
1023 int ret, size;
1024 u8 *data;
1025 char *file;
matthieu castetfdf290f2006-01-18 07:39:27 +01001026 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
matthieu castetb72458a2005-11-07 23:27:13 +01001027
1028 if (cmv_file[sc->modem_index] == NULL) {
1029 if (UEA_CHIP_VERSION(sc) == ADI930)
matthieu casteta7a0c9c2006-10-03 21:44:11 +02001030 file = (IS_ISDN(sc->usb_dev)) ? "CMV9i.bin" : "CMV9p.bin";
matthieu castetb72458a2005-11-07 23:27:13 +01001031 else
matthieu casteta7a0c9c2006-10-03 21:44:11 +02001032 file = (IS_ISDN(sc->usb_dev)) ? "CMVei.bin" : "CMVep.bin";
matthieu castetb72458a2005-11-07 23:27:13 +01001033 } else
1034 file = cmv_file[sc->modem_index];
1035
1036 strcpy(cmv_name, FW_DIR);
1037 strlcat(cmv_name, file, sizeof(cmv_name));
1038
1039 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1040 if (ret < 0) {
1041 uea_err(INS_TO_USBDEV(sc),
1042 "requesting firmware %s failed with error %d\n",
1043 cmv_name, ret);
1044 return ret;
1045 }
1046
1047 data = (u8 *) (*fw)->data;
1048 size = *data * sizeof(struct uea_cmvs) + 1;
1049 if (size != (*fw)->size) {
1050 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1051 cmv_name);
1052 release_firmware(*fw);
1053 return -EILSEQ;
1054 }
1055
1056 *cmvs = (struct uea_cmvs *)(data + 1);
1057 return *data;
1058}
1059
1060/* Start boot post firmware modem:
1061 * - send reset commands through usb control pipe
1062 * - start workqueue for DSP loading
1063 * - send CMV options to modem
1064 */
1065
1066static int uea_start_reset(struct uea_softc *sc)
1067{
1068 u16 zero = 0; /* ;-) */
1069 int i, len, ret;
1070 struct uea_cmvs *cmvs;
1071 const struct firmware *cmvs_fw;
1072
1073 uea_enters(INS_TO_USBDEV(sc));
1074 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1075
matthieu castet22fcceb2006-04-02 18:44:20 +02001076 /* mask interrupt */
matthieu castetb72458a2005-11-07 23:27:13 +01001077 sc->booting = 1;
matthieu castet22fcceb2006-04-02 18:44:20 +02001078 /* We need to set this here because, a ack timeout could have occured,
1079 * but before we start the reboot, the ack occurs and set this to 1.
1080 * So we will failed to wait Ready CMV.
1081 */
1082 sc->cmv_ack = 0;
matthieu castetb72458a2005-11-07 23:27:13 +01001083 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST);
1084
1085 /* reset statistics */
1086 memset(&sc->stats, 0, sizeof(struct uea_stats));
1087
1088 /* tell the modem that we want to boot in IDMA mode */
1089 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1090 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1091
1092 /* enter reset mode */
1093 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1094
1095 /* original driver use 200ms, but windows driver use 100ms */
1096 msleep(100);
1097
1098 /* leave reset mode */
1099 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1100
1101 /* clear tx and rx mailboxes */
1102 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1103 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1104 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1105
1106 msleep(1000);
1107 sc->cmv_function = MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY);
matthieu castet22fcceb2006-04-02 18:44:20 +02001108 /* demask interrupt */
matthieu castetb72458a2005-11-07 23:27:13 +01001109 sc->booting = 0;
1110
1111 /* start loading DSP */
1112 sc->pageno = 0;
1113 sc->ovl = 0;
1114 schedule_work(&sc->task);
1115
1116 /* wait for modem ready CMV */
1117 ret = wait_cmv_ack(sc);
1118 if (ret < 0)
1119 return ret;
1120
matthieu castet2a99b502006-04-02 18:43:53 +02001121 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1122
matthieu castetb72458a2005-11-07 23:27:13 +01001123 /* Enter in R-IDLE (cmv) until instructed otherwise */
1124 ret = uea_write_cmv(sc, SA_CNTL, 0, 1);
1125 if (ret < 0)
1126 return ret;
1127
matthieu casteta7a0c9c2006-10-03 21:44:11 +02001128 /* Dump firmware version */
1129 ret = uea_read_cmv(sc, SA_INFO, 10, &sc->stats.phy.firmid);
1130 if (ret < 0)
1131 return ret;
1132 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1133 sc->stats.phy.firmid);
1134
matthieu castetb72458a2005-11-07 23:27:13 +01001135 /* get options */
1136 ret = len = request_cmvs(sc, &cmvs, &cmvs_fw);
1137 if (ret < 0)
1138 return ret;
1139
1140 /* send options */
1141 for (i = 0; i < len; i++) {
1142 ret = uea_write_cmv(sc, FW_GET_LONG(&cmvs[i].address),
1143 FW_GET_WORD(&cmvs[i].offset),
1144 FW_GET_LONG(&cmvs[i].data));
1145 if (ret < 0)
1146 goto out;
1147 }
1148 /* Enter in R-ACT-REQ */
1149 ret = uea_write_cmv(sc, SA_CNTL, 0, 2);
matthieu castet2a99b502006-04-02 18:43:53 +02001150 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
matthieu casteta7a0c9c2006-10-03 21:44:11 +02001151 uea_info(INS_TO_USBDEV(sc), "Modem started, "
1152 "waiting synchronization\n");
matthieu castetb72458a2005-11-07 23:27:13 +01001153out:
1154 release_firmware(cmvs_fw);
1155 sc->reset = 0;
1156 uea_leaves(INS_TO_USBDEV(sc));
1157 return ret;
1158}
1159
1160/*
1161 * In case of an error wait 1s before rebooting the modem
1162 * if the modem don't request reboot (-EAGAIN).
1163 * Monitor the modem every 1s.
1164 */
1165
1166static int uea_kthread(void *data)
1167{
1168 struct uea_softc *sc = data;
1169 int ret = -EAGAIN;
1170
1171 uea_enters(INS_TO_USBDEV(sc));
1172 while (!kthread_should_stop()) {
1173 if (ret < 0 || sc->reset)
1174 ret = uea_start_reset(sc);
1175 if (!ret)
1176 ret = uea_stat(sc);
1177 if (ret != -EAGAIN)
matthieu castet531a39b2006-10-03 21:49:29 +02001178 msleep_interruptible(1000);
matthieu castet9ca53462006-10-03 21:46:33 +02001179 if (try_to_freeze())
1180 uea_err(INS_TO_USBDEV(sc), "suspend/resume not supported, "
1181 "please unplug/replug your modem\n");
matthieu castetb72458a2005-11-07 23:27:13 +01001182 }
1183 uea_leaves(INS_TO_USBDEV(sc));
1184 return ret;
1185}
1186
1187/* Load second usb firmware for ADI930 chip */
1188static int load_XILINX_firmware(struct uea_softc *sc)
1189{
1190 const struct firmware *fw_entry;
1191 int ret, size, u, ln;
1192 u8 *pfw, value;
1193 char *fw_name = FW_DIR "930-fpga.bin";
1194
1195 uea_enters(INS_TO_USBDEV(sc));
1196
1197 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1198 if (ret) {
1199 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1200 fw_name);
1201 goto err0;
1202 }
1203
1204 pfw = fw_entry->data;
1205 size = fw_entry->size;
1206 if (size != 0x577B) {
1207 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1208 fw_name);
1209 ret = -EILSEQ;
1210 goto err1;
1211 }
1212 for (u = 0; u < size; u += ln) {
1213 ln = min(size - u, 64);
1214 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1215 if (ret < 0) {
1216 uea_err(INS_TO_USBDEV(sc),
1217 "elsa download data failed (%d)\n", ret);
1218 goto err1;
1219 }
1220 }
1221
matthieu castete40abaf2006-01-18 07:38:37 +01001222 /* finish to send the fpga */
matthieu castetb72458a2005-11-07 23:27:13 +01001223 ret = uea_request(sc, 0xe, 1, 0, NULL);
1224 if (ret < 0) {
1225 uea_err(INS_TO_USBDEV(sc),
1226 "elsa download data failed (%d)\n", ret);
1227 goto err1;
1228 }
1229
matthieu castete40abaf2006-01-18 07:38:37 +01001230 /* Tell the modem we finish : de-assert reset */
matthieu castetb72458a2005-11-07 23:27:13 +01001231 value = 0;
1232 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1233 if (ret < 0)
1234 uea_err(sc->usb_dev, "elsa de-assert failed with error %d\n", ret);
1235
1236
1237err1:
1238 release_firmware(fw_entry);
1239err0:
1240 uea_leaves(INS_TO_USBDEV(sc));
1241 return ret;
1242}
1243
matthieu castete40abaf2006-01-18 07:38:37 +01001244/* The modem send us an ack. First with check if it right */
matthieu castetb72458a2005-11-07 23:27:13 +01001245static void uea_dispatch_cmv(struct uea_softc *sc, struct cmv* cmv)
1246{
1247 uea_enters(INS_TO_USBDEV(sc));
1248 if (le16_to_cpu(cmv->wPreamble) != PREAMBLE)
1249 goto bad1;
1250
1251 if (cmv->bDirection != MODEMTOHOST)
1252 goto bad1;
1253
1254 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1255 * the first MEMACESS cmv. Ignore it...
1256 */
1257 if (cmv->bFunction != sc->cmv_function) {
1258 if (UEA_CHIP_VERSION(sc) == ADI930
1259 && cmv->bFunction == MAKEFUNCTION(2, 2)) {
1260 cmv->wIndex = cpu_to_le16(sc->cmv_idx);
1261 put_unaligned(cpu_to_le32(sc->cmv_address), &cmv->dwSymbolicAddress);
1262 cmv->wOffsetAddress = cpu_to_le16(sc->cmv_offset);
1263 }
1264 else
1265 goto bad2;
1266 }
1267
1268 if (cmv->bFunction == MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY)) {
1269 wake_up_cmv_ack(sc);
matthieu castet2a99b502006-04-02 18:43:53 +02001270 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01001271 return;
1272 }
1273
1274 /* in case of MEMACCESS */
1275 if (le16_to_cpu(cmv->wIndex) != sc->cmv_idx ||
1276 le32_to_cpu(get_unaligned(&cmv->dwSymbolicAddress)) !=
1277 sc->cmv_address
1278 || le16_to_cpu(cmv->wOffsetAddress) != sc->cmv_offset)
1279 goto bad2;
1280
1281 sc->data = le32_to_cpu(get_unaligned(&cmv->dwData));
1282 sc->data = sc->data << 16 | sc->data >> 16;
1283
1284 wake_up_cmv_ack(sc);
matthieu castet2a99b502006-04-02 18:43:53 +02001285 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01001286 return;
1287
1288bad2:
1289 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
1290 "Function : %d, Subfunction : %d\n",
1291 FUNCTION_TYPE(cmv->bFunction),
1292 FUNCTION_SUBTYPE(cmv->bFunction));
matthieu castet2a99b502006-04-02 18:43:53 +02001293 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01001294 return;
1295
1296bad1:
1297 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
1298 "wPreamble %d, bDirection %d\n",
1299 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
matthieu castet2a99b502006-04-02 18:43:53 +02001300 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01001301}
1302
1303/*
1304 * interrupt handler
1305 */
David Howells7d12e782006-10-05 14:55:46 +01001306static void uea_intr(struct urb *urb)
matthieu castetb72458a2005-11-07 23:27:13 +01001307{
matthieu castete40abaf2006-01-18 07:38:37 +01001308 struct uea_softc *sc = urb->context;
1309 struct intr_pkt *intr = urb->transfer_buffer;
matthieu castetb72458a2005-11-07 23:27:13 +01001310 uea_enters(INS_TO_USBDEV(sc));
1311
matthieu castete40abaf2006-01-18 07:38:37 +01001312 if (unlikely(urb->status < 0)) {
matthieu castetb72458a2005-11-07 23:27:13 +01001313 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
1314 urb->status);
1315 return;
1316 }
1317
matthieu castetb72458a2005-11-07 23:27:13 +01001318 /* device-to-host interrupt */
1319 if (intr->bType != 0x08 || sc->booting) {
matthieu castete40abaf2006-01-18 07:38:37 +01001320 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
matthieu castetb72458a2005-11-07 23:27:13 +01001321 goto resubmit;
1322 }
1323
1324 switch (le16_to_cpu(intr->wInterrupt)) {
1325 case INT_LOADSWAPPAGE:
1326 sc->pageno = intr->bSwapPageNo;
1327 sc->ovl = intr->bOvl >> 4 | intr->bOvl << 4;
1328 schedule_work(&sc->task);
1329 break;
1330
1331 case INT_INCOMINGCMV:
1332 uea_dispatch_cmv(sc, &intr->u.s2.cmv);
1333 break;
1334
1335 default:
matthieu castete40abaf2006-01-18 07:38:37 +01001336 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
matthieu castetb72458a2005-11-07 23:27:13 +01001337 le16_to_cpu(intr->wInterrupt));
1338 }
1339
1340resubmit:
1341 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
1342}
1343
1344/*
1345 * Start the modem : init the data and start kernel thread
1346 */
1347static int uea_boot(struct uea_softc *sc)
1348{
1349 int ret;
1350 struct intr_pkt *intr;
1351
1352 uea_enters(INS_TO_USBDEV(sc));
1353
David Howellsc4028952006-11-22 14:57:56 +00001354 INIT_WORK(&sc->task, uea_load_page);
matthieu castetb72458a2005-11-07 23:27:13 +01001355 init_waitqueue_head(&sc->sync_q);
1356 init_waitqueue_head(&sc->cmv_ack_wait);
1357
1358 if (UEA_CHIP_VERSION(sc) == ADI930)
1359 load_XILINX_firmware(sc);
1360
1361 intr = kmalloc(INTR_PKT_SIZE, GFP_KERNEL);
1362 if (!intr) {
1363 uea_err(INS_TO_USBDEV(sc),
1364 "cannot allocate interrupt package\n");
1365 uea_leaves(INS_TO_USBDEV(sc));
1366 return -ENOMEM;
1367 }
1368
1369 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
1370 if (!sc->urb_int) {
1371 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
1372 goto err;
1373 }
1374
1375 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
1376 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
1377 intr, INTR_PKT_SIZE, uea_intr, sc,
1378 sc->usb_dev->actconfig->interface[0]->altsetting[0].
1379 endpoint[0].desc.bInterval);
1380
1381 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
1382 if (ret < 0) {
1383 uea_err(INS_TO_USBDEV(sc),
1384 "urb submition failed with error %d\n", ret);
matthieu castet4d45e212006-04-02 18:45:46 +02001385 goto err;
matthieu castetb72458a2005-11-07 23:27:13 +01001386 }
1387
1388 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm");
1389 if (sc->kthread == ERR_PTR(-ENOMEM)) {
1390 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
1391 goto err2;
1392 }
1393
1394 uea_leaves(INS_TO_USBDEV(sc));
1395 return 0;
1396
1397err2:
1398 usb_kill_urb(sc->urb_int);
matthieu castetb72458a2005-11-07 23:27:13 +01001399err:
1400 usb_free_urb(sc->urb_int);
matthieu castet4d45e212006-04-02 18:45:46 +02001401 sc->urb_int = NULL;
1402 kfree(intr);
matthieu castetb72458a2005-11-07 23:27:13 +01001403 uea_leaves(INS_TO_USBDEV(sc));
1404 return -ENOMEM;
1405}
1406
1407/*
1408 * Stop the modem : kill kernel thread and free data
1409 */
1410static void uea_stop(struct uea_softc *sc)
1411{
1412 int ret;
1413 uea_enters(INS_TO_USBDEV(sc));
1414 ret = kthread_stop(sc->kthread);
matthieu castete40abaf2006-01-18 07:38:37 +01001415 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
matthieu castetb72458a2005-11-07 23:27:13 +01001416
1417 /* stop any pending boot process */
1418 flush_scheduled_work();
1419
1420 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1421
1422 usb_kill_urb(sc->urb_int);
1423 kfree(sc->urb_int->transfer_buffer);
1424 usb_free_urb(sc->urb_int);
1425
1426 if (sc->dsp_firm)
1427 release_firmware(sc->dsp_firm);
1428 uea_leaves(INS_TO_USBDEV(sc));
1429}
1430
1431/* syfs interface */
1432static struct uea_softc *dev_to_uea(struct device *dev)
1433{
1434 struct usb_interface *intf;
1435 struct usbatm_data *usbatm;
1436
1437 intf = to_usb_interface(dev);
1438 if (!intf)
1439 return NULL;
1440
1441 usbatm = usb_get_intfdata(intf);
1442 if (!usbatm)
1443 return NULL;
1444
1445 return usbatm->driver_data;
1446}
1447
1448static ssize_t read_status(struct device *dev, struct device_attribute *attr,
1449 char *buf)
1450{
1451 int ret = -ENODEV;
1452 struct uea_softc *sc;
1453
Arjan van de Venab3c81f2006-01-13 15:52:55 +01001454 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01001455 sc = dev_to_uea(dev);
1456 if (!sc)
1457 goto out;
1458 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
1459out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01001460 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01001461 return ret;
1462}
1463
1464static ssize_t reboot(struct device *dev, struct device_attribute *attr,
1465 const char *buf, size_t count)
1466{
1467 int ret = -ENODEV;
1468 struct uea_softc *sc;
1469
Arjan van de Venab3c81f2006-01-13 15:52:55 +01001470 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01001471 sc = dev_to_uea(dev);
1472 if (!sc)
1473 goto out;
1474 sc->reset = 1;
1475 ret = count;
1476out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01001477 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01001478 return ret;
1479}
1480
1481static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot);
1482
1483static ssize_t read_human_status(struct device *dev, struct device_attribute *attr,
1484 char *buf)
1485{
1486 int ret = -ENODEV;
1487 struct uea_softc *sc;
1488
Arjan van de Venab3c81f2006-01-13 15:52:55 +01001489 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01001490 sc = dev_to_uea(dev);
1491 if (!sc)
1492 goto out;
1493
1494 switch (GET_STATUS(sc->stats.phy.state)) {
1495 case 0:
1496 ret = sprintf(buf, "Modem is booting\n");
1497 break;
1498 case 1:
1499 ret = sprintf(buf, "Modem is initializing\n");
1500 break;
1501 case 2:
1502 ret = sprintf(buf, "Modem is operational\n");
1503 break;
1504 default:
1505 ret = sprintf(buf, "Modem synchronization failed\n");
1506 break;
1507 }
1508out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01001509 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01001510 return ret;
1511}
1512
1513static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, read_human_status, NULL);
1514
1515static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
1516 char *buf)
1517{
1518 int ret = -ENODEV;
1519 struct uea_softc *sc;
1520
Arjan van de Venab3c81f2006-01-13 15:52:55 +01001521 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01001522 sc = dev_to_uea(dev);
1523 if (!sc)
1524 goto out;
1525
1526 if (sc->stats.phy.flags & 0x0C00)
1527 ret = sprintf(buf, "ERROR\n");
1528 else if (sc->stats.phy.flags & 0x0030)
1529 ret = sprintf(buf, "LOSS\n");
1530 else
1531 ret = sprintf(buf, "GOOD\n");
1532out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01001533 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01001534 return ret;
1535}
1536
1537static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL);
1538
1539#define UEA_ATTR(name, reset) \
1540 \
1541static ssize_t read_##name(struct device *dev, \
1542 struct device_attribute *attr, char *buf) \
1543{ \
1544 int ret = -ENODEV; \
1545 struct uea_softc *sc; \
1546 \
matthieu castet2a99b502006-04-02 18:43:53 +02001547 mutex_lock(&uea_mutex); \
matthieu castetb72458a2005-11-07 23:27:13 +01001548 sc = dev_to_uea(dev); \
1549 if (!sc) \
1550 goto out; \
1551 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
1552 if (reset) \
1553 sc->stats.phy.name = 0; \
1554out: \
matthieu castet2a99b502006-04-02 18:43:53 +02001555 mutex_unlock(&uea_mutex); \
matthieu castetb72458a2005-11-07 23:27:13 +01001556 return ret; \
1557} \
1558 \
1559static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
1560
1561UEA_ATTR(mflags, 1);
1562UEA_ATTR(vidcpe, 0);
1563UEA_ATTR(usrate, 0);
1564UEA_ATTR(dsrate, 0);
1565UEA_ATTR(usattenuation, 0);
1566UEA_ATTR(dsattenuation, 0);
1567UEA_ATTR(usmargin, 0);
1568UEA_ATTR(dsmargin, 0);
1569UEA_ATTR(txflow, 0);
1570UEA_ATTR(rxflow, 0);
1571UEA_ATTR(uscorr, 0);
1572UEA_ATTR(dscorr, 0);
1573UEA_ATTR(usunc, 0);
1574UEA_ATTR(dsunc, 0);
matthieu casteta7a0c9c2006-10-03 21:44:11 +02001575UEA_ATTR(firmid, 0);
matthieu castetb72458a2005-11-07 23:27:13 +01001576
1577/* Retrieve the device End System Identifier (MAC) */
1578
1579#define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
1580static int uea_getesi(struct uea_softc *sc, u_char * esi)
1581{
1582 unsigned char mac_str[2 * ETH_ALEN + 1];
1583 int i;
1584 if (usb_string
1585 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
1586 sizeof(mac_str)) != 2 * ETH_ALEN)
1587 return 1;
1588
1589 for (i = 0; i < ETH_ALEN; i++)
1590 esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]);
1591
1592 return 0;
1593}
1594
1595/* ATM stuff */
1596static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
1597{
1598 struct uea_softc *sc = usbatm->driver_data;
1599
1600 return uea_getesi(sc, atm_dev->esi);
1601}
1602
1603static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
1604{
1605 struct uea_softc *sc = usbatm->driver_data;
1606
matthieu castet531a39b2006-10-03 21:49:29 +02001607 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01001608
1609 return 0;
1610
1611}
1612
1613static int claim_interface(struct usb_device *usb_dev,
1614 struct usbatm_data *usbatm, int ifnum)
1615{
1616 int ret;
1617 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
1618
1619 if (!intf) {
1620 uea_err(usb_dev, "interface %d not found\n", ifnum);
1621 return -ENODEV;
1622 }
1623
1624 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
1625 if (ret != 0)
1626 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
1627 ret);
1628 return ret;
1629}
1630
Greg Kroah-Hartmane7ccdfe2006-08-28 11:43:25 -07001631static struct attribute *attrs[] = {
1632 &dev_attr_stat_status.attr,
1633 &dev_attr_stat_mflags.attr,
1634 &dev_attr_stat_human_status.attr,
1635 &dev_attr_stat_delin.attr,
1636 &dev_attr_stat_vidcpe.attr,
1637 &dev_attr_stat_usrate.attr,
1638 &dev_attr_stat_dsrate.attr,
1639 &dev_attr_stat_usattenuation.attr,
1640 &dev_attr_stat_dsattenuation.attr,
1641 &dev_attr_stat_usmargin.attr,
1642 &dev_attr_stat_dsmargin.attr,
1643 &dev_attr_stat_txflow.attr,
1644 &dev_attr_stat_rxflow.attr,
1645 &dev_attr_stat_uscorr.attr,
1646 &dev_attr_stat_dscorr.attr,
1647 &dev_attr_stat_usunc.attr,
1648 &dev_attr_stat_dsunc.attr,
matthieu casteta7a0c9c2006-10-03 21:44:11 +02001649 &dev_attr_stat_firmid.attr,
matthieu castet9ab99c82006-10-11 14:20:56 -07001650 NULL,
Greg Kroah-Hartmane7ccdfe2006-08-28 11:43:25 -07001651};
1652static struct attribute_group attr_grp = {
1653 .attrs = attrs,
1654};
1655
matthieu castetb72458a2005-11-07 23:27:13 +01001656static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
Duncan Sands35644b02006-01-17 11:16:13 +01001657 const struct usb_device_id *id)
matthieu castetb72458a2005-11-07 23:27:13 +01001658{
1659 struct usb_device *usb = interface_to_usbdev(intf);
1660 struct uea_softc *sc;
1661 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
1662
1663 uea_enters(usb);
1664
1665 /* interface 0 is for firmware/monitoring */
1666 if (ifnum != UEA_INTR_IFACE_NO)
1667 return -ENODEV;
1668
Duncan Sands0dfcd3e2006-01-13 09:36:20 +01001669 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
matthieu castetb72458a2005-11-07 23:27:13 +01001670
1671 /* interface 1 is for outbound traffic */
1672 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
1673 if (ret < 0)
1674 return ret;
1675
matthieu castete40abaf2006-01-18 07:38:37 +01001676 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
matthieu castetb72458a2005-11-07 23:27:13 +01001677 if (UEA_CHIP_VERSION(id) != ADI930) {
1678 /* interface 2 is for inbound traffic */
1679 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
1680 if (ret < 0)
1681 return ret;
1682 }
1683
1684 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
1685 if (!sc) {
matthieu castet584958c2006-04-02 18:44:48 +02001686 uea_err(usb, "uea_init: not enough memory !\n");
matthieu castetb72458a2005-11-07 23:27:13 +01001687 return -ENOMEM;
1688 }
1689
1690 sc->usb_dev = usb;
1691 usbatm->driver_data = sc;
1692 sc->usbatm = usbatm;
1693 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
1694 sc->driver_info = id->driver_info;
1695
matthieu castet3c9666c2006-01-18 07:38:19 +01001696 /* ADI930 don't support iso */
1697 if (UEA_CHIP_VERSION(id) != ADI930 && use_iso[sc->modem_index]) {
1698 int i;
1699
1700 /* try set fastest alternate for inbound traffic interface */
1701 for (i = FASTEST_ISO_INTF; i > 0; i--)
1702 if (usb_set_interface(usb, UEA_DS_IFACE_NO, i) == 0)
1703 break;
1704
1705 if (i > 0) {
1706 uea_dbg(usb, "set alternate %d for 2 interface\n", i);
1707 uea_info(usb, "using iso mode\n");
1708 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
1709 } else {
1710 uea_err(usb, "setting any alternate failed for "
1711 "2 interface, using bulk mode\n");
1712 }
1713 }
1714
matthieu castet9ab99c82006-10-11 14:20:56 -07001715 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
1716 if (ret < 0)
1717 goto error;
1718
matthieu castetb72458a2005-11-07 23:27:13 +01001719 ret = uea_boot(sc);
matthieu castet9ab99c82006-10-11 14:20:56 -07001720 if (ret < 0)
1721 goto error;
matthieu castetb72458a2005-11-07 23:27:13 +01001722
matthieu castetb72458a2005-11-07 23:27:13 +01001723 return 0;
matthieu castet9ab99c82006-10-11 14:20:56 -07001724error:
1725 kfree(sc);
1726 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001727}
1728
1729static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
1730{
1731 struct uea_softc *sc = usbatm->driver_data;
1732
matthieu castet9ab99c82006-10-11 14:20:56 -07001733 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
matthieu castetb72458a2005-11-07 23:27:13 +01001734 uea_stop(sc);
1735 kfree(sc);
1736}
1737
1738static struct usbatm_driver uea_usbatm_driver = {
1739 .driver_name = "ueagle-atm",
matthieu castetb72458a2005-11-07 23:27:13 +01001740 .bind = uea_bind,
1741 .atm_start = uea_atm_open,
1742 .unbind = uea_unbind,
1743 .heavy_init = uea_heavy,
Duncan Sands80aae7a2006-01-13 10:59:23 +01001744 .bulk_in = UEA_BULK_DATA_PIPE,
1745 .bulk_out = UEA_BULK_DATA_PIPE,
matthieu castet3c9666c2006-01-18 07:38:19 +01001746 .isoc_in = UEA_ISO_DATA_PIPE,
matthieu castetb72458a2005-11-07 23:27:13 +01001747};
1748
1749static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
1750{
1751 struct usb_device *usb = interface_to_usbdev(intf);
1752
1753 uea_enters(usb);
matthieu casteta7a0c9c2006-10-03 21:44:11 +02001754 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) : %s %s\n",
matthieu castetb72458a2005-11-07 23:27:13 +01001755 le16_to_cpu(usb->descriptor.idVendor),
1756 le16_to_cpu(usb->descriptor.idProduct),
matthieu casteta7a0c9c2006-10-03 21:44:11 +02001757 chip_name[UEA_CHIP_VERSION(id)], IS_ISDN(usb)?"isdn":"pots");
matthieu castetb72458a2005-11-07 23:27:13 +01001758
1759 usb_reset_device(usb);
1760
1761 if (UEA_IS_PREFIRM(id))
1762 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
1763
1764 return usbatm_usb_probe(intf, id, &uea_usbatm_driver);
1765}
1766
1767static void uea_disconnect(struct usb_interface *intf)
1768{
1769 struct usb_device *usb = interface_to_usbdev(intf);
1770 int ifnum = intf->altsetting->desc.bInterfaceNumber;
1771 uea_enters(usb);
1772
1773 /* ADI930 has 2 interfaces and eagle 3 interfaces.
1774 * Pre-firmware device has one interface
1775 */
1776 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
Arjan van de Venab3c81f2006-01-13 15:52:55 +01001777 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01001778 usbatm_usb_disconnect(intf);
Arjan van de Venab3c81f2006-01-13 15:52:55 +01001779 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01001780 uea_info(usb, "ADSL device removed\n");
1781 }
1782
1783 uea_leaves(usb);
1784}
1785
1786/*
1787 * List of supported VID/PID
1788 */
1789static const struct usb_device_id uea_ids[] = {
1790 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
1791 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
1792 {USB_DEVICE(EAGLE_VID, EAGLE_I_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
1793 {USB_DEVICE(EAGLE_VID, EAGLE_I_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
1794 {USB_DEVICE(EAGLE_VID, EAGLE_II_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
1795 {USB_DEVICE(EAGLE_VID, EAGLE_II_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
1796 {USB_DEVICE(EAGLE_VID, EAGLE_IIC_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
1797 {USB_DEVICE(EAGLE_VID, EAGLE_IIC_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
1798 {USB_DEVICE(EAGLE_VID, EAGLE_III_PID_PREFIRM), .driver_info = EAGLE_III | PREFIRM},
1799 {USB_DEVICE(EAGLE_VID, EAGLE_III_PID_PSTFIRM), .driver_info = EAGLE_III | PSTFIRM},
1800 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
1801 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
1802 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
1803 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
1804 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
1805 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM},
1806 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
1807 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM},
1808 {}
1809};
1810
1811/*
1812 * USB driver descriptor
1813 */
1814static struct usb_driver uea_driver = {
matthieu castetb72458a2005-11-07 23:27:13 +01001815 .name = "ueagle-atm",
1816 .id_table = uea_ids,
1817 .probe = uea_probe,
1818 .disconnect = uea_disconnect,
1819};
1820
1821MODULE_DEVICE_TABLE(usb, uea_ids);
1822
1823/**
1824 * uea_init - Initialize the module.
1825 * Register to USB subsystem
1826 */
1827static int __init uea_init(void)
1828{
1829 printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n");
1830
1831 usb_register(&uea_driver);
1832
1833 return 0;
1834}
1835
1836module_init(uea_init);
1837
1838/**
1839 * uea_exit - Destroy module
1840 * Deregister with USB subsystem
1841 */
1842static void __exit uea_exit(void)
1843{
1844 /*
1845 * This calls automatically the uea_disconnect method if necessary:
1846 */
1847 usb_deregister(&uea_driver);
1848
1849 printk(KERN_INFO "[ueagle-atm] driver unloaded\n");
1850}
1851
1852module_exit(uea_exit);
1853
1854MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
1855MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
1856MODULE_LICENSE("Dual BSD/GPL");