1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-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 * This software is available to you under a choice of one of two
10 * licenses. You may choose to be licensed under the terms of the GNU
11 * General Public License (GPL) Version 2, available from the file
12 * COPYING in the main directory of this source tree, or the
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice unmodified, this list of conditions, and the following
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * This program is free software; you can redistribute it and/or
39 * modify it under the terms of the GNU General Public License
40 * as published by the Free Software Foundation; either version 2
41 * of the License, or (at your option) any later version.
43 * This program is distributed in the hope that it will be useful,
44 * but WITHOUT ANY WARRANTY; without even the implied warranty of
45 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 * GNU General Public License for more details.
48 * You should have received a copy of the GNU General Public License
49 * along with this program; if not, write to the Free Software
50 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
53 * HISTORY : some part of the code was base on ueagle 1.3 BSD driver,
54 * Damien Bergamini agree to put his code under a DUAL GPL/BSD license.
56 * The rest of the code was was rewritten from scratch.
59 #include <linux/module.h>
60 #include <linux/moduleparam.h>
61 #include <linux/crc32.h>
62 #include <linux/usb.h>
63 #include <linux/firmware.h>
64 #include <linux/ctype.h>
65 #include <linux/sched.h>
66 #include <linux/kthread.h>
67 #include <linux/mutex.h>
68 #include <linux/freezer.h>
69 #include <linux/slab.h>
70 #include <linux/kernel.h>
72 #include <asm/unaligned.h>
76 #define EAGLEUSBVERSION "ueagle 1.4"
82 #define uea_dbg(usb_dev, format, args...) \
85 dev_dbg(&(usb_dev)->dev, \
86 "[ueagle-atm dbg] %s: " format, \
90 #define uea_vdbg(usb_dev, format, args...) \
93 dev_dbg(&(usb_dev)->dev, \
94 "[ueagle-atm vdbg] " format, ##args); \
97 #define uea_enters(usb_dev) \
98 uea_vdbg(usb_dev, "entering %s\n" , __func__)
100 #define uea_leaves(usb_dev) \
101 uea_vdbg(usb_dev, "leaving %s\n" , __func__)
103 #define uea_err(usb_dev, format, args...) \
104 dev_err(&(usb_dev)->dev , "[UEAGLE-ATM] " format , ##args)
106 #define uea_warn(usb_dev, format, args...) \
107 dev_warn(&(usb_dev)->dev , "[Ueagle-atm] " format, ##args)
109 #define uea_info(usb_dev, format, args...) \
110 dev_info(&(usb_dev)->dev , "[ueagle-atm] " format, ##args)
114 /* cmv's from firmware */
128 /* information about currently processed cmv */
144 struct cmv_dsc_e1 e1
;
145 struct cmv_dsc_e4 e4
;
149 struct usb_device
*usb_dev
;
150 struct usbatm_data
*usbatm
;
153 unsigned int driver_info
;
161 wait_queue_head_t sync_q
;
163 struct task_struct
*kthread
;
168 union cmv_dsc cmv_dsc
;
170 struct work_struct task
;
174 const struct firmware
*dsp_firm
;
177 void (*dispatch_cmv
)(struct uea_softc
*, struct intr_pkt
*);
178 void (*schedule_load_page
)(struct uea_softc
*, struct intr_pkt
*);
179 int (*stat
)(struct uea_softc
*);
180 int (*send_cmvs
)(struct uea_softc
*);
182 /* keep in sync with eaglectl */
210 #define ELSA_VID 0x05CC
211 #define ELSA_PID_PSTFIRM 0x3350
212 #define ELSA_PID_PREFIRM 0x3351
214 #define ELSA_PID_A_PREFIRM 0x3352
215 #define ELSA_PID_A_PSTFIRM 0x3353
216 #define ELSA_PID_B_PREFIRM 0x3362
217 #define ELSA_PID_B_PSTFIRM 0x3363
220 * Devolo IDs : pots if (pid & 0x10)
222 #define DEVOLO_VID 0x1039
223 #define DEVOLO_EAGLE_I_A_PID_PSTFIRM 0x2110
224 #define DEVOLO_EAGLE_I_A_PID_PREFIRM 0x2111
226 #define DEVOLO_EAGLE_I_B_PID_PSTFIRM 0x2100
227 #define DEVOLO_EAGLE_I_B_PID_PREFIRM 0x2101
229 #define DEVOLO_EAGLE_II_A_PID_PSTFIRM 0x2130
230 #define DEVOLO_EAGLE_II_A_PID_PREFIRM 0x2131
232 #define DEVOLO_EAGLE_II_B_PID_PSTFIRM 0x2120
233 #define DEVOLO_EAGLE_II_B_PID_PREFIRM 0x2121
236 * Reference design USB IDs
238 #define ANALOG_VID 0x1110
239 #define ADI930_PID_PREFIRM 0x9001
240 #define ADI930_PID_PSTFIRM 0x9000
242 #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
243 #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
245 #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
246 #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
248 #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
249 #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
251 #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
252 #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
254 #define EAGLE_IV_PID_PREFIRM 0x9042 /* Eagle IV */
255 #define EAGLE_IV_PID_PSTFIRM 0x9041 /* Eagle IV */
260 #define USR_VID 0x0BAF
261 #define MILLER_A_PID_PREFIRM 0x00F2
262 #define MILLER_A_PID_PSTFIRM 0x00F1
263 #define MILLER_B_PID_PREFIRM 0x00FA
264 #define MILLER_B_PID_PSTFIRM 0x00F9
265 #define HEINEKEN_A_PID_PREFIRM 0x00F6
266 #define HEINEKEN_A_PID_PSTFIRM 0x00F5
267 #define HEINEKEN_B_PID_PREFIRM 0x00F8
268 #define HEINEKEN_B_PID_PSTFIRM 0x00F7
271 #define PSTFIRM (1<<7)
272 #define AUTO_ANNEX_A (1<<8)
273 #define AUTO_ANNEX_B (1<<9)
283 /* macros for both struct usb_device_id and struct uea_softc */
284 #define UEA_IS_PREFIRM(x) \
285 (!((x)->driver_info & PSTFIRM))
286 #define UEA_CHIP_VERSION(x) \
287 ((x)->driver_info & 0xf)
290 ((x)->annex & ANNEXB)
292 #define INS_TO_USBDEV(ins) (ins->usb_dev)
294 #define GET_STATUS(data) \
297 #define IS_OPERATIONAL(sc) \
298 ((UEA_CHIP_VERSION(sc) != EAGLE_IV) ? \
299 (GET_STATUS(sc->stats.phy.state) == 2) : \
300 (sc->stats.phy.state == 7))
303 * Set of macros to handle unaligned data in the firmware blob.
304 * The FW_GET_BYTE() macro is provided only for consistency.
307 #define FW_GET_BYTE(p) (*((__u8 *) (p)))
309 #define FW_DIR "ueagle-atm/"
310 #define EAGLE_FIRMWARE FW_DIR "eagle.fw"
311 #define ADI930_FIRMWARE FW_DIR "adi930.fw"
312 #define EAGLE_I_FIRMWARE FW_DIR "eagleI.fw"
313 #define EAGLE_II_FIRMWARE FW_DIR "eagleII.fw"
314 #define EAGLE_III_FIRMWARE FW_DIR "eagleIII.fw"
315 #define EAGLE_IV_FIRMWARE FW_DIR "eagleIV.fw"
317 #define DSP4I_FIRMWARE FW_DIR "DSP4i.bin"
318 #define DSP4P_FIRMWARE FW_DIR "DSP4p.bin"
319 #define DSP9I_FIRMWARE FW_DIR "DSP9i.bin"
320 #define DSP9P_FIRMWARE FW_DIR "DSP9p.bin"
321 #define DSPEI_FIRMWARE FW_DIR "DSPei.bin"
322 #define DSPEP_FIRMWARE FW_DIR "DSPep.bin"
323 #define FPGA930_FIRMWARE FW_DIR "930-fpga.bin"
325 #define CMV4P_FIRMWARE FW_DIR "CMV4p.bin"
326 #define CMV4PV2_FIRMWARE FW_DIR "CMV4p.bin.v2"
327 #define CMV4I_FIRMWARE FW_DIR "CMV4i.bin"
328 #define CMV4IV2_FIRMWARE FW_DIR "CMV4i.bin.v2"
329 #define CMV9P_FIRMWARE FW_DIR "CMV9p.bin"
330 #define CMV9PV2_FIRMWARE FW_DIR "CMV9p.bin.v2"
331 #define CMV9I_FIRMWARE FW_DIR "CMV9i.bin"
332 #define CMV9IV2_FIRMWARE FW_DIR "CMV9i.bin.v2"
333 #define CMVEP_FIRMWARE FW_DIR "CMVep.bin"
334 #define CMVEPV2_FIRMWARE FW_DIR "CMVep.bin.v2"
335 #define CMVEI_FIRMWARE FW_DIR "CMVei.bin"
336 #define CMVEIV2_FIRMWARE FW_DIR "CMVei.bin.v2"
338 #define UEA_FW_NAME_MAX 30
341 #define BULK_TIMEOUT 300
342 #define CTRL_TIMEOUT 1000
344 #define ACK_TIMEOUT msecs_to_jiffies(3000)
346 #define UEA_INTR_IFACE_NO 0
347 #define UEA_US_IFACE_NO 1
348 #define UEA_DS_IFACE_NO 2
350 #define FASTEST_ISO_INTF 8
352 #define UEA_BULK_DATA_PIPE 0x02
353 #define UEA_IDMA_PIPE 0x04
354 #define UEA_INTR_PIPE 0x04
355 #define UEA_ISO_DATA_PIPE 0x08
357 #define UEA_E1_SET_BLOCK 0x0001
358 #define UEA_E4_SET_BLOCK 0x002c
359 #define UEA_SET_MODE 0x0003
360 #define UEA_SET_2183_DATA 0x0004
361 #define UEA_SET_TIMEOUT 0x0011
363 #define UEA_LOOPBACK_OFF 0x0002
364 #define UEA_LOOPBACK_ON 0x0003
365 #define UEA_BOOT_IDMA 0x0006
366 #define UEA_START_RESET 0x0007
367 #define UEA_END_RESET 0x0008
369 #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
370 #define UEA_MPTX_START (0x3fce | 0x4000)
371 #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
372 #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
374 /* block information in eagle4 dsp firmware */
385 #define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
386 #define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
388 #define E4_L1_STRING_HEADER 0x10
389 #define E4_MAX_PAGE_NUMBER 0x58
390 #define E4_NO_SWAPPAGE_HEADERS 0x31
392 /* l1_code is eagle4 dsp firmware format */
394 u8 string_header
[E4_L1_STRING_HEADER
];
395 u8 page_number_to_block_index
[E4_MAX_PAGE_NUMBER
];
396 struct block_index page_header
[E4_NO_SWAPPAGE_HEADERS
];
400 /* structures describing a block within a DSP page */
401 struct block_info_e1
{
406 __le16 wOvl
; /* overlay */
409 #define E1_BLOCK_INFO_SIZE 12
411 struct block_info_e4
{
419 #define E4_BLOCK_INFO_SIZE 14
421 #define UEA_BIHDR 0xabcd
422 #define UEA_RESERVED 0xffff
424 /* constants describing cmv type */
425 #define E1_PREAMBLE 0x535c
426 #define E1_MODEMTOHOST 0x01
427 #define E1_HOSTTOMODEM 0x10
429 #define E1_MEMACCESS 0x1
430 #define E1_ADSLDIRECTIVE 0x7
431 #define E1_FUNCTION_TYPE(f) ((f) >> 4)
432 #define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f)
434 #define E4_MEMACCESS 0
435 #define E4_ADSLDIRECTIVE 0xf
436 #define E4_FUNCTION_TYPE(f) ((f) >> 8)
437 #define E4_FUNCTION_SIZE(f) ((f) & 0x0f)
438 #define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f)
441 #define E1_REQUESTREAD 0x0
442 #define E1_REQUESTWRITE 0x1
443 #define E1_REPLYREAD 0x2
444 #define E1_REPLYWRITE 0x3
446 #define E4_REQUESTREAD 0x0
447 #define E4_REQUESTWRITE 0x4
448 #define E4_REPLYREAD (E4_REQUESTREAD | 1)
449 #define E4_REPLYWRITE (E4_REQUESTWRITE | 1)
451 /* for ADSLDIRECTIVE */
452 #define E1_KERNELREADY 0x0
453 #define E1_MODEMREADY 0x1
455 #define E4_KERNELREADY 0x0
456 #define E4_MODEMREADY 0x1
458 #define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
459 #define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | \
460 ((st) & 0xf) << 4 | ((s) & 0xf))
462 #define E1_MAKESA(a, b, c, d) \
463 (((c) & 0xff) << 24 | \
464 ((d) & 0xff) << 16 | \
465 ((a) & 0xff) << 8 | \
468 #define E1_GETSA1(a) ((a >> 8) & 0xff)
469 #define E1_GETSA2(a) (a & 0xff)
470 #define E1_GETSA3(a) ((a >> 24) & 0xff)
471 #define E1_GETSA4(a) ((a >> 16) & 0xff)
473 #define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L')
474 #define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G')
475 #define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O')
476 #define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N')
477 #define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E')
478 #define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T')
489 /* structures representing a CMV (Configuration and Management Variable) */
495 __le32 dwSymbolicAddress
;
496 __le16 wOffsetAddress
;
508 /* structures representing swap information */
509 struct swap_info_e1
{
511 __u8 bOvl
; /* overlay */
514 struct swap_info_e4
{
518 /* structures representing interrupt data */
519 #define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
520 #define e1_bOvl u.e1.s1.swapinfo.bOvl
521 #define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo
523 #define INT_LOADSWAPPAGE 0x0001
524 #define INT_INCOMINGCMV 0x0002
528 struct swap_info_e1 swapinfo
;
539 struct swap_info_e4 swapinfo
;
556 union intr_data_e1 e1
;
557 union intr_data_e4 e4
;
561 #define E1_INTR_PKT_SIZE 28
562 #define E4_INTR_PKT_SIZE 64
564 static struct usb_driver uea_driver
;
565 static DEFINE_MUTEX(uea_mutex
);
566 static const char * const chip_name
[] = {
567 "ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
569 static int modem_index
;
570 static unsigned int debug
;
571 static unsigned int altsetting
[NB_MODEM
] = {
572 [0 ... (NB_MODEM
- 1)] = FASTEST_ISO_INTF
};
573 static bool sync_wait
[NB_MODEM
];
574 static char *cmv_file
[NB_MODEM
];
575 static int annex
[NB_MODEM
];
577 module_param(debug
, uint
, 0644);
578 MODULE_PARM_DESC(debug
, "module debug level (0=off,1=on,2=verbose)");
579 module_param_array(altsetting
, uint
, NULL
, 0644);
580 MODULE_PARM_DESC(altsetting
, "alternate setting for incoming traffic: 0=bulk, "
581 "1=isoc slowest, ... , 8=isoc fastest (default)");
582 module_param_array(sync_wait
, bool, NULL
, 0644);
583 MODULE_PARM_DESC(sync_wait
, "wait the synchronisation before starting ATM");
584 module_param_array(cmv_file
, charp
, NULL
, 0644);
585 MODULE_PARM_DESC(cmv_file
,
586 "file name with configuration and management variables");
587 module_param_array(annex
, uint
, NULL
, 0644);
588 MODULE_PARM_DESC(annex
,
589 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
591 #define uea_wait(sc, cond, timeo) \
593 int _r = wait_event_interruptible_timeout(sc->sync_q, \
594 (cond) || kthread_should_stop(), timeo); \
595 if (kthread_should_stop()) \
600 #define UPDATE_ATM_STAT(type, val) \
602 if (sc->usbatm->atm_dev) \
603 sc->usbatm->atm_dev->type = val; \
606 #define UPDATE_ATM_SIGNAL(val) \
608 if (sc->usbatm->atm_dev) \
609 atm_dev_signal_change(sc->usbatm->atm_dev, val); \
613 /* Firmware loading */
614 #define LOAD_INTERNAL 0xA0
615 #define F8051_USBCS 0x7f92
618 * uea_send_modem_cmd - Send a command for pre-firmware devices.
620 static int uea_send_modem_cmd(struct usb_device
*usb
,
621 u16 addr
, u16 size
, const u8
*buff
)
626 xfer_buff
= kmemdup(buff
, size
, GFP_KERNEL
);
628 ret
= usb_control_msg(usb
,
629 usb_sndctrlpipe(usb
, 0),
631 USB_DIR_OUT
| USB_TYPE_VENDOR
|
632 USB_RECIP_DEVICE
, addr
, 0, xfer_buff
,
640 return (ret
== size
) ? 0 : -EIO
;
643 static void uea_upload_pre_firmware(const struct firmware
*fw_entry
,
646 struct usb_device
*usb
= context
;
654 uea_err(usb
, "firmware is not available\n");
658 pfw
= fw_entry
->data
;
659 size
= fw_entry
->size
;
661 goto err_fw_corrupted
;
663 crc
= get_unaligned_le32(pfw
);
666 if (crc32_be(0, pfw
, size
) != crc
)
667 goto err_fw_corrupted
;
670 * Start to upload firmware : send reset
673 ret
= uea_send_modem_cmd(usb
, F8051_USBCS
, sizeof(value
), &value
);
676 uea_err(usb
, "modem reset failed with error %d\n", ret
);
681 u8 len
= FW_GET_BYTE(pfw
);
682 u16 add
= get_unaligned_le16(pfw
+ 1);
686 goto err_fw_corrupted
;
688 ret
= uea_send_modem_cmd(usb
, add
, len
, pfw
+ 3);
690 uea_err(usb
, "uploading firmware data failed "
691 "with error %d\n", ret
);
698 goto err_fw_corrupted
;
701 * Tell the modem we finish : de-assert reset
704 ret
= uea_send_modem_cmd(usb
, F8051_USBCS
, 1, &value
);
706 uea_err(usb
, "modem de-assert failed with error %d\n", ret
);
708 uea_info(usb
, "firmware uploaded\n");
713 uea_err(usb
, "firmware is corrupted\n");
715 release_firmware(fw_entry
);
720 * uea_load_firmware - Load usb firmware for pre-firmware devices.
722 static int uea_load_firmware(struct usb_device
*usb
, unsigned int ver
)
725 char *fw_name
= EAGLE_FIRMWARE
;
728 uea_info(usb
, "pre-firmware device, uploading firmware\n");
732 fw_name
= ADI930_FIRMWARE
;
735 fw_name
= EAGLE_I_FIRMWARE
;
738 fw_name
= EAGLE_II_FIRMWARE
;
741 fw_name
= EAGLE_III_FIRMWARE
;
744 fw_name
= EAGLE_IV_FIRMWARE
;
748 ret
= request_firmware_nowait(THIS_MODULE
, 1, fw_name
, &usb
->dev
,
750 uea_upload_pre_firmware
);
752 uea_err(usb
, "firmware %s is not available\n", fw_name
);
754 uea_info(usb
, "loading firmware %s\n", fw_name
);
760 /* modem management : dsp firmware, send/read CMV, monitoring statistic
764 * Make sure that the DSP code provided is safe to use.
766 static int check_dsp_e1(const u8
*dsp
, unsigned int len
)
768 u8 pagecount
, blockcount
;
771 unsigned int i
, j
, p
, pp
;
773 pagecount
= FW_GET_BYTE(dsp
);
776 /* enough space for page offsets? */
777 if (p
+ 4 * pagecount
> len
)
780 for (i
= 0; i
< pagecount
; i
++) {
782 pageoffset
= get_unaligned_le32(dsp
+ p
);
788 /* enough space for blockcount? */
789 if (pageoffset
>= len
)
793 blockcount
= FW_GET_BYTE(dsp
+ pp
);
796 for (j
= 0; j
< blockcount
; j
++) {
798 /* enough space for block header? */
802 pp
+= 2; /* skip blockaddr */
803 blocksize
= get_unaligned_le16(dsp
+ pp
);
806 /* enough space for block data? */
807 if (pp
+ blocksize
> len
)
817 static int check_dsp_e4(const u8
*dsp
, int len
)
820 struct l1_code
*p
= (struct l1_code
*) dsp
;
821 unsigned int sum
= p
->code
- dsp
;
826 if (strcmp("STRATIPHY ANEXA", p
->string_header
) != 0 &&
827 strcmp("STRATIPHY ANEXB", p
->string_header
) != 0)
830 for (i
= 0; i
< E4_MAX_PAGE_NUMBER
; i
++) {
831 struct block_index
*blockidx
;
832 u8 blockno
= p
->page_number_to_block_index
[i
];
833 if (blockno
>= E4_NO_SWAPPAGE_HEADERS
)
839 if (blockno
>= E4_NO_SWAPPAGE_HEADERS
)
842 blockidx
= &p
->page_header
[blockno
++];
843 if ((u8
*)(blockidx
+ 1) - dsp
>= len
)
846 if (le16_to_cpu(blockidx
->PageNumber
) != i
)
849 l
= E4_PAGE_BYTES(blockidx
->PageSize
);
851 l
+= le32_to_cpu(blockidx
->PageOffset
);
855 /* zero is zero regardless endianes */
856 } while (blockidx
->NotLastBlock
);
859 return (sum
== len
) ? 0 : 1;
863 * send data to the idma pipe
865 static int uea_idma_write(struct uea_softc
*sc
, const void *data
, u32 size
)
871 xfer_buff
= kmemdup(data
, size
, GFP_KERNEL
);
873 uea_err(INS_TO_USBDEV(sc
), "can't allocate xfer_buff\n");
877 ret
= usb_bulk_msg(sc
->usb_dev
,
878 usb_sndbulkpipe(sc
->usb_dev
, UEA_IDMA_PIPE
),
879 xfer_buff
, size
, &bytes_read
, BULK_TIMEOUT
);
884 if (size
!= bytes_read
) {
885 uea_err(INS_TO_USBDEV(sc
), "size != bytes_read %d %d\n", size
,
893 static int request_dsp(struct uea_softc
*sc
)
898 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
900 dsp_name
= DSP4I_FIRMWARE
;
902 dsp_name
= DSP4P_FIRMWARE
;
903 } else if (UEA_CHIP_VERSION(sc
) == ADI930
) {
905 dsp_name
= DSP9I_FIRMWARE
;
907 dsp_name
= DSP9P_FIRMWARE
;
910 dsp_name
= DSPEI_FIRMWARE
;
912 dsp_name
= DSPEP_FIRMWARE
;
915 ret
= request_firmware(&sc
->dsp_firm
, dsp_name
, &sc
->usb_dev
->dev
);
917 uea_err(INS_TO_USBDEV(sc
),
918 "requesting firmware %s failed with error %d\n",
923 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
)
924 ret
= check_dsp_e4(sc
->dsp_firm
->data
, sc
->dsp_firm
->size
);
926 ret
= check_dsp_e1(sc
->dsp_firm
->data
, sc
->dsp_firm
->size
);
929 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n",
931 release_firmware(sc
->dsp_firm
);
940 * The uea_load_page() function must be called within a process context
942 static void uea_load_page_e1(struct work_struct
*work
)
944 struct uea_softc
*sc
= container_of(work
, struct uea_softc
, task
);
945 u16 pageno
= sc
->pageno
;
947 struct block_info_e1 bi
;
950 u8 pagecount
, blockcount
;
951 u16 blockaddr
, blocksize
;
955 /* reload firmware when reboot start and it's loaded already */
956 if (ovl
== 0 && pageno
== 0) {
957 release_firmware(sc
->dsp_firm
);
961 if (sc
->dsp_firm
== NULL
&& request_dsp(sc
) < 0)
964 p
= sc
->dsp_firm
->data
;
965 pagecount
= FW_GET_BYTE(p
);
968 if (pageno
>= pagecount
)
972 pageoffset
= get_unaligned_le32(p
);
977 p
= sc
->dsp_firm
->data
+ pageoffset
;
978 blockcount
= FW_GET_BYTE(p
);
981 uea_dbg(INS_TO_USBDEV(sc
),
982 "sending %u blocks for DSP page %u\n", blockcount
, pageno
);
984 bi
.wHdr
= cpu_to_le16(UEA_BIHDR
);
985 bi
.wOvl
= cpu_to_le16(ovl
);
986 bi
.wOvlOffset
= cpu_to_le16(ovl
| 0x8000);
988 for (i
= 0; i
< blockcount
; i
++) {
989 blockaddr
= get_unaligned_le16(p
);
992 blocksize
= get_unaligned_le16(p
);
995 bi
.wSize
= cpu_to_le16(blocksize
);
996 bi
.wAddress
= cpu_to_le16(blockaddr
);
997 bi
.wLast
= cpu_to_le16((i
== blockcount
- 1) ? 1 : 0);
999 /* send block info through the IDMA pipe */
1000 if (uea_idma_write(sc
, &bi
, E1_BLOCK_INFO_SIZE
))
1003 /* send block data through the IDMA pipe */
1004 if (uea_idma_write(sc
, p
, blocksize
))
1013 uea_err(INS_TO_USBDEV(sc
), "sending DSP block %u failed\n", i
);
1016 uea_err(INS_TO_USBDEV(sc
), "invalid DSP page %u requested\n", pageno
);
1019 static void __uea_load_page_e4(struct uea_softc
*sc
, u8 pageno
, int boot
)
1021 struct block_info_e4 bi
;
1022 struct block_index
*blockidx
;
1023 struct l1_code
*p
= (struct l1_code
*) sc
->dsp_firm
->data
;
1024 u8 blockno
= p
->page_number_to_block_index
[pageno
];
1026 bi
.wHdr
= cpu_to_be16(UEA_BIHDR
);
1027 bi
.bBootPage
= boot
;
1028 bi
.bPageNumber
= pageno
;
1029 bi
.wReserved
= cpu_to_be16(UEA_RESERVED
);
1032 const u8
*blockoffset
;
1033 unsigned int blocksize
;
1035 blockidx
= &p
->page_header
[blockno
];
1036 blocksize
= E4_PAGE_BYTES(blockidx
->PageSize
);
1037 blockoffset
= sc
->dsp_firm
->data
+ le32_to_cpu(
1038 blockidx
->PageOffset
);
1040 bi
.dwSize
= cpu_to_be32(blocksize
);
1041 bi
.dwAddress
= cpu_to_be32(le32_to_cpu(blockidx
->PageAddress
));
1043 uea_dbg(INS_TO_USBDEV(sc
),
1044 "sending block %u for DSP page "
1045 "%u size %u address %x\n",
1046 blockno
, pageno
, blocksize
,
1047 le32_to_cpu(blockidx
->PageAddress
));
1049 /* send block info through the IDMA pipe */
1050 if (uea_idma_write(sc
, &bi
, E4_BLOCK_INFO_SIZE
))
1053 /* send block data through the IDMA pipe */
1054 if (uea_idma_write(sc
, blockoffset
, blocksize
))
1058 } while (blockidx
->NotLastBlock
);
1063 uea_err(INS_TO_USBDEV(sc
), "sending DSP block %u failed\n", blockno
);
1067 static void uea_load_page_e4(struct work_struct
*work
)
1069 struct uea_softc
*sc
= container_of(work
, struct uea_softc
, task
);
1070 u8 pageno
= sc
->pageno
;
1072 struct block_info_e4 bi
;
1075 uea_dbg(INS_TO_USBDEV(sc
), "sending DSP page %u\n", pageno
);
1077 /* reload firmware when reboot start and it's loaded already */
1079 release_firmware(sc
->dsp_firm
);
1080 sc
->dsp_firm
= NULL
;
1083 if (sc
->dsp_firm
== NULL
&& request_dsp(sc
) < 0)
1086 p
= (struct l1_code
*) sc
->dsp_firm
->data
;
1087 if (pageno
>= le16_to_cpu(p
->page_header
[0].PageNumber
)) {
1088 uea_err(INS_TO_USBDEV(sc
), "invalid DSP "
1089 "page %u requested\n", pageno
);
1094 __uea_load_page_e4(sc
, pageno
, 0);
1098 uea_dbg(INS_TO_USBDEV(sc
),
1099 "sending Main DSP page %u\n", p
->page_header
[0].PageNumber
);
1101 for (i
= 0; i
< le16_to_cpu(p
->page_header
[0].PageNumber
); i
++) {
1102 if (E4_IS_BOOT_PAGE(p
->page_header
[i
].PageSize
))
1103 __uea_load_page_e4(sc
, i
, 1);
1106 uea_dbg(INS_TO_USBDEV(sc
) , "sending start bi\n");
1108 bi
.wHdr
= cpu_to_be16(UEA_BIHDR
);
1110 bi
.bPageNumber
= 0xff;
1111 bi
.wReserved
= cpu_to_be16(UEA_RESERVED
);
1112 bi
.dwSize
= cpu_to_be32(E4_PAGE_BYTES(p
->page_header
[0].PageSize
));
1113 bi
.dwAddress
= cpu_to_be32(le32_to_cpu(p
->page_header
[0].PageAddress
));
1115 /* send block info through the IDMA pipe */
1116 if (uea_idma_write(sc
, &bi
, E4_BLOCK_INFO_SIZE
))
1117 uea_err(INS_TO_USBDEV(sc
), "sending DSP start bi failed\n");
1120 static inline void wake_up_cmv_ack(struct uea_softc
*sc
)
1122 BUG_ON(sc
->cmv_ack
);
1124 wake_up(&sc
->sync_q
);
1127 static inline int wait_cmv_ack(struct uea_softc
*sc
)
1129 int ret
= uea_wait(sc
, sc
->cmv_ack
, ACK_TIMEOUT
);
1133 uea_dbg(INS_TO_USBDEV(sc
), "wait_event_timeout : %d ms\n",
1134 jiffies_to_msecs(ret
));
1139 return (ret
== 0) ? -ETIMEDOUT
: 0;
1142 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1144 static int uea_request(struct uea_softc
*sc
,
1145 u16 value
, u16 index
, u16 size
, const void *data
)
1150 xfer_buff
= kmemdup(data
, size
, GFP_KERNEL
);
1152 uea_err(INS_TO_USBDEV(sc
), "can't allocate xfer_buff\n");
1156 ret
= usb_control_msg(sc
->usb_dev
, usb_sndctrlpipe(sc
->usb_dev
, 0),
1157 UCDC_SEND_ENCAPSULATED_COMMAND
,
1158 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
1159 value
, index
, xfer_buff
, size
, CTRL_TIMEOUT
);
1163 uea_err(INS_TO_USBDEV(sc
), "usb_control_msg error %d\n", ret
);
1168 uea_err(INS_TO_USBDEV(sc
),
1169 "usb_control_msg send only %d bytes (instead of %d)\n",
1177 static int uea_cmv_e1(struct uea_softc
*sc
,
1178 u8 function
, u32 address
, u16 offset
, u32 data
)
1183 uea_enters(INS_TO_USBDEV(sc
));
1184 uea_vdbg(INS_TO_USBDEV(sc
), "Function : %d-%d, Address : %c%c%c%c, "
1185 "offset : 0x%04x, data : 0x%08x\n",
1186 E1_FUNCTION_TYPE(function
),
1187 E1_FUNCTION_SUBTYPE(function
),
1188 E1_GETSA1(address
), E1_GETSA2(address
),
1190 E1_GETSA4(address
), offset
, data
);
1192 /* we send a request, but we expect a reply */
1193 sc
->cmv_dsc
.e1
.function
= function
| 0x2;
1194 sc
->cmv_dsc
.e1
.idx
++;
1195 sc
->cmv_dsc
.e1
.address
= address
;
1196 sc
->cmv_dsc
.e1
.offset
= offset
;
1198 cmv
.wPreamble
= cpu_to_le16(E1_PREAMBLE
);
1199 cmv
.bDirection
= E1_HOSTTOMODEM
;
1200 cmv
.bFunction
= function
;
1201 cmv
.wIndex
= cpu_to_le16(sc
->cmv_dsc
.e1
.idx
);
1202 put_unaligned_le32(address
, &cmv
.dwSymbolicAddress
);
1203 cmv
.wOffsetAddress
= cpu_to_le16(offset
);
1204 put_unaligned_le32(data
>> 16 | data
<< 16, &cmv
.dwData
);
1206 ret
= uea_request(sc
, UEA_E1_SET_BLOCK
, UEA_MPTX_START
,
1210 ret
= wait_cmv_ack(sc
);
1211 uea_leaves(INS_TO_USBDEV(sc
));
1215 static int uea_cmv_e4(struct uea_softc
*sc
,
1216 u16 function
, u16 group
, u16 address
, u16 offset
, u32 data
)
1221 uea_enters(INS_TO_USBDEV(sc
));
1222 memset(&cmv
, 0, sizeof(cmv
));
1224 uea_vdbg(INS_TO_USBDEV(sc
), "Function : %d-%d, Group : 0x%04x, "
1225 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1226 E4_FUNCTION_TYPE(function
), E4_FUNCTION_SUBTYPE(function
),
1227 group
, address
, offset
, data
);
1229 /* we send a request, but we expect a reply */
1230 sc
->cmv_dsc
.e4
.function
= function
| (0x1 << 4);
1231 sc
->cmv_dsc
.e4
.offset
= offset
;
1232 sc
->cmv_dsc
.e4
.address
= address
;
1233 sc
->cmv_dsc
.e4
.group
= group
;
1235 cmv
.wFunction
= cpu_to_be16(function
);
1236 cmv
.wGroup
= cpu_to_be16(group
);
1237 cmv
.wAddress
= cpu_to_be16(address
);
1238 cmv
.wOffset
= cpu_to_be16(offset
);
1239 cmv
.dwData
[0] = cpu_to_be32(data
);
1241 ret
= uea_request(sc
, UEA_E4_SET_BLOCK
, UEA_MPTX_START
,
1245 ret
= wait_cmv_ack(sc
);
1246 uea_leaves(INS_TO_USBDEV(sc
));
1250 static inline int uea_read_cmv_e1(struct uea_softc
*sc
,
1251 u32 address
, u16 offset
, u32
*data
)
1253 int ret
= uea_cmv_e1(sc
, E1_MAKEFUNCTION(E1_MEMACCESS
, E1_REQUESTREAD
),
1254 address
, offset
, 0);
1256 uea_err(INS_TO_USBDEV(sc
),
1257 "reading cmv failed with error %d\n", ret
);
1264 static inline int uea_read_cmv_e4(struct uea_softc
*sc
,
1265 u8 size
, u16 group
, u16 address
, u16 offset
, u32
*data
)
1267 int ret
= uea_cmv_e4(sc
, E4_MAKEFUNCTION(E4_MEMACCESS
,
1268 E4_REQUESTREAD
, size
),
1269 group
, address
, offset
, 0);
1271 uea_err(INS_TO_USBDEV(sc
),
1272 "reading cmv failed with error %d\n", ret
);
1275 /* size is in 16-bit word quantities */
1277 *(data
+ 1) = sc
->data1
;
1282 static inline int uea_write_cmv_e1(struct uea_softc
*sc
,
1283 u32 address
, u16 offset
, u32 data
)
1285 int ret
= uea_cmv_e1(sc
, E1_MAKEFUNCTION(E1_MEMACCESS
, E1_REQUESTWRITE
),
1286 address
, offset
, data
);
1288 uea_err(INS_TO_USBDEV(sc
),
1289 "writing cmv failed with error %d\n", ret
);
1294 static inline int uea_write_cmv_e4(struct uea_softc
*sc
,
1295 u8 size
, u16 group
, u16 address
, u16 offset
, u32 data
)
1297 int ret
= uea_cmv_e4(sc
, E4_MAKEFUNCTION(E4_MEMACCESS
,
1298 E4_REQUESTWRITE
, size
),
1299 group
, address
, offset
, data
);
1301 uea_err(INS_TO_USBDEV(sc
),
1302 "writing cmv failed with error %d\n", ret
);
1307 static void uea_set_bulk_timeout(struct uea_softc
*sc
, u32 dsrate
)
1312 /* in bulk mode the modem have problem with high rate
1313 * changing internal timing could improve things, but the
1314 * value is mysterious.
1315 * ADI930 don't support it (-EPIPE error).
1318 if (UEA_CHIP_VERSION(sc
) == ADI930
||
1319 altsetting
[sc
->modem_index
] > 0 ||
1320 sc
->stats
.phy
.dsrate
== dsrate
)
1323 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1324 timeout
= (dsrate
<= 1024*1024) ? 0 : 1;
1325 ret
= uea_request(sc
, UEA_SET_TIMEOUT
, timeout
, 0, NULL
);
1326 uea_info(INS_TO_USBDEV(sc
), "setting new timeout %d%s\n",
1327 timeout
, ret
< 0 ? " failed" : "");
1332 * Monitor the modem and update the stat
1333 * return 0 if everything is ok
1334 * return < 0 if an error occurs (-EAGAIN reboot needed)
1336 static int uea_stat_e1(struct uea_softc
*sc
)
1341 uea_enters(INS_TO_USBDEV(sc
));
1342 data
= sc
->stats
.phy
.state
;
1344 ret
= uea_read_cmv_e1(sc
, E1_SA_STAT
, 0, &sc
->stats
.phy
.state
);
1348 switch (GET_STATUS(sc
->stats
.phy
.state
)) {
1349 case 0: /* not yet synchronized */
1350 uea_dbg(INS_TO_USBDEV(sc
),
1351 "modem not yet synchronized\n");
1354 case 1: /* initialization */
1355 uea_dbg(INS_TO_USBDEV(sc
), "modem initializing\n");
1358 case 2: /* operational */
1359 uea_vdbg(INS_TO_USBDEV(sc
), "modem operational\n");
1362 case 3: /* fail ... */
1363 uea_info(INS_TO_USBDEV(sc
), "modem synchronization failed"
1364 " (may be try other cmv/dsp)\n");
1367 case 4 ... 6: /* test state */
1368 uea_warn(INS_TO_USBDEV(sc
),
1369 "modem in test mode - not supported\n");
1372 case 7: /* fast-retain ... */
1373 uea_info(INS_TO_USBDEV(sc
), "modem in fast-retain mode\n");
1376 uea_err(INS_TO_USBDEV(sc
), "modem invalid SW mode %d\n",
1377 GET_STATUS(sc
->stats
.phy
.state
));
1381 if (GET_STATUS(data
) != 2) {
1382 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_OFF
, 0, NULL
);
1383 uea_info(INS_TO_USBDEV(sc
), "modem operational\n");
1385 /* release the dsp firmware as it is not needed until
1388 release_firmware(sc
->dsp_firm
);
1389 sc
->dsp_firm
= NULL
;
1392 /* always update it as atm layer could not be init when we switch to
1395 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND
);
1397 /* wake up processes waiting for synchronization */
1398 wake_up(&sc
->sync_q
);
1400 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 2, &sc
->stats
.phy
.flags
);
1403 sc
->stats
.phy
.mflags
|= sc
->stats
.phy
.flags
;
1405 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1406 * we check the status again in order to detect the failure earlier
1408 if (sc
->stats
.phy
.flags
) {
1409 uea_dbg(INS_TO_USBDEV(sc
), "Stat flag = 0x%x\n",
1410 sc
->stats
.phy
.flags
);
1414 ret
= uea_read_cmv_e1(sc
, E1_SA_RATE
, 0, &data
);
1418 uea_set_bulk_timeout(sc
, (data
>> 16) * 32);
1419 sc
->stats
.phy
.dsrate
= (data
>> 16) * 32;
1420 sc
->stats
.phy
.usrate
= (data
& 0xffff) * 32;
1421 UPDATE_ATM_STAT(link_rate
, sc
->stats
.phy
.dsrate
* 1000 / 424);
1423 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 23, &data
);
1426 sc
->stats
.phy
.dsattenuation
= (data
& 0xff) / 2;
1428 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 47, &data
);
1431 sc
->stats
.phy
.usattenuation
= (data
& 0xff) / 2;
1433 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 25, &sc
->stats
.phy
.dsmargin
);
1437 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 49, &sc
->stats
.phy
.usmargin
);
1441 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 51, &sc
->stats
.phy
.rxflow
);
1445 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 52, &sc
->stats
.phy
.txflow
);
1449 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 54, &sc
->stats
.phy
.dsunc
);
1453 /* only for atu-c */
1454 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 58, &sc
->stats
.phy
.usunc
);
1458 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 53, &sc
->stats
.phy
.dscorr
);
1462 /* only for atu-c */
1463 ret
= uea_read_cmv_e1(sc
, E1_SA_DIAG
, 57, &sc
->stats
.phy
.uscorr
);
1467 ret
= uea_read_cmv_e1(sc
, E1_SA_INFO
, 8, &sc
->stats
.phy
.vidco
);
1471 ret
= uea_read_cmv_e1(sc
, E1_SA_INFO
, 13, &sc
->stats
.phy
.vidcpe
);
1478 static int uea_stat_e4(struct uea_softc
*sc
)
1484 uea_enters(INS_TO_USBDEV(sc
));
1485 data
= sc
->stats
.phy
.state
;
1487 /* XXX only need to be done before operationnal... */
1488 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_STAT
, 0, 0, &sc
->stats
.phy
.state
);
1492 switch (sc
->stats
.phy
.state
) {
1493 case 0x0: /* not yet synchronized */
1497 uea_dbg(INS_TO_USBDEV(sc
), "modem not yet "
1500 case 0x5: /* initialization */
1504 uea_dbg(INS_TO_USBDEV(sc
), "modem initializing\n");
1506 case 0x2: /* fail ... */
1507 uea_info(INS_TO_USBDEV(sc
), "modem synchronization "
1508 "failed (may be try other cmv/dsp)\n");
1510 case 0x7: /* operational */
1513 uea_warn(INS_TO_USBDEV(sc
), "unknown state: %x\n",
1514 sc
->stats
.phy
.state
);
1519 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_OFF
, 0, NULL
);
1520 uea_info(INS_TO_USBDEV(sc
), "modem operational\n");
1522 /* release the dsp firmware as it is not needed until
1525 release_firmware(sc
->dsp_firm
);
1526 sc
->dsp_firm
= NULL
;
1529 /* always update it as atm layer could not be init when we switch to
1532 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND
);
1534 /* wake up processes waiting for synchronization */
1535 wake_up(&sc
->sync_q
);
1537 /* TODO improve this state machine :
1538 * we need some CMV info : what they do and their unit
1539 * we should find the equivalent of eagle3- CMV
1542 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_DIAG
, 0, 0, &sc
->stats
.phy
.flags
);
1545 sc
->stats
.phy
.mflags
|= sc
->stats
.phy
.flags
;
1547 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1548 * we check the status again in order to detect the failure earlier
1550 if (sc
->stats
.phy
.flags
) {
1551 uea_dbg(INS_TO_USBDEV(sc
), "Stat flag = 0x%x\n",
1552 sc
->stats
.phy
.flags
);
1553 if (sc
->stats
.phy
.flags
& 1) /* delineation LOSS */
1555 if (sc
->stats
.phy
.flags
& 0x4000) /* Reset Flag */
1560 /* rate data may be in upper or lower half of 64 bit word, strange */
1561 ret
= uea_read_cmv_e4(sc
, 4, E4_SA_RATE
, 0, 0, tmp_arr
);
1564 data
= (tmp_arr
[0]) ? tmp_arr
[0] : tmp_arr
[1];
1565 sc
->stats
.phy
.usrate
= data
/ 1000;
1567 ret
= uea_read_cmv_e4(sc
, 4, E4_SA_RATE
, 1, 0, tmp_arr
);
1570 data
= (tmp_arr
[0]) ? tmp_arr
[0] : tmp_arr
[1];
1571 uea_set_bulk_timeout(sc
, data
/ 1000);
1572 sc
->stats
.phy
.dsrate
= data
/ 1000;
1573 UPDATE_ATM_STAT(link_rate
, sc
->stats
.phy
.dsrate
* 1000 / 424);
1575 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 68, 1, &data
);
1578 sc
->stats
.phy
.dsattenuation
= data
/ 10;
1580 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 69, 1, &data
);
1583 sc
->stats
.phy
.usattenuation
= data
/ 10;
1585 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 68, 3, &data
);
1588 sc
->stats
.phy
.dsmargin
= data
/ 2;
1590 ret
= uea_read_cmv_e4(sc
, 1, E4_SA_INFO
, 69, 3, &data
);
1593 sc
->stats
.phy
.usmargin
= data
/ 10;
1598 static void cmvs_file_name(struct uea_softc
*sc
, char *const cmv_name
, int ver
)
1600 char file_arr
[] = "CMVxy.bin";
1603 kernel_param_lock(THIS_MODULE
);
1604 /* set proper name corresponding modem version and line type */
1605 if (cmv_file
[sc
->modem_index
] == NULL
) {
1606 if (UEA_CHIP_VERSION(sc
) == ADI930
)
1608 else if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
)
1613 file_arr
[4] = IS_ISDN(sc
) ? 'i' : 'p';
1616 file
= cmv_file
[sc
->modem_index
];
1618 strcpy(cmv_name
, FW_DIR
);
1619 strlcat(cmv_name
, file
, UEA_FW_NAME_MAX
);
1621 strlcat(cmv_name
, ".v2", UEA_FW_NAME_MAX
);
1622 kernel_param_unlock(THIS_MODULE
);
1625 static int request_cmvs_old(struct uea_softc
*sc
,
1626 void **cmvs
, const struct firmware
**fw
)
1630 char cmv_name
[UEA_FW_NAME_MAX
]; /* 30 bytes stack variable */
1632 cmvs_file_name(sc
, cmv_name
, 1);
1633 ret
= request_firmware(fw
, cmv_name
, &sc
->usb_dev
->dev
);
1635 uea_err(INS_TO_USBDEV(sc
),
1636 "requesting firmware %s failed with error %d\n",
1641 data
= (u8
*) (*fw
)->data
;
1644 goto err_fw_corrupted
;
1646 if (size
!= *data
* sizeof(struct uea_cmvs_v1
) + 1)
1647 goto err_fw_corrupted
;
1649 *cmvs
= (void *)(data
+ 1);
1653 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n", cmv_name
);
1654 release_firmware(*fw
);
1658 static int request_cmvs(struct uea_softc
*sc
,
1659 void **cmvs
, const struct firmware
**fw
, int *ver
)
1664 char cmv_name
[UEA_FW_NAME_MAX
]; /* 30 bytes stack variable */
1666 cmvs_file_name(sc
, cmv_name
, 2);
1667 ret
= request_firmware(fw
, cmv_name
, &sc
->usb_dev
->dev
);
1669 /* if caller can handle old version, try to provide it */
1671 uea_warn(INS_TO_USBDEV(sc
), "requesting "
1672 "firmware %s failed, "
1673 "try to get older cmvs\n", cmv_name
);
1674 return request_cmvs_old(sc
, cmvs
, fw
);
1676 uea_err(INS_TO_USBDEV(sc
),
1677 "requesting firmware %s failed with error %d\n",
1683 data
= (u8
*) (*fw
)->data
;
1684 if (size
< 4 || strncmp(data
, "cmv2", 4) != 0) {
1686 uea_warn(INS_TO_USBDEV(sc
), "firmware %s is corrupted,"
1687 " try to get older cmvs\n", cmv_name
);
1688 release_firmware(*fw
);
1689 return request_cmvs_old(sc
, cmvs
, fw
);
1691 goto err_fw_corrupted
;
1699 goto err_fw_corrupted
;
1701 crc
= get_unaligned_le32(data
);
1704 if (crc32_be(0, data
, size
) != crc
)
1705 goto err_fw_corrupted
;
1707 if (size
!= *data
* sizeof(struct uea_cmvs_v2
) + 1)
1708 goto err_fw_corrupted
;
1710 *cmvs
= (void *) (data
+ 1);
1714 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n", cmv_name
);
1715 release_firmware(*fw
);
1719 static int uea_send_cmvs_e1(struct uea_softc
*sc
)
1723 const struct firmware
*cmvs_fw
;
1724 int ver
= 1; /* we can handle v1 cmv firmware version; */
1726 /* Enter in R-IDLE (cmv) until instructed otherwise */
1727 ret
= uea_write_cmv_e1(sc
, E1_SA_CNTL
, 0, 1);
1731 /* Dump firmware version */
1732 ret
= uea_read_cmv_e1(sc
, E1_SA_INFO
, 10, &sc
->stats
.phy
.firmid
);
1735 uea_info(INS_TO_USBDEV(sc
), "ATU-R firmware version : %x\n",
1736 sc
->stats
.phy
.firmid
);
1739 ret
= len
= request_cmvs(sc
, &cmvs_ptr
, &cmvs_fw
, &ver
);
1745 struct uea_cmvs_v1
*cmvs_v1
= cmvs_ptr
;
1747 uea_warn(INS_TO_USBDEV(sc
), "use deprecated cmvs version, "
1748 "please update your firmware\n");
1750 for (i
= 0; i
< len
; i
++) {
1751 ret
= uea_write_cmv_e1(sc
,
1752 get_unaligned_le32(&cmvs_v1
[i
].address
),
1753 get_unaligned_le16(&cmvs_v1
[i
].offset
),
1754 get_unaligned_le32(&cmvs_v1
[i
].data
));
1758 } else if (ver
== 2) {
1759 struct uea_cmvs_v2
*cmvs_v2
= cmvs_ptr
;
1761 for (i
= 0; i
< len
; i
++) {
1762 ret
= uea_write_cmv_e1(sc
,
1763 get_unaligned_le32(&cmvs_v2
[i
].address
),
1764 (u16
) get_unaligned_le32(&cmvs_v2
[i
].offset
),
1765 get_unaligned_le32(&cmvs_v2
[i
].data
));
1770 /* This really should not happen */
1771 uea_err(INS_TO_USBDEV(sc
), "bad cmvs version %d\n", ver
);
1775 /* Enter in R-ACT-REQ */
1776 ret
= uea_write_cmv_e1(sc
, E1_SA_CNTL
, 0, 2);
1777 uea_vdbg(INS_TO_USBDEV(sc
), "Entering in R-ACT-REQ state\n");
1778 uea_info(INS_TO_USBDEV(sc
), "modem started, waiting "
1779 "synchronization...\n");
1781 release_firmware(cmvs_fw
);
1785 static int uea_send_cmvs_e4(struct uea_softc
*sc
)
1789 const struct firmware
*cmvs_fw
;
1790 int ver
= 2; /* we can only handle v2 cmv firmware version; */
1792 /* Enter in R-IDLE (cmv) until instructed otherwise */
1793 ret
= uea_write_cmv_e4(sc
, 1, E4_SA_CNTL
, 0, 0, 1);
1797 /* Dump firmware version */
1798 /* XXX don't read the 3th byte as it is always 6 */
1799 ret
= uea_read_cmv_e4(sc
, 2, E4_SA_INFO
, 55, 0, &sc
->stats
.phy
.firmid
);
1802 uea_info(INS_TO_USBDEV(sc
), "ATU-R firmware version : %x\n",
1803 sc
->stats
.phy
.firmid
);
1807 ret
= len
= request_cmvs(sc
, &cmvs_ptr
, &cmvs_fw
, &ver
);
1813 struct uea_cmvs_v2
*cmvs_v2
= cmvs_ptr
;
1815 for (i
= 0; i
< len
; i
++) {
1816 ret
= uea_write_cmv_e4(sc
, 1,
1817 get_unaligned_le32(&cmvs_v2
[i
].group
),
1818 get_unaligned_le32(&cmvs_v2
[i
].address
),
1819 get_unaligned_le32(&cmvs_v2
[i
].offset
),
1820 get_unaligned_le32(&cmvs_v2
[i
].data
));
1825 /* This really should not happen */
1826 uea_err(INS_TO_USBDEV(sc
), "bad cmvs version %d\n", ver
);
1830 /* Enter in R-ACT-REQ */
1831 ret
= uea_write_cmv_e4(sc
, 1, E4_SA_CNTL
, 0, 0, 2);
1832 uea_vdbg(INS_TO_USBDEV(sc
), "Entering in R-ACT-REQ state\n");
1833 uea_info(INS_TO_USBDEV(sc
), "modem started, waiting "
1834 "synchronization...\n");
1836 release_firmware(cmvs_fw
);
1840 /* Start boot post firmware modem:
1841 * - send reset commands through usb control pipe
1842 * - start workqueue for DSP loading
1843 * - send CMV options to modem
1846 static int uea_start_reset(struct uea_softc
*sc
)
1848 u16 zero
= 0; /* ;-) */
1851 uea_enters(INS_TO_USBDEV(sc
));
1852 uea_info(INS_TO_USBDEV(sc
), "(re)booting started\n");
1854 /* mask interrupt */
1856 /* We need to set this here because, a ack timeout could have occurred,
1857 * but before we start the reboot, the ack occurs and set this to 1.
1858 * So we will failed to wait Ready CMV.
1861 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST
);
1863 /* reset statistics */
1864 memset(&sc
->stats
, 0, sizeof(struct uea_stats
));
1866 /* tell the modem that we want to boot in IDMA mode */
1867 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_ON
, 0, NULL
);
1868 uea_request(sc
, UEA_SET_MODE
, UEA_BOOT_IDMA
, 0, NULL
);
1870 /* enter reset mode */
1871 uea_request(sc
, UEA_SET_MODE
, UEA_START_RESET
, 0, NULL
);
1873 /* original driver use 200ms, but windows driver use 100ms */
1874 ret
= uea_wait(sc
, 0, msecs_to_jiffies(100));
1878 /* leave reset mode */
1879 uea_request(sc
, UEA_SET_MODE
, UEA_END_RESET
, 0, NULL
);
1881 if (UEA_CHIP_VERSION(sc
) != EAGLE_IV
) {
1882 /* clear tx and rx mailboxes */
1883 uea_request(sc
, UEA_SET_2183_DATA
, UEA_MPTX_MAILBOX
, 2, &zero
);
1884 uea_request(sc
, UEA_SET_2183_DATA
, UEA_MPRX_MAILBOX
, 2, &zero
);
1885 uea_request(sc
, UEA_SET_2183_DATA
, UEA_SWAP_MAILBOX
, 2, &zero
);
1888 ret
= uea_wait(sc
, 0, msecs_to_jiffies(1000));
1892 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
)
1893 sc
->cmv_dsc
.e4
.function
= E4_MAKEFUNCTION(E4_ADSLDIRECTIVE
,
1896 sc
->cmv_dsc
.e1
.function
= E1_MAKEFUNCTION(E1_ADSLDIRECTIVE
,
1899 /* demask interrupt */
1902 /* start loading DSP */
1905 schedule_work(&sc
->task
);
1907 /* wait for modem ready CMV */
1908 ret
= wait_cmv_ack(sc
);
1912 uea_vdbg(INS_TO_USBDEV(sc
), "Ready CMV received\n");
1914 ret
= sc
->send_cmvs(sc
);
1919 uea_leaves(INS_TO_USBDEV(sc
));
1924 * In case of an error wait 1s before rebooting the modem
1925 * if the modem don't request reboot (-EAGAIN).
1926 * Monitor the modem every 1s.
1929 static int uea_kthread(void *data
)
1931 struct uea_softc
*sc
= data
;
1935 uea_enters(INS_TO_USBDEV(sc
));
1936 while (!kthread_should_stop()) {
1937 if (ret
< 0 || sc
->reset
)
1938 ret
= uea_start_reset(sc
);
1942 uea_wait(sc
, 0, msecs_to_jiffies(1000));
1945 uea_leaves(INS_TO_USBDEV(sc
));
1949 /* Load second usb firmware for ADI930 chip */
1950 static int load_XILINX_firmware(struct uea_softc
*sc
)
1952 const struct firmware
*fw_entry
;
1953 int ret
, size
, u
, ln
;
1956 char *fw_name
= FPGA930_FIRMWARE
;
1958 uea_enters(INS_TO_USBDEV(sc
));
1960 ret
= request_firmware(&fw_entry
, fw_name
, &sc
->usb_dev
->dev
);
1962 uea_err(INS_TO_USBDEV(sc
), "firmware %s is not available\n",
1967 pfw
= fw_entry
->data
;
1968 size
= fw_entry
->size
;
1969 if (size
!= 0x577B) {
1970 uea_err(INS_TO_USBDEV(sc
), "firmware %s is corrupted\n",
1975 for (u
= 0; u
< size
; u
+= ln
) {
1976 ln
= min(size
- u
, 64);
1977 ret
= uea_request(sc
, 0xe, 0, ln
, pfw
+ u
);
1979 uea_err(INS_TO_USBDEV(sc
),
1980 "elsa download data failed (%d)\n", ret
);
1985 /* finish to send the fpga */
1986 ret
= uea_request(sc
, 0xe, 1, 0, NULL
);
1988 uea_err(INS_TO_USBDEV(sc
),
1989 "elsa download data failed (%d)\n", ret
);
1993 /* Tell the modem we finish : de-assert reset */
1995 ret
= uea_send_modem_cmd(sc
->usb_dev
, 0xe, 1, &value
);
1997 uea_err(sc
->usb_dev
, "elsa de-assert failed with error"
2001 release_firmware(fw_entry
);
2003 uea_leaves(INS_TO_USBDEV(sc
));
2007 /* The modem send us an ack. First with check if it right */
2008 static void uea_dispatch_cmv_e1(struct uea_softc
*sc
, struct intr_pkt
*intr
)
2010 struct cmv_dsc_e1
*dsc
= &sc
->cmv_dsc
.e1
;
2011 struct cmv_e1
*cmv
= &intr
->u
.e1
.s2
.cmv
;
2013 uea_enters(INS_TO_USBDEV(sc
));
2014 if (le16_to_cpu(cmv
->wPreamble
) != E1_PREAMBLE
)
2017 if (cmv
->bDirection
!= E1_MODEMTOHOST
)
2020 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
2021 * the first MEMACCESS cmv. Ignore it...
2023 if (cmv
->bFunction
!= dsc
->function
) {
2024 if (UEA_CHIP_VERSION(sc
) == ADI930
2025 && cmv
->bFunction
== E1_MAKEFUNCTION(2, 2)) {
2026 cmv
->wIndex
= cpu_to_le16(dsc
->idx
);
2027 put_unaligned_le32(dsc
->address
,
2028 &cmv
->dwSymbolicAddress
);
2029 cmv
->wOffsetAddress
= cpu_to_le16(dsc
->offset
);
2034 if (cmv
->bFunction
== E1_MAKEFUNCTION(E1_ADSLDIRECTIVE
,
2036 wake_up_cmv_ack(sc
);
2037 uea_leaves(INS_TO_USBDEV(sc
));
2041 /* in case of MEMACCESS */
2042 if (le16_to_cpu(cmv
->wIndex
) != dsc
->idx
||
2043 get_unaligned_le32(&cmv
->dwSymbolicAddress
) != dsc
->address
||
2044 le16_to_cpu(cmv
->wOffsetAddress
) != dsc
->offset
)
2047 sc
->data
= get_unaligned_le32(&cmv
->dwData
);
2048 sc
->data
= sc
->data
<< 16 | sc
->data
>> 16;
2050 wake_up_cmv_ack(sc
);
2051 uea_leaves(INS_TO_USBDEV(sc
));
2055 uea_err(INS_TO_USBDEV(sc
), "unexpected cmv received, "
2056 "Function : %d, Subfunction : %d\n",
2057 E1_FUNCTION_TYPE(cmv
->bFunction
),
2058 E1_FUNCTION_SUBTYPE(cmv
->bFunction
));
2059 uea_leaves(INS_TO_USBDEV(sc
));
2063 uea_err(INS_TO_USBDEV(sc
), "invalid cmv received, "
2064 "wPreamble %d, bDirection %d\n",
2065 le16_to_cpu(cmv
->wPreamble
), cmv
->bDirection
);
2066 uea_leaves(INS_TO_USBDEV(sc
));
2069 /* The modem send us an ack. First with check if it right */
2070 static void uea_dispatch_cmv_e4(struct uea_softc
*sc
, struct intr_pkt
*intr
)
2072 struct cmv_dsc_e4
*dsc
= &sc
->cmv_dsc
.e4
;
2073 struct cmv_e4
*cmv
= &intr
->u
.e4
.s2
.cmv
;
2075 uea_enters(INS_TO_USBDEV(sc
));
2076 uea_dbg(INS_TO_USBDEV(sc
), "cmv %x %x %x %x %x %x\n",
2077 be16_to_cpu(cmv
->wGroup
), be16_to_cpu(cmv
->wFunction
),
2078 be16_to_cpu(cmv
->wOffset
), be16_to_cpu(cmv
->wAddress
),
2079 be32_to_cpu(cmv
->dwData
[0]), be32_to_cpu(cmv
->dwData
[1]));
2081 if (be16_to_cpu(cmv
->wFunction
) != dsc
->function
)
2084 if (be16_to_cpu(cmv
->wFunction
) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE
,
2085 E4_MODEMREADY
, 1)) {
2086 wake_up_cmv_ack(sc
);
2087 uea_leaves(INS_TO_USBDEV(sc
));
2091 /* in case of MEMACCESS */
2092 if (be16_to_cpu(cmv
->wOffset
) != dsc
->offset
||
2093 be16_to_cpu(cmv
->wGroup
) != dsc
->group
||
2094 be16_to_cpu(cmv
->wAddress
) != dsc
->address
)
2097 sc
->data
= be32_to_cpu(cmv
->dwData
[0]);
2098 sc
->data1
= be32_to_cpu(cmv
->dwData
[1]);
2099 wake_up_cmv_ack(sc
);
2100 uea_leaves(INS_TO_USBDEV(sc
));
2104 uea_err(INS_TO_USBDEV(sc
), "unexpected cmv received, "
2105 "Function : %d, Subfunction : %d\n",
2106 E4_FUNCTION_TYPE(cmv
->wFunction
),
2107 E4_FUNCTION_SUBTYPE(cmv
->wFunction
));
2108 uea_leaves(INS_TO_USBDEV(sc
));
2112 static void uea_schedule_load_page_e1(struct uea_softc
*sc
,
2113 struct intr_pkt
*intr
)
2115 sc
->pageno
= intr
->e1_bSwapPageNo
;
2116 sc
->ovl
= intr
->e1_bOvl
>> 4 | intr
->e1_bOvl
<< 4;
2117 schedule_work(&sc
->task
);
2120 static void uea_schedule_load_page_e4(struct uea_softc
*sc
,
2121 struct intr_pkt
*intr
)
2123 sc
->pageno
= intr
->e4_bSwapPageNo
;
2124 schedule_work(&sc
->task
);
2130 static void uea_intr(struct urb
*urb
)
2132 struct uea_softc
*sc
= urb
->context
;
2133 struct intr_pkt
*intr
= urb
->transfer_buffer
;
2134 int status
= urb
->status
;
2136 uea_enters(INS_TO_USBDEV(sc
));
2138 if (unlikely(status
< 0)) {
2139 uea_err(INS_TO_USBDEV(sc
), "uea_intr() failed with %d\n",
2144 /* device-to-host interrupt */
2145 if (intr
->bType
!= 0x08 || sc
->booting
) {
2146 uea_err(INS_TO_USBDEV(sc
), "wrong interrupt\n");
2150 switch (le16_to_cpu(intr
->wInterrupt
)) {
2151 case INT_LOADSWAPPAGE
:
2152 sc
->schedule_load_page(sc
, intr
);
2155 case INT_INCOMINGCMV
:
2156 sc
->dispatch_cmv(sc
, intr
);
2160 uea_err(INS_TO_USBDEV(sc
), "unknown interrupt %u\n",
2161 le16_to_cpu(intr
->wInterrupt
));
2165 usb_submit_urb(sc
->urb_int
, GFP_ATOMIC
);
2169 * Start the modem : init the data and start kernel thread
2171 static int uea_boot(struct uea_softc
*sc
)
2174 struct intr_pkt
*intr
;
2176 uea_enters(INS_TO_USBDEV(sc
));
2178 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
2179 size
= E4_INTR_PKT_SIZE
;
2180 sc
->dispatch_cmv
= uea_dispatch_cmv_e4
;
2181 sc
->schedule_load_page
= uea_schedule_load_page_e4
;
2182 sc
->stat
= uea_stat_e4
;
2183 sc
->send_cmvs
= uea_send_cmvs_e4
;
2184 INIT_WORK(&sc
->task
, uea_load_page_e4
);
2186 size
= E1_INTR_PKT_SIZE
;
2187 sc
->dispatch_cmv
= uea_dispatch_cmv_e1
;
2188 sc
->schedule_load_page
= uea_schedule_load_page_e1
;
2189 sc
->stat
= uea_stat_e1
;
2190 sc
->send_cmvs
= uea_send_cmvs_e1
;
2191 INIT_WORK(&sc
->task
, uea_load_page_e1
);
2194 init_waitqueue_head(&sc
->sync_q
);
2196 if (UEA_CHIP_VERSION(sc
) == ADI930
)
2197 load_XILINX_firmware(sc
);
2199 intr
= kmalloc(size
, GFP_KERNEL
);
2203 sc
->urb_int
= usb_alloc_urb(0, GFP_KERNEL
);
2207 usb_fill_int_urb(sc
->urb_int
, sc
->usb_dev
,
2208 usb_rcvintpipe(sc
->usb_dev
, UEA_INTR_PIPE
),
2209 intr
, size
, uea_intr
, sc
,
2210 sc
->usb_dev
->actconfig
->interface
[0]->altsetting
[0].
2211 endpoint
[0].desc
.bInterval
);
2213 ret
= usb_submit_urb(sc
->urb_int
, GFP_KERNEL
);
2215 uea_err(INS_TO_USBDEV(sc
),
2216 "urb submission failed with error %d\n", ret
);
2220 /* Create worker thread, but don't start it here. Start it after
2221 * all usbatm generic initialization is done.
2223 sc
->kthread
= kthread_create(uea_kthread
, sc
, "ueagle-atm");
2224 if (IS_ERR(sc
->kthread
)) {
2225 uea_err(INS_TO_USBDEV(sc
), "failed to create thread\n");
2229 uea_leaves(INS_TO_USBDEV(sc
));
2233 usb_kill_urb(sc
->urb_int
);
2235 usb_free_urb(sc
->urb_int
);
2239 uea_leaves(INS_TO_USBDEV(sc
));
2244 * Stop the modem : kill kernel thread and free data
2246 static void uea_stop(struct uea_softc
*sc
)
2249 uea_enters(INS_TO_USBDEV(sc
));
2250 ret
= kthread_stop(sc
->kthread
);
2251 uea_dbg(INS_TO_USBDEV(sc
), "kthread finish with status %d\n", ret
);
2253 uea_request(sc
, UEA_SET_MODE
, UEA_LOOPBACK_ON
, 0, NULL
);
2255 usb_kill_urb(sc
->urb_int
);
2256 kfree(sc
->urb_int
->transfer_buffer
);
2257 usb_free_urb(sc
->urb_int
);
2259 /* flush the work item, when no one can schedule it */
2260 flush_work(&sc
->task
);
2262 release_firmware(sc
->dsp_firm
);
2263 uea_leaves(INS_TO_USBDEV(sc
));
2266 /* syfs interface */
2267 static struct uea_softc
*dev_to_uea(struct device
*dev
)
2269 struct usb_interface
*intf
;
2270 struct usbatm_data
*usbatm
;
2272 intf
= to_usb_interface(dev
);
2276 usbatm
= usb_get_intfdata(intf
);
2280 return usbatm
->driver_data
;
2283 static ssize_t
stat_status_show(struct device
*dev
, struct device_attribute
*attr
,
2287 struct uea_softc
*sc
;
2289 mutex_lock(&uea_mutex
);
2290 sc
= dev_to_uea(dev
);
2293 ret
= snprintf(buf
, 10, "%08x\n", sc
->stats
.phy
.state
);
2295 mutex_unlock(&uea_mutex
);
2299 static ssize_t
stat_status_store(struct device
*dev
, struct device_attribute
*attr
,
2300 const char *buf
, size_t count
)
2303 struct uea_softc
*sc
;
2305 mutex_lock(&uea_mutex
);
2306 sc
= dev_to_uea(dev
);
2312 mutex_unlock(&uea_mutex
);
2316 static DEVICE_ATTR_RW(stat_status
);
2318 static ssize_t
stat_human_status_show(struct device
*dev
,
2319 struct device_attribute
*attr
, char *buf
)
2323 struct uea_softc
*sc
;
2325 mutex_lock(&uea_mutex
);
2326 sc
= dev_to_uea(dev
);
2330 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
2331 switch (sc
->stats
.phy
.state
) {
2332 case 0x0: /* not yet synchronized */
2338 case 0x5: /* initialization */
2344 case 0x7: /* operational */
2347 case 0x2: /* fail ... */
2350 default: /* unknown */
2355 modem_state
= GET_STATUS(sc
->stats
.phy
.state
);
2357 switch (modem_state
) {
2359 ret
= sprintf(buf
, "Modem is booting\n");
2362 ret
= sprintf(buf
, "Modem is initializing\n");
2365 ret
= sprintf(buf
, "Modem is operational\n");
2368 ret
= sprintf(buf
, "Modem synchronization failed\n");
2371 ret
= sprintf(buf
, "Modem state is unknown\n");
2375 mutex_unlock(&uea_mutex
);
2379 static DEVICE_ATTR_RO(stat_human_status
);
2381 static ssize_t
stat_delin_show(struct device
*dev
, struct device_attribute
*attr
,
2385 struct uea_softc
*sc
;
2386 char *delin
= "GOOD";
2388 mutex_lock(&uea_mutex
);
2389 sc
= dev_to_uea(dev
);
2393 if (UEA_CHIP_VERSION(sc
) == EAGLE_IV
) {
2394 if (sc
->stats
.phy
.flags
& 0x4000)
2396 else if (sc
->stats
.phy
.flags
& 0x0001)
2399 if (sc
->stats
.phy
.flags
& 0x0C00)
2401 else if (sc
->stats
.phy
.flags
& 0x0030)
2405 ret
= sprintf(buf
, "%s\n", delin
);
2407 mutex_unlock(&uea_mutex
);
2411 static DEVICE_ATTR_RO(stat_delin
);
2413 #define UEA_ATTR(name, reset) \
2415 static ssize_t stat_##name##_show(struct device *dev, \
2416 struct device_attribute *attr, char *buf) \
2418 int ret = -ENODEV; \
2419 struct uea_softc *sc; \
2421 mutex_lock(&uea_mutex); \
2422 sc = dev_to_uea(dev); \
2425 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2427 sc->stats.phy.name = 0; \
2429 mutex_unlock(&uea_mutex); \
2433 static DEVICE_ATTR_RO(stat_##name)
2435 UEA_ATTR(mflags
, 1);
2436 UEA_ATTR(vidcpe
, 0);
2437 UEA_ATTR(usrate
, 0);
2438 UEA_ATTR(dsrate
, 0);
2439 UEA_ATTR(usattenuation
, 0);
2440 UEA_ATTR(dsattenuation
, 0);
2441 UEA_ATTR(usmargin
, 0);
2442 UEA_ATTR(dsmargin
, 0);
2443 UEA_ATTR(txflow
, 0);
2444 UEA_ATTR(rxflow
, 0);
2445 UEA_ATTR(uscorr
, 0);
2446 UEA_ATTR(dscorr
, 0);
2449 UEA_ATTR(firmid
, 0);
2451 /* Retrieve the device End System Identifier (MAC) */
2453 static int uea_getesi(struct uea_softc
*sc
, u_char
*esi
)
2455 unsigned char mac_str
[2 * ETH_ALEN
+ 1];
2458 (sc
->usb_dev
, sc
->usb_dev
->descriptor
.iSerialNumber
, mac_str
,
2459 sizeof(mac_str
)) != 2 * ETH_ALEN
)
2462 for (i
= 0; i
< ETH_ALEN
; i
++)
2463 esi
[i
] = hex_to_bin(mac_str
[2 * i
]) * 16 +
2464 hex_to_bin(mac_str
[2 * i
+ 1]);
2470 static int uea_atm_open(struct usbatm_data
*usbatm
, struct atm_dev
*atm_dev
)
2472 struct uea_softc
*sc
= usbatm
->driver_data
;
2474 return uea_getesi(sc
, atm_dev
->esi
);
2477 static int uea_heavy(struct usbatm_data
*usbatm
, struct usb_interface
*intf
)
2479 struct uea_softc
*sc
= usbatm
->driver_data
;
2481 wait_event_interruptible(sc
->sync_q
, IS_OPERATIONAL(sc
));
2487 static int claim_interface(struct usb_device
*usb_dev
,
2488 struct usbatm_data
*usbatm
, int ifnum
)
2491 struct usb_interface
*intf
= usb_ifnum_to_if(usb_dev
, ifnum
);
2494 uea_err(usb_dev
, "interface %d not found\n", ifnum
);
2498 ret
= usb_driver_claim_interface(&uea_driver
, intf
, usbatm
);
2500 uea_err(usb_dev
, "can't claim interface %d, error %d\n", ifnum
,
2505 static struct attribute
*attrs
[] = {
2506 &dev_attr_stat_status
.attr
,
2507 &dev_attr_stat_mflags
.attr
,
2508 &dev_attr_stat_human_status
.attr
,
2509 &dev_attr_stat_delin
.attr
,
2510 &dev_attr_stat_vidcpe
.attr
,
2511 &dev_attr_stat_usrate
.attr
,
2512 &dev_attr_stat_dsrate
.attr
,
2513 &dev_attr_stat_usattenuation
.attr
,
2514 &dev_attr_stat_dsattenuation
.attr
,
2515 &dev_attr_stat_usmargin
.attr
,
2516 &dev_attr_stat_dsmargin
.attr
,
2517 &dev_attr_stat_txflow
.attr
,
2518 &dev_attr_stat_rxflow
.attr
,
2519 &dev_attr_stat_uscorr
.attr
,
2520 &dev_attr_stat_dscorr
.attr
,
2521 &dev_attr_stat_usunc
.attr
,
2522 &dev_attr_stat_dsunc
.attr
,
2523 &dev_attr_stat_firmid
.attr
,
2526 static const struct attribute_group attr_grp
= {
2530 static int uea_bind(struct usbatm_data
*usbatm
, struct usb_interface
*intf
,
2531 const struct usb_device_id
*id
)
2533 struct usb_device
*usb
= interface_to_usbdev(intf
);
2534 struct uea_softc
*sc
;
2535 int ret
, ifnum
= intf
->altsetting
->desc
.bInterfaceNumber
;
2540 /* interface 0 is for firmware/monitoring */
2541 if (ifnum
!= UEA_INTR_IFACE_NO
)
2544 usbatm
->flags
= (sync_wait
[modem_index
] ? 0 : UDSL_SKIP_HEAVY_INIT
);
2546 /* interface 1 is for outbound traffic */
2547 ret
= claim_interface(usb
, usbatm
, UEA_US_IFACE_NO
);
2551 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
2552 if (UEA_CHIP_VERSION(id
) != ADI930
) {
2553 /* interface 2 is for inbound traffic */
2554 ret
= claim_interface(usb
, usbatm
, UEA_DS_IFACE_NO
);
2559 sc
= kzalloc(sizeof(struct uea_softc
), GFP_KERNEL
);
2564 usbatm
->driver_data
= sc
;
2565 sc
->usbatm
= usbatm
;
2566 sc
->modem_index
= (modem_index
< NB_MODEM
) ? modem_index
++ : 0;
2567 sc
->driver_info
= id
->driver_info
;
2569 /* first try to use module parameter */
2570 if (annex
[sc
->modem_index
] == 1)
2572 else if (annex
[sc
->modem_index
] == 2)
2574 /* try to autodetect annex */
2575 else if (sc
->driver_info
& AUTO_ANNEX_A
)
2577 else if (sc
->driver_info
& AUTO_ANNEX_B
)
2580 sc
->annex
= (le16_to_cpu
2581 (sc
->usb_dev
->descriptor
.bcdDevice
) & 0x80) ? ANNEXB
: ANNEXA
;
2583 alt
= altsetting
[sc
->modem_index
];
2584 /* ADI930 don't support iso */
2585 if (UEA_CHIP_VERSION(id
) != ADI930
&& alt
> 0) {
2587 usb_set_interface(usb
, UEA_DS_IFACE_NO
, alt
) == 0) {
2588 uea_dbg(usb
, "set alternate %u for 2 interface\n", alt
);
2589 uea_info(usb
, "using iso mode\n");
2590 usbatm
->flags
|= UDSL_USE_ISOC
| UDSL_IGNORE_EILSEQ
;
2592 uea_err(usb
, "setting alternate %u failed for "
2593 "2 interface, using bulk mode\n", alt
);
2597 ret
= sysfs_create_group(&intf
->dev
.kobj
, &attr_grp
);
2608 sysfs_remove_group(&intf
->dev
.kobj
, &attr_grp
);
2614 static void uea_unbind(struct usbatm_data
*usbatm
, struct usb_interface
*intf
)
2616 struct uea_softc
*sc
= usbatm
->driver_data
;
2618 sysfs_remove_group(&intf
->dev
.kobj
, &attr_grp
);
2623 static struct usbatm_driver uea_usbatm_driver
= {
2624 .driver_name
= "ueagle-atm",
2626 .atm_start
= uea_atm_open
,
2627 .unbind
= uea_unbind
,
2628 .heavy_init
= uea_heavy
,
2629 .bulk_in
= UEA_BULK_DATA_PIPE
,
2630 .bulk_out
= UEA_BULK_DATA_PIPE
,
2631 .isoc_in
= UEA_ISO_DATA_PIPE
,
2634 static int uea_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
2636 struct usb_device
*usb
= interface_to_usbdev(intf
);
2640 uea_info(usb
, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2641 le16_to_cpu(usb
->descriptor
.idVendor
),
2642 le16_to_cpu(usb
->descriptor
.idProduct
),
2643 le16_to_cpu(usb
->descriptor
.bcdDevice
),
2644 chip_name
[UEA_CHIP_VERSION(id
)]);
2646 usb_reset_device(usb
);
2648 if (UEA_IS_PREFIRM(id
))
2649 return uea_load_firmware(usb
, UEA_CHIP_VERSION(id
));
2651 ret
= usbatm_usb_probe(intf
, id
, &uea_usbatm_driver
);
2653 struct usbatm_data
*usbatm
= usb_get_intfdata(intf
);
2654 struct uea_softc
*sc
= usbatm
->driver_data
;
2656 /* Ensure carrier is initialized to off as early as possible */
2657 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST
);
2659 /* Only start the worker thread when all init is done */
2660 wake_up_process(sc
->kthread
);
2666 static void uea_disconnect(struct usb_interface
*intf
)
2668 struct usb_device
*usb
= interface_to_usbdev(intf
);
2669 int ifnum
= intf
->altsetting
->desc
.bInterfaceNumber
;
2672 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2673 * Pre-firmware device has one interface
2675 if (usb
->config
->desc
.bNumInterfaces
!= 1 && ifnum
== 0) {
2676 mutex_lock(&uea_mutex
);
2677 usbatm_usb_disconnect(intf
);
2678 mutex_unlock(&uea_mutex
);
2679 uea_info(usb
, "ADSL device removed\n");
2686 * List of supported VID/PID
2688 static const struct usb_device_id uea_ids
[] = {
2689 {USB_DEVICE(ANALOG_VID
, ADI930_PID_PREFIRM
),
2690 .driver_info
= ADI930
| PREFIRM
},
2691 {USB_DEVICE(ANALOG_VID
, ADI930_PID_PSTFIRM
),
2692 .driver_info
= ADI930
| PSTFIRM
},
2693 {USB_DEVICE(ANALOG_VID
, EAGLE_I_PID_PREFIRM
),
2694 .driver_info
= EAGLE_I
| PREFIRM
},
2695 {USB_DEVICE(ANALOG_VID
, EAGLE_I_PID_PSTFIRM
),
2696 .driver_info
= EAGLE_I
| PSTFIRM
},
2697 {USB_DEVICE(ANALOG_VID
, EAGLE_II_PID_PREFIRM
),
2698 .driver_info
= EAGLE_II
| PREFIRM
},
2699 {USB_DEVICE(ANALOG_VID
, EAGLE_II_PID_PSTFIRM
),
2700 .driver_info
= EAGLE_II
| PSTFIRM
},
2701 {USB_DEVICE(ANALOG_VID
, EAGLE_IIC_PID_PREFIRM
),
2702 .driver_info
= EAGLE_II
| PREFIRM
},
2703 {USB_DEVICE(ANALOG_VID
, EAGLE_IIC_PID_PSTFIRM
),
2704 .driver_info
= EAGLE_II
| PSTFIRM
},
2705 {USB_DEVICE(ANALOG_VID
, EAGLE_III_PID_PREFIRM
),
2706 .driver_info
= EAGLE_III
| PREFIRM
},
2707 {USB_DEVICE(ANALOG_VID
, EAGLE_III_PID_PSTFIRM
),
2708 .driver_info
= EAGLE_III
| PSTFIRM
},
2709 {USB_DEVICE(ANALOG_VID
, EAGLE_IV_PID_PREFIRM
),
2710 .driver_info
= EAGLE_IV
| PREFIRM
},
2711 {USB_DEVICE(ANALOG_VID
, EAGLE_IV_PID_PSTFIRM
),
2712 .driver_info
= EAGLE_IV
| PSTFIRM
},
2713 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_A_PID_PREFIRM
),
2714 .driver_info
= EAGLE_I
| PREFIRM
},
2715 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_A_PID_PSTFIRM
),
2716 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_A
},
2717 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_B_PID_PREFIRM
),
2718 .driver_info
= EAGLE_I
| PREFIRM
},
2719 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_I_B_PID_PSTFIRM
),
2720 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_B
},
2721 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_A_PID_PREFIRM
),
2722 .driver_info
= EAGLE_II
| PREFIRM
},
2723 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_A_PID_PSTFIRM
),
2724 .driver_info
= EAGLE_II
| PSTFIRM
| AUTO_ANNEX_A
},
2725 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_B_PID_PREFIRM
),
2726 .driver_info
= EAGLE_II
| PREFIRM
},
2727 {USB_DEVICE(DEVOLO_VID
, DEVOLO_EAGLE_II_B_PID_PSTFIRM
),
2728 .driver_info
= EAGLE_II
| PSTFIRM
| AUTO_ANNEX_B
},
2729 {USB_DEVICE(ELSA_VID
, ELSA_PID_PREFIRM
),
2730 .driver_info
= ADI930
| PREFIRM
},
2731 {USB_DEVICE(ELSA_VID
, ELSA_PID_PSTFIRM
),
2732 .driver_info
= ADI930
| PSTFIRM
},
2733 {USB_DEVICE(ELSA_VID
, ELSA_PID_A_PREFIRM
),
2734 .driver_info
= ADI930
| PREFIRM
},
2735 {USB_DEVICE(ELSA_VID
, ELSA_PID_A_PSTFIRM
),
2736 .driver_info
= ADI930
| PSTFIRM
| AUTO_ANNEX_A
},
2737 {USB_DEVICE(ELSA_VID
, ELSA_PID_B_PREFIRM
),
2738 .driver_info
= ADI930
| PREFIRM
},
2739 {USB_DEVICE(ELSA_VID
, ELSA_PID_B_PSTFIRM
),
2740 .driver_info
= ADI930
| PSTFIRM
| AUTO_ANNEX_B
},
2741 {USB_DEVICE(USR_VID
, MILLER_A_PID_PREFIRM
),
2742 .driver_info
= EAGLE_I
| PREFIRM
},
2743 {USB_DEVICE(USR_VID
, MILLER_A_PID_PSTFIRM
),
2744 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_A
},
2745 {USB_DEVICE(USR_VID
, MILLER_B_PID_PREFIRM
),
2746 .driver_info
= EAGLE_I
| PREFIRM
},
2747 {USB_DEVICE(USR_VID
, MILLER_B_PID_PSTFIRM
),
2748 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_B
},
2749 {USB_DEVICE(USR_VID
, HEINEKEN_A_PID_PREFIRM
),
2750 .driver_info
= EAGLE_I
| PREFIRM
},
2751 {USB_DEVICE(USR_VID
, HEINEKEN_A_PID_PSTFIRM
),
2752 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_A
},
2753 {USB_DEVICE(USR_VID
, HEINEKEN_B_PID_PREFIRM
),
2754 .driver_info
= EAGLE_I
| PREFIRM
},
2755 {USB_DEVICE(USR_VID
, HEINEKEN_B_PID_PSTFIRM
),
2756 .driver_info
= EAGLE_I
| PSTFIRM
| AUTO_ANNEX_B
},
2761 * USB driver descriptor
2763 static struct usb_driver uea_driver
= {
2764 .name
= "ueagle-atm",
2765 .id_table
= uea_ids
,
2767 .disconnect
= uea_disconnect
,
2770 MODULE_DEVICE_TABLE(usb
, uea_ids
);
2772 module_usb_driver(uea_driver
);
2774 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2775 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2776 MODULE_LICENSE("Dual BSD/GPL");
2777 MODULE_FIRMWARE(EAGLE_FIRMWARE
);
2778 MODULE_FIRMWARE(ADI930_FIRMWARE
);
2779 MODULE_FIRMWARE(EAGLE_I_FIRMWARE
);
2780 MODULE_FIRMWARE(EAGLE_II_FIRMWARE
);
2781 MODULE_FIRMWARE(EAGLE_III_FIRMWARE
);
2782 MODULE_FIRMWARE(EAGLE_IV_FIRMWARE
);
2783 MODULE_FIRMWARE(DSP4I_FIRMWARE
);
2784 MODULE_FIRMWARE(DSP4P_FIRMWARE
);
2785 MODULE_FIRMWARE(DSP9I_FIRMWARE
);
2786 MODULE_FIRMWARE(DSP9P_FIRMWARE
);
2787 MODULE_FIRMWARE(DSPEI_FIRMWARE
);
2788 MODULE_FIRMWARE(DSPEP_FIRMWARE
);
2789 MODULE_FIRMWARE(FPGA930_FIRMWARE
);
2790 MODULE_FIRMWARE(CMV4P_FIRMWARE
);
2791 MODULE_FIRMWARE(CMV4PV2_FIRMWARE
);
2792 MODULE_FIRMWARE(CMV4I_FIRMWARE
);
2793 MODULE_FIRMWARE(CMV4IV2_FIRMWARE
);
2794 MODULE_FIRMWARE(CMV9P_FIRMWARE
);
2795 MODULE_FIRMWARE(CMV9PV2_FIRMWARE
);
2796 MODULE_FIRMWARE(CMV9I_FIRMWARE
);
2797 MODULE_FIRMWARE(CMV9IV2_FIRMWARE
);
2798 MODULE_FIRMWARE(CMVEP_FIRMWARE
);
2799 MODULE_FIRMWARE(CMVEPV2_FIRMWARE
);
2800 MODULE_FIRMWARE(CMVEI_FIRMWARE
);
2801 MODULE_FIRMWARE(CMVEIV2_FIRMWARE
);