blob: df67815f74e68020076c8b59bcecc8ba0bf3782d [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>
matthieu castetb72458a2005-11-07 23:27:13 +010060#include <linux/crc32.h>
61#include <linux/usb.h>
62#include <linux/firmware.h>
63#include <linux/ctype.h>
Randy Dunlap5371f802007-02-16 01:47:33 -080064#include <linux/sched.h>
matthieu castetb72458a2005-11-07 23:27:13 +010065#include <linux/kthread.h>
Arjan van de Venab3c81f2006-01-13 15:52:55 +010066#include <linux/mutex.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080067#include <linux/freezer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090068#include <linux/slab.h>
Andy Shevchenkoe6448142010-06-15 17:04:44 +030069#include <linux/kernel.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080070
matthieu castetb72458a2005-11-07 23:27:13 +010071#include <asm/unaligned.h>
72
73#include "usbatm.h"
74
matthieu casteta7a0c9c2006-10-03 21:44:11 +020075#define EAGLEUSBVERSION "ueagle 1.4"
matthieu castetb72458a2005-11-07 23:27:13 +010076
77
78/*
79 * Debug macros
80 */
81#define uea_dbg(usb_dev, format, args...) \
82 do { \
83 if (debug >= 1) \
84 dev_dbg(&(usb_dev)->dev, \
85 "[ueagle-atm dbg] %s: " format, \
Harvey Harrison441b62c2008-03-03 16:08:34 -080086 __func__, ##args); \
matthieu casteta7a0c9c2006-10-03 21:44:11 +020087 } while (0)
matthieu castetb72458a2005-11-07 23:27:13 +010088
89#define uea_vdbg(usb_dev, format, args...) \
90 do { \
91 if (debug >= 2) \
92 dev_dbg(&(usb_dev)->dev, \
93 "[ueagle-atm vdbg] " format, ##args); \
matthieu casteta7a0c9c2006-10-03 21:44:11 +020094 } while (0)
matthieu castetb72458a2005-11-07 23:27:13 +010095
96#define uea_enters(usb_dev) \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +020097 uea_vdbg(usb_dev, "entering %s\n" , __func__)
matthieu castetb72458a2005-11-07 23:27:13 +010098
99#define uea_leaves(usb_dev) \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200100 uea_vdbg(usb_dev, "leaving %s\n" , __func__)
matthieu castetb72458a2005-11-07 23:27:13 +0100101
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200102#define uea_err(usb_dev, format, args...) \
103 dev_err(&(usb_dev)->dev , "[UEAGLE-ATM] " format , ##args)
matthieu castetb72458a2005-11-07 23:27:13 +0100104
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200105#define uea_warn(usb_dev, format, args...) \
106 dev_warn(&(usb_dev)->dev , "[Ueagle-atm] " format, ##args)
matthieu castetb72458a2005-11-07 23:27:13 +0100107
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200108#define uea_info(usb_dev, format, args...) \
109 dev_info(&(usb_dev)->dev , "[ueagle-atm] " format, ##args)
matthieu castetb72458a2005-11-07 23:27:13 +0100110
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200111struct intr_pkt;
112
113/* cmv's from firmware */
114struct uea_cmvs_v1 {
matthieu castetb72458a2005-11-07 23:27:13 +0100115 u32 address;
116 u16 offset;
117 u32 data;
Chris Forbes58607302011-07-03 11:53:33 +1200118} __packed;
matthieu castetb72458a2005-11-07 23:27:13 +0100119
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200120struct uea_cmvs_v2 {
121 u32 group;
122 u32 address;
123 u32 offset;
124 u32 data;
Chris Forbes58607302011-07-03 11:53:33 +1200125} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200126
127/* information about currently processed cmv */
128struct cmv_dsc_e1 {
129 u8 function;
130 u16 idx;
131 u32 address;
132 u16 offset;
133};
134
135struct cmv_dsc_e4 {
136 u16 function;
137 u16 offset;
138 u16 address;
139 u16 group;
140};
141
142union cmv_dsc {
143 struct cmv_dsc_e1 e1;
144 struct cmv_dsc_e4 e4;
145};
146
matthieu castetb72458a2005-11-07 23:27:13 +0100147struct uea_softc {
148 struct usb_device *usb_dev;
149 struct usbatm_data *usbatm;
150
151 int modem_index;
152 unsigned int driver_info;
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200153 int annex;
154#define ANNEXA 0
155#define ANNEXB 1
matthieu castetb72458a2005-11-07 23:27:13 +0100156
157 int booting;
158 int reset;
159
160 wait_queue_head_t sync_q;
161
162 struct task_struct *kthread;
163 u32 data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200164 u32 data1;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200165
matthieu castetb72458a2005-11-07 23:27:13 +0100166 int cmv_ack;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200167 union cmv_dsc cmv_dsc;
matthieu castetb72458a2005-11-07 23:27:13 +0100168
169 struct work_struct task;
170 u16 pageno;
171 u16 ovl;
172
173 const struct firmware *dsp_firm;
174 struct urb *urb_int;
175
Sandhya Bankar62b5c802016-04-24 12:00:40 +0530176 void (*dispatch_cmv)(struct uea_softc *, struct intr_pkt *);
177 void (*schedule_load_page)(struct uea_softc *, struct intr_pkt *);
178 int (*stat)(struct uea_softc *);
179 int (*send_cmvs)(struct uea_softc *);
matthieu castetb72458a2005-11-07 23:27:13 +0100180
181 /* keep in sync with eaglectl */
182 struct uea_stats {
183 struct {
184 u32 state;
185 u32 flags;
186 u32 mflags;
187 u32 vidcpe;
188 u32 vidco;
189 u32 dsrate;
190 u32 usrate;
191 u32 dsunc;
192 u32 usunc;
193 u32 dscorr;
194 u32 uscorr;
195 u32 txflow;
196 u32 rxflow;
197 u32 usattenuation;
198 u32 dsattenuation;
199 u32 dsmargin;
200 u32 usmargin;
201 u32 firmid;
202 } phy;
203 } stats;
204};
205
206/*
207 * Elsa IDs
208 */
209#define ELSA_VID 0x05CC
210#define ELSA_PID_PSTFIRM 0x3350
211#define ELSA_PID_PREFIRM 0x3351
212
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200213#define ELSA_PID_A_PREFIRM 0x3352
214#define ELSA_PID_A_PSTFIRM 0x3353
215#define ELSA_PID_B_PREFIRM 0x3362
216#define ELSA_PID_B_PSTFIRM 0x3363
217
matthieu castetb72458a2005-11-07 23:27:13 +0100218/*
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200219 * Devolo IDs : pots if (pid & 0x10)
matthieu castetb72458a2005-11-07 23:27:13 +0100220 */
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200221#define DEVOLO_VID 0x1039
222#define DEVOLO_EAGLE_I_A_PID_PSTFIRM 0x2110
223#define DEVOLO_EAGLE_I_A_PID_PREFIRM 0x2111
224
225#define DEVOLO_EAGLE_I_B_PID_PSTFIRM 0x2100
226#define DEVOLO_EAGLE_I_B_PID_PREFIRM 0x2101
227
228#define DEVOLO_EAGLE_II_A_PID_PSTFIRM 0x2130
229#define DEVOLO_EAGLE_II_A_PID_PREFIRM 0x2131
230
231#define DEVOLO_EAGLE_II_B_PID_PSTFIRM 0x2120
232#define DEVOLO_EAGLE_II_B_PID_PREFIRM 0x2121
233
234/*
235 * Reference design USB IDs
236 */
237#define ANALOG_VID 0x1110
238#define ADI930_PID_PREFIRM 0x9001
239#define ADI930_PID_PSTFIRM 0x9000
240
matthieu castetb72458a2005-11-07 23:27:13 +0100241#define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
242#define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
243
244#define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
245#define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
246
247#define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
248#define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
249
matthieu castetb72458a2005-11-07 23:27:13 +0100250#define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
251#define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
252
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200253#define EAGLE_IV_PID_PREFIRM 0x9042 /* Eagle IV */
254#define EAGLE_IV_PID_PSTFIRM 0x9041 /* Eagle IV */
255
matthieu castetb72458a2005-11-07 23:27:13 +0100256/*
257 * USR USB IDs
258 */
259#define USR_VID 0x0BAF
260#define MILLER_A_PID_PREFIRM 0x00F2
261#define MILLER_A_PID_PSTFIRM 0x00F1
262#define MILLER_B_PID_PREFIRM 0x00FA
263#define MILLER_B_PID_PSTFIRM 0x00F9
264#define HEINEKEN_A_PID_PREFIRM 0x00F6
265#define HEINEKEN_A_PID_PSTFIRM 0x00F5
266#define HEINEKEN_B_PID_PREFIRM 0x00F8
267#define HEINEKEN_B_PID_PSTFIRM 0x00F7
268
269#define PREFIRM 0
270#define PSTFIRM (1<<7)
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200271#define AUTO_ANNEX_A (1<<8)
272#define AUTO_ANNEX_B (1<<9)
273
matthieu castetb72458a2005-11-07 23:27:13 +0100274enum {
275 ADI930 = 0,
276 EAGLE_I,
277 EAGLE_II,
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200278 EAGLE_III,
279 EAGLE_IV
matthieu castetb72458a2005-11-07 23:27:13 +0100280};
281
282/* macros for both struct usb_device_id and struct uea_softc */
283#define UEA_IS_PREFIRM(x) \
284 (!((x)->driver_info & PSTFIRM))
285#define UEA_CHIP_VERSION(x) \
286 ((x)->driver_info & 0xf)
287
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200288#define IS_ISDN(x) \
289 ((x)->annex & ANNEXB)
matthieu castetb72458a2005-11-07 23:27:13 +0100290
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200291#define INS_TO_USBDEV(ins) (ins->usb_dev)
matthieu castetb72458a2005-11-07 23:27:13 +0100292
293#define GET_STATUS(data) \
294 ((data >> 8) & 0xf)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200295
matthieu castetb72458a2005-11-07 23:27:13 +0100296#define IS_OPERATIONAL(sc) \
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200297 ((UEA_CHIP_VERSION(sc) != EAGLE_IV) ? \
298 (GET_STATUS(sc->stats.phy.state) == 2) : \
299 (sc->stats.phy.state == 7))
matthieu castetb72458a2005-11-07 23:27:13 +0100300
301/*
302 * Set of macros to handle unaligned data in the firmware blob.
303 * The FW_GET_BYTE() macro is provided only for consistency.
304 */
305
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200306#define FW_GET_BYTE(p) (*((__u8 *) (p)))
matthieu castetb72458a2005-11-07 23:27:13 +0100307
308#define FW_DIR "ueagle-atm/"
Tim Gardner47282502012-07-25 14:32:50 -0600309#define EAGLE_FIRMWARE FW_DIR "eagle.fw"
310#define ADI930_FIRMWARE FW_DIR "adi930.fw"
311#define EAGLE_I_FIRMWARE FW_DIR "eagleI.fw"
312#define EAGLE_II_FIRMWARE FW_DIR "eagleII.fw"
313#define EAGLE_III_FIRMWARE FW_DIR "eagleIII.fw"
314#define EAGLE_IV_FIRMWARE FW_DIR "eagleIV.fw"
315
316#define DSP4I_FIRMWARE FW_DIR "DSP4i.bin"
317#define DSP4P_FIRMWARE FW_DIR "DSP4p.bin"
318#define DSP9I_FIRMWARE FW_DIR "DSP9i.bin"
319#define DSP9P_FIRMWARE FW_DIR "DSP9p.bin"
320#define DSPEI_FIRMWARE FW_DIR "DSPei.bin"
321#define DSPEP_FIRMWARE FW_DIR "DSPep.bin"
322#define FPGA930_FIRMWARE FW_DIR "930-fpga.bin"
323
324#define CMV4P_FIRMWARE FW_DIR "CMV4p.bin"
325#define CMV4PV2_FIRMWARE FW_DIR "CMV4p.bin.v2"
326#define CMV4I_FIRMWARE FW_DIR "CMV4i.bin"
327#define CMV4IV2_FIRMWARE FW_DIR "CMV4i.bin.v2"
328#define CMV9P_FIRMWARE FW_DIR "CMV9p.bin"
329#define CMV9PV2_FIRMWARE FW_DIR "CMV9p.bin.v2"
330#define CMV9I_FIRMWARE FW_DIR "CMV9i.bin"
331#define CMV9IV2_FIRMWARE FW_DIR "CMV9i.bin.v2"
332#define CMVEP_FIRMWARE FW_DIR "CMVep.bin"
333#define CMVEPV2_FIRMWARE FW_DIR "CMVep.bin.v2"
334#define CMVEI_FIRMWARE FW_DIR "CMVei.bin"
335#define CMVEIV2_FIRMWARE FW_DIR "CMVei.bin.v2"
336
Samuel Ortizade901d2009-05-27 00:49:32 +0200337#define UEA_FW_NAME_MAX 30
matthieu castetb72458a2005-11-07 23:27:13 +0100338#define NB_MODEM 4
339
340#define BULK_TIMEOUT 300
341#define CTRL_TIMEOUT 1000
342
matthieu castet22fcceb2006-04-02 18:44:20 +0200343#define ACK_TIMEOUT msecs_to_jiffies(3000)
matthieu castetb72458a2005-11-07 23:27:13 +0100344
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200345#define UEA_INTR_IFACE_NO 0
matthieu castetb72458a2005-11-07 23:27:13 +0100346#define UEA_US_IFACE_NO 1
347#define UEA_DS_IFACE_NO 2
348
349#define FASTEST_ISO_INTF 8
350
351#define UEA_BULK_DATA_PIPE 0x02
352#define UEA_IDMA_PIPE 0x04
353#define UEA_INTR_PIPE 0x04
354#define UEA_ISO_DATA_PIPE 0x08
355
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200356#define UEA_E1_SET_BLOCK 0x0001
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200357#define UEA_E4_SET_BLOCK 0x002c
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200358#define UEA_SET_MODE 0x0003
matthieu castetb72458a2005-11-07 23:27:13 +0100359#define UEA_SET_2183_DATA 0x0004
360#define UEA_SET_TIMEOUT 0x0011
361
362#define UEA_LOOPBACK_OFF 0x0002
363#define UEA_LOOPBACK_ON 0x0003
364#define UEA_BOOT_IDMA 0x0006
365#define UEA_START_RESET 0x0007
366#define UEA_END_RESET 0x0008
367
368#define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
369#define UEA_MPTX_START (0x3fce | 0x4000)
370#define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
371#define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
372
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200373/* block information in eagle4 dsp firmware */
374struct block_index {
375 __le32 PageOffset;
376 __le32 NotLastBlock;
377 __le32 dummy;
378 __le32 PageSize;
379 __le32 PageAddress;
380 __le16 dummy1;
381 __le16 PageNumber;
Chris Forbes58607302011-07-03 11:53:33 +1200382} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200383
384#define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000)
385#define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4)
386
387#define E4_L1_STRING_HEADER 0x10
388#define E4_MAX_PAGE_NUMBER 0x58
389#define E4_NO_SWAPPAGE_HEADERS 0x31
390
391/* l1_code is eagle4 dsp firmware format */
392struct l1_code {
393 u8 string_header[E4_L1_STRING_HEADER];
394 u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER];
395 struct block_index page_header[E4_NO_SWAPPAGE_HEADERS];
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200396 u8 code[0];
Chris Forbes58607302011-07-03 11:53:33 +1200397} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200398
399/* structures describing a block within a DSP page */
400struct block_info_e1 {
matthieu castetb72458a2005-11-07 23:27:13 +0100401 __le16 wHdr;
matthieu castetb72458a2005-11-07 23:27:13 +0100402 __le16 wAddress;
403 __le16 wSize;
404 __le16 wOvlOffset;
405 __le16 wOvl; /* overlay */
406 __le16 wLast;
Chris Forbes58607302011-07-03 11:53:33 +1200407} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200408#define E1_BLOCK_INFO_SIZE 12
matthieu castetb72458a2005-11-07 23:27:13 +0100409
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200410struct block_info_e4 {
411 __be16 wHdr;
412 __u8 bBootPage;
413 __u8 bPageNumber;
414 __be32 dwSize;
415 __be32 dwAddress;
416 __be16 wReserved;
Chris Forbes58607302011-07-03 11:53:33 +1200417} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200418#define E4_BLOCK_INFO_SIZE 14
matthieu castetb72458a2005-11-07 23:27:13 +0100419
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200420#define UEA_BIHDR 0xabcd
421#define UEA_RESERVED 0xffff
422
423/* constants describing cmv type */
424#define E1_PREAMBLE 0x535c
425#define E1_MODEMTOHOST 0x01
426#define E1_HOSTTOMODEM 0x10
427
428#define E1_MEMACCESS 0x1
429#define E1_ADSLDIRECTIVE 0x7
430#define E1_FUNCTION_TYPE(f) ((f) >> 4)
431#define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f)
432
433#define E4_MEMACCESS 0
434#define E4_ADSLDIRECTIVE 0xf
435#define E4_FUNCTION_TYPE(f) ((f) >> 8)
436#define E4_FUNCTION_SIZE(f) ((f) & 0x0f)
437#define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f)
438
matthieu castetb72458a2005-11-07 23:27:13 +0100439/* for MEMACCESS */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200440#define E1_REQUESTREAD 0x0
441#define E1_REQUESTWRITE 0x1
442#define E1_REPLYREAD 0x2
443#define E1_REPLYWRITE 0x3
matthieu castetb72458a2005-11-07 23:27:13 +0100444
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200445#define E4_REQUESTREAD 0x0
446#define E4_REQUESTWRITE 0x4
447#define E4_REPLYREAD (E4_REQUESTREAD | 1)
448#define E4_REPLYWRITE (E4_REQUESTWRITE | 1)
449
450/* for ADSLDIRECTIVE */
451#define E1_KERNELREADY 0x0
452#define E1_MODEMREADY 0x1
453
454#define E4_KERNELREADY 0x0
455#define E4_MODEMREADY 0x1
456
457#define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200458#define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | \
459 ((st) & 0xf) << 4 | ((s) & 0xf))
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200460
461#define E1_MAKESA(a, b, c, d) \
matthieu castetb72458a2005-11-07 23:27:13 +0100462 (((c) & 0xff) << 24 | \
463 ((d) & 0xff) << 16 | \
464 ((a) & 0xff) << 8 | \
465 ((b) & 0xff))
466
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200467#define E1_GETSA1(a) ((a >> 8) & 0xff)
468#define E1_GETSA2(a) (a & 0xff)
469#define E1_GETSA3(a) ((a >> 24) & 0xff)
470#define E1_GETSA4(a) ((a >> 16) & 0xff)
471
472#define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L')
473#define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G')
474#define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O')
475#define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N')
476#define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E')
477#define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T')
478
479#define E4_SA_CNTL 1
480#define E4_SA_STAT 2
481#define E4_SA_INFO 3
482#define E4_SA_TEST 4
483#define E4_SA_OPTN 5
484#define E4_SA_RATE 6
485#define E4_SA_DIAG 7
486#define E4_SA_CNFG 8
487
488/* structures representing a CMV (Configuration and Management Variable) */
489struct cmv_e1 {
490 __le16 wPreamble;
491 __u8 bDirection;
492 __u8 bFunction;
493 __le16 wIndex;
494 __le32 dwSymbolicAddress;
matthieu castetb72458a2005-11-07 23:27:13 +0100495 __le16 wOffsetAddress;
496 __le32 dwData;
Chris Forbes58607302011-07-03 11:53:33 +1200497} __packed;
matthieu castetb72458a2005-11-07 23:27:13 +0100498
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200499struct cmv_e4 {
500 __be16 wGroup;
501 __be16 wFunction;
502 __be16 wOffset;
503 __be16 wAddress;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200504 __be32 dwData[6];
Chris Forbes58607302011-07-03 11:53:33 +1200505} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200506
507/* structures representing swap information */
508struct swap_info_e1 {
matthieu castetb72458a2005-11-07 23:27:13 +0100509 __u8 bSwapPageNo;
510 __u8 bOvl; /* overlay */
Chris Forbes58607302011-07-03 11:53:33 +1200511} __packed;
matthieu castetb72458a2005-11-07 23:27:13 +0100512
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200513struct swap_info_e4 {
514 __u8 bSwapPageNo;
Chris Forbes58607302011-07-03 11:53:33 +1200515} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200516
517/* structures representing interrupt data */
518#define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo
519#define e1_bOvl u.e1.s1.swapinfo.bOvl
520#define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo
521
522#define INT_LOADSWAPPAGE 0x0001
523#define INT_INCOMINGCMV 0x0002
524
525union intr_data_e1 {
526 struct {
527 struct swap_info_e1 swapinfo;
528 __le16 wDataSize;
Chris Forbes58607302011-07-03 11:53:33 +1200529 } __packed s1;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200530 struct {
531 struct cmv_e1 cmv;
532 __le16 wDataSize;
Chris Forbes58607302011-07-03 11:53:33 +1200533 } __packed s2;
534} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200535
536union intr_data_e4 {
537 struct {
538 struct swap_info_e4 swapinfo;
539 __le16 wDataSize;
Chris Forbes58607302011-07-03 11:53:33 +1200540 } __packed s1;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200541 struct {
542 struct cmv_e4 cmv;
543 __le16 wDataSize;
Chris Forbes58607302011-07-03 11:53:33 +1200544 } __packed s2;
545} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200546
matthieu castetb72458a2005-11-07 23:27:13 +0100547struct intr_pkt {
548 __u8 bType;
549 __u8 bNotification;
550 __le16 wValue;
551 __le16 wIndex;
552 __le16 wLength;
553 __le16 wInterrupt;
matthieu castetb72458a2005-11-07 23:27:13 +0100554 union {
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200555 union intr_data_e1 e1;
556 union intr_data_e4 e4;
557 } u;
Chris Forbes58607302011-07-03 11:53:33 +1200558} __packed;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200559
560#define E1_INTR_PKT_SIZE 28
561#define E4_INTR_PKT_SIZE 64
matthieu castetb72458a2005-11-07 23:27:13 +0100562
563static struct usb_driver uea_driver;
Arjan van de Venab3c81f2006-01-13 15:52:55 +0100564static DEFINE_MUTEX(uea_mutex);
Chris Forbes6f95b4b2011-07-03 11:53:34 +1200565static const char * const chip_name[] = {
566 "ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"};
matthieu castetb72458a2005-11-07 23:27:13 +0100567
568static int modem_index;
569static unsigned int debug;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200570static unsigned int altsetting[NB_MODEM] = {
571 [0 ... (NB_MODEM - 1)] = FASTEST_ISO_INTF};
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030572static bool sync_wait[NB_MODEM];
matthieu castetb72458a2005-11-07 23:27:13 +0100573static char *cmv_file[NB_MODEM];
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200574static int annex[NB_MODEM];
matthieu castetb72458a2005-11-07 23:27:13 +0100575
576module_param(debug, uint, 0644);
577MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
Stanislaw Gruszka503add42007-08-20 23:21:06 +0200578module_param_array(altsetting, uint, NULL, 0644);
579MODULE_PARM_DESC(altsetting, "alternate setting for incoming traffic: 0=bulk, "
580 "1=isoc slowest, ... , 8=isoc fastest (default)");
matthieu castetb72458a2005-11-07 23:27:13 +0100581module_param_array(sync_wait, bool, NULL, 0644);
582MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
583module_param_array(cmv_file, charp, NULL, 0644);
584MODULE_PARM_DESC(cmv_file,
585 "file name with configuration and management variables");
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200586module_param_array(annex, uint, NULL, 0644);
587MODULE_PARM_DESC(annex,
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200588 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
matthieu castetb72458a2005-11-07 23:27:13 +0100589
Stanislaw Gruszka337427f2007-08-20 23:21:14 +0200590#define uea_wait(sc, cond, timeo) \
591({ \
592 int _r = wait_event_interruptible_timeout(sc->sync_q, \
593 (cond) || kthread_should_stop(), timeo); \
594 if (kthread_should_stop()) \
595 _r = -ENODEV; \
596 _r; \
597})
598
matthieu castetb72458a2005-11-07 23:27:13 +0100599#define UPDATE_ATM_STAT(type, val) \
600 do { \
601 if (sc->usbatm->atm_dev) \
602 sc->usbatm->atm_dev->type = val; \
603 } while (0)
604
Karl Hiramotocc7b86c2010-07-08 20:55:38 +0000605#define UPDATE_ATM_SIGNAL(val) \
606 do { \
607 if (sc->usbatm->atm_dev) \
608 atm_dev_signal_change(sc->usbatm->atm_dev, val); \
609 } while (0)
610
611
matthieu castetb72458a2005-11-07 23:27:13 +0100612/* Firmware loading */
613#define LOAD_INTERNAL 0xA0
614#define F8051_USBCS 0x7f92
615
616/**
617 * uea_send_modem_cmd - Send a command for pre-firmware devices.
618 */
619static int uea_send_modem_cmd(struct usb_device *usb,
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100620 u16 addr, u16 size, const u8 *buff)
matthieu castetb72458a2005-11-07 23:27:13 +0100621{
622 int ret = -ENOMEM;
623 u8 *xfer_buff;
624
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +0200625 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +0100626 if (xfer_buff) {
matthieu castetb72458a2005-11-07 23:27:13 +0100627 ret = usb_control_msg(usb,
628 usb_sndctrlpipe(usb, 0),
629 LOAD_INTERNAL,
630 USB_DIR_OUT | USB_TYPE_VENDOR |
631 USB_RECIP_DEVICE, addr, 0, xfer_buff,
632 size, CTRL_TIMEOUT);
633 kfree(xfer_buff);
634 }
635
636 if (ret < 0)
637 return ret;
638
639 return (ret == size) ? 0 : -EIO;
640}
641
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200642static void uea_upload_pre_firmware(const struct firmware *fw_entry,
643 void *context)
matthieu castetb72458a2005-11-07 23:27:13 +0100644{
645 struct usb_device *usb = context;
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100646 const u8 *pfw;
647 u8 value;
matthieu castetb72458a2005-11-07 23:27:13 +0100648 u32 crc = 0;
649 int ret, size;
650
651 uea_enters(usb);
652 if (!fw_entry) {
653 uea_err(usb, "firmware is not available\n");
654 goto err;
655 }
656
657 pfw = fw_entry->data;
658 size = fw_entry->size;
matthieu castet8d7802e2005-11-08 00:02:30 +0100659 if (size < 4)
660 goto err_fw_corrupted;
matthieu castetb72458a2005-11-07 23:27:13 +0100661
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700662 crc = get_unaligned_le32(pfw);
matthieu castetb72458a2005-11-07 23:27:13 +0100663 pfw += 4;
664 size -= 4;
matthieu castet8d7802e2005-11-08 00:02:30 +0100665 if (crc32_be(0, pfw, size) != crc)
666 goto err_fw_corrupted;
matthieu castetb72458a2005-11-07 23:27:13 +0100667
668 /*
Nick Andrew877d0312009-01-26 11:06:57 +0100669 * Start to upload firmware : send reset
matthieu castetb72458a2005-11-07 23:27:13 +0100670 */
671 value = 1;
672 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
673
674 if (ret < 0) {
675 uea_err(usb, "modem reset failed with error %d\n", ret);
676 goto err;
677 }
678
matthieu castet8d7802e2005-11-08 00:02:30 +0100679 while (size > 3) {
matthieu castetb72458a2005-11-07 23:27:13 +0100680 u8 len = FW_GET_BYTE(pfw);
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700681 u16 add = get_unaligned_le16(pfw + 1);
matthieu castet8d7802e2005-11-08 00:02:30 +0100682
683 size -= len + 3;
684 if (size < 0)
685 goto err_fw_corrupted;
686
matthieu castetb72458a2005-11-07 23:27:13 +0100687 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
688 if (ret < 0) {
689 uea_err(usb, "uploading firmware data failed "
690 "with error %d\n", ret);
691 goto err;
692 }
693 pfw += len + 3;
matthieu castetb72458a2005-11-07 23:27:13 +0100694 }
695
matthieu castet8d7802e2005-11-08 00:02:30 +0100696 if (size != 0)
697 goto err_fw_corrupted;
698
matthieu castetb72458a2005-11-07 23:27:13 +0100699 /*
700 * Tell the modem we finish : de-assert reset
701 */
702 value = 0;
703 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
704 if (ret < 0)
705 uea_err(usb, "modem de-assert failed with error %d\n", ret);
706 else
707 uea_info(usb, "firmware uploaded\n");
708
Johannes Berg9ebfbd42009-10-29 12:36:02 +0100709 goto err;
matthieu castet8d7802e2005-11-08 00:02:30 +0100710
711err_fw_corrupted:
712 uea_err(usb, "firmware is corrupted\n");
matthieu castetb72458a2005-11-07 23:27:13 +0100713err:
Johannes Berg9ebfbd42009-10-29 12:36:02 +0100714 release_firmware(fw_entry);
matthieu castetb72458a2005-11-07 23:27:13 +0100715 uea_leaves(usb);
716}
717
718/**
719 * uea_load_firmware - Load usb firmware for pre-firmware devices.
720 */
721static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
722{
723 int ret;
Tim Gardner47282502012-07-25 14:32:50 -0600724 char *fw_name = EAGLE_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100725
726 uea_enters(usb);
727 uea_info(usb, "pre-firmware device, uploading firmware\n");
728
729 switch (ver) {
730 case ADI930:
Tim Gardner47282502012-07-25 14:32:50 -0600731 fw_name = ADI930_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100732 break;
733 case EAGLE_I:
Tim Gardner47282502012-07-25 14:32:50 -0600734 fw_name = EAGLE_I_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100735 break;
736 case EAGLE_II:
Tim Gardner47282502012-07-25 14:32:50 -0600737 fw_name = EAGLE_II_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100738 break;
739 case EAGLE_III:
Tim Gardner47282502012-07-25 14:32:50 -0600740 fw_name = EAGLE_III_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100741 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200742 case EAGLE_IV:
Tim Gardner47282502012-07-25 14:32:50 -0600743 fw_name = EAGLE_IV_FIRMWARE;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200744 break;
matthieu castetb72458a2005-11-07 23:27:13 +0100745 }
746
Johannes Berg9ebfbd42009-10-29 12:36:02 +0100747 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev,
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200748 GFP_KERNEL, usb,
749 uea_upload_pre_firmware);
matthieu castetb72458a2005-11-07 23:27:13 +0100750 if (ret)
751 uea_err(usb, "firmware %s is not available\n", fw_name);
752 else
753 uea_info(usb, "loading firmware %s\n", fw_name);
754
755 uea_leaves(usb);
756 return ret;
757}
758
759/* modem management : dsp firmware, send/read CMV, monitoring statistic
760 */
761
762/*
763 * Make sure that the DSP code provided is safe to use.
764 */
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100765static int check_dsp_e1(const u8 *dsp, unsigned int len)
matthieu castetb72458a2005-11-07 23:27:13 +0100766{
767 u8 pagecount, blockcount;
768 u16 blocksize;
769 u32 pageoffset;
770 unsigned int i, j, p, pp;
771
matthieu castetb72458a2005-11-07 23:27:13 +0100772 pagecount = FW_GET_BYTE(dsp);
773 p = 1;
774
775 /* enough space for page offsets? */
776 if (p + 4 * pagecount > len)
777 return 1;
778
779 for (i = 0; i < pagecount; i++) {
780
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700781 pageoffset = get_unaligned_le32(dsp + p);
matthieu castetb72458a2005-11-07 23:27:13 +0100782 p += 4;
783
784 if (pageoffset == 0)
785 continue;
786
787 /* enough space for blockcount? */
788 if (pageoffset >= len)
789 return 1;
790
791 pp = pageoffset;
792 blockcount = FW_GET_BYTE(dsp + pp);
793 pp += 1;
794
795 for (j = 0; j < blockcount; j++) {
796
797 /* enough space for block header? */
798 if (pp + 4 > len)
799 return 1;
800
801 pp += 2; /* skip blockaddr */
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700802 blocksize = get_unaligned_le16(dsp + pp);
matthieu castetb72458a2005-11-07 23:27:13 +0100803 pp += 2;
804
805 /* enough space for block data? */
806 if (pp + blocksize > len)
807 return 1;
808
809 pp += blocksize;
810 }
811 }
812
813 return 0;
814}
815
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100816static int check_dsp_e4(const u8 *dsp, int len)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200817{
818 int i;
819 struct l1_code *p = (struct l1_code *) dsp;
820 unsigned int sum = p->code - dsp;
821
822 if (len < sum)
823 return 1;
824
825 if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 &&
826 strcmp("STRATIPHY ANEXB", p->string_header) != 0)
827 return 1;
828
829 for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) {
830 struct block_index *blockidx;
831 u8 blockno = p->page_number_to_block_index[i];
832 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
833 continue;
834
835 do {
836 u64 l;
837
838 if (blockno >= E4_NO_SWAPPAGE_HEADERS)
839 return 1;
840
841 blockidx = &p->page_header[blockno++];
842 if ((u8 *)(blockidx + 1) - dsp >= len)
843 return 1;
844
845 if (le16_to_cpu(blockidx->PageNumber) != i)
846 return 1;
847
848 l = E4_PAGE_BYTES(blockidx->PageSize);
849 sum += l;
850 l += le32_to_cpu(blockidx->PageOffset);
851 if (l > len)
852 return 1;
853
854 /* zero is zero regardless endianes */
855 } while (blockidx->NotLastBlock);
856 }
857
858 return (sum == len) ? 0 : 1;
859}
860
matthieu castetb72458a2005-11-07 23:27:13 +0100861/*
862 * send data to the idma pipe
863 * */
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100864static int uea_idma_write(struct uea_softc *sc, const void *data, u32 size)
matthieu castetb72458a2005-11-07 23:27:13 +0100865{
866 int ret = -ENOMEM;
867 u8 *xfer_buff;
868 int bytes_read;
869
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +0200870 xfer_buff = kmemdup(data, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +0100871 if (!xfer_buff) {
872 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
873 return ret;
874 }
875
matthieu castetb72458a2005-11-07 23:27:13 +0100876 ret = usb_bulk_msg(sc->usb_dev,
877 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
878 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
879
880 kfree(xfer_buff);
881 if (ret < 0)
882 return ret;
883 if (size != bytes_read) {
884 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
885 bytes_read);
886 return -EIO;
887 }
888
889 return 0;
890}
891
892static int request_dsp(struct uea_softc *sc)
893{
894 int ret;
895 char *dsp_name;
896
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200897 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200898 if (IS_ISDN(sc))
Tim Gardner47282502012-07-25 14:32:50 -0600899 dsp_name = DSP4I_FIRMWARE;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200900 else
Tim Gardner47282502012-07-25 14:32:50 -0600901 dsp_name = DSP4P_FIRMWARE;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200902 } else if (UEA_CHIP_VERSION(sc) == ADI930) {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200903 if (IS_ISDN(sc))
Tim Gardner47282502012-07-25 14:32:50 -0600904 dsp_name = DSP9I_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100905 else
Tim Gardner47282502012-07-25 14:32:50 -0600906 dsp_name = DSP9P_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100907 } else {
Stanislaw Gruszka603cf602007-08-20 23:21:01 +0200908 if (IS_ISDN(sc))
Tim Gardner47282502012-07-25 14:32:50 -0600909 dsp_name = DSPEI_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100910 else
Tim Gardner47282502012-07-25 14:32:50 -0600911 dsp_name = DSPEP_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +0100912 }
913
matthieu castete40abaf2006-01-18 07:38:37 +0100914 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
matthieu castetb72458a2005-11-07 23:27:13 +0100915 if (ret < 0) {
916 uea_err(INS_TO_USBDEV(sc),
917 "requesting firmware %s failed with error %d\n",
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +0200918 dsp_name, ret);
matthieu castetb72458a2005-11-07 23:27:13 +0100919 return ret;
920 }
921
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200922 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
923 ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size);
924 else
925 ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size);
926
927 if (ret) {
matthieu castetb72458a2005-11-07 23:27:13 +0100928 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
929 dsp_name);
930 release_firmware(sc->dsp_firm);
931 sc->dsp_firm = NULL;
932 return -EILSEQ;
933 }
934
935 return 0;
936}
937
938/*
939 * The uea_load_page() function must be called within a process context
940 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200941static void uea_load_page_e1(struct work_struct *work)
matthieu castetb72458a2005-11-07 23:27:13 +0100942{
David Howellsc4028952006-11-22 14:57:56 +0000943 struct uea_softc *sc = container_of(work, struct uea_softc, task);
matthieu castetb72458a2005-11-07 23:27:13 +0100944 u16 pageno = sc->pageno;
945 u16 ovl = sc->ovl;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200946 struct block_info_e1 bi;
matthieu castetb72458a2005-11-07 23:27:13 +0100947
David Woodhouseaafcd2f2008-05-24 00:05:10 +0100948 const u8 *p;
matthieu castetb72458a2005-11-07 23:27:13 +0100949 u8 pagecount, blockcount;
950 u16 blockaddr, blocksize;
951 u32 pageoffset;
952 int i;
953
954 /* reload firmware when reboot start and it's loaded already */
Markus Elfring533726f2015-02-05 16:33:09 +0100955 if (ovl == 0 && pageno == 0) {
matthieu castetb72458a2005-11-07 23:27:13 +0100956 release_firmware(sc->dsp_firm);
957 sc->dsp_firm = NULL;
958 }
959
960 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
961 return;
962
963 p = sc->dsp_firm->data;
964 pagecount = FW_GET_BYTE(p);
965 p += 1;
966
967 if (pageno >= pagecount)
968 goto bad1;
969
970 p += 4 * pageno;
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700971 pageoffset = get_unaligned_le32(p);
matthieu castetb72458a2005-11-07 23:27:13 +0100972
973 if (pageoffset == 0)
974 goto bad1;
975
976 p = sc->dsp_firm->data + pageoffset;
977 blockcount = FW_GET_BYTE(p);
978 p += 1;
979
980 uea_dbg(INS_TO_USBDEV(sc),
981 "sending %u blocks for DSP page %u\n", blockcount, pageno);
982
983 bi.wHdr = cpu_to_le16(UEA_BIHDR);
984 bi.wOvl = cpu_to_le16(ovl);
985 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
986
987 for (i = 0; i < blockcount; i++) {
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700988 blockaddr = get_unaligned_le16(p);
matthieu castetb72458a2005-11-07 23:27:13 +0100989 p += 2;
990
Harvey Harrisona5abdea2008-04-29 01:03:40 -0700991 blocksize = get_unaligned_le16(p);
matthieu castetb72458a2005-11-07 23:27:13 +0100992 p += 2;
993
994 bi.wSize = cpu_to_le16(blocksize);
995 bi.wAddress = cpu_to_le16(blockaddr);
996 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
997
998 /* send block info through the IDMA pipe */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +0200999 if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE))
matthieu castetb72458a2005-11-07 23:27:13 +01001000 goto bad2;
1001
1002 /* send block data through the IDMA pipe */
1003 if (uea_idma_write(sc, p, blocksize))
1004 goto bad2;
1005
1006 p += blocksize;
1007 }
1008
1009 return;
1010
1011bad2:
1012 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
1013 return;
1014bad1:
matthieu castet2a99b502006-04-02 18:43:53 +02001015 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
matthieu castetb72458a2005-11-07 23:27:13 +01001016}
1017
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001018static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
1019{
1020 struct block_info_e4 bi;
1021 struct block_index *blockidx;
1022 struct l1_code *p = (struct l1_code *) sc->dsp_firm->data;
1023 u8 blockno = p->page_number_to_block_index[pageno];
1024
1025 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1026 bi.bBootPage = boot;
1027 bi.bPageNumber = pageno;
1028 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1029
1030 do {
David Woodhouseaafcd2f2008-05-24 00:05:10 +01001031 const u8 *blockoffset;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001032 unsigned int blocksize;
1033
1034 blockidx = &p->page_header[blockno];
1035 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001036 blockoffset = sc->dsp_firm->data + le32_to_cpu(
1037 blockidx->PageOffset);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001038
1039 bi.dwSize = cpu_to_be32(blocksize);
Al Virofd05e722008-04-28 07:00:16 +01001040 bi.dwAddress = cpu_to_be32(le32_to_cpu(blockidx->PageAddress));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001041
1042 uea_dbg(INS_TO_USBDEV(sc),
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001043 "sending block %u for DSP page "
1044 "%u size %u address %x\n",
1045 blockno, pageno, blocksize,
1046 le32_to_cpu(blockidx->PageAddress));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001047
1048 /* send block info through the IDMA pipe */
1049 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1050 goto bad;
1051
1052 /* send block data through the IDMA pipe */
1053 if (uea_idma_write(sc, blockoffset, blocksize))
1054 goto bad;
1055
1056 blockno++;
1057 } while (blockidx->NotLastBlock);
1058
1059 return;
1060
1061bad:
1062 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno);
1063 return;
1064}
1065
1066static void uea_load_page_e4(struct work_struct *work)
1067{
1068 struct uea_softc *sc = container_of(work, struct uea_softc, task);
1069 u8 pageno = sc->pageno;
1070 int i;
1071 struct block_info_e4 bi;
1072 struct l1_code *p;
1073
1074 uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
1075
1076 /* reload firmware when reboot start and it's loaded already */
Markus Elfring533726f2015-02-05 16:33:09 +01001077 if (pageno == 0) {
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001078 release_firmware(sc->dsp_firm);
1079 sc->dsp_firm = NULL;
1080 }
1081
1082 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
1083 return;
1084
1085 p = (struct l1_code *) sc->dsp_firm->data;
Al Virofd05e722008-04-28 07:00:16 +01001086 if (pageno >= le16_to_cpu(p->page_header[0].PageNumber)) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001087 uea_err(INS_TO_USBDEV(sc), "invalid DSP "
1088 "page %u requested\n", pageno);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001089 return;
1090 }
1091
1092 if (pageno != 0) {
1093 __uea_load_page_e4(sc, pageno, 0);
1094 return;
1095 }
1096
1097 uea_dbg(INS_TO_USBDEV(sc),
1098 "sending Main DSP page %u\n", p->page_header[0].PageNumber);
1099
1100 for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) {
1101 if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize))
1102 __uea_load_page_e4(sc, i, 1);
1103 }
1104
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001105 uea_dbg(INS_TO_USBDEV(sc) , "sending start bi\n");
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001106
1107 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1108 bi.bBootPage = 0;
1109 bi.bPageNumber = 0xff;
1110 bi.wReserved = cpu_to_be16(UEA_RESERVED);
1111 bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize));
Al Virofd05e722008-04-28 07:00:16 +01001112 bi.dwAddress = cpu_to_be32(le32_to_cpu(p->page_header[0].PageAddress));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001113
1114 /* send block info through the IDMA pipe */
1115 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
1116 uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n");
1117}
1118
matthieu castetb72458a2005-11-07 23:27:13 +01001119static inline void wake_up_cmv_ack(struct uea_softc *sc)
1120{
matthieu castet2a99b502006-04-02 18:43:53 +02001121 BUG_ON(sc->cmv_ack);
matthieu castetb72458a2005-11-07 23:27:13 +01001122 sc->cmv_ack = 1;
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001123 wake_up(&sc->sync_q);
matthieu castetb72458a2005-11-07 23:27:13 +01001124}
1125
1126static inline int wait_cmv_ack(struct uea_softc *sc)
1127{
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001128 int ret = uea_wait(sc, sc->cmv_ack , ACK_TIMEOUT);
1129
matthieu castetb72458a2005-11-07 23:27:13 +01001130 sc->cmv_ack = 0;
1131
matthieu castet2a99b502006-04-02 18:43:53 +02001132 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
1133 jiffies_to_msecs(ret));
1134
matthieu castetb72458a2005-11-07 23:27:13 +01001135 if (ret < 0)
1136 return ret;
1137
1138 return (ret == 0) ? -ETIMEDOUT : 0;
matthieu castetb72458a2005-11-07 23:27:13 +01001139}
1140
1141#define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
1142
1143static int uea_request(struct uea_softc *sc,
David Woodhouseaafcd2f2008-05-24 00:05:10 +01001144 u16 value, u16 index, u16 size, const void *data)
matthieu castetb72458a2005-11-07 23:27:13 +01001145{
1146 u8 *xfer_buff;
1147 int ret = -ENOMEM;
1148
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +02001149 xfer_buff = kmemdup(data, size, GFP_KERNEL);
matthieu castetb72458a2005-11-07 23:27:13 +01001150 if (!xfer_buff) {
1151 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
1152 return ret;
1153 }
matthieu castetb72458a2005-11-07 23:27:13 +01001154
1155 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
1156 UCDC_SEND_ENCAPSULATED_COMMAND,
1157 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1158 value, index, xfer_buff, size, CTRL_TIMEOUT);
1159
1160 kfree(xfer_buff);
1161 if (ret < 0) {
1162 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
1163 return ret;
1164 }
1165
1166 if (ret != size) {
1167 uea_err(INS_TO_USBDEV(sc),
1168 "usb_control_msg send only %d bytes (instead of %d)\n",
1169 ret, size);
1170 return -EIO;
1171 }
1172
1173 return 0;
1174}
1175
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001176static int uea_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001177 u8 function, u32 address, u16 offset, u32 data)
1178{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001179 struct cmv_e1 cmv;
matthieu castetb72458a2005-11-07 23:27:13 +01001180 int ret;
1181
matthieu castet2a99b502006-04-02 18:43:53 +02001182 uea_enters(INS_TO_USBDEV(sc));
1183 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1184 "offset : 0x%04x, data : 0x%08x\n",
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001185 E1_FUNCTION_TYPE(function),
1186 E1_FUNCTION_SUBTYPE(function),
1187 E1_GETSA1(address), E1_GETSA2(address),
1188 E1_GETSA3(address),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001189 E1_GETSA4(address), offset, data);
matthieu castetb72458a2005-11-07 23:27:13 +01001190
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001191 /* we send a request, but we expect a reply */
1192 sc->cmv_dsc.e1.function = function | 0x2;
1193 sc->cmv_dsc.e1.idx++;
1194 sc->cmv_dsc.e1.address = address;
1195 sc->cmv_dsc.e1.offset = offset;
1196
1197 cmv.wPreamble = cpu_to_le16(E1_PREAMBLE);
1198 cmv.bDirection = E1_HOSTTOMODEM;
matthieu castetb72458a2005-11-07 23:27:13 +01001199 cmv.bFunction = function;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001200 cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx);
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001201 put_unaligned_le32(address, &cmv.dwSymbolicAddress);
matthieu castetb72458a2005-11-07 23:27:13 +01001202 cmv.wOffsetAddress = cpu_to_le16(offset);
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001203 put_unaligned_le32(data >> 16 | data << 16, &cmv.dwData);
matthieu castetb72458a2005-11-07 23:27:13 +01001204
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001205 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START,
1206 sizeof(cmv), &cmv);
matthieu castetb72458a2005-11-07 23:27:13 +01001207 if (ret < 0)
1208 return ret;
matthieu castet2a99b502006-04-02 18:43:53 +02001209 ret = wait_cmv_ack(sc);
1210 uea_leaves(INS_TO_USBDEV(sc));
1211 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001212}
1213
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001214static int uea_cmv_e4(struct uea_softc *sc,
1215 u16 function, u16 group, u16 address, u16 offset, u32 data)
1216{
1217 struct cmv_e4 cmv;
1218 int ret;
1219
1220 uea_enters(INS_TO_USBDEV(sc));
1221 memset(&cmv, 0, sizeof(cmv));
1222
1223 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, "
1224 "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n",
1225 E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function),
1226 group, address, offset, data);
1227
1228 /* we send a request, but we expect a reply */
1229 sc->cmv_dsc.e4.function = function | (0x1 << 4);
1230 sc->cmv_dsc.e4.offset = offset;
1231 sc->cmv_dsc.e4.address = address;
1232 sc->cmv_dsc.e4.group = group;
1233
1234 cmv.wFunction = cpu_to_be16(function);
1235 cmv.wGroup = cpu_to_be16(group);
1236 cmv.wAddress = cpu_to_be16(address);
1237 cmv.wOffset = cpu_to_be16(offset);
1238 cmv.dwData[0] = cpu_to_be32(data);
1239
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001240 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START,
1241 sizeof(cmv), &cmv);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001242 if (ret < 0)
1243 return ret;
1244 ret = wait_cmv_ack(sc);
1245 uea_leaves(INS_TO_USBDEV(sc));
1246 return ret;
1247}
1248
1249static inline int uea_read_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001250 u32 address, u16 offset, u32 *data)
1251{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001252 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD),
matthieu castetb72458a2005-11-07 23:27:13 +01001253 address, offset, 0);
1254 if (ret < 0)
1255 uea_err(INS_TO_USBDEV(sc),
1256 "reading cmv failed with error %d\n", ret);
1257 else
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001258 *data = sc->data;
matthieu castetb72458a2005-11-07 23:27:13 +01001259
1260 return ret;
1261}
1262
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001263static inline int uea_read_cmv_e4(struct uea_softc *sc,
1264 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1265{
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001266 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1267 E4_REQUESTREAD, size),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001268 group, address, offset, 0);
1269 if (ret < 0)
1270 uea_err(INS_TO_USBDEV(sc),
1271 "reading cmv failed with error %d\n", ret);
1272 else {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001273 *data = sc->data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001274 /* size is in 16-bit word quantities */
1275 if (size > 2)
1276 *(data + 1) = sc->data1;
1277 }
1278 return ret;
1279}
1280
1281static inline int uea_write_cmv_e1(struct uea_softc *sc,
matthieu castetb72458a2005-11-07 23:27:13 +01001282 u32 address, u16 offset, u32 data)
1283{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001284 int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE),
matthieu castetb72458a2005-11-07 23:27:13 +01001285 address, offset, data);
1286 if (ret < 0)
1287 uea_err(INS_TO_USBDEV(sc),
1288 "writing cmv failed with error %d\n", ret);
1289
1290 return ret;
1291}
1292
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001293static inline int uea_write_cmv_e4(struct uea_softc *sc,
1294 u8 size, u16 group, u16 address, u16 offset, u32 data)
1295{
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001296 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1297 E4_REQUESTWRITE, size),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001298 group, address, offset, data);
1299 if (ret < 0)
1300 uea_err(INS_TO_USBDEV(sc),
1301 "writing cmv failed with error %d\n", ret);
1302
1303 return ret;
1304}
1305
1306static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate)
1307{
1308 int ret;
1309 u16 timeout;
1310
1311 /* in bulk mode the modem have problem with high rate
1312 * changing internal timing could improve things, but the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001313 * value is mysterious.
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001314 * ADI930 don't support it (-EPIPE error).
1315 */
1316
1317 if (UEA_CHIP_VERSION(sc) == ADI930 ||
Stanislaw Gruszka503add42007-08-20 23:21:06 +02001318 altsetting[sc->modem_index] > 0 ||
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001319 sc->stats.phy.dsrate == dsrate)
1320 return;
1321
1322 /* Original timming (1Mbit/s) from ADI (used in windows driver) */
1323 timeout = (dsrate <= 1024*1024) ? 0 : 1;
1324 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
1325 uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n",
1326 timeout, ret < 0 ? " failed" : "");
1327
1328}
1329
matthieu castetb72458a2005-11-07 23:27:13 +01001330/*
1331 * Monitor the modem and update the stat
1332 * return 0 if everything is ok
1333 * return < 0 if an error occurs (-EAGAIN reboot needed)
1334 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001335static int uea_stat_e1(struct uea_softc *sc)
matthieu castetb72458a2005-11-07 23:27:13 +01001336{
1337 u32 data;
1338 int ret;
1339
1340 uea_enters(INS_TO_USBDEV(sc));
1341 data = sc->stats.phy.state;
1342
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001343 ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state);
matthieu castetb72458a2005-11-07 23:27:13 +01001344 if (ret < 0)
1345 return ret;
1346
1347 switch (GET_STATUS(sc->stats.phy.state)) {
1348 case 0: /* not yet synchronized */
1349 uea_dbg(INS_TO_USBDEV(sc),
1350 "modem not yet synchronized\n");
1351 return 0;
1352
1353 case 1: /* initialization */
1354 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1355 return 0;
1356
1357 case 2: /* operational */
1358 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
1359 break;
1360
1361 case 3: /* fail ... */
matthieu casteta7a0c9c2006-10-03 21:44:11 +02001362 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001363 " (may be try other cmv/dsp)\n");
matthieu castetb72458a2005-11-07 23:27:13 +01001364 return -EAGAIN;
1365
1366 case 4 ... 6: /* test state */
1367 uea_warn(INS_TO_USBDEV(sc),
1368 "modem in test mode - not supported\n");
1369 return -EAGAIN;
1370
1371 case 7: /* fast-retain ... */
1372 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
1373 return 0;
1374 default:
1375 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
1376 GET_STATUS(sc->stats.phy.state));
1377 return -EAGAIN;
1378 }
1379
1380 if (GET_STATUS(data) != 2) {
1381 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1382 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1383
1384 /* release the dsp firmware as it is not needed until
1385 * the next failure
1386 */
Jesper Juhl7af39592012-04-09 22:52:26 +02001387 release_firmware(sc->dsp_firm);
1388 sc->dsp_firm = NULL;
matthieu castetb72458a2005-11-07 23:27:13 +01001389 }
1390
1391 /* always update it as atm layer could not be init when we switch to
1392 * operational state
1393 */
Karl Hiramotocc7b86c2010-07-08 20:55:38 +00001394 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND);
matthieu castetb72458a2005-11-07 23:27:13 +01001395
1396 /* wake up processes waiting for synchronization */
1397 wake_up(&sc->sync_q);
1398
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001399 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags);
matthieu castetb72458a2005-11-07 23:27:13 +01001400 if (ret < 0)
1401 return ret;
1402 sc->stats.phy.mflags |= sc->stats.phy.flags;
1403
1404 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1405 * we check the status again in order to detect the failure earlier
1406 */
1407 if (sc->stats.phy.flags) {
matthieu castet2a99b502006-04-02 18:43:53 +02001408 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
matthieu castetb72458a2005-11-07 23:27:13 +01001409 sc->stats.phy.flags);
1410 return 0;
1411 }
1412
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001413 ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001414 if (ret < 0)
1415 return ret;
1416
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001417 uea_set_bulk_timeout(sc, (data >> 16) * 32);
matthieu castetb72458a2005-11-07 23:27:13 +01001418 sc->stats.phy.dsrate = (data >> 16) * 32;
1419 sc->stats.phy.usrate = (data & 0xffff) * 32;
1420 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1421
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001422 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001423 if (ret < 0)
1424 return ret;
1425 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
1426
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001427 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data);
matthieu castetb72458a2005-11-07 23:27:13 +01001428 if (ret < 0)
1429 return ret;
1430 sc->stats.phy.usattenuation = (data & 0xff) / 2;
1431
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001432 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin);
matthieu castetb72458a2005-11-07 23:27:13 +01001433 if (ret < 0)
1434 return ret;
1435
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001436 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin);
matthieu castetb72458a2005-11-07 23:27:13 +01001437 if (ret < 0)
1438 return ret;
1439
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001440 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow);
matthieu castetb72458a2005-11-07 23:27:13 +01001441 if (ret < 0)
1442 return ret;
1443
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001444 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow);
matthieu castetb72458a2005-11-07 23:27:13 +01001445 if (ret < 0)
1446 return ret;
1447
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001448 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc);
matthieu castetb72458a2005-11-07 23:27:13 +01001449 if (ret < 0)
1450 return ret;
1451
1452 /* only for atu-c */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001453 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc);
matthieu castetb72458a2005-11-07 23:27:13 +01001454 if (ret < 0)
1455 return ret;
1456
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001457 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr);
matthieu castetb72458a2005-11-07 23:27:13 +01001458 if (ret < 0)
1459 return ret;
1460
1461 /* only for atu-c */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001462 ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr);
matthieu castetb72458a2005-11-07 23:27:13 +01001463 if (ret < 0)
1464 return ret;
1465
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001466 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 8, &sc->stats.phy.vidco);
matthieu castetb72458a2005-11-07 23:27:13 +01001467 if (ret < 0)
1468 return ret;
1469
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001470 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 13, &sc->stats.phy.vidcpe);
matthieu castetb72458a2005-11-07 23:27:13 +01001471 if (ret < 0)
1472 return ret;
1473
1474 return 0;
1475}
1476
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001477static int uea_stat_e4(struct uea_softc *sc)
matthieu castetb72458a2005-11-07 23:27:13 +01001478{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001479 u32 data;
1480 u32 tmp_arr[2];
1481 int ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001482
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001483 uea_enters(INS_TO_USBDEV(sc));
1484 data = sc->stats.phy.state;
1485
1486 /* XXX only need to be done before operationnal... */
1487 ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state);
1488 if (ret < 0)
1489 return ret;
1490
1491 switch (sc->stats.phy.state) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001492 case 0x0: /* not yet synchronized */
1493 case 0x1:
1494 case 0x3:
1495 case 0x4:
1496 uea_dbg(INS_TO_USBDEV(sc), "modem not yet "
1497 "synchronized\n");
1498 return 0;
1499 case 0x5: /* initialization */
1500 case 0x6:
1501 case 0x9:
1502 case 0xa:
1503 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1504 return 0;
1505 case 0x2: /* fail ... */
1506 uea_info(INS_TO_USBDEV(sc), "modem synchronization "
1507 "failed (may be try other cmv/dsp)\n");
1508 return -EAGAIN;
1509 case 0x7: /* operational */
1510 break;
1511 default:
1512 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n",
1513 sc->stats.phy.state);
1514 return 0;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001515 }
1516
1517 if (data != 7) {
1518 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
1519 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
1520
1521 /* release the dsp firmware as it is not needed until
1522 * the next failure
1523 */
Jesper Juhl7af39592012-04-09 22:52:26 +02001524 release_firmware(sc->dsp_firm);
1525 sc->dsp_firm = NULL;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001526 }
1527
1528 /* always update it as atm layer could not be init when we switch to
1529 * operational state
1530 */
Karl Hiramotocc7b86c2010-07-08 20:55:38 +00001531 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001532
1533 /* wake up processes waiting for synchronization */
1534 wake_up(&sc->sync_q);
1535
1536 /* TODO improve this state machine :
1537 * we need some CMV info : what they do and their unit
1538 * we should find the equivalent of eagle3- CMV
1539 */
1540 /* check flags */
1541 ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags);
1542 if (ret < 0)
1543 return ret;
1544 sc->stats.phy.mflags |= sc->stats.phy.flags;
1545
1546 /* in case of a flags ( for example delineation LOSS (& 0x10)),
1547 * we check the status again in order to detect the failure earlier
1548 */
1549 if (sc->stats.phy.flags) {
1550 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1551 sc->stats.phy.flags);
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001552 if (sc->stats.phy.flags & 1) /* delineation LOSS */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001553 return -EAGAIN;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001554 if (sc->stats.phy.flags & 0x4000) /* Reset Flag */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001555 return -EAGAIN;
1556 return 0;
1557 }
1558
1559 /* rate data may be in upper or lower half of 64 bit word, strange */
1560 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr);
1561 if (ret < 0)
1562 return ret;
1563 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1564 sc->stats.phy.usrate = data / 1000;
1565
1566 ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr);
1567 if (ret < 0)
1568 return ret;
1569 data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1];
1570 uea_set_bulk_timeout(sc, data / 1000);
1571 sc->stats.phy.dsrate = data / 1000;
1572 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
1573
1574 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data);
1575 if (ret < 0)
1576 return ret;
1577 sc->stats.phy.dsattenuation = data / 10;
1578
1579 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data);
1580 if (ret < 0)
1581 return ret;
1582 sc->stats.phy.usattenuation = data / 10;
1583
1584 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data);
1585 if (ret < 0)
1586 return ret;
1587 sc->stats.phy.dsmargin = data / 2;
1588
1589 ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data);
1590 if (ret < 0)
1591 return ret;
1592 sc->stats.phy.usmargin = data / 10;
1593
1594 return 0;
1595}
1596
1597static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1598{
1599 char file_arr[] = "CMVxy.bin";
1600 char *file;
1601
Dan Streetmanb51d23e2015-06-17 06:18:52 +09301602 kernel_param_lock(THIS_MODULE);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001603 /* set proper name corresponding modem version and line type */
matthieu castetb72458a2005-11-07 23:27:13 +01001604 if (cmv_file[sc->modem_index] == NULL) {
1605 if (UEA_CHIP_VERSION(sc) == ADI930)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001606 file_arr[3] = '9';
1607 else if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1608 file_arr[3] = '4';
matthieu castetb72458a2005-11-07 23:27:13 +01001609 else
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001610 file_arr[3] = 'e';
1611
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02001612 file_arr[4] = IS_ISDN(sc) ? 'i' : 'p';
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001613 file = file_arr;
matthieu castetb72458a2005-11-07 23:27:13 +01001614 } else
1615 file = cmv_file[sc->modem_index];
1616
1617 strcpy(cmv_name, FW_DIR);
Samuel Ortizade901d2009-05-27 00:49:32 +02001618 strlcat(cmv_name, file, UEA_FW_NAME_MAX);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001619 if (ver == 2)
Samuel Ortizade901d2009-05-27 00:49:32 +02001620 strlcat(cmv_name, ".v2", UEA_FW_NAME_MAX);
Dan Streetmanb51d23e2015-06-17 06:18:52 +09301621 kernel_param_unlock(THIS_MODULE);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001622}
matthieu castetb72458a2005-11-07 23:27:13 +01001623
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001624static int request_cmvs_old(struct uea_softc *sc,
1625 void **cmvs, const struct firmware **fw)
1626{
1627 int ret, size;
1628 u8 *data;
Samuel Ortizade901d2009-05-27 00:49:32 +02001629 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001630
1631 cmvs_file_name(sc, cmv_name, 1);
matthieu castetb72458a2005-11-07 23:27:13 +01001632 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1633 if (ret < 0) {
1634 uea_err(INS_TO_USBDEV(sc),
1635 "requesting firmware %s failed with error %d\n",
1636 cmv_name, ret);
1637 return ret;
1638 }
1639
1640 data = (u8 *) (*fw)->data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001641 size = (*fw)->size;
1642 if (size < 1)
1643 goto err_fw_corrupted;
1644
1645 if (size != *data * sizeof(struct uea_cmvs_v1) + 1)
1646 goto err_fw_corrupted;
1647
1648 *cmvs = (void *)(data + 1);
1649 return *data;
1650
1651err_fw_corrupted:
1652 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1653 release_firmware(*fw);
1654 return -EILSEQ;
1655}
1656
1657static int request_cmvs(struct uea_softc *sc,
1658 void **cmvs, const struct firmware **fw, int *ver)
1659{
1660 int ret, size;
1661 u32 crc;
1662 u8 *data;
Samuel Ortizade901d2009-05-27 00:49:32 +02001663 char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001664
1665 cmvs_file_name(sc, cmv_name, 2);
1666 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1667 if (ret < 0) {
1668 /* if caller can handle old version, try to provide it */
1669 if (*ver == 1) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001670 uea_warn(INS_TO_USBDEV(sc), "requesting "
1671 "firmware %s failed, "
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001672 "try to get older cmvs\n", cmv_name);
1673 return request_cmvs_old(sc, cmvs, fw);
1674 }
1675 uea_err(INS_TO_USBDEV(sc),
1676 "requesting firmware %s failed with error %d\n",
1677 cmv_name, ret);
1678 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001679 }
1680
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001681 size = (*fw)->size;
1682 data = (u8 *) (*fw)->data;
1683 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1684 if (*ver == 1) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001685 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted,"
1686 " try to get older cmvs\n", cmv_name);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001687 release_firmware(*fw);
1688 return request_cmvs_old(sc, cmvs, fw);
1689 }
1690 goto err_fw_corrupted;
1691 }
1692
1693 *ver = 2;
1694
1695 data += 4;
1696 size -= 4;
1697 if (size < 5)
1698 goto err_fw_corrupted;
1699
Harvey Harrisona5abdea2008-04-29 01:03:40 -07001700 crc = get_unaligned_le32(data);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001701 data += 4;
1702 size -= 4;
1703 if (crc32_be(0, data, size) != crc)
1704 goto err_fw_corrupted;
1705
1706 if (size != *data * sizeof(struct uea_cmvs_v2) + 1)
1707 goto err_fw_corrupted;
1708
1709 *cmvs = (void *) (data + 1);
matthieu castetb72458a2005-11-07 23:27:13 +01001710 return *data;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001711
1712err_fw_corrupted:
1713 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name);
1714 release_firmware(*fw);
1715 return -EILSEQ;
1716}
1717
1718static int uea_send_cmvs_e1(struct uea_softc *sc)
1719{
1720 int i, ret, len;
1721 void *cmvs_ptr;
1722 const struct firmware *cmvs_fw;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001723 int ver = 1; /* we can handle v1 cmv firmware version; */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001724
1725 /* Enter in R-IDLE (cmv) until instructed otherwise */
1726 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
1727 if (ret < 0)
1728 return ret;
1729
1730 /* Dump firmware version */
1731 ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid);
1732 if (ret < 0)
1733 return ret;
1734 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1735 sc->stats.phy.firmid);
1736
1737 /* get options */
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001738 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001739 if (ret < 0)
1740 return ret;
1741
1742 /* send options */
1743 if (ver == 1) {
1744 struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr;
1745
1746 uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, "
1747 "please update your firmware\n");
1748
1749 for (i = 0; i < len; i++) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001750 ret = uea_write_cmv_e1(sc,
1751 get_unaligned_le32(&cmvs_v1[i].address),
1752 get_unaligned_le16(&cmvs_v1[i].offset),
1753 get_unaligned_le32(&cmvs_v1[i].data));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001754 if (ret < 0)
1755 goto out;
1756 }
1757 } else if (ver == 2) {
1758 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1759
1760 for (i = 0; i < len; i++) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001761 ret = uea_write_cmv_e1(sc,
1762 get_unaligned_le32(&cmvs_v2[i].address),
1763 (u16) get_unaligned_le32(&cmvs_v2[i].offset),
1764 get_unaligned_le32(&cmvs_v2[i].data));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001765 if (ret < 0)
1766 goto out;
1767 }
1768 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001769 /* This really should not happen */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001770 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1771 goto out;
1772 }
1773
1774 /* Enter in R-ACT-REQ */
1775 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1776 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001777 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1778 "synchronization...\n");
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001779out:
1780 release_firmware(cmvs_fw);
1781 return ret;
1782}
1783
1784static int uea_send_cmvs_e4(struct uea_softc *sc)
1785{
1786 int i, ret, len;
1787 void *cmvs_ptr;
1788 const struct firmware *cmvs_fw;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001789 int ver = 2; /* we can only handle v2 cmv firmware version; */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001790
1791 /* Enter in R-IDLE (cmv) until instructed otherwise */
1792 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
1793 if (ret < 0)
1794 return ret;
1795
1796 /* Dump firmware version */
1797 /* XXX don't read the 3th byte as it is always 6 */
1798 ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid);
1799 if (ret < 0)
1800 return ret;
1801 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1802 sc->stats.phy.firmid);
1803
1804
1805 /* get options */
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001806 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001807 if (ret < 0)
1808 return ret;
1809
1810 /* send options */
1811 if (ver == 2) {
1812 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1813
1814 for (i = 0; i < len; i++) {
1815 ret = uea_write_cmv_e4(sc, 1,
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001816 get_unaligned_le32(&cmvs_v2[i].group),
1817 get_unaligned_le32(&cmvs_v2[i].address),
1818 get_unaligned_le32(&cmvs_v2[i].offset),
1819 get_unaligned_le32(&cmvs_v2[i].data));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001820 if (ret < 0)
1821 goto out;
1822 }
1823 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001824 /* This really should not happen */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001825 uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver);
1826 goto out;
1827 }
1828
1829 /* Enter in R-ACT-REQ */
1830 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1831 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001832 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1833 "synchronization...\n");
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001834out:
1835 release_firmware(cmvs_fw);
1836 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001837}
1838
1839/* Start boot post firmware modem:
1840 * - send reset commands through usb control pipe
1841 * - start workqueue for DSP loading
1842 * - send CMV options to modem
1843 */
1844
1845static int uea_start_reset(struct uea_softc *sc)
1846{
1847 u16 zero = 0; /* ;-) */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001848 int ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001849
1850 uea_enters(INS_TO_USBDEV(sc));
1851 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1852
matthieu castet22fcceb2006-04-02 18:44:20 +02001853 /* mask interrupt */
matthieu castetb72458a2005-11-07 23:27:13 +01001854 sc->booting = 1;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001855 /* We need to set this here because, a ack timeout could have occurred,
matthieu castet22fcceb2006-04-02 18:44:20 +02001856 * but before we start the reboot, the ack occurs and set this to 1.
1857 * So we will failed to wait Ready CMV.
1858 */
1859 sc->cmv_ack = 0;
Karl Hiramotocc7b86c2010-07-08 20:55:38 +00001860 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST);
matthieu castetb72458a2005-11-07 23:27:13 +01001861
1862 /* reset statistics */
1863 memset(&sc->stats, 0, sizeof(struct uea_stats));
1864
1865 /* tell the modem that we want to boot in IDMA mode */
1866 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1867 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1868
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001869 /* enter reset mode */
matthieu castetb72458a2005-11-07 23:27:13 +01001870 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1871
1872 /* original driver use 200ms, but windows driver use 100ms */
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001873 ret = uea_wait(sc, 0, msecs_to_jiffies(100));
1874 if (ret < 0)
1875 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01001876
1877 /* leave reset mode */
1878 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1879
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001880 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001881 /* clear tx and rx mailboxes */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001882 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1883 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1884 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1885 }
matthieu castetb72458a2005-11-07 23:27:13 +01001886
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001887 ret = uea_wait(sc, 0, msecs_to_jiffies(1000));
1888 if (ret < 0)
1889 return ret;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001890
1891 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001892 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
1893 E4_MODEMREADY, 1);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001894 else
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001895 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
1896 E1_MODEMREADY);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001897
matthieu castet22fcceb2006-04-02 18:44:20 +02001898 /* demask interrupt */
matthieu castetb72458a2005-11-07 23:27:13 +01001899 sc->booting = 0;
1900
1901 /* start loading DSP */
1902 sc->pageno = 0;
1903 sc->ovl = 0;
Tejun Heo9abff152011-01-03 14:49:42 +01001904 schedule_work(&sc->task);
matthieu castetb72458a2005-11-07 23:27:13 +01001905
1906 /* wait for modem ready CMV */
1907 ret = wait_cmv_ack(sc);
1908 if (ret < 0)
1909 return ret;
1910
matthieu castet2a99b502006-04-02 18:43:53 +02001911 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1912
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001913 ret = sc->send_cmvs(sc);
matthieu castetb72458a2005-11-07 23:27:13 +01001914 if (ret < 0)
1915 return ret;
1916
matthieu castetb72458a2005-11-07 23:27:13 +01001917 sc->reset = 0;
1918 uea_leaves(INS_TO_USBDEV(sc));
1919 return ret;
1920}
1921
1922/*
1923 * In case of an error wait 1s before rebooting the modem
1924 * if the modem don't request reboot (-EAGAIN).
1925 * Monitor the modem every 1s.
1926 */
1927
1928static int uea_kthread(void *data)
1929{
1930 struct uea_softc *sc = data;
1931 int ret = -EAGAIN;
1932
Rafael J. Wysocki83144182007-07-17 04:03:35 -07001933 set_freezable();
matthieu castetb72458a2005-11-07 23:27:13 +01001934 uea_enters(INS_TO_USBDEV(sc));
1935 while (!kthread_should_stop()) {
1936 if (ret < 0 || sc->reset)
1937 ret = uea_start_reset(sc);
1938 if (!ret)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02001939 ret = sc->stat(sc);
matthieu castetb72458a2005-11-07 23:27:13 +01001940 if (ret != -EAGAIN)
Stanislaw Gruszka337427f2007-08-20 23:21:14 +02001941 uea_wait(sc, 0, msecs_to_jiffies(1000));
Stanislaw Gruszka0eb02262007-08-20 23:21:19 +02001942 try_to_freeze();
matthieu castetb72458a2005-11-07 23:27:13 +01001943 }
1944 uea_leaves(INS_TO_USBDEV(sc));
1945 return ret;
1946}
1947
1948/* Load second usb firmware for ADI930 chip */
1949static int load_XILINX_firmware(struct uea_softc *sc)
1950{
1951 const struct firmware *fw_entry;
1952 int ret, size, u, ln;
David Woodhouseaafcd2f2008-05-24 00:05:10 +01001953 const u8 *pfw;
1954 u8 value;
Tim Gardner47282502012-07-25 14:32:50 -06001955 char *fw_name = FPGA930_FIRMWARE;
matthieu castetb72458a2005-11-07 23:27:13 +01001956
1957 uea_enters(INS_TO_USBDEV(sc));
1958
1959 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1960 if (ret) {
1961 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1962 fw_name);
1963 goto err0;
1964 }
1965
1966 pfw = fw_entry->data;
1967 size = fw_entry->size;
1968 if (size != 0x577B) {
1969 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1970 fw_name);
1971 ret = -EILSEQ;
1972 goto err1;
1973 }
1974 for (u = 0; u < size; u += ln) {
1975 ln = min(size - u, 64);
1976 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1977 if (ret < 0) {
1978 uea_err(INS_TO_USBDEV(sc),
1979 "elsa download data failed (%d)\n", ret);
1980 goto err1;
1981 }
1982 }
1983
matthieu castete40abaf2006-01-18 07:38:37 +01001984 /* finish to send the fpga */
matthieu castetb72458a2005-11-07 23:27:13 +01001985 ret = uea_request(sc, 0xe, 1, 0, NULL);
1986 if (ret < 0) {
1987 uea_err(INS_TO_USBDEV(sc),
1988 "elsa download data failed (%d)\n", ret);
1989 goto err1;
1990 }
1991
matthieu castete40abaf2006-01-18 07:38:37 +01001992 /* Tell the modem we finish : de-assert reset */
matthieu castetb72458a2005-11-07 23:27:13 +01001993 value = 0;
1994 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1995 if (ret < 0)
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02001996 uea_err(sc->usb_dev, "elsa de-assert failed with error"
1997 " %d\n", ret);
matthieu castetb72458a2005-11-07 23:27:13 +01001998
matthieu castetb72458a2005-11-07 23:27:13 +01001999err1:
2000 release_firmware(fw_entry);
2001err0:
2002 uea_leaves(INS_TO_USBDEV(sc));
2003 return ret;
2004}
2005
matthieu castete40abaf2006-01-18 07:38:37 +01002006/* The modem send us an ack. First with check if it right */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002007static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
matthieu castetb72458a2005-11-07 23:27:13 +01002008{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002009 struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1;
2010 struct cmv_e1 *cmv = &intr->u.e1.s2.cmv;
2011
matthieu castetb72458a2005-11-07 23:27:13 +01002012 uea_enters(INS_TO_USBDEV(sc));
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002013 if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE)
matthieu castetb72458a2005-11-07 23:27:13 +01002014 goto bad1;
2015
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002016 if (cmv->bDirection != E1_MODEMTOHOST)
matthieu castetb72458a2005-11-07 23:27:13 +01002017 goto bad1;
2018
2019 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002020 * the first MEMACCESS cmv. Ignore it...
matthieu castetb72458a2005-11-07 23:27:13 +01002021 */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002022 if (cmv->bFunction != dsc->function) {
matthieu castetb72458a2005-11-07 23:27:13 +01002023 if (UEA_CHIP_VERSION(sc) == ADI930
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002024 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
2025 cmv->wIndex = cpu_to_le16(dsc->idx);
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002026 put_unaligned_le32(dsc->address,
2027 &cmv->dwSymbolicAddress);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002028 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
2029 } else
matthieu castetb72458a2005-11-07 23:27:13 +01002030 goto bad2;
2031 }
2032
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002033 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
2034 E1_MODEMREADY)) {
matthieu castetb72458a2005-11-07 23:27:13 +01002035 wake_up_cmv_ack(sc);
matthieu castet2a99b502006-04-02 18:43:53 +02002036 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002037 return;
2038 }
2039
2040 /* in case of MEMACCESS */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002041 if (le16_to_cpu(cmv->wIndex) != dsc->idx ||
Harvey Harrisona5abdea2008-04-29 01:03:40 -07002042 get_unaligned_le32(&cmv->dwSymbolicAddress) != dsc->address ||
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002043 le16_to_cpu(cmv->wOffsetAddress) != dsc->offset)
matthieu castetb72458a2005-11-07 23:27:13 +01002044 goto bad2;
2045
Harvey Harrisona5abdea2008-04-29 01:03:40 -07002046 sc->data = get_unaligned_le32(&cmv->dwData);
matthieu castetb72458a2005-11-07 23:27:13 +01002047 sc->data = sc->data << 16 | sc->data >> 16;
2048
2049 wake_up_cmv_ack(sc);
matthieu castet2a99b502006-04-02 18:43:53 +02002050 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002051 return;
2052
2053bad2:
Joe Perchesfec8de32007-11-19 17:53:33 -08002054 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
matthieu castetb72458a2005-11-07 23:27:13 +01002055 "Function : %d, Subfunction : %d\n",
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002056 E1_FUNCTION_TYPE(cmv->bFunction),
2057 E1_FUNCTION_SUBTYPE(cmv->bFunction));
matthieu castet2a99b502006-04-02 18:43:53 +02002058 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002059 return;
2060
2061bad1:
2062 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
2063 "wPreamble %d, bDirection %d\n",
2064 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
matthieu castet2a99b502006-04-02 18:43:53 +02002065 uea_leaves(INS_TO_USBDEV(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002066}
2067
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002068/* The modem send us an ack. First with check if it right */
2069static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
2070{
2071 struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4;
2072 struct cmv_e4 *cmv = &intr->u.e4.s2.cmv;
2073
2074 uea_enters(INS_TO_USBDEV(sc));
2075 uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n",
2076 be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction),
2077 be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress),
2078 be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1]));
2079
2080 if (be16_to_cpu(cmv->wFunction) != dsc->function)
2081 goto bad2;
2082
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002083 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
2084 E4_MODEMREADY, 1)) {
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002085 wake_up_cmv_ack(sc);
2086 uea_leaves(INS_TO_USBDEV(sc));
2087 return;
2088 }
2089
2090 /* in case of MEMACCESS */
2091 if (be16_to_cpu(cmv->wOffset) != dsc->offset ||
2092 be16_to_cpu(cmv->wGroup) != dsc->group ||
2093 be16_to_cpu(cmv->wAddress) != dsc->address)
2094 goto bad2;
2095
2096 sc->data = be32_to_cpu(cmv->dwData[0]);
2097 sc->data1 = be32_to_cpu(cmv->dwData[1]);
2098 wake_up_cmv_ack(sc);
2099 uea_leaves(INS_TO_USBDEV(sc));
2100 return;
2101
2102bad2:
Joe Perchesfec8de32007-11-19 17:53:33 -08002103 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002104 "Function : %d, Subfunction : %d\n",
2105 E4_FUNCTION_TYPE(cmv->wFunction),
2106 E4_FUNCTION_SUBTYPE(cmv->wFunction));
2107 uea_leaves(INS_TO_USBDEV(sc));
2108 return;
2109}
2110
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002111static void uea_schedule_load_page_e1(struct uea_softc *sc,
2112 struct intr_pkt *intr)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002113{
2114 sc->pageno = intr->e1_bSwapPageNo;
2115 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
Tejun Heo9abff152011-01-03 14:49:42 +01002116 schedule_work(&sc->task);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002117}
2118
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002119static void uea_schedule_load_page_e4(struct uea_softc *sc,
2120 struct intr_pkt *intr)
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002121{
2122 sc->pageno = intr->e4_bSwapPageNo;
Tejun Heo9abff152011-01-03 14:49:42 +01002123 schedule_work(&sc->task);
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002124}
2125
matthieu castetb72458a2005-11-07 23:27:13 +01002126/*
2127 * interrupt handler
2128 */
David Howells7d12e782006-10-05 14:55:46 +01002129static void uea_intr(struct urb *urb)
matthieu castetb72458a2005-11-07 23:27:13 +01002130{
matthieu castete40abaf2006-01-18 07:38:37 +01002131 struct uea_softc *sc = urb->context;
2132 struct intr_pkt *intr = urb->transfer_buffer;
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002133 int status = urb->status;
2134
matthieu castetb72458a2005-11-07 23:27:13 +01002135 uea_enters(INS_TO_USBDEV(sc));
2136
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002137 if (unlikely(status < 0)) {
matthieu castetb72458a2005-11-07 23:27:13 +01002138 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
Greg Kroah-Hartman508330e2007-07-18 10:58:02 -07002139 status);
matthieu castetb72458a2005-11-07 23:27:13 +01002140 return;
2141 }
2142
matthieu castetb72458a2005-11-07 23:27:13 +01002143 /* device-to-host interrupt */
2144 if (intr->bType != 0x08 || sc->booting) {
matthieu castete40abaf2006-01-18 07:38:37 +01002145 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
matthieu castetb72458a2005-11-07 23:27:13 +01002146 goto resubmit;
2147 }
2148
2149 switch (le16_to_cpu(intr->wInterrupt)) {
2150 case INT_LOADSWAPPAGE:
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002151 sc->schedule_load_page(sc, intr);
matthieu castetb72458a2005-11-07 23:27:13 +01002152 break;
2153
2154 case INT_INCOMINGCMV:
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002155 sc->dispatch_cmv(sc, intr);
matthieu castetb72458a2005-11-07 23:27:13 +01002156 break;
2157
2158 default:
matthieu castete40abaf2006-01-18 07:38:37 +01002159 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
matthieu castetb72458a2005-11-07 23:27:13 +01002160 le16_to_cpu(intr->wInterrupt));
2161 }
2162
2163resubmit:
2164 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
2165}
2166
2167/*
2168 * Start the modem : init the data and start kernel thread
2169 */
2170static int uea_boot(struct uea_softc *sc)
2171{
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002172 int ret, size;
matthieu castetb72458a2005-11-07 23:27:13 +01002173 struct intr_pkt *intr;
2174
2175 uea_enters(INS_TO_USBDEV(sc));
2176
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002177 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2178 size = E4_INTR_PKT_SIZE;
2179 sc->dispatch_cmv = uea_dispatch_cmv_e4;
2180 sc->schedule_load_page = uea_schedule_load_page_e4;
2181 sc->stat = uea_stat_e4;
2182 sc->send_cmvs = uea_send_cmvs_e4;
2183 INIT_WORK(&sc->task, uea_load_page_e4);
2184 } else {
2185 size = E1_INTR_PKT_SIZE;
2186 sc->dispatch_cmv = uea_dispatch_cmv_e1;
2187 sc->schedule_load_page = uea_schedule_load_page_e1;
2188 sc->stat = uea_stat_e1;
2189 sc->send_cmvs = uea_send_cmvs_e1;
2190 INIT_WORK(&sc->task, uea_load_page_e1);
2191 }
2192
matthieu castetb72458a2005-11-07 23:27:13 +01002193 init_waitqueue_head(&sc->sync_q);
matthieu castetb72458a2005-11-07 23:27:13 +01002194
2195 if (UEA_CHIP_VERSION(sc) == ADI930)
2196 load_XILINX_firmware(sc);
2197
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002198 intr = kmalloc(size, GFP_KERNEL);
Wolfram Sang59e12002016-08-25 19:38:55 +02002199 if (!intr)
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002200 goto err0;
matthieu castetb72458a2005-11-07 23:27:13 +01002201
2202 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
Wolfram Sang7ff56852016-08-11 23:14:33 +02002203 if (!sc->urb_int)
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002204 goto err1;
matthieu castetb72458a2005-11-07 23:27:13 +01002205
2206 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
2207 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002208 intr, size, uea_intr, sc,
matthieu castetb72458a2005-11-07 23:27:13 +01002209 sc->usb_dev->actconfig->interface[0]->altsetting[0].
2210 endpoint[0].desc.bInterval);
2211
2212 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2213 if (ret < 0) {
2214 uea_err(INS_TO_USBDEV(sc),
2215 "urb submition failed with error %d\n", ret);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002216 goto err1;
matthieu castetb72458a2005-11-07 23:27:13 +01002217 }
2218
Dan Williams12f188f2010-12-19 08:17:50 +00002219 /* Create worker thread, but don't start it here. Start it after
2220 * all usbatm generic initialization is done.
2221 */
2222 sc->kthread = kthread_create(uea_kthread, sc, "ueagle-atm");
2223 if (IS_ERR(sc->kthread)) {
matthieu castetb72458a2005-11-07 23:27:13 +01002224 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
2225 goto err2;
2226 }
2227
2228 uea_leaves(INS_TO_USBDEV(sc));
2229 return 0;
2230
2231err2:
2232 usb_kill_urb(sc->urb_int);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002233err1:
matthieu castetb72458a2005-11-07 23:27:13 +01002234 usb_free_urb(sc->urb_int);
matthieu castet4d45e212006-04-02 18:45:46 +02002235 sc->urb_int = NULL;
2236 kfree(intr);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002237err0:
matthieu castetb72458a2005-11-07 23:27:13 +01002238 uea_leaves(INS_TO_USBDEV(sc));
2239 return -ENOMEM;
2240}
2241
2242/*
2243 * Stop the modem : kill kernel thread and free data
2244 */
2245static void uea_stop(struct uea_softc *sc)
2246{
2247 int ret;
2248 uea_enters(INS_TO_USBDEV(sc));
2249 ret = kthread_stop(sc->kthread);
matthieu castete40abaf2006-01-18 07:38:37 +01002250 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
matthieu castetb72458a2005-11-07 23:27:13 +01002251
matthieu castetb72458a2005-11-07 23:27:13 +01002252 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
2253
2254 usb_kill_urb(sc->urb_int);
2255 kfree(sc->urb_int->transfer_buffer);
2256 usb_free_urb(sc->urb_int);
2257
Tejun Heo9abff152011-01-03 14:49:42 +01002258 /* flush the work item, when no one can schedule it */
Tejun Heo43829732012-08-20 14:51:24 -07002259 flush_work(&sc->task);
Stanislaw Gruszka04ea02f2007-08-20 23:21:10 +02002260
Jesper Juhl7af39592012-04-09 22:52:26 +02002261 release_firmware(sc->dsp_firm);
matthieu castetb72458a2005-11-07 23:27:13 +01002262 uea_leaves(INS_TO_USBDEV(sc));
2263}
2264
2265/* syfs interface */
2266static struct uea_softc *dev_to_uea(struct device *dev)
2267{
2268 struct usb_interface *intf;
2269 struct usbatm_data *usbatm;
2270
2271 intf = to_usb_interface(dev);
2272 if (!intf)
2273 return NULL;
2274
2275 usbatm = usb_get_intfdata(intf);
2276 if (!usbatm)
2277 return NULL;
2278
2279 return usbatm->driver_data;
2280}
2281
2282static ssize_t read_status(struct device *dev, struct device_attribute *attr,
2283 char *buf)
2284{
2285 int ret = -ENODEV;
2286 struct uea_softc *sc;
2287
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002288 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002289 sc = dev_to_uea(dev);
2290 if (!sc)
2291 goto out;
2292 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
2293out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002294 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002295 return ret;
2296}
2297
2298static ssize_t reboot(struct device *dev, struct device_attribute *attr,
2299 const char *buf, size_t count)
2300{
2301 int ret = -ENODEV;
2302 struct uea_softc *sc;
2303
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002304 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002305 sc = dev_to_uea(dev);
2306 if (!sc)
2307 goto out;
2308 sc->reset = 1;
2309 ret = count;
2310out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002311 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002312 return ret;
2313}
2314
Greg Kroah-Hartmane502ac52010-11-15 11:11:45 -08002315static DEVICE_ATTR(stat_status, S_IWUSR | S_IRUGO, read_status, reboot);
matthieu castetb72458a2005-11-07 23:27:13 +01002316
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002317static ssize_t read_human_status(struct device *dev,
2318 struct device_attribute *attr, char *buf)
matthieu castetb72458a2005-11-07 23:27:13 +01002319{
2320 int ret = -ENODEV;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002321 int modem_state;
matthieu castetb72458a2005-11-07 23:27:13 +01002322 struct uea_softc *sc;
2323
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002324 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002325 sc = dev_to_uea(dev);
2326 if (!sc)
2327 goto out;
2328
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002329 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2330 switch (sc->stats.phy.state) {
2331 case 0x0: /* not yet synchronized */
2332 case 0x1:
2333 case 0x3:
2334 case 0x4:
2335 modem_state = 0;
2336 break;
2337 case 0x5: /* initialization */
2338 case 0x6:
2339 case 0x9:
2340 case 0xa:
2341 modem_state = 1;
2342 break;
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002343 case 0x7: /* operational */
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002344 modem_state = 2;
2345 break;
2346 case 0x2: /* fail ... */
2347 modem_state = 3;
2348 break;
2349 default: /* unknown */
2350 modem_state = 4;
2351 break;
2352 }
2353 } else
2354 modem_state = GET_STATUS(sc->stats.phy.state);
2355
2356 switch (modem_state) {
matthieu castetb72458a2005-11-07 23:27:13 +01002357 case 0:
2358 ret = sprintf(buf, "Modem is booting\n");
2359 break;
2360 case 1:
2361 ret = sprintf(buf, "Modem is initializing\n");
2362 break;
2363 case 2:
2364 ret = sprintf(buf, "Modem is operational\n");
2365 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002366 case 3:
matthieu castetb72458a2005-11-07 23:27:13 +01002367 ret = sprintf(buf, "Modem synchronization failed\n");
2368 break;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002369 default:
2370 ret = sprintf(buf, "Modem state is unknown\n");
2371 break;
matthieu castetb72458a2005-11-07 23:27:13 +01002372 }
2373out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002374 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002375 return ret;
2376}
2377
Greg Kroah-Hartmane502ac52010-11-15 11:11:45 -08002378static DEVICE_ATTR(stat_human_status, S_IRUGO, read_human_status, NULL);
matthieu castetb72458a2005-11-07 23:27:13 +01002379
2380static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2381 char *buf)
2382{
2383 int ret = -ENODEV;
2384 struct uea_softc *sc;
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002385 char *delin = "GOOD";
matthieu castetb72458a2005-11-07 23:27:13 +01002386
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002387 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002388 sc = dev_to_uea(dev);
2389 if (!sc)
2390 goto out;
2391
Stanislaw Gruszkac8e46372007-08-20 23:23:12 +02002392 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) {
2393 if (sc->stats.phy.flags & 0x4000)
2394 delin = "RESET";
2395 else if (sc->stats.phy.flags & 0x0001)
2396 delin = "LOSS";
2397 } else {
2398 if (sc->stats.phy.flags & 0x0C00)
2399 delin = "ERROR";
2400 else if (sc->stats.phy.flags & 0x0030)
2401 delin = "LOSS";
2402 }
2403
2404 ret = sprintf(buf, "%s\n", delin);
matthieu castetb72458a2005-11-07 23:27:13 +01002405out:
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002406 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002407 return ret;
2408}
2409
Greg Kroah-Hartmane502ac52010-11-15 11:11:45 -08002410static DEVICE_ATTR(stat_delin, S_IRUGO, read_delin, NULL);
matthieu castetb72458a2005-11-07 23:27:13 +01002411
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002412#define UEA_ATTR(name, reset) \
matthieu castetb72458a2005-11-07 23:27:13 +01002413 \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002414static ssize_t read_##name(struct device *dev, \
matthieu castetb72458a2005-11-07 23:27:13 +01002415 struct device_attribute *attr, char *buf) \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002416{ \
2417 int ret = -ENODEV; \
2418 struct uea_softc *sc; \
2419 \
2420 mutex_lock(&uea_mutex); \
matthieu castetb72458a2005-11-07 23:27:13 +01002421 sc = dev_to_uea(dev); \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002422 if (!sc) \
2423 goto out; \
matthieu castetb72458a2005-11-07 23:27:13 +01002424 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2425 if (reset) \
2426 sc->stats.phy.name = 0; \
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002427out: \
2428 mutex_unlock(&uea_mutex); \
2429 return ret; \
2430} \
matthieu castetb72458a2005-11-07 23:27:13 +01002431 \
2432static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2433
2434UEA_ATTR(mflags, 1);
2435UEA_ATTR(vidcpe, 0);
2436UEA_ATTR(usrate, 0);
2437UEA_ATTR(dsrate, 0);
2438UEA_ATTR(usattenuation, 0);
2439UEA_ATTR(dsattenuation, 0);
2440UEA_ATTR(usmargin, 0);
2441UEA_ATTR(dsmargin, 0);
2442UEA_ATTR(txflow, 0);
2443UEA_ATTR(rxflow, 0);
2444UEA_ATTR(uscorr, 0);
2445UEA_ATTR(dscorr, 0);
2446UEA_ATTR(usunc, 0);
2447UEA_ATTR(dsunc, 0);
matthieu casteta7a0c9c2006-10-03 21:44:11 +02002448UEA_ATTR(firmid, 0);
matthieu castetb72458a2005-11-07 23:27:13 +01002449
2450/* Retrieve the device End System Identifier (MAC) */
2451
Sandhya Bankar49e8ecc2016-04-24 09:25:40 +05302452static int uea_getesi(struct uea_softc *sc, u_char *esi)
matthieu castetb72458a2005-11-07 23:27:13 +01002453{
2454 unsigned char mac_str[2 * ETH_ALEN + 1];
2455 int i;
2456 if (usb_string
2457 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
2458 sizeof(mac_str)) != 2 * ETH_ALEN)
2459 return 1;
2460
2461 for (i = 0; i < ETH_ALEN; i++)
Andy Shevchenkoe6448142010-06-15 17:04:44 +03002462 esi[i] = hex_to_bin(mac_str[2 * i]) * 16 +
2463 hex_to_bin(mac_str[2 * i + 1]);
matthieu castetb72458a2005-11-07 23:27:13 +01002464
2465 return 0;
2466}
2467
2468/* ATM stuff */
2469static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
2470{
2471 struct uea_softc *sc = usbatm->driver_data;
2472
2473 return uea_getesi(sc, atm_dev->esi);
2474}
2475
2476static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
2477{
2478 struct uea_softc *sc = usbatm->driver_data;
2479
matthieu castet531a39b2006-10-03 21:49:29 +02002480 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
matthieu castetb72458a2005-11-07 23:27:13 +01002481
2482 return 0;
2483
2484}
2485
2486static int claim_interface(struct usb_device *usb_dev,
2487 struct usbatm_data *usbatm, int ifnum)
2488{
2489 int ret;
2490 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
2491
2492 if (!intf) {
2493 uea_err(usb_dev, "interface %d not found\n", ifnum);
2494 return -ENODEV;
2495 }
2496
2497 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
2498 if (ret != 0)
2499 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
2500 ret);
2501 return ret;
2502}
2503
Greg Kroah-Hartmane7ccdfe2006-08-28 11:43:25 -07002504static struct attribute *attrs[] = {
2505 &dev_attr_stat_status.attr,
2506 &dev_attr_stat_mflags.attr,
2507 &dev_attr_stat_human_status.attr,
2508 &dev_attr_stat_delin.attr,
2509 &dev_attr_stat_vidcpe.attr,
2510 &dev_attr_stat_usrate.attr,
2511 &dev_attr_stat_dsrate.attr,
2512 &dev_attr_stat_usattenuation.attr,
2513 &dev_attr_stat_dsattenuation.attr,
2514 &dev_attr_stat_usmargin.attr,
2515 &dev_attr_stat_dsmargin.attr,
2516 &dev_attr_stat_txflow.attr,
2517 &dev_attr_stat_rxflow.attr,
2518 &dev_attr_stat_uscorr.attr,
2519 &dev_attr_stat_dscorr.attr,
2520 &dev_attr_stat_usunc.attr,
2521 &dev_attr_stat_dsunc.attr,
matthieu casteta7a0c9c2006-10-03 21:44:11 +02002522 &dev_attr_stat_firmid.attr,
matthieu castet9ab99c82006-10-11 14:20:56 -07002523 NULL,
Greg Kroah-Hartmane7ccdfe2006-08-28 11:43:25 -07002524};
2525static struct attribute_group attr_grp = {
2526 .attrs = attrs,
2527};
2528
matthieu castetb72458a2005-11-07 23:27:13 +01002529static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
Duncan Sands35644b02006-01-17 11:16:13 +01002530 const struct usb_device_id *id)
matthieu castetb72458a2005-11-07 23:27:13 +01002531{
2532 struct usb_device *usb = interface_to_usbdev(intf);
2533 struct uea_softc *sc;
2534 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002535 unsigned int alt;
matthieu castetb72458a2005-11-07 23:27:13 +01002536
2537 uea_enters(usb);
2538
2539 /* interface 0 is for firmware/monitoring */
2540 if (ifnum != UEA_INTR_IFACE_NO)
2541 return -ENODEV;
2542
Duncan Sands0dfcd3e2006-01-13 09:36:20 +01002543 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
matthieu castetb72458a2005-11-07 23:27:13 +01002544
2545 /* interface 1 is for outbound traffic */
2546 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
2547 if (ret < 0)
2548 return ret;
2549
matthieu castete40abaf2006-01-18 07:38:37 +01002550 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
matthieu castetb72458a2005-11-07 23:27:13 +01002551 if (UEA_CHIP_VERSION(id) != ADI930) {
2552 /* interface 2 is for inbound traffic */
2553 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
2554 if (ret < 0)
2555 return ret;
2556 }
2557
2558 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
Wolfram Sang59e12002016-08-25 19:38:55 +02002559 if (!sc)
matthieu castetb72458a2005-11-07 23:27:13 +01002560 return -ENOMEM;
matthieu castetb72458a2005-11-07 23:27:13 +01002561
2562 sc->usb_dev = usb;
2563 usbatm->driver_data = sc;
2564 sc->usbatm = usbatm;
2565 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
2566 sc->driver_info = id->driver_info;
2567
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002568 /* first try to use module parameter */
2569 if (annex[sc->modem_index] == 1)
2570 sc->annex = ANNEXA;
2571 else if (annex[sc->modem_index] == 2)
2572 sc->annex = ANNEXB;
2573 /* try to autodetect annex */
2574 else if (sc->driver_info & AUTO_ANNEX_A)
2575 sc->annex = ANNEXA;
2576 else if (sc->driver_info & AUTO_ANNEX_B)
2577 sc->annex = ANNEXB;
2578 else
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002579 sc->annex = (le16_to_cpu
2580 (sc->usb_dev->descriptor.bcdDevice) & 0x80) ? ANNEXB : ANNEXA;
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002581
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002582 alt = altsetting[sc->modem_index];
matthieu castet3c9666c2006-01-18 07:38:19 +01002583 /* ADI930 don't support iso */
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002584 if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002585 if (alt <= 8 &&
2586 usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) {
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002587 uea_dbg(usb, "set alternate %u for 2 interface\n", alt);
matthieu castet3c9666c2006-01-18 07:38:19 +01002588 uea_info(usb, "using iso mode\n");
2589 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
2590 } else {
Stanislaw Gruszka503add42007-08-20 23:21:06 +02002591 uea_err(usb, "setting alternate %u failed for "
2592 "2 interface, using bulk mode\n", alt);
matthieu castet3c9666c2006-01-18 07:38:19 +01002593 }
2594 }
2595
matthieu castet9ab99c82006-10-11 14:20:56 -07002596 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
2597 if (ret < 0)
2598 goto error;
2599
matthieu castetb72458a2005-11-07 23:27:13 +01002600 ret = uea_boot(sc);
matthieu castet9ab99c82006-10-11 14:20:56 -07002601 if (ret < 0)
Stanislaw Gruszka4c132e72007-08-20 23:20:49 +02002602 goto error_rm_grp;
matthieu castetb72458a2005-11-07 23:27:13 +01002603
matthieu castetb72458a2005-11-07 23:27:13 +01002604 return 0;
Stanislaw Gruszka4c132e72007-08-20 23:20:49 +02002605
2606error_rm_grp:
2607 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
matthieu castet9ab99c82006-10-11 14:20:56 -07002608error:
2609 kfree(sc);
2610 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01002611}
2612
2613static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
2614{
2615 struct uea_softc *sc = usbatm->driver_data;
2616
matthieu castet9ab99c82006-10-11 14:20:56 -07002617 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
matthieu castetb72458a2005-11-07 23:27:13 +01002618 uea_stop(sc);
2619 kfree(sc);
2620}
2621
2622static struct usbatm_driver uea_usbatm_driver = {
2623 .driver_name = "ueagle-atm",
matthieu castetb72458a2005-11-07 23:27:13 +01002624 .bind = uea_bind,
2625 .atm_start = uea_atm_open,
2626 .unbind = uea_unbind,
2627 .heavy_init = uea_heavy,
Duncan Sands80aae7a2006-01-13 10:59:23 +01002628 .bulk_in = UEA_BULK_DATA_PIPE,
2629 .bulk_out = UEA_BULK_DATA_PIPE,
matthieu castet3c9666c2006-01-18 07:38:19 +01002630 .isoc_in = UEA_ISO_DATA_PIPE,
matthieu castetb72458a2005-11-07 23:27:13 +01002631};
2632
2633static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
2634{
2635 struct usb_device *usb = interface_to_usbdev(intf);
Dan Williams12f188f2010-12-19 08:17:50 +00002636 int ret;
matthieu castetb72458a2005-11-07 23:27:13 +01002637
2638 uea_enters(usb);
Stanislaw Gruszka603cf602007-08-20 23:21:01 +02002639 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n",
2640 le16_to_cpu(usb->descriptor.idVendor),
2641 le16_to_cpu(usb->descriptor.idProduct),
2642 le16_to_cpu(usb->descriptor.bcdDevice),
2643 chip_name[UEA_CHIP_VERSION(id)]);
matthieu castetb72458a2005-11-07 23:27:13 +01002644
2645 usb_reset_device(usb);
2646
2647 if (UEA_IS_PREFIRM(id))
2648 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
2649
Dan Williams12f188f2010-12-19 08:17:50 +00002650 ret = usbatm_usb_probe(intf, id, &uea_usbatm_driver);
2651 if (ret == 0) {
2652 struct usbatm_data *usbatm = usb_get_intfdata(intf);
2653 struct uea_softc *sc = usbatm->driver_data;
2654
2655 /* Ensure carrier is initialized to off as early as possible */
2656 UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST);
2657
2658 /* Only start the worker thread when all init is done */
2659 wake_up_process(sc->kthread);
2660 }
2661
2662 return ret;
matthieu castetb72458a2005-11-07 23:27:13 +01002663}
2664
2665static void uea_disconnect(struct usb_interface *intf)
2666{
2667 struct usb_device *usb = interface_to_usbdev(intf);
2668 int ifnum = intf->altsetting->desc.bInterfaceNumber;
2669 uea_enters(usb);
2670
2671 /* ADI930 has 2 interfaces and eagle 3 interfaces.
2672 * Pre-firmware device has one interface
2673 */
2674 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002675 mutex_lock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002676 usbatm_usb_disconnect(intf);
Arjan van de Venab3c81f2006-01-13 15:52:55 +01002677 mutex_unlock(&uea_mutex);
matthieu castetb72458a2005-11-07 23:27:13 +01002678 uea_info(usb, "ADSL device removed\n");
2679 }
2680
2681 uea_leaves(usb);
2682}
2683
2684/*
2685 * List of supported VID/PID
2686 */
2687static const struct usb_device_id uea_ids[] = {
Javier Blanco de Torres (Neurowork)4545f7e2010-04-12 09:21:13 +02002688 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM),
2689 .driver_info = ADI930 | PREFIRM},
2690 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM),
2691 .driver_info = ADI930 | PSTFIRM},
2692 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM),
2693 .driver_info = EAGLE_I | PREFIRM},
2694 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM),
2695 .driver_info = EAGLE_I | PSTFIRM},
2696 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM),
2697 .driver_info = EAGLE_II | PREFIRM},
2698 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM),
2699 .driver_info = EAGLE_II | PSTFIRM},
2700 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM),
2701 .driver_info = EAGLE_II | PREFIRM},
2702 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM),
2703 .driver_info = EAGLE_II | PSTFIRM},
2704 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM),
2705 .driver_info = EAGLE_III | PREFIRM},
2706 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM),
2707 .driver_info = EAGLE_III | PSTFIRM},
2708 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM),
2709 .driver_info = EAGLE_IV | PREFIRM},
2710 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM),
2711 .driver_info = EAGLE_IV | PSTFIRM},
2712 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM),
2713 .driver_info = EAGLE_I | PREFIRM},
2714 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM),
2715 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2716 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM),
2717 .driver_info = EAGLE_I | PREFIRM},
2718 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM),
2719 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2720 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM),
2721 .driver_info = EAGLE_II | PREFIRM},
2722 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM),
2723 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A},
2724 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM),
2725 .driver_info = EAGLE_II | PREFIRM},
2726 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM),
2727 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B},
2728 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM),
2729 .driver_info = ADI930 | PREFIRM},
2730 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM),
2731 .driver_info = ADI930 | PSTFIRM},
2732 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM),
2733 .driver_info = ADI930 | PREFIRM},
2734 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM),
2735 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A},
2736 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM),
2737 .driver_info = ADI930 | PREFIRM},
2738 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM),
2739 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B},
2740 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM),
2741 .driver_info = EAGLE_I | PREFIRM},
2742 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM),
2743 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2744 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM),
2745 .driver_info = EAGLE_I | PREFIRM},
2746 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM),
2747 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2748 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),
2749 .driver_info = EAGLE_I | PREFIRM},
2750 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),
2751 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2752 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),
2753 .driver_info = EAGLE_I | PREFIRM},
2754 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),
2755 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
matthieu castetb72458a2005-11-07 23:27:13 +01002756 {}
2757};
2758
2759/*
2760 * USB driver descriptor
2761 */
2762static struct usb_driver uea_driver = {
matthieu castetb72458a2005-11-07 23:27:13 +01002763 .name = "ueagle-atm",
2764 .id_table = uea_ids,
2765 .probe = uea_probe,
2766 .disconnect = uea_disconnect,
2767};
2768
2769MODULE_DEVICE_TABLE(usb, uea_ids);
2770
Greg Kroah-Hartman65db4302011-11-18 09:34:02 -08002771module_usb_driver(uea_driver);
matthieu castetb72458a2005-11-07 23:27:13 +01002772
2773MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
2774MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
2775MODULE_LICENSE("Dual BSD/GPL");
Tim Gardner47282502012-07-25 14:32:50 -06002776MODULE_FIRMWARE(EAGLE_FIRMWARE);
2777MODULE_FIRMWARE(ADI930_FIRMWARE);
2778MODULE_FIRMWARE(EAGLE_I_FIRMWARE);
2779MODULE_FIRMWARE(EAGLE_II_FIRMWARE);
2780MODULE_FIRMWARE(EAGLE_III_FIRMWARE);
2781MODULE_FIRMWARE(EAGLE_IV_FIRMWARE);
2782MODULE_FIRMWARE(DSP4I_FIRMWARE);
2783MODULE_FIRMWARE(DSP4P_FIRMWARE);
2784MODULE_FIRMWARE(DSP9I_FIRMWARE);
2785MODULE_FIRMWARE(DSP9P_FIRMWARE);
2786MODULE_FIRMWARE(DSPEI_FIRMWARE);
2787MODULE_FIRMWARE(DSPEP_FIRMWARE);
2788MODULE_FIRMWARE(FPGA930_FIRMWARE);
2789MODULE_FIRMWARE(CMV4P_FIRMWARE);
2790MODULE_FIRMWARE(CMV4PV2_FIRMWARE);
2791MODULE_FIRMWARE(CMV4I_FIRMWARE);
2792MODULE_FIRMWARE(CMV4IV2_FIRMWARE);
2793MODULE_FIRMWARE(CMV9P_FIRMWARE);
2794MODULE_FIRMWARE(CMV9PV2_FIRMWARE);
2795MODULE_FIRMWARE(CMV9I_FIRMWARE);
2796MODULE_FIRMWARE(CMV9IV2_FIRMWARE);
2797MODULE_FIRMWARE(CMVEP_FIRMWARE);
2798MODULE_FIRMWARE(CMVEPV2_FIRMWARE);
2799MODULE_FIRMWARE(CMVEI_FIRMWARE);
2800MODULE_FIRMWARE(CMVEIV2_FIRMWARE);