blob: ebae94480140e01322ba9176ac808f71296567b1 [file] [log] [blame]
matthieu castetb72458a2005-11-07 23:27:13 +01001/*-
2 * Copyright (c) 2003, 2004
3 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
4 *
Stanislaw Gruszka0eb02262007-08-20 23:21:19 +02005 * Copyright (c) 2005-2007 Matthieu Castet <castet.matthieu@free.fr>
6 * Copyright (c) 2005-2007 Stanislaw Gruszka <stf_xl@wp.pl>
matthieu castetb72458a2005-11-07 23:27:13 +01007 *
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:
13 *
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.
23 *
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.
35 *
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.
41 *
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.
46 *
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.
50 *
51 *
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.
54 *
55 * The rest of the code was was rewritten from scratch.
56 */
57
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>
Randy Dunlap5371f802007-02-16 01:47:33 -080065#include <linux/sched.h>
matthieu castetb72458a2005-11-07 23:27:13 +010066#include <linux/kthread.h>
Arjan van de Venab3c81f2006-01-13 15:52:55 +010067#include <linux/mutex.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080068#include <linux/freezer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090069#include <linux/slab.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080070
matthieu castetb72458a2005-11-07 23:27:13 +010071#include <asm/unaligned.h>
72
73#include "usbatm.h"
74
matthieu casteta7a0c9c2006-10-03 21:44:11 +020075#define EAGLEUSBVERSION "ueagle 1.4"
matthieu castetb72458a2005-11-07 23:27:13 +010076
77
78/*
79 * Debug macros
80 */
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, \
Harvey Harrison441b62c2008-03-03 16:08:34 -080086 __func__, ##args); \
matthieu casteta7a0c9c2006-10-03 21:44:11 +020087 } while (0)
matthieu castetb72458a2005-11-07 23:27:13 +010088
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); \
matthieu casteta7a0c9c2006-10-03 21:44:11 +020094 } while (0)
matthieu castetb72458a2005-11-07 23:27:13 +010095
96#define uea_enters(usb_dev) \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +020097 uea_vdbg(usb_dev, "entering %s\n" , __func__)
matthieu castetb72458a2005-11-07 23:27:13 +010098
99#define uea_leaves(usb_dev) \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200100 uea_vdbg(usb_dev, "leaving %s\n" , __func__)
matthieu castetb72458a2005-11-07 23:27:13 +0100101
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200102#define uea_err(usb_dev, format, args...) \
103 dev_err(&(usb_dev)->dev , "[UEAGLE-ATM] " format , ##args)
matthieu castetb72458a2005-11-07 23:27:13 +0100104
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200105#define uea_warn(usb_dev, format, args...) \
106 dev_warn(&(usb_dev)->dev , "[Ueagle-atm] " format, ##args)
matthieu castetb72458a2005-11-07 23:27:13 +0100107
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200108#define uea_info(usb_dev, format, args...) \
109 dev_info(&(usb_dev)->dev , "[ueagle-atm] " format, ##args)
matthieu castetb72458a2005-11-07 23:27:13 +0100110
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200111struct intr_pkt;
112
113/* cmv's from firmware */
114struct uea_cmvs_v1 {
matthieu castetb72458a2005-11-07 23:27:13 +0100115 u32 address;
116 u16 offset;
117 u32 data;
118} __attribute__ ((packed));
119
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200120struct uea_cmvs_v2 {
121 u32 group;
122 u32 address;
123 u32 offset;
124 u32 data;
125} __attribute__ ((packed));
126
127/* information about currently processed cmv */
128struct cmv_dsc_e1 {
129 u8 function;
130 u16 idx;
131 u32 address;
132 u16 offset;
133};
134
135struct cmv_dsc_e4 {
136 u16 function;
137 u16 offset;
138 u16 address;
139 u16 group;
140};
141
142union cmv_dsc {
143 struct cmv_dsc_e1 e1;
144 struct cmv_dsc_e4 e4;
145};
146
matthieu castetb72458a2005-11-07 23:27:13 +0100147struct uea_softc {
148 struct usb_device *usb_dev;
149 struct usbatm_data *usbatm;
150
151 int modem_index;
152 unsigned int driver_info;
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200153 int annex;
154#define ANNEXA 0
155#define ANNEXB 1
matthieu castetb72458a2005-11-07 23:27:13 +0100156
157 int booting;
158 int reset;
159
160 wait_queue_head_t sync_q;
161
162 struct task_struct *kthread;
163 u32 data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200164 u32 data1;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200165
matthieu castetb72458a2005-11-07 23:27:13 +0100166 int cmv_ack;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200167 union cmv_dsc cmv_dsc;
matthieu castetb72458a2005-11-07 23:27:13 +0100168
169 struct work_struct task;
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +0200170 struct workqueue_struct *work_q;
matthieu castetb72458a2005-11-07 23:27:13 +0100171 u16 pageno;
172 u16 ovl;
173
174 const struct firmware *dsp_firm;
175 struct urb *urb_int;
176
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200177 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 *);
matthieu castetb72458a2005-11-07 23:27:13 +0100181
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;
205};
206
207/*
208 * Elsa IDs
209 */
210#define ELSA_VID 0x05CC
211#define ELSA_PID_PSTFIRM 0x3350
212#define ELSA_PID_PREFIRM 0x3351
213
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200214#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
218
matthieu castetb72458a2005-11-07 23:27:13 +0100219/*
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200220 * Devolo IDs : pots if (pid & 0x10)
matthieu castetb72458a2005-11-07 23:27:13 +0100221 */
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200222#define DEVOLO_VID 0x1039
223#define DEVOLO_EAGLE_I_A_PID_PSTFIRM 0x2110
224#define DEVOLO_EAGLE_I_A_PID_PREFIRM 0x2111
225
226#define DEVOLO_EAGLE_I_B_PID_PSTFIRM 0x2100
227#define DEVOLO_EAGLE_I_B_PID_PREFIRM 0x2101
228
229#define DEVOLO_EAGLE_II_A_PID_PSTFIRM 0x2130
230#define DEVOLO_EAGLE_II_A_PID_PREFIRM 0x2131
231
232#define DEVOLO_EAGLE_II_B_PID_PSTFIRM 0x2120
233#define DEVOLO_EAGLE_II_B_PID_PREFIRM 0x2121
234
235/*
236 * Reference design USB IDs
237 */
238#define ANALOG_VID 0x1110
239#define ADI930_PID_PREFIRM 0x9001
240#define ADI930_PID_PSTFIRM 0x9000
241
matthieu castetb72458a2005-11-07 23:27:13 +0100242#define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
243#define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
244
245#define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
246#define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
247
248#define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
249#define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
250
matthieu castetb72458a2005-11-07 23:27:13 +0100251#define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
252#define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
253
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200254#define EAGLE_IV_PID_PREFIRM 0x9042 /* Eagle IV */
255#define EAGLE_IV_PID_PSTFIRM 0x9041 /* Eagle IV */
256
matthieu castetb72458a2005-11-07 23:27:13 +0100257/*
258 * USR USB IDs
259 */
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
269
270#define PREFIRM 0
271#define PSTFIRM (1<<7)
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200272#define AUTO_ANNEX_A (1<<8)
273#define AUTO_ANNEX_B (1<<9)
274
matthieu castetb72458a2005-11-07 23:27:13 +0100275enum {
276 ADI930 = 0,
277 EAGLE_I,
278 EAGLE_II,
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200279 EAGLE_III,
280 EAGLE_IV
matthieu castetb72458a2005-11-07 23:27:13 +0100281};
282
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)
288
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200289#define IS_ISDN(x) \
290 ((x)->annex & ANNEXB)
matthieu castetb72458a2005-11-07 23:27:13 +0100291
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200292#define INS_TO_USBDEV(ins) (ins->usb_dev)
matthieu castetb72458a2005-11-07 23:27:13 +0100293
294#define GET_STATUS(data) \
295 ((data >> 8) & 0xf)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200296
matthieu castetb72458a2005-11-07 23:27:13 +0100297#define IS_OPERATIONAL(sc) \
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200298 ((UEA_CHIP_VERSION(sc) != EAGLE_IV) ? \
299 (GET_STATUS(sc->stats.phy.state) == 2) : \
300 (sc->stats.phy.state == 7))
matthieu castetb72458a2005-11-07 23:27:13 +0100301
302/*
303 * Set of macros to handle unaligned data in the firmware blob.
304 * The FW_GET_BYTE() macro is provided only for consistency.
305 */
306
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200307#define FW_GET_BYTE(p) (*((__u8 *) (p)))
matthieu castetb72458a2005-11-07 23:27:13 +0100308
309#define FW_DIR "ueagle-atm/"
Samuel Ortizade901d2009-05-27 00:49:32 +0200310#define UEA_FW_NAME_MAX 30
matthieu castetb72458a2005-11-07 23:27:13 +0100311#define NB_MODEM 4
312
313#define BULK_TIMEOUT 300
314#define CTRL_TIMEOUT 1000
315
matthieu castet22fcceb2006-04-02 18:44:20 +0200316#define ACK_TIMEOUT msecs_to_jiffies(3000)
matthieu castetb72458a2005-11-07 23:27:13 +0100317
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200318#define UEA_INTR_IFACE_NO 0
matthieu castetb72458a2005-11-07 23:27:13 +0100319#define UEA_US_IFACE_NO 1
320#define UEA_DS_IFACE_NO 2
321
322#define FASTEST_ISO_INTF 8
323
324#define UEA_BULK_DATA_PIPE 0x02
325#define UEA_IDMA_PIPE 0x04
326#define UEA_INTR_PIPE 0x04
327#define UEA_ISO_DATA_PIPE 0x08
328
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200329#define UEA_E1_SET_BLOCK 0x0001
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200330#define UEA_E4_SET_BLOCK 0x002c
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200331#define UEA_SET_MODE 0x0003
matthieu castetb72458a2005-11-07 23:27:13 +0100332#define UEA_SET_2183_DATA 0x0004
333#define UEA_SET_TIMEOUT 0x0011
334
335#define UEA_LOOPBACK_OFF 0x0002
336#define UEA_LOOPBACK_ON 0x0003
337#define UEA_BOOT_IDMA 0x0006
338#define UEA_START_RESET 0x0007
339#define UEA_END_RESET 0x0008
340
341#define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
342#define UEA_MPTX_START (0x3fce | 0x4000)
343#define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
344#define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
345
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200346/* block information in eagle4 dsp firmware */
347struct block_index {
348 __le32 PageOffset;
349 __le32 NotLastBlock;
350 __le32 dummy;
351 __le32 PageSize;
352 __le32 PageAddress;
353 __le16 dummy1;
354 __le16 PageNumber;
355} __attribute__ ((packed));
356
357#define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
358#define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
359
360#define E4_L1_STRING_HEADER 0x10
361#define E4_MAX_PAGE_NUMBER 0x58
362#define E4_NO_SWAPPAGE_HEADERS 0x31
363
364/* l1_code is eagle4 dsp firmware format */
365struct l1_code {
366 u8 string_header[E4_L1_STRING_HEADER];
367 u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER];
368 struct block_index page_header[E4_NO_SWAPPAGE_HEADERS];
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200369 u8 code[0];
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200370} __attribute__ ((packed));
371
372/* structures describing a block within a DSP page */
373struct block_info_e1 {
matthieu castetb72458a2005-11-07 23:27:13 +0100374 __le16 wHdr;
matthieu castetb72458a2005-11-07 23:27:13 +0100375 __le16 wAddress;
376 __le16 wSize;
377 __le16 wOvlOffset;
378 __le16 wOvl; /* overlay */
379 __le16 wLast;
380} __attribute__ ((packed));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200381#define E1_BLOCK_INFO_SIZE 12
matthieu castetb72458a2005-11-07 23:27:13 +0100382
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200383struct block_info_e4 {
384 __be16 wHdr;
385 __u8 bBootPage;
386 __u8 bPageNumber;
387 __be32 dwSize;
388 __be32 dwAddress;
389 __be16 wReserved;
390} __attribute__ ((packed));
391#define E4_BLOCK_INFO_SIZE 14
matthieu castetb72458a2005-11-07 23:27:13 +0100392
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200393#define UEA_BIHDR 0xabcd
394#define UEA_RESERVED 0xffff
395
396/* constants describing cmv type */
397#define E1_PREAMBLE 0x535c
398#define E1_MODEMTOHOST 0x01
399#define E1_HOSTTOMODEM 0x10
400
401#define E1_MEMACCESS 0x1
402#define E1_ADSLDIRECTIVE 0x7
403#define E1_FUNCTION_TYPE(f) ((f) >> 4)
404#define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f)
405
406#define E4_MEMACCESS 0
407#define E4_ADSLDIRECTIVE 0xf
408#define E4_FUNCTION_TYPE(f) ((f) >> 8)
409#define E4_FUNCTION_SIZE(f) ((f) & 0x0f)
410#define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f)
411
matthieu castetb72458a2005-11-07 23:27:13 +0100412/* for MEMACCESS */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200413#define E1_REQUESTREAD 0x0
414#define E1_REQUESTWRITE 0x1
415#define E1_REPLYREAD 0x2
416#define E1_REPLYWRITE 0x3
matthieu castetb72458a2005-11-07 23:27:13 +0100417
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200418#define E4_REQUESTREAD 0x0
419#define E4_REQUESTWRITE 0x4
420#define E4_REPLYREAD (E4_REQUESTREAD | 1)
421#define E4_REPLYWRITE (E4_REQUESTWRITE | 1)
422
423/* for ADSLDIRECTIVE */
424#define E1_KERNELREADY 0x0
425#define E1_MODEMREADY 0x1
426
427#define E4_KERNELREADY 0x0
428#define E4_MODEMREADY 0x1
429
430#define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200431#define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | \
432 ((st) & 0xf) << 4 | ((s) & 0xf))
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200433
434#define E1_MAKESA(a, b, c, d) \
matthieu castetb72458a2005-11-07 23:27:13 +0100435 (((c) & 0xff) << 24 | \
436 ((d) & 0xff) << 16 | \
437 ((a) & 0xff) << 8 | \
438 ((b) & 0xff))
439
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200440#define E1_GETSA1(a) ((a >> 8) & 0xff)
441#define E1_GETSA2(a) (a & 0xff)
442#define E1_GETSA3(a) ((a >> 24) & 0xff)
443#define E1_GETSA4(a) ((a >> 16) & 0xff)
444
445#define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L')
446#define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G')
447#define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O')
448#define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N')
449#define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E')
450#define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T')
451
452#define E4_SA_CNTL 1
453#define E4_SA_STAT 2
454#define E4_SA_INFO 3
455#define E4_SA_TEST 4
456#define E4_SA_OPTN 5
457#define E4_SA_RATE 6
458#define E4_SA_DIAG 7
459#define E4_SA_CNFG 8
460
461/* structures representing a CMV (Configuration and Management Variable) */
462struct cmv_e1 {
463 __le16 wPreamble;
464 __u8 bDirection;
465 __u8 bFunction;
466 __le16 wIndex;
467 __le32 dwSymbolicAddress;
matthieu castetb72458a2005-11-07 23:27:13 +0100468 __le16 wOffsetAddress;
469 __le32 dwData;
470} __attribute__ ((packed));
matthieu castetb72458a2005-11-07 23:27:13 +0100471
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200472struct cmv_e4 {
473 __be16 wGroup;
474 __be16 wFunction;
475 __be16 wOffset;
476 __be16 wAddress;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200477 __be32 dwData[6];
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200478} __attribute__ ((packed));
479
480/* structures representing swap information */
481struct swap_info_e1 {
matthieu castetb72458a2005-11-07 23:27:13 +0100482 __u8 bSwapPageNo;
483 __u8 bOvl; /* overlay */
484} __attribute__ ((packed));
485
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200486struct swap_info_e4 {
487 __u8 bSwapPageNo;
488} __attribute__ ((packed));
489
490/* structures representing interrupt data */
491#define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
492#define e1_bOvl u.e1.s1.swapinfo.bOvl
493#define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo
494
495#define INT_LOADSWAPPAGE 0x0001
496#define INT_INCOMINGCMV 0x0002
497
498union intr_data_e1 {
499 struct {
500 struct swap_info_e1 swapinfo;
501 __le16 wDataSize;
502 } __attribute__ ((packed)) s1;
503 struct {
504 struct cmv_e1 cmv;
505 __le16 wDataSize;
506 } __attribute__ ((packed)) s2;
507} __attribute__ ((packed));
508
509union intr_data_e4 {
510 struct {
511 struct swap_info_e4 swapinfo;
512 __le16 wDataSize;
513 } __attribute__ ((packed)) s1;
514 struct {
515 struct cmv_e4 cmv;
516 __le16 wDataSize;
517 } __attribute__ ((packed)) s2;
518} __attribute__ ((packed));
519
matthieu castetb72458a2005-11-07 23:27:13 +0100520struct intr_pkt {
521 __u8 bType;
522 __u8 bNotification;
523 __le16 wValue;
524 __le16 wIndex;
525 __le16 wLength;
526 __le16 wInterrupt;
matthieu castetb72458a2005-11-07 23:27:13 +0100527 union {
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200528 union intr_data_e1 e1;
529 union intr_data_e4 e4;
530 } u;
matthieu castetb72458a2005-11-07 23:27:13 +0100531} __attribute__ ((packed));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200532
533#define E1_INTR_PKT_SIZE 28
534#define E4_INTR_PKT_SIZE 64
matthieu castetb72458a2005-11-07 23:27:13 +0100535
536static struct usb_driver uea_driver;
Arjan van de Venab3c81f2006-01-13 15:52:55 +0100537static DEFINE_MUTEX(uea_mutex);
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200538static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III",
539 "Eagle IV"};
matthieu castetb72458a2005-11-07 23:27:13 +0100540
541static int modem_index;
542static unsigned int debug;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200543static unsigned int altsetting[NB_MODEM] = {
544 [0 ... (NB_MODEM - 1)] = FASTEST_ISO_INTF};
matthieu castetb72458a2005-11-07 23:27:13 +0100545static int sync_wait[NB_MODEM];
546static char *cmv_file[NB_MODEM];
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200547static int annex[NB_MODEM];
matthieu castetb72458a2005-11-07 23:27:13 +0100548
549module_param(debug, uint, 0644);
550MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
Stanislaw Gruszka503add42007-08-20 23:21:06 +0200551module_param_array(altsetting, uint, NULL, 0644);
552MODULE_PARM_DESC(altsetting, "alternate setting for incoming traffic: 0=bulk, "
553 "1=isoc slowest, ... , 8=isoc fastest (default)");
matthieu castetb72458a2005-11-07 23:27:13 +0100554module_param_array(sync_wait, bool, NULL, 0644);
555MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
556module_param_array(cmv_file, charp, NULL, 0644);
557MODULE_PARM_DESC(cmv_file,
558 "file name with configuration and management variables");
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200559module_param_array(annex, uint, NULL, 0644);
560MODULE_PARM_DESC(annex,
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200561 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
matthieu castetb72458a2005-11-07 23:27:13 +0100562
Stanislaw Gruszka337427f2007-08-20 23:21:14 +0200563#define uea_wait(sc, cond, timeo) \
564({ \
565 int _r = wait_event_interruptible_timeout(sc->sync_q, \
566 (cond) || kthread_should_stop(), timeo); \
567 if (kthread_should_stop()) \
568 _r = -ENODEV; \
569 _r; \
570})
571
matthieu castetb72458a2005-11-07 23:27:13 +0100572#define UPDATE_ATM_STAT(type, val) \
573 do { \
574 if (sc->usbatm->atm_dev) \
575 sc->usbatm->atm_dev->type = val; \
576 } while (0)
577
Karl Hiramotocc7b86c2010-07-08 20:55:38 +0000578#define UPDATE_ATM_SIGNAL(val) \
579 do { \
580 if (sc->usbatm->atm_dev) \
581 atm_dev_signal_change(sc->usbatm->atm_dev, val); \
582 } while (0)
583
584
matthieu castetb72458a2005-11-07 23:27:13 +0100585/* Firmware loading */
586#define LOAD_INTERNAL 0xA0
587#define F8051_USBCS 0x7f92
588
589/**
590 * uea_send_modem_cmd - Send a command for pre-firmware devices.
591 */
592static int uea_send_modem_cmd(struct usb_device *usb,
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100593 u16 addr, u16 size, const u8 *buff)
matthieu castetb72458a2005-11-07 23:27:13 +0100594{
595 int ret = -ENOMEM;
596 u8 *xfer_buff;
597
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +0200598 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +0100599 if (xfer_buff) {
matthieu castetb72458a2005-11-07 23:27:13 +0100600 ret = usb_control_msg(usb,
601 usb_sndctrlpipe(usb, 0),
602 LOAD_INTERNAL,
603 USB_DIR_OUT | USB_TYPE_VENDOR |
604 USB_RECIP_DEVICE, addr, 0, xfer_buff,
605 size, CTRL_TIMEOUT);
606 kfree(xfer_buff);
607 }
608
609 if (ret < 0)
610 return ret;
611
612 return (ret == size) ? 0 : -EIO;
613}
614
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200615static void uea_upload_pre_firmware(const struct firmware *fw_entry,
616 void *context)
matthieu castetb72458a2005-11-07 23:27:13 +0100617{
618 struct usb_device *usb = context;
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100619 const u8 *pfw;
620 u8 value;
matthieu castetb72458a2005-11-07 23:27:13 +0100621 u32 crc = 0;
622 int ret, size;
623
624 uea_enters(usb);
625 if (!fw_entry) {
626 uea_err(usb, "firmware is not available\n");
627 goto err;
628 }
629
630 pfw = fw_entry->data;
631 size = fw_entry->size;
matthieu castet8d7802e2005-11-08 00:02:30 +0100632 if (size < 4)
633 goto err_fw_corrupted;
matthieu castetb72458a2005-11-07 23:27:13 +0100634
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700635 crc = get_unaligned_le32(pfw);
matthieu castetb72458a2005-11-07 23:27:13 +0100636 pfw += 4;
637 size -= 4;
matthieu castet8d7802e2005-11-08 00:02:30 +0100638 if (crc32_be(0, pfw, size) != crc)
639 goto err_fw_corrupted;
matthieu castetb72458a2005-11-07 23:27:13 +0100640
641 /*
Nick Andrew877d0312009-01-26 11:06:57 +0100642 * Start to upload firmware : send reset
matthieu castetb72458a2005-11-07 23:27:13 +0100643 */
644 value = 1;
645 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
646
647 if (ret < 0) {
648 uea_err(usb, "modem reset failed with error %d\n", ret);
649 goto err;
650 }
651
matthieu castet8d7802e2005-11-08 00:02:30 +0100652 while (size > 3) {
matthieu castetb72458a2005-11-07 23:27:13 +0100653 u8 len = FW_GET_BYTE(pfw);
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700654 u16 add = get_unaligned_le16(pfw + 1);
matthieu castet8d7802e2005-11-08 00:02:30 +0100655
656 size -= len + 3;
657 if (size < 0)
658 goto err_fw_corrupted;
659
matthieu castetb72458a2005-11-07 23:27:13 +0100660 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
661 if (ret < 0) {
662 uea_err(usb, "uploading firmware data failed "
663 "with error %d\n", ret);
664 goto err;
665 }
666 pfw += len + 3;
matthieu castetb72458a2005-11-07 23:27:13 +0100667 }
668
matthieu castet8d7802e2005-11-08 00:02:30 +0100669 if (size != 0)
670 goto err_fw_corrupted;
671
matthieu castetb72458a2005-11-07 23:27:13 +0100672 /*
673 * Tell the modem we finish : de-assert reset
674 */
675 value = 0;
676 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
677 if (ret < 0)
678 uea_err(usb, "modem de-assert failed with error %d\n", ret);
679 else
680 uea_info(usb, "firmware uploaded\n");
681
Johannes Berg9ebfbd42009-10-29 12:36:02 +0100682 goto err;
matthieu castet8d7802e2005-11-08 00:02:30 +0100683
684err_fw_corrupted:
685 uea_err(usb, "firmware is corrupted\n");
matthieu castetb72458a2005-11-07 23:27:13 +0100686err:
Johannes Berg9ebfbd42009-10-29 12:36:02 +0100687 release_firmware(fw_entry);
matthieu castetb72458a2005-11-07 23:27:13 +0100688 uea_leaves(usb);
689}
690
691/**
692 * uea_load_firmware - Load usb firmware for pre-firmware devices.
693 */
694static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
695{
696 int ret;
697 char *fw_name = FW_DIR "eagle.fw";
698
699 uea_enters(usb);
700 uea_info(usb, "pre-firmware device, uploading firmware\n");
701
702 switch (ver) {
703 case ADI930:
704 fw_name = FW_DIR "adi930.fw";
705 break;
706 case EAGLE_I:
707 fw_name = FW_DIR "eagleI.fw";
708 break;
709 case EAGLE_II:
710 fw_name = FW_DIR "eagleII.fw";
711 break;
712 case EAGLE_III:
713 fw_name = FW_DIR "eagleIII.fw";
714 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200715 case EAGLE_IV:
716 fw_name = FW_DIR "eagleIV.fw";
717 break;
matthieu castetb72458a2005-11-07 23:27:13 +0100718 }
719
Johannes Berg9ebfbd42009-10-29 12:36:02 +0100720 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev,
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200721 GFP_KERNEL, usb,
722 uea_upload_pre_firmware);
matthieu castetb72458a2005-11-07 23:27:13 +0100723 if (ret)
724 uea_err(usb, "firmware %s is not available\n", fw_name);
725 else
726 uea_info(usb, "loading firmware %s\n", fw_name);
727
728 uea_leaves(usb);
729 return ret;
730}
731
732/* modem management : dsp firmware, send/read CMV, monitoring statistic
733 */
734
735/*
736 * Make sure that the DSP code provided is safe to use.
737 */
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100738static int check_dsp_e1(const u8 *dsp, unsigned int len)
matthieu castetb72458a2005-11-07 23:27:13 +0100739{
740 u8 pagecount, blockcount;
741 u16 blocksize;
742 u32 pageoffset;
743 unsigned int i, j, p, pp;
744
matthieu castetb72458a2005-11-07 23:27:13 +0100745 pagecount = FW_GET_BYTE(dsp);
746 p = 1;
747
748 /* enough space for page offsets? */
749 if (p + 4 * pagecount > len)
750 return 1;
751
752 for (i = 0; i < pagecount; i++) {
753
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700754 pageoffset = get_unaligned_le32(dsp + p);
matthieu castetb72458a2005-11-07 23:27:13 +0100755 p += 4;
756
757 if (pageoffset == 0)
758 continue;
759
760 /* enough space for blockcount? */
761 if (pageoffset >= len)
762 return 1;
763
764 pp = pageoffset;
765 blockcount = FW_GET_BYTE(dsp + pp);
766 pp += 1;
767
768 for (j = 0; j < blockcount; j++) {
769
770 /* enough space for block header? */
771 if (pp + 4 > len)
772 return 1;
773
774 pp += 2; /* skip blockaddr */
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700775 blocksize = get_unaligned_le16(dsp + pp);
matthieu castetb72458a2005-11-07 23:27:13 +0100776 pp += 2;
777
778 /* enough space for block data? */
779 if (pp + blocksize > len)
780 return 1;
781
782 pp += blocksize;
783 }
784 }
785
786 return 0;
787}
788
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100789static int check_dsp_e4(const u8 *dsp, int len)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200790{
791 int i;
792 struct l1_code *p = (struct l1_code *) dsp;
793 unsigned int sum = p->code - dsp;
794
795 if (len < sum)
796 return 1;
797
798 if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 &&
799 strcmp("STRATIPHY ANEXB", p->string_header) != 0)
800 return 1;
801
802 for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) {
803 struct block_index *blockidx;
804 u8 blockno = p->page_number_to_block_index[i];
805 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
806 continue;
807
808 do {
809 u64 l;
810
811 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
812 return 1;
813
814 blockidx = &p->page_header[blockno++];
815 if ((u8 *)(blockidx + 1) - dsp >= len)
816 return 1;
817
818 if (le16_to_cpu(blockidx->PageNumber) != i)
819 return 1;
820
821 l = E4_PAGE_BYTES(blockidx->PageSize);
822 sum += l;
823 l += le32_to_cpu(blockidx->PageOffset);
824 if (l > len)
825 return 1;
826
827 /* zero is zero regardless endianes */
828 } while (blockidx->NotLastBlock);
829 }
830
831 return (sum == len) ? 0 : 1;
832}
833
matthieu castetb72458a2005-11-07 23:27:13 +0100834/*
835 * send data to the idma pipe
836 * */
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100837static int uea_idma_write(struct uea_softc *sc, const void *data, u32 size)
matthieu castetb72458a2005-11-07 23:27:13 +0100838{
839 int ret = -ENOMEM;
840 u8 *xfer_buff;
841 int bytes_read;
842
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +0200843 xfer_buff = kmemdup(data, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +0100844 if (!xfer_buff) {
845 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
846 return ret;
847 }
848
matthieu castetb72458a2005-11-07 23:27:13 +0100849 ret = usb_bulk_msg(sc->usb_dev,
850 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
851 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
852
853 kfree(xfer_buff);
854 if (ret < 0)
855 return ret;
856 if (size != bytes_read) {
857 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
858 bytes_read);
859 return -EIO;
860 }
861
862 return 0;
863}
864
865static int request_dsp(struct uea_softc *sc)
866{
867 int ret;
868 char *dsp_name;
869
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200870 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200871 if (IS_ISDN(sc))
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200872 dsp_name = FW_DIR "DSP4i.bin";
873 else
874 dsp_name = FW_DIR "DSP4p.bin";
875 } else if (UEA_CHIP_VERSION(sc) == ADI930) {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200876 if (IS_ISDN(sc))
matthieu castetb72458a2005-11-07 23:27:13 +0100877 dsp_name = FW_DIR "DSP9i.bin";
878 else
879 dsp_name = FW_DIR "DSP9p.bin";
880 } else {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200881 if (IS_ISDN(sc))
matthieu castetb72458a2005-11-07 23:27:13 +0100882 dsp_name = FW_DIR "DSPei.bin";
883 else
884 dsp_name = FW_DIR "DSPep.bin";
885 }
886
matthieu castete40abaf2006-01-18 07:38:37 +0100887 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
matthieu castetb72458a2005-11-07 23:27:13 +0100888 if (ret < 0) {
889 uea_err(INS_TO_USBDEV(sc),
890 "requesting firmware %s failed with error %d\n",
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200891 dsp_name, ret);
matthieu castetb72458a2005-11-07 23:27:13 +0100892 return ret;
893 }
894
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200895 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
896 ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size);
897 else
898 ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size);
899
900 if (ret) {
matthieu castetb72458a2005-11-07 23:27:13 +0100901 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
902 dsp_name);
903 release_firmware(sc->dsp_firm);
904 sc->dsp_firm = NULL;
905 return -EILSEQ;
906 }
907
908 return 0;
909}
910
911/*
912 * The uea_load_page() function must be called within a process context
913 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200914static void uea_load_page_e1(struct work_struct *work)
matthieu castetb72458a2005-11-07 23:27:13 +0100915{
David Howellsc4028952006-11-22 14:57:56 +0000916 struct uea_softc *sc = container_of(work, struct uea_softc, task);
matthieu castetb72458a2005-11-07 23:27:13 +0100917 u16 pageno = sc->pageno;
918 u16 ovl = sc->ovl;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200919 struct block_info_e1 bi;
matthieu castetb72458a2005-11-07 23:27:13 +0100920
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100921 const u8 *p;
matthieu castetb72458a2005-11-07 23:27:13 +0100922 u8 pagecount, blockcount;
923 u16 blockaddr, blocksize;
924 u32 pageoffset;
925 int i;
926
927 /* reload firmware when reboot start and it's loaded already */
928 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
929 release_firmware(sc->dsp_firm);
930 sc->dsp_firm = NULL;
931 }
932
933 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
934 return;
935
936 p = sc->dsp_firm->data;
937 pagecount = FW_GET_BYTE(p);
938 p += 1;
939
940 if (pageno >= pagecount)
941 goto bad1;
942
943 p += 4 * pageno;
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700944 pageoffset = get_unaligned_le32(p);
matthieu castetb72458a2005-11-07 23:27:13 +0100945
946 if (pageoffset == 0)
947 goto bad1;
948
949 p = sc->dsp_firm->data + pageoffset;
950 blockcount = FW_GET_BYTE(p);
951 p += 1;
952
953 uea_dbg(INS_TO_USBDEV(sc),
954 "sending %u blocks for DSP page %u\n", blockcount, pageno);
955
956 bi.wHdr = cpu_to_le16(UEA_BIHDR);
957 bi.wOvl = cpu_to_le16(ovl);
958 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
959
960 for (i = 0; i < blockcount; i++) {
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700961 blockaddr = get_unaligned_le16(p);
matthieu castetb72458a2005-11-07 23:27:13 +0100962 p += 2;
963
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700964 blocksize = get_unaligned_le16(p);
matthieu castetb72458a2005-11-07 23:27:13 +0100965 p += 2;
966
967 bi.wSize = cpu_to_le16(blocksize);
968 bi.wAddress = cpu_to_le16(blockaddr);
969 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
970
971 /* send block info through the IDMA pipe */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200972 if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE))
matthieu castetb72458a2005-11-07 23:27:13 +0100973 goto bad2;
974
975 /* send block data through the IDMA pipe */
976 if (uea_idma_write(sc, p, blocksize))
977 goto bad2;
978
979 p += blocksize;
980 }
981
982 return;
983
984bad2:
985 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
986 return;
987bad1:
matthieu castet2a99b502006-04-02 18:43:53 +0200988 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
matthieu castetb72458a2005-11-07 23:27:13 +0100989}
990
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200991static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
992{
993 struct block_info_e4 bi;
994 struct block_index *blockidx;
995 struct l1_code *p = (struct l1_code *) sc->dsp_firm->data;
996 u8 blockno = p->page_number_to_block_index[pageno];
997
998 bi.wHdr = cpu_to_be16(UEA_BIHDR);
999 bi.bBootPage = boot;
1000 bi.bPageNumber = pageno;
1001 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1002
1003 do {
David Woodhouseaafcd2f2008-05-24 00:05:10 +01001004 const u8 *blockoffset;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001005 unsigned int blocksize;
1006
1007 blockidx = &p->page_header[blockno];
1008 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001009 blockoffset = sc->dsp_firm->data + le32_to_cpu(
1010 blockidx->PageOffset);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001011
1012 bi.dwSize = cpu_to_be32(blocksize);
Al Virofd05e722008-04-28 07:00:16 +01001013 bi.dwAddress = cpu_to_be32(le32_to_cpu(blockidx->PageAddress));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001014
1015 uea_dbg(INS_TO_USBDEV(sc),
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001016 "sending block %u for DSP page "
1017 "%u size %u address %x\n",
1018 blockno, pageno, blocksize,
1019 le32_to_cpu(blockidx->PageAddress));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001020
1021 /* send block info through the IDMA pipe */
1022 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1023 goto bad;
1024
1025 /* send block data through the IDMA pipe */
1026 if (uea_idma_write(sc, blockoffset, blocksize))
1027 goto bad;
1028
1029 blockno++;
1030 } while (blockidx->NotLastBlock);
1031
1032 return;
1033
1034bad:
1035 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno);
1036 return;
1037}
1038
1039static void uea_load_page_e4(struct work_struct *work)
1040{
1041 struct uea_softc *sc = container_of(work, struct uea_softc, task);
1042 u8 pageno = sc->pageno;
1043 int i;
1044 struct block_info_e4 bi;
1045 struct l1_code *p;
1046
1047 uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
1048
1049 /* reload firmware when reboot start and it's loaded already */
1050 if (pageno == 0 && sc->dsp_firm) {
1051 release_firmware(sc->dsp_firm);
1052 sc->dsp_firm = NULL;
1053 }
1054
1055 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
1056 return;
1057
1058 p = (struct l1_code *) sc->dsp_firm->data;
Al Virofd05e722008-04-28 07:00:16 +01001059 if (pageno >= le16_to_cpu(p->page_header[0].PageNumber)) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001060 uea_err(INS_TO_USBDEV(sc), "invalid DSP "
1061 "page %u requested\n", pageno);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001062 return;
1063 }
1064
1065 if (pageno != 0) {
1066 __uea_load_page_e4(sc, pageno, 0);
1067 return;
1068 }
1069
1070 uea_dbg(INS_TO_USBDEV(sc),
1071 "sending Main DSP page %u\n", p->page_header[0].PageNumber);
1072
1073 for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) {
1074 if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize))
1075 __uea_load_page_e4(sc, i, 1);
1076 }
1077
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001078 uea_dbg(INS_TO_USBDEV(sc) , "sending start bi\n");
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001079
1080 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1081 bi.bBootPage = 0;
1082 bi.bPageNumber = 0xff;
1083 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1084 bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize));
Al Virofd05e722008-04-28 07:00:16 +01001085 bi.dwAddress = cpu_to_be32(le32_to_cpu(p->page_header[0].PageAddress));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001086
1087 /* send block info through the IDMA pipe */
1088 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1089 uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n");
1090}
1091
matthieu castetb72458a2005-11-07 23:27:13 +01001092static inline void wake_up_cmv_ack(struct uea_softc *sc)
1093{
matthieu castet2a99b502006-04-02 18:43:53 +02001094 BUG_ON(sc->cmv_ack);
matthieu castetb72458a2005-11-07 23:27:13 +01001095 sc->cmv_ack = 1;
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001096 wake_up(&sc->sync_q);
matthieu castetb72458a2005-11-07 23:27:13 +01001097}
1098
1099static inline int wait_cmv_ack(struct uea_softc *sc)
1100{
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001101 int ret = uea_wait(sc, sc->cmv_ack , ACK_TIMEOUT);
1102
matthieu castetb72458a2005-11-07 23:27:13 +01001103 sc->cmv_ack = 0;
1104
matthieu castet2a99b502006-04-02 18:43:53 +02001105 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
1106 jiffies_to_msecs(ret));
1107
matthieu castetb72458a2005-11-07 23:27:13 +01001108 if (ret < 0)
1109 return ret;
1110
1111 return (ret == 0) ? -ETIMEDOUT : 0;
matthieu castetb72458a2005-11-07 23:27:13 +01001112}
1113
1114#define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1115
1116static int uea_request(struct uea_softc *sc,
David Woodhouseaafcd2f2008-05-24 00:05:10 +01001117 u16 value, u16 index, u16 size, const void *data)
matthieu castetb72458a2005-11-07 23:27:13 +01001118{
1119 u8 *xfer_buff;
1120 int ret = -ENOMEM;
1121
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +02001122 xfer_buff = kmemdup(data, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +01001123 if (!xfer_buff) {
1124 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
1125 return ret;
1126 }
matthieu castetb72458a2005-11-07 23:27:13 +01001127
1128 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
1129 UCDC_SEND_ENCAPSULATED_COMMAND,
1130 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1131 value, index, xfer_buff, size, CTRL_TIMEOUT);
1132
1133 kfree(xfer_buff);
1134 if (ret < 0) {
1135 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
1136 return ret;
1137 }
1138
1139 if (ret != size) {
1140 uea_err(INS_TO_USBDEV(sc),
1141 "usb_control_msg send only %d bytes (instead of %d)\n",
1142 ret, size);
1143 return -EIO;
1144 }
1145
1146 return 0;
1147}
1148
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001149static int uea_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001150 u8 function, u32 address, u16 offset, u32 data)
1151{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001152 struct cmv_e1 cmv;
matthieu castetb72458a2005-11-07 23:27:13 +01001153 int ret;
1154
matthieu castet2a99b502006-04-02 18:43:53 +02001155 uea_enters(INS_TO_USBDEV(sc));
1156 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1157 "offset : 0x%04x, data : 0x%08x\n",
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001158 E1_FUNCTION_TYPE(function),
1159 E1_FUNCTION_SUBTYPE(function),
1160 E1_GETSA1(address), E1_GETSA2(address),
1161 E1_GETSA3(address),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001162 E1_GETSA4(address), offset, data);
matthieu castetb72458a2005-11-07 23:27:13 +01001163
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001164 /* we send a request, but we expect a reply */
1165 sc->cmv_dsc.e1.function = function | 0x2;
1166 sc->cmv_dsc.e1.idx++;
1167 sc->cmv_dsc.e1.address = address;
1168 sc->cmv_dsc.e1.offset = offset;
1169
1170 cmv.wPreamble = cpu_to_le16(E1_PREAMBLE);
1171 cmv.bDirection = E1_HOSTTOMODEM;
matthieu castetb72458a2005-11-07 23:27:13 +01001172 cmv.bFunction = function;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001173 cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx);
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001174 put_unaligned_le32(address, &cmv.dwSymbolicAddress);
matthieu castetb72458a2005-11-07 23:27:13 +01001175 cmv.wOffsetAddress = cpu_to_le16(offset);
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001176 put_unaligned_le32(data >> 16 | data << 16, &cmv.dwData);
matthieu castetb72458a2005-11-07 23:27:13 +01001177
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001178 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START,
1179 sizeof(cmv), &cmv);
matthieu castetb72458a2005-11-07 23:27:13 +01001180 if (ret < 0)
1181 return ret;
matthieu castet2a99b502006-04-02 18:43:53 +02001182 ret = wait_cmv_ack(sc);
1183 uea_leaves(INS_TO_USBDEV(sc));
1184 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001185}
1186
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001187static int uea_cmv_e4(struct uea_softc *sc,
1188 u16 function, u16 group, u16 address, u16 offset, u32 data)
1189{
1190 struct cmv_e4 cmv;
1191 int ret;
1192
1193 uea_enters(INS_TO_USBDEV(sc));
1194 memset(&cmv, 0, sizeof(cmv));
1195
1196 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
1197 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1198 E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function),
1199 group, address, offset, data);
1200
1201 /* we send a request, but we expect a reply */
1202 sc->cmv_dsc.e4.function = function | (0x1 << 4);
1203 sc->cmv_dsc.e4.offset = offset;
1204 sc->cmv_dsc.e4.address = address;
1205 sc->cmv_dsc.e4.group = group;
1206
1207 cmv.wFunction = cpu_to_be16(function);
1208 cmv.wGroup = cpu_to_be16(group);
1209 cmv.wAddress = cpu_to_be16(address);
1210 cmv.wOffset = cpu_to_be16(offset);
1211 cmv.dwData[0] = cpu_to_be32(data);
1212
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001213 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START,
1214 sizeof(cmv), &cmv);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001215 if (ret < 0)
1216 return ret;
1217 ret = wait_cmv_ack(sc);
1218 uea_leaves(INS_TO_USBDEV(sc));
1219 return ret;
1220}
1221
1222static inline int uea_read_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001223 u32 address, u16 offset, u32 *data)
1224{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001225 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD),
matthieu castetb72458a2005-11-07 23:27:13 +01001226 address, offset, 0);
1227 if (ret < 0)
1228 uea_err(INS_TO_USBDEV(sc),
1229 "reading cmv failed with error %d\n", ret);
1230 else
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001231 *data = sc->data;
matthieu castetb72458a2005-11-07 23:27:13 +01001232
1233 return ret;
1234}
1235
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001236static inline int uea_read_cmv_e4(struct uea_softc *sc,
1237 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1238{
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001239 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1240 E4_REQUESTREAD, size),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001241 group, address, offset, 0);
1242 if (ret < 0)
1243 uea_err(INS_TO_USBDEV(sc),
1244 "reading cmv failed with error %d\n", ret);
1245 else {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001246 *data = sc->data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001247 /* size is in 16-bit word quantities */
1248 if (size > 2)
1249 *(data + 1) = sc->data1;
1250 }
1251 return ret;
1252}
1253
1254static inline int uea_write_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001255 u32 address, u16 offset, u32 data)
1256{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001257 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE),
matthieu castetb72458a2005-11-07 23:27:13 +01001258 address, offset, data);
1259 if (ret < 0)
1260 uea_err(INS_TO_USBDEV(sc),
1261 "writing cmv failed with error %d\n", ret);
1262
1263 return ret;
1264}
1265
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001266static inline int uea_write_cmv_e4(struct uea_softc *sc,
1267 u8 size, u16 group, u16 address, u16 offset, u32 data)
1268{
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001269 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1270 E4_REQUESTWRITE, size),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001271 group, address, offset, data);
1272 if (ret < 0)
1273 uea_err(INS_TO_USBDEV(sc),
1274 "writing cmv failed with error %d\n", ret);
1275
1276 return ret;
1277}
1278
1279static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1280{
1281 int ret;
1282 u16 timeout;
1283
1284 /* in bulk mode the modem have problem with high rate
1285 * changing internal timing could improve things, but the
1286 * value is misterious.
1287 * ADI930 don't support it (-EPIPE error).
1288 */
1289
1290 if (UEA_CHIP_VERSION(sc) == ADI930 ||
Stanislaw Gruszka503add42007-08-20 23:21:06 +02001291 altsetting[sc->modem_index] > 0 ||
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001292 sc->stats.phy.dsrate == dsrate)
1293 return;
1294
1295 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1296 timeout = (dsrate <= 1024*1024) ? 0 : 1;
1297 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
1298 uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n",
1299 timeout, ret < 0 ? " failed" : "");
1300
1301}
1302
matthieu castetb72458a2005-11-07 23:27:13 +01001303/*
1304 * Monitor the modem and update the stat
1305 * return 0 if everything is ok
1306 * return < 0 if an error occurs (-EAGAIN reboot needed)
1307 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001308static int uea_stat_e1(struct uea_softc *sc)
matthieu castetb72458a2005-11-07 23:27:13 +01001309{
1310 u32 data;
1311 int ret;
1312
1313 uea_enters(INS_TO_USBDEV(sc));
1314 data = sc->stats.phy.state;
1315
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001316 ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state);
matthieu castetb72458a2005-11-07 23:27:13 +01001317 if (ret < 0)
1318 return ret;
1319
1320 switch (GET_STATUS(sc->stats.phy.state)) {
1321 case 0: /* not yet synchronized */
1322 uea_dbg(INS_TO_USBDEV(sc),
1323 "modem not yet synchronized\n");
1324 return 0;
1325
1326 case 1: /* initialization */
1327 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1328 return 0;
1329
1330 case 2: /* operational */
1331 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
1332 break;
1333
1334 case 3: /* fail ... */
matthieu casteta7a0c9c2006-10-03 21:44:11 +02001335 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001336 " (may be try other cmv/dsp)\n");
matthieu castetb72458a2005-11-07 23:27:13 +01001337 return -EAGAIN;
1338
1339 case 4 ... 6: /* test state */
1340 uea_warn(INS_TO_USBDEV(sc),
1341 "modem in test mode - not supported\n");
1342 return -EAGAIN;
1343
1344 case 7: /* fast-retain ... */
1345 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
1346 return 0;
1347 default:
1348 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
1349 GET_STATUS(sc->stats.phy.state));
1350 return -EAGAIN;
1351 }
1352
1353 if (GET_STATUS(data) != 2) {
1354 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1355 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1356
1357 /* release the dsp firmware as it is not needed until
1358 * the next failure
1359 */
1360 if (sc->dsp_firm) {
1361 release_firmware(sc->dsp_firm);
1362 sc->dsp_firm = NULL;
1363 }
matthieu castetb72458a2005-11-07 23:27:13 +01001364 }
1365
1366 /* always update it as atm layer could not be init when we switch to
1367 * operational state
1368 */
Karl Hiramotocc7b86c2010-07-08 20:55:38 +00001369 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND);
matthieu castetb72458a2005-11-07 23:27:13 +01001370
1371 /* wake up processes waiting for synchronization */
1372 wake_up(&sc->sync_q);
1373
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001374 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags);
matthieu castetb72458a2005-11-07 23:27:13 +01001375 if (ret < 0)
1376 return ret;
1377 sc->stats.phy.mflags |= sc->stats.phy.flags;
1378
1379 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1380 * we check the status again in order to detect the failure earlier
1381 */
1382 if (sc->stats.phy.flags) {
matthieu castet2a99b502006-04-02 18:43:53 +02001383 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
matthieu castetb72458a2005-11-07 23:27:13 +01001384 sc->stats.phy.flags);
1385 return 0;
1386 }
1387
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001388 ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001389 if (ret < 0)
1390 return ret;
1391
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001392 uea_set_bulk_timeout(sc, (data >> 16) * 32);
matthieu castetb72458a2005-11-07 23:27:13 +01001393 sc->stats.phy.dsrate = (data >> 16) * 32;
1394 sc->stats.phy.usrate = (data & 0xffff) * 32;
1395 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1396
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001397 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001398 if (ret < 0)
1399 return ret;
1400 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
1401
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001402 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001403 if (ret < 0)
1404 return ret;
1405 sc->stats.phy.usattenuation = (data & 0xff) / 2;
1406
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001407 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin);
matthieu castetb72458a2005-11-07 23:27:13 +01001408 if (ret < 0)
1409 return ret;
1410
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001411 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin);
matthieu castetb72458a2005-11-07 23:27:13 +01001412 if (ret < 0)
1413 return ret;
1414
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001415 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow);
matthieu castetb72458a2005-11-07 23:27:13 +01001416 if (ret < 0)
1417 return ret;
1418
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001419 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow);
matthieu castetb72458a2005-11-07 23:27:13 +01001420 if (ret < 0)
1421 return ret;
1422
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001423 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc);
matthieu castetb72458a2005-11-07 23:27:13 +01001424 if (ret < 0)
1425 return ret;
1426
1427 /* only for atu-c */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001428 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc);
matthieu castetb72458a2005-11-07 23:27:13 +01001429 if (ret < 0)
1430 return ret;
1431
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001432 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr);
matthieu castetb72458a2005-11-07 23:27:13 +01001433 if (ret < 0)
1434 return ret;
1435
1436 /* only for atu-c */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001437 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr);
matthieu castetb72458a2005-11-07 23:27:13 +01001438 if (ret < 0)
1439 return ret;
1440
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001441 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 8, &sc->stats.phy.vidco);
matthieu castetb72458a2005-11-07 23:27:13 +01001442 if (ret < 0)
1443 return ret;
1444
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001445 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 13, &sc->stats.phy.vidcpe);
matthieu castetb72458a2005-11-07 23:27:13 +01001446 if (ret < 0)
1447 return ret;
1448
1449 return 0;
1450}
1451
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001452static int uea_stat_e4(struct uea_softc *sc)
matthieu castetb72458a2005-11-07 23:27:13 +01001453{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001454 u32 data;
1455 u32 tmp_arr[2];
1456 int ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001457
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001458 uea_enters(INS_TO_USBDEV(sc));
1459 data = sc->stats.phy.state;
1460
1461 /* XXX only need to be done before operationnal... */
1462 ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state);
1463 if (ret < 0)
1464 return ret;
1465
1466 switch (sc->stats.phy.state) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001467 case 0x0: /* not yet synchronized */
1468 case 0x1:
1469 case 0x3:
1470 case 0x4:
1471 uea_dbg(INS_TO_USBDEV(sc), "modem not yet "
1472 "synchronized\n");
1473 return 0;
1474 case 0x5: /* initialization */
1475 case 0x6:
1476 case 0x9:
1477 case 0xa:
1478 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1479 return 0;
1480 case 0x2: /* fail ... */
1481 uea_info(INS_TO_USBDEV(sc), "modem synchronization "
1482 "failed (may be try other cmv/dsp)\n");
1483 return -EAGAIN;
1484 case 0x7: /* operational */
1485 break;
1486 default:
1487 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n",
1488 sc->stats.phy.state);
1489 return 0;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001490 }
1491
1492 if (data != 7) {
1493 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1494 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1495
1496 /* release the dsp firmware as it is not needed until
1497 * the next failure
1498 */
1499 if (sc->dsp_firm) {
1500 release_firmware(sc->dsp_firm);
1501 sc->dsp_firm = NULL;
1502 }
1503 }
1504
1505 /* always update it as atm layer could not be init when we switch to
1506 * operational state
1507 */
Karl Hiramotocc7b86c2010-07-08 20:55:38 +00001508 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001509
1510 /* wake up processes waiting for synchronization */
1511 wake_up(&sc->sync_q);
1512
1513 /* TODO improve this state machine :
1514 * we need some CMV info : what they do and their unit
1515 * we should find the equivalent of eagle3- CMV
1516 */
1517 /* check flags */
1518 ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags);
1519 if (ret < 0)
1520 return ret;
1521 sc->stats.phy.mflags |= sc->stats.phy.flags;
1522
1523 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1524 * we check the status again in order to detect the failure earlier
1525 */
1526 if (sc->stats.phy.flags) {
1527 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1528 sc->stats.phy.flags);
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001529 if (sc->stats.phy.flags & 1) /* delineation LOSS */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001530 return -EAGAIN;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001531 if (sc->stats.phy.flags & 0x4000) /* Reset Flag */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001532 return -EAGAIN;
1533 return 0;
1534 }
1535
1536 /* rate data may be in upper or lower half of 64 bit word, strange */
1537 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr);
1538 if (ret < 0)
1539 return ret;
1540 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1541 sc->stats.phy.usrate = data / 1000;
1542
1543 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr);
1544 if (ret < 0)
1545 return ret;
1546 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1547 uea_set_bulk_timeout(sc, data / 1000);
1548 sc->stats.phy.dsrate = data / 1000;
1549 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1550
1551 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data);
1552 if (ret < 0)
1553 return ret;
1554 sc->stats.phy.dsattenuation = data / 10;
1555
1556 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data);
1557 if (ret < 0)
1558 return ret;
1559 sc->stats.phy.usattenuation = data / 10;
1560
1561 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data);
1562 if (ret < 0)
1563 return ret;
1564 sc->stats.phy.dsmargin = data / 2;
1565
1566 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data);
1567 if (ret < 0)
1568 return ret;
1569 sc->stats.phy.usmargin = data / 10;
1570
1571 return 0;
1572}
1573
1574static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1575{
1576 char file_arr[] = "CMVxy.bin";
1577 char *file;
1578
1579 /* set proper name corresponding modem version and line type */
matthieu castetb72458a2005-11-07 23:27:13 +01001580 if (cmv_file[sc->modem_index] == NULL) {
1581 if (UEA_CHIP_VERSION(sc) == ADI930)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001582 file_arr[3] = '9';
1583 else if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1584 file_arr[3] = '4';
matthieu castetb72458a2005-11-07 23:27:13 +01001585 else
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001586 file_arr[3] = 'e';
1587
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02001588 file_arr[4] = IS_ISDN(sc) ? 'i' : 'p';
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001589 file = file_arr;
matthieu castetb72458a2005-11-07 23:27:13 +01001590 } else
1591 file = cmv_file[sc->modem_index];
1592
1593 strcpy(cmv_name, FW_DIR);
Samuel Ortizade901d2009-05-27 00:49:32 +02001594 strlcat(cmv_name, file, UEA_FW_NAME_MAX);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001595 if (ver == 2)
Samuel Ortizade901d2009-05-27 00:49:32 +02001596 strlcat(cmv_name, ".v2", UEA_FW_NAME_MAX);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001597}
matthieu castetb72458a2005-11-07 23:27:13 +01001598
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001599static int request_cmvs_old(struct uea_softc *sc,
1600 void **cmvs, const struct firmware **fw)
1601{
1602 int ret, size;
1603 u8 *data;
Samuel Ortizade901d2009-05-27 00:49:32 +02001604 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001605
1606 cmvs_file_name(sc, cmv_name, 1);
matthieu castetb72458a2005-11-07 23:27:13 +01001607 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1608 if (ret < 0) {
1609 uea_err(INS_TO_USBDEV(sc),
1610 "requesting firmware %s failed with error %d\n",
1611 cmv_name, ret);
1612 return ret;
1613 }
1614
1615 data = (u8 *) (*fw)->data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001616 size = (*fw)->size;
1617 if (size < 1)
1618 goto err_fw_corrupted;
1619
1620 if (size != *data * sizeof(struct uea_cmvs_v1) + 1)
1621 goto err_fw_corrupted;
1622
1623 *cmvs = (void *)(data + 1);
1624 return *data;
1625
1626err_fw_corrupted:
1627 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1628 release_firmware(*fw);
1629 return -EILSEQ;
1630}
1631
1632static int request_cmvs(struct uea_softc *sc,
1633 void **cmvs, const struct firmware **fw, int *ver)
1634{
1635 int ret, size;
1636 u32 crc;
1637 u8 *data;
Samuel Ortizade901d2009-05-27 00:49:32 +02001638 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001639
1640 cmvs_file_name(sc, cmv_name, 2);
1641 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1642 if (ret < 0) {
1643 /* if caller can handle old version, try to provide it */
1644 if (*ver == 1) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001645 uea_warn(INS_TO_USBDEV(sc), "requesting "
1646 "firmware %s failed, "
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001647 "try to get older cmvs\n", cmv_name);
1648 return request_cmvs_old(sc, cmvs, fw);
1649 }
1650 uea_err(INS_TO_USBDEV(sc),
1651 "requesting firmware %s failed with error %d\n",
1652 cmv_name, ret);
1653 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001654 }
1655
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001656 size = (*fw)->size;
1657 data = (u8 *) (*fw)->data;
1658 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1659 if (*ver == 1) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001660 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted,"
1661 " try to get older cmvs\n", cmv_name);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001662 release_firmware(*fw);
1663 return request_cmvs_old(sc, cmvs, fw);
1664 }
1665 goto err_fw_corrupted;
1666 }
1667
1668 *ver = 2;
1669
1670 data += 4;
1671 size -= 4;
1672 if (size < 5)
1673 goto err_fw_corrupted;
1674
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001675 crc = get_unaligned_le32(data);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001676 data += 4;
1677 size -= 4;
1678 if (crc32_be(0, data, size) != crc)
1679 goto err_fw_corrupted;
1680
1681 if (size != *data * sizeof(struct uea_cmvs_v2) + 1)
1682 goto err_fw_corrupted;
1683
1684 *cmvs = (void *) (data + 1);
matthieu castetb72458a2005-11-07 23:27:13 +01001685 return *data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001686
1687err_fw_corrupted:
1688 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1689 release_firmware(*fw);
1690 return -EILSEQ;
1691}
1692
1693static int uea_send_cmvs_e1(struct uea_softc *sc)
1694{
1695 int i, ret, len;
1696 void *cmvs_ptr;
1697 const struct firmware *cmvs_fw;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001698 int ver = 1; /* we can handle v1 cmv firmware version; */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001699
1700 /* Enter in R-IDLE (cmv) until instructed otherwise */
1701 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
1702 if (ret < 0)
1703 return ret;
1704
1705 /* Dump firmware version */
1706 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid);
1707 if (ret < 0)
1708 return ret;
1709 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1710 sc->stats.phy.firmid);
1711
1712 /* get options */
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001713 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001714 if (ret < 0)
1715 return ret;
1716
1717 /* send options */
1718 if (ver == 1) {
1719 struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr;
1720
1721 uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, "
1722 "please update your firmware\n");
1723
1724 for (i = 0; i < len; i++) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001725 ret = uea_write_cmv_e1(sc,
1726 get_unaligned_le32(&cmvs_v1[i].address),
1727 get_unaligned_le16(&cmvs_v1[i].offset),
1728 get_unaligned_le32(&cmvs_v1[i].data));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001729 if (ret < 0)
1730 goto out;
1731 }
1732 } else if (ver == 2) {
1733 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1734
1735 for (i = 0; i < len; i++) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001736 ret = uea_write_cmv_e1(sc,
1737 get_unaligned_le32(&cmvs_v2[i].address),
1738 (u16) get_unaligned_le32(&cmvs_v2[i].offset),
1739 get_unaligned_le32(&cmvs_v2[i].data));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001740 if (ret < 0)
1741 goto out;
1742 }
1743 } else {
1744 /* This realy should not happen */
1745 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1746 goto out;
1747 }
1748
1749 /* Enter in R-ACT-REQ */
1750 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1751 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001752 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1753 "synchronization...\n");
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001754out:
1755 release_firmware(cmvs_fw);
1756 return ret;
1757}
1758
1759static int uea_send_cmvs_e4(struct uea_softc *sc)
1760{
1761 int i, ret, len;
1762 void *cmvs_ptr;
1763 const struct firmware *cmvs_fw;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001764 int ver = 2; /* we can only handle v2 cmv firmware version; */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001765
1766 /* Enter in R-IDLE (cmv) until instructed otherwise */
1767 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
1768 if (ret < 0)
1769 return ret;
1770
1771 /* Dump firmware version */
1772 /* XXX don't read the 3th byte as it is always 6 */
1773 ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid);
1774 if (ret < 0)
1775 return ret;
1776 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1777 sc->stats.phy.firmid);
1778
1779
1780 /* get options */
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001781 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001782 if (ret < 0)
1783 return ret;
1784
1785 /* send options */
1786 if (ver == 2) {
1787 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1788
1789 for (i = 0; i < len; i++) {
1790 ret = uea_write_cmv_e4(sc, 1,
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001791 get_unaligned_le32(&cmvs_v2[i].group),
1792 get_unaligned_le32(&cmvs_v2[i].address),
1793 get_unaligned_le32(&cmvs_v2[i].offset),
1794 get_unaligned_le32(&cmvs_v2[i].data));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001795 if (ret < 0)
1796 goto out;
1797 }
1798 } else {
1799 /* This realy should not happen */
1800 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1801 goto out;
1802 }
1803
1804 /* Enter in R-ACT-REQ */
1805 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1806 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001807 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1808 "synchronization...\n");
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001809out:
1810 release_firmware(cmvs_fw);
1811 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001812}
1813
1814/* Start boot post firmware modem:
1815 * - send reset commands through usb control pipe
1816 * - start workqueue for DSP loading
1817 * - send CMV options to modem
1818 */
1819
1820static int uea_start_reset(struct uea_softc *sc)
1821{
1822 u16 zero = 0; /* ;-) */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001823 int ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001824
1825 uea_enters(INS_TO_USBDEV(sc));
1826 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1827
matthieu castet22fcceb2006-04-02 18:44:20 +02001828 /* mask interrupt */
matthieu castetb72458a2005-11-07 23:27:13 +01001829 sc->booting = 1;
matthieu castet22fcceb2006-04-02 18:44:20 +02001830 /* We need to set this here because, a ack timeout could have occured,
1831 * but before we start the reboot, the ack occurs and set this to 1.
1832 * So we will failed to wait Ready CMV.
1833 */
1834 sc->cmv_ack = 0;
Karl Hiramotocc7b86c2010-07-08 20:55:38 +00001835 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST);
matthieu castetb72458a2005-11-07 23:27:13 +01001836
1837 /* reset statistics */
1838 memset(&sc->stats, 0, sizeof(struct uea_stats));
1839
1840 /* tell the modem that we want to boot in IDMA mode */
1841 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1842 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1843
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001844 /* enter reset mode */
matthieu castetb72458a2005-11-07 23:27:13 +01001845 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1846
1847 /* original driver use 200ms, but windows driver use 100ms */
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001848 ret = uea_wait(sc, 0, msecs_to_jiffies(100));
1849 if (ret < 0)
1850 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001851
1852 /* leave reset mode */
1853 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1854
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001855 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001856 /* clear tx and rx mailboxes */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001857 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1858 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1859 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1860 }
matthieu castetb72458a2005-11-07 23:27:13 +01001861
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001862 ret = uea_wait(sc, 0, msecs_to_jiffies(1000));
1863 if (ret < 0)
1864 return ret;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001865
1866 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001867 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
1868 E4_MODEMREADY, 1);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001869 else
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001870 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
1871 E1_MODEMREADY);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001872
matthieu castet22fcceb2006-04-02 18:44:20 +02001873 /* demask interrupt */
matthieu castetb72458a2005-11-07 23:27:13 +01001874 sc->booting = 0;
1875
1876 /* start loading DSP */
1877 sc->pageno = 0;
1878 sc->ovl = 0;
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02001879 queue_work(sc->work_q, &sc->task);
matthieu castetb72458a2005-11-07 23:27:13 +01001880
1881 /* wait for modem ready CMV */
1882 ret = wait_cmv_ack(sc);
1883 if (ret < 0)
1884 return ret;
1885
matthieu castet2a99b502006-04-02 18:43:53 +02001886 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1887
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001888 ret = sc->send_cmvs(sc);
matthieu castetb72458a2005-11-07 23:27:13 +01001889 if (ret < 0)
1890 return ret;
1891
matthieu castetb72458a2005-11-07 23:27:13 +01001892 sc->reset = 0;
1893 uea_leaves(INS_TO_USBDEV(sc));
1894 return ret;
1895}
1896
1897/*
1898 * In case of an error wait 1s before rebooting the modem
1899 * if the modem don't request reboot (-EAGAIN).
1900 * Monitor the modem every 1s.
1901 */
1902
1903static int uea_kthread(void *data)
1904{
1905 struct uea_softc *sc = data;
1906 int ret = -EAGAIN;
1907
Rafael J. Wysocki83144182007-07-17 04:03:35 -07001908 set_freezable();
matthieu castetb72458a2005-11-07 23:27:13 +01001909 uea_enters(INS_TO_USBDEV(sc));
1910 while (!kthread_should_stop()) {
1911 if (ret < 0 || sc->reset)
1912 ret = uea_start_reset(sc);
1913 if (!ret)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001914 ret = sc->stat(sc);
matthieu castetb72458a2005-11-07 23:27:13 +01001915 if (ret != -EAGAIN)
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001916 uea_wait(sc, 0, msecs_to_jiffies(1000));
Stanislaw Gruszka0eb02262007-08-20 23:21:19 +02001917 try_to_freeze();
matthieu castetb72458a2005-11-07 23:27:13 +01001918 }
1919 uea_leaves(INS_TO_USBDEV(sc));
1920 return ret;
1921}
1922
1923/* Load second usb firmware for ADI930 chip */
1924static int load_XILINX_firmware(struct uea_softc *sc)
1925{
1926 const struct firmware *fw_entry;
1927 int ret, size, u, ln;
David Woodhouseaafcd2f2008-05-24 00:05:10 +01001928 const u8 *pfw;
1929 u8 value;
matthieu castetb72458a2005-11-07 23:27:13 +01001930 char *fw_name = FW_DIR "930-fpga.bin";
1931
1932 uea_enters(INS_TO_USBDEV(sc));
1933
1934 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1935 if (ret) {
1936 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1937 fw_name);
1938 goto err0;
1939 }
1940
1941 pfw = fw_entry->data;
1942 size = fw_entry->size;
1943 if (size != 0x577B) {
1944 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1945 fw_name);
1946 ret = -EILSEQ;
1947 goto err1;
1948 }
1949 for (u = 0; u < size; u += ln) {
1950 ln = min(size - u, 64);
1951 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1952 if (ret < 0) {
1953 uea_err(INS_TO_USBDEV(sc),
1954 "elsa download data failed (%d)\n", ret);
1955 goto err1;
1956 }
1957 }
1958
matthieu castete40abaf2006-01-18 07:38:37 +01001959 /* finish to send the fpga */
matthieu castetb72458a2005-11-07 23:27:13 +01001960 ret = uea_request(sc, 0xe, 1, 0, NULL);
1961 if (ret < 0) {
1962 uea_err(INS_TO_USBDEV(sc),
1963 "elsa download data failed (%d)\n", ret);
1964 goto err1;
1965 }
1966
matthieu castete40abaf2006-01-18 07:38:37 +01001967 /* Tell the modem we finish : de-assert reset */
matthieu castetb72458a2005-11-07 23:27:13 +01001968 value = 0;
1969 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1970 if (ret < 0)
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001971 uea_err(sc->usb_dev, "elsa de-assert failed with error"
1972 " %d\n", ret);
matthieu castetb72458a2005-11-07 23:27:13 +01001973
matthieu castetb72458a2005-11-07 23:27:13 +01001974err1:
1975 release_firmware(fw_entry);
1976err0:
1977 uea_leaves(INS_TO_USBDEV(sc));
1978 return ret;
1979}
1980
matthieu castete40abaf2006-01-18 07:38:37 +01001981/* The modem send us an ack. First with check if it right */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001982static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
matthieu castetb72458a2005-11-07 23:27:13 +01001983{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001984 struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;
1985 struct cmv_e1 *cmv = &intr->u.e1.s2.cmv;
1986
matthieu castetb72458a2005-11-07 23:27:13 +01001987 uea_enters(INS_TO_USBDEV(sc));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001988 if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE)
matthieu castetb72458a2005-11-07 23:27:13 +01001989 goto bad1;
1990
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001991 if (cmv->bDirection != E1_MODEMTOHOST)
matthieu castetb72458a2005-11-07 23:27:13 +01001992 goto bad1;
1993
1994 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001995 * the first MEMACCESS cmv. Ignore it...
matthieu castetb72458a2005-11-07 23:27:13 +01001996 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001997 if (cmv->bFunction != dsc->function) {
matthieu castetb72458a2005-11-07 23:27:13 +01001998 if (UEA_CHIP_VERSION(sc) == ADI930
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001999 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
2000 cmv->wIndex = cpu_to_le16(dsc->idx);
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002001 put_unaligned_le32(dsc->address,
2002 &cmv->dwSymbolicAddress);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002003 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
2004 } else
matthieu castetb72458a2005-11-07 23:27:13 +01002005 goto bad2;
2006 }
2007
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002008 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
2009 E1_MODEMREADY)) {
matthieu castetb72458a2005-11-07 23:27:13 +01002010 wake_up_cmv_ack(sc);
matthieu castet2a99b502006-04-02 18:43:53 +02002011 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002012 return;
2013 }
2014
2015 /* in case of MEMACCESS */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002016 if (le16_to_cpu(cmv->wIndex) != dsc->idx ||
Harvey Harrisona5abdea2008-04-29 01:03:40 -07002017 get_unaligned_le32(&cmv->dwSymbolicAddress) != dsc->address ||
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002018 le16_to_cpu(cmv->wOffsetAddress) != dsc->offset)
matthieu castetb72458a2005-11-07 23:27:13 +01002019 goto bad2;
2020
Harvey Harrisona5abdea2008-04-29 01:03:40 -07002021 sc->data = get_unaligned_le32(&cmv->dwData);
matthieu castetb72458a2005-11-07 23:27:13 +01002022 sc->data = sc->data << 16 | sc->data >> 16;
2023
2024 wake_up_cmv_ack(sc);
matthieu castet2a99b502006-04-02 18:43:53 +02002025 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002026 return;
2027
2028bad2:
Joe Perchesfec8de32007-11-19 17:53:33 -08002029 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
matthieu castetb72458a2005-11-07 23:27:13 +01002030 "Function : %d, Subfunction : %d\n",
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002031 E1_FUNCTION_TYPE(cmv->bFunction),
2032 E1_FUNCTION_SUBTYPE(cmv->bFunction));
matthieu castet2a99b502006-04-02 18:43:53 +02002033 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002034 return;
2035
2036bad1:
2037 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
2038 "wPreamble %d, bDirection %d\n",
2039 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
matthieu castet2a99b502006-04-02 18:43:53 +02002040 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002041}
2042
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002043/* The modem send us an ack. First with check if it right */
2044static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
2045{
2046 struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;
2047 struct cmv_e4 *cmv = &intr->u.e4.s2.cmv;
2048
2049 uea_enters(INS_TO_USBDEV(sc));
2050 uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n",
2051 be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction),
2052 be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
2053 be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1]));
2054
2055 if (be16_to_cpu(cmv->wFunction) != dsc->function)
2056 goto bad2;
2057
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002058 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
2059 E4_MODEMREADY, 1)) {
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002060 wake_up_cmv_ack(sc);
2061 uea_leaves(INS_TO_USBDEV(sc));
2062 return;
2063 }
2064
2065 /* in case of MEMACCESS */
2066 if (be16_to_cpu(cmv->wOffset) != dsc->offset ||
2067 be16_to_cpu(cmv->wGroup) != dsc->group ||
2068 be16_to_cpu(cmv->wAddress) != dsc->address)
2069 goto bad2;
2070
2071 sc->data = be32_to_cpu(cmv->dwData[0]);
2072 sc->data1 = be32_to_cpu(cmv->dwData[1]);
2073 wake_up_cmv_ack(sc);
2074 uea_leaves(INS_TO_USBDEV(sc));
2075 return;
2076
2077bad2:
Joe Perchesfec8de32007-11-19 17:53:33 -08002078 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002079 "Function : %d, Subfunction : %d\n",
2080 E4_FUNCTION_TYPE(cmv->wFunction),
2081 E4_FUNCTION_SUBTYPE(cmv->wFunction));
2082 uea_leaves(INS_TO_USBDEV(sc));
2083 return;
2084}
2085
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002086static void uea_schedule_load_page_e1(struct uea_softc *sc,
2087 struct intr_pkt *intr)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002088{
2089 sc->pageno = intr->e1_bSwapPageNo;
2090 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002091 queue_work(sc->work_q, &sc->task);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002092}
2093
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002094static void uea_schedule_load_page_e4(struct uea_softc *sc,
2095 struct intr_pkt *intr)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002096{
2097 sc->pageno = intr->e4_bSwapPageNo;
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002098 queue_work(sc->work_q, &sc->task);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002099}
2100
matthieu castetb72458a2005-11-07 23:27:13 +01002101/*
2102 * interrupt handler
2103 */
David Howells7d12e782006-10-05 14:55:46 +01002104static void uea_intr(struct urb *urb)
matthieu castetb72458a2005-11-07 23:27:13 +01002105{
matthieu castete40abaf2006-01-18 07:38:37 +01002106 struct uea_softc *sc = urb->context;
2107 struct intr_pkt *intr = urb->transfer_buffer;
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002108 int status = urb->status;
2109
matthieu castetb72458a2005-11-07 23:27:13 +01002110 uea_enters(INS_TO_USBDEV(sc));
2111
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002112 if (unlikely(status < 0)) {
matthieu castetb72458a2005-11-07 23:27:13 +01002113 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002114 status);
matthieu castetb72458a2005-11-07 23:27:13 +01002115 return;
2116 }
2117
matthieu castetb72458a2005-11-07 23:27:13 +01002118 /* device-to-host interrupt */
2119 if (intr->bType != 0x08 || sc->booting) {
matthieu castete40abaf2006-01-18 07:38:37 +01002120 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
matthieu castetb72458a2005-11-07 23:27:13 +01002121 goto resubmit;
2122 }
2123
2124 switch (le16_to_cpu(intr->wInterrupt)) {
2125 case INT_LOADSWAPPAGE:
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002126 sc->schedule_load_page(sc, intr);
matthieu castetb72458a2005-11-07 23:27:13 +01002127 break;
2128
2129 case INT_INCOMINGCMV:
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002130 sc->dispatch_cmv(sc, intr);
matthieu castetb72458a2005-11-07 23:27:13 +01002131 break;
2132
2133 default:
matthieu castete40abaf2006-01-18 07:38:37 +01002134 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
matthieu castetb72458a2005-11-07 23:27:13 +01002135 le16_to_cpu(intr->wInterrupt));
2136 }
2137
2138resubmit:
2139 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
2140}
2141
2142/*
2143 * Start the modem : init the data and start kernel thread
2144 */
2145static int uea_boot(struct uea_softc *sc)
2146{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002147 int ret, size;
matthieu castetb72458a2005-11-07 23:27:13 +01002148 struct intr_pkt *intr;
2149
2150 uea_enters(INS_TO_USBDEV(sc));
2151
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002152 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2153 size = E4_INTR_PKT_SIZE;
2154 sc->dispatch_cmv = uea_dispatch_cmv_e4;
2155 sc->schedule_load_page = uea_schedule_load_page_e4;
2156 sc->stat = uea_stat_e4;
2157 sc->send_cmvs = uea_send_cmvs_e4;
2158 INIT_WORK(&sc->task, uea_load_page_e4);
2159 } else {
2160 size = E1_INTR_PKT_SIZE;
2161 sc->dispatch_cmv = uea_dispatch_cmv_e1;
2162 sc->schedule_load_page = uea_schedule_load_page_e1;
2163 sc->stat = uea_stat_e1;
2164 sc->send_cmvs = uea_send_cmvs_e1;
2165 INIT_WORK(&sc->task, uea_load_page_e1);
2166 }
2167
matthieu castetb72458a2005-11-07 23:27:13 +01002168 init_waitqueue_head(&sc->sync_q);
matthieu castetb72458a2005-11-07 23:27:13 +01002169
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002170 sc->work_q = create_workqueue("ueagle-dsp");
2171 if (!sc->work_q) {
2172 uea_err(INS_TO_USBDEV(sc), "cannot allocate workqueue\n");
2173 uea_leaves(INS_TO_USBDEV(sc));
2174 return -ENOMEM;
2175 }
2176
matthieu castetb72458a2005-11-07 23:27:13 +01002177 if (UEA_CHIP_VERSION(sc) == ADI930)
2178 load_XILINX_firmware(sc);
2179
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002180 intr = kmalloc(size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +01002181 if (!intr) {
2182 uea_err(INS_TO_USBDEV(sc),
2183 "cannot allocate interrupt package\n");
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002184 goto err0;
matthieu castetb72458a2005-11-07 23:27:13 +01002185 }
2186
2187 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
2188 if (!sc->urb_int) {
2189 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002190 goto err1;
matthieu castetb72458a2005-11-07 23:27:13 +01002191 }
2192
2193 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
2194 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002195 intr, size, uea_intr, sc,
matthieu castetb72458a2005-11-07 23:27:13 +01002196 sc->usb_dev->actconfig->interface[0]->altsetting[0].
2197 endpoint[0].desc.bInterval);
2198
2199 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2200 if (ret < 0) {
2201 uea_err(INS_TO_USBDEV(sc),
2202 "urb submition failed with error %d\n", ret);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002203 goto err1;
matthieu castetb72458a2005-11-07 23:27:13 +01002204 }
2205
2206 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm");
2207 if (sc->kthread == ERR_PTR(-ENOMEM)) {
2208 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2209 goto err2;
2210 }
2211
2212 uea_leaves(INS_TO_USBDEV(sc));
2213 return 0;
2214
2215err2:
2216 usb_kill_urb(sc->urb_int);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002217err1:
matthieu castetb72458a2005-11-07 23:27:13 +01002218 usb_free_urb(sc->urb_int);
matthieu castet4d45e212006-04-02 18:45:46 +02002219 sc->urb_int = NULL;
2220 kfree(intr);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002221err0:
2222 destroy_workqueue(sc->work_q);
matthieu castetb72458a2005-11-07 23:27:13 +01002223 uea_leaves(INS_TO_USBDEV(sc));
2224 return -ENOMEM;
2225}
2226
2227/*
2228 * Stop the modem : kill kernel thread and free data
2229 */
2230static void uea_stop(struct uea_softc *sc)
2231{
2232 int ret;
2233 uea_enters(INS_TO_USBDEV(sc));
2234 ret = kthread_stop(sc->kthread);
matthieu castete40abaf2006-01-18 07:38:37 +01002235 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
matthieu castetb72458a2005-11-07 23:27:13 +01002236
matthieu castetb72458a2005-11-07 23:27:13 +01002237 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
2238
2239 usb_kill_urb(sc->urb_int);
2240 kfree(sc->urb_int->transfer_buffer);
2241 usb_free_urb(sc->urb_int);
2242
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002243 /* stop any pending boot process, when no one can schedule work */
2244 destroy_workqueue(sc->work_q);
2245
matthieu castetb72458a2005-11-07 23:27:13 +01002246 if (sc->dsp_firm)
2247 release_firmware(sc->dsp_firm);
2248 uea_leaves(INS_TO_USBDEV(sc));
2249}
2250
2251/* syfs interface */
2252static struct uea_softc *dev_to_uea(struct device *dev)
2253{
2254 struct usb_interface *intf;
2255 struct usbatm_data *usbatm;
2256
2257 intf = to_usb_interface(dev);
2258 if (!intf)
2259 return NULL;
2260
2261 usbatm = usb_get_intfdata(intf);
2262 if (!usbatm)
2263 return NULL;
2264
2265 return usbatm->driver_data;
2266}
2267
2268static ssize_t read_status(struct device *dev, struct device_attribute *attr,
2269 char *buf)
2270{
2271 int ret = -ENODEV;
2272 struct uea_softc *sc;
2273
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002274 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002275 sc = dev_to_uea(dev);
2276 if (!sc)
2277 goto out;
2278 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
2279out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002280 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002281 return ret;
2282}
2283
2284static ssize_t reboot(struct device *dev, struct device_attribute *attr,
2285 const char *buf, size_t count)
2286{
2287 int ret = -ENODEV;
2288 struct uea_softc *sc;
2289
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002290 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002291 sc = dev_to_uea(dev);
2292 if (!sc)
2293 goto out;
2294 sc->reset = 1;
2295 ret = count;
2296out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002297 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002298 return ret;
2299}
2300
2301static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot);
2302
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002303static ssize_t read_human_status(struct device *dev,
2304 struct device_attribute *attr, char *buf)
matthieu castetb72458a2005-11-07 23:27:13 +01002305{
2306 int ret = -ENODEV;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002307 int modem_state;
matthieu castetb72458a2005-11-07 23:27:13 +01002308 struct uea_softc *sc;
2309
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002310 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002311 sc = dev_to_uea(dev);
2312 if (!sc)
2313 goto out;
2314
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002315 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2316 switch (sc->stats.phy.state) {
2317 case 0x0: /* not yet synchronized */
2318 case 0x1:
2319 case 0x3:
2320 case 0x4:
2321 modem_state = 0;
2322 break;
2323 case 0x5: /* initialization */
2324 case 0x6:
2325 case 0x9:
2326 case 0xa:
2327 modem_state = 1;
2328 break;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002329 case 0x7: /* operational */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002330 modem_state = 2;
2331 break;
2332 case 0x2: /* fail ... */
2333 modem_state = 3;
2334 break;
2335 default: /* unknown */
2336 modem_state = 4;
2337 break;
2338 }
2339 } else
2340 modem_state = GET_STATUS(sc->stats.phy.state);
2341
2342 switch (modem_state) {
matthieu castetb72458a2005-11-07 23:27:13 +01002343 case 0:
2344 ret = sprintf(buf, "Modem is booting\n");
2345 break;
2346 case 1:
2347 ret = sprintf(buf, "Modem is initializing\n");
2348 break;
2349 case 2:
2350 ret = sprintf(buf, "Modem is operational\n");
2351 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002352 case 3:
matthieu castetb72458a2005-11-07 23:27:13 +01002353 ret = sprintf(buf, "Modem synchronization failed\n");
2354 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002355 default:
2356 ret = sprintf(buf, "Modem state is unknown\n");
2357 break;
matthieu castetb72458a2005-11-07 23:27:13 +01002358 }
2359out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002360 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002361 return ret;
2362}
2363
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002364static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO,
2365 read_human_status, NULL);
matthieu castetb72458a2005-11-07 23:27:13 +01002366
2367static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2368 char *buf)
2369{
2370 int ret = -ENODEV;
2371 struct uea_softc *sc;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002372 char *delin = "GOOD";
matthieu castetb72458a2005-11-07 23:27:13 +01002373
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002374 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002375 sc = dev_to_uea(dev);
2376 if (!sc)
2377 goto out;
2378
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002379 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2380 if (sc->stats.phy.flags & 0x4000)
2381 delin = "RESET";
2382 else if (sc->stats.phy.flags & 0x0001)
2383 delin = "LOSS";
2384 } else {
2385 if (sc->stats.phy.flags & 0x0C00)
2386 delin = "ERROR";
2387 else if (sc->stats.phy.flags & 0x0030)
2388 delin = "LOSS";
2389 }
2390
2391 ret = sprintf(buf, "%s\n", delin);
matthieu castetb72458a2005-11-07 23:27:13 +01002392out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002393 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002394 return ret;
2395}
2396
2397static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL);
2398
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002399#define UEA_ATTR(name, reset) \
matthieu castetb72458a2005-11-07 23:27:13 +01002400 \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002401static ssize_t read_##name(struct device *dev, \
matthieu castetb72458a2005-11-07 23:27:13 +01002402 struct device_attribute *attr, char *buf) \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002403{ \
2404 int ret = -ENODEV; \
2405 struct uea_softc *sc; \
2406 \
2407 mutex_lock(&uea_mutex); \
matthieu castetb72458a2005-11-07 23:27:13 +01002408 sc = dev_to_uea(dev); \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002409 if (!sc) \
2410 goto out; \
matthieu castetb72458a2005-11-07 23:27:13 +01002411 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2412 if (reset) \
2413 sc->stats.phy.name = 0; \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002414out: \
2415 mutex_unlock(&uea_mutex); \
2416 return ret; \
2417} \
matthieu castetb72458a2005-11-07 23:27:13 +01002418 \
2419static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2420
2421UEA_ATTR(mflags, 1);
2422UEA_ATTR(vidcpe, 0);
2423UEA_ATTR(usrate, 0);
2424UEA_ATTR(dsrate, 0);
2425UEA_ATTR(usattenuation, 0);
2426UEA_ATTR(dsattenuation, 0);
2427UEA_ATTR(usmargin, 0);
2428UEA_ATTR(dsmargin, 0);
2429UEA_ATTR(txflow, 0);
2430UEA_ATTR(rxflow, 0);
2431UEA_ATTR(uscorr, 0);
2432UEA_ATTR(dscorr, 0);
2433UEA_ATTR(usunc, 0);
2434UEA_ATTR(dsunc, 0);
matthieu casteta7a0c9c2006-10-03 21:44:11 +02002435UEA_ATTR(firmid, 0);
matthieu castetb72458a2005-11-07 23:27:13 +01002436
2437/* Retrieve the device End System Identifier (MAC) */
2438
2439#define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
2440static int uea_getesi(struct uea_softc *sc, u_char * esi)
2441{
2442 unsigned char mac_str[2 * ETH_ALEN + 1];
2443 int i;
2444 if (usb_string
2445 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
2446 sizeof(mac_str)) != 2 * ETH_ALEN)
2447 return 1;
2448
2449 for (i = 0; i < ETH_ALEN; i++)
2450 esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]);
2451
2452 return 0;
2453}
2454
2455/* ATM stuff */
2456static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
2457{
2458 struct uea_softc *sc = usbatm->driver_data;
2459
2460 return uea_getesi(sc, atm_dev->esi);
2461}
2462
2463static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
2464{
2465 struct uea_softc *sc = usbatm->driver_data;
2466
matthieu castet531a39b2006-10-03 21:49:29 +02002467 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002468
2469 return 0;
2470
2471}
2472
2473static int claim_interface(struct usb_device *usb_dev,
2474 struct usbatm_data *usbatm, int ifnum)
2475{
2476 int ret;
2477 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
2478
2479 if (!intf) {
2480 uea_err(usb_dev, "interface %d not found\n", ifnum);
2481 return -ENODEV;
2482 }
2483
2484 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
2485 if (ret != 0)
2486 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
2487 ret);
2488 return ret;
2489}
2490
Greg Kroah-Hartmane7ccdfe2006-08-28 11:43:25 -07002491static struct attribute *attrs[] = {
2492 &dev_attr_stat_status.attr,
2493 &dev_attr_stat_mflags.attr,
2494 &dev_attr_stat_human_status.attr,
2495 &dev_attr_stat_delin.attr,
2496 &dev_attr_stat_vidcpe.attr,
2497 &dev_attr_stat_usrate.attr,
2498 &dev_attr_stat_dsrate.attr,
2499 &dev_attr_stat_usattenuation.attr,
2500 &dev_attr_stat_dsattenuation.attr,
2501 &dev_attr_stat_usmargin.attr,
2502 &dev_attr_stat_dsmargin.attr,
2503 &dev_attr_stat_txflow.attr,
2504 &dev_attr_stat_rxflow.attr,
2505 &dev_attr_stat_uscorr.attr,
2506 &dev_attr_stat_dscorr.attr,
2507 &dev_attr_stat_usunc.attr,
2508 &dev_attr_stat_dsunc.attr,
matthieu casteta7a0c9c2006-10-03 21:44:11 +02002509 &dev_attr_stat_firmid.attr,
matthieu castet9ab99c82006-10-11 14:20:56 -07002510 NULL,
Greg Kroah-Hartmane7ccdfe2006-08-28 11:43:25 -07002511};
2512static struct attribute_group attr_grp = {
2513 .attrs = attrs,
2514};
2515
matthieu castetb72458a2005-11-07 23:27:13 +01002516static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
Duncan Sands35644b02006-01-17 11:16:13 +01002517 const struct usb_device_id *id)
matthieu castetb72458a2005-11-07 23:27:13 +01002518{
2519 struct usb_device *usb = interface_to_usbdev(intf);
2520 struct uea_softc *sc;
2521 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002522 unsigned int alt;
matthieu castetb72458a2005-11-07 23:27:13 +01002523
2524 uea_enters(usb);
2525
2526 /* interface 0 is for firmware/monitoring */
2527 if (ifnum != UEA_INTR_IFACE_NO)
2528 return -ENODEV;
2529
Duncan Sands0dfcd3e2006-01-13 09:36:20 +01002530 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
matthieu castetb72458a2005-11-07 23:27:13 +01002531
2532 /* interface 1 is for outbound traffic */
2533 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
2534 if (ret < 0)
2535 return ret;
2536
matthieu castete40abaf2006-01-18 07:38:37 +01002537 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
matthieu castetb72458a2005-11-07 23:27:13 +01002538 if (UEA_CHIP_VERSION(id) != ADI930) {
2539 /* interface 2 is for inbound traffic */
2540 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
2541 if (ret < 0)
2542 return ret;
2543 }
2544
2545 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
2546 if (!sc) {
matthieu castet584958c2006-04-02 18:44:48 +02002547 uea_err(usb, "uea_init: not enough memory !\n");
matthieu castetb72458a2005-11-07 23:27:13 +01002548 return -ENOMEM;
2549 }
2550
2551 sc->usb_dev = usb;
2552 usbatm->driver_data = sc;
2553 sc->usbatm = usbatm;
2554 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
2555 sc->driver_info = id->driver_info;
2556
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002557 /* first try to use module parameter */
2558 if (annex[sc->modem_index] == 1)
2559 sc->annex = ANNEXA;
2560 else if (annex[sc->modem_index] == 2)
2561 sc->annex = ANNEXB;
2562 /* try to autodetect annex */
2563 else if (sc->driver_info & AUTO_ANNEX_A)
2564 sc->annex = ANNEXA;
2565 else if (sc->driver_info & AUTO_ANNEX_B)
2566 sc->annex = ANNEXB;
2567 else
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002568 sc->annex = (le16_to_cpu
2569 (sc->usb_dev->descriptor.bcdDevice) & 0x80) ? ANNEXB : ANNEXA;
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002570
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002571 alt = altsetting[sc->modem_index];
matthieu castet3c9666c2006-01-18 07:38:19 +01002572 /* ADI930 don't support iso */
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002573 if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002574 if (alt <= 8 &&
2575 usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) {
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002576 uea_dbg(usb, "set alternate %u for 2 interface\n", alt);
matthieu castet3c9666c2006-01-18 07:38:19 +01002577 uea_info(usb, "using iso mode\n");
2578 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
2579 } else {
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002580 uea_err(usb, "setting alternate %u failed for "
2581 "2 interface, using bulk mode\n", alt);
matthieu castet3c9666c2006-01-18 07:38:19 +01002582 }
2583 }
2584
matthieu castet9ab99c82006-10-11 14:20:56 -07002585 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
2586 if (ret < 0)
2587 goto error;
2588
matthieu castetb72458a2005-11-07 23:27:13 +01002589 ret = uea_boot(sc);
matthieu castet9ab99c82006-10-11 14:20:56 -07002590 if (ret < 0)
Stanislaw Gruszka4c132e72007-08-20 23:20:49 +02002591 goto error_rm_grp;
matthieu castetb72458a2005-11-07 23:27:13 +01002592
matthieu castetb72458a2005-11-07 23:27:13 +01002593 return 0;
Stanislaw Gruszka4c132e72007-08-20 23:20:49 +02002594
2595error_rm_grp:
2596 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
matthieu castet9ab99c82006-10-11 14:20:56 -07002597error:
2598 kfree(sc);
2599 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01002600}
2601
2602static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
2603{
2604 struct uea_softc *sc = usbatm->driver_data;
2605
matthieu castet9ab99c82006-10-11 14:20:56 -07002606 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
matthieu castetb72458a2005-11-07 23:27:13 +01002607 uea_stop(sc);
2608 kfree(sc);
2609}
2610
2611static struct usbatm_driver uea_usbatm_driver = {
2612 .driver_name = "ueagle-atm",
matthieu castetb72458a2005-11-07 23:27:13 +01002613 .bind = uea_bind,
2614 .atm_start = uea_atm_open,
2615 .unbind = uea_unbind,
2616 .heavy_init = uea_heavy,
Duncan Sands80aae7a2006-01-13 10:59:23 +01002617 .bulk_in = UEA_BULK_DATA_PIPE,
2618 .bulk_out = UEA_BULK_DATA_PIPE,
matthieu castet3c9666c2006-01-18 07:38:19 +01002619 .isoc_in = UEA_ISO_DATA_PIPE,
matthieu castetb72458a2005-11-07 23:27:13 +01002620};
2621
2622static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2623{
2624 struct usb_device *usb = interface_to_usbdev(intf);
2625
2626 uea_enters(usb);
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002627 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2628 le16_to_cpu(usb->descriptor.idVendor),
2629 le16_to_cpu(usb->descriptor.idProduct),
2630 le16_to_cpu(usb->descriptor.bcdDevice),
2631 chip_name[UEA_CHIP_VERSION(id)]);
matthieu castetb72458a2005-11-07 23:27:13 +01002632
2633 usb_reset_device(usb);
2634
2635 if (UEA_IS_PREFIRM(id))
2636 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2637
2638 return usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2639}
2640
2641static void uea_disconnect(struct usb_interface *intf)
2642{
2643 struct usb_device *usb = interface_to_usbdev(intf);
2644 int ifnum = intf->altsetting->desc.bInterfaceNumber;
2645 uea_enters(usb);
2646
2647 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2648 * Pre-firmware device has one interface
2649 */
2650 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002651 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002652 usbatm_usb_disconnect(intf);
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002653 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002654 uea_info(usb, "ADSL device removed\n");
2655 }
2656
2657 uea_leaves(usb);
2658}
2659
2660/*
2661 * List of supported VID/PID
2662 */
2663static const struct usb_device_id uea_ids[] = {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002664 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM),
2665 .driver_info = ADI930 | PREFIRM},
2666 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM),
2667 .driver_info = ADI930 | PSTFIRM},
2668 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM),
2669 .driver_info = EAGLE_I | PREFIRM},
2670 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM),
2671 .driver_info = EAGLE_I | PSTFIRM},
2672 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM),
2673 .driver_info = EAGLE_II | PREFIRM},
2674 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM),
2675 .driver_info = EAGLE_II | PSTFIRM},
2676 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM),
2677 .driver_info = EAGLE_II | PREFIRM},
2678 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM),
2679 .driver_info = EAGLE_II | PSTFIRM},
2680 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM),
2681 .driver_info = EAGLE_III | PREFIRM},
2682 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM),
2683 .driver_info = EAGLE_III | PSTFIRM},
2684 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM),
2685 .driver_info = EAGLE_IV | PREFIRM},
2686 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM),
2687 .driver_info = EAGLE_IV | PSTFIRM},
2688 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM),
2689 .driver_info = EAGLE_I | PREFIRM},
2690 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM),
2691 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2692 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM),
2693 .driver_info = EAGLE_I | PREFIRM},
2694 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM),
2695 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2696 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM),
2697 .driver_info = EAGLE_II | PREFIRM},
2698 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM),
2699 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A},
2700 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM),
2701 .driver_info = EAGLE_II | PREFIRM},
2702 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM),
2703 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B},
2704 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM),
2705 .driver_info = ADI930 | PREFIRM},
2706 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM),
2707 .driver_info = ADI930 | PSTFIRM},
2708 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM),
2709 .driver_info = ADI930 | PREFIRM},
2710 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM),
2711 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A},
2712 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM),
2713 .driver_info = ADI930 | PREFIRM},
2714 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM),
2715 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B},
2716 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM),
2717 .driver_info = EAGLE_I | PREFIRM},
2718 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM),
2719 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2720 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM),
2721 .driver_info = EAGLE_I | PREFIRM},
2722 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM),
2723 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2724 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),
2725 .driver_info = EAGLE_I | PREFIRM},
2726 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),
2727 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2728 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),
2729 .driver_info = EAGLE_I | PREFIRM},
2730 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),
2731 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
matthieu castetb72458a2005-11-07 23:27:13 +01002732 {}
2733};
2734
2735/*
2736 * USB driver descriptor
2737 */
2738static struct usb_driver uea_driver = {
matthieu castetb72458a2005-11-07 23:27:13 +01002739 .name = "ueagle-atm",
2740 .id_table = uea_ids,
2741 .probe = uea_probe,
2742 .disconnect = uea_disconnect,
2743};
2744
2745MODULE_DEVICE_TABLE(usb, uea_ids);
2746
2747/**
2748 * uea_init - Initialize the module.
2749 * Register to USB subsystem
2750 */
2751static int __init uea_init(void)
2752{
2753 printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n");
2754
2755 usb_register(&uea_driver);
2756
2757 return 0;
2758}
2759
2760module_init(uea_init);
2761
2762/**
2763 * uea_exit - Destroy module
2764 * Deregister with USB subsystem
2765 */
2766static void __exit uea_exit(void)
2767{
2768 /*
2769 * This calls automatically the uea_disconnect method if necessary:
2770 */
2771 usb_deregister(&uea_driver);
2772
2773 printk(KERN_INFO "[ueagle-atm] driver unloaded\n");
2774}
2775
2776module_exit(uea_exit);
2777
2778MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2779MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2780MODULE_LICENSE("Dual BSD/GPL");