Linux 4.2.1
[linux/fpc-iii.git] / drivers / usb / atm / ueagle-atm.c
bloba2ae88dbda784f257923a730caf20c2986b22798
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/crc32.h>
61 #include <linux/usb.h>
62 #include <linux/firmware.h>
63 #include <linux/ctype.h>
64 #include <linux/sched.h>
65 #include <linux/kthread.h>
66 #include <linux/mutex.h>
67 #include <linux/freezer.h>
68 #include <linux/slab.h>
69 #include <linux/kernel.h>
71 #include <asm/unaligned.h>
73 #include "usbatm.h"
75 #define EAGLEUSBVERSION "ueagle 1.4"
79 * Debug macros
81 #define uea_dbg(usb_dev, format, args...) \
82 do { \
83 if (debug >= 1) \
84 dev_dbg(&(usb_dev)->dev, \
85 "[ueagle-atm dbg] %s: " format, \
86 __func__, ##args); \
87 } while (0)
89 #define uea_vdbg(usb_dev, format, args...) \
90 do { \
91 if (debug >= 2) \
92 dev_dbg(&(usb_dev)->dev, \
93 "[ueagle-atm vdbg] " format, ##args); \
94 } while (0)
96 #define uea_enters(usb_dev) \
97 uea_vdbg(usb_dev, "entering %s\n" , __func__)
99 #define uea_leaves(usb_dev) \
100 uea_vdbg(usb_dev, "leaving %s\n" , __func__)
102 #define uea_err(usb_dev, format, args...) \
103 dev_err(&(usb_dev)->dev , "[UEAGLE-ATM] " format , ##args)
105 #define uea_warn(usb_dev, format, args...) \
106 dev_warn(&(usb_dev)->dev , "[Ueagle-atm] " format, ##args)
108 #define uea_info(usb_dev, format, args...) \
109 dev_info(&(usb_dev)->dev , "[ueagle-atm] " format, ##args)
111 struct intr_pkt;
113 /* cmv's from firmware */
114 struct uea_cmvs_v1 {
115 u32 address;
116 u16 offset;
117 u32 data;
118 } __packed;
120 struct uea_cmvs_v2 {
121 u32 group;
122 u32 address;
123 u32 offset;
124 u32 data;
125 } __packed;
127 /* information about currently processed cmv */
128 struct cmv_dsc_e1 {
129 u8 function;
130 u16 idx;
131 u32 address;
132 u16 offset;
135 struct cmv_dsc_e4 {
136 u16 function;
137 u16 offset;
138 u16 address;
139 u16 group;
142 union cmv_dsc {
143 struct cmv_dsc_e1 e1;
144 struct cmv_dsc_e4 e4;
147 struct uea_softc {
148 struct usb_device *usb_dev;
149 struct usbatm_data *usbatm;
151 int modem_index;
152 unsigned int driver_info;
153 int annex;
154 #define ANNEXA 0
155 #define ANNEXB 1
157 int booting;
158 int reset;
160 wait_queue_head_t sync_q;
162 struct task_struct *kthread;
163 u32 data;
164 u32 data1;
166 int cmv_ack;
167 union cmv_dsc cmv_dsc;
169 struct work_struct task;
170 u16 pageno;
171 u16 ovl;
173 const struct firmware *dsp_firm;
174 struct urb *urb_int;
176 void (*dispatch_cmv) (struct uea_softc *, struct intr_pkt *);
177 void (*schedule_load_page) (struct uea_softc *, struct intr_pkt *);
178 int (*stat) (struct uea_softc *);
179 int (*send_cmvs) (struct uea_softc *);
181 /* keep in sync with eaglectl */
182 struct uea_stats {
183 struct {
184 u32 state;
185 u32 flags;
186 u32 mflags;
187 u32 vidcpe;
188 u32 vidco;
189 u32 dsrate;
190 u32 usrate;
191 u32 dsunc;
192 u32 usunc;
193 u32 dscorr;
194 u32 uscorr;
195 u32 txflow;
196 u32 rxflow;
197 u32 usattenuation;
198 u32 dsattenuation;
199 u32 dsmargin;
200 u32 usmargin;
201 u32 firmid;
202 } phy;
203 } stats;
207 * Elsa IDs
209 #define ELSA_VID 0x05CC
210 #define ELSA_PID_PSTFIRM 0x3350
211 #define ELSA_PID_PREFIRM 0x3351
213 #define ELSA_PID_A_PREFIRM 0x3352
214 #define ELSA_PID_A_PSTFIRM 0x3353
215 #define ELSA_PID_B_PREFIRM 0x3362
216 #define ELSA_PID_B_PSTFIRM 0x3363
219 * Devolo IDs : pots if (pid & 0x10)
221 #define DEVOLO_VID 0x1039
222 #define DEVOLO_EAGLE_I_A_PID_PSTFIRM 0x2110
223 #define DEVOLO_EAGLE_I_A_PID_PREFIRM 0x2111
225 #define DEVOLO_EAGLE_I_B_PID_PSTFIRM 0x2100
226 #define DEVOLO_EAGLE_I_B_PID_PREFIRM 0x2101
228 #define DEVOLO_EAGLE_II_A_PID_PSTFIRM 0x2130
229 #define DEVOLO_EAGLE_II_A_PID_PREFIRM 0x2131
231 #define DEVOLO_EAGLE_II_B_PID_PSTFIRM 0x2120
232 #define DEVOLO_EAGLE_II_B_PID_PREFIRM 0x2121
235 * Reference design USB IDs
237 #define ANALOG_VID 0x1110
238 #define ADI930_PID_PREFIRM 0x9001
239 #define ADI930_PID_PSTFIRM 0x9000
241 #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
242 #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
244 #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
245 #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
247 #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
248 #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
250 #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
251 #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
253 #define EAGLE_IV_PID_PREFIRM 0x9042 /* Eagle IV */
254 #define EAGLE_IV_PID_PSTFIRM 0x9041 /* Eagle IV */
257 * USR USB IDs
259 #define USR_VID 0x0BAF
260 #define MILLER_A_PID_PREFIRM 0x00F2
261 #define MILLER_A_PID_PSTFIRM 0x00F1
262 #define MILLER_B_PID_PREFIRM 0x00FA
263 #define MILLER_B_PID_PSTFIRM 0x00F9
264 #define HEINEKEN_A_PID_PREFIRM 0x00F6
265 #define HEINEKEN_A_PID_PSTFIRM 0x00F5
266 #define HEINEKEN_B_PID_PREFIRM 0x00F8
267 #define HEINEKEN_B_PID_PSTFIRM 0x00F7
269 #define PREFIRM 0
270 #define PSTFIRM (1<<7)
271 #define AUTO_ANNEX_A (1<<8)
272 #define AUTO_ANNEX_B (1<<9)
274 enum {
275 ADI930 = 0,
276 EAGLE_I,
277 EAGLE_II,
278 EAGLE_III,
279 EAGLE_IV
282 /* macros for both struct usb_device_id and struct uea_softc */
283 #define UEA_IS_PREFIRM(x) \
284 (!((x)->driver_info & PSTFIRM))
285 #define UEA_CHIP_VERSION(x) \
286 ((x)->driver_info & 0xf)
288 #define IS_ISDN(x) \
289 ((x)->annex & ANNEXB)
291 #define INS_TO_USBDEV(ins) (ins->usb_dev)
293 #define GET_STATUS(data) \
294 ((data >> 8) & 0xf)
296 #define IS_OPERATIONAL(sc) \
297 ((UEA_CHIP_VERSION(sc) != EAGLE_IV) ? \
298 (GET_STATUS(sc->stats.phy.state) == 2) : \
299 (sc->stats.phy.state == 7))
302 * Set of macros to handle unaligned data in the firmware blob.
303 * The FW_GET_BYTE() macro is provided only for consistency.
306 #define FW_GET_BYTE(p) (*((__u8 *) (p)))
308 #define FW_DIR "ueagle-atm/"
309 #define EAGLE_FIRMWARE FW_DIR "eagle.fw"
310 #define ADI930_FIRMWARE FW_DIR "adi930.fw"
311 #define EAGLE_I_FIRMWARE FW_DIR "eagleI.fw"
312 #define EAGLE_II_FIRMWARE FW_DIR "eagleII.fw"
313 #define EAGLE_III_FIRMWARE FW_DIR "eagleIII.fw"
314 #define EAGLE_IV_FIRMWARE FW_DIR "eagleIV.fw"
316 #define DSP4I_FIRMWARE FW_DIR "DSP4i.bin"
317 #define DSP4P_FIRMWARE FW_DIR "DSP4p.bin"
318 #define DSP9I_FIRMWARE FW_DIR "DSP9i.bin"
319 #define DSP9P_FIRMWARE FW_DIR "DSP9p.bin"
320 #define DSPEI_FIRMWARE FW_DIR "DSPei.bin"
321 #define DSPEP_FIRMWARE FW_DIR "DSPep.bin"
322 #define FPGA930_FIRMWARE FW_DIR "930-fpga.bin"
324 #define CMV4P_FIRMWARE FW_DIR "CMV4p.bin"
325 #define CMV4PV2_FIRMWARE FW_DIR "CMV4p.bin.v2"
326 #define CMV4I_FIRMWARE FW_DIR "CMV4i.bin"
327 #define CMV4IV2_FIRMWARE FW_DIR "CMV4i.bin.v2"
328 #define CMV9P_FIRMWARE FW_DIR "CMV9p.bin"
329 #define CMV9PV2_FIRMWARE FW_DIR "CMV9p.bin.v2"
330 #define CMV9I_FIRMWARE FW_DIR "CMV9i.bin"
331 #define CMV9IV2_FIRMWARE FW_DIR "CMV9i.bin.v2"
332 #define CMVEP_FIRMWARE FW_DIR "CMVep.bin"
333 #define CMVEPV2_FIRMWARE FW_DIR "CMVep.bin.v2"
334 #define CMVEI_FIRMWARE FW_DIR "CMVei.bin"
335 #define CMVEIV2_FIRMWARE FW_DIR "CMVei.bin.v2"
337 #define UEA_FW_NAME_MAX 30
338 #define NB_MODEM 4
340 #define BULK_TIMEOUT 300
341 #define CTRL_TIMEOUT 1000
343 #define ACK_TIMEOUT msecs_to_jiffies(3000)
345 #define UEA_INTR_IFACE_NO 0
346 #define UEA_US_IFACE_NO 1
347 #define UEA_DS_IFACE_NO 2
349 #define FASTEST_ISO_INTF 8
351 #define UEA_BULK_DATA_PIPE 0x02
352 #define UEA_IDMA_PIPE 0x04
353 #define UEA_INTR_PIPE 0x04
354 #define UEA_ISO_DATA_PIPE 0x08
356 #define UEA_E1_SET_BLOCK 0x0001
357 #define UEA_E4_SET_BLOCK 0x002c
358 #define UEA_SET_MODE 0x0003
359 #define UEA_SET_2183_DATA 0x0004
360 #define UEA_SET_TIMEOUT 0x0011
362 #define UEA_LOOPBACK_OFF 0x0002
363 #define UEA_LOOPBACK_ON 0x0003
364 #define UEA_BOOT_IDMA 0x0006
365 #define UEA_START_RESET 0x0007
366 #define UEA_END_RESET 0x0008
368 #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
369 #define UEA_MPTX_START (0x3fce | 0x4000)
370 #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
371 #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
373 /* block information in eagle4 dsp firmware */
374 struct block_index {
375 __le32 PageOffset;
376 __le32 NotLastBlock;
377 __le32 dummy;
378 __le32 PageSize;
379 __le32 PageAddress;
380 __le16 dummy1;
381 __le16 PageNumber;
382 } __packed;
384 #define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
385 #define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
387 #define E4_L1_STRING_HEADER 0x10
388 #define E4_MAX_PAGE_NUMBER 0x58
389 #define E4_NO_SWAPPAGE_HEADERS 0x31
391 /* l1_code is eagle4 dsp firmware format */
392 struct l1_code {
393 u8 string_header[E4_L1_STRING_HEADER];
394 u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER];
395 struct block_index page_header[E4_NO_SWAPPAGE_HEADERS];
396 u8 code[0];
397 } __packed;
399 /* structures describing a block within a DSP page */
400 struct block_info_e1 {
401 __le16 wHdr;
402 __le16 wAddress;
403 __le16 wSize;
404 __le16 wOvlOffset;
405 __le16 wOvl; /* overlay */
406 __le16 wLast;
407 } __packed;
408 #define E1_BLOCK_INFO_SIZE 12
410 struct block_info_e4 {
411 __be16 wHdr;
412 __u8 bBootPage;
413 __u8 bPageNumber;
414 __be32 dwSize;
415 __be32 dwAddress;
416 __be16 wReserved;
417 } __packed;
418 #define E4_BLOCK_INFO_SIZE 14
420 #define UEA_BIHDR 0xabcd
421 #define UEA_RESERVED 0xffff
423 /* constants describing cmv type */
424 #define E1_PREAMBLE 0x535c
425 #define E1_MODEMTOHOST 0x01
426 #define E1_HOSTTOMODEM 0x10
428 #define E1_MEMACCESS 0x1
429 #define E1_ADSLDIRECTIVE 0x7
430 #define E1_FUNCTION_TYPE(f) ((f) >> 4)
431 #define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f)
433 #define E4_MEMACCESS 0
434 #define E4_ADSLDIRECTIVE 0xf
435 #define E4_FUNCTION_TYPE(f) ((f) >> 8)
436 #define E4_FUNCTION_SIZE(f) ((f) & 0x0f)
437 #define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f)
439 /* for MEMACCESS */
440 #define E1_REQUESTREAD 0x0
441 #define E1_REQUESTWRITE 0x1
442 #define E1_REPLYREAD 0x2
443 #define E1_REPLYWRITE 0x3
445 #define E4_REQUESTREAD 0x0
446 #define E4_REQUESTWRITE 0x4
447 #define E4_REPLYREAD (E4_REQUESTREAD | 1)
448 #define E4_REPLYWRITE (E4_REQUESTWRITE | 1)
450 /* for ADSLDIRECTIVE */
451 #define E1_KERNELREADY 0x0
452 #define E1_MODEMREADY 0x1
454 #define E4_KERNELREADY 0x0
455 #define E4_MODEMREADY 0x1
457 #define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
458 #define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | \
459 ((st) & 0xf) << 4 | ((s) & 0xf))
461 #define E1_MAKESA(a, b, c, d) \
462 (((c) & 0xff) << 24 | \
463 ((d) & 0xff) << 16 | \
464 ((a) & 0xff) << 8 | \
465 ((b) & 0xff))
467 #define E1_GETSA1(a) ((a >> 8) & 0xff)
468 #define E1_GETSA2(a) (a & 0xff)
469 #define E1_GETSA3(a) ((a >> 24) & 0xff)
470 #define E1_GETSA4(a) ((a >> 16) & 0xff)
472 #define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L')
473 #define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G')
474 #define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O')
475 #define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N')
476 #define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E')
477 #define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T')
479 #define E4_SA_CNTL 1
480 #define E4_SA_STAT 2
481 #define E4_SA_INFO 3
482 #define E4_SA_TEST 4
483 #define E4_SA_OPTN 5
484 #define E4_SA_RATE 6
485 #define E4_SA_DIAG 7
486 #define E4_SA_CNFG 8
488 /* structures representing a CMV (Configuration and Management Variable) */
489 struct cmv_e1 {
490 __le16 wPreamble;
491 __u8 bDirection;
492 __u8 bFunction;
493 __le16 wIndex;
494 __le32 dwSymbolicAddress;
495 __le16 wOffsetAddress;
496 __le32 dwData;
497 } __packed;
499 struct cmv_e4 {
500 __be16 wGroup;
501 __be16 wFunction;
502 __be16 wOffset;
503 __be16 wAddress;
504 __be32 dwData[6];
505 } __packed;
507 /* structures representing swap information */
508 struct swap_info_e1 {
509 __u8 bSwapPageNo;
510 __u8 bOvl; /* overlay */
511 } __packed;
513 struct swap_info_e4 {
514 __u8 bSwapPageNo;
515 } __packed;
517 /* structures representing interrupt data */
518 #define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
519 #define e1_bOvl u.e1.s1.swapinfo.bOvl
520 #define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo
522 #define INT_LOADSWAPPAGE 0x0001
523 #define INT_INCOMINGCMV 0x0002
525 union intr_data_e1 {
526 struct {
527 struct swap_info_e1 swapinfo;
528 __le16 wDataSize;
529 } __packed s1;
530 struct {
531 struct cmv_e1 cmv;
532 __le16 wDataSize;
533 } __packed s2;
534 } __packed;
536 union intr_data_e4 {
537 struct {
538 struct swap_info_e4 swapinfo;
539 __le16 wDataSize;
540 } __packed s1;
541 struct {
542 struct cmv_e4 cmv;
543 __le16 wDataSize;
544 } __packed s2;
545 } __packed;
547 struct intr_pkt {
548 __u8 bType;
549 __u8 bNotification;
550 __le16 wValue;
551 __le16 wIndex;
552 __le16 wLength;
553 __le16 wInterrupt;
554 union {
555 union intr_data_e1 e1;
556 union intr_data_e4 e4;
557 } u;
558 } __packed;
560 #define E1_INTR_PKT_SIZE 28
561 #define E4_INTR_PKT_SIZE 64
563 static struct usb_driver uea_driver;
564 static DEFINE_MUTEX(uea_mutex);
565 static const char * const chip_name[] = {
566 "ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
568 static int modem_index;
569 static unsigned int debug;
570 static unsigned int altsetting[NB_MODEM] = {
571 [0 ... (NB_MODEM - 1)] = FASTEST_ISO_INTF};
572 static bool sync_wait[NB_MODEM];
573 static char *cmv_file[NB_MODEM];
574 static int annex[NB_MODEM];
576 module_param(debug, uint, 0644);
577 MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
578 module_param_array(altsetting, uint, NULL, 0644);
579 MODULE_PARM_DESC(altsetting, "alternate setting for incoming traffic: 0=bulk, "
580 "1=isoc slowest, ... , 8=isoc fastest (default)");
581 module_param_array(sync_wait, bool, NULL, 0644);
582 MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
583 module_param_array(cmv_file, charp, NULL, 0644);
584 MODULE_PARM_DESC(cmv_file,
585 "file name with configuration and management variables");
586 module_param_array(annex, uint, NULL, 0644);
587 MODULE_PARM_DESC(annex,
588 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
590 #define uea_wait(sc, cond, timeo) \
591 ({ \
592 int _r = wait_event_interruptible_timeout(sc->sync_q, \
593 (cond) || kthread_should_stop(), timeo); \
594 if (kthread_should_stop()) \
595 _r = -ENODEV; \
596 _r; \
599 #define UPDATE_ATM_STAT(type, val) \
600 do { \
601 if (sc->usbatm->atm_dev) \
602 sc->usbatm->atm_dev->type = val; \
603 } while (0)
605 #define UPDATE_ATM_SIGNAL(val) \
606 do { \
607 if (sc->usbatm->atm_dev) \
608 atm_dev_signal_change(sc->usbatm->atm_dev, val); \
609 } while (0)
612 /* Firmware loading */
613 #define LOAD_INTERNAL 0xA0
614 #define F8051_USBCS 0x7f92
617 * uea_send_modem_cmd - Send a command for pre-firmware devices.
619 static int uea_send_modem_cmd(struct usb_device *usb,
620 u16 addr, u16 size, const u8 *buff)
622 int ret = -ENOMEM;
623 u8 *xfer_buff;
625 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
626 if (xfer_buff) {
627 ret = usb_control_msg(usb,
628 usb_sndctrlpipe(usb, 0),
629 LOAD_INTERNAL,
630 USB_DIR_OUT | USB_TYPE_VENDOR |
631 USB_RECIP_DEVICE, addr, 0, xfer_buff,
632 size, CTRL_TIMEOUT);
633 kfree(xfer_buff);
636 if (ret < 0)
637 return ret;
639 return (ret == size) ? 0 : -EIO;
642 static void uea_upload_pre_firmware(const struct firmware *fw_entry,
643 void *context)
645 struct usb_device *usb = context;
646 const u8 *pfw;
647 u8 value;
648 u32 crc = 0;
649 int ret, size;
651 uea_enters(usb);
652 if (!fw_entry) {
653 uea_err(usb, "firmware is not available\n");
654 goto err;
657 pfw = fw_entry->data;
658 size = fw_entry->size;
659 if (size < 4)
660 goto err_fw_corrupted;
662 crc = get_unaligned_le32(pfw);
663 pfw += 4;
664 size -= 4;
665 if (crc32_be(0, pfw, size) != crc)
666 goto err_fw_corrupted;
669 * Start to upload firmware : send reset
671 value = 1;
672 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
674 if (ret < 0) {
675 uea_err(usb, "modem reset failed with error %d\n", ret);
676 goto err;
679 while (size > 3) {
680 u8 len = FW_GET_BYTE(pfw);
681 u16 add = get_unaligned_le16(pfw + 1);
683 size -= len + 3;
684 if (size < 0)
685 goto err_fw_corrupted;
687 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
688 if (ret < 0) {
689 uea_err(usb, "uploading firmware data failed "
690 "with error %d\n", ret);
691 goto err;
693 pfw += len + 3;
696 if (size != 0)
697 goto err_fw_corrupted;
700 * Tell the modem we finish : de-assert reset
702 value = 0;
703 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
704 if (ret < 0)
705 uea_err(usb, "modem de-assert failed with error %d\n", ret);
706 else
707 uea_info(usb, "firmware uploaded\n");
709 goto err;
711 err_fw_corrupted:
712 uea_err(usb, "firmware is corrupted\n");
713 err:
714 release_firmware(fw_entry);
715 uea_leaves(usb);
719 * uea_load_firmware - Load usb firmware for pre-firmware devices.
721 static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
723 int ret;
724 char *fw_name = EAGLE_FIRMWARE;
726 uea_enters(usb);
727 uea_info(usb, "pre-firmware device, uploading firmware\n");
729 switch (ver) {
730 case ADI930:
731 fw_name = ADI930_FIRMWARE;
732 break;
733 case EAGLE_I:
734 fw_name = EAGLE_I_FIRMWARE;
735 break;
736 case EAGLE_II:
737 fw_name = EAGLE_II_FIRMWARE;
738 break;
739 case EAGLE_III:
740 fw_name = EAGLE_III_FIRMWARE;
741 break;
742 case EAGLE_IV:
743 fw_name = EAGLE_IV_FIRMWARE;
744 break;
747 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev,
748 GFP_KERNEL, usb,
749 uea_upload_pre_firmware);
750 if (ret)
751 uea_err(usb, "firmware %s is not available\n", fw_name);
752 else
753 uea_info(usb, "loading firmware %s\n", fw_name);
755 uea_leaves(usb);
756 return ret;
759 /* modem management : dsp firmware, send/read CMV, monitoring statistic
763 * Make sure that the DSP code provided is safe to use.
765 static int check_dsp_e1(const u8 *dsp, unsigned int len)
767 u8 pagecount, blockcount;
768 u16 blocksize;
769 u32 pageoffset;
770 unsigned int i, j, p, pp;
772 pagecount = FW_GET_BYTE(dsp);
773 p = 1;
775 /* enough space for page offsets? */
776 if (p + 4 * pagecount > len)
777 return 1;
779 for (i = 0; i < pagecount; i++) {
781 pageoffset = get_unaligned_le32(dsp + p);
782 p += 4;
784 if (pageoffset == 0)
785 continue;
787 /* enough space for blockcount? */
788 if (pageoffset >= len)
789 return 1;
791 pp = pageoffset;
792 blockcount = FW_GET_BYTE(dsp + pp);
793 pp += 1;
795 for (j = 0; j < blockcount; j++) {
797 /* enough space for block header? */
798 if (pp + 4 > len)
799 return 1;
801 pp += 2; /* skip blockaddr */
802 blocksize = get_unaligned_le16(dsp + pp);
803 pp += 2;
805 /* enough space for block data? */
806 if (pp + blocksize > len)
807 return 1;
809 pp += blocksize;
813 return 0;
816 static int check_dsp_e4(const u8 *dsp, int len)
818 int i;
819 struct l1_code *p = (struct l1_code *) dsp;
820 unsigned int sum = p->code - dsp;
822 if (len < sum)
823 return 1;
825 if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 &&
826 strcmp("STRATIPHY ANEXB", p->string_header) != 0)
827 return 1;
829 for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) {
830 struct block_index *blockidx;
831 u8 blockno = p->page_number_to_block_index[i];
832 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
833 continue;
835 do {
836 u64 l;
838 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
839 return 1;
841 blockidx = &p->page_header[blockno++];
842 if ((u8 *)(blockidx + 1) - dsp >= len)
843 return 1;
845 if (le16_to_cpu(blockidx->PageNumber) != i)
846 return 1;
848 l = E4_PAGE_BYTES(blockidx->PageSize);
849 sum += l;
850 l += le32_to_cpu(blockidx->PageOffset);
851 if (l > len)
852 return 1;
854 /* zero is zero regardless endianes */
855 } while (blockidx->NotLastBlock);
858 return (sum == len) ? 0 : 1;
862 * send data to the idma pipe
863 * */
864 static int uea_idma_write(struct uea_softc *sc, const void *data, u32 size)
866 int ret = -ENOMEM;
867 u8 *xfer_buff;
868 int bytes_read;
870 xfer_buff = kmemdup(data, size, GFP_KERNEL);
871 if (!xfer_buff) {
872 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
873 return ret;
876 ret = usb_bulk_msg(sc->usb_dev,
877 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
878 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
880 kfree(xfer_buff);
881 if (ret < 0)
882 return ret;
883 if (size != bytes_read) {
884 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
885 bytes_read);
886 return -EIO;
889 return 0;
892 static int request_dsp(struct uea_softc *sc)
894 int ret;
895 char *dsp_name;
897 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
898 if (IS_ISDN(sc))
899 dsp_name = DSP4I_FIRMWARE;
900 else
901 dsp_name = DSP4P_FIRMWARE;
902 } else if (UEA_CHIP_VERSION(sc) == ADI930) {
903 if (IS_ISDN(sc))
904 dsp_name = DSP9I_FIRMWARE;
905 else
906 dsp_name = DSP9P_FIRMWARE;
907 } else {
908 if (IS_ISDN(sc))
909 dsp_name = DSPEI_FIRMWARE;
910 else
911 dsp_name = DSPEP_FIRMWARE;
914 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
915 if (ret < 0) {
916 uea_err(INS_TO_USBDEV(sc),
917 "requesting firmware %s failed with error %d\n",
918 dsp_name, ret);
919 return ret;
922 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
923 ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size);
924 else
925 ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size);
927 if (ret) {
928 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
929 dsp_name);
930 release_firmware(sc->dsp_firm);
931 sc->dsp_firm = NULL;
932 return -EILSEQ;
935 return 0;
939 * The uea_load_page() function must be called within a process context
941 static void uea_load_page_e1(struct work_struct *work)
943 struct uea_softc *sc = container_of(work, struct uea_softc, task);
944 u16 pageno = sc->pageno;
945 u16 ovl = sc->ovl;
946 struct block_info_e1 bi;
948 const u8 *p;
949 u8 pagecount, blockcount;
950 u16 blockaddr, blocksize;
951 u32 pageoffset;
952 int i;
954 /* reload firmware when reboot start and it's loaded already */
955 if (ovl == 0 && pageno == 0) {
956 release_firmware(sc->dsp_firm);
957 sc->dsp_firm = NULL;
960 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
961 return;
963 p = sc->dsp_firm->data;
964 pagecount = FW_GET_BYTE(p);
965 p += 1;
967 if (pageno >= pagecount)
968 goto bad1;
970 p += 4 * pageno;
971 pageoffset = get_unaligned_le32(p);
973 if (pageoffset == 0)
974 goto bad1;
976 p = sc->dsp_firm->data + pageoffset;
977 blockcount = FW_GET_BYTE(p);
978 p += 1;
980 uea_dbg(INS_TO_USBDEV(sc),
981 "sending %u blocks for DSP page %u\n", blockcount, pageno);
983 bi.wHdr = cpu_to_le16(UEA_BIHDR);
984 bi.wOvl = cpu_to_le16(ovl);
985 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
987 for (i = 0; i < blockcount; i++) {
988 blockaddr = get_unaligned_le16(p);
989 p += 2;
991 blocksize = get_unaligned_le16(p);
992 p += 2;
994 bi.wSize = cpu_to_le16(blocksize);
995 bi.wAddress = cpu_to_le16(blockaddr);
996 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
998 /* send block info through the IDMA pipe */
999 if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE))
1000 goto bad2;
1002 /* send block data through the IDMA pipe */
1003 if (uea_idma_write(sc, p, blocksize))
1004 goto bad2;
1006 p += blocksize;
1009 return;
1011 bad2:
1012 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
1013 return;
1014 bad1:
1015 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
1018 static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
1020 struct block_info_e4 bi;
1021 struct block_index *blockidx;
1022 struct l1_code *p = (struct l1_code *) sc->dsp_firm->data;
1023 u8 blockno = p->page_number_to_block_index[pageno];
1025 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1026 bi.bBootPage = boot;
1027 bi.bPageNumber = pageno;
1028 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1030 do {
1031 const u8 *blockoffset;
1032 unsigned int blocksize;
1034 blockidx = &p->page_header[blockno];
1035 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
1036 blockoffset = sc->dsp_firm->data + le32_to_cpu(
1037 blockidx->PageOffset);
1039 bi.dwSize = cpu_to_be32(blocksize);
1040 bi.dwAddress = cpu_to_be32(le32_to_cpu(blockidx->PageAddress));
1042 uea_dbg(INS_TO_USBDEV(sc),
1043 "sending block %u for DSP page "
1044 "%u size %u address %x\n",
1045 blockno, pageno, blocksize,
1046 le32_to_cpu(blockidx->PageAddress));
1048 /* send block info through the IDMA pipe */
1049 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1050 goto bad;
1052 /* send block data through the IDMA pipe */
1053 if (uea_idma_write(sc, blockoffset, blocksize))
1054 goto bad;
1056 blockno++;
1057 } while (blockidx->NotLastBlock);
1059 return;
1061 bad:
1062 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno);
1063 return;
1066 static void uea_load_page_e4(struct work_struct *work)
1068 struct uea_softc *sc = container_of(work, struct uea_softc, task);
1069 u8 pageno = sc->pageno;
1070 int i;
1071 struct block_info_e4 bi;
1072 struct l1_code *p;
1074 uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
1076 /* reload firmware when reboot start and it's loaded already */
1077 if (pageno == 0) {
1078 release_firmware(sc->dsp_firm);
1079 sc->dsp_firm = NULL;
1082 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
1083 return;
1085 p = (struct l1_code *) sc->dsp_firm->data;
1086 if (pageno >= le16_to_cpu(p->page_header[0].PageNumber)) {
1087 uea_err(INS_TO_USBDEV(sc), "invalid DSP "
1088 "page %u requested\n", pageno);
1089 return;
1092 if (pageno != 0) {
1093 __uea_load_page_e4(sc, pageno, 0);
1094 return;
1097 uea_dbg(INS_TO_USBDEV(sc),
1098 "sending Main DSP page %u\n", p->page_header[0].PageNumber);
1100 for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) {
1101 if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize))
1102 __uea_load_page_e4(sc, i, 1);
1105 uea_dbg(INS_TO_USBDEV(sc) , "sending start bi\n");
1107 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1108 bi.bBootPage = 0;
1109 bi.bPageNumber = 0xff;
1110 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1111 bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize));
1112 bi.dwAddress = cpu_to_be32(le32_to_cpu(p->page_header[0].PageAddress));
1114 /* send block info through the IDMA pipe */
1115 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1116 uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n");
1119 static inline void wake_up_cmv_ack(struct uea_softc *sc)
1121 BUG_ON(sc->cmv_ack);
1122 sc->cmv_ack = 1;
1123 wake_up(&sc->sync_q);
1126 static inline int wait_cmv_ack(struct uea_softc *sc)
1128 int ret = uea_wait(sc, sc->cmv_ack , ACK_TIMEOUT);
1130 sc->cmv_ack = 0;
1132 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
1133 jiffies_to_msecs(ret));
1135 if (ret < 0)
1136 return ret;
1138 return (ret == 0) ? -ETIMEDOUT : 0;
1141 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1143 static int uea_request(struct uea_softc *sc,
1144 u16 value, u16 index, u16 size, const void *data)
1146 u8 *xfer_buff;
1147 int ret = -ENOMEM;
1149 xfer_buff = kmemdup(data, size, GFP_KERNEL);
1150 if (!xfer_buff) {
1151 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
1152 return ret;
1155 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
1156 UCDC_SEND_ENCAPSULATED_COMMAND,
1157 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1158 value, index, xfer_buff, size, CTRL_TIMEOUT);
1160 kfree(xfer_buff);
1161 if (ret < 0) {
1162 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
1163 return ret;
1166 if (ret != size) {
1167 uea_err(INS_TO_USBDEV(sc),
1168 "usb_control_msg send only %d bytes (instead of %d)\n",
1169 ret, size);
1170 return -EIO;
1173 return 0;
1176 static int uea_cmv_e1(struct uea_softc *sc,
1177 u8 function, u32 address, u16 offset, u32 data)
1179 struct cmv_e1 cmv;
1180 int ret;
1182 uea_enters(INS_TO_USBDEV(sc));
1183 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1184 "offset : 0x%04x, data : 0x%08x\n",
1185 E1_FUNCTION_TYPE(function),
1186 E1_FUNCTION_SUBTYPE(function),
1187 E1_GETSA1(address), E1_GETSA2(address),
1188 E1_GETSA3(address),
1189 E1_GETSA4(address), offset, data);
1191 /* we send a request, but we expect a reply */
1192 sc->cmv_dsc.e1.function = function | 0x2;
1193 sc->cmv_dsc.e1.idx++;
1194 sc->cmv_dsc.e1.address = address;
1195 sc->cmv_dsc.e1.offset = offset;
1197 cmv.wPreamble = cpu_to_le16(E1_PREAMBLE);
1198 cmv.bDirection = E1_HOSTTOMODEM;
1199 cmv.bFunction = function;
1200 cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx);
1201 put_unaligned_le32(address, &cmv.dwSymbolicAddress);
1202 cmv.wOffsetAddress = cpu_to_le16(offset);
1203 put_unaligned_le32(data >> 16 | data << 16, &cmv.dwData);
1205 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START,
1206 sizeof(cmv), &cmv);
1207 if (ret < 0)
1208 return ret;
1209 ret = wait_cmv_ack(sc);
1210 uea_leaves(INS_TO_USBDEV(sc));
1211 return ret;
1214 static int uea_cmv_e4(struct uea_softc *sc,
1215 u16 function, u16 group, u16 address, u16 offset, u32 data)
1217 struct cmv_e4 cmv;
1218 int ret;
1220 uea_enters(INS_TO_USBDEV(sc));
1221 memset(&cmv, 0, sizeof(cmv));
1223 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
1224 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1225 E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function),
1226 group, address, offset, data);
1228 /* we send a request, but we expect a reply */
1229 sc->cmv_dsc.e4.function = function | (0x1 << 4);
1230 sc->cmv_dsc.e4.offset = offset;
1231 sc->cmv_dsc.e4.address = address;
1232 sc->cmv_dsc.e4.group = group;
1234 cmv.wFunction = cpu_to_be16(function);
1235 cmv.wGroup = cpu_to_be16(group);
1236 cmv.wAddress = cpu_to_be16(address);
1237 cmv.wOffset = cpu_to_be16(offset);
1238 cmv.dwData[0] = cpu_to_be32(data);
1240 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START,
1241 sizeof(cmv), &cmv);
1242 if (ret < 0)
1243 return ret;
1244 ret = wait_cmv_ack(sc);
1245 uea_leaves(INS_TO_USBDEV(sc));
1246 return ret;
1249 static inline int uea_read_cmv_e1(struct uea_softc *sc,
1250 u32 address, u16 offset, u32 *data)
1252 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD),
1253 address, offset, 0);
1254 if (ret < 0)
1255 uea_err(INS_TO_USBDEV(sc),
1256 "reading cmv failed with error %d\n", ret);
1257 else
1258 *data = sc->data;
1260 return ret;
1263 static inline int uea_read_cmv_e4(struct uea_softc *sc,
1264 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1266 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1267 E4_REQUESTREAD, size),
1268 group, address, offset, 0);
1269 if (ret < 0)
1270 uea_err(INS_TO_USBDEV(sc),
1271 "reading cmv failed with error %d\n", ret);
1272 else {
1273 *data = sc->data;
1274 /* size is in 16-bit word quantities */
1275 if (size > 2)
1276 *(data + 1) = sc->data1;
1278 return ret;
1281 static inline int uea_write_cmv_e1(struct uea_softc *sc,
1282 u32 address, u16 offset, u32 data)
1284 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE),
1285 address, offset, data);
1286 if (ret < 0)
1287 uea_err(INS_TO_USBDEV(sc),
1288 "writing cmv failed with error %d\n", ret);
1290 return ret;
1293 static inline int uea_write_cmv_e4(struct uea_softc *sc,
1294 u8 size, u16 group, u16 address, u16 offset, u32 data)
1296 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1297 E4_REQUESTWRITE, size),
1298 group, address, offset, data);
1299 if (ret < 0)
1300 uea_err(INS_TO_USBDEV(sc),
1301 "writing cmv failed with error %d\n", ret);
1303 return ret;
1306 static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1308 int ret;
1309 u16 timeout;
1311 /* in bulk mode the modem have problem with high rate
1312 * changing internal timing could improve things, but the
1313 * value is mysterious.
1314 * ADI930 don't support it (-EPIPE error).
1317 if (UEA_CHIP_VERSION(sc) == ADI930 ||
1318 altsetting[sc->modem_index] > 0 ||
1319 sc->stats.phy.dsrate == dsrate)
1320 return;
1322 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1323 timeout = (dsrate <= 1024*1024) ? 0 : 1;
1324 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
1325 uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n",
1326 timeout, ret < 0 ? " failed" : "");
1331 * Monitor the modem and update the stat
1332 * return 0 if everything is ok
1333 * return < 0 if an error occurs (-EAGAIN reboot needed)
1335 static int uea_stat_e1(struct uea_softc *sc)
1337 u32 data;
1338 int ret;
1340 uea_enters(INS_TO_USBDEV(sc));
1341 data = sc->stats.phy.state;
1343 ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state);
1344 if (ret < 0)
1345 return ret;
1347 switch (GET_STATUS(sc->stats.phy.state)) {
1348 case 0: /* not yet synchronized */
1349 uea_dbg(INS_TO_USBDEV(sc),
1350 "modem not yet synchronized\n");
1351 return 0;
1353 case 1: /* initialization */
1354 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1355 return 0;
1357 case 2: /* operational */
1358 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
1359 break;
1361 case 3: /* fail ... */
1362 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1363 " (may be try other cmv/dsp)\n");
1364 return -EAGAIN;
1366 case 4 ... 6: /* test state */
1367 uea_warn(INS_TO_USBDEV(sc),
1368 "modem in test mode - not supported\n");
1369 return -EAGAIN;
1371 case 7: /* fast-retain ... */
1372 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
1373 return 0;
1374 default:
1375 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
1376 GET_STATUS(sc->stats.phy.state));
1377 return -EAGAIN;
1380 if (GET_STATUS(data) != 2) {
1381 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1382 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1384 /* release the dsp firmware as it is not needed until
1385 * the next failure
1387 release_firmware(sc->dsp_firm);
1388 sc->dsp_firm = NULL;
1391 /* always update it as atm layer could not be init when we switch to
1392 * operational state
1394 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND);
1396 /* wake up processes waiting for synchronization */
1397 wake_up(&sc->sync_q);
1399 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags);
1400 if (ret < 0)
1401 return ret;
1402 sc->stats.phy.mflags |= sc->stats.phy.flags;
1404 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1405 * we check the status again in order to detect the failure earlier
1407 if (sc->stats.phy.flags) {
1408 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1409 sc->stats.phy.flags);
1410 return 0;
1413 ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data);
1414 if (ret < 0)
1415 return ret;
1417 uea_set_bulk_timeout(sc, (data >> 16) * 32);
1418 sc->stats.phy.dsrate = (data >> 16) * 32;
1419 sc->stats.phy.usrate = (data & 0xffff) * 32;
1420 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1422 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data);
1423 if (ret < 0)
1424 return ret;
1425 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
1427 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data);
1428 if (ret < 0)
1429 return ret;
1430 sc->stats.phy.usattenuation = (data & 0xff) / 2;
1432 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin);
1433 if (ret < 0)
1434 return ret;
1436 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin);
1437 if (ret < 0)
1438 return ret;
1440 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow);
1441 if (ret < 0)
1442 return ret;
1444 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow);
1445 if (ret < 0)
1446 return ret;
1448 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc);
1449 if (ret < 0)
1450 return ret;
1452 /* only for atu-c */
1453 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc);
1454 if (ret < 0)
1455 return ret;
1457 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr);
1458 if (ret < 0)
1459 return ret;
1461 /* only for atu-c */
1462 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr);
1463 if (ret < 0)
1464 return ret;
1466 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 8, &sc->stats.phy.vidco);
1467 if (ret < 0)
1468 return ret;
1470 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 13, &sc->stats.phy.vidcpe);
1471 if (ret < 0)
1472 return ret;
1474 return 0;
1477 static int uea_stat_e4(struct uea_softc *sc)
1479 u32 data;
1480 u32 tmp_arr[2];
1481 int ret;
1483 uea_enters(INS_TO_USBDEV(sc));
1484 data = sc->stats.phy.state;
1486 /* XXX only need to be done before operationnal... */
1487 ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state);
1488 if (ret < 0)
1489 return ret;
1491 switch (sc->stats.phy.state) {
1492 case 0x0: /* not yet synchronized */
1493 case 0x1:
1494 case 0x3:
1495 case 0x4:
1496 uea_dbg(INS_TO_USBDEV(sc), "modem not yet "
1497 "synchronized\n");
1498 return 0;
1499 case 0x5: /* initialization */
1500 case 0x6:
1501 case 0x9:
1502 case 0xa:
1503 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1504 return 0;
1505 case 0x2: /* fail ... */
1506 uea_info(INS_TO_USBDEV(sc), "modem synchronization "
1507 "failed (may be try other cmv/dsp)\n");
1508 return -EAGAIN;
1509 case 0x7: /* operational */
1510 break;
1511 default:
1512 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n",
1513 sc->stats.phy.state);
1514 return 0;
1517 if (data != 7) {
1518 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1519 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1521 /* release the dsp firmware as it is not needed until
1522 * the next failure
1524 release_firmware(sc->dsp_firm);
1525 sc->dsp_firm = NULL;
1528 /* always update it as atm layer could not be init when we switch to
1529 * operational state
1531 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND);
1533 /* wake up processes waiting for synchronization */
1534 wake_up(&sc->sync_q);
1536 /* TODO improve this state machine :
1537 * we need some CMV info : what they do and their unit
1538 * we should find the equivalent of eagle3- CMV
1540 /* check flags */
1541 ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags);
1542 if (ret < 0)
1543 return ret;
1544 sc->stats.phy.mflags |= sc->stats.phy.flags;
1546 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1547 * we check the status again in order to detect the failure earlier
1549 if (sc->stats.phy.flags) {
1550 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1551 sc->stats.phy.flags);
1552 if (sc->stats.phy.flags & 1) /* delineation LOSS */
1553 return -EAGAIN;
1554 if (sc->stats.phy.flags & 0x4000) /* Reset Flag */
1555 return -EAGAIN;
1556 return 0;
1559 /* rate data may be in upper or lower half of 64 bit word, strange */
1560 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr);
1561 if (ret < 0)
1562 return ret;
1563 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1564 sc->stats.phy.usrate = data / 1000;
1566 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr);
1567 if (ret < 0)
1568 return ret;
1569 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1570 uea_set_bulk_timeout(sc, data / 1000);
1571 sc->stats.phy.dsrate = data / 1000;
1572 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1574 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data);
1575 if (ret < 0)
1576 return ret;
1577 sc->stats.phy.dsattenuation = data / 10;
1579 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data);
1580 if (ret < 0)
1581 return ret;
1582 sc->stats.phy.usattenuation = data / 10;
1584 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data);
1585 if (ret < 0)
1586 return ret;
1587 sc->stats.phy.dsmargin = data / 2;
1589 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data);
1590 if (ret < 0)
1591 return ret;
1592 sc->stats.phy.usmargin = data / 10;
1594 return 0;
1597 static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1599 char file_arr[] = "CMVxy.bin";
1600 char *file;
1602 kernel_param_lock(THIS_MODULE);
1603 /* set proper name corresponding modem version and line type */
1604 if (cmv_file[sc->modem_index] == NULL) {
1605 if (UEA_CHIP_VERSION(sc) == ADI930)
1606 file_arr[3] = '9';
1607 else if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1608 file_arr[3] = '4';
1609 else
1610 file_arr[3] = 'e';
1612 file_arr[4] = IS_ISDN(sc) ? 'i' : 'p';
1613 file = file_arr;
1614 } else
1615 file = cmv_file[sc->modem_index];
1617 strcpy(cmv_name, FW_DIR);
1618 strlcat(cmv_name, file, UEA_FW_NAME_MAX);
1619 if (ver == 2)
1620 strlcat(cmv_name, ".v2", UEA_FW_NAME_MAX);
1621 kernel_param_unlock(THIS_MODULE);
1624 static int request_cmvs_old(struct uea_softc *sc,
1625 void **cmvs, const struct firmware **fw)
1627 int ret, size;
1628 u8 *data;
1629 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
1631 cmvs_file_name(sc, cmv_name, 1);
1632 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1633 if (ret < 0) {
1634 uea_err(INS_TO_USBDEV(sc),
1635 "requesting firmware %s failed with error %d\n",
1636 cmv_name, ret);
1637 return ret;
1640 data = (u8 *) (*fw)->data;
1641 size = (*fw)->size;
1642 if (size < 1)
1643 goto err_fw_corrupted;
1645 if (size != *data * sizeof(struct uea_cmvs_v1) + 1)
1646 goto err_fw_corrupted;
1648 *cmvs = (void *)(data + 1);
1649 return *data;
1651 err_fw_corrupted:
1652 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1653 release_firmware(*fw);
1654 return -EILSEQ;
1657 static int request_cmvs(struct uea_softc *sc,
1658 void **cmvs, const struct firmware **fw, int *ver)
1660 int ret, size;
1661 u32 crc;
1662 u8 *data;
1663 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
1665 cmvs_file_name(sc, cmv_name, 2);
1666 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1667 if (ret < 0) {
1668 /* if caller can handle old version, try to provide it */
1669 if (*ver == 1) {
1670 uea_warn(INS_TO_USBDEV(sc), "requesting "
1671 "firmware %s failed, "
1672 "try to get older cmvs\n", cmv_name);
1673 return request_cmvs_old(sc, cmvs, fw);
1675 uea_err(INS_TO_USBDEV(sc),
1676 "requesting firmware %s failed with error %d\n",
1677 cmv_name, ret);
1678 return ret;
1681 size = (*fw)->size;
1682 data = (u8 *) (*fw)->data;
1683 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1684 if (*ver == 1) {
1685 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted,"
1686 " try to get older cmvs\n", cmv_name);
1687 release_firmware(*fw);
1688 return request_cmvs_old(sc, cmvs, fw);
1690 goto err_fw_corrupted;
1693 *ver = 2;
1695 data += 4;
1696 size -= 4;
1697 if (size < 5)
1698 goto err_fw_corrupted;
1700 crc = get_unaligned_le32(data);
1701 data += 4;
1702 size -= 4;
1703 if (crc32_be(0, data, size) != crc)
1704 goto err_fw_corrupted;
1706 if (size != *data * sizeof(struct uea_cmvs_v2) + 1)
1707 goto err_fw_corrupted;
1709 *cmvs = (void *) (data + 1);
1710 return *data;
1712 err_fw_corrupted:
1713 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1714 release_firmware(*fw);
1715 return -EILSEQ;
1718 static int uea_send_cmvs_e1(struct uea_softc *sc)
1720 int i, ret, len;
1721 void *cmvs_ptr;
1722 const struct firmware *cmvs_fw;
1723 int ver = 1; /* we can handle v1 cmv firmware version; */
1725 /* Enter in R-IDLE (cmv) until instructed otherwise */
1726 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
1727 if (ret < 0)
1728 return ret;
1730 /* Dump firmware version */
1731 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid);
1732 if (ret < 0)
1733 return ret;
1734 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1735 sc->stats.phy.firmid);
1737 /* get options */
1738 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1739 if (ret < 0)
1740 return ret;
1742 /* send options */
1743 if (ver == 1) {
1744 struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr;
1746 uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, "
1747 "please update your firmware\n");
1749 for (i = 0; i < len; i++) {
1750 ret = uea_write_cmv_e1(sc,
1751 get_unaligned_le32(&cmvs_v1[i].address),
1752 get_unaligned_le16(&cmvs_v1[i].offset),
1753 get_unaligned_le32(&cmvs_v1[i].data));
1754 if (ret < 0)
1755 goto out;
1757 } else if (ver == 2) {
1758 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1760 for (i = 0; i < len; i++) {
1761 ret = uea_write_cmv_e1(sc,
1762 get_unaligned_le32(&cmvs_v2[i].address),
1763 (u16) get_unaligned_le32(&cmvs_v2[i].offset),
1764 get_unaligned_le32(&cmvs_v2[i].data));
1765 if (ret < 0)
1766 goto out;
1768 } else {
1769 /* This really should not happen */
1770 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1771 goto out;
1774 /* Enter in R-ACT-REQ */
1775 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1776 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1777 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1778 "synchronization...\n");
1779 out:
1780 release_firmware(cmvs_fw);
1781 return ret;
1784 static int uea_send_cmvs_e4(struct uea_softc *sc)
1786 int i, ret, len;
1787 void *cmvs_ptr;
1788 const struct firmware *cmvs_fw;
1789 int ver = 2; /* we can only handle v2 cmv firmware version; */
1791 /* Enter in R-IDLE (cmv) until instructed otherwise */
1792 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
1793 if (ret < 0)
1794 return ret;
1796 /* Dump firmware version */
1797 /* XXX don't read the 3th byte as it is always 6 */
1798 ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid);
1799 if (ret < 0)
1800 return ret;
1801 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1802 sc->stats.phy.firmid);
1805 /* get options */
1806 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1807 if (ret < 0)
1808 return ret;
1810 /* send options */
1811 if (ver == 2) {
1812 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1814 for (i = 0; i < len; i++) {
1815 ret = uea_write_cmv_e4(sc, 1,
1816 get_unaligned_le32(&cmvs_v2[i].group),
1817 get_unaligned_le32(&cmvs_v2[i].address),
1818 get_unaligned_le32(&cmvs_v2[i].offset),
1819 get_unaligned_le32(&cmvs_v2[i].data));
1820 if (ret < 0)
1821 goto out;
1823 } else {
1824 /* This really should not happen */
1825 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1826 goto out;
1829 /* Enter in R-ACT-REQ */
1830 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1831 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1832 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1833 "synchronization...\n");
1834 out:
1835 release_firmware(cmvs_fw);
1836 return ret;
1839 /* Start boot post firmware modem:
1840 * - send reset commands through usb control pipe
1841 * - start workqueue for DSP loading
1842 * - send CMV options to modem
1845 static int uea_start_reset(struct uea_softc *sc)
1847 u16 zero = 0; /* ;-) */
1848 int ret;
1850 uea_enters(INS_TO_USBDEV(sc));
1851 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1853 /* mask interrupt */
1854 sc->booting = 1;
1855 /* We need to set this here because, a ack timeout could have occurred,
1856 * but before we start the reboot, the ack occurs and set this to 1.
1857 * So we will failed to wait Ready CMV.
1859 sc->cmv_ack = 0;
1860 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST);
1862 /* reset statistics */
1863 memset(&sc->stats, 0, sizeof(struct uea_stats));
1865 /* tell the modem that we want to boot in IDMA mode */
1866 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1867 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1869 /* enter reset mode */
1870 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1872 /* original driver use 200ms, but windows driver use 100ms */
1873 ret = uea_wait(sc, 0, msecs_to_jiffies(100));
1874 if (ret < 0)
1875 return ret;
1877 /* leave reset mode */
1878 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1880 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
1881 /* clear tx and rx mailboxes */
1882 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1883 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1884 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1887 ret = uea_wait(sc, 0, msecs_to_jiffies(1000));
1888 if (ret < 0)
1889 return ret;
1891 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1892 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
1893 E4_MODEMREADY, 1);
1894 else
1895 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
1896 E1_MODEMREADY);
1898 /* demask interrupt */
1899 sc->booting = 0;
1901 /* start loading DSP */
1902 sc->pageno = 0;
1903 sc->ovl = 0;
1904 schedule_work(&sc->task);
1906 /* wait for modem ready CMV */
1907 ret = wait_cmv_ack(sc);
1908 if (ret < 0)
1909 return ret;
1911 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1913 ret = sc->send_cmvs(sc);
1914 if (ret < 0)
1915 return ret;
1917 sc->reset = 0;
1918 uea_leaves(INS_TO_USBDEV(sc));
1919 return ret;
1923 * In case of an error wait 1s before rebooting the modem
1924 * if the modem don't request reboot (-EAGAIN).
1925 * Monitor the modem every 1s.
1928 static int uea_kthread(void *data)
1930 struct uea_softc *sc = data;
1931 int ret = -EAGAIN;
1933 set_freezable();
1934 uea_enters(INS_TO_USBDEV(sc));
1935 while (!kthread_should_stop()) {
1936 if (ret < 0 || sc->reset)
1937 ret = uea_start_reset(sc);
1938 if (!ret)
1939 ret = sc->stat(sc);
1940 if (ret != -EAGAIN)
1941 uea_wait(sc, 0, msecs_to_jiffies(1000));
1942 try_to_freeze();
1944 uea_leaves(INS_TO_USBDEV(sc));
1945 return ret;
1948 /* Load second usb firmware for ADI930 chip */
1949 static int load_XILINX_firmware(struct uea_softc *sc)
1951 const struct firmware *fw_entry;
1952 int ret, size, u, ln;
1953 const u8 *pfw;
1954 u8 value;
1955 char *fw_name = FPGA930_FIRMWARE;
1957 uea_enters(INS_TO_USBDEV(sc));
1959 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1960 if (ret) {
1961 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1962 fw_name);
1963 goto err0;
1966 pfw = fw_entry->data;
1967 size = fw_entry->size;
1968 if (size != 0x577B) {
1969 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1970 fw_name);
1971 ret = -EILSEQ;
1972 goto err1;
1974 for (u = 0; u < size; u += ln) {
1975 ln = min(size - u, 64);
1976 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1977 if (ret < 0) {
1978 uea_err(INS_TO_USBDEV(sc),
1979 "elsa download data failed (%d)\n", ret);
1980 goto err1;
1984 /* finish to send the fpga */
1985 ret = uea_request(sc, 0xe, 1, 0, NULL);
1986 if (ret < 0) {
1987 uea_err(INS_TO_USBDEV(sc),
1988 "elsa download data failed (%d)\n", ret);
1989 goto err1;
1992 /* Tell the modem we finish : de-assert reset */
1993 value = 0;
1994 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1995 if (ret < 0)
1996 uea_err(sc->usb_dev, "elsa de-assert failed with error"
1997 " %d\n", ret);
1999 err1:
2000 release_firmware(fw_entry);
2001 err0:
2002 uea_leaves(INS_TO_USBDEV(sc));
2003 return ret;
2006 /* The modem send us an ack. First with check if it right */
2007 static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
2009 struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;
2010 struct cmv_e1 *cmv = &intr->u.e1.s2.cmv;
2012 uea_enters(INS_TO_USBDEV(sc));
2013 if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE)
2014 goto bad1;
2016 if (cmv->bDirection != E1_MODEMTOHOST)
2017 goto bad1;
2019 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
2020 * the first MEMACCESS cmv. Ignore it...
2022 if (cmv->bFunction != dsc->function) {
2023 if (UEA_CHIP_VERSION(sc) == ADI930
2024 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
2025 cmv->wIndex = cpu_to_le16(dsc->idx);
2026 put_unaligned_le32(dsc->address,
2027 &cmv->dwSymbolicAddress);
2028 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
2029 } else
2030 goto bad2;
2033 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
2034 E1_MODEMREADY)) {
2035 wake_up_cmv_ack(sc);
2036 uea_leaves(INS_TO_USBDEV(sc));
2037 return;
2040 /* in case of MEMACCESS */
2041 if (le16_to_cpu(cmv->wIndex) != dsc->idx ||
2042 get_unaligned_le32(&cmv->dwSymbolicAddress) != dsc->address ||
2043 le16_to_cpu(cmv->wOffsetAddress) != dsc->offset)
2044 goto bad2;
2046 sc->data = get_unaligned_le32(&cmv->dwData);
2047 sc->data = sc->data << 16 | sc->data >> 16;
2049 wake_up_cmv_ack(sc);
2050 uea_leaves(INS_TO_USBDEV(sc));
2051 return;
2053 bad2:
2054 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
2055 "Function : %d, Subfunction : %d\n",
2056 E1_FUNCTION_TYPE(cmv->bFunction),
2057 E1_FUNCTION_SUBTYPE(cmv->bFunction));
2058 uea_leaves(INS_TO_USBDEV(sc));
2059 return;
2061 bad1:
2062 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
2063 "wPreamble %d, bDirection %d\n",
2064 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
2065 uea_leaves(INS_TO_USBDEV(sc));
2068 /* The modem send us an ack. First with check if it right */
2069 static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
2071 struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;
2072 struct cmv_e4 *cmv = &intr->u.e4.s2.cmv;
2074 uea_enters(INS_TO_USBDEV(sc));
2075 uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n",
2076 be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction),
2077 be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
2078 be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1]));
2080 if (be16_to_cpu(cmv->wFunction) != dsc->function)
2081 goto bad2;
2083 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
2084 E4_MODEMREADY, 1)) {
2085 wake_up_cmv_ack(sc);
2086 uea_leaves(INS_TO_USBDEV(sc));
2087 return;
2090 /* in case of MEMACCESS */
2091 if (be16_to_cpu(cmv->wOffset) != dsc->offset ||
2092 be16_to_cpu(cmv->wGroup) != dsc->group ||
2093 be16_to_cpu(cmv->wAddress) != dsc->address)
2094 goto bad2;
2096 sc->data = be32_to_cpu(cmv->dwData[0]);
2097 sc->data1 = be32_to_cpu(cmv->dwData[1]);
2098 wake_up_cmv_ack(sc);
2099 uea_leaves(INS_TO_USBDEV(sc));
2100 return;
2102 bad2:
2103 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
2104 "Function : %d, Subfunction : %d\n",
2105 E4_FUNCTION_TYPE(cmv->wFunction),
2106 E4_FUNCTION_SUBTYPE(cmv->wFunction));
2107 uea_leaves(INS_TO_USBDEV(sc));
2108 return;
2111 static void uea_schedule_load_page_e1(struct uea_softc *sc,
2112 struct intr_pkt *intr)
2114 sc->pageno = intr->e1_bSwapPageNo;
2115 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
2116 schedule_work(&sc->task);
2119 static void uea_schedule_load_page_e4(struct uea_softc *sc,
2120 struct intr_pkt *intr)
2122 sc->pageno = intr->e4_bSwapPageNo;
2123 schedule_work(&sc->task);
2127 * interrupt handler
2129 static void uea_intr(struct urb *urb)
2131 struct uea_softc *sc = urb->context;
2132 struct intr_pkt *intr = urb->transfer_buffer;
2133 int status = urb->status;
2135 uea_enters(INS_TO_USBDEV(sc));
2137 if (unlikely(status < 0)) {
2138 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
2139 status);
2140 return;
2143 /* device-to-host interrupt */
2144 if (intr->bType != 0x08 || sc->booting) {
2145 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
2146 goto resubmit;
2149 switch (le16_to_cpu(intr->wInterrupt)) {
2150 case INT_LOADSWAPPAGE:
2151 sc->schedule_load_page(sc, intr);
2152 break;
2154 case INT_INCOMINGCMV:
2155 sc->dispatch_cmv(sc, intr);
2156 break;
2158 default:
2159 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
2160 le16_to_cpu(intr->wInterrupt));
2163 resubmit:
2164 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
2168 * Start the modem : init the data and start kernel thread
2170 static int uea_boot(struct uea_softc *sc)
2172 int ret, size;
2173 struct intr_pkt *intr;
2175 uea_enters(INS_TO_USBDEV(sc));
2177 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2178 size = E4_INTR_PKT_SIZE;
2179 sc->dispatch_cmv = uea_dispatch_cmv_e4;
2180 sc->schedule_load_page = uea_schedule_load_page_e4;
2181 sc->stat = uea_stat_e4;
2182 sc->send_cmvs = uea_send_cmvs_e4;
2183 INIT_WORK(&sc->task, uea_load_page_e4);
2184 } else {
2185 size = E1_INTR_PKT_SIZE;
2186 sc->dispatch_cmv = uea_dispatch_cmv_e1;
2187 sc->schedule_load_page = uea_schedule_load_page_e1;
2188 sc->stat = uea_stat_e1;
2189 sc->send_cmvs = uea_send_cmvs_e1;
2190 INIT_WORK(&sc->task, uea_load_page_e1);
2193 init_waitqueue_head(&sc->sync_q);
2195 if (UEA_CHIP_VERSION(sc) == ADI930)
2196 load_XILINX_firmware(sc);
2198 intr = kmalloc(size, GFP_KERNEL);
2199 if (!intr) {
2200 uea_err(INS_TO_USBDEV(sc),
2201 "cannot allocate interrupt package\n");
2202 goto err0;
2205 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
2206 if (!sc->urb_int) {
2207 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
2208 goto err1;
2211 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
2212 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
2213 intr, size, uea_intr, sc,
2214 sc->usb_dev->actconfig->interface[0]->altsetting[0].
2215 endpoint[0].desc.bInterval);
2217 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2218 if (ret < 0) {
2219 uea_err(INS_TO_USBDEV(sc),
2220 "urb submition failed with error %d\n", ret);
2221 goto err1;
2224 /* Create worker thread, but don't start it here. Start it after
2225 * all usbatm generic initialization is done.
2227 sc->kthread = kthread_create(uea_kthread, sc, "ueagle-atm");
2228 if (IS_ERR(sc->kthread)) {
2229 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2230 goto err2;
2233 uea_leaves(INS_TO_USBDEV(sc));
2234 return 0;
2236 err2:
2237 usb_kill_urb(sc->urb_int);
2238 err1:
2239 usb_free_urb(sc->urb_int);
2240 sc->urb_int = NULL;
2241 kfree(intr);
2242 err0:
2243 uea_leaves(INS_TO_USBDEV(sc));
2244 return -ENOMEM;
2248 * Stop the modem : kill kernel thread and free data
2250 static void uea_stop(struct uea_softc *sc)
2252 int ret;
2253 uea_enters(INS_TO_USBDEV(sc));
2254 ret = kthread_stop(sc->kthread);
2255 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
2257 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
2259 usb_kill_urb(sc->urb_int);
2260 kfree(sc->urb_int->transfer_buffer);
2261 usb_free_urb(sc->urb_int);
2263 /* flush the work item, when no one can schedule it */
2264 flush_work(&sc->task);
2266 release_firmware(sc->dsp_firm);
2267 uea_leaves(INS_TO_USBDEV(sc));
2270 /* syfs interface */
2271 static struct uea_softc *dev_to_uea(struct device *dev)
2273 struct usb_interface *intf;
2274 struct usbatm_data *usbatm;
2276 intf = to_usb_interface(dev);
2277 if (!intf)
2278 return NULL;
2280 usbatm = usb_get_intfdata(intf);
2281 if (!usbatm)
2282 return NULL;
2284 return usbatm->driver_data;
2287 static ssize_t read_status(struct device *dev, struct device_attribute *attr,
2288 char *buf)
2290 int ret = -ENODEV;
2291 struct uea_softc *sc;
2293 mutex_lock(&uea_mutex);
2294 sc = dev_to_uea(dev);
2295 if (!sc)
2296 goto out;
2297 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
2298 out:
2299 mutex_unlock(&uea_mutex);
2300 return ret;
2303 static ssize_t reboot(struct device *dev, struct device_attribute *attr,
2304 const char *buf, size_t count)
2306 int ret = -ENODEV;
2307 struct uea_softc *sc;
2309 mutex_lock(&uea_mutex);
2310 sc = dev_to_uea(dev);
2311 if (!sc)
2312 goto out;
2313 sc->reset = 1;
2314 ret = count;
2315 out:
2316 mutex_unlock(&uea_mutex);
2317 return ret;
2320 static DEVICE_ATTR(stat_status, S_IWUSR | S_IRUGO, read_status, reboot);
2322 static ssize_t read_human_status(struct device *dev,
2323 struct device_attribute *attr, char *buf)
2325 int ret = -ENODEV;
2326 int modem_state;
2327 struct uea_softc *sc;
2329 mutex_lock(&uea_mutex);
2330 sc = dev_to_uea(dev);
2331 if (!sc)
2332 goto out;
2334 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2335 switch (sc->stats.phy.state) {
2336 case 0x0: /* not yet synchronized */
2337 case 0x1:
2338 case 0x3:
2339 case 0x4:
2340 modem_state = 0;
2341 break;
2342 case 0x5: /* initialization */
2343 case 0x6:
2344 case 0x9:
2345 case 0xa:
2346 modem_state = 1;
2347 break;
2348 case 0x7: /* operational */
2349 modem_state = 2;
2350 break;
2351 case 0x2: /* fail ... */
2352 modem_state = 3;
2353 break;
2354 default: /* unknown */
2355 modem_state = 4;
2356 break;
2358 } else
2359 modem_state = GET_STATUS(sc->stats.phy.state);
2361 switch (modem_state) {
2362 case 0:
2363 ret = sprintf(buf, "Modem is booting\n");
2364 break;
2365 case 1:
2366 ret = sprintf(buf, "Modem is initializing\n");
2367 break;
2368 case 2:
2369 ret = sprintf(buf, "Modem is operational\n");
2370 break;
2371 case 3:
2372 ret = sprintf(buf, "Modem synchronization failed\n");
2373 break;
2374 default:
2375 ret = sprintf(buf, "Modem state is unknown\n");
2376 break;
2378 out:
2379 mutex_unlock(&uea_mutex);
2380 return ret;
2383 static DEVICE_ATTR(stat_human_status, S_IRUGO, read_human_status, NULL);
2385 static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2386 char *buf)
2388 int ret = -ENODEV;
2389 struct uea_softc *sc;
2390 char *delin = "GOOD";
2392 mutex_lock(&uea_mutex);
2393 sc = dev_to_uea(dev);
2394 if (!sc)
2395 goto out;
2397 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2398 if (sc->stats.phy.flags & 0x4000)
2399 delin = "RESET";
2400 else if (sc->stats.phy.flags & 0x0001)
2401 delin = "LOSS";
2402 } else {
2403 if (sc->stats.phy.flags & 0x0C00)
2404 delin = "ERROR";
2405 else if (sc->stats.phy.flags & 0x0030)
2406 delin = "LOSS";
2409 ret = sprintf(buf, "%s\n", delin);
2410 out:
2411 mutex_unlock(&uea_mutex);
2412 return ret;
2415 static DEVICE_ATTR(stat_delin, S_IRUGO, read_delin, NULL);
2417 #define UEA_ATTR(name, reset) \
2419 static ssize_t read_##name(struct device *dev, \
2420 struct device_attribute *attr, char *buf) \
2422 int ret = -ENODEV; \
2423 struct uea_softc *sc; \
2425 mutex_lock(&uea_mutex); \
2426 sc = dev_to_uea(dev); \
2427 if (!sc) \
2428 goto out; \
2429 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2430 if (reset) \
2431 sc->stats.phy.name = 0; \
2432 out: \
2433 mutex_unlock(&uea_mutex); \
2434 return ret; \
2437 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2439 UEA_ATTR(mflags, 1);
2440 UEA_ATTR(vidcpe, 0);
2441 UEA_ATTR(usrate, 0);
2442 UEA_ATTR(dsrate, 0);
2443 UEA_ATTR(usattenuation, 0);
2444 UEA_ATTR(dsattenuation, 0);
2445 UEA_ATTR(usmargin, 0);
2446 UEA_ATTR(dsmargin, 0);
2447 UEA_ATTR(txflow, 0);
2448 UEA_ATTR(rxflow, 0);
2449 UEA_ATTR(uscorr, 0);
2450 UEA_ATTR(dscorr, 0);
2451 UEA_ATTR(usunc, 0);
2452 UEA_ATTR(dsunc, 0);
2453 UEA_ATTR(firmid, 0);
2455 /* Retrieve the device End System Identifier (MAC) */
2457 static int uea_getesi(struct uea_softc *sc, u_char * esi)
2459 unsigned char mac_str[2 * ETH_ALEN + 1];
2460 int i;
2461 if (usb_string
2462 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
2463 sizeof(mac_str)) != 2 * ETH_ALEN)
2464 return 1;
2466 for (i = 0; i < ETH_ALEN; i++)
2467 esi[i] = hex_to_bin(mac_str[2 * i]) * 16 +
2468 hex_to_bin(mac_str[2 * i + 1]);
2470 return 0;
2473 /* ATM stuff */
2474 static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
2476 struct uea_softc *sc = usbatm->driver_data;
2478 return uea_getesi(sc, atm_dev->esi);
2481 static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
2483 struct uea_softc *sc = usbatm->driver_data;
2485 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
2487 return 0;
2491 static int claim_interface(struct usb_device *usb_dev,
2492 struct usbatm_data *usbatm, int ifnum)
2494 int ret;
2495 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
2497 if (!intf) {
2498 uea_err(usb_dev, "interface %d not found\n", ifnum);
2499 return -ENODEV;
2502 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
2503 if (ret != 0)
2504 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
2505 ret);
2506 return ret;
2509 static struct attribute *attrs[] = {
2510 &dev_attr_stat_status.attr,
2511 &dev_attr_stat_mflags.attr,
2512 &dev_attr_stat_human_status.attr,
2513 &dev_attr_stat_delin.attr,
2514 &dev_attr_stat_vidcpe.attr,
2515 &dev_attr_stat_usrate.attr,
2516 &dev_attr_stat_dsrate.attr,
2517 &dev_attr_stat_usattenuation.attr,
2518 &dev_attr_stat_dsattenuation.attr,
2519 &dev_attr_stat_usmargin.attr,
2520 &dev_attr_stat_dsmargin.attr,
2521 &dev_attr_stat_txflow.attr,
2522 &dev_attr_stat_rxflow.attr,
2523 &dev_attr_stat_uscorr.attr,
2524 &dev_attr_stat_dscorr.attr,
2525 &dev_attr_stat_usunc.attr,
2526 &dev_attr_stat_dsunc.attr,
2527 &dev_attr_stat_firmid.attr,
2528 NULL,
2530 static struct attribute_group attr_grp = {
2531 .attrs = attrs,
2534 static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
2535 const struct usb_device_id *id)
2537 struct usb_device *usb = interface_to_usbdev(intf);
2538 struct uea_softc *sc;
2539 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
2540 unsigned int alt;
2542 uea_enters(usb);
2544 /* interface 0 is for firmware/monitoring */
2545 if (ifnum != UEA_INTR_IFACE_NO)
2546 return -ENODEV;
2548 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
2550 /* interface 1 is for outbound traffic */
2551 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
2552 if (ret < 0)
2553 return ret;
2555 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
2556 if (UEA_CHIP_VERSION(id) != ADI930) {
2557 /* interface 2 is for inbound traffic */
2558 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
2559 if (ret < 0)
2560 return ret;
2563 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
2564 if (!sc) {
2565 uea_err(usb, "uea_init: not enough memory !\n");
2566 return -ENOMEM;
2569 sc->usb_dev = usb;
2570 usbatm->driver_data = sc;
2571 sc->usbatm = usbatm;
2572 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
2573 sc->driver_info = id->driver_info;
2575 /* first try to use module parameter */
2576 if (annex[sc->modem_index] == 1)
2577 sc->annex = ANNEXA;
2578 else if (annex[sc->modem_index] == 2)
2579 sc->annex = ANNEXB;
2580 /* try to autodetect annex */
2581 else if (sc->driver_info & AUTO_ANNEX_A)
2582 sc->annex = ANNEXA;
2583 else if (sc->driver_info & AUTO_ANNEX_B)
2584 sc->annex = ANNEXB;
2585 else
2586 sc->annex = (le16_to_cpu
2587 (sc->usb_dev->descriptor.bcdDevice) & 0x80) ? ANNEXB : ANNEXA;
2589 alt = altsetting[sc->modem_index];
2590 /* ADI930 don't support iso */
2591 if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) {
2592 if (alt <= 8 &&
2593 usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) {
2594 uea_dbg(usb, "set alternate %u for 2 interface\n", alt);
2595 uea_info(usb, "using iso mode\n");
2596 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
2597 } else {
2598 uea_err(usb, "setting alternate %u failed for "
2599 "2 interface, using bulk mode\n", alt);
2603 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
2604 if (ret < 0)
2605 goto error;
2607 ret = uea_boot(sc);
2608 if (ret < 0)
2609 goto error_rm_grp;
2611 return 0;
2613 error_rm_grp:
2614 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2615 error:
2616 kfree(sc);
2617 return ret;
2620 static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
2622 struct uea_softc *sc = usbatm->driver_data;
2624 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
2625 uea_stop(sc);
2626 kfree(sc);
2629 static struct usbatm_driver uea_usbatm_driver = {
2630 .driver_name = "ueagle-atm",
2631 .bind = uea_bind,
2632 .atm_start = uea_atm_open,
2633 .unbind = uea_unbind,
2634 .heavy_init = uea_heavy,
2635 .bulk_in = UEA_BULK_DATA_PIPE,
2636 .bulk_out = UEA_BULK_DATA_PIPE,
2637 .isoc_in = UEA_ISO_DATA_PIPE,
2640 static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2642 struct usb_device *usb = interface_to_usbdev(intf);
2643 int ret;
2645 uea_enters(usb);
2646 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2647 le16_to_cpu(usb->descriptor.idVendor),
2648 le16_to_cpu(usb->descriptor.idProduct),
2649 le16_to_cpu(usb->descriptor.bcdDevice),
2650 chip_name[UEA_CHIP_VERSION(id)]);
2652 usb_reset_device(usb);
2654 if (UEA_IS_PREFIRM(id))
2655 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2657 ret = usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2658 if (ret == 0) {
2659 struct usbatm_data *usbatm = usb_get_intfdata(intf);
2660 struct uea_softc *sc = usbatm->driver_data;
2662 /* Ensure carrier is initialized to off as early as possible */
2663 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST);
2665 /* Only start the worker thread when all init is done */
2666 wake_up_process(sc->kthread);
2669 return ret;
2672 static void uea_disconnect(struct usb_interface *intf)
2674 struct usb_device *usb = interface_to_usbdev(intf);
2675 int ifnum = intf->altsetting->desc.bInterfaceNumber;
2676 uea_enters(usb);
2678 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2679 * Pre-firmware device has one interface
2681 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
2682 mutex_lock(&uea_mutex);
2683 usbatm_usb_disconnect(intf);
2684 mutex_unlock(&uea_mutex);
2685 uea_info(usb, "ADSL device removed\n");
2688 uea_leaves(usb);
2692 * List of supported VID/PID
2694 static const struct usb_device_id uea_ids[] = {
2695 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM),
2696 .driver_info = ADI930 | PREFIRM},
2697 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM),
2698 .driver_info = ADI930 | PSTFIRM},
2699 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM),
2700 .driver_info = EAGLE_I | PREFIRM},
2701 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM),
2702 .driver_info = EAGLE_I | PSTFIRM},
2703 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM),
2704 .driver_info = EAGLE_II | PREFIRM},
2705 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM),
2706 .driver_info = EAGLE_II | PSTFIRM},
2707 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM),
2708 .driver_info = EAGLE_II | PREFIRM},
2709 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM),
2710 .driver_info = EAGLE_II | PSTFIRM},
2711 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM),
2712 .driver_info = EAGLE_III | PREFIRM},
2713 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM),
2714 .driver_info = EAGLE_III | PSTFIRM},
2715 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM),
2716 .driver_info = EAGLE_IV | PREFIRM},
2717 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM),
2718 .driver_info = EAGLE_IV | PSTFIRM},
2719 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM),
2720 .driver_info = EAGLE_I | PREFIRM},
2721 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM),
2722 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2723 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM),
2724 .driver_info = EAGLE_I | PREFIRM},
2725 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM),
2726 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2727 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM),
2728 .driver_info = EAGLE_II | PREFIRM},
2729 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM),
2730 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A},
2731 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM),
2732 .driver_info = EAGLE_II | PREFIRM},
2733 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM),
2734 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B},
2735 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM),
2736 .driver_info = ADI930 | PREFIRM},
2737 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM),
2738 .driver_info = ADI930 | PSTFIRM},
2739 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM),
2740 .driver_info = ADI930 | PREFIRM},
2741 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM),
2742 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A},
2743 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM),
2744 .driver_info = ADI930 | PREFIRM},
2745 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM),
2746 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B},
2747 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM),
2748 .driver_info = EAGLE_I | PREFIRM},
2749 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM),
2750 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2751 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM),
2752 .driver_info = EAGLE_I | PREFIRM},
2753 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM),
2754 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2755 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),
2756 .driver_info = EAGLE_I | PREFIRM},
2757 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),
2758 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2759 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),
2760 .driver_info = EAGLE_I | PREFIRM},
2761 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),
2762 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2767 * USB driver descriptor
2769 static struct usb_driver uea_driver = {
2770 .name = "ueagle-atm",
2771 .id_table = uea_ids,
2772 .probe = uea_probe,
2773 .disconnect = uea_disconnect,
2776 MODULE_DEVICE_TABLE(usb, uea_ids);
2778 module_usb_driver(uea_driver);
2780 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2781 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2782 MODULE_LICENSE("Dual BSD/GPL");
2783 MODULE_FIRMWARE(EAGLE_FIRMWARE);
2784 MODULE_FIRMWARE(ADI930_FIRMWARE);
2785 MODULE_FIRMWARE(EAGLE_I_FIRMWARE);
2786 MODULE_FIRMWARE(EAGLE_II_FIRMWARE);
2787 MODULE_FIRMWARE(EAGLE_III_FIRMWARE);
2788 MODULE_FIRMWARE(EAGLE_IV_FIRMWARE);
2789 MODULE_FIRMWARE(DSP4I_FIRMWARE);
2790 MODULE_FIRMWARE(DSP4P_FIRMWARE);
2791 MODULE_FIRMWARE(DSP9I_FIRMWARE);
2792 MODULE_FIRMWARE(DSP9P_FIRMWARE);
2793 MODULE_FIRMWARE(DSPEI_FIRMWARE);
2794 MODULE_FIRMWARE(DSPEP_FIRMWARE);
2795 MODULE_FIRMWARE(FPGA930_FIRMWARE);
2796 MODULE_FIRMWARE(CMV4P_FIRMWARE);
2797 MODULE_FIRMWARE(CMV4PV2_FIRMWARE);
2798 MODULE_FIRMWARE(CMV4I_FIRMWARE);
2799 MODULE_FIRMWARE(CMV4IV2_FIRMWARE);
2800 MODULE_FIRMWARE(CMV9P_FIRMWARE);
2801 MODULE_FIRMWARE(CMV9PV2_FIRMWARE);
2802 MODULE_FIRMWARE(CMV9I_FIRMWARE);
2803 MODULE_FIRMWARE(CMV9IV2_FIRMWARE);
2804 MODULE_FIRMWARE(CMVEP_FIRMWARE);
2805 MODULE_FIRMWARE(CMVEPV2_FIRMWARE);
2806 MODULE_FIRMWARE(CMVEI_FIRMWARE);
2807 MODULE_FIRMWARE(CMVEIV2_FIRMWARE);