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/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/mutex.h>
67 #include <linux/freezer.h>
68 #include <linux/slab.h>
69 #include <linux/kernel.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 */
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
;
173 const struct firmware
*dsp_firm
;
176 void (*dispatch_cmv
) (struct uea_softc
*, struct intr_pkt
*);
177 void (*schedule_load_page
) (struct uea_softc
*, struct intr_pkt
*);
178 int (*stat
) (struct uea_softc
*);
179 int (*send_cmvs
) (struct uea_softc
*);
181 /* keep in sync with eaglectl */
209 #define ELSA_VID 0x05CC
210 #define ELSA_PID_PSTFIRM 0x3350
211 #define ELSA_PID_PREFIRM 0x3351
213 #define ELSA_PID_A_PREFIRM 0x3352
214 #define ELSA_PID_A_PSTFIRM 0x3353
215 #define ELSA_PID_B_PREFIRM 0x3362
216 #define ELSA_PID_B_PSTFIRM 0x3363
219 * Devolo IDs : pots if (pid & 0x10)
221 #define DEVOLO_VID 0x1039
222 #define DEVOLO_EAGLE_I_A_PID_PSTFIRM 0x2110
223 #define DEVOLO_EAGLE_I_A_PID_PREFIRM 0x2111
225 #define DEVOLO_EAGLE_I_B_PID_PSTFIRM 0x2100
226 #define DEVOLO_EAGLE_I_B_PID_PREFIRM 0x2101
228 #define DEVOLO_EAGLE_II_A_PID_PSTFIRM 0x2130
229 #define DEVOLO_EAGLE_II_A_PID_PREFIRM 0x2131
231 #define DEVOLO_EAGLE_II_B_PID_PSTFIRM 0x2120
232 #define DEVOLO_EAGLE_II_B_PID_PREFIRM 0x2121
235 * Reference design USB IDs
237 #define ANALOG_VID 0x1110
238 #define ADI930_PID_PREFIRM 0x9001
239 #define ADI930_PID_PSTFIRM 0x9000
241 #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
242 #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
244 #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
245 #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
247 #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
248 #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
250 #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
251 #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
253 #define EAGLE_IV_PID_PREFIRM 0x9042 /* Eagle IV */
254 #define EAGLE_IV_PID_PSTFIRM 0x9041 /* Eagle IV */
259 #define USR_VID 0x0BAF
260 #define MILLER_A_PID_PREFIRM 0x00F2
261 #define MILLER_A_PID_PSTFIRM 0x00F1
262 #define MILLER_B_PID_PREFIRM 0x00FA
263 #define MILLER_B_PID_PSTFIRM 0x00F9
264 #define HEINEKEN_A_PID_PREFIRM 0x00F6
265 #define HEINEKEN_A_PID_PSTFIRM 0x00F5
266 #define HEINEKEN_B_PID_PREFIRM 0x00F8
267 #define HEINEKEN_B_PID_PSTFIRM 0x00F7
270 #define PSTFIRM (1<<7)
271 #define AUTO_ANNEX_A (1<<8)
272 #define AUTO_ANNEX_B (1<<9)
282 /* macros for both struct usb_device_id and struct uea_softc */
283 #define UEA_IS_PREFIRM(x) \
284 (!((x)->driver_info & PSTFIRM))
285 #define UEA_CHIP_VERSION(x) \
286 ((x)->driver_info & 0xf)
289 ((x)->annex & ANNEXB)
291 #define INS_TO_USBDEV(ins) (ins->usb_dev)
293 #define GET_STATUS(data) \
296 #define IS_OPERATIONAL(sc) \
297 ((UEA_CHIP_VERSION(sc) != EAGLE_IV) ? \
298 (GET_STATUS(sc->stats.phy.state) == 2) : \
299 (sc->stats.phy.state == 7))
302 * Set of macros to handle unaligned data in the firmware blob.
303 * The FW_GET_BYTE() macro is provided only for consistency.
306 #define FW_GET_BYTE(p) (*((__u8 *) (p)))
308 #define FW_DIR "ueagle-atm/"
309 #define EAGLE_FIRMWARE FW_DIR "eagle.fw"
310 #define ADI930_FIRMWARE FW_DIR "adi930.fw"
311 #define EAGLE_I_FIRMWARE FW_DIR "eagleI.fw"
312 #define EAGLE_II_FIRMWARE FW_DIR "eagleII.fw"
313 #define EAGLE_III_FIRMWARE FW_DIR "eagleIII.fw"
314 #define EAGLE_IV_FIRMWARE FW_DIR "eagleIV.fw"
316 #define DSP4I_FIRMWARE FW_DIR "DSP4i.bin"
317 #define DSP4P_FIRMWARE FW_DIR "DSP4p.bin"
318 #define DSP9I_FIRMWARE FW_DIR "DSP9i.bin"
319 #define DSP9P_FIRMWARE FW_DIR "DSP9p.bin"
320 #define DSPEI_FIRMWARE FW_DIR "DSPei.bin"
321 #define DSPEP_FIRMWARE FW_DIR "DSPep.bin"
322 #define FPGA930_FIRMWARE FW_DIR "930-fpga.bin"
324 #define CMV4P_FIRMWARE FW_DIR "CMV4p.bin"
325 #define CMV4PV2_FIRMWARE FW_DIR "CMV4p.bin.v2"
326 #define CMV4I_FIRMWARE FW_DIR "CMV4i.bin"
327 #define CMV4IV2_FIRMWARE FW_DIR "CMV4i.bin.v2"
328 #define CMV9P_FIRMWARE FW_DIR "CMV9p.bin"
329 #define CMV9PV2_FIRMWARE FW_DIR "CMV9p.bin.v2"
330 #define CMV9I_FIRMWARE FW_DIR "CMV9i.bin"
331 #define CMV9IV2_FIRMWARE FW_DIR "CMV9i.bin.v2"
332 #define CMVEP_FIRMWARE FW_DIR "CMVep.bin"
333 #define CMVEPV2_FIRMWARE FW_DIR "CMVep.bin.v2"
334 #define CMVEI_FIRMWARE FW_DIR "CMVei.bin"
335 #define CMVEIV2_FIRMWARE FW_DIR "CMVei.bin.v2"
337 #define UEA_FW_NAME_MAX 30
340 #define BULK_TIMEOUT 300
341 #define CTRL_TIMEOUT 1000
343 #define ACK_TIMEOUT msecs_to_jiffies(3000)
345 #define UEA_INTR_IFACE_NO 0
346 #define UEA_US_IFACE_NO 1
347 #define UEA_DS_IFACE_NO 2
349 #define FASTEST_ISO_INTF 8
351 #define UEA_BULK_DATA_PIPE 0x02
352 #define UEA_IDMA_PIPE 0x04
353 #define UEA_INTR_PIPE 0x04
354 #define UEA_ISO_DATA_PIPE 0x08
356 #define UEA_E1_SET_BLOCK 0x0001
357 #define UEA_E4_SET_BLOCK 0x002c
358 #define UEA_SET_MODE 0x0003
359 #define UEA_SET_2183_DATA 0x0004
360 #define UEA_SET_TIMEOUT 0x0011
362 #define UEA_LOOPBACK_OFF 0x0002
363 #define UEA_LOOPBACK_ON 0x0003
364 #define UEA_BOOT_IDMA 0x0006
365 #define UEA_START_RESET 0x0007
366 #define UEA_END_RESET 0x0008
368 #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
369 #define UEA_MPTX_START (0x3fce | 0x4000)
370 #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
371 #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
373 /* block information in eagle4 dsp firmware */
384 #define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
385 #define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
387 #define E4_L1_STRING_HEADER 0x10
388 #define E4_MAX_PAGE_NUMBER 0x58
389 #define E4_NO_SWAPPAGE_HEADERS 0x31
391 /* l1_code is eagle4 dsp firmware format */
393 u8 string_header
[E4_L1_STRING_HEADER
];
394 u8 page_number_to_block_index
[E4_MAX_PAGE_NUMBER
];
395 struct block_index page_header
[E4_NO_SWAPPAGE_HEADERS
];
399 /* structures describing a block within a DSP page */
400 struct block_info_e1
{
405 __le16 wOvl
; /* overlay */
408 #define E1_BLOCK_INFO_SIZE 12
410 struct block_info_e4
{
418 #define E4_BLOCK_INFO_SIZE 14
420 #define UEA_BIHDR 0xabcd
421 #define UEA_RESERVED 0xffff
423 /* constants describing cmv type */
424 #define E1_PREAMBLE 0x535c
425 #define E1_MODEMTOHOST 0x01
426 #define E1_HOSTTOMODEM 0x10
428 #define E1_MEMACCESS 0x1
429 #define E1_ADSLDIRECTIVE 0x7
430 #define E1_FUNCTION_TYPE(f) ((f) >> 4)
431 #define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f)
433 #define E4_MEMACCESS 0
434 #define E4_ADSLDIRECTIVE 0xf
435 #define E4_FUNCTION_TYPE(f) ((f) >> 8)
436 #define E4_FUNCTION_SIZE(f) ((f) & 0x0f)
437 #define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f)
440 #define E1_REQUESTREAD 0x0
441 #define E1_REQUESTWRITE 0x1
442 #define E1_REPLYREAD 0x2
443 #define E1_REPLYWRITE 0x3
445 #define E4_REQUESTREAD 0x0
446 #define E4_REQUESTWRITE 0x4
447 #define E4_REPLYREAD (E4_REQUESTREAD | 1)
448 #define E4_REPLYWRITE (E4_REQUESTWRITE | 1)
450 /* for ADSLDIRECTIVE */
451 #define E1_KERNELREADY 0x0
452 #define E1_MODEMREADY 0x1
454 #define E4_KERNELREADY 0x0
455 #define E4_MODEMREADY 0x1
457 #define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
458 #define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | \
459 ((st) & 0xf) << 4 | ((s) & 0xf))
461 #define E1_MAKESA(a, b, c, d) \
462 (((c) & 0xff) << 24 | \
463 ((d) & 0xff) << 16 | \
464 ((a) & 0xff) << 8 | \
467 #define E1_GETSA1(a) ((a >> 8) & 0xff)
468 #define E1_GETSA2(a) (a & 0xff)
469 #define E1_GETSA3(a) ((a >> 24) & 0xff)
470 #define E1_GETSA4(a) ((a >> 16) & 0xff)
472 #define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L')
473 #define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G')
474 #define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O')
475 #define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N')
476 #define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E')
477 #define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T')
488 /* structures representing a CMV (Configuration and Management Variable) */
494 __le32 dwSymbolicAddress
;
495 __le16 wOffsetAddress
;
507 /* structures representing swap information */
508 struct swap_info_e1
{
510 __u8 bOvl
; /* overlay */
513 struct swap_info_e4
{
517 /* structures representing interrupt data */
518 #define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
519 #define e1_bOvl u.e1.s1.swapinfo.bOvl
520 #define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo
522 #define INT_LOADSWAPPAGE 0x0001
523 #define INT_INCOMINGCMV 0x0002
527 struct swap_info_e1 swapinfo
;
538 struct swap_info_e4 swapinfo
;
555 union intr_data_e1 e1
;
556 union intr_data_e4 e4
;
560 #define E1_INTR_PKT_SIZE 28
561 #define E4_INTR_PKT_SIZE 64
563 static struct usb_driver uea_driver
;
564 static DEFINE_MUTEX(uea_mutex
);
565 static const char * const chip_name
[] = {
566 "ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
568 static int modem_index
;
569 static unsigned int debug
;
570 static unsigned int altsetting
[NB_MODEM
] = {
571 [0 ... (NB_MODEM
- 1)] = FASTEST_ISO_INTF
};
572 static bool sync_wait
[NB_MODEM
];
573 static char *cmv_file
[NB_MODEM
];
574 static int annex
[NB_MODEM
];
576 module_param(debug
, uint
, 0644);
577 MODULE_PARM_DESC(debug
, "module debug level (0=off,1=on,2=verbose)");
578 module_param_array(altsetting
, uint
, NULL
, 0644);
579 MODULE_PARM_DESC(altsetting
, "alternate setting for incoming traffic: 0=bulk, "
580 "1=isoc slowest, ... , 8=isoc fastest (default)");
581 module_param_array(sync_wait
, bool, NULL
, 0644);
582 MODULE_PARM_DESC(sync_wait
, "wait the synchronisation before starting ATM");
583 module_param_array(cmv_file
, charp
, NULL
, 0644);
584 MODULE_PARM_DESC(cmv_file
,
585 "file name with configuration and management variables");
586 module_param_array(annex
, uint
, NULL
, 0644);
587 MODULE_PARM_DESC(annex
,
588 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
590 #define uea_wait(sc, cond, timeo) \
592 int _r = wait_event_interruptible_timeout(sc->sync_q, \
593 (cond) || kthread_should_stop(), timeo); \
594 if (kthread_should_stop()) \
599 #define UPDATE_ATM_STAT(type, val) \
601 if (sc->usbatm->atm_dev) \
602 sc->usbatm->atm_dev->type = val; \
605 #define UPDATE_ATM_SIGNAL(val) \
607 if (sc->usbatm->atm_dev) \
608 atm_dev_signal_change(sc->usbatm->atm_dev, val); \
612 /* Firmware loading */
613 #define LOAD_INTERNAL 0xA0
614 #define F8051_USBCS 0x7f92
617 * uea_send_modem_cmd - Send a command for pre-firmware devices.
619 static int uea_send_modem_cmd(struct usb_device
*usb
,
620 u16 addr
, u16 size
, const u8
*buff
)
625 xfer_buff
= kmemdup(buff
, size
, GFP_KERNEL
);
627 ret
= usb_control_msg(usb
,
628 usb_sndctrlpipe(usb
, 0),
630 USB_DIR_OUT
| USB_TYPE_VENDOR
|
631 USB_RECIP_DEVICE
, addr
, 0, xfer_buff
,
639 return (ret
== size
) ? 0 : -EIO
;
642 static void uea_upload_pre_firmware(const struct firmware
*fw_entry
,
645 struct usb_device
*usb
= context
;
653 uea_err(usb
, "firmware is not available\n");
657 pfw
= fw_entry
->data
;
658 size
= fw_entry
->size
;
660 goto err_fw_corrupted
;
662 crc
= get_unaligned_le32(pfw
);
665 if (crc32_be(0, pfw
, size
) != crc
)
666 goto err_fw_corrupted
;
669 * Start to upload firmware : send reset
672 ret
= uea_send_modem_cmd(usb
, F8051_USBCS
, sizeof(value
), &value
);
675 uea_err(usb
, "modem reset failed with error %d\n", ret
);
680 u8 len
= FW_GET_BYTE(pfw
);
681 u16 add
= get_unaligned_le16(pfw
+ 1);
685 goto err_fw_corrupted
;
687 ret
= uea_send_modem_cmd(usb
, add
, len
, pfw
+ 3);
689 uea_err(usb
, "uploading firmware data failed "
690 "with error %d\n", ret
);
697 goto err_fw_corrupted
;
700 * Tell the modem we finish : de-assert reset
703 ret
= uea_send_modem_cmd(usb
, F8051_USBCS
, 1, &value
);
705 uea_err(usb
, "modem de-assert failed with error %d\n", ret
);
707 uea_info(usb
, "firmware uploaded\n");
712 uea_err(usb
, "firmware is corrupted\n");
714 release_firmware(fw_entry
);
719 * uea_load_firmware - Load usb firmware for pre-firmware devices.
721 static int uea_load_firmware(struct usb_device
*usb
, unsigned int ver
)
724 char *fw_name
= EAGLE_FIRMWARE
;
727 uea_info(usb
, "pre-firmware device, uploading firmware\n");
731 fw_name
= ADI930_FIRMWARE
;
734 fw_name
= EAGLE_I_FIRMWARE
;
737 fw_name
= EAGLE_II_FIRMWARE
;
740 fw_name
= EAGLE_III_FIRMWARE
;
743 fw_name
= EAGLE_IV_FIRMWARE
;
747 ret
= request_firmware_nowait(THIS_MODULE
, 1, fw_name
, &usb
->dev
,
749 uea_upload_pre_firmware
);
751 uea_err(usb
, "firmware %s is not available\n", fw_name
);
753 uea_info(usb
, "loading firmware %s\n", fw_name
);
759 /* modem management : dsp firmware, send/read CMV, monitoring statistic
763 * Make sure that the DSP code provided is safe to use.
765 static int check_dsp_e1(const u8
*dsp
, unsigned int len
)
767 u8 pagecount
, blockcount
;
770 unsigned int i
, j
, p
, pp
;
772 pagecount
= FW_GET_BYTE(dsp
);
775 /* enough space for page offsets? */
776 if (p
+ 4 * pagecount
> len
)
779 for (i
= 0; i
< pagecount
; i
++) {
781 pageoffset
= get_unaligned_le32(dsp
+ p
);
787 /* enough space for blockcount? */
788 if (pageoffset
>= len
)
792 blockcount
= FW_GET_BYTE(dsp
+ pp
);
795 for (j
= 0; j
< blockcount
; j
++) {
797 /* enough space for block header? */
801 pp
+= 2; /* skip blockaddr */
802 blocksize
= get_unaligned_le16(dsp
+ pp
);
805 /* enough space for block data? */
806 if (pp
+ blocksize
> len
)
816 static int check_dsp_e4(const u8
*dsp
, int len
)
819 struct l1_code
*p
= (struct l1_code
*) dsp
;
820 unsigned int sum
= p
->code
- dsp
;
825 if (strcmp("STRATIPHY ANEXA", p
->string_header
) != 0 &&
826 strcmp("STRATIPHY ANEXB", p
->string_header
) != 0)
829 for (i
= 0; i
< E4_MAX_PAGE_NUMBER
; i
++) {
830 struct block_index
*blockidx
;
831 u8 blockno
= p
->page_number_to_block_index
[i
];
832 if (blockno
>= E4_NO_SWAPPAGE_HEADERS
)
838 if (blockno
>= E4_NO_SWAPPAGE_HEADERS
)
841 blockidx
= &p
->page_header
[blockno
++];
842 if ((u8
*)(blockidx
+ 1) - dsp
>= len
)
845 if (le16_to_cpu(blockidx
->PageNumber
) != i
)
848 l
= E4_PAGE_BYTES(blockidx
->PageSize
);
850 l
+= le32_to_cpu(blockidx
->PageOffset
);
854 /* zero is zero regardless endianes */
855 } while (blockidx
->NotLastBlock
);
858 return (sum
== len
) ? 0 : 1;
862 * send data to the idma pipe
864 static int uea_idma_write(struct uea_softc
*sc
, const void *data
, u32 size
)
870 xfer_buff
= kmemdup(data
, size
, GFP_KERNEL
);
872 uea_err(INS_TO_USBDEV(sc
), "can't allocate xfer_buff\n");
876 ret
= usb_bulk_msg(sc
->usb_dev
,
877 usb_sndbulkpipe(sc
->usb_dev
, UEA_IDMA_PIPE
),
878 xfer_buff
, size
, &bytes_read
, BULK_TIMEOUT
);
883 if (size
!= bytes_read
) {
884 uea_err(INS_TO_USBDEV(sc
), "size != bytes_read %d %d\n", size
,
892 static int request_dsp(struct uea_softc
*sc
)
897 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
899 dsp_name
= DSP4I_FIRMWARE
;
901 dsp_name
= DSP4P_FIRMWARE
;
902 } else if (UEA_CHIP_VERSION(sc
) == ADI930
) {
904 dsp_name
= DSP9I_FIRMWARE
;
906 dsp_name
= DSP9P_FIRMWARE
;
909 dsp_name
= DSPEI_FIRMWARE
;
911 dsp_name
= DSPEP_FIRMWARE
;
914 ret
= request_firmware(&sc
->dsp_firm
, dsp_name
, &sc
->usb_dev
->dev
);
916 uea_err(INS_TO_USBDEV(sc
),
917 "requesting firmware %s failed with error %d\n",
922 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
)
923 ret
= check_dsp_e4(sc
->dsp_firm
->data
, sc
->dsp_firm
->size
);
925 ret
= check_dsp_e1(sc
->dsp_firm
->data
, sc
->dsp_firm
->size
);
928 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n",
930 release_firmware(sc
->dsp_firm
);
939 * The uea_load_page() function must be called within a process context
941 static void uea_load_page_e1(struct work_struct
*work
)
943 struct uea_softc
*sc
= container_of(work
, struct uea_softc
, task
);
944 u16 pageno
= sc
->pageno
;
946 struct block_info_e1 bi
;
949 u8 pagecount
, blockcount
;
950 u16 blockaddr
, blocksize
;
954 /* reload firmware when reboot start and it's loaded already */
955 if (ovl
== 0 && pageno
== 0) {
956 release_firmware(sc
->dsp_firm
);
960 if (sc
->dsp_firm
== NULL
&& request_dsp(sc
) < 0)
963 p
= sc
->dsp_firm
->data
;
964 pagecount
= FW_GET_BYTE(p
);
967 if (pageno
>= pagecount
)
971 pageoffset
= get_unaligned_le32(p
);
976 p
= sc
->dsp_firm
->data
+ pageoffset
;
977 blockcount
= FW_GET_BYTE(p
);
980 uea_dbg(INS_TO_USBDEV(sc
),
981 "sending %u blocks for DSP page %u\n", blockcount
, pageno
);
983 bi
.wHdr
= cpu_to_le16(UEA_BIHDR
);
984 bi
.wOvl
= cpu_to_le16(ovl
);
985 bi
.wOvlOffset
= cpu_to_le16(ovl
| 0x8000);
987 for (i
= 0; i
< blockcount
; i
++) {
988 blockaddr
= get_unaligned_le16(p
);
991 blocksize
= get_unaligned_le16(p
);
994 bi
.wSize
= cpu_to_le16(blocksize
);
995 bi
.wAddress
= cpu_to_le16(blockaddr
);
996 bi
.wLast
= cpu_to_le16((i
== blockcount
- 1) ? 1 : 0);
998 /* send block info through the IDMA pipe */
999 if (uea_idma_write(sc
, &bi
, E1_BLOCK_INFO_SIZE
))
1002 /* send block data through the IDMA pipe */
1003 if (uea_idma_write(sc
, p
, blocksize
))
1012 uea_err(INS_TO_USBDEV(sc
), "sending DSP block %u failed\n", i
);
1015 uea_err(INS_TO_USBDEV(sc
), "invalid DSP page %u requested\n", pageno
);
1018 static void __uea_load_page_e4(struct uea_softc
*sc
, u8 pageno
, int boot
)
1020 struct block_info_e4 bi
;
1021 struct block_index
*blockidx
;
1022 struct l1_code
*p
= (struct l1_code
*) sc
->dsp_firm
->data
;
1023 u8 blockno
= p
->page_number_to_block_index
[pageno
];
1025 bi
.wHdr
= cpu_to_be16(UEA_BIHDR
);
1026 bi
.bBootPage
= boot
;
1027 bi
.bPageNumber
= pageno
;
1028 bi
.wReserved
= cpu_to_be16(UEA_RESERVED
);
1031 const u8
*blockoffset
;
1032 unsigned int blocksize
;
1034 blockidx
= &p
->page_header
[blockno
];
1035 blocksize
= E4_PAGE_BYTES(blockidx
->PageSize
);
1036 blockoffset
= sc
->dsp_firm
->data
+ le32_to_cpu(
1037 blockidx
->PageOffset
);
1039 bi
.dwSize
= cpu_to_be32(blocksize
);
1040 bi
.dwAddress
= cpu_to_be32(le32_to_cpu(blockidx
->PageAddress
));
1042 uea_dbg(INS_TO_USBDEV(sc
),
1043 "sending block %u for DSP page "
1044 "%u size %u address %x\n",
1045 blockno
, pageno
, blocksize
,
1046 le32_to_cpu(blockidx
->PageAddress
));
1048 /* send block info through the IDMA pipe */
1049 if (uea_idma_write(sc
, &bi
, E4_BLOCK_INFO_SIZE
))
1052 /* send block data through the IDMA pipe */
1053 if (uea_idma_write(sc
, blockoffset
, blocksize
))
1057 } while (blockidx
->NotLastBlock
);
1062 uea_err(INS_TO_USBDEV(sc
), "sending DSP block %u failed\n", blockno
);
1066 static void uea_load_page_e4(struct work_struct
*work
)
1068 struct uea_softc
*sc
= container_of(work
, struct uea_softc
, task
);
1069 u8 pageno
= sc
->pageno
;
1071 struct block_info_e4 bi
;
1074 uea_dbg(INS_TO_USBDEV(sc
), "sending DSP page %u\n", pageno
);
1076 /* reload firmware when reboot start and it's loaded already */
1078 release_firmware(sc
->dsp_firm
);
1079 sc
->dsp_firm
= NULL
;
1082 if (sc
->dsp_firm
== NULL
&& request_dsp(sc
) < 0)
1085 p
= (struct l1_code
*) sc
->dsp_firm
->data
;
1086 if (pageno
>= le16_to_cpu(p
->page_header
[0].PageNumber
)) {
1087 uea_err(INS_TO_USBDEV(sc
), "invalid DSP "
1088 "page %u requested\n", pageno
);
1093 __uea_load_page_e4(sc
, pageno
, 0);
1097 uea_dbg(INS_TO_USBDEV(sc
),
1098 "sending Main DSP page %u\n", p
->page_header
[0].PageNumber
);
1100 for (i
= 0; i
< le16_to_cpu(p
->page_header
[0].PageNumber
); i
++) {
1101 if (E4_IS_BOOT_PAGE(p
->page_header
[i
].PageSize
))
1102 __uea_load_page_e4(sc
, i
, 1);
1105 uea_dbg(INS_TO_USBDEV(sc
) , "sending start bi\n");
1107 bi
.wHdr
= cpu_to_be16(UEA_BIHDR
);
1109 bi
.bPageNumber
= 0xff;
1110 bi
.wReserved
= cpu_to_be16(UEA_RESERVED
);
1111 bi
.dwSize
= cpu_to_be32(E4_PAGE_BYTES(p
->page_header
[0].PageSize
));
1112 bi
.dwAddress
= cpu_to_be32(le32_to_cpu(p
->page_header
[0].PageAddress
));
1114 /* send block info through the IDMA pipe */
1115 if (uea_idma_write(sc
, &bi
, E4_BLOCK_INFO_SIZE
))
1116 uea_err(INS_TO_USBDEV(sc
), "sending DSP start bi failed\n");
1119 static inline void wake_up_cmv_ack(struct uea_softc
*sc
)
1121 BUG_ON(sc
->cmv_ack
);
1123 wake_up(&sc
->sync_q
);
1126 static inline int wait_cmv_ack(struct uea_softc
*sc
)
1128 int ret
= uea_wait(sc
, sc
->cmv_ack
, ACK_TIMEOUT
);
1132 uea_dbg(INS_TO_USBDEV(sc
), "wait_event_timeout : %d ms\n",
1133 jiffies_to_msecs(ret
));
1138 return (ret
== 0) ? -ETIMEDOUT
: 0;
1141 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1143 static int uea_request(struct uea_softc
*sc
,
1144 u16 value
, u16 index
, u16 size
, const void *data
)
1149 xfer_buff
= kmemdup(data
, size
, GFP_KERNEL
);
1151 uea_err(INS_TO_USBDEV(sc
), "can't allocate xfer_buff\n");
1155 ret
= usb_control_msg(sc
->usb_dev
, usb_sndctrlpipe(sc
->usb_dev
, 0),
1156 UCDC_SEND_ENCAPSULATED_COMMAND
,
1157 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
1158 value
, index
, xfer_buff
, size
, CTRL_TIMEOUT
);
1162 uea_err(INS_TO_USBDEV(sc
), "usb_control_msg error %d\n", ret
);
1167 uea_err(INS_TO_USBDEV(sc
),
1168 "usb_control_msg send only %d bytes (instead of %d)\n",
1176 static int uea_cmv_e1(struct uea_softc
*sc
,
1177 u8 function
, u32 address
, u16 offset
, u32 data
)
1182 uea_enters(INS_TO_USBDEV(sc
));
1183 uea_vdbg(INS_TO_USBDEV(sc
), "Function : %d-%d, Address : %c%c%c%c, "
1184 "offset : 0x%04x, data : 0x%08x\n",
1185 E1_FUNCTION_TYPE(function
),
1186 E1_FUNCTION_SUBTYPE(function
),
1187 E1_GETSA1(address
), E1_GETSA2(address
),
1189 E1_GETSA4(address
), offset
, data
);
1191 /* we send a request, but we expect a reply */
1192 sc
->cmv_dsc
.e1
.function
= function
| 0x2;
1193 sc
->cmv_dsc
.e1
.idx
++;
1194 sc
->cmv_dsc
.e1
.address
= address
;
1195 sc
->cmv_dsc
.e1
.offset
= offset
;
1197 cmv
.wPreamble
= cpu_to_le16(E1_PREAMBLE
);
1198 cmv
.bDirection
= E1_HOSTTOMODEM
;
1199 cmv
.bFunction
= function
;
1200 cmv
.wIndex
= cpu_to_le16(sc
->cmv_dsc
.e1
.idx
);
1201 put_unaligned_le32(address
, &cmv
.dwSymbolicAddress
);
1202 cmv
.wOffsetAddress
= cpu_to_le16(offset
);
1203 put_unaligned_le32(data
>> 16 | data
<< 16, &cmv
.dwData
);
1205 ret
= uea_request(sc
, UEA_E1_SET_BLOCK
, UEA_MPTX_START
,
1209 ret
= wait_cmv_ack(sc
);
1210 uea_leaves(INS_TO_USBDEV(sc
));
1214 static int uea_cmv_e4(struct uea_softc
*sc
,
1215 u16 function
, u16 group
, u16 address
, u16 offset
, u32 data
)
1220 uea_enters(INS_TO_USBDEV(sc
));
1221 memset(&cmv
, 0, sizeof(cmv
));
1223 uea_vdbg(INS_TO_USBDEV(sc
), "Function : %d-%d, Group : 0x%04x, "
1224 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1225 E4_FUNCTION_TYPE(function
), E4_FUNCTION_SUBTYPE(function
),
1226 group
, address
, offset
, data
);
1228 /* we send a request, but we expect a reply */
1229 sc
->cmv_dsc
.e4
.function
= function
| (0x1 << 4);
1230 sc
->cmv_dsc
.e4
.offset
= offset
;
1231 sc
->cmv_dsc
.e4
.address
= address
;
1232 sc
->cmv_dsc
.e4
.group
= group
;
1234 cmv
.wFunction
= cpu_to_be16(function
);
1235 cmv
.wGroup
= cpu_to_be16(group
);
1236 cmv
.wAddress
= cpu_to_be16(address
);
1237 cmv
.wOffset
= cpu_to_be16(offset
);
1238 cmv
.dwData
[0] = cpu_to_be32(data
);
1240 ret
= uea_request(sc
, UEA_E4_SET_BLOCK
, UEA_MPTX_START
,
1244 ret
= wait_cmv_ack(sc
);
1245 uea_leaves(INS_TO_USBDEV(sc
));
1249 static inline int uea_read_cmv_e1(struct uea_softc
*sc
,
1250 u32 address
, u16 offset
, u32
*data
)
1252 int ret
= uea_cmv_e1(sc
, E1_MAKEFUNCTION(E1_MEMACCESS
, E1_REQUESTREAD
),
1253 address
, offset
, 0);
1255 uea_err(INS_TO_USBDEV(sc
),
1256 "reading cmv failed with error %d\n", ret
);
1263 static inline int uea_read_cmv_e4(struct uea_softc
*sc
,
1264 u8 size
, u16 group
, u16 address
, u16 offset
, u32
*data
)
1266 int ret
= uea_cmv_e4(sc
, E4_MAKEFUNCTION(E4_MEMACCESS
,
1267 E4_REQUESTREAD
, size
),
1268 group
, address
, offset
, 0);
1270 uea_err(INS_TO_USBDEV(sc
),
1271 "reading cmv failed with error %d\n", ret
);
1274 /* size is in 16-bit word quantities */
1276 *(data
+ 1) = sc
->data1
;
1281 static inline int uea_write_cmv_e1(struct uea_softc
*sc
,
1282 u32 address
, u16 offset
, u32 data
)
1284 int ret
= uea_cmv_e1(sc
, E1_MAKEFUNCTION(E1_MEMACCESS
, E1_REQUESTWRITE
),
1285 address
, offset
, data
);
1287 uea_err(INS_TO_USBDEV(sc
),
1288 "writing cmv failed with error %d\n", ret
);
1293 static inline int uea_write_cmv_e4(struct uea_softc
*sc
,
1294 u8 size
, u16 group
, u16 address
, u16 offset
, u32 data
)
1296 int ret
= uea_cmv_e4(sc
, E4_MAKEFUNCTION(E4_MEMACCESS
,
1297 E4_REQUESTWRITE
, size
),
1298 group
, address
, offset
, data
);
1300 uea_err(INS_TO_USBDEV(sc
),
1301 "writing cmv failed with error %d\n", ret
);
1306 static void uea_set_bulk_timeout(struct uea_softc
*sc
, u32 dsrate
)
1311 /* in bulk mode the modem have problem with high rate
1312 * changing internal timing could improve things, but the
1313 * value is mysterious.
1314 * ADI930 don't support it (-EPIPE error).
1317 if (UEA_CHIP_VERSION(sc
) == ADI930
||
1318 altsetting
[sc
->modem_index
] > 0 ||
1319 sc
->stats
.phy
.dsrate
== dsrate
)
1322 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1323 timeout
= (dsrate
<= 1024*1024) ? 0 : 1;
1324 ret
= uea_request(sc
, UEA_SET_TIMEOUT
, timeout
, 0, NULL
);
1325 uea_info(INS_TO_USBDEV(sc
), "setting new timeout %d%s\n",
1326 timeout
, ret
< 0 ? " failed" : "");
1331 * Monitor the modem and update the stat
1332 * return 0 if everything is ok
1333 * return < 0 if an error occurs (-EAGAIN reboot needed)
1335 static int uea_stat_e1(struct uea_softc
*sc
)
1340 uea_enters(INS_TO_USBDEV(sc
));
1341 data
= sc
->stats
.phy
.state
;
1343 ret
= uea_read_cmv_e1(sc
, E1_SA_STAT
, 0, &sc
->stats
.phy
.state
);
1347 switch (GET_STATUS(sc
->stats
.phy
.state
)) {
1348 case 0: /* not yet synchronized */
1349 uea_dbg(INS_TO_USBDEV(sc
),
1350 "modem not yet synchronized\n");
1353 case 1: /* initialization */
1354 uea_dbg(INS_TO_USBDEV(sc
), "modem initializing\n");
1357 case 2: /* operational */
1358 uea_vdbg(INS_TO_USBDEV(sc
), "modem operational\n");
1361 case 3: /* fail ... */
1362 uea_info(INS_TO_USBDEV(sc
), "modem synchronization failed"
1363 " (may be try other cmv/dsp)\n");
1366 case 4 ... 6: /* test state */
1367 uea_warn(INS_TO_USBDEV(sc
),
1368 "modem in test mode - not supported\n");
1371 case 7: /* fast-retain ... */
1372 uea_info(INS_TO_USBDEV(sc
), "modem in fast-retain mode\n");
1375 uea_err(INS_TO_USBDEV(sc
), "modem invalid SW mode %d\n",
1376 GET_STATUS(sc
->stats
.phy
.state
));
1380 if (GET_STATUS(data
) != 2) {
1381 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_OFF
, 0, NULL
);
1382 uea_info(INS_TO_USBDEV(sc
), "modem operational\n");
1384 /* release the dsp firmware as it is not needed until
1387 release_firmware(sc
->dsp_firm
);
1388 sc
->dsp_firm
= NULL
;
1391 /* always update it as atm layer could not be init when we switch to
1394 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND
);
1396 /* wake up processes waiting for synchronization */
1397 wake_up(&sc
->sync_q
);
1399 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 2, &sc
->stats
.phy
.flags
);
1402 sc
->stats
.phy
.mflags
|= sc
->stats
.phy
.flags
;
1404 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1405 * we check the status again in order to detect the failure earlier
1407 if (sc
->stats
.phy
.flags
) {
1408 uea_dbg(INS_TO_USBDEV(sc
), "Stat flag = 0x%x\n",
1409 sc
->stats
.phy
.flags
);
1413 ret
= uea_read_cmv_e1(sc
, E1_SA_RATE
, 0, &data
);
1417 uea_set_bulk_timeout(sc
, (data
>> 16) * 32);
1418 sc
->stats
.phy
.dsrate
= (data
>> 16) * 32;
1419 sc
->stats
.phy
.usrate
= (data
& 0xffff) * 32;
1420 UPDATE_ATM_STAT(link_rate
, sc
->stats
.phy
.dsrate
* 1000 / 424);
1422 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 23, &data
);
1425 sc
->stats
.phy
.dsattenuation
= (data
& 0xff) / 2;
1427 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 47, &data
);
1430 sc
->stats
.phy
.usattenuation
= (data
& 0xff) / 2;
1432 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 25, &sc
->stats
.phy
.dsmargin
);
1436 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 49, &sc
->stats
.phy
.usmargin
);
1440 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 51, &sc
->stats
.phy
.rxflow
);
1444 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 52, &sc
->stats
.phy
.txflow
);
1448 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 54, &sc
->stats
.phy
.dsunc
);
1452 /* only for atu-c */
1453 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 58, &sc
->stats
.phy
.usunc
);
1457 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 53, &sc
->stats
.phy
.dscorr
);
1461 /* only for atu-c */
1462 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 57, &sc
->stats
.phy
.uscorr
);
1466 ret
= uea_read_cmv_e1(sc
, E1_SA_INFO
, 8, &sc
->stats
.phy
.vidco
);
1470 ret
= uea_read_cmv_e1(sc
, E1_SA_INFO
, 13, &sc
->stats
.phy
.vidcpe
);
1477 static int uea_stat_e4(struct uea_softc
*sc
)
1483 uea_enters(INS_TO_USBDEV(sc
));
1484 data
= sc
->stats
.phy
.state
;
1486 /* XXX only need to be done before operationnal... */
1487 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_STAT
, 0, 0, &sc
->stats
.phy
.state
);
1491 switch (sc
->stats
.phy
.state
) {
1492 case 0x0: /* not yet synchronized */
1496 uea_dbg(INS_TO_USBDEV(sc
), "modem not yet "
1499 case 0x5: /* initialization */
1503 uea_dbg(INS_TO_USBDEV(sc
), "modem initializing\n");
1505 case 0x2: /* fail ... */
1506 uea_info(INS_TO_USBDEV(sc
), "modem synchronization "
1507 "failed (may be try other cmv/dsp)\n");
1509 case 0x7: /* operational */
1512 uea_warn(INS_TO_USBDEV(sc
), "unknown state: %x\n",
1513 sc
->stats
.phy
.state
);
1518 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_OFF
, 0, NULL
);
1519 uea_info(INS_TO_USBDEV(sc
), "modem operational\n");
1521 /* release the dsp firmware as it is not needed until
1524 release_firmware(sc
->dsp_firm
);
1525 sc
->dsp_firm
= NULL
;
1528 /* always update it as atm layer could not be init when we switch to
1531 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND
);
1533 /* wake up processes waiting for synchronization */
1534 wake_up(&sc
->sync_q
);
1536 /* TODO improve this state machine :
1537 * we need some CMV info : what they do and their unit
1538 * we should find the equivalent of eagle3- CMV
1541 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_DIAG
, 0, 0, &sc
->stats
.phy
.flags
);
1544 sc
->stats
.phy
.mflags
|= sc
->stats
.phy
.flags
;
1546 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1547 * we check the status again in order to detect the failure earlier
1549 if (sc
->stats
.phy
.flags
) {
1550 uea_dbg(INS_TO_USBDEV(sc
), "Stat flag = 0x%x\n",
1551 sc
->stats
.phy
.flags
);
1552 if (sc
->stats
.phy
.flags
& 1) /* delineation LOSS */
1554 if (sc
->stats
.phy
.flags
& 0x4000) /* Reset Flag */
1559 /* rate data may be in upper or lower half of 64 bit word, strange */
1560 ret
= uea_read_cmv_e4(sc
, 4, E4_SA_RATE
, 0, 0, tmp_arr
);
1563 data
= (tmp_arr
[0]) ? tmp_arr
[0] : tmp_arr
[1];
1564 sc
->stats
.phy
.usrate
= data
/ 1000;
1566 ret
= uea_read_cmv_e4(sc
, 4, E4_SA_RATE
, 1, 0, tmp_arr
);
1569 data
= (tmp_arr
[0]) ? tmp_arr
[0] : tmp_arr
[1];
1570 uea_set_bulk_timeout(sc
, data
/ 1000);
1571 sc
->stats
.phy
.dsrate
= data
/ 1000;
1572 UPDATE_ATM_STAT(link_rate
, sc
->stats
.phy
.dsrate
* 1000 / 424);
1574 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 68, 1, &data
);
1577 sc
->stats
.phy
.dsattenuation
= data
/ 10;
1579 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 69, 1, &data
);
1582 sc
->stats
.phy
.usattenuation
= data
/ 10;
1584 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 68, 3, &data
);
1587 sc
->stats
.phy
.dsmargin
= data
/ 2;
1589 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 69, 3, &data
);
1592 sc
->stats
.phy
.usmargin
= data
/ 10;
1597 static void cmvs_file_name(struct uea_softc
*sc
, char *const cmv_name
, int ver
)
1599 char file_arr
[] = "CMVxy.bin";
1602 kernel_param_lock(THIS_MODULE
);
1603 /* set proper name corresponding modem version and line type */
1604 if (cmv_file
[sc
->modem_index
] == NULL
) {
1605 if (UEA_CHIP_VERSION(sc
) == ADI930
)
1607 else if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
)
1612 file_arr
[4] = IS_ISDN(sc
) ? 'i' : 'p';
1615 file
= cmv_file
[sc
->modem_index
];
1617 strcpy(cmv_name
, FW_DIR
);
1618 strlcat(cmv_name
, file
, UEA_FW_NAME_MAX
);
1620 strlcat(cmv_name
, ".v2", UEA_FW_NAME_MAX
);
1621 kernel_param_unlock(THIS_MODULE
);
1624 static int request_cmvs_old(struct uea_softc
*sc
,
1625 void **cmvs
, const struct firmware
**fw
)
1629 char cmv_name
[UEA_FW_NAME_MAX
]; /* 30 bytes stack variable */
1631 cmvs_file_name(sc
, cmv_name
, 1);
1632 ret
= request_firmware(fw
, cmv_name
, &sc
->usb_dev
->dev
);
1634 uea_err(INS_TO_USBDEV(sc
),
1635 "requesting firmware %s failed with error %d\n",
1640 data
= (u8
*) (*fw
)->data
;
1643 goto err_fw_corrupted
;
1645 if (size
!= *data
* sizeof(struct uea_cmvs_v1
) + 1)
1646 goto err_fw_corrupted
;
1648 *cmvs
= (void *)(data
+ 1);
1652 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n", cmv_name
);
1653 release_firmware(*fw
);
1657 static int request_cmvs(struct uea_softc
*sc
,
1658 void **cmvs
, const struct firmware
**fw
, int *ver
)
1663 char cmv_name
[UEA_FW_NAME_MAX
]; /* 30 bytes stack variable */
1665 cmvs_file_name(sc
, cmv_name
, 2);
1666 ret
= request_firmware(fw
, cmv_name
, &sc
->usb_dev
->dev
);
1668 /* if caller can handle old version, try to provide it */
1670 uea_warn(INS_TO_USBDEV(sc
), "requesting "
1671 "firmware %s failed, "
1672 "try to get older cmvs\n", cmv_name
);
1673 return request_cmvs_old(sc
, cmvs
, fw
);
1675 uea_err(INS_TO_USBDEV(sc
),
1676 "requesting firmware %s failed with error %d\n",
1682 data
= (u8
*) (*fw
)->data
;
1683 if (size
< 4 || strncmp(data
, "cmv2", 4) != 0) {
1685 uea_warn(INS_TO_USBDEV(sc
), "firmware %s is corrupted,"
1686 " try to get older cmvs\n", cmv_name
);
1687 release_firmware(*fw
);
1688 return request_cmvs_old(sc
, cmvs
, fw
);
1690 goto err_fw_corrupted
;
1698 goto err_fw_corrupted
;
1700 crc
= get_unaligned_le32(data
);
1703 if (crc32_be(0, data
, size
) != crc
)
1704 goto err_fw_corrupted
;
1706 if (size
!= *data
* sizeof(struct uea_cmvs_v2
) + 1)
1707 goto err_fw_corrupted
;
1709 *cmvs
= (void *) (data
+ 1);
1713 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n", cmv_name
);
1714 release_firmware(*fw
);
1718 static int uea_send_cmvs_e1(struct uea_softc
*sc
)
1722 const struct firmware
*cmvs_fw
;
1723 int ver
= 1; /* we can handle v1 cmv firmware version; */
1725 /* Enter in R-IDLE (cmv) until instructed otherwise */
1726 ret
= uea_write_cmv_e1(sc
, E1_SA_CNTL
, 0, 1);
1730 /* Dump firmware version */
1731 ret
= uea_read_cmv_e1(sc
, E1_SA_INFO
, 10, &sc
->stats
.phy
.firmid
);
1734 uea_info(INS_TO_USBDEV(sc
), "ATU-R firmware version : %x\n",
1735 sc
->stats
.phy
.firmid
);
1738 ret
= len
= request_cmvs(sc
, &cmvs_ptr
, &cmvs_fw
, &ver
);
1744 struct uea_cmvs_v1
*cmvs_v1
= cmvs_ptr
;
1746 uea_warn(INS_TO_USBDEV(sc
), "use deprecated cmvs version, "
1747 "please update your firmware\n");
1749 for (i
= 0; i
< len
; i
++) {
1750 ret
= uea_write_cmv_e1(sc
,
1751 get_unaligned_le32(&cmvs_v1
[i
].address
),
1752 get_unaligned_le16(&cmvs_v1
[i
].offset
),
1753 get_unaligned_le32(&cmvs_v1
[i
].data
));
1757 } else if (ver
== 2) {
1758 struct uea_cmvs_v2
*cmvs_v2
= cmvs_ptr
;
1760 for (i
= 0; i
< len
; i
++) {
1761 ret
= uea_write_cmv_e1(sc
,
1762 get_unaligned_le32(&cmvs_v2
[i
].address
),
1763 (u16
) get_unaligned_le32(&cmvs_v2
[i
].offset
),
1764 get_unaligned_le32(&cmvs_v2
[i
].data
));
1769 /* This really should not happen */
1770 uea_err(INS_TO_USBDEV(sc
), "bad cmvs version %d\n", ver
);
1774 /* Enter in R-ACT-REQ */
1775 ret
= uea_write_cmv_e1(sc
, E1_SA_CNTL
, 0, 2);
1776 uea_vdbg(INS_TO_USBDEV(sc
), "Entering in R-ACT-REQ state\n");
1777 uea_info(INS_TO_USBDEV(sc
), "modem started, waiting "
1778 "synchronization...\n");
1780 release_firmware(cmvs_fw
);
1784 static int uea_send_cmvs_e4(struct uea_softc
*sc
)
1788 const struct firmware
*cmvs_fw
;
1789 int ver
= 2; /* we can only handle v2 cmv firmware version; */
1791 /* Enter in R-IDLE (cmv) until instructed otherwise */
1792 ret
= uea_write_cmv_e4(sc
, 1, E4_SA_CNTL
, 0, 0, 1);
1796 /* Dump firmware version */
1797 /* XXX don't read the 3th byte as it is always 6 */
1798 ret
= uea_read_cmv_e4(sc
, 2, E4_SA_INFO
, 55, 0, &sc
->stats
.phy
.firmid
);
1801 uea_info(INS_TO_USBDEV(sc
), "ATU-R firmware version : %x\n",
1802 sc
->stats
.phy
.firmid
);
1806 ret
= len
= request_cmvs(sc
, &cmvs_ptr
, &cmvs_fw
, &ver
);
1812 struct uea_cmvs_v2
*cmvs_v2
= cmvs_ptr
;
1814 for (i
= 0; i
< len
; i
++) {
1815 ret
= uea_write_cmv_e4(sc
, 1,
1816 get_unaligned_le32(&cmvs_v2
[i
].group
),
1817 get_unaligned_le32(&cmvs_v2
[i
].address
),
1818 get_unaligned_le32(&cmvs_v2
[i
].offset
),
1819 get_unaligned_le32(&cmvs_v2
[i
].data
));
1824 /* This really should not happen */
1825 uea_err(INS_TO_USBDEV(sc
), "bad cmvs version %d\n", ver
);
1829 /* Enter in R-ACT-REQ */
1830 ret
= uea_write_cmv_e4(sc
, 1, E4_SA_CNTL
, 0, 0, 2);
1831 uea_vdbg(INS_TO_USBDEV(sc
), "Entering in R-ACT-REQ state\n");
1832 uea_info(INS_TO_USBDEV(sc
), "modem started, waiting "
1833 "synchronization...\n");
1835 release_firmware(cmvs_fw
);
1839 /* Start boot post firmware modem:
1840 * - send reset commands through usb control pipe
1841 * - start workqueue for DSP loading
1842 * - send CMV options to modem
1845 static int uea_start_reset(struct uea_softc
*sc
)
1847 u16 zero
= 0; /* ;-) */
1850 uea_enters(INS_TO_USBDEV(sc
));
1851 uea_info(INS_TO_USBDEV(sc
), "(re)booting started\n");
1853 /* mask interrupt */
1855 /* We need to set this here because, a ack timeout could have occurred,
1856 * but before we start the reboot, the ack occurs and set this to 1.
1857 * So we will failed to wait Ready CMV.
1860 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST
);
1862 /* reset statistics */
1863 memset(&sc
->stats
, 0, sizeof(struct uea_stats
));
1865 /* tell the modem that we want to boot in IDMA mode */
1866 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_ON
, 0, NULL
);
1867 uea_request(sc
, UEA_SET_MODE
, UEA_BOOT_IDMA
, 0, NULL
);
1869 /* enter reset mode */
1870 uea_request(sc
, UEA_SET_MODE
, UEA_START_RESET
, 0, NULL
);
1872 /* original driver use 200ms, but windows driver use 100ms */
1873 ret
= uea_wait(sc
, 0, msecs_to_jiffies(100));
1877 /* leave reset mode */
1878 uea_request(sc
, UEA_SET_MODE
, UEA_END_RESET
, 0, NULL
);
1880 if (UEA_CHIP_VERSION(sc
) != EAGLE_IV
) {
1881 /* clear tx and rx mailboxes */
1882 uea_request(sc
, UEA_SET_2183_DATA
, UEA_MPTX_MAILBOX
, 2, &zero
);
1883 uea_request(sc
, UEA_SET_2183_DATA
, UEA_MPRX_MAILBOX
, 2, &zero
);
1884 uea_request(sc
, UEA_SET_2183_DATA
, UEA_SWAP_MAILBOX
, 2, &zero
);
1887 ret
= uea_wait(sc
, 0, msecs_to_jiffies(1000));
1891 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
)
1892 sc
->cmv_dsc
.e4
.function
= E4_MAKEFUNCTION(E4_ADSLDIRECTIVE
,
1895 sc
->cmv_dsc
.e1
.function
= E1_MAKEFUNCTION(E1_ADSLDIRECTIVE
,
1898 /* demask interrupt */
1901 /* start loading DSP */
1904 schedule_work(&sc
->task
);
1906 /* wait for modem ready CMV */
1907 ret
= wait_cmv_ack(sc
);
1911 uea_vdbg(INS_TO_USBDEV(sc
), "Ready CMV received\n");
1913 ret
= sc
->send_cmvs(sc
);
1918 uea_leaves(INS_TO_USBDEV(sc
));
1923 * In case of an error wait 1s before rebooting the modem
1924 * if the modem don't request reboot (-EAGAIN).
1925 * Monitor the modem every 1s.
1928 static int uea_kthread(void *data
)
1930 struct uea_softc
*sc
= data
;
1934 uea_enters(INS_TO_USBDEV(sc
));
1935 while (!kthread_should_stop()) {
1936 if (ret
< 0 || sc
->reset
)
1937 ret
= uea_start_reset(sc
);
1941 uea_wait(sc
, 0, msecs_to_jiffies(1000));
1944 uea_leaves(INS_TO_USBDEV(sc
));
1948 /* Load second usb firmware for ADI930 chip */
1949 static int load_XILINX_firmware(struct uea_softc
*sc
)
1951 const struct firmware
*fw_entry
;
1952 int ret
, size
, u
, ln
;
1955 char *fw_name
= FPGA930_FIRMWARE
;
1957 uea_enters(INS_TO_USBDEV(sc
));
1959 ret
= request_firmware(&fw_entry
, fw_name
, &sc
->usb_dev
->dev
);
1961 uea_err(INS_TO_USBDEV(sc
), "firmware %s is not available\n",
1966 pfw
= fw_entry
->data
;
1967 size
= fw_entry
->size
;
1968 if (size
!= 0x577B) {
1969 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n",
1974 for (u
= 0; u
< size
; u
+= ln
) {
1975 ln
= min(size
- u
, 64);
1976 ret
= uea_request(sc
, 0xe, 0, ln
, pfw
+ u
);
1978 uea_err(INS_TO_USBDEV(sc
),
1979 "elsa download data failed (%d)\n", ret
);
1984 /* finish to send the fpga */
1985 ret
= uea_request(sc
, 0xe, 1, 0, NULL
);
1987 uea_err(INS_TO_USBDEV(sc
),
1988 "elsa download data failed (%d)\n", ret
);
1992 /* Tell the modem we finish : de-assert reset */
1994 ret
= uea_send_modem_cmd(sc
->usb_dev
, 0xe, 1, &value
);
1996 uea_err(sc
->usb_dev
, "elsa de-assert failed with error"
2000 release_firmware(fw_entry
);
2002 uea_leaves(INS_TO_USBDEV(sc
));
2006 /* The modem send us an ack. First with check if it right */
2007 static void uea_dispatch_cmv_e1(struct uea_softc
*sc
, struct intr_pkt
*intr
)
2009 struct cmv_dsc_e1
*dsc
= &sc
->cmv_dsc
.e1
;
2010 struct cmv_e1
*cmv
= &intr
->u
.e1
.s2
.cmv
;
2012 uea_enters(INS_TO_USBDEV(sc
));
2013 if (le16_to_cpu(cmv
->wPreamble
) != E1_PREAMBLE
)
2016 if (cmv
->bDirection
!= E1_MODEMTOHOST
)
2019 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
2020 * the first MEMACCESS cmv. Ignore it...
2022 if (cmv
->bFunction
!= dsc
->function
) {
2023 if (UEA_CHIP_VERSION(sc
) == ADI930
2024 && cmv
->bFunction
== E1_MAKEFUNCTION(2, 2)) {
2025 cmv
->wIndex
= cpu_to_le16(dsc
->idx
);
2026 put_unaligned_le32(dsc
->address
,
2027 &cmv
->dwSymbolicAddress
);
2028 cmv
->wOffsetAddress
= cpu_to_le16(dsc
->offset
);
2033 if (cmv
->bFunction
== E1_MAKEFUNCTION(E1_ADSLDIRECTIVE
,
2035 wake_up_cmv_ack(sc
);
2036 uea_leaves(INS_TO_USBDEV(sc
));
2040 /* in case of MEMACCESS */
2041 if (le16_to_cpu(cmv
->wIndex
) != dsc
->idx
||
2042 get_unaligned_le32(&cmv
->dwSymbolicAddress
) != dsc
->address
||
2043 le16_to_cpu(cmv
->wOffsetAddress
) != dsc
->offset
)
2046 sc
->data
= get_unaligned_le32(&cmv
->dwData
);
2047 sc
->data
= sc
->data
<< 16 | sc
->data
>> 16;
2049 wake_up_cmv_ack(sc
);
2050 uea_leaves(INS_TO_USBDEV(sc
));
2054 uea_err(INS_TO_USBDEV(sc
), "unexpected cmv received, "
2055 "Function : %d, Subfunction : %d\n",
2056 E1_FUNCTION_TYPE(cmv
->bFunction
),
2057 E1_FUNCTION_SUBTYPE(cmv
->bFunction
));
2058 uea_leaves(INS_TO_USBDEV(sc
));
2062 uea_err(INS_TO_USBDEV(sc
), "invalid cmv received, "
2063 "wPreamble %d, bDirection %d\n",
2064 le16_to_cpu(cmv
->wPreamble
), cmv
->bDirection
);
2065 uea_leaves(INS_TO_USBDEV(sc
));
2068 /* The modem send us an ack. First with check if it right */
2069 static void uea_dispatch_cmv_e4(struct uea_softc
*sc
, struct intr_pkt
*intr
)
2071 struct cmv_dsc_e4
*dsc
= &sc
->cmv_dsc
.e4
;
2072 struct cmv_e4
*cmv
= &intr
->u
.e4
.s2
.cmv
;
2074 uea_enters(INS_TO_USBDEV(sc
));
2075 uea_dbg(INS_TO_USBDEV(sc
), "cmv %x %x %x %x %x %x\n",
2076 be16_to_cpu(cmv
->wGroup
), be16_to_cpu(cmv
->wFunction
),
2077 be16_to_cpu(cmv
->wOffset
), be16_to_cpu(cmv
->wAddress
),
2078 be32_to_cpu(cmv
->dwData
[0]), be32_to_cpu(cmv
->dwData
[1]));
2080 if (be16_to_cpu(cmv
->wFunction
) != dsc
->function
)
2083 if (be16_to_cpu(cmv
->wFunction
) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE
,
2084 E4_MODEMREADY
, 1)) {
2085 wake_up_cmv_ack(sc
);
2086 uea_leaves(INS_TO_USBDEV(sc
));
2090 /* in case of MEMACCESS */
2091 if (be16_to_cpu(cmv
->wOffset
) != dsc
->offset
||
2092 be16_to_cpu(cmv
->wGroup
) != dsc
->group
||
2093 be16_to_cpu(cmv
->wAddress
) != dsc
->address
)
2096 sc
->data
= be32_to_cpu(cmv
->dwData
[0]);
2097 sc
->data1
= be32_to_cpu(cmv
->dwData
[1]);
2098 wake_up_cmv_ack(sc
);
2099 uea_leaves(INS_TO_USBDEV(sc
));
2103 uea_err(INS_TO_USBDEV(sc
), "unexpected cmv received, "
2104 "Function : %d, Subfunction : %d\n",
2105 E4_FUNCTION_TYPE(cmv
->wFunction
),
2106 E4_FUNCTION_SUBTYPE(cmv
->wFunction
));
2107 uea_leaves(INS_TO_USBDEV(sc
));
2111 static void uea_schedule_load_page_e1(struct uea_softc
*sc
,
2112 struct intr_pkt
*intr
)
2114 sc
->pageno
= intr
->e1_bSwapPageNo
;
2115 sc
->ovl
= intr
->e1_bOvl
>> 4 | intr
->e1_bOvl
<< 4;
2116 schedule_work(&sc
->task
);
2119 static void uea_schedule_load_page_e4(struct uea_softc
*sc
,
2120 struct intr_pkt
*intr
)
2122 sc
->pageno
= intr
->e4_bSwapPageNo
;
2123 schedule_work(&sc
->task
);
2129 static void uea_intr(struct urb
*urb
)
2131 struct uea_softc
*sc
= urb
->context
;
2132 struct intr_pkt
*intr
= urb
->transfer_buffer
;
2133 int status
= urb
->status
;
2135 uea_enters(INS_TO_USBDEV(sc
));
2137 if (unlikely(status
< 0)) {
2138 uea_err(INS_TO_USBDEV(sc
), "uea_intr() failed with %d\n",
2143 /* device-to-host interrupt */
2144 if (intr
->bType
!= 0x08 || sc
->booting
) {
2145 uea_err(INS_TO_USBDEV(sc
), "wrong interrupt\n");
2149 switch (le16_to_cpu(intr
->wInterrupt
)) {
2150 case INT_LOADSWAPPAGE
:
2151 sc
->schedule_load_page(sc
, intr
);
2154 case INT_INCOMINGCMV
:
2155 sc
->dispatch_cmv(sc
, intr
);
2159 uea_err(INS_TO_USBDEV(sc
), "unknown interrupt %u\n",
2160 le16_to_cpu(intr
->wInterrupt
));
2164 usb_submit_urb(sc
->urb_int
, GFP_ATOMIC
);
2168 * Start the modem : init the data and start kernel thread
2170 static int uea_boot(struct uea_softc
*sc
)
2173 struct intr_pkt
*intr
;
2175 uea_enters(INS_TO_USBDEV(sc
));
2177 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
2178 size
= E4_INTR_PKT_SIZE
;
2179 sc
->dispatch_cmv
= uea_dispatch_cmv_e4
;
2180 sc
->schedule_load_page
= uea_schedule_load_page_e4
;
2181 sc
->stat
= uea_stat_e4
;
2182 sc
->send_cmvs
= uea_send_cmvs_e4
;
2183 INIT_WORK(&sc
->task
, uea_load_page_e4
);
2185 size
= E1_INTR_PKT_SIZE
;
2186 sc
->dispatch_cmv
= uea_dispatch_cmv_e1
;
2187 sc
->schedule_load_page
= uea_schedule_load_page_e1
;
2188 sc
->stat
= uea_stat_e1
;
2189 sc
->send_cmvs
= uea_send_cmvs_e1
;
2190 INIT_WORK(&sc
->task
, uea_load_page_e1
);
2193 init_waitqueue_head(&sc
->sync_q
);
2195 if (UEA_CHIP_VERSION(sc
) == ADI930
)
2196 load_XILINX_firmware(sc
);
2198 intr
= kmalloc(size
, GFP_KERNEL
);
2200 uea_err(INS_TO_USBDEV(sc
),
2201 "cannot allocate interrupt package\n");
2205 sc
->urb_int
= usb_alloc_urb(0, GFP_KERNEL
);
2207 uea_err(INS_TO_USBDEV(sc
), "cannot allocate interrupt URB\n");
2211 usb_fill_int_urb(sc
->urb_int
, sc
->usb_dev
,
2212 usb_rcvintpipe(sc
->usb_dev
, UEA_INTR_PIPE
),
2213 intr
, size
, uea_intr
, sc
,
2214 sc
->usb_dev
->actconfig
->interface
[0]->altsetting
[0].
2215 endpoint
[0].desc
.bInterval
);
2217 ret
= usb_submit_urb(sc
->urb_int
, GFP_KERNEL
);
2219 uea_err(INS_TO_USBDEV(sc
),
2220 "urb submition failed with error %d\n", ret
);
2224 /* Create worker thread, but don't start it here. Start it after
2225 * all usbatm generic initialization is done.
2227 sc
->kthread
= kthread_create(uea_kthread
, sc
, "ueagle-atm");
2228 if (IS_ERR(sc
->kthread
)) {
2229 uea_err(INS_TO_USBDEV(sc
), "failed to create thread\n");
2233 uea_leaves(INS_TO_USBDEV(sc
));
2237 usb_kill_urb(sc
->urb_int
);
2239 usb_free_urb(sc
->urb_int
);
2243 uea_leaves(INS_TO_USBDEV(sc
));
2248 * Stop the modem : kill kernel thread and free data
2250 static void uea_stop(struct uea_softc
*sc
)
2253 uea_enters(INS_TO_USBDEV(sc
));
2254 ret
= kthread_stop(sc
->kthread
);
2255 uea_dbg(INS_TO_USBDEV(sc
), "kthread finish with status %d\n", ret
);
2257 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_ON
, 0, NULL
);
2259 usb_kill_urb(sc
->urb_int
);
2260 kfree(sc
->urb_int
->transfer_buffer
);
2261 usb_free_urb(sc
->urb_int
);
2263 /* flush the work item, when no one can schedule it */
2264 flush_work(&sc
->task
);
2266 release_firmware(sc
->dsp_firm
);
2267 uea_leaves(INS_TO_USBDEV(sc
));
2270 /* syfs interface */
2271 static struct uea_softc
*dev_to_uea(struct device
*dev
)
2273 struct usb_interface
*intf
;
2274 struct usbatm_data
*usbatm
;
2276 intf
= to_usb_interface(dev
);
2280 usbatm
= usb_get_intfdata(intf
);
2284 return usbatm
->driver_data
;
2287 static ssize_t
read_status(struct device
*dev
, struct device_attribute
*attr
,
2291 struct uea_softc
*sc
;
2293 mutex_lock(&uea_mutex
);
2294 sc
= dev_to_uea(dev
);
2297 ret
= snprintf(buf
, 10, "%08x\n", sc
->stats
.phy
.state
);
2299 mutex_unlock(&uea_mutex
);
2303 static ssize_t
reboot(struct device
*dev
, struct device_attribute
*attr
,
2304 const char *buf
, size_t count
)
2307 struct uea_softc
*sc
;
2309 mutex_lock(&uea_mutex
);
2310 sc
= dev_to_uea(dev
);
2316 mutex_unlock(&uea_mutex
);
2320 static DEVICE_ATTR(stat_status
, S_IWUSR
| S_IRUGO
, read_status
, reboot
);
2322 static ssize_t
read_human_status(struct device
*dev
,
2323 struct device_attribute
*attr
, char *buf
)
2327 struct uea_softc
*sc
;
2329 mutex_lock(&uea_mutex
);
2330 sc
= dev_to_uea(dev
);
2334 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
2335 switch (sc
->stats
.phy
.state
) {
2336 case 0x0: /* not yet synchronized */
2342 case 0x5: /* initialization */
2348 case 0x7: /* operational */
2351 case 0x2: /* fail ... */
2354 default: /* unknown */
2359 modem_state
= GET_STATUS(sc
->stats
.phy
.state
);
2361 switch (modem_state
) {
2363 ret
= sprintf(buf
, "Modem is booting\n");
2366 ret
= sprintf(buf
, "Modem is initializing\n");
2369 ret
= sprintf(buf
, "Modem is operational\n");
2372 ret
= sprintf(buf
, "Modem synchronization failed\n");
2375 ret
= sprintf(buf
, "Modem state is unknown\n");
2379 mutex_unlock(&uea_mutex
);
2383 static DEVICE_ATTR(stat_human_status
, S_IRUGO
, read_human_status
, NULL
);
2385 static ssize_t
read_delin(struct device
*dev
, struct device_attribute
*attr
,
2389 struct uea_softc
*sc
;
2390 char *delin
= "GOOD";
2392 mutex_lock(&uea_mutex
);
2393 sc
= dev_to_uea(dev
);
2397 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
2398 if (sc
->stats
.phy
.flags
& 0x4000)
2400 else if (sc
->stats
.phy
.flags
& 0x0001)
2403 if (sc
->stats
.phy
.flags
& 0x0C00)
2405 else if (sc
->stats
.phy
.flags
& 0x0030)
2409 ret
= sprintf(buf
, "%s\n", delin
);
2411 mutex_unlock(&uea_mutex
);
2415 static DEVICE_ATTR(stat_delin
, S_IRUGO
, read_delin
, NULL
);
2417 #define UEA_ATTR(name, reset) \
2419 static ssize_t read_##name(struct device *dev, \
2420 struct device_attribute *attr, char *buf) \
2422 int ret = -ENODEV; \
2423 struct uea_softc *sc; \
2425 mutex_lock(&uea_mutex); \
2426 sc = dev_to_uea(dev); \
2429 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2431 sc->stats.phy.name = 0; \
2433 mutex_unlock(&uea_mutex); \
2437 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2439 UEA_ATTR(mflags
, 1);
2440 UEA_ATTR(vidcpe
, 0);
2441 UEA_ATTR(usrate
, 0);
2442 UEA_ATTR(dsrate
, 0);
2443 UEA_ATTR(usattenuation
, 0);
2444 UEA_ATTR(dsattenuation
, 0);
2445 UEA_ATTR(usmargin
, 0);
2446 UEA_ATTR(dsmargin
, 0);
2447 UEA_ATTR(txflow
, 0);
2448 UEA_ATTR(rxflow
, 0);
2449 UEA_ATTR(uscorr
, 0);
2450 UEA_ATTR(dscorr
, 0);
2453 UEA_ATTR(firmid
, 0);
2455 /* Retrieve the device End System Identifier (MAC) */
2457 static int uea_getesi(struct uea_softc
*sc
, u_char
* esi
)
2459 unsigned char mac_str
[2 * ETH_ALEN
+ 1];
2462 (sc
->usb_dev
, sc
->usb_dev
->descriptor
.iSerialNumber
, mac_str
,
2463 sizeof(mac_str
)) != 2 * ETH_ALEN
)
2466 for (i
= 0; i
< ETH_ALEN
; i
++)
2467 esi
[i
] = hex_to_bin(mac_str
[2 * i
]) * 16 +
2468 hex_to_bin(mac_str
[2 * i
+ 1]);
2474 static int uea_atm_open(struct usbatm_data
*usbatm
, struct atm_dev
*atm_dev
)
2476 struct uea_softc
*sc
= usbatm
->driver_data
;
2478 return uea_getesi(sc
, atm_dev
->esi
);
2481 static int uea_heavy(struct usbatm_data
*usbatm
, struct usb_interface
*intf
)
2483 struct uea_softc
*sc
= usbatm
->driver_data
;
2485 wait_event_interruptible(sc
->sync_q
, IS_OPERATIONAL(sc
));
2491 static int claim_interface(struct usb_device
*usb_dev
,
2492 struct usbatm_data
*usbatm
, int ifnum
)
2495 struct usb_interface
*intf
= usb_ifnum_to_if(usb_dev
, ifnum
);
2498 uea_err(usb_dev
, "interface %d not found\n", ifnum
);
2502 ret
= usb_driver_claim_interface(&uea_driver
, intf
, usbatm
);
2504 uea_err(usb_dev
, "can't claim interface %d, error %d\n", ifnum
,
2509 static struct attribute
*attrs
[] = {
2510 &dev_attr_stat_status
.attr
,
2511 &dev_attr_stat_mflags
.attr
,
2512 &dev_attr_stat_human_status
.attr
,
2513 &dev_attr_stat_delin
.attr
,
2514 &dev_attr_stat_vidcpe
.attr
,
2515 &dev_attr_stat_usrate
.attr
,
2516 &dev_attr_stat_dsrate
.attr
,
2517 &dev_attr_stat_usattenuation
.attr
,
2518 &dev_attr_stat_dsattenuation
.attr
,
2519 &dev_attr_stat_usmargin
.attr
,
2520 &dev_attr_stat_dsmargin
.attr
,
2521 &dev_attr_stat_txflow
.attr
,
2522 &dev_attr_stat_rxflow
.attr
,
2523 &dev_attr_stat_uscorr
.attr
,
2524 &dev_attr_stat_dscorr
.attr
,
2525 &dev_attr_stat_usunc
.attr
,
2526 &dev_attr_stat_dsunc
.attr
,
2527 &dev_attr_stat_firmid
.attr
,
2530 static struct attribute_group attr_grp
= {
2534 static int uea_bind(struct usbatm_data
*usbatm
, struct usb_interface
*intf
,
2535 const struct usb_device_id
*id
)
2537 struct usb_device
*usb
= interface_to_usbdev(intf
);
2538 struct uea_softc
*sc
;
2539 int ret
, ifnum
= intf
->altsetting
->desc
.bInterfaceNumber
;
2544 /* interface 0 is for firmware/monitoring */
2545 if (ifnum
!= UEA_INTR_IFACE_NO
)
2548 usbatm
->flags
= (sync_wait
[modem_index
] ? 0 : UDSL_SKIP_HEAVY_INIT
);
2550 /* interface 1 is for outbound traffic */
2551 ret
= claim_interface(usb
, usbatm
, UEA_US_IFACE_NO
);
2555 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
2556 if (UEA_CHIP_VERSION(id
) != ADI930
) {
2557 /* interface 2 is for inbound traffic */
2558 ret
= claim_interface(usb
, usbatm
, UEA_DS_IFACE_NO
);
2563 sc
= kzalloc(sizeof(struct uea_softc
), GFP_KERNEL
);
2565 uea_err(usb
, "uea_init: not enough memory !\n");
2570 usbatm
->driver_data
= sc
;
2571 sc
->usbatm
= usbatm
;
2572 sc
->modem_index
= (modem_index
< NB_MODEM
) ? modem_index
++ : 0;
2573 sc
->driver_info
= id
->driver_info
;
2575 /* first try to use module parameter */
2576 if (annex
[sc
->modem_index
] == 1)
2578 else if (annex
[sc
->modem_index
] == 2)
2580 /* try to autodetect annex */
2581 else if (sc
->driver_info
& AUTO_ANNEX_A
)
2583 else if (sc
->driver_info
& AUTO_ANNEX_B
)
2586 sc
->annex
= (le16_to_cpu
2587 (sc
->usb_dev
->descriptor
.bcdDevice
) & 0x80) ? ANNEXB
: ANNEXA
;
2589 alt
= altsetting
[sc
->modem_index
];
2590 /* ADI930 don't support iso */
2591 if (UEA_CHIP_VERSION(id
) != ADI930
&& alt
> 0) {
2593 usb_set_interface(usb
, UEA_DS_IFACE_NO
, alt
) == 0) {
2594 uea_dbg(usb
, "set alternate %u for 2 interface\n", alt
);
2595 uea_info(usb
, "using iso mode\n");
2596 usbatm
->flags
|= UDSL_USE_ISOC
| UDSL_IGNORE_EILSEQ
;
2598 uea_err(usb
, "setting alternate %u failed for "
2599 "2 interface, using bulk mode\n", alt
);
2603 ret
= sysfs_create_group(&intf
->dev
.kobj
, &attr_grp
);
2614 sysfs_remove_group(&intf
->dev
.kobj
, &attr_grp
);
2620 static void uea_unbind(struct usbatm_data
*usbatm
, struct usb_interface
*intf
)
2622 struct uea_softc
*sc
= usbatm
->driver_data
;
2624 sysfs_remove_group(&intf
->dev
.kobj
, &attr_grp
);
2629 static struct usbatm_driver uea_usbatm_driver
= {
2630 .driver_name
= "ueagle-atm",
2632 .atm_start
= uea_atm_open
,
2633 .unbind
= uea_unbind
,
2634 .heavy_init
= uea_heavy
,
2635 .bulk_in
= UEA_BULK_DATA_PIPE
,
2636 .bulk_out
= UEA_BULK_DATA_PIPE
,
2637 .isoc_in
= UEA_ISO_DATA_PIPE
,
2640 static int uea_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
2642 struct usb_device
*usb
= interface_to_usbdev(intf
);
2646 uea_info(usb
, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2647 le16_to_cpu(usb
->descriptor
.idVendor
),
2648 le16_to_cpu(usb
->descriptor
.idProduct
),
2649 le16_to_cpu(usb
->descriptor
.bcdDevice
),
2650 chip_name
[UEA_CHIP_VERSION(id
)]);
2652 usb_reset_device(usb
);
2654 if (UEA_IS_PREFIRM(id
))
2655 return uea_load_firmware(usb
, UEA_CHIP_VERSION(id
));
2657 ret
= usbatm_usb_probe(intf
, id
, &uea_usbatm_driver
);
2659 struct usbatm_data
*usbatm
= usb_get_intfdata(intf
);
2660 struct uea_softc
*sc
= usbatm
->driver_data
;
2662 /* Ensure carrier is initialized to off as early as possible */
2663 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST
);
2665 /* Only start the worker thread when all init is done */
2666 wake_up_process(sc
->kthread
);
2672 static void uea_disconnect(struct usb_interface
*intf
)
2674 struct usb_device
*usb
= interface_to_usbdev(intf
);
2675 int ifnum
= intf
->altsetting
->desc
.bInterfaceNumber
;
2678 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2679 * Pre-firmware device has one interface
2681 if (usb
->config
->desc
.bNumInterfaces
!= 1 && ifnum
== 0) {
2682 mutex_lock(&uea_mutex
);
2683 usbatm_usb_disconnect(intf
);
2684 mutex_unlock(&uea_mutex
);
2685 uea_info(usb
, "ADSL device removed\n");
2692 * List of supported VID/PID
2694 static const struct usb_device_id uea_ids
[] = {
2695 {USB_DEVICE(ANALOG_VID
, ADI930_PID_PREFIRM
),
2696 .driver_info
= ADI930
| PREFIRM
},
2697 {USB_DEVICE(ANALOG_VID
, ADI930_PID_PSTFIRM
),
2698 .driver_info
= ADI930
| PSTFIRM
},
2699 {USB_DEVICE(ANALOG_VID
, EAGLE_I_PID_PREFIRM
),
2700 .driver_info
= EAGLE_I
| PREFIRM
},
2701 {USB_DEVICE(ANALOG_VID
, EAGLE_I_PID_PSTFIRM
),
2702 .driver_info
= EAGLE_I
| PSTFIRM
},
2703 {USB_DEVICE(ANALOG_VID
, EAGLE_II_PID_PREFIRM
),
2704 .driver_info
= EAGLE_II
| PREFIRM
},
2705 {USB_DEVICE(ANALOG_VID
, EAGLE_II_PID_PSTFIRM
),
2706 .driver_info
= EAGLE_II
| PSTFIRM
},
2707 {USB_DEVICE(ANALOG_VID
, EAGLE_IIC_PID_PREFIRM
),
2708 .driver_info
= EAGLE_II
| PREFIRM
},
2709 {USB_DEVICE(ANALOG_VID
, EAGLE_IIC_PID_PSTFIRM
),
2710 .driver_info
= EAGLE_II
| PSTFIRM
},
2711 {USB_DEVICE(ANALOG_VID
, EAGLE_III_PID_PREFIRM
),
2712 .driver_info
= EAGLE_III
| PREFIRM
},
2713 {USB_DEVICE(ANALOG_VID
, EAGLE_III_PID_PSTFIRM
),
2714 .driver_info
= EAGLE_III
| PSTFIRM
},
2715 {USB_DEVICE(ANALOG_VID
, EAGLE_IV_PID_PREFIRM
),
2716 .driver_info
= EAGLE_IV
| PREFIRM
},
2717 {USB_DEVICE(ANALOG_VID
, EAGLE_IV_PID_PSTFIRM
),
2718 .driver_info
= EAGLE_IV
| PSTFIRM
},
2719 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_A_PID_PREFIRM
),
2720 .driver_info
= EAGLE_I
| PREFIRM
},
2721 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_A_PID_PSTFIRM
),
2722 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_A
},
2723 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_B_PID_PREFIRM
),
2724 .driver_info
= EAGLE_I
| PREFIRM
},
2725 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_B_PID_PSTFIRM
),
2726 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_B
},
2727 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_A_PID_PREFIRM
),
2728 .driver_info
= EAGLE_II
| PREFIRM
},
2729 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_A_PID_PSTFIRM
),
2730 .driver_info
= EAGLE_II
| PSTFIRM
| AUTO_ANNEX_A
},
2731 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_B_PID_PREFIRM
),
2732 .driver_info
= EAGLE_II
| PREFIRM
},
2733 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_B_PID_PSTFIRM
),
2734 .driver_info
= EAGLE_II
| PSTFIRM
| AUTO_ANNEX_B
},
2735 {USB_DEVICE(ELSA_VID
, ELSA_PID_PREFIRM
),
2736 .driver_info
= ADI930
| PREFIRM
},
2737 {USB_DEVICE(ELSA_VID
, ELSA_PID_PSTFIRM
),
2738 .driver_info
= ADI930
| PSTFIRM
},
2739 {USB_DEVICE(ELSA_VID
, ELSA_PID_A_PREFIRM
),
2740 .driver_info
= ADI930
| PREFIRM
},
2741 {USB_DEVICE(ELSA_VID
, ELSA_PID_A_PSTFIRM
),
2742 .driver_info
= ADI930
| PSTFIRM
| AUTO_ANNEX_A
},
2743 {USB_DEVICE(ELSA_VID
, ELSA_PID_B_PREFIRM
),
2744 .driver_info
= ADI930
| PREFIRM
},
2745 {USB_DEVICE(ELSA_VID
, ELSA_PID_B_PSTFIRM
),
2746 .driver_info
= ADI930
| PSTFIRM
| AUTO_ANNEX_B
},
2747 {USB_DEVICE(USR_VID
, MILLER_A_PID_PREFIRM
),
2748 .driver_info
= EAGLE_I
| PREFIRM
},
2749 {USB_DEVICE(USR_VID
, MILLER_A_PID_PSTFIRM
),
2750 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_A
},
2751 {USB_DEVICE(USR_VID
, MILLER_B_PID_PREFIRM
),
2752 .driver_info
= EAGLE_I
| PREFIRM
},
2753 {USB_DEVICE(USR_VID
, MILLER_B_PID_PSTFIRM
),
2754 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_B
},
2755 {USB_DEVICE(USR_VID
, HEINEKEN_A_PID_PREFIRM
),
2756 .driver_info
= EAGLE_I
| PREFIRM
},
2757 {USB_DEVICE(USR_VID
, HEINEKEN_A_PID_PSTFIRM
),
2758 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_A
},
2759 {USB_DEVICE(USR_VID
, HEINEKEN_B_PID_PREFIRM
),
2760 .driver_info
= EAGLE_I
| PREFIRM
},
2761 {USB_DEVICE(USR_VID
, HEINEKEN_B_PID_PSTFIRM
),
2762 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_B
},
2767 * USB driver descriptor
2769 static struct usb_driver uea_driver
= {
2770 .name
= "ueagle-atm",
2771 .id_table
= uea_ids
,
2773 .disconnect
= uea_disconnect
,
2776 MODULE_DEVICE_TABLE(usb
, uea_ids
);
2778 module_usb_driver(uea_driver
);
2780 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2781 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2782 MODULE_LICENSE("Dual BSD/GPL");
2783 MODULE_FIRMWARE(EAGLE_FIRMWARE
);
2784 MODULE_FIRMWARE(ADI930_FIRMWARE
);
2785 MODULE_FIRMWARE(EAGLE_I_FIRMWARE
);
2786 MODULE_FIRMWARE(EAGLE_II_FIRMWARE
);
2787 MODULE_FIRMWARE(EAGLE_III_FIRMWARE
);
2788 MODULE_FIRMWARE(EAGLE_IV_FIRMWARE
);
2789 MODULE_FIRMWARE(DSP4I_FIRMWARE
);
2790 MODULE_FIRMWARE(DSP4P_FIRMWARE
);
2791 MODULE_FIRMWARE(DSP9I_FIRMWARE
);
2792 MODULE_FIRMWARE(DSP9P_FIRMWARE
);
2793 MODULE_FIRMWARE(DSPEI_FIRMWARE
);
2794 MODULE_FIRMWARE(DSPEP_FIRMWARE
);
2795 MODULE_FIRMWARE(FPGA930_FIRMWARE
);
2796 MODULE_FIRMWARE(CMV4P_FIRMWARE
);
2797 MODULE_FIRMWARE(CMV4PV2_FIRMWARE
);
2798 MODULE_FIRMWARE(CMV4I_FIRMWARE
);
2799 MODULE_FIRMWARE(CMV4IV2_FIRMWARE
);
2800 MODULE_FIRMWARE(CMV9P_FIRMWARE
);
2801 MODULE_FIRMWARE(CMV9PV2_FIRMWARE
);
2802 MODULE_FIRMWARE(CMV9I_FIRMWARE
);
2803 MODULE_FIRMWARE(CMV9IV2_FIRMWARE
);
2804 MODULE_FIRMWARE(CMVEP_FIRMWARE
);
2805 MODULE_FIRMWARE(CMVEPV2_FIRMWARE
);
2806 MODULE_FIRMWARE(CMVEI_FIRMWARE
);
2807 MODULE_FIRMWARE(CMVEIV2_FIRMWARE
);