2 * Copyright (c) 2003, 2004
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/mutex.h>
68 #include <linux/freezer.h>
69 #include <linux/slab.h>
70 #include <linux/kernel.h>
72 #include <asm/unaligned.h>
76 #define EAGLEUSBVERSION "ueagle 1.4"
82 #define uea_dbg(usb_dev, format, args...) \
85 dev_dbg(&(usb_dev)->dev, \
86 "[ueagle-atm dbg] %s: " format, \
90 #define uea_vdbg(usb_dev, format, args...) \
93 dev_dbg(&(usb_dev)->dev, \
94 "[ueagle-atm vdbg] " format, ##args); \
97 #define uea_enters(usb_dev) \
98 uea_vdbg(usb_dev, "entering %s\n" , __func__)
100 #define uea_leaves(usb_dev) \
101 uea_vdbg(usb_dev, "leaving %s\n" , __func__)
103 #define uea_err(usb_dev, format, args...) \
104 dev_err(&(usb_dev)->dev , "[UEAGLE-ATM] " format , ##args)
106 #define uea_warn(usb_dev, format, args...) \
107 dev_warn(&(usb_dev)->dev , "[Ueagle-atm] " format, ##args)
109 #define uea_info(usb_dev, format, args...) \
110 dev_info(&(usb_dev)->dev , "[ueagle-atm] " format, ##args)
114 /* cmv's from firmware */
128 /* information about currently processed cmv */
144 struct cmv_dsc_e1 e1;
145 struct cmv_dsc_e4 e4;
149 struct usb_device *usb_dev;
150 struct usbatm_data *usbatm;
153 unsigned int driver_info;
161 wait_queue_head_t sync_q;
163 struct task_struct *kthread;
168 union cmv_dsc cmv_dsc;
170 struct work_struct task;
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)))
309 #define FW_DIR "ueagle-atm/"
310 #define UEA_FW_NAME_MAX 30
313 #define BULK_TIMEOUT 300
314 #define CTRL_TIMEOUT 1000
316 #define ACK_TIMEOUT msecs_to_jiffies(3000)
318 #define UEA_INTR_IFACE_NO 0
319 #define UEA_US_IFACE_NO 1
320 #define UEA_DS_IFACE_NO 2
322 #define FASTEST_ISO_INTF 8
324 #define UEA_BULK_DATA_PIPE 0x02
325 #define UEA_IDMA_PIPE 0x04
326 #define UEA_INTR_PIPE 0x04
327 #define UEA_ISO_DATA_PIPE 0x08
329 #define UEA_E1_SET_BLOCK 0x0001
330 #define UEA_E4_SET_BLOCK 0x002c
331 #define UEA_SET_MODE 0x0003
332 #define UEA_SET_2183_DATA 0x0004
333 #define UEA_SET_TIMEOUT 0x0011
335 #define UEA_LOOPBACK_OFF 0x0002
336 #define UEA_LOOPBACK_ON 0x0003
337 #define UEA_BOOT_IDMA 0x0006
338 #define UEA_START_RESET 0x0007
339 #define UEA_END_RESET 0x0008
341 #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
342 #define UEA_MPTX_START (0x3fce | 0x4000)
343 #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
344 #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
346 /* block information in eagle4 dsp firmware */
357 #define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
358 #define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
360 #define E4_L1_STRING_HEADER 0x10
361 #define E4_MAX_PAGE_NUMBER 0x58
362 #define E4_NO_SWAPPAGE_HEADERS 0x31
364 /* l1_code is eagle4 dsp firmware format */
366 u8 string_header[E4_L1_STRING_HEADER];
367 u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER];
368 struct block_index page_header[E4_NO_SWAPPAGE_HEADERS];
372 /* structures describing a block within a DSP page */
373 struct block_info_e1 {
378 __le16 wOvl; /* overlay */
381 #define E1_BLOCK_INFO_SIZE 12
383 struct block_info_e4 {
391 #define E4_BLOCK_INFO_SIZE 14
393 #define UEA_BIHDR 0xabcd
394 #define UEA_RESERVED 0xffff
396 /* constants describing cmv type */
397 #define E1_PREAMBLE 0x535c
398 #define E1_MODEMTOHOST 0x01
399 #define E1_HOSTTOMODEM 0x10
401 #define E1_MEMACCESS 0x1
402 #define E1_ADSLDIRECTIVE 0x7
403 #define E1_FUNCTION_TYPE(f) ((f) >> 4)
404 #define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f)
406 #define E4_MEMACCESS 0
407 #define E4_ADSLDIRECTIVE 0xf
408 #define E4_FUNCTION_TYPE(f) ((f) >> 8)
409 #define E4_FUNCTION_SIZE(f) ((f) & 0x0f)
410 #define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f)
413 #define E1_REQUESTREAD 0x0
414 #define E1_REQUESTWRITE 0x1
415 #define E1_REPLYREAD 0x2
416 #define E1_REPLYWRITE 0x3
418 #define E4_REQUESTREAD 0x0
419 #define E4_REQUESTWRITE 0x4
420 #define E4_REPLYREAD (E4_REQUESTREAD | 1)
421 #define E4_REPLYWRITE (E4_REQUESTWRITE | 1)
423 /* for ADSLDIRECTIVE */
424 #define E1_KERNELREADY 0x0
425 #define E1_MODEMREADY 0x1
427 #define E4_KERNELREADY 0x0
428 #define E4_MODEMREADY 0x1
430 #define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
431 #define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | \
432 ((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;
480 /* structures representing swap information */
481 struct swap_info_e1 {
483 __u8 bOvl; /* overlay */
486 struct swap_info_e4 {
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;
511 struct swap_info_e4 swapinfo;
528 union intr_data_e1 e1;
529 union intr_data_e4 e4;
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 * const chip_name[] = {
539 "ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
541 static int modem_index;
542 static unsigned int debug;
543 static unsigned int altsetting[NB_MODEM] = {
544 [0 ... (NB_MODEM - 1)] = FASTEST_ISO_INTF};
545 static bool sync_wait[NB_MODEM];
546 static char *cmv_file[NB_MODEM];
547 static int annex[NB_MODEM];
549 module_param(debug, uint, 0644);
550 MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
551 module_param_array(altsetting, uint, NULL, 0644);
552 MODULE_PARM_DESC(altsetting, "alternate setting for incoming traffic: 0=bulk, "
553 "1=isoc slowest, ... , 8=isoc fastest (default)");
554 module_param_array(sync_wait, bool, NULL, 0644);
555 MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
556 module_param_array(cmv_file, charp, NULL, 0644);
557 MODULE_PARM_DESC(cmv_file,
558 "file name with configuration and management variables");
559 module_param_array(annex, uint, NULL, 0644);
560 MODULE_PARM_DESC(annex,
561 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
563 #define uea_wait(sc, cond, timeo) \
565 int _r = wait_event_interruptible_timeout(sc->sync_q, \
566 (cond) || kthread_should_stop(), timeo); \
567 if (kthread_should_stop()) \
572 #define UPDATE_ATM_STAT(type, val) \
574 if (sc->usbatm->atm_dev) \
575 sc->usbatm->atm_dev->type = val; \
578 #define UPDATE_ATM_SIGNAL(val) \
580 if (sc->usbatm->atm_dev) \
581 atm_dev_signal_change(sc->usbatm->atm_dev, val); \
585 /* Firmware loading */
586 #define LOAD_INTERNAL 0xA0
587 #define F8051_USBCS 0x7f92
590 * uea_send_modem_cmd - Send a command for pre-firmware devices.
592 static int uea_send_modem_cmd(struct usb_device *usb,
593 u16 addr, u16 size, const u8 *buff)
598 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
600 ret = usb_control_msg(usb,
601 usb_sndctrlpipe(usb, 0),
603 USB_DIR_OUT | USB_TYPE_VENDOR |
604 USB_RECIP_DEVICE, addr, 0, xfer_buff,
612 return (ret == size) ? 0 : -EIO;
615 static void uea_upload_pre_firmware(const struct firmware *fw_entry,
618 struct usb_device *usb = context;
626 uea_err(usb, "firmware is not available\n");
630 pfw = fw_entry->data;
631 size = fw_entry->size;
633 goto err_fw_corrupted;
635 crc = get_unaligned_le32(pfw);
638 if (crc32_be(0, pfw, size) != crc)
639 goto err_fw_corrupted;
642 * Start to upload firmware : send reset
645 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
648 uea_err(usb, "modem reset failed with error %d\n", ret);
653 u8 len = FW_GET_BYTE(pfw);
654 u16 add = get_unaligned_le16(pfw + 1);
658 goto err_fw_corrupted;
660 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
662 uea_err(usb, "uploading firmware data failed "
663 "with error %d\n", ret);
670 goto err_fw_corrupted;
673 * Tell the modem we finish : de-assert reset
676 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
678 uea_err(usb, "modem de-assert failed with error %d\n", ret);
680 uea_info(usb, "firmware uploaded\n");
685 uea_err(usb, "firmware is corrupted\n");
687 release_firmware(fw_entry);
692 * uea_load_firmware - Load usb firmware for pre-firmware devices.
694 static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
697 char *fw_name = FW_DIR "eagle.fw";
700 uea_info(usb, "pre-firmware device, uploading firmware\n");
704 fw_name = FW_DIR "adi930.fw";
707 fw_name = FW_DIR "eagleI.fw";
710 fw_name = FW_DIR "eagleII.fw";
713 fw_name = FW_DIR "eagleIII.fw";
716 fw_name = FW_DIR "eagleIV.fw";
720 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev,
722 uea_upload_pre_firmware);
724 uea_err(usb, "firmware %s is not available\n", fw_name);
726 uea_info(usb, "loading firmware %s\n", fw_name);
732 /* modem management : dsp firmware, send/read CMV, monitoring statistic
736 * Make sure that the DSP code provided is safe to use.
738 static int check_dsp_e1(const u8 *dsp, unsigned int len)
740 u8 pagecount, blockcount;
743 unsigned int i, j, p, pp;
745 pagecount = FW_GET_BYTE(dsp);
748 /* enough space for page offsets? */
749 if (p + 4 * pagecount > len)
752 for (i = 0; i < pagecount; i++) {
754 pageoffset = get_unaligned_le32(dsp + p);
760 /* enough space for blockcount? */
761 if (pageoffset >= len)
765 blockcount = FW_GET_BYTE(dsp + pp);
768 for (j = 0; j < blockcount; j++) {
770 /* enough space for block header? */
774 pp += 2; /* skip blockaddr */
775 blocksize = get_unaligned_le16(dsp + pp);
778 /* enough space for block data? */
779 if (pp + blocksize > len)
789 static int check_dsp_e4(const u8 *dsp, int len)
792 struct l1_code *p = (struct l1_code *) dsp;
793 unsigned int sum = p->code - dsp;
798 if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 &&
799 strcmp("STRATIPHY ANEXB", p->string_header) != 0)
802 for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) {
803 struct block_index *blockidx;
804 u8 blockno = p->page_number_to_block_index[i];
805 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
811 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
814 blockidx = &p->page_header[blockno++];
815 if ((u8 *)(blockidx + 1) - dsp >= len)
818 if (le16_to_cpu(blockidx->PageNumber) != i)
821 l = E4_PAGE_BYTES(blockidx->PageSize);
823 l += le32_to_cpu(blockidx->PageOffset);
827 /* zero is zero regardless endianes */
828 } while (blockidx->NotLastBlock);
831 return (sum == len) ? 0 : 1;
835 * send data to the idma pipe
837 static int uea_idma_write(struct uea_softc *sc, const void *data, u32 size)
843 xfer_buff = kmemdup(data, size, GFP_KERNEL);
845 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
849 ret = usb_bulk_msg(sc->usb_dev,
850 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
851 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
856 if (size != bytes_read) {
857 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
865 static int request_dsp(struct uea_softc *sc)
870 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
872 dsp_name = FW_DIR "DSP4i.bin";
874 dsp_name = FW_DIR "DSP4p.bin";
875 } else if (UEA_CHIP_VERSION(sc) == ADI930) {
877 dsp_name = FW_DIR "DSP9i.bin";
879 dsp_name = FW_DIR "DSP9p.bin";
882 dsp_name = FW_DIR "DSPei.bin";
884 dsp_name = FW_DIR "DSPep.bin";
887 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
889 uea_err(INS_TO_USBDEV(sc),
890 "requesting firmware %s failed with error %d\n",
895 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
896 ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size);
898 ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size);
901 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
903 release_firmware(sc->dsp_firm);
912 * The uea_load_page() function must be called within a process context
914 static void uea_load_page_e1(struct work_struct *work)
916 struct uea_softc *sc = container_of(work, struct uea_softc, task);
917 u16 pageno = sc->pageno;
919 struct block_info_e1 bi;
922 u8 pagecount, blockcount;
923 u16 blockaddr, blocksize;
927 /* reload firmware when reboot start and it's loaded already */
928 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
929 release_firmware(sc->dsp_firm);
933 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
936 p = sc->dsp_firm->data;
937 pagecount = FW_GET_BYTE(p);
940 if (pageno >= pagecount)
944 pageoffset = get_unaligned_le32(p);
949 p = sc->dsp_firm->data + pageoffset;
950 blockcount = FW_GET_BYTE(p);
953 uea_dbg(INS_TO_USBDEV(sc),
954 "sending %u blocks for DSP page %u\n", blockcount, pageno);
956 bi.wHdr = cpu_to_le16(UEA_BIHDR);
957 bi.wOvl = cpu_to_le16(ovl);
958 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
960 for (i = 0; i < blockcount; i++) {
961 blockaddr = get_unaligned_le16(p);
964 blocksize = get_unaligned_le16(p);
967 bi.wSize = cpu_to_le16(blocksize);
968 bi.wAddress = cpu_to_le16(blockaddr);
969 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
971 /* send block info through the IDMA pipe */
972 if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE))
975 /* send block data through the IDMA pipe */
976 if (uea_idma_write(sc, p, blocksize))
985 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
988 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
991 static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
993 struct block_info_e4 bi;
994 struct block_index *blockidx;
995 struct l1_code *p = (struct l1_code *) sc->dsp_firm->data;
996 u8 blockno = p->page_number_to_block_index[pageno];
998 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1000 bi.bPageNumber = pageno;
1001 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1004 const u8 *blockoffset;
1005 unsigned int blocksize;
1007 blockidx = &p->page_header[blockno];
1008 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
1009 blockoffset = sc->dsp_firm->data + le32_to_cpu(
1010 blockidx->PageOffset);
1012 bi.dwSize = cpu_to_be32(blocksize);
1013 bi.dwAddress = cpu_to_be32(le32_to_cpu(blockidx->PageAddress));
1015 uea_dbg(INS_TO_USBDEV(sc),
1016 "sending block %u for DSP page "
1017 "%u size %u address %x\n",
1018 blockno, pageno, blocksize,
1019 le32_to_cpu(blockidx->PageAddress));
1021 /* send block info through the IDMA pipe */
1022 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1025 /* send block data through the IDMA pipe */
1026 if (uea_idma_write(sc, blockoffset, blocksize))
1030 } while (blockidx->NotLastBlock);
1035 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno);
1039 static void uea_load_page_e4(struct work_struct *work)
1041 struct uea_softc *sc = container_of(work, struct uea_softc, task);
1042 u8 pageno = sc->pageno;
1044 struct block_info_e4 bi;
1047 uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
1049 /* reload firmware when reboot start and it's loaded already */
1050 if (pageno == 0 && sc->dsp_firm) {
1051 release_firmware(sc->dsp_firm);
1052 sc->dsp_firm = NULL;
1055 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
1058 p = (struct l1_code *) sc->dsp_firm->data;
1059 if (pageno >= le16_to_cpu(p->page_header[0].PageNumber)) {
1060 uea_err(INS_TO_USBDEV(sc), "invalid DSP "
1061 "page %u requested\n", pageno);
1066 __uea_load_page_e4(sc, pageno, 0);
1070 uea_dbg(INS_TO_USBDEV(sc),
1071 "sending Main DSP page %u\n", p->page_header[0].PageNumber);
1073 for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) {
1074 if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize))
1075 __uea_load_page_e4(sc, i, 1);
1078 uea_dbg(INS_TO_USBDEV(sc) , "sending start bi\n");
1080 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1082 bi.bPageNumber = 0xff;
1083 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1084 bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize));
1085 bi.dwAddress = cpu_to_be32(le32_to_cpu(p->page_header[0].PageAddress));
1087 /* send block info through the IDMA pipe */
1088 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1089 uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n");
1092 static inline void wake_up_cmv_ack(struct uea_softc *sc)
1094 BUG_ON(sc->cmv_ack);
1096 wake_up(&sc->sync_q);
1099 static inline int wait_cmv_ack(struct uea_softc *sc)
1101 int ret = uea_wait(sc, sc->cmv_ack , ACK_TIMEOUT);
1105 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
1106 jiffies_to_msecs(ret));
1111 return (ret == 0) ? -ETIMEDOUT : 0;
1114 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1116 static int uea_request(struct uea_softc *sc,
1117 u16 value, u16 index, u16 size, const void *data)
1122 xfer_buff = kmemdup(data, size, GFP_KERNEL);
1124 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
1128 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
1129 UCDC_SEND_ENCAPSULATED_COMMAND,
1130 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1131 value, index, xfer_buff, size, CTRL_TIMEOUT);
1135 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
1140 uea_err(INS_TO_USBDEV(sc),
1141 "usb_control_msg send only %d bytes (instead of %d)\n",
1149 static int uea_cmv_e1(struct uea_softc *sc,
1150 u8 function, u32 address, u16 offset, u32 data)
1155 uea_enters(INS_TO_USBDEV(sc));
1156 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1157 "offset : 0x%04x, data : 0x%08x\n",
1158 E1_FUNCTION_TYPE(function),
1159 E1_FUNCTION_SUBTYPE(function),
1160 E1_GETSA1(address), E1_GETSA2(address),
1162 E1_GETSA4(address), offset, data);
1164 /* we send a request, but we expect a reply */
1165 sc->cmv_dsc.e1.function = function | 0x2;
1166 sc->cmv_dsc.e1.idx++;
1167 sc->cmv_dsc.e1.address = address;
1168 sc->cmv_dsc.e1.offset = offset;
1170 cmv.wPreamble = cpu_to_le16(E1_PREAMBLE);
1171 cmv.bDirection = E1_HOSTTOMODEM;
1172 cmv.bFunction = function;
1173 cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx);
1174 put_unaligned_le32(address, &cmv.dwSymbolicAddress);
1175 cmv.wOffsetAddress = cpu_to_le16(offset);
1176 put_unaligned_le32(data >> 16 | data << 16, &cmv.dwData);
1178 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START,
1182 ret = wait_cmv_ack(sc);
1183 uea_leaves(INS_TO_USBDEV(sc));
1187 static int uea_cmv_e4(struct uea_softc *sc,
1188 u16 function, u16 group, u16 address, u16 offset, u32 data)
1193 uea_enters(INS_TO_USBDEV(sc));
1194 memset(&cmv, 0, sizeof(cmv));
1196 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
1197 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1198 E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function),
1199 group, address, offset, data);
1201 /* we send a request, but we expect a reply */
1202 sc->cmv_dsc.e4.function = function | (0x1 << 4);
1203 sc->cmv_dsc.e4.offset = offset;
1204 sc->cmv_dsc.e4.address = address;
1205 sc->cmv_dsc.e4.group = group;
1207 cmv.wFunction = cpu_to_be16(function);
1208 cmv.wGroup = cpu_to_be16(group);
1209 cmv.wAddress = cpu_to_be16(address);
1210 cmv.wOffset = cpu_to_be16(offset);
1211 cmv.dwData[0] = cpu_to_be32(data);
1213 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START,
1217 ret = wait_cmv_ack(sc);
1218 uea_leaves(INS_TO_USBDEV(sc));
1222 static inline int uea_read_cmv_e1(struct uea_softc *sc,
1223 u32 address, u16 offset, u32 *data)
1225 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD),
1226 address, offset, 0);
1228 uea_err(INS_TO_USBDEV(sc),
1229 "reading cmv failed with error %d\n", ret);
1236 static inline int uea_read_cmv_e4(struct uea_softc *sc,
1237 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1239 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1240 E4_REQUESTREAD, size),
1241 group, address, offset, 0);
1243 uea_err(INS_TO_USBDEV(sc),
1244 "reading cmv failed with error %d\n", ret);
1247 /* size is in 16-bit word quantities */
1249 *(data + 1) = sc->data1;
1254 static inline int uea_write_cmv_e1(struct uea_softc *sc,
1255 u32 address, u16 offset, u32 data)
1257 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE),
1258 address, offset, data);
1260 uea_err(INS_TO_USBDEV(sc),
1261 "writing cmv failed with error %d\n", ret);
1266 static inline int uea_write_cmv_e4(struct uea_softc *sc,
1267 u8 size, u16 group, u16 address, u16 offset, u32 data)
1269 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1270 E4_REQUESTWRITE, size),
1271 group, address, offset, data);
1273 uea_err(INS_TO_USBDEV(sc),
1274 "writing cmv failed with error %d\n", ret);
1279 static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1284 /* in bulk mode the modem have problem with high rate
1285 * changing internal timing could improve things, but the
1286 * value is mysterious.
1287 * ADI930 don't support it (-EPIPE error).
1290 if (UEA_CHIP_VERSION(sc) == ADI930 ||
1291 altsetting[sc->modem_index] > 0 ||
1292 sc->stats.phy.dsrate == dsrate)
1295 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1296 timeout = (dsrate <= 1024*1024) ? 0 : 1;
1297 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
1298 uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n",
1299 timeout, ret < 0 ? " failed" : "");
1304 * Monitor the modem and update the stat
1305 * return 0 if everything is ok
1306 * return < 0 if an error occurs (-EAGAIN reboot needed)
1308 static int uea_stat_e1(struct uea_softc *sc)
1313 uea_enters(INS_TO_USBDEV(sc));
1314 data = sc->stats.phy.state;
1316 ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state);
1320 switch (GET_STATUS(sc->stats.phy.state)) {
1321 case 0: /* not yet synchronized */
1322 uea_dbg(INS_TO_USBDEV(sc),
1323 "modem not yet synchronized\n");
1326 case 1: /* initialization */
1327 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1330 case 2: /* operational */
1331 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
1334 case 3: /* fail ... */
1335 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1336 " (may be try other cmv/dsp)\n");
1339 case 4 ... 6: /* test state */
1340 uea_warn(INS_TO_USBDEV(sc),
1341 "modem in test mode - not supported\n");
1344 case 7: /* fast-retain ... */
1345 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
1348 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
1349 GET_STATUS(sc->stats.phy.state));
1353 if (GET_STATUS(data) != 2) {
1354 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1355 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1357 /* release the dsp firmware as it is not needed until
1361 release_firmware(sc->dsp_firm);
1362 sc->dsp_firm = NULL;
1366 /* always update it as atm layer could not be init when we switch to
1369 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND);
1371 /* wake up processes waiting for synchronization */
1372 wake_up(&sc->sync_q);
1374 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags);
1377 sc->stats.phy.mflags |= sc->stats.phy.flags;
1379 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1380 * we check the status again in order to detect the failure earlier
1382 if (sc->stats.phy.flags) {
1383 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1384 sc->stats.phy.flags);
1388 ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data);
1392 uea_set_bulk_timeout(sc, (data >> 16) * 32);
1393 sc->stats.phy.dsrate = (data >> 16) * 32;
1394 sc->stats.phy.usrate = (data & 0xffff) * 32;
1395 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1397 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data);
1400 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
1402 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data);
1405 sc->stats.phy.usattenuation = (data & 0xff) / 2;
1407 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin);
1411 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin);
1415 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow);
1419 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow);
1423 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc);
1427 /* only for atu-c */
1428 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc);
1432 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr);
1436 /* only for atu-c */
1437 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr);
1441 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 8, &sc->stats.phy.vidco);
1445 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 13, &sc->stats.phy.vidcpe);
1452 static int uea_stat_e4(struct uea_softc *sc)
1458 uea_enters(INS_TO_USBDEV(sc));
1459 data = sc->stats.phy.state;
1461 /* XXX only need to be done before operationnal... */
1462 ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state);
1466 switch (sc->stats.phy.state) {
1467 case 0x0: /* not yet synchronized */
1471 uea_dbg(INS_TO_USBDEV(sc), "modem not yet "
1474 case 0x5: /* initialization */
1478 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1480 case 0x2: /* fail ... */
1481 uea_info(INS_TO_USBDEV(sc), "modem synchronization "
1482 "failed (may be try other cmv/dsp)\n");
1484 case 0x7: /* operational */
1487 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n",
1488 sc->stats.phy.state);
1493 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1494 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1496 /* release the dsp firmware as it is not needed until
1500 release_firmware(sc->dsp_firm);
1501 sc->dsp_firm = NULL;
1505 /* always update it as atm layer could not be init when we switch to
1508 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND);
1510 /* wake up processes waiting for synchronization */
1511 wake_up(&sc->sync_q);
1513 /* TODO improve this state machine :
1514 * we need some CMV info : what they do and their unit
1515 * we should find the equivalent of eagle3- CMV
1518 ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags);
1521 sc->stats.phy.mflags |= sc->stats.phy.flags;
1523 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1524 * we check the status again in order to detect the failure earlier
1526 if (sc->stats.phy.flags) {
1527 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1528 sc->stats.phy.flags);
1529 if (sc->stats.phy.flags & 1) /* delineation LOSS */
1531 if (sc->stats.phy.flags & 0x4000) /* Reset Flag */
1536 /* rate data may be in upper or lower half of 64 bit word, strange */
1537 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr);
1540 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1541 sc->stats.phy.usrate = data / 1000;
1543 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr);
1546 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1547 uea_set_bulk_timeout(sc, data / 1000);
1548 sc->stats.phy.dsrate = data / 1000;
1549 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1551 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data);
1554 sc->stats.phy.dsattenuation = data / 10;
1556 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data);
1559 sc->stats.phy.usattenuation = data / 10;
1561 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data);
1564 sc->stats.phy.dsmargin = data / 2;
1566 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data);
1569 sc->stats.phy.usmargin = data / 10;
1574 static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1576 char file_arr[] = "CMVxy.bin";
1579 kparam_block_sysfs_write(cmv_file);
1580 /* set proper name corresponding modem version and line type */
1581 if (cmv_file[sc->modem_index] == NULL) {
1582 if (UEA_CHIP_VERSION(sc) == ADI930)
1584 else if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1589 file_arr[4] = IS_ISDN(sc) ? 'i' : 'p';
1592 file = cmv_file[sc->modem_index];
1594 strcpy(cmv_name, FW_DIR);
1595 strlcat(cmv_name, file, UEA_FW_NAME_MAX);
1597 strlcat(cmv_name, ".v2", UEA_FW_NAME_MAX);
1598 kparam_unblock_sysfs_write(cmv_file);
1601 static int request_cmvs_old(struct uea_softc *sc,
1602 void **cmvs, const struct firmware **fw)
1606 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
1608 cmvs_file_name(sc, cmv_name, 1);
1609 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1611 uea_err(INS_TO_USBDEV(sc),
1612 "requesting firmware %s failed with error %d\n",
1617 data = (u8 *) (*fw)->data;
1620 goto err_fw_corrupted;
1622 if (size != *data * sizeof(struct uea_cmvs_v1) + 1)
1623 goto err_fw_corrupted;
1625 *cmvs = (void *)(data + 1);
1629 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1630 release_firmware(*fw);
1634 static int request_cmvs(struct uea_softc *sc,
1635 void **cmvs, const struct firmware **fw, int *ver)
1640 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
1642 cmvs_file_name(sc, cmv_name, 2);
1643 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1645 /* if caller can handle old version, try to provide it */
1647 uea_warn(INS_TO_USBDEV(sc), "requesting "
1648 "firmware %s failed, "
1649 "try to get older cmvs\n", cmv_name);
1650 return request_cmvs_old(sc, cmvs, fw);
1652 uea_err(INS_TO_USBDEV(sc),
1653 "requesting firmware %s failed with error %d\n",
1659 data = (u8 *) (*fw)->data;
1660 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1662 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted,"
1663 " try to get older cmvs\n", cmv_name);
1664 release_firmware(*fw);
1665 return request_cmvs_old(sc, cmvs, fw);
1667 goto err_fw_corrupted;
1675 goto err_fw_corrupted;
1677 crc = get_unaligned_le32(data);
1680 if (crc32_be(0, data, size) != crc)
1681 goto err_fw_corrupted;
1683 if (size != *data * sizeof(struct uea_cmvs_v2) + 1)
1684 goto err_fw_corrupted;
1686 *cmvs = (void *) (data + 1);
1690 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1691 release_firmware(*fw);
1695 static int uea_send_cmvs_e1(struct uea_softc *sc)
1699 const struct firmware *cmvs_fw;
1700 int ver = 1; /* we can handle v1 cmv firmware version; */
1702 /* Enter in R-IDLE (cmv) until instructed otherwise */
1703 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
1707 /* Dump firmware version */
1708 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid);
1711 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1712 sc->stats.phy.firmid);
1715 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1721 struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr;
1723 uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, "
1724 "please update your firmware\n");
1726 for (i = 0; i < len; i++) {
1727 ret = uea_write_cmv_e1(sc,
1728 get_unaligned_le32(&cmvs_v1[i].address),
1729 get_unaligned_le16(&cmvs_v1[i].offset),
1730 get_unaligned_le32(&cmvs_v1[i].data));
1734 } else if (ver == 2) {
1735 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1737 for (i = 0; i < len; i++) {
1738 ret = uea_write_cmv_e1(sc,
1739 get_unaligned_le32(&cmvs_v2[i].address),
1740 (u16) get_unaligned_le32(&cmvs_v2[i].offset),
1741 get_unaligned_le32(&cmvs_v2[i].data));
1746 /* This really should not happen */
1747 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1751 /* Enter in R-ACT-REQ */
1752 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1753 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1754 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1755 "synchronization...\n");
1757 release_firmware(cmvs_fw);
1761 static int uea_send_cmvs_e4(struct uea_softc *sc)
1765 const struct firmware *cmvs_fw;
1766 int ver = 2; /* we can only handle v2 cmv firmware version; */
1768 /* Enter in R-IDLE (cmv) until instructed otherwise */
1769 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
1773 /* Dump firmware version */
1774 /* XXX don't read the 3th byte as it is always 6 */
1775 ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid);
1778 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1779 sc->stats.phy.firmid);
1783 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1789 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1791 for (i = 0; i < len; i++) {
1792 ret = uea_write_cmv_e4(sc, 1,
1793 get_unaligned_le32(&cmvs_v2[i].group),
1794 get_unaligned_le32(&cmvs_v2[i].address),
1795 get_unaligned_le32(&cmvs_v2[i].offset),
1796 get_unaligned_le32(&cmvs_v2[i].data));
1801 /* This really should not happen */
1802 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1806 /* Enter in R-ACT-REQ */
1807 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1808 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1809 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1810 "synchronization...\n");
1812 release_firmware(cmvs_fw);
1816 /* Start boot post firmware modem:
1817 * - send reset commands through usb control pipe
1818 * - start workqueue for DSP loading
1819 * - send CMV options to modem
1822 static int uea_start_reset(struct uea_softc *sc)
1824 u16 zero = 0; /* ;-) */
1827 uea_enters(INS_TO_USBDEV(sc));
1828 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1830 /* mask interrupt */
1832 /* We need to set this here because, a ack timeout could have occurred,
1833 * but before we start the reboot, the ack occurs and set this to 1.
1834 * So we will failed to wait Ready CMV.
1837 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST);
1839 /* reset statistics */
1840 memset(&sc->stats, 0, sizeof(struct uea_stats));
1842 /* tell the modem that we want to boot in IDMA mode */
1843 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1844 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1846 /* enter reset mode */
1847 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1849 /* original driver use 200ms, but windows driver use 100ms */
1850 ret = uea_wait(sc, 0, msecs_to_jiffies(100));
1854 /* leave reset mode */
1855 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1857 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
1858 /* clear tx and rx mailboxes */
1859 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1860 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1861 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1864 ret = uea_wait(sc, 0, msecs_to_jiffies(1000));
1868 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1869 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
1872 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
1875 /* demask interrupt */
1878 /* start loading DSP */
1881 schedule_work(&sc->task);
1883 /* wait for modem ready CMV */
1884 ret = wait_cmv_ack(sc);
1888 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1890 ret = sc->send_cmvs(sc);
1895 uea_leaves(INS_TO_USBDEV(sc));
1900 * In case of an error wait 1s before rebooting the modem
1901 * if the modem don't request reboot (-EAGAIN).
1902 * Monitor the modem every 1s.
1905 static int uea_kthread(void *data)
1907 struct uea_softc *sc = data;
1911 uea_enters(INS_TO_USBDEV(sc));
1912 while (!kthread_should_stop()) {
1913 if (ret < 0 || sc->reset)
1914 ret = uea_start_reset(sc);
1918 uea_wait(sc, 0, msecs_to_jiffies(1000));
1921 uea_leaves(INS_TO_USBDEV(sc));
1925 /* Load second usb firmware for ADI930 chip */
1926 static int load_XILINX_firmware(struct uea_softc *sc)
1928 const struct firmware *fw_entry;
1929 int ret, size, u, ln;
1932 char *fw_name = FW_DIR "930-fpga.bin";
1934 uea_enters(INS_TO_USBDEV(sc));
1936 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1938 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1943 pfw = fw_entry->data;
1944 size = fw_entry->size;
1945 if (size != 0x577B) {
1946 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1951 for (u = 0; u < size; u += ln) {
1952 ln = min(size - u, 64);
1953 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1955 uea_err(INS_TO_USBDEV(sc),
1956 "elsa download data failed (%d)\n", ret);
1961 /* finish to send the fpga */
1962 ret = uea_request(sc, 0xe, 1, 0, NULL);
1964 uea_err(INS_TO_USBDEV(sc),
1965 "elsa download data failed (%d)\n", ret);
1969 /* Tell the modem we finish : de-assert reset */
1971 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1973 uea_err(sc->usb_dev, "elsa de-assert failed with error"
1977 release_firmware(fw_entry);
1979 uea_leaves(INS_TO_USBDEV(sc));
1983 /* The modem send us an ack. First with check if it right */
1984 static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
1986 struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;
1987 struct cmv_e1 *cmv = &intr->u.e1.s2.cmv;
1989 uea_enters(INS_TO_USBDEV(sc));
1990 if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE)
1993 if (cmv->bDirection != E1_MODEMTOHOST)
1996 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1997 * the first MEMACCESS cmv. Ignore it...
1999 if (cmv->bFunction != dsc->function) {
2000 if (UEA_CHIP_VERSION(sc) == ADI930
2001 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
2002 cmv->wIndex = cpu_to_le16(dsc->idx);
2003 put_unaligned_le32(dsc->address,
2004 &cmv->dwSymbolicAddress);
2005 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
2010 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
2012 wake_up_cmv_ack(sc);
2013 uea_leaves(INS_TO_USBDEV(sc));
2017 /* in case of MEMACCESS */
2018 if (le16_to_cpu(cmv->wIndex) != dsc->idx ||
2019 get_unaligned_le32(&cmv->dwSymbolicAddress) != dsc->address ||
2020 le16_to_cpu(cmv->wOffsetAddress) != dsc->offset)
2023 sc->data = get_unaligned_le32(&cmv->dwData);
2024 sc->data = sc->data << 16 | sc->data >> 16;
2026 wake_up_cmv_ack(sc);
2027 uea_leaves(INS_TO_USBDEV(sc));
2031 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
2032 "Function : %d, Subfunction : %d\n",
2033 E1_FUNCTION_TYPE(cmv->bFunction),
2034 E1_FUNCTION_SUBTYPE(cmv->bFunction));
2035 uea_leaves(INS_TO_USBDEV(sc));
2039 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
2040 "wPreamble %d, bDirection %d\n",
2041 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
2042 uea_leaves(INS_TO_USBDEV(sc));
2045 /* The modem send us an ack. First with check if it right */
2046 static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
2048 struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;
2049 struct cmv_e4 *cmv = &intr->u.e4.s2.cmv;
2051 uea_enters(INS_TO_USBDEV(sc));
2052 uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n",
2053 be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction),
2054 be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
2055 be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1]));
2057 if (be16_to_cpu(cmv->wFunction) != dsc->function)
2060 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
2061 E4_MODEMREADY, 1)) {
2062 wake_up_cmv_ack(sc);
2063 uea_leaves(INS_TO_USBDEV(sc));
2067 /* in case of MEMACCESS */
2068 if (be16_to_cpu(cmv->wOffset) != dsc->offset ||
2069 be16_to_cpu(cmv->wGroup) != dsc->group ||
2070 be16_to_cpu(cmv->wAddress) != dsc->address)
2073 sc->data = be32_to_cpu(cmv->dwData[0]);
2074 sc->data1 = be32_to_cpu(cmv->dwData[1]);
2075 wake_up_cmv_ack(sc);
2076 uea_leaves(INS_TO_USBDEV(sc));
2080 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
2081 "Function : %d, Subfunction : %d\n",
2082 E4_FUNCTION_TYPE(cmv->wFunction),
2083 E4_FUNCTION_SUBTYPE(cmv->wFunction));
2084 uea_leaves(INS_TO_USBDEV(sc));
2088 static void uea_schedule_load_page_e1(struct uea_softc *sc,
2089 struct intr_pkt *intr)
2091 sc->pageno = intr->e1_bSwapPageNo;
2092 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
2093 schedule_work(&sc->task);
2096 static void uea_schedule_load_page_e4(struct uea_softc *sc,
2097 struct intr_pkt *intr)
2099 sc->pageno = intr->e4_bSwapPageNo;
2100 schedule_work(&sc->task);
2106 static void uea_intr(struct urb *urb)
2108 struct uea_softc *sc = urb->context;
2109 struct intr_pkt *intr = urb->transfer_buffer;
2110 int status = urb->status;
2112 uea_enters(INS_TO_USBDEV(sc));
2114 if (unlikely(status < 0)) {
2115 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
2120 /* device-to-host interrupt */
2121 if (intr->bType != 0x08 || sc->booting) {
2122 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
2126 switch (le16_to_cpu(intr->wInterrupt)) {
2127 case INT_LOADSWAPPAGE:
2128 sc->schedule_load_page(sc, intr);
2131 case INT_INCOMINGCMV:
2132 sc->dispatch_cmv(sc, intr);
2136 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
2137 le16_to_cpu(intr->wInterrupt));
2141 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
2145 * Start the modem : init the data and start kernel thread
2147 static int uea_boot(struct uea_softc *sc)
2150 struct intr_pkt *intr;
2152 uea_enters(INS_TO_USBDEV(sc));
2154 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2155 size = E4_INTR_PKT_SIZE;
2156 sc->dispatch_cmv = uea_dispatch_cmv_e4;
2157 sc->schedule_load_page = uea_schedule_load_page_e4;
2158 sc->stat = uea_stat_e4;
2159 sc->send_cmvs = uea_send_cmvs_e4;
2160 INIT_WORK(&sc->task, uea_load_page_e4);
2162 size = E1_INTR_PKT_SIZE;
2163 sc->dispatch_cmv = uea_dispatch_cmv_e1;
2164 sc->schedule_load_page = uea_schedule_load_page_e1;
2165 sc->stat = uea_stat_e1;
2166 sc->send_cmvs = uea_send_cmvs_e1;
2167 INIT_WORK(&sc->task, uea_load_page_e1);
2170 init_waitqueue_head(&sc->sync_q);
2172 if (UEA_CHIP_VERSION(sc) == ADI930)
2173 load_XILINX_firmware(sc);
2175 intr = kmalloc(size, GFP_KERNEL);
2177 uea_err(INS_TO_USBDEV(sc),
2178 "cannot allocate interrupt package\n");
2182 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
2184 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
2188 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
2189 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
2190 intr, size, uea_intr, sc,
2191 sc->usb_dev->actconfig->interface[0]->altsetting[0].
2192 endpoint[0].desc.bInterval);
2194 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2196 uea_err(INS_TO_USBDEV(sc),
2197 "urb submition failed with error %d\n", ret);
2201 /* Create worker thread, but don't start it here. Start it after
2202 * all usbatm generic initialization is done.
2204 sc->kthread = kthread_create(uea_kthread, sc, "ueagle-atm");
2205 if (IS_ERR(sc->kthread)) {
2206 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2210 uea_leaves(INS_TO_USBDEV(sc));
2214 usb_kill_urb(sc->urb_int);
2216 usb_free_urb(sc->urb_int);
2220 uea_leaves(INS_TO_USBDEV(sc));
2225 * Stop the modem : kill kernel thread and free data
2227 static void uea_stop(struct uea_softc *sc)
2230 uea_enters(INS_TO_USBDEV(sc));
2231 ret = kthread_stop(sc->kthread);
2232 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
2234 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
2236 usb_kill_urb(sc->urb_int);
2237 kfree(sc->urb_int->transfer_buffer);
2238 usb_free_urb(sc->urb_int);
2240 /* flush the work item, when no one can schedule it */
2241 flush_work_sync(&sc->task);
2244 release_firmware(sc->dsp_firm);
2245 uea_leaves(INS_TO_USBDEV(sc));
2248 /* syfs interface */
2249 static struct uea_softc *dev_to_uea(struct device *dev)
2251 struct usb_interface *intf;
2252 struct usbatm_data *usbatm;
2254 intf = to_usb_interface(dev);
2258 usbatm = usb_get_intfdata(intf);
2262 return usbatm->driver_data;
2265 static ssize_t read_status(struct device *dev, struct device_attribute *attr,
2269 struct uea_softc *sc;
2271 mutex_lock(&uea_mutex);
2272 sc = dev_to_uea(dev);
2275 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
2277 mutex_unlock(&uea_mutex);
2281 static ssize_t reboot(struct device *dev, struct device_attribute *attr,
2282 const char *buf, size_t count)
2285 struct uea_softc *sc;
2287 mutex_lock(&uea_mutex);
2288 sc = dev_to_uea(dev);
2294 mutex_unlock(&uea_mutex);
2298 static DEVICE_ATTR(stat_status, S_IWUSR | S_IRUGO, read_status, reboot);
2300 static ssize_t read_human_status(struct device *dev,
2301 struct device_attribute *attr, char *buf)
2305 struct uea_softc *sc;
2307 mutex_lock(&uea_mutex);
2308 sc = dev_to_uea(dev);
2312 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2313 switch (sc->stats.phy.state) {
2314 case 0x0: /* not yet synchronized */
2320 case 0x5: /* initialization */
2326 case 0x7: /* operational */
2329 case 0x2: /* fail ... */
2332 default: /* unknown */
2337 modem_state = GET_STATUS(sc->stats.phy.state);
2339 switch (modem_state) {
2341 ret = sprintf(buf, "Modem is booting\n");
2344 ret = sprintf(buf, "Modem is initializing\n");
2347 ret = sprintf(buf, "Modem is operational\n");
2350 ret = sprintf(buf, "Modem synchronization failed\n");
2353 ret = sprintf(buf, "Modem state is unknown\n");
2357 mutex_unlock(&uea_mutex);
2361 static DEVICE_ATTR(stat_human_status, S_IRUGO, read_human_status, NULL);
2363 static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2367 struct uea_softc *sc;
2368 char *delin = "GOOD";
2370 mutex_lock(&uea_mutex);
2371 sc = dev_to_uea(dev);
2375 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2376 if (sc->stats.phy.flags & 0x4000)
2378 else if (sc->stats.phy.flags & 0x0001)
2381 if (sc->stats.phy.flags & 0x0C00)
2383 else if (sc->stats.phy.flags & 0x0030)
2387 ret = sprintf(buf, "%s\n", delin);
2389 mutex_unlock(&uea_mutex);
2393 static DEVICE_ATTR(stat_delin, S_IRUGO, read_delin, NULL);
2395 #define UEA_ATTR(name, reset) \
2397 static ssize_t read_##name(struct device *dev, \
2398 struct device_attribute *attr, char *buf) \
2400 int ret = -ENODEV; \
2401 struct uea_softc *sc; \
2403 mutex_lock(&uea_mutex); \
2404 sc = dev_to_uea(dev); \
2407 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2409 sc->stats.phy.name = 0; \
2411 mutex_unlock(&uea_mutex); \
2415 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2417 UEA_ATTR(mflags, 1);
2418 UEA_ATTR(vidcpe, 0);
2419 UEA_ATTR(usrate, 0);
2420 UEA_ATTR(dsrate, 0);
2421 UEA_ATTR(usattenuation, 0);
2422 UEA_ATTR(dsattenuation, 0);
2423 UEA_ATTR(usmargin, 0);
2424 UEA_ATTR(dsmargin, 0);
2425 UEA_ATTR(txflow, 0);
2426 UEA_ATTR(rxflow, 0);
2427 UEA_ATTR(uscorr, 0);
2428 UEA_ATTR(dscorr, 0);
2431 UEA_ATTR(firmid, 0);
2433 /* Retrieve the device End System Identifier (MAC) */
2435 static int uea_getesi(struct uea_softc *sc, u_char * esi)
2437 unsigned char mac_str[2 * ETH_ALEN + 1];
2440 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
2441 sizeof(mac_str)) != 2 * ETH_ALEN)
2444 for (i = 0; i < ETH_ALEN; i++)
2445 esi[i] = hex_to_bin(mac_str[2 * i]) * 16 +
2446 hex_to_bin(mac_str[2 * i + 1]);
2452 static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
2454 struct uea_softc *sc = usbatm->driver_data;
2456 return uea_getesi(sc, atm_dev->esi);
2459 static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
2461 struct uea_softc *sc = usbatm->driver_data;
2463 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
2469 static int claim_interface(struct usb_device *usb_dev,
2470 struct usbatm_data *usbatm, int ifnum)
2473 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
2476 uea_err(usb_dev, "interface %d not found\n", ifnum);
2480 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
2482 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
2487 static struct attribute *attrs[] = {
2488 &dev_attr_stat_status.attr,
2489 &dev_attr_stat_mflags.attr,
2490 &dev_attr_stat_human_status.attr,
2491 &dev_attr_stat_delin.attr,
2492 &dev_attr_stat_vidcpe.attr,
2493 &dev_attr_stat_usrate.attr,
2494 &dev_attr_stat_dsrate.attr,
2495 &dev_attr_stat_usattenuation.attr,
2496 &dev_attr_stat_dsattenuation.attr,
2497 &dev_attr_stat_usmargin.attr,
2498 &dev_attr_stat_dsmargin.attr,
2499 &dev_attr_stat_txflow.attr,
2500 &dev_attr_stat_rxflow.attr,
2501 &dev_attr_stat_uscorr.attr,
2502 &dev_attr_stat_dscorr.attr,
2503 &dev_attr_stat_usunc.attr,
2504 &dev_attr_stat_dsunc.attr,
2505 &dev_attr_stat_firmid.attr,
2508 static struct attribute_group attr_grp = {
2512 static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
2513 const struct usb_device_id *id)
2515 struct usb_device *usb = interface_to_usbdev(intf);
2516 struct uea_softc *sc;
2517 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
2522 /* interface 0 is for firmware/monitoring */
2523 if (ifnum != UEA_INTR_IFACE_NO)
2526 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
2528 /* interface 1 is for outbound traffic */
2529 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
2533 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
2534 if (UEA_CHIP_VERSION(id) != ADI930) {
2535 /* interface 2 is for inbound traffic */
2536 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
2541 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
2543 uea_err(usb, "uea_init: not enough memory !\n");
2548 usbatm->driver_data = sc;
2549 sc->usbatm = usbatm;
2550 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
2551 sc->driver_info = id->driver_info;
2553 /* first try to use module parameter */
2554 if (annex[sc->modem_index] == 1)
2556 else if (annex[sc->modem_index] == 2)
2558 /* try to autodetect annex */
2559 else if (sc->driver_info & AUTO_ANNEX_A)
2561 else if (sc->driver_info & AUTO_ANNEX_B)
2564 sc->annex = (le16_to_cpu
2565 (sc->usb_dev->descriptor.bcdDevice) & 0x80) ? ANNEXB : ANNEXA;
2567 alt = altsetting[sc->modem_index];
2568 /* ADI930 don't support iso */
2569 if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) {
2571 usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) {
2572 uea_dbg(usb, "set alternate %u for 2 interface\n", alt);
2573 uea_info(usb, "using iso mode\n");
2574 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
2576 uea_err(usb, "setting alternate %u failed for "
2577 "2 interface, using bulk mode\n", alt);
2581 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
2592 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2598 static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
2600 struct uea_softc *sc = usbatm->driver_data;
2602 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2607 static struct usbatm_driver uea_usbatm_driver = {
2608 .driver_name = "ueagle-atm",
2610 .atm_start = uea_atm_open,
2611 .unbind = uea_unbind,
2612 .heavy_init = uea_heavy,
2613 .bulk_in = UEA_BULK_DATA_PIPE,
2614 .bulk_out = UEA_BULK_DATA_PIPE,
2615 .isoc_in = UEA_ISO_DATA_PIPE,
2618 static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2620 struct usb_device *usb = interface_to_usbdev(intf);
2624 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2625 le16_to_cpu(usb->descriptor.idVendor),
2626 le16_to_cpu(usb->descriptor.idProduct),
2627 le16_to_cpu(usb->descriptor.bcdDevice),
2628 chip_name[UEA_CHIP_VERSION(id)]);
2630 usb_reset_device(usb);
2632 if (UEA_IS_PREFIRM(id))
2633 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2635 ret = usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2637 struct usbatm_data *usbatm = usb_get_intfdata(intf);
2638 struct uea_softc *sc = usbatm->driver_data;
2640 /* Ensure carrier is initialized to off as early as possible */
2641 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST);
2643 /* Only start the worker thread when all init is done */
2644 wake_up_process(sc->kthread);
2650 static void uea_disconnect(struct usb_interface *intf)
2652 struct usb_device *usb = interface_to_usbdev(intf);
2653 int ifnum = intf->altsetting->desc.bInterfaceNumber;
2656 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2657 * Pre-firmware device has one interface
2659 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
2660 mutex_lock(&uea_mutex);
2661 usbatm_usb_disconnect(intf);
2662 mutex_unlock(&uea_mutex);
2663 uea_info(usb, "ADSL device removed\n");
2670 * List of supported VID/PID
2672 static const struct usb_device_id uea_ids[] = {
2673 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM),
2674 .driver_info = ADI930 | PREFIRM},
2675 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM),
2676 .driver_info = ADI930 | PSTFIRM},
2677 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM),
2678 .driver_info = EAGLE_I | PREFIRM},
2679 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM),
2680 .driver_info = EAGLE_I | PSTFIRM},
2681 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM),
2682 .driver_info = EAGLE_II | PREFIRM},
2683 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM),
2684 .driver_info = EAGLE_II | PSTFIRM},
2685 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM),
2686 .driver_info = EAGLE_II | PREFIRM},
2687 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM),
2688 .driver_info = EAGLE_II | PSTFIRM},
2689 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM),
2690 .driver_info = EAGLE_III | PREFIRM},
2691 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM),
2692 .driver_info = EAGLE_III | PSTFIRM},
2693 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM),
2694 .driver_info = EAGLE_IV | PREFIRM},
2695 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM),
2696 .driver_info = EAGLE_IV | PSTFIRM},
2697 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM),
2698 .driver_info = EAGLE_I | PREFIRM},
2699 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM),
2700 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2701 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM),
2702 .driver_info = EAGLE_I | PREFIRM},
2703 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM),
2704 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2705 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM),
2706 .driver_info = EAGLE_II | PREFIRM},
2707 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM),
2708 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A},
2709 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM),
2710 .driver_info = EAGLE_II | PREFIRM},
2711 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM),
2712 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B},
2713 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM),
2714 .driver_info = ADI930 | PREFIRM},
2715 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM),
2716 .driver_info = ADI930 | PSTFIRM},
2717 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM),
2718 .driver_info = ADI930 | PREFIRM},
2719 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM),
2720 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A},
2721 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM),
2722 .driver_info = ADI930 | PREFIRM},
2723 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM),
2724 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B},
2725 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM),
2726 .driver_info = EAGLE_I | PREFIRM},
2727 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM),
2728 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2729 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM),
2730 .driver_info = EAGLE_I | PREFIRM},
2731 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM),
2732 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2733 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),
2734 .driver_info = EAGLE_I | PREFIRM},
2735 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),
2736 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2737 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),
2738 .driver_info = EAGLE_I | PREFIRM},
2739 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),
2740 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2745 * USB driver descriptor
2747 static struct usb_driver uea_driver = {
2748 .name = "ueagle-atm",
2749 .id_table = uea_ids,
2751 .disconnect = uea_disconnect,
2754 MODULE_DEVICE_TABLE(usb, uea_ids);
2756 module_usb_driver(uea_driver);
2758 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2759 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2760 MODULE_LICENSE("Dual BSD/GPL");