2 * Copyright (c) 2003, 2004
3 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
5 * Copyright (c) 2005-2007 Matthieu Castet <castet.matthieu@free.fr>
6 * Copyright (c) 2005-2007 Stanislaw Gruszka <stf_xl@wp.pl>
8 * This software is available to you under a choice of one of two
9 * licenses. You may choose to be licensed under the terms of the GNU
10 * General Public License (GPL) Version 2, available from the file
11 * COPYING in the main directory of this source tree, or the
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice unmodified, this list of conditions, and the following
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * This program is free software; you can redistribute it and/or
38 * modify it under the terms of the GNU General Public License
39 * as published by the Free Software Foundation; either version 2
40 * of the License, or (at your option) any later version.
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
47 * You should have received a copy of the GNU General Public License
48 * along with this program; if not, write to the Free Software
49 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
52 * HISTORY : some part of the code was base on ueagle 1.3 BSD driver,
53 * Damien Bergamini agree to put his code under a DUAL GPL/BSD license.
55 * The rest of the code was was rewritten from scratch.
58 #include <linux/module.h>
59 #include <linux/moduleparam.h>
60 #include <linux/init.h>
61 #include <linux/crc32.h>
62 #include <linux/usb.h>
63 #include <linux/firmware.h>
64 #include <linux/ctype.h>
65 #include <linux/sched.h>
66 #include <linux/kthread.h>
67 #include <linux/mutex.h>
68 #include <linux/freezer.h>
69 #include <linux/slab.h>
71 #include <asm/unaligned.h>
75 #define EAGLEUSBVERSION "ueagle 1.4"
81 #define uea_dbg(usb_dev, format, args...) \
84 dev_dbg(&(usb_dev)->dev, \
85 "[ueagle-atm dbg] %s: " format, \
89 #define uea_vdbg(usb_dev, format, args...) \
92 dev_dbg(&(usb_dev)->dev, \
93 "[ueagle-atm vdbg] " format, ##args); \
96 #define uea_enters(usb_dev) \
97 uea_vdbg(usb_dev, "entering %s\n", __func__)
99 #define uea_leaves(usb_dev) \
100 uea_vdbg(usb_dev, "leaving %s\n", __func__)
102 #define uea_err(usb_dev, format,args...) \
103 dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args)
105 #define uea_warn(usb_dev, format,args...) \
106 dev_warn(&(usb_dev)->dev ,"[Ueagle-atm] " format, ##args)
108 #define uea_info(usb_dev, format,args...) \
109 dev_info(&(usb_dev)->dev ,"[ueagle-atm] " format, ##args)
113 /* cmv's from firmware */
118 } __attribute__ ((packed
));
125 } __attribute__ ((packed
));
127 /* information about currently processed cmv */
143 struct cmv_dsc_e1 e1
;
144 struct cmv_dsc_e4 e4
;
148 struct usb_device
*usb_dev
;
149 struct usbatm_data
*usbatm
;
152 unsigned int driver_info
;
160 wait_queue_head_t sync_q
;
162 struct task_struct
*kthread
;
167 union cmv_dsc cmv_dsc
;
169 struct work_struct task
;
170 struct workqueue_struct
*work_q
;
174 const struct firmware
*dsp_firm
;
177 void (*dispatch_cmv
) (struct uea_softc
*, struct intr_pkt
*);
178 void (*schedule_load_page
) (struct uea_softc
*, struct intr_pkt
*);
179 int (*stat
) (struct uea_softc
*);
180 int (*send_cmvs
) (struct uea_softc
*);
182 /* keep in sync with eaglectl */
210 #define ELSA_VID 0x05CC
211 #define ELSA_PID_PSTFIRM 0x3350
212 #define ELSA_PID_PREFIRM 0x3351
214 #define ELSA_PID_A_PREFIRM 0x3352
215 #define ELSA_PID_A_PSTFIRM 0x3353
216 #define ELSA_PID_B_PREFIRM 0x3362
217 #define ELSA_PID_B_PSTFIRM 0x3363
220 * Devolo IDs : pots if (pid & 0x10)
222 #define DEVOLO_VID 0x1039
223 #define DEVOLO_EAGLE_I_A_PID_PSTFIRM 0x2110
224 #define DEVOLO_EAGLE_I_A_PID_PREFIRM 0x2111
226 #define DEVOLO_EAGLE_I_B_PID_PSTFIRM 0x2100
227 #define DEVOLO_EAGLE_I_B_PID_PREFIRM 0x2101
229 #define DEVOLO_EAGLE_II_A_PID_PSTFIRM 0x2130
230 #define DEVOLO_EAGLE_II_A_PID_PREFIRM 0x2131
232 #define DEVOLO_EAGLE_II_B_PID_PSTFIRM 0x2120
233 #define DEVOLO_EAGLE_II_B_PID_PREFIRM 0x2121
236 * Reference design USB IDs
238 #define ANALOG_VID 0x1110
239 #define ADI930_PID_PREFIRM 0x9001
240 #define ADI930_PID_PSTFIRM 0x9000
242 #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
243 #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
245 #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
246 #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
248 #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
249 #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
251 #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
252 #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
254 #define EAGLE_IV_PID_PREFIRM 0x9042 /* Eagle IV */
255 #define EAGLE_IV_PID_PSTFIRM 0x9041 /* Eagle IV */
260 #define USR_VID 0x0BAF
261 #define MILLER_A_PID_PREFIRM 0x00F2
262 #define MILLER_A_PID_PSTFIRM 0x00F1
263 #define MILLER_B_PID_PREFIRM 0x00FA
264 #define MILLER_B_PID_PSTFIRM 0x00F9
265 #define HEINEKEN_A_PID_PREFIRM 0x00F6
266 #define HEINEKEN_A_PID_PSTFIRM 0x00F5
267 #define HEINEKEN_B_PID_PREFIRM 0x00F8
268 #define HEINEKEN_B_PID_PSTFIRM 0x00F7
271 #define PSTFIRM (1<<7)
272 #define AUTO_ANNEX_A (1<<8)
273 #define AUTO_ANNEX_B (1<<9)
283 /* macros for both struct usb_device_id and struct uea_softc */
284 #define UEA_IS_PREFIRM(x) \
285 (!((x)->driver_info & PSTFIRM))
286 #define UEA_CHIP_VERSION(x) \
287 ((x)->driver_info & 0xf)
290 ((x)->annex & ANNEXB)
292 #define INS_TO_USBDEV(ins) ins->usb_dev
294 #define GET_STATUS(data) \
297 #define IS_OPERATIONAL(sc) \
298 ((UEA_CHIP_VERSION(sc) != EAGLE_IV) ? \
299 (GET_STATUS(sc->stats.phy.state) == 2) : \
300 (sc->stats.phy.state == 7))
303 * Set of macros to handle unaligned data in the firmware blob.
304 * The FW_GET_BYTE() macro is provided only for consistency.
307 #define FW_GET_BYTE(p) *((__u8 *) (p))
309 #define FW_DIR "ueagle-atm/"
310 #define UEA_FW_NAME_MAX 30
313 #define BULK_TIMEOUT 300
314 #define CTRL_TIMEOUT 1000
316 #define ACK_TIMEOUT msecs_to_jiffies(3000)
318 #define UEA_INTR_IFACE_NO 0
319 #define UEA_US_IFACE_NO 1
320 #define UEA_DS_IFACE_NO 2
322 #define FASTEST_ISO_INTF 8
324 #define UEA_BULK_DATA_PIPE 0x02
325 #define UEA_IDMA_PIPE 0x04
326 #define UEA_INTR_PIPE 0x04
327 #define UEA_ISO_DATA_PIPE 0x08
329 #define UEA_E1_SET_BLOCK 0x0001
330 #define UEA_E4_SET_BLOCK 0x002c
331 #define UEA_SET_MODE 0x0003
332 #define UEA_SET_2183_DATA 0x0004
333 #define UEA_SET_TIMEOUT 0x0011
335 #define UEA_LOOPBACK_OFF 0x0002
336 #define UEA_LOOPBACK_ON 0x0003
337 #define UEA_BOOT_IDMA 0x0006
338 #define UEA_START_RESET 0x0007
339 #define UEA_END_RESET 0x0008
341 #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
342 #define UEA_MPTX_START (0x3fce | 0x4000)
343 #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
344 #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
346 /* block information in eagle4 dsp firmware */
355 } __attribute__ ((packed
));
357 #define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
358 #define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
360 #define E4_L1_STRING_HEADER 0x10
361 #define E4_MAX_PAGE_NUMBER 0x58
362 #define E4_NO_SWAPPAGE_HEADERS 0x31
364 /* l1_code is eagle4 dsp firmware format */
366 u8 string_header
[E4_L1_STRING_HEADER
];
367 u8 page_number_to_block_index
[E4_MAX_PAGE_NUMBER
];
368 struct block_index page_header
[E4_NO_SWAPPAGE_HEADERS
];
370 } __attribute__ ((packed
));
372 /* structures describing a block within a DSP page */
373 struct block_info_e1
{
378 __le16 wOvl
; /* overlay */
380 } __attribute__ ((packed
));
381 #define E1_BLOCK_INFO_SIZE 12
383 struct block_info_e4
{
390 } __attribute__ ((packed
));
391 #define E4_BLOCK_INFO_SIZE 14
393 #define UEA_BIHDR 0xabcd
394 #define UEA_RESERVED 0xffff
396 /* constants describing cmv type */
397 #define E1_PREAMBLE 0x535c
398 #define E1_MODEMTOHOST 0x01
399 #define E1_HOSTTOMODEM 0x10
401 #define E1_MEMACCESS 0x1
402 #define E1_ADSLDIRECTIVE 0x7
403 #define E1_FUNCTION_TYPE(f) ((f) >> 4)
404 #define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f)
406 #define E4_MEMACCESS 0
407 #define E4_ADSLDIRECTIVE 0xf
408 #define E4_FUNCTION_TYPE(f) ((f) >> 8)
409 #define E4_FUNCTION_SIZE(f) ((f) & 0x0f)
410 #define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f)
413 #define E1_REQUESTREAD 0x0
414 #define E1_REQUESTWRITE 0x1
415 #define E1_REPLYREAD 0x2
416 #define E1_REPLYWRITE 0x3
418 #define E4_REQUESTREAD 0x0
419 #define E4_REQUESTWRITE 0x4
420 #define E4_REPLYREAD (E4_REQUESTREAD | 1)
421 #define E4_REPLYWRITE (E4_REQUESTWRITE | 1)
423 /* for ADSLDIRECTIVE */
424 #define E1_KERNELREADY 0x0
425 #define E1_MODEMREADY 0x1
427 #define E4_KERNELREADY 0x0
428 #define E4_MODEMREADY 0x1
430 #define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
431 #define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | ((st) & 0xf) << 4 | ((s) & 0xf))
433 #define E1_MAKESA(a, b, c, d) \
434 (((c) & 0xff) << 24 | \
435 ((d) & 0xff) << 16 | \
436 ((a) & 0xff) << 8 | \
439 #define E1_GETSA1(a) ((a >> 8) & 0xff)
440 #define E1_GETSA2(a) (a & 0xff)
441 #define E1_GETSA3(a) ((a >> 24) & 0xff)
442 #define E1_GETSA4(a) ((a >> 16) & 0xff)
444 #define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L')
445 #define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G')
446 #define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O')
447 #define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N')
448 #define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E')
449 #define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T')
460 /* structures representing a CMV (Configuration and Management Variable) */
466 __le32 dwSymbolicAddress
;
467 __le16 wOffsetAddress
;
469 } __attribute__ ((packed
));
477 } __attribute__ ((packed
));
479 /* structures representing swap information */
480 struct swap_info_e1
{
482 __u8 bOvl
; /* overlay */
483 } __attribute__ ((packed
));
485 struct swap_info_e4
{
487 } __attribute__ ((packed
));
489 /* structures representing interrupt data */
490 #define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
491 #define e1_bOvl u.e1.s1.swapinfo.bOvl
492 #define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo
494 #define INT_LOADSWAPPAGE 0x0001
495 #define INT_INCOMINGCMV 0x0002
499 struct swap_info_e1 swapinfo
;
501 } __attribute__ ((packed
)) s1
;
505 } __attribute__ ((packed
)) s2
;
506 } __attribute__ ((packed
));
510 struct swap_info_e4 swapinfo
;
512 } __attribute__ ((packed
)) s1
;
516 } __attribute__ ((packed
)) s2
;
517 } __attribute__ ((packed
));
527 union intr_data_e1 e1
;
528 union intr_data_e4 e4
;
530 } __attribute__ ((packed
));
532 #define E1_INTR_PKT_SIZE 28
533 #define E4_INTR_PKT_SIZE 64
535 static struct usb_driver uea_driver
;
536 static DEFINE_MUTEX(uea_mutex
);
537 static const char *chip_name
[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
539 static int modem_index
;
540 static unsigned int debug
;
541 static unsigned int altsetting
[NB_MODEM
] = {[0 ... (NB_MODEM
- 1)] = FASTEST_ISO_INTF
};
542 static int sync_wait
[NB_MODEM
];
543 static char *cmv_file
[NB_MODEM
];
544 static int annex
[NB_MODEM
];
546 module_param(debug
, uint
, 0644);
547 MODULE_PARM_DESC(debug
, "module debug level (0=off,1=on,2=verbose)");
548 module_param_array(altsetting
, uint
, NULL
, 0644);
549 MODULE_PARM_DESC(altsetting
, "alternate setting for incoming traffic: 0=bulk, "
550 "1=isoc slowest, ... , 8=isoc fastest (default)");
551 module_param_array(sync_wait
, bool, NULL
, 0644);
552 MODULE_PARM_DESC(sync_wait
, "wait the synchronisation before starting ATM");
553 module_param_array(cmv_file
, charp
, NULL
, 0644);
554 MODULE_PARM_DESC(cmv_file
,
555 "file name with configuration and management variables");
556 module_param_array(annex
, uint
, NULL
, 0644);
557 MODULE_PARM_DESC(annex
,
558 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
560 #define uea_wait(sc, cond, timeo) \
562 int _r = wait_event_interruptible_timeout(sc->sync_q, \
563 (cond) || kthread_should_stop(), timeo); \
564 if (kthread_should_stop()) \
569 #define UPDATE_ATM_STAT(type, val) \
571 if (sc->usbatm->atm_dev) \
572 sc->usbatm->atm_dev->type = val; \
575 /* Firmware loading */
576 #define LOAD_INTERNAL 0xA0
577 #define F8051_USBCS 0x7f92
580 * uea_send_modem_cmd - Send a command for pre-firmware devices.
582 static int uea_send_modem_cmd(struct usb_device
*usb
,
583 u16 addr
, u16 size
, const u8
*buff
)
588 xfer_buff
= kmemdup(buff
, size
, GFP_KERNEL
);
590 ret
= usb_control_msg(usb
,
591 usb_sndctrlpipe(usb
, 0),
593 USB_DIR_OUT
| USB_TYPE_VENDOR
|
594 USB_RECIP_DEVICE
, addr
, 0, xfer_buff
,
602 return (ret
== size
) ? 0 : -EIO
;
605 static void uea_upload_pre_firmware(const struct firmware
*fw_entry
, void *context
)
607 struct usb_device
*usb
= context
;
615 uea_err(usb
, "firmware is not available\n");
619 pfw
= fw_entry
->data
;
620 size
= fw_entry
->size
;
622 goto err_fw_corrupted
;
624 crc
= get_unaligned_le32(pfw
);
627 if (crc32_be(0, pfw
, size
) != crc
)
628 goto err_fw_corrupted
;
631 * Start to upload firmware : send reset
634 ret
= uea_send_modem_cmd(usb
, F8051_USBCS
, sizeof(value
), &value
);
637 uea_err(usb
, "modem reset failed with error %d\n", ret
);
642 u8 len
= FW_GET_BYTE(pfw
);
643 u16 add
= get_unaligned_le16(pfw
+ 1);
647 goto err_fw_corrupted
;
649 ret
= uea_send_modem_cmd(usb
, add
, len
, pfw
+ 3);
651 uea_err(usb
, "uploading firmware data failed "
652 "with error %d\n", ret
);
659 goto err_fw_corrupted
;
662 * Tell the modem we finish : de-assert reset
665 ret
= uea_send_modem_cmd(usb
, F8051_USBCS
, 1, &value
);
667 uea_err(usb
, "modem de-assert failed with error %d\n", ret
);
669 uea_info(usb
, "firmware uploaded\n");
674 uea_err(usb
, "firmware is corrupted\n");
676 release_firmware(fw_entry
);
681 * uea_load_firmware - Load usb firmware for pre-firmware devices.
683 static int uea_load_firmware(struct usb_device
*usb
, unsigned int ver
)
686 char *fw_name
= FW_DIR
"eagle.fw";
689 uea_info(usb
, "pre-firmware device, uploading firmware\n");
693 fw_name
= FW_DIR
"adi930.fw";
696 fw_name
= FW_DIR
"eagleI.fw";
699 fw_name
= FW_DIR
"eagleII.fw";
702 fw_name
= FW_DIR
"eagleIII.fw";
705 fw_name
= FW_DIR
"eagleIV.fw";
709 ret
= request_firmware_nowait(THIS_MODULE
, 1, fw_name
, &usb
->dev
,
710 GFP_KERNEL
, usb
, uea_upload_pre_firmware
);
712 uea_err(usb
, "firmware %s is not available\n", fw_name
);
714 uea_info(usb
, "loading firmware %s\n", fw_name
);
720 /* modem management : dsp firmware, send/read CMV, monitoring statistic
724 * Make sure that the DSP code provided is safe to use.
726 static int check_dsp_e1(const u8
*dsp
, unsigned int len
)
728 u8 pagecount
, blockcount
;
731 unsigned int i
, j
, p
, pp
;
733 pagecount
= FW_GET_BYTE(dsp
);
736 /* enough space for page offsets? */
737 if (p
+ 4 * pagecount
> len
)
740 for (i
= 0; i
< pagecount
; i
++) {
742 pageoffset
= get_unaligned_le32(dsp
+ p
);
748 /* enough space for blockcount? */
749 if (pageoffset
>= len
)
753 blockcount
= FW_GET_BYTE(dsp
+ pp
);
756 for (j
= 0; j
< blockcount
; j
++) {
758 /* enough space for block header? */
762 pp
+= 2; /* skip blockaddr */
763 blocksize
= get_unaligned_le16(dsp
+ pp
);
766 /* enough space for block data? */
767 if (pp
+ blocksize
> len
)
777 static int check_dsp_e4(const u8
*dsp
, int len
)
780 struct l1_code
*p
= (struct l1_code
*) dsp
;
781 unsigned int sum
= p
->code
- dsp
;
786 if (strcmp("STRATIPHY ANEXA", p
->string_header
) != 0 &&
787 strcmp("STRATIPHY ANEXB", p
->string_header
) != 0)
790 for (i
= 0; i
< E4_MAX_PAGE_NUMBER
; i
++) {
791 struct block_index
*blockidx
;
792 u8 blockno
= p
->page_number_to_block_index
[i
];
793 if (blockno
>= E4_NO_SWAPPAGE_HEADERS
)
799 if (blockno
>= E4_NO_SWAPPAGE_HEADERS
)
802 blockidx
= &p
->page_header
[blockno
++];
803 if ((u8
*)(blockidx
+ 1) - dsp
>= len
)
806 if (le16_to_cpu(blockidx
->PageNumber
) != i
)
809 l
= E4_PAGE_BYTES(blockidx
->PageSize
);
811 l
+= le32_to_cpu(blockidx
->PageOffset
);
815 /* zero is zero regardless endianes */
816 } while (blockidx
->NotLastBlock
);
819 return (sum
== len
) ? 0 : 1;
823 * send data to the idma pipe
825 static int uea_idma_write(struct uea_softc
*sc
, const void *data
, u32 size
)
831 xfer_buff
= kmemdup(data
, size
, GFP_KERNEL
);
833 uea_err(INS_TO_USBDEV(sc
), "can't allocate xfer_buff\n");
837 ret
= usb_bulk_msg(sc
->usb_dev
,
838 usb_sndbulkpipe(sc
->usb_dev
, UEA_IDMA_PIPE
),
839 xfer_buff
, size
, &bytes_read
, BULK_TIMEOUT
);
844 if (size
!= bytes_read
) {
845 uea_err(INS_TO_USBDEV(sc
), "size != bytes_read %d %d\n", size
,
853 static int request_dsp(struct uea_softc
*sc
)
858 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
860 dsp_name
= FW_DIR
"DSP4i.bin";
862 dsp_name
= FW_DIR
"DSP4p.bin";
863 } else if (UEA_CHIP_VERSION(sc
) == ADI930
) {
865 dsp_name
= FW_DIR
"DSP9i.bin";
867 dsp_name
= FW_DIR
"DSP9p.bin";
870 dsp_name
= FW_DIR
"DSPei.bin";
872 dsp_name
= FW_DIR
"DSPep.bin";
875 ret
= request_firmware(&sc
->dsp_firm
, dsp_name
, &sc
->usb_dev
->dev
);
877 uea_err(INS_TO_USBDEV(sc
),
878 "requesting firmware %s failed with error %d\n",
883 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
)
884 ret
= check_dsp_e4(sc
->dsp_firm
->data
, sc
->dsp_firm
->size
);
886 ret
= check_dsp_e1(sc
->dsp_firm
->data
, sc
->dsp_firm
->size
);
889 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n",
891 release_firmware(sc
->dsp_firm
);
900 * The uea_load_page() function must be called within a process context
902 static void uea_load_page_e1(struct work_struct
*work
)
904 struct uea_softc
*sc
= container_of(work
, struct uea_softc
, task
);
905 u16 pageno
= sc
->pageno
;
907 struct block_info_e1 bi
;
910 u8 pagecount
, blockcount
;
911 u16 blockaddr
, blocksize
;
915 /* reload firmware when reboot start and it's loaded already */
916 if (ovl
== 0 && pageno
== 0 && sc
->dsp_firm
) {
917 release_firmware(sc
->dsp_firm
);
921 if (sc
->dsp_firm
== NULL
&& request_dsp(sc
) < 0)
924 p
= sc
->dsp_firm
->data
;
925 pagecount
= FW_GET_BYTE(p
);
928 if (pageno
>= pagecount
)
932 pageoffset
= get_unaligned_le32(p
);
937 p
= sc
->dsp_firm
->data
+ pageoffset
;
938 blockcount
= FW_GET_BYTE(p
);
941 uea_dbg(INS_TO_USBDEV(sc
),
942 "sending %u blocks for DSP page %u\n", blockcount
, pageno
);
944 bi
.wHdr
= cpu_to_le16(UEA_BIHDR
);
945 bi
.wOvl
= cpu_to_le16(ovl
);
946 bi
.wOvlOffset
= cpu_to_le16(ovl
| 0x8000);
948 for (i
= 0; i
< blockcount
; i
++) {
949 blockaddr
= get_unaligned_le16(p
);
952 blocksize
= get_unaligned_le16(p
);
955 bi
.wSize
= cpu_to_le16(blocksize
);
956 bi
.wAddress
= cpu_to_le16(blockaddr
);
957 bi
.wLast
= cpu_to_le16((i
== blockcount
- 1) ? 1 : 0);
959 /* send block info through the IDMA pipe */
960 if (uea_idma_write(sc
, &bi
, E1_BLOCK_INFO_SIZE
))
963 /* send block data through the IDMA pipe */
964 if (uea_idma_write(sc
, p
, blocksize
))
973 uea_err(INS_TO_USBDEV(sc
), "sending DSP block %u failed\n", i
);
976 uea_err(INS_TO_USBDEV(sc
), "invalid DSP page %u requested\n", pageno
);
979 static void __uea_load_page_e4(struct uea_softc
*sc
, u8 pageno
, int boot
)
981 struct block_info_e4 bi
;
982 struct block_index
*blockidx
;
983 struct l1_code
*p
= (struct l1_code
*) sc
->dsp_firm
->data
;
984 u8 blockno
= p
->page_number_to_block_index
[pageno
];
986 bi
.wHdr
= cpu_to_be16(UEA_BIHDR
);
988 bi
.bPageNumber
= pageno
;
989 bi
.wReserved
= cpu_to_be16(UEA_RESERVED
);
992 const u8
*blockoffset
;
993 unsigned int blocksize
;
995 blockidx
= &p
->page_header
[blockno
];
996 blocksize
= E4_PAGE_BYTES(blockidx
->PageSize
);
997 blockoffset
= sc
->dsp_firm
->data
+ le32_to_cpu(blockidx
->PageOffset
);
999 bi
.dwSize
= cpu_to_be32(blocksize
);
1000 bi
.dwAddress
= cpu_to_be32(le32_to_cpu(blockidx
->PageAddress
));
1002 uea_dbg(INS_TO_USBDEV(sc
),
1003 "sending block %u for DSP page %u size %u address %x\n",
1004 blockno
, pageno
, blocksize
, le32_to_cpu(blockidx
->PageAddress
));
1006 /* send block info through the IDMA pipe */
1007 if (uea_idma_write(sc
, &bi
, E4_BLOCK_INFO_SIZE
))
1010 /* send block data through the IDMA pipe */
1011 if (uea_idma_write(sc
, blockoffset
, blocksize
))
1015 } while (blockidx
->NotLastBlock
);
1020 uea_err(INS_TO_USBDEV(sc
), "sending DSP block %u failed\n", blockno
);
1024 static void uea_load_page_e4(struct work_struct
*work
)
1026 struct uea_softc
*sc
= container_of(work
, struct uea_softc
, task
);
1027 u8 pageno
= sc
->pageno
;
1029 struct block_info_e4 bi
;
1032 uea_dbg(INS_TO_USBDEV(sc
), "sending DSP page %u\n", pageno
);
1034 /* reload firmware when reboot start and it's loaded already */
1035 if (pageno
== 0 && sc
->dsp_firm
) {
1036 release_firmware(sc
->dsp_firm
);
1037 sc
->dsp_firm
= NULL
;
1040 if (sc
->dsp_firm
== NULL
&& request_dsp(sc
) < 0)
1043 p
= (struct l1_code
*) sc
->dsp_firm
->data
;
1044 if (pageno
>= le16_to_cpu(p
->page_header
[0].PageNumber
)) {
1045 uea_err(INS_TO_USBDEV(sc
), "invalid DSP page %u requested\n", pageno
);
1050 __uea_load_page_e4(sc
, pageno
, 0);
1054 uea_dbg(INS_TO_USBDEV(sc
),
1055 "sending Main DSP page %u\n", p
->page_header
[0].PageNumber
);
1057 for (i
= 0; i
< le16_to_cpu(p
->page_header
[0].PageNumber
); i
++) {
1058 if (E4_IS_BOOT_PAGE(p
->page_header
[i
].PageSize
))
1059 __uea_load_page_e4(sc
, i
, 1);
1062 uea_dbg(INS_TO_USBDEV(sc
),"sending start bi\n");
1064 bi
.wHdr
= cpu_to_be16(UEA_BIHDR
);
1066 bi
.bPageNumber
= 0xff;
1067 bi
.wReserved
= cpu_to_be16(UEA_RESERVED
);
1068 bi
.dwSize
= cpu_to_be32(E4_PAGE_BYTES(p
->page_header
[0].PageSize
));
1069 bi
.dwAddress
= cpu_to_be32(le32_to_cpu(p
->page_header
[0].PageAddress
));
1071 /* send block info through the IDMA pipe */
1072 if (uea_idma_write(sc
, &bi
, E4_BLOCK_INFO_SIZE
))
1073 uea_err(INS_TO_USBDEV(sc
), "sending DSP start bi failed\n");
1076 static inline void wake_up_cmv_ack(struct uea_softc
*sc
)
1078 BUG_ON(sc
->cmv_ack
);
1080 wake_up(&sc
->sync_q
);
1083 static inline int wait_cmv_ack(struct uea_softc
*sc
)
1085 int ret
= uea_wait(sc
, sc
->cmv_ack
, ACK_TIMEOUT
);
1089 uea_dbg(INS_TO_USBDEV(sc
), "wait_event_timeout : %d ms\n",
1090 jiffies_to_msecs(ret
));
1095 return (ret
== 0) ? -ETIMEDOUT
: 0;
1098 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1100 static int uea_request(struct uea_softc
*sc
,
1101 u16 value
, u16 index
, u16 size
, const void *data
)
1106 xfer_buff
= kmemdup(data
, size
, GFP_KERNEL
);
1108 uea_err(INS_TO_USBDEV(sc
), "can't allocate xfer_buff\n");
1112 ret
= usb_control_msg(sc
->usb_dev
, usb_sndctrlpipe(sc
->usb_dev
, 0),
1113 UCDC_SEND_ENCAPSULATED_COMMAND
,
1114 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
1115 value
, index
, xfer_buff
, size
, CTRL_TIMEOUT
);
1119 uea_err(INS_TO_USBDEV(sc
), "usb_control_msg error %d\n", ret
);
1124 uea_err(INS_TO_USBDEV(sc
),
1125 "usb_control_msg send only %d bytes (instead of %d)\n",
1133 static int uea_cmv_e1(struct uea_softc
*sc
,
1134 u8 function
, u32 address
, u16 offset
, u32 data
)
1139 uea_enters(INS_TO_USBDEV(sc
));
1140 uea_vdbg(INS_TO_USBDEV(sc
), "Function : %d-%d, Address : %c%c%c%c, "
1141 "offset : 0x%04x, data : 0x%08x\n",
1142 E1_FUNCTION_TYPE(function
), E1_FUNCTION_SUBTYPE(function
),
1143 E1_GETSA1(address
), E1_GETSA2(address
), E1_GETSA3(address
),
1144 E1_GETSA4(address
), offset
, data
);
1146 /* we send a request, but we expect a reply */
1147 sc
->cmv_dsc
.e1
.function
= function
| 0x2;
1148 sc
->cmv_dsc
.e1
.idx
++;
1149 sc
->cmv_dsc
.e1
.address
= address
;
1150 sc
->cmv_dsc
.e1
.offset
= offset
;
1152 cmv
.wPreamble
= cpu_to_le16(E1_PREAMBLE
);
1153 cmv
.bDirection
= E1_HOSTTOMODEM
;
1154 cmv
.bFunction
= function
;
1155 cmv
.wIndex
= cpu_to_le16(sc
->cmv_dsc
.e1
.idx
);
1156 put_unaligned_le32(address
, &cmv
.dwSymbolicAddress
);
1157 cmv
.wOffsetAddress
= cpu_to_le16(offset
);
1158 put_unaligned_le32(data
>> 16 | data
<< 16, &cmv
.dwData
);
1160 ret
= uea_request(sc
, UEA_E1_SET_BLOCK
, UEA_MPTX_START
, sizeof(cmv
), &cmv
);
1163 ret
= wait_cmv_ack(sc
);
1164 uea_leaves(INS_TO_USBDEV(sc
));
1168 static int uea_cmv_e4(struct uea_softc
*sc
,
1169 u16 function
, u16 group
, u16 address
, u16 offset
, u32 data
)
1174 uea_enters(INS_TO_USBDEV(sc
));
1175 memset(&cmv
, 0, sizeof(cmv
));
1177 uea_vdbg(INS_TO_USBDEV(sc
), "Function : %d-%d, Group : 0x%04x, "
1178 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1179 E4_FUNCTION_TYPE(function
), E4_FUNCTION_SUBTYPE(function
),
1180 group
, address
, offset
, data
);
1182 /* we send a request, but we expect a reply */
1183 sc
->cmv_dsc
.e4
.function
= function
| (0x1 << 4);
1184 sc
->cmv_dsc
.e4
.offset
= offset
;
1185 sc
->cmv_dsc
.e4
.address
= address
;
1186 sc
->cmv_dsc
.e4
.group
= group
;
1188 cmv
.wFunction
= cpu_to_be16(function
);
1189 cmv
.wGroup
= cpu_to_be16(group
);
1190 cmv
.wAddress
= cpu_to_be16(address
);
1191 cmv
.wOffset
= cpu_to_be16(offset
);
1192 cmv
.dwData
[0] = cpu_to_be32(data
);
1194 ret
= uea_request(sc
, UEA_E4_SET_BLOCK
, UEA_MPTX_START
, sizeof(cmv
), &cmv
);
1197 ret
= wait_cmv_ack(sc
);
1198 uea_leaves(INS_TO_USBDEV(sc
));
1202 static inline int uea_read_cmv_e1(struct uea_softc
*sc
,
1203 u32 address
, u16 offset
, u32
*data
)
1205 int ret
= uea_cmv_e1(sc
, E1_MAKEFUNCTION(E1_MEMACCESS
, E1_REQUESTREAD
),
1206 address
, offset
, 0);
1208 uea_err(INS_TO_USBDEV(sc
),
1209 "reading cmv failed with error %d\n", ret
);
1216 static inline int uea_read_cmv_e4(struct uea_softc
*sc
,
1217 u8 size
, u16 group
, u16 address
, u16 offset
, u32
*data
)
1219 int ret
= uea_cmv_e4(sc
, E4_MAKEFUNCTION(E4_MEMACCESS
, E4_REQUESTREAD
, size
),
1220 group
, address
, offset
, 0);
1222 uea_err(INS_TO_USBDEV(sc
),
1223 "reading cmv failed with error %d\n", ret
);
1226 /* size is in 16-bit word quantities */
1228 *(data
+ 1) = sc
->data1
;
1233 static inline int uea_write_cmv_e1(struct uea_softc
*sc
,
1234 u32 address
, u16 offset
, u32 data
)
1236 int ret
= uea_cmv_e1(sc
, E1_MAKEFUNCTION(E1_MEMACCESS
, E1_REQUESTWRITE
),
1237 address
, offset
, data
);
1239 uea_err(INS_TO_USBDEV(sc
),
1240 "writing cmv failed with error %d\n", ret
);
1245 static inline int uea_write_cmv_e4(struct uea_softc
*sc
,
1246 u8 size
, u16 group
, u16 address
, u16 offset
, u32 data
)
1248 int ret
= uea_cmv_e4(sc
, E4_MAKEFUNCTION(E4_MEMACCESS
, E4_REQUESTWRITE
, size
),
1249 group
, address
, offset
, data
);
1251 uea_err(INS_TO_USBDEV(sc
),
1252 "writing cmv failed with error %d\n", ret
);
1257 static void uea_set_bulk_timeout(struct uea_softc
*sc
, u32 dsrate
)
1262 /* in bulk mode the modem have problem with high rate
1263 * changing internal timing could improve things, but the
1264 * value is misterious.
1265 * ADI930 don't support it (-EPIPE error).
1268 if (UEA_CHIP_VERSION(sc
) == ADI930
||
1269 altsetting
[sc
->modem_index
] > 0 ||
1270 sc
->stats
.phy
.dsrate
== dsrate
)
1273 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1274 timeout
= (dsrate
<= 1024*1024) ? 0 : 1;
1275 ret
= uea_request(sc
, UEA_SET_TIMEOUT
, timeout
, 0, NULL
);
1276 uea_info(INS_TO_USBDEV(sc
), "setting new timeout %d%s\n",
1277 timeout
, ret
< 0 ? " failed" : "");
1282 * Monitor the modem and update the stat
1283 * return 0 if everything is ok
1284 * return < 0 if an error occurs (-EAGAIN reboot needed)
1286 static int uea_stat_e1(struct uea_softc
*sc
)
1291 uea_enters(INS_TO_USBDEV(sc
));
1292 data
= sc
->stats
.phy
.state
;
1294 ret
= uea_read_cmv_e1(sc
, E1_SA_STAT
, 0, &sc
->stats
.phy
.state
);
1298 switch (GET_STATUS(sc
->stats
.phy
.state
)) {
1299 case 0: /* not yet synchronized */
1300 uea_dbg(INS_TO_USBDEV(sc
),
1301 "modem not yet synchronized\n");
1304 case 1: /* initialization */
1305 uea_dbg(INS_TO_USBDEV(sc
), "modem initializing\n");
1308 case 2: /* operational */
1309 uea_vdbg(INS_TO_USBDEV(sc
), "modem operational\n");
1312 case 3: /* fail ... */
1313 uea_info(INS_TO_USBDEV(sc
), "modem synchronization failed"
1314 " (may be try other cmv/dsp)\n");
1317 case 4 ... 6: /* test state */
1318 uea_warn(INS_TO_USBDEV(sc
),
1319 "modem in test mode - not supported\n");
1322 case 7: /* fast-retain ... */
1323 uea_info(INS_TO_USBDEV(sc
), "modem in fast-retain mode\n");
1326 uea_err(INS_TO_USBDEV(sc
), "modem invalid SW mode %d\n",
1327 GET_STATUS(sc
->stats
.phy
.state
));
1331 if (GET_STATUS(data
) != 2) {
1332 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_OFF
, 0, NULL
);
1333 uea_info(INS_TO_USBDEV(sc
), "modem operational\n");
1335 /* release the dsp firmware as it is not needed until
1339 release_firmware(sc
->dsp_firm
);
1340 sc
->dsp_firm
= NULL
;
1344 /* always update it as atm layer could not be init when we switch to
1347 UPDATE_ATM_STAT(signal
, ATM_PHY_SIG_FOUND
);
1349 /* wake up processes waiting for synchronization */
1350 wake_up(&sc
->sync_q
);
1352 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 2, &sc
->stats
.phy
.flags
);
1355 sc
->stats
.phy
.mflags
|= sc
->stats
.phy
.flags
;
1357 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1358 * we check the status again in order to detect the failure earlier
1360 if (sc
->stats
.phy
.flags
) {
1361 uea_dbg(INS_TO_USBDEV(sc
), "Stat flag = 0x%x\n",
1362 sc
->stats
.phy
.flags
);
1366 ret
= uea_read_cmv_e1(sc
, E1_SA_RATE
, 0, &data
);
1370 uea_set_bulk_timeout(sc
, (data
>> 16) * 32);
1371 sc
->stats
.phy
.dsrate
= (data
>> 16) * 32;
1372 sc
->stats
.phy
.usrate
= (data
& 0xffff) * 32;
1373 UPDATE_ATM_STAT(link_rate
, sc
->stats
.phy
.dsrate
* 1000 / 424);
1375 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 23, &data
);
1378 sc
->stats
.phy
.dsattenuation
= (data
& 0xff) / 2;
1380 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 47, &data
);
1383 sc
->stats
.phy
.usattenuation
= (data
& 0xff) / 2;
1385 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 25, &sc
->stats
.phy
.dsmargin
);
1389 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 49, &sc
->stats
.phy
.usmargin
);
1393 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 51, &sc
->stats
.phy
.rxflow
);
1397 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 52, &sc
->stats
.phy
.txflow
);
1401 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 54, &sc
->stats
.phy
.dsunc
);
1405 /* only for atu-c */
1406 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 58, &sc
->stats
.phy
.usunc
);
1410 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 53, &sc
->stats
.phy
.dscorr
);
1414 /* only for atu-c */
1415 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 57, &sc
->stats
.phy
.uscorr
);
1419 ret
= uea_read_cmv_e1(sc
, E1_SA_INFO
, 8, &sc
->stats
.phy
.vidco
);
1423 ret
= uea_read_cmv_e1(sc
, E1_SA_INFO
, 13, &sc
->stats
.phy
.vidcpe
);
1430 static int uea_stat_e4(struct uea_softc
*sc
)
1436 uea_enters(INS_TO_USBDEV(sc
));
1437 data
= sc
->stats
.phy
.state
;
1439 /* XXX only need to be done before operationnal... */
1440 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_STAT
, 0, 0, &sc
->stats
.phy
.state
);
1444 switch (sc
->stats
.phy
.state
) {
1445 case 0x0: /* not yet synchronized */
1449 uea_dbg(INS_TO_USBDEV(sc
), "modem not yet synchronized\n");
1451 case 0x5: /* initialization */
1455 uea_dbg(INS_TO_USBDEV(sc
), "modem initializing\n");
1457 case 0x2: /* fail ... */
1458 uea_info(INS_TO_USBDEV(sc
), "modem synchronization failed"
1459 " (may be try other cmv/dsp)\n");
1461 case 0x7: /* operational */
1464 uea_warn(INS_TO_USBDEV(sc
), "unknown state: %x\n", sc
->stats
.phy
.state
);
1469 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_OFF
, 0, NULL
);
1470 uea_info(INS_TO_USBDEV(sc
), "modem operational\n");
1472 /* release the dsp firmware as it is not needed until
1476 release_firmware(sc
->dsp_firm
);
1477 sc
->dsp_firm
= NULL
;
1481 /* always update it as atm layer could not be init when we switch to
1484 UPDATE_ATM_STAT(signal
, ATM_PHY_SIG_FOUND
);
1486 /* wake up processes waiting for synchronization */
1487 wake_up(&sc
->sync_q
);
1489 /* TODO improve this state machine :
1490 * we need some CMV info : what they do and their unit
1491 * we should find the equivalent of eagle3- CMV
1494 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_DIAG
, 0, 0, &sc
->stats
.phy
.flags
);
1497 sc
->stats
.phy
.mflags
|= sc
->stats
.phy
.flags
;
1499 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1500 * we check the status again in order to detect the failure earlier
1502 if (sc
->stats
.phy
.flags
) {
1503 uea_dbg(INS_TO_USBDEV(sc
), "Stat flag = 0x%x\n",
1504 sc
->stats
.phy
.flags
);
1505 if (sc
->stats
.phy
.flags
& 1) //delineation LOSS
1507 if (sc
->stats
.phy
.flags
& 0x4000) //Reset Flag
1512 /* rate data may be in upper or lower half of 64 bit word, strange */
1513 ret
= uea_read_cmv_e4(sc
, 4, E4_SA_RATE
, 0, 0, tmp_arr
);
1516 data
= (tmp_arr
[0]) ? tmp_arr
[0] : tmp_arr
[1];
1517 sc
->stats
.phy
.usrate
= data
/ 1000;
1519 ret
= uea_read_cmv_e4(sc
, 4, E4_SA_RATE
, 1, 0, tmp_arr
);
1522 data
= (tmp_arr
[0]) ? tmp_arr
[0] : tmp_arr
[1];
1523 uea_set_bulk_timeout(sc
, data
/ 1000);
1524 sc
->stats
.phy
.dsrate
= data
/ 1000;
1525 UPDATE_ATM_STAT(link_rate
, sc
->stats
.phy
.dsrate
* 1000 / 424);
1527 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 68, 1, &data
);
1530 sc
->stats
.phy
.dsattenuation
= data
/ 10;
1532 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 69, 1, &data
);
1535 sc
->stats
.phy
.usattenuation
= data
/ 10;
1537 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 68, 3, &data
);
1540 sc
->stats
.phy
.dsmargin
= data
/ 2;
1542 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 69, 3, &data
);
1545 sc
->stats
.phy
.usmargin
= data
/ 10;
1550 static void cmvs_file_name(struct uea_softc
*sc
, char *const cmv_name
, int ver
)
1552 char file_arr
[] = "CMVxy.bin";
1555 /* set proper name corresponding modem version and line type */
1556 if (cmv_file
[sc
->modem_index
] == NULL
) {
1557 if (UEA_CHIP_VERSION(sc
) == ADI930
)
1559 else if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
)
1564 file_arr
[4] = IS_ISDN(sc
) ? 'i' : 'p';
1567 file
= cmv_file
[sc
->modem_index
];
1569 strcpy(cmv_name
, FW_DIR
);
1570 strlcat(cmv_name
, file
, UEA_FW_NAME_MAX
);
1572 strlcat(cmv_name
, ".v2", UEA_FW_NAME_MAX
);
1575 static int request_cmvs_old(struct uea_softc
*sc
,
1576 void **cmvs
, const struct firmware
**fw
)
1580 char cmv_name
[UEA_FW_NAME_MAX
]; /* 30 bytes stack variable */
1582 cmvs_file_name(sc
, cmv_name
, 1);
1583 ret
= request_firmware(fw
, cmv_name
, &sc
->usb_dev
->dev
);
1585 uea_err(INS_TO_USBDEV(sc
),
1586 "requesting firmware %s failed with error %d\n",
1591 data
= (u8
*) (*fw
)->data
;
1594 goto err_fw_corrupted
;
1596 if (size
!= *data
* sizeof(struct uea_cmvs_v1
) + 1)
1597 goto err_fw_corrupted
;
1599 *cmvs
= (void *)(data
+ 1);
1603 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n", cmv_name
);
1604 release_firmware(*fw
);
1608 static int request_cmvs(struct uea_softc
*sc
,
1609 void **cmvs
, const struct firmware
**fw
, int *ver
)
1614 char cmv_name
[UEA_FW_NAME_MAX
]; /* 30 bytes stack variable */
1616 cmvs_file_name(sc
, cmv_name
, 2);
1617 ret
= request_firmware(fw
, cmv_name
, &sc
->usb_dev
->dev
);
1619 /* if caller can handle old version, try to provide it */
1621 uea_warn(INS_TO_USBDEV(sc
), "requesting firmware %s failed, "
1622 "try to get older cmvs\n", cmv_name
);
1623 return request_cmvs_old(sc
, cmvs
, fw
);
1625 uea_err(INS_TO_USBDEV(sc
),
1626 "requesting firmware %s failed with error %d\n",
1632 data
= (u8
*) (*fw
)->data
;
1633 if (size
< 4 || strncmp(data
, "cmv2", 4) != 0) {
1635 uea_warn(INS_TO_USBDEV(sc
), "firmware %s is corrupted, "
1636 "try to get older cmvs\n", cmv_name
);
1637 release_firmware(*fw
);
1638 return request_cmvs_old(sc
, cmvs
, fw
);
1640 goto err_fw_corrupted
;
1648 goto err_fw_corrupted
;
1650 crc
= get_unaligned_le32(data
);
1653 if (crc32_be(0, data
, size
) != crc
)
1654 goto err_fw_corrupted
;
1656 if (size
!= *data
* sizeof(struct uea_cmvs_v2
) + 1)
1657 goto err_fw_corrupted
;
1659 *cmvs
= (void *) (data
+ 1);
1663 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n", cmv_name
);
1664 release_firmware(*fw
);
1668 static int uea_send_cmvs_e1(struct uea_softc
*sc
)
1672 const struct firmware
*cmvs_fw
;
1673 int ver
= 1; // we can handle v1 cmv firmware version;
1675 /* Enter in R-IDLE (cmv) until instructed otherwise */
1676 ret
= uea_write_cmv_e1(sc
, E1_SA_CNTL
, 0, 1);
1680 /* Dump firmware version */
1681 ret
= uea_read_cmv_e1(sc
, E1_SA_INFO
, 10, &sc
->stats
.phy
.firmid
);
1684 uea_info(INS_TO_USBDEV(sc
), "ATU-R firmware version : %x\n",
1685 sc
->stats
.phy
.firmid
);
1688 ret
= len
= request_cmvs(sc
, &cmvs_ptr
, &cmvs_fw
, &ver
);
1694 struct uea_cmvs_v1
*cmvs_v1
= cmvs_ptr
;
1696 uea_warn(INS_TO_USBDEV(sc
), "use deprecated cmvs version, "
1697 "please update your firmware\n");
1699 for (i
= 0; i
< len
; i
++) {
1700 ret
= uea_write_cmv_e1(sc
, get_unaligned_le32(&cmvs_v1
[i
].address
),
1701 get_unaligned_le16(&cmvs_v1
[i
].offset
),
1702 get_unaligned_le32(&cmvs_v1
[i
].data
));
1706 } else if (ver
== 2) {
1707 struct uea_cmvs_v2
*cmvs_v2
= cmvs_ptr
;
1709 for (i
= 0; i
< len
; i
++) {
1710 ret
= uea_write_cmv_e1(sc
, get_unaligned_le32(&cmvs_v2
[i
].address
),
1711 (u16
) get_unaligned_le32(&cmvs_v2
[i
].offset
),
1712 get_unaligned_le32(&cmvs_v2
[i
].data
));
1717 /* This realy should not happen */
1718 uea_err(INS_TO_USBDEV(sc
), "bad cmvs version %d\n", ver
);
1722 /* Enter in R-ACT-REQ */
1723 ret
= uea_write_cmv_e1(sc
, E1_SA_CNTL
, 0, 2);
1724 uea_vdbg(INS_TO_USBDEV(sc
), "Entering in R-ACT-REQ state\n");
1725 uea_info(INS_TO_USBDEV(sc
), "modem started, waiting synchronization...\n");
1727 release_firmware(cmvs_fw
);
1731 static int uea_send_cmvs_e4(struct uea_softc
*sc
)
1735 const struct firmware
*cmvs_fw
;
1736 int ver
= 2; // we can only handle v2 cmv firmware version;
1738 /* Enter in R-IDLE (cmv) until instructed otherwise */
1739 ret
= uea_write_cmv_e4(sc
, 1, E4_SA_CNTL
, 0, 0, 1);
1743 /* Dump firmware version */
1744 /* XXX don't read the 3th byte as it is always 6 */
1745 ret
= uea_read_cmv_e4(sc
, 2, E4_SA_INFO
, 55, 0, &sc
->stats
.phy
.firmid
);
1748 uea_info(INS_TO_USBDEV(sc
), "ATU-R firmware version : %x\n",
1749 sc
->stats
.phy
.firmid
);
1753 ret
= len
= request_cmvs(sc
, &cmvs_ptr
, &cmvs_fw
, &ver
);
1759 struct uea_cmvs_v2
*cmvs_v2
= cmvs_ptr
;
1761 for (i
= 0; i
< len
; i
++) {
1762 ret
= uea_write_cmv_e4(sc
, 1,
1763 get_unaligned_le32(&cmvs_v2
[i
].group
),
1764 get_unaligned_le32(&cmvs_v2
[i
].address
),
1765 get_unaligned_le32(&cmvs_v2
[i
].offset
),
1766 get_unaligned_le32(&cmvs_v2
[i
].data
));
1771 /* This realy should not happen */
1772 uea_err(INS_TO_USBDEV(sc
), "bad cmvs version %d\n", ver
);
1776 /* Enter in R-ACT-REQ */
1777 ret
= uea_write_cmv_e4(sc
, 1, E4_SA_CNTL
, 0, 0, 2);
1778 uea_vdbg(INS_TO_USBDEV(sc
), "Entering in R-ACT-REQ state\n");
1779 uea_info(INS_TO_USBDEV(sc
), "modem started, waiting synchronization...\n");
1781 release_firmware(cmvs_fw
);
1785 /* Start boot post firmware modem:
1786 * - send reset commands through usb control pipe
1787 * - start workqueue for DSP loading
1788 * - send CMV options to modem
1791 static int uea_start_reset(struct uea_softc
*sc
)
1793 u16 zero
= 0; /* ;-) */
1796 uea_enters(INS_TO_USBDEV(sc
));
1797 uea_info(INS_TO_USBDEV(sc
), "(re)booting started\n");
1799 /* mask interrupt */
1801 /* We need to set this here because, a ack timeout could have occured,
1802 * but before we start the reboot, the ack occurs and set this to 1.
1803 * So we will failed to wait Ready CMV.
1806 UPDATE_ATM_STAT(signal
, ATM_PHY_SIG_LOST
);
1808 /* reset statistics */
1809 memset(&sc
->stats
, 0, sizeof(struct uea_stats
));
1811 /* tell the modem that we want to boot in IDMA mode */
1812 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_ON
, 0, NULL
);
1813 uea_request(sc
, UEA_SET_MODE
, UEA_BOOT_IDMA
, 0, NULL
);
1815 /* enter reset mode */
1816 uea_request(sc
, UEA_SET_MODE
, UEA_START_RESET
, 0, NULL
);
1818 /* original driver use 200ms, but windows driver use 100ms */
1819 ret
= uea_wait(sc
, 0, msecs_to_jiffies(100));
1823 /* leave reset mode */
1824 uea_request(sc
, UEA_SET_MODE
, UEA_END_RESET
, 0, NULL
);
1826 if (UEA_CHIP_VERSION(sc
) != EAGLE_IV
) {
1827 /* clear tx and rx mailboxes */
1828 uea_request(sc
, UEA_SET_2183_DATA
, UEA_MPTX_MAILBOX
, 2, &zero
);
1829 uea_request(sc
, UEA_SET_2183_DATA
, UEA_MPRX_MAILBOX
, 2, &zero
);
1830 uea_request(sc
, UEA_SET_2183_DATA
, UEA_SWAP_MAILBOX
, 2, &zero
);
1833 ret
= uea_wait(sc
, 0, msecs_to_jiffies(1000));
1837 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
)
1838 sc
->cmv_dsc
.e4
.function
= E4_MAKEFUNCTION(E4_ADSLDIRECTIVE
, E4_MODEMREADY
, 1);
1840 sc
->cmv_dsc
.e1
.function
= E1_MAKEFUNCTION(E1_ADSLDIRECTIVE
, E1_MODEMREADY
);
1842 /* demask interrupt */
1845 /* start loading DSP */
1848 queue_work(sc
->work_q
, &sc
->task
);
1850 /* wait for modem ready CMV */
1851 ret
= wait_cmv_ack(sc
);
1855 uea_vdbg(INS_TO_USBDEV(sc
), "Ready CMV received\n");
1857 ret
= sc
->send_cmvs(sc
);
1862 uea_leaves(INS_TO_USBDEV(sc
));
1867 * In case of an error wait 1s before rebooting the modem
1868 * if the modem don't request reboot (-EAGAIN).
1869 * Monitor the modem every 1s.
1872 static int uea_kthread(void *data
)
1874 struct uea_softc
*sc
= data
;
1878 uea_enters(INS_TO_USBDEV(sc
));
1879 while (!kthread_should_stop()) {
1880 if (ret
< 0 || sc
->reset
)
1881 ret
= uea_start_reset(sc
);
1885 uea_wait(sc
, 0, msecs_to_jiffies(1000));
1888 uea_leaves(INS_TO_USBDEV(sc
));
1892 /* Load second usb firmware for ADI930 chip */
1893 static int load_XILINX_firmware(struct uea_softc
*sc
)
1895 const struct firmware
*fw_entry
;
1896 int ret
, size
, u
, ln
;
1899 char *fw_name
= FW_DIR
"930-fpga.bin";
1901 uea_enters(INS_TO_USBDEV(sc
));
1903 ret
= request_firmware(&fw_entry
, fw_name
, &sc
->usb_dev
->dev
);
1905 uea_err(INS_TO_USBDEV(sc
), "firmware %s is not available\n",
1910 pfw
= fw_entry
->data
;
1911 size
= fw_entry
->size
;
1912 if (size
!= 0x577B) {
1913 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n",
1918 for (u
= 0; u
< size
; u
+= ln
) {
1919 ln
= min(size
- u
, 64);
1920 ret
= uea_request(sc
, 0xe, 0, ln
, pfw
+ u
);
1922 uea_err(INS_TO_USBDEV(sc
),
1923 "elsa download data failed (%d)\n", ret
);
1928 /* finish to send the fpga */
1929 ret
= uea_request(sc
, 0xe, 1, 0, NULL
);
1931 uea_err(INS_TO_USBDEV(sc
),
1932 "elsa download data failed (%d)\n", ret
);
1936 /* Tell the modem we finish : de-assert reset */
1938 ret
= uea_send_modem_cmd(sc
->usb_dev
, 0xe, 1, &value
);
1940 uea_err(sc
->usb_dev
, "elsa de-assert failed with error %d\n", ret
);
1943 release_firmware(fw_entry
);
1945 uea_leaves(INS_TO_USBDEV(sc
));
1949 /* The modem send us an ack. First with check if it right */
1950 static void uea_dispatch_cmv_e1(struct uea_softc
*sc
, struct intr_pkt
*intr
)
1952 struct cmv_dsc_e1
*dsc
= &sc
->cmv_dsc
.e1
;
1953 struct cmv_e1
*cmv
= &intr
->u
.e1
.s2
.cmv
;
1955 uea_enters(INS_TO_USBDEV(sc
));
1956 if (le16_to_cpu(cmv
->wPreamble
) != E1_PREAMBLE
)
1959 if (cmv
->bDirection
!= E1_MODEMTOHOST
)
1962 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1963 * the first MEMACCESS cmv. Ignore it...
1965 if (cmv
->bFunction
!= dsc
->function
) {
1966 if (UEA_CHIP_VERSION(sc
) == ADI930
1967 && cmv
->bFunction
== E1_MAKEFUNCTION(2, 2)) {
1968 cmv
->wIndex
= cpu_to_le16(dsc
->idx
);
1969 put_unaligned_le32(dsc
->address
, &cmv
->dwSymbolicAddress
);
1970 cmv
->wOffsetAddress
= cpu_to_le16(dsc
->offset
);
1975 if (cmv
->bFunction
== E1_MAKEFUNCTION(E1_ADSLDIRECTIVE
, E1_MODEMREADY
)) {
1976 wake_up_cmv_ack(sc
);
1977 uea_leaves(INS_TO_USBDEV(sc
));
1981 /* in case of MEMACCESS */
1982 if (le16_to_cpu(cmv
->wIndex
) != dsc
->idx
||
1983 get_unaligned_le32(&cmv
->dwSymbolicAddress
) != dsc
->address
||
1984 le16_to_cpu(cmv
->wOffsetAddress
) != dsc
->offset
)
1987 sc
->data
= get_unaligned_le32(&cmv
->dwData
);
1988 sc
->data
= sc
->data
<< 16 | sc
->data
>> 16;
1990 wake_up_cmv_ack(sc
);
1991 uea_leaves(INS_TO_USBDEV(sc
));
1995 uea_err(INS_TO_USBDEV(sc
), "unexpected cmv received, "
1996 "Function : %d, Subfunction : %d\n",
1997 E1_FUNCTION_TYPE(cmv
->bFunction
),
1998 E1_FUNCTION_SUBTYPE(cmv
->bFunction
));
1999 uea_leaves(INS_TO_USBDEV(sc
));
2003 uea_err(INS_TO_USBDEV(sc
), "invalid cmv received, "
2004 "wPreamble %d, bDirection %d\n",
2005 le16_to_cpu(cmv
->wPreamble
), cmv
->bDirection
);
2006 uea_leaves(INS_TO_USBDEV(sc
));
2009 /* The modem send us an ack. First with check if it right */
2010 static void uea_dispatch_cmv_e4(struct uea_softc
*sc
, struct intr_pkt
*intr
)
2012 struct cmv_dsc_e4
*dsc
= &sc
->cmv_dsc
.e4
;
2013 struct cmv_e4
*cmv
= &intr
->u
.e4
.s2
.cmv
;
2015 uea_enters(INS_TO_USBDEV(sc
));
2016 uea_dbg(INS_TO_USBDEV(sc
), "cmv %x %x %x %x %x %x\n",
2017 be16_to_cpu(cmv
->wGroup
), be16_to_cpu(cmv
->wFunction
),
2018 be16_to_cpu(cmv
->wOffset
), be16_to_cpu(cmv
->wAddress
),
2019 be32_to_cpu(cmv
->dwData
[0]), be32_to_cpu(cmv
->dwData
[1]));
2021 if (be16_to_cpu(cmv
->wFunction
) != dsc
->function
)
2024 if (be16_to_cpu(cmv
->wFunction
) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE
, E4_MODEMREADY
, 1)) {
2025 wake_up_cmv_ack(sc
);
2026 uea_leaves(INS_TO_USBDEV(sc
));
2030 /* in case of MEMACCESS */
2031 if (be16_to_cpu(cmv
->wOffset
) != dsc
->offset
||
2032 be16_to_cpu(cmv
->wGroup
) != dsc
->group
||
2033 be16_to_cpu(cmv
->wAddress
) != dsc
->address
)
2036 sc
->data
= be32_to_cpu(cmv
->dwData
[0]);
2037 sc
->data1
= be32_to_cpu(cmv
->dwData
[1]);
2038 wake_up_cmv_ack(sc
);
2039 uea_leaves(INS_TO_USBDEV(sc
));
2043 uea_err(INS_TO_USBDEV(sc
), "unexpected cmv received, "
2044 "Function : %d, Subfunction : %d\n",
2045 E4_FUNCTION_TYPE(cmv
->wFunction
),
2046 E4_FUNCTION_SUBTYPE(cmv
->wFunction
));
2047 uea_leaves(INS_TO_USBDEV(sc
));
2051 static void uea_schedule_load_page_e1(struct uea_softc
*sc
, struct intr_pkt
*intr
)
2053 sc
->pageno
= intr
->e1_bSwapPageNo
;
2054 sc
->ovl
= intr
->e1_bOvl
>> 4 | intr
->e1_bOvl
<< 4;
2055 queue_work(sc
->work_q
, &sc
->task
);
2058 static void uea_schedule_load_page_e4(struct uea_softc
*sc
, struct intr_pkt
*intr
)
2060 sc
->pageno
= intr
->e4_bSwapPageNo
;
2061 queue_work(sc
->work_q
, &sc
->task
);
2067 static void uea_intr(struct urb
*urb
)
2069 struct uea_softc
*sc
= urb
->context
;
2070 struct intr_pkt
*intr
= urb
->transfer_buffer
;
2071 int status
= urb
->status
;
2073 uea_enters(INS_TO_USBDEV(sc
));
2075 if (unlikely(status
< 0)) {
2076 uea_err(INS_TO_USBDEV(sc
), "uea_intr() failed with %d\n",
2081 /* device-to-host interrupt */
2082 if (intr
->bType
!= 0x08 || sc
->booting
) {
2083 uea_err(INS_TO_USBDEV(sc
), "wrong interrupt\n");
2087 switch (le16_to_cpu(intr
->wInterrupt
)) {
2088 case INT_LOADSWAPPAGE
:
2089 sc
->schedule_load_page(sc
, intr
);
2092 case INT_INCOMINGCMV
:
2093 sc
->dispatch_cmv(sc
, intr
);
2097 uea_err(INS_TO_USBDEV(sc
), "unknown interrupt %u\n",
2098 le16_to_cpu(intr
->wInterrupt
));
2102 usb_submit_urb(sc
->urb_int
, GFP_ATOMIC
);
2106 * Start the modem : init the data and start kernel thread
2108 static int uea_boot(struct uea_softc
*sc
)
2111 struct intr_pkt
*intr
;
2113 uea_enters(INS_TO_USBDEV(sc
));
2115 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
2116 size
= E4_INTR_PKT_SIZE
;
2117 sc
->dispatch_cmv
= uea_dispatch_cmv_e4
;
2118 sc
->schedule_load_page
= uea_schedule_load_page_e4
;
2119 sc
->stat
= uea_stat_e4
;
2120 sc
->send_cmvs
= uea_send_cmvs_e4
;
2121 INIT_WORK(&sc
->task
, uea_load_page_e4
);
2123 size
= E1_INTR_PKT_SIZE
;
2124 sc
->dispatch_cmv
= uea_dispatch_cmv_e1
;
2125 sc
->schedule_load_page
= uea_schedule_load_page_e1
;
2126 sc
->stat
= uea_stat_e1
;
2127 sc
->send_cmvs
= uea_send_cmvs_e1
;
2128 INIT_WORK(&sc
->task
, uea_load_page_e1
);
2131 init_waitqueue_head(&sc
->sync_q
);
2133 sc
->work_q
= create_workqueue("ueagle-dsp");
2135 uea_err(INS_TO_USBDEV(sc
), "cannot allocate workqueue\n");
2136 uea_leaves(INS_TO_USBDEV(sc
));
2140 if (UEA_CHIP_VERSION(sc
) == ADI930
)
2141 load_XILINX_firmware(sc
);
2143 intr
= kmalloc(size
, GFP_KERNEL
);
2145 uea_err(INS_TO_USBDEV(sc
),
2146 "cannot allocate interrupt package\n");
2150 sc
->urb_int
= usb_alloc_urb(0, GFP_KERNEL
);
2152 uea_err(INS_TO_USBDEV(sc
), "cannot allocate interrupt URB\n");
2156 usb_fill_int_urb(sc
->urb_int
, sc
->usb_dev
,
2157 usb_rcvintpipe(sc
->usb_dev
, UEA_INTR_PIPE
),
2158 intr
, size
, uea_intr
, sc
,
2159 sc
->usb_dev
->actconfig
->interface
[0]->altsetting
[0].
2160 endpoint
[0].desc
.bInterval
);
2162 ret
= usb_submit_urb(sc
->urb_int
, GFP_KERNEL
);
2164 uea_err(INS_TO_USBDEV(sc
),
2165 "urb submition failed with error %d\n", ret
);
2169 sc
->kthread
= kthread_run(uea_kthread
, sc
, "ueagle-atm");
2170 if (sc
->kthread
== ERR_PTR(-ENOMEM
)) {
2171 uea_err(INS_TO_USBDEV(sc
), "failed to create thread\n");
2175 uea_leaves(INS_TO_USBDEV(sc
));
2179 usb_kill_urb(sc
->urb_int
);
2181 usb_free_urb(sc
->urb_int
);
2185 destroy_workqueue(sc
->work_q
);
2186 uea_leaves(INS_TO_USBDEV(sc
));
2191 * Stop the modem : kill kernel thread and free data
2193 static void uea_stop(struct uea_softc
*sc
)
2196 uea_enters(INS_TO_USBDEV(sc
));
2197 ret
= kthread_stop(sc
->kthread
);
2198 uea_dbg(INS_TO_USBDEV(sc
), "kthread finish with status %d\n", ret
);
2200 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_ON
, 0, NULL
);
2202 usb_kill_urb(sc
->urb_int
);
2203 kfree(sc
->urb_int
->transfer_buffer
);
2204 usb_free_urb(sc
->urb_int
);
2206 /* stop any pending boot process, when no one can schedule work */
2207 destroy_workqueue(sc
->work_q
);
2210 release_firmware(sc
->dsp_firm
);
2211 uea_leaves(INS_TO_USBDEV(sc
));
2214 /* syfs interface */
2215 static struct uea_softc
*dev_to_uea(struct device
*dev
)
2217 struct usb_interface
*intf
;
2218 struct usbatm_data
*usbatm
;
2220 intf
= to_usb_interface(dev
);
2224 usbatm
= usb_get_intfdata(intf
);
2228 return usbatm
->driver_data
;
2231 static ssize_t
read_status(struct device
*dev
, struct device_attribute
*attr
,
2235 struct uea_softc
*sc
;
2237 mutex_lock(&uea_mutex
);
2238 sc
= dev_to_uea(dev
);
2241 ret
= snprintf(buf
, 10, "%08x\n", sc
->stats
.phy
.state
);
2243 mutex_unlock(&uea_mutex
);
2247 static ssize_t
reboot(struct device
*dev
, struct device_attribute
*attr
,
2248 const char *buf
, size_t count
)
2251 struct uea_softc
*sc
;
2253 mutex_lock(&uea_mutex
);
2254 sc
= dev_to_uea(dev
);
2260 mutex_unlock(&uea_mutex
);
2264 static DEVICE_ATTR(stat_status
, S_IWUGO
| S_IRUGO
, read_status
, reboot
);
2266 static ssize_t
read_human_status(struct device
*dev
, struct device_attribute
*attr
,
2271 struct uea_softc
*sc
;
2273 mutex_lock(&uea_mutex
);
2274 sc
= dev_to_uea(dev
);
2278 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
2279 switch (sc
->stats
.phy
.state
) {
2280 case 0x0: /* not yet synchronized */
2286 case 0x5: /* initialization */
2292 case 0x7: /* operational */
2295 case 0x2: /* fail ... */
2298 default: /* unknown */
2303 modem_state
= GET_STATUS(sc
->stats
.phy
.state
);
2305 switch (modem_state
) {
2307 ret
= sprintf(buf
, "Modem is booting\n");
2310 ret
= sprintf(buf
, "Modem is initializing\n");
2313 ret
= sprintf(buf
, "Modem is operational\n");
2316 ret
= sprintf(buf
, "Modem synchronization failed\n");
2319 ret
= sprintf(buf
, "Modem state is unknown\n");
2323 mutex_unlock(&uea_mutex
);
2327 static DEVICE_ATTR(stat_human_status
, S_IWUGO
| S_IRUGO
, read_human_status
, NULL
);
2329 static ssize_t
read_delin(struct device
*dev
, struct device_attribute
*attr
,
2333 struct uea_softc
*sc
;
2334 char *delin
= "GOOD";
2336 mutex_lock(&uea_mutex
);
2337 sc
= dev_to_uea(dev
);
2341 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
2342 if (sc
->stats
.phy
.flags
& 0x4000)
2344 else if (sc
->stats
.phy
.flags
& 0x0001)
2347 if (sc
->stats
.phy
.flags
& 0x0C00)
2349 else if (sc
->stats
.phy
.flags
& 0x0030)
2353 ret
= sprintf(buf
, "%s\n", delin
);
2355 mutex_unlock(&uea_mutex
);
2359 static DEVICE_ATTR(stat_delin
, S_IWUGO
| S_IRUGO
, read_delin
, NULL
);
2361 #define UEA_ATTR(name, reset) \
2363 static ssize_t read_##name(struct device *dev, \
2364 struct device_attribute *attr, char *buf) \
2366 int ret = -ENODEV; \
2367 struct uea_softc *sc; \
2369 mutex_lock(&uea_mutex); \
2370 sc = dev_to_uea(dev); \
2373 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2375 sc->stats.phy.name = 0; \
2377 mutex_unlock(&uea_mutex); \
2381 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2383 UEA_ATTR(mflags
, 1);
2384 UEA_ATTR(vidcpe
, 0);
2385 UEA_ATTR(usrate
, 0);
2386 UEA_ATTR(dsrate
, 0);
2387 UEA_ATTR(usattenuation
, 0);
2388 UEA_ATTR(dsattenuation
, 0);
2389 UEA_ATTR(usmargin
, 0);
2390 UEA_ATTR(dsmargin
, 0);
2391 UEA_ATTR(txflow
, 0);
2392 UEA_ATTR(rxflow
, 0);
2393 UEA_ATTR(uscorr
, 0);
2394 UEA_ATTR(dscorr
, 0);
2397 UEA_ATTR(firmid
, 0);
2399 /* Retrieve the device End System Identifier (MAC) */
2401 #define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
2402 static int uea_getesi(struct uea_softc
*sc
, u_char
* esi
)
2404 unsigned char mac_str
[2 * ETH_ALEN
+ 1];
2407 (sc
->usb_dev
, sc
->usb_dev
->descriptor
.iSerialNumber
, mac_str
,
2408 sizeof(mac_str
)) != 2 * ETH_ALEN
)
2411 for (i
= 0; i
< ETH_ALEN
; i
++)
2412 esi
[i
] = htoi(mac_str
[2 * i
]) * 16 + htoi(mac_str
[2 * i
+ 1]);
2418 static int uea_atm_open(struct usbatm_data
*usbatm
, struct atm_dev
*atm_dev
)
2420 struct uea_softc
*sc
= usbatm
->driver_data
;
2422 return uea_getesi(sc
, atm_dev
->esi
);
2425 static int uea_heavy(struct usbatm_data
*usbatm
, struct usb_interface
*intf
)
2427 struct uea_softc
*sc
= usbatm
->driver_data
;
2429 wait_event_interruptible(sc
->sync_q
, IS_OPERATIONAL(sc
));
2435 static int claim_interface(struct usb_device
*usb_dev
,
2436 struct usbatm_data
*usbatm
, int ifnum
)
2439 struct usb_interface
*intf
= usb_ifnum_to_if(usb_dev
, ifnum
);
2442 uea_err(usb_dev
, "interface %d not found\n", ifnum
);
2446 ret
= usb_driver_claim_interface(&uea_driver
, intf
, usbatm
);
2448 uea_err(usb_dev
, "can't claim interface %d, error %d\n", ifnum
,
2453 static struct attribute
*attrs
[] = {
2454 &dev_attr_stat_status
.attr
,
2455 &dev_attr_stat_mflags
.attr
,
2456 &dev_attr_stat_human_status
.attr
,
2457 &dev_attr_stat_delin
.attr
,
2458 &dev_attr_stat_vidcpe
.attr
,
2459 &dev_attr_stat_usrate
.attr
,
2460 &dev_attr_stat_dsrate
.attr
,
2461 &dev_attr_stat_usattenuation
.attr
,
2462 &dev_attr_stat_dsattenuation
.attr
,
2463 &dev_attr_stat_usmargin
.attr
,
2464 &dev_attr_stat_dsmargin
.attr
,
2465 &dev_attr_stat_txflow
.attr
,
2466 &dev_attr_stat_rxflow
.attr
,
2467 &dev_attr_stat_uscorr
.attr
,
2468 &dev_attr_stat_dscorr
.attr
,
2469 &dev_attr_stat_usunc
.attr
,
2470 &dev_attr_stat_dsunc
.attr
,
2471 &dev_attr_stat_firmid
.attr
,
2474 static struct attribute_group attr_grp
= {
2478 static int uea_bind(struct usbatm_data
*usbatm
, struct usb_interface
*intf
,
2479 const struct usb_device_id
*id
)
2481 struct usb_device
*usb
= interface_to_usbdev(intf
);
2482 struct uea_softc
*sc
;
2483 int ret
, ifnum
= intf
->altsetting
->desc
.bInterfaceNumber
;
2488 /* interface 0 is for firmware/monitoring */
2489 if (ifnum
!= UEA_INTR_IFACE_NO
)
2492 usbatm
->flags
= (sync_wait
[modem_index
] ? 0 : UDSL_SKIP_HEAVY_INIT
);
2494 /* interface 1 is for outbound traffic */
2495 ret
= claim_interface(usb
, usbatm
, UEA_US_IFACE_NO
);
2499 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
2500 if (UEA_CHIP_VERSION(id
) != ADI930
) {
2501 /* interface 2 is for inbound traffic */
2502 ret
= claim_interface(usb
, usbatm
, UEA_DS_IFACE_NO
);
2507 sc
= kzalloc(sizeof(struct uea_softc
), GFP_KERNEL
);
2509 uea_err(usb
, "uea_init: not enough memory !\n");
2514 usbatm
->driver_data
= sc
;
2515 sc
->usbatm
= usbatm
;
2516 sc
->modem_index
= (modem_index
< NB_MODEM
) ? modem_index
++ : 0;
2517 sc
->driver_info
= id
->driver_info
;
2519 /* first try to use module parameter */
2520 if (annex
[sc
->modem_index
] == 1)
2522 else if (annex
[sc
->modem_index
] == 2)
2524 /* try to autodetect annex */
2525 else if (sc
->driver_info
& AUTO_ANNEX_A
)
2527 else if (sc
->driver_info
& AUTO_ANNEX_B
)
2530 sc
->annex
= (le16_to_cpu(sc
->usb_dev
->descriptor
.bcdDevice
) & 0x80)?ANNEXB
:ANNEXA
;
2532 alt
= altsetting
[sc
->modem_index
];
2533 /* ADI930 don't support iso */
2534 if (UEA_CHIP_VERSION(id
) != ADI930
&& alt
> 0) {
2535 if (alt
<= 8 && usb_set_interface(usb
, UEA_DS_IFACE_NO
, alt
) == 0) {
2536 uea_dbg(usb
, "set alternate %u for 2 interface\n", alt
);
2537 uea_info(usb
, "using iso mode\n");
2538 usbatm
->flags
|= UDSL_USE_ISOC
| UDSL_IGNORE_EILSEQ
;
2540 uea_err(usb
, "setting alternate %u failed for "
2541 "2 interface, using bulk mode\n", alt
);
2545 ret
= sysfs_create_group(&intf
->dev
.kobj
, &attr_grp
);
2556 sysfs_remove_group(&intf
->dev
.kobj
, &attr_grp
);
2562 static void uea_unbind(struct usbatm_data
*usbatm
, struct usb_interface
*intf
)
2564 struct uea_softc
*sc
= usbatm
->driver_data
;
2566 sysfs_remove_group(&intf
->dev
.kobj
, &attr_grp
);
2571 static struct usbatm_driver uea_usbatm_driver
= {
2572 .driver_name
= "ueagle-atm",
2574 .atm_start
= uea_atm_open
,
2575 .unbind
= uea_unbind
,
2576 .heavy_init
= uea_heavy
,
2577 .bulk_in
= UEA_BULK_DATA_PIPE
,
2578 .bulk_out
= UEA_BULK_DATA_PIPE
,
2579 .isoc_in
= UEA_ISO_DATA_PIPE
,
2582 static int uea_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
2584 struct usb_device
*usb
= interface_to_usbdev(intf
);
2587 uea_info(usb
, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2588 le16_to_cpu(usb
->descriptor
.idVendor
),
2589 le16_to_cpu(usb
->descriptor
.idProduct
),
2590 le16_to_cpu(usb
->descriptor
.bcdDevice
),
2591 chip_name
[UEA_CHIP_VERSION(id
)]);
2593 usb_reset_device(usb
);
2595 if (UEA_IS_PREFIRM(id
))
2596 return uea_load_firmware(usb
, UEA_CHIP_VERSION(id
));
2598 return usbatm_usb_probe(intf
, id
, &uea_usbatm_driver
);
2601 static void uea_disconnect(struct usb_interface
*intf
)
2603 struct usb_device
*usb
= interface_to_usbdev(intf
);
2604 int ifnum
= intf
->altsetting
->desc
.bInterfaceNumber
;
2607 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2608 * Pre-firmware device has one interface
2610 if (usb
->config
->desc
.bNumInterfaces
!= 1 && ifnum
== 0) {
2611 mutex_lock(&uea_mutex
);
2612 usbatm_usb_disconnect(intf
);
2613 mutex_unlock(&uea_mutex
);
2614 uea_info(usb
, "ADSL device removed\n");
2621 * List of supported VID/PID
2623 static const struct usb_device_id uea_ids
[] = {
2624 {USB_DEVICE(ANALOG_VID
, ADI930_PID_PREFIRM
), .driver_info
= ADI930
| PREFIRM
},
2625 {USB_DEVICE(ANALOG_VID
, ADI930_PID_PSTFIRM
), .driver_info
= ADI930
| PSTFIRM
},
2626 {USB_DEVICE(ANALOG_VID
, EAGLE_I_PID_PREFIRM
), .driver_info
= EAGLE_I
| PREFIRM
},
2627 {USB_DEVICE(ANALOG_VID
, EAGLE_I_PID_PSTFIRM
), .driver_info
= EAGLE_I
| PSTFIRM
},
2628 {USB_DEVICE(ANALOG_VID
, EAGLE_II_PID_PREFIRM
), .driver_info
= EAGLE_II
| PREFIRM
},
2629 {USB_DEVICE(ANALOG_VID
, EAGLE_II_PID_PSTFIRM
), .driver_info
= EAGLE_II
| PSTFIRM
},
2630 {USB_DEVICE(ANALOG_VID
, EAGLE_IIC_PID_PREFIRM
), .driver_info
= EAGLE_II
| PREFIRM
},
2631 {USB_DEVICE(ANALOG_VID
, EAGLE_IIC_PID_PSTFIRM
), .driver_info
= EAGLE_II
| PSTFIRM
},
2632 {USB_DEVICE(ANALOG_VID
, EAGLE_III_PID_PREFIRM
), .driver_info
= EAGLE_III
| PREFIRM
},
2633 {USB_DEVICE(ANALOG_VID
, EAGLE_III_PID_PSTFIRM
), .driver_info
= EAGLE_III
| PSTFIRM
},
2634 {USB_DEVICE(ANALOG_VID
, EAGLE_IV_PID_PREFIRM
), .driver_info
= EAGLE_IV
| PREFIRM
},
2635 {USB_DEVICE(ANALOG_VID
, EAGLE_IV_PID_PSTFIRM
), .driver_info
= EAGLE_IV
| PSTFIRM
},
2636 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_A_PID_PREFIRM
), .driver_info
= EAGLE_I
| PREFIRM
},
2637 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_A_PID_PSTFIRM
), .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_A
},
2638 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_B_PID_PREFIRM
), .driver_info
= EAGLE_I
| PREFIRM
},
2639 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_B_PID_PSTFIRM
), .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_B
},
2640 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_A_PID_PREFIRM
), .driver_info
= EAGLE_II
| PREFIRM
},
2641 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_A_PID_PSTFIRM
), .driver_info
= EAGLE_II
| PSTFIRM
| AUTO_ANNEX_A
},
2642 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_B_PID_PREFIRM
), .driver_info
= EAGLE_II
| PREFIRM
},
2643 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_B_PID_PSTFIRM
), .driver_info
= EAGLE_II
| PSTFIRM
| AUTO_ANNEX_B
},
2644 {USB_DEVICE(ELSA_VID
, ELSA_PID_PREFIRM
), .driver_info
= ADI930
| PREFIRM
},
2645 {USB_DEVICE(ELSA_VID
, ELSA_PID_PSTFIRM
), .driver_info
= ADI930
| PSTFIRM
},
2646 {USB_DEVICE(ELSA_VID
, ELSA_PID_A_PREFIRM
), .driver_info
= ADI930
| PREFIRM
},
2647 {USB_DEVICE(ELSA_VID
, ELSA_PID_A_PSTFIRM
), .driver_info
= ADI930
| PSTFIRM
| AUTO_ANNEX_A
},
2648 {USB_DEVICE(ELSA_VID
, ELSA_PID_B_PREFIRM
), .driver_info
= ADI930
| PREFIRM
},
2649 {USB_DEVICE(ELSA_VID
, ELSA_PID_B_PSTFIRM
), .driver_info
= ADI930
| PSTFIRM
| AUTO_ANNEX_B
},
2650 {USB_DEVICE(USR_VID
, MILLER_A_PID_PREFIRM
), .driver_info
= EAGLE_I
| PREFIRM
},
2651 {USB_DEVICE(USR_VID
, MILLER_A_PID_PSTFIRM
), .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_A
},
2652 {USB_DEVICE(USR_VID
, MILLER_B_PID_PREFIRM
), .driver_info
= EAGLE_I
| PREFIRM
},
2653 {USB_DEVICE(USR_VID
, MILLER_B_PID_PSTFIRM
), .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_B
},
2654 {USB_DEVICE(USR_VID
, HEINEKEN_A_PID_PREFIRM
),.driver_info
= EAGLE_I
| PREFIRM
},
2655 {USB_DEVICE(USR_VID
, HEINEKEN_A_PID_PSTFIRM
),.driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_A
},
2656 {USB_DEVICE(USR_VID
, HEINEKEN_B_PID_PREFIRM
),.driver_info
= EAGLE_I
| PREFIRM
},
2657 {USB_DEVICE(USR_VID
, HEINEKEN_B_PID_PSTFIRM
),.driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_B
},
2662 * USB driver descriptor
2664 static struct usb_driver uea_driver
= {
2665 .name
= "ueagle-atm",
2666 .id_table
= uea_ids
,
2668 .disconnect
= uea_disconnect
,
2671 MODULE_DEVICE_TABLE(usb
, uea_ids
);
2674 * uea_init - Initialize the module.
2675 * Register to USB subsystem
2677 static int __init
uea_init(void)
2679 printk(KERN_INFO
"[ueagle-atm] driver " EAGLEUSBVERSION
" loaded\n");
2681 usb_register(&uea_driver
);
2686 module_init(uea_init
);
2689 * uea_exit - Destroy module
2690 * Deregister with USB subsystem
2692 static void __exit
uea_exit(void)
2695 * This calls automatically the uea_disconnect method if necessary:
2697 usb_deregister(&uea_driver
);
2699 printk(KERN_INFO
"[ueagle-atm] driver unloaded\n");
2702 module_exit(uea_exit
);
2704 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2705 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2706 MODULE_LICENSE("Dual BSD/GPL");