2 * Copyright (c) 2003, 2004
3 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
5 * Copyright (c) 2005 Matthieu Castet <castet.matthieu@free.fr>
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice unmodified, this list of conditions, and the following
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * This program is free software; you can redistribute it and/or
37 * modify it under the terms of the GNU General Public License
38 * as published by the Free Software Foundation; either version 2
39 * of the License, or (at your option) any later version.
41 * This program is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU General Public License for more details.
46 * You should have received a copy of the GNU General Public License
47 * along with this program; if not, write to the Free Software
48 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
51 * HISTORY : some part of the code was base on ueagle 1.3 BSD driver,
52 * Damien Bergamini agree to put his code under a DUAL GPL/BSD license.
54 * The rest of the code was was rewritten from scratch.
57 #include <linux/module.h>
58 #include <linux/moduleparam.h>
59 #include <linux/init.h>
60 #include <linux/crc32.h>
61 #include <linux/usb.h>
62 #include <linux/firmware.h>
63 #include <linux/ctype.h>
64 #include <linux/sched.h>
65 #include <linux/kthread.h>
66 #include <linux/version.h>
67 #include <linux/mutex.h>
68 #include <linux/freezer.h>
70 #include <asm/unaligned.h>
74 #define EAGLEUSBVERSION "ueagle 1.4"
80 #define uea_dbg(usb_dev, format, args...) \
83 dev_dbg(&(usb_dev)->dev, \
84 "[ueagle-atm dbg] %s: " format, \
85 __FUNCTION__, ##args); \
88 #define uea_vdbg(usb_dev, format, args...) \
91 dev_dbg(&(usb_dev)->dev, \
92 "[ueagle-atm vdbg] " format, ##args); \
95 #define uea_enters(usb_dev) \
96 uea_vdbg(usb_dev, "entering %s\n", __FUNCTION__)
98 #define uea_leaves(usb_dev) \
99 uea_vdbg(usb_dev, "leaving %s\n", __FUNCTION__)
101 #define uea_err(usb_dev, format,args...) \
102 dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args)
104 #define uea_warn(usb_dev, format,args...) \
105 dev_warn(&(usb_dev)->dev ,"[Ueagle-atm] " format, ##args)
107 #define uea_info(usb_dev, format,args...) \
108 dev_info(&(usb_dev)->dev ,"[ueagle-atm] " format, ##args)
112 /* cmv's from firmware */
117 } __attribute__ ((packed));
124 } __attribute__ ((packed));
126 /* information about currently processed cmv */
142 struct cmv_dsc_e1 e1;
143 struct cmv_dsc_e4 e4;
147 struct usb_device *usb_dev;
148 struct usbatm_data *usbatm;
151 unsigned int driver_info;
159 wait_queue_head_t sync_q;
161 struct task_struct *kthread;
164 wait_queue_head_t cmv_ack_wait;
167 union cmv_dsc cmv_dsc;
169 struct work_struct task;
173 const struct firmware *dsp_firm;
176 void (*dispatch_cmv) (struct uea_softc *, struct intr_pkt *);
177 void (*schedule_load_page) (struct uea_softc *, struct intr_pkt *);
178 int (*stat) (struct uea_softc *);
179 int (*send_cmvs) (struct uea_softc *);
181 /* keep in sync with eaglectl */
209 #define ELSA_VID 0x05CC
210 #define ELSA_PID_PSTFIRM 0x3350
211 #define ELSA_PID_PREFIRM 0x3351
213 #define ELSA_PID_A_PREFIRM 0x3352
214 #define ELSA_PID_A_PSTFIRM 0x3353
215 #define ELSA_PID_B_PREFIRM 0x3362
216 #define ELSA_PID_B_PSTFIRM 0x3363
219 * Devolo IDs : pots if (pid & 0x10)
221 #define DEVOLO_VID 0x1039
222 #define DEVOLO_EAGLE_I_A_PID_PSTFIRM 0x2110
223 #define DEVOLO_EAGLE_I_A_PID_PREFIRM 0x2111
225 #define DEVOLO_EAGLE_I_B_PID_PSTFIRM 0x2100
226 #define DEVOLO_EAGLE_I_B_PID_PREFIRM 0x2101
228 #define DEVOLO_EAGLE_II_A_PID_PSTFIRM 0x2130
229 #define DEVOLO_EAGLE_II_A_PID_PREFIRM 0x2131
231 #define DEVOLO_EAGLE_II_B_PID_PSTFIRM 0x2120
232 #define DEVOLO_EAGLE_II_B_PID_PREFIRM 0x2121
235 * Reference design USB IDs
237 #define ANALOG_VID 0x1110
238 #define ADI930_PID_PREFIRM 0x9001
239 #define ADI930_PID_PSTFIRM 0x9000
241 #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
242 #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
244 #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
245 #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
247 #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
248 #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
250 #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
251 #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
253 #define EAGLE_IV_PID_PREFIRM 0x9042 /* Eagle IV */
254 #define EAGLE_IV_PID_PSTFIRM 0x9041 /* Eagle IV */
259 #define USR_VID 0x0BAF
260 #define MILLER_A_PID_PREFIRM 0x00F2
261 #define MILLER_A_PID_PSTFIRM 0x00F1
262 #define MILLER_B_PID_PREFIRM 0x00FA
263 #define MILLER_B_PID_PSTFIRM 0x00F9
264 #define HEINEKEN_A_PID_PREFIRM 0x00F6
265 #define HEINEKEN_A_PID_PSTFIRM 0x00F5
266 #define HEINEKEN_B_PID_PREFIRM 0x00F8
267 #define HEINEKEN_B_PID_PSTFIRM 0x00F7
270 #define PSTFIRM (1<<7)
271 #define AUTO_ANNEX_A (1<<8)
272 #define AUTO_ANNEX_B (1<<9)
282 /* macros for both struct usb_device_id and struct uea_softc */
283 #define UEA_IS_PREFIRM(x) \
284 (!((x)->driver_info & PSTFIRM))
285 #define UEA_CHIP_VERSION(x) \
286 ((x)->driver_info & 0xf)
289 ((x)->annex & ANNEXB)
291 #define INS_TO_USBDEV(ins) ins->usb_dev
293 #define GET_STATUS(data) \
296 #define IS_OPERATIONAL(sc) \
297 ((UEA_CHIP_VERSION(sc) != EAGLE_IV) ? \
298 (GET_STATUS(sc->stats.phy.state) == 2) : \
299 (sc->stats.phy.state == 7))
302 * Set of macros to handle unaligned data in the firmware blob.
303 * The FW_GET_BYTE() macro is provided only for consistency.
306 #define FW_GET_BYTE(p) *((__u8 *) (p))
307 #define FW_GET_WORD(p) le16_to_cpu(get_unaligned((__le16 *) (p)))
308 #define FW_GET_LONG(p) le32_to_cpu(get_unaligned((__le32 *) (p)))
310 #define FW_DIR "ueagle-atm/"
313 #define BULK_TIMEOUT 300
314 #define CTRL_TIMEOUT 1000
316 #define ACK_TIMEOUT msecs_to_jiffies(3000)
318 #define UEA_INTR_IFACE_NO 0
319 #define UEA_US_IFACE_NO 1
320 #define UEA_DS_IFACE_NO 2
322 #define FASTEST_ISO_INTF 8
324 #define UEA_BULK_DATA_PIPE 0x02
325 #define UEA_IDMA_PIPE 0x04
326 #define UEA_INTR_PIPE 0x04
327 #define UEA_ISO_DATA_PIPE 0x08
329 #define UEA_E1_SET_BLOCK 0x0001
330 #define UEA_E4_SET_BLOCK 0x002c
331 #define UEA_SET_MODE 0x0003
332 #define UEA_SET_2183_DATA 0x0004
333 #define UEA_SET_TIMEOUT 0x0011
335 #define UEA_LOOPBACK_OFF 0x0002
336 #define UEA_LOOPBACK_ON 0x0003
337 #define UEA_BOOT_IDMA 0x0006
338 #define UEA_START_RESET 0x0007
339 #define UEA_END_RESET 0x0008
341 #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
342 #define UEA_MPTX_START (0x3fce | 0x4000)
343 #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
344 #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
346 /* block information in eagle4 dsp firmware */
355 } __attribute__ ((packed));
357 #define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
358 #define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
360 #define E4_L1_STRING_HEADER 0x10
361 #define E4_MAX_PAGE_NUMBER 0x58
362 #define E4_NO_SWAPPAGE_HEADERS 0x31
364 /* l1_code is eagle4 dsp firmware format */
366 u8 string_header[E4_L1_STRING_HEADER];
367 u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER];
368 struct block_index page_header[E4_NO_SWAPPAGE_HEADERS];
370 } __attribute__ ((packed));
372 /* structures describing a block within a DSP page */
373 struct block_info_e1 {
378 __le16 wOvl; /* overlay */
380 } __attribute__ ((packed));
381 #define E1_BLOCK_INFO_SIZE 12
383 struct block_info_e4 {
390 } __attribute__ ((packed));
391 #define E4_BLOCK_INFO_SIZE 14
393 #define UEA_BIHDR 0xabcd
394 #define UEA_RESERVED 0xffff
396 /* constants describing cmv type */
397 #define E1_PREAMBLE 0x535c
398 #define E1_MODEMTOHOST 0x01
399 #define E1_HOSTTOMODEM 0x10
401 #define E1_MEMACCESS 0x1
402 #define E1_ADSLDIRECTIVE 0x7
403 #define E1_FUNCTION_TYPE(f) ((f) >> 4)
404 #define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f)
406 #define E4_MEMACCESS 0
407 #define E4_ADSLDIRECTIVE 0xf
408 #define E4_FUNCTION_TYPE(f) ((f) >> 8)
409 #define E4_FUNCTION_SIZE(f) ((f) & 0x0f)
410 #define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f)
413 #define E1_REQUESTREAD 0x0
414 #define E1_REQUESTWRITE 0x1
415 #define E1_REPLYREAD 0x2
416 #define E1_REPLYWRITE 0x3
418 #define E4_REQUESTREAD 0x0
419 #define E4_REQUESTWRITE 0x4
420 #define E4_REPLYREAD (E4_REQUESTREAD | 1)
421 #define E4_REPLYWRITE (E4_REQUESTWRITE | 1)
423 /* for ADSLDIRECTIVE */
424 #define E1_KERNELREADY 0x0
425 #define E1_MODEMREADY 0x1
427 #define E4_KERNELREADY 0x0
428 #define E4_MODEMREADY 0x1
430 #define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
431 #define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | ((st) & 0xf) << 4 | ((s) & 0xf))
433 #define E1_MAKESA(a, b, c, d) \
434 (((c) & 0xff) << 24 | \
435 ((d) & 0xff) << 16 | \
436 ((a) & 0xff) << 8 | \
439 #define E1_GETSA1(a) ((a >> 8) & 0xff)
440 #define E1_GETSA2(a) (a & 0xff)
441 #define E1_GETSA3(a) ((a >> 24) & 0xff)
442 #define E1_GETSA4(a) ((a >> 16) & 0xff)
444 #define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L')
445 #define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G')
446 #define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O')
447 #define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N')
448 #define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E')
449 #define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T')
460 /* structures representing a CMV (Configuration and Management Variable) */
466 __le32 dwSymbolicAddress;
467 __le16 wOffsetAddress;
469 } __attribute__ ((packed));
477 } __attribute__ ((packed));
479 /* structures representing swap information */
480 struct swap_info_e1 {
482 __u8 bOvl; /* overlay */
483 } __attribute__ ((packed));
485 struct swap_info_e4 {
487 } __attribute__ ((packed));
489 /* structures representing interrupt data */
490 #define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
491 #define e1_bOvl u.e1.s1.swapinfo.bOvl
492 #define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo
494 #define INT_LOADSWAPPAGE 0x0001
495 #define INT_INCOMINGCMV 0x0002
499 struct swap_info_e1 swapinfo;
501 } __attribute__ ((packed)) s1;
505 } __attribute__ ((packed)) s2;
506 } __attribute__ ((packed));
510 struct swap_info_e4 swapinfo;
512 } __attribute__ ((packed)) s1;
516 } __attribute__ ((packed)) s2;
517 } __attribute__ ((packed));
527 union intr_data_e1 e1;
528 union intr_data_e4 e4;
530 } __attribute__ ((packed));
532 #define E1_INTR_PKT_SIZE 28
533 #define E4_INTR_PKT_SIZE 64
535 static struct usb_driver uea_driver;
536 static DEFINE_MUTEX(uea_mutex);
537 static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
539 static int modem_index;
540 static unsigned int debug;
541 static int use_iso[NB_MODEM] = {[0 ... (NB_MODEM - 1)] = 1};
542 static int sync_wait[NB_MODEM];
543 static char *cmv_file[NB_MODEM];
544 static int annex[NB_MODEM];
546 module_param(debug, uint, 0644);
547 MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
548 module_param_array(use_iso, bool, NULL, 0644);
549 MODULE_PARM_DESC(use_iso, "use isochronous usb pipe for incoming traffic");
550 module_param_array(sync_wait, bool, NULL, 0644);
551 MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
552 module_param_array(cmv_file, charp, NULL, 0644);
553 MODULE_PARM_DESC(cmv_file,
554 "file name with configuration and management variables");
555 module_param_array(annex, uint, NULL, 0644);
556 MODULE_PARM_DESC(annex,
557 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
559 #define UPDATE_ATM_STAT(type, val) \
561 if (sc->usbatm->atm_dev) \
562 sc->usbatm->atm_dev->type = val; \
565 /* Firmware loading */
566 #define LOAD_INTERNAL 0xA0
567 #define F8051_USBCS 0x7f92
570 * uea_send_modem_cmd - Send a command for pre-firmware devices.
572 static int uea_send_modem_cmd(struct usb_device *usb,
573 u16 addr, u16 size, u8 * buff)
578 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
580 ret = usb_control_msg(usb,
581 usb_sndctrlpipe(usb, 0),
583 USB_DIR_OUT | USB_TYPE_VENDOR |
584 USB_RECIP_DEVICE, addr, 0, xfer_buff,
592 return (ret == size) ? 0 : -EIO;
595 static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *context)
597 struct usb_device *usb = context;
604 uea_err(usb, "firmware is not available\n");
608 pfw = fw_entry->data;
609 size = fw_entry->size;
611 goto err_fw_corrupted;
613 crc = FW_GET_LONG(pfw);
616 if (crc32_be(0, pfw, size) != crc)
617 goto err_fw_corrupted;
620 * Start to upload formware : send reset
623 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
626 uea_err(usb, "modem reset failed with error %d\n", ret);
631 u8 len = FW_GET_BYTE(pfw);
632 u16 add = FW_GET_WORD(pfw + 1);
636 goto err_fw_corrupted;
638 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
640 uea_err(usb, "uploading firmware data failed "
641 "with error %d\n", ret);
648 goto err_fw_corrupted;
651 * Tell the modem we finish : de-assert reset
654 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
656 uea_err(usb, "modem de-assert failed with error %d\n", ret);
658 uea_info(usb, "firmware uploaded\n");
664 uea_err(usb, "firmware is corrupted\n");
670 * uea_load_firmware - Load usb firmware for pre-firmware devices.
672 static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
675 char *fw_name = FW_DIR "eagle.fw";
678 uea_info(usb, "pre-firmware device, uploading firmware\n");
682 fw_name = FW_DIR "adi930.fw";
685 fw_name = FW_DIR "eagleI.fw";
688 fw_name = FW_DIR "eagleII.fw";
691 fw_name = FW_DIR "eagleIII.fw";
694 fw_name = FW_DIR "eagleIV.fw";
698 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware);
700 uea_err(usb, "firmware %s is not available\n", fw_name);
702 uea_info(usb, "loading firmware %s\n", fw_name);
708 /* modem management : dsp firmware, send/read CMV, monitoring statistic
712 * Make sure that the DSP code provided is safe to use.
714 static int check_dsp_e1(u8 *dsp, unsigned int len)
716 u8 pagecount, blockcount;
719 unsigned int i, j, p, pp;
721 pagecount = FW_GET_BYTE(dsp);
724 /* enough space for page offsets? */
725 if (p + 4 * pagecount > len)
728 for (i = 0; i < pagecount; i++) {
730 pageoffset = FW_GET_LONG(dsp + p);
736 /* enough space for blockcount? */
737 if (pageoffset >= len)
741 blockcount = FW_GET_BYTE(dsp + pp);
744 for (j = 0; j < blockcount; j++) {
746 /* enough space for block header? */
750 pp += 2; /* skip blockaddr */
751 blocksize = FW_GET_WORD(dsp + pp);
754 /* enough space for block data? */
755 if (pp + blocksize > len)
765 static int check_dsp_e4(u8 *dsp, int len)
768 struct l1_code *p = (struct l1_code *) dsp;
769 unsigned int sum = p->code - dsp;
774 if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 &&
775 strcmp("STRATIPHY ANEXB", p->string_header) != 0)
778 for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) {
779 struct block_index *blockidx;
780 u8 blockno = p->page_number_to_block_index[i];
781 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
787 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
790 blockidx = &p->page_header[blockno++];
791 if ((u8 *)(blockidx + 1) - dsp >= len)
794 if (le16_to_cpu(blockidx->PageNumber) != i)
797 l = E4_PAGE_BYTES(blockidx->PageSize);
799 l += le32_to_cpu(blockidx->PageOffset);
803 /* zero is zero regardless endianes */
804 } while (blockidx->NotLastBlock);
807 return (sum == len) ? 0 : 1;
811 * send data to the idma pipe
813 static int uea_idma_write(struct uea_softc *sc, void *data, u32 size)
819 xfer_buff = kmemdup(data, size, GFP_KERNEL);
821 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
825 ret = usb_bulk_msg(sc->usb_dev,
826 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
827 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
832 if (size != bytes_read) {
833 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
841 static int request_dsp(struct uea_softc *sc)
846 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
848 dsp_name = FW_DIR "DSP4i.bin";
850 dsp_name = FW_DIR "DSP4p.bin";
851 } else if (UEA_CHIP_VERSION(sc) == ADI930) {
853 dsp_name = FW_DIR "DSP9i.bin";
855 dsp_name = FW_DIR "DSP9p.bin";
858 dsp_name = FW_DIR "DSPei.bin";
860 dsp_name = FW_DIR "DSPep.bin";
863 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
865 uea_err(INS_TO_USBDEV(sc),
866 "requesting firmware %s failed with error %d\n",
871 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
872 ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size);
874 ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size);
877 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
879 release_firmware(sc->dsp_firm);
888 * The uea_load_page() function must be called within a process context
890 static void uea_load_page_e1(struct work_struct *work)
892 struct uea_softc *sc = container_of(work, struct uea_softc, task);
893 u16 pageno = sc->pageno;
895 struct block_info_e1 bi;
898 u8 pagecount, blockcount;
899 u16 blockaddr, blocksize;
903 /* reload firmware when reboot start and it's loaded already */
904 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
905 release_firmware(sc->dsp_firm);
909 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
912 p = sc->dsp_firm->data;
913 pagecount = FW_GET_BYTE(p);
916 if (pageno >= pagecount)
920 pageoffset = FW_GET_LONG(p);
925 p = sc->dsp_firm->data + pageoffset;
926 blockcount = FW_GET_BYTE(p);
929 uea_dbg(INS_TO_USBDEV(sc),
930 "sending %u blocks for DSP page %u\n", blockcount, pageno);
932 bi.wHdr = cpu_to_le16(UEA_BIHDR);
933 bi.wOvl = cpu_to_le16(ovl);
934 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
936 for (i = 0; i < blockcount; i++) {
937 blockaddr = FW_GET_WORD(p);
940 blocksize = FW_GET_WORD(p);
943 bi.wSize = cpu_to_le16(blocksize);
944 bi.wAddress = cpu_to_le16(blockaddr);
945 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
947 /* send block info through the IDMA pipe */
948 if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE))
951 /* send block data through the IDMA pipe */
952 if (uea_idma_write(sc, p, blocksize))
961 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
964 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
967 static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
969 struct block_info_e4 bi;
970 struct block_index *blockidx;
971 struct l1_code *p = (struct l1_code *) sc->dsp_firm->data;
972 u8 blockno = p->page_number_to_block_index[pageno];
974 bi.wHdr = cpu_to_be16(UEA_BIHDR);
976 bi.bPageNumber = pageno;
977 bi.wReserved = cpu_to_be16(UEA_RESERVED);
981 unsigned int blocksize;
983 blockidx = &p->page_header[blockno];
984 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
985 blockoffset = sc->dsp_firm->data + le32_to_cpu(blockidx->PageOffset);
987 bi.dwSize = cpu_to_be32(blocksize);
988 bi.dwAddress = swab32(blockidx->PageAddress);
990 uea_dbg(INS_TO_USBDEV(sc),
991 "sending block %u for DSP page %u size %u adress %x\n",
992 blockno, pageno, blocksize, le32_to_cpu(blockidx->PageAddress));
994 /* send block info through the IDMA pipe */
995 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
998 /* send block data through the IDMA pipe */
999 if (uea_idma_write(sc, blockoffset, blocksize))
1003 } while (blockidx->NotLastBlock);
1008 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno);
1012 static void uea_load_page_e4(struct work_struct *work)
1014 struct uea_softc *sc = container_of(work, struct uea_softc, task);
1015 u8 pageno = sc->pageno;
1017 struct block_info_e4 bi;
1020 uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
1022 /* reload firmware when reboot start and it's loaded already */
1023 if (pageno == 0 && sc->dsp_firm) {
1024 release_firmware(sc->dsp_firm);
1025 sc->dsp_firm = NULL;
1028 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
1031 p = (struct l1_code *) sc->dsp_firm->data;
1032 if (pageno >= p->page_header[0].PageNumber) {
1033 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
1038 __uea_load_page_e4(sc, pageno, 0);
1042 uea_dbg(INS_TO_USBDEV(sc),
1043 "sending Main DSP page %u\n", p->page_header[0].PageNumber);
1045 for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) {
1046 if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize))
1047 __uea_load_page_e4(sc, i, 1);
1050 uea_dbg(INS_TO_USBDEV(sc),"sending start bi\n");
1052 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1054 bi.bPageNumber = 0xff;
1055 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1056 bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize));
1057 bi.dwAddress = swab32(p->page_header[0].PageAddress);
1059 /* send block info through the IDMA pipe */
1060 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1061 uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n");
1064 static inline void wake_up_cmv_ack(struct uea_softc *sc)
1066 BUG_ON(sc->cmv_ack);
1068 wake_up(&sc->cmv_ack_wait);
1071 static inline int wait_cmv_ack(struct uea_softc *sc)
1073 int ret = wait_event_interruptible_timeout(sc->cmv_ack_wait,
1074 sc->cmv_ack, ACK_TIMEOUT);
1077 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
1078 jiffies_to_msecs(ret));
1083 return (ret == 0) ? -ETIMEDOUT : 0;
1086 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1088 static int uea_request(struct uea_softc *sc,
1089 u16 value, u16 index, u16 size, void *data)
1094 xfer_buff = kmemdup(data, size, GFP_KERNEL);
1096 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
1100 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
1101 UCDC_SEND_ENCAPSULATED_COMMAND,
1102 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1103 value, index, xfer_buff, size, CTRL_TIMEOUT);
1107 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
1112 uea_err(INS_TO_USBDEV(sc),
1113 "usb_control_msg send only %d bytes (instead of %d)\n",
1121 static int uea_cmv_e1(struct uea_softc *sc,
1122 u8 function, u32 address, u16 offset, u32 data)
1127 uea_enters(INS_TO_USBDEV(sc));
1128 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1129 "offset : 0x%04x, data : 0x%08x\n",
1130 E1_FUNCTION_TYPE(function), E1_FUNCTION_SUBTYPE(function),
1131 E1_GETSA1(address), E1_GETSA2(address), E1_GETSA3(address),
1132 E1_GETSA4(address), offset, data);
1134 /* we send a request, but we expect a reply */
1135 sc->cmv_dsc.e1.function = function | 0x2;
1136 sc->cmv_dsc.e1.idx++;
1137 sc->cmv_dsc.e1.address = address;
1138 sc->cmv_dsc.e1.offset = offset;
1140 cmv.wPreamble = cpu_to_le16(E1_PREAMBLE);
1141 cmv.bDirection = E1_HOSTTOMODEM;
1142 cmv.bFunction = function;
1143 cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx);
1144 put_unaligned(cpu_to_le32(address), &cmv.dwSymbolicAddress);
1145 cmv.wOffsetAddress = cpu_to_le16(offset);
1146 put_unaligned(cpu_to_le32(data >> 16 | data << 16), &cmv.dwData);
1148 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv);
1151 ret = wait_cmv_ack(sc);
1152 uea_leaves(INS_TO_USBDEV(sc));
1156 static int uea_cmv_e4(struct uea_softc *sc,
1157 u16 function, u16 group, u16 address, u16 offset, u32 data)
1162 uea_enters(INS_TO_USBDEV(sc));
1163 memset(&cmv, 0, sizeof(cmv));
1165 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
1166 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1167 E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function),
1168 group, address, offset, data);
1170 /* we send a request, but we expect a reply */
1171 sc->cmv_dsc.e4.function = function | (0x1 << 4);
1172 sc->cmv_dsc.e4.offset = offset;
1173 sc->cmv_dsc.e4.address = address;
1174 sc->cmv_dsc.e4.group = group;
1176 cmv.wFunction = cpu_to_be16(function);
1177 cmv.wGroup = cpu_to_be16(group);
1178 cmv.wAddress = cpu_to_be16(address);
1179 cmv.wOffset = cpu_to_be16(offset);
1180 cmv.dwData[0] = cpu_to_be32(data);
1182 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv);
1185 ret = wait_cmv_ack(sc);
1186 uea_leaves(INS_TO_USBDEV(sc));
1190 static inline int uea_read_cmv_e1(struct uea_softc *sc,
1191 u32 address, u16 offset, u32 *data)
1193 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD),
1194 address, offset, 0);
1196 uea_err(INS_TO_USBDEV(sc),
1197 "reading cmv failed with error %d\n", ret);
1204 static inline int uea_read_cmv_e4(struct uea_softc *sc,
1205 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1207 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTREAD, size),
1208 group, address, offset, 0);
1210 uea_err(INS_TO_USBDEV(sc),
1211 "reading cmv failed with error %d\n", ret);
1214 /* size is in 16-bit word quantities */
1216 *(data + 1) = sc->data1;
1221 static inline int uea_write_cmv_e1(struct uea_softc *sc,
1222 u32 address, u16 offset, u32 data)
1224 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE),
1225 address, offset, data);
1227 uea_err(INS_TO_USBDEV(sc),
1228 "writing cmv failed with error %d\n", ret);
1233 static inline int uea_write_cmv_e4(struct uea_softc *sc,
1234 u8 size, u16 group, u16 address, u16 offset, u32 data)
1236 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTWRITE, size),
1237 group, address, offset, data);
1239 uea_err(INS_TO_USBDEV(sc),
1240 "writing cmv failed with error %d\n", ret);
1245 static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1250 /* in bulk mode the modem have problem with high rate
1251 * changing internal timing could improve things, but the
1252 * value is misterious.
1253 * ADI930 don't support it (-EPIPE error).
1256 if (UEA_CHIP_VERSION(sc) == ADI930 ||
1257 use_iso[sc->modem_index] > 0 ||
1258 sc->stats.phy.dsrate == dsrate)
1261 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1262 timeout = (dsrate <= 1024*1024) ? 0 : 1;
1263 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
1264 uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n",
1265 timeout, ret < 0 ? " failed" : "");
1270 * Monitor the modem and update the stat
1271 * return 0 if everything is ok
1272 * return < 0 if an error occurs (-EAGAIN reboot needed)
1274 static int uea_stat_e1(struct uea_softc *sc)
1279 uea_enters(INS_TO_USBDEV(sc));
1280 data = sc->stats.phy.state;
1282 ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state);
1286 switch (GET_STATUS(sc->stats.phy.state)) {
1287 case 0: /* not yet synchronized */
1288 uea_dbg(INS_TO_USBDEV(sc),
1289 "modem not yet synchronized\n");
1292 case 1: /* initialization */
1293 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1296 case 2: /* operational */
1297 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
1300 case 3: /* fail ... */
1301 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1302 " (may be try other cmv/dsp)\n");
1305 case 4 ... 6: /* test state */
1306 uea_warn(INS_TO_USBDEV(sc),
1307 "modem in test mode - not supported\n");
1310 case 7: /* fast-retain ... */
1311 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
1314 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
1315 GET_STATUS(sc->stats.phy.state));
1319 if (GET_STATUS(data) != 2) {
1320 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1321 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1323 /* release the dsp firmware as it is not needed until
1327 release_firmware(sc->dsp_firm);
1328 sc->dsp_firm = NULL;
1332 /* always update it as atm layer could not be init when we switch to
1335 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1337 /* wake up processes waiting for synchronization */
1338 wake_up(&sc->sync_q);
1340 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags);
1343 sc->stats.phy.mflags |= sc->stats.phy.flags;
1345 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1346 * we check the status again in order to detect the failure earlier
1348 if (sc->stats.phy.flags) {
1349 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1350 sc->stats.phy.flags);
1354 ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data);
1358 uea_set_bulk_timeout(sc, (data >> 16) * 32);
1359 sc->stats.phy.dsrate = (data >> 16) * 32;
1360 sc->stats.phy.usrate = (data & 0xffff) * 32;
1361 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1363 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data);
1366 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
1368 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data);
1371 sc->stats.phy.usattenuation = (data & 0xff) / 2;
1373 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin);
1377 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin);
1381 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow);
1385 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow);
1389 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc);
1393 /* only for atu-c */
1394 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc);
1398 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr);
1402 /* only for atu-c */
1403 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr);
1407 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 8, &sc->stats.phy.vidco);
1411 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 13, &sc->stats.phy.vidcpe);
1418 static int uea_stat_e4(struct uea_softc *sc)
1424 uea_enters(INS_TO_USBDEV(sc));
1425 data = sc->stats.phy.state;
1427 /* XXX only need to be done before operationnal... */
1428 ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state);
1432 switch (sc->stats.phy.state) {
1433 case 0x0: /* not yet synchronized */
1437 uea_dbg(INS_TO_USBDEV(sc), "modem not yet synchronized\n");
1439 case 0x5: /* initialization */
1443 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1445 case 0x2: /* fail ... */
1446 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1447 " (may be try other cmv/dsp)\n");
1449 case 0x7: /* operational */
1452 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n", sc->stats.phy.state);
1457 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1458 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1460 /* release the dsp firmware as it is not needed until
1464 release_firmware(sc->dsp_firm);
1465 sc->dsp_firm = NULL;
1469 /* always update it as atm layer could not be init when we switch to
1472 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1474 /* wake up processes waiting for synchronization */
1475 wake_up(&sc->sync_q);
1477 /* TODO improve this state machine :
1478 * we need some CMV info : what they do and their unit
1479 * we should find the equivalent of eagle3- CMV
1482 ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags);
1485 sc->stats.phy.mflags |= sc->stats.phy.flags;
1487 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1488 * we check the status again in order to detect the failure earlier
1490 if (sc->stats.phy.flags) {
1491 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1492 sc->stats.phy.flags);
1493 if (sc->stats.phy.flags & 1) //delineation LOSS
1495 if (sc->stats.phy.flags & 0x4000) //Reset Flag
1500 /* rate data may be in upper or lower half of 64 bit word, strange */
1501 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr);
1504 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1505 sc->stats.phy.usrate = data / 1000;
1507 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr);
1510 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1511 uea_set_bulk_timeout(sc, data / 1000);
1512 sc->stats.phy.dsrate = data / 1000;
1513 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1515 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data);
1518 sc->stats.phy.dsattenuation = data / 10;
1520 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data);
1523 sc->stats.phy.usattenuation = data / 10;
1525 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data);
1528 sc->stats.phy.dsmargin = data / 2;
1530 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data);
1533 sc->stats.phy.usmargin = data / 10;
1538 static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1540 char file_arr[] = "CMVxy.bin";
1543 /* set proper name corresponding modem version and line type */
1544 if (cmv_file[sc->modem_index] == NULL) {
1545 if (UEA_CHIP_VERSION(sc) == ADI930)
1547 else if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1552 file_arr[4] = IS_ISDN(sc) ? 'i' : 'p';
1555 file = cmv_file[sc->modem_index];
1557 strcpy(cmv_name, FW_DIR);
1558 strlcat(cmv_name, file, FIRMWARE_NAME_MAX);
1560 strlcat(cmv_name, ".v2", FIRMWARE_NAME_MAX);
1563 static int request_cmvs_old(struct uea_softc *sc,
1564 void **cmvs, const struct firmware **fw)
1568 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1570 cmvs_file_name(sc, cmv_name, 1);
1571 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1573 uea_err(INS_TO_USBDEV(sc),
1574 "requesting firmware %s failed with error %d\n",
1579 data = (u8 *) (*fw)->data;
1582 goto err_fw_corrupted;
1584 if (size != *data * sizeof(struct uea_cmvs_v1) + 1)
1585 goto err_fw_corrupted;
1587 *cmvs = (void *)(data + 1);
1591 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1592 release_firmware(*fw);
1596 static int request_cmvs(struct uea_softc *sc,
1597 void **cmvs, const struct firmware **fw, int *ver)
1602 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1604 cmvs_file_name(sc, cmv_name, 2);
1605 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1607 /* if caller can handle old version, try to provide it */
1609 uea_warn(INS_TO_USBDEV(sc), "requesting firmware %s failed, "
1610 "try to get older cmvs\n", cmv_name);
1611 return request_cmvs_old(sc, cmvs, fw);
1613 uea_err(INS_TO_USBDEV(sc),
1614 "requesting firmware %s failed with error %d\n",
1620 data = (u8 *) (*fw)->data;
1621 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1623 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted, "
1624 "try to get older cmvs\n", cmv_name);
1625 release_firmware(*fw);
1626 return request_cmvs_old(sc, cmvs, fw);
1628 goto err_fw_corrupted;
1636 goto err_fw_corrupted;
1638 crc = FW_GET_LONG(data);
1641 if (crc32_be(0, data, size) != crc)
1642 goto err_fw_corrupted;
1644 if (size != *data * sizeof(struct uea_cmvs_v2) + 1)
1645 goto err_fw_corrupted;
1647 *cmvs = (void *) (data + 1);
1651 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1652 release_firmware(*fw);
1656 static int uea_send_cmvs_e1(struct uea_softc *sc)
1660 const struct firmware *cmvs_fw;
1661 int ver = 1; // we can handle v1 cmv firmware version;
1663 /* Enter in R-IDLE (cmv) until instructed otherwise */
1664 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
1668 /* Dump firmware version */
1669 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid);
1672 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1673 sc->stats.phy.firmid);
1676 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1682 struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr;
1684 uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, "
1685 "please update your firmware\n");
1687 for (i = 0; i < len; i++) {
1688 ret = uea_write_cmv_e1(sc, FW_GET_LONG(&cmvs_v1[i].address),
1689 FW_GET_WORD(&cmvs_v1[i].offset),
1690 FW_GET_LONG(&cmvs_v1[i].data));
1694 } else if (ver == 2) {
1695 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1697 for (i = 0; i < len; i++) {
1698 ret = uea_write_cmv_e1(sc, FW_GET_LONG(&cmvs_v2[i].address),
1699 (u16) FW_GET_LONG(&cmvs_v2[i].offset),
1700 FW_GET_LONG(&cmvs_v2[i].data));
1705 /* This realy should not happen */
1706 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1710 /* Enter in R-ACT-REQ */
1711 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1712 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1713 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n");
1715 release_firmware(cmvs_fw);
1719 static int uea_send_cmvs_e4(struct uea_softc *sc)
1723 const struct firmware *cmvs_fw;
1724 int ver = 2; // we can only handle v2 cmv firmware version;
1726 /* Enter in R-IDLE (cmv) until instructed otherwise */
1727 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
1731 /* Dump firmware version */
1732 /* XXX don't read the 3th byte as it is always 6 */
1733 ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid);
1736 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1737 sc->stats.phy.firmid);
1741 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1747 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1749 for (i = 0; i < len; i++) {
1750 ret = uea_write_cmv_e4(sc, 1,
1751 FW_GET_LONG(&cmvs_v2[i].group),
1752 FW_GET_LONG(&cmvs_v2[i].address),
1753 FW_GET_LONG(&cmvs_v2[i].offset),
1754 FW_GET_LONG(&cmvs_v2[i].data));
1759 /* This realy should not happen */
1760 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1764 /* Enter in R-ACT-REQ */
1765 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1766 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1767 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n");
1769 release_firmware(cmvs_fw);
1773 /* Start boot post firmware modem:
1774 * - send reset commands through usb control pipe
1775 * - start workqueue for DSP loading
1776 * - send CMV options to modem
1779 static int uea_start_reset(struct uea_softc *sc)
1781 u16 zero = 0; /* ;-) */
1784 uea_enters(INS_TO_USBDEV(sc));
1785 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1787 /* mask interrupt */
1789 /* We need to set this here because, a ack timeout could have occured,
1790 * but before we start the reboot, the ack occurs and set this to 1.
1791 * So we will failed to wait Ready CMV.
1794 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST);
1796 /* reset statistics */
1797 memset(&sc->stats, 0, sizeof(struct uea_stats));
1799 /* tell the modem that we want to boot in IDMA mode */
1800 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1801 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1803 /* enter reset mode */
1804 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1806 /* original driver use 200ms, but windows driver use 100ms */
1809 /* leave reset mode */
1810 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1812 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
1813 /* clear tx and rx mailboxes */
1814 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1815 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1816 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1821 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1822 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1);
1824 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY);
1826 /* demask interrupt */
1829 /* start loading DSP */
1832 schedule_work(&sc->task);
1834 /* wait for modem ready CMV */
1835 ret = wait_cmv_ack(sc);
1839 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1841 ret = sc->send_cmvs(sc);
1846 uea_leaves(INS_TO_USBDEV(sc));
1851 * In case of an error wait 1s before rebooting the modem
1852 * if the modem don't request reboot (-EAGAIN).
1853 * Monitor the modem every 1s.
1856 static int uea_kthread(void *data)
1858 struct uea_softc *sc = data;
1862 uea_enters(INS_TO_USBDEV(sc));
1863 while (!kthread_should_stop()) {
1864 if (ret < 0 || sc->reset)
1865 ret = uea_start_reset(sc);
1869 msleep_interruptible(1000);
1870 if (try_to_freeze())
1871 uea_err(INS_TO_USBDEV(sc), "suspend/resume not supported, "
1872 "please unplug/replug your modem\n");
1874 uea_leaves(INS_TO_USBDEV(sc));
1878 /* Load second usb firmware for ADI930 chip */
1879 static int load_XILINX_firmware(struct uea_softc *sc)
1881 const struct firmware *fw_entry;
1882 int ret, size, u, ln;
1884 char *fw_name = FW_DIR "930-fpga.bin";
1886 uea_enters(INS_TO_USBDEV(sc));
1888 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1890 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1895 pfw = fw_entry->data;
1896 size = fw_entry->size;
1897 if (size != 0x577B) {
1898 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1903 for (u = 0; u < size; u += ln) {
1904 ln = min(size - u, 64);
1905 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1907 uea_err(INS_TO_USBDEV(sc),
1908 "elsa download data failed (%d)\n", ret);
1913 /* finish to send the fpga */
1914 ret = uea_request(sc, 0xe, 1, 0, NULL);
1916 uea_err(INS_TO_USBDEV(sc),
1917 "elsa download data failed (%d)\n", ret);
1921 /* Tell the modem we finish : de-assert reset */
1923 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1925 uea_err(sc->usb_dev, "elsa de-assert failed with error %d\n", ret);
1928 release_firmware(fw_entry);
1930 uea_leaves(INS_TO_USBDEV(sc));
1934 /* The modem send us an ack. First with check if it right */
1935 static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
1937 struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;
1938 struct cmv_e1 *cmv = &intr->u.e1.s2.cmv;
1940 uea_enters(INS_TO_USBDEV(sc));
1941 if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE)
1944 if (cmv->bDirection != E1_MODEMTOHOST)
1947 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1948 * the first MEMACESS cmv. Ignore it...
1950 if (cmv->bFunction != dsc->function) {
1951 if (UEA_CHIP_VERSION(sc) == ADI930
1952 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
1953 cmv->wIndex = cpu_to_le16(dsc->idx);
1954 put_unaligned(cpu_to_le32(dsc->address), &cmv->dwSymbolicAddress);
1955 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
1960 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY)) {
1961 wake_up_cmv_ack(sc);
1962 uea_leaves(INS_TO_USBDEV(sc));
1966 /* in case of MEMACCESS */
1967 if (le16_to_cpu(cmv->wIndex) != dsc->idx ||
1968 le32_to_cpu(get_unaligned(&cmv->dwSymbolicAddress)) != dsc->address ||
1969 le16_to_cpu(cmv->wOffsetAddress) != dsc->offset)
1972 sc->data = le32_to_cpu(get_unaligned(&cmv->dwData));
1973 sc->data = sc->data << 16 | sc->data >> 16;
1975 wake_up_cmv_ack(sc);
1976 uea_leaves(INS_TO_USBDEV(sc));
1980 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
1981 "Function : %d, Subfunction : %d\n",
1982 E1_FUNCTION_TYPE(cmv->bFunction),
1983 E1_FUNCTION_SUBTYPE(cmv->bFunction));
1984 uea_leaves(INS_TO_USBDEV(sc));
1988 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
1989 "wPreamble %d, bDirection %d\n",
1990 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
1991 uea_leaves(INS_TO_USBDEV(sc));
1994 /* The modem send us an ack. First with check if it right */
1995 static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
1997 struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;
1998 struct cmv_e4 *cmv = &intr->u.e4.s2.cmv;
2000 uea_enters(INS_TO_USBDEV(sc));
2001 uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n",
2002 be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction),
2003 be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
2004 be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1]));
2006 if (be16_to_cpu(cmv->wFunction) != dsc->function)
2009 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1)) {
2010 wake_up_cmv_ack(sc);
2011 uea_leaves(INS_TO_USBDEV(sc));
2015 /* in case of MEMACCESS */
2016 if (be16_to_cpu(cmv->wOffset) != dsc->offset ||
2017 be16_to_cpu(cmv->wGroup) != dsc->group ||
2018 be16_to_cpu(cmv->wAddress) != dsc->address)
2021 sc->data = be32_to_cpu(cmv->dwData[0]);
2022 sc->data1 = be32_to_cpu(cmv->dwData[1]);
2023 wake_up_cmv_ack(sc);
2024 uea_leaves(INS_TO_USBDEV(sc));
2028 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
2029 "Function : %d, Subfunction : %d\n",
2030 E4_FUNCTION_TYPE(cmv->wFunction),
2031 E4_FUNCTION_SUBTYPE(cmv->wFunction));
2032 uea_leaves(INS_TO_USBDEV(sc));
2036 static void uea_schedule_load_page_e1(struct uea_softc *sc, struct intr_pkt *intr)
2038 sc->pageno = intr->e1_bSwapPageNo;
2039 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
2040 schedule_work(&sc->task);
2043 static void uea_schedule_load_page_e4(struct uea_softc *sc, struct intr_pkt *intr)
2045 sc->pageno = intr->e4_bSwapPageNo;
2046 schedule_work(&sc->task);
2052 static void uea_intr(struct urb *urb)
2054 struct uea_softc *sc = urb->context;
2055 struct intr_pkt *intr = urb->transfer_buffer;
2056 int status = urb->status;
2058 uea_enters(INS_TO_USBDEV(sc));
2060 if (unlikely(status < 0)) {
2061 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
2066 /* device-to-host interrupt */
2067 if (intr->bType != 0x08 || sc->booting) {
2068 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
2072 switch (le16_to_cpu(intr->wInterrupt)) {
2073 case INT_LOADSWAPPAGE:
2074 sc->schedule_load_page(sc, intr);
2077 case INT_INCOMINGCMV:
2078 sc->dispatch_cmv(sc, intr);
2082 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
2083 le16_to_cpu(intr->wInterrupt));
2087 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
2091 * Start the modem : init the data and start kernel thread
2093 static int uea_boot(struct uea_softc *sc)
2096 struct intr_pkt *intr;
2098 uea_enters(INS_TO_USBDEV(sc));
2100 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2101 size = E4_INTR_PKT_SIZE;
2102 sc->dispatch_cmv = uea_dispatch_cmv_e4;
2103 sc->schedule_load_page = uea_schedule_load_page_e4;
2104 sc->stat = uea_stat_e4;
2105 sc->send_cmvs = uea_send_cmvs_e4;
2106 INIT_WORK(&sc->task, uea_load_page_e4);
2108 size = E1_INTR_PKT_SIZE;
2109 sc->dispatch_cmv = uea_dispatch_cmv_e1;
2110 sc->schedule_load_page = uea_schedule_load_page_e1;
2111 sc->stat = uea_stat_e1;
2112 sc->send_cmvs = uea_send_cmvs_e1;
2113 INIT_WORK(&sc->task, uea_load_page_e1);
2116 init_waitqueue_head(&sc->sync_q);
2117 init_waitqueue_head(&sc->cmv_ack_wait);
2119 if (UEA_CHIP_VERSION(sc) == ADI930)
2120 load_XILINX_firmware(sc);
2122 intr = kmalloc(size, GFP_KERNEL);
2124 uea_err(INS_TO_USBDEV(sc),
2125 "cannot allocate interrupt package\n");
2126 uea_leaves(INS_TO_USBDEV(sc));
2130 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
2132 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
2136 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
2137 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
2138 intr, size, uea_intr, sc,
2139 sc->usb_dev->actconfig->interface[0]->altsetting[0].
2140 endpoint[0].desc.bInterval);
2142 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2144 uea_err(INS_TO_USBDEV(sc),
2145 "urb submition failed with error %d\n", ret);
2149 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm");
2150 if (sc->kthread == ERR_PTR(-ENOMEM)) {
2151 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2155 uea_leaves(INS_TO_USBDEV(sc));
2159 usb_kill_urb(sc->urb_int);
2161 usb_free_urb(sc->urb_int);
2164 uea_leaves(INS_TO_USBDEV(sc));
2169 * Stop the modem : kill kernel thread and free data
2171 static void uea_stop(struct uea_softc *sc)
2174 uea_enters(INS_TO_USBDEV(sc));
2175 ret = kthread_stop(sc->kthread);
2176 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
2178 /* stop any pending boot process */
2179 flush_scheduled_work();
2181 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
2183 usb_kill_urb(sc->urb_int);
2184 kfree(sc->urb_int->transfer_buffer);
2185 usb_free_urb(sc->urb_int);
2188 release_firmware(sc->dsp_firm);
2189 uea_leaves(INS_TO_USBDEV(sc));
2192 /* syfs interface */
2193 static struct uea_softc *dev_to_uea(struct device *dev)
2195 struct usb_interface *intf;
2196 struct usbatm_data *usbatm;
2198 intf = to_usb_interface(dev);
2202 usbatm = usb_get_intfdata(intf);
2206 return usbatm->driver_data;
2209 static ssize_t read_status(struct device *dev, struct device_attribute *attr,
2213 struct uea_softc *sc;
2215 mutex_lock(&uea_mutex);
2216 sc = dev_to_uea(dev);
2219 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
2221 mutex_unlock(&uea_mutex);
2225 static ssize_t reboot(struct device *dev, struct device_attribute *attr,
2226 const char *buf, size_t count)
2229 struct uea_softc *sc;
2231 mutex_lock(&uea_mutex);
2232 sc = dev_to_uea(dev);
2238 mutex_unlock(&uea_mutex);
2242 static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot);
2244 static ssize_t read_human_status(struct device *dev, struct device_attribute *attr,
2249 struct uea_softc *sc;
2251 mutex_lock(&uea_mutex);
2252 sc = dev_to_uea(dev);
2256 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2257 switch (sc->stats.phy.state) {
2258 case 0x0: /* not yet synchronized */
2264 case 0x5: /* initialization */
2270 case 0x7: /* operational */
2273 case 0x2: /* fail ... */
2276 default: /* unknown */
2281 modem_state = GET_STATUS(sc->stats.phy.state);
2283 switch (modem_state) {
2285 ret = sprintf(buf, "Modem is booting\n");
2288 ret = sprintf(buf, "Modem is initializing\n");
2291 ret = sprintf(buf, "Modem is operational\n");
2294 ret = sprintf(buf, "Modem synchronization failed\n");
2297 ret = sprintf(buf, "Modem state is unknown\n");
2301 mutex_unlock(&uea_mutex);
2305 static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, read_human_status, NULL);
2307 static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2311 struct uea_softc *sc;
2312 char *delin = "GOOD";
2314 mutex_lock(&uea_mutex);
2315 sc = dev_to_uea(dev);
2319 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2320 if (sc->stats.phy.flags & 0x4000)
2322 else if (sc->stats.phy.flags & 0x0001)
2325 if (sc->stats.phy.flags & 0x0C00)
2327 else if (sc->stats.phy.flags & 0x0030)
2331 ret = sprintf(buf, "%s\n", delin);
2333 mutex_unlock(&uea_mutex);
2337 static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL);
2339 #define UEA_ATTR(name, reset) \
2341 static ssize_t read_##name(struct device *dev, \
2342 struct device_attribute *attr, char *buf) \
2344 int ret = -ENODEV; \
2345 struct uea_softc *sc; \
2347 mutex_lock(&uea_mutex); \
2348 sc = dev_to_uea(dev); \
2351 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2353 sc->stats.phy.name = 0; \
2355 mutex_unlock(&uea_mutex); \
2359 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2361 UEA_ATTR(mflags, 1);
2362 UEA_ATTR(vidcpe, 0);
2363 UEA_ATTR(usrate, 0);
2364 UEA_ATTR(dsrate, 0);
2365 UEA_ATTR(usattenuation, 0);
2366 UEA_ATTR(dsattenuation, 0);
2367 UEA_ATTR(usmargin, 0);
2368 UEA_ATTR(dsmargin, 0);
2369 UEA_ATTR(txflow, 0);
2370 UEA_ATTR(rxflow, 0);
2371 UEA_ATTR(uscorr, 0);
2372 UEA_ATTR(dscorr, 0);
2375 UEA_ATTR(firmid, 0);
2377 /* Retrieve the device End System Identifier (MAC) */
2379 #define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
2380 static int uea_getesi(struct uea_softc *sc, u_char * esi)
2382 unsigned char mac_str[2 * ETH_ALEN + 1];
2385 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
2386 sizeof(mac_str)) != 2 * ETH_ALEN)
2389 for (i = 0; i < ETH_ALEN; i++)
2390 esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]);
2396 static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
2398 struct uea_softc *sc = usbatm->driver_data;
2400 return uea_getesi(sc, atm_dev->esi);
2403 static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
2405 struct uea_softc *sc = usbatm->driver_data;
2407 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
2413 static int claim_interface(struct usb_device *usb_dev,
2414 struct usbatm_data *usbatm, int ifnum)
2417 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
2420 uea_err(usb_dev, "interface %d not found\n", ifnum);
2424 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
2426 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
2431 static struct attribute *attrs[] = {
2432 &dev_attr_stat_status.attr,
2433 &dev_attr_stat_mflags.attr,
2434 &dev_attr_stat_human_status.attr,
2435 &dev_attr_stat_delin.attr,
2436 &dev_attr_stat_vidcpe.attr,
2437 &dev_attr_stat_usrate.attr,
2438 &dev_attr_stat_dsrate.attr,
2439 &dev_attr_stat_usattenuation.attr,
2440 &dev_attr_stat_dsattenuation.attr,
2441 &dev_attr_stat_usmargin.attr,
2442 &dev_attr_stat_dsmargin.attr,
2443 &dev_attr_stat_txflow.attr,
2444 &dev_attr_stat_rxflow.attr,
2445 &dev_attr_stat_uscorr.attr,
2446 &dev_attr_stat_dscorr.attr,
2447 &dev_attr_stat_usunc.attr,
2448 &dev_attr_stat_dsunc.attr,
2449 &dev_attr_stat_firmid.attr,
2452 static struct attribute_group attr_grp = {
2456 static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
2457 const struct usb_device_id *id)
2459 struct usb_device *usb = interface_to_usbdev(intf);
2460 struct uea_softc *sc;
2461 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
2465 /* interface 0 is for firmware/monitoring */
2466 if (ifnum != UEA_INTR_IFACE_NO)
2469 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
2471 /* interface 1 is for outbound traffic */
2472 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
2476 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
2477 if (UEA_CHIP_VERSION(id) != ADI930) {
2478 /* interface 2 is for inbound traffic */
2479 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
2484 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
2486 uea_err(usb, "uea_init: not enough memory !\n");
2491 usbatm->driver_data = sc;
2492 sc->usbatm = usbatm;
2493 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
2494 sc->driver_info = id->driver_info;
2496 /* first try to use module parameter */
2497 if (annex[sc->modem_index] == 1)
2499 else if (annex[sc->modem_index] == 2)
2501 /* try to autodetect annex */
2502 else if (sc->driver_info & AUTO_ANNEX_A)
2504 else if (sc->driver_info & AUTO_ANNEX_B)
2507 sc->annex = (le16_to_cpu(sc->usb_dev->descriptor.bcdDevice) & 0x80)?ANNEXB:ANNEXA;
2509 /* ADI930 don't support iso */
2510 if (UEA_CHIP_VERSION(id) != ADI930 && use_iso[sc->modem_index]) {
2513 /* try set fastest alternate for inbound traffic interface */
2514 for (i = FASTEST_ISO_INTF; i > 0; i--)
2515 if (usb_set_interface(usb, UEA_DS_IFACE_NO, i) == 0)
2519 uea_dbg(usb, "set alternate %d for 2 interface\n", i);
2520 uea_info(usb, "using iso mode\n");
2521 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
2523 uea_err(usb, "setting any alternate failed for "
2524 "2 interface, using bulk mode\n");
2528 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
2539 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2545 static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
2547 struct uea_softc *sc = usbatm->driver_data;
2549 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2554 static struct usbatm_driver uea_usbatm_driver = {
2555 .driver_name = "ueagle-atm",
2557 .atm_start = uea_atm_open,
2558 .unbind = uea_unbind,
2559 .heavy_init = uea_heavy,
2560 .bulk_in = UEA_BULK_DATA_PIPE,
2561 .bulk_out = UEA_BULK_DATA_PIPE,
2562 .isoc_in = UEA_ISO_DATA_PIPE,
2565 static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2567 struct usb_device *usb = interface_to_usbdev(intf);
2570 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2571 le16_to_cpu(usb->descriptor.idVendor),
2572 le16_to_cpu(usb->descriptor.idProduct),
2573 le16_to_cpu(usb->descriptor.bcdDevice),
2574 chip_name[UEA_CHIP_VERSION(id)]);
2576 usb_reset_device(usb);
2578 if (UEA_IS_PREFIRM(id))
2579 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2581 return usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2584 static void uea_disconnect(struct usb_interface *intf)
2586 struct usb_device *usb = interface_to_usbdev(intf);
2587 int ifnum = intf->altsetting->desc.bInterfaceNumber;
2590 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2591 * Pre-firmware device has one interface
2593 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
2594 mutex_lock(&uea_mutex);
2595 usbatm_usb_disconnect(intf);
2596 mutex_unlock(&uea_mutex);
2597 uea_info(usb, "ADSL device removed\n");
2604 * List of supported VID/PID
2606 static const struct usb_device_id uea_ids[] = {
2607 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
2608 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
2609 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2610 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
2611 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2612 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
2613 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2614 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
2615 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM), .driver_info = EAGLE_III | PREFIRM},
2616 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM), .driver_info = EAGLE_III | PSTFIRM},
2617 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM), .driver_info = EAGLE_IV | PREFIRM},
2618 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM), .driver_info = EAGLE_IV | PSTFIRM},
2619 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2620 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2621 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2622 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2623 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2624 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A},
2625 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2626 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B},
2627 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
2628 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
2629 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM), .driver_info = ADI930 | PREFIRM},
2630 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM), .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A},
2631 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM), .driver_info = ADI930 | PREFIRM},
2632 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM), .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B},
2633 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2634 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2635 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2636 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2637 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
2638 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2639 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
2640 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2645 * USB driver descriptor
2647 static struct usb_driver uea_driver = {
2648 .name = "ueagle-atm",
2649 .id_table = uea_ids,
2651 .disconnect = uea_disconnect,
2654 MODULE_DEVICE_TABLE(usb, uea_ids);
2657 * uea_init - Initialize the module.
2658 * Register to USB subsystem
2660 static int __init uea_init(void)
2662 printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n");
2664 usb_register(&uea_driver);
2669 module_init(uea_init);
2672 * uea_exit - Destroy module
2673 * Deregister with USB subsystem
2675 static void __exit uea_exit(void)
2678 * This calls automatically the uea_disconnect method if necessary:
2680 usb_deregister(&uea_driver);
2682 printk(KERN_INFO "[ueagle-atm] driver unloaded\n");
2685 module_exit(uea_exit);
2687 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2688 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2689 MODULE_LICENSE("Dual BSD/GPL");