blob: e213d3fa4920a22d261d7113089b2759a011cad1 [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
578/* Firmware loading */
579#define LOAD_INTERNAL 0xA0
580#define F8051_USBCS 0x7f92
581
582/**
583 * uea_send_modem_cmd - Send a command for pre-firmware devices.
584 */
585static int uea_send_modem_cmd(struct usb_device *usb,
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100586 u16 addr, u16 size, const u8 *buff)
matthieu castetb72458a2005-11-07 23:27:13 +0100587{
588 int ret = -ENOMEM;
589 u8 *xfer_buff;
590
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +0200591 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +0100592 if (xfer_buff) {
matthieu castetb72458a2005-11-07 23:27:13 +0100593 ret = usb_control_msg(usb,
594 usb_sndctrlpipe(usb, 0),
595 LOAD_INTERNAL,
596 USB_DIR_OUT | USB_TYPE_VENDOR |
597 USB_RECIP_DEVICE, addr, 0, xfer_buff,
598 size, CTRL_TIMEOUT);
599 kfree(xfer_buff);
600 }
601
602 if (ret < 0)
603 return ret;
604
605 return (ret == size) ? 0 : -EIO;
606}
607
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200608static void uea_upload_pre_firmware(const struct firmware *fw_entry,
609 void *context)
matthieu castetb72458a2005-11-07 23:27:13 +0100610{
611 struct usb_device *usb = context;
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100612 const u8 *pfw;
613 u8 value;
matthieu castetb72458a2005-11-07 23:27:13 +0100614 u32 crc = 0;
615 int ret, size;
616
617 uea_enters(usb);
618 if (!fw_entry) {
619 uea_err(usb, "firmware is not available\n");
620 goto err;
621 }
622
623 pfw = fw_entry->data;
624 size = fw_entry->size;
matthieu castet8d7802e2005-11-08 00:02:30 +0100625 if (size < 4)
626 goto err_fw_corrupted;
matthieu castetb72458a2005-11-07 23:27:13 +0100627
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700628 crc = get_unaligned_le32(pfw);
matthieu castetb72458a2005-11-07 23:27:13 +0100629 pfw += 4;
630 size -= 4;
matthieu castet8d7802e2005-11-08 00:02:30 +0100631 if (crc32_be(0, pfw, size) != crc)
632 goto err_fw_corrupted;
matthieu castetb72458a2005-11-07 23:27:13 +0100633
634 /*
Nick Andrew877d0312009-01-26 11:06:57 +0100635 * Start to upload firmware : send reset
matthieu castetb72458a2005-11-07 23:27:13 +0100636 */
637 value = 1;
638 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
639
640 if (ret < 0) {
641 uea_err(usb, "modem reset failed with error %d\n", ret);
642 goto err;
643 }
644
matthieu castet8d7802e2005-11-08 00:02:30 +0100645 while (size > 3) {
matthieu castetb72458a2005-11-07 23:27:13 +0100646 u8 len = FW_GET_BYTE(pfw);
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700647 u16 add = get_unaligned_le16(pfw + 1);
matthieu castet8d7802e2005-11-08 00:02:30 +0100648
649 size -= len + 3;
650 if (size < 0)
651 goto err_fw_corrupted;
652
matthieu castetb72458a2005-11-07 23:27:13 +0100653 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
654 if (ret < 0) {
655 uea_err(usb, "uploading firmware data failed "
656 "with error %d\n", ret);
657 goto err;
658 }
659 pfw += len + 3;
matthieu castetb72458a2005-11-07 23:27:13 +0100660 }
661
matthieu castet8d7802e2005-11-08 00:02:30 +0100662 if (size != 0)
663 goto err_fw_corrupted;
664
matthieu castetb72458a2005-11-07 23:27:13 +0100665 /*
666 * Tell the modem we finish : de-assert reset
667 */
668 value = 0;
669 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
670 if (ret < 0)
671 uea_err(usb, "modem de-assert failed with error %d\n", ret);
672 else
673 uea_info(usb, "firmware uploaded\n");
674
Johannes Berg9ebfbd42009-10-29 12:36:02 +0100675 goto err;
matthieu castet8d7802e2005-11-08 00:02:30 +0100676
677err_fw_corrupted:
678 uea_err(usb, "firmware is corrupted\n");
matthieu castetb72458a2005-11-07 23:27:13 +0100679err:
Johannes Berg9ebfbd42009-10-29 12:36:02 +0100680 release_firmware(fw_entry);
matthieu castetb72458a2005-11-07 23:27:13 +0100681 uea_leaves(usb);
682}
683
684/**
685 * uea_load_firmware - Load usb firmware for pre-firmware devices.
686 */
687static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
688{
689 int ret;
690 char *fw_name = FW_DIR "eagle.fw";
691
692 uea_enters(usb);
693 uea_info(usb, "pre-firmware device, uploading firmware\n");
694
695 switch (ver) {
696 case ADI930:
697 fw_name = FW_DIR "adi930.fw";
698 break;
699 case EAGLE_I:
700 fw_name = FW_DIR "eagleI.fw";
701 break;
702 case EAGLE_II:
703 fw_name = FW_DIR "eagleII.fw";
704 break;
705 case EAGLE_III:
706 fw_name = FW_DIR "eagleIII.fw";
707 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200708 case EAGLE_IV:
709 fw_name = FW_DIR "eagleIV.fw";
710 break;
matthieu castetb72458a2005-11-07 23:27:13 +0100711 }
712
Johannes Berg9ebfbd42009-10-29 12:36:02 +0100713 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev,
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200714 GFP_KERNEL, usb,
715 uea_upload_pre_firmware);
matthieu castetb72458a2005-11-07 23:27:13 +0100716 if (ret)
717 uea_err(usb, "firmware %s is not available\n", fw_name);
718 else
719 uea_info(usb, "loading firmware %s\n", fw_name);
720
721 uea_leaves(usb);
722 return ret;
723}
724
725/* modem management : dsp firmware, send/read CMV, monitoring statistic
726 */
727
728/*
729 * Make sure that the DSP code provided is safe to use.
730 */
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100731static int check_dsp_e1(const u8 *dsp, unsigned int len)
matthieu castetb72458a2005-11-07 23:27:13 +0100732{
733 u8 pagecount, blockcount;
734 u16 blocksize;
735 u32 pageoffset;
736 unsigned int i, j, p, pp;
737
matthieu castetb72458a2005-11-07 23:27:13 +0100738 pagecount = FW_GET_BYTE(dsp);
739 p = 1;
740
741 /* enough space for page offsets? */
742 if (p + 4 * pagecount > len)
743 return 1;
744
745 for (i = 0; i < pagecount; i++) {
746
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700747 pageoffset = get_unaligned_le32(dsp + p);
matthieu castetb72458a2005-11-07 23:27:13 +0100748 p += 4;
749
750 if (pageoffset == 0)
751 continue;
752
753 /* enough space for blockcount? */
754 if (pageoffset >= len)
755 return 1;
756
757 pp = pageoffset;
758 blockcount = FW_GET_BYTE(dsp + pp);
759 pp += 1;
760
761 for (j = 0; j < blockcount; j++) {
762
763 /* enough space for block header? */
764 if (pp + 4 > len)
765 return 1;
766
767 pp += 2; /* skip blockaddr */
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700768 blocksize = get_unaligned_le16(dsp + pp);
matthieu castetb72458a2005-11-07 23:27:13 +0100769 pp += 2;
770
771 /* enough space for block data? */
772 if (pp + blocksize > len)
773 return 1;
774
775 pp += blocksize;
776 }
777 }
778
779 return 0;
780}
781
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100782static int check_dsp_e4(const u8 *dsp, int len)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200783{
784 int i;
785 struct l1_code *p = (struct l1_code *) dsp;
786 unsigned int sum = p->code - dsp;
787
788 if (len < sum)
789 return 1;
790
791 if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 &&
792 strcmp("STRATIPHY ANEXB", p->string_header) != 0)
793 return 1;
794
795 for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) {
796 struct block_index *blockidx;
797 u8 blockno = p->page_number_to_block_index[i];
798 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
799 continue;
800
801 do {
802 u64 l;
803
804 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
805 return 1;
806
807 blockidx = &p->page_header[blockno++];
808 if ((u8 *)(blockidx + 1) - dsp >= len)
809 return 1;
810
811 if (le16_to_cpu(blockidx->PageNumber) != i)
812 return 1;
813
814 l = E4_PAGE_BYTES(blockidx->PageSize);
815 sum += l;
816 l += le32_to_cpu(blockidx->PageOffset);
817 if (l > len)
818 return 1;
819
820 /* zero is zero regardless endianes */
821 } while (blockidx->NotLastBlock);
822 }
823
824 return (sum == len) ? 0 : 1;
825}
826
matthieu castetb72458a2005-11-07 23:27:13 +0100827/*
828 * send data to the idma pipe
829 * */
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100830static int uea_idma_write(struct uea_softc *sc, const void *data, u32 size)
matthieu castetb72458a2005-11-07 23:27:13 +0100831{
832 int ret = -ENOMEM;
833 u8 *xfer_buff;
834 int bytes_read;
835
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +0200836 xfer_buff = kmemdup(data, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +0100837 if (!xfer_buff) {
838 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
839 return ret;
840 }
841
matthieu castetb72458a2005-11-07 23:27:13 +0100842 ret = usb_bulk_msg(sc->usb_dev,
843 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
844 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
845
846 kfree(xfer_buff);
847 if (ret < 0)
848 return ret;
849 if (size != bytes_read) {
850 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
851 bytes_read);
852 return -EIO;
853 }
854
855 return 0;
856}
857
858static int request_dsp(struct uea_softc *sc)
859{
860 int ret;
861 char *dsp_name;
862
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200863 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200864 if (IS_ISDN(sc))
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200865 dsp_name = FW_DIR "DSP4i.bin";
866 else
867 dsp_name = FW_DIR "DSP4p.bin";
868 } else if (UEA_CHIP_VERSION(sc) == ADI930) {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200869 if (IS_ISDN(sc))
matthieu castetb72458a2005-11-07 23:27:13 +0100870 dsp_name = FW_DIR "DSP9i.bin";
871 else
872 dsp_name = FW_DIR "DSP9p.bin";
873 } else {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200874 if (IS_ISDN(sc))
matthieu castetb72458a2005-11-07 23:27:13 +0100875 dsp_name = FW_DIR "DSPei.bin";
876 else
877 dsp_name = FW_DIR "DSPep.bin";
878 }
879
matthieu castete40abaf2006-01-18 07:38:37 +0100880 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
matthieu castetb72458a2005-11-07 23:27:13 +0100881 if (ret < 0) {
882 uea_err(INS_TO_USBDEV(sc),
883 "requesting firmware %s failed with error %d\n",
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200884 dsp_name, ret);
matthieu castetb72458a2005-11-07 23:27:13 +0100885 return ret;
886 }
887
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200888 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
889 ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size);
890 else
891 ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size);
892
893 if (ret) {
matthieu castetb72458a2005-11-07 23:27:13 +0100894 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
895 dsp_name);
896 release_firmware(sc->dsp_firm);
897 sc->dsp_firm = NULL;
898 return -EILSEQ;
899 }
900
901 return 0;
902}
903
904/*
905 * The uea_load_page() function must be called within a process context
906 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200907static void uea_load_page_e1(struct work_struct *work)
matthieu castetb72458a2005-11-07 23:27:13 +0100908{
David Howellsc4028952006-11-22 14:57:56 +0000909 struct uea_softc *sc = container_of(work, struct uea_softc, task);
matthieu castetb72458a2005-11-07 23:27:13 +0100910 u16 pageno = sc->pageno;
911 u16 ovl = sc->ovl;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200912 struct block_info_e1 bi;
matthieu castetb72458a2005-11-07 23:27:13 +0100913
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100914 const u8 *p;
matthieu castetb72458a2005-11-07 23:27:13 +0100915 u8 pagecount, blockcount;
916 u16 blockaddr, blocksize;
917 u32 pageoffset;
918 int i;
919
920 /* reload firmware when reboot start and it's loaded already */
921 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
922 release_firmware(sc->dsp_firm);
923 sc->dsp_firm = NULL;
924 }
925
926 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
927 return;
928
929 p = sc->dsp_firm->data;
930 pagecount = FW_GET_BYTE(p);
931 p += 1;
932
933 if (pageno >= pagecount)
934 goto bad1;
935
936 p += 4 * pageno;
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700937 pageoffset = get_unaligned_le32(p);
matthieu castetb72458a2005-11-07 23:27:13 +0100938
939 if (pageoffset == 0)
940 goto bad1;
941
942 p = sc->dsp_firm->data + pageoffset;
943 blockcount = FW_GET_BYTE(p);
944 p += 1;
945
946 uea_dbg(INS_TO_USBDEV(sc),
947 "sending %u blocks for DSP page %u\n", blockcount, pageno);
948
949 bi.wHdr = cpu_to_le16(UEA_BIHDR);
950 bi.wOvl = cpu_to_le16(ovl);
951 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
952
953 for (i = 0; i < blockcount; i++) {
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700954 blockaddr = get_unaligned_le16(p);
matthieu castetb72458a2005-11-07 23:27:13 +0100955 p += 2;
956
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700957 blocksize = get_unaligned_le16(p);
matthieu castetb72458a2005-11-07 23:27:13 +0100958 p += 2;
959
960 bi.wSize = cpu_to_le16(blocksize);
961 bi.wAddress = cpu_to_le16(blockaddr);
962 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
963
964 /* send block info through the IDMA pipe */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200965 if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE))
matthieu castetb72458a2005-11-07 23:27:13 +0100966 goto bad2;
967
968 /* send block data through the IDMA pipe */
969 if (uea_idma_write(sc, p, blocksize))
970 goto bad2;
971
972 p += blocksize;
973 }
974
975 return;
976
977bad2:
978 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
979 return;
980bad1:
matthieu castet2a99b502006-04-02 18:43:53 +0200981 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
matthieu castetb72458a2005-11-07 23:27:13 +0100982}
983
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200984static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
985{
986 struct block_info_e4 bi;
987 struct block_index *blockidx;
988 struct l1_code *p = (struct l1_code *) sc->dsp_firm->data;
989 u8 blockno = p->page_number_to_block_index[pageno];
990
991 bi.wHdr = cpu_to_be16(UEA_BIHDR);
992 bi.bBootPage = boot;
993 bi.bPageNumber = pageno;
994 bi.wReserved = cpu_to_be16(UEA_RESERVED);
995
996 do {
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100997 const u8 *blockoffset;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200998 unsigned int blocksize;
999
1000 blockidx = &p->page_header[blockno];
1001 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001002 blockoffset = sc->dsp_firm->data + le32_to_cpu(
1003 blockidx->PageOffset);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001004
1005 bi.dwSize = cpu_to_be32(blocksize);
Al Virofd05e722008-04-28 07:00:16 +01001006 bi.dwAddress = cpu_to_be32(le32_to_cpu(blockidx->PageAddress));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001007
1008 uea_dbg(INS_TO_USBDEV(sc),
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001009 "sending block %u for DSP page "
1010 "%u size %u address %x\n",
1011 blockno, pageno, blocksize,
1012 le32_to_cpu(blockidx->PageAddress));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001013
1014 /* send block info through the IDMA pipe */
1015 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1016 goto bad;
1017
1018 /* send block data through the IDMA pipe */
1019 if (uea_idma_write(sc, blockoffset, blocksize))
1020 goto bad;
1021
1022 blockno++;
1023 } while (blockidx->NotLastBlock);
1024
1025 return;
1026
1027bad:
1028 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno);
1029 return;
1030}
1031
1032static void uea_load_page_e4(struct work_struct *work)
1033{
1034 struct uea_softc *sc = container_of(work, struct uea_softc, task);
1035 u8 pageno = sc->pageno;
1036 int i;
1037 struct block_info_e4 bi;
1038 struct l1_code *p;
1039
1040 uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
1041
1042 /* reload firmware when reboot start and it's loaded already */
1043 if (pageno == 0 && sc->dsp_firm) {
1044 release_firmware(sc->dsp_firm);
1045 sc->dsp_firm = NULL;
1046 }
1047
1048 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
1049 return;
1050
1051 p = (struct l1_code *) sc->dsp_firm->data;
Al Virofd05e722008-04-28 07:00:16 +01001052 if (pageno >= le16_to_cpu(p->page_header[0].PageNumber)) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001053 uea_err(INS_TO_USBDEV(sc), "invalid DSP "
1054 "page %u requested\n", pageno);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001055 return;
1056 }
1057
1058 if (pageno != 0) {
1059 __uea_load_page_e4(sc, pageno, 0);
1060 return;
1061 }
1062
1063 uea_dbg(INS_TO_USBDEV(sc),
1064 "sending Main DSP page %u\n", p->page_header[0].PageNumber);
1065
1066 for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) {
1067 if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize))
1068 __uea_load_page_e4(sc, i, 1);
1069 }
1070
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001071 uea_dbg(INS_TO_USBDEV(sc) , "sending start bi\n");
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001072
1073 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1074 bi.bBootPage = 0;
1075 bi.bPageNumber = 0xff;
1076 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1077 bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize));
Al Virofd05e722008-04-28 07:00:16 +01001078 bi.dwAddress = cpu_to_be32(le32_to_cpu(p->page_header[0].PageAddress));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001079
1080 /* send block info through the IDMA pipe */
1081 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1082 uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n");
1083}
1084
matthieu castetb72458a2005-11-07 23:27:13 +01001085static inline void wake_up_cmv_ack(struct uea_softc *sc)
1086{
matthieu castet2a99b502006-04-02 18:43:53 +02001087 BUG_ON(sc->cmv_ack);
matthieu castetb72458a2005-11-07 23:27:13 +01001088 sc->cmv_ack = 1;
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001089 wake_up(&sc->sync_q);
matthieu castetb72458a2005-11-07 23:27:13 +01001090}
1091
1092static inline int wait_cmv_ack(struct uea_softc *sc)
1093{
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001094 int ret = uea_wait(sc, sc->cmv_ack , ACK_TIMEOUT);
1095
matthieu castetb72458a2005-11-07 23:27:13 +01001096 sc->cmv_ack = 0;
1097
matthieu castet2a99b502006-04-02 18:43:53 +02001098 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
1099 jiffies_to_msecs(ret));
1100
matthieu castetb72458a2005-11-07 23:27:13 +01001101 if (ret < 0)
1102 return ret;
1103
1104 return (ret == 0) ? -ETIMEDOUT : 0;
matthieu castetb72458a2005-11-07 23:27:13 +01001105}
1106
1107#define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1108
1109static int uea_request(struct uea_softc *sc,
David Woodhouseaafcd2f2008-05-24 00:05:10 +01001110 u16 value, u16 index, u16 size, const void *data)
matthieu castetb72458a2005-11-07 23:27:13 +01001111{
1112 u8 *xfer_buff;
1113 int ret = -ENOMEM;
1114
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +02001115 xfer_buff = kmemdup(data, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +01001116 if (!xfer_buff) {
1117 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
1118 return ret;
1119 }
matthieu castetb72458a2005-11-07 23:27:13 +01001120
1121 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
1122 UCDC_SEND_ENCAPSULATED_COMMAND,
1123 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1124 value, index, xfer_buff, size, CTRL_TIMEOUT);
1125
1126 kfree(xfer_buff);
1127 if (ret < 0) {
1128 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
1129 return ret;
1130 }
1131
1132 if (ret != size) {
1133 uea_err(INS_TO_USBDEV(sc),
1134 "usb_control_msg send only %d bytes (instead of %d)\n",
1135 ret, size);
1136 return -EIO;
1137 }
1138
1139 return 0;
1140}
1141
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001142static int uea_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001143 u8 function, u32 address, u16 offset, u32 data)
1144{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001145 struct cmv_e1 cmv;
matthieu castetb72458a2005-11-07 23:27:13 +01001146 int ret;
1147
matthieu castet2a99b502006-04-02 18:43:53 +02001148 uea_enters(INS_TO_USBDEV(sc));
1149 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1150 "offset : 0x%04x, data : 0x%08x\n",
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001151 E1_FUNCTION_TYPE(function),
1152 E1_FUNCTION_SUBTYPE(function),
1153 E1_GETSA1(address), E1_GETSA2(address),
1154 E1_GETSA3(address),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001155 E1_GETSA4(address), offset, data);
matthieu castetb72458a2005-11-07 23:27:13 +01001156
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001157 /* we send a request, but we expect a reply */
1158 sc->cmv_dsc.e1.function = function | 0x2;
1159 sc->cmv_dsc.e1.idx++;
1160 sc->cmv_dsc.e1.address = address;
1161 sc->cmv_dsc.e1.offset = offset;
1162
1163 cmv.wPreamble = cpu_to_le16(E1_PREAMBLE);
1164 cmv.bDirection = E1_HOSTTOMODEM;
matthieu castetb72458a2005-11-07 23:27:13 +01001165 cmv.bFunction = function;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001166 cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx);
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001167 put_unaligned_le32(address, &cmv.dwSymbolicAddress);
matthieu castetb72458a2005-11-07 23:27:13 +01001168 cmv.wOffsetAddress = cpu_to_le16(offset);
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001169 put_unaligned_le32(data >> 16 | data << 16, &cmv.dwData);
matthieu castetb72458a2005-11-07 23:27:13 +01001170
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001171 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START,
1172 sizeof(cmv), &cmv);
matthieu castetb72458a2005-11-07 23:27:13 +01001173 if (ret < 0)
1174 return ret;
matthieu castet2a99b502006-04-02 18:43:53 +02001175 ret = wait_cmv_ack(sc);
1176 uea_leaves(INS_TO_USBDEV(sc));
1177 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001178}
1179
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001180static int uea_cmv_e4(struct uea_softc *sc,
1181 u16 function, u16 group, u16 address, u16 offset, u32 data)
1182{
1183 struct cmv_e4 cmv;
1184 int ret;
1185
1186 uea_enters(INS_TO_USBDEV(sc));
1187 memset(&cmv, 0, sizeof(cmv));
1188
1189 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
1190 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1191 E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function),
1192 group, address, offset, data);
1193
1194 /* we send a request, but we expect a reply */
1195 sc->cmv_dsc.e4.function = function | (0x1 << 4);
1196 sc->cmv_dsc.e4.offset = offset;
1197 sc->cmv_dsc.e4.address = address;
1198 sc->cmv_dsc.e4.group = group;
1199
1200 cmv.wFunction = cpu_to_be16(function);
1201 cmv.wGroup = cpu_to_be16(group);
1202 cmv.wAddress = cpu_to_be16(address);
1203 cmv.wOffset = cpu_to_be16(offset);
1204 cmv.dwData[0] = cpu_to_be32(data);
1205
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001206 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START,
1207 sizeof(cmv), &cmv);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001208 if (ret < 0)
1209 return ret;
1210 ret = wait_cmv_ack(sc);
1211 uea_leaves(INS_TO_USBDEV(sc));
1212 return ret;
1213}
1214
1215static inline int uea_read_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001216 u32 address, u16 offset, u32 *data)
1217{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001218 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD),
matthieu castetb72458a2005-11-07 23:27:13 +01001219 address, offset, 0);
1220 if (ret < 0)
1221 uea_err(INS_TO_USBDEV(sc),
1222 "reading cmv failed with error %d\n", ret);
1223 else
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001224 *data = sc->data;
matthieu castetb72458a2005-11-07 23:27:13 +01001225
1226 return ret;
1227}
1228
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001229static inline int uea_read_cmv_e4(struct uea_softc *sc,
1230 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1231{
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001232 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1233 E4_REQUESTREAD, size),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001234 group, address, offset, 0);
1235 if (ret < 0)
1236 uea_err(INS_TO_USBDEV(sc),
1237 "reading cmv failed with error %d\n", ret);
1238 else {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001239 *data = sc->data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001240 /* size is in 16-bit word quantities */
1241 if (size > 2)
1242 *(data + 1) = sc->data1;
1243 }
1244 return ret;
1245}
1246
1247static inline int uea_write_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001248 u32 address, u16 offset, u32 data)
1249{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001250 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE),
matthieu castetb72458a2005-11-07 23:27:13 +01001251 address, offset, data);
1252 if (ret < 0)
1253 uea_err(INS_TO_USBDEV(sc),
1254 "writing cmv failed with error %d\n", ret);
1255
1256 return ret;
1257}
1258
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001259static inline int uea_write_cmv_e4(struct uea_softc *sc,
1260 u8 size, u16 group, u16 address, u16 offset, u32 data)
1261{
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001262 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1263 E4_REQUESTWRITE, size),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001264 group, address, offset, data);
1265 if (ret < 0)
1266 uea_err(INS_TO_USBDEV(sc),
1267 "writing cmv failed with error %d\n", ret);
1268
1269 return ret;
1270}
1271
1272static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1273{
1274 int ret;
1275 u16 timeout;
1276
1277 /* in bulk mode the modem have problem with high rate
1278 * changing internal timing could improve things, but the
1279 * value is misterious.
1280 * ADI930 don't support it (-EPIPE error).
1281 */
1282
1283 if (UEA_CHIP_VERSION(sc) == ADI930 ||
Stanislaw Gruszka503add42007-08-20 23:21:06 +02001284 altsetting[sc->modem_index] > 0 ||
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001285 sc->stats.phy.dsrate == dsrate)
1286 return;
1287
1288 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1289 timeout = (dsrate <= 1024*1024) ? 0 : 1;
1290 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
1291 uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n",
1292 timeout, ret < 0 ? " failed" : "");
1293
1294}
1295
matthieu castetb72458a2005-11-07 23:27:13 +01001296/*
1297 * Monitor the modem and update the stat
1298 * return 0 if everything is ok
1299 * return < 0 if an error occurs (-EAGAIN reboot needed)
1300 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001301static int uea_stat_e1(struct uea_softc *sc)
matthieu castetb72458a2005-11-07 23:27:13 +01001302{
1303 u32 data;
1304 int ret;
1305
1306 uea_enters(INS_TO_USBDEV(sc));
1307 data = sc->stats.phy.state;
1308
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001309 ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state);
matthieu castetb72458a2005-11-07 23:27:13 +01001310 if (ret < 0)
1311 return ret;
1312
1313 switch (GET_STATUS(sc->stats.phy.state)) {
1314 case 0: /* not yet synchronized */
1315 uea_dbg(INS_TO_USBDEV(sc),
1316 "modem not yet synchronized\n");
1317 return 0;
1318
1319 case 1: /* initialization */
1320 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1321 return 0;
1322
1323 case 2: /* operational */
1324 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
1325 break;
1326
1327 case 3: /* fail ... */
matthieu casteta7a0c9c2006-10-03 21:44:11 +02001328 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001329 " (may be try other cmv/dsp)\n");
matthieu castetb72458a2005-11-07 23:27:13 +01001330 return -EAGAIN;
1331
1332 case 4 ... 6: /* test state */
1333 uea_warn(INS_TO_USBDEV(sc),
1334 "modem in test mode - not supported\n");
1335 return -EAGAIN;
1336
1337 case 7: /* fast-retain ... */
1338 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
1339 return 0;
1340 default:
1341 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
1342 GET_STATUS(sc->stats.phy.state));
1343 return -EAGAIN;
1344 }
1345
1346 if (GET_STATUS(data) != 2) {
1347 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1348 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1349
1350 /* release the dsp firmware as it is not needed until
1351 * the next failure
1352 */
1353 if (sc->dsp_firm) {
1354 release_firmware(sc->dsp_firm);
1355 sc->dsp_firm = NULL;
1356 }
matthieu castetb72458a2005-11-07 23:27:13 +01001357 }
1358
1359 /* always update it as atm layer could not be init when we switch to
1360 * operational state
1361 */
1362 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1363
1364 /* wake up processes waiting for synchronization */
1365 wake_up(&sc->sync_q);
1366
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001367 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags);
matthieu castetb72458a2005-11-07 23:27:13 +01001368 if (ret < 0)
1369 return ret;
1370 sc->stats.phy.mflags |= sc->stats.phy.flags;
1371
1372 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1373 * we check the status again in order to detect the failure earlier
1374 */
1375 if (sc->stats.phy.flags) {
matthieu castet2a99b502006-04-02 18:43:53 +02001376 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
matthieu castetb72458a2005-11-07 23:27:13 +01001377 sc->stats.phy.flags);
1378 return 0;
1379 }
1380
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001381 ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001382 if (ret < 0)
1383 return ret;
1384
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001385 uea_set_bulk_timeout(sc, (data >> 16) * 32);
matthieu castetb72458a2005-11-07 23:27:13 +01001386 sc->stats.phy.dsrate = (data >> 16) * 32;
1387 sc->stats.phy.usrate = (data & 0xffff) * 32;
1388 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1389
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001390 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001391 if (ret < 0)
1392 return ret;
1393 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
1394
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001395 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001396 if (ret < 0)
1397 return ret;
1398 sc->stats.phy.usattenuation = (data & 0xff) / 2;
1399
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001400 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin);
matthieu castetb72458a2005-11-07 23:27:13 +01001401 if (ret < 0)
1402 return ret;
1403
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001404 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin);
matthieu castetb72458a2005-11-07 23:27:13 +01001405 if (ret < 0)
1406 return ret;
1407
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001408 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow);
matthieu castetb72458a2005-11-07 23:27:13 +01001409 if (ret < 0)
1410 return ret;
1411
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001412 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow);
matthieu castetb72458a2005-11-07 23:27:13 +01001413 if (ret < 0)
1414 return ret;
1415
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001416 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc);
matthieu castetb72458a2005-11-07 23:27:13 +01001417 if (ret < 0)
1418 return ret;
1419
1420 /* only for atu-c */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001421 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc);
matthieu castetb72458a2005-11-07 23:27:13 +01001422 if (ret < 0)
1423 return ret;
1424
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001425 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr);
matthieu castetb72458a2005-11-07 23:27:13 +01001426 if (ret < 0)
1427 return ret;
1428
1429 /* only for atu-c */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001430 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr);
matthieu castetb72458a2005-11-07 23:27:13 +01001431 if (ret < 0)
1432 return ret;
1433
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001434 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 8, &sc->stats.phy.vidco);
matthieu castetb72458a2005-11-07 23:27:13 +01001435 if (ret < 0)
1436 return ret;
1437
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001438 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 13, &sc->stats.phy.vidcpe);
matthieu castetb72458a2005-11-07 23:27:13 +01001439 if (ret < 0)
1440 return ret;
1441
1442 return 0;
1443}
1444
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001445static int uea_stat_e4(struct uea_softc *sc)
matthieu castetb72458a2005-11-07 23:27:13 +01001446{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001447 u32 data;
1448 u32 tmp_arr[2];
1449 int ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001450
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001451 uea_enters(INS_TO_USBDEV(sc));
1452 data = sc->stats.phy.state;
1453
1454 /* XXX only need to be done before operationnal... */
1455 ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state);
1456 if (ret < 0)
1457 return ret;
1458
1459 switch (sc->stats.phy.state) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001460 case 0x0: /* not yet synchronized */
1461 case 0x1:
1462 case 0x3:
1463 case 0x4:
1464 uea_dbg(INS_TO_USBDEV(sc), "modem not yet "
1465 "synchronized\n");
1466 return 0;
1467 case 0x5: /* initialization */
1468 case 0x6:
1469 case 0x9:
1470 case 0xa:
1471 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1472 return 0;
1473 case 0x2: /* fail ... */
1474 uea_info(INS_TO_USBDEV(sc), "modem synchronization "
1475 "failed (may be try other cmv/dsp)\n");
1476 return -EAGAIN;
1477 case 0x7: /* operational */
1478 break;
1479 default:
1480 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n",
1481 sc->stats.phy.state);
1482 return 0;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001483 }
1484
1485 if (data != 7) {
1486 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1487 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1488
1489 /* release the dsp firmware as it is not needed until
1490 * the next failure
1491 */
1492 if (sc->dsp_firm) {
1493 release_firmware(sc->dsp_firm);
1494 sc->dsp_firm = NULL;
1495 }
1496 }
1497
1498 /* always update it as atm layer could not be init when we switch to
1499 * operational state
1500 */
1501 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1502
1503 /* wake up processes waiting for synchronization */
1504 wake_up(&sc->sync_q);
1505
1506 /* TODO improve this state machine :
1507 * we need some CMV info : what they do and their unit
1508 * we should find the equivalent of eagle3- CMV
1509 */
1510 /* check flags */
1511 ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags);
1512 if (ret < 0)
1513 return ret;
1514 sc->stats.phy.mflags |= sc->stats.phy.flags;
1515
1516 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1517 * we check the status again in order to detect the failure earlier
1518 */
1519 if (sc->stats.phy.flags) {
1520 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1521 sc->stats.phy.flags);
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001522 if (sc->stats.phy.flags & 1) /* delineation LOSS */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001523 return -EAGAIN;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001524 if (sc->stats.phy.flags & 0x4000) /* Reset Flag */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001525 return -EAGAIN;
1526 return 0;
1527 }
1528
1529 /* rate data may be in upper or lower half of 64 bit word, strange */
1530 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr);
1531 if (ret < 0)
1532 return ret;
1533 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1534 sc->stats.phy.usrate = data / 1000;
1535
1536 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr);
1537 if (ret < 0)
1538 return ret;
1539 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1540 uea_set_bulk_timeout(sc, data / 1000);
1541 sc->stats.phy.dsrate = data / 1000;
1542 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1543
1544 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data);
1545 if (ret < 0)
1546 return ret;
1547 sc->stats.phy.dsattenuation = data / 10;
1548
1549 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data);
1550 if (ret < 0)
1551 return ret;
1552 sc->stats.phy.usattenuation = data / 10;
1553
1554 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data);
1555 if (ret < 0)
1556 return ret;
1557 sc->stats.phy.dsmargin = data / 2;
1558
1559 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data);
1560 if (ret < 0)
1561 return ret;
1562 sc->stats.phy.usmargin = data / 10;
1563
1564 return 0;
1565}
1566
1567static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1568{
1569 char file_arr[] = "CMVxy.bin";
1570 char *file;
1571
1572 /* set proper name corresponding modem version and line type */
matthieu castetb72458a2005-11-07 23:27:13 +01001573 if (cmv_file[sc->modem_index] == NULL) {
1574 if (UEA_CHIP_VERSION(sc) == ADI930)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001575 file_arr[3] = '9';
1576 else if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1577 file_arr[3] = '4';
matthieu castetb72458a2005-11-07 23:27:13 +01001578 else
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001579 file_arr[3] = 'e';
1580
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02001581 file_arr[4] = IS_ISDN(sc) ? 'i' : 'p';
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001582 file = file_arr;
matthieu castetb72458a2005-11-07 23:27:13 +01001583 } else
1584 file = cmv_file[sc->modem_index];
1585
1586 strcpy(cmv_name, FW_DIR);
Samuel Ortizade901d2009-05-27 00:49:32 +02001587 strlcat(cmv_name, file, UEA_FW_NAME_MAX);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001588 if (ver == 2)
Samuel Ortizade901d2009-05-27 00:49:32 +02001589 strlcat(cmv_name, ".v2", UEA_FW_NAME_MAX);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001590}
matthieu castetb72458a2005-11-07 23:27:13 +01001591
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001592static int request_cmvs_old(struct uea_softc *sc,
1593 void **cmvs, const struct firmware **fw)
1594{
1595 int ret, size;
1596 u8 *data;
Samuel Ortizade901d2009-05-27 00:49:32 +02001597 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001598
1599 cmvs_file_name(sc, cmv_name, 1);
matthieu castetb72458a2005-11-07 23:27:13 +01001600 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1601 if (ret < 0) {
1602 uea_err(INS_TO_USBDEV(sc),
1603 "requesting firmware %s failed with error %d\n",
1604 cmv_name, ret);
1605 return ret;
1606 }
1607
1608 data = (u8 *) (*fw)->data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001609 size = (*fw)->size;
1610 if (size < 1)
1611 goto err_fw_corrupted;
1612
1613 if (size != *data * sizeof(struct uea_cmvs_v1) + 1)
1614 goto err_fw_corrupted;
1615
1616 *cmvs = (void *)(data + 1);
1617 return *data;
1618
1619err_fw_corrupted:
1620 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1621 release_firmware(*fw);
1622 return -EILSEQ;
1623}
1624
1625static int request_cmvs(struct uea_softc *sc,
1626 void **cmvs, const struct firmware **fw, int *ver)
1627{
1628 int ret, size;
1629 u32 crc;
1630 u8 *data;
Samuel Ortizade901d2009-05-27 00:49:32 +02001631 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001632
1633 cmvs_file_name(sc, cmv_name, 2);
1634 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1635 if (ret < 0) {
1636 /* if caller can handle old version, try to provide it */
1637 if (*ver == 1) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001638 uea_warn(INS_TO_USBDEV(sc), "requesting "
1639 "firmware %s failed, "
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001640 "try to get older cmvs\n", cmv_name);
1641 return request_cmvs_old(sc, cmvs, fw);
1642 }
1643 uea_err(INS_TO_USBDEV(sc),
1644 "requesting firmware %s failed with error %d\n",
1645 cmv_name, ret);
1646 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001647 }
1648
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001649 size = (*fw)->size;
1650 data = (u8 *) (*fw)->data;
1651 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1652 if (*ver == 1) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001653 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted,"
1654 " try to get older cmvs\n", cmv_name);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001655 release_firmware(*fw);
1656 return request_cmvs_old(sc, cmvs, fw);
1657 }
1658 goto err_fw_corrupted;
1659 }
1660
1661 *ver = 2;
1662
1663 data += 4;
1664 size -= 4;
1665 if (size < 5)
1666 goto err_fw_corrupted;
1667
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001668 crc = get_unaligned_le32(data);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001669 data += 4;
1670 size -= 4;
1671 if (crc32_be(0, data, size) != crc)
1672 goto err_fw_corrupted;
1673
1674 if (size != *data * sizeof(struct uea_cmvs_v2) + 1)
1675 goto err_fw_corrupted;
1676
1677 *cmvs = (void *) (data + 1);
matthieu castetb72458a2005-11-07 23:27:13 +01001678 return *data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001679
1680err_fw_corrupted:
1681 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1682 release_firmware(*fw);
1683 return -EILSEQ;
1684}
1685
1686static int uea_send_cmvs_e1(struct uea_softc *sc)
1687{
1688 int i, ret, len;
1689 void *cmvs_ptr;
1690 const struct firmware *cmvs_fw;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001691 int ver = 1; /* we can handle v1 cmv firmware version; */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001692
1693 /* Enter in R-IDLE (cmv) until instructed otherwise */
1694 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
1695 if (ret < 0)
1696 return ret;
1697
1698 /* Dump firmware version */
1699 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid);
1700 if (ret < 0)
1701 return ret;
1702 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1703 sc->stats.phy.firmid);
1704
1705 /* get options */
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001706 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001707 if (ret < 0)
1708 return ret;
1709
1710 /* send options */
1711 if (ver == 1) {
1712 struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr;
1713
1714 uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, "
1715 "please update your firmware\n");
1716
1717 for (i = 0; i < len; i++) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001718 ret = uea_write_cmv_e1(sc,
1719 get_unaligned_le32(&cmvs_v1[i].address),
1720 get_unaligned_le16(&cmvs_v1[i].offset),
1721 get_unaligned_le32(&cmvs_v1[i].data));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001722 if (ret < 0)
1723 goto out;
1724 }
1725 } else if (ver == 2) {
1726 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1727
1728 for (i = 0; i < len; i++) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001729 ret = uea_write_cmv_e1(sc,
1730 get_unaligned_le32(&cmvs_v2[i].address),
1731 (u16) get_unaligned_le32(&cmvs_v2[i].offset),
1732 get_unaligned_le32(&cmvs_v2[i].data));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001733 if (ret < 0)
1734 goto out;
1735 }
1736 } else {
1737 /* This realy should not happen */
1738 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1739 goto out;
1740 }
1741
1742 /* Enter in R-ACT-REQ */
1743 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1744 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001745 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1746 "synchronization...\n");
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001747out:
1748 release_firmware(cmvs_fw);
1749 return ret;
1750}
1751
1752static int uea_send_cmvs_e4(struct uea_softc *sc)
1753{
1754 int i, ret, len;
1755 void *cmvs_ptr;
1756 const struct firmware *cmvs_fw;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001757 int ver = 2; /* we can only handle v2 cmv firmware version; */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001758
1759 /* Enter in R-IDLE (cmv) until instructed otherwise */
1760 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
1761 if (ret < 0)
1762 return ret;
1763
1764 /* Dump firmware version */
1765 /* XXX don't read the 3th byte as it is always 6 */
1766 ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid);
1767 if (ret < 0)
1768 return ret;
1769 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1770 sc->stats.phy.firmid);
1771
1772
1773 /* get options */
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001774 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001775 if (ret < 0)
1776 return ret;
1777
1778 /* send options */
1779 if (ver == 2) {
1780 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1781
1782 for (i = 0; i < len; i++) {
1783 ret = uea_write_cmv_e4(sc, 1,
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001784 get_unaligned_le32(&cmvs_v2[i].group),
1785 get_unaligned_le32(&cmvs_v2[i].address),
1786 get_unaligned_le32(&cmvs_v2[i].offset),
1787 get_unaligned_le32(&cmvs_v2[i].data));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001788 if (ret < 0)
1789 goto out;
1790 }
1791 } else {
1792 /* This realy should not happen */
1793 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1794 goto out;
1795 }
1796
1797 /* Enter in R-ACT-REQ */
1798 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1799 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001800 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1801 "synchronization...\n");
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001802out:
1803 release_firmware(cmvs_fw);
1804 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001805}
1806
1807/* Start boot post firmware modem:
1808 * - send reset commands through usb control pipe
1809 * - start workqueue for DSP loading
1810 * - send CMV options to modem
1811 */
1812
1813static int uea_start_reset(struct uea_softc *sc)
1814{
1815 u16 zero = 0; /* ;-) */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001816 int ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001817
1818 uea_enters(INS_TO_USBDEV(sc));
1819 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1820
matthieu castet22fcceb2006-04-02 18:44:20 +02001821 /* mask interrupt */
matthieu castetb72458a2005-11-07 23:27:13 +01001822 sc->booting = 1;
matthieu castet22fcceb2006-04-02 18:44:20 +02001823 /* We need to set this here because, a ack timeout could have occured,
1824 * but before we start the reboot, the ack occurs and set this to 1.
1825 * So we will failed to wait Ready CMV.
1826 */
1827 sc->cmv_ack = 0;
matthieu castetb72458a2005-11-07 23:27:13 +01001828 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST);
1829
1830 /* reset statistics */
1831 memset(&sc->stats, 0, sizeof(struct uea_stats));
1832
1833 /* tell the modem that we want to boot in IDMA mode */
1834 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1835 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1836
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001837 /* enter reset mode */
matthieu castetb72458a2005-11-07 23:27:13 +01001838 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1839
1840 /* original driver use 200ms, but windows driver use 100ms */
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001841 ret = uea_wait(sc, 0, msecs_to_jiffies(100));
1842 if (ret < 0)
1843 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001844
1845 /* leave reset mode */
1846 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1847
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001848 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001849 /* clear tx and rx mailboxes */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001850 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1851 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1852 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1853 }
matthieu castetb72458a2005-11-07 23:27:13 +01001854
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001855 ret = uea_wait(sc, 0, msecs_to_jiffies(1000));
1856 if (ret < 0)
1857 return ret;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001858
1859 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001860 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
1861 E4_MODEMREADY, 1);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001862 else
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001863 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
1864 E1_MODEMREADY);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001865
matthieu castet22fcceb2006-04-02 18:44:20 +02001866 /* demask interrupt */
matthieu castetb72458a2005-11-07 23:27:13 +01001867 sc->booting = 0;
1868
1869 /* start loading DSP */
1870 sc->pageno = 0;
1871 sc->ovl = 0;
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02001872 queue_work(sc->work_q, &sc->task);
matthieu castetb72458a2005-11-07 23:27:13 +01001873
1874 /* wait for modem ready CMV */
1875 ret = wait_cmv_ack(sc);
1876 if (ret < 0)
1877 return ret;
1878
matthieu castet2a99b502006-04-02 18:43:53 +02001879 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1880
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001881 ret = sc->send_cmvs(sc);
matthieu castetb72458a2005-11-07 23:27:13 +01001882 if (ret < 0)
1883 return ret;
1884
matthieu castetb72458a2005-11-07 23:27:13 +01001885 sc->reset = 0;
1886 uea_leaves(INS_TO_USBDEV(sc));
1887 return ret;
1888}
1889
1890/*
1891 * In case of an error wait 1s before rebooting the modem
1892 * if the modem don't request reboot (-EAGAIN).
1893 * Monitor the modem every 1s.
1894 */
1895
1896static int uea_kthread(void *data)
1897{
1898 struct uea_softc *sc = data;
1899 int ret = -EAGAIN;
1900
Rafael J. Wysocki83144182007-07-17 04:03:35 -07001901 set_freezable();
matthieu castetb72458a2005-11-07 23:27:13 +01001902 uea_enters(INS_TO_USBDEV(sc));
1903 while (!kthread_should_stop()) {
1904 if (ret < 0 || sc->reset)
1905 ret = uea_start_reset(sc);
1906 if (!ret)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001907 ret = sc->stat(sc);
matthieu castetb72458a2005-11-07 23:27:13 +01001908 if (ret != -EAGAIN)
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001909 uea_wait(sc, 0, msecs_to_jiffies(1000));
Stanislaw Gruszka0eb02262007-08-20 23:21:19 +02001910 try_to_freeze();
matthieu castetb72458a2005-11-07 23:27:13 +01001911 }
1912 uea_leaves(INS_TO_USBDEV(sc));
1913 return ret;
1914}
1915
1916/* Load second usb firmware for ADI930 chip */
1917static int load_XILINX_firmware(struct uea_softc *sc)
1918{
1919 const struct firmware *fw_entry;
1920 int ret, size, u, ln;
David Woodhouseaafcd2f2008-05-24 00:05:10 +01001921 const u8 *pfw;
1922 u8 value;
matthieu castetb72458a2005-11-07 23:27:13 +01001923 char *fw_name = FW_DIR "930-fpga.bin";
1924
1925 uea_enters(INS_TO_USBDEV(sc));
1926
1927 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1928 if (ret) {
1929 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1930 fw_name);
1931 goto err0;
1932 }
1933
1934 pfw = fw_entry->data;
1935 size = fw_entry->size;
1936 if (size != 0x577B) {
1937 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1938 fw_name);
1939 ret = -EILSEQ;
1940 goto err1;
1941 }
1942 for (u = 0; u < size; u += ln) {
1943 ln = min(size - u, 64);
1944 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1945 if (ret < 0) {
1946 uea_err(INS_TO_USBDEV(sc),
1947 "elsa download data failed (%d)\n", ret);
1948 goto err1;
1949 }
1950 }
1951
matthieu castete40abaf2006-01-18 07:38:37 +01001952 /* finish to send the fpga */
matthieu castetb72458a2005-11-07 23:27:13 +01001953 ret = uea_request(sc, 0xe, 1, 0, NULL);
1954 if (ret < 0) {
1955 uea_err(INS_TO_USBDEV(sc),
1956 "elsa download data failed (%d)\n", ret);
1957 goto err1;
1958 }
1959
matthieu castete40abaf2006-01-18 07:38:37 +01001960 /* Tell the modem we finish : de-assert reset */
matthieu castetb72458a2005-11-07 23:27:13 +01001961 value = 0;
1962 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1963 if (ret < 0)
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001964 uea_err(sc->usb_dev, "elsa de-assert failed with error"
1965 " %d\n", ret);
matthieu castetb72458a2005-11-07 23:27:13 +01001966
matthieu castetb72458a2005-11-07 23:27:13 +01001967err1:
1968 release_firmware(fw_entry);
1969err0:
1970 uea_leaves(INS_TO_USBDEV(sc));
1971 return ret;
1972}
1973
matthieu castete40abaf2006-01-18 07:38:37 +01001974/* The modem send us an ack. First with check if it right */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001975static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
matthieu castetb72458a2005-11-07 23:27:13 +01001976{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001977 struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;
1978 struct cmv_e1 *cmv = &intr->u.e1.s2.cmv;
1979
matthieu castetb72458a2005-11-07 23:27:13 +01001980 uea_enters(INS_TO_USBDEV(sc));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001981 if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE)
matthieu castetb72458a2005-11-07 23:27:13 +01001982 goto bad1;
1983
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001984 if (cmv->bDirection != E1_MODEMTOHOST)
matthieu castetb72458a2005-11-07 23:27:13 +01001985 goto bad1;
1986
1987 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001988 * the first MEMACCESS cmv. Ignore it...
matthieu castetb72458a2005-11-07 23:27:13 +01001989 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001990 if (cmv->bFunction != dsc->function) {
matthieu castetb72458a2005-11-07 23:27:13 +01001991 if (UEA_CHIP_VERSION(sc) == ADI930
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001992 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
1993 cmv->wIndex = cpu_to_le16(dsc->idx);
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001994 put_unaligned_le32(dsc->address,
1995 &cmv->dwSymbolicAddress);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001996 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
1997 } else
matthieu castetb72458a2005-11-07 23:27:13 +01001998 goto bad2;
1999 }
2000
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002001 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
2002 E1_MODEMREADY)) {
matthieu castetb72458a2005-11-07 23:27:13 +01002003 wake_up_cmv_ack(sc);
matthieu castet2a99b502006-04-02 18:43:53 +02002004 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002005 return;
2006 }
2007
2008 /* in case of MEMACCESS */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002009 if (le16_to_cpu(cmv->wIndex) != dsc->idx ||
Harvey Harrisona5abdea2008-04-29 01:03:40 -07002010 get_unaligned_le32(&cmv->dwSymbolicAddress) != dsc->address ||
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002011 le16_to_cpu(cmv->wOffsetAddress) != dsc->offset)
matthieu castetb72458a2005-11-07 23:27:13 +01002012 goto bad2;
2013
Harvey Harrisona5abdea2008-04-29 01:03:40 -07002014 sc->data = get_unaligned_le32(&cmv->dwData);
matthieu castetb72458a2005-11-07 23:27:13 +01002015 sc->data = sc->data << 16 | sc->data >> 16;
2016
2017 wake_up_cmv_ack(sc);
matthieu castet2a99b502006-04-02 18:43:53 +02002018 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002019 return;
2020
2021bad2:
Joe Perchesfec8de32007-11-19 17:53:33 -08002022 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
matthieu castetb72458a2005-11-07 23:27:13 +01002023 "Function : %d, Subfunction : %d\n",
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002024 E1_FUNCTION_TYPE(cmv->bFunction),
2025 E1_FUNCTION_SUBTYPE(cmv->bFunction));
matthieu castet2a99b502006-04-02 18:43:53 +02002026 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002027 return;
2028
2029bad1:
2030 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
2031 "wPreamble %d, bDirection %d\n",
2032 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
matthieu castet2a99b502006-04-02 18:43:53 +02002033 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002034}
2035
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002036/* The modem send us an ack. First with check if it right */
2037static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
2038{
2039 struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;
2040 struct cmv_e4 *cmv = &intr->u.e4.s2.cmv;
2041
2042 uea_enters(INS_TO_USBDEV(sc));
2043 uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n",
2044 be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction),
2045 be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
2046 be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1]));
2047
2048 if (be16_to_cpu(cmv->wFunction) != dsc->function)
2049 goto bad2;
2050
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002051 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
2052 E4_MODEMREADY, 1)) {
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002053 wake_up_cmv_ack(sc);
2054 uea_leaves(INS_TO_USBDEV(sc));
2055 return;
2056 }
2057
2058 /* in case of MEMACCESS */
2059 if (be16_to_cpu(cmv->wOffset) != dsc->offset ||
2060 be16_to_cpu(cmv->wGroup) != dsc->group ||
2061 be16_to_cpu(cmv->wAddress) != dsc->address)
2062 goto bad2;
2063
2064 sc->data = be32_to_cpu(cmv->dwData[0]);
2065 sc->data1 = be32_to_cpu(cmv->dwData[1]);
2066 wake_up_cmv_ack(sc);
2067 uea_leaves(INS_TO_USBDEV(sc));
2068 return;
2069
2070bad2:
Joe Perchesfec8de32007-11-19 17:53:33 -08002071 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002072 "Function : %d, Subfunction : %d\n",
2073 E4_FUNCTION_TYPE(cmv->wFunction),
2074 E4_FUNCTION_SUBTYPE(cmv->wFunction));
2075 uea_leaves(INS_TO_USBDEV(sc));
2076 return;
2077}
2078
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002079static void uea_schedule_load_page_e1(struct uea_softc *sc,
2080 struct intr_pkt *intr)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002081{
2082 sc->pageno = intr->e1_bSwapPageNo;
2083 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002084 queue_work(sc->work_q, &sc->task);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002085}
2086
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002087static void uea_schedule_load_page_e4(struct uea_softc *sc,
2088 struct intr_pkt *intr)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002089{
2090 sc->pageno = intr->e4_bSwapPageNo;
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002091 queue_work(sc->work_q, &sc->task);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002092}
2093
matthieu castetb72458a2005-11-07 23:27:13 +01002094/*
2095 * interrupt handler
2096 */
David Howells7d12e782006-10-05 14:55:46 +01002097static void uea_intr(struct urb *urb)
matthieu castetb72458a2005-11-07 23:27:13 +01002098{
matthieu castete40abaf2006-01-18 07:38:37 +01002099 struct uea_softc *sc = urb->context;
2100 struct intr_pkt *intr = urb->transfer_buffer;
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002101 int status = urb->status;
2102
matthieu castetb72458a2005-11-07 23:27:13 +01002103 uea_enters(INS_TO_USBDEV(sc));
2104
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002105 if (unlikely(status < 0)) {
matthieu castetb72458a2005-11-07 23:27:13 +01002106 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002107 status);
matthieu castetb72458a2005-11-07 23:27:13 +01002108 return;
2109 }
2110
matthieu castetb72458a2005-11-07 23:27:13 +01002111 /* device-to-host interrupt */
2112 if (intr->bType != 0x08 || sc->booting) {
matthieu castete40abaf2006-01-18 07:38:37 +01002113 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
matthieu castetb72458a2005-11-07 23:27:13 +01002114 goto resubmit;
2115 }
2116
2117 switch (le16_to_cpu(intr->wInterrupt)) {
2118 case INT_LOADSWAPPAGE:
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002119 sc->schedule_load_page(sc, intr);
matthieu castetb72458a2005-11-07 23:27:13 +01002120 break;
2121
2122 case INT_INCOMINGCMV:
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002123 sc->dispatch_cmv(sc, intr);
matthieu castetb72458a2005-11-07 23:27:13 +01002124 break;
2125
2126 default:
matthieu castete40abaf2006-01-18 07:38:37 +01002127 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
matthieu castetb72458a2005-11-07 23:27:13 +01002128 le16_to_cpu(intr->wInterrupt));
2129 }
2130
2131resubmit:
2132 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
2133}
2134
2135/*
2136 * Start the modem : init the data and start kernel thread
2137 */
2138static int uea_boot(struct uea_softc *sc)
2139{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002140 int ret, size;
matthieu castetb72458a2005-11-07 23:27:13 +01002141 struct intr_pkt *intr;
2142
2143 uea_enters(INS_TO_USBDEV(sc));
2144
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002145 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2146 size = E4_INTR_PKT_SIZE;
2147 sc->dispatch_cmv = uea_dispatch_cmv_e4;
2148 sc->schedule_load_page = uea_schedule_load_page_e4;
2149 sc->stat = uea_stat_e4;
2150 sc->send_cmvs = uea_send_cmvs_e4;
2151 INIT_WORK(&sc->task, uea_load_page_e4);
2152 } else {
2153 size = E1_INTR_PKT_SIZE;
2154 sc->dispatch_cmv = uea_dispatch_cmv_e1;
2155 sc->schedule_load_page = uea_schedule_load_page_e1;
2156 sc->stat = uea_stat_e1;
2157 sc->send_cmvs = uea_send_cmvs_e1;
2158 INIT_WORK(&sc->task, uea_load_page_e1);
2159 }
2160
matthieu castetb72458a2005-11-07 23:27:13 +01002161 init_waitqueue_head(&sc->sync_q);
matthieu castetb72458a2005-11-07 23:27:13 +01002162
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002163 sc->work_q = create_workqueue("ueagle-dsp");
2164 if (!sc->work_q) {
2165 uea_err(INS_TO_USBDEV(sc), "cannot allocate workqueue\n");
2166 uea_leaves(INS_TO_USBDEV(sc));
2167 return -ENOMEM;
2168 }
2169
matthieu castetb72458a2005-11-07 23:27:13 +01002170 if (UEA_CHIP_VERSION(sc) == ADI930)
2171 load_XILINX_firmware(sc);
2172
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002173 intr = kmalloc(size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +01002174 if (!intr) {
2175 uea_err(INS_TO_USBDEV(sc),
2176 "cannot allocate interrupt package\n");
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002177 goto err0;
matthieu castetb72458a2005-11-07 23:27:13 +01002178 }
2179
2180 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
2181 if (!sc->urb_int) {
2182 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002183 goto err1;
matthieu castetb72458a2005-11-07 23:27:13 +01002184 }
2185
2186 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
2187 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002188 intr, size, uea_intr, sc,
matthieu castetb72458a2005-11-07 23:27:13 +01002189 sc->usb_dev->actconfig->interface[0]->altsetting[0].
2190 endpoint[0].desc.bInterval);
2191
2192 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2193 if (ret < 0) {
2194 uea_err(INS_TO_USBDEV(sc),
2195 "urb submition failed with error %d\n", ret);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002196 goto err1;
matthieu castetb72458a2005-11-07 23:27:13 +01002197 }
2198
2199 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm");
2200 if (sc->kthread == ERR_PTR(-ENOMEM)) {
2201 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2202 goto err2;
2203 }
2204
2205 uea_leaves(INS_TO_USBDEV(sc));
2206 return 0;
2207
2208err2:
2209 usb_kill_urb(sc->urb_int);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002210err1:
matthieu castetb72458a2005-11-07 23:27:13 +01002211 usb_free_urb(sc->urb_int);
matthieu castet4d45e212006-04-02 18:45:46 +02002212 sc->urb_int = NULL;
2213 kfree(intr);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002214err0:
2215 destroy_workqueue(sc->work_q);
matthieu castetb72458a2005-11-07 23:27:13 +01002216 uea_leaves(INS_TO_USBDEV(sc));
2217 return -ENOMEM;
2218}
2219
2220/*
2221 * Stop the modem : kill kernel thread and free data
2222 */
2223static void uea_stop(struct uea_softc *sc)
2224{
2225 int ret;
2226 uea_enters(INS_TO_USBDEV(sc));
2227 ret = kthread_stop(sc->kthread);
matthieu castete40abaf2006-01-18 07:38:37 +01002228 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
matthieu castetb72458a2005-11-07 23:27:13 +01002229
matthieu castetb72458a2005-11-07 23:27:13 +01002230 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
2231
2232 usb_kill_urb(sc->urb_int);
2233 kfree(sc->urb_int->transfer_buffer);
2234 usb_free_urb(sc->urb_int);
2235
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002236 /* stop any pending boot process, when no one can schedule work */
2237 destroy_workqueue(sc->work_q);
2238
matthieu castetb72458a2005-11-07 23:27:13 +01002239 if (sc->dsp_firm)
2240 release_firmware(sc->dsp_firm);
2241 uea_leaves(INS_TO_USBDEV(sc));
2242}
2243
2244/* syfs interface */
2245static struct uea_softc *dev_to_uea(struct device *dev)
2246{
2247 struct usb_interface *intf;
2248 struct usbatm_data *usbatm;
2249
2250 intf = to_usb_interface(dev);
2251 if (!intf)
2252 return NULL;
2253
2254 usbatm = usb_get_intfdata(intf);
2255 if (!usbatm)
2256 return NULL;
2257
2258 return usbatm->driver_data;
2259}
2260
2261static ssize_t read_status(struct device *dev, struct device_attribute *attr,
2262 char *buf)
2263{
2264 int ret = -ENODEV;
2265 struct uea_softc *sc;
2266
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002267 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002268 sc = dev_to_uea(dev);
2269 if (!sc)
2270 goto out;
2271 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
2272out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002273 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002274 return ret;
2275}
2276
2277static ssize_t reboot(struct device *dev, struct device_attribute *attr,
2278 const char *buf, size_t count)
2279{
2280 int ret = -ENODEV;
2281 struct uea_softc *sc;
2282
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002283 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002284 sc = dev_to_uea(dev);
2285 if (!sc)
2286 goto out;
2287 sc->reset = 1;
2288 ret = count;
2289out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002290 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002291 return ret;
2292}
2293
2294static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot);
2295
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002296static ssize_t read_human_status(struct device *dev,
2297 struct device_attribute *attr, char *buf)
matthieu castetb72458a2005-11-07 23:27:13 +01002298{
2299 int ret = -ENODEV;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002300 int modem_state;
matthieu castetb72458a2005-11-07 23:27:13 +01002301 struct uea_softc *sc;
2302
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002303 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002304 sc = dev_to_uea(dev);
2305 if (!sc)
2306 goto out;
2307
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002308 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2309 switch (sc->stats.phy.state) {
2310 case 0x0: /* not yet synchronized */
2311 case 0x1:
2312 case 0x3:
2313 case 0x4:
2314 modem_state = 0;
2315 break;
2316 case 0x5: /* initialization */
2317 case 0x6:
2318 case 0x9:
2319 case 0xa:
2320 modem_state = 1;
2321 break;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002322 case 0x7: /* operational */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002323 modem_state = 2;
2324 break;
2325 case 0x2: /* fail ... */
2326 modem_state = 3;
2327 break;
2328 default: /* unknown */
2329 modem_state = 4;
2330 break;
2331 }
2332 } else
2333 modem_state = GET_STATUS(sc->stats.phy.state);
2334
2335 switch (modem_state) {
matthieu castetb72458a2005-11-07 23:27:13 +01002336 case 0:
2337 ret = sprintf(buf, "Modem is booting\n");
2338 break;
2339 case 1:
2340 ret = sprintf(buf, "Modem is initializing\n");
2341 break;
2342 case 2:
2343 ret = sprintf(buf, "Modem is operational\n");
2344 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002345 case 3:
matthieu castetb72458a2005-11-07 23:27:13 +01002346 ret = sprintf(buf, "Modem synchronization failed\n");
2347 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002348 default:
2349 ret = sprintf(buf, "Modem state is unknown\n");
2350 break;
matthieu castetb72458a2005-11-07 23:27:13 +01002351 }
2352out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002353 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002354 return ret;
2355}
2356
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002357static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO,
2358 read_human_status, NULL);
matthieu castetb72458a2005-11-07 23:27:13 +01002359
2360static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2361 char *buf)
2362{
2363 int ret = -ENODEV;
2364 struct uea_softc *sc;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002365 char *delin = "GOOD";
matthieu castetb72458a2005-11-07 23:27:13 +01002366
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002367 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002368 sc = dev_to_uea(dev);
2369 if (!sc)
2370 goto out;
2371
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002372 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2373 if (sc->stats.phy.flags & 0x4000)
2374 delin = "RESET";
2375 else if (sc->stats.phy.flags & 0x0001)
2376 delin = "LOSS";
2377 } else {
2378 if (sc->stats.phy.flags & 0x0C00)
2379 delin = "ERROR";
2380 else if (sc->stats.phy.flags & 0x0030)
2381 delin = "LOSS";
2382 }
2383
2384 ret = sprintf(buf, "%s\n", delin);
matthieu castetb72458a2005-11-07 23:27:13 +01002385out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002386 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002387 return ret;
2388}
2389
2390static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL);
2391
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002392#define UEA_ATTR(name, reset) \
matthieu castetb72458a2005-11-07 23:27:13 +01002393 \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002394static ssize_t read_##name(struct device *dev, \
matthieu castetb72458a2005-11-07 23:27:13 +01002395 struct device_attribute *attr, char *buf) \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002396{ \
2397 int ret = -ENODEV; \
2398 struct uea_softc *sc; \
2399 \
2400 mutex_lock(&uea_mutex); \
matthieu castetb72458a2005-11-07 23:27:13 +01002401 sc = dev_to_uea(dev); \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002402 if (!sc) \
2403 goto out; \
matthieu castetb72458a2005-11-07 23:27:13 +01002404 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2405 if (reset) \
2406 sc->stats.phy.name = 0; \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002407out: \
2408 mutex_unlock(&uea_mutex); \
2409 return ret; \
2410} \
matthieu castetb72458a2005-11-07 23:27:13 +01002411 \
2412static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2413
2414UEA_ATTR(mflags, 1);
2415UEA_ATTR(vidcpe, 0);
2416UEA_ATTR(usrate, 0);
2417UEA_ATTR(dsrate, 0);
2418UEA_ATTR(usattenuation, 0);
2419UEA_ATTR(dsattenuation, 0);
2420UEA_ATTR(usmargin, 0);
2421UEA_ATTR(dsmargin, 0);
2422UEA_ATTR(txflow, 0);
2423UEA_ATTR(rxflow, 0);
2424UEA_ATTR(uscorr, 0);
2425UEA_ATTR(dscorr, 0);
2426UEA_ATTR(usunc, 0);
2427UEA_ATTR(dsunc, 0);
matthieu casteta7a0c9c2006-10-03 21:44:11 +02002428UEA_ATTR(firmid, 0);
matthieu castetb72458a2005-11-07 23:27:13 +01002429
2430/* Retrieve the device End System Identifier (MAC) */
2431
2432#define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
2433static int uea_getesi(struct uea_softc *sc, u_char * esi)
2434{
2435 unsigned char mac_str[2 * ETH_ALEN + 1];
2436 int i;
2437 if (usb_string
2438 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
2439 sizeof(mac_str)) != 2 * ETH_ALEN)
2440 return 1;
2441
2442 for (i = 0; i < ETH_ALEN; i++)
2443 esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]);
2444
2445 return 0;
2446}
2447
2448/* ATM stuff */
2449static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
2450{
2451 struct uea_softc *sc = usbatm->driver_data;
2452
2453 return uea_getesi(sc, atm_dev->esi);
2454}
2455
2456static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
2457{
2458 struct uea_softc *sc = usbatm->driver_data;
2459
matthieu castet531a39b2006-10-03 21:49:29 +02002460 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002461
2462 return 0;
2463
2464}
2465
2466static int claim_interface(struct usb_device *usb_dev,
2467 struct usbatm_data *usbatm, int ifnum)
2468{
2469 int ret;
2470 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
2471
2472 if (!intf) {
2473 uea_err(usb_dev, "interface %d not found\n", ifnum);
2474 return -ENODEV;
2475 }
2476
2477 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
2478 if (ret != 0)
2479 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
2480 ret);
2481 return ret;
2482}
2483
Greg Kroah-Hartmane7ccdfe2006-08-28 11:43:25 -07002484static struct attribute *attrs[] = {
2485 &dev_attr_stat_status.attr,
2486 &dev_attr_stat_mflags.attr,
2487 &dev_attr_stat_human_status.attr,
2488 &dev_attr_stat_delin.attr,
2489 &dev_attr_stat_vidcpe.attr,
2490 &dev_attr_stat_usrate.attr,
2491 &dev_attr_stat_dsrate.attr,
2492 &dev_attr_stat_usattenuation.attr,
2493 &dev_attr_stat_dsattenuation.attr,
2494 &dev_attr_stat_usmargin.attr,
2495 &dev_attr_stat_dsmargin.attr,
2496 &dev_attr_stat_txflow.attr,
2497 &dev_attr_stat_rxflow.attr,
2498 &dev_attr_stat_uscorr.attr,
2499 &dev_attr_stat_dscorr.attr,
2500 &dev_attr_stat_usunc.attr,
2501 &dev_attr_stat_dsunc.attr,
matthieu casteta7a0c9c2006-10-03 21:44:11 +02002502 &dev_attr_stat_firmid.attr,
matthieu castet9ab99c82006-10-11 14:20:56 -07002503 NULL,
Greg Kroah-Hartmane7ccdfe2006-08-28 11:43:25 -07002504};
2505static struct attribute_group attr_grp = {
2506 .attrs = attrs,
2507};
2508
matthieu castetb72458a2005-11-07 23:27:13 +01002509static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
Duncan Sands35644b02006-01-17 11:16:13 +01002510 const struct usb_device_id *id)
matthieu castetb72458a2005-11-07 23:27:13 +01002511{
2512 struct usb_device *usb = interface_to_usbdev(intf);
2513 struct uea_softc *sc;
2514 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002515 unsigned int alt;
matthieu castetb72458a2005-11-07 23:27:13 +01002516
2517 uea_enters(usb);
2518
2519 /* interface 0 is for firmware/monitoring */
2520 if (ifnum != UEA_INTR_IFACE_NO)
2521 return -ENODEV;
2522
Duncan Sands0dfcd3e2006-01-13 09:36:20 +01002523 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
matthieu castetb72458a2005-11-07 23:27:13 +01002524
2525 /* interface 1 is for outbound traffic */
2526 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
2527 if (ret < 0)
2528 return ret;
2529
matthieu castete40abaf2006-01-18 07:38:37 +01002530 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
matthieu castetb72458a2005-11-07 23:27:13 +01002531 if (UEA_CHIP_VERSION(id) != ADI930) {
2532 /* interface 2 is for inbound traffic */
2533 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
2534 if (ret < 0)
2535 return ret;
2536 }
2537
2538 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
2539 if (!sc) {
matthieu castet584958c2006-04-02 18:44:48 +02002540 uea_err(usb, "uea_init: not enough memory !\n");
matthieu castetb72458a2005-11-07 23:27:13 +01002541 return -ENOMEM;
2542 }
2543
2544 sc->usb_dev = usb;
2545 usbatm->driver_data = sc;
2546 sc->usbatm = usbatm;
2547 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
2548 sc->driver_info = id->driver_info;
2549
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002550 /* first try to use module parameter */
2551 if (annex[sc->modem_index] == 1)
2552 sc->annex = ANNEXA;
2553 else if (annex[sc->modem_index] == 2)
2554 sc->annex = ANNEXB;
2555 /* try to autodetect annex */
2556 else if (sc->driver_info & AUTO_ANNEX_A)
2557 sc->annex = ANNEXA;
2558 else if (sc->driver_info & AUTO_ANNEX_B)
2559 sc->annex = ANNEXB;
2560 else
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002561 sc->annex = (le16_to_cpu
2562 (sc->usb_dev->descriptor.bcdDevice) & 0x80) ? ANNEXB : ANNEXA;
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002563
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002564 alt = altsetting[sc->modem_index];
matthieu castet3c9666c2006-01-18 07:38:19 +01002565 /* ADI930 don't support iso */
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002566 if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002567 if (alt <= 8 &&
2568 usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) {
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002569 uea_dbg(usb, "set alternate %u for 2 interface\n", alt);
matthieu castet3c9666c2006-01-18 07:38:19 +01002570 uea_info(usb, "using iso mode\n");
2571 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
2572 } else {
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002573 uea_err(usb, "setting alternate %u failed for "
2574 "2 interface, using bulk mode\n", alt);
matthieu castet3c9666c2006-01-18 07:38:19 +01002575 }
2576 }
2577
matthieu castet9ab99c82006-10-11 14:20:56 -07002578 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
2579 if (ret < 0)
2580 goto error;
2581
matthieu castetb72458a2005-11-07 23:27:13 +01002582 ret = uea_boot(sc);
matthieu castet9ab99c82006-10-11 14:20:56 -07002583 if (ret < 0)
Stanislaw Gruszka4c132e72007-08-20 23:20:49 +02002584 goto error_rm_grp;
matthieu castetb72458a2005-11-07 23:27:13 +01002585
matthieu castetb72458a2005-11-07 23:27:13 +01002586 return 0;
Stanislaw Gruszka4c132e72007-08-20 23:20:49 +02002587
2588error_rm_grp:
2589 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
matthieu castet9ab99c82006-10-11 14:20:56 -07002590error:
2591 kfree(sc);
2592 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01002593}
2594
2595static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
2596{
2597 struct uea_softc *sc = usbatm->driver_data;
2598
matthieu castet9ab99c82006-10-11 14:20:56 -07002599 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
matthieu castetb72458a2005-11-07 23:27:13 +01002600 uea_stop(sc);
2601 kfree(sc);
2602}
2603
2604static struct usbatm_driver uea_usbatm_driver = {
2605 .driver_name = "ueagle-atm",
matthieu castetb72458a2005-11-07 23:27:13 +01002606 .bind = uea_bind,
2607 .atm_start = uea_atm_open,
2608 .unbind = uea_unbind,
2609 .heavy_init = uea_heavy,
Duncan Sands80aae7a2006-01-13 10:59:23 +01002610 .bulk_in = UEA_BULK_DATA_PIPE,
2611 .bulk_out = UEA_BULK_DATA_PIPE,
matthieu castet3c9666c2006-01-18 07:38:19 +01002612 .isoc_in = UEA_ISO_DATA_PIPE,
matthieu castetb72458a2005-11-07 23:27:13 +01002613};
2614
2615static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2616{
2617 struct usb_device *usb = interface_to_usbdev(intf);
2618
2619 uea_enters(usb);
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002620 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2621 le16_to_cpu(usb->descriptor.idVendor),
2622 le16_to_cpu(usb->descriptor.idProduct),
2623 le16_to_cpu(usb->descriptor.bcdDevice),
2624 chip_name[UEA_CHIP_VERSION(id)]);
matthieu castetb72458a2005-11-07 23:27:13 +01002625
2626 usb_reset_device(usb);
2627
2628 if (UEA_IS_PREFIRM(id))
2629 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2630
2631 return usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2632}
2633
2634static void uea_disconnect(struct usb_interface *intf)
2635{
2636 struct usb_device *usb = interface_to_usbdev(intf);
2637 int ifnum = intf->altsetting->desc.bInterfaceNumber;
2638 uea_enters(usb);
2639
2640 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2641 * Pre-firmware device has one interface
2642 */
2643 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002644 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002645 usbatm_usb_disconnect(intf);
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002646 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002647 uea_info(usb, "ADSL device removed\n");
2648 }
2649
2650 uea_leaves(usb);
2651}
2652
2653/*
2654 * List of supported VID/PID
2655 */
2656static const struct usb_device_id uea_ids[] = {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002657 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM),
2658 .driver_info = ADI930 | PREFIRM},
2659 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM),
2660 .driver_info = ADI930 | PSTFIRM},
2661 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM),
2662 .driver_info = EAGLE_I | PREFIRM},
2663 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM),
2664 .driver_info = EAGLE_I | PSTFIRM},
2665 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM),
2666 .driver_info = EAGLE_II | PREFIRM},
2667 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM),
2668 .driver_info = EAGLE_II | PSTFIRM},
2669 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM),
2670 .driver_info = EAGLE_II | PREFIRM},
2671 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM),
2672 .driver_info = EAGLE_II | PSTFIRM},
2673 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM),
2674 .driver_info = EAGLE_III | PREFIRM},
2675 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM),
2676 .driver_info = EAGLE_III | PSTFIRM},
2677 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM),
2678 .driver_info = EAGLE_IV | PREFIRM},
2679 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM),
2680 .driver_info = EAGLE_IV | PSTFIRM},
2681 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM),
2682 .driver_info = EAGLE_I | PREFIRM},
2683 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM),
2684 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2685 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM),
2686 .driver_info = EAGLE_I | PREFIRM},
2687 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM),
2688 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2689 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM),
2690 .driver_info = EAGLE_II | PREFIRM},
2691 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM),
2692 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A},
2693 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM),
2694 .driver_info = EAGLE_II | PREFIRM},
2695 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM),
2696 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B},
2697 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM),
2698 .driver_info = ADI930 | PREFIRM},
2699 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM),
2700 .driver_info = ADI930 | PSTFIRM},
2701 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM),
2702 .driver_info = ADI930 | PREFIRM},
2703 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM),
2704 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A},
2705 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM),
2706 .driver_info = ADI930 | PREFIRM},
2707 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM),
2708 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B},
2709 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM),
2710 .driver_info = EAGLE_I | PREFIRM},
2711 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM),
2712 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2713 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM),
2714 .driver_info = EAGLE_I | PREFIRM},
2715 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM),
2716 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2717 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),
2718 .driver_info = EAGLE_I | PREFIRM},
2719 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),
2720 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2721 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),
2722 .driver_info = EAGLE_I | PREFIRM},
2723 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),
2724 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
matthieu castetb72458a2005-11-07 23:27:13 +01002725 {}
2726};
2727
2728/*
2729 * USB driver descriptor
2730 */
2731static struct usb_driver uea_driver = {
matthieu castetb72458a2005-11-07 23:27:13 +01002732 .name = "ueagle-atm",
2733 .id_table = uea_ids,
2734 .probe = uea_probe,
2735 .disconnect = uea_disconnect,
2736};
2737
2738MODULE_DEVICE_TABLE(usb, uea_ids);
2739
2740/**
2741 * uea_init - Initialize the module.
2742 * Register to USB subsystem
2743 */
2744static int __init uea_init(void)
2745{
2746 printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n");
2747
2748 usb_register(&uea_driver);
2749
2750 return 0;
2751}
2752
2753module_init(uea_init);
2754
2755/**
2756 * uea_exit - Destroy module
2757 * Deregister with USB subsystem
2758 */
2759static void __exit uea_exit(void)
2760{
2761 /*
2762 * This calls automatically the uea_disconnect method if necessary:
2763 */
2764 usb_deregister(&uea_driver);
2765
2766 printk(KERN_INFO "[ueagle-atm] driver unloaded\n");
2767}
2768
2769module_exit(uea_exit);
2770
2771MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2772MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2773MODULE_LICENSE("Dual BSD/GPL");