mm, vmalloc: remove useless variable in vmap_block
[linux/fpc-iii.git] / drivers / usb / atm / ueagle-atm.c
blobdefff43950bc11a6ae49ee6d0c80f446e31701c9
1 /*-
2 * Copyright (c) 2003, 2004
3 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
5 * Copyright (c) 2005-2007 Matthieu Castet <castet.matthieu@free.fr>
6 * Copyright (c) 2005-2007 Stanislaw Gruszka <stf_xl@wp.pl>
8 * This software is available to you under a choice of one of two
9 * licenses. You may choose to be licensed under the terms of the GNU
10 * General Public License (GPL) Version 2, available from the file
11 * COPYING in the main directory of this source tree, or the
12 * BSD license below:
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice unmodified, this list of conditions, and the following
19 * disclaimer.
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
34 * SUCH DAMAGE.
36 * GPL license :
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>
74 #include "usbatm.h"
76 #define EAGLEUSBVERSION "ueagle 1.4"
80 * Debug macros
82 #define uea_dbg(usb_dev, format, args...) \
83 do { \
84 if (debug >= 1) \
85 dev_dbg(&(usb_dev)->dev, \
86 "[ueagle-atm dbg] %s: " format, \
87 __func__, ##args); \
88 } while (0)
90 #define uea_vdbg(usb_dev, format, args...) \
91 do { \
92 if (debug >= 2) \
93 dev_dbg(&(usb_dev)->dev, \
94 "[ueagle-atm vdbg] " format, ##args); \
95 } while (0)
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)
112 struct intr_pkt;
114 /* cmv's from firmware */
115 struct uea_cmvs_v1 {
116 u32 address;
117 u16 offset;
118 u32 data;
119 } __packed;
121 struct uea_cmvs_v2 {
122 u32 group;
123 u32 address;
124 u32 offset;
125 u32 data;
126 } __packed;
128 /* information about currently processed cmv */
129 struct cmv_dsc_e1 {
130 u8 function;
131 u16 idx;
132 u32 address;
133 u16 offset;
136 struct cmv_dsc_e4 {
137 u16 function;
138 u16 offset;
139 u16 address;
140 u16 group;
143 union cmv_dsc {
144 struct cmv_dsc_e1 e1;
145 struct cmv_dsc_e4 e4;
148 struct uea_softc {
149 struct usb_device *usb_dev;
150 struct usbatm_data *usbatm;
152 int modem_index;
153 unsigned int driver_info;
154 int annex;
155 #define ANNEXA 0
156 #define ANNEXB 1
158 int booting;
159 int reset;
161 wait_queue_head_t sync_q;
163 struct task_struct *kthread;
164 u32 data;
165 u32 data1;
167 int cmv_ack;
168 union cmv_dsc cmv_dsc;
170 struct work_struct task;
171 u16 pageno;
172 u16 ovl;
174 const struct firmware *dsp_firm;
175 struct urb *urb_int;
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 */
183 struct uea_stats {
184 struct {
185 u32 state;
186 u32 flags;
187 u32 mflags;
188 u32 vidcpe;
189 u32 vidco;
190 u32 dsrate;
191 u32 usrate;
192 u32 dsunc;
193 u32 usunc;
194 u32 dscorr;
195 u32 uscorr;
196 u32 txflow;
197 u32 rxflow;
198 u32 usattenuation;
199 u32 dsattenuation;
200 u32 dsmargin;
201 u32 usmargin;
202 u32 firmid;
203 } phy;
204 } stats;
208 * Elsa IDs
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 */
258 * USR USB IDs
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
270 #define PREFIRM 0
271 #define PSTFIRM (1<<7)
272 #define AUTO_ANNEX_A (1<<8)
273 #define AUTO_ANNEX_B (1<<9)
275 enum {
276 ADI930 = 0,
277 EAGLE_I,
278 EAGLE_II,
279 EAGLE_III,
280 EAGLE_IV
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)
289 #define IS_ISDN(x) \
290 ((x)->annex & ANNEXB)
292 #define INS_TO_USBDEV(ins) (ins->usb_dev)
294 #define GET_STATUS(data) \
295 ((data >> 8) & 0xf)
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 EAGLE_FIRMWARE FW_DIR "eagle.fw"
311 #define ADI930_FIRMWARE FW_DIR "adi930.fw"
312 #define EAGLE_I_FIRMWARE FW_DIR "eagleI.fw"
313 #define EAGLE_II_FIRMWARE FW_DIR "eagleII.fw"
314 #define EAGLE_III_FIRMWARE FW_DIR "eagleIII.fw"
315 #define EAGLE_IV_FIRMWARE FW_DIR "eagleIV.fw"
317 #define DSP4I_FIRMWARE FW_DIR "DSP4i.bin"
318 #define DSP4P_FIRMWARE FW_DIR "DSP4p.bin"
319 #define DSP9I_FIRMWARE FW_DIR "DSP9i.bin"
320 #define DSP9P_FIRMWARE FW_DIR "DSP9p.bin"
321 #define DSPEI_FIRMWARE FW_DIR "DSPei.bin"
322 #define DSPEP_FIRMWARE FW_DIR "DSPep.bin"
323 #define FPGA930_FIRMWARE FW_DIR "930-fpga.bin"
325 #define CMV4P_FIRMWARE FW_DIR "CMV4p.bin"
326 #define CMV4PV2_FIRMWARE FW_DIR "CMV4p.bin.v2"
327 #define CMV4I_FIRMWARE FW_DIR "CMV4i.bin"
328 #define CMV4IV2_FIRMWARE FW_DIR "CMV4i.bin.v2"
329 #define CMV9P_FIRMWARE FW_DIR "CMV9p.bin"
330 #define CMV9PV2_FIRMWARE FW_DIR "CMV9p.bin.v2"
331 #define CMV9I_FIRMWARE FW_DIR "CMV9i.bin"
332 #define CMV9IV2_FIRMWARE FW_DIR "CMV9i.bin.v2"
333 #define CMVEP_FIRMWARE FW_DIR "CMVep.bin"
334 #define CMVEPV2_FIRMWARE FW_DIR "CMVep.bin.v2"
335 #define CMVEI_FIRMWARE FW_DIR "CMVei.bin"
336 #define CMVEIV2_FIRMWARE FW_DIR "CMVei.bin.v2"
338 #define UEA_FW_NAME_MAX 30
339 #define NB_MODEM 4
341 #define BULK_TIMEOUT 300
342 #define CTRL_TIMEOUT 1000
344 #define ACK_TIMEOUT msecs_to_jiffies(3000)
346 #define UEA_INTR_IFACE_NO 0
347 #define UEA_US_IFACE_NO 1
348 #define UEA_DS_IFACE_NO 2
350 #define FASTEST_ISO_INTF 8
352 #define UEA_BULK_DATA_PIPE 0x02
353 #define UEA_IDMA_PIPE 0x04
354 #define UEA_INTR_PIPE 0x04
355 #define UEA_ISO_DATA_PIPE 0x08
357 #define UEA_E1_SET_BLOCK 0x0001
358 #define UEA_E4_SET_BLOCK 0x002c
359 #define UEA_SET_MODE 0x0003
360 #define UEA_SET_2183_DATA 0x0004
361 #define UEA_SET_TIMEOUT 0x0011
363 #define UEA_LOOPBACK_OFF 0x0002
364 #define UEA_LOOPBACK_ON 0x0003
365 #define UEA_BOOT_IDMA 0x0006
366 #define UEA_START_RESET 0x0007
367 #define UEA_END_RESET 0x0008
369 #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
370 #define UEA_MPTX_START (0x3fce | 0x4000)
371 #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
372 #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
374 /* block information in eagle4 dsp firmware */
375 struct block_index {
376 __le32 PageOffset;
377 __le32 NotLastBlock;
378 __le32 dummy;
379 __le32 PageSize;
380 __le32 PageAddress;
381 __le16 dummy1;
382 __le16 PageNumber;
383 } __packed;
385 #define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
386 #define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
388 #define E4_L1_STRING_HEADER 0x10
389 #define E4_MAX_PAGE_NUMBER 0x58
390 #define E4_NO_SWAPPAGE_HEADERS 0x31
392 /* l1_code is eagle4 dsp firmware format */
393 struct l1_code {
394 u8 string_header[E4_L1_STRING_HEADER];
395 u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER];
396 struct block_index page_header[E4_NO_SWAPPAGE_HEADERS];
397 u8 code[0];
398 } __packed;
400 /* structures describing a block within a DSP page */
401 struct block_info_e1 {
402 __le16 wHdr;
403 __le16 wAddress;
404 __le16 wSize;
405 __le16 wOvlOffset;
406 __le16 wOvl; /* overlay */
407 __le16 wLast;
408 } __packed;
409 #define E1_BLOCK_INFO_SIZE 12
411 struct block_info_e4 {
412 __be16 wHdr;
413 __u8 bBootPage;
414 __u8 bPageNumber;
415 __be32 dwSize;
416 __be32 dwAddress;
417 __be16 wReserved;
418 } __packed;
419 #define E4_BLOCK_INFO_SIZE 14
421 #define UEA_BIHDR 0xabcd
422 #define UEA_RESERVED 0xffff
424 /* constants describing cmv type */
425 #define E1_PREAMBLE 0x535c
426 #define E1_MODEMTOHOST 0x01
427 #define E1_HOSTTOMODEM 0x10
429 #define E1_MEMACCESS 0x1
430 #define E1_ADSLDIRECTIVE 0x7
431 #define E1_FUNCTION_TYPE(f) ((f) >> 4)
432 #define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f)
434 #define E4_MEMACCESS 0
435 #define E4_ADSLDIRECTIVE 0xf
436 #define E4_FUNCTION_TYPE(f) ((f) >> 8)
437 #define E4_FUNCTION_SIZE(f) ((f) & 0x0f)
438 #define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f)
440 /* for MEMACCESS */
441 #define E1_REQUESTREAD 0x0
442 #define E1_REQUESTWRITE 0x1
443 #define E1_REPLYREAD 0x2
444 #define E1_REPLYWRITE 0x3
446 #define E4_REQUESTREAD 0x0
447 #define E4_REQUESTWRITE 0x4
448 #define E4_REPLYREAD (E4_REQUESTREAD | 1)
449 #define E4_REPLYWRITE (E4_REQUESTWRITE | 1)
451 /* for ADSLDIRECTIVE */
452 #define E1_KERNELREADY 0x0
453 #define E1_MODEMREADY 0x1
455 #define E4_KERNELREADY 0x0
456 #define E4_MODEMREADY 0x1
458 #define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
459 #define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | \
460 ((st) & 0xf) << 4 | ((s) & 0xf))
462 #define E1_MAKESA(a, b, c, d) \
463 (((c) & 0xff) << 24 | \
464 ((d) & 0xff) << 16 | \
465 ((a) & 0xff) << 8 | \
466 ((b) & 0xff))
468 #define E1_GETSA1(a) ((a >> 8) & 0xff)
469 #define E1_GETSA2(a) (a & 0xff)
470 #define E1_GETSA3(a) ((a >> 24) & 0xff)
471 #define E1_GETSA4(a) ((a >> 16) & 0xff)
473 #define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L')
474 #define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G')
475 #define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O')
476 #define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N')
477 #define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E')
478 #define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T')
480 #define E4_SA_CNTL 1
481 #define E4_SA_STAT 2
482 #define E4_SA_INFO 3
483 #define E4_SA_TEST 4
484 #define E4_SA_OPTN 5
485 #define E4_SA_RATE 6
486 #define E4_SA_DIAG 7
487 #define E4_SA_CNFG 8
489 /* structures representing a CMV (Configuration and Management Variable) */
490 struct cmv_e1 {
491 __le16 wPreamble;
492 __u8 bDirection;
493 __u8 bFunction;
494 __le16 wIndex;
495 __le32 dwSymbolicAddress;
496 __le16 wOffsetAddress;
497 __le32 dwData;
498 } __packed;
500 struct cmv_e4 {
501 __be16 wGroup;
502 __be16 wFunction;
503 __be16 wOffset;
504 __be16 wAddress;
505 __be32 dwData[6];
506 } __packed;
508 /* structures representing swap information */
509 struct swap_info_e1 {
510 __u8 bSwapPageNo;
511 __u8 bOvl; /* overlay */
512 } __packed;
514 struct swap_info_e4 {
515 __u8 bSwapPageNo;
516 } __packed;
518 /* structures representing interrupt data */
519 #define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
520 #define e1_bOvl u.e1.s1.swapinfo.bOvl
521 #define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo
523 #define INT_LOADSWAPPAGE 0x0001
524 #define INT_INCOMINGCMV 0x0002
526 union intr_data_e1 {
527 struct {
528 struct swap_info_e1 swapinfo;
529 __le16 wDataSize;
530 } __packed s1;
531 struct {
532 struct cmv_e1 cmv;
533 __le16 wDataSize;
534 } __packed s2;
535 } __packed;
537 union intr_data_e4 {
538 struct {
539 struct swap_info_e4 swapinfo;
540 __le16 wDataSize;
541 } __packed s1;
542 struct {
543 struct cmv_e4 cmv;
544 __le16 wDataSize;
545 } __packed s2;
546 } __packed;
548 struct intr_pkt {
549 __u8 bType;
550 __u8 bNotification;
551 __le16 wValue;
552 __le16 wIndex;
553 __le16 wLength;
554 __le16 wInterrupt;
555 union {
556 union intr_data_e1 e1;
557 union intr_data_e4 e4;
558 } u;
559 } __packed;
561 #define E1_INTR_PKT_SIZE 28
562 #define E4_INTR_PKT_SIZE 64
564 static struct usb_driver uea_driver;
565 static DEFINE_MUTEX(uea_mutex);
566 static const char * const chip_name[] = {
567 "ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
569 static int modem_index;
570 static unsigned int debug;
571 static unsigned int altsetting[NB_MODEM] = {
572 [0 ... (NB_MODEM - 1)] = FASTEST_ISO_INTF};
573 static bool sync_wait[NB_MODEM];
574 static char *cmv_file[NB_MODEM];
575 static int annex[NB_MODEM];
577 module_param(debug, uint, 0644);
578 MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
579 module_param_array(altsetting, uint, NULL, 0644);
580 MODULE_PARM_DESC(altsetting, "alternate setting for incoming traffic: 0=bulk, "
581 "1=isoc slowest, ... , 8=isoc fastest (default)");
582 module_param_array(sync_wait, bool, NULL, 0644);
583 MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
584 module_param_array(cmv_file, charp, NULL, 0644);
585 MODULE_PARM_DESC(cmv_file,
586 "file name with configuration and management variables");
587 module_param_array(annex, uint, NULL, 0644);
588 MODULE_PARM_DESC(annex,
589 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
591 #define uea_wait(sc, cond, timeo) \
592 ({ \
593 int _r = wait_event_interruptible_timeout(sc->sync_q, \
594 (cond) || kthread_should_stop(), timeo); \
595 if (kthread_should_stop()) \
596 _r = -ENODEV; \
597 _r; \
600 #define UPDATE_ATM_STAT(type, val) \
601 do { \
602 if (sc->usbatm->atm_dev) \
603 sc->usbatm->atm_dev->type = val; \
604 } while (0)
606 #define UPDATE_ATM_SIGNAL(val) \
607 do { \
608 if (sc->usbatm->atm_dev) \
609 atm_dev_signal_change(sc->usbatm->atm_dev, val); \
610 } while (0)
613 /* Firmware loading */
614 #define LOAD_INTERNAL 0xA0
615 #define F8051_USBCS 0x7f92
618 * uea_send_modem_cmd - Send a command for pre-firmware devices.
620 static int uea_send_modem_cmd(struct usb_device *usb,
621 u16 addr, u16 size, const u8 *buff)
623 int ret = -ENOMEM;
624 u8 *xfer_buff;
626 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
627 if (xfer_buff) {
628 ret = usb_control_msg(usb,
629 usb_sndctrlpipe(usb, 0),
630 LOAD_INTERNAL,
631 USB_DIR_OUT | USB_TYPE_VENDOR |
632 USB_RECIP_DEVICE, addr, 0, xfer_buff,
633 size, CTRL_TIMEOUT);
634 kfree(xfer_buff);
637 if (ret < 0)
638 return ret;
640 return (ret == size) ? 0 : -EIO;
643 static void uea_upload_pre_firmware(const struct firmware *fw_entry,
644 void *context)
646 struct usb_device *usb = context;
647 const u8 *pfw;
648 u8 value;
649 u32 crc = 0;
650 int ret, size;
652 uea_enters(usb);
653 if (!fw_entry) {
654 uea_err(usb, "firmware is not available\n");
655 goto err;
658 pfw = fw_entry->data;
659 size = fw_entry->size;
660 if (size < 4)
661 goto err_fw_corrupted;
663 crc = get_unaligned_le32(pfw);
664 pfw += 4;
665 size -= 4;
666 if (crc32_be(0, pfw, size) != crc)
667 goto err_fw_corrupted;
670 * Start to upload firmware : send reset
672 value = 1;
673 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
675 if (ret < 0) {
676 uea_err(usb, "modem reset failed with error %d\n", ret);
677 goto err;
680 while (size > 3) {
681 u8 len = FW_GET_BYTE(pfw);
682 u16 add = get_unaligned_le16(pfw + 1);
684 size -= len + 3;
685 if (size < 0)
686 goto err_fw_corrupted;
688 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
689 if (ret < 0) {
690 uea_err(usb, "uploading firmware data failed "
691 "with error %d\n", ret);
692 goto err;
694 pfw += len + 3;
697 if (size != 0)
698 goto err_fw_corrupted;
701 * Tell the modem we finish : de-assert reset
703 value = 0;
704 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
705 if (ret < 0)
706 uea_err(usb, "modem de-assert failed with error %d\n", ret);
707 else
708 uea_info(usb, "firmware uploaded\n");
710 goto err;
712 err_fw_corrupted:
713 uea_err(usb, "firmware is corrupted\n");
714 err:
715 release_firmware(fw_entry);
716 uea_leaves(usb);
720 * uea_load_firmware - Load usb firmware for pre-firmware devices.
722 static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
724 int ret;
725 char *fw_name = EAGLE_FIRMWARE;
727 uea_enters(usb);
728 uea_info(usb, "pre-firmware device, uploading firmware\n");
730 switch (ver) {
731 case ADI930:
732 fw_name = ADI930_FIRMWARE;
733 break;
734 case EAGLE_I:
735 fw_name = EAGLE_I_FIRMWARE;
736 break;
737 case EAGLE_II:
738 fw_name = EAGLE_II_FIRMWARE;
739 break;
740 case EAGLE_III:
741 fw_name = EAGLE_III_FIRMWARE;
742 break;
743 case EAGLE_IV:
744 fw_name = EAGLE_IV_FIRMWARE;
745 break;
748 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev,
749 GFP_KERNEL, usb,
750 uea_upload_pre_firmware);
751 if (ret)
752 uea_err(usb, "firmware %s is not available\n", fw_name);
753 else
754 uea_info(usb, "loading firmware %s\n", fw_name);
756 uea_leaves(usb);
757 return ret;
760 /* modem management : dsp firmware, send/read CMV, monitoring statistic
764 * Make sure that the DSP code provided is safe to use.
766 static int check_dsp_e1(const u8 *dsp, unsigned int len)
768 u8 pagecount, blockcount;
769 u16 blocksize;
770 u32 pageoffset;
771 unsigned int i, j, p, pp;
773 pagecount = FW_GET_BYTE(dsp);
774 p = 1;
776 /* enough space for page offsets? */
777 if (p + 4 * pagecount > len)
778 return 1;
780 for (i = 0; i < pagecount; i++) {
782 pageoffset = get_unaligned_le32(dsp + p);
783 p += 4;
785 if (pageoffset == 0)
786 continue;
788 /* enough space for blockcount? */
789 if (pageoffset >= len)
790 return 1;
792 pp = pageoffset;
793 blockcount = FW_GET_BYTE(dsp + pp);
794 pp += 1;
796 for (j = 0; j < blockcount; j++) {
798 /* enough space for block header? */
799 if (pp + 4 > len)
800 return 1;
802 pp += 2; /* skip blockaddr */
803 blocksize = get_unaligned_le16(dsp + pp);
804 pp += 2;
806 /* enough space for block data? */
807 if (pp + blocksize > len)
808 return 1;
810 pp += blocksize;
814 return 0;
817 static int check_dsp_e4(const u8 *dsp, int len)
819 int i;
820 struct l1_code *p = (struct l1_code *) dsp;
821 unsigned int sum = p->code - dsp;
823 if (len < sum)
824 return 1;
826 if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 &&
827 strcmp("STRATIPHY ANEXB", p->string_header) != 0)
828 return 1;
830 for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) {
831 struct block_index *blockidx;
832 u8 blockno = p->page_number_to_block_index[i];
833 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
834 continue;
836 do {
837 u64 l;
839 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
840 return 1;
842 blockidx = &p->page_header[blockno++];
843 if ((u8 *)(blockidx + 1) - dsp >= len)
844 return 1;
846 if (le16_to_cpu(blockidx->PageNumber) != i)
847 return 1;
849 l = E4_PAGE_BYTES(blockidx->PageSize);
850 sum += l;
851 l += le32_to_cpu(blockidx->PageOffset);
852 if (l > len)
853 return 1;
855 /* zero is zero regardless endianes */
856 } while (blockidx->NotLastBlock);
859 return (sum == len) ? 0 : 1;
863 * send data to the idma pipe
864 * */
865 static int uea_idma_write(struct uea_softc *sc, const void *data, u32 size)
867 int ret = -ENOMEM;
868 u8 *xfer_buff;
869 int bytes_read;
871 xfer_buff = kmemdup(data, size, GFP_KERNEL);
872 if (!xfer_buff) {
873 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
874 return ret;
877 ret = usb_bulk_msg(sc->usb_dev,
878 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
879 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
881 kfree(xfer_buff);
882 if (ret < 0)
883 return ret;
884 if (size != bytes_read) {
885 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
886 bytes_read);
887 return -EIO;
890 return 0;
893 static int request_dsp(struct uea_softc *sc)
895 int ret;
896 char *dsp_name;
898 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
899 if (IS_ISDN(sc))
900 dsp_name = DSP4I_FIRMWARE;
901 else
902 dsp_name = DSP4P_FIRMWARE;
903 } else if (UEA_CHIP_VERSION(sc) == ADI930) {
904 if (IS_ISDN(sc))
905 dsp_name = DSP9I_FIRMWARE;
906 else
907 dsp_name = DSP9P_FIRMWARE;
908 } else {
909 if (IS_ISDN(sc))
910 dsp_name = DSPEI_FIRMWARE;
911 else
912 dsp_name = DSPEP_FIRMWARE;
915 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
916 if (ret < 0) {
917 uea_err(INS_TO_USBDEV(sc),
918 "requesting firmware %s failed with error %d\n",
919 dsp_name, ret);
920 return ret;
923 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
924 ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size);
925 else
926 ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size);
928 if (ret) {
929 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
930 dsp_name);
931 release_firmware(sc->dsp_firm);
932 sc->dsp_firm = NULL;
933 return -EILSEQ;
936 return 0;
940 * The uea_load_page() function must be called within a process context
942 static void uea_load_page_e1(struct work_struct *work)
944 struct uea_softc *sc = container_of(work, struct uea_softc, task);
945 u16 pageno = sc->pageno;
946 u16 ovl = sc->ovl;
947 struct block_info_e1 bi;
949 const u8 *p;
950 u8 pagecount, blockcount;
951 u16 blockaddr, blocksize;
952 u32 pageoffset;
953 int i;
955 /* reload firmware when reboot start and it's loaded already */
956 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
957 release_firmware(sc->dsp_firm);
958 sc->dsp_firm = NULL;
961 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
962 return;
964 p = sc->dsp_firm->data;
965 pagecount = FW_GET_BYTE(p);
966 p += 1;
968 if (pageno >= pagecount)
969 goto bad1;
971 p += 4 * pageno;
972 pageoffset = get_unaligned_le32(p);
974 if (pageoffset == 0)
975 goto bad1;
977 p = sc->dsp_firm->data + pageoffset;
978 blockcount = FW_GET_BYTE(p);
979 p += 1;
981 uea_dbg(INS_TO_USBDEV(sc),
982 "sending %u blocks for DSP page %u\n", blockcount, pageno);
984 bi.wHdr = cpu_to_le16(UEA_BIHDR);
985 bi.wOvl = cpu_to_le16(ovl);
986 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
988 for (i = 0; i < blockcount; i++) {
989 blockaddr = get_unaligned_le16(p);
990 p += 2;
992 blocksize = get_unaligned_le16(p);
993 p += 2;
995 bi.wSize = cpu_to_le16(blocksize);
996 bi.wAddress = cpu_to_le16(blockaddr);
997 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
999 /* send block info through the IDMA pipe */
1000 if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE))
1001 goto bad2;
1003 /* send block data through the IDMA pipe */
1004 if (uea_idma_write(sc, p, blocksize))
1005 goto bad2;
1007 p += blocksize;
1010 return;
1012 bad2:
1013 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
1014 return;
1015 bad1:
1016 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
1019 static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
1021 struct block_info_e4 bi;
1022 struct block_index *blockidx;
1023 struct l1_code *p = (struct l1_code *) sc->dsp_firm->data;
1024 u8 blockno = p->page_number_to_block_index[pageno];
1026 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1027 bi.bBootPage = boot;
1028 bi.bPageNumber = pageno;
1029 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1031 do {
1032 const u8 *blockoffset;
1033 unsigned int blocksize;
1035 blockidx = &p->page_header[blockno];
1036 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
1037 blockoffset = sc->dsp_firm->data + le32_to_cpu(
1038 blockidx->PageOffset);
1040 bi.dwSize = cpu_to_be32(blocksize);
1041 bi.dwAddress = cpu_to_be32(le32_to_cpu(blockidx->PageAddress));
1043 uea_dbg(INS_TO_USBDEV(sc),
1044 "sending block %u for DSP page "
1045 "%u size %u address %x\n",
1046 blockno, pageno, blocksize,
1047 le32_to_cpu(blockidx->PageAddress));
1049 /* send block info through the IDMA pipe */
1050 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1051 goto bad;
1053 /* send block data through the IDMA pipe */
1054 if (uea_idma_write(sc, blockoffset, blocksize))
1055 goto bad;
1057 blockno++;
1058 } while (blockidx->NotLastBlock);
1060 return;
1062 bad:
1063 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno);
1064 return;
1067 static void uea_load_page_e4(struct work_struct *work)
1069 struct uea_softc *sc = container_of(work, struct uea_softc, task);
1070 u8 pageno = sc->pageno;
1071 int i;
1072 struct block_info_e4 bi;
1073 struct l1_code *p;
1075 uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
1077 /* reload firmware when reboot start and it's loaded already */
1078 if (pageno == 0 && sc->dsp_firm) {
1079 release_firmware(sc->dsp_firm);
1080 sc->dsp_firm = NULL;
1083 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
1084 return;
1086 p = (struct l1_code *) sc->dsp_firm->data;
1087 if (pageno >= le16_to_cpu(p->page_header[0].PageNumber)) {
1088 uea_err(INS_TO_USBDEV(sc), "invalid DSP "
1089 "page %u requested\n", pageno);
1090 return;
1093 if (pageno != 0) {
1094 __uea_load_page_e4(sc, pageno, 0);
1095 return;
1098 uea_dbg(INS_TO_USBDEV(sc),
1099 "sending Main DSP page %u\n", p->page_header[0].PageNumber);
1101 for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) {
1102 if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize))
1103 __uea_load_page_e4(sc, i, 1);
1106 uea_dbg(INS_TO_USBDEV(sc) , "sending start bi\n");
1108 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1109 bi.bBootPage = 0;
1110 bi.bPageNumber = 0xff;
1111 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1112 bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize));
1113 bi.dwAddress = cpu_to_be32(le32_to_cpu(p->page_header[0].PageAddress));
1115 /* send block info through the IDMA pipe */
1116 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1117 uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n");
1120 static inline void wake_up_cmv_ack(struct uea_softc *sc)
1122 BUG_ON(sc->cmv_ack);
1123 sc->cmv_ack = 1;
1124 wake_up(&sc->sync_q);
1127 static inline int wait_cmv_ack(struct uea_softc *sc)
1129 int ret = uea_wait(sc, sc->cmv_ack , ACK_TIMEOUT);
1131 sc->cmv_ack = 0;
1133 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
1134 jiffies_to_msecs(ret));
1136 if (ret < 0)
1137 return ret;
1139 return (ret == 0) ? -ETIMEDOUT : 0;
1142 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1144 static int uea_request(struct uea_softc *sc,
1145 u16 value, u16 index, u16 size, const void *data)
1147 u8 *xfer_buff;
1148 int ret = -ENOMEM;
1150 xfer_buff = kmemdup(data, size, GFP_KERNEL);
1151 if (!xfer_buff) {
1152 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
1153 return ret;
1156 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
1157 UCDC_SEND_ENCAPSULATED_COMMAND,
1158 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1159 value, index, xfer_buff, size, CTRL_TIMEOUT);
1161 kfree(xfer_buff);
1162 if (ret < 0) {
1163 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
1164 return ret;
1167 if (ret != size) {
1168 uea_err(INS_TO_USBDEV(sc),
1169 "usb_control_msg send only %d bytes (instead of %d)\n",
1170 ret, size);
1171 return -EIO;
1174 return 0;
1177 static int uea_cmv_e1(struct uea_softc *sc,
1178 u8 function, u32 address, u16 offset, u32 data)
1180 struct cmv_e1 cmv;
1181 int ret;
1183 uea_enters(INS_TO_USBDEV(sc));
1184 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1185 "offset : 0x%04x, data : 0x%08x\n",
1186 E1_FUNCTION_TYPE(function),
1187 E1_FUNCTION_SUBTYPE(function),
1188 E1_GETSA1(address), E1_GETSA2(address),
1189 E1_GETSA3(address),
1190 E1_GETSA4(address), offset, data);
1192 /* we send a request, but we expect a reply */
1193 sc->cmv_dsc.e1.function = function | 0x2;
1194 sc->cmv_dsc.e1.idx++;
1195 sc->cmv_dsc.e1.address = address;
1196 sc->cmv_dsc.e1.offset = offset;
1198 cmv.wPreamble = cpu_to_le16(E1_PREAMBLE);
1199 cmv.bDirection = E1_HOSTTOMODEM;
1200 cmv.bFunction = function;
1201 cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx);
1202 put_unaligned_le32(address, &cmv.dwSymbolicAddress);
1203 cmv.wOffsetAddress = cpu_to_le16(offset);
1204 put_unaligned_le32(data >> 16 | data << 16, &cmv.dwData);
1206 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START,
1207 sizeof(cmv), &cmv);
1208 if (ret < 0)
1209 return ret;
1210 ret = wait_cmv_ack(sc);
1211 uea_leaves(INS_TO_USBDEV(sc));
1212 return ret;
1215 static int uea_cmv_e4(struct uea_softc *sc,
1216 u16 function, u16 group, u16 address, u16 offset, u32 data)
1218 struct cmv_e4 cmv;
1219 int ret;
1221 uea_enters(INS_TO_USBDEV(sc));
1222 memset(&cmv, 0, sizeof(cmv));
1224 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
1225 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1226 E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function),
1227 group, address, offset, data);
1229 /* we send a request, but we expect a reply */
1230 sc->cmv_dsc.e4.function = function | (0x1 << 4);
1231 sc->cmv_dsc.e4.offset = offset;
1232 sc->cmv_dsc.e4.address = address;
1233 sc->cmv_dsc.e4.group = group;
1235 cmv.wFunction = cpu_to_be16(function);
1236 cmv.wGroup = cpu_to_be16(group);
1237 cmv.wAddress = cpu_to_be16(address);
1238 cmv.wOffset = cpu_to_be16(offset);
1239 cmv.dwData[0] = cpu_to_be32(data);
1241 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START,
1242 sizeof(cmv), &cmv);
1243 if (ret < 0)
1244 return ret;
1245 ret = wait_cmv_ack(sc);
1246 uea_leaves(INS_TO_USBDEV(sc));
1247 return ret;
1250 static inline int uea_read_cmv_e1(struct uea_softc *sc,
1251 u32 address, u16 offset, u32 *data)
1253 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD),
1254 address, offset, 0);
1255 if (ret < 0)
1256 uea_err(INS_TO_USBDEV(sc),
1257 "reading cmv failed with error %d\n", ret);
1258 else
1259 *data = sc->data;
1261 return ret;
1264 static inline int uea_read_cmv_e4(struct uea_softc *sc,
1265 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1267 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1268 E4_REQUESTREAD, size),
1269 group, address, offset, 0);
1270 if (ret < 0)
1271 uea_err(INS_TO_USBDEV(sc),
1272 "reading cmv failed with error %d\n", ret);
1273 else {
1274 *data = sc->data;
1275 /* size is in 16-bit word quantities */
1276 if (size > 2)
1277 *(data + 1) = sc->data1;
1279 return ret;
1282 static inline int uea_write_cmv_e1(struct uea_softc *sc,
1283 u32 address, u16 offset, u32 data)
1285 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE),
1286 address, offset, data);
1287 if (ret < 0)
1288 uea_err(INS_TO_USBDEV(sc),
1289 "writing cmv failed with error %d\n", ret);
1291 return ret;
1294 static inline int uea_write_cmv_e4(struct uea_softc *sc,
1295 u8 size, u16 group, u16 address, u16 offset, u32 data)
1297 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1298 E4_REQUESTWRITE, size),
1299 group, address, offset, data);
1300 if (ret < 0)
1301 uea_err(INS_TO_USBDEV(sc),
1302 "writing cmv failed with error %d\n", ret);
1304 return ret;
1307 static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1309 int ret;
1310 u16 timeout;
1312 /* in bulk mode the modem have problem with high rate
1313 * changing internal timing could improve things, but the
1314 * value is mysterious.
1315 * ADI930 don't support it (-EPIPE error).
1318 if (UEA_CHIP_VERSION(sc) == ADI930 ||
1319 altsetting[sc->modem_index] > 0 ||
1320 sc->stats.phy.dsrate == dsrate)
1321 return;
1323 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1324 timeout = (dsrate <= 1024*1024) ? 0 : 1;
1325 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
1326 uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n",
1327 timeout, ret < 0 ? " failed" : "");
1332 * Monitor the modem and update the stat
1333 * return 0 if everything is ok
1334 * return < 0 if an error occurs (-EAGAIN reboot needed)
1336 static int uea_stat_e1(struct uea_softc *sc)
1338 u32 data;
1339 int ret;
1341 uea_enters(INS_TO_USBDEV(sc));
1342 data = sc->stats.phy.state;
1344 ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state);
1345 if (ret < 0)
1346 return ret;
1348 switch (GET_STATUS(sc->stats.phy.state)) {
1349 case 0: /* not yet synchronized */
1350 uea_dbg(INS_TO_USBDEV(sc),
1351 "modem not yet synchronized\n");
1352 return 0;
1354 case 1: /* initialization */
1355 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1356 return 0;
1358 case 2: /* operational */
1359 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
1360 break;
1362 case 3: /* fail ... */
1363 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1364 " (may be try other cmv/dsp)\n");
1365 return -EAGAIN;
1367 case 4 ... 6: /* test state */
1368 uea_warn(INS_TO_USBDEV(sc),
1369 "modem in test mode - not supported\n");
1370 return -EAGAIN;
1372 case 7: /* fast-retain ... */
1373 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
1374 return 0;
1375 default:
1376 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
1377 GET_STATUS(sc->stats.phy.state));
1378 return -EAGAIN;
1381 if (GET_STATUS(data) != 2) {
1382 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1383 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1385 /* release the dsp firmware as it is not needed until
1386 * the next failure
1388 release_firmware(sc->dsp_firm);
1389 sc->dsp_firm = NULL;
1392 /* always update it as atm layer could not be init when we switch to
1393 * operational state
1395 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND);
1397 /* wake up processes waiting for synchronization */
1398 wake_up(&sc->sync_q);
1400 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags);
1401 if (ret < 0)
1402 return ret;
1403 sc->stats.phy.mflags |= sc->stats.phy.flags;
1405 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1406 * we check the status again in order to detect the failure earlier
1408 if (sc->stats.phy.flags) {
1409 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1410 sc->stats.phy.flags);
1411 return 0;
1414 ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data);
1415 if (ret < 0)
1416 return ret;
1418 uea_set_bulk_timeout(sc, (data >> 16) * 32);
1419 sc->stats.phy.dsrate = (data >> 16) * 32;
1420 sc->stats.phy.usrate = (data & 0xffff) * 32;
1421 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1423 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data);
1424 if (ret < 0)
1425 return ret;
1426 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
1428 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data);
1429 if (ret < 0)
1430 return ret;
1431 sc->stats.phy.usattenuation = (data & 0xff) / 2;
1433 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin);
1434 if (ret < 0)
1435 return ret;
1437 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin);
1438 if (ret < 0)
1439 return ret;
1441 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow);
1442 if (ret < 0)
1443 return ret;
1445 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow);
1446 if (ret < 0)
1447 return ret;
1449 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc);
1450 if (ret < 0)
1451 return ret;
1453 /* only for atu-c */
1454 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc);
1455 if (ret < 0)
1456 return ret;
1458 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr);
1459 if (ret < 0)
1460 return ret;
1462 /* only for atu-c */
1463 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr);
1464 if (ret < 0)
1465 return ret;
1467 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 8, &sc->stats.phy.vidco);
1468 if (ret < 0)
1469 return ret;
1471 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 13, &sc->stats.phy.vidcpe);
1472 if (ret < 0)
1473 return ret;
1475 return 0;
1478 static int uea_stat_e4(struct uea_softc *sc)
1480 u32 data;
1481 u32 tmp_arr[2];
1482 int ret;
1484 uea_enters(INS_TO_USBDEV(sc));
1485 data = sc->stats.phy.state;
1487 /* XXX only need to be done before operationnal... */
1488 ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state);
1489 if (ret < 0)
1490 return ret;
1492 switch (sc->stats.phy.state) {
1493 case 0x0: /* not yet synchronized */
1494 case 0x1:
1495 case 0x3:
1496 case 0x4:
1497 uea_dbg(INS_TO_USBDEV(sc), "modem not yet "
1498 "synchronized\n");
1499 return 0;
1500 case 0x5: /* initialization */
1501 case 0x6:
1502 case 0x9:
1503 case 0xa:
1504 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1505 return 0;
1506 case 0x2: /* fail ... */
1507 uea_info(INS_TO_USBDEV(sc), "modem synchronization "
1508 "failed (may be try other cmv/dsp)\n");
1509 return -EAGAIN;
1510 case 0x7: /* operational */
1511 break;
1512 default:
1513 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n",
1514 sc->stats.phy.state);
1515 return 0;
1518 if (data != 7) {
1519 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1520 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1522 /* release the dsp firmware as it is not needed until
1523 * the next failure
1525 release_firmware(sc->dsp_firm);
1526 sc->dsp_firm = NULL;
1529 /* always update it as atm layer could not be init when we switch to
1530 * operational state
1532 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND);
1534 /* wake up processes waiting for synchronization */
1535 wake_up(&sc->sync_q);
1537 /* TODO improve this state machine :
1538 * we need some CMV info : what they do and their unit
1539 * we should find the equivalent of eagle3- CMV
1541 /* check flags */
1542 ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags);
1543 if (ret < 0)
1544 return ret;
1545 sc->stats.phy.mflags |= sc->stats.phy.flags;
1547 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1548 * we check the status again in order to detect the failure earlier
1550 if (sc->stats.phy.flags) {
1551 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1552 sc->stats.phy.flags);
1553 if (sc->stats.phy.flags & 1) /* delineation LOSS */
1554 return -EAGAIN;
1555 if (sc->stats.phy.flags & 0x4000) /* Reset Flag */
1556 return -EAGAIN;
1557 return 0;
1560 /* rate data may be in upper or lower half of 64 bit word, strange */
1561 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr);
1562 if (ret < 0)
1563 return ret;
1564 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1565 sc->stats.phy.usrate = data / 1000;
1567 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr);
1568 if (ret < 0)
1569 return ret;
1570 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1571 uea_set_bulk_timeout(sc, data / 1000);
1572 sc->stats.phy.dsrate = data / 1000;
1573 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1575 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data);
1576 if (ret < 0)
1577 return ret;
1578 sc->stats.phy.dsattenuation = data / 10;
1580 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data);
1581 if (ret < 0)
1582 return ret;
1583 sc->stats.phy.usattenuation = data / 10;
1585 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data);
1586 if (ret < 0)
1587 return ret;
1588 sc->stats.phy.dsmargin = data / 2;
1590 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data);
1591 if (ret < 0)
1592 return ret;
1593 sc->stats.phy.usmargin = data / 10;
1595 return 0;
1598 static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1600 char file_arr[] = "CMVxy.bin";
1601 char *file;
1603 kparam_block_sysfs_write(cmv_file);
1604 /* set proper name corresponding modem version and line type */
1605 if (cmv_file[sc->modem_index] == NULL) {
1606 if (UEA_CHIP_VERSION(sc) == ADI930)
1607 file_arr[3] = '9';
1608 else if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1609 file_arr[3] = '4';
1610 else
1611 file_arr[3] = 'e';
1613 file_arr[4] = IS_ISDN(sc) ? 'i' : 'p';
1614 file = file_arr;
1615 } else
1616 file = cmv_file[sc->modem_index];
1618 strcpy(cmv_name, FW_DIR);
1619 strlcat(cmv_name, file, UEA_FW_NAME_MAX);
1620 if (ver == 2)
1621 strlcat(cmv_name, ".v2", UEA_FW_NAME_MAX);
1622 kparam_unblock_sysfs_write(cmv_file);
1625 static int request_cmvs_old(struct uea_softc *sc,
1626 void **cmvs, const struct firmware **fw)
1628 int ret, size;
1629 u8 *data;
1630 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
1632 cmvs_file_name(sc, cmv_name, 1);
1633 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1634 if (ret < 0) {
1635 uea_err(INS_TO_USBDEV(sc),
1636 "requesting firmware %s failed with error %d\n",
1637 cmv_name, ret);
1638 return ret;
1641 data = (u8 *) (*fw)->data;
1642 size = (*fw)->size;
1643 if (size < 1)
1644 goto err_fw_corrupted;
1646 if (size != *data * sizeof(struct uea_cmvs_v1) + 1)
1647 goto err_fw_corrupted;
1649 *cmvs = (void *)(data + 1);
1650 return *data;
1652 err_fw_corrupted:
1653 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1654 release_firmware(*fw);
1655 return -EILSEQ;
1658 static int request_cmvs(struct uea_softc *sc,
1659 void **cmvs, const struct firmware **fw, int *ver)
1661 int ret, size;
1662 u32 crc;
1663 u8 *data;
1664 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
1666 cmvs_file_name(sc, cmv_name, 2);
1667 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1668 if (ret < 0) {
1669 /* if caller can handle old version, try to provide it */
1670 if (*ver == 1) {
1671 uea_warn(INS_TO_USBDEV(sc), "requesting "
1672 "firmware %s failed, "
1673 "try to get older cmvs\n", cmv_name);
1674 return request_cmvs_old(sc, cmvs, fw);
1676 uea_err(INS_TO_USBDEV(sc),
1677 "requesting firmware %s failed with error %d\n",
1678 cmv_name, ret);
1679 return ret;
1682 size = (*fw)->size;
1683 data = (u8 *) (*fw)->data;
1684 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1685 if (*ver == 1) {
1686 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted,"
1687 " try to get older cmvs\n", cmv_name);
1688 release_firmware(*fw);
1689 return request_cmvs_old(sc, cmvs, fw);
1691 goto err_fw_corrupted;
1694 *ver = 2;
1696 data += 4;
1697 size -= 4;
1698 if (size < 5)
1699 goto err_fw_corrupted;
1701 crc = get_unaligned_le32(data);
1702 data += 4;
1703 size -= 4;
1704 if (crc32_be(0, data, size) != crc)
1705 goto err_fw_corrupted;
1707 if (size != *data * sizeof(struct uea_cmvs_v2) + 1)
1708 goto err_fw_corrupted;
1710 *cmvs = (void *) (data + 1);
1711 return *data;
1713 err_fw_corrupted:
1714 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1715 release_firmware(*fw);
1716 return -EILSEQ;
1719 static int uea_send_cmvs_e1(struct uea_softc *sc)
1721 int i, ret, len;
1722 void *cmvs_ptr;
1723 const struct firmware *cmvs_fw;
1724 int ver = 1; /* we can handle v1 cmv firmware version; */
1726 /* Enter in R-IDLE (cmv) until instructed otherwise */
1727 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
1728 if (ret < 0)
1729 return ret;
1731 /* Dump firmware version */
1732 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid);
1733 if (ret < 0)
1734 return ret;
1735 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1736 sc->stats.phy.firmid);
1738 /* get options */
1739 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1740 if (ret < 0)
1741 return ret;
1743 /* send options */
1744 if (ver == 1) {
1745 struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr;
1747 uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, "
1748 "please update your firmware\n");
1750 for (i = 0; i < len; i++) {
1751 ret = uea_write_cmv_e1(sc,
1752 get_unaligned_le32(&cmvs_v1[i].address),
1753 get_unaligned_le16(&cmvs_v1[i].offset),
1754 get_unaligned_le32(&cmvs_v1[i].data));
1755 if (ret < 0)
1756 goto out;
1758 } else if (ver == 2) {
1759 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1761 for (i = 0; i < len; i++) {
1762 ret = uea_write_cmv_e1(sc,
1763 get_unaligned_le32(&cmvs_v2[i].address),
1764 (u16) get_unaligned_le32(&cmvs_v2[i].offset),
1765 get_unaligned_le32(&cmvs_v2[i].data));
1766 if (ret < 0)
1767 goto out;
1769 } else {
1770 /* This really should not happen */
1771 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1772 goto out;
1775 /* Enter in R-ACT-REQ */
1776 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1777 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1778 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1779 "synchronization...\n");
1780 out:
1781 release_firmware(cmvs_fw);
1782 return ret;
1785 static int uea_send_cmvs_e4(struct uea_softc *sc)
1787 int i, ret, len;
1788 void *cmvs_ptr;
1789 const struct firmware *cmvs_fw;
1790 int ver = 2; /* we can only handle v2 cmv firmware version; */
1792 /* Enter in R-IDLE (cmv) until instructed otherwise */
1793 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
1794 if (ret < 0)
1795 return ret;
1797 /* Dump firmware version */
1798 /* XXX don't read the 3th byte as it is always 6 */
1799 ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid);
1800 if (ret < 0)
1801 return ret;
1802 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1803 sc->stats.phy.firmid);
1806 /* get options */
1807 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1808 if (ret < 0)
1809 return ret;
1811 /* send options */
1812 if (ver == 2) {
1813 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1815 for (i = 0; i < len; i++) {
1816 ret = uea_write_cmv_e4(sc, 1,
1817 get_unaligned_le32(&cmvs_v2[i].group),
1818 get_unaligned_le32(&cmvs_v2[i].address),
1819 get_unaligned_le32(&cmvs_v2[i].offset),
1820 get_unaligned_le32(&cmvs_v2[i].data));
1821 if (ret < 0)
1822 goto out;
1824 } else {
1825 /* This really should not happen */
1826 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1827 goto out;
1830 /* Enter in R-ACT-REQ */
1831 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1832 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1833 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1834 "synchronization...\n");
1835 out:
1836 release_firmware(cmvs_fw);
1837 return ret;
1840 /* Start boot post firmware modem:
1841 * - send reset commands through usb control pipe
1842 * - start workqueue for DSP loading
1843 * - send CMV options to modem
1846 static int uea_start_reset(struct uea_softc *sc)
1848 u16 zero = 0; /* ;-) */
1849 int ret;
1851 uea_enters(INS_TO_USBDEV(sc));
1852 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1854 /* mask interrupt */
1855 sc->booting = 1;
1856 /* We need to set this here because, a ack timeout could have occurred,
1857 * but before we start the reboot, the ack occurs and set this to 1.
1858 * So we will failed to wait Ready CMV.
1860 sc->cmv_ack = 0;
1861 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST);
1863 /* reset statistics */
1864 memset(&sc->stats, 0, sizeof(struct uea_stats));
1866 /* tell the modem that we want to boot in IDMA mode */
1867 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1868 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1870 /* enter reset mode */
1871 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1873 /* original driver use 200ms, but windows driver use 100ms */
1874 ret = uea_wait(sc, 0, msecs_to_jiffies(100));
1875 if (ret < 0)
1876 return ret;
1878 /* leave reset mode */
1879 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1881 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
1882 /* clear tx and rx mailboxes */
1883 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1884 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1885 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1888 ret = uea_wait(sc, 0, msecs_to_jiffies(1000));
1889 if (ret < 0)
1890 return ret;
1892 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1893 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
1894 E4_MODEMREADY, 1);
1895 else
1896 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
1897 E1_MODEMREADY);
1899 /* demask interrupt */
1900 sc->booting = 0;
1902 /* start loading DSP */
1903 sc->pageno = 0;
1904 sc->ovl = 0;
1905 schedule_work(&sc->task);
1907 /* wait for modem ready CMV */
1908 ret = wait_cmv_ack(sc);
1909 if (ret < 0)
1910 return ret;
1912 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1914 ret = sc->send_cmvs(sc);
1915 if (ret < 0)
1916 return ret;
1918 sc->reset = 0;
1919 uea_leaves(INS_TO_USBDEV(sc));
1920 return ret;
1924 * In case of an error wait 1s before rebooting the modem
1925 * if the modem don't request reboot (-EAGAIN).
1926 * Monitor the modem every 1s.
1929 static int uea_kthread(void *data)
1931 struct uea_softc *sc = data;
1932 int ret = -EAGAIN;
1934 set_freezable();
1935 uea_enters(INS_TO_USBDEV(sc));
1936 while (!kthread_should_stop()) {
1937 if (ret < 0 || sc->reset)
1938 ret = uea_start_reset(sc);
1939 if (!ret)
1940 ret = sc->stat(sc);
1941 if (ret != -EAGAIN)
1942 uea_wait(sc, 0, msecs_to_jiffies(1000));
1943 try_to_freeze();
1945 uea_leaves(INS_TO_USBDEV(sc));
1946 return ret;
1949 /* Load second usb firmware for ADI930 chip */
1950 static int load_XILINX_firmware(struct uea_softc *sc)
1952 const struct firmware *fw_entry;
1953 int ret, size, u, ln;
1954 const u8 *pfw;
1955 u8 value;
1956 char *fw_name = FPGA930_FIRMWARE;
1958 uea_enters(INS_TO_USBDEV(sc));
1960 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1961 if (ret) {
1962 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1963 fw_name);
1964 goto err0;
1967 pfw = fw_entry->data;
1968 size = fw_entry->size;
1969 if (size != 0x577B) {
1970 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1971 fw_name);
1972 ret = -EILSEQ;
1973 goto err1;
1975 for (u = 0; u < size; u += ln) {
1976 ln = min(size - u, 64);
1977 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1978 if (ret < 0) {
1979 uea_err(INS_TO_USBDEV(sc),
1980 "elsa download data failed (%d)\n", ret);
1981 goto err1;
1985 /* finish to send the fpga */
1986 ret = uea_request(sc, 0xe, 1, 0, NULL);
1987 if (ret < 0) {
1988 uea_err(INS_TO_USBDEV(sc),
1989 "elsa download data failed (%d)\n", ret);
1990 goto err1;
1993 /* Tell the modem we finish : de-assert reset */
1994 value = 0;
1995 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1996 if (ret < 0)
1997 uea_err(sc->usb_dev, "elsa de-assert failed with error"
1998 " %d\n", ret);
2000 err1:
2001 release_firmware(fw_entry);
2002 err0:
2003 uea_leaves(INS_TO_USBDEV(sc));
2004 return ret;
2007 /* The modem send us an ack. First with check if it right */
2008 static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
2010 struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;
2011 struct cmv_e1 *cmv = &intr->u.e1.s2.cmv;
2013 uea_enters(INS_TO_USBDEV(sc));
2014 if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE)
2015 goto bad1;
2017 if (cmv->bDirection != E1_MODEMTOHOST)
2018 goto bad1;
2020 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
2021 * the first MEMACCESS cmv. Ignore it...
2023 if (cmv->bFunction != dsc->function) {
2024 if (UEA_CHIP_VERSION(sc) == ADI930
2025 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
2026 cmv->wIndex = cpu_to_le16(dsc->idx);
2027 put_unaligned_le32(dsc->address,
2028 &cmv->dwSymbolicAddress);
2029 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
2030 } else
2031 goto bad2;
2034 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
2035 E1_MODEMREADY)) {
2036 wake_up_cmv_ack(sc);
2037 uea_leaves(INS_TO_USBDEV(sc));
2038 return;
2041 /* in case of MEMACCESS */
2042 if (le16_to_cpu(cmv->wIndex) != dsc->idx ||
2043 get_unaligned_le32(&cmv->dwSymbolicAddress) != dsc->address ||
2044 le16_to_cpu(cmv->wOffsetAddress) != dsc->offset)
2045 goto bad2;
2047 sc->data = get_unaligned_le32(&cmv->dwData);
2048 sc->data = sc->data << 16 | sc->data >> 16;
2050 wake_up_cmv_ack(sc);
2051 uea_leaves(INS_TO_USBDEV(sc));
2052 return;
2054 bad2:
2055 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
2056 "Function : %d, Subfunction : %d\n",
2057 E1_FUNCTION_TYPE(cmv->bFunction),
2058 E1_FUNCTION_SUBTYPE(cmv->bFunction));
2059 uea_leaves(INS_TO_USBDEV(sc));
2060 return;
2062 bad1:
2063 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
2064 "wPreamble %d, bDirection %d\n",
2065 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
2066 uea_leaves(INS_TO_USBDEV(sc));
2069 /* The modem send us an ack. First with check if it right */
2070 static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
2072 struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;
2073 struct cmv_e4 *cmv = &intr->u.e4.s2.cmv;
2075 uea_enters(INS_TO_USBDEV(sc));
2076 uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n",
2077 be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction),
2078 be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
2079 be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1]));
2081 if (be16_to_cpu(cmv->wFunction) != dsc->function)
2082 goto bad2;
2084 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
2085 E4_MODEMREADY, 1)) {
2086 wake_up_cmv_ack(sc);
2087 uea_leaves(INS_TO_USBDEV(sc));
2088 return;
2091 /* in case of MEMACCESS */
2092 if (be16_to_cpu(cmv->wOffset) != dsc->offset ||
2093 be16_to_cpu(cmv->wGroup) != dsc->group ||
2094 be16_to_cpu(cmv->wAddress) != dsc->address)
2095 goto bad2;
2097 sc->data = be32_to_cpu(cmv->dwData[0]);
2098 sc->data1 = be32_to_cpu(cmv->dwData[1]);
2099 wake_up_cmv_ack(sc);
2100 uea_leaves(INS_TO_USBDEV(sc));
2101 return;
2103 bad2:
2104 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
2105 "Function : %d, Subfunction : %d\n",
2106 E4_FUNCTION_TYPE(cmv->wFunction),
2107 E4_FUNCTION_SUBTYPE(cmv->wFunction));
2108 uea_leaves(INS_TO_USBDEV(sc));
2109 return;
2112 static void uea_schedule_load_page_e1(struct uea_softc *sc,
2113 struct intr_pkt *intr)
2115 sc->pageno = intr->e1_bSwapPageNo;
2116 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
2117 schedule_work(&sc->task);
2120 static void uea_schedule_load_page_e4(struct uea_softc *sc,
2121 struct intr_pkt *intr)
2123 sc->pageno = intr->e4_bSwapPageNo;
2124 schedule_work(&sc->task);
2128 * interrupt handler
2130 static void uea_intr(struct urb *urb)
2132 struct uea_softc *sc = urb->context;
2133 struct intr_pkt *intr = urb->transfer_buffer;
2134 int status = urb->status;
2136 uea_enters(INS_TO_USBDEV(sc));
2138 if (unlikely(status < 0)) {
2139 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
2140 status);
2141 return;
2144 /* device-to-host interrupt */
2145 if (intr->bType != 0x08 || sc->booting) {
2146 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
2147 goto resubmit;
2150 switch (le16_to_cpu(intr->wInterrupt)) {
2151 case INT_LOADSWAPPAGE:
2152 sc->schedule_load_page(sc, intr);
2153 break;
2155 case INT_INCOMINGCMV:
2156 sc->dispatch_cmv(sc, intr);
2157 break;
2159 default:
2160 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
2161 le16_to_cpu(intr->wInterrupt));
2164 resubmit:
2165 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
2169 * Start the modem : init the data and start kernel thread
2171 static int uea_boot(struct uea_softc *sc)
2173 int ret, size;
2174 struct intr_pkt *intr;
2176 uea_enters(INS_TO_USBDEV(sc));
2178 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2179 size = E4_INTR_PKT_SIZE;
2180 sc->dispatch_cmv = uea_dispatch_cmv_e4;
2181 sc->schedule_load_page = uea_schedule_load_page_e4;
2182 sc->stat = uea_stat_e4;
2183 sc->send_cmvs = uea_send_cmvs_e4;
2184 INIT_WORK(&sc->task, uea_load_page_e4);
2185 } else {
2186 size = E1_INTR_PKT_SIZE;
2187 sc->dispatch_cmv = uea_dispatch_cmv_e1;
2188 sc->schedule_load_page = uea_schedule_load_page_e1;
2189 sc->stat = uea_stat_e1;
2190 sc->send_cmvs = uea_send_cmvs_e1;
2191 INIT_WORK(&sc->task, uea_load_page_e1);
2194 init_waitqueue_head(&sc->sync_q);
2196 if (UEA_CHIP_VERSION(sc) == ADI930)
2197 load_XILINX_firmware(sc);
2199 intr = kmalloc(size, GFP_KERNEL);
2200 if (!intr) {
2201 uea_err(INS_TO_USBDEV(sc),
2202 "cannot allocate interrupt package\n");
2203 goto err0;
2206 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
2207 if (!sc->urb_int) {
2208 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
2209 goto err1;
2212 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
2213 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
2214 intr, size, uea_intr, sc,
2215 sc->usb_dev->actconfig->interface[0]->altsetting[0].
2216 endpoint[0].desc.bInterval);
2218 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2219 if (ret < 0) {
2220 uea_err(INS_TO_USBDEV(sc),
2221 "urb submition failed with error %d\n", ret);
2222 goto err1;
2225 /* Create worker thread, but don't start it here. Start it after
2226 * all usbatm generic initialization is done.
2228 sc->kthread = kthread_create(uea_kthread, sc, "ueagle-atm");
2229 if (IS_ERR(sc->kthread)) {
2230 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2231 goto err2;
2234 uea_leaves(INS_TO_USBDEV(sc));
2235 return 0;
2237 err2:
2238 usb_kill_urb(sc->urb_int);
2239 err1:
2240 usb_free_urb(sc->urb_int);
2241 sc->urb_int = NULL;
2242 kfree(intr);
2243 err0:
2244 uea_leaves(INS_TO_USBDEV(sc));
2245 return -ENOMEM;
2249 * Stop the modem : kill kernel thread and free data
2251 static void uea_stop(struct uea_softc *sc)
2253 int ret;
2254 uea_enters(INS_TO_USBDEV(sc));
2255 ret = kthread_stop(sc->kthread);
2256 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
2258 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
2260 usb_kill_urb(sc->urb_int);
2261 kfree(sc->urb_int->transfer_buffer);
2262 usb_free_urb(sc->urb_int);
2264 /* flush the work item, when no one can schedule it */
2265 flush_work(&sc->task);
2267 release_firmware(sc->dsp_firm);
2268 uea_leaves(INS_TO_USBDEV(sc));
2271 /* syfs interface */
2272 static struct uea_softc *dev_to_uea(struct device *dev)
2274 struct usb_interface *intf;
2275 struct usbatm_data *usbatm;
2277 intf = to_usb_interface(dev);
2278 if (!intf)
2279 return NULL;
2281 usbatm = usb_get_intfdata(intf);
2282 if (!usbatm)
2283 return NULL;
2285 return usbatm->driver_data;
2288 static ssize_t read_status(struct device *dev, struct device_attribute *attr,
2289 char *buf)
2291 int ret = -ENODEV;
2292 struct uea_softc *sc;
2294 mutex_lock(&uea_mutex);
2295 sc = dev_to_uea(dev);
2296 if (!sc)
2297 goto out;
2298 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
2299 out:
2300 mutex_unlock(&uea_mutex);
2301 return ret;
2304 static ssize_t reboot(struct device *dev, struct device_attribute *attr,
2305 const char *buf, size_t count)
2307 int ret = -ENODEV;
2308 struct uea_softc *sc;
2310 mutex_lock(&uea_mutex);
2311 sc = dev_to_uea(dev);
2312 if (!sc)
2313 goto out;
2314 sc->reset = 1;
2315 ret = count;
2316 out:
2317 mutex_unlock(&uea_mutex);
2318 return ret;
2321 static DEVICE_ATTR(stat_status, S_IWUSR | S_IRUGO, read_status, reboot);
2323 static ssize_t read_human_status(struct device *dev,
2324 struct device_attribute *attr, char *buf)
2326 int ret = -ENODEV;
2327 int modem_state;
2328 struct uea_softc *sc;
2330 mutex_lock(&uea_mutex);
2331 sc = dev_to_uea(dev);
2332 if (!sc)
2333 goto out;
2335 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2336 switch (sc->stats.phy.state) {
2337 case 0x0: /* not yet synchronized */
2338 case 0x1:
2339 case 0x3:
2340 case 0x4:
2341 modem_state = 0;
2342 break;
2343 case 0x5: /* initialization */
2344 case 0x6:
2345 case 0x9:
2346 case 0xa:
2347 modem_state = 1;
2348 break;
2349 case 0x7: /* operational */
2350 modem_state = 2;
2351 break;
2352 case 0x2: /* fail ... */
2353 modem_state = 3;
2354 break;
2355 default: /* unknown */
2356 modem_state = 4;
2357 break;
2359 } else
2360 modem_state = GET_STATUS(sc->stats.phy.state);
2362 switch (modem_state) {
2363 case 0:
2364 ret = sprintf(buf, "Modem is booting\n");
2365 break;
2366 case 1:
2367 ret = sprintf(buf, "Modem is initializing\n");
2368 break;
2369 case 2:
2370 ret = sprintf(buf, "Modem is operational\n");
2371 break;
2372 case 3:
2373 ret = sprintf(buf, "Modem synchronization failed\n");
2374 break;
2375 default:
2376 ret = sprintf(buf, "Modem state is unknown\n");
2377 break;
2379 out:
2380 mutex_unlock(&uea_mutex);
2381 return ret;
2384 static DEVICE_ATTR(stat_human_status, S_IRUGO, read_human_status, NULL);
2386 static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2387 char *buf)
2389 int ret = -ENODEV;
2390 struct uea_softc *sc;
2391 char *delin = "GOOD";
2393 mutex_lock(&uea_mutex);
2394 sc = dev_to_uea(dev);
2395 if (!sc)
2396 goto out;
2398 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2399 if (sc->stats.phy.flags & 0x4000)
2400 delin = "RESET";
2401 else if (sc->stats.phy.flags & 0x0001)
2402 delin = "LOSS";
2403 } else {
2404 if (sc->stats.phy.flags & 0x0C00)
2405 delin = "ERROR";
2406 else if (sc->stats.phy.flags & 0x0030)
2407 delin = "LOSS";
2410 ret = sprintf(buf, "%s\n", delin);
2411 out:
2412 mutex_unlock(&uea_mutex);
2413 return ret;
2416 static DEVICE_ATTR(stat_delin, S_IRUGO, read_delin, NULL);
2418 #define UEA_ATTR(name, reset) \
2420 static ssize_t read_##name(struct device *dev, \
2421 struct device_attribute *attr, char *buf) \
2423 int ret = -ENODEV; \
2424 struct uea_softc *sc; \
2426 mutex_lock(&uea_mutex); \
2427 sc = dev_to_uea(dev); \
2428 if (!sc) \
2429 goto out; \
2430 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2431 if (reset) \
2432 sc->stats.phy.name = 0; \
2433 out: \
2434 mutex_unlock(&uea_mutex); \
2435 return ret; \
2438 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2440 UEA_ATTR(mflags, 1);
2441 UEA_ATTR(vidcpe, 0);
2442 UEA_ATTR(usrate, 0);
2443 UEA_ATTR(dsrate, 0);
2444 UEA_ATTR(usattenuation, 0);
2445 UEA_ATTR(dsattenuation, 0);
2446 UEA_ATTR(usmargin, 0);
2447 UEA_ATTR(dsmargin, 0);
2448 UEA_ATTR(txflow, 0);
2449 UEA_ATTR(rxflow, 0);
2450 UEA_ATTR(uscorr, 0);
2451 UEA_ATTR(dscorr, 0);
2452 UEA_ATTR(usunc, 0);
2453 UEA_ATTR(dsunc, 0);
2454 UEA_ATTR(firmid, 0);
2456 /* Retrieve the device End System Identifier (MAC) */
2458 static int uea_getesi(struct uea_softc *sc, u_char * esi)
2460 unsigned char mac_str[2 * ETH_ALEN + 1];
2461 int i;
2462 if (usb_string
2463 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
2464 sizeof(mac_str)) != 2 * ETH_ALEN)
2465 return 1;
2467 for (i = 0; i < ETH_ALEN; i++)
2468 esi[i] = hex_to_bin(mac_str[2 * i]) * 16 +
2469 hex_to_bin(mac_str[2 * i + 1]);
2471 return 0;
2474 /* ATM stuff */
2475 static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
2477 struct uea_softc *sc = usbatm->driver_data;
2479 return uea_getesi(sc, atm_dev->esi);
2482 static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
2484 struct uea_softc *sc = usbatm->driver_data;
2486 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
2488 return 0;
2492 static int claim_interface(struct usb_device *usb_dev,
2493 struct usbatm_data *usbatm, int ifnum)
2495 int ret;
2496 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
2498 if (!intf) {
2499 uea_err(usb_dev, "interface %d not found\n", ifnum);
2500 return -ENODEV;
2503 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
2504 if (ret != 0)
2505 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
2506 ret);
2507 return ret;
2510 static struct attribute *attrs[] = {
2511 &dev_attr_stat_status.attr,
2512 &dev_attr_stat_mflags.attr,
2513 &dev_attr_stat_human_status.attr,
2514 &dev_attr_stat_delin.attr,
2515 &dev_attr_stat_vidcpe.attr,
2516 &dev_attr_stat_usrate.attr,
2517 &dev_attr_stat_dsrate.attr,
2518 &dev_attr_stat_usattenuation.attr,
2519 &dev_attr_stat_dsattenuation.attr,
2520 &dev_attr_stat_usmargin.attr,
2521 &dev_attr_stat_dsmargin.attr,
2522 &dev_attr_stat_txflow.attr,
2523 &dev_attr_stat_rxflow.attr,
2524 &dev_attr_stat_uscorr.attr,
2525 &dev_attr_stat_dscorr.attr,
2526 &dev_attr_stat_usunc.attr,
2527 &dev_attr_stat_dsunc.attr,
2528 &dev_attr_stat_firmid.attr,
2529 NULL,
2531 static struct attribute_group attr_grp = {
2532 .attrs = attrs,
2535 static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
2536 const struct usb_device_id *id)
2538 struct usb_device *usb = interface_to_usbdev(intf);
2539 struct uea_softc *sc;
2540 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
2541 unsigned int alt;
2543 uea_enters(usb);
2545 /* interface 0 is for firmware/monitoring */
2546 if (ifnum != UEA_INTR_IFACE_NO)
2547 return -ENODEV;
2549 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
2551 /* interface 1 is for outbound traffic */
2552 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
2553 if (ret < 0)
2554 return ret;
2556 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
2557 if (UEA_CHIP_VERSION(id) != ADI930) {
2558 /* interface 2 is for inbound traffic */
2559 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
2560 if (ret < 0)
2561 return ret;
2564 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
2565 if (!sc) {
2566 uea_err(usb, "uea_init: not enough memory !\n");
2567 return -ENOMEM;
2570 sc->usb_dev = usb;
2571 usbatm->driver_data = sc;
2572 sc->usbatm = usbatm;
2573 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
2574 sc->driver_info = id->driver_info;
2576 /* first try to use module parameter */
2577 if (annex[sc->modem_index] == 1)
2578 sc->annex = ANNEXA;
2579 else if (annex[sc->modem_index] == 2)
2580 sc->annex = ANNEXB;
2581 /* try to autodetect annex */
2582 else if (sc->driver_info & AUTO_ANNEX_A)
2583 sc->annex = ANNEXA;
2584 else if (sc->driver_info & AUTO_ANNEX_B)
2585 sc->annex = ANNEXB;
2586 else
2587 sc->annex = (le16_to_cpu
2588 (sc->usb_dev->descriptor.bcdDevice) & 0x80) ? ANNEXB : ANNEXA;
2590 alt = altsetting[sc->modem_index];
2591 /* ADI930 don't support iso */
2592 if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) {
2593 if (alt <= 8 &&
2594 usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) {
2595 uea_dbg(usb, "set alternate %u for 2 interface\n", alt);
2596 uea_info(usb, "using iso mode\n");
2597 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
2598 } else {
2599 uea_err(usb, "setting alternate %u failed for "
2600 "2 interface, using bulk mode\n", alt);
2604 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
2605 if (ret < 0)
2606 goto error;
2608 ret = uea_boot(sc);
2609 if (ret < 0)
2610 goto error_rm_grp;
2612 return 0;
2614 error_rm_grp:
2615 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2616 error:
2617 kfree(sc);
2618 return ret;
2621 static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
2623 struct uea_softc *sc = usbatm->driver_data;
2625 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2626 uea_stop(sc);
2627 kfree(sc);
2630 static struct usbatm_driver uea_usbatm_driver = {
2631 .driver_name = "ueagle-atm",
2632 .bind = uea_bind,
2633 .atm_start = uea_atm_open,
2634 .unbind = uea_unbind,
2635 .heavy_init = uea_heavy,
2636 .bulk_in = UEA_BULK_DATA_PIPE,
2637 .bulk_out = UEA_BULK_DATA_PIPE,
2638 .isoc_in = UEA_ISO_DATA_PIPE,
2641 static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2643 struct usb_device *usb = interface_to_usbdev(intf);
2644 int ret;
2646 uea_enters(usb);
2647 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2648 le16_to_cpu(usb->descriptor.idVendor),
2649 le16_to_cpu(usb->descriptor.idProduct),
2650 le16_to_cpu(usb->descriptor.bcdDevice),
2651 chip_name[UEA_CHIP_VERSION(id)]);
2653 usb_reset_device(usb);
2655 if (UEA_IS_PREFIRM(id))
2656 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2658 ret = usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2659 if (ret == 0) {
2660 struct usbatm_data *usbatm = usb_get_intfdata(intf);
2661 struct uea_softc *sc = usbatm->driver_data;
2663 /* Ensure carrier is initialized to off as early as possible */
2664 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST);
2666 /* Only start the worker thread when all init is done */
2667 wake_up_process(sc->kthread);
2670 return ret;
2673 static void uea_disconnect(struct usb_interface *intf)
2675 struct usb_device *usb = interface_to_usbdev(intf);
2676 int ifnum = intf->altsetting->desc.bInterfaceNumber;
2677 uea_enters(usb);
2679 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2680 * Pre-firmware device has one interface
2682 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
2683 mutex_lock(&uea_mutex);
2684 usbatm_usb_disconnect(intf);
2685 mutex_unlock(&uea_mutex);
2686 uea_info(usb, "ADSL device removed\n");
2689 uea_leaves(usb);
2693 * List of supported VID/PID
2695 static const struct usb_device_id uea_ids[] = {
2696 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM),
2697 .driver_info = ADI930 | PREFIRM},
2698 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM),
2699 .driver_info = ADI930 | PSTFIRM},
2700 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM),
2701 .driver_info = EAGLE_I | PREFIRM},
2702 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM),
2703 .driver_info = EAGLE_I | PSTFIRM},
2704 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM),
2705 .driver_info = EAGLE_II | PREFIRM},
2706 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM),
2707 .driver_info = EAGLE_II | PSTFIRM},
2708 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM),
2709 .driver_info = EAGLE_II | PREFIRM},
2710 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM),
2711 .driver_info = EAGLE_II | PSTFIRM},
2712 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM),
2713 .driver_info = EAGLE_III | PREFIRM},
2714 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM),
2715 .driver_info = EAGLE_III | PSTFIRM},
2716 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM),
2717 .driver_info = EAGLE_IV | PREFIRM},
2718 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM),
2719 .driver_info = EAGLE_IV | PSTFIRM},
2720 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM),
2721 .driver_info = EAGLE_I | PREFIRM},
2722 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM),
2723 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2724 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM),
2725 .driver_info = EAGLE_I | PREFIRM},
2726 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM),
2727 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2728 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM),
2729 .driver_info = EAGLE_II | PREFIRM},
2730 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM),
2731 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A},
2732 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM),
2733 .driver_info = EAGLE_II | PREFIRM},
2734 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM),
2735 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B},
2736 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM),
2737 .driver_info = ADI930 | PREFIRM},
2738 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM),
2739 .driver_info = ADI930 | PSTFIRM},
2740 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM),
2741 .driver_info = ADI930 | PREFIRM},
2742 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM),
2743 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A},
2744 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM),
2745 .driver_info = ADI930 | PREFIRM},
2746 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM),
2747 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B},
2748 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM),
2749 .driver_info = EAGLE_I | PREFIRM},
2750 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM),
2751 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2752 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM),
2753 .driver_info = EAGLE_I | PREFIRM},
2754 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM),
2755 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2756 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),
2757 .driver_info = EAGLE_I | PREFIRM},
2758 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),
2759 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2760 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),
2761 .driver_info = EAGLE_I | PREFIRM},
2762 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),
2763 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2768 * USB driver descriptor
2770 static struct usb_driver uea_driver = {
2771 .name = "ueagle-atm",
2772 .id_table = uea_ids,
2773 .probe = uea_probe,
2774 .disconnect = uea_disconnect,
2777 MODULE_DEVICE_TABLE(usb, uea_ids);
2779 module_usb_driver(uea_driver);
2781 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2782 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2783 MODULE_LICENSE("Dual BSD/GPL");
2784 MODULE_FIRMWARE(EAGLE_FIRMWARE);
2785 MODULE_FIRMWARE(ADI930_FIRMWARE);
2786 MODULE_FIRMWARE(EAGLE_I_FIRMWARE);
2787 MODULE_FIRMWARE(EAGLE_II_FIRMWARE);
2788 MODULE_FIRMWARE(EAGLE_III_FIRMWARE);
2789 MODULE_FIRMWARE(EAGLE_IV_FIRMWARE);
2790 MODULE_FIRMWARE(DSP4I_FIRMWARE);
2791 MODULE_FIRMWARE(DSP4P_FIRMWARE);
2792 MODULE_FIRMWARE(DSP9I_FIRMWARE);
2793 MODULE_FIRMWARE(DSP9P_FIRMWARE);
2794 MODULE_FIRMWARE(DSPEI_FIRMWARE);
2795 MODULE_FIRMWARE(DSPEP_FIRMWARE);
2796 MODULE_FIRMWARE(FPGA930_FIRMWARE);
2797 MODULE_FIRMWARE(CMV4P_FIRMWARE);
2798 MODULE_FIRMWARE(CMV4PV2_FIRMWARE);
2799 MODULE_FIRMWARE(CMV4I_FIRMWARE);
2800 MODULE_FIRMWARE(CMV4IV2_FIRMWARE);
2801 MODULE_FIRMWARE(CMV9P_FIRMWARE);
2802 MODULE_FIRMWARE(CMV9PV2_FIRMWARE);
2803 MODULE_FIRMWARE(CMV9I_FIRMWARE);
2804 MODULE_FIRMWARE(CMV9IV2_FIRMWARE);
2805 MODULE_FIRMWARE(CMVEP_FIRMWARE);
2806 MODULE_FIRMWARE(CMVEPV2_FIRMWARE);
2807 MODULE_FIRMWARE(CMVEI_FIRMWARE);
2808 MODULE_FIRMWARE(CMVEIV2_FIRMWARE);