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;
156 wait_queue_head_t sync_q;
158 struct task_struct *kthread;
161 wait_queue_head_t cmv_ack_wait;
164 union cmv_dsc cmv_dsc;
166 struct work_struct task;
170 const struct firmware *dsp_firm;
173 void (*dispatch_cmv) (struct uea_softc *, struct intr_pkt *);
174 void (*schedule_load_page) (struct uea_softc *, struct intr_pkt *);
175 int (*stat) (struct uea_softc *);
176 int (*send_cmvs) (struct uea_softc *);
178 /* keep in sync with eaglectl */
206 #define ELSA_VID 0x05CC
207 #define ELSA_PID_PSTFIRM 0x3350
208 #define ELSA_PID_PREFIRM 0x3351
213 #define EAGLE_VID 0x1110
214 #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
215 #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
217 #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
218 #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
220 #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
221 #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
223 #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
224 #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
226 #define EAGLE_IV_PID_PREFIRM 0x9042 /* Eagle IV */
227 #define EAGLE_IV_PID_PSTFIRM 0x9041 /* Eagle IV */
232 #define USR_VID 0x0BAF
233 #define MILLER_A_PID_PREFIRM 0x00F2
234 #define MILLER_A_PID_PSTFIRM 0x00F1
235 #define MILLER_B_PID_PREFIRM 0x00FA
236 #define MILLER_B_PID_PSTFIRM 0x00F9
237 #define HEINEKEN_A_PID_PREFIRM 0x00F6
238 #define HEINEKEN_A_PID_PSTFIRM 0x00F5
239 #define HEINEKEN_B_PID_PREFIRM 0x00F8
240 #define HEINEKEN_B_PID_PSTFIRM 0x00F7
243 #define PSTFIRM (1<<7)
252 /* macros for both struct usb_device_id and struct uea_softc */
253 #define UEA_IS_PREFIRM(x) \
254 (!((x)->driver_info & PSTFIRM))
255 #define UEA_CHIP_VERSION(x) \
256 ((x)->driver_info & 0xf)
258 #define IS_ISDN(usb_dev) \
259 (le16_to_cpu((usb_dev)->descriptor.bcdDevice) & 0x80)
261 #define INS_TO_USBDEV(ins) ins->usb_dev
263 #define GET_STATUS(data) \
266 #define IS_OPERATIONAL(sc) \
267 ((UEA_CHIP_VERSION(sc) != EAGLE_IV) ? \
268 (GET_STATUS(sc->stats.phy.state) == 2) : \
269 (sc->stats.phy.state == 7))
272 * Set of macros to handle unaligned data in the firmware blob.
273 * The FW_GET_BYTE() macro is provided only for consistency.
276 #define FW_GET_BYTE(p) *((__u8 *) (p))
277 #define FW_GET_WORD(p) le16_to_cpu(get_unaligned((__le16 *) (p)))
278 #define FW_GET_LONG(p) le32_to_cpu(get_unaligned((__le32 *) (p)))
280 #define FW_DIR "ueagle-atm/"
283 #define BULK_TIMEOUT 300
284 #define CTRL_TIMEOUT 1000
286 #define ACK_TIMEOUT msecs_to_jiffies(3000)
288 #define UEA_INTR_IFACE_NO 0
289 #define UEA_US_IFACE_NO 1
290 #define UEA_DS_IFACE_NO 2
292 #define FASTEST_ISO_INTF 8
294 #define UEA_BULK_DATA_PIPE 0x02
295 #define UEA_IDMA_PIPE 0x04
296 #define UEA_INTR_PIPE 0x04
297 #define UEA_ISO_DATA_PIPE 0x08
299 #define UEA_E1_SET_BLOCK 0x0001
300 #define UEA_E4_SET_BLOCK 0x002c
301 #define UEA_SET_MODE 0x0003
302 #define UEA_SET_2183_DATA 0x0004
303 #define UEA_SET_TIMEOUT 0x0011
305 #define UEA_LOOPBACK_OFF 0x0002
306 #define UEA_LOOPBACK_ON 0x0003
307 #define UEA_BOOT_IDMA 0x0006
308 #define UEA_START_RESET 0x0007
309 #define UEA_END_RESET 0x0008
311 #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
312 #define UEA_MPTX_START (0x3fce | 0x4000)
313 #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
314 #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
316 /* block information in eagle4 dsp firmware */
325 } __attribute__ ((packed));
327 #define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
328 #define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
330 #define E4_L1_STRING_HEADER 0x10
331 #define E4_MAX_PAGE_NUMBER 0x58
332 #define E4_NO_SWAPPAGE_HEADERS 0x31
334 /* l1_code is eagle4 dsp firmware format */
336 u8 string_header[E4_L1_STRING_HEADER];
337 u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER];
338 struct block_index page_header[E4_NO_SWAPPAGE_HEADERS];
340 } __attribute__ ((packed));
342 /* structures describing a block within a DSP page */
343 struct block_info_e1 {
348 __le16 wOvl; /* overlay */
350 } __attribute__ ((packed));
351 #define E1_BLOCK_INFO_SIZE 12
353 struct block_info_e4 {
360 } __attribute__ ((packed));
361 #define E4_BLOCK_INFO_SIZE 14
363 #define UEA_BIHDR 0xabcd
364 #define UEA_RESERVED 0xffff
366 /* constants describing cmv type */
367 #define E1_PREAMBLE 0x535c
368 #define E1_MODEMTOHOST 0x01
369 #define E1_HOSTTOMODEM 0x10
371 #define E1_MEMACCESS 0x1
372 #define E1_ADSLDIRECTIVE 0x7
373 #define E1_FUNCTION_TYPE(f) ((f) >> 4)
374 #define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f)
376 #define E4_MEMACCESS 0
377 #define E4_ADSLDIRECTIVE 0xf
378 #define E4_FUNCTION_TYPE(f) ((f) >> 8)
379 #define E4_FUNCTION_SIZE(f) ((f) & 0x0f)
380 #define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f)
383 #define E1_REQUESTREAD 0x0
384 #define E1_REQUESTWRITE 0x1
385 #define E1_REPLYREAD 0x2
386 #define E1_REPLYWRITE 0x3
388 #define E4_REQUESTREAD 0x0
389 #define E4_REQUESTWRITE 0x4
390 #define E4_REPLYREAD (E4_REQUESTREAD | 1)
391 #define E4_REPLYWRITE (E4_REQUESTWRITE | 1)
393 /* for ADSLDIRECTIVE */
394 #define E1_KERNELREADY 0x0
395 #define E1_MODEMREADY 0x1
397 #define E4_KERNELREADY 0x0
398 #define E4_MODEMREADY 0x1
400 #define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
401 #define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | ((st) & 0xf) << 4 | ((s) & 0xf))
403 #define E1_MAKESA(a, b, c, d) \
404 (((c) & 0xff) << 24 | \
405 ((d) & 0xff) << 16 | \
406 ((a) & 0xff) << 8 | \
409 #define E1_GETSA1(a) ((a >> 8) & 0xff)
410 #define E1_GETSA2(a) (a & 0xff)
411 #define E1_GETSA3(a) ((a >> 24) & 0xff)
412 #define E1_GETSA4(a) ((a >> 16) & 0xff)
414 #define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L')
415 #define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G')
416 #define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O')
417 #define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N')
418 #define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E')
419 #define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T')
430 /* structures representing a CMV (Configuration and Management Variable) */
436 __le32 dwSymbolicAddress;
437 __le16 wOffsetAddress;
439 } __attribute__ ((packed));
447 } __attribute__ ((packed));
449 /* structures representing swap information */
450 struct swap_info_e1 {
452 __u8 bOvl; /* overlay */
453 } __attribute__ ((packed));
455 struct swap_info_e4 {
457 } __attribute__ ((packed));
459 /* structures representing interrupt data */
460 #define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
461 #define e1_bOvl u.e1.s1.swapinfo.bOvl
462 #define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo
464 #define INT_LOADSWAPPAGE 0x0001
465 #define INT_INCOMINGCMV 0x0002
469 struct swap_info_e1 swapinfo;
471 } __attribute__ ((packed)) s1;
475 } __attribute__ ((packed)) s2;
476 } __attribute__ ((packed));
480 struct swap_info_e4 swapinfo;
482 } __attribute__ ((packed)) s1;
486 } __attribute__ ((packed)) s2;
487 } __attribute__ ((packed));
497 union intr_data_e1 e1;
498 union intr_data_e4 e4;
500 } __attribute__ ((packed));
502 #define E1_INTR_PKT_SIZE 28
503 #define E4_INTR_PKT_SIZE 64
505 static struct usb_driver uea_driver;
506 static DEFINE_MUTEX(uea_mutex);
507 static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
509 static int modem_index;
510 static unsigned int debug;
511 static int use_iso[NB_MODEM] = {[0 ... (NB_MODEM - 1)] = 1};
512 static int sync_wait[NB_MODEM];
513 static char *cmv_file[NB_MODEM];
515 module_param(debug, uint, 0644);
516 MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
517 module_param_array(use_iso, bool, NULL, 0644);
518 MODULE_PARM_DESC(use_iso, "use isochronous usb pipe for incoming traffic");
519 module_param_array(sync_wait, bool, NULL, 0644);
520 MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
521 module_param_array(cmv_file, charp, NULL, 0644);
522 MODULE_PARM_DESC(cmv_file,
523 "file name with configuration and management variables");
525 #define UPDATE_ATM_STAT(type, val) \
527 if (sc->usbatm->atm_dev) \
528 sc->usbatm->atm_dev->type = val; \
531 /* Firmware loading */
532 #define LOAD_INTERNAL 0xA0
533 #define F8051_USBCS 0x7f92
536 * uea_send_modem_cmd - Send a command for pre-firmware devices.
538 static int uea_send_modem_cmd(struct usb_device *usb,
539 u16 addr, u16 size, u8 * buff)
544 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
546 ret = usb_control_msg(usb,
547 usb_sndctrlpipe(usb, 0),
549 USB_DIR_OUT | USB_TYPE_VENDOR |
550 USB_RECIP_DEVICE, addr, 0, xfer_buff,
558 return (ret == size) ? 0 : -EIO;
561 static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *context)
563 struct usb_device *usb = context;
570 uea_err(usb, "firmware is not available\n");
574 pfw = fw_entry->data;
575 size = fw_entry->size;
577 goto err_fw_corrupted;
579 crc = FW_GET_LONG(pfw);
582 if (crc32_be(0, pfw, size) != crc)
583 goto err_fw_corrupted;
586 * Start to upload formware : send reset
589 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
592 uea_err(usb, "modem reset failed with error %d\n", ret);
597 u8 len = FW_GET_BYTE(pfw);
598 u16 add = FW_GET_WORD(pfw + 1);
602 goto err_fw_corrupted;
604 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
606 uea_err(usb, "uploading firmware data failed "
607 "with error %d\n", ret);
614 goto err_fw_corrupted;
617 * Tell the modem we finish : de-assert reset
620 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
622 uea_err(usb, "modem de-assert failed with error %d\n", ret);
624 uea_info(usb, "firmware uploaded\n");
630 uea_err(usb, "firmware is corrupted\n");
636 * uea_load_firmware - Load usb firmware for pre-firmware devices.
638 static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
641 char *fw_name = FW_DIR "eagle.fw";
644 uea_info(usb, "pre-firmware device, uploading firmware\n");
648 fw_name = FW_DIR "adi930.fw";
651 fw_name = FW_DIR "eagleI.fw";
654 fw_name = FW_DIR "eagleII.fw";
657 fw_name = FW_DIR "eagleIII.fw";
660 fw_name = FW_DIR "eagleIV.fw";
664 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware);
666 uea_err(usb, "firmware %s is not available\n", fw_name);
668 uea_info(usb, "loading firmware %s\n", fw_name);
674 /* modem management : dsp firmware, send/read CMV, monitoring statistic
678 * Make sure that the DSP code provided is safe to use.
680 static int check_dsp_e1(u8 *dsp, unsigned int len)
682 u8 pagecount, blockcount;
685 unsigned int i, j, p, pp;
687 pagecount = FW_GET_BYTE(dsp);
690 /* enough space for page offsets? */
691 if (p + 4 * pagecount > len)
694 for (i = 0; i < pagecount; i++) {
696 pageoffset = FW_GET_LONG(dsp + p);
702 /* enough space for blockcount? */
703 if (pageoffset >= len)
707 blockcount = FW_GET_BYTE(dsp + pp);
710 for (j = 0; j < blockcount; j++) {
712 /* enough space for block header? */
716 pp += 2; /* skip blockaddr */
717 blocksize = FW_GET_WORD(dsp + pp);
720 /* enough space for block data? */
721 if (pp + blocksize > len)
731 static int check_dsp_e4(u8 *dsp, int len)
734 struct l1_code *p = (struct l1_code *) dsp;
735 unsigned int sum = p->code - dsp;
740 if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 &&
741 strcmp("STRATIPHY ANEXB", p->string_header) != 0)
744 for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) {
745 struct block_index *blockidx;
746 u8 blockno = p->page_number_to_block_index[i];
747 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
753 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
756 blockidx = &p->page_header[blockno++];
757 if ((u8 *)(blockidx + 1) - dsp >= len)
760 if (le16_to_cpu(blockidx->PageNumber) != i)
763 l = E4_PAGE_BYTES(blockidx->PageSize);
765 l += le32_to_cpu(blockidx->PageOffset);
769 /* zero is zero regardless endianes */
770 } while (blockidx->NotLastBlock);
773 return (sum == len) ? 0 : 1;
777 * send data to the idma pipe
779 static int uea_idma_write(struct uea_softc *sc, void *data, u32 size)
785 xfer_buff = kmemdup(data, size, GFP_KERNEL);
787 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
791 ret = usb_bulk_msg(sc->usb_dev,
792 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
793 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
798 if (size != bytes_read) {
799 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
807 static int request_dsp(struct uea_softc *sc)
812 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
813 if (IS_ISDN(sc->usb_dev))
814 dsp_name = FW_DIR "DSP4i.bin";
816 dsp_name = FW_DIR "DSP4p.bin";
817 } else if (UEA_CHIP_VERSION(sc) == ADI930) {
818 if (IS_ISDN(sc->usb_dev))
819 dsp_name = FW_DIR "DSP9i.bin";
821 dsp_name = FW_DIR "DSP9p.bin";
823 if (IS_ISDN(sc->usb_dev))
824 dsp_name = FW_DIR "DSPei.bin";
826 dsp_name = FW_DIR "DSPep.bin";
829 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
831 uea_err(INS_TO_USBDEV(sc),
832 "requesting firmware %s failed with error %d\n",
837 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
838 ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size);
840 ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size);
843 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
845 release_firmware(sc->dsp_firm);
854 * The uea_load_page() function must be called within a process context
856 static void uea_load_page_e1(struct work_struct *work)
858 struct uea_softc *sc = container_of(work, struct uea_softc, task);
859 u16 pageno = sc->pageno;
861 struct block_info_e1 bi;
864 u8 pagecount, blockcount;
865 u16 blockaddr, blocksize;
869 /* reload firmware when reboot start and it's loaded already */
870 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
871 release_firmware(sc->dsp_firm);
875 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
878 p = sc->dsp_firm->data;
879 pagecount = FW_GET_BYTE(p);
882 if (pageno >= pagecount)
886 pageoffset = FW_GET_LONG(p);
891 p = sc->dsp_firm->data + pageoffset;
892 blockcount = FW_GET_BYTE(p);
895 uea_dbg(INS_TO_USBDEV(sc),
896 "sending %u blocks for DSP page %u\n", blockcount, pageno);
898 bi.wHdr = cpu_to_le16(UEA_BIHDR);
899 bi.wOvl = cpu_to_le16(ovl);
900 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
902 for (i = 0; i < blockcount; i++) {
903 blockaddr = FW_GET_WORD(p);
906 blocksize = FW_GET_WORD(p);
909 bi.wSize = cpu_to_le16(blocksize);
910 bi.wAddress = cpu_to_le16(blockaddr);
911 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
913 /* send block info through the IDMA pipe */
914 if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE))
917 /* send block data through the IDMA pipe */
918 if (uea_idma_write(sc, p, blocksize))
927 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
930 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
933 static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
935 struct block_info_e4 bi;
936 struct block_index *blockidx;
937 struct l1_code *p = (struct l1_code *) sc->dsp_firm->data;
938 u8 blockno = p->page_number_to_block_index[pageno];
940 bi.wHdr = cpu_to_be16(UEA_BIHDR);
942 bi.bPageNumber = pageno;
943 bi.wReserved = cpu_to_be16(UEA_RESERVED);
947 unsigned int blocksize;
949 blockidx = &p->page_header[blockno];
950 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
951 blockoffset = sc->dsp_firm->data + le32_to_cpu(blockidx->PageOffset);
953 bi.dwSize = cpu_to_be32(blocksize);
954 bi.dwAddress = swab32(blockidx->PageAddress);
956 uea_dbg(INS_TO_USBDEV(sc),
957 "sending block %u for DSP page %u size %u adress %x\n",
958 blockno, pageno, blocksize, le32_to_cpu(blockidx->PageAddress));
960 /* send block info through the IDMA pipe */
961 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
964 /* send block data through the IDMA pipe */
965 if (uea_idma_write(sc, blockoffset, blocksize))
969 } while (blockidx->NotLastBlock);
974 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno);
978 static void uea_load_page_e4(struct work_struct *work)
980 struct uea_softc *sc = container_of(work, struct uea_softc, task);
981 u8 pageno = sc->pageno;
983 struct block_info_e4 bi;
986 uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
988 /* reload firmware when reboot start and it's loaded already */
989 if (pageno == 0 && sc->dsp_firm) {
990 release_firmware(sc->dsp_firm);
994 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
997 p = (struct l1_code *) sc->dsp_firm->data;
998 if (pageno >= p->page_header[0].PageNumber) {
999 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
1004 __uea_load_page_e4(sc, pageno, 0);
1008 uea_dbg(INS_TO_USBDEV(sc),
1009 "sending Main DSP page %u\n", p->page_header[0].PageNumber);
1011 for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) {
1012 if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize))
1013 __uea_load_page_e4(sc, i, 1);
1016 uea_dbg(INS_TO_USBDEV(sc),"sending start bi\n");
1018 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1020 bi.bPageNumber = 0xff;
1021 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1022 bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize));
1023 bi.dwAddress = swab32(p->page_header[0].PageAddress);
1025 /* send block info through the IDMA pipe */
1026 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1027 uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n");
1030 static inline void wake_up_cmv_ack(struct uea_softc *sc)
1032 BUG_ON(sc->cmv_ack);
1034 wake_up(&sc->cmv_ack_wait);
1037 static inline int wait_cmv_ack(struct uea_softc *sc)
1039 int ret = wait_event_interruptible_timeout(sc->cmv_ack_wait,
1040 sc->cmv_ack, ACK_TIMEOUT);
1043 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
1044 jiffies_to_msecs(ret));
1049 return (ret == 0) ? -ETIMEDOUT : 0;
1052 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1054 static int uea_request(struct uea_softc *sc,
1055 u16 value, u16 index, u16 size, void *data)
1060 xfer_buff = kmemdup(data, size, GFP_KERNEL);
1062 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
1066 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
1067 UCDC_SEND_ENCAPSULATED_COMMAND,
1068 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1069 value, index, xfer_buff, size, CTRL_TIMEOUT);
1073 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
1078 uea_err(INS_TO_USBDEV(sc),
1079 "usb_control_msg send only %d bytes (instead of %d)\n",
1087 static int uea_cmv_e1(struct uea_softc *sc,
1088 u8 function, u32 address, u16 offset, u32 data)
1093 uea_enters(INS_TO_USBDEV(sc));
1094 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1095 "offset : 0x%04x, data : 0x%08x\n",
1096 E1_FUNCTION_TYPE(function), E1_FUNCTION_SUBTYPE(function),
1097 E1_GETSA1(address), E1_GETSA2(address), E1_GETSA3(address),
1098 E1_GETSA4(address), offset, data);
1100 /* we send a request, but we expect a reply */
1101 sc->cmv_dsc.e1.function = function | 0x2;
1102 sc->cmv_dsc.e1.idx++;
1103 sc->cmv_dsc.e1.address = address;
1104 sc->cmv_dsc.e1.offset = offset;
1106 cmv.wPreamble = cpu_to_le16(E1_PREAMBLE);
1107 cmv.bDirection = E1_HOSTTOMODEM;
1108 cmv.bFunction = function;
1109 cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx);
1110 put_unaligned(cpu_to_le32(address), &cmv.dwSymbolicAddress);
1111 cmv.wOffsetAddress = cpu_to_le16(offset);
1112 put_unaligned(cpu_to_le32(data >> 16 | data << 16), &cmv.dwData);
1114 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv);
1117 ret = wait_cmv_ack(sc);
1118 uea_leaves(INS_TO_USBDEV(sc));
1122 static int uea_cmv_e4(struct uea_softc *sc,
1123 u16 function, u16 group, u16 address, u16 offset, u32 data)
1128 uea_enters(INS_TO_USBDEV(sc));
1129 memset(&cmv, 0, sizeof(cmv));
1131 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
1132 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1133 E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function),
1134 group, address, offset, data);
1136 /* we send a request, but we expect a reply */
1137 sc->cmv_dsc.e4.function = function | (0x1 << 4);
1138 sc->cmv_dsc.e4.offset = offset;
1139 sc->cmv_dsc.e4.address = address;
1140 sc->cmv_dsc.e4.group = group;
1142 cmv.wFunction = cpu_to_be16(function);
1143 cmv.wGroup = cpu_to_be16(group);
1144 cmv.wAddress = cpu_to_be16(address);
1145 cmv.wOffset = cpu_to_be16(offset);
1146 cmv.dwData[0] = cpu_to_be32(data);
1148 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv);
1151 ret = wait_cmv_ack(sc);
1152 uea_leaves(INS_TO_USBDEV(sc));
1156 static inline int uea_read_cmv_e1(struct uea_softc *sc,
1157 u32 address, u16 offset, u32 *data)
1159 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD),
1160 address, offset, 0);
1162 uea_err(INS_TO_USBDEV(sc),
1163 "reading cmv failed with error %d\n", ret);
1170 static inline int uea_read_cmv_e4(struct uea_softc *sc,
1171 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1173 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTREAD, size),
1174 group, address, offset, 0);
1176 uea_err(INS_TO_USBDEV(sc),
1177 "reading cmv failed with error %d\n", ret);
1180 /* size is in 16-bit word quantities */
1182 *(data + 1) = sc->data1;
1187 static inline int uea_write_cmv_e1(struct uea_softc *sc,
1188 u32 address, u16 offset, u32 data)
1190 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE),
1191 address, offset, data);
1193 uea_err(INS_TO_USBDEV(sc),
1194 "writing cmv failed with error %d\n", ret);
1199 static inline int uea_write_cmv_e4(struct uea_softc *sc,
1200 u8 size, u16 group, u16 address, u16 offset, u32 data)
1202 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTWRITE, size),
1203 group, address, offset, data);
1205 uea_err(INS_TO_USBDEV(sc),
1206 "writing cmv failed with error %d\n", ret);
1211 static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1216 /* in bulk mode the modem have problem with high rate
1217 * changing internal timing could improve things, but the
1218 * value is misterious.
1219 * ADI930 don't support it (-EPIPE error).
1222 if (UEA_CHIP_VERSION(sc) == ADI930 ||
1223 use_iso[sc->modem_index] > 0 ||
1224 sc->stats.phy.dsrate == dsrate)
1227 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1228 timeout = (dsrate <= 1024*1024) ? 0 : 1;
1229 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
1230 uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n",
1231 timeout, ret < 0 ? " failed" : "");
1236 * Monitor the modem and update the stat
1237 * return 0 if everything is ok
1238 * return < 0 if an error occurs (-EAGAIN reboot needed)
1240 static int uea_stat_e1(struct uea_softc *sc)
1245 uea_enters(INS_TO_USBDEV(sc));
1246 data = sc->stats.phy.state;
1248 ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state);
1252 switch (GET_STATUS(sc->stats.phy.state)) {
1253 case 0: /* not yet synchronized */
1254 uea_dbg(INS_TO_USBDEV(sc),
1255 "modem not yet synchronized\n");
1258 case 1: /* initialization */
1259 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1262 case 2: /* operational */
1263 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
1266 case 3: /* fail ... */
1267 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1268 " (may be try other cmv/dsp)\n");
1271 case 4 ... 6: /* test state */
1272 uea_warn(INS_TO_USBDEV(sc),
1273 "modem in test mode - not supported\n");
1276 case 7: /* fast-retain ... */
1277 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
1280 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
1281 GET_STATUS(sc->stats.phy.state));
1285 if (GET_STATUS(data) != 2) {
1286 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1287 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1289 /* release the dsp firmware as it is not needed until
1293 release_firmware(sc->dsp_firm);
1294 sc->dsp_firm = NULL;
1298 /* always update it as atm layer could not be init when we switch to
1301 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1303 /* wake up processes waiting for synchronization */
1304 wake_up(&sc->sync_q);
1306 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags);
1309 sc->stats.phy.mflags |= sc->stats.phy.flags;
1311 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1312 * we check the status again in order to detect the failure earlier
1314 if (sc->stats.phy.flags) {
1315 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1316 sc->stats.phy.flags);
1320 ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data);
1324 uea_set_bulk_timeout(sc, (data >> 16) * 32);
1325 sc->stats.phy.dsrate = (data >> 16) * 32;
1326 sc->stats.phy.usrate = (data & 0xffff) * 32;
1327 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1329 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data);
1332 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
1334 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data);
1337 sc->stats.phy.usattenuation = (data & 0xff) / 2;
1339 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin);
1343 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin);
1347 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow);
1351 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow);
1355 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc);
1359 /* only for atu-c */
1360 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc);
1364 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr);
1368 /* only for atu-c */
1369 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr);
1373 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 8, &sc->stats.phy.vidco);
1377 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 13, &sc->stats.phy.vidcpe);
1384 static int uea_stat_e4(struct uea_softc *sc)
1390 uea_enters(INS_TO_USBDEV(sc));
1391 data = sc->stats.phy.state;
1393 /* XXX only need to be done before operationnal... */
1394 ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state);
1398 switch (sc->stats.phy.state) {
1399 case 0x0: /* not yet synchronized */
1403 uea_dbg(INS_TO_USBDEV(sc), "modem not yet synchronized\n");
1405 case 0x5: /* initialization */
1409 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1411 case 0x2: /* fail ... */
1412 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1413 " (may be try other cmv/dsp)\n");
1415 case 0x7: /* operational */
1418 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n", sc->stats.phy.state);
1423 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1424 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1426 /* release the dsp firmware as it is not needed until
1430 release_firmware(sc->dsp_firm);
1431 sc->dsp_firm = NULL;
1435 /* always update it as atm layer could not be init when we switch to
1438 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1440 /* wake up processes waiting for synchronization */
1441 wake_up(&sc->sync_q);
1443 /* TODO improve this state machine :
1444 * we need some CMV info : what they do and their unit
1445 * we should find the equivalent of eagle3- CMV
1448 ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags);
1451 sc->stats.phy.mflags |= sc->stats.phy.flags;
1453 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1454 * we check the status again in order to detect the failure earlier
1456 if (sc->stats.phy.flags) {
1457 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1458 sc->stats.phy.flags);
1459 if (sc->stats.phy.flags & 1) //delineation LOSS
1461 if (sc->stats.phy.flags & 0x4000) //Reset Flag
1466 /* rate data may be in upper or lower half of 64 bit word, strange */
1467 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr);
1470 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1471 sc->stats.phy.usrate = data / 1000;
1473 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr);
1476 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1477 uea_set_bulk_timeout(sc, data / 1000);
1478 sc->stats.phy.dsrate = data / 1000;
1479 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1481 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data);
1484 sc->stats.phy.dsattenuation = data / 10;
1486 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data);
1489 sc->stats.phy.usattenuation = data / 10;
1491 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data);
1494 sc->stats.phy.dsmargin = data / 2;
1496 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data);
1499 sc->stats.phy.usmargin = data / 10;
1504 static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1506 char file_arr[] = "CMVxy.bin";
1509 /* set proper name corresponding modem version and line type */
1510 if (cmv_file[sc->modem_index] == NULL) {
1511 if (UEA_CHIP_VERSION(sc) == ADI930)
1513 else if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1518 file_arr[4] = IS_ISDN(sc->usb_dev) ? 'i' : 'p';
1521 file = cmv_file[sc->modem_index];
1523 strcpy(cmv_name, FW_DIR);
1524 strlcat(cmv_name, file, FIRMWARE_NAME_MAX);
1526 strlcat(cmv_name, ".v2", FIRMWARE_NAME_MAX);
1529 static int request_cmvs_old(struct uea_softc *sc,
1530 void **cmvs, const struct firmware **fw)
1534 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1536 cmvs_file_name(sc, cmv_name, 1);
1537 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1539 uea_err(INS_TO_USBDEV(sc),
1540 "requesting firmware %s failed with error %d\n",
1545 data = (u8 *) (*fw)->data;
1548 goto err_fw_corrupted;
1550 if (size != *data * sizeof(struct uea_cmvs_v1) + 1)
1551 goto err_fw_corrupted;
1553 *cmvs = (void *)(data + 1);
1557 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1558 release_firmware(*fw);
1562 static int request_cmvs(struct uea_softc *sc,
1563 void **cmvs, const struct firmware **fw, int *ver)
1568 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1570 cmvs_file_name(sc, cmv_name, 2);
1571 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1573 /* if caller can handle old version, try to provide it */
1575 uea_warn(INS_TO_USBDEV(sc), "requesting firmware %s failed, "
1576 "try to get older cmvs\n", cmv_name);
1577 return request_cmvs_old(sc, cmvs, fw);
1579 uea_err(INS_TO_USBDEV(sc),
1580 "requesting firmware %s failed with error %d\n",
1586 data = (u8 *) (*fw)->data;
1587 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1589 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted, "
1590 "try to get older cmvs\n", cmv_name);
1591 release_firmware(*fw);
1592 return request_cmvs_old(sc, cmvs, fw);
1594 goto err_fw_corrupted;
1602 goto err_fw_corrupted;
1604 crc = FW_GET_LONG(data);
1607 if (crc32_be(0, data, size) != crc)
1608 goto err_fw_corrupted;
1610 if (size != *data * sizeof(struct uea_cmvs_v2) + 1)
1611 goto err_fw_corrupted;
1613 *cmvs = (void *) (data + 1);
1617 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1618 release_firmware(*fw);
1622 static int uea_send_cmvs_e1(struct uea_softc *sc)
1626 const struct firmware *cmvs_fw;
1627 int ver = 1; // we can handle v1 cmv firmware version;
1629 /* Enter in R-IDLE (cmv) until instructed otherwise */
1630 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
1634 /* Dump firmware version */
1635 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid);
1638 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1639 sc->stats.phy.firmid);
1642 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1648 struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr;
1650 uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, "
1651 "please update your firmware\n");
1653 for (i = 0; i < len; i++) {
1654 ret = uea_write_cmv_e1(sc, FW_GET_LONG(&cmvs_v1[i].address),
1655 FW_GET_WORD(&cmvs_v1[i].offset),
1656 FW_GET_LONG(&cmvs_v1[i].data));
1660 } else if (ver == 2) {
1661 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1663 for (i = 0; i < len; i++) {
1664 ret = uea_write_cmv_e1(sc, FW_GET_LONG(&cmvs_v2[i].address),
1665 (u16) FW_GET_LONG(&cmvs_v2[i].offset),
1666 FW_GET_LONG(&cmvs_v2[i].data));
1671 /* This realy should not happen */
1672 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1676 /* Enter in R-ACT-REQ */
1677 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1678 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1679 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n");
1681 release_firmware(cmvs_fw);
1685 static int uea_send_cmvs_e4(struct uea_softc *sc)
1689 const struct firmware *cmvs_fw;
1690 int ver = 2; // we can only handle v2 cmv firmware version;
1692 /* Enter in R-IDLE (cmv) until instructed otherwise */
1693 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
1697 /* Dump firmware version */
1698 /* XXX don't read the 3th byte as it is always 6 */
1699 ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid);
1702 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1703 sc->stats.phy.firmid);
1707 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1713 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1715 for (i = 0; i < len; i++) {
1716 ret = uea_write_cmv_e4(sc, 1,
1717 FW_GET_LONG(&cmvs_v2[i].group),
1718 FW_GET_LONG(&cmvs_v2[i].address),
1719 FW_GET_LONG(&cmvs_v2[i].offset),
1720 FW_GET_LONG(&cmvs_v2[i].data));
1725 /* This realy should not happen */
1726 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1730 /* Enter in R-ACT-REQ */
1731 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1732 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1733 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n");
1735 release_firmware(cmvs_fw);
1739 /* Start boot post firmware modem:
1740 * - send reset commands through usb control pipe
1741 * - start workqueue for DSP loading
1742 * - send CMV options to modem
1745 static int uea_start_reset(struct uea_softc *sc)
1747 u16 zero = 0; /* ;-) */
1750 uea_enters(INS_TO_USBDEV(sc));
1751 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1753 /* mask interrupt */
1755 /* We need to set this here because, a ack timeout could have occured,
1756 * but before we start the reboot, the ack occurs and set this to 1.
1757 * So we will failed to wait Ready CMV.
1760 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST);
1762 /* reset statistics */
1763 memset(&sc->stats, 0, sizeof(struct uea_stats));
1765 /* tell the modem that we want to boot in IDMA mode */
1766 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1767 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1769 /* enter reset mode */
1770 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1772 /* original driver use 200ms, but windows driver use 100ms */
1775 /* leave reset mode */
1776 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1778 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
1779 /* clear tx and rx mailboxes */
1780 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1781 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1782 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1787 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1788 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1);
1790 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY);
1792 /* demask interrupt */
1795 /* start loading DSP */
1798 schedule_work(&sc->task);
1800 /* wait for modem ready CMV */
1801 ret = wait_cmv_ack(sc);
1805 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1807 ret = sc->send_cmvs(sc);
1812 uea_leaves(INS_TO_USBDEV(sc));
1817 * In case of an error wait 1s before rebooting the modem
1818 * if the modem don't request reboot (-EAGAIN).
1819 * Monitor the modem every 1s.
1822 static int uea_kthread(void *data)
1824 struct uea_softc *sc = data;
1828 uea_enters(INS_TO_USBDEV(sc));
1829 while (!kthread_should_stop()) {
1830 if (ret < 0 || sc->reset)
1831 ret = uea_start_reset(sc);
1835 msleep_interruptible(1000);
1836 if (try_to_freeze())
1837 uea_err(INS_TO_USBDEV(sc), "suspend/resume not supported, "
1838 "please unplug/replug your modem\n");
1840 uea_leaves(INS_TO_USBDEV(sc));
1844 /* Load second usb firmware for ADI930 chip */
1845 static int load_XILINX_firmware(struct uea_softc *sc)
1847 const struct firmware *fw_entry;
1848 int ret, size, u, ln;
1850 char *fw_name = FW_DIR "930-fpga.bin";
1852 uea_enters(INS_TO_USBDEV(sc));
1854 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1856 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1861 pfw = fw_entry->data;
1862 size = fw_entry->size;
1863 if (size != 0x577B) {
1864 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1869 for (u = 0; u < size; u += ln) {
1870 ln = min(size - u, 64);
1871 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1873 uea_err(INS_TO_USBDEV(sc),
1874 "elsa download data failed (%d)\n", ret);
1879 /* finish to send the fpga */
1880 ret = uea_request(sc, 0xe, 1, 0, NULL);
1882 uea_err(INS_TO_USBDEV(sc),
1883 "elsa download data failed (%d)\n", ret);
1887 /* Tell the modem we finish : de-assert reset */
1889 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1891 uea_err(sc->usb_dev, "elsa de-assert failed with error %d\n", ret);
1894 release_firmware(fw_entry);
1896 uea_leaves(INS_TO_USBDEV(sc));
1900 /* The modem send us an ack. First with check if it right */
1901 static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
1903 struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;
1904 struct cmv_e1 *cmv = &intr->u.e1.s2.cmv;
1906 uea_enters(INS_TO_USBDEV(sc));
1907 if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE)
1910 if (cmv->bDirection != E1_MODEMTOHOST)
1913 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1914 * the first MEMACESS cmv. Ignore it...
1916 if (cmv->bFunction != dsc->function) {
1917 if (UEA_CHIP_VERSION(sc) == ADI930
1918 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
1919 cmv->wIndex = cpu_to_le16(dsc->idx);
1920 put_unaligned(cpu_to_le32(dsc->address), &cmv->dwSymbolicAddress);
1921 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
1926 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY)) {
1927 wake_up_cmv_ack(sc);
1928 uea_leaves(INS_TO_USBDEV(sc));
1932 /* in case of MEMACCESS */
1933 if (le16_to_cpu(cmv->wIndex) != dsc->idx ||
1934 le32_to_cpu(get_unaligned(&cmv->dwSymbolicAddress)) != dsc->address ||
1935 le16_to_cpu(cmv->wOffsetAddress) != dsc->offset)
1938 sc->data = le32_to_cpu(get_unaligned(&cmv->dwData));
1939 sc->data = sc->data << 16 | sc->data >> 16;
1941 wake_up_cmv_ack(sc);
1942 uea_leaves(INS_TO_USBDEV(sc));
1946 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
1947 "Function : %d, Subfunction : %d\n",
1948 E1_FUNCTION_TYPE(cmv->bFunction),
1949 E1_FUNCTION_SUBTYPE(cmv->bFunction));
1950 uea_leaves(INS_TO_USBDEV(sc));
1954 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
1955 "wPreamble %d, bDirection %d\n",
1956 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
1957 uea_leaves(INS_TO_USBDEV(sc));
1960 /* The modem send us an ack. First with check if it right */
1961 static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
1963 struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;
1964 struct cmv_e4 *cmv = &intr->u.e4.s2.cmv;
1966 uea_enters(INS_TO_USBDEV(sc));
1967 uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n",
1968 be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction),
1969 be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
1970 be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1]));
1972 if (be16_to_cpu(cmv->wFunction) != dsc->function)
1975 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1)) {
1976 wake_up_cmv_ack(sc);
1977 uea_leaves(INS_TO_USBDEV(sc));
1981 /* in case of MEMACCESS */
1982 if (be16_to_cpu(cmv->wOffset) != dsc->offset ||
1983 be16_to_cpu(cmv->wGroup) != dsc->group ||
1984 be16_to_cpu(cmv->wAddress) != dsc->address)
1987 sc->data = be32_to_cpu(cmv->dwData[0]);
1988 sc->data1 = be32_to_cpu(cmv->dwData[1]);
1989 wake_up_cmv_ack(sc);
1990 uea_leaves(INS_TO_USBDEV(sc));
1994 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
1995 "Function : %d, Subfunction : %d\n",
1996 E4_FUNCTION_TYPE(cmv->wFunction),
1997 E4_FUNCTION_SUBTYPE(cmv->wFunction));
1998 uea_leaves(INS_TO_USBDEV(sc));
2002 static void uea_schedule_load_page_e1(struct uea_softc *sc, struct intr_pkt *intr)
2004 sc->pageno = intr->e1_bSwapPageNo;
2005 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
2006 schedule_work(&sc->task);
2009 static void uea_schedule_load_page_e4(struct uea_softc *sc, struct intr_pkt *intr)
2011 sc->pageno = intr->e4_bSwapPageNo;
2012 schedule_work(&sc->task);
2018 static void uea_intr(struct urb *urb)
2020 struct uea_softc *sc = urb->context;
2021 struct intr_pkt *intr = urb->transfer_buffer;
2022 int status = urb->status;
2024 uea_enters(INS_TO_USBDEV(sc));
2026 if (unlikely(status < 0)) {
2027 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
2032 /* device-to-host interrupt */
2033 if (intr->bType != 0x08 || sc->booting) {
2034 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
2038 switch (le16_to_cpu(intr->wInterrupt)) {
2039 case INT_LOADSWAPPAGE:
2040 sc->schedule_load_page(sc, intr);
2043 case INT_INCOMINGCMV:
2044 sc->dispatch_cmv(sc, intr);
2048 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
2049 le16_to_cpu(intr->wInterrupt));
2053 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
2057 * Start the modem : init the data and start kernel thread
2059 static int uea_boot(struct uea_softc *sc)
2062 struct intr_pkt *intr;
2064 uea_enters(INS_TO_USBDEV(sc));
2066 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2067 size = E4_INTR_PKT_SIZE;
2068 sc->dispatch_cmv = uea_dispatch_cmv_e4;
2069 sc->schedule_load_page = uea_schedule_load_page_e4;
2070 sc->stat = uea_stat_e4;
2071 sc->send_cmvs = uea_send_cmvs_e4;
2072 INIT_WORK(&sc->task, uea_load_page_e4);
2074 size = E1_INTR_PKT_SIZE;
2075 sc->dispatch_cmv = uea_dispatch_cmv_e1;
2076 sc->schedule_load_page = uea_schedule_load_page_e1;
2077 sc->stat = uea_stat_e1;
2078 sc->send_cmvs = uea_send_cmvs_e1;
2079 INIT_WORK(&sc->task, uea_load_page_e1);
2082 init_waitqueue_head(&sc->sync_q);
2083 init_waitqueue_head(&sc->cmv_ack_wait);
2085 if (UEA_CHIP_VERSION(sc) == ADI930)
2086 load_XILINX_firmware(sc);
2088 intr = kmalloc(size, GFP_KERNEL);
2090 uea_err(INS_TO_USBDEV(sc),
2091 "cannot allocate interrupt package\n");
2092 uea_leaves(INS_TO_USBDEV(sc));
2096 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
2098 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
2102 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
2103 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
2104 intr, size, uea_intr, sc,
2105 sc->usb_dev->actconfig->interface[0]->altsetting[0].
2106 endpoint[0].desc.bInterval);
2108 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2110 uea_err(INS_TO_USBDEV(sc),
2111 "urb submition failed with error %d\n", ret);
2115 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm");
2116 if (sc->kthread == ERR_PTR(-ENOMEM)) {
2117 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2121 uea_leaves(INS_TO_USBDEV(sc));
2125 usb_kill_urb(sc->urb_int);
2127 usb_free_urb(sc->urb_int);
2130 uea_leaves(INS_TO_USBDEV(sc));
2135 * Stop the modem : kill kernel thread and free data
2137 static void uea_stop(struct uea_softc *sc)
2140 uea_enters(INS_TO_USBDEV(sc));
2141 ret = kthread_stop(sc->kthread);
2142 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
2144 /* stop any pending boot process */
2145 flush_scheduled_work();
2147 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
2149 usb_kill_urb(sc->urb_int);
2150 kfree(sc->urb_int->transfer_buffer);
2151 usb_free_urb(sc->urb_int);
2154 release_firmware(sc->dsp_firm);
2155 uea_leaves(INS_TO_USBDEV(sc));
2158 /* syfs interface */
2159 static struct uea_softc *dev_to_uea(struct device *dev)
2161 struct usb_interface *intf;
2162 struct usbatm_data *usbatm;
2164 intf = to_usb_interface(dev);
2168 usbatm = usb_get_intfdata(intf);
2172 return usbatm->driver_data;
2175 static ssize_t read_status(struct device *dev, struct device_attribute *attr,
2179 struct uea_softc *sc;
2181 mutex_lock(&uea_mutex);
2182 sc = dev_to_uea(dev);
2185 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
2187 mutex_unlock(&uea_mutex);
2191 static ssize_t reboot(struct device *dev, struct device_attribute *attr,
2192 const char *buf, size_t count)
2195 struct uea_softc *sc;
2197 mutex_lock(&uea_mutex);
2198 sc = dev_to_uea(dev);
2204 mutex_unlock(&uea_mutex);
2208 static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot);
2210 static ssize_t read_human_status(struct device *dev, struct device_attribute *attr,
2215 struct uea_softc *sc;
2217 mutex_lock(&uea_mutex);
2218 sc = dev_to_uea(dev);
2222 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2223 switch (sc->stats.phy.state) {
2224 case 0x0: /* not yet synchronized */
2230 case 0x5: /* initialization */
2236 case 0x7: /* operational */
2239 case 0x2: /* fail ... */
2242 default: /* unknown */
2247 modem_state = GET_STATUS(sc->stats.phy.state);
2249 switch (modem_state) {
2251 ret = sprintf(buf, "Modem is booting\n");
2254 ret = sprintf(buf, "Modem is initializing\n");
2257 ret = sprintf(buf, "Modem is operational\n");
2260 ret = sprintf(buf, "Modem synchronization failed\n");
2263 ret = sprintf(buf, "Modem state is unknown\n");
2267 mutex_unlock(&uea_mutex);
2271 static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, read_human_status, NULL);
2273 static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2277 struct uea_softc *sc;
2278 char *delin = "GOOD";
2280 mutex_lock(&uea_mutex);
2281 sc = dev_to_uea(dev);
2285 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2286 if (sc->stats.phy.flags & 0x4000)
2288 else if (sc->stats.phy.flags & 0x0001)
2291 if (sc->stats.phy.flags & 0x0C00)
2293 else if (sc->stats.phy.flags & 0x0030)
2297 ret = sprintf(buf, "%s\n", delin);
2299 mutex_unlock(&uea_mutex);
2303 static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL);
2305 #define UEA_ATTR(name, reset) \
2307 static ssize_t read_##name(struct device *dev, \
2308 struct device_attribute *attr, char *buf) \
2310 int ret = -ENODEV; \
2311 struct uea_softc *sc; \
2313 mutex_lock(&uea_mutex); \
2314 sc = dev_to_uea(dev); \
2317 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2319 sc->stats.phy.name = 0; \
2321 mutex_unlock(&uea_mutex); \
2325 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2327 UEA_ATTR(mflags, 1);
2328 UEA_ATTR(vidcpe, 0);
2329 UEA_ATTR(usrate, 0);
2330 UEA_ATTR(dsrate, 0);
2331 UEA_ATTR(usattenuation, 0);
2332 UEA_ATTR(dsattenuation, 0);
2333 UEA_ATTR(usmargin, 0);
2334 UEA_ATTR(dsmargin, 0);
2335 UEA_ATTR(txflow, 0);
2336 UEA_ATTR(rxflow, 0);
2337 UEA_ATTR(uscorr, 0);
2338 UEA_ATTR(dscorr, 0);
2341 UEA_ATTR(firmid, 0);
2343 /* Retrieve the device End System Identifier (MAC) */
2345 #define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
2346 static int uea_getesi(struct uea_softc *sc, u_char * esi)
2348 unsigned char mac_str[2 * ETH_ALEN + 1];
2351 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
2352 sizeof(mac_str)) != 2 * ETH_ALEN)
2355 for (i = 0; i < ETH_ALEN; i++)
2356 esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]);
2362 static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
2364 struct uea_softc *sc = usbatm->driver_data;
2366 return uea_getesi(sc, atm_dev->esi);
2369 static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
2371 struct uea_softc *sc = usbatm->driver_data;
2373 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
2379 static int claim_interface(struct usb_device *usb_dev,
2380 struct usbatm_data *usbatm, int ifnum)
2383 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
2386 uea_err(usb_dev, "interface %d not found\n", ifnum);
2390 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
2392 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
2397 static struct attribute *attrs[] = {
2398 &dev_attr_stat_status.attr,
2399 &dev_attr_stat_mflags.attr,
2400 &dev_attr_stat_human_status.attr,
2401 &dev_attr_stat_delin.attr,
2402 &dev_attr_stat_vidcpe.attr,
2403 &dev_attr_stat_usrate.attr,
2404 &dev_attr_stat_dsrate.attr,
2405 &dev_attr_stat_usattenuation.attr,
2406 &dev_attr_stat_dsattenuation.attr,
2407 &dev_attr_stat_usmargin.attr,
2408 &dev_attr_stat_dsmargin.attr,
2409 &dev_attr_stat_txflow.attr,
2410 &dev_attr_stat_rxflow.attr,
2411 &dev_attr_stat_uscorr.attr,
2412 &dev_attr_stat_dscorr.attr,
2413 &dev_attr_stat_usunc.attr,
2414 &dev_attr_stat_dsunc.attr,
2415 &dev_attr_stat_firmid.attr,
2418 static struct attribute_group attr_grp = {
2422 static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
2423 const struct usb_device_id *id)
2425 struct usb_device *usb = interface_to_usbdev(intf);
2426 struct uea_softc *sc;
2427 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
2431 /* interface 0 is for firmware/monitoring */
2432 if (ifnum != UEA_INTR_IFACE_NO)
2435 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
2437 /* interface 1 is for outbound traffic */
2438 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
2442 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
2443 if (UEA_CHIP_VERSION(id) != ADI930) {
2444 /* interface 2 is for inbound traffic */
2445 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
2450 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
2452 uea_err(usb, "uea_init: not enough memory !\n");
2457 usbatm->driver_data = sc;
2458 sc->usbatm = usbatm;
2459 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
2460 sc->driver_info = id->driver_info;
2462 /* ADI930 don't support iso */
2463 if (UEA_CHIP_VERSION(id) != ADI930 && use_iso[sc->modem_index]) {
2466 /* try set fastest alternate for inbound traffic interface */
2467 for (i = FASTEST_ISO_INTF; i > 0; i--)
2468 if (usb_set_interface(usb, UEA_DS_IFACE_NO, i) == 0)
2472 uea_dbg(usb, "set alternate %d for 2 interface\n", i);
2473 uea_info(usb, "using iso mode\n");
2474 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
2476 uea_err(usb, "setting any alternate failed for "
2477 "2 interface, using bulk mode\n");
2481 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
2492 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2498 static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
2500 struct uea_softc *sc = usbatm->driver_data;
2502 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2507 static struct usbatm_driver uea_usbatm_driver = {
2508 .driver_name = "ueagle-atm",
2510 .atm_start = uea_atm_open,
2511 .unbind = uea_unbind,
2512 .heavy_init = uea_heavy,
2513 .bulk_in = UEA_BULK_DATA_PIPE,
2514 .bulk_out = UEA_BULK_DATA_PIPE,
2515 .isoc_in = UEA_ISO_DATA_PIPE,
2518 static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2520 struct usb_device *usb = interface_to_usbdev(intf);
2523 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) : %s %s\n",
2524 le16_to_cpu(usb->descriptor.idVendor),
2525 le16_to_cpu(usb->descriptor.idProduct),
2526 chip_name[UEA_CHIP_VERSION(id)], IS_ISDN(usb)?"isdn":"pots");
2528 usb_reset_device(usb);
2530 if (UEA_IS_PREFIRM(id))
2531 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2533 return usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2536 static void uea_disconnect(struct usb_interface *intf)
2538 struct usb_device *usb = interface_to_usbdev(intf);
2539 int ifnum = intf->altsetting->desc.bInterfaceNumber;
2542 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2543 * Pre-firmware device has one interface
2545 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
2546 mutex_lock(&uea_mutex);
2547 usbatm_usb_disconnect(intf);
2548 mutex_unlock(&uea_mutex);
2549 uea_info(usb, "ADSL device removed\n");
2556 * List of supported VID/PID
2558 static const struct usb_device_id uea_ids[] = {
2559 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
2560 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
2561 {USB_DEVICE(EAGLE_VID, EAGLE_I_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2562 {USB_DEVICE(EAGLE_VID, EAGLE_I_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
2563 {USB_DEVICE(EAGLE_VID, EAGLE_II_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2564 {USB_DEVICE(EAGLE_VID, EAGLE_II_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
2565 {USB_DEVICE(EAGLE_VID, EAGLE_IIC_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2566 {USB_DEVICE(EAGLE_VID, EAGLE_IIC_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
2567 {USB_DEVICE(EAGLE_VID, EAGLE_III_PID_PREFIRM), .driver_info = EAGLE_III | PREFIRM},
2568 {USB_DEVICE(EAGLE_VID, EAGLE_III_PID_PSTFIRM), .driver_info = EAGLE_III | PSTFIRM},
2569 {USB_DEVICE(EAGLE_VID, EAGLE_IV_PID_PREFIRM), .driver_info = EAGLE_IV | PREFIRM},
2570 {USB_DEVICE(EAGLE_VID, EAGLE_IV_PID_PSTFIRM), .driver_info = EAGLE_IV | PSTFIRM},
2571 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2572 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
2573 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2574 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
2575 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
2576 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM},
2577 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
2578 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM},
2583 * USB driver descriptor
2585 static struct usb_driver uea_driver = {
2586 .name = "ueagle-atm",
2587 .id_table = uea_ids,
2589 .disconnect = uea_disconnect,
2592 MODULE_DEVICE_TABLE(usb, uea_ids);
2595 * uea_init - Initialize the module.
2596 * Register to USB subsystem
2598 static int __init uea_init(void)
2600 printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n");
2602 usb_register(&uea_driver);
2607 module_init(uea_init);
2610 * uea_exit - Destroy module
2611 * Deregister with USB subsystem
2613 static void __exit uea_exit(void)
2616 * This calls automatically the uea_disconnect method if necessary:
2618 usb_deregister(&uea_driver);
2620 printk(KERN_INFO "[ueagle-atm] driver unloaded\n");
2623 module_exit(uea_exit);
2625 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2626 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2627 MODULE_LICENSE("Dual BSD/GPL");