blob: dee5f798946c29d9f417209851eee3345e157ea7 [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 *
5 * Copyright (c) 2005 Matthieu Castet <castet.matthieu@free.fr>
6 *
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * BSD license below:
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice unmodified, this list of conditions, and the following
18 * disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * GPL license :
36 * This program is free software; you can redistribute it and/or
37 * modify it under the terms of the GNU General Public License
38 * as published by the Free Software Foundation; either version 2
39 * of the License, or (at your option) any later version.
40 *
41 * This program is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU General Public License for more details.
45 *
46 * You should have received a copy of the GNU General Public License
47 * along with this program; if not, write to the Free Software
48 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
49 *
50 *
51 * HISTORY : some part of the code was base on ueagle 1.3 BSD driver,
52 * Damien Bergamini agree to put his code under a DUAL GPL/BSD license.
53 *
54 * The rest of the code was was rewritten from scratch.
55 */
56
57#include <linux/module.h>
58#include <linux/moduleparam.h>
59#include <linux/init.h>
60#include <linux/crc32.h>
61#include <linux/usb.h>
62#include <linux/firmware.h>
63#include <linux/ctype.h>
Randy Dunlap5371f802007-02-16 01:47:33 -080064#include <linux/sched.h>
matthieu castetb72458a2005-11-07 23:27:13 +010065#include <linux/kthread.h>
66#include <linux/version.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>
69
matthieu castetb72458a2005-11-07 23:27:13 +010070#include <asm/unaligned.h>
71
72#include "usbatm.h"
73
matthieu casteta7a0c9c2006-10-03 21:44:11 +020074#define EAGLEUSBVERSION "ueagle 1.4"
matthieu castetb72458a2005-11-07 23:27:13 +010075
76
77/*
78 * Debug macros
79 */
80#define uea_dbg(usb_dev, format, args...) \
81 do { \
82 if (debug >= 1) \
83 dev_dbg(&(usb_dev)->dev, \
84 "[ueagle-atm dbg] %s: " format, \
85 __FUNCTION__, ##args); \
matthieu casteta7a0c9c2006-10-03 21:44:11 +020086 } while (0)
matthieu castetb72458a2005-11-07 23:27:13 +010087
88#define uea_vdbg(usb_dev, format, args...) \
89 do { \
90 if (debug >= 2) \
91 dev_dbg(&(usb_dev)->dev, \
92 "[ueagle-atm vdbg] " format, ##args); \
matthieu casteta7a0c9c2006-10-03 21:44:11 +020093 } while (0)
matthieu castetb72458a2005-11-07 23:27:13 +010094
95#define uea_enters(usb_dev) \
96 uea_vdbg(usb_dev, "entering %s\n", __FUNCTION__)
97
98#define uea_leaves(usb_dev) \
99 uea_vdbg(usb_dev, "leaving %s\n", __FUNCTION__)
100
101#define uea_err(usb_dev, format,args...) \
102 dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args)
103
104#define uea_warn(usb_dev, format,args...) \
105 dev_warn(&(usb_dev)->dev ,"[Ueagle-atm] " format, ##args)
106
107#define uea_info(usb_dev, format,args...) \
108 dev_info(&(usb_dev)->dev ,"[ueagle-atm] " format, ##args)
109
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200110struct intr_pkt;
111
112/* cmv's from firmware */
113struct uea_cmvs_v1 {
matthieu castetb72458a2005-11-07 23:27:13 +0100114 u32 address;
115 u16 offset;
116 u32 data;
117} __attribute__ ((packed));
118
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200119struct uea_cmvs_v2 {
120 u32 group;
121 u32 address;
122 u32 offset;
123 u32 data;
124} __attribute__ ((packed));
125
126/* information about currently processed cmv */
127struct cmv_dsc_e1 {
128 u8 function;
129 u16 idx;
130 u32 address;
131 u16 offset;
132};
133
134struct cmv_dsc_e4 {
135 u16 function;
136 u16 offset;
137 u16 address;
138 u16 group;
139};
140
141union cmv_dsc {
142 struct cmv_dsc_e1 e1;
143 struct cmv_dsc_e4 e4;
144};
145
matthieu castetb72458a2005-11-07 23:27:13 +0100146struct uea_softc {
147 struct usb_device *usb_dev;
148 struct usbatm_data *usbatm;
149
150 int modem_index;
151 unsigned int driver_info;
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200152 int annex;
153#define ANNEXA 0
154#define ANNEXB 1
matthieu castetb72458a2005-11-07 23:27:13 +0100155
156 int booting;
157 int reset;
158
159 wait_queue_head_t sync_q;
160
161 struct task_struct *kthread;
162 u32 data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200163 u32 data1;
matthieu castetb72458a2005-11-07 23:27:13 +0100164 wait_queue_head_t cmv_ack_wait;
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;
170 u16 pageno;
171 u16 ovl;
172
173 const struct firmware *dsp_firm;
174 struct urb *urb_int;
175
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200176 void (*dispatch_cmv) (struct uea_softc *, struct intr_pkt *);
177 void (*schedule_load_page) (struct uea_softc *, struct intr_pkt *);
178 int (*stat) (struct uea_softc *);
179 int (*send_cmvs) (struct uea_softc *);
matthieu castetb72458a2005-11-07 23:27:13 +0100180
181 /* keep in sync with eaglectl */
182 struct uea_stats {
183 struct {
184 u32 state;
185 u32 flags;
186 u32 mflags;
187 u32 vidcpe;
188 u32 vidco;
189 u32 dsrate;
190 u32 usrate;
191 u32 dsunc;
192 u32 usunc;
193 u32 dscorr;
194 u32 uscorr;
195 u32 txflow;
196 u32 rxflow;
197 u32 usattenuation;
198 u32 dsattenuation;
199 u32 dsmargin;
200 u32 usmargin;
201 u32 firmid;
202 } phy;
203 } stats;
204};
205
206/*
207 * Elsa IDs
208 */
209#define ELSA_VID 0x05CC
210#define ELSA_PID_PSTFIRM 0x3350
211#define ELSA_PID_PREFIRM 0x3351
212
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200213#define ELSA_PID_A_PREFIRM 0x3352
214#define ELSA_PID_A_PSTFIRM 0x3353
215#define ELSA_PID_B_PREFIRM 0x3362
216#define ELSA_PID_B_PSTFIRM 0x3363
217
matthieu castetb72458a2005-11-07 23:27:13 +0100218/*
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200219 * Devolo IDs : pots if (pid & 0x10)
matthieu castetb72458a2005-11-07 23:27:13 +0100220 */
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200221#define DEVOLO_VID 0x1039
222#define DEVOLO_EAGLE_I_A_PID_PSTFIRM 0x2110
223#define DEVOLO_EAGLE_I_A_PID_PREFIRM 0x2111
224
225#define DEVOLO_EAGLE_I_B_PID_PSTFIRM 0x2100
226#define DEVOLO_EAGLE_I_B_PID_PREFIRM 0x2101
227
228#define DEVOLO_EAGLE_II_A_PID_PSTFIRM 0x2130
229#define DEVOLO_EAGLE_II_A_PID_PREFIRM 0x2131
230
231#define DEVOLO_EAGLE_II_B_PID_PSTFIRM 0x2120
232#define DEVOLO_EAGLE_II_B_PID_PREFIRM 0x2121
233
234/*
235 * Reference design USB IDs
236 */
237#define ANALOG_VID 0x1110
238#define ADI930_PID_PREFIRM 0x9001
239#define ADI930_PID_PSTFIRM 0x9000
240
matthieu castetb72458a2005-11-07 23:27:13 +0100241#define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
242#define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
243
244#define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
245#define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
246
247#define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
248#define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
249
matthieu castetb72458a2005-11-07 23:27:13 +0100250#define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
251#define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
252
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200253#define EAGLE_IV_PID_PREFIRM 0x9042 /* Eagle IV */
254#define EAGLE_IV_PID_PSTFIRM 0x9041 /* Eagle IV */
255
matthieu castetb72458a2005-11-07 23:27:13 +0100256/*
257 * USR USB IDs
258 */
259#define USR_VID 0x0BAF
260#define MILLER_A_PID_PREFIRM 0x00F2
261#define MILLER_A_PID_PSTFIRM 0x00F1
262#define MILLER_B_PID_PREFIRM 0x00FA
263#define MILLER_B_PID_PSTFIRM 0x00F9
264#define HEINEKEN_A_PID_PREFIRM 0x00F6
265#define HEINEKEN_A_PID_PSTFIRM 0x00F5
266#define HEINEKEN_B_PID_PREFIRM 0x00F8
267#define HEINEKEN_B_PID_PSTFIRM 0x00F7
268
269#define PREFIRM 0
270#define PSTFIRM (1<<7)
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200271#define AUTO_ANNEX_A (1<<8)
272#define AUTO_ANNEX_B (1<<9)
273
matthieu castetb72458a2005-11-07 23:27:13 +0100274enum {
275 ADI930 = 0,
276 EAGLE_I,
277 EAGLE_II,
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200278 EAGLE_III,
279 EAGLE_IV
matthieu castetb72458a2005-11-07 23:27:13 +0100280};
281
282/* macros for both struct usb_device_id and struct uea_softc */
283#define UEA_IS_PREFIRM(x) \
284 (!((x)->driver_info & PSTFIRM))
285#define UEA_CHIP_VERSION(x) \
286 ((x)->driver_info & 0xf)
287
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200288#define IS_ISDN(x) \
289 ((x)->annex & ANNEXB)
matthieu castetb72458a2005-11-07 23:27:13 +0100290
291#define INS_TO_USBDEV(ins) ins->usb_dev
292
293#define GET_STATUS(data) \
294 ((data >> 8) & 0xf)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200295
matthieu castetb72458a2005-11-07 23:27:13 +0100296#define IS_OPERATIONAL(sc) \
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200297 ((UEA_CHIP_VERSION(sc) != EAGLE_IV) ? \
298 (GET_STATUS(sc->stats.phy.state) == 2) : \
299 (sc->stats.phy.state == 7))
matthieu castetb72458a2005-11-07 23:27:13 +0100300
301/*
302 * Set of macros to handle unaligned data in the firmware blob.
303 * The FW_GET_BYTE() macro is provided only for consistency.
304 */
305
306#define FW_GET_BYTE(p) *((__u8 *) (p))
307#define FW_GET_WORD(p) le16_to_cpu(get_unaligned((__le16 *) (p)))
308#define FW_GET_LONG(p) le32_to_cpu(get_unaligned((__le32 *) (p)))
309
310#define FW_DIR "ueagle-atm/"
311#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
318#define UEA_INTR_IFACE_NO 0
319#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
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200329#define UEA_E1_SET_BLOCK 0x0001
330#define UEA_E4_SET_BLOCK 0x002c
matthieu castetb72458a2005-11-07 23:27:13 +0100331#define UEA_SET_MODE 0x0003
332#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];
369 u8 code [0];
370} __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))
431#define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | ((st) & 0xf) << 4 | ((s) & 0xf))
432
433#define E1_MAKESA(a, b, c, d) \
matthieu castetb72458a2005-11-07 23:27:13 +0100434 (((c) & 0xff) << 24 | \
435 ((d) & 0xff) << 16 | \
436 ((a) & 0xff) << 8 | \
437 ((b) & 0xff))
438
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200439#define E1_GETSA1(a) ((a >> 8) & 0xff)
440#define E1_GETSA2(a) (a & 0xff)
441#define E1_GETSA3(a) ((a >> 24) & 0xff)
442#define E1_GETSA4(a) ((a >> 16) & 0xff)
443
444#define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L')
445#define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G')
446#define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O')
447#define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N')
448#define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E')
449#define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T')
450
451#define E4_SA_CNTL 1
452#define E4_SA_STAT 2
453#define E4_SA_INFO 3
454#define E4_SA_TEST 4
455#define E4_SA_OPTN 5
456#define E4_SA_RATE 6
457#define E4_SA_DIAG 7
458#define E4_SA_CNFG 8
459
460/* structures representing a CMV (Configuration and Management Variable) */
461struct cmv_e1 {
462 __le16 wPreamble;
463 __u8 bDirection;
464 __u8 bFunction;
465 __le16 wIndex;
466 __le32 dwSymbolicAddress;
matthieu castetb72458a2005-11-07 23:27:13 +0100467 __le16 wOffsetAddress;
468 __le32 dwData;
469} __attribute__ ((packed));
matthieu castetb72458a2005-11-07 23:27:13 +0100470
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200471struct cmv_e4 {
472 __be16 wGroup;
473 __be16 wFunction;
474 __be16 wOffset;
475 __be16 wAddress;
476 __be32 dwData [6];
477} __attribute__ ((packed));
478
479/* structures representing swap information */
480struct swap_info_e1 {
matthieu castetb72458a2005-11-07 23:27:13 +0100481 __u8 bSwapPageNo;
482 __u8 bOvl; /* overlay */
483} __attribute__ ((packed));
484
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200485struct swap_info_e4 {
486 __u8 bSwapPageNo;
487} __attribute__ ((packed));
488
489/* structures representing interrupt data */
490#define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
491#define e1_bOvl u.e1.s1.swapinfo.bOvl
492#define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo
493
494#define INT_LOADSWAPPAGE 0x0001
495#define INT_INCOMINGCMV 0x0002
496
497union intr_data_e1 {
498 struct {
499 struct swap_info_e1 swapinfo;
500 __le16 wDataSize;
501 } __attribute__ ((packed)) s1;
502 struct {
503 struct cmv_e1 cmv;
504 __le16 wDataSize;
505 } __attribute__ ((packed)) s2;
506} __attribute__ ((packed));
507
508union intr_data_e4 {
509 struct {
510 struct swap_info_e4 swapinfo;
511 __le16 wDataSize;
512 } __attribute__ ((packed)) s1;
513 struct {
514 struct cmv_e4 cmv;
515 __le16 wDataSize;
516 } __attribute__ ((packed)) s2;
517} __attribute__ ((packed));
518
matthieu castetb72458a2005-11-07 23:27:13 +0100519struct intr_pkt {
520 __u8 bType;
521 __u8 bNotification;
522 __le16 wValue;
523 __le16 wIndex;
524 __le16 wLength;
525 __le16 wInterrupt;
matthieu castetb72458a2005-11-07 23:27:13 +0100526 union {
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200527 union intr_data_e1 e1;
528 union intr_data_e4 e4;
529 } u;
matthieu castetb72458a2005-11-07 23:27:13 +0100530} __attribute__ ((packed));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200531
532#define E1_INTR_PKT_SIZE 28
533#define E4_INTR_PKT_SIZE 64
matthieu castetb72458a2005-11-07 23:27:13 +0100534
535static struct usb_driver uea_driver;
Arjan van de Venab3c81f2006-01-13 15:52:55 +0100536static DEFINE_MUTEX(uea_mutex);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200537static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
matthieu castetb72458a2005-11-07 23:27:13 +0100538
539static int modem_index;
540static unsigned int debug;
Stanislaw Gruszka503add42007-08-20 23:21:06 +0200541static unsigned int altsetting[NB_MODEM] = {[0 ... (NB_MODEM - 1)] = FASTEST_ISO_INTF};
matthieu castetb72458a2005-11-07 23:27:13 +0100542static int sync_wait[NB_MODEM];
543static char *cmv_file[NB_MODEM];
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200544static int annex[NB_MODEM];
matthieu castetb72458a2005-11-07 23:27:13 +0100545
546module_param(debug, uint, 0644);
547MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
Stanislaw Gruszka503add42007-08-20 23:21:06 +0200548module_param_array(altsetting, uint, NULL, 0644);
549MODULE_PARM_DESC(altsetting, "alternate setting for incoming traffic: 0=bulk, "
550 "1=isoc slowest, ... , 8=isoc fastest (default)");
matthieu castetb72458a2005-11-07 23:27:13 +0100551module_param_array(sync_wait, bool, NULL, 0644);
552MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
553module_param_array(cmv_file, charp, NULL, 0644);
554MODULE_PARM_DESC(cmv_file,
555 "file name with configuration and management variables");
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200556module_param_array(annex, uint, NULL, 0644);
557MODULE_PARM_DESC(annex,
558 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
matthieu castetb72458a2005-11-07 23:27:13 +0100559
560#define UPDATE_ATM_STAT(type, val) \
561 do { \
562 if (sc->usbatm->atm_dev) \
563 sc->usbatm->atm_dev->type = val; \
564 } while (0)
565
566/* Firmware loading */
567#define LOAD_INTERNAL 0xA0
568#define F8051_USBCS 0x7f92
569
570/**
571 * uea_send_modem_cmd - Send a command for pre-firmware devices.
572 */
573static int uea_send_modem_cmd(struct usb_device *usb,
574 u16 addr, u16 size, u8 * buff)
575{
576 int ret = -ENOMEM;
577 u8 *xfer_buff;
578
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +0200579 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +0100580 if (xfer_buff) {
matthieu castetb72458a2005-11-07 23:27:13 +0100581 ret = usb_control_msg(usb,
582 usb_sndctrlpipe(usb, 0),
583 LOAD_INTERNAL,
584 USB_DIR_OUT | USB_TYPE_VENDOR |
585 USB_RECIP_DEVICE, addr, 0, xfer_buff,
586 size, CTRL_TIMEOUT);
587 kfree(xfer_buff);
588 }
589
590 if (ret < 0)
591 return ret;
592
593 return (ret == size) ? 0 : -EIO;
594}
595
596static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *context)
597{
598 struct usb_device *usb = context;
599 u8 *pfw, value;
600 u32 crc = 0;
601 int ret, size;
602
603 uea_enters(usb);
604 if (!fw_entry) {
605 uea_err(usb, "firmware is not available\n");
606 goto err;
607 }
608
609 pfw = fw_entry->data;
610 size = fw_entry->size;
matthieu castet8d7802e2005-11-08 00:02:30 +0100611 if (size < 4)
612 goto err_fw_corrupted;
matthieu castetb72458a2005-11-07 23:27:13 +0100613
614 crc = FW_GET_LONG(pfw);
615 pfw += 4;
616 size -= 4;
matthieu castet8d7802e2005-11-08 00:02:30 +0100617 if (crc32_be(0, pfw, size) != crc)
618 goto err_fw_corrupted;
matthieu castetb72458a2005-11-07 23:27:13 +0100619
620 /*
621 * Start to upload formware : send reset
622 */
623 value = 1;
624 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
625
626 if (ret < 0) {
627 uea_err(usb, "modem reset failed with error %d\n", ret);
628 goto err;
629 }
630
matthieu castet8d7802e2005-11-08 00:02:30 +0100631 while (size > 3) {
matthieu castetb72458a2005-11-07 23:27:13 +0100632 u8 len = FW_GET_BYTE(pfw);
633 u16 add = FW_GET_WORD(pfw + 1);
matthieu castet8d7802e2005-11-08 00:02:30 +0100634
635 size -= len + 3;
636 if (size < 0)
637 goto err_fw_corrupted;
638
matthieu castetb72458a2005-11-07 23:27:13 +0100639 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
640 if (ret < 0) {
641 uea_err(usb, "uploading firmware data failed "
642 "with error %d\n", ret);
643 goto err;
644 }
645 pfw += len + 3;
matthieu castetb72458a2005-11-07 23:27:13 +0100646 }
647
matthieu castet8d7802e2005-11-08 00:02:30 +0100648 if (size != 0)
649 goto err_fw_corrupted;
650
matthieu castetb72458a2005-11-07 23:27:13 +0100651 /*
652 * Tell the modem we finish : de-assert reset
653 */
654 value = 0;
655 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
656 if (ret < 0)
657 uea_err(usb, "modem de-assert failed with error %d\n", ret);
658 else
659 uea_info(usb, "firmware uploaded\n");
660
matthieu castet8d7802e2005-11-08 00:02:30 +0100661 uea_leaves(usb);
662 return;
663
664err_fw_corrupted:
665 uea_err(usb, "firmware is corrupted\n");
matthieu castetb72458a2005-11-07 23:27:13 +0100666err:
667 uea_leaves(usb);
668}
669
670/**
671 * uea_load_firmware - Load usb firmware for pre-firmware devices.
672 */
673static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
674{
675 int ret;
676 char *fw_name = FW_DIR "eagle.fw";
677
678 uea_enters(usb);
679 uea_info(usb, "pre-firmware device, uploading firmware\n");
680
681 switch (ver) {
682 case ADI930:
683 fw_name = FW_DIR "adi930.fw";
684 break;
685 case EAGLE_I:
686 fw_name = FW_DIR "eagleI.fw";
687 break;
688 case EAGLE_II:
689 fw_name = FW_DIR "eagleII.fw";
690 break;
691 case EAGLE_III:
692 fw_name = FW_DIR "eagleIII.fw";
693 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200694 case EAGLE_IV:
695 fw_name = FW_DIR "eagleIV.fw";
696 break;
matthieu castetb72458a2005-11-07 23:27:13 +0100697 }
698
699 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware);
700 if (ret)
701 uea_err(usb, "firmware %s is not available\n", fw_name);
702 else
703 uea_info(usb, "loading firmware %s\n", fw_name);
704
705 uea_leaves(usb);
706 return ret;
707}
708
709/* modem management : dsp firmware, send/read CMV, monitoring statistic
710 */
711
712/*
713 * Make sure that the DSP code provided is safe to use.
714 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200715static int check_dsp_e1(u8 *dsp, unsigned int len)
matthieu castetb72458a2005-11-07 23:27:13 +0100716{
717 u8 pagecount, blockcount;
718 u16 blocksize;
719 u32 pageoffset;
720 unsigned int i, j, p, pp;
721
matthieu castetb72458a2005-11-07 23:27:13 +0100722 pagecount = FW_GET_BYTE(dsp);
723 p = 1;
724
725 /* enough space for page offsets? */
726 if (p + 4 * pagecount > len)
727 return 1;
728
729 for (i = 0; i < pagecount; i++) {
730
731 pageoffset = FW_GET_LONG(dsp + p);
732 p += 4;
733
734 if (pageoffset == 0)
735 continue;
736
737 /* enough space for blockcount? */
738 if (pageoffset >= len)
739 return 1;
740
741 pp = pageoffset;
742 blockcount = FW_GET_BYTE(dsp + pp);
743 pp += 1;
744
745 for (j = 0; j < blockcount; j++) {
746
747 /* enough space for block header? */
748 if (pp + 4 > len)
749 return 1;
750
751 pp += 2; /* skip blockaddr */
752 blocksize = FW_GET_WORD(dsp + pp);
753 pp += 2;
754
755 /* enough space for block data? */
756 if (pp + blocksize > len)
757 return 1;
758
759 pp += blocksize;
760 }
761 }
762
763 return 0;
764}
765
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200766static int check_dsp_e4(u8 *dsp, int len)
767{
768 int i;
769 struct l1_code *p = (struct l1_code *) dsp;
770 unsigned int sum = p->code - dsp;
771
772 if (len < sum)
773 return 1;
774
775 if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 &&
776 strcmp("STRATIPHY ANEXB", p->string_header) != 0)
777 return 1;
778
779 for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) {
780 struct block_index *blockidx;
781 u8 blockno = p->page_number_to_block_index[i];
782 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
783 continue;
784
785 do {
786 u64 l;
787
788 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
789 return 1;
790
791 blockidx = &p->page_header[blockno++];
792 if ((u8 *)(blockidx + 1) - dsp >= len)
793 return 1;
794
795 if (le16_to_cpu(blockidx->PageNumber) != i)
796 return 1;
797
798 l = E4_PAGE_BYTES(blockidx->PageSize);
799 sum += l;
800 l += le32_to_cpu(blockidx->PageOffset);
801 if (l > len)
802 return 1;
803
804 /* zero is zero regardless endianes */
805 } while (blockidx->NotLastBlock);
806 }
807
808 return (sum == len) ? 0 : 1;
809}
810
matthieu castetb72458a2005-11-07 23:27:13 +0100811/*
812 * send data to the idma pipe
813 * */
814static int uea_idma_write(struct uea_softc *sc, void *data, u32 size)
815{
816 int ret = -ENOMEM;
817 u8 *xfer_buff;
818 int bytes_read;
819
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +0200820 xfer_buff = kmemdup(data, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +0100821 if (!xfer_buff) {
822 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
823 return ret;
824 }
825
matthieu castetb72458a2005-11-07 23:27:13 +0100826 ret = usb_bulk_msg(sc->usb_dev,
827 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
828 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
829
830 kfree(xfer_buff);
831 if (ret < 0)
832 return ret;
833 if (size != bytes_read) {
834 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
835 bytes_read);
836 return -EIO;
837 }
838
839 return 0;
840}
841
842static int request_dsp(struct uea_softc *sc)
843{
844 int ret;
845 char *dsp_name;
846
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200847 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200848 if (IS_ISDN(sc))
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200849 dsp_name = FW_DIR "DSP4i.bin";
850 else
851 dsp_name = FW_DIR "DSP4p.bin";
852 } else if (UEA_CHIP_VERSION(sc) == ADI930) {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200853 if (IS_ISDN(sc))
matthieu castetb72458a2005-11-07 23:27:13 +0100854 dsp_name = FW_DIR "DSP9i.bin";
855 else
856 dsp_name = FW_DIR "DSP9p.bin";
857 } else {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200858 if (IS_ISDN(sc))
matthieu castetb72458a2005-11-07 23:27:13 +0100859 dsp_name = FW_DIR "DSPei.bin";
860 else
861 dsp_name = FW_DIR "DSPep.bin";
862 }
863
matthieu castete40abaf2006-01-18 07:38:37 +0100864 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
matthieu castetb72458a2005-11-07 23:27:13 +0100865 if (ret < 0) {
866 uea_err(INS_TO_USBDEV(sc),
867 "requesting firmware %s failed with error %d\n",
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200868 dsp_name, ret);
matthieu castetb72458a2005-11-07 23:27:13 +0100869 return ret;
870 }
871
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200872 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
873 ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size);
874 else
875 ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size);
876
877 if (ret) {
matthieu castetb72458a2005-11-07 23:27:13 +0100878 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
879 dsp_name);
880 release_firmware(sc->dsp_firm);
881 sc->dsp_firm = NULL;
882 return -EILSEQ;
883 }
884
885 return 0;
886}
887
888/*
889 * The uea_load_page() function must be called within a process context
890 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200891static void uea_load_page_e1(struct work_struct *work)
matthieu castetb72458a2005-11-07 23:27:13 +0100892{
David Howellsc4028952006-11-22 14:57:56 +0000893 struct uea_softc *sc = container_of(work, struct uea_softc, task);
matthieu castetb72458a2005-11-07 23:27:13 +0100894 u16 pageno = sc->pageno;
895 u16 ovl = sc->ovl;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200896 struct block_info_e1 bi;
matthieu castetb72458a2005-11-07 23:27:13 +0100897
898 u8 *p;
899 u8 pagecount, blockcount;
900 u16 blockaddr, blocksize;
901 u32 pageoffset;
902 int i;
903
904 /* reload firmware when reboot start and it's loaded already */
905 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
906 release_firmware(sc->dsp_firm);
907 sc->dsp_firm = NULL;
908 }
909
910 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
911 return;
912
913 p = sc->dsp_firm->data;
914 pagecount = FW_GET_BYTE(p);
915 p += 1;
916
917 if (pageno >= pagecount)
918 goto bad1;
919
920 p += 4 * pageno;
921 pageoffset = FW_GET_LONG(p);
922
923 if (pageoffset == 0)
924 goto bad1;
925
926 p = sc->dsp_firm->data + pageoffset;
927 blockcount = FW_GET_BYTE(p);
928 p += 1;
929
930 uea_dbg(INS_TO_USBDEV(sc),
931 "sending %u blocks for DSP page %u\n", blockcount, pageno);
932
933 bi.wHdr = cpu_to_le16(UEA_BIHDR);
934 bi.wOvl = cpu_to_le16(ovl);
935 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
936
937 for (i = 0; i < blockcount; i++) {
938 blockaddr = FW_GET_WORD(p);
939 p += 2;
940
941 blocksize = FW_GET_WORD(p);
942 p += 2;
943
944 bi.wSize = cpu_to_le16(blocksize);
945 bi.wAddress = cpu_to_le16(blockaddr);
946 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
947
948 /* send block info through the IDMA pipe */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200949 if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE))
matthieu castetb72458a2005-11-07 23:27:13 +0100950 goto bad2;
951
952 /* send block data through the IDMA pipe */
953 if (uea_idma_write(sc, p, blocksize))
954 goto bad2;
955
956 p += blocksize;
957 }
958
959 return;
960
961bad2:
962 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
963 return;
964bad1:
matthieu castet2a99b502006-04-02 18:43:53 +0200965 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
matthieu castetb72458a2005-11-07 23:27:13 +0100966}
967
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200968static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
969{
970 struct block_info_e4 bi;
971 struct block_index *blockidx;
972 struct l1_code *p = (struct l1_code *) sc->dsp_firm->data;
973 u8 blockno = p->page_number_to_block_index[pageno];
974
975 bi.wHdr = cpu_to_be16(UEA_BIHDR);
976 bi.bBootPage = boot;
977 bi.bPageNumber = pageno;
978 bi.wReserved = cpu_to_be16(UEA_RESERVED);
979
980 do {
981 u8 *blockoffset;
982 unsigned int blocksize;
983
984 blockidx = &p->page_header[blockno];
985 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
986 blockoffset = sc->dsp_firm->data + le32_to_cpu(blockidx->PageOffset);
987
988 bi.dwSize = cpu_to_be32(blocksize);
989 bi.dwAddress = swab32(blockidx->PageAddress);
990
991 uea_dbg(INS_TO_USBDEV(sc),
992 "sending block %u for DSP page %u size %u adress %x\n",
993 blockno, pageno, blocksize, le32_to_cpu(blockidx->PageAddress));
994
995 /* send block info through the IDMA pipe */
996 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
997 goto bad;
998
999 /* send block data through the IDMA pipe */
1000 if (uea_idma_write(sc, blockoffset, blocksize))
1001 goto bad;
1002
1003 blockno++;
1004 } while (blockidx->NotLastBlock);
1005
1006 return;
1007
1008bad:
1009 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno);
1010 return;
1011}
1012
1013static void uea_load_page_e4(struct work_struct *work)
1014{
1015 struct uea_softc *sc = container_of(work, struct uea_softc, task);
1016 u8 pageno = sc->pageno;
1017 int i;
1018 struct block_info_e4 bi;
1019 struct l1_code *p;
1020
1021 uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
1022
1023 /* reload firmware when reboot start and it's loaded already */
1024 if (pageno == 0 && sc->dsp_firm) {
1025 release_firmware(sc->dsp_firm);
1026 sc->dsp_firm = NULL;
1027 }
1028
1029 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
1030 return;
1031
1032 p = (struct l1_code *) sc->dsp_firm->data;
1033 if (pageno >= p->page_header[0].PageNumber) {
1034 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
1035 return;
1036 }
1037
1038 if (pageno != 0) {
1039 __uea_load_page_e4(sc, pageno, 0);
1040 return;
1041 }
1042
1043 uea_dbg(INS_TO_USBDEV(sc),
1044 "sending Main DSP page %u\n", p->page_header[0].PageNumber);
1045
1046 for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) {
1047 if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize))
1048 __uea_load_page_e4(sc, i, 1);
1049 }
1050
1051 uea_dbg(INS_TO_USBDEV(sc),"sending start bi\n");
1052
1053 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1054 bi.bBootPage = 0;
1055 bi.bPageNumber = 0xff;
1056 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1057 bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize));
1058 bi.dwAddress = swab32(p->page_header[0].PageAddress);
1059
1060 /* send block info through the IDMA pipe */
1061 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1062 uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n");
1063}
1064
matthieu castetb72458a2005-11-07 23:27:13 +01001065static inline void wake_up_cmv_ack(struct uea_softc *sc)
1066{
matthieu castet2a99b502006-04-02 18:43:53 +02001067 BUG_ON(sc->cmv_ack);
matthieu castetb72458a2005-11-07 23:27:13 +01001068 sc->cmv_ack = 1;
1069 wake_up(&sc->cmv_ack_wait);
1070}
1071
1072static inline int wait_cmv_ack(struct uea_softc *sc)
1073{
matthieu castet531a39b2006-10-03 21:49:29 +02001074 int ret = wait_event_interruptible_timeout(sc->cmv_ack_wait,
matthieu castetb72458a2005-11-07 23:27:13 +01001075 sc->cmv_ack, ACK_TIMEOUT);
1076 sc->cmv_ack = 0;
1077
matthieu castet2a99b502006-04-02 18:43:53 +02001078 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
1079 jiffies_to_msecs(ret));
1080
matthieu castetb72458a2005-11-07 23:27:13 +01001081 if (ret < 0)
1082 return ret;
1083
1084 return (ret == 0) ? -ETIMEDOUT : 0;
matthieu castetb72458a2005-11-07 23:27:13 +01001085}
1086
1087#define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1088
1089static int uea_request(struct uea_softc *sc,
1090 u16 value, u16 index, u16 size, void *data)
1091{
1092 u8 *xfer_buff;
1093 int ret = -ENOMEM;
1094
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +02001095 xfer_buff = kmemdup(data, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +01001096 if (!xfer_buff) {
1097 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
1098 return ret;
1099 }
matthieu castetb72458a2005-11-07 23:27:13 +01001100
1101 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
1102 UCDC_SEND_ENCAPSULATED_COMMAND,
1103 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1104 value, index, xfer_buff, size, CTRL_TIMEOUT);
1105
1106 kfree(xfer_buff);
1107 if (ret < 0) {
1108 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
1109 return ret;
1110 }
1111
1112 if (ret != size) {
1113 uea_err(INS_TO_USBDEV(sc),
1114 "usb_control_msg send only %d bytes (instead of %d)\n",
1115 ret, size);
1116 return -EIO;
1117 }
1118
1119 return 0;
1120}
1121
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001122static int uea_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001123 u8 function, u32 address, u16 offset, u32 data)
1124{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001125 struct cmv_e1 cmv;
matthieu castetb72458a2005-11-07 23:27:13 +01001126 int ret;
1127
matthieu castet2a99b502006-04-02 18:43:53 +02001128 uea_enters(INS_TO_USBDEV(sc));
1129 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1130 "offset : 0x%04x, data : 0x%08x\n",
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001131 E1_FUNCTION_TYPE(function), E1_FUNCTION_SUBTYPE(function),
1132 E1_GETSA1(address), E1_GETSA2(address), E1_GETSA3(address),
1133 E1_GETSA4(address), offset, data);
matthieu castetb72458a2005-11-07 23:27:13 +01001134
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001135 /* we send a request, but we expect a reply */
1136 sc->cmv_dsc.e1.function = function | 0x2;
1137 sc->cmv_dsc.e1.idx++;
1138 sc->cmv_dsc.e1.address = address;
1139 sc->cmv_dsc.e1.offset = offset;
1140
1141 cmv.wPreamble = cpu_to_le16(E1_PREAMBLE);
1142 cmv.bDirection = E1_HOSTTOMODEM;
matthieu castetb72458a2005-11-07 23:27:13 +01001143 cmv.bFunction = function;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001144 cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx);
matthieu castetb72458a2005-11-07 23:27:13 +01001145 put_unaligned(cpu_to_le32(address), &cmv.dwSymbolicAddress);
1146 cmv.wOffsetAddress = cpu_to_le16(offset);
1147 put_unaligned(cpu_to_le32(data >> 16 | data << 16), &cmv.dwData);
1148
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001149 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv);
matthieu castetb72458a2005-11-07 23:27:13 +01001150 if (ret < 0)
1151 return ret;
matthieu castet2a99b502006-04-02 18:43:53 +02001152 ret = wait_cmv_ack(sc);
1153 uea_leaves(INS_TO_USBDEV(sc));
1154 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001155}
1156
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001157static int uea_cmv_e4(struct uea_softc *sc,
1158 u16 function, u16 group, u16 address, u16 offset, u32 data)
1159{
1160 struct cmv_e4 cmv;
1161 int ret;
1162
1163 uea_enters(INS_TO_USBDEV(sc));
1164 memset(&cmv, 0, sizeof(cmv));
1165
1166 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
1167 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1168 E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function),
1169 group, address, offset, data);
1170
1171 /* we send a request, but we expect a reply */
1172 sc->cmv_dsc.e4.function = function | (0x1 << 4);
1173 sc->cmv_dsc.e4.offset = offset;
1174 sc->cmv_dsc.e4.address = address;
1175 sc->cmv_dsc.e4.group = group;
1176
1177 cmv.wFunction = cpu_to_be16(function);
1178 cmv.wGroup = cpu_to_be16(group);
1179 cmv.wAddress = cpu_to_be16(address);
1180 cmv.wOffset = cpu_to_be16(offset);
1181 cmv.dwData[0] = cpu_to_be32(data);
1182
1183 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv);
1184 if (ret < 0)
1185 return ret;
1186 ret = wait_cmv_ack(sc);
1187 uea_leaves(INS_TO_USBDEV(sc));
1188 return ret;
1189}
1190
1191static inline int uea_read_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001192 u32 address, u16 offset, u32 *data)
1193{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001194 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD),
matthieu castetb72458a2005-11-07 23:27:13 +01001195 address, offset, 0);
1196 if (ret < 0)
1197 uea_err(INS_TO_USBDEV(sc),
1198 "reading cmv failed with error %d\n", ret);
1199 else
1200 *data = sc->data;
1201
1202 return ret;
1203}
1204
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001205static inline int uea_read_cmv_e4(struct uea_softc *sc,
1206 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1207{
1208 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTREAD, size),
1209 group, address, offset, 0);
1210 if (ret < 0)
1211 uea_err(INS_TO_USBDEV(sc),
1212 "reading cmv failed with error %d\n", ret);
1213 else {
1214 *data = sc->data;
1215 /* size is in 16-bit word quantities */
1216 if (size > 2)
1217 *(data + 1) = sc->data1;
1218 }
1219 return ret;
1220}
1221
1222static inline int uea_write_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001223 u32 address, u16 offset, u32 data)
1224{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001225 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE),
matthieu castetb72458a2005-11-07 23:27:13 +01001226 address, offset, data);
1227 if (ret < 0)
1228 uea_err(INS_TO_USBDEV(sc),
1229 "writing cmv failed with error %d\n", ret);
1230
1231 return ret;
1232}
1233
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001234static inline int uea_write_cmv_e4(struct uea_softc *sc,
1235 u8 size, u16 group, u16 address, u16 offset, u32 data)
1236{
1237 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTWRITE, size),
1238 group, address, offset, data);
1239 if (ret < 0)
1240 uea_err(INS_TO_USBDEV(sc),
1241 "writing cmv failed with error %d\n", ret);
1242
1243 return ret;
1244}
1245
1246static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1247{
1248 int ret;
1249 u16 timeout;
1250
1251 /* in bulk mode the modem have problem with high rate
1252 * changing internal timing could improve things, but the
1253 * value is misterious.
1254 * ADI930 don't support it (-EPIPE error).
1255 */
1256
1257 if (UEA_CHIP_VERSION(sc) == ADI930 ||
Stanislaw Gruszka503add42007-08-20 23:21:06 +02001258 altsetting[sc->modem_index] > 0 ||
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001259 sc->stats.phy.dsrate == dsrate)
1260 return;
1261
1262 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1263 timeout = (dsrate <= 1024*1024) ? 0 : 1;
1264 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
1265 uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n",
1266 timeout, ret < 0 ? " failed" : "");
1267
1268}
1269
matthieu castetb72458a2005-11-07 23:27:13 +01001270/*
1271 * Monitor the modem and update the stat
1272 * return 0 if everything is ok
1273 * return < 0 if an error occurs (-EAGAIN reboot needed)
1274 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001275static int uea_stat_e1(struct uea_softc *sc)
matthieu castetb72458a2005-11-07 23:27:13 +01001276{
1277 u32 data;
1278 int ret;
1279
1280 uea_enters(INS_TO_USBDEV(sc));
1281 data = sc->stats.phy.state;
1282
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001283 ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state);
matthieu castetb72458a2005-11-07 23:27:13 +01001284 if (ret < 0)
1285 return ret;
1286
1287 switch (GET_STATUS(sc->stats.phy.state)) {
1288 case 0: /* not yet synchronized */
1289 uea_dbg(INS_TO_USBDEV(sc),
1290 "modem not yet synchronized\n");
1291 return 0;
1292
1293 case 1: /* initialization */
1294 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1295 return 0;
1296
1297 case 2: /* operational */
1298 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
1299 break;
1300
1301 case 3: /* fail ... */
matthieu casteta7a0c9c2006-10-03 21:44:11 +02001302 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001303 " (may be try other cmv/dsp)\n");
matthieu castetb72458a2005-11-07 23:27:13 +01001304 return -EAGAIN;
1305
1306 case 4 ... 6: /* test state */
1307 uea_warn(INS_TO_USBDEV(sc),
1308 "modem in test mode - not supported\n");
1309 return -EAGAIN;
1310
1311 case 7: /* fast-retain ... */
1312 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
1313 return 0;
1314 default:
1315 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
1316 GET_STATUS(sc->stats.phy.state));
1317 return -EAGAIN;
1318 }
1319
1320 if (GET_STATUS(data) != 2) {
1321 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1322 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1323
1324 /* release the dsp firmware as it is not needed until
1325 * the next failure
1326 */
1327 if (sc->dsp_firm) {
1328 release_firmware(sc->dsp_firm);
1329 sc->dsp_firm = NULL;
1330 }
matthieu castetb72458a2005-11-07 23:27:13 +01001331 }
1332
1333 /* always update it as atm layer could not be init when we switch to
1334 * operational state
1335 */
1336 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1337
1338 /* wake up processes waiting for synchronization */
1339 wake_up(&sc->sync_q);
1340
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001341 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags);
matthieu castetb72458a2005-11-07 23:27:13 +01001342 if (ret < 0)
1343 return ret;
1344 sc->stats.phy.mflags |= sc->stats.phy.flags;
1345
1346 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1347 * we check the status again in order to detect the failure earlier
1348 */
1349 if (sc->stats.phy.flags) {
matthieu castet2a99b502006-04-02 18:43:53 +02001350 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
matthieu castetb72458a2005-11-07 23:27:13 +01001351 sc->stats.phy.flags);
1352 return 0;
1353 }
1354
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001355 ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001356 if (ret < 0)
1357 return ret;
1358
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001359 uea_set_bulk_timeout(sc, (data >> 16) * 32);
matthieu castetb72458a2005-11-07 23:27:13 +01001360 sc->stats.phy.dsrate = (data >> 16) * 32;
1361 sc->stats.phy.usrate = (data & 0xffff) * 32;
1362 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1363
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001364 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001365 if (ret < 0)
1366 return ret;
1367 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
1368
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001369 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001370 if (ret < 0)
1371 return ret;
1372 sc->stats.phy.usattenuation = (data & 0xff) / 2;
1373
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001374 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin);
matthieu castetb72458a2005-11-07 23:27:13 +01001375 if (ret < 0)
1376 return ret;
1377
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001378 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin);
matthieu castetb72458a2005-11-07 23:27:13 +01001379 if (ret < 0)
1380 return ret;
1381
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001382 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow);
matthieu castetb72458a2005-11-07 23:27:13 +01001383 if (ret < 0)
1384 return ret;
1385
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001386 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow);
matthieu castetb72458a2005-11-07 23:27:13 +01001387 if (ret < 0)
1388 return ret;
1389
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001390 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc);
matthieu castetb72458a2005-11-07 23:27:13 +01001391 if (ret < 0)
1392 return ret;
1393
1394 /* only for atu-c */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001395 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc);
matthieu castetb72458a2005-11-07 23:27:13 +01001396 if (ret < 0)
1397 return ret;
1398
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001399 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr);
matthieu castetb72458a2005-11-07 23:27:13 +01001400 if (ret < 0)
1401 return ret;
1402
1403 /* only for atu-c */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001404 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr);
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_INFO, 8, &sc->stats.phy.vidco);
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_INFO, 13, &sc->stats.phy.vidcpe);
matthieu castetb72458a2005-11-07 23:27:13 +01001413 if (ret < 0)
1414 return ret;
1415
1416 return 0;
1417}
1418
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001419static int uea_stat_e4(struct uea_softc *sc)
matthieu castetb72458a2005-11-07 23:27:13 +01001420{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001421 u32 data;
1422 u32 tmp_arr[2];
1423 int ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001424
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001425 uea_enters(INS_TO_USBDEV(sc));
1426 data = sc->stats.phy.state;
1427
1428 /* XXX only need to be done before operationnal... */
1429 ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state);
1430 if (ret < 0)
1431 return ret;
1432
1433 switch (sc->stats.phy.state) {
1434 case 0x0: /* not yet synchronized */
1435 case 0x1:
1436 case 0x3:
1437 case 0x4:
1438 uea_dbg(INS_TO_USBDEV(sc), "modem not yet synchronized\n");
1439 return 0;
1440 case 0x5: /* initialization */
1441 case 0x6:
1442 case 0x9:
1443 case 0xa:
1444 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1445 return 0;
1446 case 0x2: /* fail ... */
1447 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
1448 " (may be try other cmv/dsp)\n");
1449 return -EAGAIN;
1450 case 0x7: /* operational */
1451 break;
1452 default:
1453 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n", sc->stats.phy.state);
1454 return 0;
1455 }
1456
1457 if (data != 7) {
1458 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1459 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1460
1461 /* release the dsp firmware as it is not needed until
1462 * the next failure
1463 */
1464 if (sc->dsp_firm) {
1465 release_firmware(sc->dsp_firm);
1466 sc->dsp_firm = NULL;
1467 }
1468 }
1469
1470 /* always update it as atm layer could not be init when we switch to
1471 * operational state
1472 */
1473 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
1474
1475 /* wake up processes waiting for synchronization */
1476 wake_up(&sc->sync_q);
1477
1478 /* TODO improve this state machine :
1479 * we need some CMV info : what they do and their unit
1480 * we should find the equivalent of eagle3- CMV
1481 */
1482 /* check flags */
1483 ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags);
1484 if (ret < 0)
1485 return ret;
1486 sc->stats.phy.mflags |= sc->stats.phy.flags;
1487
1488 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1489 * we check the status again in order to detect the failure earlier
1490 */
1491 if (sc->stats.phy.flags) {
1492 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1493 sc->stats.phy.flags);
1494 if (sc->stats.phy.flags & 1) //delineation LOSS
1495 return -EAGAIN;
1496 if (sc->stats.phy.flags & 0x4000) //Reset Flag
1497 return -EAGAIN;
1498 return 0;
1499 }
1500
1501 /* rate data may be in upper or lower half of 64 bit word, strange */
1502 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr);
1503 if (ret < 0)
1504 return ret;
1505 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1506 sc->stats.phy.usrate = data / 1000;
1507
1508 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr);
1509 if (ret < 0)
1510 return ret;
1511 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1512 uea_set_bulk_timeout(sc, data / 1000);
1513 sc->stats.phy.dsrate = data / 1000;
1514 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1515
1516 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data);
1517 if (ret < 0)
1518 return ret;
1519 sc->stats.phy.dsattenuation = data / 10;
1520
1521 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data);
1522 if (ret < 0)
1523 return ret;
1524 sc->stats.phy.usattenuation = data / 10;
1525
1526 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data);
1527 if (ret < 0)
1528 return ret;
1529 sc->stats.phy.dsmargin = data / 2;
1530
1531 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data);
1532 if (ret < 0)
1533 return ret;
1534 sc->stats.phy.usmargin = data / 10;
1535
1536 return 0;
1537}
1538
1539static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1540{
1541 char file_arr[] = "CMVxy.bin";
1542 char *file;
1543
1544 /* set proper name corresponding modem version and line type */
matthieu castetb72458a2005-11-07 23:27:13 +01001545 if (cmv_file[sc->modem_index] == NULL) {
1546 if (UEA_CHIP_VERSION(sc) == ADI930)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001547 file_arr[3] = '9';
1548 else if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1549 file_arr[3] = '4';
matthieu castetb72458a2005-11-07 23:27:13 +01001550 else
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001551 file_arr[3] = 'e';
1552
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02001553 file_arr[4] = IS_ISDN(sc) ? 'i' : 'p';
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001554 file = file_arr;
matthieu castetb72458a2005-11-07 23:27:13 +01001555 } else
1556 file = cmv_file[sc->modem_index];
1557
1558 strcpy(cmv_name, FW_DIR);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001559 strlcat(cmv_name, file, FIRMWARE_NAME_MAX);
1560 if (ver == 2)
1561 strlcat(cmv_name, ".v2", FIRMWARE_NAME_MAX);
1562}
matthieu castetb72458a2005-11-07 23:27:13 +01001563
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001564static int request_cmvs_old(struct uea_softc *sc,
1565 void **cmvs, const struct firmware **fw)
1566{
1567 int ret, size;
1568 u8 *data;
1569 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1570
1571 cmvs_file_name(sc, cmv_name, 1);
matthieu castetb72458a2005-11-07 23:27:13 +01001572 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1573 if (ret < 0) {
1574 uea_err(INS_TO_USBDEV(sc),
1575 "requesting firmware %s failed with error %d\n",
1576 cmv_name, ret);
1577 return ret;
1578 }
1579
1580 data = (u8 *) (*fw)->data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001581 size = (*fw)->size;
1582 if (size < 1)
1583 goto err_fw_corrupted;
1584
1585 if (size != *data * sizeof(struct uea_cmvs_v1) + 1)
1586 goto err_fw_corrupted;
1587
1588 *cmvs = (void *)(data + 1);
1589 return *data;
1590
1591err_fw_corrupted:
1592 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1593 release_firmware(*fw);
1594 return -EILSEQ;
1595}
1596
1597static int request_cmvs(struct uea_softc *sc,
1598 void **cmvs, const struct firmware **fw, int *ver)
1599{
1600 int ret, size;
1601 u32 crc;
1602 u8 *data;
1603 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1604
1605 cmvs_file_name(sc, cmv_name, 2);
1606 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1607 if (ret < 0) {
1608 /* if caller can handle old version, try to provide it */
1609 if (*ver == 1) {
1610 uea_warn(INS_TO_USBDEV(sc), "requesting firmware %s failed, "
1611 "try to get older cmvs\n", cmv_name);
1612 return request_cmvs_old(sc, cmvs, fw);
1613 }
1614 uea_err(INS_TO_USBDEV(sc),
1615 "requesting firmware %s failed with error %d\n",
1616 cmv_name, ret);
1617 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001618 }
1619
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001620 size = (*fw)->size;
1621 data = (u8 *) (*fw)->data;
1622 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1623 if (*ver == 1) {
1624 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted, "
1625 "try to get older cmvs\n", cmv_name);
1626 release_firmware(*fw);
1627 return request_cmvs_old(sc, cmvs, fw);
1628 }
1629 goto err_fw_corrupted;
1630 }
1631
1632 *ver = 2;
1633
1634 data += 4;
1635 size -= 4;
1636 if (size < 5)
1637 goto err_fw_corrupted;
1638
1639 crc = FW_GET_LONG(data);
1640 data += 4;
1641 size -= 4;
1642 if (crc32_be(0, data, size) != crc)
1643 goto err_fw_corrupted;
1644
1645 if (size != *data * sizeof(struct uea_cmvs_v2) + 1)
1646 goto err_fw_corrupted;
1647
1648 *cmvs = (void *) (data + 1);
matthieu castetb72458a2005-11-07 23:27:13 +01001649 return *data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001650
1651err_fw_corrupted:
1652 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1653 release_firmware(*fw);
1654 return -EILSEQ;
1655}
1656
1657static int uea_send_cmvs_e1(struct uea_softc *sc)
1658{
1659 int i, ret, len;
1660 void *cmvs_ptr;
1661 const struct firmware *cmvs_fw;
1662 int ver = 1; // we can handle v1 cmv firmware version;
1663
1664 /* Enter in R-IDLE (cmv) until instructed otherwise */
1665 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
1666 if (ret < 0)
1667 return ret;
1668
1669 /* Dump firmware version */
1670 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid);
1671 if (ret < 0)
1672 return ret;
1673 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1674 sc->stats.phy.firmid);
1675
1676 /* get options */
1677 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1678 if (ret < 0)
1679 return ret;
1680
1681 /* send options */
1682 if (ver == 1) {
1683 struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr;
1684
1685 uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, "
1686 "please update your firmware\n");
1687
1688 for (i = 0; i < len; i++) {
1689 ret = uea_write_cmv_e1(sc, FW_GET_LONG(&cmvs_v1[i].address),
1690 FW_GET_WORD(&cmvs_v1[i].offset),
1691 FW_GET_LONG(&cmvs_v1[i].data));
1692 if (ret < 0)
1693 goto out;
1694 }
1695 } else if (ver == 2) {
1696 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1697
1698 for (i = 0; i < len; i++) {
1699 ret = uea_write_cmv_e1(sc, FW_GET_LONG(&cmvs_v2[i].address),
1700 (u16) FW_GET_LONG(&cmvs_v2[i].offset),
1701 FW_GET_LONG(&cmvs_v2[i].data));
1702 if (ret < 0)
1703 goto out;
1704 }
1705 } else {
1706 /* This realy should not happen */
1707 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1708 goto out;
1709 }
1710
1711 /* Enter in R-ACT-REQ */
1712 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1713 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1714 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n");
1715out:
1716 release_firmware(cmvs_fw);
1717 return ret;
1718}
1719
1720static int uea_send_cmvs_e4(struct uea_softc *sc)
1721{
1722 int i, ret, len;
1723 void *cmvs_ptr;
1724 const struct firmware *cmvs_fw;
1725 int ver = 2; // we can only handle v2 cmv firmware version;
1726
1727 /* Enter in R-IDLE (cmv) until instructed otherwise */
1728 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
1729 if (ret < 0)
1730 return ret;
1731
1732 /* Dump firmware version */
1733 /* XXX don't read the 3th byte as it is always 6 */
1734 ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid);
1735 if (ret < 0)
1736 return ret;
1737 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1738 sc->stats.phy.firmid);
1739
1740
1741 /* get options */
1742 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1743 if (ret < 0)
1744 return ret;
1745
1746 /* send options */
1747 if (ver == 2) {
1748 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1749
1750 for (i = 0; i < len; i++) {
1751 ret = uea_write_cmv_e4(sc, 1,
1752 FW_GET_LONG(&cmvs_v2[i].group),
1753 FW_GET_LONG(&cmvs_v2[i].address),
1754 FW_GET_LONG(&cmvs_v2[i].offset),
1755 FW_GET_LONG(&cmvs_v2[i].data));
1756 if (ret < 0)
1757 goto out;
1758 }
1759 } else {
1760 /* This realy should not happen */
1761 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1762 goto out;
1763 }
1764
1765 /* Enter in R-ACT-REQ */
1766 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1767 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1768 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n");
1769out:
1770 release_firmware(cmvs_fw);
1771 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001772}
1773
1774/* Start boot post firmware modem:
1775 * - send reset commands through usb control pipe
1776 * - start workqueue for DSP loading
1777 * - send CMV options to modem
1778 */
1779
1780static int uea_start_reset(struct uea_softc *sc)
1781{
1782 u16 zero = 0; /* ;-) */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001783 int ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001784
1785 uea_enters(INS_TO_USBDEV(sc));
1786 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1787
matthieu castet22fcceb2006-04-02 18:44:20 +02001788 /* mask interrupt */
matthieu castetb72458a2005-11-07 23:27:13 +01001789 sc->booting = 1;
matthieu castet22fcceb2006-04-02 18:44:20 +02001790 /* We need to set this here because, a ack timeout could have occured,
1791 * but before we start the reboot, the ack occurs and set this to 1.
1792 * So we will failed to wait Ready CMV.
1793 */
1794 sc->cmv_ack = 0;
matthieu castetb72458a2005-11-07 23:27:13 +01001795 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST);
1796
1797 /* reset statistics */
1798 memset(&sc->stats, 0, sizeof(struct uea_stats));
1799
1800 /* tell the modem that we want to boot in IDMA mode */
1801 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1802 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1803
1804 /* enter reset mode */
1805 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1806
1807 /* original driver use 200ms, but windows driver use 100ms */
1808 msleep(100);
1809
1810 /* leave reset mode */
1811 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1812
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001813 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
1814 /* clear tx and rx mailboxes */
1815 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1816 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1817 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1818 }
matthieu castetb72458a2005-11-07 23:27:13 +01001819
1820 msleep(1000);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001821
1822 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1823 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1);
1824 else
1825 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY);
1826
matthieu castet22fcceb2006-04-02 18:44:20 +02001827 /* demask interrupt */
matthieu castetb72458a2005-11-07 23:27:13 +01001828 sc->booting = 0;
1829
1830 /* start loading DSP */
1831 sc->pageno = 0;
1832 sc->ovl = 0;
1833 schedule_work(&sc->task);
1834
1835 /* wait for modem ready CMV */
1836 ret = wait_cmv_ack(sc);
1837 if (ret < 0)
1838 return ret;
1839
matthieu castet2a99b502006-04-02 18:43:53 +02001840 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1841
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001842 ret = sc->send_cmvs(sc);
matthieu castetb72458a2005-11-07 23:27:13 +01001843 if (ret < 0)
1844 return ret;
1845
matthieu castetb72458a2005-11-07 23:27:13 +01001846 sc->reset = 0;
1847 uea_leaves(INS_TO_USBDEV(sc));
1848 return ret;
1849}
1850
1851/*
1852 * In case of an error wait 1s before rebooting the modem
1853 * if the modem don't request reboot (-EAGAIN).
1854 * Monitor the modem every 1s.
1855 */
1856
1857static int uea_kthread(void *data)
1858{
1859 struct uea_softc *sc = data;
1860 int ret = -EAGAIN;
1861
Rafael J. Wysocki83144182007-07-17 04:03:35 -07001862 set_freezable();
matthieu castetb72458a2005-11-07 23:27:13 +01001863 uea_enters(INS_TO_USBDEV(sc));
1864 while (!kthread_should_stop()) {
1865 if (ret < 0 || sc->reset)
1866 ret = uea_start_reset(sc);
1867 if (!ret)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001868 ret = sc->stat(sc);
matthieu castetb72458a2005-11-07 23:27:13 +01001869 if (ret != -EAGAIN)
matthieu castet531a39b2006-10-03 21:49:29 +02001870 msleep_interruptible(1000);
matthieu castet9ca53462006-10-03 21:46:33 +02001871 if (try_to_freeze())
1872 uea_err(INS_TO_USBDEV(sc), "suspend/resume not supported, "
1873 "please unplug/replug your modem\n");
matthieu castetb72458a2005-11-07 23:27:13 +01001874 }
1875 uea_leaves(INS_TO_USBDEV(sc));
1876 return ret;
1877}
1878
1879/* Load second usb firmware for ADI930 chip */
1880static int load_XILINX_firmware(struct uea_softc *sc)
1881{
1882 const struct firmware *fw_entry;
1883 int ret, size, u, ln;
1884 u8 *pfw, value;
1885 char *fw_name = FW_DIR "930-fpga.bin";
1886
1887 uea_enters(INS_TO_USBDEV(sc));
1888
1889 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1890 if (ret) {
1891 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1892 fw_name);
1893 goto err0;
1894 }
1895
1896 pfw = fw_entry->data;
1897 size = fw_entry->size;
1898 if (size != 0x577B) {
1899 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1900 fw_name);
1901 ret = -EILSEQ;
1902 goto err1;
1903 }
1904 for (u = 0; u < size; u += ln) {
1905 ln = min(size - u, 64);
1906 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1907 if (ret < 0) {
1908 uea_err(INS_TO_USBDEV(sc),
1909 "elsa download data failed (%d)\n", ret);
1910 goto err1;
1911 }
1912 }
1913
matthieu castete40abaf2006-01-18 07:38:37 +01001914 /* finish to send the fpga */
matthieu castetb72458a2005-11-07 23:27:13 +01001915 ret = uea_request(sc, 0xe, 1, 0, NULL);
1916 if (ret < 0) {
1917 uea_err(INS_TO_USBDEV(sc),
1918 "elsa download data failed (%d)\n", ret);
1919 goto err1;
1920 }
1921
matthieu castete40abaf2006-01-18 07:38:37 +01001922 /* Tell the modem we finish : de-assert reset */
matthieu castetb72458a2005-11-07 23:27:13 +01001923 value = 0;
1924 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1925 if (ret < 0)
1926 uea_err(sc->usb_dev, "elsa de-assert failed with error %d\n", ret);
1927
matthieu castetb72458a2005-11-07 23:27:13 +01001928err1:
1929 release_firmware(fw_entry);
1930err0:
1931 uea_leaves(INS_TO_USBDEV(sc));
1932 return ret;
1933}
1934
matthieu castete40abaf2006-01-18 07:38:37 +01001935/* The modem send us an ack. First with check if it right */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001936static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
matthieu castetb72458a2005-11-07 23:27:13 +01001937{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001938 struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;
1939 struct cmv_e1 *cmv = &intr->u.e1.s2.cmv;
1940
matthieu castetb72458a2005-11-07 23:27:13 +01001941 uea_enters(INS_TO_USBDEV(sc));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001942 if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE)
matthieu castetb72458a2005-11-07 23:27:13 +01001943 goto bad1;
1944
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001945 if (cmv->bDirection != E1_MODEMTOHOST)
matthieu castetb72458a2005-11-07 23:27:13 +01001946 goto bad1;
1947
1948 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1949 * the first MEMACESS cmv. Ignore it...
1950 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001951 if (cmv->bFunction != dsc->function) {
matthieu castetb72458a2005-11-07 23:27:13 +01001952 if (UEA_CHIP_VERSION(sc) == ADI930
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001953 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
1954 cmv->wIndex = cpu_to_le16(dsc->idx);
1955 put_unaligned(cpu_to_le32(dsc->address), &cmv->dwSymbolicAddress);
1956 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
1957 } else
matthieu castetb72458a2005-11-07 23:27:13 +01001958 goto bad2;
1959 }
1960
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001961 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY)) {
matthieu castetb72458a2005-11-07 23:27:13 +01001962 wake_up_cmv_ack(sc);
matthieu castet2a99b502006-04-02 18:43:53 +02001963 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01001964 return;
1965 }
1966
1967 /* in case of MEMACCESS */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001968 if (le16_to_cpu(cmv->wIndex) != dsc->idx ||
1969 le32_to_cpu(get_unaligned(&cmv->dwSymbolicAddress)) != dsc->address ||
1970 le16_to_cpu(cmv->wOffsetAddress) != dsc->offset)
matthieu castetb72458a2005-11-07 23:27:13 +01001971 goto bad2;
1972
1973 sc->data = le32_to_cpu(get_unaligned(&cmv->dwData));
1974 sc->data = sc->data << 16 | sc->data >> 16;
1975
1976 wake_up_cmv_ack(sc);
matthieu castet2a99b502006-04-02 18:43:53 +02001977 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01001978 return;
1979
1980bad2:
1981 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
1982 "Function : %d, Subfunction : %d\n",
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001983 E1_FUNCTION_TYPE(cmv->bFunction),
1984 E1_FUNCTION_SUBTYPE(cmv->bFunction));
matthieu castet2a99b502006-04-02 18:43:53 +02001985 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01001986 return;
1987
1988bad1:
1989 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
1990 "wPreamble %d, bDirection %d\n",
1991 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
matthieu castet2a99b502006-04-02 18:43:53 +02001992 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01001993}
1994
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001995/* The modem send us an ack. First with check if it right */
1996static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
1997{
1998 struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;
1999 struct cmv_e4 *cmv = &intr->u.e4.s2.cmv;
2000
2001 uea_enters(INS_TO_USBDEV(sc));
2002 uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n",
2003 be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction),
2004 be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
2005 be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1]));
2006
2007 if (be16_to_cpu(cmv->wFunction) != dsc->function)
2008 goto bad2;
2009
2010 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1)) {
2011 wake_up_cmv_ack(sc);
2012 uea_leaves(INS_TO_USBDEV(sc));
2013 return;
2014 }
2015
2016 /* in case of MEMACCESS */
2017 if (be16_to_cpu(cmv->wOffset) != dsc->offset ||
2018 be16_to_cpu(cmv->wGroup) != dsc->group ||
2019 be16_to_cpu(cmv->wAddress) != dsc->address)
2020 goto bad2;
2021
2022 sc->data = be32_to_cpu(cmv->dwData[0]);
2023 sc->data1 = be32_to_cpu(cmv->dwData[1]);
2024 wake_up_cmv_ack(sc);
2025 uea_leaves(INS_TO_USBDEV(sc));
2026 return;
2027
2028bad2:
2029 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
2030 "Function : %d, Subfunction : %d\n",
2031 E4_FUNCTION_TYPE(cmv->wFunction),
2032 E4_FUNCTION_SUBTYPE(cmv->wFunction));
2033 uea_leaves(INS_TO_USBDEV(sc));
2034 return;
2035}
2036
2037static void uea_schedule_load_page_e1(struct uea_softc *sc, struct intr_pkt *intr)
2038{
2039 sc->pageno = intr->e1_bSwapPageNo;
2040 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
2041 schedule_work(&sc->task);
2042}
2043
2044static void uea_schedule_load_page_e4(struct uea_softc *sc, struct intr_pkt *intr)
2045{
2046 sc->pageno = intr->e4_bSwapPageNo;
2047 schedule_work(&sc->task);
2048}
2049
matthieu castetb72458a2005-11-07 23:27:13 +01002050/*
2051 * interrupt handler
2052 */
David Howells7d12e782006-10-05 14:55:46 +01002053static void uea_intr(struct urb *urb)
matthieu castetb72458a2005-11-07 23:27:13 +01002054{
matthieu castete40abaf2006-01-18 07:38:37 +01002055 struct uea_softc *sc = urb->context;
2056 struct intr_pkt *intr = urb->transfer_buffer;
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002057 int status = urb->status;
2058
matthieu castetb72458a2005-11-07 23:27:13 +01002059 uea_enters(INS_TO_USBDEV(sc));
2060
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002061 if (unlikely(status < 0)) {
matthieu castetb72458a2005-11-07 23:27:13 +01002062 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002063 status);
matthieu castetb72458a2005-11-07 23:27:13 +01002064 return;
2065 }
2066
matthieu castetb72458a2005-11-07 23:27:13 +01002067 /* device-to-host interrupt */
2068 if (intr->bType != 0x08 || sc->booting) {
matthieu castete40abaf2006-01-18 07:38:37 +01002069 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
matthieu castetb72458a2005-11-07 23:27:13 +01002070 goto resubmit;
2071 }
2072
2073 switch (le16_to_cpu(intr->wInterrupt)) {
2074 case INT_LOADSWAPPAGE:
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002075 sc->schedule_load_page(sc, intr);
matthieu castetb72458a2005-11-07 23:27:13 +01002076 break;
2077
2078 case INT_INCOMINGCMV:
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002079 sc->dispatch_cmv(sc, intr);
matthieu castetb72458a2005-11-07 23:27:13 +01002080 break;
2081
2082 default:
matthieu castete40abaf2006-01-18 07:38:37 +01002083 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
matthieu castetb72458a2005-11-07 23:27:13 +01002084 le16_to_cpu(intr->wInterrupt));
2085 }
2086
2087resubmit:
2088 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
2089}
2090
2091/*
2092 * Start the modem : init the data and start kernel thread
2093 */
2094static int uea_boot(struct uea_softc *sc)
2095{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002096 int ret, size;
matthieu castetb72458a2005-11-07 23:27:13 +01002097 struct intr_pkt *intr;
2098
2099 uea_enters(INS_TO_USBDEV(sc));
2100
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002101 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2102 size = E4_INTR_PKT_SIZE;
2103 sc->dispatch_cmv = uea_dispatch_cmv_e4;
2104 sc->schedule_load_page = uea_schedule_load_page_e4;
2105 sc->stat = uea_stat_e4;
2106 sc->send_cmvs = uea_send_cmvs_e4;
2107 INIT_WORK(&sc->task, uea_load_page_e4);
2108 } else {
2109 size = E1_INTR_PKT_SIZE;
2110 sc->dispatch_cmv = uea_dispatch_cmv_e1;
2111 sc->schedule_load_page = uea_schedule_load_page_e1;
2112 sc->stat = uea_stat_e1;
2113 sc->send_cmvs = uea_send_cmvs_e1;
2114 INIT_WORK(&sc->task, uea_load_page_e1);
2115 }
2116
matthieu castetb72458a2005-11-07 23:27:13 +01002117 init_waitqueue_head(&sc->sync_q);
2118 init_waitqueue_head(&sc->cmv_ack_wait);
2119
2120 if (UEA_CHIP_VERSION(sc) == ADI930)
2121 load_XILINX_firmware(sc);
2122
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002123 intr = kmalloc(size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +01002124 if (!intr) {
2125 uea_err(INS_TO_USBDEV(sc),
2126 "cannot allocate interrupt package\n");
2127 uea_leaves(INS_TO_USBDEV(sc));
2128 return -ENOMEM;
2129 }
2130
2131 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
2132 if (!sc->urb_int) {
2133 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
2134 goto err;
2135 }
2136
2137 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
2138 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002139 intr, size, uea_intr, sc,
matthieu castetb72458a2005-11-07 23:27:13 +01002140 sc->usb_dev->actconfig->interface[0]->altsetting[0].
2141 endpoint[0].desc.bInterval);
2142
2143 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2144 if (ret < 0) {
2145 uea_err(INS_TO_USBDEV(sc),
2146 "urb submition failed with error %d\n", ret);
matthieu castet4d45e212006-04-02 18:45:46 +02002147 goto err;
matthieu castetb72458a2005-11-07 23:27:13 +01002148 }
2149
2150 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm");
2151 if (sc->kthread == ERR_PTR(-ENOMEM)) {
2152 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2153 goto err2;
2154 }
2155
2156 uea_leaves(INS_TO_USBDEV(sc));
2157 return 0;
2158
2159err2:
2160 usb_kill_urb(sc->urb_int);
matthieu castetb72458a2005-11-07 23:27:13 +01002161err:
2162 usb_free_urb(sc->urb_int);
matthieu castet4d45e212006-04-02 18:45:46 +02002163 sc->urb_int = NULL;
2164 kfree(intr);
matthieu castetb72458a2005-11-07 23:27:13 +01002165 uea_leaves(INS_TO_USBDEV(sc));
2166 return -ENOMEM;
2167}
2168
2169/*
2170 * Stop the modem : kill kernel thread and free data
2171 */
2172static void uea_stop(struct uea_softc *sc)
2173{
2174 int ret;
2175 uea_enters(INS_TO_USBDEV(sc));
2176 ret = kthread_stop(sc->kthread);
matthieu castete40abaf2006-01-18 07:38:37 +01002177 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
matthieu castetb72458a2005-11-07 23:27:13 +01002178
2179 /* stop any pending boot process */
2180 flush_scheduled_work();
2181
2182 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
2183
2184 usb_kill_urb(sc->urb_int);
2185 kfree(sc->urb_int->transfer_buffer);
2186 usb_free_urb(sc->urb_int);
2187
2188 if (sc->dsp_firm)
2189 release_firmware(sc->dsp_firm);
2190 uea_leaves(INS_TO_USBDEV(sc));
2191}
2192
2193/* syfs interface */
2194static struct uea_softc *dev_to_uea(struct device *dev)
2195{
2196 struct usb_interface *intf;
2197 struct usbatm_data *usbatm;
2198
2199 intf = to_usb_interface(dev);
2200 if (!intf)
2201 return NULL;
2202
2203 usbatm = usb_get_intfdata(intf);
2204 if (!usbatm)
2205 return NULL;
2206
2207 return usbatm->driver_data;
2208}
2209
2210static ssize_t read_status(struct device *dev, struct device_attribute *attr,
2211 char *buf)
2212{
2213 int ret = -ENODEV;
2214 struct uea_softc *sc;
2215
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002216 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002217 sc = dev_to_uea(dev);
2218 if (!sc)
2219 goto out;
2220 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
2221out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002222 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002223 return ret;
2224}
2225
2226static ssize_t reboot(struct device *dev, struct device_attribute *attr,
2227 const char *buf, size_t count)
2228{
2229 int ret = -ENODEV;
2230 struct uea_softc *sc;
2231
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002232 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002233 sc = dev_to_uea(dev);
2234 if (!sc)
2235 goto out;
2236 sc->reset = 1;
2237 ret = count;
2238out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002239 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002240 return ret;
2241}
2242
2243static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot);
2244
2245static ssize_t read_human_status(struct device *dev, struct device_attribute *attr,
2246 char *buf)
2247{
2248 int ret = -ENODEV;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002249 int modem_state;
matthieu castetb72458a2005-11-07 23:27:13 +01002250 struct uea_softc *sc;
2251
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002252 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002253 sc = dev_to_uea(dev);
2254 if (!sc)
2255 goto out;
2256
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002257 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2258 switch (sc->stats.phy.state) {
2259 case 0x0: /* not yet synchronized */
2260 case 0x1:
2261 case 0x3:
2262 case 0x4:
2263 modem_state = 0;
2264 break;
2265 case 0x5: /* initialization */
2266 case 0x6:
2267 case 0x9:
2268 case 0xa:
2269 modem_state = 1;
2270 break;
2271 case 0x7: /* operational */
2272 modem_state = 2;
2273 break;
2274 case 0x2: /* fail ... */
2275 modem_state = 3;
2276 break;
2277 default: /* unknown */
2278 modem_state = 4;
2279 break;
2280 }
2281 } else
2282 modem_state = GET_STATUS(sc->stats.phy.state);
2283
2284 switch (modem_state) {
matthieu castetb72458a2005-11-07 23:27:13 +01002285 case 0:
2286 ret = sprintf(buf, "Modem is booting\n");
2287 break;
2288 case 1:
2289 ret = sprintf(buf, "Modem is initializing\n");
2290 break;
2291 case 2:
2292 ret = sprintf(buf, "Modem is operational\n");
2293 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002294 case 3:
matthieu castetb72458a2005-11-07 23:27:13 +01002295 ret = sprintf(buf, "Modem synchronization failed\n");
2296 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002297 default:
2298 ret = sprintf(buf, "Modem state is unknown\n");
2299 break;
matthieu castetb72458a2005-11-07 23:27:13 +01002300 }
2301out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002302 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002303 return ret;
2304}
2305
2306static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, read_human_status, NULL);
2307
2308static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2309 char *buf)
2310{
2311 int ret = -ENODEV;
2312 struct uea_softc *sc;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002313 char *delin = "GOOD";
matthieu castetb72458a2005-11-07 23:27:13 +01002314
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002315 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002316 sc = dev_to_uea(dev);
2317 if (!sc)
2318 goto out;
2319
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002320 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2321 if (sc->stats.phy.flags & 0x4000)
2322 delin = "RESET";
2323 else if (sc->stats.phy.flags & 0x0001)
2324 delin = "LOSS";
2325 } else {
2326 if (sc->stats.phy.flags & 0x0C00)
2327 delin = "ERROR";
2328 else if (sc->stats.phy.flags & 0x0030)
2329 delin = "LOSS";
2330 }
2331
2332 ret = sprintf(buf, "%s\n", delin);
matthieu castetb72458a2005-11-07 23:27:13 +01002333out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002334 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002335 return ret;
2336}
2337
2338static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL);
2339
2340#define UEA_ATTR(name, reset) \
2341 \
2342static ssize_t read_##name(struct device *dev, \
2343 struct device_attribute *attr, char *buf) \
2344{ \
2345 int ret = -ENODEV; \
2346 struct uea_softc *sc; \
2347 \
matthieu castet2a99b502006-04-02 18:43:53 +02002348 mutex_lock(&uea_mutex); \
matthieu castetb72458a2005-11-07 23:27:13 +01002349 sc = dev_to_uea(dev); \
2350 if (!sc) \
2351 goto out; \
2352 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2353 if (reset) \
2354 sc->stats.phy.name = 0; \
2355out: \
matthieu castet2a99b502006-04-02 18:43:53 +02002356 mutex_unlock(&uea_mutex); \
matthieu castetb72458a2005-11-07 23:27:13 +01002357 return ret; \
2358} \
2359 \
2360static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2361
2362UEA_ATTR(mflags, 1);
2363UEA_ATTR(vidcpe, 0);
2364UEA_ATTR(usrate, 0);
2365UEA_ATTR(dsrate, 0);
2366UEA_ATTR(usattenuation, 0);
2367UEA_ATTR(dsattenuation, 0);
2368UEA_ATTR(usmargin, 0);
2369UEA_ATTR(dsmargin, 0);
2370UEA_ATTR(txflow, 0);
2371UEA_ATTR(rxflow, 0);
2372UEA_ATTR(uscorr, 0);
2373UEA_ATTR(dscorr, 0);
2374UEA_ATTR(usunc, 0);
2375UEA_ATTR(dsunc, 0);
matthieu casteta7a0c9c2006-10-03 21:44:11 +02002376UEA_ATTR(firmid, 0);
matthieu castetb72458a2005-11-07 23:27:13 +01002377
2378/* Retrieve the device End System Identifier (MAC) */
2379
2380#define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
2381static int uea_getesi(struct uea_softc *sc, u_char * esi)
2382{
2383 unsigned char mac_str[2 * ETH_ALEN + 1];
2384 int i;
2385 if (usb_string
2386 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
2387 sizeof(mac_str)) != 2 * ETH_ALEN)
2388 return 1;
2389
2390 for (i = 0; i < ETH_ALEN; i++)
2391 esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]);
2392
2393 return 0;
2394}
2395
2396/* ATM stuff */
2397static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
2398{
2399 struct uea_softc *sc = usbatm->driver_data;
2400
2401 return uea_getesi(sc, atm_dev->esi);
2402}
2403
2404static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
2405{
2406 struct uea_softc *sc = usbatm->driver_data;
2407
matthieu castet531a39b2006-10-03 21:49:29 +02002408 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002409
2410 return 0;
2411
2412}
2413
2414static int claim_interface(struct usb_device *usb_dev,
2415 struct usbatm_data *usbatm, int ifnum)
2416{
2417 int ret;
2418 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
2419
2420 if (!intf) {
2421 uea_err(usb_dev, "interface %d not found\n", ifnum);
2422 return -ENODEV;
2423 }
2424
2425 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
2426 if (ret != 0)
2427 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
2428 ret);
2429 return ret;
2430}
2431
Greg Kroah-Hartmane7ccdfe2006-08-28 11:43:25 -07002432static struct attribute *attrs[] = {
2433 &dev_attr_stat_status.attr,
2434 &dev_attr_stat_mflags.attr,
2435 &dev_attr_stat_human_status.attr,
2436 &dev_attr_stat_delin.attr,
2437 &dev_attr_stat_vidcpe.attr,
2438 &dev_attr_stat_usrate.attr,
2439 &dev_attr_stat_dsrate.attr,
2440 &dev_attr_stat_usattenuation.attr,
2441 &dev_attr_stat_dsattenuation.attr,
2442 &dev_attr_stat_usmargin.attr,
2443 &dev_attr_stat_dsmargin.attr,
2444 &dev_attr_stat_txflow.attr,
2445 &dev_attr_stat_rxflow.attr,
2446 &dev_attr_stat_uscorr.attr,
2447 &dev_attr_stat_dscorr.attr,
2448 &dev_attr_stat_usunc.attr,
2449 &dev_attr_stat_dsunc.attr,
matthieu casteta7a0c9c2006-10-03 21:44:11 +02002450 &dev_attr_stat_firmid.attr,
matthieu castet9ab99c82006-10-11 14:20:56 -07002451 NULL,
Greg Kroah-Hartmane7ccdfe2006-08-28 11:43:25 -07002452};
2453static struct attribute_group attr_grp = {
2454 .attrs = attrs,
2455};
2456
matthieu castetb72458a2005-11-07 23:27:13 +01002457static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
Duncan Sands35644b02006-01-17 11:16:13 +01002458 const struct usb_device_id *id)
matthieu castetb72458a2005-11-07 23:27:13 +01002459{
2460 struct usb_device *usb = interface_to_usbdev(intf);
2461 struct uea_softc *sc;
2462 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002463 unsigned int alt;
matthieu castetb72458a2005-11-07 23:27:13 +01002464
2465 uea_enters(usb);
2466
2467 /* interface 0 is for firmware/monitoring */
2468 if (ifnum != UEA_INTR_IFACE_NO)
2469 return -ENODEV;
2470
Duncan Sands0dfcd3e2006-01-13 09:36:20 +01002471 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
matthieu castetb72458a2005-11-07 23:27:13 +01002472
2473 /* interface 1 is for outbound traffic */
2474 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
2475 if (ret < 0)
2476 return ret;
2477
matthieu castete40abaf2006-01-18 07:38:37 +01002478 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
matthieu castetb72458a2005-11-07 23:27:13 +01002479 if (UEA_CHIP_VERSION(id) != ADI930) {
2480 /* interface 2 is for inbound traffic */
2481 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
2482 if (ret < 0)
2483 return ret;
2484 }
2485
2486 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
2487 if (!sc) {
matthieu castet584958c2006-04-02 18:44:48 +02002488 uea_err(usb, "uea_init: not enough memory !\n");
matthieu castetb72458a2005-11-07 23:27:13 +01002489 return -ENOMEM;
2490 }
2491
2492 sc->usb_dev = usb;
2493 usbatm->driver_data = sc;
2494 sc->usbatm = usbatm;
2495 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
2496 sc->driver_info = id->driver_info;
2497
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002498 /* first try to use module parameter */
2499 if (annex[sc->modem_index] == 1)
2500 sc->annex = ANNEXA;
2501 else if (annex[sc->modem_index] == 2)
2502 sc->annex = ANNEXB;
2503 /* try to autodetect annex */
2504 else if (sc->driver_info & AUTO_ANNEX_A)
2505 sc->annex = ANNEXA;
2506 else if (sc->driver_info & AUTO_ANNEX_B)
2507 sc->annex = ANNEXB;
2508 else
2509 sc->annex = (le16_to_cpu(sc->usb_dev->descriptor.bcdDevice) & 0x80)?ANNEXB:ANNEXA;
2510
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002511 alt = altsetting[sc->modem_index];
matthieu castet3c9666c2006-01-18 07:38:19 +01002512 /* ADI930 don't support iso */
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002513 if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) {
2514 if (alt <= 8 && usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) {
2515 uea_dbg(usb, "set alternate %u for 2 interface\n", alt);
matthieu castet3c9666c2006-01-18 07:38:19 +01002516 uea_info(usb, "using iso mode\n");
2517 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
2518 } else {
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002519 uea_err(usb, "setting alternate %u failed for "
2520 "2 interface, using bulk mode\n", alt);
matthieu castet3c9666c2006-01-18 07:38:19 +01002521 }
2522 }
2523
matthieu castet9ab99c82006-10-11 14:20:56 -07002524 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
2525 if (ret < 0)
2526 goto error;
2527
matthieu castetb72458a2005-11-07 23:27:13 +01002528 ret = uea_boot(sc);
matthieu castet9ab99c82006-10-11 14:20:56 -07002529 if (ret < 0)
Stanislaw Gruszka4c132e72007-08-20 23:20:49 +02002530 goto error_rm_grp;
matthieu castetb72458a2005-11-07 23:27:13 +01002531
matthieu castetb72458a2005-11-07 23:27:13 +01002532 return 0;
Stanislaw Gruszka4c132e72007-08-20 23:20:49 +02002533
2534error_rm_grp:
2535 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
matthieu castet9ab99c82006-10-11 14:20:56 -07002536error:
2537 kfree(sc);
2538 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01002539}
2540
2541static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
2542{
2543 struct uea_softc *sc = usbatm->driver_data;
2544
matthieu castet9ab99c82006-10-11 14:20:56 -07002545 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
matthieu castetb72458a2005-11-07 23:27:13 +01002546 uea_stop(sc);
2547 kfree(sc);
2548}
2549
2550static struct usbatm_driver uea_usbatm_driver = {
2551 .driver_name = "ueagle-atm",
matthieu castetb72458a2005-11-07 23:27:13 +01002552 .bind = uea_bind,
2553 .atm_start = uea_atm_open,
2554 .unbind = uea_unbind,
2555 .heavy_init = uea_heavy,
Duncan Sands80aae7a2006-01-13 10:59:23 +01002556 .bulk_in = UEA_BULK_DATA_PIPE,
2557 .bulk_out = UEA_BULK_DATA_PIPE,
matthieu castet3c9666c2006-01-18 07:38:19 +01002558 .isoc_in = UEA_ISO_DATA_PIPE,
matthieu castetb72458a2005-11-07 23:27:13 +01002559};
2560
2561static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2562{
2563 struct usb_device *usb = interface_to_usbdev(intf);
2564
2565 uea_enters(usb);
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002566 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2567 le16_to_cpu(usb->descriptor.idVendor),
2568 le16_to_cpu(usb->descriptor.idProduct),
2569 le16_to_cpu(usb->descriptor.bcdDevice),
2570 chip_name[UEA_CHIP_VERSION(id)]);
matthieu castetb72458a2005-11-07 23:27:13 +01002571
2572 usb_reset_device(usb);
2573
2574 if (UEA_IS_PREFIRM(id))
2575 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2576
2577 return usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2578}
2579
2580static void uea_disconnect(struct usb_interface *intf)
2581{
2582 struct usb_device *usb = interface_to_usbdev(intf);
2583 int ifnum = intf->altsetting->desc.bInterfaceNumber;
2584 uea_enters(usb);
2585
2586 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2587 * Pre-firmware device has one interface
2588 */
2589 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002590 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002591 usbatm_usb_disconnect(intf);
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002592 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002593 uea_info(usb, "ADSL device removed\n");
2594 }
2595
2596 uea_leaves(usb);
2597}
2598
2599/*
2600 * List of supported VID/PID
2601 */
2602static const struct usb_device_id uea_ids[] = {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002603 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
2604 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
2605 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2606 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
2607 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2608 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
2609 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2610 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
2611 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM), .driver_info = EAGLE_III | PREFIRM},
2612 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM), .driver_info = EAGLE_III | PSTFIRM},
2613 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM), .driver_info = EAGLE_IV | PREFIRM},
2614 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM), .driver_info = EAGLE_IV | PSTFIRM},
2615 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2616 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2617 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
2618 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2619 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2620 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A},
2621 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
2622 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B},
matthieu castetb72458a2005-11-07 23:27:13 +01002623 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
2624 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002625 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM), .driver_info = ADI930 | PREFIRM},
2626 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM), .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A},
2627 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM), .driver_info = ADI930 | PREFIRM},
2628 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM), .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B},
matthieu castetb72458a2005-11-07 23:27:13 +01002629 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002630 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
matthieu castetb72458a2005-11-07 23:27:13 +01002631 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002632 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
matthieu castetb72458a2005-11-07 23:27:13 +01002633 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002634 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
matthieu castetb72458a2005-11-07 23:27:13 +01002635 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002636 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
matthieu castetb72458a2005-11-07 23:27:13 +01002637 {}
2638};
2639
2640/*
2641 * USB driver descriptor
2642 */
2643static struct usb_driver uea_driver = {
matthieu castetb72458a2005-11-07 23:27:13 +01002644 .name = "ueagle-atm",
2645 .id_table = uea_ids,
2646 .probe = uea_probe,
2647 .disconnect = uea_disconnect,
2648};
2649
2650MODULE_DEVICE_TABLE(usb, uea_ids);
2651
2652/**
2653 * uea_init - Initialize the module.
2654 * Register to USB subsystem
2655 */
2656static int __init uea_init(void)
2657{
2658 printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n");
2659
2660 usb_register(&uea_driver);
2661
2662 return 0;
2663}
2664
2665module_init(uea_init);
2666
2667/**
2668 * uea_exit - Destroy module
2669 * Deregister with USB subsystem
2670 */
2671static void __exit uea_exit(void)
2672{
2673 /*
2674 * This calls automatically the uea_disconnect method if necessary:
2675 */
2676 usb_deregister(&uea_driver);
2677
2678 printk(KERN_INFO "[ueagle-atm] driver unloaded\n");
2679}
2680
2681module_exit(uea_exit);
2682
2683MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2684MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2685MODULE_LICENSE("Dual BSD/GPL");