blob: defff43950bc11a6ae49ee6d0c80f446e31701c9 [file] [log] [blame]
matthieu castetb72458a2005-11-07 23:27:13 +01001/*-
2 * Copyright (c) 2003, 2004
3 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
4 *
Stanislaw Gruszka0eb02262007-08-20 23:21:19 +02005 * Copyright (c) 2005-2007 Matthieu Castet <castet.matthieu@free.fr>
6 * Copyright (c) 2005-2007 Stanislaw Gruszka <stf_xl@wp.pl>
matthieu castetb72458a2005-11-07 23:27:13 +01007 *
8 * This software is available to you under a choice of one of two
9 * licenses. You may choose to be licensed under the terms of the GNU
10 * General Public License (GPL) Version 2, available from the file
11 * COPYING in the main directory of this source tree, or the
12 * BSD license below:
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice unmodified, this list of conditions, and the following
19 * disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * GPL license :
37 * This program is free software; you can redistribute it and/or
38 * modify it under the terms of the GNU General Public License
39 * as published by the Free Software Foundation; either version 2
40 * of the License, or (at your option) any later version.
41 *
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
46 *
47 * You should have received a copy of the GNU General Public License
48 * along with this program; if not, write to the Free Software
49 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
50 *
51 *
52 * HISTORY : some part of the code was base on ueagle 1.3 BSD driver,
53 * Damien Bergamini agree to put his code under a DUAL GPL/BSD license.
54 *
55 * The rest of the code was was rewritten from scratch.
56 */
57
58#include <linux/module.h>
59#include <linux/moduleparam.h>
60#include <linux/init.h>
61#include <linux/crc32.h>
62#include <linux/usb.h>
63#include <linux/firmware.h>
64#include <linux/ctype.h>
Randy Dunlap5371f802007-02-16 01:47:33 -080065#include <linux/sched.h>
matthieu castetb72458a2005-11-07 23:27:13 +010066#include <linux/kthread.h>
Arjan van de Venab3c81f2006-01-13 15:52:55 +010067#include <linux/mutex.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080068#include <linux/freezer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090069#include <linux/slab.h>
Andy Shevchenkoe6448142010-06-15 17:04:44 +030070#include <linux/kernel.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080071
matthieu castetb72458a2005-11-07 23:27:13 +010072#include <asm/unaligned.h>
73
74#include "usbatm.h"
75
matthieu casteta7a0c9c2006-10-03 21:44:11 +020076#define EAGLEUSBVERSION "ueagle 1.4"
matthieu castetb72458a2005-11-07 23:27:13 +010077
78
79/*
80 * Debug macros
81 */
82#define uea_dbg(usb_dev, format, args...) \
83 do { \
84 if (debug >= 1) \
85 dev_dbg(&(usb_dev)->dev, \
86 "[ueagle-atm dbg] %s: " format, \
Harvey Harrison441b62c2008-03-03 16:08:34 -080087 __func__, ##args); \
matthieu casteta7a0c9c2006-10-03 21:44:11 +020088 } while (0)
matthieu castetb72458a2005-11-07 23:27:13 +010089
90#define uea_vdbg(usb_dev, format, args...) \
91 do { \
92 if (debug >= 2) \
93 dev_dbg(&(usb_dev)->dev, \
94 "[ueagle-atm vdbg] " format, ##args); \
matthieu casteta7a0c9c2006-10-03 21:44:11 +020095 } while (0)
matthieu castetb72458a2005-11-07 23:27:13 +010096
97#define uea_enters(usb_dev) \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +020098 uea_vdbg(usb_dev, "entering %s\n" , __func__)
matthieu castetb72458a2005-11-07 23:27:13 +010099
100#define uea_leaves(usb_dev) \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200101 uea_vdbg(usb_dev, "leaving %s\n" , __func__)
matthieu castetb72458a2005-11-07 23:27:13 +0100102
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200103#define uea_err(usb_dev, format, args...) \
104 dev_err(&(usb_dev)->dev , "[UEAGLE-ATM] " format , ##args)
matthieu castetb72458a2005-11-07 23:27:13 +0100105
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200106#define uea_warn(usb_dev, format, args...) \
107 dev_warn(&(usb_dev)->dev , "[Ueagle-atm] " format, ##args)
matthieu castetb72458a2005-11-07 23:27:13 +0100108
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200109#define uea_info(usb_dev, format, args...) \
110 dev_info(&(usb_dev)->dev , "[ueagle-atm] " format, ##args)
matthieu castetb72458a2005-11-07 23:27:13 +0100111
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200112struct intr_pkt;
113
114/* cmv's from firmware */
115struct uea_cmvs_v1 {
matthieu castetb72458a2005-11-07 23:27:13 +0100116 u32 address;
117 u16 offset;
118 u32 data;
Chris Forbes58607302011-07-03 11:53:33 +1200119} __packed;
matthieu castetb72458a2005-11-07 23:27:13 +0100120
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200121struct uea_cmvs_v2 {
122 u32 group;
123 u32 address;
124 u32 offset;
125 u32 data;
Chris Forbes58607302011-07-03 11:53:33 +1200126} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200127
128/* information about currently processed cmv */
129struct cmv_dsc_e1 {
130 u8 function;
131 u16 idx;
132 u32 address;
133 u16 offset;
134};
135
136struct cmv_dsc_e4 {
137 u16 function;
138 u16 offset;
139 u16 address;
140 u16 group;
141};
142
143union cmv_dsc {
144 struct cmv_dsc_e1 e1;
145 struct cmv_dsc_e4 e4;
146};
147
matthieu castetb72458a2005-11-07 23:27:13 +0100148struct uea_softc {
149 struct usb_device *usb_dev;
150 struct usbatm_data *usbatm;
151
152 int modem_index;
153 unsigned int driver_info;
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200154 int annex;
155#define ANNEXA 0
156#define ANNEXB 1
matthieu castetb72458a2005-11-07 23:27:13 +0100157
158 int booting;
159 int reset;
160
161 wait_queue_head_t sync_q;
162
163 struct task_struct *kthread;
164 u32 data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200165 u32 data1;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200166
matthieu castetb72458a2005-11-07 23:27:13 +0100167 int cmv_ack;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200168 union cmv_dsc cmv_dsc;
matthieu castetb72458a2005-11-07 23:27:13 +0100169
170 struct work_struct task;
171 u16 pageno;
172 u16 ovl;
173
174 const struct firmware *dsp_firm;
175 struct urb *urb_int;
176
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200177 void (*dispatch_cmv) (struct uea_softc *, struct intr_pkt *);
178 void (*schedule_load_page) (struct uea_softc *, struct intr_pkt *);
179 int (*stat) (struct uea_softc *);
180 int (*send_cmvs) (struct uea_softc *);
matthieu castetb72458a2005-11-07 23:27:13 +0100181
182 /* keep in sync with eaglectl */
183 struct uea_stats {
184 struct {
185 u32 state;
186 u32 flags;
187 u32 mflags;
188 u32 vidcpe;
189 u32 vidco;
190 u32 dsrate;
191 u32 usrate;
192 u32 dsunc;
193 u32 usunc;
194 u32 dscorr;
195 u32 uscorr;
196 u32 txflow;
197 u32 rxflow;
198 u32 usattenuation;
199 u32 dsattenuation;
200 u32 dsmargin;
201 u32 usmargin;
202 u32 firmid;
203 } phy;
204 } stats;
205};
206
207/*
208 * Elsa IDs
209 */
210#define ELSA_VID 0x05CC
211#define ELSA_PID_PSTFIRM 0x3350
212#define ELSA_PID_PREFIRM 0x3351
213
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200214#define ELSA_PID_A_PREFIRM 0x3352
215#define ELSA_PID_A_PSTFIRM 0x3353
216#define ELSA_PID_B_PREFIRM 0x3362
217#define ELSA_PID_B_PSTFIRM 0x3363
218
matthieu castetb72458a2005-11-07 23:27:13 +0100219/*
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200220 * Devolo IDs : pots if (pid & 0x10)
matthieu castetb72458a2005-11-07 23:27:13 +0100221 */
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200222#define DEVOLO_VID 0x1039
223#define DEVOLO_EAGLE_I_A_PID_PSTFIRM 0x2110
224#define DEVOLO_EAGLE_I_A_PID_PREFIRM 0x2111
225
226#define DEVOLO_EAGLE_I_B_PID_PSTFIRM 0x2100
227#define DEVOLO_EAGLE_I_B_PID_PREFIRM 0x2101
228
229#define DEVOLO_EAGLE_II_A_PID_PSTFIRM 0x2130
230#define DEVOLO_EAGLE_II_A_PID_PREFIRM 0x2131
231
232#define DEVOLO_EAGLE_II_B_PID_PSTFIRM 0x2120
233#define DEVOLO_EAGLE_II_B_PID_PREFIRM 0x2121
234
235/*
236 * Reference design USB IDs
237 */
238#define ANALOG_VID 0x1110
239#define ADI930_PID_PREFIRM 0x9001
240#define ADI930_PID_PSTFIRM 0x9000
241
matthieu castetb72458a2005-11-07 23:27:13 +0100242#define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
243#define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
244
245#define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
246#define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
247
248#define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
249#define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
250
matthieu castetb72458a2005-11-07 23:27:13 +0100251#define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
252#define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
253
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200254#define EAGLE_IV_PID_PREFIRM 0x9042 /* Eagle IV */
255#define EAGLE_IV_PID_PSTFIRM 0x9041 /* Eagle IV */
256
matthieu castetb72458a2005-11-07 23:27:13 +0100257/*
258 * USR USB IDs
259 */
260#define USR_VID 0x0BAF
261#define MILLER_A_PID_PREFIRM 0x00F2
262#define MILLER_A_PID_PSTFIRM 0x00F1
263#define MILLER_B_PID_PREFIRM 0x00FA
264#define MILLER_B_PID_PSTFIRM 0x00F9
265#define HEINEKEN_A_PID_PREFIRM 0x00F6
266#define HEINEKEN_A_PID_PSTFIRM 0x00F5
267#define HEINEKEN_B_PID_PREFIRM 0x00F8
268#define HEINEKEN_B_PID_PSTFIRM 0x00F7
269
270#define PREFIRM 0
271#define PSTFIRM (1<<7)
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200272#define AUTO_ANNEX_A (1<<8)
273#define AUTO_ANNEX_B (1<<9)
274
matthieu castetb72458a2005-11-07 23:27:13 +0100275enum {
276 ADI930 = 0,
277 EAGLE_I,
278 EAGLE_II,
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200279 EAGLE_III,
280 EAGLE_IV
matthieu castetb72458a2005-11-07 23:27:13 +0100281};
282
283/* macros for both struct usb_device_id and struct uea_softc */
284#define UEA_IS_PREFIRM(x) \
285 (!((x)->driver_info & PSTFIRM))
286#define UEA_CHIP_VERSION(x) \
287 ((x)->driver_info & 0xf)
288
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200289#define IS_ISDN(x) \
290 ((x)->annex & ANNEXB)
matthieu castetb72458a2005-11-07 23:27:13 +0100291
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200292#define INS_TO_USBDEV(ins) (ins->usb_dev)
matthieu castetb72458a2005-11-07 23:27:13 +0100293
294#define GET_STATUS(data) \
295 ((data >> 8) & 0xf)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200296
matthieu castetb72458a2005-11-07 23:27:13 +0100297#define IS_OPERATIONAL(sc) \
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200298 ((UEA_CHIP_VERSION(sc) != EAGLE_IV) ? \
299 (GET_STATUS(sc->stats.phy.state) == 2) : \
300 (sc->stats.phy.state == 7))
matthieu castetb72458a2005-11-07 23:27:13 +0100301
302/*
303 * Set of macros to handle unaligned data in the firmware blob.
304 * The FW_GET_BYTE() macro is provided only for consistency.
305 */
306
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200307#define FW_GET_BYTE(p) (*((__u8 *) (p)))
matthieu castetb72458a2005-11-07 23:27:13 +0100308
309#define FW_DIR "ueagle-atm/"
Tim Gardner47282502012-07-25 14:32:50 -0600310#define EAGLE_FIRMWARE FW_DIR "eagle.fw"
311#define ADI930_FIRMWARE FW_DIR "adi930.fw"
312#define EAGLE_I_FIRMWARE FW_DIR "eagleI.fw"
313#define EAGLE_II_FIRMWARE FW_DIR "eagleII.fw"
314#define EAGLE_III_FIRMWARE FW_DIR "eagleIII.fw"
315#define EAGLE_IV_FIRMWARE FW_DIR "eagleIV.fw"
316
317#define DSP4I_FIRMWARE FW_DIR "DSP4i.bin"
318#define DSP4P_FIRMWARE FW_DIR "DSP4p.bin"
319#define DSP9I_FIRMWARE FW_DIR "DSP9i.bin"
320#define DSP9P_FIRMWARE FW_DIR "DSP9p.bin"
321#define DSPEI_FIRMWARE FW_DIR "DSPei.bin"
322#define DSPEP_FIRMWARE FW_DIR "DSPep.bin"
323#define FPGA930_FIRMWARE FW_DIR "930-fpga.bin"
324
325#define CMV4P_FIRMWARE FW_DIR "CMV4p.bin"
326#define CMV4PV2_FIRMWARE FW_DIR "CMV4p.bin.v2"
327#define CMV4I_FIRMWARE FW_DIR "CMV4i.bin"
328#define CMV4IV2_FIRMWARE FW_DIR "CMV4i.bin.v2"
329#define CMV9P_FIRMWARE FW_DIR "CMV9p.bin"
330#define CMV9PV2_FIRMWARE FW_DIR "CMV9p.bin.v2"
331#define CMV9I_FIRMWARE FW_DIR "CMV9i.bin"
332#define CMV9IV2_FIRMWARE FW_DIR "CMV9i.bin.v2"
333#define CMVEP_FIRMWARE FW_DIR "CMVep.bin"
334#define CMVEPV2_FIRMWARE FW_DIR "CMVep.bin.v2"
335#define CMVEI_FIRMWARE FW_DIR "CMVei.bin"
336#define CMVEIV2_FIRMWARE FW_DIR "CMVei.bin.v2"
337
Samuel Ortizade901d2009-05-27 00:49:32 +0200338#define UEA_FW_NAME_MAX 30
matthieu castetb72458a2005-11-07 23:27:13 +0100339#define NB_MODEM 4
340
341#define BULK_TIMEOUT 300
342#define CTRL_TIMEOUT 1000
343
matthieu castet22fcceb2006-04-02 18:44:20 +0200344#define ACK_TIMEOUT msecs_to_jiffies(3000)
matthieu castetb72458a2005-11-07 23:27:13 +0100345
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200346#define UEA_INTR_IFACE_NO 0
matthieu castetb72458a2005-11-07 23:27:13 +0100347#define UEA_US_IFACE_NO 1
348#define UEA_DS_IFACE_NO 2
349
350#define FASTEST_ISO_INTF 8
351
352#define UEA_BULK_DATA_PIPE 0x02
353#define UEA_IDMA_PIPE 0x04
354#define UEA_INTR_PIPE 0x04
355#define UEA_ISO_DATA_PIPE 0x08
356
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200357#define UEA_E1_SET_BLOCK 0x0001
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200358#define UEA_E4_SET_BLOCK 0x002c
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200359#define UEA_SET_MODE 0x0003
matthieu castetb72458a2005-11-07 23:27:13 +0100360#define UEA_SET_2183_DATA 0x0004
361#define UEA_SET_TIMEOUT 0x0011
362
363#define UEA_LOOPBACK_OFF 0x0002
364#define UEA_LOOPBACK_ON 0x0003
365#define UEA_BOOT_IDMA 0x0006
366#define UEA_START_RESET 0x0007
367#define UEA_END_RESET 0x0008
368
369#define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
370#define UEA_MPTX_START (0x3fce | 0x4000)
371#define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
372#define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
373
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200374/* block information in eagle4 dsp firmware */
375struct block_index {
376 __le32 PageOffset;
377 __le32 NotLastBlock;
378 __le32 dummy;
379 __le32 PageSize;
380 __le32 PageAddress;
381 __le16 dummy1;
382 __le16 PageNumber;
Chris Forbes58607302011-07-03 11:53:33 +1200383} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200384
385#define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
386#define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
387
388#define E4_L1_STRING_HEADER 0x10
389#define E4_MAX_PAGE_NUMBER 0x58
390#define E4_NO_SWAPPAGE_HEADERS 0x31
391
392/* l1_code is eagle4 dsp firmware format */
393struct l1_code {
394 u8 string_header[E4_L1_STRING_HEADER];
395 u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER];
396 struct block_index page_header[E4_NO_SWAPPAGE_HEADERS];
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200397 u8 code[0];
Chris Forbes58607302011-07-03 11:53:33 +1200398} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200399
400/* structures describing a block within a DSP page */
401struct block_info_e1 {
matthieu castetb72458a2005-11-07 23:27:13 +0100402 __le16 wHdr;
matthieu castetb72458a2005-11-07 23:27:13 +0100403 __le16 wAddress;
404 __le16 wSize;
405 __le16 wOvlOffset;
406 __le16 wOvl; /* overlay */
407 __le16 wLast;
Chris Forbes58607302011-07-03 11:53:33 +1200408} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200409#define E1_BLOCK_INFO_SIZE 12
matthieu castetb72458a2005-11-07 23:27:13 +0100410
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200411struct block_info_e4 {
412 __be16 wHdr;
413 __u8 bBootPage;
414 __u8 bPageNumber;
415 __be32 dwSize;
416 __be32 dwAddress;
417 __be16 wReserved;
Chris Forbes58607302011-07-03 11:53:33 +1200418} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200419#define E4_BLOCK_INFO_SIZE 14
matthieu castetb72458a2005-11-07 23:27:13 +0100420
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200421#define UEA_BIHDR 0xabcd
422#define UEA_RESERVED 0xffff
423
424/* constants describing cmv type */
425#define E1_PREAMBLE 0x535c
426#define E1_MODEMTOHOST 0x01
427#define E1_HOSTTOMODEM 0x10
428
429#define E1_MEMACCESS 0x1
430#define E1_ADSLDIRECTIVE 0x7
431#define E1_FUNCTION_TYPE(f) ((f) >> 4)
432#define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f)
433
434#define E4_MEMACCESS 0
435#define E4_ADSLDIRECTIVE 0xf
436#define E4_FUNCTION_TYPE(f) ((f) >> 8)
437#define E4_FUNCTION_SIZE(f) ((f) & 0x0f)
438#define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f)
439
matthieu castetb72458a2005-11-07 23:27:13 +0100440/* for MEMACCESS */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200441#define E1_REQUESTREAD 0x0
442#define E1_REQUESTWRITE 0x1
443#define E1_REPLYREAD 0x2
444#define E1_REPLYWRITE 0x3
matthieu castetb72458a2005-11-07 23:27:13 +0100445
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200446#define E4_REQUESTREAD 0x0
447#define E4_REQUESTWRITE 0x4
448#define E4_REPLYREAD (E4_REQUESTREAD | 1)
449#define E4_REPLYWRITE (E4_REQUESTWRITE | 1)
450
451/* for ADSLDIRECTIVE */
452#define E1_KERNELREADY 0x0
453#define E1_MODEMREADY 0x1
454
455#define E4_KERNELREADY 0x0
456#define E4_MODEMREADY 0x1
457
458#define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200459#define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | \
460 ((st) & 0xf) << 4 | ((s) & 0xf))
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200461
462#define E1_MAKESA(a, b, c, d) \
matthieu castetb72458a2005-11-07 23:27:13 +0100463 (((c) & 0xff) << 24 | \
464 ((d) & 0xff) << 16 | \
465 ((a) & 0xff) << 8 | \
466 ((b) & 0xff))
467
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200468#define E1_GETSA1(a) ((a >> 8) & 0xff)
469#define E1_GETSA2(a) (a & 0xff)
470#define E1_GETSA3(a) ((a >> 24) & 0xff)
471#define E1_GETSA4(a) ((a >> 16) & 0xff)
472
473#define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L')
474#define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G')
475#define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O')
476#define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N')
477#define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E')
478#define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T')
479
480#define E4_SA_CNTL 1
481#define E4_SA_STAT 2
482#define E4_SA_INFO 3
483#define E4_SA_TEST 4
484#define E4_SA_OPTN 5
485#define E4_SA_RATE 6
486#define E4_SA_DIAG 7
487#define E4_SA_CNFG 8
488
489/* structures representing a CMV (Configuration and Management Variable) */
490struct cmv_e1 {
491 __le16 wPreamble;
492 __u8 bDirection;
493 __u8 bFunction;
494 __le16 wIndex;
495 __le32 dwSymbolicAddress;
matthieu castetb72458a2005-11-07 23:27:13 +0100496 __le16 wOffsetAddress;
497 __le32 dwData;
Chris Forbes58607302011-07-03 11:53:33 +1200498} __packed;
matthieu castetb72458a2005-11-07 23:27:13 +0100499
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200500struct cmv_e4 {
501 __be16 wGroup;
502 __be16 wFunction;
503 __be16 wOffset;
504 __be16 wAddress;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200505 __be32 dwData[6];
Chris Forbes58607302011-07-03 11:53:33 +1200506} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200507
508/* structures representing swap information */
509struct swap_info_e1 {
matthieu castetb72458a2005-11-07 23:27:13 +0100510 __u8 bSwapPageNo;
511 __u8 bOvl; /* overlay */
Chris Forbes58607302011-07-03 11:53:33 +1200512} __packed;
matthieu castetb72458a2005-11-07 23:27:13 +0100513
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200514struct swap_info_e4 {
515 __u8 bSwapPageNo;
Chris Forbes58607302011-07-03 11:53:33 +1200516} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200517
518/* structures representing interrupt data */
519#define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
520#define e1_bOvl u.e1.s1.swapinfo.bOvl
521#define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo
522
523#define INT_LOADSWAPPAGE 0x0001
524#define INT_INCOMINGCMV 0x0002
525
526union intr_data_e1 {
527 struct {
528 struct swap_info_e1 swapinfo;
529 __le16 wDataSize;
Chris Forbes58607302011-07-03 11:53:33 +1200530 } __packed s1;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200531 struct {
532 struct cmv_e1 cmv;
533 __le16 wDataSize;
Chris Forbes58607302011-07-03 11:53:33 +1200534 } __packed s2;
535} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200536
537union intr_data_e4 {
538 struct {
539 struct swap_info_e4 swapinfo;
540 __le16 wDataSize;
Chris Forbes58607302011-07-03 11:53:33 +1200541 } __packed s1;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200542 struct {
543 struct cmv_e4 cmv;
544 __le16 wDataSize;
Chris Forbes58607302011-07-03 11:53:33 +1200545 } __packed s2;
546} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200547
matthieu castetb72458a2005-11-07 23:27:13 +0100548struct intr_pkt {
549 __u8 bType;
550 __u8 bNotification;
551 __le16 wValue;
552 __le16 wIndex;
553 __le16 wLength;
554 __le16 wInterrupt;
matthieu castetb72458a2005-11-07 23:27:13 +0100555 union {
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200556 union intr_data_e1 e1;
557 union intr_data_e4 e4;
558 } u;
Chris Forbes58607302011-07-03 11:53:33 +1200559} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200560
561#define E1_INTR_PKT_SIZE 28
562#define E4_INTR_PKT_SIZE 64
matthieu castetb72458a2005-11-07 23:27:13 +0100563
564static struct usb_driver uea_driver;
Arjan van de Venab3c81f2006-01-13 15:52:55 +0100565static DEFINE_MUTEX(uea_mutex);
Chris Forbes6f95b4b2011-07-03 11:53:34 +1200566static const char * const chip_name[] = {
567 "ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
matthieu castetb72458a2005-11-07 23:27:13 +0100568
569static int modem_index;
570static unsigned int debug;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200571static unsigned int altsetting[NB_MODEM] = {
572 [0 ... (NB_MODEM - 1)] = FASTEST_ISO_INTF};
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030573static bool sync_wait[NB_MODEM];
matthieu castetb72458a2005-11-07 23:27:13 +0100574static char *cmv_file[NB_MODEM];
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200575static int annex[NB_MODEM];
matthieu castetb72458a2005-11-07 23:27:13 +0100576
577module_param(debug, uint, 0644);
578MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
Stanislaw Gruszka503add42007-08-20 23:21:06 +0200579module_param_array(altsetting, uint, NULL, 0644);
580MODULE_PARM_DESC(altsetting, "alternate setting for incoming traffic: 0=bulk, "
581 "1=isoc slowest, ... , 8=isoc fastest (default)");
matthieu castetb72458a2005-11-07 23:27:13 +0100582module_param_array(sync_wait, bool, NULL, 0644);
583MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
584module_param_array(cmv_file, charp, NULL, 0644);
585MODULE_PARM_DESC(cmv_file,
586 "file name with configuration and management variables");
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200587module_param_array(annex, uint, NULL, 0644);
588MODULE_PARM_DESC(annex,
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200589 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
matthieu castetb72458a2005-11-07 23:27:13 +0100590
Stanislaw Gruszka337427f2007-08-20 23:21:14 +0200591#define uea_wait(sc, cond, timeo) \
592({ \
593 int _r = wait_event_interruptible_timeout(sc->sync_q, \
594 (cond) || kthread_should_stop(), timeo); \
595 if (kthread_should_stop()) \
596 _r = -ENODEV; \
597 _r; \
598})
599
matthieu castetb72458a2005-11-07 23:27:13 +0100600#define UPDATE_ATM_STAT(type, val) \
601 do { \
602 if (sc->usbatm->atm_dev) \
603 sc->usbatm->atm_dev->type = val; \
604 } while (0)
605
Karl Hiramotocc7b86c2010-07-08 20:55:38 +0000606#define UPDATE_ATM_SIGNAL(val) \
607 do { \
608 if (sc->usbatm->atm_dev) \
609 atm_dev_signal_change(sc->usbatm->atm_dev, val); \
610 } while (0)
611
612
matthieu castetb72458a2005-11-07 23:27:13 +0100613/* Firmware loading */
614#define LOAD_INTERNAL 0xA0
615#define F8051_USBCS 0x7f92
616
617/**
618 * uea_send_modem_cmd - Send a command for pre-firmware devices.
619 */
620static int uea_send_modem_cmd(struct usb_device *usb,
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100621 u16 addr, u16 size, const u8 *buff)
matthieu castetb72458a2005-11-07 23:27:13 +0100622{
623 int ret = -ENOMEM;
624 u8 *xfer_buff;
625
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +0200626 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +0100627 if (xfer_buff) {
matthieu castetb72458a2005-11-07 23:27:13 +0100628 ret = usb_control_msg(usb,
629 usb_sndctrlpipe(usb, 0),
630 LOAD_INTERNAL,
631 USB_DIR_OUT | USB_TYPE_VENDOR |
632 USB_RECIP_DEVICE, addr, 0, xfer_buff,
633 size, CTRL_TIMEOUT);
634 kfree(xfer_buff);
635 }
636
637 if (ret < 0)
638 return ret;
639
640 return (ret == size) ? 0 : -EIO;
641}
642
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200643static void uea_upload_pre_firmware(const struct firmware *fw_entry,
644 void *context)
matthieu castetb72458a2005-11-07 23:27:13 +0100645{
646 struct usb_device *usb = context;
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100647 const u8 *pfw;
648 u8 value;
matthieu castetb72458a2005-11-07 23:27:13 +0100649 u32 crc = 0;
650 int ret, size;
651
652 uea_enters(usb);
653 if (!fw_entry) {
654 uea_err(usb, "firmware is not available\n");
655 goto err;
656 }
657
658 pfw = fw_entry->data;
659 size = fw_entry->size;
matthieu castet8d7802e2005-11-08 00:02:30 +0100660 if (size < 4)
661 goto err_fw_corrupted;
matthieu castetb72458a2005-11-07 23:27:13 +0100662
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700663 crc = get_unaligned_le32(pfw);
matthieu castetb72458a2005-11-07 23:27:13 +0100664 pfw += 4;
665 size -= 4;
matthieu castet8d7802e2005-11-08 00:02:30 +0100666 if (crc32_be(0, pfw, size) != crc)
667 goto err_fw_corrupted;
matthieu castetb72458a2005-11-07 23:27:13 +0100668
669 /*
Nick Andrew877d0312009-01-26 11:06:57 +0100670 * Start to upload firmware : send reset
matthieu castetb72458a2005-11-07 23:27:13 +0100671 */
672 value = 1;
673 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
674
675 if (ret < 0) {
676 uea_err(usb, "modem reset failed with error %d\n", ret);
677 goto err;
678 }
679
matthieu castet8d7802e2005-11-08 00:02:30 +0100680 while (size > 3) {
matthieu castetb72458a2005-11-07 23:27:13 +0100681 u8 len = FW_GET_BYTE(pfw);
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700682 u16 add = get_unaligned_le16(pfw + 1);
matthieu castet8d7802e2005-11-08 00:02:30 +0100683
684 size -= len + 3;
685 if (size < 0)
686 goto err_fw_corrupted;
687
matthieu castetb72458a2005-11-07 23:27:13 +0100688 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
689 if (ret < 0) {
690 uea_err(usb, "uploading firmware data failed "
691 "with error %d\n", ret);
692 goto err;
693 }
694 pfw += len + 3;
matthieu castetb72458a2005-11-07 23:27:13 +0100695 }
696
matthieu castet8d7802e2005-11-08 00:02:30 +0100697 if (size != 0)
698 goto err_fw_corrupted;
699
matthieu castetb72458a2005-11-07 23:27:13 +0100700 /*
701 * Tell the modem we finish : de-assert reset
702 */
703 value = 0;
704 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
705 if (ret < 0)
706 uea_err(usb, "modem de-assert failed with error %d\n", ret);
707 else
708 uea_info(usb, "firmware uploaded\n");
709
Johannes Berg9ebfbd42009-10-29 12:36:02 +0100710 goto err;
matthieu castet8d7802e2005-11-08 00:02:30 +0100711
712err_fw_corrupted:
713 uea_err(usb, "firmware is corrupted\n");
matthieu castetb72458a2005-11-07 23:27:13 +0100714err:
Johannes Berg9ebfbd42009-10-29 12:36:02 +0100715 release_firmware(fw_entry);
matthieu castetb72458a2005-11-07 23:27:13 +0100716 uea_leaves(usb);
717}
718
719/**
720 * uea_load_firmware - Load usb firmware for pre-firmware devices.
721 */
722static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
723{
724 int ret;
Tim Gardner47282502012-07-25 14:32:50 -0600725 char *fw_name = EAGLE_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100726
727 uea_enters(usb);
728 uea_info(usb, "pre-firmware device, uploading firmware\n");
729
730 switch (ver) {
731 case ADI930:
Tim Gardner47282502012-07-25 14:32:50 -0600732 fw_name = ADI930_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100733 break;
734 case EAGLE_I:
Tim Gardner47282502012-07-25 14:32:50 -0600735 fw_name = EAGLE_I_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100736 break;
737 case EAGLE_II:
Tim Gardner47282502012-07-25 14:32:50 -0600738 fw_name = EAGLE_II_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100739 break;
740 case EAGLE_III:
Tim Gardner47282502012-07-25 14:32:50 -0600741 fw_name = EAGLE_III_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100742 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200743 case EAGLE_IV:
Tim Gardner47282502012-07-25 14:32:50 -0600744 fw_name = EAGLE_IV_FIRMWARE;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200745 break;
matthieu castetb72458a2005-11-07 23:27:13 +0100746 }
747
Johannes Berg9ebfbd42009-10-29 12:36:02 +0100748 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev,
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200749 GFP_KERNEL, usb,
750 uea_upload_pre_firmware);
matthieu castetb72458a2005-11-07 23:27:13 +0100751 if (ret)
752 uea_err(usb, "firmware %s is not available\n", fw_name);
753 else
754 uea_info(usb, "loading firmware %s\n", fw_name);
755
756 uea_leaves(usb);
757 return ret;
758}
759
760/* modem management : dsp firmware, send/read CMV, monitoring statistic
761 */
762
763/*
764 * Make sure that the DSP code provided is safe to use.
765 */
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100766static int check_dsp_e1(const u8 *dsp, unsigned int len)
matthieu castetb72458a2005-11-07 23:27:13 +0100767{
768 u8 pagecount, blockcount;
769 u16 blocksize;
770 u32 pageoffset;
771 unsigned int i, j, p, pp;
772
matthieu castetb72458a2005-11-07 23:27:13 +0100773 pagecount = FW_GET_BYTE(dsp);
774 p = 1;
775
776 /* enough space for page offsets? */
777 if (p + 4 * pagecount > len)
778 return 1;
779
780 for (i = 0; i < pagecount; i++) {
781
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700782 pageoffset = get_unaligned_le32(dsp + p);
matthieu castetb72458a2005-11-07 23:27:13 +0100783 p += 4;
784
785 if (pageoffset == 0)
786 continue;
787
788 /* enough space for blockcount? */
789 if (pageoffset >= len)
790 return 1;
791
792 pp = pageoffset;
793 blockcount = FW_GET_BYTE(dsp + pp);
794 pp += 1;
795
796 for (j = 0; j < blockcount; j++) {
797
798 /* enough space for block header? */
799 if (pp + 4 > len)
800 return 1;
801
802 pp += 2; /* skip blockaddr */
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700803 blocksize = get_unaligned_le16(dsp + pp);
matthieu castetb72458a2005-11-07 23:27:13 +0100804 pp += 2;
805
806 /* enough space for block data? */
807 if (pp + blocksize > len)
808 return 1;
809
810 pp += blocksize;
811 }
812 }
813
814 return 0;
815}
816
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100817static int check_dsp_e4(const u8 *dsp, int len)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200818{
819 int i;
820 struct l1_code *p = (struct l1_code *) dsp;
821 unsigned int sum = p->code - dsp;
822
823 if (len < sum)
824 return 1;
825
826 if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 &&
827 strcmp("STRATIPHY ANEXB", p->string_header) != 0)
828 return 1;
829
830 for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) {
831 struct block_index *blockidx;
832 u8 blockno = p->page_number_to_block_index[i];
833 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
834 continue;
835
836 do {
837 u64 l;
838
839 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
840 return 1;
841
842 blockidx = &p->page_header[blockno++];
843 if ((u8 *)(blockidx + 1) - dsp >= len)
844 return 1;
845
846 if (le16_to_cpu(blockidx->PageNumber) != i)
847 return 1;
848
849 l = E4_PAGE_BYTES(blockidx->PageSize);
850 sum += l;
851 l += le32_to_cpu(blockidx->PageOffset);
852 if (l > len)
853 return 1;
854
855 /* zero is zero regardless endianes */
856 } while (blockidx->NotLastBlock);
857 }
858
859 return (sum == len) ? 0 : 1;
860}
861
matthieu castetb72458a2005-11-07 23:27:13 +0100862/*
863 * send data to the idma pipe
864 * */
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100865static int uea_idma_write(struct uea_softc *sc, const void *data, u32 size)
matthieu castetb72458a2005-11-07 23:27:13 +0100866{
867 int ret = -ENOMEM;
868 u8 *xfer_buff;
869 int bytes_read;
870
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +0200871 xfer_buff = kmemdup(data, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +0100872 if (!xfer_buff) {
873 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
874 return ret;
875 }
876
matthieu castetb72458a2005-11-07 23:27:13 +0100877 ret = usb_bulk_msg(sc->usb_dev,
878 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
879 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
880
881 kfree(xfer_buff);
882 if (ret < 0)
883 return ret;
884 if (size != bytes_read) {
885 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
886 bytes_read);
887 return -EIO;
888 }
889
890 return 0;
891}
892
893static int request_dsp(struct uea_softc *sc)
894{
895 int ret;
896 char *dsp_name;
897
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200898 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200899 if (IS_ISDN(sc))
Tim Gardner47282502012-07-25 14:32:50 -0600900 dsp_name = DSP4I_FIRMWARE;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200901 else
Tim Gardner47282502012-07-25 14:32:50 -0600902 dsp_name = DSP4P_FIRMWARE;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200903 } else if (UEA_CHIP_VERSION(sc) == ADI930) {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200904 if (IS_ISDN(sc))
Tim Gardner47282502012-07-25 14:32:50 -0600905 dsp_name = DSP9I_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100906 else
Tim Gardner47282502012-07-25 14:32:50 -0600907 dsp_name = DSP9P_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100908 } else {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200909 if (IS_ISDN(sc))
Tim Gardner47282502012-07-25 14:32:50 -0600910 dsp_name = DSPEI_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100911 else
Tim Gardner47282502012-07-25 14:32:50 -0600912 dsp_name = DSPEP_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100913 }
914
matthieu castete40abaf2006-01-18 07:38:37 +0100915 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
matthieu castetb72458a2005-11-07 23:27:13 +0100916 if (ret < 0) {
917 uea_err(INS_TO_USBDEV(sc),
918 "requesting firmware %s failed with error %d\n",
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200919 dsp_name, ret);
matthieu castetb72458a2005-11-07 23:27:13 +0100920 return ret;
921 }
922
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200923 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
924 ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size);
925 else
926 ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size);
927
928 if (ret) {
matthieu castetb72458a2005-11-07 23:27:13 +0100929 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
930 dsp_name);
931 release_firmware(sc->dsp_firm);
932 sc->dsp_firm = NULL;
933 return -EILSEQ;
934 }
935
936 return 0;
937}
938
939/*
940 * The uea_load_page() function must be called within a process context
941 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200942static void uea_load_page_e1(struct work_struct *work)
matthieu castetb72458a2005-11-07 23:27:13 +0100943{
David Howellsc4028952006-11-22 14:57:56 +0000944 struct uea_softc *sc = container_of(work, struct uea_softc, task);
matthieu castetb72458a2005-11-07 23:27:13 +0100945 u16 pageno = sc->pageno;
946 u16 ovl = sc->ovl;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200947 struct block_info_e1 bi;
matthieu castetb72458a2005-11-07 23:27:13 +0100948
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100949 const u8 *p;
matthieu castetb72458a2005-11-07 23:27:13 +0100950 u8 pagecount, blockcount;
951 u16 blockaddr, blocksize;
952 u32 pageoffset;
953 int i;
954
955 /* reload firmware when reboot start and it's loaded already */
956 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
957 release_firmware(sc->dsp_firm);
958 sc->dsp_firm = NULL;
959 }
960
961 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
962 return;
963
964 p = sc->dsp_firm->data;
965 pagecount = FW_GET_BYTE(p);
966 p += 1;
967
968 if (pageno >= pagecount)
969 goto bad1;
970
971 p += 4 * pageno;
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700972 pageoffset = get_unaligned_le32(p);
matthieu castetb72458a2005-11-07 23:27:13 +0100973
974 if (pageoffset == 0)
975 goto bad1;
976
977 p = sc->dsp_firm->data + pageoffset;
978 blockcount = FW_GET_BYTE(p);
979 p += 1;
980
981 uea_dbg(INS_TO_USBDEV(sc),
982 "sending %u blocks for DSP page %u\n", blockcount, pageno);
983
984 bi.wHdr = cpu_to_le16(UEA_BIHDR);
985 bi.wOvl = cpu_to_le16(ovl);
986 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
987
988 for (i = 0; i < blockcount; i++) {
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700989 blockaddr = get_unaligned_le16(p);
matthieu castetb72458a2005-11-07 23:27:13 +0100990 p += 2;
991
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700992 blocksize = get_unaligned_le16(p);
matthieu castetb72458a2005-11-07 23:27:13 +0100993 p += 2;
994
995 bi.wSize = cpu_to_le16(blocksize);
996 bi.wAddress = cpu_to_le16(blockaddr);
997 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
998
999 /* send block info through the IDMA pipe */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001000 if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE))
matthieu castetb72458a2005-11-07 23:27:13 +01001001 goto bad2;
1002
1003 /* send block data through the IDMA pipe */
1004 if (uea_idma_write(sc, p, blocksize))
1005 goto bad2;
1006
1007 p += blocksize;
1008 }
1009
1010 return;
1011
1012bad2:
1013 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
1014 return;
1015bad1:
matthieu castet2a99b502006-04-02 18:43:53 +02001016 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
matthieu castetb72458a2005-11-07 23:27:13 +01001017}
1018
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001019static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
1020{
1021 struct block_info_e4 bi;
1022 struct block_index *blockidx;
1023 struct l1_code *p = (struct l1_code *) sc->dsp_firm->data;
1024 u8 blockno = p->page_number_to_block_index[pageno];
1025
1026 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1027 bi.bBootPage = boot;
1028 bi.bPageNumber = pageno;
1029 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1030
1031 do {
David Woodhouseaafcd2f2008-05-24 00:05:10 +01001032 const u8 *blockoffset;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001033 unsigned int blocksize;
1034
1035 blockidx = &p->page_header[blockno];
1036 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001037 blockoffset = sc->dsp_firm->data + le32_to_cpu(
1038 blockidx->PageOffset);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001039
1040 bi.dwSize = cpu_to_be32(blocksize);
Al Virofd05e722008-04-28 07:00:16 +01001041 bi.dwAddress = cpu_to_be32(le32_to_cpu(blockidx->PageAddress));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001042
1043 uea_dbg(INS_TO_USBDEV(sc),
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001044 "sending block %u for DSP page "
1045 "%u size %u address %x\n",
1046 blockno, pageno, blocksize,
1047 le32_to_cpu(blockidx->PageAddress));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001048
1049 /* send block info through the IDMA pipe */
1050 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1051 goto bad;
1052
1053 /* send block data through the IDMA pipe */
1054 if (uea_idma_write(sc, blockoffset, blocksize))
1055 goto bad;
1056
1057 blockno++;
1058 } while (blockidx->NotLastBlock);
1059
1060 return;
1061
1062bad:
1063 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno);
1064 return;
1065}
1066
1067static void uea_load_page_e4(struct work_struct *work)
1068{
1069 struct uea_softc *sc = container_of(work, struct uea_softc, task);
1070 u8 pageno = sc->pageno;
1071 int i;
1072 struct block_info_e4 bi;
1073 struct l1_code *p;
1074
1075 uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
1076
1077 /* reload firmware when reboot start and it's loaded already */
1078 if (pageno == 0 && sc->dsp_firm) {
1079 release_firmware(sc->dsp_firm);
1080 sc->dsp_firm = NULL;
1081 }
1082
1083 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
1084 return;
1085
1086 p = (struct l1_code *) sc->dsp_firm->data;
Al Virofd05e722008-04-28 07:00:16 +01001087 if (pageno >= le16_to_cpu(p->page_header[0].PageNumber)) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001088 uea_err(INS_TO_USBDEV(sc), "invalid DSP "
1089 "page %u requested\n", pageno);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001090 return;
1091 }
1092
1093 if (pageno != 0) {
1094 __uea_load_page_e4(sc, pageno, 0);
1095 return;
1096 }
1097
1098 uea_dbg(INS_TO_USBDEV(sc),
1099 "sending Main DSP page %u\n", p->page_header[0].PageNumber);
1100
1101 for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) {
1102 if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize))
1103 __uea_load_page_e4(sc, i, 1);
1104 }
1105
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001106 uea_dbg(INS_TO_USBDEV(sc) , "sending start bi\n");
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001107
1108 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1109 bi.bBootPage = 0;
1110 bi.bPageNumber = 0xff;
1111 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1112 bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize));
Al Virofd05e722008-04-28 07:00:16 +01001113 bi.dwAddress = cpu_to_be32(le32_to_cpu(p->page_header[0].PageAddress));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001114
1115 /* send block info through the IDMA pipe */
1116 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1117 uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n");
1118}
1119
matthieu castetb72458a2005-11-07 23:27:13 +01001120static inline void wake_up_cmv_ack(struct uea_softc *sc)
1121{
matthieu castet2a99b502006-04-02 18:43:53 +02001122 BUG_ON(sc->cmv_ack);
matthieu castetb72458a2005-11-07 23:27:13 +01001123 sc->cmv_ack = 1;
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001124 wake_up(&sc->sync_q);
matthieu castetb72458a2005-11-07 23:27:13 +01001125}
1126
1127static inline int wait_cmv_ack(struct uea_softc *sc)
1128{
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001129 int ret = uea_wait(sc, sc->cmv_ack , ACK_TIMEOUT);
1130
matthieu castetb72458a2005-11-07 23:27:13 +01001131 sc->cmv_ack = 0;
1132
matthieu castet2a99b502006-04-02 18:43:53 +02001133 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
1134 jiffies_to_msecs(ret));
1135
matthieu castetb72458a2005-11-07 23:27:13 +01001136 if (ret < 0)
1137 return ret;
1138
1139 return (ret == 0) ? -ETIMEDOUT : 0;
matthieu castetb72458a2005-11-07 23:27:13 +01001140}
1141
1142#define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1143
1144static int uea_request(struct uea_softc *sc,
David Woodhouseaafcd2f2008-05-24 00:05:10 +01001145 u16 value, u16 index, u16 size, const void *data)
matthieu castetb72458a2005-11-07 23:27:13 +01001146{
1147 u8 *xfer_buff;
1148 int ret = -ENOMEM;
1149
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +02001150 xfer_buff = kmemdup(data, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +01001151 if (!xfer_buff) {
1152 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
1153 return ret;
1154 }
matthieu castetb72458a2005-11-07 23:27:13 +01001155
1156 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
1157 UCDC_SEND_ENCAPSULATED_COMMAND,
1158 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1159 value, index, xfer_buff, size, CTRL_TIMEOUT);
1160
1161 kfree(xfer_buff);
1162 if (ret < 0) {
1163 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
1164 return ret;
1165 }
1166
1167 if (ret != size) {
1168 uea_err(INS_TO_USBDEV(sc),
1169 "usb_control_msg send only %d bytes (instead of %d)\n",
1170 ret, size);
1171 return -EIO;
1172 }
1173
1174 return 0;
1175}
1176
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001177static int uea_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001178 u8 function, u32 address, u16 offset, u32 data)
1179{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001180 struct cmv_e1 cmv;
matthieu castetb72458a2005-11-07 23:27:13 +01001181 int ret;
1182
matthieu castet2a99b502006-04-02 18:43:53 +02001183 uea_enters(INS_TO_USBDEV(sc));
1184 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1185 "offset : 0x%04x, data : 0x%08x\n",
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001186 E1_FUNCTION_TYPE(function),
1187 E1_FUNCTION_SUBTYPE(function),
1188 E1_GETSA1(address), E1_GETSA2(address),
1189 E1_GETSA3(address),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001190 E1_GETSA4(address), offset, data);
matthieu castetb72458a2005-11-07 23:27:13 +01001191
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001192 /* we send a request, but we expect a reply */
1193 sc->cmv_dsc.e1.function = function | 0x2;
1194 sc->cmv_dsc.e1.idx++;
1195 sc->cmv_dsc.e1.address = address;
1196 sc->cmv_dsc.e1.offset = offset;
1197
1198 cmv.wPreamble = cpu_to_le16(E1_PREAMBLE);
1199 cmv.bDirection = E1_HOSTTOMODEM;
matthieu castetb72458a2005-11-07 23:27:13 +01001200 cmv.bFunction = function;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001201 cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx);
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001202 put_unaligned_le32(address, &cmv.dwSymbolicAddress);
matthieu castetb72458a2005-11-07 23:27:13 +01001203 cmv.wOffsetAddress = cpu_to_le16(offset);
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001204 put_unaligned_le32(data >> 16 | data << 16, &cmv.dwData);
matthieu castetb72458a2005-11-07 23:27:13 +01001205
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001206 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START,
1207 sizeof(cmv), &cmv);
matthieu castetb72458a2005-11-07 23:27:13 +01001208 if (ret < 0)
1209 return ret;
matthieu castet2a99b502006-04-02 18:43:53 +02001210 ret = wait_cmv_ack(sc);
1211 uea_leaves(INS_TO_USBDEV(sc));
1212 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001213}
1214
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001215static int uea_cmv_e4(struct uea_softc *sc,
1216 u16 function, u16 group, u16 address, u16 offset, u32 data)
1217{
1218 struct cmv_e4 cmv;
1219 int ret;
1220
1221 uea_enters(INS_TO_USBDEV(sc));
1222 memset(&cmv, 0, sizeof(cmv));
1223
1224 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
1225 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1226 E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function),
1227 group, address, offset, data);
1228
1229 /* we send a request, but we expect a reply */
1230 sc->cmv_dsc.e4.function = function | (0x1 << 4);
1231 sc->cmv_dsc.e4.offset = offset;
1232 sc->cmv_dsc.e4.address = address;
1233 sc->cmv_dsc.e4.group = group;
1234
1235 cmv.wFunction = cpu_to_be16(function);
1236 cmv.wGroup = cpu_to_be16(group);
1237 cmv.wAddress = cpu_to_be16(address);
1238 cmv.wOffset = cpu_to_be16(offset);
1239 cmv.dwData[0] = cpu_to_be32(data);
1240
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001241 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START,
1242 sizeof(cmv), &cmv);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001243 if (ret < 0)
1244 return ret;
1245 ret = wait_cmv_ack(sc);
1246 uea_leaves(INS_TO_USBDEV(sc));
1247 return ret;
1248}
1249
1250static inline int uea_read_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001251 u32 address, u16 offset, u32 *data)
1252{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001253 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD),
matthieu castetb72458a2005-11-07 23:27:13 +01001254 address, offset, 0);
1255 if (ret < 0)
1256 uea_err(INS_TO_USBDEV(sc),
1257 "reading cmv failed with error %d\n", ret);
1258 else
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001259 *data = sc->data;
matthieu castetb72458a2005-11-07 23:27:13 +01001260
1261 return ret;
1262}
1263
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001264static inline int uea_read_cmv_e4(struct uea_softc *sc,
1265 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1266{
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001267 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1268 E4_REQUESTREAD, size),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001269 group, address, offset, 0);
1270 if (ret < 0)
1271 uea_err(INS_TO_USBDEV(sc),
1272 "reading cmv failed with error %d\n", ret);
1273 else {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001274 *data = sc->data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001275 /* size is in 16-bit word quantities */
1276 if (size > 2)
1277 *(data + 1) = sc->data1;
1278 }
1279 return ret;
1280}
1281
1282static inline int uea_write_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001283 u32 address, u16 offset, u32 data)
1284{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001285 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE),
matthieu castetb72458a2005-11-07 23:27:13 +01001286 address, offset, data);
1287 if (ret < 0)
1288 uea_err(INS_TO_USBDEV(sc),
1289 "writing cmv failed with error %d\n", ret);
1290
1291 return ret;
1292}
1293
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001294static inline int uea_write_cmv_e4(struct uea_softc *sc,
1295 u8 size, u16 group, u16 address, u16 offset, u32 data)
1296{
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001297 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1298 E4_REQUESTWRITE, size),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001299 group, address, offset, data);
1300 if (ret < 0)
1301 uea_err(INS_TO_USBDEV(sc),
1302 "writing cmv failed with error %d\n", ret);
1303
1304 return ret;
1305}
1306
1307static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1308{
1309 int ret;
1310 u16 timeout;
1311
1312 /* in bulk mode the modem have problem with high rate
1313 * changing internal timing could improve things, but the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001314 * value is mysterious.
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001315 * ADI930 don't support it (-EPIPE error).
1316 */
1317
1318 if (UEA_CHIP_VERSION(sc) == ADI930 ||
Stanislaw Gruszka503add42007-08-20 23:21:06 +02001319 altsetting[sc->modem_index] > 0 ||
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001320 sc->stats.phy.dsrate == dsrate)
1321 return;
1322
1323 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1324 timeout = (dsrate <= 1024*1024) ? 0 : 1;
1325 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
1326 uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n",
1327 timeout, ret < 0 ? " failed" : "");
1328
1329}
1330
matthieu castetb72458a2005-11-07 23:27:13 +01001331/*
1332 * Monitor the modem and update the stat
1333 * return 0 if everything is ok
1334 * return < 0 if an error occurs (-EAGAIN reboot needed)
1335 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001336static int uea_stat_e1(struct uea_softc *sc)
matthieu castetb72458a2005-11-07 23:27:13 +01001337{
1338 u32 data;
1339 int ret;
1340
1341 uea_enters(INS_TO_USBDEV(sc));
1342 data = sc->stats.phy.state;
1343
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001344 ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state);
matthieu castetb72458a2005-11-07 23:27:13 +01001345 if (ret < 0)
1346 return ret;
1347
1348 switch (GET_STATUS(sc->stats.phy.state)) {
1349 case 0: /* not yet synchronized */
1350 uea_dbg(INS_TO_USBDEV(sc),
1351 "modem not yet synchronized\n");
1352 return 0;
1353
1354 case 1: /* initialization */
1355 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1356 return 0;
1357
1358 case 2: /* operational */
1359 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
1360 break;
1361
1362 case 3: /* fail ... */
matthieu casteta7a0c9c2006-10-03 21:44:11 +02001363 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001364 " (may be try other cmv/dsp)\n");
matthieu castetb72458a2005-11-07 23:27:13 +01001365 return -EAGAIN;
1366
1367 case 4 ... 6: /* test state */
1368 uea_warn(INS_TO_USBDEV(sc),
1369 "modem in test mode - not supported\n");
1370 return -EAGAIN;
1371
1372 case 7: /* fast-retain ... */
1373 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
1374 return 0;
1375 default:
1376 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
1377 GET_STATUS(sc->stats.phy.state));
1378 return -EAGAIN;
1379 }
1380
1381 if (GET_STATUS(data) != 2) {
1382 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1383 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1384
1385 /* release the dsp firmware as it is not needed until
1386 * the next failure
1387 */
Jesper Juhl7af39592012-04-09 22:52:26 +02001388 release_firmware(sc->dsp_firm);
1389 sc->dsp_firm = NULL;
matthieu castetb72458a2005-11-07 23:27:13 +01001390 }
1391
1392 /* always update it as atm layer could not be init when we switch to
1393 * operational state
1394 */
Karl Hiramotocc7b86c2010-07-08 20:55:38 +00001395 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND);
matthieu castetb72458a2005-11-07 23:27:13 +01001396
1397 /* wake up processes waiting for synchronization */
1398 wake_up(&sc->sync_q);
1399
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001400 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags);
matthieu castetb72458a2005-11-07 23:27:13 +01001401 if (ret < 0)
1402 return ret;
1403 sc->stats.phy.mflags |= sc->stats.phy.flags;
1404
1405 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1406 * we check the status again in order to detect the failure earlier
1407 */
1408 if (sc->stats.phy.flags) {
matthieu castet2a99b502006-04-02 18:43:53 +02001409 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
matthieu castetb72458a2005-11-07 23:27:13 +01001410 sc->stats.phy.flags);
1411 return 0;
1412 }
1413
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001414 ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001415 if (ret < 0)
1416 return ret;
1417
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001418 uea_set_bulk_timeout(sc, (data >> 16) * 32);
matthieu castetb72458a2005-11-07 23:27:13 +01001419 sc->stats.phy.dsrate = (data >> 16) * 32;
1420 sc->stats.phy.usrate = (data & 0xffff) * 32;
1421 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1422
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001423 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001424 if (ret < 0)
1425 return ret;
1426 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
1427
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001428 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001429 if (ret < 0)
1430 return ret;
1431 sc->stats.phy.usattenuation = (data & 0xff) / 2;
1432
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001433 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin);
matthieu castetb72458a2005-11-07 23:27:13 +01001434 if (ret < 0)
1435 return ret;
1436
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001437 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin);
matthieu castetb72458a2005-11-07 23:27:13 +01001438 if (ret < 0)
1439 return ret;
1440
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001441 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow);
matthieu castetb72458a2005-11-07 23:27:13 +01001442 if (ret < 0)
1443 return ret;
1444
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001445 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow);
matthieu castetb72458a2005-11-07 23:27:13 +01001446 if (ret < 0)
1447 return ret;
1448
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001449 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc);
matthieu castetb72458a2005-11-07 23:27:13 +01001450 if (ret < 0)
1451 return ret;
1452
1453 /* only for atu-c */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001454 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc);
matthieu castetb72458a2005-11-07 23:27:13 +01001455 if (ret < 0)
1456 return ret;
1457
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001458 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr);
matthieu castetb72458a2005-11-07 23:27:13 +01001459 if (ret < 0)
1460 return ret;
1461
1462 /* only for atu-c */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001463 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr);
matthieu castetb72458a2005-11-07 23:27:13 +01001464 if (ret < 0)
1465 return ret;
1466
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001467 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 8, &sc->stats.phy.vidco);
matthieu castetb72458a2005-11-07 23:27:13 +01001468 if (ret < 0)
1469 return ret;
1470
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001471 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 13, &sc->stats.phy.vidcpe);
matthieu castetb72458a2005-11-07 23:27:13 +01001472 if (ret < 0)
1473 return ret;
1474
1475 return 0;
1476}
1477
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001478static int uea_stat_e4(struct uea_softc *sc)
matthieu castetb72458a2005-11-07 23:27:13 +01001479{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001480 u32 data;
1481 u32 tmp_arr[2];
1482 int ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001483
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001484 uea_enters(INS_TO_USBDEV(sc));
1485 data = sc->stats.phy.state;
1486
1487 /* XXX only need to be done before operationnal... */
1488 ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state);
1489 if (ret < 0)
1490 return ret;
1491
1492 switch (sc->stats.phy.state) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001493 case 0x0: /* not yet synchronized */
1494 case 0x1:
1495 case 0x3:
1496 case 0x4:
1497 uea_dbg(INS_TO_USBDEV(sc), "modem not yet "
1498 "synchronized\n");
1499 return 0;
1500 case 0x5: /* initialization */
1501 case 0x6:
1502 case 0x9:
1503 case 0xa:
1504 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1505 return 0;
1506 case 0x2: /* fail ... */
1507 uea_info(INS_TO_USBDEV(sc), "modem synchronization "
1508 "failed (may be try other cmv/dsp)\n");
1509 return -EAGAIN;
1510 case 0x7: /* operational */
1511 break;
1512 default:
1513 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n",
1514 sc->stats.phy.state);
1515 return 0;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001516 }
1517
1518 if (data != 7) {
1519 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1520 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1521
1522 /* release the dsp firmware as it is not needed until
1523 * the next failure
1524 */
Jesper Juhl7af39592012-04-09 22:52:26 +02001525 release_firmware(sc->dsp_firm);
1526 sc->dsp_firm = NULL;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001527 }
1528
1529 /* always update it as atm layer could not be init when we switch to
1530 * operational state
1531 */
Karl Hiramotocc7b86c2010-07-08 20:55:38 +00001532 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001533
1534 /* wake up processes waiting for synchronization */
1535 wake_up(&sc->sync_q);
1536
1537 /* TODO improve this state machine :
1538 * we need some CMV info : what they do and their unit
1539 * we should find the equivalent of eagle3- CMV
1540 */
1541 /* check flags */
1542 ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags);
1543 if (ret < 0)
1544 return ret;
1545 sc->stats.phy.mflags |= sc->stats.phy.flags;
1546
1547 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1548 * we check the status again in order to detect the failure earlier
1549 */
1550 if (sc->stats.phy.flags) {
1551 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1552 sc->stats.phy.flags);
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001553 if (sc->stats.phy.flags & 1) /* delineation LOSS */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001554 return -EAGAIN;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001555 if (sc->stats.phy.flags & 0x4000) /* Reset Flag */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001556 return -EAGAIN;
1557 return 0;
1558 }
1559
1560 /* rate data may be in upper or lower half of 64 bit word, strange */
1561 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr);
1562 if (ret < 0)
1563 return ret;
1564 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1565 sc->stats.phy.usrate = data / 1000;
1566
1567 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr);
1568 if (ret < 0)
1569 return ret;
1570 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1571 uea_set_bulk_timeout(sc, data / 1000);
1572 sc->stats.phy.dsrate = data / 1000;
1573 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1574
1575 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data);
1576 if (ret < 0)
1577 return ret;
1578 sc->stats.phy.dsattenuation = data / 10;
1579
1580 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data);
1581 if (ret < 0)
1582 return ret;
1583 sc->stats.phy.usattenuation = data / 10;
1584
1585 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data);
1586 if (ret < 0)
1587 return ret;
1588 sc->stats.phy.dsmargin = data / 2;
1589
1590 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data);
1591 if (ret < 0)
1592 return ret;
1593 sc->stats.phy.usmargin = data / 10;
1594
1595 return 0;
1596}
1597
1598static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1599{
1600 char file_arr[] = "CMVxy.bin";
1601 char *file;
1602
Rusty Russelld6d1b652010-08-11 23:04:27 -06001603 kparam_block_sysfs_write(cmv_file);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001604 /* set proper name corresponding modem version and line type */
matthieu castetb72458a2005-11-07 23:27:13 +01001605 if (cmv_file[sc->modem_index] == NULL) {
1606 if (UEA_CHIP_VERSION(sc) == ADI930)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001607 file_arr[3] = '9';
1608 else if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1609 file_arr[3] = '4';
matthieu castetb72458a2005-11-07 23:27:13 +01001610 else
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001611 file_arr[3] = 'e';
1612
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02001613 file_arr[4] = IS_ISDN(sc) ? 'i' : 'p';
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001614 file = file_arr;
matthieu castetb72458a2005-11-07 23:27:13 +01001615 } else
1616 file = cmv_file[sc->modem_index];
1617
1618 strcpy(cmv_name, FW_DIR);
Samuel Ortizade901d2009-05-27 00:49:32 +02001619 strlcat(cmv_name, file, UEA_FW_NAME_MAX);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001620 if (ver == 2)
Samuel Ortizade901d2009-05-27 00:49:32 +02001621 strlcat(cmv_name, ".v2", UEA_FW_NAME_MAX);
Rusty Russelld6d1b652010-08-11 23:04:27 -06001622 kparam_unblock_sysfs_write(cmv_file);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001623}
matthieu castetb72458a2005-11-07 23:27:13 +01001624
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001625static int request_cmvs_old(struct uea_softc *sc,
1626 void **cmvs, const struct firmware **fw)
1627{
1628 int ret, size;
1629 u8 *data;
Samuel Ortizade901d2009-05-27 00:49:32 +02001630 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001631
1632 cmvs_file_name(sc, cmv_name, 1);
matthieu castetb72458a2005-11-07 23:27:13 +01001633 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1634 if (ret < 0) {
1635 uea_err(INS_TO_USBDEV(sc),
1636 "requesting firmware %s failed with error %d\n",
1637 cmv_name, ret);
1638 return ret;
1639 }
1640
1641 data = (u8 *) (*fw)->data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001642 size = (*fw)->size;
1643 if (size < 1)
1644 goto err_fw_corrupted;
1645
1646 if (size != *data * sizeof(struct uea_cmvs_v1) + 1)
1647 goto err_fw_corrupted;
1648
1649 *cmvs = (void *)(data + 1);
1650 return *data;
1651
1652err_fw_corrupted:
1653 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1654 release_firmware(*fw);
1655 return -EILSEQ;
1656}
1657
1658static int request_cmvs(struct uea_softc *sc,
1659 void **cmvs, const struct firmware **fw, int *ver)
1660{
1661 int ret, size;
1662 u32 crc;
1663 u8 *data;
Samuel Ortizade901d2009-05-27 00:49:32 +02001664 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001665
1666 cmvs_file_name(sc, cmv_name, 2);
1667 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1668 if (ret < 0) {
1669 /* if caller can handle old version, try to provide it */
1670 if (*ver == 1) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001671 uea_warn(INS_TO_USBDEV(sc), "requesting "
1672 "firmware %s failed, "
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001673 "try to get older cmvs\n", cmv_name);
1674 return request_cmvs_old(sc, cmvs, fw);
1675 }
1676 uea_err(INS_TO_USBDEV(sc),
1677 "requesting firmware %s failed with error %d\n",
1678 cmv_name, ret);
1679 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001680 }
1681
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001682 size = (*fw)->size;
1683 data = (u8 *) (*fw)->data;
1684 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1685 if (*ver == 1) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001686 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted,"
1687 " try to get older cmvs\n", cmv_name);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001688 release_firmware(*fw);
1689 return request_cmvs_old(sc, cmvs, fw);
1690 }
1691 goto err_fw_corrupted;
1692 }
1693
1694 *ver = 2;
1695
1696 data += 4;
1697 size -= 4;
1698 if (size < 5)
1699 goto err_fw_corrupted;
1700
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001701 crc = get_unaligned_le32(data);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001702 data += 4;
1703 size -= 4;
1704 if (crc32_be(0, data, size) != crc)
1705 goto err_fw_corrupted;
1706
1707 if (size != *data * sizeof(struct uea_cmvs_v2) + 1)
1708 goto err_fw_corrupted;
1709
1710 *cmvs = (void *) (data + 1);
matthieu castetb72458a2005-11-07 23:27:13 +01001711 return *data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001712
1713err_fw_corrupted:
1714 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1715 release_firmware(*fw);
1716 return -EILSEQ;
1717}
1718
1719static int uea_send_cmvs_e1(struct uea_softc *sc)
1720{
1721 int i, ret, len;
1722 void *cmvs_ptr;
1723 const struct firmware *cmvs_fw;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001724 int ver = 1; /* we can handle v1 cmv firmware version; */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001725
1726 /* Enter in R-IDLE (cmv) until instructed otherwise */
1727 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
1728 if (ret < 0)
1729 return ret;
1730
1731 /* Dump firmware version */
1732 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid);
1733 if (ret < 0)
1734 return ret;
1735 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1736 sc->stats.phy.firmid);
1737
1738 /* get options */
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001739 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001740 if (ret < 0)
1741 return ret;
1742
1743 /* send options */
1744 if (ver == 1) {
1745 struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr;
1746
1747 uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, "
1748 "please update your firmware\n");
1749
1750 for (i = 0; i < len; i++) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001751 ret = uea_write_cmv_e1(sc,
1752 get_unaligned_le32(&cmvs_v1[i].address),
1753 get_unaligned_le16(&cmvs_v1[i].offset),
1754 get_unaligned_le32(&cmvs_v1[i].data));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001755 if (ret < 0)
1756 goto out;
1757 }
1758 } else if (ver == 2) {
1759 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1760
1761 for (i = 0; i < len; i++) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001762 ret = uea_write_cmv_e1(sc,
1763 get_unaligned_le32(&cmvs_v2[i].address),
1764 (u16) get_unaligned_le32(&cmvs_v2[i].offset),
1765 get_unaligned_le32(&cmvs_v2[i].data));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001766 if (ret < 0)
1767 goto out;
1768 }
1769 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001770 /* This really should not happen */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001771 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1772 goto out;
1773 }
1774
1775 /* Enter in R-ACT-REQ */
1776 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1777 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001778 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1779 "synchronization...\n");
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001780out:
1781 release_firmware(cmvs_fw);
1782 return ret;
1783}
1784
1785static int uea_send_cmvs_e4(struct uea_softc *sc)
1786{
1787 int i, ret, len;
1788 void *cmvs_ptr;
1789 const struct firmware *cmvs_fw;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001790 int ver = 2; /* we can only handle v2 cmv firmware version; */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001791
1792 /* Enter in R-IDLE (cmv) until instructed otherwise */
1793 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
1794 if (ret < 0)
1795 return ret;
1796
1797 /* Dump firmware version */
1798 /* XXX don't read the 3th byte as it is always 6 */
1799 ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid);
1800 if (ret < 0)
1801 return ret;
1802 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1803 sc->stats.phy.firmid);
1804
1805
1806 /* get options */
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001807 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001808 if (ret < 0)
1809 return ret;
1810
1811 /* send options */
1812 if (ver == 2) {
1813 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1814
1815 for (i = 0; i < len; i++) {
1816 ret = uea_write_cmv_e4(sc, 1,
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001817 get_unaligned_le32(&cmvs_v2[i].group),
1818 get_unaligned_le32(&cmvs_v2[i].address),
1819 get_unaligned_le32(&cmvs_v2[i].offset),
1820 get_unaligned_le32(&cmvs_v2[i].data));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001821 if (ret < 0)
1822 goto out;
1823 }
1824 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001825 /* This really should not happen */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001826 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1827 goto out;
1828 }
1829
1830 /* Enter in R-ACT-REQ */
1831 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1832 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001833 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1834 "synchronization...\n");
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001835out:
1836 release_firmware(cmvs_fw);
1837 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001838}
1839
1840/* Start boot post firmware modem:
1841 * - send reset commands through usb control pipe
1842 * - start workqueue for DSP loading
1843 * - send CMV options to modem
1844 */
1845
1846static int uea_start_reset(struct uea_softc *sc)
1847{
1848 u16 zero = 0; /* ;-) */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001849 int ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001850
1851 uea_enters(INS_TO_USBDEV(sc));
1852 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1853
matthieu castet22fcceb2006-04-02 18:44:20 +02001854 /* mask interrupt */
matthieu castetb72458a2005-11-07 23:27:13 +01001855 sc->booting = 1;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001856 /* We need to set this here because, a ack timeout could have occurred,
matthieu castet22fcceb2006-04-02 18:44:20 +02001857 * but before we start the reboot, the ack occurs and set this to 1.
1858 * So we will failed to wait Ready CMV.
1859 */
1860 sc->cmv_ack = 0;
Karl Hiramotocc7b86c2010-07-08 20:55:38 +00001861 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST);
matthieu castetb72458a2005-11-07 23:27:13 +01001862
1863 /* reset statistics */
1864 memset(&sc->stats, 0, sizeof(struct uea_stats));
1865
1866 /* tell the modem that we want to boot in IDMA mode */
1867 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1868 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1869
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001870 /* enter reset mode */
matthieu castetb72458a2005-11-07 23:27:13 +01001871 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1872
1873 /* original driver use 200ms, but windows driver use 100ms */
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001874 ret = uea_wait(sc, 0, msecs_to_jiffies(100));
1875 if (ret < 0)
1876 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001877
1878 /* leave reset mode */
1879 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1880
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001881 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001882 /* clear tx and rx mailboxes */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001883 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1884 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1885 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1886 }
matthieu castetb72458a2005-11-07 23:27:13 +01001887
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001888 ret = uea_wait(sc, 0, msecs_to_jiffies(1000));
1889 if (ret < 0)
1890 return ret;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001891
1892 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001893 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
1894 E4_MODEMREADY, 1);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001895 else
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001896 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
1897 E1_MODEMREADY);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001898
matthieu castet22fcceb2006-04-02 18:44:20 +02001899 /* demask interrupt */
matthieu castetb72458a2005-11-07 23:27:13 +01001900 sc->booting = 0;
1901
1902 /* start loading DSP */
1903 sc->pageno = 0;
1904 sc->ovl = 0;
Tejun Heo9abff152011-01-03 14:49:42 +01001905 schedule_work(&sc->task);
matthieu castetb72458a2005-11-07 23:27:13 +01001906
1907 /* wait for modem ready CMV */
1908 ret = wait_cmv_ack(sc);
1909 if (ret < 0)
1910 return ret;
1911
matthieu castet2a99b502006-04-02 18:43:53 +02001912 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1913
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001914 ret = sc->send_cmvs(sc);
matthieu castetb72458a2005-11-07 23:27:13 +01001915 if (ret < 0)
1916 return ret;
1917
matthieu castetb72458a2005-11-07 23:27:13 +01001918 sc->reset = 0;
1919 uea_leaves(INS_TO_USBDEV(sc));
1920 return ret;
1921}
1922
1923/*
1924 * In case of an error wait 1s before rebooting the modem
1925 * if the modem don't request reboot (-EAGAIN).
1926 * Monitor the modem every 1s.
1927 */
1928
1929static int uea_kthread(void *data)
1930{
1931 struct uea_softc *sc = data;
1932 int ret = -EAGAIN;
1933
Rafael J. Wysocki83144182007-07-17 04:03:35 -07001934 set_freezable();
matthieu castetb72458a2005-11-07 23:27:13 +01001935 uea_enters(INS_TO_USBDEV(sc));
1936 while (!kthread_should_stop()) {
1937 if (ret < 0 || sc->reset)
1938 ret = uea_start_reset(sc);
1939 if (!ret)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001940 ret = sc->stat(sc);
matthieu castetb72458a2005-11-07 23:27:13 +01001941 if (ret != -EAGAIN)
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001942 uea_wait(sc, 0, msecs_to_jiffies(1000));
Stanislaw Gruszka0eb02262007-08-20 23:21:19 +02001943 try_to_freeze();
matthieu castetb72458a2005-11-07 23:27:13 +01001944 }
1945 uea_leaves(INS_TO_USBDEV(sc));
1946 return ret;
1947}
1948
1949/* Load second usb firmware for ADI930 chip */
1950static int load_XILINX_firmware(struct uea_softc *sc)
1951{
1952 const struct firmware *fw_entry;
1953 int ret, size, u, ln;
David Woodhouseaafcd2f2008-05-24 00:05:10 +01001954 const u8 *pfw;
1955 u8 value;
Tim Gardner47282502012-07-25 14:32:50 -06001956 char *fw_name = FPGA930_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +01001957
1958 uea_enters(INS_TO_USBDEV(sc));
1959
1960 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1961 if (ret) {
1962 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1963 fw_name);
1964 goto err0;
1965 }
1966
1967 pfw = fw_entry->data;
1968 size = fw_entry->size;
1969 if (size != 0x577B) {
1970 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1971 fw_name);
1972 ret = -EILSEQ;
1973 goto err1;
1974 }
1975 for (u = 0; u < size; u += ln) {
1976 ln = min(size - u, 64);
1977 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1978 if (ret < 0) {
1979 uea_err(INS_TO_USBDEV(sc),
1980 "elsa download data failed (%d)\n", ret);
1981 goto err1;
1982 }
1983 }
1984
matthieu castete40abaf2006-01-18 07:38:37 +01001985 /* finish to send the fpga */
matthieu castetb72458a2005-11-07 23:27:13 +01001986 ret = uea_request(sc, 0xe, 1, 0, NULL);
1987 if (ret < 0) {
1988 uea_err(INS_TO_USBDEV(sc),
1989 "elsa download data failed (%d)\n", ret);
1990 goto err1;
1991 }
1992
matthieu castete40abaf2006-01-18 07:38:37 +01001993 /* Tell the modem we finish : de-assert reset */
matthieu castetb72458a2005-11-07 23:27:13 +01001994 value = 0;
1995 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1996 if (ret < 0)
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001997 uea_err(sc->usb_dev, "elsa de-assert failed with error"
1998 " %d\n", ret);
matthieu castetb72458a2005-11-07 23:27:13 +01001999
matthieu castetb72458a2005-11-07 23:27:13 +01002000err1:
2001 release_firmware(fw_entry);
2002err0:
2003 uea_leaves(INS_TO_USBDEV(sc));
2004 return ret;
2005}
2006
matthieu castete40abaf2006-01-18 07:38:37 +01002007/* The modem send us an ack. First with check if it right */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002008static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
matthieu castetb72458a2005-11-07 23:27:13 +01002009{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002010 struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;
2011 struct cmv_e1 *cmv = &intr->u.e1.s2.cmv;
2012
matthieu castetb72458a2005-11-07 23:27:13 +01002013 uea_enters(INS_TO_USBDEV(sc));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002014 if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE)
matthieu castetb72458a2005-11-07 23:27:13 +01002015 goto bad1;
2016
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002017 if (cmv->bDirection != E1_MODEMTOHOST)
matthieu castetb72458a2005-11-07 23:27:13 +01002018 goto bad1;
2019
2020 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002021 * the first MEMACCESS cmv. Ignore it...
matthieu castetb72458a2005-11-07 23:27:13 +01002022 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002023 if (cmv->bFunction != dsc->function) {
matthieu castetb72458a2005-11-07 23:27:13 +01002024 if (UEA_CHIP_VERSION(sc) == ADI930
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002025 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
2026 cmv->wIndex = cpu_to_le16(dsc->idx);
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002027 put_unaligned_le32(dsc->address,
2028 &cmv->dwSymbolicAddress);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002029 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
2030 } else
matthieu castetb72458a2005-11-07 23:27:13 +01002031 goto bad2;
2032 }
2033
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002034 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
2035 E1_MODEMREADY)) {
matthieu castetb72458a2005-11-07 23:27:13 +01002036 wake_up_cmv_ack(sc);
matthieu castet2a99b502006-04-02 18:43:53 +02002037 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002038 return;
2039 }
2040
2041 /* in case of MEMACCESS */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002042 if (le16_to_cpu(cmv->wIndex) != dsc->idx ||
Harvey Harrisona5abdea2008-04-29 01:03:40 -07002043 get_unaligned_le32(&cmv->dwSymbolicAddress) != dsc->address ||
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002044 le16_to_cpu(cmv->wOffsetAddress) != dsc->offset)
matthieu castetb72458a2005-11-07 23:27:13 +01002045 goto bad2;
2046
Harvey Harrisona5abdea2008-04-29 01:03:40 -07002047 sc->data = get_unaligned_le32(&cmv->dwData);
matthieu castetb72458a2005-11-07 23:27:13 +01002048 sc->data = sc->data << 16 | sc->data >> 16;
2049
2050 wake_up_cmv_ack(sc);
matthieu castet2a99b502006-04-02 18:43:53 +02002051 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002052 return;
2053
2054bad2:
Joe Perchesfec8de32007-11-19 17:53:33 -08002055 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
matthieu castetb72458a2005-11-07 23:27:13 +01002056 "Function : %d, Subfunction : %d\n",
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002057 E1_FUNCTION_TYPE(cmv->bFunction),
2058 E1_FUNCTION_SUBTYPE(cmv->bFunction));
matthieu castet2a99b502006-04-02 18:43:53 +02002059 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002060 return;
2061
2062bad1:
2063 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
2064 "wPreamble %d, bDirection %d\n",
2065 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
matthieu castet2a99b502006-04-02 18:43:53 +02002066 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002067}
2068
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002069/* The modem send us an ack. First with check if it right */
2070static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
2071{
2072 struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;
2073 struct cmv_e4 *cmv = &intr->u.e4.s2.cmv;
2074
2075 uea_enters(INS_TO_USBDEV(sc));
2076 uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n",
2077 be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction),
2078 be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
2079 be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1]));
2080
2081 if (be16_to_cpu(cmv->wFunction) != dsc->function)
2082 goto bad2;
2083
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002084 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
2085 E4_MODEMREADY, 1)) {
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002086 wake_up_cmv_ack(sc);
2087 uea_leaves(INS_TO_USBDEV(sc));
2088 return;
2089 }
2090
2091 /* in case of MEMACCESS */
2092 if (be16_to_cpu(cmv->wOffset) != dsc->offset ||
2093 be16_to_cpu(cmv->wGroup) != dsc->group ||
2094 be16_to_cpu(cmv->wAddress) != dsc->address)
2095 goto bad2;
2096
2097 sc->data = be32_to_cpu(cmv->dwData[0]);
2098 sc->data1 = be32_to_cpu(cmv->dwData[1]);
2099 wake_up_cmv_ack(sc);
2100 uea_leaves(INS_TO_USBDEV(sc));
2101 return;
2102
2103bad2:
Joe Perchesfec8de32007-11-19 17:53:33 -08002104 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002105 "Function : %d, Subfunction : %d\n",
2106 E4_FUNCTION_TYPE(cmv->wFunction),
2107 E4_FUNCTION_SUBTYPE(cmv->wFunction));
2108 uea_leaves(INS_TO_USBDEV(sc));
2109 return;
2110}
2111
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002112static void uea_schedule_load_page_e1(struct uea_softc *sc,
2113 struct intr_pkt *intr)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002114{
2115 sc->pageno = intr->e1_bSwapPageNo;
2116 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
Tejun Heo9abff152011-01-03 14:49:42 +01002117 schedule_work(&sc->task);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002118}
2119
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002120static void uea_schedule_load_page_e4(struct uea_softc *sc,
2121 struct intr_pkt *intr)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002122{
2123 sc->pageno = intr->e4_bSwapPageNo;
Tejun Heo9abff152011-01-03 14:49:42 +01002124 schedule_work(&sc->task);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002125}
2126
matthieu castetb72458a2005-11-07 23:27:13 +01002127/*
2128 * interrupt handler
2129 */
David Howells7d12e782006-10-05 14:55:46 +01002130static void uea_intr(struct urb *urb)
matthieu castetb72458a2005-11-07 23:27:13 +01002131{
matthieu castete40abaf2006-01-18 07:38:37 +01002132 struct uea_softc *sc = urb->context;
2133 struct intr_pkt *intr = urb->transfer_buffer;
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002134 int status = urb->status;
2135
matthieu castetb72458a2005-11-07 23:27:13 +01002136 uea_enters(INS_TO_USBDEV(sc));
2137
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002138 if (unlikely(status < 0)) {
matthieu castetb72458a2005-11-07 23:27:13 +01002139 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002140 status);
matthieu castetb72458a2005-11-07 23:27:13 +01002141 return;
2142 }
2143
matthieu castetb72458a2005-11-07 23:27:13 +01002144 /* device-to-host interrupt */
2145 if (intr->bType != 0x08 || sc->booting) {
matthieu castete40abaf2006-01-18 07:38:37 +01002146 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
matthieu castetb72458a2005-11-07 23:27:13 +01002147 goto resubmit;
2148 }
2149
2150 switch (le16_to_cpu(intr->wInterrupt)) {
2151 case INT_LOADSWAPPAGE:
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002152 sc->schedule_load_page(sc, intr);
matthieu castetb72458a2005-11-07 23:27:13 +01002153 break;
2154
2155 case INT_INCOMINGCMV:
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002156 sc->dispatch_cmv(sc, intr);
matthieu castetb72458a2005-11-07 23:27:13 +01002157 break;
2158
2159 default:
matthieu castete40abaf2006-01-18 07:38:37 +01002160 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
matthieu castetb72458a2005-11-07 23:27:13 +01002161 le16_to_cpu(intr->wInterrupt));
2162 }
2163
2164resubmit:
2165 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
2166}
2167
2168/*
2169 * Start the modem : init the data and start kernel thread
2170 */
2171static int uea_boot(struct uea_softc *sc)
2172{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002173 int ret, size;
matthieu castetb72458a2005-11-07 23:27:13 +01002174 struct intr_pkt *intr;
2175
2176 uea_enters(INS_TO_USBDEV(sc));
2177
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002178 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2179 size = E4_INTR_PKT_SIZE;
2180 sc->dispatch_cmv = uea_dispatch_cmv_e4;
2181 sc->schedule_load_page = uea_schedule_load_page_e4;
2182 sc->stat = uea_stat_e4;
2183 sc->send_cmvs = uea_send_cmvs_e4;
2184 INIT_WORK(&sc->task, uea_load_page_e4);
2185 } else {
2186 size = E1_INTR_PKT_SIZE;
2187 sc->dispatch_cmv = uea_dispatch_cmv_e1;
2188 sc->schedule_load_page = uea_schedule_load_page_e1;
2189 sc->stat = uea_stat_e1;
2190 sc->send_cmvs = uea_send_cmvs_e1;
2191 INIT_WORK(&sc->task, uea_load_page_e1);
2192 }
2193
matthieu castetb72458a2005-11-07 23:27:13 +01002194 init_waitqueue_head(&sc->sync_q);
matthieu castetb72458a2005-11-07 23:27:13 +01002195
2196 if (UEA_CHIP_VERSION(sc) == ADI930)
2197 load_XILINX_firmware(sc);
2198
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002199 intr = kmalloc(size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +01002200 if (!intr) {
2201 uea_err(INS_TO_USBDEV(sc),
2202 "cannot allocate interrupt package\n");
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002203 goto err0;
matthieu castetb72458a2005-11-07 23:27:13 +01002204 }
2205
2206 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
2207 if (!sc->urb_int) {
2208 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002209 goto err1;
matthieu castetb72458a2005-11-07 23:27:13 +01002210 }
2211
2212 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
2213 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002214 intr, size, uea_intr, sc,
matthieu castetb72458a2005-11-07 23:27:13 +01002215 sc->usb_dev->actconfig->interface[0]->altsetting[0].
2216 endpoint[0].desc.bInterval);
2217
2218 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2219 if (ret < 0) {
2220 uea_err(INS_TO_USBDEV(sc),
2221 "urb submition failed with error %d\n", ret);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002222 goto err1;
matthieu castetb72458a2005-11-07 23:27:13 +01002223 }
2224
Dan Williams12f188f2010-12-19 08:17:50 +00002225 /* Create worker thread, but don't start it here. Start it after
2226 * all usbatm generic initialization is done.
2227 */
2228 sc->kthread = kthread_create(uea_kthread, sc, "ueagle-atm");
2229 if (IS_ERR(sc->kthread)) {
matthieu castetb72458a2005-11-07 23:27:13 +01002230 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2231 goto err2;
2232 }
2233
2234 uea_leaves(INS_TO_USBDEV(sc));
2235 return 0;
2236
2237err2:
2238 usb_kill_urb(sc->urb_int);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002239err1:
matthieu castetb72458a2005-11-07 23:27:13 +01002240 usb_free_urb(sc->urb_int);
matthieu castet4d45e212006-04-02 18:45:46 +02002241 sc->urb_int = NULL;
2242 kfree(intr);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002243err0:
matthieu castetb72458a2005-11-07 23:27:13 +01002244 uea_leaves(INS_TO_USBDEV(sc));
2245 return -ENOMEM;
2246}
2247
2248/*
2249 * Stop the modem : kill kernel thread and free data
2250 */
2251static void uea_stop(struct uea_softc *sc)
2252{
2253 int ret;
2254 uea_enters(INS_TO_USBDEV(sc));
2255 ret = kthread_stop(sc->kthread);
matthieu castete40abaf2006-01-18 07:38:37 +01002256 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
matthieu castetb72458a2005-11-07 23:27:13 +01002257
matthieu castetb72458a2005-11-07 23:27:13 +01002258 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
2259
2260 usb_kill_urb(sc->urb_int);
2261 kfree(sc->urb_int->transfer_buffer);
2262 usb_free_urb(sc->urb_int);
2263
Tejun Heo9abff152011-01-03 14:49:42 +01002264 /* flush the work item, when no one can schedule it */
Tejun Heo43829732012-08-20 14:51:24 -07002265 flush_work(&sc->task);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002266
Jesper Juhl7af39592012-04-09 22:52:26 +02002267 release_firmware(sc->dsp_firm);
matthieu castetb72458a2005-11-07 23:27:13 +01002268 uea_leaves(INS_TO_USBDEV(sc));
2269}
2270
2271/* syfs interface */
2272static struct uea_softc *dev_to_uea(struct device *dev)
2273{
2274 struct usb_interface *intf;
2275 struct usbatm_data *usbatm;
2276
2277 intf = to_usb_interface(dev);
2278 if (!intf)
2279 return NULL;
2280
2281 usbatm = usb_get_intfdata(intf);
2282 if (!usbatm)
2283 return NULL;
2284
2285 return usbatm->driver_data;
2286}
2287
2288static ssize_t read_status(struct device *dev, struct device_attribute *attr,
2289 char *buf)
2290{
2291 int ret = -ENODEV;
2292 struct uea_softc *sc;
2293
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002294 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002295 sc = dev_to_uea(dev);
2296 if (!sc)
2297 goto out;
2298 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
2299out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002300 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002301 return ret;
2302}
2303
2304static ssize_t reboot(struct device *dev, struct device_attribute *attr,
2305 const char *buf, size_t count)
2306{
2307 int ret = -ENODEV;
2308 struct uea_softc *sc;
2309
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002310 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002311 sc = dev_to_uea(dev);
2312 if (!sc)
2313 goto out;
2314 sc->reset = 1;
2315 ret = count;
2316out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002317 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002318 return ret;
2319}
2320
Greg Kroah-Hartmane502ac52010-11-15 11:11:45 -08002321static DEVICE_ATTR(stat_status, S_IWUSR | S_IRUGO, read_status, reboot);
matthieu castetb72458a2005-11-07 23:27:13 +01002322
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002323static ssize_t read_human_status(struct device *dev,
2324 struct device_attribute *attr, char *buf)
matthieu castetb72458a2005-11-07 23:27:13 +01002325{
2326 int ret = -ENODEV;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002327 int modem_state;
matthieu castetb72458a2005-11-07 23:27:13 +01002328 struct uea_softc *sc;
2329
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002330 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002331 sc = dev_to_uea(dev);
2332 if (!sc)
2333 goto out;
2334
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002335 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2336 switch (sc->stats.phy.state) {
2337 case 0x0: /* not yet synchronized */
2338 case 0x1:
2339 case 0x3:
2340 case 0x4:
2341 modem_state = 0;
2342 break;
2343 case 0x5: /* initialization */
2344 case 0x6:
2345 case 0x9:
2346 case 0xa:
2347 modem_state = 1;
2348 break;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002349 case 0x7: /* operational */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002350 modem_state = 2;
2351 break;
2352 case 0x2: /* fail ... */
2353 modem_state = 3;
2354 break;
2355 default: /* unknown */
2356 modem_state = 4;
2357 break;
2358 }
2359 } else
2360 modem_state = GET_STATUS(sc->stats.phy.state);
2361
2362 switch (modem_state) {
matthieu castetb72458a2005-11-07 23:27:13 +01002363 case 0:
2364 ret = sprintf(buf, "Modem is booting\n");
2365 break;
2366 case 1:
2367 ret = sprintf(buf, "Modem is initializing\n");
2368 break;
2369 case 2:
2370 ret = sprintf(buf, "Modem is operational\n");
2371 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002372 case 3:
matthieu castetb72458a2005-11-07 23:27:13 +01002373 ret = sprintf(buf, "Modem synchronization failed\n");
2374 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002375 default:
2376 ret = sprintf(buf, "Modem state is unknown\n");
2377 break;
matthieu castetb72458a2005-11-07 23:27:13 +01002378 }
2379out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002380 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002381 return ret;
2382}
2383
Greg Kroah-Hartmane502ac52010-11-15 11:11:45 -08002384static DEVICE_ATTR(stat_human_status, S_IRUGO, read_human_status, NULL);
matthieu castetb72458a2005-11-07 23:27:13 +01002385
2386static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2387 char *buf)
2388{
2389 int ret = -ENODEV;
2390 struct uea_softc *sc;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002391 char *delin = "GOOD";
matthieu castetb72458a2005-11-07 23:27:13 +01002392
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002393 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002394 sc = dev_to_uea(dev);
2395 if (!sc)
2396 goto out;
2397
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002398 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2399 if (sc->stats.phy.flags & 0x4000)
2400 delin = "RESET";
2401 else if (sc->stats.phy.flags & 0x0001)
2402 delin = "LOSS";
2403 } else {
2404 if (sc->stats.phy.flags & 0x0C00)
2405 delin = "ERROR";
2406 else if (sc->stats.phy.flags & 0x0030)
2407 delin = "LOSS";
2408 }
2409
2410 ret = sprintf(buf, "%s\n", delin);
matthieu castetb72458a2005-11-07 23:27:13 +01002411out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002412 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002413 return ret;
2414}
2415
Greg Kroah-Hartmane502ac52010-11-15 11:11:45 -08002416static DEVICE_ATTR(stat_delin, S_IRUGO, read_delin, NULL);
matthieu castetb72458a2005-11-07 23:27:13 +01002417
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002418#define UEA_ATTR(name, reset) \
matthieu castetb72458a2005-11-07 23:27:13 +01002419 \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002420static ssize_t read_##name(struct device *dev, \
matthieu castetb72458a2005-11-07 23:27:13 +01002421 struct device_attribute *attr, char *buf) \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002422{ \
2423 int ret = -ENODEV; \
2424 struct uea_softc *sc; \
2425 \
2426 mutex_lock(&uea_mutex); \
matthieu castetb72458a2005-11-07 23:27:13 +01002427 sc = dev_to_uea(dev); \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002428 if (!sc) \
2429 goto out; \
matthieu castetb72458a2005-11-07 23:27:13 +01002430 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2431 if (reset) \
2432 sc->stats.phy.name = 0; \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002433out: \
2434 mutex_unlock(&uea_mutex); \
2435 return ret; \
2436} \
matthieu castetb72458a2005-11-07 23:27:13 +01002437 \
2438static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2439
2440UEA_ATTR(mflags, 1);
2441UEA_ATTR(vidcpe, 0);
2442UEA_ATTR(usrate, 0);
2443UEA_ATTR(dsrate, 0);
2444UEA_ATTR(usattenuation, 0);
2445UEA_ATTR(dsattenuation, 0);
2446UEA_ATTR(usmargin, 0);
2447UEA_ATTR(dsmargin, 0);
2448UEA_ATTR(txflow, 0);
2449UEA_ATTR(rxflow, 0);
2450UEA_ATTR(uscorr, 0);
2451UEA_ATTR(dscorr, 0);
2452UEA_ATTR(usunc, 0);
2453UEA_ATTR(dsunc, 0);
matthieu casteta7a0c9c2006-10-03 21:44:11 +02002454UEA_ATTR(firmid, 0);
matthieu castetb72458a2005-11-07 23:27:13 +01002455
2456/* Retrieve the device End System Identifier (MAC) */
2457
matthieu castetb72458a2005-11-07 23:27:13 +01002458static int uea_getesi(struct uea_softc *sc, u_char * esi)
2459{
2460 unsigned char mac_str[2 * ETH_ALEN + 1];
2461 int i;
2462 if (usb_string
2463 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
2464 sizeof(mac_str)) != 2 * ETH_ALEN)
2465 return 1;
2466
2467 for (i = 0; i < ETH_ALEN; i++)
Andy Shevchenkoe6448142010-06-15 17:04:44 +03002468 esi[i] = hex_to_bin(mac_str[2 * i]) * 16 +
2469 hex_to_bin(mac_str[2 * i + 1]);
matthieu castetb72458a2005-11-07 23:27:13 +01002470
2471 return 0;
2472}
2473
2474/* ATM stuff */
2475static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
2476{
2477 struct uea_softc *sc = usbatm->driver_data;
2478
2479 return uea_getesi(sc, atm_dev->esi);
2480}
2481
2482static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
2483{
2484 struct uea_softc *sc = usbatm->driver_data;
2485
matthieu castet531a39b2006-10-03 21:49:29 +02002486 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002487
2488 return 0;
2489
2490}
2491
2492static int claim_interface(struct usb_device *usb_dev,
2493 struct usbatm_data *usbatm, int ifnum)
2494{
2495 int ret;
2496 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
2497
2498 if (!intf) {
2499 uea_err(usb_dev, "interface %d not found\n", ifnum);
2500 return -ENODEV;
2501 }
2502
2503 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
2504 if (ret != 0)
2505 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
2506 ret);
2507 return ret;
2508}
2509
Greg Kroah-Hartmane7ccdfe2006-08-28 11:43:25 -07002510static struct attribute *attrs[] = {
2511 &dev_attr_stat_status.attr,
2512 &dev_attr_stat_mflags.attr,
2513 &dev_attr_stat_human_status.attr,
2514 &dev_attr_stat_delin.attr,
2515 &dev_attr_stat_vidcpe.attr,
2516 &dev_attr_stat_usrate.attr,
2517 &dev_attr_stat_dsrate.attr,
2518 &dev_attr_stat_usattenuation.attr,
2519 &dev_attr_stat_dsattenuation.attr,
2520 &dev_attr_stat_usmargin.attr,
2521 &dev_attr_stat_dsmargin.attr,
2522 &dev_attr_stat_txflow.attr,
2523 &dev_attr_stat_rxflow.attr,
2524 &dev_attr_stat_uscorr.attr,
2525 &dev_attr_stat_dscorr.attr,
2526 &dev_attr_stat_usunc.attr,
2527 &dev_attr_stat_dsunc.attr,
matthieu casteta7a0c9c2006-10-03 21:44:11 +02002528 &dev_attr_stat_firmid.attr,
matthieu castet9ab99c82006-10-11 14:20:56 -07002529 NULL,
Greg Kroah-Hartmane7ccdfe2006-08-28 11:43:25 -07002530};
2531static struct attribute_group attr_grp = {
2532 .attrs = attrs,
2533};
2534
matthieu castetb72458a2005-11-07 23:27:13 +01002535static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
Duncan Sands35644b02006-01-17 11:16:13 +01002536 const struct usb_device_id *id)
matthieu castetb72458a2005-11-07 23:27:13 +01002537{
2538 struct usb_device *usb = interface_to_usbdev(intf);
2539 struct uea_softc *sc;
2540 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002541 unsigned int alt;
matthieu castetb72458a2005-11-07 23:27:13 +01002542
2543 uea_enters(usb);
2544
2545 /* interface 0 is for firmware/monitoring */
2546 if (ifnum != UEA_INTR_IFACE_NO)
2547 return -ENODEV;
2548
Duncan Sands0dfcd3e2006-01-13 09:36:20 +01002549 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
matthieu castetb72458a2005-11-07 23:27:13 +01002550
2551 /* interface 1 is for outbound traffic */
2552 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
2553 if (ret < 0)
2554 return ret;
2555
matthieu castete40abaf2006-01-18 07:38:37 +01002556 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
matthieu castetb72458a2005-11-07 23:27:13 +01002557 if (UEA_CHIP_VERSION(id) != ADI930) {
2558 /* interface 2 is for inbound traffic */
2559 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
2560 if (ret < 0)
2561 return ret;
2562 }
2563
2564 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
2565 if (!sc) {
matthieu castet584958c2006-04-02 18:44:48 +02002566 uea_err(usb, "uea_init: not enough memory !\n");
matthieu castetb72458a2005-11-07 23:27:13 +01002567 return -ENOMEM;
2568 }
2569
2570 sc->usb_dev = usb;
2571 usbatm->driver_data = sc;
2572 sc->usbatm = usbatm;
2573 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
2574 sc->driver_info = id->driver_info;
2575
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002576 /* first try to use module parameter */
2577 if (annex[sc->modem_index] == 1)
2578 sc->annex = ANNEXA;
2579 else if (annex[sc->modem_index] == 2)
2580 sc->annex = ANNEXB;
2581 /* try to autodetect annex */
2582 else if (sc->driver_info & AUTO_ANNEX_A)
2583 sc->annex = ANNEXA;
2584 else if (sc->driver_info & AUTO_ANNEX_B)
2585 sc->annex = ANNEXB;
2586 else
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002587 sc->annex = (le16_to_cpu
2588 (sc->usb_dev->descriptor.bcdDevice) & 0x80) ? ANNEXB : ANNEXA;
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002589
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002590 alt = altsetting[sc->modem_index];
matthieu castet3c9666c2006-01-18 07:38:19 +01002591 /* ADI930 don't support iso */
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002592 if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002593 if (alt <= 8 &&
2594 usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) {
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002595 uea_dbg(usb, "set alternate %u for 2 interface\n", alt);
matthieu castet3c9666c2006-01-18 07:38:19 +01002596 uea_info(usb, "using iso mode\n");
2597 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
2598 } else {
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002599 uea_err(usb, "setting alternate %u failed for "
2600 "2 interface, using bulk mode\n", alt);
matthieu castet3c9666c2006-01-18 07:38:19 +01002601 }
2602 }
2603
matthieu castet9ab99c82006-10-11 14:20:56 -07002604 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
2605 if (ret < 0)
2606 goto error;
2607
matthieu castetb72458a2005-11-07 23:27:13 +01002608 ret = uea_boot(sc);
matthieu castet9ab99c82006-10-11 14:20:56 -07002609 if (ret < 0)
Stanislaw Gruszka4c132e72007-08-20 23:20:49 +02002610 goto error_rm_grp;
matthieu castetb72458a2005-11-07 23:27:13 +01002611
matthieu castetb72458a2005-11-07 23:27:13 +01002612 return 0;
Stanislaw Gruszka4c132e72007-08-20 23:20:49 +02002613
2614error_rm_grp:
2615 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
matthieu castet9ab99c82006-10-11 14:20:56 -07002616error:
2617 kfree(sc);
2618 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01002619}
2620
2621static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
2622{
2623 struct uea_softc *sc = usbatm->driver_data;
2624
matthieu castet9ab99c82006-10-11 14:20:56 -07002625 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
matthieu castetb72458a2005-11-07 23:27:13 +01002626 uea_stop(sc);
2627 kfree(sc);
2628}
2629
2630static struct usbatm_driver uea_usbatm_driver = {
2631 .driver_name = "ueagle-atm",
matthieu castetb72458a2005-11-07 23:27:13 +01002632 .bind = uea_bind,
2633 .atm_start = uea_atm_open,
2634 .unbind = uea_unbind,
2635 .heavy_init = uea_heavy,
Duncan Sands80aae7a2006-01-13 10:59:23 +01002636 .bulk_in = UEA_BULK_DATA_PIPE,
2637 .bulk_out = UEA_BULK_DATA_PIPE,
matthieu castet3c9666c2006-01-18 07:38:19 +01002638 .isoc_in = UEA_ISO_DATA_PIPE,
matthieu castetb72458a2005-11-07 23:27:13 +01002639};
2640
2641static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2642{
2643 struct usb_device *usb = interface_to_usbdev(intf);
Dan Williams12f188f2010-12-19 08:17:50 +00002644 int ret;
matthieu castetb72458a2005-11-07 23:27:13 +01002645
2646 uea_enters(usb);
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002647 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2648 le16_to_cpu(usb->descriptor.idVendor),
2649 le16_to_cpu(usb->descriptor.idProduct),
2650 le16_to_cpu(usb->descriptor.bcdDevice),
2651 chip_name[UEA_CHIP_VERSION(id)]);
matthieu castetb72458a2005-11-07 23:27:13 +01002652
2653 usb_reset_device(usb);
2654
2655 if (UEA_IS_PREFIRM(id))
2656 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2657
Dan Williams12f188f2010-12-19 08:17:50 +00002658 ret = usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2659 if (ret == 0) {
2660 struct usbatm_data *usbatm = usb_get_intfdata(intf);
2661 struct uea_softc *sc = usbatm->driver_data;
2662
2663 /* Ensure carrier is initialized to off as early as possible */
2664 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST);
2665
2666 /* Only start the worker thread when all init is done */
2667 wake_up_process(sc->kthread);
2668 }
2669
2670 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01002671}
2672
2673static void uea_disconnect(struct usb_interface *intf)
2674{
2675 struct usb_device *usb = interface_to_usbdev(intf);
2676 int ifnum = intf->altsetting->desc.bInterfaceNumber;
2677 uea_enters(usb);
2678
2679 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2680 * Pre-firmware device has one interface
2681 */
2682 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002683 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002684 usbatm_usb_disconnect(intf);
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002685 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002686 uea_info(usb, "ADSL device removed\n");
2687 }
2688
2689 uea_leaves(usb);
2690}
2691
2692/*
2693 * List of supported VID/PID
2694 */
2695static const struct usb_device_id uea_ids[] = {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002696 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM),
2697 .driver_info = ADI930 | PREFIRM},
2698 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM),
2699 .driver_info = ADI930 | PSTFIRM},
2700 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM),
2701 .driver_info = EAGLE_I | PREFIRM},
2702 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM),
2703 .driver_info = EAGLE_I | PSTFIRM},
2704 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM),
2705 .driver_info = EAGLE_II | PREFIRM},
2706 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM),
2707 .driver_info = EAGLE_II | PSTFIRM},
2708 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM),
2709 .driver_info = EAGLE_II | PREFIRM},
2710 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM),
2711 .driver_info = EAGLE_II | PSTFIRM},
2712 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM),
2713 .driver_info = EAGLE_III | PREFIRM},
2714 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM),
2715 .driver_info = EAGLE_III | PSTFIRM},
2716 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM),
2717 .driver_info = EAGLE_IV | PREFIRM},
2718 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM),
2719 .driver_info = EAGLE_IV | PSTFIRM},
2720 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM),
2721 .driver_info = EAGLE_I | PREFIRM},
2722 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM),
2723 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2724 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM),
2725 .driver_info = EAGLE_I | PREFIRM},
2726 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM),
2727 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2728 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM),
2729 .driver_info = EAGLE_II | PREFIRM},
2730 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM),
2731 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A},
2732 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM),
2733 .driver_info = EAGLE_II | PREFIRM},
2734 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM),
2735 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B},
2736 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM),
2737 .driver_info = ADI930 | PREFIRM},
2738 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM),
2739 .driver_info = ADI930 | PSTFIRM},
2740 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM),
2741 .driver_info = ADI930 | PREFIRM},
2742 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM),
2743 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A},
2744 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM),
2745 .driver_info = ADI930 | PREFIRM},
2746 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM),
2747 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B},
2748 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM),
2749 .driver_info = EAGLE_I | PREFIRM},
2750 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM),
2751 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2752 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM),
2753 .driver_info = EAGLE_I | PREFIRM},
2754 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM),
2755 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2756 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),
2757 .driver_info = EAGLE_I | PREFIRM},
2758 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),
2759 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2760 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),
2761 .driver_info = EAGLE_I | PREFIRM},
2762 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),
2763 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
matthieu castetb72458a2005-11-07 23:27:13 +01002764 {}
2765};
2766
2767/*
2768 * USB driver descriptor
2769 */
2770static struct usb_driver uea_driver = {
matthieu castetb72458a2005-11-07 23:27:13 +01002771 .name = "ueagle-atm",
2772 .id_table = uea_ids,
2773 .probe = uea_probe,
2774 .disconnect = uea_disconnect,
2775};
2776
2777MODULE_DEVICE_TABLE(usb, uea_ids);
2778
Greg Kroah-Hartman65db4302011-11-18 09:34:02 -08002779module_usb_driver(uea_driver);
matthieu castetb72458a2005-11-07 23:27:13 +01002780
2781MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2782MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2783MODULE_LICENSE("Dual BSD/GPL");
Tim Gardner47282502012-07-25 14:32:50 -06002784MODULE_FIRMWARE(EAGLE_FIRMWARE);
2785MODULE_FIRMWARE(ADI930_FIRMWARE);
2786MODULE_FIRMWARE(EAGLE_I_FIRMWARE);
2787MODULE_FIRMWARE(EAGLE_II_FIRMWARE);
2788MODULE_FIRMWARE(EAGLE_III_FIRMWARE);
2789MODULE_FIRMWARE(EAGLE_IV_FIRMWARE);
2790MODULE_FIRMWARE(DSP4I_FIRMWARE);
2791MODULE_FIRMWARE(DSP4P_FIRMWARE);
2792MODULE_FIRMWARE(DSP9I_FIRMWARE);
2793MODULE_FIRMWARE(DSP9P_FIRMWARE);
2794MODULE_FIRMWARE(DSPEI_FIRMWARE);
2795MODULE_FIRMWARE(DSPEP_FIRMWARE);
2796MODULE_FIRMWARE(FPGA930_FIRMWARE);
2797MODULE_FIRMWARE(CMV4P_FIRMWARE);
2798MODULE_FIRMWARE(CMV4PV2_FIRMWARE);
2799MODULE_FIRMWARE(CMV4I_FIRMWARE);
2800MODULE_FIRMWARE(CMV4IV2_FIRMWARE);
2801MODULE_FIRMWARE(CMV9P_FIRMWARE);
2802MODULE_FIRMWARE(CMV9PV2_FIRMWARE);
2803MODULE_FIRMWARE(CMV9I_FIRMWARE);
2804MODULE_FIRMWARE(CMV9IV2_FIRMWARE);
2805MODULE_FIRMWARE(CMVEP_FIRMWARE);
2806MODULE_FIRMWARE(CMVEPV2_FIRMWARE);
2807MODULE_FIRMWARE(CMVEI_FIRMWARE);
2808MODULE_FIRMWARE(CMVEIV2_FIRMWARE);