2 * Copyright (c) 2003, 2004
3 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
5 * Copyright (c) 2005-2007 Matthieu Castet <castet.matthieu@free.fr>
6 * Copyright (c) 2005-2007 Stanislaw Gruszka <stf_xl@wp.pl>
8 * This software is available to you under a choice of one of two
9 * licenses. You may choose to be licensed under the terms of the GNU
10 * General Public License (GPL) Version 2, available from the file
11 * COPYING in the main directory of this source tree, or the
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice unmodified, this list of conditions, and the following
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * This program is free software; you can redistribute it and/or
38 * modify it under the terms of the GNU General Public License
39 * as published by the Free Software Foundation; either version 2
40 * of the License, or (at your option) any later version.
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
47 * You should have received a copy of the GNU General Public License
48 * along with this program; if not, write to the Free Software
49 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
52 * HISTORY : some part of the code was base on ueagle 1.3 BSD driver,
53 * Damien Bergamini agree to put his code under a DUAL GPL/BSD license.
55 * The rest of the code was was rewritten from scratch.
58 #include <linux/module.h>
59 #include <linux/moduleparam.h>
60 #include <linux/init.h>
61 #include <linux/crc32.h>
62 #include <linux/usb.h>
63 #include <linux/firmware.h>
64 #include <linux/ctype.h>
65 #include <linux/sched.h>
66 #include <linux/kthread.h>
67 #include <linux/version.h>
68 #include <linux/mutex.h>
69 #include <linux/freezer.h>
71 #include <asm/unaligned.h>
75 #define EAGLEUSBVERSION "ueagle 1.4"
81 #define uea_dbg(usb_dev, format, args...) \
84 dev_dbg(&(usb_dev)->dev, \
85 "[ueagle-atm dbg] %s: " format, \
86 __FUNCTION__, ##args); \
89 #define uea_vdbg(usb_dev, format, args...) \
92 dev_dbg(&(usb_dev)->dev, \
93 "[ueagle-atm vdbg] " format, ##args); \
96 #define uea_enters(usb_dev) \
97 uea_vdbg(usb_dev, "entering %s\n", __FUNCTION__)
99 #define uea_leaves(usb_dev) \
100 uea_vdbg(usb_dev, "leaving %s\n", __FUNCTION__)
102 #define uea_err(usb_dev, format,args...) \
103 dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args)
105 #define uea_warn(usb_dev, format,args...) \
106 dev_warn(&(usb_dev)->dev ,"[Ueagle-atm] " format, ##args)
108 #define uea_info(usb_dev, format,args...) \
109 dev_info(&(usb_dev)->dev ,"[ueagle-atm] " format, ##args)
113 /* cmv's from firmware */
118 } __attribute__ ((packed));
125 } __attribute__ ((packed));
127 /* information about currently processed cmv */
143 struct cmv_dsc_e1 e1;
144 struct cmv_dsc_e4 e4;
148 struct usb_device *usb_dev;
149 struct usbatm_data *usbatm;
152 unsigned int driver_info;
160 wait_queue_head_t sync_q;
162 struct task_struct *kthread;
167 union cmv_dsc cmv_dsc;
169 struct work_struct task;
170 struct workqueue_struct *work_q;
174 const struct firmware *dsp_firm;
177 void (*dispatch_cmv) (struct uea_softc *, struct intr_pkt *);
178 void (*schedule_load_page) (struct uea_softc *, struct intr_pkt *);
179 int (*stat) (struct uea_softc *);
180 int (*send_cmvs) (struct uea_softc *);
182 /* keep in sync with eaglectl */
210 #define ELSA_VID 0x05CC
211 #define ELSA_PID_PSTFIRM 0x3350
212 #define ELSA_PID_PREFIRM 0x3351
214 #define ELSA_PID_A_PREFIRM 0x3352
215 #define ELSA_PID_A_PSTFIRM 0x3353
216 #define ELSA_PID_B_PREFIRM 0x3362
217 #define ELSA_PID_B_PSTFIRM 0x3363
220 * Devolo IDs : pots if (pid & 0x10)
222 #define DEVOLO_VID 0x1039
223 #define DEVOLO_EAGLE_I_A_PID_PSTFIRM 0x2110
224 #define DEVOLO_EAGLE_I_A_PID_PREFIRM 0x2111
226 #define DEVOLO_EAGLE_I_B_PID_PSTFIRM 0x2100
227 #define DEVOLO_EAGLE_I_B_PID_PREFIRM 0x2101
229 #define DEVOLO_EAGLE_II_A_PID_PSTFIRM 0x2130
230 #define DEVOLO_EAGLE_II_A_PID_PREFIRM 0x2131
232 #define DEVOLO_EAGLE_II_B_PID_PSTFIRM 0x2120
233 #define DEVOLO_EAGLE_II_B_PID_PREFIRM 0x2121
236 * Reference design USB IDs
238 #define ANALOG_VID 0x1110
239 #define ADI930_PID_PREFIRM 0x9001
240 #define ADI930_PID_PSTFIRM 0x9000
242 #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
243 #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
245 #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
246 #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
248 #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
249 #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
251 #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
252 #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
254 #define EAGLE_IV_PID_PREFIRM 0x9042 /* Eagle IV */
255 #define EAGLE_IV_PID_PSTFIRM 0x9041 /* Eagle IV */
260 #define USR_VID 0x0BAF
261 #define MILLER_A_PID_PREFIRM 0x00F2
262 #define MILLER_A_PID_PSTFIRM 0x00F1
263 #define MILLER_B_PID_PREFIRM 0x00FA
264 #define MILLER_B_PID_PSTFIRM 0x00F9
265 #define HEINEKEN_A_PID_PREFIRM 0x00F6
266 #define HEINEKEN_A_PID_PSTFIRM 0x00F5
267 #define HEINEKEN_B_PID_PREFIRM 0x00F8
268 #define HEINEKEN_B_PID_PSTFIRM 0x00F7
271 #define PSTFIRM (1<<7)
272 #define AUTO_ANNEX_A (1<<8)
273 #define AUTO_ANNEX_B (1<<9)
283 /* macros for both struct usb_device_id and struct uea_softc */
284 #define UEA_IS_PREFIRM(x) \
285 (!((x)->driver_info & PSTFIRM))
286 #define UEA_CHIP_VERSION(x) \
287 ((x)->driver_info & 0xf)
290 ((x)->annex & ANNEXB)
292 #define INS_TO_USBDEV(ins) ins->usb_dev
294 #define GET_STATUS(data) \
297 #define IS_OPERATIONAL(sc) \
298 ((UEA_CHIP_VERSION(sc) != EAGLE_IV) ? \
299 (GET_STATUS(sc->stats.phy.state) == 2) : \
300 (sc->stats.phy.state == 7))
303 * Set of macros to handle unaligned data in the firmware blob.
304 * The FW_GET_BYTE() macro is provided only for consistency.
307 #define FW_GET_BYTE(p) *((__u8 *) (p))
308 #define FW_GET_WORD(p) le16_to_cpu(get_unaligned((__le16 *) (p)))
309 #define FW_GET_LONG(p) le32_to_cpu(get_unaligned((__le32 *) (p)))
311 #define FW_DIR "ueagle-atm/"
314 #define BULK_TIMEOUT 300
315 #define CTRL_TIMEOUT 1000
317 #define ACK_TIMEOUT msecs_to_jiffies(3000)
319 #define UEA_INTR_IFACE_NO 0
320 #define UEA_US_IFACE_NO 1
321 #define UEA_DS_IFACE_NO 2
323 #define FASTEST_ISO_INTF 8
325 #define UEA_BULK_DATA_PIPE 0x02
326 #define UEA_IDMA_PIPE 0x04
327 #define UEA_INTR_PIPE 0x04
328 #define UEA_ISO_DATA_PIPE 0x08
330 #define UEA_E1_SET_BLOCK 0x0001
331 #define UEA_E4_SET_BLOCK 0x002c
332 #define UEA_SET_MODE 0x0003
333 #define UEA_SET_2183_DATA 0x0004
334 #define UEA_SET_TIMEOUT 0x0011
336 #define UEA_LOOPBACK_OFF 0x0002
337 #define UEA_LOOPBACK_ON 0x0003
338 #define UEA_BOOT_IDMA 0x0006
339 #define UEA_START_RESET 0x0007
340 #define UEA_END_RESET 0x0008
342 #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
343 #define UEA_MPTX_START (0x3fce | 0x4000)
344 #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
345 #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
347 /* block information in eagle4 dsp firmware */
356 } __attribute__ ((packed));
358 #define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
359 #define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
361 #define E4_L1_STRING_HEADER 0x10
362 #define E4_MAX_PAGE_NUMBER 0x58
363 #define E4_NO_SWAPPAGE_HEADERS 0x31
365 /* l1_code is eagle4 dsp firmware format */
367 u8 string_header[E4_L1_STRING_HEADER];
368 u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER];
369 struct block_index page_header[E4_NO_SWAPPAGE_HEADERS];
371 } __attribute__ ((packed));
373 /* structures describing a block within a DSP page */
374 struct block_info_e1 {
379 __le16 wOvl; /* overlay */
381 } __attribute__ ((packed));
382 #define E1_BLOCK_INFO_SIZE 12
384 struct block_info_e4 {
391 } __attribute__ ((packed));
392 #define E4_BLOCK_INFO_SIZE 14
394 #define UEA_BIHDR 0xabcd
395 #define UEA_RESERVED 0xffff
397 /* constants describing cmv type */
398 #define E1_PREAMBLE 0x535c
399 #define E1_MODEMTOHOST 0x01
400 #define E1_HOSTTOMODEM 0x10
402 #define E1_MEMACCESS 0x1
403 #define E1_ADSLDIRECTIVE 0x7
404 #define E1_FUNCTION_TYPE(f) ((f) >> 4)
405 #define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f)
407 #define E4_MEMACCESS 0
408 #define E4_ADSLDIRECTIVE 0xf
409 #define E4_FUNCTION_TYPE(f) ((f) >> 8)
410 #define E4_FUNCTION_SIZE(f) ((f) & 0x0f)
411 #define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f)
414 #define E1_REQUESTREAD 0x0
415 #define E1_REQUESTWRITE 0x1
416 #define E1_REPLYREAD 0x2
417 #define E1_REPLYWRITE 0x3
419 #define E4_REQUESTREAD 0x0
420 #define E4_REQUESTWRITE 0x4
421 #define E4_REPLYREAD (E4_REQUESTREAD | 1)
422 #define E4_REPLYWRITE (E4_REQUESTWRITE | 1)
424 /* for ADSLDIRECTIVE */
425 #define E1_KERNELREADY 0x0
426 #define E1_MODEMREADY 0x1
428 #define E4_KERNELREADY 0x0
429 #define E4_MODEMREADY 0x1
431 #define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
432 #define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | ((st) & 0xf) << 4 | ((s) & 0xf))
434 #define E1_MAKESA(a, b, c, d) \
435 (((c) & 0xff) << 24 | \
436 ((d) & 0xff) << 16 | \
437 ((a) & 0xff) << 8 | \
440 #define E1_GETSA1(a) ((a >> 8) & 0xff)
441 #define E1_GETSA2(a) (a & 0xff)
442 #define E1_GETSA3(a) ((a >> 24) & 0xff)
443 #define E1_GETSA4(a) ((a >> 16) & 0xff)
445 #define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L')
446 #define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G')
447 #define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O')
448 #define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N')
449 #define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E')
450 #define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T')
461 /* structures representing a CMV (Configuration and Management Variable) */
467 __le32 dwSymbolicAddress;
468 __le16 wOffsetAddress;
470 } __attribute__ ((packed));
478 } __attribute__ ((packed));
480 /* structures representing swap information */
481 struct swap_info_e1 {
483 __u8 bOvl; /* overlay */
484 } __attribute__ ((packed));
486 struct swap_info_e4 {
488 } __attribute__ ((packed));
490 /* structures representing interrupt data */
491 #define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
492 #define e1_bOvl u.e1.s1.swapinfo.bOvl
493 #define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo
495 #define INT_LOADSWAPPAGE 0x0001
496 #define INT_INCOMINGCMV 0x0002
500 struct swap_info_e1 swapinfo;
502 } __attribute__ ((packed)) s1;
506 } __attribute__ ((packed)) s2;
507 } __attribute__ ((packed));
511 struct swap_info_e4 swapinfo;
513 } __attribute__ ((packed)) s1;
517 } __attribute__ ((packed)) s2;
518 } __attribute__ ((packed));
528 union intr_data_e1 e1;
529 union intr_data_e4 e4;
531 } __attribute__ ((packed));
533 #define E1_INTR_PKT_SIZE 28
534 #define E4_INTR_PKT_SIZE 64
536 static struct usb_driver uea_driver;
537 static DEFINE_MUTEX(uea_mutex);
538 static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
540 static int modem_index;
541 static unsigned int debug;
542 static unsigned int altsetting[NB_MODEM] = {[0 ... (NB_MODEM - 1)] = FASTEST_ISO_INTF};
543 static int sync_wait[NB_MODEM];
544 static char *cmv_file[NB_MODEM];
545 static int annex[NB_MODEM];
547 module_param(debug, uint, 0644);
548 MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
549 module_param_array(altsetting, uint, NULL, 0644);
550 MODULE_PARM_DESC(altsetting, "alternate setting for incoming traffic: 0=bulk, "
551 "1=isoc slowest, ... , 8=isoc fastest (default)");
552 module_param_array(sync_wait, bool, NULL, 0644);
553 MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
554 module_param_array(cmv_file, charp, NULL, 0644);
555 MODULE_PARM_DESC(cmv_file,
556 "file name with configuration and management variables");
557 module_param_array(annex, uint, NULL, 0644);
558 MODULE_PARM_DESC(annex,
559 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
561 #define uea_wait(sc, cond, timeo) \
563 int _r = wait_event_interruptible_timeout(sc->sync_q, \
564 (cond) || kthread_should_stop(), timeo); \
565 if (kthread_should_stop()) \
570 #define UPDATE_ATM_STAT(type, val) \
572 if (sc->usbatm->atm_dev) \
573 sc->usbatm->atm_dev->type = val; \
576 /* Firmware loading */
577 #define LOAD_INTERNAL 0xA0
578 #define F8051_USBCS 0x7f92
581 * uea_send_modem_cmd - Send a command for pre-firmware devices.
583 static int uea_send_modem_cmd(struct usb_device *usb,
584 u16 addr, u16 size, u8 * buff)
589 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
591 ret = usb_control_msg(usb,
592 usb_sndctrlpipe(usb, 0),
594 USB_DIR_OUT | USB_TYPE_VENDOR |
595 USB_RECIP_DEVICE, addr, 0, xfer_buff,
603 return (ret == size) ? 0 : -EIO;
606 static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *context)
608 struct usb_device *usb = context;
615 uea_err(usb, "firmware is not available\n");
619 pfw = fw_entry->data;
620 size = fw_entry->size;
622 goto err_fw_corrupted;
624 crc = FW_GET_LONG(pfw);
627 if (crc32_be(0, pfw, size) != crc)
628 goto err_fw_corrupted;
631 * Start to upload formware : send reset
634 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
637 uea_err(usb, "modem reset failed with error %d\n", ret);
642 u8 len = FW_GET_BYTE(pfw);
643 u16 add = FW_GET_WORD(pfw + 1);
647 goto err_fw_corrupted;
649 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
651 uea_err(usb, "uploading firmware data failed "
652 "with error %d\n", ret);
659 goto err_fw_corrupted;
662 * Tell the modem we finish : de-assert reset
665 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
667 uea_err(usb, "modem de-assert failed with error %d\n", ret);
669 uea_info(usb, "firmware uploaded\n");
675 uea_err(usb, "firmware is corrupted\n");
681 * uea_load_firmware - Load usb firmware for pre-firmware devices.
683 static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
686 char *fw_name = FW_DIR "eagle.fw";
689 uea_info(usb, "pre-firmware device, uploading firmware\n");
693 fw_name = FW_DIR "adi930.fw";
696 fw_name = FW_DIR "eagleI.fw";
699 fw_name = FW_DIR "eagleII.fw";
702 fw_name = FW_DIR "eagleIII.fw";
705 fw_name = FW_DIR "eagleIV.fw";
709 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware);
711 uea_err(usb, "firmware %s is not available\n", fw_name);
713 uea_info(usb, "loading firmware %s\n", fw_name);
719 /* modem management : dsp firmware, send/read CMV, monitoring statistic
723 * Make sure that the DSP code provided is safe to use.
725 static int check_dsp_e1(u8 *dsp, unsigned int len)
727 u8 pagecount, blockcount;
730 unsigned int i, j, p, pp;
732 pagecount = FW_GET_BYTE(dsp);
735 /* enough space for page offsets? */
736 if (p + 4 * pagecount > len)
739 for (i = 0; i < pagecount; i++) {
741 pageoffset = FW_GET_LONG(dsp + p);
747 /* enough space for blockcount? */
748 if (pageoffset >= len)
752 blockcount = FW_GET_BYTE(dsp + pp);
755 for (j = 0; j < blockcount; j++) {
757 /* enough space for block header? */
761 pp += 2; /* skip blockaddr */
762 blocksize = FW_GET_WORD(dsp + pp);
765 /* enough space for block data? */
766 if (pp + blocksize > len)
776 static int check_dsp_e4(u8 *dsp, int len)
779 struct l1_code *p = (struct l1_code *) dsp;
780 unsigned int sum = p->code - dsp;
785 if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 &&
786 strcmp("STRATIPHY ANEXB", p->string_header) != 0)
789 for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) {
790 struct block_index *blockidx;
791 u8 blockno = p->page_number_to_block_index[i];
792 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
798 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
801 blockidx = &p->page_header[blockno++];
802 if ((u8 *)(blockidx + 1) - dsp >= len)
805 if (le16_to_cpu(blockidx->PageNumber) != i)
808 l = E4_PAGE_BYTES(blockidx->PageSize);
810 l += le32_to_cpu(blockidx->PageOffset);
814 /* zero is zero regardless endianes */
815 } while (blockidx->NotLastBlock);
818 return (sum == len) ? 0 : 1;
822 * send data to the idma pipe
824 static int uea_idma_write(struct uea_softc *sc, void *data, u32 size)
830 xfer_buff = kmemdup(data, size, GFP_KERNEL);
832 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
836 ret = usb_bulk_msg(sc->usb_dev,
837 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
838 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
843 if (size != bytes_read) {
844 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
852 static int request_dsp(struct uea_softc *sc)
857 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
859 dsp_name = FW_DIR "DSP4i.bin";
861 dsp_name = FW_DIR "DSP4p.bin";
862 } else if (UEA_CHIP_VERSION(sc) == ADI930) {
864 dsp_name = FW_DIR "DSP9i.bin";
866 dsp_name = FW_DIR "DSP9p.bin";
869 dsp_name = FW_DIR "DSPei.bin";
871 dsp_name = FW_DIR "DSPep.bin";
874 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
876 uea_err(INS_TO_USBDEV(sc),
877 "requesting firmware %s failed with error %d\n",
882 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
883 ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size);
885 ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size);
888 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
890 release_firmware(sc->dsp_firm);
899 * The uea_load_page() function must be called within a process context
901 static void uea_load_page_e1(struct work_struct *work)
903 struct uea_softc *sc = container_of(work, struct uea_softc, task);
904 u16 pageno = sc->pageno;
906 struct block_info_e1 bi;
909 u8 pagecount, blockcount;
910 u16 blockaddr, blocksize;
914 /* reload firmware when reboot start and it's loaded already */
915 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
916 release_firmware(sc->dsp_firm);
920 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
923 p = sc->dsp_firm->data;
924 pagecount = FW_GET_BYTE(p);
927 if (pageno >= pagecount)
931 pageoffset = FW_GET_LONG(p);
936 p = sc->dsp_firm->data + pageoffset;
937 blockcount = FW_GET_BYTE(p);
940 uea_dbg(INS_TO_USBDEV(sc),
941 "sending %u blocks for DSP page %u\n", blockcount, pageno);
943 bi.wHdr = cpu_to_le16(UEA_BIHDR);
944 bi.wOvl = cpu_to_le16(ovl);
945 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
947 for (i = 0; i < blockcount; i++) {
948 blockaddr = FW_GET_WORD(p);
951 blocksize = FW_GET_WORD(p);
954 bi.wSize = cpu_to_le16(blocksize);
955 bi.wAddress = cpu_to_le16(blockaddr);
956 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
958 /* send block info through the IDMA pipe */
959 if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE))
962 /* send block data through the IDMA pipe */
963 if (uea_idma_write(sc, p, blocksize))
972 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
975 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
978 static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
980 struct block_info_e4 bi;
981 struct block_index *blockidx;
982 struct l1_code *p = (struct l1_code *) sc->dsp_firm->data;
983 u8 blockno = p->page_number_to_block_index[pageno];
985 bi.wHdr = cpu_to_be16(UEA_BIHDR);
987 bi.bPageNumber = pageno;
988 bi.wReserved = cpu_to_be16(UEA_RESERVED);
992 unsigned int blocksize;
994 blockidx = &p->page_header[blockno];
995 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
996 blockoffset = sc->dsp_firm->data + le32_to_cpu(blockidx->PageOffset);
998 bi.dwSize = cpu_to_be32(blocksize);
999 bi.dwAddress = swab32(blockidx->PageAddress);
1001 uea_dbg(INS_TO_USBDEV(sc),
1002 "sending block %u for DSP page %u size %u address %x\n",
1003 blockno, pageno, blocksize, le32_to_cpu(blockidx->PageAddress));
1005 /* send block info through the IDMA pipe */
1006 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1009 /* send block data through the IDMA pipe */
1010 if (uea_idma_write(sc, blockoffset, blocksize))
1014 } while (blockidx->NotLastBlock);
1019 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno);
1023 static void uea_load_page_e4(struct work_struct *work)
1025 struct uea_softc *sc = container_of(work, struct uea_softc, task);
1026 u8 pageno = sc->pageno;
1028 struct block_info_e4 bi;
1031 uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
1033 /* reload firmware when reboot start and it's loaded already */
1034 if (pageno == 0 && sc->dsp_firm) {
1035 release_firmware(sc->dsp_firm);
1036 sc->dsp_firm = NULL;
1039 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
1042 p = (struct l1_code *) sc->dsp_firm->data;
1043 if (pageno >= p->page_header[0].PageNumber) {
1044 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
1049 __uea_load_page_e4(sc, pageno, 0);
1053 uea_dbg(INS_TO_USBDEV(sc),
1054 "sending Main DSP page %u\n", p->page_header[0].PageNumber);
1056 for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) {
1057 if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize))
1058 __uea_load_page_e4(sc, i, 1);
1061 uea_dbg(INS_TO_USBDEV(sc),"sending start bi\n");
1063 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1065 bi.bPageNumber = 0xff;
1066 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1067 bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize));
1068 bi.dwAddress = swab32(p->page_header[0].PageAddress);
1070 /* send block info through the IDMA pipe */
1071 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1072 uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n");
1075 static inline void wake_up_cmv_ack(struct uea_softc *sc)
1077 BUG_ON(sc->cmv_ack);
1079 wake_up(&sc->sync_q);
1082 static inline int wait_cmv_ack(struct uea_softc *sc)
1084 int ret = uea_wait(sc, sc->cmv_ack , ACK_TIMEOUT);
1088 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
1089 jiffies_to_msecs(ret));
1094 return (ret == 0) ? -ETIMEDOUT : 0;
1097 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1099 static int uea_request(struct uea_softc *sc,
1100 u16 value, u16 index, u16 size, void *data)
1105 xfer_buff = kmemdup(data, size, GFP_KERNEL);
1107 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
1111 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
1112 UCDC_SEND_ENCAPSULATED_COMMAND,
1113 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1114 value, index, xfer_buff, size, CTRL_TIMEOUT);
1118 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
1123 uea_err(INS_TO_USBDEV(sc),
1124 "usb_control_msg send only %d bytes (instead of %d)\n",
1132 static int uea_cmv_e1(struct uea_softc *sc,
1133 u8 function, u32 address, u16 offset, u32 data)
1138 uea_enters(INS_TO_USBDEV(sc));
1139 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1140 "offset : 0x%04x, data : 0x%08x\n",
1141 E1_FUNCTION_TYPE(function), E1_FUNCTION_SUBTYPE(function),
1142 E1_GETSA1(address), E1_GETSA2(address), E1_GETSA3(address),
1143 E1_GETSA4(address), offset, data);
1145 /* we send a request, but we expect a reply */
1146 sc->cmv_dsc.e1.function = function | 0x2;
1147 sc->cmv_dsc.e1.idx++;
1148 sc->cmv_dsc.e1.address = address;
1149 sc->cmv_dsc.e1.offset = offset;
1151 cmv.wPreamble = cpu_to_le16(E1_PREAMBLE);
1152 cmv.bDirection = E1_HOSTTOMODEM;
1153 cmv.bFunction = function;
1154 cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx);
1155 put_unaligned(cpu_to_le32(address), &cmv.dwSymbolicAddress);
1156 cmv.wOffsetAddress = cpu_to_le16(offset);
1157 put_unaligned(cpu_to_le32(data >> 16 | data << 16), &cmv.dwData);
1159 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv);
1162 ret = wait_cmv_ack(sc);
1163 uea_leaves(INS_TO_USBDEV(sc));
1167 static int uea_cmv_e4(struct uea_softc *sc,
1168 u16 function, u16 group, u16 address, u16 offset, u32 data)
1173 uea_enters(INS_TO_USBDEV(sc));
1174 memset(&cmv, 0, sizeof(cmv));
1176 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
1177 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1178 E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function),
1179 group, address, offset, data);
1181 /* we send a request, but we expect a reply */
1182 sc->cmv_dsc.e4.function = function | (0x1 << 4);
1183 sc->cmv_dsc.e4.offset = offset;
1184 sc->cmv_dsc.e4.address = address;
1185 sc->cmv_dsc.e4.group = group;
1187 cmv.wFunction = cpu_to_be16(function);
1188 cmv.wGroup = cpu_to_be16(group);
1189 cmv.wAddress = cpu_to_be16(address);
1190 cmv.wOffset = cpu_to_be16(offset);
1191 cmv.dwData[0] = cpu_to_be32(data);
1193 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv);
1196 ret = wait_cmv_ack(sc);
1197 uea_leaves(INS_TO_USBDEV(sc));
1201 static inline int uea_read_cmv_e1(struct uea_softc *sc,
1202 u32 address, u16 offset, u32 *data)
1204 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD),
1205 address, offset, 0);
1207 uea_err(INS_TO_USBDEV(sc),
1208 "reading cmv failed with error %d\n", ret);
1215 static inline int uea_read_cmv_e4(struct uea_softc *sc,
1216 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1218 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTREAD, size),
1219 group, address, offset, 0);
1221 uea_err(INS_TO_USBDEV(sc),
1222 "reading cmv failed with error %d\n", ret);
1225 /* size is in 16-bit word quantities */
1227 *(data + 1) = sc->data1;
1232 static inline int uea_write_cmv_e1(struct uea_softc *sc,
1233 u32 address, u16 offset, u32 data)
1235 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE),
1236 address, offset, data);
1238 uea_err(INS_TO_USBDEV(sc),
1239 "writing cmv failed with error %d\n", ret);
1244 static inline int uea_write_cmv_e4(struct uea_softc *sc,
1245 u8 size, u16 group, u16 address, u16 offset, u32 data)
1247 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTWRITE, size),
1248 group, address, offset, data);
1250 uea_err(INS_TO_USBDEV(sc),
1251 "writing cmv failed with error %d\n", ret);
1256 static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1261 /* in bulk mode the modem have problem with high rate
1262 * changing internal timing could improve things, but the
1263 * value is misterious.
1264 * ADI930 don't support it (-EPIPE error).
1267 if (UEA_CHIP_VERSION(sc) == ADI930 ||
1268 altsetting[sc->modem_index] > 0 ||
1269 sc->stats.phy.dsrate == dsrate)
1272 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1273 timeout = (dsrate <= 1024*1024) ? 0 : 1;
1274 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
1275 uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n",
1276 timeout, ret < 0 ? " failed" : "");
1281 * Monitor the modem and update the stat
1282 * return 0 if everything is ok
1283 * return < 0 if an error occurs (-EAGAIN reboot needed)
1285 static int uea_stat_e1(struct uea_softc *sc)
1290 uea_enters(INS_TO_USBDEV(sc));
1291 data = sc->stats.phy.state;
1293 ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state);
1297 switch (GET_STATUS(sc->stats.phy.state)) {
1298 case 0: /* not yet synchronized */
1299 uea_dbg(INS_TO_USBDEV(sc),
1300 "modem not yet synchronized\n");
1303 case 1: /* initialization */
1304 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1307 case 2: /* operational */
1308 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
1311 case 3: /* fail ... */
1312 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1313 " (may be try other cmv/dsp)\n");
1316 case 4 ... 6: /* test state */
1317 uea_warn(INS_TO_USBDEV(sc),
1318 "modem in test mode - not supported\n");
1321 case 7: /* fast-retain ... */
1322 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
1325 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
1326 GET_STATUS(sc->stats.phy.state));
1330 if (GET_STATUS(data) != 2) {
1331 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1332 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1334 /* release the dsp firmware as it is not needed until
1338 release_firmware(sc->dsp_firm);
1339 sc->dsp_firm = NULL;
1343 /* always update it as atm layer could not be init when we switch to
1346 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1348 /* wake up processes waiting for synchronization */
1349 wake_up(&sc->sync_q);
1351 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags);
1354 sc->stats.phy.mflags |= sc->stats.phy.flags;
1356 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1357 * we check the status again in order to detect the failure earlier
1359 if (sc->stats.phy.flags) {
1360 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1361 sc->stats.phy.flags);
1365 ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data);
1369 uea_set_bulk_timeout(sc, (data >> 16) * 32);
1370 sc->stats.phy.dsrate = (data >> 16) * 32;
1371 sc->stats.phy.usrate = (data & 0xffff) * 32;
1372 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1374 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data);
1377 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
1379 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data);
1382 sc->stats.phy.usattenuation = (data & 0xff) / 2;
1384 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin);
1388 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin);
1392 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow);
1396 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow);
1400 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc);
1404 /* only for atu-c */
1405 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc);
1409 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr);
1413 /* only for atu-c */
1414 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr);
1418 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 8, &sc->stats.phy.vidco);
1422 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 13, &sc->stats.phy.vidcpe);
1429 static int uea_stat_e4(struct uea_softc *sc)
1435 uea_enters(INS_TO_USBDEV(sc));
1436 data = sc->stats.phy.state;
1438 /* XXX only need to be done before operationnal... */
1439 ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state);
1443 switch (sc->stats.phy.state) {
1444 case 0x0: /* not yet synchronized */
1448 uea_dbg(INS_TO_USBDEV(sc), "modem not yet synchronized\n");
1450 case 0x5: /* initialization */
1454 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1456 case 0x2: /* fail ... */
1457 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1458 " (may be try other cmv/dsp)\n");
1460 case 0x7: /* operational */
1463 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n", sc->stats.phy.state);
1468 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1469 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1471 /* release the dsp firmware as it is not needed until
1475 release_firmware(sc->dsp_firm);
1476 sc->dsp_firm = NULL;
1480 /* always update it as atm layer could not be init when we switch to
1483 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1485 /* wake up processes waiting for synchronization */
1486 wake_up(&sc->sync_q);
1488 /* TODO improve this state machine :
1489 * we need some CMV info : what they do and their unit
1490 * we should find the equivalent of eagle3- CMV
1493 ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags);
1496 sc->stats.phy.mflags |= sc->stats.phy.flags;
1498 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1499 * we check the status again in order to detect the failure earlier
1501 if (sc->stats.phy.flags) {
1502 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1503 sc->stats.phy.flags);
1504 if (sc->stats.phy.flags & 1) //delineation LOSS
1506 if (sc->stats.phy.flags & 0x4000) //Reset Flag
1511 /* rate data may be in upper or lower half of 64 bit word, strange */
1512 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr);
1515 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1516 sc->stats.phy.usrate = data / 1000;
1518 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr);
1521 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1522 uea_set_bulk_timeout(sc, data / 1000);
1523 sc->stats.phy.dsrate = data / 1000;
1524 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1526 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data);
1529 sc->stats.phy.dsattenuation = data / 10;
1531 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data);
1534 sc->stats.phy.usattenuation = data / 10;
1536 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data);
1539 sc->stats.phy.dsmargin = data / 2;
1541 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data);
1544 sc->stats.phy.usmargin = data / 10;
1549 static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1551 char file_arr[] = "CMVxy.bin";
1554 /* set proper name corresponding modem version and line type */
1555 if (cmv_file[sc->modem_index] == NULL) {
1556 if (UEA_CHIP_VERSION(sc) == ADI930)
1558 else if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1563 file_arr[4] = IS_ISDN(sc) ? 'i' : 'p';
1566 file = cmv_file[sc->modem_index];
1568 strcpy(cmv_name, FW_DIR);
1569 strlcat(cmv_name, file, FIRMWARE_NAME_MAX);
1571 strlcat(cmv_name, ".v2", FIRMWARE_NAME_MAX);
1574 static int request_cmvs_old(struct uea_softc *sc,
1575 void **cmvs, const struct firmware **fw)
1579 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1581 cmvs_file_name(sc, cmv_name, 1);
1582 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1584 uea_err(INS_TO_USBDEV(sc),
1585 "requesting firmware %s failed with error %d\n",
1590 data = (u8 *) (*fw)->data;
1593 goto err_fw_corrupted;
1595 if (size != *data * sizeof(struct uea_cmvs_v1) + 1)
1596 goto err_fw_corrupted;
1598 *cmvs = (void *)(data + 1);
1602 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1603 release_firmware(*fw);
1607 static int request_cmvs(struct uea_softc *sc,
1608 void **cmvs, const struct firmware **fw, int *ver)
1613 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1615 cmvs_file_name(sc, cmv_name, 2);
1616 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1618 /* if caller can handle old version, try to provide it */
1620 uea_warn(INS_TO_USBDEV(sc), "requesting firmware %s failed, "
1621 "try to get older cmvs\n", cmv_name);
1622 return request_cmvs_old(sc, cmvs, fw);
1624 uea_err(INS_TO_USBDEV(sc),
1625 "requesting firmware %s failed with error %d\n",
1631 data = (u8 *) (*fw)->data;
1632 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1634 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted, "
1635 "try to get older cmvs\n", cmv_name);
1636 release_firmware(*fw);
1637 return request_cmvs_old(sc, cmvs, fw);
1639 goto err_fw_corrupted;
1647 goto err_fw_corrupted;
1649 crc = FW_GET_LONG(data);
1652 if (crc32_be(0, data, size) != crc)
1653 goto err_fw_corrupted;
1655 if (size != *data * sizeof(struct uea_cmvs_v2) + 1)
1656 goto err_fw_corrupted;
1658 *cmvs = (void *) (data + 1);
1662 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1663 release_firmware(*fw);
1667 static int uea_send_cmvs_e1(struct uea_softc *sc)
1671 const struct firmware *cmvs_fw;
1672 int ver = 1; // we can handle v1 cmv firmware version;
1674 /* Enter in R-IDLE (cmv) until instructed otherwise */
1675 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
1679 /* Dump firmware version */
1680 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid);
1683 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1684 sc->stats.phy.firmid);
1687 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1693 struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr;
1695 uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, "
1696 "please update your firmware\n");
1698 for (i = 0; i < len; i++) {
1699 ret = uea_write_cmv_e1(sc, FW_GET_LONG(&cmvs_v1[i].address),
1700 FW_GET_WORD(&cmvs_v1[i].offset),
1701 FW_GET_LONG(&cmvs_v1[i].data));
1705 } else if (ver == 2) {
1706 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1708 for (i = 0; i < len; i++) {
1709 ret = uea_write_cmv_e1(sc, FW_GET_LONG(&cmvs_v2[i].address),
1710 (u16) FW_GET_LONG(&cmvs_v2[i].offset),
1711 FW_GET_LONG(&cmvs_v2[i].data));
1716 /* This realy should not happen */
1717 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1721 /* Enter in R-ACT-REQ */
1722 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1723 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1724 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n");
1726 release_firmware(cmvs_fw);
1730 static int uea_send_cmvs_e4(struct uea_softc *sc)
1734 const struct firmware *cmvs_fw;
1735 int ver = 2; // we can only handle v2 cmv firmware version;
1737 /* Enter in R-IDLE (cmv) until instructed otherwise */
1738 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
1742 /* Dump firmware version */
1743 /* XXX don't read the 3th byte as it is always 6 */
1744 ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid);
1747 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1748 sc->stats.phy.firmid);
1752 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1758 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1760 for (i = 0; i < len; i++) {
1761 ret = uea_write_cmv_e4(sc, 1,
1762 FW_GET_LONG(&cmvs_v2[i].group),
1763 FW_GET_LONG(&cmvs_v2[i].address),
1764 FW_GET_LONG(&cmvs_v2[i].offset),
1765 FW_GET_LONG(&cmvs_v2[i].data));
1770 /* This realy should not happen */
1771 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1775 /* Enter in R-ACT-REQ */
1776 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1777 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1778 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n");
1780 release_firmware(cmvs_fw);
1784 /* Start boot post firmware modem:
1785 * - send reset commands through usb control pipe
1786 * - start workqueue for DSP loading
1787 * - send CMV options to modem
1790 static int uea_start_reset(struct uea_softc *sc)
1792 u16 zero = 0; /* ;-) */
1795 uea_enters(INS_TO_USBDEV(sc));
1796 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1798 /* mask interrupt */
1800 /* We need to set this here because, a ack timeout could have occured,
1801 * but before we start the reboot, the ack occurs and set this to 1.
1802 * So we will failed to wait Ready CMV.
1805 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST);
1807 /* reset statistics */
1808 memset(&sc->stats, 0, sizeof(struct uea_stats));
1810 /* tell the modem that we want to boot in IDMA mode */
1811 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1812 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1814 /* enter reset mode */
1815 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1817 /* original driver use 200ms, but windows driver use 100ms */
1818 ret = uea_wait(sc, 0, msecs_to_jiffies(100));
1822 /* leave reset mode */
1823 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1825 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
1826 /* clear tx and rx mailboxes */
1827 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1828 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1829 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1832 ret = uea_wait(sc, 0, msecs_to_jiffies(1000));
1836 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1837 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1);
1839 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY);
1841 /* demask interrupt */
1844 /* start loading DSP */
1847 queue_work(sc->work_q, &sc->task);
1849 /* wait for modem ready CMV */
1850 ret = wait_cmv_ack(sc);
1854 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1856 ret = sc->send_cmvs(sc);
1861 uea_leaves(INS_TO_USBDEV(sc));
1866 * In case of an error wait 1s before rebooting the modem
1867 * if the modem don't request reboot (-EAGAIN).
1868 * Monitor the modem every 1s.
1871 static int uea_kthread(void *data)
1873 struct uea_softc *sc = data;
1877 uea_enters(INS_TO_USBDEV(sc));
1878 while (!kthread_should_stop()) {
1879 if (ret < 0 || sc->reset)
1880 ret = uea_start_reset(sc);
1884 uea_wait(sc, 0, msecs_to_jiffies(1000));
1887 uea_leaves(INS_TO_USBDEV(sc));
1891 /* Load second usb firmware for ADI930 chip */
1892 static int load_XILINX_firmware(struct uea_softc *sc)
1894 const struct firmware *fw_entry;
1895 int ret, size, u, ln;
1897 char *fw_name = FW_DIR "930-fpga.bin";
1899 uea_enters(INS_TO_USBDEV(sc));
1901 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1903 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1908 pfw = fw_entry->data;
1909 size = fw_entry->size;
1910 if (size != 0x577B) {
1911 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1916 for (u = 0; u < size; u += ln) {
1917 ln = min(size - u, 64);
1918 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1920 uea_err(INS_TO_USBDEV(sc),
1921 "elsa download data failed (%d)\n", ret);
1926 /* finish to send the fpga */
1927 ret = uea_request(sc, 0xe, 1, 0, NULL);
1929 uea_err(INS_TO_USBDEV(sc),
1930 "elsa download data failed (%d)\n", ret);
1934 /* Tell the modem we finish : de-assert reset */
1936 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1938 uea_err(sc->usb_dev, "elsa de-assert failed with error %d\n", ret);
1941 release_firmware(fw_entry);
1943 uea_leaves(INS_TO_USBDEV(sc));
1947 /* The modem send us an ack. First with check if it right */
1948 static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
1950 struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;
1951 struct cmv_e1 *cmv = &intr->u.e1.s2.cmv;
1953 uea_enters(INS_TO_USBDEV(sc));
1954 if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE)
1957 if (cmv->bDirection != E1_MODEMTOHOST)
1960 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1961 * the first MEMACESS cmv. Ignore it...
1963 if (cmv->bFunction != dsc->function) {
1964 if (UEA_CHIP_VERSION(sc) == ADI930
1965 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
1966 cmv->wIndex = cpu_to_le16(dsc->idx);
1967 put_unaligned(cpu_to_le32(dsc->address), &cmv->dwSymbolicAddress);
1968 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
1973 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY)) {
1974 wake_up_cmv_ack(sc);
1975 uea_leaves(INS_TO_USBDEV(sc));
1979 /* in case of MEMACCESS */
1980 if (le16_to_cpu(cmv->wIndex) != dsc->idx ||
1981 le32_to_cpu(get_unaligned(&cmv->dwSymbolicAddress)) != dsc->address ||
1982 le16_to_cpu(cmv->wOffsetAddress) != dsc->offset)
1985 sc->data = le32_to_cpu(get_unaligned(&cmv->dwData));
1986 sc->data = sc->data << 16 | sc->data >> 16;
1988 wake_up_cmv_ack(sc);
1989 uea_leaves(INS_TO_USBDEV(sc));
1993 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
1994 "Function : %d, Subfunction : %d\n",
1995 E1_FUNCTION_TYPE(cmv->bFunction),
1996 E1_FUNCTION_SUBTYPE(cmv->bFunction));
1997 uea_leaves(INS_TO_USBDEV(sc));
2001 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
2002 "wPreamble %d, bDirection %d\n",
2003 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
2004 uea_leaves(INS_TO_USBDEV(sc));
2007 /* The modem send us an ack. First with check if it right */
2008 static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
2010 struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;
2011 struct cmv_e4 *cmv = &intr->u.e4.s2.cmv;
2013 uea_enters(INS_TO_USBDEV(sc));
2014 uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n",
2015 be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction),
2016 be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
2017 be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1]));
2019 if (be16_to_cpu(cmv->wFunction) != dsc->function)
2022 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1)) {
2023 wake_up_cmv_ack(sc);
2024 uea_leaves(INS_TO_USBDEV(sc));
2028 /* in case of MEMACCESS */
2029 if (be16_to_cpu(cmv->wOffset) != dsc->offset ||
2030 be16_to_cpu(cmv->wGroup) != dsc->group ||
2031 be16_to_cpu(cmv->wAddress) != dsc->address)
2034 sc->data = be32_to_cpu(cmv->dwData[0]);
2035 sc->data1 = be32_to_cpu(cmv->dwData[1]);
2036 wake_up_cmv_ack(sc);
2037 uea_leaves(INS_TO_USBDEV(sc));
2041 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
2042 "Function : %d, Subfunction : %d\n",
2043 E4_FUNCTION_TYPE(cmv->wFunction),
2044 E4_FUNCTION_SUBTYPE(cmv->wFunction));
2045 uea_leaves(INS_TO_USBDEV(sc));
2049 static void uea_schedule_load_page_e1(struct uea_softc *sc, struct intr_pkt *intr)
2051 sc->pageno = intr->e1_bSwapPageNo;
2052 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
2053 queue_work(sc->work_q, &sc->task);
2056 static void uea_schedule_load_page_e4(struct uea_softc *sc, struct intr_pkt *intr)
2058 sc->pageno = intr->e4_bSwapPageNo;
2059 queue_work(sc->work_q, &sc->task);
2065 static void uea_intr(struct urb *urb)
2067 struct uea_softc *sc = urb->context;
2068 struct intr_pkt *intr = urb->transfer_buffer;
2069 int status = urb->status;
2071 uea_enters(INS_TO_USBDEV(sc));
2073 if (unlikely(status < 0)) {
2074 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
2079 /* device-to-host interrupt */
2080 if (intr->bType != 0x08 || sc->booting) {
2081 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
2085 switch (le16_to_cpu(intr->wInterrupt)) {
2086 case INT_LOADSWAPPAGE:
2087 sc->schedule_load_page(sc, intr);
2090 case INT_INCOMINGCMV:
2091 sc->dispatch_cmv(sc, intr);
2095 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
2096 le16_to_cpu(intr->wInterrupt));
2100 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
2104 * Start the modem : init the data and start kernel thread
2106 static int uea_boot(struct uea_softc *sc)
2109 struct intr_pkt *intr;
2111 uea_enters(INS_TO_USBDEV(sc));
2113 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2114 size = E4_INTR_PKT_SIZE;
2115 sc->dispatch_cmv = uea_dispatch_cmv_e4;
2116 sc->schedule_load_page = uea_schedule_load_page_e4;
2117 sc->stat = uea_stat_e4;
2118 sc->send_cmvs = uea_send_cmvs_e4;
2119 INIT_WORK(&sc->task, uea_load_page_e4);
2121 size = E1_INTR_PKT_SIZE;
2122 sc->dispatch_cmv = uea_dispatch_cmv_e1;
2123 sc->schedule_load_page = uea_schedule_load_page_e1;
2124 sc->stat = uea_stat_e1;
2125 sc->send_cmvs = uea_send_cmvs_e1;
2126 INIT_WORK(&sc->task, uea_load_page_e1);
2129 init_waitqueue_head(&sc->sync_q);
2131 sc->work_q = create_workqueue("ueagle-dsp");
2133 uea_err(INS_TO_USBDEV(sc), "cannot allocate workqueue\n");
2134 uea_leaves(INS_TO_USBDEV(sc));
2138 if (UEA_CHIP_VERSION(sc) == ADI930)
2139 load_XILINX_firmware(sc);
2141 intr = kmalloc(size, GFP_KERNEL);
2143 uea_err(INS_TO_USBDEV(sc),
2144 "cannot allocate interrupt package\n");
2148 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
2150 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
2154 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
2155 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
2156 intr, size, uea_intr, sc,
2157 sc->usb_dev->actconfig->interface[0]->altsetting[0].
2158 endpoint[0].desc.bInterval);
2160 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2162 uea_err(INS_TO_USBDEV(sc),
2163 "urb submition failed with error %d\n", ret);
2167 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm");
2168 if (sc->kthread == ERR_PTR(-ENOMEM)) {
2169 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2173 uea_leaves(INS_TO_USBDEV(sc));
2177 usb_kill_urb(sc->urb_int);
2179 usb_free_urb(sc->urb_int);
2183 destroy_workqueue(sc->work_q);
2184 uea_leaves(INS_TO_USBDEV(sc));
2189 * Stop the modem : kill kernel thread and free data
2191 static void uea_stop(struct uea_softc *sc)
2194 uea_enters(INS_TO_USBDEV(sc));
2195 ret = kthread_stop(sc->kthread);
2196 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
2198 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
2200 usb_kill_urb(sc->urb_int);
2201 kfree(sc->urb_int->transfer_buffer);
2202 usb_free_urb(sc->urb_int);
2204 /* stop any pending boot process, when no one can schedule work */
2205 destroy_workqueue(sc->work_q);
2208 release_firmware(sc->dsp_firm);
2209 uea_leaves(INS_TO_USBDEV(sc));
2212 /* syfs interface */
2213 static struct uea_softc *dev_to_uea(struct device *dev)
2215 struct usb_interface *intf;
2216 struct usbatm_data *usbatm;
2218 intf = to_usb_interface(dev);
2222 usbatm = usb_get_intfdata(intf);
2226 return usbatm->driver_data;
2229 static ssize_t read_status(struct device *dev, struct device_attribute *attr,
2233 struct uea_softc *sc;
2235 mutex_lock(&uea_mutex);
2236 sc = dev_to_uea(dev);
2239 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
2241 mutex_unlock(&uea_mutex);
2245 static ssize_t reboot(struct device *dev, struct device_attribute *attr,
2246 const char *buf, size_t count)
2249 struct uea_softc *sc;
2251 mutex_lock(&uea_mutex);
2252 sc = dev_to_uea(dev);
2258 mutex_unlock(&uea_mutex);
2262 static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot);
2264 static ssize_t read_human_status(struct device *dev, struct device_attribute *attr,
2269 struct uea_softc *sc;
2271 mutex_lock(&uea_mutex);
2272 sc = dev_to_uea(dev);
2276 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2277 switch (sc->stats.phy.state) {
2278 case 0x0: /* not yet synchronized */
2284 case 0x5: /* initialization */
2290 case 0x7: /* operational */
2293 case 0x2: /* fail ... */
2296 default: /* unknown */
2301 modem_state = GET_STATUS(sc->stats.phy.state);
2303 switch (modem_state) {
2305 ret = sprintf(buf, "Modem is booting\n");
2308 ret = sprintf(buf, "Modem is initializing\n");
2311 ret = sprintf(buf, "Modem is operational\n");
2314 ret = sprintf(buf, "Modem synchronization failed\n");
2317 ret = sprintf(buf, "Modem state is unknown\n");
2321 mutex_unlock(&uea_mutex);
2325 static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, read_human_status, NULL);
2327 static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2331 struct uea_softc *sc;
2332 char *delin = "GOOD";
2334 mutex_lock(&uea_mutex);
2335 sc = dev_to_uea(dev);
2339 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2340 if (sc->stats.phy.flags & 0x4000)
2342 else if (sc->stats.phy.flags & 0x0001)
2345 if (sc->stats.phy.flags & 0x0C00)
2347 else if (sc->stats.phy.flags & 0x0030)
2351 ret = sprintf(buf, "%s\n", delin);
2353 mutex_unlock(&uea_mutex);
2357 static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL);
2359 #define UEA_ATTR(name, reset) \
2361 static ssize_t read_##name(struct device *dev, \
2362 struct device_attribute *attr, char *buf) \
2364 int ret = -ENODEV; \
2365 struct uea_softc *sc; \
2367 mutex_lock(&uea_mutex); \
2368 sc = dev_to_uea(dev); \
2371 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2373 sc->stats.phy.name = 0; \
2375 mutex_unlock(&uea_mutex); \
2379 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2381 UEA_ATTR(mflags, 1);
2382 UEA_ATTR(vidcpe, 0);
2383 UEA_ATTR(usrate, 0);
2384 UEA_ATTR(dsrate, 0);
2385 UEA_ATTR(usattenuation, 0);
2386 UEA_ATTR(dsattenuation, 0);
2387 UEA_ATTR(usmargin, 0);
2388 UEA_ATTR(dsmargin, 0);
2389 UEA_ATTR(txflow, 0);
2390 UEA_ATTR(rxflow, 0);
2391 UEA_ATTR(uscorr, 0);
2392 UEA_ATTR(dscorr, 0);
2395 UEA_ATTR(firmid, 0);
2397 /* Retrieve the device End System Identifier (MAC) */
2399 #define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
2400 static int uea_getesi(struct uea_softc *sc, u_char * esi)
2402 unsigned char mac_str[2 * ETH_ALEN + 1];
2405 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
2406 sizeof(mac_str)) != 2 * ETH_ALEN)
2409 for (i = 0; i < ETH_ALEN; i++)
2410 esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]);
2416 static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
2418 struct uea_softc *sc = usbatm->driver_data;
2420 return uea_getesi(sc, atm_dev->esi);
2423 static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
2425 struct uea_softc *sc = usbatm->driver_data;
2427 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
2433 static int claim_interface(struct usb_device *usb_dev,
2434 struct usbatm_data *usbatm, int ifnum)
2437 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
2440 uea_err(usb_dev, "interface %d not found\n", ifnum);
2444 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
2446 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
2451 static struct attribute *attrs[] = {
2452 &dev_attr_stat_status.attr,
2453 &dev_attr_stat_mflags.attr,
2454 &dev_attr_stat_human_status.attr,
2455 &dev_attr_stat_delin.attr,
2456 &dev_attr_stat_vidcpe.attr,
2457 &dev_attr_stat_usrate.attr,
2458 &dev_attr_stat_dsrate.attr,
2459 &dev_attr_stat_usattenuation.attr,
2460 &dev_attr_stat_dsattenuation.attr,
2461 &dev_attr_stat_usmargin.attr,
2462 &dev_attr_stat_dsmargin.attr,
2463 &dev_attr_stat_txflow.attr,
2464 &dev_attr_stat_rxflow.attr,
2465 &dev_attr_stat_uscorr.attr,
2466 &dev_attr_stat_dscorr.attr,
2467 &dev_attr_stat_usunc.attr,
2468 &dev_attr_stat_dsunc.attr,
2469 &dev_attr_stat_firmid.attr,
2472 static struct attribute_group attr_grp = {
2476 static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
2477 const struct usb_device_id *id)
2479 struct usb_device *usb = interface_to_usbdev(intf);
2480 struct uea_softc *sc;
2481 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
2486 /* interface 0 is for firmware/monitoring */
2487 if (ifnum != UEA_INTR_IFACE_NO)
2490 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
2492 /* interface 1 is for outbound traffic */
2493 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
2497 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
2498 if (UEA_CHIP_VERSION(id) != ADI930) {
2499 /* interface 2 is for inbound traffic */
2500 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
2505 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
2507 uea_err(usb, "uea_init: not enough memory !\n");
2512 usbatm->driver_data = sc;
2513 sc->usbatm = usbatm;
2514 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
2515 sc->driver_info = id->driver_info;
2517 /* first try to use module parameter */
2518 if (annex[sc->modem_index] == 1)
2520 else if (annex[sc->modem_index] == 2)
2522 /* try to autodetect annex */
2523 else if (sc->driver_info & AUTO_ANNEX_A)
2525 else if (sc->driver_info & AUTO_ANNEX_B)
2528 sc->annex = (le16_to_cpu(sc->usb_dev->descriptor.bcdDevice) & 0x80)?ANNEXB:ANNEXA;
2530 alt = altsetting[sc->modem_index];
2531 /* ADI930 don't support iso */
2532 if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) {
2533 if (alt <= 8 && usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) {
2534 uea_dbg(usb, "set alternate %u for 2 interface\n", alt);
2535 uea_info(usb, "using iso mode\n");
2536 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
2538 uea_err(usb, "setting alternate %u failed for "
2539 "2 interface, using bulk mode\n", alt);
2543 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
2554 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2560 static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
2562 struct uea_softc *sc = usbatm->driver_data;
2564 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2569 static struct usbatm_driver uea_usbatm_driver = {
2570 .driver_name = "ueagle-atm",
2572 .atm_start = uea_atm_open,
2573 .unbind = uea_unbind,
2574 .heavy_init = uea_heavy,
2575 .bulk_in = UEA_BULK_DATA_PIPE,
2576 .bulk_out = UEA_BULK_DATA_PIPE,
2577 .isoc_in = UEA_ISO_DATA_PIPE,
2580 static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2582 struct usb_device *usb = interface_to_usbdev(intf);
2585 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2586 le16_to_cpu(usb->descriptor.idVendor),
2587 le16_to_cpu(usb->descriptor.idProduct),
2588 le16_to_cpu(usb->descriptor.bcdDevice),
2589 chip_name[UEA_CHIP_VERSION(id)]);
2591 usb_reset_device(usb);
2593 if (UEA_IS_PREFIRM(id))
2594 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2596 return usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2599 static void uea_disconnect(struct usb_interface *intf)
2601 struct usb_device *usb = interface_to_usbdev(intf);
2602 int ifnum = intf->altsetting->desc.bInterfaceNumber;
2605 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2606 * Pre-firmware device has one interface
2608 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
2609 mutex_lock(&uea_mutex);
2610 usbatm_usb_disconnect(intf);
2611 mutex_unlock(&uea_mutex);
2612 uea_info(usb, "ADSL device removed\n");
2619 * List of supported VID/PID
2621 static const struct usb_device_id uea_ids[] = {
2622 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
2623 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
2624 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2625 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
2626 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2627 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
2628 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2629 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
2630 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM), .driver_info = EAGLE_III | PREFIRM},
2631 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM), .driver_info = EAGLE_III | PSTFIRM},
2632 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM), .driver_info = EAGLE_IV | PREFIRM},
2633 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM), .driver_info = EAGLE_IV | PSTFIRM},
2634 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2635 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2636 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2637 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2638 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2639 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A},
2640 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2641 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B},
2642 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
2643 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
2644 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM), .driver_info = ADI930 | PREFIRM},
2645 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM), .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A},
2646 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM), .driver_info = ADI930 | PREFIRM},
2647 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM), .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B},
2648 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2649 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2650 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2651 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2652 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
2653 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2654 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
2655 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2660 * USB driver descriptor
2662 static struct usb_driver uea_driver = {
2663 .name = "ueagle-atm",
2664 .id_table = uea_ids,
2666 .disconnect = uea_disconnect,
2669 MODULE_DEVICE_TABLE(usb, uea_ids);
2672 * uea_init - Initialize the module.
2673 * Register to USB subsystem
2675 static int __init uea_init(void)
2677 printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n");
2679 usb_register(&uea_driver);
2684 module_init(uea_init);
2687 * uea_exit - Destroy module
2688 * Deregister with USB subsystem
2690 static void __exit uea_exit(void)
2693 * This calls automatically the uea_disconnect method if necessary:
2695 usb_deregister(&uea_driver);
2697 printk(KERN_INFO "[ueagle-atm] driver unloaded\n");
2700 module_exit(uea_exit);
2702 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2703 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2704 MODULE_LICENSE("Dual BSD/GPL");