2 * Copyright (c) 2003, 2004
3 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
5 * Copyright (c) 2005 Matthieu Castet <castet.matthieu@free.fr>
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice unmodified, this list of conditions, and the following
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * This program is free software; you can redistribute it and/or
37 * modify it under the terms of the GNU General Public License
38 * as published by the Free Software Foundation; either version 2
39 * of the License, or (at your option) any later version.
41 * This program is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU General Public License for more details.
46 * You should have received a copy of the GNU General Public License
47 * along with this program; if not, write to the Free Software
48 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
51 * HISTORY : some part of the code was base on ueagle 1.3 BSD driver,
52 * Damien Bergamini agree to put his code under a DUAL GPL/BSD license.
54 * The rest of the code was was rewritten from scratch.
57 #include <linux/module.h>
58 #include <linux/moduleparam.h>
59 #include <linux/init.h>
60 #include <linux/crc32.h>
61 #include <linux/usb.h>
62 #include <linux/firmware.h>
63 #include <linux/ctype.h>
64 #include <linux/sched.h>
65 #include <linux/kthread.h>
66 #include <linux/version.h>
67 #include <linux/mutex.h>
68 #include <linux/freezer.h>
70 #include <asm/unaligned.h>
74 #define EAGLEUSBVERSION "ueagle 1.4"
80 #define uea_dbg(usb_dev, format, args...) \
83 dev_dbg(&(usb_dev)->dev, \
84 "[ueagle-atm dbg] %s: " format, \
85 __FUNCTION__, ##args); \
88 #define uea_vdbg(usb_dev, format, args...) \
91 dev_dbg(&(usb_dev)->dev, \
92 "[ueagle-atm vdbg] " format, ##args); \
95 #define uea_enters(usb_dev) \
96 uea_vdbg(usb_dev, "entering %s\n", __FUNCTION__)
98 #define uea_leaves(usb_dev) \
99 uea_vdbg(usb_dev, "leaving %s\n", __FUNCTION__)
101 #define uea_err(usb_dev, format,args...) \
102 dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args)
104 #define uea_warn(usb_dev, format,args...) \
105 dev_warn(&(usb_dev)->dev ,"[Ueagle-atm] " format, ##args)
107 #define uea_info(usb_dev, format,args...) \
108 dev_info(&(usb_dev)->dev ,"[ueagle-atm] " format, ##args)
112 /* cmv's from firmware */
117 } __attribute__ ((packed));
124 } __attribute__ ((packed));
126 /* information about currently processed cmv */
142 struct cmv_dsc_e1 e1;
143 struct cmv_dsc_e4 e4;
147 struct usb_device *usb_dev;
148 struct usbatm_data *usbatm;
151 unsigned int driver_info;
159 wait_queue_head_t sync_q;
161 struct task_struct *kthread;
164 wait_queue_head_t cmv_ack_wait;
167 union cmv_dsc cmv_dsc;
169 struct work_struct task;
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 UPDATE_ATM_STAT(type, val) \
563 if (sc->usbatm->atm_dev) \
564 sc->usbatm->atm_dev->type = val; \
567 /* Firmware loading */
568 #define LOAD_INTERNAL 0xA0
569 #define F8051_USBCS 0x7f92
572 * uea_send_modem_cmd - Send a command for pre-firmware devices.
574 static int uea_send_modem_cmd(struct usb_device *usb,
575 u16 addr, u16 size, u8 * buff)
580 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
582 ret = usb_control_msg(usb,
583 usb_sndctrlpipe(usb, 0),
585 USB_DIR_OUT | USB_TYPE_VENDOR |
586 USB_RECIP_DEVICE, addr, 0, xfer_buff,
594 return (ret == size) ? 0 : -EIO;
597 static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *context)
599 struct usb_device *usb = context;
606 uea_err(usb, "firmware is not available\n");
610 pfw = fw_entry->data;
611 size = fw_entry->size;
613 goto err_fw_corrupted;
615 crc = FW_GET_LONG(pfw);
618 if (crc32_be(0, pfw, size) != crc)
619 goto err_fw_corrupted;
622 * Start to upload formware : send reset
625 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
628 uea_err(usb, "modem reset failed with error %d\n", ret);
633 u8 len = FW_GET_BYTE(pfw);
634 u16 add = FW_GET_WORD(pfw + 1);
638 goto err_fw_corrupted;
640 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
642 uea_err(usb, "uploading firmware data failed "
643 "with error %d\n", ret);
650 goto err_fw_corrupted;
653 * Tell the modem we finish : de-assert reset
656 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
658 uea_err(usb, "modem de-assert failed with error %d\n", ret);
660 uea_info(usb, "firmware uploaded\n");
666 uea_err(usb, "firmware is corrupted\n");
672 * uea_load_firmware - Load usb firmware for pre-firmware devices.
674 static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
677 char *fw_name = FW_DIR "eagle.fw";
680 uea_info(usb, "pre-firmware device, uploading firmware\n");
684 fw_name = FW_DIR "adi930.fw";
687 fw_name = FW_DIR "eagleI.fw";
690 fw_name = FW_DIR "eagleII.fw";
693 fw_name = FW_DIR "eagleIII.fw";
696 fw_name = FW_DIR "eagleIV.fw";
700 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware);
702 uea_err(usb, "firmware %s is not available\n", fw_name);
704 uea_info(usb, "loading firmware %s\n", fw_name);
710 /* modem management : dsp firmware, send/read CMV, monitoring statistic
714 * Make sure that the DSP code provided is safe to use.
716 static int check_dsp_e1(u8 *dsp, unsigned int len)
718 u8 pagecount, blockcount;
721 unsigned int i, j, p, pp;
723 pagecount = FW_GET_BYTE(dsp);
726 /* enough space for page offsets? */
727 if (p + 4 * pagecount > len)
730 for (i = 0; i < pagecount; i++) {
732 pageoffset = FW_GET_LONG(dsp + p);
738 /* enough space for blockcount? */
739 if (pageoffset >= len)
743 blockcount = FW_GET_BYTE(dsp + pp);
746 for (j = 0; j < blockcount; j++) {
748 /* enough space for block header? */
752 pp += 2; /* skip blockaddr */
753 blocksize = FW_GET_WORD(dsp + pp);
756 /* enough space for block data? */
757 if (pp + blocksize > len)
767 static int check_dsp_e4(u8 *dsp, int len)
770 struct l1_code *p = (struct l1_code *) dsp;
771 unsigned int sum = p->code - dsp;
776 if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 &&
777 strcmp("STRATIPHY ANEXB", p->string_header) != 0)
780 for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) {
781 struct block_index *blockidx;
782 u8 blockno = p->page_number_to_block_index[i];
783 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
789 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
792 blockidx = &p->page_header[blockno++];
793 if ((u8 *)(blockidx + 1) - dsp >= len)
796 if (le16_to_cpu(blockidx->PageNumber) != i)
799 l = E4_PAGE_BYTES(blockidx->PageSize);
801 l += le32_to_cpu(blockidx->PageOffset);
805 /* zero is zero regardless endianes */
806 } while (blockidx->NotLastBlock);
809 return (sum == len) ? 0 : 1;
813 * send data to the idma pipe
815 static int uea_idma_write(struct uea_softc *sc, void *data, u32 size)
821 xfer_buff = kmemdup(data, size, GFP_KERNEL);
823 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
827 ret = usb_bulk_msg(sc->usb_dev,
828 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
829 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
834 if (size != bytes_read) {
835 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
843 static int request_dsp(struct uea_softc *sc)
848 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
850 dsp_name = FW_DIR "DSP4i.bin";
852 dsp_name = FW_DIR "DSP4p.bin";
853 } else if (UEA_CHIP_VERSION(sc) == ADI930) {
855 dsp_name = FW_DIR "DSP9i.bin";
857 dsp_name = FW_DIR "DSP9p.bin";
860 dsp_name = FW_DIR "DSPei.bin";
862 dsp_name = FW_DIR "DSPep.bin";
865 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
867 uea_err(INS_TO_USBDEV(sc),
868 "requesting firmware %s failed with error %d\n",
873 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
874 ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size);
876 ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size);
879 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
881 release_firmware(sc->dsp_firm);
890 * The uea_load_page() function must be called within a process context
892 static void uea_load_page_e1(struct work_struct *work)
894 struct uea_softc *sc = container_of(work, struct uea_softc, task);
895 u16 pageno = sc->pageno;
897 struct block_info_e1 bi;
900 u8 pagecount, blockcount;
901 u16 blockaddr, blocksize;
905 /* reload firmware when reboot start and it's loaded already */
906 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
907 release_firmware(sc->dsp_firm);
911 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
914 p = sc->dsp_firm->data;
915 pagecount = FW_GET_BYTE(p);
918 if (pageno >= pagecount)
922 pageoffset = FW_GET_LONG(p);
927 p = sc->dsp_firm->data + pageoffset;
928 blockcount = FW_GET_BYTE(p);
931 uea_dbg(INS_TO_USBDEV(sc),
932 "sending %u blocks for DSP page %u\n", blockcount, pageno);
934 bi.wHdr = cpu_to_le16(UEA_BIHDR);
935 bi.wOvl = cpu_to_le16(ovl);
936 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
938 for (i = 0; i < blockcount; i++) {
939 blockaddr = FW_GET_WORD(p);
942 blocksize = FW_GET_WORD(p);
945 bi.wSize = cpu_to_le16(blocksize);
946 bi.wAddress = cpu_to_le16(blockaddr);
947 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
949 /* send block info through the IDMA pipe */
950 if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE))
953 /* send block data through the IDMA pipe */
954 if (uea_idma_write(sc, p, blocksize))
963 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
966 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
969 static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
971 struct block_info_e4 bi;
972 struct block_index *blockidx;
973 struct l1_code *p = (struct l1_code *) sc->dsp_firm->data;
974 u8 blockno = p->page_number_to_block_index[pageno];
976 bi.wHdr = cpu_to_be16(UEA_BIHDR);
978 bi.bPageNumber = pageno;
979 bi.wReserved = cpu_to_be16(UEA_RESERVED);
983 unsigned int blocksize;
985 blockidx = &p->page_header[blockno];
986 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
987 blockoffset = sc->dsp_firm->data + le32_to_cpu(blockidx->PageOffset);
989 bi.dwSize = cpu_to_be32(blocksize);
990 bi.dwAddress = swab32(blockidx->PageAddress);
992 uea_dbg(INS_TO_USBDEV(sc),
993 "sending block %u for DSP page %u size %u adress %x\n",
994 blockno, pageno, blocksize, le32_to_cpu(blockidx->PageAddress));
996 /* send block info through the IDMA pipe */
997 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1000 /* send block data through the IDMA pipe */
1001 if (uea_idma_write(sc, blockoffset, blocksize))
1005 } while (blockidx->NotLastBlock);
1010 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno);
1014 static void uea_load_page_e4(struct work_struct *work)
1016 struct uea_softc *sc = container_of(work, struct uea_softc, task);
1017 u8 pageno = sc->pageno;
1019 struct block_info_e4 bi;
1022 uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
1024 /* reload firmware when reboot start and it's loaded already */
1025 if (pageno == 0 && sc->dsp_firm) {
1026 release_firmware(sc->dsp_firm);
1027 sc->dsp_firm = NULL;
1030 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
1033 p = (struct l1_code *) sc->dsp_firm->data;
1034 if (pageno >= p->page_header[0].PageNumber) {
1035 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
1040 __uea_load_page_e4(sc, pageno, 0);
1044 uea_dbg(INS_TO_USBDEV(sc),
1045 "sending Main DSP page %u\n", p->page_header[0].PageNumber);
1047 for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) {
1048 if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize))
1049 __uea_load_page_e4(sc, i, 1);
1052 uea_dbg(INS_TO_USBDEV(sc),"sending start bi\n");
1054 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1056 bi.bPageNumber = 0xff;
1057 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1058 bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize));
1059 bi.dwAddress = swab32(p->page_header[0].PageAddress);
1061 /* send block info through the IDMA pipe */
1062 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1063 uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n");
1066 static inline void wake_up_cmv_ack(struct uea_softc *sc)
1068 BUG_ON(sc->cmv_ack);
1070 wake_up(&sc->cmv_ack_wait);
1073 static inline int wait_cmv_ack(struct uea_softc *sc)
1075 int ret = wait_event_interruptible_timeout(sc->cmv_ack_wait,
1076 sc->cmv_ack, ACK_TIMEOUT);
1079 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
1080 jiffies_to_msecs(ret));
1085 return (ret == 0) ? -ETIMEDOUT : 0;
1088 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1090 static int uea_request(struct uea_softc *sc,
1091 u16 value, u16 index, u16 size, void *data)
1096 xfer_buff = kmemdup(data, size, GFP_KERNEL);
1098 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
1102 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
1103 UCDC_SEND_ENCAPSULATED_COMMAND,
1104 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1105 value, index, xfer_buff, size, CTRL_TIMEOUT);
1109 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
1114 uea_err(INS_TO_USBDEV(sc),
1115 "usb_control_msg send only %d bytes (instead of %d)\n",
1123 static int uea_cmv_e1(struct uea_softc *sc,
1124 u8 function, u32 address, u16 offset, u32 data)
1129 uea_enters(INS_TO_USBDEV(sc));
1130 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1131 "offset : 0x%04x, data : 0x%08x\n",
1132 E1_FUNCTION_TYPE(function), E1_FUNCTION_SUBTYPE(function),
1133 E1_GETSA1(address), E1_GETSA2(address), E1_GETSA3(address),
1134 E1_GETSA4(address), offset, data);
1136 /* we send a request, but we expect a reply */
1137 sc->cmv_dsc.e1.function = function | 0x2;
1138 sc->cmv_dsc.e1.idx++;
1139 sc->cmv_dsc.e1.address = address;
1140 sc->cmv_dsc.e1.offset = offset;
1142 cmv.wPreamble = cpu_to_le16(E1_PREAMBLE);
1143 cmv.bDirection = E1_HOSTTOMODEM;
1144 cmv.bFunction = function;
1145 cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx);
1146 put_unaligned(cpu_to_le32(address), &cmv.dwSymbolicAddress);
1147 cmv.wOffsetAddress = cpu_to_le16(offset);
1148 put_unaligned(cpu_to_le32(data >> 16 | data << 16), &cmv.dwData);
1150 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv);
1153 ret = wait_cmv_ack(sc);
1154 uea_leaves(INS_TO_USBDEV(sc));
1158 static int uea_cmv_e4(struct uea_softc *sc,
1159 u16 function, u16 group, u16 address, u16 offset, u32 data)
1164 uea_enters(INS_TO_USBDEV(sc));
1165 memset(&cmv, 0, sizeof(cmv));
1167 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
1168 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1169 E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function),
1170 group, address, offset, data);
1172 /* we send a request, but we expect a reply */
1173 sc->cmv_dsc.e4.function = function | (0x1 << 4);
1174 sc->cmv_dsc.e4.offset = offset;
1175 sc->cmv_dsc.e4.address = address;
1176 sc->cmv_dsc.e4.group = group;
1178 cmv.wFunction = cpu_to_be16(function);
1179 cmv.wGroup = cpu_to_be16(group);
1180 cmv.wAddress = cpu_to_be16(address);
1181 cmv.wOffset = cpu_to_be16(offset);
1182 cmv.dwData[0] = cpu_to_be32(data);
1184 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv);
1187 ret = wait_cmv_ack(sc);
1188 uea_leaves(INS_TO_USBDEV(sc));
1192 static inline int uea_read_cmv_e1(struct uea_softc *sc,
1193 u32 address, u16 offset, u32 *data)
1195 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD),
1196 address, offset, 0);
1198 uea_err(INS_TO_USBDEV(sc),
1199 "reading cmv failed with error %d\n", ret);
1206 static inline int uea_read_cmv_e4(struct uea_softc *sc,
1207 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1209 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTREAD, size),
1210 group, address, offset, 0);
1212 uea_err(INS_TO_USBDEV(sc),
1213 "reading cmv failed with error %d\n", ret);
1216 /* size is in 16-bit word quantities */
1218 *(data + 1) = sc->data1;
1223 static inline int uea_write_cmv_e1(struct uea_softc *sc,
1224 u32 address, u16 offset, u32 data)
1226 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE),
1227 address, offset, data);
1229 uea_err(INS_TO_USBDEV(sc),
1230 "writing cmv failed with error %d\n", ret);
1235 static inline int uea_write_cmv_e4(struct uea_softc *sc,
1236 u8 size, u16 group, u16 address, u16 offset, u32 data)
1238 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTWRITE, size),
1239 group, address, offset, data);
1241 uea_err(INS_TO_USBDEV(sc),
1242 "writing cmv failed with error %d\n", ret);
1247 static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1252 /* in bulk mode the modem have problem with high rate
1253 * changing internal timing could improve things, but the
1254 * value is misterious.
1255 * ADI930 don't support it (-EPIPE error).
1258 if (UEA_CHIP_VERSION(sc) == ADI930 ||
1259 altsetting[sc->modem_index] > 0 ||
1260 sc->stats.phy.dsrate == dsrate)
1263 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1264 timeout = (dsrate <= 1024*1024) ? 0 : 1;
1265 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
1266 uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n",
1267 timeout, ret < 0 ? " failed" : "");
1272 * Monitor the modem and update the stat
1273 * return 0 if everything is ok
1274 * return < 0 if an error occurs (-EAGAIN reboot needed)
1276 static int uea_stat_e1(struct uea_softc *sc)
1281 uea_enters(INS_TO_USBDEV(sc));
1282 data = sc->stats.phy.state;
1284 ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state);
1288 switch (GET_STATUS(sc->stats.phy.state)) {
1289 case 0: /* not yet synchronized */
1290 uea_dbg(INS_TO_USBDEV(sc),
1291 "modem not yet synchronized\n");
1294 case 1: /* initialization */
1295 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1298 case 2: /* operational */
1299 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
1302 case 3: /* fail ... */
1303 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1304 " (may be try other cmv/dsp)\n");
1307 case 4 ... 6: /* test state */
1308 uea_warn(INS_TO_USBDEV(sc),
1309 "modem in test mode - not supported\n");
1312 case 7: /* fast-retain ... */
1313 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
1316 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
1317 GET_STATUS(sc->stats.phy.state));
1321 if (GET_STATUS(data) != 2) {
1322 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1323 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1325 /* release the dsp firmware as it is not needed until
1329 release_firmware(sc->dsp_firm);
1330 sc->dsp_firm = NULL;
1334 /* always update it as atm layer could not be init when we switch to
1337 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1339 /* wake up processes waiting for synchronization */
1340 wake_up(&sc->sync_q);
1342 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags);
1345 sc->stats.phy.mflags |= sc->stats.phy.flags;
1347 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1348 * we check the status again in order to detect the failure earlier
1350 if (sc->stats.phy.flags) {
1351 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1352 sc->stats.phy.flags);
1356 ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data);
1360 uea_set_bulk_timeout(sc, (data >> 16) * 32);
1361 sc->stats.phy.dsrate = (data >> 16) * 32;
1362 sc->stats.phy.usrate = (data & 0xffff) * 32;
1363 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1365 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data);
1368 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
1370 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data);
1373 sc->stats.phy.usattenuation = (data & 0xff) / 2;
1375 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin);
1379 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin);
1383 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow);
1387 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow);
1391 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc);
1395 /* only for atu-c */
1396 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc);
1400 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr);
1404 /* only for atu-c */
1405 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr);
1409 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 8, &sc->stats.phy.vidco);
1413 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 13, &sc->stats.phy.vidcpe);
1420 static int uea_stat_e4(struct uea_softc *sc)
1426 uea_enters(INS_TO_USBDEV(sc));
1427 data = sc->stats.phy.state;
1429 /* XXX only need to be done before operationnal... */
1430 ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state);
1434 switch (sc->stats.phy.state) {
1435 case 0x0: /* not yet synchronized */
1439 uea_dbg(INS_TO_USBDEV(sc), "modem not yet synchronized\n");
1441 case 0x5: /* initialization */
1445 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1447 case 0x2: /* fail ... */
1448 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1449 " (may be try other cmv/dsp)\n");
1451 case 0x7: /* operational */
1454 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n", sc->stats.phy.state);
1459 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1460 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1462 /* release the dsp firmware as it is not needed until
1466 release_firmware(sc->dsp_firm);
1467 sc->dsp_firm = NULL;
1471 /* always update it as atm layer could not be init when we switch to
1474 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1476 /* wake up processes waiting for synchronization */
1477 wake_up(&sc->sync_q);
1479 /* TODO improve this state machine :
1480 * we need some CMV info : what they do and their unit
1481 * we should find the equivalent of eagle3- CMV
1484 ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags);
1487 sc->stats.phy.mflags |= sc->stats.phy.flags;
1489 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1490 * we check the status again in order to detect the failure earlier
1492 if (sc->stats.phy.flags) {
1493 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1494 sc->stats.phy.flags);
1495 if (sc->stats.phy.flags & 1) //delineation LOSS
1497 if (sc->stats.phy.flags & 0x4000) //Reset Flag
1502 /* rate data may be in upper or lower half of 64 bit word, strange */
1503 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr);
1506 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1507 sc->stats.phy.usrate = data / 1000;
1509 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr);
1512 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1513 uea_set_bulk_timeout(sc, data / 1000);
1514 sc->stats.phy.dsrate = data / 1000;
1515 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1517 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data);
1520 sc->stats.phy.dsattenuation = data / 10;
1522 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data);
1525 sc->stats.phy.usattenuation = data / 10;
1527 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data);
1530 sc->stats.phy.dsmargin = data / 2;
1532 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data);
1535 sc->stats.phy.usmargin = data / 10;
1540 static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1542 char file_arr[] = "CMVxy.bin";
1545 /* set proper name corresponding modem version and line type */
1546 if (cmv_file[sc->modem_index] == NULL) {
1547 if (UEA_CHIP_VERSION(sc) == ADI930)
1549 else if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1554 file_arr[4] = IS_ISDN(sc) ? 'i' : 'p';
1557 file = cmv_file[sc->modem_index];
1559 strcpy(cmv_name, FW_DIR);
1560 strlcat(cmv_name, file, FIRMWARE_NAME_MAX);
1562 strlcat(cmv_name, ".v2", FIRMWARE_NAME_MAX);
1565 static int request_cmvs_old(struct uea_softc *sc,
1566 void **cmvs, const struct firmware **fw)
1570 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1572 cmvs_file_name(sc, cmv_name, 1);
1573 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1575 uea_err(INS_TO_USBDEV(sc),
1576 "requesting firmware %s failed with error %d\n",
1581 data = (u8 *) (*fw)->data;
1584 goto err_fw_corrupted;
1586 if (size != *data * sizeof(struct uea_cmvs_v1) + 1)
1587 goto err_fw_corrupted;
1589 *cmvs = (void *)(data + 1);
1593 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1594 release_firmware(*fw);
1598 static int request_cmvs(struct uea_softc *sc,
1599 void **cmvs, const struct firmware **fw, int *ver)
1604 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1606 cmvs_file_name(sc, cmv_name, 2);
1607 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1609 /* if caller can handle old version, try to provide it */
1611 uea_warn(INS_TO_USBDEV(sc), "requesting firmware %s failed, "
1612 "try to get older cmvs\n", cmv_name);
1613 return request_cmvs_old(sc, cmvs, fw);
1615 uea_err(INS_TO_USBDEV(sc),
1616 "requesting firmware %s failed with error %d\n",
1622 data = (u8 *) (*fw)->data;
1623 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1625 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted, "
1626 "try to get older cmvs\n", cmv_name);
1627 release_firmware(*fw);
1628 return request_cmvs_old(sc, cmvs, fw);
1630 goto err_fw_corrupted;
1638 goto err_fw_corrupted;
1640 crc = FW_GET_LONG(data);
1643 if (crc32_be(0, data, size) != crc)
1644 goto err_fw_corrupted;
1646 if (size != *data * sizeof(struct uea_cmvs_v2) + 1)
1647 goto err_fw_corrupted;
1649 *cmvs = (void *) (data + 1);
1653 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1654 release_firmware(*fw);
1658 static int uea_send_cmvs_e1(struct uea_softc *sc)
1662 const struct firmware *cmvs_fw;
1663 int ver = 1; // we can handle v1 cmv firmware version;
1665 /* Enter in R-IDLE (cmv) until instructed otherwise */
1666 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
1670 /* Dump firmware version */
1671 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid);
1674 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1675 sc->stats.phy.firmid);
1678 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1684 struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr;
1686 uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, "
1687 "please update your firmware\n");
1689 for (i = 0; i < len; i++) {
1690 ret = uea_write_cmv_e1(sc, FW_GET_LONG(&cmvs_v1[i].address),
1691 FW_GET_WORD(&cmvs_v1[i].offset),
1692 FW_GET_LONG(&cmvs_v1[i].data));
1696 } else if (ver == 2) {
1697 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1699 for (i = 0; i < len; i++) {
1700 ret = uea_write_cmv_e1(sc, FW_GET_LONG(&cmvs_v2[i].address),
1701 (u16) FW_GET_LONG(&cmvs_v2[i].offset),
1702 FW_GET_LONG(&cmvs_v2[i].data));
1707 /* This realy should not happen */
1708 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1712 /* Enter in R-ACT-REQ */
1713 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1714 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1715 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n");
1717 release_firmware(cmvs_fw);
1721 static int uea_send_cmvs_e4(struct uea_softc *sc)
1725 const struct firmware *cmvs_fw;
1726 int ver = 2; // we can only handle v2 cmv firmware version;
1728 /* Enter in R-IDLE (cmv) until instructed otherwise */
1729 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
1733 /* Dump firmware version */
1734 /* XXX don't read the 3th byte as it is always 6 */
1735 ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid);
1738 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1739 sc->stats.phy.firmid);
1743 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1749 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1751 for (i = 0; i < len; i++) {
1752 ret = uea_write_cmv_e4(sc, 1,
1753 FW_GET_LONG(&cmvs_v2[i].group),
1754 FW_GET_LONG(&cmvs_v2[i].address),
1755 FW_GET_LONG(&cmvs_v2[i].offset),
1756 FW_GET_LONG(&cmvs_v2[i].data));
1761 /* This realy should not happen */
1762 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1766 /* Enter in R-ACT-REQ */
1767 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1768 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1769 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n");
1771 release_firmware(cmvs_fw);
1775 /* Start boot post firmware modem:
1776 * - send reset commands through usb control pipe
1777 * - start workqueue for DSP loading
1778 * - send CMV options to modem
1781 static int uea_start_reset(struct uea_softc *sc)
1783 u16 zero = 0; /* ;-) */
1786 uea_enters(INS_TO_USBDEV(sc));
1787 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1789 /* mask interrupt */
1791 /* We need to set this here because, a ack timeout could have occured,
1792 * but before we start the reboot, the ack occurs and set this to 1.
1793 * So we will failed to wait Ready CMV.
1796 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST);
1798 /* reset statistics */
1799 memset(&sc->stats, 0, sizeof(struct uea_stats));
1801 /* tell the modem that we want to boot in IDMA mode */
1802 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1803 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1805 /* enter reset mode */
1806 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1808 /* original driver use 200ms, but windows driver use 100ms */
1811 /* leave reset mode */
1812 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1814 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
1815 /* clear tx and rx mailboxes */
1816 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1817 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1818 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1823 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1824 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1);
1826 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY);
1828 /* demask interrupt */
1831 /* start loading DSP */
1834 queue_work(sc->work_q, &sc->task);
1836 /* wait for modem ready CMV */
1837 ret = wait_cmv_ack(sc);
1841 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1843 ret = sc->send_cmvs(sc);
1848 uea_leaves(INS_TO_USBDEV(sc));
1853 * In case of an error wait 1s before rebooting the modem
1854 * if the modem don't request reboot (-EAGAIN).
1855 * Monitor the modem every 1s.
1858 static int uea_kthread(void *data)
1860 struct uea_softc *sc = data;
1864 uea_enters(INS_TO_USBDEV(sc));
1865 while (!kthread_should_stop()) {
1866 if (ret < 0 || sc->reset)
1867 ret = uea_start_reset(sc);
1871 msleep_interruptible(1000);
1872 if (try_to_freeze())
1873 uea_err(INS_TO_USBDEV(sc), "suspend/resume not supported, "
1874 "please unplug/replug your modem\n");
1876 uea_leaves(INS_TO_USBDEV(sc));
1880 /* Load second usb firmware for ADI930 chip */
1881 static int load_XILINX_firmware(struct uea_softc *sc)
1883 const struct firmware *fw_entry;
1884 int ret, size, u, ln;
1886 char *fw_name = FW_DIR "930-fpga.bin";
1888 uea_enters(INS_TO_USBDEV(sc));
1890 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1892 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1897 pfw = fw_entry->data;
1898 size = fw_entry->size;
1899 if (size != 0x577B) {
1900 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1905 for (u = 0; u < size; u += ln) {
1906 ln = min(size - u, 64);
1907 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1909 uea_err(INS_TO_USBDEV(sc),
1910 "elsa download data failed (%d)\n", ret);
1915 /* finish to send the fpga */
1916 ret = uea_request(sc, 0xe, 1, 0, NULL);
1918 uea_err(INS_TO_USBDEV(sc),
1919 "elsa download data failed (%d)\n", ret);
1923 /* Tell the modem we finish : de-assert reset */
1925 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1927 uea_err(sc->usb_dev, "elsa de-assert failed with error %d\n", ret);
1930 release_firmware(fw_entry);
1932 uea_leaves(INS_TO_USBDEV(sc));
1936 /* The modem send us an ack. First with check if it right */
1937 static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
1939 struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;
1940 struct cmv_e1 *cmv = &intr->u.e1.s2.cmv;
1942 uea_enters(INS_TO_USBDEV(sc));
1943 if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE)
1946 if (cmv->bDirection != E1_MODEMTOHOST)
1949 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1950 * the first MEMACESS cmv. Ignore it...
1952 if (cmv->bFunction != dsc->function) {
1953 if (UEA_CHIP_VERSION(sc) == ADI930
1954 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
1955 cmv->wIndex = cpu_to_le16(dsc->idx);
1956 put_unaligned(cpu_to_le32(dsc->address), &cmv->dwSymbolicAddress);
1957 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
1962 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY)) {
1963 wake_up_cmv_ack(sc);
1964 uea_leaves(INS_TO_USBDEV(sc));
1968 /* in case of MEMACCESS */
1969 if (le16_to_cpu(cmv->wIndex) != dsc->idx ||
1970 le32_to_cpu(get_unaligned(&cmv->dwSymbolicAddress)) != dsc->address ||
1971 le16_to_cpu(cmv->wOffsetAddress) != dsc->offset)
1974 sc->data = le32_to_cpu(get_unaligned(&cmv->dwData));
1975 sc->data = sc->data << 16 | sc->data >> 16;
1977 wake_up_cmv_ack(sc);
1978 uea_leaves(INS_TO_USBDEV(sc));
1982 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
1983 "Function : %d, Subfunction : %d\n",
1984 E1_FUNCTION_TYPE(cmv->bFunction),
1985 E1_FUNCTION_SUBTYPE(cmv->bFunction));
1986 uea_leaves(INS_TO_USBDEV(sc));
1990 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
1991 "wPreamble %d, bDirection %d\n",
1992 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
1993 uea_leaves(INS_TO_USBDEV(sc));
1996 /* The modem send us an ack. First with check if it right */
1997 static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
1999 struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;
2000 struct cmv_e4 *cmv = &intr->u.e4.s2.cmv;
2002 uea_enters(INS_TO_USBDEV(sc));
2003 uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n",
2004 be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction),
2005 be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
2006 be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1]));
2008 if (be16_to_cpu(cmv->wFunction) != dsc->function)
2011 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1)) {
2012 wake_up_cmv_ack(sc);
2013 uea_leaves(INS_TO_USBDEV(sc));
2017 /* in case of MEMACCESS */
2018 if (be16_to_cpu(cmv->wOffset) != dsc->offset ||
2019 be16_to_cpu(cmv->wGroup) != dsc->group ||
2020 be16_to_cpu(cmv->wAddress) != dsc->address)
2023 sc->data = be32_to_cpu(cmv->dwData[0]);
2024 sc->data1 = be32_to_cpu(cmv->dwData[1]);
2025 wake_up_cmv_ack(sc);
2026 uea_leaves(INS_TO_USBDEV(sc));
2030 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
2031 "Function : %d, Subfunction : %d\n",
2032 E4_FUNCTION_TYPE(cmv->wFunction),
2033 E4_FUNCTION_SUBTYPE(cmv->wFunction));
2034 uea_leaves(INS_TO_USBDEV(sc));
2038 static void uea_schedule_load_page_e1(struct uea_softc *sc, struct intr_pkt *intr)
2040 sc->pageno = intr->e1_bSwapPageNo;
2041 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
2042 queue_work(sc->work_q, &sc->task);
2045 static void uea_schedule_load_page_e4(struct uea_softc *sc, struct intr_pkt *intr)
2047 sc->pageno = intr->e4_bSwapPageNo;
2048 queue_work(sc->work_q, &sc->task);
2054 static void uea_intr(struct urb *urb)
2056 struct uea_softc *sc = urb->context;
2057 struct intr_pkt *intr = urb->transfer_buffer;
2058 int status = urb->status;
2060 uea_enters(INS_TO_USBDEV(sc));
2062 if (unlikely(status < 0)) {
2063 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
2068 /* device-to-host interrupt */
2069 if (intr->bType != 0x08 || sc->booting) {
2070 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
2074 switch (le16_to_cpu(intr->wInterrupt)) {
2075 case INT_LOADSWAPPAGE:
2076 sc->schedule_load_page(sc, intr);
2079 case INT_INCOMINGCMV:
2080 sc->dispatch_cmv(sc, intr);
2084 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
2085 le16_to_cpu(intr->wInterrupt));
2089 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
2093 * Start the modem : init the data and start kernel thread
2095 static int uea_boot(struct uea_softc *sc)
2098 struct intr_pkt *intr;
2100 uea_enters(INS_TO_USBDEV(sc));
2102 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2103 size = E4_INTR_PKT_SIZE;
2104 sc->dispatch_cmv = uea_dispatch_cmv_e4;
2105 sc->schedule_load_page = uea_schedule_load_page_e4;
2106 sc->stat = uea_stat_e4;
2107 sc->send_cmvs = uea_send_cmvs_e4;
2108 INIT_WORK(&sc->task, uea_load_page_e4);
2110 size = E1_INTR_PKT_SIZE;
2111 sc->dispatch_cmv = uea_dispatch_cmv_e1;
2112 sc->schedule_load_page = uea_schedule_load_page_e1;
2113 sc->stat = uea_stat_e1;
2114 sc->send_cmvs = uea_send_cmvs_e1;
2115 INIT_WORK(&sc->task, uea_load_page_e1);
2118 init_waitqueue_head(&sc->sync_q);
2119 init_waitqueue_head(&sc->cmv_ack_wait);
2121 sc->work_q = create_workqueue("ueagle-dsp");
2123 uea_err(INS_TO_USBDEV(sc), "cannot allocate workqueue\n");
2124 uea_leaves(INS_TO_USBDEV(sc));
2128 if (UEA_CHIP_VERSION(sc) == ADI930)
2129 load_XILINX_firmware(sc);
2131 intr = kmalloc(size, GFP_KERNEL);
2133 uea_err(INS_TO_USBDEV(sc),
2134 "cannot allocate interrupt package\n");
2138 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
2140 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
2144 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
2145 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
2146 intr, size, uea_intr, sc,
2147 sc->usb_dev->actconfig->interface[0]->altsetting[0].
2148 endpoint[0].desc.bInterval);
2150 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2152 uea_err(INS_TO_USBDEV(sc),
2153 "urb submition failed with error %d\n", ret);
2157 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm");
2158 if (sc->kthread == ERR_PTR(-ENOMEM)) {
2159 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2163 uea_leaves(INS_TO_USBDEV(sc));
2167 usb_kill_urb(sc->urb_int);
2169 usb_free_urb(sc->urb_int);
2173 destroy_workqueue(sc->work_q);
2174 uea_leaves(INS_TO_USBDEV(sc));
2179 * Stop the modem : kill kernel thread and free data
2181 static void uea_stop(struct uea_softc *sc)
2184 uea_enters(INS_TO_USBDEV(sc));
2185 ret = kthread_stop(sc->kthread);
2186 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
2188 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
2190 usb_kill_urb(sc->urb_int);
2191 kfree(sc->urb_int->transfer_buffer);
2192 usb_free_urb(sc->urb_int);
2194 /* stop any pending boot process, when no one can schedule work */
2195 destroy_workqueue(sc->work_q);
2198 release_firmware(sc->dsp_firm);
2199 uea_leaves(INS_TO_USBDEV(sc));
2202 /* syfs interface */
2203 static struct uea_softc *dev_to_uea(struct device *dev)
2205 struct usb_interface *intf;
2206 struct usbatm_data *usbatm;
2208 intf = to_usb_interface(dev);
2212 usbatm = usb_get_intfdata(intf);
2216 return usbatm->driver_data;
2219 static ssize_t read_status(struct device *dev, struct device_attribute *attr,
2223 struct uea_softc *sc;
2225 mutex_lock(&uea_mutex);
2226 sc = dev_to_uea(dev);
2229 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
2231 mutex_unlock(&uea_mutex);
2235 static ssize_t reboot(struct device *dev, struct device_attribute *attr,
2236 const char *buf, size_t count)
2239 struct uea_softc *sc;
2241 mutex_lock(&uea_mutex);
2242 sc = dev_to_uea(dev);
2248 mutex_unlock(&uea_mutex);
2252 static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot);
2254 static ssize_t read_human_status(struct device *dev, struct device_attribute *attr,
2259 struct uea_softc *sc;
2261 mutex_lock(&uea_mutex);
2262 sc = dev_to_uea(dev);
2266 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2267 switch (sc->stats.phy.state) {
2268 case 0x0: /* not yet synchronized */
2274 case 0x5: /* initialization */
2280 case 0x7: /* operational */
2283 case 0x2: /* fail ... */
2286 default: /* unknown */
2291 modem_state = GET_STATUS(sc->stats.phy.state);
2293 switch (modem_state) {
2295 ret = sprintf(buf, "Modem is booting\n");
2298 ret = sprintf(buf, "Modem is initializing\n");
2301 ret = sprintf(buf, "Modem is operational\n");
2304 ret = sprintf(buf, "Modem synchronization failed\n");
2307 ret = sprintf(buf, "Modem state is unknown\n");
2311 mutex_unlock(&uea_mutex);
2315 static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, read_human_status, NULL);
2317 static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2321 struct uea_softc *sc;
2322 char *delin = "GOOD";
2324 mutex_lock(&uea_mutex);
2325 sc = dev_to_uea(dev);
2329 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2330 if (sc->stats.phy.flags & 0x4000)
2332 else if (sc->stats.phy.flags & 0x0001)
2335 if (sc->stats.phy.flags & 0x0C00)
2337 else if (sc->stats.phy.flags & 0x0030)
2341 ret = sprintf(buf, "%s\n", delin);
2343 mutex_unlock(&uea_mutex);
2347 static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL);
2349 #define UEA_ATTR(name, reset) \
2351 static ssize_t read_##name(struct device *dev, \
2352 struct device_attribute *attr, char *buf) \
2354 int ret = -ENODEV; \
2355 struct uea_softc *sc; \
2357 mutex_lock(&uea_mutex); \
2358 sc = dev_to_uea(dev); \
2361 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2363 sc->stats.phy.name = 0; \
2365 mutex_unlock(&uea_mutex); \
2369 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2371 UEA_ATTR(mflags, 1);
2372 UEA_ATTR(vidcpe, 0);
2373 UEA_ATTR(usrate, 0);
2374 UEA_ATTR(dsrate, 0);
2375 UEA_ATTR(usattenuation, 0);
2376 UEA_ATTR(dsattenuation, 0);
2377 UEA_ATTR(usmargin, 0);
2378 UEA_ATTR(dsmargin, 0);
2379 UEA_ATTR(txflow, 0);
2380 UEA_ATTR(rxflow, 0);
2381 UEA_ATTR(uscorr, 0);
2382 UEA_ATTR(dscorr, 0);
2385 UEA_ATTR(firmid, 0);
2387 /* Retrieve the device End System Identifier (MAC) */
2389 #define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
2390 static int uea_getesi(struct uea_softc *sc, u_char * esi)
2392 unsigned char mac_str[2 * ETH_ALEN + 1];
2395 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
2396 sizeof(mac_str)) != 2 * ETH_ALEN)
2399 for (i = 0; i < ETH_ALEN; i++)
2400 esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]);
2406 static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
2408 struct uea_softc *sc = usbatm->driver_data;
2410 return uea_getesi(sc, atm_dev->esi);
2413 static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
2415 struct uea_softc *sc = usbatm->driver_data;
2417 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
2423 static int claim_interface(struct usb_device *usb_dev,
2424 struct usbatm_data *usbatm, int ifnum)
2427 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
2430 uea_err(usb_dev, "interface %d not found\n", ifnum);
2434 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
2436 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
2441 static struct attribute *attrs[] = {
2442 &dev_attr_stat_status.attr,
2443 &dev_attr_stat_mflags.attr,
2444 &dev_attr_stat_human_status.attr,
2445 &dev_attr_stat_delin.attr,
2446 &dev_attr_stat_vidcpe.attr,
2447 &dev_attr_stat_usrate.attr,
2448 &dev_attr_stat_dsrate.attr,
2449 &dev_attr_stat_usattenuation.attr,
2450 &dev_attr_stat_dsattenuation.attr,
2451 &dev_attr_stat_usmargin.attr,
2452 &dev_attr_stat_dsmargin.attr,
2453 &dev_attr_stat_txflow.attr,
2454 &dev_attr_stat_rxflow.attr,
2455 &dev_attr_stat_uscorr.attr,
2456 &dev_attr_stat_dscorr.attr,
2457 &dev_attr_stat_usunc.attr,
2458 &dev_attr_stat_dsunc.attr,
2459 &dev_attr_stat_firmid.attr,
2462 static struct attribute_group attr_grp = {
2466 static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
2467 const struct usb_device_id *id)
2469 struct usb_device *usb = interface_to_usbdev(intf);
2470 struct uea_softc *sc;
2471 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
2476 /* interface 0 is for firmware/monitoring */
2477 if (ifnum != UEA_INTR_IFACE_NO)
2480 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
2482 /* interface 1 is for outbound traffic */
2483 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
2487 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
2488 if (UEA_CHIP_VERSION(id) != ADI930) {
2489 /* interface 2 is for inbound traffic */
2490 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
2495 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
2497 uea_err(usb, "uea_init: not enough memory !\n");
2502 usbatm->driver_data = sc;
2503 sc->usbatm = usbatm;
2504 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
2505 sc->driver_info = id->driver_info;
2507 /* first try to use module parameter */
2508 if (annex[sc->modem_index] == 1)
2510 else if (annex[sc->modem_index] == 2)
2512 /* try to autodetect annex */
2513 else if (sc->driver_info & AUTO_ANNEX_A)
2515 else if (sc->driver_info & AUTO_ANNEX_B)
2518 sc->annex = (le16_to_cpu(sc->usb_dev->descriptor.bcdDevice) & 0x80)?ANNEXB:ANNEXA;
2520 alt = altsetting[sc->modem_index];
2521 /* ADI930 don't support iso */
2522 if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) {
2523 if (alt <= 8 && usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) {
2524 uea_dbg(usb, "set alternate %u for 2 interface\n", alt);
2525 uea_info(usb, "using iso mode\n");
2526 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
2528 uea_err(usb, "setting alternate %u failed for "
2529 "2 interface, using bulk mode\n", alt);
2533 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
2544 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2550 static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
2552 struct uea_softc *sc = usbatm->driver_data;
2554 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2559 static struct usbatm_driver uea_usbatm_driver = {
2560 .driver_name = "ueagle-atm",
2562 .atm_start = uea_atm_open,
2563 .unbind = uea_unbind,
2564 .heavy_init = uea_heavy,
2565 .bulk_in = UEA_BULK_DATA_PIPE,
2566 .bulk_out = UEA_BULK_DATA_PIPE,
2567 .isoc_in = UEA_ISO_DATA_PIPE,
2570 static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2572 struct usb_device *usb = interface_to_usbdev(intf);
2575 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2576 le16_to_cpu(usb->descriptor.idVendor),
2577 le16_to_cpu(usb->descriptor.idProduct),
2578 le16_to_cpu(usb->descriptor.bcdDevice),
2579 chip_name[UEA_CHIP_VERSION(id)]);
2581 usb_reset_device(usb);
2583 if (UEA_IS_PREFIRM(id))
2584 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2586 return usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2589 static void uea_disconnect(struct usb_interface *intf)
2591 struct usb_device *usb = interface_to_usbdev(intf);
2592 int ifnum = intf->altsetting->desc.bInterfaceNumber;
2595 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2596 * Pre-firmware device has one interface
2598 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
2599 mutex_lock(&uea_mutex);
2600 usbatm_usb_disconnect(intf);
2601 mutex_unlock(&uea_mutex);
2602 uea_info(usb, "ADSL device removed\n");
2609 * List of supported VID/PID
2611 static const struct usb_device_id uea_ids[] = {
2612 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
2613 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
2614 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2615 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
2616 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2617 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
2618 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2619 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
2620 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM), .driver_info = EAGLE_III | PREFIRM},
2621 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM), .driver_info = EAGLE_III | PSTFIRM},
2622 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM), .driver_info = EAGLE_IV | PREFIRM},
2623 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM), .driver_info = EAGLE_IV | PSTFIRM},
2624 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2625 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2626 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2627 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2628 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2629 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A},
2630 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2631 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B},
2632 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
2633 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
2634 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM), .driver_info = ADI930 | PREFIRM},
2635 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM), .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A},
2636 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM), .driver_info = ADI930 | PREFIRM},
2637 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM), .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B},
2638 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2639 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2640 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2641 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2642 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
2643 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2644 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
2645 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2650 * USB driver descriptor
2652 static struct usb_driver uea_driver = {
2653 .name = "ueagle-atm",
2654 .id_table = uea_ids,
2656 .disconnect = uea_disconnect,
2659 MODULE_DEVICE_TABLE(usb, uea_ids);
2662 * uea_init - Initialize the module.
2663 * Register to USB subsystem
2665 static int __init uea_init(void)
2667 printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n");
2669 usb_register(&uea_driver);
2674 module_init(uea_init);
2677 * uea_exit - Destroy module
2678 * Deregister with USB subsystem
2680 static void __exit uea_exit(void)
2683 * This calls automatically the uea_disconnect method if necessary:
2685 usb_deregister(&uea_driver);
2687 printk(KERN_INFO "[ueagle-atm] driver unloaded\n");
2690 module_exit(uea_exit);
2692 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2693 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2694 MODULE_LICENSE("Dual BSD/GPL");