2 * Copyright (c) 2003, 2004
3 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
5 * Copyright (c) 2005 Matthieu Castet <castet.matthieu@free.fr>
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
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice unmodified, this list of conditions, and the following
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.
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
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.
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.
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.
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.
54 * The rest of the code was was rewritten from scratch.
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>
64 #include <linux/kthread.h>
65 #include <linux/version.h>
66 #include <linux/mutex.h>
67 #include <linux/freezer.h>
69 #include <asm/unaligned.h>
73 #define EAGLEUSBVERSION "ueagle 1.4"
79 #define uea_dbg(usb_dev, format, args...) \
82 dev_dbg(&(usb_dev)->dev, \
83 "[ueagle-atm dbg] %s: " format, \
84 __FUNCTION__, ##args); \
87 #define uea_vdbg(usb_dev, format, args...) \
90 dev_dbg(&(usb_dev)->dev, \
91 "[ueagle-atm vdbg] " format, ##args); \
94 #define uea_enters(usb_dev) \
95 uea_vdbg(usb_dev, "entering %s\n", __FUNCTION__)
97 #define uea_leaves(usb_dev) \
98 uea_vdbg(usb_dev, "leaving %s\n", __FUNCTION__)
100 #define uea_err(usb_dev, format,args...) \
101 dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args)
103 #define uea_warn(usb_dev, format,args...) \
104 dev_warn(&(usb_dev)->dev ,"[Ueagle-atm] " format, ##args)
106 #define uea_info(usb_dev, format,args...) \
107 dev_info(&(usb_dev)->dev ,"[ueagle-atm] " format, ##args)
113 } __attribute__ ((packed
));
116 struct usb_device
*usb_dev
;
117 struct usbatm_data
*usbatm
;
120 unsigned int driver_info
;
125 wait_queue_head_t sync_q
;
127 struct task_struct
*kthread
;
129 wait_queue_head_t cmv_ack_wait
;
132 struct work_struct task
;
136 const struct firmware
*dsp_firm
;
144 /* keep in sync with eaglectl */
172 #define ELSA_VID 0x05CC
173 #define ELSA_PID_PSTFIRM 0x3350
174 #define ELSA_PID_PREFIRM 0x3351
179 #define EAGLE_VID 0x1110
180 #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
181 #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
183 #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
184 #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
186 #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
187 #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
192 #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
193 #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
198 #define USR_VID 0x0BAF
199 #define MILLER_A_PID_PREFIRM 0x00F2
200 #define MILLER_A_PID_PSTFIRM 0x00F1
201 #define MILLER_B_PID_PREFIRM 0x00FA
202 #define MILLER_B_PID_PSTFIRM 0x00F9
203 #define HEINEKEN_A_PID_PREFIRM 0x00F6
204 #define HEINEKEN_A_PID_PSTFIRM 0x00F5
205 #define HEINEKEN_B_PID_PREFIRM 0x00F8
206 #define HEINEKEN_B_PID_PSTFIRM 0x00F7
209 #define PSTFIRM (1<<7)
217 /* macros for both struct usb_device_id and struct uea_softc */
218 #define UEA_IS_PREFIRM(x) \
219 (!((x)->driver_info & PSTFIRM))
220 #define UEA_CHIP_VERSION(x) \
221 ((x)->driver_info & 0xf)
223 #define IS_ISDN(usb_dev) \
224 (le16_to_cpu((usb_dev)->descriptor.bcdDevice) & 0x80)
226 #define INS_TO_USBDEV(ins) ins->usb_dev
228 #define GET_STATUS(data) \
230 #define IS_OPERATIONAL(sc) \
231 (GET_STATUS(sc->stats.phy.state) == 2)
234 * Set of macros to handle unaligned data in the firmware blob.
235 * The FW_GET_BYTE() macro is provided only for consistency.
238 #define FW_GET_BYTE(p) *((__u8 *) (p))
239 #define FW_GET_WORD(p) le16_to_cpu(get_unaligned((__le16 *) (p)))
240 #define FW_GET_LONG(p) le32_to_cpu(get_unaligned((__le32 *) (p)))
242 #define FW_DIR "ueagle-atm/"
245 #define BULK_TIMEOUT 300
246 #define CTRL_TIMEOUT 1000
248 #define ACK_TIMEOUT msecs_to_jiffies(3000)
250 #define UEA_INTR_IFACE_NO 0
251 #define UEA_US_IFACE_NO 1
252 #define UEA_DS_IFACE_NO 2
254 #define FASTEST_ISO_INTF 8
256 #define UEA_BULK_DATA_PIPE 0x02
257 #define UEA_IDMA_PIPE 0x04
258 #define UEA_INTR_PIPE 0x04
259 #define UEA_ISO_DATA_PIPE 0x08
261 #define UEA_SET_BLOCK 0x0001
262 #define UEA_SET_MODE 0x0003
263 #define UEA_SET_2183_DATA 0x0004
264 #define UEA_SET_TIMEOUT 0x0011
266 #define UEA_LOOPBACK_OFF 0x0002
267 #define UEA_LOOPBACK_ON 0x0003
268 #define UEA_BOOT_IDMA 0x0006
269 #define UEA_START_RESET 0x0007
270 #define UEA_END_RESET 0x0008
272 #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
273 #define UEA_MPTX_START (0x3fce | 0x4000)
274 #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
275 #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
277 /* structure describing a block within a DSP page */
280 #define UEA_BIHDR 0xabcd
284 __le16 wOvl
; /* overlay */
286 } __attribute__ ((packed
));
287 #define BLOCK_INFO_SIZE 12
289 /* structure representing a CMV (Configuration and Management Variable) */
292 #define PREAMBLE 0x535c
294 #define MODEMTOHOST 0x01
295 #define HOSTTOMODEM 0x10
297 #define FUNCTION_TYPE(f) ((f) >> 4)
298 #define MEMACCESS 0x1
299 #define ADSLDIRECTIVE 0x7
301 #define FUNCTION_SUBTYPE(f) ((f) & 0x0f)
303 #define REQUESTREAD 0x0
304 #define REQUESTWRITE 0x1
305 #define REPLYREAD 0x2
306 #define REPLYWRITE 0x3
307 /* for ADSLDIRECTIVE */
308 #define KERNELREADY 0x0
309 #define MODEMREADY 0x1
311 #define MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
313 __le32 dwSymbolicAddress
;
314 #define MAKESA(a, b, c, d) \
315 (((c) & 0xff) << 24 | \
316 ((d) & 0xff) << 16 | \
317 ((a) & 0xff) << 8 | \
319 #define GETSA1(a) ((a >> 8) & 0xff)
320 #define GETSA2(a) (a & 0xff)
321 #define GETSA3(a) ((a >> 24) & 0xff)
322 #define GETSA4(a) ((a >> 16) & 0xff)
324 #define SA_CNTL MAKESA('C', 'N', 'T', 'L')
325 #define SA_DIAG MAKESA('D', 'I', 'A', 'G')
326 #define SA_INFO MAKESA('I', 'N', 'F', 'O')
327 #define SA_OPTN MAKESA('O', 'P', 'T', 'N')
328 #define SA_RATE MAKESA('R', 'A', 'T', 'E')
329 #define SA_STAT MAKESA('S', 'T', 'A', 'T')
330 __le16 wOffsetAddress
;
332 } __attribute__ ((packed
));
335 /* structure representing swap information */
338 __u8 bOvl
; /* overlay */
339 } __attribute__ ((packed
));
341 /* structure representing interrupt data */
349 #define INT_LOADSWAPPAGE 0x0001
350 #define INT_INCOMINGCMV 0x0002
353 struct swap_info swapinfo
;
355 } __attribute__ ((packed
)) s1
;
360 } __attribute__ ((packed
)) s2
;
361 } __attribute__ ((packed
)) u
;
362 #define bSwapPageNo u.s1.swapinfo.bSwapPageNo
363 #define bOvl u.s1.swapinfo.bOvl
364 } __attribute__ ((packed
));
365 #define INTR_PKT_SIZE 28
367 static struct usb_driver uea_driver
;
368 static DEFINE_MUTEX(uea_mutex
);
369 static const char *chip_name
[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III"};
371 static int modem_index
;
372 static unsigned int debug
;
373 static int use_iso
[NB_MODEM
] = {[0 ... (NB_MODEM
- 1)] = 1};
374 static int sync_wait
[NB_MODEM
];
375 static char *cmv_file
[NB_MODEM
];
377 module_param(debug
, uint
, 0644);
378 MODULE_PARM_DESC(debug
, "module debug level (0=off,1=on,2=verbose)");
379 module_param_array(use_iso
, bool, NULL
, 0644);
380 MODULE_PARM_DESC(use_iso
, "use isochronous usb pipe for incoming traffic");
381 module_param_array(sync_wait
, bool, NULL
, 0644);
382 MODULE_PARM_DESC(sync_wait
, "wait the synchronisation before starting ATM");
383 module_param_array(cmv_file
, charp
, NULL
, 0644);
384 MODULE_PARM_DESC(cmv_file
,
385 "file name with configuration and management variables");
387 #define UPDATE_ATM_STAT(type, val) \
389 if (sc->usbatm->atm_dev) \
390 sc->usbatm->atm_dev->type = val; \
393 /* Firmware loading */
394 #define LOAD_INTERNAL 0xA0
395 #define F8051_USBCS 0x7f92
398 * uea_send_modem_cmd - Send a command for pre-firmware devices.
400 static int uea_send_modem_cmd(struct usb_device
*usb
,
401 u16 addr
, u16 size
, u8
* buff
)
406 xfer_buff
= kmemdup(buff
, size
, GFP_KERNEL
);
408 ret
= usb_control_msg(usb
,
409 usb_sndctrlpipe(usb
, 0),
411 USB_DIR_OUT
| USB_TYPE_VENDOR
|
412 USB_RECIP_DEVICE
, addr
, 0, xfer_buff
,
420 return (ret
== size
) ? 0 : -EIO
;
423 static void uea_upload_pre_firmware(const struct firmware
*fw_entry
, void *context
)
425 struct usb_device
*usb
= context
;
432 uea_err(usb
, "firmware is not available\n");
436 pfw
= fw_entry
->data
;
437 size
= fw_entry
->size
;
439 goto err_fw_corrupted
;
441 crc
= FW_GET_LONG(pfw
);
444 if (crc32_be(0, pfw
, size
) != crc
)
445 goto err_fw_corrupted
;
448 * Start to upload formware : send reset
451 ret
= uea_send_modem_cmd(usb
, F8051_USBCS
, sizeof(value
), &value
);
454 uea_err(usb
, "modem reset failed with error %d\n", ret
);
459 u8 len
= FW_GET_BYTE(pfw
);
460 u16 add
= FW_GET_WORD(pfw
+ 1);
464 goto err_fw_corrupted
;
466 ret
= uea_send_modem_cmd(usb
, add
, len
, pfw
+ 3);
468 uea_err(usb
, "uploading firmware data failed "
469 "with error %d\n", ret
);
476 goto err_fw_corrupted
;
479 * Tell the modem we finish : de-assert reset
482 ret
= uea_send_modem_cmd(usb
, F8051_USBCS
, 1, &value
);
484 uea_err(usb
, "modem de-assert failed with error %d\n", ret
);
486 uea_info(usb
, "firmware uploaded\n");
492 uea_err(usb
, "firmware is corrupted\n");
498 * uea_load_firmware - Load usb firmware for pre-firmware devices.
500 static int uea_load_firmware(struct usb_device
*usb
, unsigned int ver
)
503 char *fw_name
= FW_DIR
"eagle.fw";
506 uea_info(usb
, "pre-firmware device, uploading firmware\n");
510 fw_name
= FW_DIR
"adi930.fw";
513 fw_name
= FW_DIR
"eagleI.fw";
516 fw_name
= FW_DIR
"eagleII.fw";
519 fw_name
= FW_DIR
"eagleIII.fw";
523 ret
= request_firmware_nowait(THIS_MODULE
, 1, fw_name
, &usb
->dev
, usb
, uea_upload_pre_firmware
);
525 uea_err(usb
, "firmware %s is not available\n", fw_name
);
527 uea_info(usb
, "loading firmware %s\n", fw_name
);
533 /* modem management : dsp firmware, send/read CMV, monitoring statistic
537 * Make sure that the DSP code provided is safe to use.
539 static int check_dsp(u8
*dsp
, unsigned int len
)
541 u8 pagecount
, blockcount
;
544 unsigned int i
, j
, p
, pp
;
546 pagecount
= FW_GET_BYTE(dsp
);
549 /* enough space for page offsets? */
550 if (p
+ 4 * pagecount
> len
)
553 for (i
= 0; i
< pagecount
; i
++) {
555 pageoffset
= FW_GET_LONG(dsp
+ p
);
561 /* enough space for blockcount? */
562 if (pageoffset
>= len
)
566 blockcount
= FW_GET_BYTE(dsp
+ pp
);
569 for (j
= 0; j
< blockcount
; j
++) {
571 /* enough space for block header? */
575 pp
+= 2; /* skip blockaddr */
576 blocksize
= FW_GET_WORD(dsp
+ pp
);
579 /* enough space for block data? */
580 if (pp
+ blocksize
> len
)
591 * send data to the idma pipe
593 static int uea_idma_write(struct uea_softc
*sc
, void *data
, u32 size
)
599 xfer_buff
= kmemdup(data
, size
, GFP_KERNEL
);
601 uea_err(INS_TO_USBDEV(sc
), "can't allocate xfer_buff\n");
605 ret
= usb_bulk_msg(sc
->usb_dev
,
606 usb_sndbulkpipe(sc
->usb_dev
, UEA_IDMA_PIPE
),
607 xfer_buff
, size
, &bytes_read
, BULK_TIMEOUT
);
612 if (size
!= bytes_read
) {
613 uea_err(INS_TO_USBDEV(sc
), "size != bytes_read %d %d\n", size
,
621 static int request_dsp(struct uea_softc
*sc
)
626 if (UEA_CHIP_VERSION(sc
) == ADI930
) {
627 if (IS_ISDN(sc
->usb_dev
))
628 dsp_name
= FW_DIR
"DSP9i.bin";
630 dsp_name
= FW_DIR
"DSP9p.bin";
632 if (IS_ISDN(sc
->usb_dev
))
633 dsp_name
= FW_DIR
"DSPei.bin";
635 dsp_name
= FW_DIR
"DSPep.bin";
638 ret
= request_firmware(&sc
->dsp_firm
, dsp_name
, &sc
->usb_dev
->dev
);
640 uea_err(INS_TO_USBDEV(sc
),
641 "requesting firmware %s failed with error %d\n",
646 if (check_dsp(sc
->dsp_firm
->data
, sc
->dsp_firm
->size
)) {
647 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n",
649 release_firmware(sc
->dsp_firm
);
658 * The uea_load_page() function must be called within a process context
660 static void uea_load_page(struct work_struct
*work
)
662 struct uea_softc
*sc
= container_of(work
, struct uea_softc
, task
);
663 u16 pageno
= sc
->pageno
;
665 struct block_info bi
;
668 u8 pagecount
, blockcount
;
669 u16 blockaddr
, blocksize
;
673 /* reload firmware when reboot start and it's loaded already */
674 if (ovl
== 0 && pageno
== 0 && sc
->dsp_firm
) {
675 release_firmware(sc
->dsp_firm
);
679 if (sc
->dsp_firm
== NULL
&& request_dsp(sc
) < 0)
682 p
= sc
->dsp_firm
->data
;
683 pagecount
= FW_GET_BYTE(p
);
686 if (pageno
>= pagecount
)
690 pageoffset
= FW_GET_LONG(p
);
695 p
= sc
->dsp_firm
->data
+ pageoffset
;
696 blockcount
= FW_GET_BYTE(p
);
699 uea_dbg(INS_TO_USBDEV(sc
),
700 "sending %u blocks for DSP page %u\n", blockcount
, pageno
);
702 bi
.wHdr
= cpu_to_le16(UEA_BIHDR
);
703 bi
.wOvl
= cpu_to_le16(ovl
);
704 bi
.wOvlOffset
= cpu_to_le16(ovl
| 0x8000);
706 for (i
= 0; i
< blockcount
; i
++) {
707 blockaddr
= FW_GET_WORD(p
);
710 blocksize
= FW_GET_WORD(p
);
713 bi
.wSize
= cpu_to_le16(blocksize
);
714 bi
.wAddress
= cpu_to_le16(blockaddr
);
715 bi
.wLast
= cpu_to_le16((i
== blockcount
- 1) ? 1 : 0);
717 /* send block info through the IDMA pipe */
718 if (uea_idma_write(sc
, &bi
, BLOCK_INFO_SIZE
))
721 /* send block data through the IDMA pipe */
722 if (uea_idma_write(sc
, p
, blocksize
))
731 uea_err(INS_TO_USBDEV(sc
), "sending DSP block %u failed\n", i
);
734 uea_err(INS_TO_USBDEV(sc
), "invalid DSP page %u requested\n", pageno
);
737 static inline void wake_up_cmv_ack(struct uea_softc
*sc
)
741 wake_up(&sc
->cmv_ack_wait
);
744 static inline int wait_cmv_ack(struct uea_softc
*sc
)
746 int ret
= wait_event_interruptible_timeout(sc
->cmv_ack_wait
,
747 sc
->cmv_ack
, ACK_TIMEOUT
);
750 uea_dbg(INS_TO_USBDEV(sc
), "wait_event_timeout : %d ms\n",
751 jiffies_to_msecs(ret
));
756 return (ret
== 0) ? -ETIMEDOUT
: 0;
759 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
761 static int uea_request(struct uea_softc
*sc
,
762 u16 value
, u16 index
, u16 size
, void *data
)
767 xfer_buff
= kmemdup(data
, size
, GFP_KERNEL
);
769 uea_err(INS_TO_USBDEV(sc
), "can't allocate xfer_buff\n");
773 ret
= usb_control_msg(sc
->usb_dev
, usb_sndctrlpipe(sc
->usb_dev
, 0),
774 UCDC_SEND_ENCAPSULATED_COMMAND
,
775 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
776 value
, index
, xfer_buff
, size
, CTRL_TIMEOUT
);
780 uea_err(INS_TO_USBDEV(sc
), "usb_control_msg error %d\n", ret
);
785 uea_err(INS_TO_USBDEV(sc
),
786 "usb_control_msg send only %d bytes (instead of %d)\n",
794 static int uea_cmv(struct uea_softc
*sc
,
795 u8 function
, u32 address
, u16 offset
, u32 data
)
800 uea_enters(INS_TO_USBDEV(sc
));
801 uea_vdbg(INS_TO_USBDEV(sc
), "Function : %d-%d, Address : %c%c%c%c, "
802 "offset : 0x%04x, data : 0x%08x\n",
803 FUNCTION_TYPE(function
), FUNCTION_SUBTYPE(function
),
804 GETSA1(address
), GETSA2(address
), GETSA3(address
),
805 GETSA4(address
), offset
, data
);
806 /* we send a request, but we expect a reply */
807 sc
->cmv_function
= function
| 0x2;
809 sc
->cmv_address
= address
;
810 sc
->cmv_offset
= offset
;
812 cmv
.wPreamble
= cpu_to_le16(PREAMBLE
);
813 cmv
.bDirection
= HOSTTOMODEM
;
814 cmv
.bFunction
= function
;
815 cmv
.wIndex
= cpu_to_le16(sc
->cmv_idx
);
816 put_unaligned(cpu_to_le32(address
), &cmv
.dwSymbolicAddress
);
817 cmv
.wOffsetAddress
= cpu_to_le16(offset
);
818 put_unaligned(cpu_to_le32(data
>> 16 | data
<< 16), &cmv
.dwData
);
820 ret
= uea_request(sc
, UEA_SET_BLOCK
, UEA_MPTX_START
, CMV_SIZE
, &cmv
);
823 ret
= wait_cmv_ack(sc
);
824 uea_leaves(INS_TO_USBDEV(sc
));
828 static inline int uea_read_cmv(struct uea_softc
*sc
,
829 u32 address
, u16 offset
, u32
*data
)
831 int ret
= uea_cmv(sc
, MAKEFUNCTION(MEMACCESS
, REQUESTREAD
),
834 uea_err(INS_TO_USBDEV(sc
),
835 "reading cmv failed with error %d\n", ret
);
842 static inline int uea_write_cmv(struct uea_softc
*sc
,
843 u32 address
, u16 offset
, u32 data
)
845 int ret
= uea_cmv(sc
, MAKEFUNCTION(MEMACCESS
, REQUESTWRITE
),
846 address
, offset
, data
);
848 uea_err(INS_TO_USBDEV(sc
),
849 "writing cmv failed with error %d\n", ret
);
855 * Monitor the modem and update the stat
856 * return 0 if everything is ok
857 * return < 0 if an error occurs (-EAGAIN reboot needed)
859 static int uea_stat(struct uea_softc
*sc
)
864 uea_enters(INS_TO_USBDEV(sc
));
865 data
= sc
->stats
.phy
.state
;
867 ret
= uea_read_cmv(sc
, SA_STAT
, 0, &sc
->stats
.phy
.state
);
871 switch (GET_STATUS(sc
->stats
.phy
.state
)) {
872 case 0: /* not yet synchronized */
873 uea_dbg(INS_TO_USBDEV(sc
),
874 "modem not yet synchronized\n");
877 case 1: /* initialization */
878 uea_dbg(INS_TO_USBDEV(sc
), "modem initializing\n");
881 case 2: /* operational */
882 uea_vdbg(INS_TO_USBDEV(sc
), "modem operational\n");
885 case 3: /* fail ... */
886 uea_info(INS_TO_USBDEV(sc
), "modem synchronization failed"
887 " (may be try other cmv/dsp)\n");
890 case 4 ... 6: /* test state */
891 uea_warn(INS_TO_USBDEV(sc
),
892 "modem in test mode - not supported\n");
895 case 7: /* fast-retain ... */
896 uea_info(INS_TO_USBDEV(sc
), "modem in fast-retain mode\n");
899 uea_err(INS_TO_USBDEV(sc
), "modem invalid SW mode %d\n",
900 GET_STATUS(sc
->stats
.phy
.state
));
904 if (GET_STATUS(data
) != 2) {
905 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_OFF
, 0, NULL
);
906 uea_info(INS_TO_USBDEV(sc
), "modem operational\n");
908 /* release the dsp firmware as it is not needed until
912 release_firmware(sc
->dsp_firm
);
917 /* always update it as atm layer could not be init when we switch to
920 UPDATE_ATM_STAT(signal
, ATM_PHY_SIG_FOUND
);
922 /* wake up processes waiting for synchronization */
923 wake_up(&sc
->sync_q
);
925 ret
= uea_read_cmv(sc
, SA_DIAG
, 2, &sc
->stats
.phy
.flags
);
928 sc
->stats
.phy
.mflags
|= sc
->stats
.phy
.flags
;
930 /* in case of a flags ( for example delineation LOSS (& 0x10)),
931 * we check the status again in order to detect the failure earlier
933 if (sc
->stats
.phy
.flags
) {
934 uea_dbg(INS_TO_USBDEV(sc
), "Stat flag = 0x%x\n",
935 sc
->stats
.phy
.flags
);
939 ret
= uea_read_cmv(sc
, SA_RATE
, 0, &data
);
943 /* in bulk mode the modem have problem with high rate
944 * changing internal timing could improve things, but the
945 * value is misterious.
946 * ADI930 don't support it (-EPIPE error).
948 if (UEA_CHIP_VERSION(sc
) != ADI930
949 && !use_iso
[sc
->modem_index
]
950 && sc
->stats
.phy
.dsrate
!= (data
>> 16) * 32) {
951 /* Original timming from ADI(used in windows driver)
952 * 0x20ffff>>16 * 32 = 32 * 32 = 1Mbits
954 u16 timeout
= (data
<= 0x20ffff) ? 0 : 1;
955 ret
= uea_request(sc
, UEA_SET_TIMEOUT
, timeout
, 0, NULL
);
956 uea_info(INS_TO_USBDEV(sc
),
957 "setting new timeout %d%s\n", timeout
,
958 ret
< 0?" failed":"");
960 sc
->stats
.phy
.dsrate
= (data
>> 16) * 32;
961 sc
->stats
.phy
.usrate
= (data
& 0xffff) * 32;
962 UPDATE_ATM_STAT(link_rate
, sc
->stats
.phy
.dsrate
* 1000 / 424);
964 ret
= uea_read_cmv(sc
, SA_DIAG
, 23, &data
);
967 sc
->stats
.phy
.dsattenuation
= (data
& 0xff) / 2;
969 ret
= uea_read_cmv(sc
, SA_DIAG
, 47, &data
);
972 sc
->stats
.phy
.usattenuation
= (data
& 0xff) / 2;
974 ret
= uea_read_cmv(sc
, SA_DIAG
, 25, &sc
->stats
.phy
.dsmargin
);
978 ret
= uea_read_cmv(sc
, SA_DIAG
, 49, &sc
->stats
.phy
.usmargin
);
982 ret
= uea_read_cmv(sc
, SA_DIAG
, 51, &sc
->stats
.phy
.rxflow
);
986 ret
= uea_read_cmv(sc
, SA_DIAG
, 52, &sc
->stats
.phy
.txflow
);
990 ret
= uea_read_cmv(sc
, SA_DIAG
, 54, &sc
->stats
.phy
.dsunc
);
995 ret
= uea_read_cmv(sc
, SA_DIAG
, 58, &sc
->stats
.phy
.usunc
);
999 ret
= uea_read_cmv(sc
, SA_DIAG
, 53, &sc
->stats
.phy
.dscorr
);
1003 /* only for atu-c */
1004 ret
= uea_read_cmv(sc
, SA_DIAG
, 57, &sc
->stats
.phy
.uscorr
);
1008 ret
= uea_read_cmv(sc
, SA_INFO
, 8, &sc
->stats
.phy
.vidco
);
1012 ret
= uea_read_cmv(sc
, SA_INFO
, 13, &sc
->stats
.phy
.vidcpe
);
1019 static int request_cmvs(struct uea_softc
*sc
,
1020 struct uea_cmvs
**cmvs
, const struct firmware
**fw
)
1025 char cmv_name
[FIRMWARE_NAME_MAX
]; /* 30 bytes stack variable */
1027 if (cmv_file
[sc
->modem_index
] == NULL
) {
1028 if (UEA_CHIP_VERSION(sc
) == ADI930
)
1029 file
= (IS_ISDN(sc
->usb_dev
)) ? "CMV9i.bin" : "CMV9p.bin";
1031 file
= (IS_ISDN(sc
->usb_dev
)) ? "CMVei.bin" : "CMVep.bin";
1033 file
= cmv_file
[sc
->modem_index
];
1035 strcpy(cmv_name
, FW_DIR
);
1036 strlcat(cmv_name
, file
, sizeof(cmv_name
));
1038 ret
= request_firmware(fw
, cmv_name
, &sc
->usb_dev
->dev
);
1040 uea_err(INS_TO_USBDEV(sc
),
1041 "requesting firmware %s failed with error %d\n",
1046 data
= (u8
*) (*fw
)->data
;
1047 size
= *data
* sizeof(struct uea_cmvs
) + 1;
1048 if (size
!= (*fw
)->size
) {
1049 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n",
1051 release_firmware(*fw
);
1055 *cmvs
= (struct uea_cmvs
*)(data
+ 1);
1059 /* Start boot post firmware modem:
1060 * - send reset commands through usb control pipe
1061 * - start workqueue for DSP loading
1062 * - send CMV options to modem
1065 static int uea_start_reset(struct uea_softc
*sc
)
1067 u16 zero
= 0; /* ;-) */
1069 struct uea_cmvs
*cmvs
;
1070 const struct firmware
*cmvs_fw
;
1072 uea_enters(INS_TO_USBDEV(sc
));
1073 uea_info(INS_TO_USBDEV(sc
), "(re)booting started\n");
1075 /* mask interrupt */
1077 /* We need to set this here because, a ack timeout could have occured,
1078 * but before we start the reboot, the ack occurs and set this to 1.
1079 * So we will failed to wait Ready CMV.
1082 UPDATE_ATM_STAT(signal
, ATM_PHY_SIG_LOST
);
1084 /* reset statistics */
1085 memset(&sc
->stats
, 0, sizeof(struct uea_stats
));
1087 /* tell the modem that we want to boot in IDMA mode */
1088 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_ON
, 0, NULL
);
1089 uea_request(sc
, UEA_SET_MODE
, UEA_BOOT_IDMA
, 0, NULL
);
1091 /* enter reset mode */
1092 uea_request(sc
, UEA_SET_MODE
, UEA_START_RESET
, 0, NULL
);
1094 /* original driver use 200ms, but windows driver use 100ms */
1097 /* leave reset mode */
1098 uea_request(sc
, UEA_SET_MODE
, UEA_END_RESET
, 0, NULL
);
1100 /* clear tx and rx mailboxes */
1101 uea_request(sc
, UEA_SET_2183_DATA
, UEA_MPTX_MAILBOX
, 2, &zero
);
1102 uea_request(sc
, UEA_SET_2183_DATA
, UEA_MPRX_MAILBOX
, 2, &zero
);
1103 uea_request(sc
, UEA_SET_2183_DATA
, UEA_SWAP_MAILBOX
, 2, &zero
);
1106 sc
->cmv_function
= MAKEFUNCTION(ADSLDIRECTIVE
, MODEMREADY
);
1107 /* demask interrupt */
1110 /* start loading DSP */
1113 schedule_work(&sc
->task
);
1115 /* wait for modem ready CMV */
1116 ret
= wait_cmv_ack(sc
);
1120 uea_vdbg(INS_TO_USBDEV(sc
), "Ready CMV received\n");
1122 /* Enter in R-IDLE (cmv) until instructed otherwise */
1123 ret
= uea_write_cmv(sc
, SA_CNTL
, 0, 1);
1127 /* Dump firmware version */
1128 ret
= uea_read_cmv(sc
, SA_INFO
, 10, &sc
->stats
.phy
.firmid
);
1131 uea_info(INS_TO_USBDEV(sc
), "ATU-R firmware version : %x\n",
1132 sc
->stats
.phy
.firmid
);
1135 ret
= len
= request_cmvs(sc
, &cmvs
, &cmvs_fw
);
1140 for (i
= 0; i
< len
; i
++) {
1141 ret
= uea_write_cmv(sc
, FW_GET_LONG(&cmvs
[i
].address
),
1142 FW_GET_WORD(&cmvs
[i
].offset
),
1143 FW_GET_LONG(&cmvs
[i
].data
));
1147 /* Enter in R-ACT-REQ */
1148 ret
= uea_write_cmv(sc
, SA_CNTL
, 0, 2);
1149 uea_vdbg(INS_TO_USBDEV(sc
), "Entering in R-ACT-REQ state\n");
1150 uea_info(INS_TO_USBDEV(sc
), "Modem started, "
1151 "waiting synchronization\n");
1153 release_firmware(cmvs_fw
);
1155 uea_leaves(INS_TO_USBDEV(sc
));
1160 * In case of an error wait 1s before rebooting the modem
1161 * if the modem don't request reboot (-EAGAIN).
1162 * Monitor the modem every 1s.
1165 static int uea_kthread(void *data
)
1167 struct uea_softc
*sc
= data
;
1170 uea_enters(INS_TO_USBDEV(sc
));
1171 while (!kthread_should_stop()) {
1172 if (ret
< 0 || sc
->reset
)
1173 ret
= uea_start_reset(sc
);
1177 msleep_interruptible(1000);
1178 if (try_to_freeze())
1179 uea_err(INS_TO_USBDEV(sc
), "suspend/resume not supported, "
1180 "please unplug/replug your modem\n");
1182 uea_leaves(INS_TO_USBDEV(sc
));
1186 /* Load second usb firmware for ADI930 chip */
1187 static int load_XILINX_firmware(struct uea_softc
*sc
)
1189 const struct firmware
*fw_entry
;
1190 int ret
, size
, u
, ln
;
1192 char *fw_name
= FW_DIR
"930-fpga.bin";
1194 uea_enters(INS_TO_USBDEV(sc
));
1196 ret
= request_firmware(&fw_entry
, fw_name
, &sc
->usb_dev
->dev
);
1198 uea_err(INS_TO_USBDEV(sc
), "firmware %s is not available\n",
1203 pfw
= fw_entry
->data
;
1204 size
= fw_entry
->size
;
1205 if (size
!= 0x577B) {
1206 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n",
1211 for (u
= 0; u
< size
; u
+= ln
) {
1212 ln
= min(size
- u
, 64);
1213 ret
= uea_request(sc
, 0xe, 0, ln
, pfw
+ u
);
1215 uea_err(INS_TO_USBDEV(sc
),
1216 "elsa download data failed (%d)\n", ret
);
1221 /* finish to send the fpga */
1222 ret
= uea_request(sc
, 0xe, 1, 0, NULL
);
1224 uea_err(INS_TO_USBDEV(sc
),
1225 "elsa download data failed (%d)\n", ret
);
1229 /* Tell the modem we finish : de-assert reset */
1231 ret
= uea_send_modem_cmd(sc
->usb_dev
, 0xe, 1, &value
);
1233 uea_err(sc
->usb_dev
, "elsa de-assert failed with error %d\n", ret
);
1237 release_firmware(fw_entry
);
1239 uea_leaves(INS_TO_USBDEV(sc
));
1243 /* The modem send us an ack. First with check if it right */
1244 static void uea_dispatch_cmv(struct uea_softc
*sc
, struct cmv
* cmv
)
1246 uea_enters(INS_TO_USBDEV(sc
));
1247 if (le16_to_cpu(cmv
->wPreamble
) != PREAMBLE
)
1250 if (cmv
->bDirection
!= MODEMTOHOST
)
1253 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1254 * the first MEMACESS cmv. Ignore it...
1256 if (cmv
->bFunction
!= sc
->cmv_function
) {
1257 if (UEA_CHIP_VERSION(sc
) == ADI930
1258 && cmv
->bFunction
== MAKEFUNCTION(2, 2)) {
1259 cmv
->wIndex
= cpu_to_le16(sc
->cmv_idx
);
1260 put_unaligned(cpu_to_le32(sc
->cmv_address
), &cmv
->dwSymbolicAddress
);
1261 cmv
->wOffsetAddress
= cpu_to_le16(sc
->cmv_offset
);
1267 if (cmv
->bFunction
== MAKEFUNCTION(ADSLDIRECTIVE
, MODEMREADY
)) {
1268 wake_up_cmv_ack(sc
);
1269 uea_leaves(INS_TO_USBDEV(sc
));
1273 /* in case of MEMACCESS */
1274 if (le16_to_cpu(cmv
->wIndex
) != sc
->cmv_idx
||
1275 le32_to_cpu(get_unaligned(&cmv
->dwSymbolicAddress
)) !=
1277 || le16_to_cpu(cmv
->wOffsetAddress
) != sc
->cmv_offset
)
1280 sc
->data
= le32_to_cpu(get_unaligned(&cmv
->dwData
));
1281 sc
->data
= sc
->data
<< 16 | sc
->data
>> 16;
1283 wake_up_cmv_ack(sc
);
1284 uea_leaves(INS_TO_USBDEV(sc
));
1288 uea_err(INS_TO_USBDEV(sc
), "unexpected cmv received,"
1289 "Function : %d, Subfunction : %d\n",
1290 FUNCTION_TYPE(cmv
->bFunction
),
1291 FUNCTION_SUBTYPE(cmv
->bFunction
));
1292 uea_leaves(INS_TO_USBDEV(sc
));
1296 uea_err(INS_TO_USBDEV(sc
), "invalid cmv received, "
1297 "wPreamble %d, bDirection %d\n",
1298 le16_to_cpu(cmv
->wPreamble
), cmv
->bDirection
);
1299 uea_leaves(INS_TO_USBDEV(sc
));
1305 static void uea_intr(struct urb
*urb
)
1307 struct uea_softc
*sc
= urb
->context
;
1308 struct intr_pkt
*intr
= urb
->transfer_buffer
;
1309 uea_enters(INS_TO_USBDEV(sc
));
1311 if (unlikely(urb
->status
< 0)) {
1312 uea_err(INS_TO_USBDEV(sc
), "uea_intr() failed with %d\n",
1317 /* device-to-host interrupt */
1318 if (intr
->bType
!= 0x08 || sc
->booting
) {
1319 uea_err(INS_TO_USBDEV(sc
), "wrong interrupt\n");
1323 switch (le16_to_cpu(intr
->wInterrupt
)) {
1324 case INT_LOADSWAPPAGE
:
1325 sc
->pageno
= intr
->bSwapPageNo
;
1326 sc
->ovl
= intr
->bOvl
>> 4 | intr
->bOvl
<< 4;
1327 schedule_work(&sc
->task
);
1330 case INT_INCOMINGCMV
:
1331 uea_dispatch_cmv(sc
, &intr
->u
.s2
.cmv
);
1335 uea_err(INS_TO_USBDEV(sc
), "unknown interrupt %u\n",
1336 le16_to_cpu(intr
->wInterrupt
));
1340 usb_submit_urb(sc
->urb_int
, GFP_ATOMIC
);
1344 * Start the modem : init the data and start kernel thread
1346 static int uea_boot(struct uea_softc
*sc
)
1349 struct intr_pkt
*intr
;
1351 uea_enters(INS_TO_USBDEV(sc
));
1353 INIT_WORK(&sc
->task
, uea_load_page
);
1354 init_waitqueue_head(&sc
->sync_q
);
1355 init_waitqueue_head(&sc
->cmv_ack_wait
);
1357 if (UEA_CHIP_VERSION(sc
) == ADI930
)
1358 load_XILINX_firmware(sc
);
1360 intr
= kmalloc(INTR_PKT_SIZE
, GFP_KERNEL
);
1362 uea_err(INS_TO_USBDEV(sc
),
1363 "cannot allocate interrupt package\n");
1364 uea_leaves(INS_TO_USBDEV(sc
));
1368 sc
->urb_int
= usb_alloc_urb(0, GFP_KERNEL
);
1370 uea_err(INS_TO_USBDEV(sc
), "cannot allocate interrupt URB\n");
1374 usb_fill_int_urb(sc
->urb_int
, sc
->usb_dev
,
1375 usb_rcvintpipe(sc
->usb_dev
, UEA_INTR_PIPE
),
1376 intr
, INTR_PKT_SIZE
, uea_intr
, sc
,
1377 sc
->usb_dev
->actconfig
->interface
[0]->altsetting
[0].
1378 endpoint
[0].desc
.bInterval
);
1380 ret
= usb_submit_urb(sc
->urb_int
, GFP_KERNEL
);
1382 uea_err(INS_TO_USBDEV(sc
),
1383 "urb submition failed with error %d\n", ret
);
1387 sc
->kthread
= kthread_run(uea_kthread
, sc
, "ueagle-atm");
1388 if (sc
->kthread
== ERR_PTR(-ENOMEM
)) {
1389 uea_err(INS_TO_USBDEV(sc
), "failed to create thread\n");
1393 uea_leaves(INS_TO_USBDEV(sc
));
1397 usb_kill_urb(sc
->urb_int
);
1399 usb_free_urb(sc
->urb_int
);
1402 uea_leaves(INS_TO_USBDEV(sc
));
1407 * Stop the modem : kill kernel thread and free data
1409 static void uea_stop(struct uea_softc
*sc
)
1412 uea_enters(INS_TO_USBDEV(sc
));
1413 ret
= kthread_stop(sc
->kthread
);
1414 uea_dbg(INS_TO_USBDEV(sc
), "kthread finish with status %d\n", ret
);
1416 /* stop any pending boot process */
1417 flush_scheduled_work();
1419 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_ON
, 0, NULL
);
1421 usb_kill_urb(sc
->urb_int
);
1422 kfree(sc
->urb_int
->transfer_buffer
);
1423 usb_free_urb(sc
->urb_int
);
1426 release_firmware(sc
->dsp_firm
);
1427 uea_leaves(INS_TO_USBDEV(sc
));
1430 /* syfs interface */
1431 static struct uea_softc
*dev_to_uea(struct device
*dev
)
1433 struct usb_interface
*intf
;
1434 struct usbatm_data
*usbatm
;
1436 intf
= to_usb_interface(dev
);
1440 usbatm
= usb_get_intfdata(intf
);
1444 return usbatm
->driver_data
;
1447 static ssize_t
read_status(struct device
*dev
, struct device_attribute
*attr
,
1451 struct uea_softc
*sc
;
1453 mutex_lock(&uea_mutex
);
1454 sc
= dev_to_uea(dev
);
1457 ret
= snprintf(buf
, 10, "%08x\n", sc
->stats
.phy
.state
);
1459 mutex_unlock(&uea_mutex
);
1463 static ssize_t
reboot(struct device
*dev
, struct device_attribute
*attr
,
1464 const char *buf
, size_t count
)
1467 struct uea_softc
*sc
;
1469 mutex_lock(&uea_mutex
);
1470 sc
= dev_to_uea(dev
);
1476 mutex_unlock(&uea_mutex
);
1480 static DEVICE_ATTR(stat_status
, S_IWUGO
| S_IRUGO
, read_status
, reboot
);
1482 static ssize_t
read_human_status(struct device
*dev
, struct device_attribute
*attr
,
1486 struct uea_softc
*sc
;
1488 mutex_lock(&uea_mutex
);
1489 sc
= dev_to_uea(dev
);
1493 switch (GET_STATUS(sc
->stats
.phy
.state
)) {
1495 ret
= sprintf(buf
, "Modem is booting\n");
1498 ret
= sprintf(buf
, "Modem is initializing\n");
1501 ret
= sprintf(buf
, "Modem is operational\n");
1504 ret
= sprintf(buf
, "Modem synchronization failed\n");
1508 mutex_unlock(&uea_mutex
);
1512 static DEVICE_ATTR(stat_human_status
, S_IWUGO
| S_IRUGO
, read_human_status
, NULL
);
1514 static ssize_t
read_delin(struct device
*dev
, struct device_attribute
*attr
,
1518 struct uea_softc
*sc
;
1520 mutex_lock(&uea_mutex
);
1521 sc
= dev_to_uea(dev
);
1525 if (sc
->stats
.phy
.flags
& 0x0C00)
1526 ret
= sprintf(buf
, "ERROR\n");
1527 else if (sc
->stats
.phy
.flags
& 0x0030)
1528 ret
= sprintf(buf
, "LOSS\n");
1530 ret
= sprintf(buf
, "GOOD\n");
1532 mutex_unlock(&uea_mutex
);
1536 static DEVICE_ATTR(stat_delin
, S_IWUGO
| S_IRUGO
, read_delin
, NULL
);
1538 #define UEA_ATTR(name, reset) \
1540 static ssize_t read_##name(struct device *dev, \
1541 struct device_attribute *attr, char *buf) \
1543 int ret = -ENODEV; \
1544 struct uea_softc *sc; \
1546 mutex_lock(&uea_mutex); \
1547 sc = dev_to_uea(dev); \
1550 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
1552 sc->stats.phy.name = 0; \
1554 mutex_unlock(&uea_mutex); \
1558 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
1560 UEA_ATTR(mflags
, 1);
1561 UEA_ATTR(vidcpe
, 0);
1562 UEA_ATTR(usrate
, 0);
1563 UEA_ATTR(dsrate
, 0);
1564 UEA_ATTR(usattenuation
, 0);
1565 UEA_ATTR(dsattenuation
, 0);
1566 UEA_ATTR(usmargin
, 0);
1567 UEA_ATTR(dsmargin
, 0);
1568 UEA_ATTR(txflow
, 0);
1569 UEA_ATTR(rxflow
, 0);
1570 UEA_ATTR(uscorr
, 0);
1571 UEA_ATTR(dscorr
, 0);
1574 UEA_ATTR(firmid
, 0);
1576 /* Retrieve the device End System Identifier (MAC) */
1578 #define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
1579 static int uea_getesi(struct uea_softc
*sc
, u_char
* esi
)
1581 unsigned char mac_str
[2 * ETH_ALEN
+ 1];
1584 (sc
->usb_dev
, sc
->usb_dev
->descriptor
.iSerialNumber
, mac_str
,
1585 sizeof(mac_str
)) != 2 * ETH_ALEN
)
1588 for (i
= 0; i
< ETH_ALEN
; i
++)
1589 esi
[i
] = htoi(mac_str
[2 * i
]) * 16 + htoi(mac_str
[2 * i
+ 1]);
1595 static int uea_atm_open(struct usbatm_data
*usbatm
, struct atm_dev
*atm_dev
)
1597 struct uea_softc
*sc
= usbatm
->driver_data
;
1599 return uea_getesi(sc
, atm_dev
->esi
);
1602 static int uea_heavy(struct usbatm_data
*usbatm
, struct usb_interface
*intf
)
1604 struct uea_softc
*sc
= usbatm
->driver_data
;
1606 wait_event_interruptible(sc
->sync_q
, IS_OPERATIONAL(sc
));
1612 static int claim_interface(struct usb_device
*usb_dev
,
1613 struct usbatm_data
*usbatm
, int ifnum
)
1616 struct usb_interface
*intf
= usb_ifnum_to_if(usb_dev
, ifnum
);
1619 uea_err(usb_dev
, "interface %d not found\n", ifnum
);
1623 ret
= usb_driver_claim_interface(&uea_driver
, intf
, usbatm
);
1625 uea_err(usb_dev
, "can't claim interface %d, error %d\n", ifnum
,
1630 static struct attribute
*attrs
[] = {
1631 &dev_attr_stat_status
.attr
,
1632 &dev_attr_stat_mflags
.attr
,
1633 &dev_attr_stat_human_status
.attr
,
1634 &dev_attr_stat_delin
.attr
,
1635 &dev_attr_stat_vidcpe
.attr
,
1636 &dev_attr_stat_usrate
.attr
,
1637 &dev_attr_stat_dsrate
.attr
,
1638 &dev_attr_stat_usattenuation
.attr
,
1639 &dev_attr_stat_dsattenuation
.attr
,
1640 &dev_attr_stat_usmargin
.attr
,
1641 &dev_attr_stat_dsmargin
.attr
,
1642 &dev_attr_stat_txflow
.attr
,
1643 &dev_attr_stat_rxflow
.attr
,
1644 &dev_attr_stat_uscorr
.attr
,
1645 &dev_attr_stat_dscorr
.attr
,
1646 &dev_attr_stat_usunc
.attr
,
1647 &dev_attr_stat_dsunc
.attr
,
1648 &dev_attr_stat_firmid
.attr
,
1651 static struct attribute_group attr_grp
= {
1655 static int uea_bind(struct usbatm_data
*usbatm
, struct usb_interface
*intf
,
1656 const struct usb_device_id
*id
)
1658 struct usb_device
*usb
= interface_to_usbdev(intf
);
1659 struct uea_softc
*sc
;
1660 int ret
, ifnum
= intf
->altsetting
->desc
.bInterfaceNumber
;
1664 /* interface 0 is for firmware/monitoring */
1665 if (ifnum
!= UEA_INTR_IFACE_NO
)
1668 usbatm
->flags
= (sync_wait
[modem_index
] ? 0 : UDSL_SKIP_HEAVY_INIT
);
1670 /* interface 1 is for outbound traffic */
1671 ret
= claim_interface(usb
, usbatm
, UEA_US_IFACE_NO
);
1675 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
1676 if (UEA_CHIP_VERSION(id
) != ADI930
) {
1677 /* interface 2 is for inbound traffic */
1678 ret
= claim_interface(usb
, usbatm
, UEA_DS_IFACE_NO
);
1683 sc
= kzalloc(sizeof(struct uea_softc
), GFP_KERNEL
);
1685 uea_err(usb
, "uea_init: not enough memory !\n");
1690 usbatm
->driver_data
= sc
;
1691 sc
->usbatm
= usbatm
;
1692 sc
->modem_index
= (modem_index
< NB_MODEM
) ? modem_index
++ : 0;
1693 sc
->driver_info
= id
->driver_info
;
1695 /* ADI930 don't support iso */
1696 if (UEA_CHIP_VERSION(id
) != ADI930
&& use_iso
[sc
->modem_index
]) {
1699 /* try set fastest alternate for inbound traffic interface */
1700 for (i
= FASTEST_ISO_INTF
; i
> 0; i
--)
1701 if (usb_set_interface(usb
, UEA_DS_IFACE_NO
, i
) == 0)
1705 uea_dbg(usb
, "set alternate %d for 2 interface\n", i
);
1706 uea_info(usb
, "using iso mode\n");
1707 usbatm
->flags
|= UDSL_USE_ISOC
| UDSL_IGNORE_EILSEQ
;
1709 uea_err(usb
, "setting any alternate failed for "
1710 "2 interface, using bulk mode\n");
1714 ret
= sysfs_create_group(&intf
->dev
.kobj
, &attr_grp
);
1728 static void uea_unbind(struct usbatm_data
*usbatm
, struct usb_interface
*intf
)
1730 struct uea_softc
*sc
= usbatm
->driver_data
;
1732 sysfs_remove_group(&intf
->dev
.kobj
, &attr_grp
);
1737 static struct usbatm_driver uea_usbatm_driver
= {
1738 .driver_name
= "ueagle-atm",
1740 .atm_start
= uea_atm_open
,
1741 .unbind
= uea_unbind
,
1742 .heavy_init
= uea_heavy
,
1743 .bulk_in
= UEA_BULK_DATA_PIPE
,
1744 .bulk_out
= UEA_BULK_DATA_PIPE
,
1745 .isoc_in
= UEA_ISO_DATA_PIPE
,
1748 static int uea_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1750 struct usb_device
*usb
= interface_to_usbdev(intf
);
1753 uea_info(usb
, "ADSL device founded vid (%#X) pid (%#X) : %s %s\n",
1754 le16_to_cpu(usb
->descriptor
.idVendor
),
1755 le16_to_cpu(usb
->descriptor
.idProduct
),
1756 chip_name
[UEA_CHIP_VERSION(id
)], IS_ISDN(usb
)?"isdn":"pots");
1758 usb_reset_device(usb
);
1760 if (UEA_IS_PREFIRM(id
))
1761 return uea_load_firmware(usb
, UEA_CHIP_VERSION(id
));
1763 return usbatm_usb_probe(intf
, id
, &uea_usbatm_driver
);
1766 static void uea_disconnect(struct usb_interface
*intf
)
1768 struct usb_device
*usb
= interface_to_usbdev(intf
);
1769 int ifnum
= intf
->altsetting
->desc
.bInterfaceNumber
;
1772 /* ADI930 has 2 interfaces and eagle 3 interfaces.
1773 * Pre-firmware device has one interface
1775 if (usb
->config
->desc
.bNumInterfaces
!= 1 && ifnum
== 0) {
1776 mutex_lock(&uea_mutex
);
1777 usbatm_usb_disconnect(intf
);
1778 mutex_unlock(&uea_mutex
);
1779 uea_info(usb
, "ADSL device removed\n");
1786 * List of supported VID/PID
1788 static const struct usb_device_id uea_ids
[] = {
1789 {USB_DEVICE(ELSA_VID
, ELSA_PID_PREFIRM
), .driver_info
= ADI930
| PREFIRM
},
1790 {USB_DEVICE(ELSA_VID
, ELSA_PID_PSTFIRM
), .driver_info
= ADI930
| PSTFIRM
},
1791 {USB_DEVICE(EAGLE_VID
, EAGLE_I_PID_PREFIRM
), .driver_info
= EAGLE_I
| PREFIRM
},
1792 {USB_DEVICE(EAGLE_VID
, EAGLE_I_PID_PSTFIRM
), .driver_info
= EAGLE_I
| PSTFIRM
},
1793 {USB_DEVICE(EAGLE_VID
, EAGLE_II_PID_PREFIRM
), .driver_info
= EAGLE_II
| PREFIRM
},
1794 {USB_DEVICE(EAGLE_VID
, EAGLE_II_PID_PSTFIRM
), .driver_info
= EAGLE_II
| PSTFIRM
},
1795 {USB_DEVICE(EAGLE_VID
, EAGLE_IIC_PID_PREFIRM
), .driver_info
= EAGLE_II
| PREFIRM
},
1796 {USB_DEVICE(EAGLE_VID
, EAGLE_IIC_PID_PSTFIRM
), .driver_info
= EAGLE_II
| PSTFIRM
},
1797 {USB_DEVICE(EAGLE_VID
, EAGLE_III_PID_PREFIRM
), .driver_info
= EAGLE_III
| PREFIRM
},
1798 {USB_DEVICE(EAGLE_VID
, EAGLE_III_PID_PSTFIRM
), .driver_info
= EAGLE_III
| PSTFIRM
},
1799 {USB_DEVICE(USR_VID
, MILLER_A_PID_PREFIRM
), .driver_info
= EAGLE_I
| PREFIRM
},
1800 {USB_DEVICE(USR_VID
, MILLER_A_PID_PSTFIRM
), .driver_info
= EAGLE_I
| PSTFIRM
},
1801 {USB_DEVICE(USR_VID
, MILLER_B_PID_PREFIRM
), .driver_info
= EAGLE_I
| PREFIRM
},
1802 {USB_DEVICE(USR_VID
, MILLER_B_PID_PSTFIRM
), .driver_info
= EAGLE_I
| PSTFIRM
},
1803 {USB_DEVICE(USR_VID
, HEINEKEN_A_PID_PREFIRM
),.driver_info
= EAGLE_I
| PREFIRM
},
1804 {USB_DEVICE(USR_VID
, HEINEKEN_A_PID_PSTFIRM
),.driver_info
= EAGLE_I
| PSTFIRM
},
1805 {USB_DEVICE(USR_VID
, HEINEKEN_B_PID_PREFIRM
),.driver_info
= EAGLE_I
| PREFIRM
},
1806 {USB_DEVICE(USR_VID
, HEINEKEN_B_PID_PSTFIRM
),.driver_info
= EAGLE_I
| PSTFIRM
},
1811 * USB driver descriptor
1813 static struct usb_driver uea_driver
= {
1814 .name
= "ueagle-atm",
1815 .id_table
= uea_ids
,
1817 .disconnect
= uea_disconnect
,
1820 MODULE_DEVICE_TABLE(usb
, uea_ids
);
1823 * uea_init - Initialize the module.
1824 * Register to USB subsystem
1826 static int __init
uea_init(void)
1828 printk(KERN_INFO
"[ueagle-atm] driver " EAGLEUSBVERSION
" loaded\n");
1830 usb_register(&uea_driver
);
1835 module_init(uea_init
);
1838 * uea_exit - Destroy module
1839 * Deregister with USB subsystem
1841 static void __exit
uea_exit(void)
1844 * This calls automatically the uea_disconnect method if necessary:
1846 usb_deregister(&uea_driver
);
1848 printk(KERN_INFO
"[ueagle-atm] driver unloaded\n");
1851 module_exit(uea_exit
);
1853 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
1854 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
1855 MODULE_LICENSE("Dual BSD/GPL");