1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-2-Clause)
3 * Copyright (c) 2003, 2004
4 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
6 * Copyright (c) 2005-2007 Matthieu Castet <castet.matthieu@free.fr>
7 * Copyright (c) 2005-2007 Stanislaw Gruszka <stf_xl@wp.pl>
9 * HISTORY : some part of the code was base on ueagle 1.3 BSD driver,
10 * Damien Bergamini agree to put his code under a DUAL GPL/BSD license.
12 * The rest of the code was was rewritten from scratch.
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/crc32.h>
18 #include <linux/usb.h>
19 #include <linux/firmware.h>
20 #include <linux/ctype.h>
21 #include <linux/sched.h>
22 #include <linux/kthread.h>
23 #include <linux/mutex.h>
24 #include <linux/freezer.h>
25 #include <linux/slab.h>
26 #include <linux/kernel.h>
28 #include <asm/unaligned.h>
32 #define EAGLEUSBVERSION "ueagle 1.4"
38 #define uea_dbg(usb_dev, format, args...) \
41 dev_dbg(&(usb_dev)->dev, \
42 "[ueagle-atm dbg] %s: " format, \
46 #define uea_vdbg(usb_dev, format, args...) \
49 dev_dbg(&(usb_dev)->dev, \
50 "[ueagle-atm vdbg] " format, ##args); \
53 #define uea_enters(usb_dev) \
54 uea_vdbg(usb_dev, "entering %s\n" , __func__)
56 #define uea_leaves(usb_dev) \
57 uea_vdbg(usb_dev, "leaving %s\n" , __func__)
59 #define uea_err(usb_dev, format, args...) \
60 dev_err(&(usb_dev)->dev , "[UEAGLE-ATM] " format , ##args)
62 #define uea_warn(usb_dev, format, args...) \
63 dev_warn(&(usb_dev)->dev , "[Ueagle-atm] " format, ##args)
65 #define uea_info(usb_dev, format, args...) \
66 dev_info(&(usb_dev)->dev , "[ueagle-atm] " format, ##args)
70 /* cmv's from firmware */
84 /* information about currently processed cmv */
100 struct cmv_dsc_e1 e1
;
101 struct cmv_dsc_e4 e4
;
105 struct usb_device
*usb_dev
;
106 struct usbatm_data
*usbatm
;
109 unsigned int driver_info
;
117 wait_queue_head_t sync_q
;
119 struct task_struct
*kthread
;
124 union cmv_dsc cmv_dsc
;
126 struct work_struct task
;
130 const struct firmware
*dsp_firm
;
133 void (*dispatch_cmv
)(struct uea_softc
*, struct intr_pkt
*);
134 void (*schedule_load_page
)(struct uea_softc
*, struct intr_pkt
*);
135 int (*stat
)(struct uea_softc
*);
136 int (*send_cmvs
)(struct uea_softc
*);
138 /* keep in sync with eaglectl */
166 #define ELSA_VID 0x05CC
167 #define ELSA_PID_PSTFIRM 0x3350
168 #define ELSA_PID_PREFIRM 0x3351
170 #define ELSA_PID_A_PREFIRM 0x3352
171 #define ELSA_PID_A_PSTFIRM 0x3353
172 #define ELSA_PID_B_PREFIRM 0x3362
173 #define ELSA_PID_B_PSTFIRM 0x3363
176 * Devolo IDs : pots if (pid & 0x10)
178 #define DEVOLO_VID 0x1039
179 #define DEVOLO_EAGLE_I_A_PID_PSTFIRM 0x2110
180 #define DEVOLO_EAGLE_I_A_PID_PREFIRM 0x2111
182 #define DEVOLO_EAGLE_I_B_PID_PSTFIRM 0x2100
183 #define DEVOLO_EAGLE_I_B_PID_PREFIRM 0x2101
185 #define DEVOLO_EAGLE_II_A_PID_PSTFIRM 0x2130
186 #define DEVOLO_EAGLE_II_A_PID_PREFIRM 0x2131
188 #define DEVOLO_EAGLE_II_B_PID_PSTFIRM 0x2120
189 #define DEVOLO_EAGLE_II_B_PID_PREFIRM 0x2121
192 * Reference design USB IDs
194 #define ANALOG_VID 0x1110
195 #define ADI930_PID_PREFIRM 0x9001
196 #define ADI930_PID_PSTFIRM 0x9000
198 #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
199 #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
201 #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
202 #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
204 #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
205 #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
207 #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
208 #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
210 #define EAGLE_IV_PID_PREFIRM 0x9042 /* Eagle IV */
211 #define EAGLE_IV_PID_PSTFIRM 0x9041 /* Eagle IV */
216 #define USR_VID 0x0BAF
217 #define MILLER_A_PID_PREFIRM 0x00F2
218 #define MILLER_A_PID_PSTFIRM 0x00F1
219 #define MILLER_B_PID_PREFIRM 0x00FA
220 #define MILLER_B_PID_PSTFIRM 0x00F9
221 #define HEINEKEN_A_PID_PREFIRM 0x00F6
222 #define HEINEKEN_A_PID_PSTFIRM 0x00F5
223 #define HEINEKEN_B_PID_PREFIRM 0x00F8
224 #define HEINEKEN_B_PID_PSTFIRM 0x00F7
227 #define PSTFIRM (1<<7)
228 #define AUTO_ANNEX_A (1<<8)
229 #define AUTO_ANNEX_B (1<<9)
239 /* macros for both struct usb_device_id and struct uea_softc */
240 #define UEA_IS_PREFIRM(x) \
241 (!((x)->driver_info & PSTFIRM))
242 #define UEA_CHIP_VERSION(x) \
243 ((x)->driver_info & 0xf)
246 ((x)->annex & ANNEXB)
248 #define INS_TO_USBDEV(ins) (ins->usb_dev)
250 #define GET_STATUS(data) \
253 #define IS_OPERATIONAL(sc) \
254 ((UEA_CHIP_VERSION(sc) != EAGLE_IV) ? \
255 (GET_STATUS(sc->stats.phy.state) == 2) : \
256 (sc->stats.phy.state == 7))
259 * Set of macros to handle unaligned data in the firmware blob.
260 * The FW_GET_BYTE() macro is provided only for consistency.
263 #define FW_GET_BYTE(p) (*((__u8 *) (p)))
265 #define FW_DIR "ueagle-atm/"
266 #define EAGLE_FIRMWARE FW_DIR "eagle.fw"
267 #define ADI930_FIRMWARE FW_DIR "adi930.fw"
268 #define EAGLE_I_FIRMWARE FW_DIR "eagleI.fw"
269 #define EAGLE_II_FIRMWARE FW_DIR "eagleII.fw"
270 #define EAGLE_III_FIRMWARE FW_DIR "eagleIII.fw"
271 #define EAGLE_IV_FIRMWARE FW_DIR "eagleIV.fw"
273 #define DSP4I_FIRMWARE FW_DIR "DSP4i.bin"
274 #define DSP4P_FIRMWARE FW_DIR "DSP4p.bin"
275 #define DSP9I_FIRMWARE FW_DIR "DSP9i.bin"
276 #define DSP9P_FIRMWARE FW_DIR "DSP9p.bin"
277 #define DSPEI_FIRMWARE FW_DIR "DSPei.bin"
278 #define DSPEP_FIRMWARE FW_DIR "DSPep.bin"
279 #define FPGA930_FIRMWARE FW_DIR "930-fpga.bin"
281 #define CMV4P_FIRMWARE FW_DIR "CMV4p.bin"
282 #define CMV4PV2_FIRMWARE FW_DIR "CMV4p.bin.v2"
283 #define CMV4I_FIRMWARE FW_DIR "CMV4i.bin"
284 #define CMV4IV2_FIRMWARE FW_DIR "CMV4i.bin.v2"
285 #define CMV9P_FIRMWARE FW_DIR "CMV9p.bin"
286 #define CMV9PV2_FIRMWARE FW_DIR "CMV9p.bin.v2"
287 #define CMV9I_FIRMWARE FW_DIR "CMV9i.bin"
288 #define CMV9IV2_FIRMWARE FW_DIR "CMV9i.bin.v2"
289 #define CMVEP_FIRMWARE FW_DIR "CMVep.bin"
290 #define CMVEPV2_FIRMWARE FW_DIR "CMVep.bin.v2"
291 #define CMVEI_FIRMWARE FW_DIR "CMVei.bin"
292 #define CMVEIV2_FIRMWARE FW_DIR "CMVei.bin.v2"
294 #define UEA_FW_NAME_MAX 30
297 #define BULK_TIMEOUT 300
298 #define CTRL_TIMEOUT 1000
300 #define ACK_TIMEOUT msecs_to_jiffies(3000)
302 #define UEA_INTR_IFACE_NO 0
303 #define UEA_US_IFACE_NO 1
304 #define UEA_DS_IFACE_NO 2
306 #define FASTEST_ISO_INTF 8
308 #define UEA_BULK_DATA_PIPE 0x02
309 #define UEA_IDMA_PIPE 0x04
310 #define UEA_INTR_PIPE 0x04
311 #define UEA_ISO_DATA_PIPE 0x08
313 #define UEA_E1_SET_BLOCK 0x0001
314 #define UEA_E4_SET_BLOCK 0x002c
315 #define UEA_SET_MODE 0x0003
316 #define UEA_SET_2183_DATA 0x0004
317 #define UEA_SET_TIMEOUT 0x0011
319 #define UEA_LOOPBACK_OFF 0x0002
320 #define UEA_LOOPBACK_ON 0x0003
321 #define UEA_BOOT_IDMA 0x0006
322 #define UEA_START_RESET 0x0007
323 #define UEA_END_RESET 0x0008
325 #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
326 #define UEA_MPTX_START (0x3fce | 0x4000)
327 #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
328 #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
330 /* block information in eagle4 dsp firmware */
341 #define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
342 #define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
344 #define E4_L1_STRING_HEADER 0x10
345 #define E4_MAX_PAGE_NUMBER 0x58
346 #define E4_NO_SWAPPAGE_HEADERS 0x31
348 /* l1_code is eagle4 dsp firmware format */
350 u8 string_header
[E4_L1_STRING_HEADER
];
351 u8 page_number_to_block_index
[E4_MAX_PAGE_NUMBER
];
352 struct block_index page_header
[E4_NO_SWAPPAGE_HEADERS
];
356 /* structures describing a block within a DSP page */
357 struct block_info_e1
{
362 __le16 wOvl
; /* overlay */
365 #define E1_BLOCK_INFO_SIZE 12
367 struct block_info_e4
{
375 #define E4_BLOCK_INFO_SIZE 14
377 #define UEA_BIHDR 0xabcd
378 #define UEA_RESERVED 0xffff
380 /* constants describing cmv type */
381 #define E1_PREAMBLE 0x535c
382 #define E1_MODEMTOHOST 0x01
383 #define E1_HOSTTOMODEM 0x10
385 #define E1_MEMACCESS 0x1
386 #define E1_ADSLDIRECTIVE 0x7
387 #define E1_FUNCTION_TYPE(f) ((f) >> 4)
388 #define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f)
390 #define E4_MEMACCESS 0
391 #define E4_ADSLDIRECTIVE 0xf
392 #define E4_FUNCTION_TYPE(f) ((f) >> 8)
393 #define E4_FUNCTION_SIZE(f) ((f) & 0x0f)
394 #define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f)
397 #define E1_REQUESTREAD 0x0
398 #define E1_REQUESTWRITE 0x1
399 #define E1_REPLYREAD 0x2
400 #define E1_REPLYWRITE 0x3
402 #define E4_REQUESTREAD 0x0
403 #define E4_REQUESTWRITE 0x4
404 #define E4_REPLYREAD (E4_REQUESTREAD | 1)
405 #define E4_REPLYWRITE (E4_REQUESTWRITE | 1)
407 /* for ADSLDIRECTIVE */
408 #define E1_KERNELREADY 0x0
409 #define E1_MODEMREADY 0x1
411 #define E4_KERNELREADY 0x0
412 #define E4_MODEMREADY 0x1
414 #define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
415 #define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | \
416 ((st) & 0xf) << 4 | ((s) & 0xf))
418 #define E1_MAKESA(a, b, c, d) \
419 (((c) & 0xff) << 24 | \
420 ((d) & 0xff) << 16 | \
421 ((a) & 0xff) << 8 | \
424 #define E1_GETSA1(a) ((a >> 8) & 0xff)
425 #define E1_GETSA2(a) (a & 0xff)
426 #define E1_GETSA3(a) ((a >> 24) & 0xff)
427 #define E1_GETSA4(a) ((a >> 16) & 0xff)
429 #define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L')
430 #define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G')
431 #define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O')
432 #define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N')
433 #define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E')
434 #define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T')
445 /* structures representing a CMV (Configuration and Management Variable) */
451 __le32 dwSymbolicAddress
;
452 __le16 wOffsetAddress
;
464 /* structures representing swap information */
465 struct swap_info_e1
{
467 __u8 bOvl
; /* overlay */
470 struct swap_info_e4
{
474 /* structures representing interrupt data */
475 #define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
476 #define e1_bOvl u.e1.s1.swapinfo.bOvl
477 #define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo
479 #define INT_LOADSWAPPAGE 0x0001
480 #define INT_INCOMINGCMV 0x0002
484 struct swap_info_e1 swapinfo
;
495 struct swap_info_e4 swapinfo
;
512 union intr_data_e1 e1
;
513 union intr_data_e4 e4
;
517 #define E1_INTR_PKT_SIZE 28
518 #define E4_INTR_PKT_SIZE 64
520 static struct usb_driver uea_driver
;
521 static DEFINE_MUTEX(uea_mutex
);
522 static const char * const chip_name
[] = {
523 "ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
525 static int modem_index
;
526 static unsigned int debug
;
527 static unsigned int altsetting
[NB_MODEM
] = {
528 [0 ... (NB_MODEM
- 1)] = FASTEST_ISO_INTF
};
529 static bool sync_wait
[NB_MODEM
];
530 static char *cmv_file
[NB_MODEM
];
531 static int annex
[NB_MODEM
];
533 module_param(debug
, uint
, 0644);
534 MODULE_PARM_DESC(debug
, "module debug level (0=off,1=on,2=verbose)");
535 module_param_array(altsetting
, uint
, NULL
, 0644);
536 MODULE_PARM_DESC(altsetting
, "alternate setting for incoming traffic: 0=bulk, "
537 "1=isoc slowest, ... , 8=isoc fastest (default)");
538 module_param_array(sync_wait
, bool, NULL
, 0644);
539 MODULE_PARM_DESC(sync_wait
, "wait the synchronisation before starting ATM");
540 module_param_array(cmv_file
, charp
, NULL
, 0644);
541 MODULE_PARM_DESC(cmv_file
,
542 "file name with configuration and management variables");
543 module_param_array(annex
, uint
, NULL
, 0644);
544 MODULE_PARM_DESC(annex
,
545 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
547 #define uea_wait(sc, cond, timeo) \
549 int _r = wait_event_interruptible_timeout(sc->sync_q, \
550 (cond) || kthread_should_stop(), timeo); \
551 if (kthread_should_stop()) \
556 #define UPDATE_ATM_STAT(type, val) \
558 if (sc->usbatm->atm_dev) \
559 sc->usbatm->atm_dev->type = val; \
562 #define UPDATE_ATM_SIGNAL(val) \
564 if (sc->usbatm->atm_dev) \
565 atm_dev_signal_change(sc->usbatm->atm_dev, val); \
569 /* Firmware loading */
570 #define LOAD_INTERNAL 0xA0
571 #define F8051_USBCS 0x7f92
574 * uea_send_modem_cmd - Send a command for pre-firmware devices.
576 static int uea_send_modem_cmd(struct usb_device
*usb
,
577 u16 addr
, u16 size
, const u8
*buff
)
582 xfer_buff
= kmemdup(buff
, size
, GFP_KERNEL
);
584 ret
= usb_control_msg(usb
,
585 usb_sndctrlpipe(usb
, 0),
587 USB_DIR_OUT
| USB_TYPE_VENDOR
|
588 USB_RECIP_DEVICE
, addr
, 0, xfer_buff
,
596 return (ret
== size
) ? 0 : -EIO
;
599 static void uea_upload_pre_firmware(const struct firmware
*fw_entry
,
602 struct usb_device
*usb
= context
;
610 uea_err(usb
, "firmware is not available\n");
614 pfw
= fw_entry
->data
;
615 size
= fw_entry
->size
;
617 goto err_fw_corrupted
;
619 crc
= get_unaligned_le32(pfw
);
622 if (crc32_be(0, pfw
, size
) != crc
)
623 goto err_fw_corrupted
;
626 * Start to upload firmware : send reset
629 ret
= uea_send_modem_cmd(usb
, F8051_USBCS
, sizeof(value
), &value
);
632 uea_err(usb
, "modem reset failed with error %d\n", ret
);
637 u8 len
= FW_GET_BYTE(pfw
);
638 u16 add
= get_unaligned_le16(pfw
+ 1);
642 goto err_fw_corrupted
;
644 ret
= uea_send_modem_cmd(usb
, add
, len
, pfw
+ 3);
646 uea_err(usb
, "uploading firmware data failed "
647 "with error %d\n", ret
);
654 goto err_fw_corrupted
;
657 * Tell the modem we finish : de-assert reset
660 ret
= uea_send_modem_cmd(usb
, F8051_USBCS
, 1, &value
);
662 uea_err(usb
, "modem de-assert failed with error %d\n", ret
);
664 uea_info(usb
, "firmware uploaded\n");
669 uea_err(usb
, "firmware is corrupted\n");
671 release_firmware(fw_entry
);
676 * uea_load_firmware - Load usb firmware for pre-firmware devices.
678 static int uea_load_firmware(struct usb_device
*usb
, unsigned int ver
)
681 char *fw_name
= EAGLE_FIRMWARE
;
684 uea_info(usb
, "pre-firmware device, uploading firmware\n");
688 fw_name
= ADI930_FIRMWARE
;
691 fw_name
= EAGLE_I_FIRMWARE
;
694 fw_name
= EAGLE_II_FIRMWARE
;
697 fw_name
= EAGLE_III_FIRMWARE
;
700 fw_name
= EAGLE_IV_FIRMWARE
;
704 ret
= request_firmware_nowait(THIS_MODULE
, 1, fw_name
, &usb
->dev
,
706 uea_upload_pre_firmware
);
708 uea_err(usb
, "firmware %s is not available\n", fw_name
);
710 uea_info(usb
, "loading firmware %s\n", fw_name
);
716 /* modem management : dsp firmware, send/read CMV, monitoring statistic
720 * Make sure that the DSP code provided is safe to use.
722 static int check_dsp_e1(const u8
*dsp
, unsigned int len
)
724 u8 pagecount
, blockcount
;
727 unsigned int i
, j
, p
, pp
;
729 pagecount
= FW_GET_BYTE(dsp
);
732 /* enough space for page offsets? */
733 if (p
+ 4 * pagecount
> len
)
736 for (i
= 0; i
< pagecount
; i
++) {
738 pageoffset
= get_unaligned_le32(dsp
+ p
);
744 /* enough space for blockcount? */
745 if (pageoffset
>= len
)
749 blockcount
= FW_GET_BYTE(dsp
+ pp
);
752 for (j
= 0; j
< blockcount
; j
++) {
754 /* enough space for block header? */
758 pp
+= 2; /* skip blockaddr */
759 blocksize
= get_unaligned_le16(dsp
+ pp
);
762 /* enough space for block data? */
763 if (pp
+ blocksize
> len
)
773 static int check_dsp_e4(const u8
*dsp
, int len
)
776 struct l1_code
*p
= (struct l1_code
*) dsp
;
777 unsigned int sum
= p
->code
- dsp
;
782 if (strcmp("STRATIPHY ANEXA", p
->string_header
) != 0 &&
783 strcmp("STRATIPHY ANEXB", p
->string_header
) != 0)
786 for (i
= 0; i
< E4_MAX_PAGE_NUMBER
; i
++) {
787 struct block_index
*blockidx
;
788 u8 blockno
= p
->page_number_to_block_index
[i
];
789 if (blockno
>= E4_NO_SWAPPAGE_HEADERS
)
795 if (blockno
>= E4_NO_SWAPPAGE_HEADERS
)
798 blockidx
= &p
->page_header
[blockno
++];
799 if ((u8
*)(blockidx
+ 1) - dsp
>= len
)
802 if (le16_to_cpu(blockidx
->PageNumber
) != i
)
805 l
= E4_PAGE_BYTES(blockidx
->PageSize
);
807 l
+= le32_to_cpu(blockidx
->PageOffset
);
811 /* zero is zero regardless endianes */
812 } while (blockidx
->NotLastBlock
);
815 return (sum
== len
) ? 0 : 1;
819 * send data to the idma pipe
821 static int uea_idma_write(struct uea_softc
*sc
, const void *data
, u32 size
)
827 xfer_buff
= kmemdup(data
, size
, GFP_KERNEL
);
829 uea_err(INS_TO_USBDEV(sc
), "can't allocate xfer_buff\n");
833 ret
= usb_bulk_msg(sc
->usb_dev
,
834 usb_sndbulkpipe(sc
->usb_dev
, UEA_IDMA_PIPE
),
835 xfer_buff
, size
, &bytes_read
, BULK_TIMEOUT
);
840 if (size
!= bytes_read
) {
841 uea_err(INS_TO_USBDEV(sc
), "size != bytes_read %d %d\n", size
,
849 static int request_dsp(struct uea_softc
*sc
)
854 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
856 dsp_name
= DSP4I_FIRMWARE
;
858 dsp_name
= DSP4P_FIRMWARE
;
859 } else if (UEA_CHIP_VERSION(sc
) == ADI930
) {
861 dsp_name
= DSP9I_FIRMWARE
;
863 dsp_name
= DSP9P_FIRMWARE
;
866 dsp_name
= DSPEI_FIRMWARE
;
868 dsp_name
= DSPEP_FIRMWARE
;
871 ret
= request_firmware(&sc
->dsp_firm
, dsp_name
, &sc
->usb_dev
->dev
);
873 uea_err(INS_TO_USBDEV(sc
),
874 "requesting firmware %s failed with error %d\n",
879 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
)
880 ret
= check_dsp_e4(sc
->dsp_firm
->data
, sc
->dsp_firm
->size
);
882 ret
= check_dsp_e1(sc
->dsp_firm
->data
, sc
->dsp_firm
->size
);
885 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n",
887 release_firmware(sc
->dsp_firm
);
896 * The uea_load_page() function must be called within a process context
898 static void uea_load_page_e1(struct work_struct
*work
)
900 struct uea_softc
*sc
= container_of(work
, struct uea_softc
, task
);
901 u16 pageno
= sc
->pageno
;
903 struct block_info_e1 bi
;
906 u8 pagecount
, blockcount
;
907 u16 blockaddr
, blocksize
;
911 /* reload firmware when reboot start and it's loaded already */
912 if (ovl
== 0 && pageno
== 0) {
913 release_firmware(sc
->dsp_firm
);
917 if (sc
->dsp_firm
== NULL
&& request_dsp(sc
) < 0)
920 p
= sc
->dsp_firm
->data
;
921 pagecount
= FW_GET_BYTE(p
);
924 if (pageno
>= pagecount
)
928 pageoffset
= get_unaligned_le32(p
);
933 p
= sc
->dsp_firm
->data
+ pageoffset
;
934 blockcount
= FW_GET_BYTE(p
);
937 uea_dbg(INS_TO_USBDEV(sc
),
938 "sending %u blocks for DSP page %u\n", blockcount
, pageno
);
940 bi
.wHdr
= cpu_to_le16(UEA_BIHDR
);
941 bi
.wOvl
= cpu_to_le16(ovl
);
942 bi
.wOvlOffset
= cpu_to_le16(ovl
| 0x8000);
944 for (i
= 0; i
< blockcount
; i
++) {
945 blockaddr
= get_unaligned_le16(p
);
948 blocksize
= get_unaligned_le16(p
);
951 bi
.wSize
= cpu_to_le16(blocksize
);
952 bi
.wAddress
= cpu_to_le16(blockaddr
);
953 bi
.wLast
= cpu_to_le16((i
== blockcount
- 1) ? 1 : 0);
955 /* send block info through the IDMA pipe */
956 if (uea_idma_write(sc
, &bi
, E1_BLOCK_INFO_SIZE
))
959 /* send block data through the IDMA pipe */
960 if (uea_idma_write(sc
, p
, blocksize
))
969 uea_err(INS_TO_USBDEV(sc
), "sending DSP block %u failed\n", i
);
972 uea_err(INS_TO_USBDEV(sc
), "invalid DSP page %u requested\n", pageno
);
975 static void __uea_load_page_e4(struct uea_softc
*sc
, u8 pageno
, int boot
)
977 struct block_info_e4 bi
;
978 struct block_index
*blockidx
;
979 struct l1_code
*p
= (struct l1_code
*) sc
->dsp_firm
->data
;
980 u8 blockno
= p
->page_number_to_block_index
[pageno
];
982 bi
.wHdr
= cpu_to_be16(UEA_BIHDR
);
984 bi
.bPageNumber
= pageno
;
985 bi
.wReserved
= cpu_to_be16(UEA_RESERVED
);
988 const u8
*blockoffset
;
989 unsigned int blocksize
;
991 blockidx
= &p
->page_header
[blockno
];
992 blocksize
= E4_PAGE_BYTES(blockidx
->PageSize
);
993 blockoffset
= sc
->dsp_firm
->data
+ le32_to_cpu(
994 blockidx
->PageOffset
);
996 bi
.dwSize
= cpu_to_be32(blocksize
);
997 bi
.dwAddress
= cpu_to_be32(le32_to_cpu(blockidx
->PageAddress
));
999 uea_dbg(INS_TO_USBDEV(sc
),
1000 "sending block %u for DSP page "
1001 "%u size %u address %x\n",
1002 blockno
, pageno
, blocksize
,
1003 le32_to_cpu(blockidx
->PageAddress
));
1005 /* send block info through the IDMA pipe */
1006 if (uea_idma_write(sc
, &bi
, E4_BLOCK_INFO_SIZE
))
1009 /* send block data through the IDMA pipe */
1010 if (uea_idma_write(sc
, blockoffset
, blocksize
))
1014 } while (blockidx
->NotLastBlock
);
1019 uea_err(INS_TO_USBDEV(sc
), "sending DSP block %u failed\n", blockno
);
1023 static void uea_load_page_e4(struct work_struct
*work
)
1025 struct uea_softc
*sc
= container_of(work
, struct uea_softc
, task
);
1026 u8 pageno
= sc
->pageno
;
1028 struct block_info_e4 bi
;
1031 uea_dbg(INS_TO_USBDEV(sc
), "sending DSP page %u\n", pageno
);
1033 /* reload firmware when reboot start and it's loaded already */
1035 release_firmware(sc
->dsp_firm
);
1036 sc
->dsp_firm
= NULL
;
1039 if (sc
->dsp_firm
== NULL
&& request_dsp(sc
) < 0)
1042 p
= (struct l1_code
*) sc
->dsp_firm
->data
;
1043 if (pageno
>= le16_to_cpu(p
->page_header
[0].PageNumber
)) {
1044 uea_err(INS_TO_USBDEV(sc
), "invalid DSP "
1045 "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
),
1143 E1_FUNCTION_SUBTYPE(function
),
1144 E1_GETSA1(address
), E1_GETSA2(address
),
1146 E1_GETSA4(address
), offset
, data
);
1148 /* we send a request, but we expect a reply */
1149 sc
->cmv_dsc
.e1
.function
= function
| 0x2;
1150 sc
->cmv_dsc
.e1
.idx
++;
1151 sc
->cmv_dsc
.e1
.address
= address
;
1152 sc
->cmv_dsc
.e1
.offset
= offset
;
1154 cmv
.wPreamble
= cpu_to_le16(E1_PREAMBLE
);
1155 cmv
.bDirection
= E1_HOSTTOMODEM
;
1156 cmv
.bFunction
= function
;
1157 cmv
.wIndex
= cpu_to_le16(sc
->cmv_dsc
.e1
.idx
);
1158 put_unaligned_le32(address
, &cmv
.dwSymbolicAddress
);
1159 cmv
.wOffsetAddress
= cpu_to_le16(offset
);
1160 put_unaligned_le32(data
>> 16 | data
<< 16, &cmv
.dwData
);
1162 ret
= uea_request(sc
, UEA_E1_SET_BLOCK
, UEA_MPTX_START
,
1166 ret
= wait_cmv_ack(sc
);
1167 uea_leaves(INS_TO_USBDEV(sc
));
1171 static int uea_cmv_e4(struct uea_softc
*sc
,
1172 u16 function
, u16 group
, u16 address
, u16 offset
, u32 data
)
1177 uea_enters(INS_TO_USBDEV(sc
));
1178 memset(&cmv
, 0, sizeof(cmv
));
1180 uea_vdbg(INS_TO_USBDEV(sc
), "Function : %d-%d, Group : 0x%04x, "
1181 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1182 E4_FUNCTION_TYPE(function
), E4_FUNCTION_SUBTYPE(function
),
1183 group
, address
, offset
, data
);
1185 /* we send a request, but we expect a reply */
1186 sc
->cmv_dsc
.e4
.function
= function
| (0x1 << 4);
1187 sc
->cmv_dsc
.e4
.offset
= offset
;
1188 sc
->cmv_dsc
.e4
.address
= address
;
1189 sc
->cmv_dsc
.e4
.group
= group
;
1191 cmv
.wFunction
= cpu_to_be16(function
);
1192 cmv
.wGroup
= cpu_to_be16(group
);
1193 cmv
.wAddress
= cpu_to_be16(address
);
1194 cmv
.wOffset
= cpu_to_be16(offset
);
1195 cmv
.dwData
[0] = cpu_to_be32(data
);
1197 ret
= uea_request(sc
, UEA_E4_SET_BLOCK
, UEA_MPTX_START
,
1201 ret
= wait_cmv_ack(sc
);
1202 uea_leaves(INS_TO_USBDEV(sc
));
1206 static inline int uea_read_cmv_e1(struct uea_softc
*sc
,
1207 u32 address
, u16 offset
, u32
*data
)
1209 int ret
= uea_cmv_e1(sc
, E1_MAKEFUNCTION(E1_MEMACCESS
, E1_REQUESTREAD
),
1210 address
, offset
, 0);
1212 uea_err(INS_TO_USBDEV(sc
),
1213 "reading cmv failed with error %d\n", ret
);
1220 static inline int uea_read_cmv_e4(struct uea_softc
*sc
,
1221 u8 size
, u16 group
, u16 address
, u16 offset
, u32
*data
)
1223 int ret
= uea_cmv_e4(sc
, E4_MAKEFUNCTION(E4_MEMACCESS
,
1224 E4_REQUESTREAD
, size
),
1225 group
, address
, offset
, 0);
1227 uea_err(INS_TO_USBDEV(sc
),
1228 "reading cmv failed with error %d\n", ret
);
1231 /* size is in 16-bit word quantities */
1233 *(data
+ 1) = sc
->data1
;
1238 static inline int uea_write_cmv_e1(struct uea_softc
*sc
,
1239 u32 address
, u16 offset
, u32 data
)
1241 int ret
= uea_cmv_e1(sc
, E1_MAKEFUNCTION(E1_MEMACCESS
, E1_REQUESTWRITE
),
1242 address
, offset
, data
);
1244 uea_err(INS_TO_USBDEV(sc
),
1245 "writing cmv failed with error %d\n", ret
);
1250 static inline int uea_write_cmv_e4(struct uea_softc
*sc
,
1251 u8 size
, u16 group
, u16 address
, u16 offset
, u32 data
)
1253 int ret
= uea_cmv_e4(sc
, E4_MAKEFUNCTION(E4_MEMACCESS
,
1254 E4_REQUESTWRITE
, size
),
1255 group
, address
, offset
, data
);
1257 uea_err(INS_TO_USBDEV(sc
),
1258 "writing cmv failed with error %d\n", ret
);
1263 static void uea_set_bulk_timeout(struct uea_softc
*sc
, u32 dsrate
)
1268 /* in bulk mode the modem have problem with high rate
1269 * changing internal timing could improve things, but the
1270 * value is mysterious.
1271 * ADI930 don't support it (-EPIPE error).
1274 if (UEA_CHIP_VERSION(sc
) == ADI930
||
1275 altsetting
[sc
->modem_index
] > 0 ||
1276 sc
->stats
.phy
.dsrate
== dsrate
)
1279 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1280 timeout
= (dsrate
<= 1024*1024) ? 0 : 1;
1281 ret
= uea_request(sc
, UEA_SET_TIMEOUT
, timeout
, 0, NULL
);
1282 uea_info(INS_TO_USBDEV(sc
), "setting new timeout %d%s\n",
1283 timeout
, ret
< 0 ? " failed" : "");
1288 * Monitor the modem and update the stat
1289 * return 0 if everything is ok
1290 * return < 0 if an error occurs (-EAGAIN reboot needed)
1292 static int uea_stat_e1(struct uea_softc
*sc
)
1297 uea_enters(INS_TO_USBDEV(sc
));
1298 data
= sc
->stats
.phy
.state
;
1300 ret
= uea_read_cmv_e1(sc
, E1_SA_STAT
, 0, &sc
->stats
.phy
.state
);
1304 switch (GET_STATUS(sc
->stats
.phy
.state
)) {
1305 case 0: /* not yet synchronized */
1306 uea_dbg(INS_TO_USBDEV(sc
),
1307 "modem not yet synchronized\n");
1310 case 1: /* initialization */
1311 uea_dbg(INS_TO_USBDEV(sc
), "modem initializing\n");
1314 case 2: /* operational */
1315 uea_vdbg(INS_TO_USBDEV(sc
), "modem operational\n");
1318 case 3: /* fail ... */
1319 uea_info(INS_TO_USBDEV(sc
), "modem synchronization failed"
1320 " (may be try other cmv/dsp)\n");
1323 case 4 ... 6: /* test state */
1324 uea_warn(INS_TO_USBDEV(sc
),
1325 "modem in test mode - not supported\n");
1328 case 7: /* fast-retain ... */
1329 uea_info(INS_TO_USBDEV(sc
), "modem in fast-retain mode\n");
1332 uea_err(INS_TO_USBDEV(sc
), "modem invalid SW mode %d\n",
1333 GET_STATUS(sc
->stats
.phy
.state
));
1337 if (GET_STATUS(data
) != 2) {
1338 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_OFF
, 0, NULL
);
1339 uea_info(INS_TO_USBDEV(sc
), "modem operational\n");
1341 /* release the dsp firmware as it is not needed until
1344 release_firmware(sc
->dsp_firm
);
1345 sc
->dsp_firm
= NULL
;
1348 /* always update it as atm layer could not be init when we switch to
1351 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND
);
1353 /* wake up processes waiting for synchronization */
1354 wake_up(&sc
->sync_q
);
1356 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 2, &sc
->stats
.phy
.flags
);
1359 sc
->stats
.phy
.mflags
|= sc
->stats
.phy
.flags
;
1361 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1362 * we check the status again in order to detect the failure earlier
1364 if (sc
->stats
.phy
.flags
) {
1365 uea_dbg(INS_TO_USBDEV(sc
), "Stat flag = 0x%x\n",
1366 sc
->stats
.phy
.flags
);
1370 ret
= uea_read_cmv_e1(sc
, E1_SA_RATE
, 0, &data
);
1374 uea_set_bulk_timeout(sc
, (data
>> 16) * 32);
1375 sc
->stats
.phy
.dsrate
= (data
>> 16) * 32;
1376 sc
->stats
.phy
.usrate
= (data
& 0xffff) * 32;
1377 UPDATE_ATM_STAT(link_rate
, sc
->stats
.phy
.dsrate
* 1000 / 424);
1379 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 23, &data
);
1382 sc
->stats
.phy
.dsattenuation
= (data
& 0xff) / 2;
1384 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 47, &data
);
1387 sc
->stats
.phy
.usattenuation
= (data
& 0xff) / 2;
1389 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 25, &sc
->stats
.phy
.dsmargin
);
1393 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 49, &sc
->stats
.phy
.usmargin
);
1397 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 51, &sc
->stats
.phy
.rxflow
);
1401 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 52, &sc
->stats
.phy
.txflow
);
1405 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 54, &sc
->stats
.phy
.dsunc
);
1409 /* only for atu-c */
1410 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 58, &sc
->stats
.phy
.usunc
);
1414 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 53, &sc
->stats
.phy
.dscorr
);
1418 /* only for atu-c */
1419 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 57, &sc
->stats
.phy
.uscorr
);
1423 ret
= uea_read_cmv_e1(sc
, E1_SA_INFO
, 8, &sc
->stats
.phy
.vidco
);
1427 ret
= uea_read_cmv_e1(sc
, E1_SA_INFO
, 13, &sc
->stats
.phy
.vidcpe
);
1434 static int uea_stat_e4(struct uea_softc
*sc
)
1440 uea_enters(INS_TO_USBDEV(sc
));
1441 data
= sc
->stats
.phy
.state
;
1443 /* XXX only need to be done before operationnal... */
1444 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_STAT
, 0, 0, &sc
->stats
.phy
.state
);
1448 switch (sc
->stats
.phy
.state
) {
1449 case 0x0: /* not yet synchronized */
1453 uea_dbg(INS_TO_USBDEV(sc
), "modem not yet "
1456 case 0x5: /* initialization */
1460 uea_dbg(INS_TO_USBDEV(sc
), "modem initializing\n");
1462 case 0x2: /* fail ... */
1463 uea_info(INS_TO_USBDEV(sc
), "modem synchronization "
1464 "failed (may be try other cmv/dsp)\n");
1466 case 0x7: /* operational */
1469 uea_warn(INS_TO_USBDEV(sc
), "unknown state: %x\n",
1470 sc
->stats
.phy
.state
);
1475 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_OFF
, 0, NULL
);
1476 uea_info(INS_TO_USBDEV(sc
), "modem operational\n");
1478 /* release the dsp firmware as it is not needed until
1481 release_firmware(sc
->dsp_firm
);
1482 sc
->dsp_firm
= NULL
;
1485 /* always update it as atm layer could not be init when we switch to
1488 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND
);
1490 /* wake up processes waiting for synchronization */
1491 wake_up(&sc
->sync_q
);
1493 /* TODO improve this state machine :
1494 * we need some CMV info : what they do and their unit
1495 * we should find the equivalent of eagle3- CMV
1498 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_DIAG
, 0, 0, &sc
->stats
.phy
.flags
);
1501 sc
->stats
.phy
.mflags
|= sc
->stats
.phy
.flags
;
1503 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1504 * we check the status again in order to detect the failure earlier
1506 if (sc
->stats
.phy
.flags
) {
1507 uea_dbg(INS_TO_USBDEV(sc
), "Stat flag = 0x%x\n",
1508 sc
->stats
.phy
.flags
);
1509 if (sc
->stats
.phy
.flags
& 1) /* delineation LOSS */
1511 if (sc
->stats
.phy
.flags
& 0x4000) /* Reset Flag */
1516 /* rate data may be in upper or lower half of 64 bit word, strange */
1517 ret
= uea_read_cmv_e4(sc
, 4, E4_SA_RATE
, 0, 0, tmp_arr
);
1520 data
= (tmp_arr
[0]) ? tmp_arr
[0] : tmp_arr
[1];
1521 sc
->stats
.phy
.usrate
= data
/ 1000;
1523 ret
= uea_read_cmv_e4(sc
, 4, E4_SA_RATE
, 1, 0, tmp_arr
);
1526 data
= (tmp_arr
[0]) ? tmp_arr
[0] : tmp_arr
[1];
1527 uea_set_bulk_timeout(sc
, data
/ 1000);
1528 sc
->stats
.phy
.dsrate
= data
/ 1000;
1529 UPDATE_ATM_STAT(link_rate
, sc
->stats
.phy
.dsrate
* 1000 / 424);
1531 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 68, 1, &data
);
1534 sc
->stats
.phy
.dsattenuation
= data
/ 10;
1536 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 69, 1, &data
);
1539 sc
->stats
.phy
.usattenuation
= data
/ 10;
1541 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 68, 3, &data
);
1544 sc
->stats
.phy
.dsmargin
= data
/ 2;
1546 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 69, 3, &data
);
1549 sc
->stats
.phy
.usmargin
= data
/ 10;
1554 static void cmvs_file_name(struct uea_softc
*sc
, char *const cmv_name
, int ver
)
1556 char file_arr
[] = "CMVxy.bin";
1559 kernel_param_lock(THIS_MODULE
);
1560 /* set proper name corresponding modem version and line type */
1561 if (cmv_file
[sc
->modem_index
] == NULL
) {
1562 if (UEA_CHIP_VERSION(sc
) == ADI930
)
1564 else if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
)
1569 file_arr
[4] = IS_ISDN(sc
) ? 'i' : 'p';
1572 file
= cmv_file
[sc
->modem_index
];
1574 strcpy(cmv_name
, FW_DIR
);
1575 strlcat(cmv_name
, file
, UEA_FW_NAME_MAX
);
1577 strlcat(cmv_name
, ".v2", UEA_FW_NAME_MAX
);
1578 kernel_param_unlock(THIS_MODULE
);
1581 static int request_cmvs_old(struct uea_softc
*sc
,
1582 void **cmvs
, const struct firmware
**fw
)
1586 char cmv_name
[UEA_FW_NAME_MAX
]; /* 30 bytes stack variable */
1588 cmvs_file_name(sc
, cmv_name
, 1);
1589 ret
= request_firmware(fw
, cmv_name
, &sc
->usb_dev
->dev
);
1591 uea_err(INS_TO_USBDEV(sc
),
1592 "requesting firmware %s failed with error %d\n",
1597 data
= (u8
*) (*fw
)->data
;
1600 goto err_fw_corrupted
;
1602 if (size
!= *data
* sizeof(struct uea_cmvs_v1
) + 1)
1603 goto err_fw_corrupted
;
1605 *cmvs
= (void *)(data
+ 1);
1609 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n", cmv_name
);
1610 release_firmware(*fw
);
1614 static int request_cmvs(struct uea_softc
*sc
,
1615 void **cmvs
, const struct firmware
**fw
, int *ver
)
1620 char cmv_name
[UEA_FW_NAME_MAX
]; /* 30 bytes stack variable */
1622 cmvs_file_name(sc
, cmv_name
, 2);
1623 ret
= request_firmware(fw
, cmv_name
, &sc
->usb_dev
->dev
);
1625 /* if caller can handle old version, try to provide it */
1627 uea_warn(INS_TO_USBDEV(sc
), "requesting "
1628 "firmware %s failed, "
1629 "try to get older cmvs\n", cmv_name
);
1630 return request_cmvs_old(sc
, cmvs
, fw
);
1632 uea_err(INS_TO_USBDEV(sc
),
1633 "requesting firmware %s failed with error %d\n",
1639 data
= (u8
*) (*fw
)->data
;
1640 if (size
< 4 || strncmp(data
, "cmv2", 4) != 0) {
1642 uea_warn(INS_TO_USBDEV(sc
), "firmware %s is corrupted,"
1643 " try to get older cmvs\n", cmv_name
);
1644 release_firmware(*fw
);
1645 return request_cmvs_old(sc
, cmvs
, fw
);
1647 goto err_fw_corrupted
;
1655 goto err_fw_corrupted
;
1657 crc
= get_unaligned_le32(data
);
1660 if (crc32_be(0, data
, size
) != crc
)
1661 goto err_fw_corrupted
;
1663 if (size
!= *data
* sizeof(struct uea_cmvs_v2
) + 1)
1664 goto err_fw_corrupted
;
1666 *cmvs
= (void *) (data
+ 1);
1670 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n", cmv_name
);
1671 release_firmware(*fw
);
1675 static int uea_send_cmvs_e1(struct uea_softc
*sc
)
1679 const struct firmware
*cmvs_fw
;
1680 int ver
= 1; /* we can handle v1 cmv firmware version; */
1682 /* Enter in R-IDLE (cmv) until instructed otherwise */
1683 ret
= uea_write_cmv_e1(sc
, E1_SA_CNTL
, 0, 1);
1687 /* Dump firmware version */
1688 ret
= uea_read_cmv_e1(sc
, E1_SA_INFO
, 10, &sc
->stats
.phy
.firmid
);
1691 uea_info(INS_TO_USBDEV(sc
), "ATU-R firmware version : %x\n",
1692 sc
->stats
.phy
.firmid
);
1695 ret
= len
= request_cmvs(sc
, &cmvs_ptr
, &cmvs_fw
, &ver
);
1701 struct uea_cmvs_v1
*cmvs_v1
= cmvs_ptr
;
1703 uea_warn(INS_TO_USBDEV(sc
), "use deprecated cmvs version, "
1704 "please update your firmware\n");
1706 for (i
= 0; i
< len
; i
++) {
1707 ret
= uea_write_cmv_e1(sc
,
1708 get_unaligned_le32(&cmvs_v1
[i
].address
),
1709 get_unaligned_le16(&cmvs_v1
[i
].offset
),
1710 get_unaligned_le32(&cmvs_v1
[i
].data
));
1714 } else if (ver
== 2) {
1715 struct uea_cmvs_v2
*cmvs_v2
= cmvs_ptr
;
1717 for (i
= 0; i
< len
; i
++) {
1718 ret
= uea_write_cmv_e1(sc
,
1719 get_unaligned_le32(&cmvs_v2
[i
].address
),
1720 (u16
) get_unaligned_le32(&cmvs_v2
[i
].offset
),
1721 get_unaligned_le32(&cmvs_v2
[i
].data
));
1726 /* This really should not happen */
1727 uea_err(INS_TO_USBDEV(sc
), "bad cmvs version %d\n", ver
);
1731 /* Enter in R-ACT-REQ */
1732 ret
= uea_write_cmv_e1(sc
, E1_SA_CNTL
, 0, 2);
1733 uea_vdbg(INS_TO_USBDEV(sc
), "Entering in R-ACT-REQ state\n");
1734 uea_info(INS_TO_USBDEV(sc
), "modem started, waiting "
1735 "synchronization...\n");
1737 release_firmware(cmvs_fw
);
1741 static int uea_send_cmvs_e4(struct uea_softc
*sc
)
1745 const struct firmware
*cmvs_fw
;
1746 int ver
= 2; /* we can only handle v2 cmv firmware version; */
1748 /* Enter in R-IDLE (cmv) until instructed otherwise */
1749 ret
= uea_write_cmv_e4(sc
, 1, E4_SA_CNTL
, 0, 0, 1);
1753 /* Dump firmware version */
1754 /* XXX don't read the 3th byte as it is always 6 */
1755 ret
= uea_read_cmv_e4(sc
, 2, E4_SA_INFO
, 55, 0, &sc
->stats
.phy
.firmid
);
1758 uea_info(INS_TO_USBDEV(sc
), "ATU-R firmware version : %x\n",
1759 sc
->stats
.phy
.firmid
);
1763 ret
= len
= request_cmvs(sc
, &cmvs_ptr
, &cmvs_fw
, &ver
);
1769 struct uea_cmvs_v2
*cmvs_v2
= cmvs_ptr
;
1771 for (i
= 0; i
< len
; i
++) {
1772 ret
= uea_write_cmv_e4(sc
, 1,
1773 get_unaligned_le32(&cmvs_v2
[i
].group
),
1774 get_unaligned_le32(&cmvs_v2
[i
].address
),
1775 get_unaligned_le32(&cmvs_v2
[i
].offset
),
1776 get_unaligned_le32(&cmvs_v2
[i
].data
));
1781 /* This really should not happen */
1782 uea_err(INS_TO_USBDEV(sc
), "bad cmvs version %d\n", ver
);
1786 /* Enter in R-ACT-REQ */
1787 ret
= uea_write_cmv_e4(sc
, 1, E4_SA_CNTL
, 0, 0, 2);
1788 uea_vdbg(INS_TO_USBDEV(sc
), "Entering in R-ACT-REQ state\n");
1789 uea_info(INS_TO_USBDEV(sc
), "modem started, waiting "
1790 "synchronization...\n");
1792 release_firmware(cmvs_fw
);
1796 /* Start boot post firmware modem:
1797 * - send reset commands through usb control pipe
1798 * - start workqueue for DSP loading
1799 * - send CMV options to modem
1802 static int uea_start_reset(struct uea_softc
*sc
)
1804 u16 zero
= 0; /* ;-) */
1807 uea_enters(INS_TO_USBDEV(sc
));
1808 uea_info(INS_TO_USBDEV(sc
), "(re)booting started\n");
1810 /* mask interrupt */
1812 /* We need to set this here because, a ack timeout could have occurred,
1813 * but before we start the reboot, the ack occurs and set this to 1.
1814 * So we will failed to wait Ready CMV.
1817 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST
);
1819 /* reset statistics */
1820 memset(&sc
->stats
, 0, sizeof(struct uea_stats
));
1822 /* tell the modem that we want to boot in IDMA mode */
1823 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_ON
, 0, NULL
);
1824 uea_request(sc
, UEA_SET_MODE
, UEA_BOOT_IDMA
, 0, NULL
);
1826 /* enter reset mode */
1827 uea_request(sc
, UEA_SET_MODE
, UEA_START_RESET
, 0, NULL
);
1829 /* original driver use 200ms, but windows driver use 100ms */
1830 ret
= uea_wait(sc
, 0, msecs_to_jiffies(100));
1834 /* leave reset mode */
1835 uea_request(sc
, UEA_SET_MODE
, UEA_END_RESET
, 0, NULL
);
1837 if (UEA_CHIP_VERSION(sc
) != EAGLE_IV
) {
1838 /* clear tx and rx mailboxes */
1839 uea_request(sc
, UEA_SET_2183_DATA
, UEA_MPTX_MAILBOX
, 2, &zero
);
1840 uea_request(sc
, UEA_SET_2183_DATA
, UEA_MPRX_MAILBOX
, 2, &zero
);
1841 uea_request(sc
, UEA_SET_2183_DATA
, UEA_SWAP_MAILBOX
, 2, &zero
);
1844 ret
= uea_wait(sc
, 0, msecs_to_jiffies(1000));
1848 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
)
1849 sc
->cmv_dsc
.e4
.function
= E4_MAKEFUNCTION(E4_ADSLDIRECTIVE
,
1852 sc
->cmv_dsc
.e1
.function
= E1_MAKEFUNCTION(E1_ADSLDIRECTIVE
,
1855 /* demask interrupt */
1858 /* start loading DSP */
1861 schedule_work(&sc
->task
);
1863 /* wait for modem ready CMV */
1864 ret
= wait_cmv_ack(sc
);
1868 uea_vdbg(INS_TO_USBDEV(sc
), "Ready CMV received\n");
1870 ret
= sc
->send_cmvs(sc
);
1875 uea_leaves(INS_TO_USBDEV(sc
));
1880 * In case of an error wait 1s before rebooting the modem
1881 * if the modem don't request reboot (-EAGAIN).
1882 * Monitor the modem every 1s.
1885 static int uea_kthread(void *data
)
1887 struct uea_softc
*sc
= data
;
1891 uea_enters(INS_TO_USBDEV(sc
));
1892 while (!kthread_should_stop()) {
1893 if (ret
< 0 || sc
->reset
)
1894 ret
= uea_start_reset(sc
);
1898 uea_wait(sc
, 0, msecs_to_jiffies(1000));
1901 uea_leaves(INS_TO_USBDEV(sc
));
1905 /* Load second usb firmware for ADI930 chip */
1906 static int load_XILINX_firmware(struct uea_softc
*sc
)
1908 const struct firmware
*fw_entry
;
1909 int ret
, size
, u
, ln
;
1912 char *fw_name
= FPGA930_FIRMWARE
;
1914 uea_enters(INS_TO_USBDEV(sc
));
1916 ret
= request_firmware(&fw_entry
, fw_name
, &sc
->usb_dev
->dev
);
1918 uea_err(INS_TO_USBDEV(sc
), "firmware %s is not available\n",
1923 pfw
= fw_entry
->data
;
1924 size
= fw_entry
->size
;
1925 if (size
!= 0x577B) {
1926 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n",
1931 for (u
= 0; u
< size
; u
+= ln
) {
1932 ln
= min(size
- u
, 64);
1933 ret
= uea_request(sc
, 0xe, 0, ln
, pfw
+ u
);
1935 uea_err(INS_TO_USBDEV(sc
),
1936 "elsa download data failed (%d)\n", ret
);
1941 /* finish to send the fpga */
1942 ret
= uea_request(sc
, 0xe, 1, 0, NULL
);
1944 uea_err(INS_TO_USBDEV(sc
),
1945 "elsa download data failed (%d)\n", ret
);
1949 /* Tell the modem we finish : de-assert reset */
1951 ret
= uea_send_modem_cmd(sc
->usb_dev
, 0xe, 1, &value
);
1953 uea_err(sc
->usb_dev
, "elsa de-assert failed with error"
1957 release_firmware(fw_entry
);
1959 uea_leaves(INS_TO_USBDEV(sc
));
1963 /* The modem send us an ack. First with check if it right */
1964 static void uea_dispatch_cmv_e1(struct uea_softc
*sc
, struct intr_pkt
*intr
)
1966 struct cmv_dsc_e1
*dsc
= &sc
->cmv_dsc
.e1
;
1967 struct cmv_e1
*cmv
= &intr
->u
.e1
.s2
.cmv
;
1969 uea_enters(INS_TO_USBDEV(sc
));
1970 if (le16_to_cpu(cmv
->wPreamble
) != E1_PREAMBLE
)
1973 if (cmv
->bDirection
!= E1_MODEMTOHOST
)
1976 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1977 * the first MEMACCESS cmv. Ignore it...
1979 if (cmv
->bFunction
!= dsc
->function
) {
1980 if (UEA_CHIP_VERSION(sc
) == ADI930
1981 && cmv
->bFunction
== E1_MAKEFUNCTION(2, 2)) {
1982 cmv
->wIndex
= cpu_to_le16(dsc
->idx
);
1983 put_unaligned_le32(dsc
->address
,
1984 &cmv
->dwSymbolicAddress
);
1985 cmv
->wOffsetAddress
= cpu_to_le16(dsc
->offset
);
1990 if (cmv
->bFunction
== E1_MAKEFUNCTION(E1_ADSLDIRECTIVE
,
1992 wake_up_cmv_ack(sc
);
1993 uea_leaves(INS_TO_USBDEV(sc
));
1997 /* in case of MEMACCESS */
1998 if (le16_to_cpu(cmv
->wIndex
) != dsc
->idx
||
1999 get_unaligned_le32(&cmv
->dwSymbolicAddress
) != dsc
->address
||
2000 le16_to_cpu(cmv
->wOffsetAddress
) != dsc
->offset
)
2003 sc
->data
= get_unaligned_le32(&cmv
->dwData
);
2004 sc
->data
= sc
->data
<< 16 | sc
->data
>> 16;
2006 wake_up_cmv_ack(sc
);
2007 uea_leaves(INS_TO_USBDEV(sc
));
2011 uea_err(INS_TO_USBDEV(sc
), "unexpected cmv received, "
2012 "Function : %d, Subfunction : %d\n",
2013 E1_FUNCTION_TYPE(cmv
->bFunction
),
2014 E1_FUNCTION_SUBTYPE(cmv
->bFunction
));
2015 uea_leaves(INS_TO_USBDEV(sc
));
2019 uea_err(INS_TO_USBDEV(sc
), "invalid cmv received, "
2020 "wPreamble %d, bDirection %d\n",
2021 le16_to_cpu(cmv
->wPreamble
), cmv
->bDirection
);
2022 uea_leaves(INS_TO_USBDEV(sc
));
2025 /* The modem send us an ack. First with check if it right */
2026 static void uea_dispatch_cmv_e4(struct uea_softc
*sc
, struct intr_pkt
*intr
)
2028 struct cmv_dsc_e4
*dsc
= &sc
->cmv_dsc
.e4
;
2029 struct cmv_e4
*cmv
= &intr
->u
.e4
.s2
.cmv
;
2031 uea_enters(INS_TO_USBDEV(sc
));
2032 uea_dbg(INS_TO_USBDEV(sc
), "cmv %x %x %x %x %x %x\n",
2033 be16_to_cpu(cmv
->wGroup
), be16_to_cpu(cmv
->wFunction
),
2034 be16_to_cpu(cmv
->wOffset
), be16_to_cpu(cmv
->wAddress
),
2035 be32_to_cpu(cmv
->dwData
[0]), be32_to_cpu(cmv
->dwData
[1]));
2037 if (be16_to_cpu(cmv
->wFunction
) != dsc
->function
)
2040 if (be16_to_cpu(cmv
->wFunction
) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE
,
2041 E4_MODEMREADY
, 1)) {
2042 wake_up_cmv_ack(sc
);
2043 uea_leaves(INS_TO_USBDEV(sc
));
2047 /* in case of MEMACCESS */
2048 if (be16_to_cpu(cmv
->wOffset
) != dsc
->offset
||
2049 be16_to_cpu(cmv
->wGroup
) != dsc
->group
||
2050 be16_to_cpu(cmv
->wAddress
) != dsc
->address
)
2053 sc
->data
= be32_to_cpu(cmv
->dwData
[0]);
2054 sc
->data1
= be32_to_cpu(cmv
->dwData
[1]);
2055 wake_up_cmv_ack(sc
);
2056 uea_leaves(INS_TO_USBDEV(sc
));
2060 uea_err(INS_TO_USBDEV(sc
), "unexpected cmv received, "
2061 "Function : %d, Subfunction : %d\n",
2062 E4_FUNCTION_TYPE(cmv
->wFunction
),
2063 E4_FUNCTION_SUBTYPE(cmv
->wFunction
));
2064 uea_leaves(INS_TO_USBDEV(sc
));
2068 static void uea_schedule_load_page_e1(struct uea_softc
*sc
,
2069 struct intr_pkt
*intr
)
2071 sc
->pageno
= intr
->e1_bSwapPageNo
;
2072 sc
->ovl
= intr
->e1_bOvl
>> 4 | intr
->e1_bOvl
<< 4;
2073 schedule_work(&sc
->task
);
2076 static void uea_schedule_load_page_e4(struct uea_softc
*sc
,
2077 struct intr_pkt
*intr
)
2079 sc
->pageno
= intr
->e4_bSwapPageNo
;
2080 schedule_work(&sc
->task
);
2086 static void uea_intr(struct urb
*urb
)
2088 struct uea_softc
*sc
= urb
->context
;
2089 struct intr_pkt
*intr
= urb
->transfer_buffer
;
2090 int status
= urb
->status
;
2092 uea_enters(INS_TO_USBDEV(sc
));
2094 if (unlikely(status
< 0)) {
2095 uea_err(INS_TO_USBDEV(sc
), "uea_intr() failed with %d\n",
2100 /* device-to-host interrupt */
2101 if (intr
->bType
!= 0x08 || sc
->booting
) {
2102 uea_err(INS_TO_USBDEV(sc
), "wrong interrupt\n");
2106 switch (le16_to_cpu(intr
->wInterrupt
)) {
2107 case INT_LOADSWAPPAGE
:
2108 sc
->schedule_load_page(sc
, intr
);
2111 case INT_INCOMINGCMV
:
2112 sc
->dispatch_cmv(sc
, intr
);
2116 uea_err(INS_TO_USBDEV(sc
), "unknown interrupt %u\n",
2117 le16_to_cpu(intr
->wInterrupt
));
2121 usb_submit_urb(sc
->urb_int
, GFP_ATOMIC
);
2125 * Start the modem : init the data and start kernel thread
2127 static int uea_boot(struct uea_softc
*sc
, struct usb_interface
*intf
)
2129 struct intr_pkt
*intr
;
2133 uea_enters(INS_TO_USBDEV(sc
));
2135 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
2136 size
= E4_INTR_PKT_SIZE
;
2137 sc
->dispatch_cmv
= uea_dispatch_cmv_e4
;
2138 sc
->schedule_load_page
= uea_schedule_load_page_e4
;
2139 sc
->stat
= uea_stat_e4
;
2140 sc
->send_cmvs
= uea_send_cmvs_e4
;
2141 INIT_WORK(&sc
->task
, uea_load_page_e4
);
2143 size
= E1_INTR_PKT_SIZE
;
2144 sc
->dispatch_cmv
= uea_dispatch_cmv_e1
;
2145 sc
->schedule_load_page
= uea_schedule_load_page_e1
;
2146 sc
->stat
= uea_stat_e1
;
2147 sc
->send_cmvs
= uea_send_cmvs_e1
;
2148 INIT_WORK(&sc
->task
, uea_load_page_e1
);
2151 init_waitqueue_head(&sc
->sync_q
);
2153 if (UEA_CHIP_VERSION(sc
) == ADI930
)
2154 load_XILINX_firmware(sc
);
2156 if (intf
->cur_altsetting
->desc
.bNumEndpoints
< 1) {
2161 intr
= kmalloc(size
, GFP_KERNEL
);
2165 sc
->urb_int
= usb_alloc_urb(0, GFP_KERNEL
);
2169 usb_fill_int_urb(sc
->urb_int
, sc
->usb_dev
,
2170 usb_rcvintpipe(sc
->usb_dev
, UEA_INTR_PIPE
),
2171 intr
, size
, uea_intr
, sc
,
2172 intf
->cur_altsetting
->endpoint
[0].desc
.bInterval
);
2174 ret
= usb_submit_urb(sc
->urb_int
, GFP_KERNEL
);
2176 uea_err(INS_TO_USBDEV(sc
),
2177 "urb submission failed with error %d\n", ret
);
2181 /* Create worker thread, but don't start it here. Start it after
2182 * all usbatm generic initialization is done.
2184 sc
->kthread
= kthread_create(uea_kthread
, sc
, "ueagle-atm");
2185 if (IS_ERR(sc
->kthread
)) {
2186 uea_err(INS_TO_USBDEV(sc
), "failed to create thread\n");
2187 ret
= PTR_ERR(sc
->kthread
);
2191 uea_leaves(INS_TO_USBDEV(sc
));
2195 usb_kill_urb(sc
->urb_int
);
2197 usb_free_urb(sc
->urb_int
);
2201 uea_leaves(INS_TO_USBDEV(sc
));
2206 * Stop the modem : kill kernel thread and free data
2208 static void uea_stop(struct uea_softc
*sc
)
2211 uea_enters(INS_TO_USBDEV(sc
));
2212 ret
= kthread_stop(sc
->kthread
);
2213 uea_dbg(INS_TO_USBDEV(sc
), "kthread finish with status %d\n", ret
);
2215 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_ON
, 0, NULL
);
2217 usb_kill_urb(sc
->urb_int
);
2218 kfree(sc
->urb_int
->transfer_buffer
);
2219 usb_free_urb(sc
->urb_int
);
2221 /* flush the work item, when no one can schedule it */
2222 flush_work(&sc
->task
);
2224 release_firmware(sc
->dsp_firm
);
2225 uea_leaves(INS_TO_USBDEV(sc
));
2228 /* syfs interface */
2229 static struct uea_softc
*dev_to_uea(struct device
*dev
)
2231 struct usb_interface
*intf
;
2232 struct usbatm_data
*usbatm
;
2234 intf
= to_usb_interface(dev
);
2238 usbatm
= usb_get_intfdata(intf
);
2242 return usbatm
->driver_data
;
2245 static ssize_t
stat_status_show(struct device
*dev
, struct device_attribute
*attr
,
2249 struct uea_softc
*sc
;
2251 mutex_lock(&uea_mutex
);
2252 sc
= dev_to_uea(dev
);
2255 ret
= snprintf(buf
, 10, "%08x\n", sc
->stats
.phy
.state
);
2257 mutex_unlock(&uea_mutex
);
2261 static ssize_t
stat_status_store(struct device
*dev
, struct device_attribute
*attr
,
2262 const char *buf
, size_t count
)
2265 struct uea_softc
*sc
;
2267 mutex_lock(&uea_mutex
);
2268 sc
= dev_to_uea(dev
);
2274 mutex_unlock(&uea_mutex
);
2278 static DEVICE_ATTR_RW(stat_status
);
2280 static ssize_t
stat_human_status_show(struct device
*dev
,
2281 struct device_attribute
*attr
, char *buf
)
2285 struct uea_softc
*sc
;
2287 mutex_lock(&uea_mutex
);
2288 sc
= dev_to_uea(dev
);
2292 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
2293 switch (sc
->stats
.phy
.state
) {
2294 case 0x0: /* not yet synchronized */
2300 case 0x5: /* initialization */
2306 case 0x7: /* operational */
2309 case 0x2: /* fail ... */
2312 default: /* unknown */
2317 modem_state
= GET_STATUS(sc
->stats
.phy
.state
);
2319 switch (modem_state
) {
2321 ret
= sprintf(buf
, "Modem is booting\n");
2324 ret
= sprintf(buf
, "Modem is initializing\n");
2327 ret
= sprintf(buf
, "Modem is operational\n");
2330 ret
= sprintf(buf
, "Modem synchronization failed\n");
2333 ret
= sprintf(buf
, "Modem state is unknown\n");
2337 mutex_unlock(&uea_mutex
);
2341 static DEVICE_ATTR_RO(stat_human_status
);
2343 static ssize_t
stat_delin_show(struct device
*dev
, struct device_attribute
*attr
,
2347 struct uea_softc
*sc
;
2348 char *delin
= "GOOD";
2350 mutex_lock(&uea_mutex
);
2351 sc
= dev_to_uea(dev
);
2355 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
2356 if (sc
->stats
.phy
.flags
& 0x4000)
2358 else if (sc
->stats
.phy
.flags
& 0x0001)
2361 if (sc
->stats
.phy
.flags
& 0x0C00)
2363 else if (sc
->stats
.phy
.flags
& 0x0030)
2367 ret
= sprintf(buf
, "%s\n", delin
);
2369 mutex_unlock(&uea_mutex
);
2373 static DEVICE_ATTR_RO(stat_delin
);
2375 #define UEA_ATTR(name, reset) \
2377 static ssize_t stat_##name##_show(struct device *dev, \
2378 struct device_attribute *attr, char *buf) \
2380 int ret = -ENODEV; \
2381 struct uea_softc *sc; \
2383 mutex_lock(&uea_mutex); \
2384 sc = dev_to_uea(dev); \
2387 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2389 sc->stats.phy.name = 0; \
2391 mutex_unlock(&uea_mutex); \
2395 static DEVICE_ATTR_RO(stat_##name)
2397 UEA_ATTR(mflags
, 1);
2398 UEA_ATTR(vidcpe
, 0);
2399 UEA_ATTR(usrate
, 0);
2400 UEA_ATTR(dsrate
, 0);
2401 UEA_ATTR(usattenuation
, 0);
2402 UEA_ATTR(dsattenuation
, 0);
2403 UEA_ATTR(usmargin
, 0);
2404 UEA_ATTR(dsmargin
, 0);
2405 UEA_ATTR(txflow
, 0);
2406 UEA_ATTR(rxflow
, 0);
2407 UEA_ATTR(uscorr
, 0);
2408 UEA_ATTR(dscorr
, 0);
2411 UEA_ATTR(firmid
, 0);
2413 /* Retrieve the device End System Identifier (MAC) */
2415 static int uea_getesi(struct uea_softc
*sc
, u_char
*esi
)
2417 unsigned char mac_str
[2 * ETH_ALEN
+ 1];
2420 (sc
->usb_dev
, sc
->usb_dev
->descriptor
.iSerialNumber
, mac_str
,
2421 sizeof(mac_str
)) != 2 * ETH_ALEN
)
2424 for (i
= 0; i
< ETH_ALEN
; i
++)
2425 esi
[i
] = hex_to_bin(mac_str
[2 * i
]) * 16 +
2426 hex_to_bin(mac_str
[2 * i
+ 1]);
2432 static int uea_atm_open(struct usbatm_data
*usbatm
, struct atm_dev
*atm_dev
)
2434 struct uea_softc
*sc
= usbatm
->driver_data
;
2436 return uea_getesi(sc
, atm_dev
->esi
);
2439 static int uea_heavy(struct usbatm_data
*usbatm
, struct usb_interface
*intf
)
2441 struct uea_softc
*sc
= usbatm
->driver_data
;
2443 wait_event_interruptible(sc
->sync_q
, IS_OPERATIONAL(sc
));
2449 static int claim_interface(struct usb_device
*usb_dev
,
2450 struct usbatm_data
*usbatm
, int ifnum
)
2453 struct usb_interface
*intf
= usb_ifnum_to_if(usb_dev
, ifnum
);
2456 uea_err(usb_dev
, "interface %d not found\n", ifnum
);
2460 ret
= usb_driver_claim_interface(&uea_driver
, intf
, usbatm
);
2462 uea_err(usb_dev
, "can't claim interface %d, error %d\n", ifnum
,
2467 static struct attribute
*uea_attrs
[] = {
2468 &dev_attr_stat_status
.attr
,
2469 &dev_attr_stat_mflags
.attr
,
2470 &dev_attr_stat_human_status
.attr
,
2471 &dev_attr_stat_delin
.attr
,
2472 &dev_attr_stat_vidcpe
.attr
,
2473 &dev_attr_stat_usrate
.attr
,
2474 &dev_attr_stat_dsrate
.attr
,
2475 &dev_attr_stat_usattenuation
.attr
,
2476 &dev_attr_stat_dsattenuation
.attr
,
2477 &dev_attr_stat_usmargin
.attr
,
2478 &dev_attr_stat_dsmargin
.attr
,
2479 &dev_attr_stat_txflow
.attr
,
2480 &dev_attr_stat_rxflow
.attr
,
2481 &dev_attr_stat_uscorr
.attr
,
2482 &dev_attr_stat_dscorr
.attr
,
2483 &dev_attr_stat_usunc
.attr
,
2484 &dev_attr_stat_dsunc
.attr
,
2485 &dev_attr_stat_firmid
.attr
,
2488 ATTRIBUTE_GROUPS(uea
);
2490 static int uea_bind(struct usbatm_data
*usbatm
, struct usb_interface
*intf
,
2491 const struct usb_device_id
*id
)
2493 struct usb_device
*usb
= interface_to_usbdev(intf
);
2494 struct uea_softc
*sc
;
2495 int ret
, ifnum
= intf
->altsetting
->desc
.bInterfaceNumber
;
2500 /* interface 0 is for firmware/monitoring */
2501 if (ifnum
!= UEA_INTR_IFACE_NO
)
2504 usbatm
->flags
= (sync_wait
[modem_index
] ? 0 : UDSL_SKIP_HEAVY_INIT
);
2506 /* interface 1 is for outbound traffic */
2507 ret
= claim_interface(usb
, usbatm
, UEA_US_IFACE_NO
);
2511 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
2512 if (UEA_CHIP_VERSION(id
) != ADI930
) {
2513 /* interface 2 is for inbound traffic */
2514 ret
= claim_interface(usb
, usbatm
, UEA_DS_IFACE_NO
);
2519 sc
= kzalloc(sizeof(struct uea_softc
), GFP_KERNEL
);
2524 usbatm
->driver_data
= sc
;
2525 sc
->usbatm
= usbatm
;
2526 sc
->modem_index
= (modem_index
< NB_MODEM
) ? modem_index
++ : 0;
2527 sc
->driver_info
= id
->driver_info
;
2529 /* first try to use module parameter */
2530 if (annex
[sc
->modem_index
] == 1)
2532 else if (annex
[sc
->modem_index
] == 2)
2534 /* try to autodetect annex */
2535 else if (sc
->driver_info
& AUTO_ANNEX_A
)
2537 else if (sc
->driver_info
& AUTO_ANNEX_B
)
2540 sc
->annex
= (le16_to_cpu
2541 (sc
->usb_dev
->descriptor
.bcdDevice
) & 0x80) ? ANNEXB
: ANNEXA
;
2543 alt
= altsetting
[sc
->modem_index
];
2544 /* ADI930 don't support iso */
2545 if (UEA_CHIP_VERSION(id
) != ADI930
&& alt
> 0) {
2547 usb_set_interface(usb
, UEA_DS_IFACE_NO
, alt
) == 0) {
2548 uea_dbg(usb
, "set alternate %u for 2 interface\n", alt
);
2549 uea_info(usb
, "using iso mode\n");
2550 usbatm
->flags
|= UDSL_USE_ISOC
| UDSL_IGNORE_EILSEQ
;
2552 uea_err(usb
, "setting alternate %u failed for "
2553 "2 interface, using bulk mode\n", alt
);
2557 ret
= uea_boot(sc
, intf
);
2568 static void uea_unbind(struct usbatm_data
*usbatm
, struct usb_interface
*intf
)
2570 struct uea_softc
*sc
= usbatm
->driver_data
;
2576 static struct usbatm_driver uea_usbatm_driver
= {
2577 .driver_name
= "ueagle-atm",
2579 .atm_start
= uea_atm_open
,
2580 .unbind
= uea_unbind
,
2581 .heavy_init
= uea_heavy
,
2582 .bulk_in
= UEA_BULK_DATA_PIPE
,
2583 .bulk_out
= UEA_BULK_DATA_PIPE
,
2584 .isoc_in
= UEA_ISO_DATA_PIPE
,
2587 static int uea_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
2589 struct usb_device
*usb
= interface_to_usbdev(intf
);
2593 uea_info(usb
, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2594 le16_to_cpu(usb
->descriptor
.idVendor
),
2595 le16_to_cpu(usb
->descriptor
.idProduct
),
2596 le16_to_cpu(usb
->descriptor
.bcdDevice
),
2597 chip_name
[UEA_CHIP_VERSION(id
)]);
2599 usb_reset_device(usb
);
2601 if (UEA_IS_PREFIRM(id
))
2602 return uea_load_firmware(usb
, UEA_CHIP_VERSION(id
));
2604 ret
= usbatm_usb_probe(intf
, id
, &uea_usbatm_driver
);
2606 struct usbatm_data
*usbatm
= usb_get_intfdata(intf
);
2607 struct uea_softc
*sc
= usbatm
->driver_data
;
2609 /* Ensure carrier is initialized to off as early as possible */
2610 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST
);
2612 /* Only start the worker thread when all init is done */
2613 wake_up_process(sc
->kthread
);
2619 static void uea_disconnect(struct usb_interface
*intf
)
2621 struct usb_device
*usb
= interface_to_usbdev(intf
);
2622 int ifnum
= intf
->altsetting
->desc
.bInterfaceNumber
;
2625 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2626 * Pre-firmware device has one interface
2628 if (usb
->config
->desc
.bNumInterfaces
!= 1 && ifnum
== 0) {
2629 mutex_lock(&uea_mutex
);
2630 usbatm_usb_disconnect(intf
);
2631 mutex_unlock(&uea_mutex
);
2632 uea_info(usb
, "ADSL device removed\n");
2639 * List of supported VID/PID
2641 static const struct usb_device_id uea_ids
[] = {
2642 {USB_DEVICE(ANALOG_VID
, ADI930_PID_PREFIRM
),
2643 .driver_info
= ADI930
| PREFIRM
},
2644 {USB_DEVICE(ANALOG_VID
, ADI930_PID_PSTFIRM
),
2645 .driver_info
= ADI930
| PSTFIRM
},
2646 {USB_DEVICE(ANALOG_VID
, EAGLE_I_PID_PREFIRM
),
2647 .driver_info
= EAGLE_I
| PREFIRM
},
2648 {USB_DEVICE(ANALOG_VID
, EAGLE_I_PID_PSTFIRM
),
2649 .driver_info
= EAGLE_I
| PSTFIRM
},
2650 {USB_DEVICE(ANALOG_VID
, EAGLE_II_PID_PREFIRM
),
2651 .driver_info
= EAGLE_II
| PREFIRM
},
2652 {USB_DEVICE(ANALOG_VID
, EAGLE_II_PID_PSTFIRM
),
2653 .driver_info
= EAGLE_II
| PSTFIRM
},
2654 {USB_DEVICE(ANALOG_VID
, EAGLE_IIC_PID_PREFIRM
),
2655 .driver_info
= EAGLE_II
| PREFIRM
},
2656 {USB_DEVICE(ANALOG_VID
, EAGLE_IIC_PID_PSTFIRM
),
2657 .driver_info
= EAGLE_II
| PSTFIRM
},
2658 {USB_DEVICE(ANALOG_VID
, EAGLE_III_PID_PREFIRM
),
2659 .driver_info
= EAGLE_III
| PREFIRM
},
2660 {USB_DEVICE(ANALOG_VID
, EAGLE_III_PID_PSTFIRM
),
2661 .driver_info
= EAGLE_III
| PSTFIRM
},
2662 {USB_DEVICE(ANALOG_VID
, EAGLE_IV_PID_PREFIRM
),
2663 .driver_info
= EAGLE_IV
| PREFIRM
},
2664 {USB_DEVICE(ANALOG_VID
, EAGLE_IV_PID_PSTFIRM
),
2665 .driver_info
= EAGLE_IV
| PSTFIRM
},
2666 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_A_PID_PREFIRM
),
2667 .driver_info
= EAGLE_I
| PREFIRM
},
2668 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_A_PID_PSTFIRM
),
2669 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_A
},
2670 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_B_PID_PREFIRM
),
2671 .driver_info
= EAGLE_I
| PREFIRM
},
2672 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_B_PID_PSTFIRM
),
2673 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_B
},
2674 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_A_PID_PREFIRM
),
2675 .driver_info
= EAGLE_II
| PREFIRM
},
2676 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_A_PID_PSTFIRM
),
2677 .driver_info
= EAGLE_II
| PSTFIRM
| AUTO_ANNEX_A
},
2678 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_B_PID_PREFIRM
),
2679 .driver_info
= EAGLE_II
| PREFIRM
},
2680 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_B_PID_PSTFIRM
),
2681 .driver_info
= EAGLE_II
| PSTFIRM
| AUTO_ANNEX_B
},
2682 {USB_DEVICE(ELSA_VID
, ELSA_PID_PREFIRM
),
2683 .driver_info
= ADI930
| PREFIRM
},
2684 {USB_DEVICE(ELSA_VID
, ELSA_PID_PSTFIRM
),
2685 .driver_info
= ADI930
| PSTFIRM
},
2686 {USB_DEVICE(ELSA_VID
, ELSA_PID_A_PREFIRM
),
2687 .driver_info
= ADI930
| PREFIRM
},
2688 {USB_DEVICE(ELSA_VID
, ELSA_PID_A_PSTFIRM
),
2689 .driver_info
= ADI930
| PSTFIRM
| AUTO_ANNEX_A
},
2690 {USB_DEVICE(ELSA_VID
, ELSA_PID_B_PREFIRM
),
2691 .driver_info
= ADI930
| PREFIRM
},
2692 {USB_DEVICE(ELSA_VID
, ELSA_PID_B_PSTFIRM
),
2693 .driver_info
= ADI930
| PSTFIRM
| AUTO_ANNEX_B
},
2694 {USB_DEVICE(USR_VID
, MILLER_A_PID_PREFIRM
),
2695 .driver_info
= EAGLE_I
| PREFIRM
},
2696 {USB_DEVICE(USR_VID
, MILLER_A_PID_PSTFIRM
),
2697 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_A
},
2698 {USB_DEVICE(USR_VID
, MILLER_B_PID_PREFIRM
),
2699 .driver_info
= EAGLE_I
| PREFIRM
},
2700 {USB_DEVICE(USR_VID
, MILLER_B_PID_PSTFIRM
),
2701 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_B
},
2702 {USB_DEVICE(USR_VID
, HEINEKEN_A_PID_PREFIRM
),
2703 .driver_info
= EAGLE_I
| PREFIRM
},
2704 {USB_DEVICE(USR_VID
, HEINEKEN_A_PID_PSTFIRM
),
2705 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_A
},
2706 {USB_DEVICE(USR_VID
, HEINEKEN_B_PID_PREFIRM
),
2707 .driver_info
= EAGLE_I
| PREFIRM
},
2708 {USB_DEVICE(USR_VID
, HEINEKEN_B_PID_PSTFIRM
),
2709 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_B
},
2714 * USB driver descriptor
2716 static struct usb_driver uea_driver
= {
2717 .name
= "ueagle-atm",
2718 .id_table
= uea_ids
,
2720 .disconnect
= uea_disconnect
,
2721 .dev_groups
= uea_groups
,
2724 MODULE_DEVICE_TABLE(usb
, uea_ids
);
2726 module_usb_driver(uea_driver
);
2728 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2729 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2730 MODULE_LICENSE("Dual BSD/GPL");
2731 MODULE_FIRMWARE(EAGLE_FIRMWARE
);
2732 MODULE_FIRMWARE(ADI930_FIRMWARE
);
2733 MODULE_FIRMWARE(EAGLE_I_FIRMWARE
);
2734 MODULE_FIRMWARE(EAGLE_II_FIRMWARE
);
2735 MODULE_FIRMWARE(EAGLE_III_FIRMWARE
);
2736 MODULE_FIRMWARE(EAGLE_IV_FIRMWARE
);
2737 MODULE_FIRMWARE(DSP4I_FIRMWARE
);
2738 MODULE_FIRMWARE(DSP4P_FIRMWARE
);
2739 MODULE_FIRMWARE(DSP9I_FIRMWARE
);
2740 MODULE_FIRMWARE(DSP9P_FIRMWARE
);
2741 MODULE_FIRMWARE(DSPEI_FIRMWARE
);
2742 MODULE_FIRMWARE(DSPEP_FIRMWARE
);
2743 MODULE_FIRMWARE(FPGA930_FIRMWARE
);
2744 MODULE_FIRMWARE(CMV4P_FIRMWARE
);
2745 MODULE_FIRMWARE(CMV4PV2_FIRMWARE
);
2746 MODULE_FIRMWARE(CMV4I_FIRMWARE
);
2747 MODULE_FIRMWARE(CMV4IV2_FIRMWARE
);
2748 MODULE_FIRMWARE(CMV9P_FIRMWARE
);
2749 MODULE_FIRMWARE(CMV9PV2_FIRMWARE
);
2750 MODULE_FIRMWARE(CMV9I_FIRMWARE
);
2751 MODULE_FIRMWARE(CMV9IV2_FIRMWARE
);
2752 MODULE_FIRMWARE(CMVEP_FIRMWARE
);
2753 MODULE_FIRMWARE(CMVEPV2_FIRMWARE
);
2754 MODULE_FIRMWARE(CMVEI_FIRMWARE
);
2755 MODULE_FIRMWARE(CMVEIV2_FIRMWARE
);