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/sched.h>
65 #include <linux/kthread.h>
66 #include <linux/version.h>
67 #include <linux/mutex.h>
68 #include <linux/freezer.h>
70 #include <asm/unaligned.h>
74 #define EAGLEUSBVERSION "ueagle 1.4"
80 #define uea_dbg(usb_dev, format, args...) \
83 dev_dbg(&(usb_dev)->dev, \
84 "[ueagle-atm dbg] %s: " format, \
85 __FUNCTION__, ##args); \
88 #define uea_vdbg(usb_dev, format, args...) \
91 dev_dbg(&(usb_dev)->dev, \
92 "[ueagle-atm vdbg] " format, ##args); \
95 #define uea_enters(usb_dev) \
96 uea_vdbg(usb_dev, "entering %s\n", __FUNCTION__)
98 #define uea_leaves(usb_dev) \
99 uea_vdbg(usb_dev, "leaving %s\n", __FUNCTION__)
101 #define uea_err(usb_dev, format,args...) \
102 dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args)
104 #define uea_warn(usb_dev, format,args...) \
105 dev_warn(&(usb_dev)->dev ,"[Ueagle-atm] " format, ##args)
107 #define uea_info(usb_dev, format,args...) \
108 dev_info(&(usb_dev)->dev ,"[ueagle-atm] " format, ##args)
114 } __attribute__ ((packed
));
117 struct usb_device
*usb_dev
;
118 struct usbatm_data
*usbatm
;
121 unsigned int driver_info
;
126 wait_queue_head_t sync_q
;
128 struct task_struct
*kthread
;
130 wait_queue_head_t cmv_ack_wait
;
133 struct work_struct task
;
137 const struct firmware
*dsp_firm
;
145 /* keep in sync with eaglectl */
173 #define ELSA_VID 0x05CC
174 #define ELSA_PID_PSTFIRM 0x3350
175 #define ELSA_PID_PREFIRM 0x3351
180 #define EAGLE_VID 0x1110
181 #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
182 #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
184 #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
185 #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
187 #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
188 #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
193 #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
194 #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
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
210 #define PSTFIRM (1<<7)
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)
224 #define IS_ISDN(usb_dev) \
225 (le16_to_cpu((usb_dev)->descriptor.bcdDevice) & 0x80)
227 #define INS_TO_USBDEV(ins) ins->usb_dev
229 #define GET_STATUS(data) \
231 #define IS_OPERATIONAL(sc) \
232 (GET_STATUS(sc->stats.phy.state) == 2)
235 * Set of macros to handle unaligned data in the firmware blob.
236 * The FW_GET_BYTE() macro is provided only for consistency.
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)))
243 #define FW_DIR "ueagle-atm/"
246 #define BULK_TIMEOUT 300
247 #define CTRL_TIMEOUT 1000
249 #define ACK_TIMEOUT msecs_to_jiffies(3000)
251 #define UEA_INTR_IFACE_NO 0
252 #define UEA_US_IFACE_NO 1
253 #define UEA_DS_IFACE_NO 2
255 #define FASTEST_ISO_INTF 8
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
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
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
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)
278 /* structure describing a block within a DSP page */
281 #define UEA_BIHDR 0xabcd
285 __le16 wOvl
; /* overlay */
287 } __attribute__ ((packed
));
288 #define BLOCK_INFO_SIZE 12
290 /* structure representing a CMV (Configuration and Management Variable) */
293 #define PREAMBLE 0x535c
295 #define MODEMTOHOST 0x01
296 #define HOSTTOMODEM 0x10
298 #define FUNCTION_TYPE(f) ((f) >> 4)
299 #define MEMACCESS 0x1
300 #define ADSLDIRECTIVE 0x7
302 #define FUNCTION_SUBTYPE(f) ((f) & 0x0f)
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
312 #define MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
314 __le32 dwSymbolicAddress
;
315 #define MAKESA(a, b, c, d) \
316 (((c) & 0xff) << 24 | \
317 ((d) & 0xff) << 16 | \
318 ((a) & 0xff) << 8 | \
320 #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)
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
;
333 } __attribute__ ((packed
));
336 /* structure representing swap information */
339 __u8 bOvl
; /* overlay */
340 } __attribute__ ((packed
));
342 /* structure representing interrupt data */
350 #define INT_LOADSWAPPAGE 0x0001
351 #define INT_INCOMINGCMV 0x0002
354 struct swap_info swapinfo
;
356 } __attribute__ ((packed
)) s1
;
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
368 static struct usb_driver uea_driver
;
369 static DEFINE_MUTEX(uea_mutex
);
370 static const char *chip_name
[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III"};
372 static int modem_index
;
373 static unsigned int debug
;
374 static int use_iso
[NB_MODEM
] = {[0 ... (NB_MODEM
- 1)] = 1};
375 static int sync_wait
[NB_MODEM
];
376 static char *cmv_file
[NB_MODEM
];
378 module_param(debug
, uint
, 0644);
379 MODULE_PARM_DESC(debug
, "module debug level (0=off,1=on,2=verbose)");
380 module_param_array(use_iso
, bool, NULL
, 0644);
381 MODULE_PARM_DESC(use_iso
, "use isochronous usb pipe for incoming traffic");
382 module_param_array(sync_wait
, bool, NULL
, 0644);
383 MODULE_PARM_DESC(sync_wait
, "wait the synchronisation before starting ATM");
384 module_param_array(cmv_file
, charp
, NULL
, 0644);
385 MODULE_PARM_DESC(cmv_file
,
386 "file name with configuration and management variables");
388 #define UPDATE_ATM_STAT(type, val) \
390 if (sc->usbatm->atm_dev) \
391 sc->usbatm->atm_dev->type = val; \
394 /* Firmware loading */
395 #define LOAD_INTERNAL 0xA0
396 #define F8051_USBCS 0x7f92
399 * uea_send_modem_cmd - Send a command for pre-firmware devices.
401 static int uea_send_modem_cmd(struct usb_device
*usb
,
402 u16 addr
, u16 size
, u8
* buff
)
407 xfer_buff
= kmemdup(buff
, size
, GFP_KERNEL
);
409 ret
= usb_control_msg(usb
,
410 usb_sndctrlpipe(usb
, 0),
412 USB_DIR_OUT
| USB_TYPE_VENDOR
|
413 USB_RECIP_DEVICE
, addr
, 0, xfer_buff
,
421 return (ret
== size
) ? 0 : -EIO
;
424 static void uea_upload_pre_firmware(const struct firmware
*fw_entry
, void *context
)
426 struct usb_device
*usb
= context
;
433 uea_err(usb
, "firmware is not available\n");
437 pfw
= fw_entry
->data
;
438 size
= fw_entry
->size
;
440 goto err_fw_corrupted
;
442 crc
= FW_GET_LONG(pfw
);
445 if (crc32_be(0, pfw
, size
) != crc
)
446 goto err_fw_corrupted
;
449 * Start to upload formware : send reset
452 ret
= uea_send_modem_cmd(usb
, F8051_USBCS
, sizeof(value
), &value
);
455 uea_err(usb
, "modem reset failed with error %d\n", ret
);
460 u8 len
= FW_GET_BYTE(pfw
);
461 u16 add
= FW_GET_WORD(pfw
+ 1);
465 goto err_fw_corrupted
;
467 ret
= uea_send_modem_cmd(usb
, add
, len
, pfw
+ 3);
469 uea_err(usb
, "uploading firmware data failed "
470 "with error %d\n", ret
);
477 goto err_fw_corrupted
;
480 * Tell the modem we finish : de-assert reset
483 ret
= uea_send_modem_cmd(usb
, F8051_USBCS
, 1, &value
);
485 uea_err(usb
, "modem de-assert failed with error %d\n", ret
);
487 uea_info(usb
, "firmware uploaded\n");
493 uea_err(usb
, "firmware is corrupted\n");
499 * uea_load_firmware - Load usb firmware for pre-firmware devices.
501 static int uea_load_firmware(struct usb_device
*usb
, unsigned int ver
)
504 char *fw_name
= FW_DIR
"eagle.fw";
507 uea_info(usb
, "pre-firmware device, uploading firmware\n");
511 fw_name
= FW_DIR
"adi930.fw";
514 fw_name
= FW_DIR
"eagleI.fw";
517 fw_name
= FW_DIR
"eagleII.fw";
520 fw_name
= FW_DIR
"eagleIII.fw";
524 ret
= request_firmware_nowait(THIS_MODULE
, 1, fw_name
, &usb
->dev
, usb
, uea_upload_pre_firmware
);
526 uea_err(usb
, "firmware %s is not available\n", fw_name
);
528 uea_info(usb
, "loading firmware %s\n", fw_name
);
534 /* modem management : dsp firmware, send/read CMV, monitoring statistic
538 * Make sure that the DSP code provided is safe to use.
540 static int check_dsp(u8
*dsp
, unsigned int len
)
542 u8 pagecount
, blockcount
;
545 unsigned int i
, j
, p
, pp
;
547 pagecount
= FW_GET_BYTE(dsp
);
550 /* enough space for page offsets? */
551 if (p
+ 4 * pagecount
> len
)
554 for (i
= 0; i
< pagecount
; i
++) {
556 pageoffset
= FW_GET_LONG(dsp
+ p
);
562 /* enough space for blockcount? */
563 if (pageoffset
>= len
)
567 blockcount
= FW_GET_BYTE(dsp
+ pp
);
570 for (j
= 0; j
< blockcount
; j
++) {
572 /* enough space for block header? */
576 pp
+= 2; /* skip blockaddr */
577 blocksize
= FW_GET_WORD(dsp
+ pp
);
580 /* enough space for block data? */
581 if (pp
+ blocksize
> len
)
592 * send data to the idma pipe
594 static int uea_idma_write(struct uea_softc
*sc
, void *data
, u32 size
)
600 xfer_buff
= kmemdup(data
, size
, GFP_KERNEL
);
602 uea_err(INS_TO_USBDEV(sc
), "can't allocate xfer_buff\n");
606 ret
= usb_bulk_msg(sc
->usb_dev
,
607 usb_sndbulkpipe(sc
->usb_dev
, UEA_IDMA_PIPE
),
608 xfer_buff
, size
, &bytes_read
, BULK_TIMEOUT
);
613 if (size
!= bytes_read
) {
614 uea_err(INS_TO_USBDEV(sc
), "size != bytes_read %d %d\n", size
,
622 static int request_dsp(struct uea_softc
*sc
)
627 if (UEA_CHIP_VERSION(sc
) == ADI930
) {
628 if (IS_ISDN(sc
->usb_dev
))
629 dsp_name
= FW_DIR
"DSP9i.bin";
631 dsp_name
= FW_DIR
"DSP9p.bin";
633 if (IS_ISDN(sc
->usb_dev
))
634 dsp_name
= FW_DIR
"DSPei.bin";
636 dsp_name
= FW_DIR
"DSPep.bin";
639 ret
= request_firmware(&sc
->dsp_firm
, dsp_name
, &sc
->usb_dev
->dev
);
641 uea_err(INS_TO_USBDEV(sc
),
642 "requesting firmware %s failed with error %d\n",
647 if (check_dsp(sc
->dsp_firm
->data
, sc
->dsp_firm
->size
)) {
648 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n",
650 release_firmware(sc
->dsp_firm
);
659 * The uea_load_page() function must be called within a process context
661 static void uea_load_page(struct work_struct
*work
)
663 struct uea_softc
*sc
= container_of(work
, struct uea_softc
, task
);
664 u16 pageno
= sc
->pageno
;
666 struct block_info bi
;
669 u8 pagecount
, blockcount
;
670 u16 blockaddr
, blocksize
;
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
);
680 if (sc
->dsp_firm
== NULL
&& request_dsp(sc
) < 0)
683 p
= sc
->dsp_firm
->data
;
684 pagecount
= FW_GET_BYTE(p
);
687 if (pageno
>= pagecount
)
691 pageoffset
= FW_GET_LONG(p
);
696 p
= sc
->dsp_firm
->data
+ pageoffset
;
697 blockcount
= FW_GET_BYTE(p
);
700 uea_dbg(INS_TO_USBDEV(sc
),
701 "sending %u blocks for DSP page %u\n", blockcount
, pageno
);
703 bi
.wHdr
= cpu_to_le16(UEA_BIHDR
);
704 bi
.wOvl
= cpu_to_le16(ovl
);
705 bi
.wOvlOffset
= cpu_to_le16(ovl
| 0x8000);
707 for (i
= 0; i
< blockcount
; i
++) {
708 blockaddr
= FW_GET_WORD(p
);
711 blocksize
= FW_GET_WORD(p
);
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);
718 /* send block info through the IDMA pipe */
719 if (uea_idma_write(sc
, &bi
, BLOCK_INFO_SIZE
))
722 /* send block data through the IDMA pipe */
723 if (uea_idma_write(sc
, p
, blocksize
))
732 uea_err(INS_TO_USBDEV(sc
), "sending DSP block %u failed\n", i
);
735 uea_err(INS_TO_USBDEV(sc
), "invalid DSP page %u requested\n", pageno
);
738 static inline void wake_up_cmv_ack(struct uea_softc
*sc
)
742 wake_up(&sc
->cmv_ack_wait
);
745 static inline int wait_cmv_ack(struct uea_softc
*sc
)
747 int ret
= wait_event_interruptible_timeout(sc
->cmv_ack_wait
,
748 sc
->cmv_ack
, ACK_TIMEOUT
);
751 uea_dbg(INS_TO_USBDEV(sc
), "wait_event_timeout : %d ms\n",
752 jiffies_to_msecs(ret
));
757 return (ret
== 0) ? -ETIMEDOUT
: 0;
760 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
762 static int uea_request(struct uea_softc
*sc
,
763 u16 value
, u16 index
, u16 size
, void *data
)
768 xfer_buff
= kmemdup(data
, size
, GFP_KERNEL
);
770 uea_err(INS_TO_USBDEV(sc
), "can't allocate xfer_buff\n");
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
);
781 uea_err(INS_TO_USBDEV(sc
), "usb_control_msg error %d\n", ret
);
786 uea_err(INS_TO_USBDEV(sc
),
787 "usb_control_msg send only %d bytes (instead of %d)\n",
795 static int uea_cmv(struct uea_softc
*sc
,
796 u8 function
, u32 address
, u16 offset
, u32 data
)
801 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
);
807 /* we send a request, but we expect a reply */
808 sc
->cmv_function
= function
| 0x2;
810 sc
->cmv_address
= address
;
811 sc
->cmv_offset
= offset
;
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
);
821 ret
= uea_request(sc
, UEA_SET_BLOCK
, UEA_MPTX_START
, CMV_SIZE
, &cmv
);
824 ret
= wait_cmv_ack(sc
);
825 uea_leaves(INS_TO_USBDEV(sc
));
829 static inline int uea_read_cmv(struct uea_softc
*sc
,
830 u32 address
, u16 offset
, u32
*data
)
832 int ret
= uea_cmv(sc
, MAKEFUNCTION(MEMACCESS
, REQUESTREAD
),
835 uea_err(INS_TO_USBDEV(sc
),
836 "reading cmv failed with error %d\n", ret
);
843 static inline int uea_write_cmv(struct uea_softc
*sc
,
844 u32 address
, u16 offset
, u32 data
)
846 int ret
= uea_cmv(sc
, MAKEFUNCTION(MEMACCESS
, REQUESTWRITE
),
847 address
, offset
, data
);
849 uea_err(INS_TO_USBDEV(sc
),
850 "writing cmv failed with error %d\n", ret
);
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)
860 static int uea_stat(struct uea_softc
*sc
)
865 uea_enters(INS_TO_USBDEV(sc
));
866 data
= sc
->stats
.phy
.state
;
868 ret
= uea_read_cmv(sc
, SA_STAT
, 0, &sc
->stats
.phy
.state
);
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");
878 case 1: /* initialization */
879 uea_dbg(INS_TO_USBDEV(sc
), "modem initializing\n");
882 case 2: /* operational */
883 uea_vdbg(INS_TO_USBDEV(sc
), "modem operational\n");
886 case 3: /* fail ... */
887 uea_info(INS_TO_USBDEV(sc
), "modem synchronization failed"
888 " (may be try other cmv/dsp)\n");
891 case 4 ... 6: /* test state */
892 uea_warn(INS_TO_USBDEV(sc
),
893 "modem in test mode - not supported\n");
896 case 7: /* fast-retain ... */
897 uea_info(INS_TO_USBDEV(sc
), "modem in fast-retain mode\n");
900 uea_err(INS_TO_USBDEV(sc
), "modem invalid SW mode %d\n",
901 GET_STATUS(sc
->stats
.phy
.state
));
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");
909 /* release the dsp firmware as it is not needed until
913 release_firmware(sc
->dsp_firm
);
918 /* always update it as atm layer could not be init when we switch to
921 UPDATE_ATM_STAT(signal
, ATM_PHY_SIG_FOUND
);
923 /* wake up processes waiting for synchronization */
924 wake_up(&sc
->sync_q
);
926 ret
= uea_read_cmv(sc
, SA_DIAG
, 2, &sc
->stats
.phy
.flags
);
929 sc
->stats
.phy
.mflags
|= sc
->stats
.phy
.flags
;
931 /* in case of a flags ( for example delineation LOSS (& 0x10)),
932 * we check the status again in order to detect the failure earlier
934 if (sc
->stats
.phy
.flags
) {
935 uea_dbg(INS_TO_USBDEV(sc
), "Stat flag = 0x%x\n",
936 sc
->stats
.phy
.flags
);
940 ret
= uea_read_cmv(sc
, SA_RATE
, 0, &data
);
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).
949 if (UEA_CHIP_VERSION(sc
) != ADI930
950 && !use_iso
[sc
->modem_index
]
951 && sc
->stats
.phy
.dsrate
!= (data
>> 16) * 32) {
952 /* Original timming from ADI(used in windows driver)
953 * 0x20ffff>>16 * 32 = 32 * 32 = 1Mbits
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":"");
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);
965 ret
= uea_read_cmv(sc
, SA_DIAG
, 23, &data
);
968 sc
->stats
.phy
.dsattenuation
= (data
& 0xff) / 2;
970 ret
= uea_read_cmv(sc
, SA_DIAG
, 47, &data
);
973 sc
->stats
.phy
.usattenuation
= (data
& 0xff) / 2;
975 ret
= uea_read_cmv(sc
, SA_DIAG
, 25, &sc
->stats
.phy
.dsmargin
);
979 ret
= uea_read_cmv(sc
, SA_DIAG
, 49, &sc
->stats
.phy
.usmargin
);
983 ret
= uea_read_cmv(sc
, SA_DIAG
, 51, &sc
->stats
.phy
.rxflow
);
987 ret
= uea_read_cmv(sc
, SA_DIAG
, 52, &sc
->stats
.phy
.txflow
);
991 ret
= uea_read_cmv(sc
, SA_DIAG
, 54, &sc
->stats
.phy
.dsunc
);
996 ret
= uea_read_cmv(sc
, SA_DIAG
, 58, &sc
->stats
.phy
.usunc
);
1000 ret
= uea_read_cmv(sc
, SA_DIAG
, 53, &sc
->stats
.phy
.dscorr
);
1004 /* only for atu-c */
1005 ret
= uea_read_cmv(sc
, SA_DIAG
, 57, &sc
->stats
.phy
.uscorr
);
1009 ret
= uea_read_cmv(sc
, SA_INFO
, 8, &sc
->stats
.phy
.vidco
);
1013 ret
= uea_read_cmv(sc
, SA_INFO
, 13, &sc
->stats
.phy
.vidcpe
);
1020 static int request_cmvs(struct uea_softc
*sc
,
1021 struct uea_cmvs
**cmvs
, const struct firmware
**fw
)
1026 char cmv_name
[FIRMWARE_NAME_MAX
]; /* 30 bytes stack variable */
1028 if (cmv_file
[sc
->modem_index
] == NULL
) {
1029 if (UEA_CHIP_VERSION(sc
) == ADI930
)
1030 file
= (IS_ISDN(sc
->usb_dev
)) ? "CMV9i.bin" : "CMV9p.bin";
1032 file
= (IS_ISDN(sc
->usb_dev
)) ? "CMVei.bin" : "CMVep.bin";
1034 file
= cmv_file
[sc
->modem_index
];
1036 strcpy(cmv_name
, FW_DIR
);
1037 strlcat(cmv_name
, file
, sizeof(cmv_name
));
1039 ret
= request_firmware(fw
, cmv_name
, &sc
->usb_dev
->dev
);
1041 uea_err(INS_TO_USBDEV(sc
),
1042 "requesting firmware %s failed with error %d\n",
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",
1052 release_firmware(*fw
);
1056 *cmvs
= (struct uea_cmvs
*)(data
+ 1);
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
1066 static int uea_start_reset(struct uea_softc
*sc
)
1068 u16 zero
= 0; /* ;-) */
1070 struct uea_cmvs
*cmvs
;
1071 const struct firmware
*cmvs_fw
;
1073 uea_enters(INS_TO_USBDEV(sc
));
1074 uea_info(INS_TO_USBDEV(sc
), "(re)booting started\n");
1076 /* mask interrupt */
1078 /* 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.
1083 UPDATE_ATM_STAT(signal
, ATM_PHY_SIG_LOST
);
1085 /* reset statistics */
1086 memset(&sc
->stats
, 0, sizeof(struct uea_stats
));
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
);
1092 /* enter reset mode */
1093 uea_request(sc
, UEA_SET_MODE
, UEA_START_RESET
, 0, NULL
);
1095 /* original driver use 200ms, but windows driver use 100ms */
1098 /* leave reset mode */
1099 uea_request(sc
, UEA_SET_MODE
, UEA_END_RESET
, 0, NULL
);
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
);
1107 sc
->cmv_function
= MAKEFUNCTION(ADSLDIRECTIVE
, MODEMREADY
);
1108 /* demask interrupt */
1111 /* start loading DSP */
1114 schedule_work(&sc
->task
);
1116 /* wait for modem ready CMV */
1117 ret
= wait_cmv_ack(sc
);
1121 uea_vdbg(INS_TO_USBDEV(sc
), "Ready CMV received\n");
1123 /* Enter in R-IDLE (cmv) until instructed otherwise */
1124 ret
= uea_write_cmv(sc
, SA_CNTL
, 0, 1);
1128 /* Dump firmware version */
1129 ret
= uea_read_cmv(sc
, SA_INFO
, 10, &sc
->stats
.phy
.firmid
);
1132 uea_info(INS_TO_USBDEV(sc
), "ATU-R firmware version : %x\n",
1133 sc
->stats
.phy
.firmid
);
1136 ret
= len
= request_cmvs(sc
, &cmvs
, &cmvs_fw
);
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
));
1148 /* Enter in R-ACT-REQ */
1149 ret
= uea_write_cmv(sc
, SA_CNTL
, 0, 2);
1150 uea_vdbg(INS_TO_USBDEV(sc
), "Entering in R-ACT-REQ state\n");
1151 uea_info(INS_TO_USBDEV(sc
), "Modem started, "
1152 "waiting synchronization\n");
1154 release_firmware(cmvs_fw
);
1156 uea_leaves(INS_TO_USBDEV(sc
));
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.
1166 static int uea_kthread(void *data
)
1168 struct uea_softc
*sc
= data
;
1171 uea_enters(INS_TO_USBDEV(sc
));
1172 while (!kthread_should_stop()) {
1173 if (ret
< 0 || sc
->reset
)
1174 ret
= uea_start_reset(sc
);
1178 msleep_interruptible(1000);
1179 if (try_to_freeze())
1180 uea_err(INS_TO_USBDEV(sc
), "suspend/resume not supported, "
1181 "please unplug/replug your modem\n");
1183 uea_leaves(INS_TO_USBDEV(sc
));
1187 /* Load second usb firmware for ADI930 chip */
1188 static int load_XILINX_firmware(struct uea_softc
*sc
)
1190 const struct firmware
*fw_entry
;
1191 int ret
, size
, u
, ln
;
1193 char *fw_name
= FW_DIR
"930-fpga.bin";
1195 uea_enters(INS_TO_USBDEV(sc
));
1197 ret
= request_firmware(&fw_entry
, fw_name
, &sc
->usb_dev
->dev
);
1199 uea_err(INS_TO_USBDEV(sc
), "firmware %s is not available\n",
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",
1212 for (u
= 0; u
< size
; u
+= ln
) {
1213 ln
= min(size
- u
, 64);
1214 ret
= uea_request(sc
, 0xe, 0, ln
, pfw
+ u
);
1216 uea_err(INS_TO_USBDEV(sc
),
1217 "elsa download data failed (%d)\n", ret
);
1222 /* finish to send the fpga */
1223 ret
= uea_request(sc
, 0xe, 1, 0, NULL
);
1225 uea_err(INS_TO_USBDEV(sc
),
1226 "elsa download data failed (%d)\n", ret
);
1230 /* Tell the modem we finish : de-assert reset */
1232 ret
= uea_send_modem_cmd(sc
->usb_dev
, 0xe, 1, &value
);
1234 uea_err(sc
->usb_dev
, "elsa de-assert failed with error %d\n", ret
);
1238 release_firmware(fw_entry
);
1240 uea_leaves(INS_TO_USBDEV(sc
));
1244 /* The modem send us an ack. First with check if it right */
1245 static void uea_dispatch_cmv(struct uea_softc
*sc
, struct cmv
* cmv
)
1247 uea_enters(INS_TO_USBDEV(sc
));
1248 if (le16_to_cpu(cmv
->wPreamble
) != PREAMBLE
)
1251 if (cmv
->bDirection
!= MODEMTOHOST
)
1254 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1255 * the first MEMACESS cmv. Ignore it...
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
);
1268 if (cmv
->bFunction
== MAKEFUNCTION(ADSLDIRECTIVE
, MODEMREADY
)) {
1269 wake_up_cmv_ack(sc
);
1270 uea_leaves(INS_TO_USBDEV(sc
));
1274 /* in case of MEMACCESS */
1275 if (le16_to_cpu(cmv
->wIndex
) != sc
->cmv_idx
||
1276 le32_to_cpu(get_unaligned(&cmv
->dwSymbolicAddress
)) !=
1278 || le16_to_cpu(cmv
->wOffsetAddress
) != sc
->cmv_offset
)
1281 sc
->data
= le32_to_cpu(get_unaligned(&cmv
->dwData
));
1282 sc
->data
= sc
->data
<< 16 | sc
->data
>> 16;
1284 wake_up_cmv_ack(sc
);
1285 uea_leaves(INS_TO_USBDEV(sc
));
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
));
1293 uea_leaves(INS_TO_USBDEV(sc
));
1297 uea_err(INS_TO_USBDEV(sc
), "invalid cmv received, "
1298 "wPreamble %d, bDirection %d\n",
1299 le16_to_cpu(cmv
->wPreamble
), cmv
->bDirection
);
1300 uea_leaves(INS_TO_USBDEV(sc
));
1306 static void uea_intr(struct urb
*urb
)
1308 struct uea_softc
*sc
= urb
->context
;
1309 struct intr_pkt
*intr
= urb
->transfer_buffer
;
1310 uea_enters(INS_TO_USBDEV(sc
));
1312 if (unlikely(urb
->status
< 0)) {
1313 uea_err(INS_TO_USBDEV(sc
), "uea_intr() failed with %d\n",
1318 /* device-to-host interrupt */
1319 if (intr
->bType
!= 0x08 || sc
->booting
) {
1320 uea_err(INS_TO_USBDEV(sc
), "wrong interrupt\n");
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
);
1331 case INT_INCOMINGCMV
:
1332 uea_dispatch_cmv(sc
, &intr
->u
.s2
.cmv
);
1336 uea_err(INS_TO_USBDEV(sc
), "unknown interrupt %u\n",
1337 le16_to_cpu(intr
->wInterrupt
));
1341 usb_submit_urb(sc
->urb_int
, GFP_ATOMIC
);
1345 * Start the modem : init the data and start kernel thread
1347 static int uea_boot(struct uea_softc
*sc
)
1350 struct intr_pkt
*intr
;
1352 uea_enters(INS_TO_USBDEV(sc
));
1354 INIT_WORK(&sc
->task
, uea_load_page
);
1355 init_waitqueue_head(&sc
->sync_q
);
1356 init_waitqueue_head(&sc
->cmv_ack_wait
);
1358 if (UEA_CHIP_VERSION(sc
) == ADI930
)
1359 load_XILINX_firmware(sc
);
1361 intr
= kmalloc(INTR_PKT_SIZE
, GFP_KERNEL
);
1363 uea_err(INS_TO_USBDEV(sc
),
1364 "cannot allocate interrupt package\n");
1365 uea_leaves(INS_TO_USBDEV(sc
));
1369 sc
->urb_int
= usb_alloc_urb(0, GFP_KERNEL
);
1371 uea_err(INS_TO_USBDEV(sc
), "cannot allocate interrupt URB\n");
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
);
1381 ret
= usb_submit_urb(sc
->urb_int
, GFP_KERNEL
);
1383 uea_err(INS_TO_USBDEV(sc
),
1384 "urb submition failed with error %d\n", ret
);
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");
1394 uea_leaves(INS_TO_USBDEV(sc
));
1398 usb_kill_urb(sc
->urb_int
);
1400 usb_free_urb(sc
->urb_int
);
1403 uea_leaves(INS_TO_USBDEV(sc
));
1408 * Stop the modem : kill kernel thread and free data
1410 static void uea_stop(struct uea_softc
*sc
)
1413 uea_enters(INS_TO_USBDEV(sc
));
1414 ret
= kthread_stop(sc
->kthread
);
1415 uea_dbg(INS_TO_USBDEV(sc
), "kthread finish with status %d\n", ret
);
1417 /* stop any pending boot process */
1418 flush_scheduled_work();
1420 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_ON
, 0, NULL
);
1422 usb_kill_urb(sc
->urb_int
);
1423 kfree(sc
->urb_int
->transfer_buffer
);
1424 usb_free_urb(sc
->urb_int
);
1427 release_firmware(sc
->dsp_firm
);
1428 uea_leaves(INS_TO_USBDEV(sc
));
1431 /* syfs interface */
1432 static struct uea_softc
*dev_to_uea(struct device
*dev
)
1434 struct usb_interface
*intf
;
1435 struct usbatm_data
*usbatm
;
1437 intf
= to_usb_interface(dev
);
1441 usbatm
= usb_get_intfdata(intf
);
1445 return usbatm
->driver_data
;
1448 static ssize_t
read_status(struct device
*dev
, struct device_attribute
*attr
,
1452 struct uea_softc
*sc
;
1454 mutex_lock(&uea_mutex
);
1455 sc
= dev_to_uea(dev
);
1458 ret
= snprintf(buf
, 10, "%08x\n", sc
->stats
.phy
.state
);
1460 mutex_unlock(&uea_mutex
);
1464 static ssize_t
reboot(struct device
*dev
, struct device_attribute
*attr
,
1465 const char *buf
, size_t count
)
1468 struct uea_softc
*sc
;
1470 mutex_lock(&uea_mutex
);
1471 sc
= dev_to_uea(dev
);
1477 mutex_unlock(&uea_mutex
);
1481 static DEVICE_ATTR(stat_status
, S_IWUGO
| S_IRUGO
, read_status
, reboot
);
1483 static ssize_t
read_human_status(struct device
*dev
, struct device_attribute
*attr
,
1487 struct uea_softc
*sc
;
1489 mutex_lock(&uea_mutex
);
1490 sc
= dev_to_uea(dev
);
1494 switch (GET_STATUS(sc
->stats
.phy
.state
)) {
1496 ret
= sprintf(buf
, "Modem is booting\n");
1499 ret
= sprintf(buf
, "Modem is initializing\n");
1502 ret
= sprintf(buf
, "Modem is operational\n");
1505 ret
= sprintf(buf
, "Modem synchronization failed\n");
1509 mutex_unlock(&uea_mutex
);
1513 static DEVICE_ATTR(stat_human_status
, S_IWUGO
| S_IRUGO
, read_human_status
, NULL
);
1515 static ssize_t
read_delin(struct device
*dev
, struct device_attribute
*attr
,
1519 struct uea_softc
*sc
;
1521 mutex_lock(&uea_mutex
);
1522 sc
= dev_to_uea(dev
);
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");
1531 ret
= sprintf(buf
, "GOOD\n");
1533 mutex_unlock(&uea_mutex
);
1537 static DEVICE_ATTR(stat_delin
, S_IWUGO
| S_IRUGO
, read_delin
, NULL
);
1539 #define UEA_ATTR(name, reset) \
1541 static ssize_t read_##name(struct device *dev, \
1542 struct device_attribute *attr, char *buf) \
1544 int ret = -ENODEV; \
1545 struct uea_softc *sc; \
1547 mutex_lock(&uea_mutex); \
1548 sc = dev_to_uea(dev); \
1551 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
1553 sc->stats.phy.name = 0; \
1555 mutex_unlock(&uea_mutex); \
1559 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
1561 UEA_ATTR(mflags
, 1);
1562 UEA_ATTR(vidcpe
, 0);
1563 UEA_ATTR(usrate
, 0);
1564 UEA_ATTR(dsrate
, 0);
1565 UEA_ATTR(usattenuation
, 0);
1566 UEA_ATTR(dsattenuation
, 0);
1567 UEA_ATTR(usmargin
, 0);
1568 UEA_ATTR(dsmargin
, 0);
1569 UEA_ATTR(txflow
, 0);
1570 UEA_ATTR(rxflow
, 0);
1571 UEA_ATTR(uscorr
, 0);
1572 UEA_ATTR(dscorr
, 0);
1575 UEA_ATTR(firmid
, 0);
1577 /* Retrieve the device End System Identifier (MAC) */
1579 #define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
1580 static int uea_getesi(struct uea_softc
*sc
, u_char
* esi
)
1582 unsigned char mac_str
[2 * ETH_ALEN
+ 1];
1585 (sc
->usb_dev
, sc
->usb_dev
->descriptor
.iSerialNumber
, mac_str
,
1586 sizeof(mac_str
)) != 2 * ETH_ALEN
)
1589 for (i
= 0; i
< ETH_ALEN
; i
++)
1590 esi
[i
] = htoi(mac_str
[2 * i
]) * 16 + htoi(mac_str
[2 * i
+ 1]);
1596 static int uea_atm_open(struct usbatm_data
*usbatm
, struct atm_dev
*atm_dev
)
1598 struct uea_softc
*sc
= usbatm
->driver_data
;
1600 return uea_getesi(sc
, atm_dev
->esi
);
1603 static int uea_heavy(struct usbatm_data
*usbatm
, struct usb_interface
*intf
)
1605 struct uea_softc
*sc
= usbatm
->driver_data
;
1607 wait_event_interruptible(sc
->sync_q
, IS_OPERATIONAL(sc
));
1613 static int claim_interface(struct usb_device
*usb_dev
,
1614 struct usbatm_data
*usbatm
, int ifnum
)
1617 struct usb_interface
*intf
= usb_ifnum_to_if(usb_dev
, ifnum
);
1620 uea_err(usb_dev
, "interface %d not found\n", ifnum
);
1624 ret
= usb_driver_claim_interface(&uea_driver
, intf
, usbatm
);
1626 uea_err(usb_dev
, "can't claim interface %d, error %d\n", ifnum
,
1631 static 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
,
1649 &dev_attr_stat_firmid
.attr
,
1652 static struct attribute_group attr_grp
= {
1656 static int uea_bind(struct usbatm_data
*usbatm
, struct usb_interface
*intf
,
1657 const struct usb_device_id
*id
)
1659 struct usb_device
*usb
= interface_to_usbdev(intf
);
1660 struct uea_softc
*sc
;
1661 int ret
, ifnum
= intf
->altsetting
->desc
.bInterfaceNumber
;
1665 /* interface 0 is for firmware/monitoring */
1666 if (ifnum
!= UEA_INTR_IFACE_NO
)
1669 usbatm
->flags
= (sync_wait
[modem_index
] ? 0 : UDSL_SKIP_HEAVY_INIT
);
1671 /* interface 1 is for outbound traffic */
1672 ret
= claim_interface(usb
, usbatm
, UEA_US_IFACE_NO
);
1676 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
1677 if (UEA_CHIP_VERSION(id
) != ADI930
) {
1678 /* interface 2 is for inbound traffic */
1679 ret
= claim_interface(usb
, usbatm
, UEA_DS_IFACE_NO
);
1684 sc
= kzalloc(sizeof(struct uea_softc
), GFP_KERNEL
);
1686 uea_err(usb
, "uea_init: not enough memory !\n");
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
;
1696 /* ADI930 don't support iso */
1697 if (UEA_CHIP_VERSION(id
) != ADI930
&& use_iso
[sc
->modem_index
]) {
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)
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
;
1710 uea_err(usb
, "setting any alternate failed for "
1711 "2 interface, using bulk mode\n");
1715 ret
= sysfs_create_group(&intf
->dev
.kobj
, &attr_grp
);
1729 static void uea_unbind(struct usbatm_data
*usbatm
, struct usb_interface
*intf
)
1731 struct uea_softc
*sc
= usbatm
->driver_data
;
1733 sysfs_remove_group(&intf
->dev
.kobj
, &attr_grp
);
1738 static struct usbatm_driver uea_usbatm_driver
= {
1739 .driver_name
= "ueagle-atm",
1741 .atm_start
= uea_atm_open
,
1742 .unbind
= uea_unbind
,
1743 .heavy_init
= uea_heavy
,
1744 .bulk_in
= UEA_BULK_DATA_PIPE
,
1745 .bulk_out
= UEA_BULK_DATA_PIPE
,
1746 .isoc_in
= UEA_ISO_DATA_PIPE
,
1749 static int uea_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1751 struct usb_device
*usb
= interface_to_usbdev(intf
);
1754 uea_info(usb
, "ADSL device founded vid (%#X) pid (%#X) : %s %s\n",
1755 le16_to_cpu(usb
->descriptor
.idVendor
),
1756 le16_to_cpu(usb
->descriptor
.idProduct
),
1757 chip_name
[UEA_CHIP_VERSION(id
)], IS_ISDN(usb
)?"isdn":"pots");
1759 usb_reset_device(usb
);
1761 if (UEA_IS_PREFIRM(id
))
1762 return uea_load_firmware(usb
, UEA_CHIP_VERSION(id
));
1764 return usbatm_usb_probe(intf
, id
, &uea_usbatm_driver
);
1767 static void uea_disconnect(struct usb_interface
*intf
)
1769 struct usb_device
*usb
= interface_to_usbdev(intf
);
1770 int ifnum
= intf
->altsetting
->desc
.bInterfaceNumber
;
1773 /* ADI930 has 2 interfaces and eagle 3 interfaces.
1774 * Pre-firmware device has one interface
1776 if (usb
->config
->desc
.bNumInterfaces
!= 1 && ifnum
== 0) {
1777 mutex_lock(&uea_mutex
);
1778 usbatm_usb_disconnect(intf
);
1779 mutex_unlock(&uea_mutex
);
1780 uea_info(usb
, "ADSL device removed\n");
1787 * List of supported VID/PID
1789 static 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
},
1812 * USB driver descriptor
1814 static struct usb_driver uea_driver
= {
1815 .name
= "ueagle-atm",
1816 .id_table
= uea_ids
,
1818 .disconnect
= uea_disconnect
,
1821 MODULE_DEVICE_TABLE(usb
, uea_ids
);
1824 * uea_init - Initialize the module.
1825 * Register to USB subsystem
1827 static int __init
uea_init(void)
1829 printk(KERN_INFO
"[ueagle-atm] driver " EAGLEUSBVERSION
" loaded\n");
1831 usb_register(&uea_driver
);
1836 module_init(uea_init
);
1839 * uea_exit - Destroy module
1840 * Deregister with USB subsystem
1842 static void __exit
uea_exit(void)
1845 * This calls automatically the uea_disconnect method if necessary:
1847 usb_deregister(&uea_driver
);
1849 printk(KERN_INFO
"[ueagle-atm] driver unloaded\n");
1852 module_exit(uea_exit
);
1854 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
1855 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
1856 MODULE_LICENSE("Dual BSD/GPL");