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;
166 union cmv_dsc cmv_dsc;
168 struct work_struct task;
169 struct workqueue_struct *work_q;
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 unsigned int altsetting[NB_MODEM] = {[0 ... (NB_MODEM - 1)] = FASTEST_ISO_INTF};
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(altsetting, uint, NULL, 0644);
549 MODULE_PARM_DESC(altsetting, "alternate setting for incoming traffic: 0=bulk, "
550 "1=isoc slowest, ... , 8=isoc fastest (default)");
551 module_param_array(sync_wait, bool, NULL, 0644);
552 MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
553 module_param_array(cmv_file, charp, NULL, 0644);
554 MODULE_PARM_DESC(cmv_file,
555 "file name with configuration and management variables");
556 module_param_array(annex, uint, NULL, 0644);
557 MODULE_PARM_DESC(annex,
558 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
560 #define uea_wait(sc, cond, timeo) \
562 int _r = wait_event_interruptible_timeout(sc->sync_q, \
563 (cond) || kthread_should_stop(), timeo); \
564 if (kthread_should_stop()) \
569 #define UPDATE_ATM_STAT(type, val) \
571 if (sc->usbatm->atm_dev) \
572 sc->usbatm->atm_dev->type = val; \
575 /* Firmware loading */
576 #define LOAD_INTERNAL 0xA0
577 #define F8051_USBCS 0x7f92
580 * uea_send_modem_cmd - Send a command for pre-firmware devices.
582 static int uea_send_modem_cmd(struct usb_device *usb,
583 u16 addr, u16 size, u8 * buff)
588 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
590 ret = usb_control_msg(usb,
591 usb_sndctrlpipe(usb, 0),
593 USB_DIR_OUT | USB_TYPE_VENDOR |
594 USB_RECIP_DEVICE, addr, 0, xfer_buff,
602 return (ret == size) ? 0 : -EIO;
605 static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *context)
607 struct usb_device *usb = context;
614 uea_err(usb, "firmware is not available\n");
618 pfw = fw_entry->data;
619 size = fw_entry->size;
621 goto err_fw_corrupted;
623 crc = FW_GET_LONG(pfw);
626 if (crc32_be(0, pfw, size) != crc)
627 goto err_fw_corrupted;
630 * Start to upload formware : send reset
633 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
636 uea_err(usb, "modem reset failed with error %d\n", ret);
641 u8 len = FW_GET_BYTE(pfw);
642 u16 add = FW_GET_WORD(pfw + 1);
646 goto err_fw_corrupted;
648 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
650 uea_err(usb, "uploading firmware data failed "
651 "with error %d\n", ret);
658 goto err_fw_corrupted;
661 * Tell the modem we finish : de-assert reset
664 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
666 uea_err(usb, "modem de-assert failed with error %d\n", ret);
668 uea_info(usb, "firmware uploaded\n");
674 uea_err(usb, "firmware is corrupted\n");
680 * uea_load_firmware - Load usb firmware for pre-firmware devices.
682 static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
685 char *fw_name = FW_DIR "eagle.fw";
688 uea_info(usb, "pre-firmware device, uploading firmware\n");
692 fw_name = FW_DIR "adi930.fw";
695 fw_name = FW_DIR "eagleI.fw";
698 fw_name = FW_DIR "eagleII.fw";
701 fw_name = FW_DIR "eagleIII.fw";
704 fw_name = FW_DIR "eagleIV.fw";
708 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware);
710 uea_err(usb, "firmware %s is not available\n", fw_name);
712 uea_info(usb, "loading firmware %s\n", fw_name);
718 /* modem management : dsp firmware, send/read CMV, monitoring statistic
722 * Make sure that the DSP code provided is safe to use.
724 static int check_dsp_e1(u8 *dsp, unsigned int len)
726 u8 pagecount, blockcount;
729 unsigned int i, j, p, pp;
731 pagecount = FW_GET_BYTE(dsp);
734 /* enough space for page offsets? */
735 if (p + 4 * pagecount > len)
738 for (i = 0; i < pagecount; i++) {
740 pageoffset = FW_GET_LONG(dsp + p);
746 /* enough space for blockcount? */
747 if (pageoffset >= len)
751 blockcount = FW_GET_BYTE(dsp + pp);
754 for (j = 0; j < blockcount; j++) {
756 /* enough space for block header? */
760 pp += 2; /* skip blockaddr */
761 blocksize = FW_GET_WORD(dsp + pp);
764 /* enough space for block data? */
765 if (pp + blocksize > len)
775 static int check_dsp_e4(u8 *dsp, int len)
778 struct l1_code *p = (struct l1_code *) dsp;
779 unsigned int sum = p->code - dsp;
784 if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 &&
785 strcmp("STRATIPHY ANEXB", p->string_header) != 0)
788 for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) {
789 struct block_index *blockidx;
790 u8 blockno = p->page_number_to_block_index[i];
791 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
797 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
800 blockidx = &p->page_header[blockno++];
801 if ((u8 *)(blockidx + 1) - dsp >= len)
804 if (le16_to_cpu(blockidx->PageNumber) != i)
807 l = E4_PAGE_BYTES(blockidx->PageSize);
809 l += le32_to_cpu(blockidx->PageOffset);
813 /* zero is zero regardless endianes */
814 } while (blockidx->NotLastBlock);
817 return (sum == len) ? 0 : 1;
821 * send data to the idma pipe
823 static int uea_idma_write(struct uea_softc *sc, void *data, u32 size)
829 xfer_buff = kmemdup(data, size, GFP_KERNEL);
831 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
835 ret = usb_bulk_msg(sc->usb_dev,
836 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
837 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
842 if (size != bytes_read) {
843 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
851 static int request_dsp(struct uea_softc *sc)
856 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
858 dsp_name = FW_DIR "DSP4i.bin";
860 dsp_name = FW_DIR "DSP4p.bin";
861 } else if (UEA_CHIP_VERSION(sc) == ADI930) {
863 dsp_name = FW_DIR "DSP9i.bin";
865 dsp_name = FW_DIR "DSP9p.bin";
868 dsp_name = FW_DIR "DSPei.bin";
870 dsp_name = FW_DIR "DSPep.bin";
873 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
875 uea_err(INS_TO_USBDEV(sc),
876 "requesting firmware %s failed with error %d\n",
881 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
882 ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size);
884 ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size);
887 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
889 release_firmware(sc->dsp_firm);
898 * The uea_load_page() function must be called within a process context
900 static void uea_load_page_e1(struct work_struct *work)
902 struct uea_softc *sc = container_of(work, struct uea_softc, task);
903 u16 pageno = sc->pageno;
905 struct block_info_e1 bi;
908 u8 pagecount, blockcount;
909 u16 blockaddr, blocksize;
913 /* reload firmware when reboot start and it's loaded already */
914 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
915 release_firmware(sc->dsp_firm);
919 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
922 p = sc->dsp_firm->data;
923 pagecount = FW_GET_BYTE(p);
926 if (pageno >= pagecount)
930 pageoffset = FW_GET_LONG(p);
935 p = sc->dsp_firm->data + pageoffset;
936 blockcount = FW_GET_BYTE(p);
939 uea_dbg(INS_TO_USBDEV(sc),
940 "sending %u blocks for DSP page %u\n", blockcount, pageno);
942 bi.wHdr = cpu_to_le16(UEA_BIHDR);
943 bi.wOvl = cpu_to_le16(ovl);
944 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
946 for (i = 0; i < blockcount; i++) {
947 blockaddr = FW_GET_WORD(p);
950 blocksize = FW_GET_WORD(p);
953 bi.wSize = cpu_to_le16(blocksize);
954 bi.wAddress = cpu_to_le16(blockaddr);
955 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
957 /* send block info through the IDMA pipe */
958 if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE))
961 /* send block data through the IDMA pipe */
962 if (uea_idma_write(sc, p, blocksize))
971 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
974 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
977 static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
979 struct block_info_e4 bi;
980 struct block_index *blockidx;
981 struct l1_code *p = (struct l1_code *) sc->dsp_firm->data;
982 u8 blockno = p->page_number_to_block_index[pageno];
984 bi.wHdr = cpu_to_be16(UEA_BIHDR);
986 bi.bPageNumber = pageno;
987 bi.wReserved = cpu_to_be16(UEA_RESERVED);
991 unsigned int blocksize;
993 blockidx = &p->page_header[blockno];
994 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
995 blockoffset = sc->dsp_firm->data + le32_to_cpu(blockidx->PageOffset);
997 bi.dwSize = cpu_to_be32(blocksize);
998 bi.dwAddress = swab32(blockidx->PageAddress);
1000 uea_dbg(INS_TO_USBDEV(sc),
1001 "sending block %u for DSP page %u size %u adress %x\n",
1002 blockno, pageno, blocksize, le32_to_cpu(blockidx->PageAddress));
1004 /* send block info through the IDMA pipe */
1005 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1008 /* send block data through the IDMA pipe */
1009 if (uea_idma_write(sc, blockoffset, blocksize))
1013 } while (blockidx->NotLastBlock);
1018 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno);
1022 static void uea_load_page_e4(struct work_struct *work)
1024 struct uea_softc *sc = container_of(work, struct uea_softc, task);
1025 u8 pageno = sc->pageno;
1027 struct block_info_e4 bi;
1030 uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
1032 /* reload firmware when reboot start and it's loaded already */
1033 if (pageno == 0 && sc->dsp_firm) {
1034 release_firmware(sc->dsp_firm);
1035 sc->dsp_firm = NULL;
1038 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
1041 p = (struct l1_code *) sc->dsp_firm->data;
1042 if (pageno >= p->page_header[0].PageNumber) {
1043 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
1048 __uea_load_page_e4(sc, pageno, 0);
1052 uea_dbg(INS_TO_USBDEV(sc),
1053 "sending Main DSP page %u\n", p->page_header[0].PageNumber);
1055 for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) {
1056 if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize))
1057 __uea_load_page_e4(sc, i, 1);
1060 uea_dbg(INS_TO_USBDEV(sc),"sending start bi\n");
1062 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1064 bi.bPageNumber = 0xff;
1065 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1066 bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize));
1067 bi.dwAddress = swab32(p->page_header[0].PageAddress);
1069 /* send block info through the IDMA pipe */
1070 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1071 uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n");
1074 static inline void wake_up_cmv_ack(struct uea_softc *sc)
1076 BUG_ON(sc->cmv_ack);
1078 wake_up(&sc->sync_q);
1081 static inline int wait_cmv_ack(struct uea_softc *sc)
1083 int ret = uea_wait(sc, sc->cmv_ack , ACK_TIMEOUT);
1087 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
1088 jiffies_to_msecs(ret));
1093 return (ret == 0) ? -ETIMEDOUT : 0;
1096 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1098 static int uea_request(struct uea_softc *sc,
1099 u16 value, u16 index, u16 size, void *data)
1104 xfer_buff = kmemdup(data, size, GFP_KERNEL);
1106 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
1110 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
1111 UCDC_SEND_ENCAPSULATED_COMMAND,
1112 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1113 value, index, xfer_buff, size, CTRL_TIMEOUT);
1117 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
1122 uea_err(INS_TO_USBDEV(sc),
1123 "usb_control_msg send only %d bytes (instead of %d)\n",
1131 static int uea_cmv_e1(struct uea_softc *sc,
1132 u8 function, u32 address, u16 offset, u32 data)
1137 uea_enters(INS_TO_USBDEV(sc));
1138 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1139 "offset : 0x%04x, data : 0x%08x\n",
1140 E1_FUNCTION_TYPE(function), E1_FUNCTION_SUBTYPE(function),
1141 E1_GETSA1(address), E1_GETSA2(address), E1_GETSA3(address),
1142 E1_GETSA4(address), offset, data);
1144 /* we send a request, but we expect a reply */
1145 sc->cmv_dsc.e1.function = function | 0x2;
1146 sc->cmv_dsc.e1.idx++;
1147 sc->cmv_dsc.e1.address = address;
1148 sc->cmv_dsc.e1.offset = offset;
1150 cmv.wPreamble = cpu_to_le16(E1_PREAMBLE);
1151 cmv.bDirection = E1_HOSTTOMODEM;
1152 cmv.bFunction = function;
1153 cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx);
1154 put_unaligned(cpu_to_le32(address), &cmv.dwSymbolicAddress);
1155 cmv.wOffsetAddress = cpu_to_le16(offset);
1156 put_unaligned(cpu_to_le32(data >> 16 | data << 16), &cmv.dwData);
1158 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv);
1161 ret = wait_cmv_ack(sc);
1162 uea_leaves(INS_TO_USBDEV(sc));
1166 static int uea_cmv_e4(struct uea_softc *sc,
1167 u16 function, u16 group, u16 address, u16 offset, u32 data)
1172 uea_enters(INS_TO_USBDEV(sc));
1173 memset(&cmv, 0, sizeof(cmv));
1175 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
1176 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1177 E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function),
1178 group, address, offset, data);
1180 /* we send a request, but we expect a reply */
1181 sc->cmv_dsc.e4.function = function | (0x1 << 4);
1182 sc->cmv_dsc.e4.offset = offset;
1183 sc->cmv_dsc.e4.address = address;
1184 sc->cmv_dsc.e4.group = group;
1186 cmv.wFunction = cpu_to_be16(function);
1187 cmv.wGroup = cpu_to_be16(group);
1188 cmv.wAddress = cpu_to_be16(address);
1189 cmv.wOffset = cpu_to_be16(offset);
1190 cmv.dwData[0] = cpu_to_be32(data);
1192 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv);
1195 ret = wait_cmv_ack(sc);
1196 uea_leaves(INS_TO_USBDEV(sc));
1200 static inline int uea_read_cmv_e1(struct uea_softc *sc,
1201 u32 address, u16 offset, u32 *data)
1203 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD),
1204 address, offset, 0);
1206 uea_err(INS_TO_USBDEV(sc),
1207 "reading cmv failed with error %d\n", ret);
1214 static inline int uea_read_cmv_e4(struct uea_softc *sc,
1215 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1217 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTREAD, size),
1218 group, address, offset, 0);
1220 uea_err(INS_TO_USBDEV(sc),
1221 "reading cmv failed with error %d\n", ret);
1224 /* size is in 16-bit word quantities */
1226 *(data + 1) = sc->data1;
1231 static inline int uea_write_cmv_e1(struct uea_softc *sc,
1232 u32 address, u16 offset, u32 data)
1234 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE),
1235 address, offset, data);
1237 uea_err(INS_TO_USBDEV(sc),
1238 "writing cmv failed with error %d\n", ret);
1243 static inline int uea_write_cmv_e4(struct uea_softc *sc,
1244 u8 size, u16 group, u16 address, u16 offset, u32 data)
1246 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTWRITE, size),
1247 group, address, offset, data);
1249 uea_err(INS_TO_USBDEV(sc),
1250 "writing cmv failed with error %d\n", ret);
1255 static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1260 /* in bulk mode the modem have problem with high rate
1261 * changing internal timing could improve things, but the
1262 * value is misterious.
1263 * ADI930 don't support it (-EPIPE error).
1266 if (UEA_CHIP_VERSION(sc) == ADI930 ||
1267 altsetting[sc->modem_index] > 0 ||
1268 sc->stats.phy.dsrate == dsrate)
1271 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1272 timeout = (dsrate <= 1024*1024) ? 0 : 1;
1273 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
1274 uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n",
1275 timeout, ret < 0 ? " failed" : "");
1280 * Monitor the modem and update the stat
1281 * return 0 if everything is ok
1282 * return < 0 if an error occurs (-EAGAIN reboot needed)
1284 static int uea_stat_e1(struct uea_softc *sc)
1289 uea_enters(INS_TO_USBDEV(sc));
1290 data = sc->stats.phy.state;
1292 ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state);
1296 switch (GET_STATUS(sc->stats.phy.state)) {
1297 case 0: /* not yet synchronized */
1298 uea_dbg(INS_TO_USBDEV(sc),
1299 "modem not yet synchronized\n");
1302 case 1: /* initialization */
1303 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1306 case 2: /* operational */
1307 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
1310 case 3: /* fail ... */
1311 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1312 " (may be try other cmv/dsp)\n");
1315 case 4 ... 6: /* test state */
1316 uea_warn(INS_TO_USBDEV(sc),
1317 "modem in test mode - not supported\n");
1320 case 7: /* fast-retain ... */
1321 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
1324 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
1325 GET_STATUS(sc->stats.phy.state));
1329 if (GET_STATUS(data) != 2) {
1330 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1331 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1333 /* release the dsp firmware as it is not needed until
1337 release_firmware(sc->dsp_firm);
1338 sc->dsp_firm = NULL;
1342 /* always update it as atm layer could not be init when we switch to
1345 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1347 /* wake up processes waiting for synchronization */
1348 wake_up(&sc->sync_q);
1350 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags);
1353 sc->stats.phy.mflags |= sc->stats.phy.flags;
1355 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1356 * we check the status again in order to detect the failure earlier
1358 if (sc->stats.phy.flags) {
1359 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1360 sc->stats.phy.flags);
1364 ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data);
1368 uea_set_bulk_timeout(sc, (data >> 16) * 32);
1369 sc->stats.phy.dsrate = (data >> 16) * 32;
1370 sc->stats.phy.usrate = (data & 0xffff) * 32;
1371 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1373 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data);
1376 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
1378 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data);
1381 sc->stats.phy.usattenuation = (data & 0xff) / 2;
1383 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin);
1387 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin);
1391 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow);
1395 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow);
1399 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc);
1403 /* only for atu-c */
1404 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc);
1408 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr);
1412 /* only for atu-c */
1413 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr);
1417 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 8, &sc->stats.phy.vidco);
1421 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 13, &sc->stats.phy.vidcpe);
1428 static int uea_stat_e4(struct uea_softc *sc)
1434 uea_enters(INS_TO_USBDEV(sc));
1435 data = sc->stats.phy.state;
1437 /* XXX only need to be done before operationnal... */
1438 ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state);
1442 switch (sc->stats.phy.state) {
1443 case 0x0: /* not yet synchronized */
1447 uea_dbg(INS_TO_USBDEV(sc), "modem not yet synchronized\n");
1449 case 0x5: /* initialization */
1453 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1455 case 0x2: /* fail ... */
1456 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1457 " (may be try other cmv/dsp)\n");
1459 case 0x7: /* operational */
1462 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n", sc->stats.phy.state);
1467 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1468 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1470 /* release the dsp firmware as it is not needed until
1474 release_firmware(sc->dsp_firm);
1475 sc->dsp_firm = NULL;
1479 /* always update it as atm layer could not be init when we switch to
1482 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1484 /* wake up processes waiting for synchronization */
1485 wake_up(&sc->sync_q);
1487 /* TODO improve this state machine :
1488 * we need some CMV info : what they do and their unit
1489 * we should find the equivalent of eagle3- CMV
1492 ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags);
1495 sc->stats.phy.mflags |= sc->stats.phy.flags;
1497 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1498 * we check the status again in order to detect the failure earlier
1500 if (sc->stats.phy.flags) {
1501 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1502 sc->stats.phy.flags);
1503 if (sc->stats.phy.flags & 1) //delineation LOSS
1505 if (sc->stats.phy.flags & 0x4000) //Reset Flag
1510 /* rate data may be in upper or lower half of 64 bit word, strange */
1511 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr);
1514 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1515 sc->stats.phy.usrate = data / 1000;
1517 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr);
1520 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1521 uea_set_bulk_timeout(sc, data / 1000);
1522 sc->stats.phy.dsrate = data / 1000;
1523 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1525 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data);
1528 sc->stats.phy.dsattenuation = data / 10;
1530 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data);
1533 sc->stats.phy.usattenuation = data / 10;
1535 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data);
1538 sc->stats.phy.dsmargin = data / 2;
1540 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data);
1543 sc->stats.phy.usmargin = data / 10;
1548 static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1550 char file_arr[] = "CMVxy.bin";
1553 /* set proper name corresponding modem version and line type */
1554 if (cmv_file[sc->modem_index] == NULL) {
1555 if (UEA_CHIP_VERSION(sc) == ADI930)
1557 else if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1562 file_arr[4] = IS_ISDN(sc) ? 'i' : 'p';
1565 file = cmv_file[sc->modem_index];
1567 strcpy(cmv_name, FW_DIR);
1568 strlcat(cmv_name, file, FIRMWARE_NAME_MAX);
1570 strlcat(cmv_name, ".v2", FIRMWARE_NAME_MAX);
1573 static int request_cmvs_old(struct uea_softc *sc,
1574 void **cmvs, const struct firmware **fw)
1578 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1580 cmvs_file_name(sc, cmv_name, 1);
1581 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1583 uea_err(INS_TO_USBDEV(sc),
1584 "requesting firmware %s failed with error %d\n",
1589 data = (u8 *) (*fw)->data;
1592 goto err_fw_corrupted;
1594 if (size != *data * sizeof(struct uea_cmvs_v1) + 1)
1595 goto err_fw_corrupted;
1597 *cmvs = (void *)(data + 1);
1601 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1602 release_firmware(*fw);
1606 static int request_cmvs(struct uea_softc *sc,
1607 void **cmvs, const struct firmware **fw, int *ver)
1612 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1614 cmvs_file_name(sc, cmv_name, 2);
1615 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1617 /* if caller can handle old version, try to provide it */
1619 uea_warn(INS_TO_USBDEV(sc), "requesting firmware %s failed, "
1620 "try to get older cmvs\n", cmv_name);
1621 return request_cmvs_old(sc, cmvs, fw);
1623 uea_err(INS_TO_USBDEV(sc),
1624 "requesting firmware %s failed with error %d\n",
1630 data = (u8 *) (*fw)->data;
1631 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1633 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted, "
1634 "try to get older cmvs\n", cmv_name);
1635 release_firmware(*fw);
1636 return request_cmvs_old(sc, cmvs, fw);
1638 goto err_fw_corrupted;
1646 goto err_fw_corrupted;
1648 crc = FW_GET_LONG(data);
1651 if (crc32_be(0, data, size) != crc)
1652 goto err_fw_corrupted;
1654 if (size != *data * sizeof(struct uea_cmvs_v2) + 1)
1655 goto err_fw_corrupted;
1657 *cmvs = (void *) (data + 1);
1661 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1662 release_firmware(*fw);
1666 static int uea_send_cmvs_e1(struct uea_softc *sc)
1670 const struct firmware *cmvs_fw;
1671 int ver = 1; // we can handle v1 cmv firmware version;
1673 /* Enter in R-IDLE (cmv) until instructed otherwise */
1674 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
1678 /* Dump firmware version */
1679 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid);
1682 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1683 sc->stats.phy.firmid);
1686 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1692 struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr;
1694 uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, "
1695 "please update your firmware\n");
1697 for (i = 0; i < len; i++) {
1698 ret = uea_write_cmv_e1(sc, FW_GET_LONG(&cmvs_v1[i].address),
1699 FW_GET_WORD(&cmvs_v1[i].offset),
1700 FW_GET_LONG(&cmvs_v1[i].data));
1704 } else if (ver == 2) {
1705 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1707 for (i = 0; i < len; i++) {
1708 ret = uea_write_cmv_e1(sc, FW_GET_LONG(&cmvs_v2[i].address),
1709 (u16) FW_GET_LONG(&cmvs_v2[i].offset),
1710 FW_GET_LONG(&cmvs_v2[i].data));
1715 /* This realy should not happen */
1716 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1720 /* Enter in R-ACT-REQ */
1721 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1722 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1723 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n");
1725 release_firmware(cmvs_fw);
1729 static int uea_send_cmvs_e4(struct uea_softc *sc)
1733 const struct firmware *cmvs_fw;
1734 int ver = 2; // we can only handle v2 cmv firmware version;
1736 /* Enter in R-IDLE (cmv) until instructed otherwise */
1737 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
1741 /* Dump firmware version */
1742 /* XXX don't read the 3th byte as it is always 6 */
1743 ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid);
1746 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1747 sc->stats.phy.firmid);
1751 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1757 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1759 for (i = 0; i < len; i++) {
1760 ret = uea_write_cmv_e4(sc, 1,
1761 FW_GET_LONG(&cmvs_v2[i].group),
1762 FW_GET_LONG(&cmvs_v2[i].address),
1763 FW_GET_LONG(&cmvs_v2[i].offset),
1764 FW_GET_LONG(&cmvs_v2[i].data));
1769 /* This realy should not happen */
1770 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1774 /* Enter in R-ACT-REQ */
1775 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1776 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1777 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n");
1779 release_firmware(cmvs_fw);
1783 /* Start boot post firmware modem:
1784 * - send reset commands through usb control pipe
1785 * - start workqueue for DSP loading
1786 * - send CMV options to modem
1789 static int uea_start_reset(struct uea_softc *sc)
1791 u16 zero = 0; /* ;-) */
1794 uea_enters(INS_TO_USBDEV(sc));
1795 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1797 /* mask interrupt */
1799 /* We need to set this here because, a ack timeout could have occured,
1800 * but before we start the reboot, the ack occurs and set this to 1.
1801 * So we will failed to wait Ready CMV.
1804 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST);
1806 /* reset statistics */
1807 memset(&sc->stats, 0, sizeof(struct uea_stats));
1809 /* tell the modem that we want to boot in IDMA mode */
1810 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1811 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1813 /* enter reset mode */
1814 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1816 /* original driver use 200ms, but windows driver use 100ms */
1817 ret = uea_wait(sc, 0, msecs_to_jiffies(100));
1821 /* leave reset mode */
1822 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1824 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
1825 /* clear tx and rx mailboxes */
1826 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1827 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1828 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1831 ret = uea_wait(sc, 0, msecs_to_jiffies(1000));
1835 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1836 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1);
1838 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY);
1840 /* demask interrupt */
1843 /* start loading DSP */
1846 queue_work(sc->work_q, &sc->task);
1848 /* wait for modem ready CMV */
1849 ret = wait_cmv_ack(sc);
1853 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1855 ret = sc->send_cmvs(sc);
1860 uea_leaves(INS_TO_USBDEV(sc));
1865 * In case of an error wait 1s before rebooting the modem
1866 * if the modem don't request reboot (-EAGAIN).
1867 * Monitor the modem every 1s.
1870 static int uea_kthread(void *data)
1872 struct uea_softc *sc = data;
1876 uea_enters(INS_TO_USBDEV(sc));
1877 while (!kthread_should_stop()) {
1878 if (ret < 0 || sc->reset)
1879 ret = uea_start_reset(sc);
1883 uea_wait(sc, 0, msecs_to_jiffies(1000));
1884 if (try_to_freeze())
1885 uea_err(INS_TO_USBDEV(sc), "suspend/resume not supported, "
1886 "please unplug/replug your modem\n");
1888 uea_leaves(INS_TO_USBDEV(sc));
1892 /* Load second usb firmware for ADI930 chip */
1893 static int load_XILINX_firmware(struct uea_softc *sc)
1895 const struct firmware *fw_entry;
1896 int ret, size, u, ln;
1898 char *fw_name = FW_DIR "930-fpga.bin";
1900 uea_enters(INS_TO_USBDEV(sc));
1902 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1904 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1909 pfw = fw_entry->data;
1910 size = fw_entry->size;
1911 if (size != 0x577B) {
1912 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1917 for (u = 0; u < size; u += ln) {
1918 ln = min(size - u, 64);
1919 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1921 uea_err(INS_TO_USBDEV(sc),
1922 "elsa download data failed (%d)\n", ret);
1927 /* finish to send the fpga */
1928 ret = uea_request(sc, 0xe, 1, 0, NULL);
1930 uea_err(INS_TO_USBDEV(sc),
1931 "elsa download data failed (%d)\n", ret);
1935 /* Tell the modem we finish : de-assert reset */
1937 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1939 uea_err(sc->usb_dev, "elsa de-assert failed with error %d\n", ret);
1942 release_firmware(fw_entry);
1944 uea_leaves(INS_TO_USBDEV(sc));
1948 /* The modem send us an ack. First with check if it right */
1949 static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
1951 struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;
1952 struct cmv_e1 *cmv = &intr->u.e1.s2.cmv;
1954 uea_enters(INS_TO_USBDEV(sc));
1955 if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE)
1958 if (cmv->bDirection != E1_MODEMTOHOST)
1961 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1962 * the first MEMACESS cmv. Ignore it...
1964 if (cmv->bFunction != dsc->function) {
1965 if (UEA_CHIP_VERSION(sc) == ADI930
1966 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
1967 cmv->wIndex = cpu_to_le16(dsc->idx);
1968 put_unaligned(cpu_to_le32(dsc->address), &cmv->dwSymbolicAddress);
1969 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
1974 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY)) {
1975 wake_up_cmv_ack(sc);
1976 uea_leaves(INS_TO_USBDEV(sc));
1980 /* in case of MEMACCESS */
1981 if (le16_to_cpu(cmv->wIndex) != dsc->idx ||
1982 le32_to_cpu(get_unaligned(&cmv->dwSymbolicAddress)) != dsc->address ||
1983 le16_to_cpu(cmv->wOffsetAddress) != dsc->offset)
1986 sc->data = le32_to_cpu(get_unaligned(&cmv->dwData));
1987 sc->data = sc->data << 16 | sc->data >> 16;
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 E1_FUNCTION_TYPE(cmv->bFunction),
1997 E1_FUNCTION_SUBTYPE(cmv->bFunction));
1998 uea_leaves(INS_TO_USBDEV(sc));
2002 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
2003 "wPreamble %d, bDirection %d\n",
2004 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
2005 uea_leaves(INS_TO_USBDEV(sc));
2008 /* The modem send us an ack. First with check if it right */
2009 static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
2011 struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;
2012 struct cmv_e4 *cmv = &intr->u.e4.s2.cmv;
2014 uea_enters(INS_TO_USBDEV(sc));
2015 uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n",
2016 be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction),
2017 be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
2018 be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1]));
2020 if (be16_to_cpu(cmv->wFunction) != dsc->function)
2023 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1)) {
2024 wake_up_cmv_ack(sc);
2025 uea_leaves(INS_TO_USBDEV(sc));
2029 /* in case of MEMACCESS */
2030 if (be16_to_cpu(cmv->wOffset) != dsc->offset ||
2031 be16_to_cpu(cmv->wGroup) != dsc->group ||
2032 be16_to_cpu(cmv->wAddress) != dsc->address)
2035 sc->data = be32_to_cpu(cmv->dwData[0]);
2036 sc->data1 = be32_to_cpu(cmv->dwData[1]);
2037 wake_up_cmv_ack(sc);
2038 uea_leaves(INS_TO_USBDEV(sc));
2042 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
2043 "Function : %d, Subfunction : %d\n",
2044 E4_FUNCTION_TYPE(cmv->wFunction),
2045 E4_FUNCTION_SUBTYPE(cmv->wFunction));
2046 uea_leaves(INS_TO_USBDEV(sc));
2050 static void uea_schedule_load_page_e1(struct uea_softc *sc, struct intr_pkt *intr)
2052 sc->pageno = intr->e1_bSwapPageNo;
2053 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
2054 queue_work(sc->work_q, &sc->task);
2057 static void uea_schedule_load_page_e4(struct uea_softc *sc, struct intr_pkt *intr)
2059 sc->pageno = intr->e4_bSwapPageNo;
2060 queue_work(sc->work_q, &sc->task);
2066 static void uea_intr(struct urb *urb)
2068 struct uea_softc *sc = urb->context;
2069 struct intr_pkt *intr = urb->transfer_buffer;
2070 int status = urb->status;
2072 uea_enters(INS_TO_USBDEV(sc));
2074 if (unlikely(status < 0)) {
2075 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
2080 /* device-to-host interrupt */
2081 if (intr->bType != 0x08 || sc->booting) {
2082 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
2086 switch (le16_to_cpu(intr->wInterrupt)) {
2087 case INT_LOADSWAPPAGE:
2088 sc->schedule_load_page(sc, intr);
2091 case INT_INCOMINGCMV:
2092 sc->dispatch_cmv(sc, intr);
2096 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
2097 le16_to_cpu(intr->wInterrupt));
2101 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
2105 * Start the modem : init the data and start kernel thread
2107 static int uea_boot(struct uea_softc *sc)
2110 struct intr_pkt *intr;
2112 uea_enters(INS_TO_USBDEV(sc));
2114 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2115 size = E4_INTR_PKT_SIZE;
2116 sc->dispatch_cmv = uea_dispatch_cmv_e4;
2117 sc->schedule_load_page = uea_schedule_load_page_e4;
2118 sc->stat = uea_stat_e4;
2119 sc->send_cmvs = uea_send_cmvs_e4;
2120 INIT_WORK(&sc->task, uea_load_page_e4);
2122 size = E1_INTR_PKT_SIZE;
2123 sc->dispatch_cmv = uea_dispatch_cmv_e1;
2124 sc->schedule_load_page = uea_schedule_load_page_e1;
2125 sc->stat = uea_stat_e1;
2126 sc->send_cmvs = uea_send_cmvs_e1;
2127 INIT_WORK(&sc->task, uea_load_page_e1);
2130 init_waitqueue_head(&sc->sync_q);
2132 sc->work_q = create_workqueue("ueagle-dsp");
2134 uea_err(INS_TO_USBDEV(sc), "cannot allocate workqueue\n");
2135 uea_leaves(INS_TO_USBDEV(sc));
2139 if (UEA_CHIP_VERSION(sc) == ADI930)
2140 load_XILINX_firmware(sc);
2142 intr = kmalloc(size, GFP_KERNEL);
2144 uea_err(INS_TO_USBDEV(sc),
2145 "cannot allocate interrupt package\n");
2149 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
2151 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
2155 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
2156 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
2157 intr, size, uea_intr, sc,
2158 sc->usb_dev->actconfig->interface[0]->altsetting[0].
2159 endpoint[0].desc.bInterval);
2161 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2163 uea_err(INS_TO_USBDEV(sc),
2164 "urb submition failed with error %d\n", ret);
2168 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm");
2169 if (sc->kthread == ERR_PTR(-ENOMEM)) {
2170 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2174 uea_leaves(INS_TO_USBDEV(sc));
2178 usb_kill_urb(sc->urb_int);
2180 usb_free_urb(sc->urb_int);
2184 destroy_workqueue(sc->work_q);
2185 uea_leaves(INS_TO_USBDEV(sc));
2190 * Stop the modem : kill kernel thread and free data
2192 static void uea_stop(struct uea_softc *sc)
2195 uea_enters(INS_TO_USBDEV(sc));
2196 ret = kthread_stop(sc->kthread);
2197 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
2199 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
2201 usb_kill_urb(sc->urb_int);
2202 kfree(sc->urb_int->transfer_buffer);
2203 usb_free_urb(sc->urb_int);
2205 /* stop any pending boot process, when no one can schedule work */
2206 destroy_workqueue(sc->work_q);
2209 release_firmware(sc->dsp_firm);
2210 uea_leaves(INS_TO_USBDEV(sc));
2213 /* syfs interface */
2214 static struct uea_softc *dev_to_uea(struct device *dev)
2216 struct usb_interface *intf;
2217 struct usbatm_data *usbatm;
2219 intf = to_usb_interface(dev);
2223 usbatm = usb_get_intfdata(intf);
2227 return usbatm->driver_data;
2230 static ssize_t read_status(struct device *dev, struct device_attribute *attr,
2234 struct uea_softc *sc;
2236 mutex_lock(&uea_mutex);
2237 sc = dev_to_uea(dev);
2240 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
2242 mutex_unlock(&uea_mutex);
2246 static ssize_t reboot(struct device *dev, struct device_attribute *attr,
2247 const char *buf, size_t count)
2250 struct uea_softc *sc;
2252 mutex_lock(&uea_mutex);
2253 sc = dev_to_uea(dev);
2259 mutex_unlock(&uea_mutex);
2263 static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot);
2265 static ssize_t read_human_status(struct device *dev, struct device_attribute *attr,
2270 struct uea_softc *sc;
2272 mutex_lock(&uea_mutex);
2273 sc = dev_to_uea(dev);
2277 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2278 switch (sc->stats.phy.state) {
2279 case 0x0: /* not yet synchronized */
2285 case 0x5: /* initialization */
2291 case 0x7: /* operational */
2294 case 0x2: /* fail ... */
2297 default: /* unknown */
2302 modem_state = GET_STATUS(sc->stats.phy.state);
2304 switch (modem_state) {
2306 ret = sprintf(buf, "Modem is booting\n");
2309 ret = sprintf(buf, "Modem is initializing\n");
2312 ret = sprintf(buf, "Modem is operational\n");
2315 ret = sprintf(buf, "Modem synchronization failed\n");
2318 ret = sprintf(buf, "Modem state is unknown\n");
2322 mutex_unlock(&uea_mutex);
2326 static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, read_human_status, NULL);
2328 static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2332 struct uea_softc *sc;
2333 char *delin = "GOOD";
2335 mutex_lock(&uea_mutex);
2336 sc = dev_to_uea(dev);
2340 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2341 if (sc->stats.phy.flags & 0x4000)
2343 else if (sc->stats.phy.flags & 0x0001)
2346 if (sc->stats.phy.flags & 0x0C00)
2348 else if (sc->stats.phy.flags & 0x0030)
2352 ret = sprintf(buf, "%s\n", delin);
2354 mutex_unlock(&uea_mutex);
2358 static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL);
2360 #define UEA_ATTR(name, reset) \
2362 static ssize_t read_##name(struct device *dev, \
2363 struct device_attribute *attr, char *buf) \
2365 int ret = -ENODEV; \
2366 struct uea_softc *sc; \
2368 mutex_lock(&uea_mutex); \
2369 sc = dev_to_uea(dev); \
2372 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2374 sc->stats.phy.name = 0; \
2376 mutex_unlock(&uea_mutex); \
2380 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2382 UEA_ATTR(mflags, 1);
2383 UEA_ATTR(vidcpe, 0);
2384 UEA_ATTR(usrate, 0);
2385 UEA_ATTR(dsrate, 0);
2386 UEA_ATTR(usattenuation, 0);
2387 UEA_ATTR(dsattenuation, 0);
2388 UEA_ATTR(usmargin, 0);
2389 UEA_ATTR(dsmargin, 0);
2390 UEA_ATTR(txflow, 0);
2391 UEA_ATTR(rxflow, 0);
2392 UEA_ATTR(uscorr, 0);
2393 UEA_ATTR(dscorr, 0);
2396 UEA_ATTR(firmid, 0);
2398 /* Retrieve the device End System Identifier (MAC) */
2400 #define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
2401 static int uea_getesi(struct uea_softc *sc, u_char * esi)
2403 unsigned char mac_str[2 * ETH_ALEN + 1];
2406 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
2407 sizeof(mac_str)) != 2 * ETH_ALEN)
2410 for (i = 0; i < ETH_ALEN; i++)
2411 esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]);
2417 static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
2419 struct uea_softc *sc = usbatm->driver_data;
2421 return uea_getesi(sc, atm_dev->esi);
2424 static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
2426 struct uea_softc *sc = usbatm->driver_data;
2428 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
2434 static int claim_interface(struct usb_device *usb_dev,
2435 struct usbatm_data *usbatm, int ifnum)
2438 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
2441 uea_err(usb_dev, "interface %d not found\n", ifnum);
2445 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
2447 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
2452 static struct attribute *attrs[] = {
2453 &dev_attr_stat_status.attr,
2454 &dev_attr_stat_mflags.attr,
2455 &dev_attr_stat_human_status.attr,
2456 &dev_attr_stat_delin.attr,
2457 &dev_attr_stat_vidcpe.attr,
2458 &dev_attr_stat_usrate.attr,
2459 &dev_attr_stat_dsrate.attr,
2460 &dev_attr_stat_usattenuation.attr,
2461 &dev_attr_stat_dsattenuation.attr,
2462 &dev_attr_stat_usmargin.attr,
2463 &dev_attr_stat_dsmargin.attr,
2464 &dev_attr_stat_txflow.attr,
2465 &dev_attr_stat_rxflow.attr,
2466 &dev_attr_stat_uscorr.attr,
2467 &dev_attr_stat_dscorr.attr,
2468 &dev_attr_stat_usunc.attr,
2469 &dev_attr_stat_dsunc.attr,
2470 &dev_attr_stat_firmid.attr,
2473 static struct attribute_group attr_grp = {
2477 static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
2478 const struct usb_device_id *id)
2480 struct usb_device *usb = interface_to_usbdev(intf);
2481 struct uea_softc *sc;
2482 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
2487 /* interface 0 is for firmware/monitoring */
2488 if (ifnum != UEA_INTR_IFACE_NO)
2491 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
2493 /* interface 1 is for outbound traffic */
2494 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
2498 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
2499 if (UEA_CHIP_VERSION(id) != ADI930) {
2500 /* interface 2 is for inbound traffic */
2501 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
2506 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
2508 uea_err(usb, "uea_init: not enough memory !\n");
2513 usbatm->driver_data = sc;
2514 sc->usbatm = usbatm;
2515 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
2516 sc->driver_info = id->driver_info;
2518 /* first try to use module parameter */
2519 if (annex[sc->modem_index] == 1)
2521 else if (annex[sc->modem_index] == 2)
2523 /* try to autodetect annex */
2524 else if (sc->driver_info & AUTO_ANNEX_A)
2526 else if (sc->driver_info & AUTO_ANNEX_B)
2529 sc->annex = (le16_to_cpu(sc->usb_dev->descriptor.bcdDevice) & 0x80)?ANNEXB:ANNEXA;
2531 alt = altsetting[sc->modem_index];
2532 /* ADI930 don't support iso */
2533 if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) {
2534 if (alt <= 8 && usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) {
2535 uea_dbg(usb, "set alternate %u for 2 interface\n", alt);
2536 uea_info(usb, "using iso mode\n");
2537 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
2539 uea_err(usb, "setting alternate %u failed for "
2540 "2 interface, using bulk mode\n", alt);
2544 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
2555 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2561 static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
2563 struct uea_softc *sc = usbatm->driver_data;
2565 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2570 static struct usbatm_driver uea_usbatm_driver = {
2571 .driver_name = "ueagle-atm",
2573 .atm_start = uea_atm_open,
2574 .unbind = uea_unbind,
2575 .heavy_init = uea_heavy,
2576 .bulk_in = UEA_BULK_DATA_PIPE,
2577 .bulk_out = UEA_BULK_DATA_PIPE,
2578 .isoc_in = UEA_ISO_DATA_PIPE,
2581 static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2583 struct usb_device *usb = interface_to_usbdev(intf);
2586 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2587 le16_to_cpu(usb->descriptor.idVendor),
2588 le16_to_cpu(usb->descriptor.idProduct),
2589 le16_to_cpu(usb->descriptor.bcdDevice),
2590 chip_name[UEA_CHIP_VERSION(id)]);
2592 usb_reset_device(usb);
2594 if (UEA_IS_PREFIRM(id))
2595 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2597 return usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2600 static void uea_disconnect(struct usb_interface *intf)
2602 struct usb_device *usb = interface_to_usbdev(intf);
2603 int ifnum = intf->altsetting->desc.bInterfaceNumber;
2606 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2607 * Pre-firmware device has one interface
2609 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
2610 mutex_lock(&uea_mutex);
2611 usbatm_usb_disconnect(intf);
2612 mutex_unlock(&uea_mutex);
2613 uea_info(usb, "ADSL device removed\n");
2620 * List of supported VID/PID
2622 static const struct usb_device_id uea_ids[] = {
2623 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
2624 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
2625 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2626 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
2627 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2628 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
2629 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2630 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
2631 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM), .driver_info = EAGLE_III | PREFIRM},
2632 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM), .driver_info = EAGLE_III | PSTFIRM},
2633 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM), .driver_info = EAGLE_IV | PREFIRM},
2634 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM), .driver_info = EAGLE_IV | PSTFIRM},
2635 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2636 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2637 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2638 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2639 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2640 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A},
2641 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2642 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B},
2643 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
2644 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
2645 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM), .driver_info = ADI930 | PREFIRM},
2646 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM), .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A},
2647 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM), .driver_info = ADI930 | PREFIRM},
2648 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM), .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B},
2649 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2650 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2651 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2652 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2653 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
2654 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2655 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
2656 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2661 * USB driver descriptor
2663 static struct usb_driver uea_driver = {
2664 .name = "ueagle-atm",
2665 .id_table = uea_ids,
2667 .disconnect = uea_disconnect,
2670 MODULE_DEVICE_TABLE(usb, uea_ids);
2673 * uea_init - Initialize the module.
2674 * Register to USB subsystem
2676 static int __init uea_init(void)
2678 printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n");
2680 usb_register(&uea_driver);
2685 module_init(uea_init);
2688 * uea_exit - Destroy module
2689 * Deregister with USB subsystem
2691 static void __exit uea_exit(void)
2694 * This calls automatically the uea_disconnect method if necessary:
2696 usb_deregister(&uea_driver);
2698 printk(KERN_INFO "[ueagle-atm] driver unloaded\n");
2701 module_exit(uea_exit);
2703 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2704 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2705 MODULE_LICENSE("Dual BSD/GPL");