Commit | Line | Data |
---|---|---|
b72458a8 | 1 | /*- |
2 | * Copyright (c) 2003, 2004 | |
3 | * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved. | |
4 | * | |
5 | * Copyright (c) 2005 Matthieu Castet <castet.matthieu@free.fr> | |
6 | * | |
7 | * This software is available to you under a choice of one of two | |
8 | * licenses. You may choose to be licensed under the terms of the GNU | |
9 | * General Public License (GPL) Version 2, available from the file | |
10 | * COPYING in the main directory of this source tree, or the | |
11 | * BSD license below: | |
12 | * | |
13 | * Redistribution and use in source and binary forms, with or without | |
14 | * modification, are permitted provided that the following conditions | |
15 | * are met: | |
16 | * 1. Redistributions of source code must retain the above copyright | |
17 | * notice unmodified, this list of conditions, and the following | |
18 | * disclaimer. | |
19 | * 2. Redistributions in binary form must reproduce the above copyright | |
20 | * notice, this list of conditions and the following disclaimer in the | |
21 | * documentation and/or other materials provided with the distribution. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
33 | * SUCH DAMAGE. | |
34 | * | |
35 | * GPL license : | |
36 | * This program is free software; you can redistribute it and/or | |
37 | * modify it under the terms of the GNU General Public License | |
38 | * as published by the Free Software Foundation; either version 2 | |
39 | * of the License, or (at your option) any later version. | |
40 | * | |
41 | * This program is distributed in the hope that it will be useful, | |
42 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
43 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
44 | * GNU General Public License for more details. | |
45 | * | |
46 | * You should have received a copy of the GNU General Public License | |
47 | * along with this program; if not, write to the Free Software | |
48 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
49 | * | |
50 | * | |
51 | * HISTORY : some part of the code was base on ueagle 1.3 BSD driver, | |
52 | * Damien Bergamini agree to put his code under a DUAL GPL/BSD license. | |
53 | * | |
54 | * The rest of the code was was rewritten from scratch. | |
55 | */ | |
56 | ||
57 | #include <linux/module.h> | |
58 | #include <linux/moduleparam.h> | |
59 | #include <linux/init.h> | |
60 | #include <linux/crc32.h> | |
61 | #include <linux/usb.h> | |
62 | #include <linux/firmware.h> | |
63 | #include <linux/ctype.h> | |
64 | #include <linux/kthread.h> | |
65 | #include <linux/version.h> | |
ab3c81ff | 66 | #include <linux/mutex.h> |
b72458a8 | 67 | #include <asm/unaligned.h> |
68 | ||
69 | #include "usbatm.h" | |
70 | ||
3c9666cc | 71 | #define EAGLEUSBVERSION "ueagle 1.2" |
b72458a8 | 72 | |
73 | ||
74 | /* | |
75 | * Debug macros | |
76 | */ | |
77 | #define uea_dbg(usb_dev, format, args...) \ | |
78 | do { \ | |
79 | if (debug >= 1) \ | |
80 | dev_dbg(&(usb_dev)->dev, \ | |
81 | "[ueagle-atm dbg] %s: " format, \ | |
82 | __FUNCTION__, ##args); \ | |
83 | } while (0) | |
84 | ||
85 | #define uea_vdbg(usb_dev, format, args...) \ | |
86 | do { \ | |
87 | if (debug >= 2) \ | |
88 | dev_dbg(&(usb_dev)->dev, \ | |
89 | "[ueagle-atm vdbg] " format, ##args); \ | |
90 | } while (0) | |
91 | ||
92 | #define uea_enters(usb_dev) \ | |
93 | uea_vdbg(usb_dev, "entering %s\n", __FUNCTION__) | |
94 | ||
95 | #define uea_leaves(usb_dev) \ | |
96 | uea_vdbg(usb_dev, "leaving %s\n", __FUNCTION__) | |
97 | ||
98 | #define uea_err(usb_dev, format,args...) \ | |
99 | dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args) | |
100 | ||
101 | #define uea_warn(usb_dev, format,args...) \ | |
102 | dev_warn(&(usb_dev)->dev ,"[Ueagle-atm] " format, ##args) | |
103 | ||
104 | #define uea_info(usb_dev, format,args...) \ | |
105 | dev_info(&(usb_dev)->dev ,"[ueagle-atm] " format, ##args) | |
106 | ||
107 | struct uea_cmvs { | |
108 | u32 address; | |
109 | u16 offset; | |
110 | u32 data; | |
111 | } __attribute__ ((packed)); | |
112 | ||
113 | struct uea_softc { | |
114 | struct usb_device *usb_dev; | |
115 | struct usbatm_data *usbatm; | |
116 | ||
117 | int modem_index; | |
118 | unsigned int driver_info; | |
119 | ||
120 | int booting; | |
121 | int reset; | |
122 | ||
123 | wait_queue_head_t sync_q; | |
124 | ||
125 | struct task_struct *kthread; | |
126 | u32 data; | |
127 | wait_queue_head_t cmv_ack_wait; | |
128 | int cmv_ack; | |
129 | ||
130 | struct work_struct task; | |
131 | u16 pageno; | |
132 | u16 ovl; | |
133 | ||
134 | const struct firmware *dsp_firm; | |
135 | struct urb *urb_int; | |
136 | ||
137 | u8 cmv_function; | |
138 | u16 cmv_idx; | |
139 | u32 cmv_address; | |
140 | u16 cmv_offset; | |
141 | ||
142 | /* keep in sync with eaglectl */ | |
143 | struct uea_stats { | |
144 | struct { | |
145 | u32 state; | |
146 | u32 flags; | |
147 | u32 mflags; | |
148 | u32 vidcpe; | |
149 | u32 vidco; | |
150 | u32 dsrate; | |
151 | u32 usrate; | |
152 | u32 dsunc; | |
153 | u32 usunc; | |
154 | u32 dscorr; | |
155 | u32 uscorr; | |
156 | u32 txflow; | |
157 | u32 rxflow; | |
158 | u32 usattenuation; | |
159 | u32 dsattenuation; | |
160 | u32 dsmargin; | |
161 | u32 usmargin; | |
162 | u32 firmid; | |
163 | } phy; | |
164 | } stats; | |
165 | }; | |
166 | ||
167 | /* | |
168 | * Elsa IDs | |
169 | */ | |
170 | #define ELSA_VID 0x05CC | |
171 | #define ELSA_PID_PSTFIRM 0x3350 | |
172 | #define ELSA_PID_PREFIRM 0x3351 | |
173 | ||
174 | /* | |
175 | * Sagem USB IDs | |
176 | */ | |
177 | #define EAGLE_VID 0x1110 | |
178 | #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */ | |
179 | #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */ | |
180 | ||
181 | #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */ | |
182 | #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */ | |
183 | ||
184 | #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */ | |
185 | #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */ | |
186 | ||
187 | /* | |
188 | * Eagle III Pid | |
189 | */ | |
190 | #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */ | |
191 | #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */ | |
192 | ||
193 | /* | |
194 | * USR USB IDs | |
195 | */ | |
196 | #define USR_VID 0x0BAF | |
197 | #define MILLER_A_PID_PREFIRM 0x00F2 | |
198 | #define MILLER_A_PID_PSTFIRM 0x00F1 | |
199 | #define MILLER_B_PID_PREFIRM 0x00FA | |
200 | #define MILLER_B_PID_PSTFIRM 0x00F9 | |
201 | #define HEINEKEN_A_PID_PREFIRM 0x00F6 | |
202 | #define HEINEKEN_A_PID_PSTFIRM 0x00F5 | |
203 | #define HEINEKEN_B_PID_PREFIRM 0x00F8 | |
204 | #define HEINEKEN_B_PID_PSTFIRM 0x00F7 | |
205 | ||
206 | #define PREFIRM 0 | |
207 | #define PSTFIRM (1<<7) | |
208 | enum { | |
209 | ADI930 = 0, | |
210 | EAGLE_I, | |
211 | EAGLE_II, | |
212 | EAGLE_III | |
213 | }; | |
214 | ||
215 | /* macros for both struct usb_device_id and struct uea_softc */ | |
216 | #define UEA_IS_PREFIRM(x) \ | |
217 | (!((x)->driver_info & PSTFIRM)) | |
218 | #define UEA_CHIP_VERSION(x) \ | |
219 | ((x)->driver_info & 0xf) | |
220 | ||
221 | #define IS_ISDN(sc) \ | |
222 | (le16_to_cpu(sc->usb_dev->descriptor.bcdDevice) & 0x80) | |
223 | ||
224 | #define INS_TO_USBDEV(ins) ins->usb_dev | |
225 | ||
226 | #define GET_STATUS(data) \ | |
227 | ((data >> 8) & 0xf) | |
228 | #define IS_OPERATIONAL(sc) \ | |
229 | (GET_STATUS(sc->stats.phy.state) == 2) | |
230 | ||
231 | /* | |
232 | * Set of macros to handle unaligned data in the firmware blob. | |
233 | * The FW_GET_BYTE() macro is provided only for consistency. | |
234 | */ | |
235 | ||
236 | #define FW_GET_BYTE(p) *((__u8 *) (p)) | |
237 | #define FW_GET_WORD(p) le16_to_cpu(get_unaligned((__le16 *) (p))) | |
238 | #define FW_GET_LONG(p) le32_to_cpu(get_unaligned((__le32 *) (p))) | |
239 | ||
240 | #define FW_DIR "ueagle-atm/" | |
241 | #define NB_MODEM 4 | |
242 | ||
243 | #define BULK_TIMEOUT 300 | |
244 | #define CTRL_TIMEOUT 1000 | |
245 | ||
246 | #define ACK_TIMEOUT msecs_to_jiffies(1500) | |
247 | ||
248 | #define UEA_INTR_IFACE_NO 0 | |
249 | #define UEA_US_IFACE_NO 1 | |
250 | #define UEA_DS_IFACE_NO 2 | |
251 | ||
252 | #define FASTEST_ISO_INTF 8 | |
253 | ||
254 | #define UEA_BULK_DATA_PIPE 0x02 | |
255 | #define UEA_IDMA_PIPE 0x04 | |
256 | #define UEA_INTR_PIPE 0x04 | |
257 | #define UEA_ISO_DATA_PIPE 0x08 | |
258 | ||
259 | #define UEA_SET_BLOCK 0x0001 | |
260 | #define UEA_SET_MODE 0x0003 | |
261 | #define UEA_SET_2183_DATA 0x0004 | |
262 | #define UEA_SET_TIMEOUT 0x0011 | |
263 | ||
264 | #define UEA_LOOPBACK_OFF 0x0002 | |
265 | #define UEA_LOOPBACK_ON 0x0003 | |
266 | #define UEA_BOOT_IDMA 0x0006 | |
267 | #define UEA_START_RESET 0x0007 | |
268 | #define UEA_END_RESET 0x0008 | |
269 | ||
270 | #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000) | |
271 | #define UEA_MPTX_START (0x3fce | 0x4000) | |
272 | #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000) | |
273 | #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000) | |
274 | ||
275 | /* structure describing a block within a DSP page */ | |
276 | struct block_info { | |
277 | __le16 wHdr; | |
278 | #define UEA_BIHDR 0xabcd | |
279 | __le16 wAddress; | |
280 | __le16 wSize; | |
281 | __le16 wOvlOffset; | |
282 | __le16 wOvl; /* overlay */ | |
283 | __le16 wLast; | |
284 | } __attribute__ ((packed)); | |
285 | #define BLOCK_INFO_SIZE 12 | |
286 | ||
287 | /* structure representing a CMV (Configuration and Management Variable) */ | |
288 | struct cmv { | |
289 | __le16 wPreamble; | |
290 | #define PREAMBLE 0x535c | |
291 | __u8 bDirection; | |
292 | #define MODEMTOHOST 0x01 | |
293 | #define HOSTTOMODEM 0x10 | |
294 | __u8 bFunction; | |
295 | #define FUNCTION_TYPE(f) ((f) >> 4) | |
296 | #define MEMACCESS 0x1 | |
297 | #define ADSLDIRECTIVE 0x7 | |
298 | ||
299 | #define FUNCTION_SUBTYPE(f) ((f) & 0x0f) | |
300 | /* for MEMACCESS */ | |
301 | #define REQUESTREAD 0x0 | |
302 | #define REQUESTWRITE 0x1 | |
303 | #define REPLYREAD 0x2 | |
304 | #define REPLYWRITE 0x3 | |
305 | /* for ADSLDIRECTIVE */ | |
306 | #define KERNELREADY 0x0 | |
307 | #define MODEMREADY 0x1 | |
308 | ||
309 | #define MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf)) | |
310 | __le16 wIndex; | |
311 | __le32 dwSymbolicAddress; | |
312 | #define MAKESA(a, b, c, d) \ | |
313 | (((c) & 0xff) << 24 | \ | |
314 | ((d) & 0xff) << 16 | \ | |
315 | ((a) & 0xff) << 8 | \ | |
316 | ((b) & 0xff)) | |
317 | ||
318 | #define SA_CNTL MAKESA('C', 'N', 'T', 'L') | |
319 | #define SA_DIAG MAKESA('D', 'I', 'A', 'G') | |
320 | #define SA_INFO MAKESA('I', 'N', 'F', 'O') | |
321 | #define SA_OPTN MAKESA('O', 'P', 'T', 'N') | |
322 | #define SA_RATE MAKESA('R', 'A', 'T', 'E') | |
323 | #define SA_STAT MAKESA('S', 'T', 'A', 'T') | |
324 | __le16 wOffsetAddress; | |
325 | __le32 dwData; | |
326 | } __attribute__ ((packed)); | |
327 | #define CMV_SIZE 16 | |
328 | ||
329 | /* structure representing swap information */ | |
330 | struct swap_info { | |
331 | __u8 bSwapPageNo; | |
332 | __u8 bOvl; /* overlay */ | |
333 | } __attribute__ ((packed)); | |
334 | ||
335 | /* structure representing interrupt data */ | |
336 | struct intr_pkt { | |
337 | __u8 bType; | |
338 | __u8 bNotification; | |
339 | __le16 wValue; | |
340 | __le16 wIndex; | |
341 | __le16 wLength; | |
342 | __le16 wInterrupt; | |
343 | #define INT_LOADSWAPPAGE 0x0001 | |
344 | #define INT_INCOMINGCMV 0x0002 | |
345 | union { | |
346 | struct { | |
347 | struct swap_info swapinfo; | |
348 | __le16 wDataSize; | |
349 | } __attribute__ ((packed)) s1; | |
350 | ||
351 | struct { | |
352 | struct cmv cmv; | |
353 | __le16 wDataSize; | |
354 | } __attribute__ ((packed)) s2; | |
355 | } __attribute__ ((packed)) u; | |
356 | #define bSwapPageNo u.s1.swapinfo.bSwapPageNo | |
357 | #define bOvl u.s1.swapinfo.bOvl | |
358 | } __attribute__ ((packed)); | |
359 | #define INTR_PKT_SIZE 28 | |
360 | ||
361 | static struct usb_driver uea_driver; | |
ab3c81ff | 362 | static DEFINE_MUTEX(uea_mutex); |
b72458a8 | 363 | static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III"}; |
364 | ||
365 | static int modem_index; | |
366 | static unsigned int debug; | |
3c9666cc | 367 | static int use_iso[NB_MODEM] = {[0 ... (NB_MODEM - 1)] = 1}; |
b72458a8 | 368 | static int sync_wait[NB_MODEM]; |
369 | static char *cmv_file[NB_MODEM]; | |
370 | ||
371 | module_param(debug, uint, 0644); | |
372 | MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)"); | |
3c9666cc | 373 | module_param_array(use_iso, bool, NULL, 0644); |
374 | MODULE_PARM_DESC(use_iso, "use isochronous usb pipe for incoming traffic"); | |
b72458a8 | 375 | module_param_array(sync_wait, bool, NULL, 0644); |
376 | MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM"); | |
377 | module_param_array(cmv_file, charp, NULL, 0644); | |
378 | MODULE_PARM_DESC(cmv_file, | |
379 | "file name with configuration and management variables"); | |
380 | ||
381 | #define UPDATE_ATM_STAT(type, val) \ | |
382 | do { \ | |
383 | if (sc->usbatm->atm_dev) \ | |
384 | sc->usbatm->atm_dev->type = val; \ | |
385 | } while (0) | |
386 | ||
387 | /* Firmware loading */ | |
388 | #define LOAD_INTERNAL 0xA0 | |
389 | #define F8051_USBCS 0x7f92 | |
390 | ||
391 | /** | |
392 | * uea_send_modem_cmd - Send a command for pre-firmware devices. | |
393 | */ | |
394 | static int uea_send_modem_cmd(struct usb_device *usb, | |
395 | u16 addr, u16 size, u8 * buff) | |
396 | { | |
397 | int ret = -ENOMEM; | |
398 | u8 *xfer_buff; | |
399 | ||
400 | xfer_buff = kmalloc(size, GFP_KERNEL); | |
401 | if (xfer_buff) { | |
402 | memcpy(xfer_buff, buff, size); | |
403 | ret = usb_control_msg(usb, | |
404 | usb_sndctrlpipe(usb, 0), | |
405 | LOAD_INTERNAL, | |
406 | USB_DIR_OUT | USB_TYPE_VENDOR | | |
407 | USB_RECIP_DEVICE, addr, 0, xfer_buff, | |
408 | size, CTRL_TIMEOUT); | |
409 | kfree(xfer_buff); | |
410 | } | |
411 | ||
412 | if (ret < 0) | |
413 | return ret; | |
414 | ||
415 | return (ret == size) ? 0 : -EIO; | |
416 | } | |
417 | ||
418 | static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *context) | |
419 | { | |
420 | struct usb_device *usb = context; | |
421 | u8 *pfw, value; | |
422 | u32 crc = 0; | |
423 | int ret, size; | |
424 | ||
425 | uea_enters(usb); | |
426 | if (!fw_entry) { | |
427 | uea_err(usb, "firmware is not available\n"); | |
428 | goto err; | |
429 | } | |
430 | ||
431 | pfw = fw_entry->data; | |
432 | size = fw_entry->size; | |
8d7802ed | 433 | if (size < 4) |
434 | goto err_fw_corrupted; | |
b72458a8 | 435 | |
436 | crc = FW_GET_LONG(pfw); | |
437 | pfw += 4; | |
438 | size -= 4; | |
8d7802ed | 439 | if (crc32_be(0, pfw, size) != crc) |
440 | goto err_fw_corrupted; | |
b72458a8 | 441 | |
442 | /* | |
443 | * Start to upload formware : send reset | |
444 | */ | |
445 | value = 1; | |
446 | ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value); | |
447 | ||
448 | if (ret < 0) { | |
449 | uea_err(usb, "modem reset failed with error %d\n", ret); | |
450 | goto err; | |
451 | } | |
452 | ||
8d7802ed | 453 | while (size > 3) { |
b72458a8 | 454 | u8 len = FW_GET_BYTE(pfw); |
455 | u16 add = FW_GET_WORD(pfw + 1); | |
8d7802ed | 456 | |
457 | size -= len + 3; | |
458 | if (size < 0) | |
459 | goto err_fw_corrupted; | |
460 | ||
b72458a8 | 461 | ret = uea_send_modem_cmd(usb, add, len, pfw + 3); |
462 | if (ret < 0) { | |
463 | uea_err(usb, "uploading firmware data failed " | |
464 | "with error %d\n", ret); | |
465 | goto err; | |
466 | } | |
467 | pfw += len + 3; | |
b72458a8 | 468 | } |
469 | ||
8d7802ed | 470 | if (size != 0) |
471 | goto err_fw_corrupted; | |
472 | ||
b72458a8 | 473 | /* |
474 | * Tell the modem we finish : de-assert reset | |
475 | */ | |
476 | value = 0; | |
477 | ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value); | |
478 | if (ret < 0) | |
479 | uea_err(usb, "modem de-assert failed with error %d\n", ret); | |
480 | else | |
481 | uea_info(usb, "firmware uploaded\n"); | |
482 | ||
8d7802ed | 483 | uea_leaves(usb); |
484 | return; | |
485 | ||
486 | err_fw_corrupted: | |
487 | uea_err(usb, "firmware is corrupted\n"); | |
b72458a8 | 488 | err: |
489 | uea_leaves(usb); | |
490 | } | |
491 | ||
492 | /** | |
493 | * uea_load_firmware - Load usb firmware for pre-firmware devices. | |
494 | */ | |
495 | static int uea_load_firmware(struct usb_device *usb, unsigned int ver) | |
496 | { | |
497 | int ret; | |
498 | char *fw_name = FW_DIR "eagle.fw"; | |
499 | ||
500 | uea_enters(usb); | |
501 | uea_info(usb, "pre-firmware device, uploading firmware\n"); | |
502 | ||
503 | switch (ver) { | |
504 | case ADI930: | |
505 | fw_name = FW_DIR "adi930.fw"; | |
506 | break; | |
507 | case EAGLE_I: | |
508 | fw_name = FW_DIR "eagleI.fw"; | |
509 | break; | |
510 | case EAGLE_II: | |
511 | fw_name = FW_DIR "eagleII.fw"; | |
512 | break; | |
513 | case EAGLE_III: | |
514 | fw_name = FW_DIR "eagleIII.fw"; | |
515 | break; | |
516 | } | |
517 | ||
518 | ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware); | |
519 | if (ret) | |
520 | uea_err(usb, "firmware %s is not available\n", fw_name); | |
521 | else | |
522 | uea_info(usb, "loading firmware %s\n", fw_name); | |
523 | ||
524 | uea_leaves(usb); | |
525 | return ret; | |
526 | } | |
527 | ||
528 | /* modem management : dsp firmware, send/read CMV, monitoring statistic | |
529 | */ | |
530 | ||
531 | /* | |
532 | * Make sure that the DSP code provided is safe to use. | |
533 | */ | |
534 | static int check_dsp(u8 *dsp, unsigned int len) | |
535 | { | |
536 | u8 pagecount, blockcount; | |
537 | u16 blocksize; | |
538 | u32 pageoffset; | |
539 | unsigned int i, j, p, pp; | |
540 | ||
b72458a8 | 541 | pagecount = FW_GET_BYTE(dsp); |
542 | p = 1; | |
543 | ||
544 | /* enough space for page offsets? */ | |
545 | if (p + 4 * pagecount > len) | |
546 | return 1; | |
547 | ||
548 | for (i = 0; i < pagecount; i++) { | |
549 | ||
550 | pageoffset = FW_GET_LONG(dsp + p); | |
551 | p += 4; | |
552 | ||
553 | if (pageoffset == 0) | |
554 | continue; | |
555 | ||
556 | /* enough space for blockcount? */ | |
557 | if (pageoffset >= len) | |
558 | return 1; | |
559 | ||
560 | pp = pageoffset; | |
561 | blockcount = FW_GET_BYTE(dsp + pp); | |
562 | pp += 1; | |
563 | ||
564 | for (j = 0; j < blockcount; j++) { | |
565 | ||
566 | /* enough space for block header? */ | |
567 | if (pp + 4 > len) | |
568 | return 1; | |
569 | ||
570 | pp += 2; /* skip blockaddr */ | |
571 | blocksize = FW_GET_WORD(dsp + pp); | |
572 | pp += 2; | |
573 | ||
574 | /* enough space for block data? */ | |
575 | if (pp + blocksize > len) | |
576 | return 1; | |
577 | ||
578 | pp += blocksize; | |
579 | } | |
580 | } | |
581 | ||
582 | return 0; | |
583 | } | |
584 | ||
585 | /* | |
586 | * send data to the idma pipe | |
587 | * */ | |
588 | static int uea_idma_write(struct uea_softc *sc, void *data, u32 size) | |
589 | { | |
590 | int ret = -ENOMEM; | |
591 | u8 *xfer_buff; | |
592 | int bytes_read; | |
593 | ||
594 | xfer_buff = kmalloc(size, GFP_KERNEL); | |
595 | if (!xfer_buff) { | |
596 | uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n"); | |
597 | return ret; | |
598 | } | |
599 | ||
600 | memcpy(xfer_buff, data, size); | |
601 | ||
602 | ret = usb_bulk_msg(sc->usb_dev, | |
603 | usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE), | |
604 | xfer_buff, size, &bytes_read, BULK_TIMEOUT); | |
605 | ||
606 | kfree(xfer_buff); | |
607 | if (ret < 0) | |
608 | return ret; | |
609 | if (size != bytes_read) { | |
610 | uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size, | |
611 | bytes_read); | |
612 | return -EIO; | |
613 | } | |
614 | ||
615 | return 0; | |
616 | } | |
617 | ||
618 | static int request_dsp(struct uea_softc *sc) | |
619 | { | |
620 | int ret; | |
621 | char *dsp_name; | |
622 | ||
623 | if (UEA_CHIP_VERSION(sc) == ADI930) { | |
624 | if (IS_ISDN(sc)) | |
625 | dsp_name = FW_DIR "DSP9i.bin"; | |
626 | else | |
627 | dsp_name = FW_DIR "DSP9p.bin"; | |
628 | } else { | |
629 | if (IS_ISDN(sc)) | |
630 | dsp_name = FW_DIR "DSPei.bin"; | |
631 | else | |
632 | dsp_name = FW_DIR "DSPep.bin"; | |
633 | } | |
634 | ||
635 | ret = request_firmware(&sc->dsp_firm, | |
636 | dsp_name, &sc->usb_dev->dev); | |
637 | if (ret < 0) { | |
638 | uea_err(INS_TO_USBDEV(sc), | |
639 | "requesting firmware %s failed with error %d\n", | |
640 | dsp_name, ret); | |
641 | return ret; | |
642 | } | |
643 | ||
644 | if (check_dsp(sc->dsp_firm->data, sc->dsp_firm->size)) { | |
645 | uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", | |
646 | dsp_name); | |
647 | release_firmware(sc->dsp_firm); | |
648 | sc->dsp_firm = NULL; | |
649 | return -EILSEQ; | |
650 | } | |
651 | ||
652 | return 0; | |
653 | } | |
654 | ||
655 | /* | |
656 | * The uea_load_page() function must be called within a process context | |
657 | */ | |
658 | static void uea_load_page(void *xsc) | |
659 | { | |
660 | struct uea_softc *sc = xsc; | |
661 | u16 pageno = sc->pageno; | |
662 | u16 ovl = sc->ovl; | |
663 | struct block_info bi; | |
664 | ||
665 | u8 *p; | |
666 | u8 pagecount, blockcount; | |
667 | u16 blockaddr, blocksize; | |
668 | u32 pageoffset; | |
669 | int i; | |
670 | ||
671 | /* reload firmware when reboot start and it's loaded already */ | |
672 | if (ovl == 0 && pageno == 0 && sc->dsp_firm) { | |
673 | release_firmware(sc->dsp_firm); | |
674 | sc->dsp_firm = NULL; | |
675 | } | |
676 | ||
677 | if (sc->dsp_firm == NULL && request_dsp(sc) < 0) | |
678 | return; | |
679 | ||
680 | p = sc->dsp_firm->data; | |
681 | pagecount = FW_GET_BYTE(p); | |
682 | p += 1; | |
683 | ||
684 | if (pageno >= pagecount) | |
685 | goto bad1; | |
686 | ||
687 | p += 4 * pageno; | |
688 | pageoffset = FW_GET_LONG(p); | |
689 | ||
690 | if (pageoffset == 0) | |
691 | goto bad1; | |
692 | ||
693 | p = sc->dsp_firm->data + pageoffset; | |
694 | blockcount = FW_GET_BYTE(p); | |
695 | p += 1; | |
696 | ||
697 | uea_dbg(INS_TO_USBDEV(sc), | |
698 | "sending %u blocks for DSP page %u\n", blockcount, pageno); | |
699 | ||
700 | bi.wHdr = cpu_to_le16(UEA_BIHDR); | |
701 | bi.wOvl = cpu_to_le16(ovl); | |
702 | bi.wOvlOffset = cpu_to_le16(ovl | 0x8000); | |
703 | ||
704 | for (i = 0; i < blockcount; i++) { | |
705 | blockaddr = FW_GET_WORD(p); | |
706 | p += 2; | |
707 | ||
708 | blocksize = FW_GET_WORD(p); | |
709 | p += 2; | |
710 | ||
711 | bi.wSize = cpu_to_le16(blocksize); | |
712 | bi.wAddress = cpu_to_le16(blockaddr); | |
713 | bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0); | |
714 | ||
715 | /* send block info through the IDMA pipe */ | |
716 | if (uea_idma_write(sc, &bi, BLOCK_INFO_SIZE)) | |
717 | goto bad2; | |
718 | ||
719 | /* send block data through the IDMA pipe */ | |
720 | if (uea_idma_write(sc, p, blocksize)) | |
721 | goto bad2; | |
722 | ||
723 | p += blocksize; | |
724 | } | |
725 | ||
726 | return; | |
727 | ||
728 | bad2: | |
729 | uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i); | |
730 | return; | |
731 | bad1: | |
732 | uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n",pageno); | |
733 | } | |
734 | ||
735 | static inline void wake_up_cmv_ack(struct uea_softc *sc) | |
736 | { | |
737 | sc->cmv_ack = 1; | |
738 | wake_up(&sc->cmv_ack_wait); | |
739 | } | |
740 | ||
741 | static inline int wait_cmv_ack(struct uea_softc *sc) | |
742 | { | |
743 | int ret = wait_event_timeout(sc->cmv_ack_wait, | |
744 | sc->cmv_ack, ACK_TIMEOUT); | |
745 | sc->cmv_ack = 0; | |
746 | ||
747 | if (ret < 0) | |
748 | return ret; | |
749 | ||
750 | return (ret == 0) ? -ETIMEDOUT : 0; | |
751 | ||
752 | } | |
753 | ||
754 | #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00 | |
755 | ||
756 | static int uea_request(struct uea_softc *sc, | |
757 | u16 value, u16 index, u16 size, void *data) | |
758 | { | |
759 | u8 *xfer_buff; | |
760 | int ret = -ENOMEM; | |
761 | ||
762 | xfer_buff = kmalloc(size, GFP_KERNEL); | |
763 | if (!xfer_buff) { | |
764 | uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n"); | |
765 | return ret; | |
766 | } | |
767 | memcpy(xfer_buff, data, size); | |
768 | ||
769 | ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0), | |
770 | UCDC_SEND_ENCAPSULATED_COMMAND, | |
771 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
772 | value, index, xfer_buff, size, CTRL_TIMEOUT); | |
773 | ||
774 | kfree(xfer_buff); | |
775 | if (ret < 0) { | |
776 | uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret); | |
777 | return ret; | |
778 | } | |
779 | ||
780 | if (ret != size) { | |
781 | uea_err(INS_TO_USBDEV(sc), | |
782 | "usb_control_msg send only %d bytes (instead of %d)\n", | |
783 | ret, size); | |
784 | return -EIO; | |
785 | } | |
786 | ||
787 | return 0; | |
788 | } | |
789 | ||
790 | static int uea_cmv(struct uea_softc *sc, | |
791 | u8 function, u32 address, u16 offset, u32 data) | |
792 | { | |
793 | struct cmv cmv; | |
794 | int ret; | |
795 | ||
796 | /* we send a request, but we expect a reply */ | |
797 | sc->cmv_function = function | 0x2; | |
798 | sc->cmv_idx++; | |
799 | sc->cmv_address = address; | |
800 | sc->cmv_offset = offset; | |
801 | ||
802 | cmv.wPreamble = cpu_to_le16(PREAMBLE); | |
803 | cmv.bDirection = HOSTTOMODEM; | |
804 | cmv.bFunction = function; | |
805 | cmv.wIndex = cpu_to_le16(sc->cmv_idx); | |
806 | put_unaligned(cpu_to_le32(address), &cmv.dwSymbolicAddress); | |
807 | cmv.wOffsetAddress = cpu_to_le16(offset); | |
808 | put_unaligned(cpu_to_le32(data >> 16 | data << 16), &cmv.dwData); | |
809 | ||
810 | ret = uea_request(sc, UEA_SET_BLOCK, UEA_MPTX_START, CMV_SIZE, &cmv); | |
811 | if (ret < 0) | |
812 | return ret; | |
813 | return wait_cmv_ack(sc); | |
814 | } | |
815 | ||
816 | static inline int uea_read_cmv(struct uea_softc *sc, | |
817 | u32 address, u16 offset, u32 *data) | |
818 | { | |
819 | int ret = uea_cmv(sc, MAKEFUNCTION(MEMACCESS, REQUESTREAD), | |
820 | address, offset, 0); | |
821 | if (ret < 0) | |
822 | uea_err(INS_TO_USBDEV(sc), | |
823 | "reading cmv failed with error %d\n", ret); | |
824 | else | |
825 | *data = sc->data; | |
826 | ||
827 | return ret; | |
828 | } | |
829 | ||
830 | static inline int uea_write_cmv(struct uea_softc *sc, | |
831 | u32 address, u16 offset, u32 data) | |
832 | { | |
833 | int ret = uea_cmv(sc, MAKEFUNCTION(MEMACCESS, REQUESTWRITE), | |
834 | address, offset, data); | |
835 | if (ret < 0) | |
836 | uea_err(INS_TO_USBDEV(sc), | |
837 | "writing cmv failed with error %d\n", ret); | |
838 | ||
839 | return ret; | |
840 | } | |
841 | ||
842 | /* | |
843 | * Monitor the modem and update the stat | |
844 | * return 0 if everything is ok | |
845 | * return < 0 if an error occurs (-EAGAIN reboot needed) | |
846 | */ | |
847 | static int uea_stat(struct uea_softc *sc) | |
848 | { | |
849 | u32 data; | |
850 | int ret; | |
851 | ||
852 | uea_enters(INS_TO_USBDEV(sc)); | |
853 | data = sc->stats.phy.state; | |
854 | ||
855 | ret = uea_read_cmv(sc, SA_STAT, 0, &sc->stats.phy.state); | |
856 | if (ret < 0) | |
857 | return ret; | |
858 | ||
859 | switch (GET_STATUS(sc->stats.phy.state)) { | |
860 | case 0: /* not yet synchronized */ | |
861 | uea_dbg(INS_TO_USBDEV(sc), | |
862 | "modem not yet synchronized\n"); | |
863 | return 0; | |
864 | ||
865 | case 1: /* initialization */ | |
866 | uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n"); | |
867 | return 0; | |
868 | ||
869 | case 2: /* operational */ | |
870 | uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n"); | |
871 | break; | |
872 | ||
873 | case 3: /* fail ... */ | |
874 | uea_info(INS_TO_USBDEV(sc), "modem synchronization failed\n"); | |
875 | return -EAGAIN; | |
876 | ||
877 | case 4 ... 6: /* test state */ | |
878 | uea_warn(INS_TO_USBDEV(sc), | |
879 | "modem in test mode - not supported\n"); | |
880 | return -EAGAIN; | |
881 | ||
882 | case 7: /* fast-retain ... */ | |
883 | uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n"); | |
884 | return 0; | |
885 | default: | |
886 | uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n", | |
887 | GET_STATUS(sc->stats.phy.state)); | |
888 | return -EAGAIN; | |
889 | } | |
890 | ||
891 | if (GET_STATUS(data) != 2) { | |
892 | uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL); | |
893 | uea_info(INS_TO_USBDEV(sc), "modem operational\n"); | |
894 | ||
895 | /* release the dsp firmware as it is not needed until | |
896 | * the next failure | |
897 | */ | |
898 | if (sc->dsp_firm) { | |
899 | release_firmware(sc->dsp_firm); | |
900 | sc->dsp_firm = NULL; | |
901 | } | |
902 | ||
903 | ret = uea_read_cmv(sc, SA_INFO, 10, &sc->stats.phy.firmid); | |
904 | if (ret < 0) | |
905 | return ret; | |
906 | uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n", | |
907 | sc->stats.phy.firmid); | |
908 | } | |
909 | ||
910 | /* always update it as atm layer could not be init when we switch to | |
911 | * operational state | |
912 | */ | |
913 | UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND); | |
914 | ||
915 | /* wake up processes waiting for synchronization */ | |
916 | wake_up(&sc->sync_q); | |
917 | ||
918 | ret = uea_read_cmv(sc, SA_DIAG, 2, &sc->stats.phy.flags); | |
919 | if (ret < 0) | |
920 | return ret; | |
921 | sc->stats.phy.mflags |= sc->stats.phy.flags; | |
922 | ||
923 | /* in case of a flags ( for example delineation LOSS (& 0x10)), | |
924 | * we check the status again in order to detect the failure earlier | |
925 | */ | |
926 | if (sc->stats.phy.flags) { | |
927 | uea_dbg(INS_TO_USBDEV(sc), "Stat flag = %d\n", | |
928 | sc->stats.phy.flags); | |
929 | return 0; | |
930 | } | |
931 | ||
932 | ret = uea_read_cmv(sc, SA_RATE, 0, &data); | |
933 | if (ret < 0) | |
934 | return ret; | |
935 | ||
936 | /* in bulk mode the modem have problem with high rate | |
937 | * changing internal timing could improve things, but the | |
938 | * value is misterious. | |
939 | * ADI930 don't support it (-EPIPE error). | |
940 | */ | |
941 | if (UEA_CHIP_VERSION(sc) != ADI930 | |
3c9666cc | 942 | && !use_iso[sc->modem_index] |
b72458a8 | 943 | && sc->stats.phy.dsrate != (data >> 16) * 32) { |
944 | /* Original timming from ADI(used in windows driver) | |
945 | * 0x20ffff>>16 * 32 = 32 * 32 = 1Mbits | |
946 | */ | |
947 | u16 timeout = (data <= 0x20ffff) ? 0 : 1; | |
948 | ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL); | |
949 | uea_info(INS_TO_USBDEV(sc), | |
950 | "setting new timeout %d%s\n", timeout, | |
951 | ret < 0?" failed":""); | |
952 | } | |
953 | sc->stats.phy.dsrate = (data >> 16) * 32; | |
954 | sc->stats.phy.usrate = (data & 0xffff) * 32; | |
955 | UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424); | |
956 | ||
957 | ret = uea_read_cmv(sc, SA_DIAG, 23, &data); | |
958 | if (ret < 0) | |
959 | return ret; | |
960 | sc->stats.phy.dsattenuation = (data & 0xff) / 2; | |
961 | ||
962 | ret = uea_read_cmv(sc, SA_DIAG, 47, &data); | |
963 | if (ret < 0) | |
964 | return ret; | |
965 | sc->stats.phy.usattenuation = (data & 0xff) / 2; | |
966 | ||
967 | ret = uea_read_cmv(sc, SA_DIAG, 25, &sc->stats.phy.dsmargin); | |
968 | if (ret < 0) | |
969 | return ret; | |
970 | ||
971 | ret = uea_read_cmv(sc, SA_DIAG, 49, &sc->stats.phy.usmargin); | |
972 | if (ret < 0) | |
973 | return ret; | |
974 | ||
975 | ret = uea_read_cmv(sc, SA_DIAG, 51, &sc->stats.phy.rxflow); | |
976 | if (ret < 0) | |
977 | return ret; | |
978 | ||
979 | ret = uea_read_cmv(sc, SA_DIAG, 52, &sc->stats.phy.txflow); | |
980 | if (ret < 0) | |
981 | return ret; | |
982 | ||
983 | ret = uea_read_cmv(sc, SA_DIAG, 54, &sc->stats.phy.dsunc); | |
984 | if (ret < 0) | |
985 | return ret; | |
986 | ||
987 | /* only for atu-c */ | |
988 | ret = uea_read_cmv(sc, SA_DIAG, 58, &sc->stats.phy.usunc); | |
989 | if (ret < 0) | |
990 | return ret; | |
991 | ||
992 | ret = uea_read_cmv(sc, SA_DIAG, 53, &sc->stats.phy.dscorr); | |
993 | if (ret < 0) | |
994 | return ret; | |
995 | ||
996 | /* only for atu-c */ | |
997 | ret = uea_read_cmv(sc, SA_DIAG, 57, &sc->stats.phy.uscorr); | |
998 | if (ret < 0) | |
999 | return ret; | |
1000 | ||
1001 | ret = uea_read_cmv(sc, SA_INFO, 8, &sc->stats.phy.vidco); | |
1002 | if (ret < 0) | |
1003 | return ret; | |
1004 | ||
1005 | ret = uea_read_cmv(sc, SA_INFO, 13, &sc->stats.phy.vidcpe); | |
1006 | if (ret < 0) | |
1007 | return ret; | |
1008 | ||
1009 | return 0; | |
1010 | } | |
1011 | ||
1012 | static int request_cmvs(struct uea_softc *sc, | |
1013 | struct uea_cmvs **cmvs, const struct firmware **fw) | |
1014 | { | |
1015 | int ret, size; | |
1016 | u8 *data; | |
1017 | char *file; | |
1018 | static char cmv_name[256] = FW_DIR; | |
1019 | ||
1020 | if (cmv_file[sc->modem_index] == NULL) { | |
1021 | if (UEA_CHIP_VERSION(sc) == ADI930) | |
1022 | file = (IS_ISDN(sc)) ? "CMV9i.bin" : "CMV9p.bin"; | |
1023 | else | |
1024 | file = (IS_ISDN(sc)) ? "CMVei.bin" : "CMVep.bin"; | |
1025 | } else | |
1026 | file = cmv_file[sc->modem_index]; | |
1027 | ||
1028 | strcpy(cmv_name, FW_DIR); | |
1029 | strlcat(cmv_name, file, sizeof(cmv_name)); | |
1030 | ||
1031 | ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev); | |
1032 | if (ret < 0) { | |
1033 | uea_err(INS_TO_USBDEV(sc), | |
1034 | "requesting firmware %s failed with error %d\n", | |
1035 | cmv_name, ret); | |
1036 | return ret; | |
1037 | } | |
1038 | ||
1039 | data = (u8 *) (*fw)->data; | |
1040 | size = *data * sizeof(struct uea_cmvs) + 1; | |
1041 | if (size != (*fw)->size) { | |
1042 | uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", | |
1043 | cmv_name); | |
1044 | release_firmware(*fw); | |
1045 | return -EILSEQ; | |
1046 | } | |
1047 | ||
1048 | *cmvs = (struct uea_cmvs *)(data + 1); | |
1049 | return *data; | |
1050 | } | |
1051 | ||
1052 | /* Start boot post firmware modem: | |
1053 | * - send reset commands through usb control pipe | |
1054 | * - start workqueue for DSP loading | |
1055 | * - send CMV options to modem | |
1056 | */ | |
1057 | ||
1058 | static int uea_start_reset(struct uea_softc *sc) | |
1059 | { | |
1060 | u16 zero = 0; /* ;-) */ | |
1061 | int i, len, ret; | |
1062 | struct uea_cmvs *cmvs; | |
1063 | const struct firmware *cmvs_fw; | |
1064 | ||
1065 | uea_enters(INS_TO_USBDEV(sc)); | |
1066 | uea_info(INS_TO_USBDEV(sc), "(re)booting started\n"); | |
1067 | ||
1068 | sc->booting = 1; | |
1069 | UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST); | |
1070 | ||
1071 | /* reset statistics */ | |
1072 | memset(&sc->stats, 0, sizeof(struct uea_stats)); | |
1073 | ||
1074 | /* tell the modem that we want to boot in IDMA mode */ | |
1075 | uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL); | |
1076 | uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL); | |
1077 | ||
1078 | /* enter reset mode */ | |
1079 | uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL); | |
1080 | ||
1081 | /* original driver use 200ms, but windows driver use 100ms */ | |
1082 | msleep(100); | |
1083 | ||
1084 | /* leave reset mode */ | |
1085 | uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL); | |
1086 | ||
1087 | /* clear tx and rx mailboxes */ | |
1088 | uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero); | |
1089 | uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero); | |
1090 | uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero); | |
1091 | ||
1092 | msleep(1000); | |
1093 | sc->cmv_function = MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY); | |
1094 | sc->booting = 0; | |
1095 | ||
1096 | /* start loading DSP */ | |
1097 | sc->pageno = 0; | |
1098 | sc->ovl = 0; | |
1099 | schedule_work(&sc->task); | |
1100 | ||
1101 | /* wait for modem ready CMV */ | |
1102 | ret = wait_cmv_ack(sc); | |
1103 | if (ret < 0) | |
1104 | return ret; | |
1105 | ||
1106 | /* Enter in R-IDLE (cmv) until instructed otherwise */ | |
1107 | ret = uea_write_cmv(sc, SA_CNTL, 0, 1); | |
1108 | if (ret < 0) | |
1109 | return ret; | |
1110 | ||
1111 | /* get options */ | |
1112 | ret = len = request_cmvs(sc, &cmvs, &cmvs_fw); | |
1113 | if (ret < 0) | |
1114 | return ret; | |
1115 | ||
1116 | /* send options */ | |
1117 | for (i = 0; i < len; i++) { | |
1118 | ret = uea_write_cmv(sc, FW_GET_LONG(&cmvs[i].address), | |
1119 | FW_GET_WORD(&cmvs[i].offset), | |
1120 | FW_GET_LONG(&cmvs[i].data)); | |
1121 | if (ret < 0) | |
1122 | goto out; | |
1123 | } | |
1124 | /* Enter in R-ACT-REQ */ | |
1125 | ret = uea_write_cmv(sc, SA_CNTL, 0, 2); | |
1126 | out: | |
1127 | release_firmware(cmvs_fw); | |
1128 | sc->reset = 0; | |
1129 | uea_leaves(INS_TO_USBDEV(sc)); | |
1130 | return ret; | |
1131 | } | |
1132 | ||
1133 | /* | |
1134 | * In case of an error wait 1s before rebooting the modem | |
1135 | * if the modem don't request reboot (-EAGAIN). | |
1136 | * Monitor the modem every 1s. | |
1137 | */ | |
1138 | ||
1139 | static int uea_kthread(void *data) | |
1140 | { | |
1141 | struct uea_softc *sc = data; | |
1142 | int ret = -EAGAIN; | |
1143 | ||
1144 | uea_enters(INS_TO_USBDEV(sc)); | |
1145 | while (!kthread_should_stop()) { | |
1146 | if (ret < 0 || sc->reset) | |
1147 | ret = uea_start_reset(sc); | |
1148 | if (!ret) | |
1149 | ret = uea_stat(sc); | |
1150 | if (ret != -EAGAIN) | |
1151 | msleep(1000); | |
1152 | } | |
1153 | uea_leaves(INS_TO_USBDEV(sc)); | |
1154 | return ret; | |
1155 | } | |
1156 | ||
1157 | /* Load second usb firmware for ADI930 chip */ | |
1158 | static int load_XILINX_firmware(struct uea_softc *sc) | |
1159 | { | |
1160 | const struct firmware *fw_entry; | |
1161 | int ret, size, u, ln; | |
1162 | u8 *pfw, value; | |
1163 | char *fw_name = FW_DIR "930-fpga.bin"; | |
1164 | ||
1165 | uea_enters(INS_TO_USBDEV(sc)); | |
1166 | ||
1167 | ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev); | |
1168 | if (ret) { | |
1169 | uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n", | |
1170 | fw_name); | |
1171 | goto err0; | |
1172 | } | |
1173 | ||
1174 | pfw = fw_entry->data; | |
1175 | size = fw_entry->size; | |
1176 | if (size != 0x577B) { | |
1177 | uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", | |
1178 | fw_name); | |
1179 | ret = -EILSEQ; | |
1180 | goto err1; | |
1181 | } | |
1182 | for (u = 0; u < size; u += ln) { | |
1183 | ln = min(size - u, 64); | |
1184 | ret = uea_request(sc, 0xe, 0, ln, pfw + u); | |
1185 | if (ret < 0) { | |
1186 | uea_err(INS_TO_USBDEV(sc), | |
1187 | "elsa download data failed (%d)\n", ret); | |
1188 | goto err1; | |
1189 | } | |
1190 | } | |
1191 | ||
1192 | /* finish to send the fpga | |
1193 | */ | |
1194 | ret = uea_request(sc, 0xe, 1, 0, NULL); | |
1195 | if (ret < 0) { | |
1196 | uea_err(INS_TO_USBDEV(sc), | |
1197 | "elsa download data failed (%d)\n", ret); | |
1198 | goto err1; | |
1199 | } | |
1200 | ||
1201 | /* | |
1202 | * Tell the modem we finish : de-assert reset | |
1203 | */ | |
1204 | value = 0; | |
1205 | ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value); | |
1206 | if (ret < 0) | |
1207 | uea_err(sc->usb_dev, "elsa de-assert failed with error %d\n", ret); | |
1208 | ||
1209 | ||
1210 | err1: | |
1211 | release_firmware(fw_entry); | |
1212 | err0: | |
1213 | uea_leaves(INS_TO_USBDEV(sc)); | |
1214 | return ret; | |
1215 | } | |
1216 | ||
1217 | static void uea_dispatch_cmv(struct uea_softc *sc, struct cmv* cmv) | |
1218 | { | |
1219 | uea_enters(INS_TO_USBDEV(sc)); | |
1220 | if (le16_to_cpu(cmv->wPreamble) != PREAMBLE) | |
1221 | goto bad1; | |
1222 | ||
1223 | if (cmv->bDirection != MODEMTOHOST) | |
1224 | goto bad1; | |
1225 | ||
1226 | /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to | |
1227 | * the first MEMACESS cmv. Ignore it... | |
1228 | */ | |
1229 | if (cmv->bFunction != sc->cmv_function) { | |
1230 | if (UEA_CHIP_VERSION(sc) == ADI930 | |
1231 | && cmv->bFunction == MAKEFUNCTION(2, 2)) { | |
1232 | cmv->wIndex = cpu_to_le16(sc->cmv_idx); | |
1233 | put_unaligned(cpu_to_le32(sc->cmv_address), &cmv->dwSymbolicAddress); | |
1234 | cmv->wOffsetAddress = cpu_to_le16(sc->cmv_offset); | |
1235 | } | |
1236 | else | |
1237 | goto bad2; | |
1238 | } | |
1239 | ||
1240 | if (cmv->bFunction == MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY)) { | |
1241 | wake_up_cmv_ack(sc); | |
1242 | return; | |
1243 | } | |
1244 | ||
1245 | /* in case of MEMACCESS */ | |
1246 | if (le16_to_cpu(cmv->wIndex) != sc->cmv_idx || | |
1247 | le32_to_cpu(get_unaligned(&cmv->dwSymbolicAddress)) != | |
1248 | sc->cmv_address | |
1249 | || le16_to_cpu(cmv->wOffsetAddress) != sc->cmv_offset) | |
1250 | goto bad2; | |
1251 | ||
1252 | sc->data = le32_to_cpu(get_unaligned(&cmv->dwData)); | |
1253 | sc->data = sc->data << 16 | sc->data >> 16; | |
1254 | ||
1255 | wake_up_cmv_ack(sc); | |
1256 | return; | |
1257 | ||
1258 | bad2: | |
1259 | uea_err(INS_TO_USBDEV(sc), "unexpected cmv received," | |
1260 | "Function : %d, Subfunction : %d\n", | |
1261 | FUNCTION_TYPE(cmv->bFunction), | |
1262 | FUNCTION_SUBTYPE(cmv->bFunction)); | |
1263 | return; | |
1264 | ||
1265 | bad1: | |
1266 | uea_err(INS_TO_USBDEV(sc), "invalid cmv received, " | |
1267 | "wPreamble %d, bDirection %d\n", | |
1268 | le16_to_cpu(cmv->wPreamble), cmv->bDirection); | |
1269 | } | |
1270 | ||
1271 | /* | |
1272 | * interrupt handler | |
1273 | */ | |
1274 | static void uea_intr(struct urb *urb, struct pt_regs *regs) | |
1275 | { | |
1276 | struct uea_softc *sc = (struct uea_softc *)urb->context; | |
1277 | struct intr_pkt *intr; | |
1278 | uea_enters(INS_TO_USBDEV(sc)); | |
1279 | ||
1280 | if (urb->status < 0) { | |
1281 | uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n", | |
1282 | urb->status); | |
1283 | return; | |
1284 | } | |
1285 | ||
1286 | intr = (struct intr_pkt *) urb->transfer_buffer; | |
1287 | ||
1288 | /* device-to-host interrupt */ | |
1289 | if (intr->bType != 0x08 || sc->booting) { | |
1290 | uea_err(INS_TO_USBDEV(sc), "wrong intr\n"); | |
1291 | // rebooting ? | |
1292 | // sc->reset = 1; | |
1293 | goto resubmit; | |
1294 | } | |
1295 | ||
1296 | switch (le16_to_cpu(intr->wInterrupt)) { | |
1297 | case INT_LOADSWAPPAGE: | |
1298 | sc->pageno = intr->bSwapPageNo; | |
1299 | sc->ovl = intr->bOvl >> 4 | intr->bOvl << 4; | |
1300 | schedule_work(&sc->task); | |
1301 | break; | |
1302 | ||
1303 | case INT_INCOMINGCMV: | |
1304 | uea_dispatch_cmv(sc, &intr->u.s2.cmv); | |
1305 | break; | |
1306 | ||
1307 | default: | |
1308 | uea_err(INS_TO_USBDEV(sc), "unknown intr %u\n", | |
1309 | le16_to_cpu(intr->wInterrupt)); | |
1310 | } | |
1311 | ||
1312 | resubmit: | |
1313 | usb_submit_urb(sc->urb_int, GFP_ATOMIC); | |
1314 | } | |
1315 | ||
1316 | /* | |
1317 | * Start the modem : init the data and start kernel thread | |
1318 | */ | |
1319 | static int uea_boot(struct uea_softc *sc) | |
1320 | { | |
1321 | int ret; | |
1322 | struct intr_pkt *intr; | |
1323 | ||
1324 | uea_enters(INS_TO_USBDEV(sc)); | |
1325 | ||
1326 | INIT_WORK(&sc->task, uea_load_page, sc); | |
1327 | init_waitqueue_head(&sc->sync_q); | |
1328 | init_waitqueue_head(&sc->cmv_ack_wait); | |
1329 | ||
1330 | if (UEA_CHIP_VERSION(sc) == ADI930) | |
1331 | load_XILINX_firmware(sc); | |
1332 | ||
1333 | intr = kmalloc(INTR_PKT_SIZE, GFP_KERNEL); | |
1334 | if (!intr) { | |
1335 | uea_err(INS_TO_USBDEV(sc), | |
1336 | "cannot allocate interrupt package\n"); | |
1337 | uea_leaves(INS_TO_USBDEV(sc)); | |
1338 | return -ENOMEM; | |
1339 | } | |
1340 | ||
1341 | sc->urb_int = usb_alloc_urb(0, GFP_KERNEL); | |
1342 | if (!sc->urb_int) { | |
1343 | uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n"); | |
1344 | goto err; | |
1345 | } | |
1346 | ||
1347 | usb_fill_int_urb(sc->urb_int, sc->usb_dev, | |
1348 | usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE), | |
1349 | intr, INTR_PKT_SIZE, uea_intr, sc, | |
1350 | sc->usb_dev->actconfig->interface[0]->altsetting[0]. | |
1351 | endpoint[0].desc.bInterval); | |
1352 | ||
1353 | ret = usb_submit_urb(sc->urb_int, GFP_KERNEL); | |
1354 | if (ret < 0) { | |
1355 | uea_err(INS_TO_USBDEV(sc), | |
1356 | "urb submition failed with error %d\n", ret); | |
1357 | goto err1; | |
1358 | } | |
1359 | ||
1360 | sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm"); | |
1361 | if (sc->kthread == ERR_PTR(-ENOMEM)) { | |
1362 | uea_err(INS_TO_USBDEV(sc), "failed to create thread\n"); | |
1363 | goto err2; | |
1364 | } | |
1365 | ||
1366 | uea_leaves(INS_TO_USBDEV(sc)); | |
1367 | return 0; | |
1368 | ||
1369 | err2: | |
1370 | usb_kill_urb(sc->urb_int); | |
1371 | err1: | |
1372 | kfree(intr); | |
1373 | err: | |
1374 | usb_free_urb(sc->urb_int); | |
1375 | uea_leaves(INS_TO_USBDEV(sc)); | |
1376 | return -ENOMEM; | |
1377 | } | |
1378 | ||
1379 | /* | |
1380 | * Stop the modem : kill kernel thread and free data | |
1381 | */ | |
1382 | static void uea_stop(struct uea_softc *sc) | |
1383 | { | |
1384 | int ret; | |
1385 | uea_enters(INS_TO_USBDEV(sc)); | |
1386 | ret = kthread_stop(sc->kthread); | |
1387 | uea_info(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret); | |
1388 | ||
1389 | /* stop any pending boot process */ | |
1390 | flush_scheduled_work(); | |
1391 | ||
1392 | uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL); | |
1393 | ||
1394 | usb_kill_urb(sc->urb_int); | |
1395 | kfree(sc->urb_int->transfer_buffer); | |
1396 | usb_free_urb(sc->urb_int); | |
1397 | ||
1398 | if (sc->dsp_firm) | |
1399 | release_firmware(sc->dsp_firm); | |
1400 | uea_leaves(INS_TO_USBDEV(sc)); | |
1401 | } | |
1402 | ||
1403 | /* syfs interface */ | |
1404 | static struct uea_softc *dev_to_uea(struct device *dev) | |
1405 | { | |
1406 | struct usb_interface *intf; | |
1407 | struct usbatm_data *usbatm; | |
1408 | ||
1409 | intf = to_usb_interface(dev); | |
1410 | if (!intf) | |
1411 | return NULL; | |
1412 | ||
1413 | usbatm = usb_get_intfdata(intf); | |
1414 | if (!usbatm) | |
1415 | return NULL; | |
1416 | ||
1417 | return usbatm->driver_data; | |
1418 | } | |
1419 | ||
1420 | static ssize_t read_status(struct device *dev, struct device_attribute *attr, | |
1421 | char *buf) | |
1422 | { | |
1423 | int ret = -ENODEV; | |
1424 | struct uea_softc *sc; | |
1425 | ||
ab3c81ff | 1426 | mutex_lock(&uea_mutex); |
b72458a8 | 1427 | sc = dev_to_uea(dev); |
1428 | if (!sc) | |
1429 | goto out; | |
1430 | ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state); | |
1431 | out: | |
ab3c81ff | 1432 | mutex_unlock(&uea_mutex); |
b72458a8 | 1433 | return ret; |
1434 | } | |
1435 | ||
1436 | static ssize_t reboot(struct device *dev, struct device_attribute *attr, | |
1437 | const char *buf, size_t count) | |
1438 | { | |
1439 | int ret = -ENODEV; | |
1440 | struct uea_softc *sc; | |
1441 | ||
ab3c81ff | 1442 | mutex_lock(&uea_mutex); |
b72458a8 | 1443 | sc = dev_to_uea(dev); |
1444 | if (!sc) | |
1445 | goto out; | |
1446 | sc->reset = 1; | |
1447 | ret = count; | |
1448 | out: | |
ab3c81ff | 1449 | mutex_unlock(&uea_mutex); |
b72458a8 | 1450 | return ret; |
1451 | } | |
1452 | ||
1453 | static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot); | |
1454 | ||
1455 | static ssize_t read_human_status(struct device *dev, struct device_attribute *attr, | |
1456 | char *buf) | |
1457 | { | |
1458 | int ret = -ENODEV; | |
1459 | struct uea_softc *sc; | |
1460 | ||
ab3c81ff | 1461 | mutex_lock(&uea_mutex); |
b72458a8 | 1462 | sc = dev_to_uea(dev); |
1463 | if (!sc) | |
1464 | goto out; | |
1465 | ||
1466 | switch (GET_STATUS(sc->stats.phy.state)) { | |
1467 | case 0: | |
1468 | ret = sprintf(buf, "Modem is booting\n"); | |
1469 | break; | |
1470 | case 1: | |
1471 | ret = sprintf(buf, "Modem is initializing\n"); | |
1472 | break; | |
1473 | case 2: | |
1474 | ret = sprintf(buf, "Modem is operational\n"); | |
1475 | break; | |
1476 | default: | |
1477 | ret = sprintf(buf, "Modem synchronization failed\n"); | |
1478 | break; | |
1479 | } | |
1480 | out: | |
ab3c81ff | 1481 | mutex_unlock(&uea_mutex); |
b72458a8 | 1482 | return ret; |
1483 | } | |
1484 | ||
1485 | static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, read_human_status, NULL); | |
1486 | ||
1487 | static ssize_t read_delin(struct device *dev, struct device_attribute *attr, | |
1488 | char *buf) | |
1489 | { | |
1490 | int ret = -ENODEV; | |
1491 | struct uea_softc *sc; | |
1492 | ||
ab3c81ff | 1493 | mutex_lock(&uea_mutex); |
b72458a8 | 1494 | sc = dev_to_uea(dev); |
1495 | if (!sc) | |
1496 | goto out; | |
1497 | ||
1498 | if (sc->stats.phy.flags & 0x0C00) | |
1499 | ret = sprintf(buf, "ERROR\n"); | |
1500 | else if (sc->stats.phy.flags & 0x0030) | |
1501 | ret = sprintf(buf, "LOSS\n"); | |
1502 | else | |
1503 | ret = sprintf(buf, "GOOD\n"); | |
1504 | out: | |
ab3c81ff | 1505 | mutex_unlock(&uea_mutex); |
b72458a8 | 1506 | return ret; |
1507 | } | |
1508 | ||
1509 | static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL); | |
1510 | ||
1511 | #define UEA_ATTR(name, reset) \ | |
1512 | \ | |
1513 | static ssize_t read_##name(struct device *dev, \ | |
1514 | struct device_attribute *attr, char *buf) \ | |
1515 | { \ | |
1516 | int ret = -ENODEV; \ | |
1517 | struct uea_softc *sc; \ | |
1518 | \ | |
ab3c81ff | 1519 | mutex_lock(&uea_mutex); \ |
b72458a8 | 1520 | sc = dev_to_uea(dev); \ |
1521 | if (!sc) \ | |
1522 | goto out; \ | |
1523 | ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \ | |
1524 | if (reset) \ | |
1525 | sc->stats.phy.name = 0; \ | |
1526 | out: \ | |
ab3c81ff | 1527 | mutex_unlock(&uea_mutex); \ |
b72458a8 | 1528 | return ret; \ |
1529 | } \ | |
1530 | \ | |
1531 | static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL) | |
1532 | ||
1533 | UEA_ATTR(mflags, 1); | |
1534 | UEA_ATTR(vidcpe, 0); | |
1535 | UEA_ATTR(usrate, 0); | |
1536 | UEA_ATTR(dsrate, 0); | |
1537 | UEA_ATTR(usattenuation, 0); | |
1538 | UEA_ATTR(dsattenuation, 0); | |
1539 | UEA_ATTR(usmargin, 0); | |
1540 | UEA_ATTR(dsmargin, 0); | |
1541 | UEA_ATTR(txflow, 0); | |
1542 | UEA_ATTR(rxflow, 0); | |
1543 | UEA_ATTR(uscorr, 0); | |
1544 | UEA_ATTR(dscorr, 0); | |
1545 | UEA_ATTR(usunc, 0); | |
1546 | UEA_ATTR(dsunc, 0); | |
1547 | ||
1548 | /* Retrieve the device End System Identifier (MAC) */ | |
1549 | ||
1550 | #define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10) | |
1551 | static int uea_getesi(struct uea_softc *sc, u_char * esi) | |
1552 | { | |
1553 | unsigned char mac_str[2 * ETH_ALEN + 1]; | |
1554 | int i; | |
1555 | if (usb_string | |
1556 | (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str, | |
1557 | sizeof(mac_str)) != 2 * ETH_ALEN) | |
1558 | return 1; | |
1559 | ||
1560 | for (i = 0; i < ETH_ALEN; i++) | |
1561 | esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]); | |
1562 | ||
1563 | return 0; | |
1564 | } | |
1565 | ||
1566 | /* ATM stuff */ | |
1567 | static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev) | |
1568 | { | |
1569 | struct uea_softc *sc = usbatm->driver_data; | |
1570 | ||
1571 | return uea_getesi(sc, atm_dev->esi); | |
1572 | } | |
1573 | ||
1574 | static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf) | |
1575 | { | |
1576 | struct uea_softc *sc = usbatm->driver_data; | |
1577 | ||
1578 | wait_event(sc->sync_q, IS_OPERATIONAL(sc)); | |
1579 | ||
1580 | return 0; | |
1581 | ||
1582 | } | |
1583 | ||
1584 | static int claim_interface(struct usb_device *usb_dev, | |
1585 | struct usbatm_data *usbatm, int ifnum) | |
1586 | { | |
1587 | int ret; | |
1588 | struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum); | |
1589 | ||
1590 | if (!intf) { | |
1591 | uea_err(usb_dev, "interface %d not found\n", ifnum); | |
1592 | return -ENODEV; | |
1593 | } | |
1594 | ||
1595 | ret = usb_driver_claim_interface(&uea_driver, intf, usbatm); | |
1596 | if (ret != 0) | |
1597 | uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum, | |
1598 | ret); | |
1599 | return ret; | |
1600 | } | |
1601 | ||
1602 | static void create_fs_entries(struct uea_softc *sc, struct usb_interface *intf) | |
1603 | { | |
1604 | /* sysfs interface */ | |
1605 | device_create_file(&intf->dev, &dev_attr_stat_status); | |
1606 | device_create_file(&intf->dev, &dev_attr_stat_mflags); | |
1607 | device_create_file(&intf->dev, &dev_attr_stat_human_status); | |
1608 | device_create_file(&intf->dev, &dev_attr_stat_delin); | |
1609 | device_create_file(&intf->dev, &dev_attr_stat_vidcpe); | |
1610 | device_create_file(&intf->dev, &dev_attr_stat_usrate); | |
1611 | device_create_file(&intf->dev, &dev_attr_stat_dsrate); | |
1612 | device_create_file(&intf->dev, &dev_attr_stat_usattenuation); | |
1613 | device_create_file(&intf->dev, &dev_attr_stat_dsattenuation); | |
1614 | device_create_file(&intf->dev, &dev_attr_stat_usmargin); | |
1615 | device_create_file(&intf->dev, &dev_attr_stat_dsmargin); | |
1616 | device_create_file(&intf->dev, &dev_attr_stat_txflow); | |
1617 | device_create_file(&intf->dev, &dev_attr_stat_rxflow); | |
1618 | device_create_file(&intf->dev, &dev_attr_stat_uscorr); | |
1619 | device_create_file(&intf->dev, &dev_attr_stat_dscorr); | |
1620 | device_create_file(&intf->dev, &dev_attr_stat_usunc); | |
1621 | device_create_file(&intf->dev, &dev_attr_stat_dsunc); | |
1622 | } | |
1623 | ||
1624 | static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf, | |
35644b0c | 1625 | const struct usb_device_id *id) |
b72458a8 | 1626 | { |
1627 | struct usb_device *usb = interface_to_usbdev(intf); | |
1628 | struct uea_softc *sc; | |
1629 | int ret, ifnum = intf->altsetting->desc.bInterfaceNumber; | |
1630 | ||
1631 | uea_enters(usb); | |
1632 | ||
1633 | /* interface 0 is for firmware/monitoring */ | |
1634 | if (ifnum != UEA_INTR_IFACE_NO) | |
1635 | return -ENODEV; | |
1636 | ||
0dfcd3e4 | 1637 | usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT); |
b72458a8 | 1638 | |
1639 | /* interface 1 is for outbound traffic */ | |
1640 | ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO); | |
1641 | if (ret < 0) | |
1642 | return ret; | |
1643 | ||
1644 | /* ADI930 has only 2 interfaces and inbound traffic | |
1645 | * is on interface 1 | |
1646 | */ | |
1647 | if (UEA_CHIP_VERSION(id) != ADI930) { | |
1648 | /* interface 2 is for inbound traffic */ | |
1649 | ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO); | |
1650 | if (ret < 0) | |
1651 | return ret; | |
1652 | } | |
1653 | ||
1654 | sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL); | |
1655 | if (!sc) { | |
1656 | uea_err(INS_TO_USBDEV(sc), "uea_init: not enough memory !\n"); | |
1657 | return -ENOMEM; | |
1658 | } | |
1659 | ||
1660 | sc->usb_dev = usb; | |
1661 | usbatm->driver_data = sc; | |
1662 | sc->usbatm = usbatm; | |
1663 | sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0; | |
1664 | sc->driver_info = id->driver_info; | |
1665 | ||
3c9666cc | 1666 | /* ADI930 don't support iso */ |
1667 | if (UEA_CHIP_VERSION(id) != ADI930 && use_iso[sc->modem_index]) { | |
1668 | int i; | |
1669 | ||
1670 | /* try set fastest alternate for inbound traffic interface */ | |
1671 | for (i = FASTEST_ISO_INTF; i > 0; i--) | |
1672 | if (usb_set_interface(usb, UEA_DS_IFACE_NO, i) == 0) | |
1673 | break; | |
1674 | ||
1675 | if (i > 0) { | |
1676 | uea_dbg(usb, "set alternate %d for 2 interface\n", i); | |
1677 | uea_info(usb, "using iso mode\n"); | |
1678 | usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ; | |
1679 | } else { | |
1680 | uea_err(usb, "setting any alternate failed for " | |
1681 | "2 interface, using bulk mode\n"); | |
1682 | } | |
1683 | } | |
1684 | ||
b72458a8 | 1685 | ret = uea_boot(sc); |
1686 | if (ret < 0) { | |
1687 | kfree(sc); | |
1688 | return ret; | |
1689 | } | |
1690 | ||
1691 | create_fs_entries(sc, intf); | |
1692 | return 0; | |
1693 | } | |
1694 | ||
1695 | static void destroy_fs_entries(struct uea_softc *sc, struct usb_interface *intf) | |
1696 | { | |
1697 | /* sysfs interface */ | |
1698 | device_remove_file(&intf->dev, &dev_attr_stat_status); | |
1699 | device_remove_file(&intf->dev, &dev_attr_stat_mflags); | |
1700 | device_remove_file(&intf->dev, &dev_attr_stat_human_status); | |
1701 | device_remove_file(&intf->dev, &dev_attr_stat_delin); | |
1702 | device_remove_file(&intf->dev, &dev_attr_stat_vidcpe); | |
1703 | device_remove_file(&intf->dev, &dev_attr_stat_usrate); | |
1704 | device_remove_file(&intf->dev, &dev_attr_stat_dsrate); | |
1705 | device_remove_file(&intf->dev, &dev_attr_stat_usattenuation); | |
1706 | device_remove_file(&intf->dev, &dev_attr_stat_dsattenuation); | |
1707 | device_remove_file(&intf->dev, &dev_attr_stat_usmargin); | |
1708 | device_remove_file(&intf->dev, &dev_attr_stat_dsmargin); | |
1709 | device_remove_file(&intf->dev, &dev_attr_stat_txflow); | |
1710 | device_remove_file(&intf->dev, &dev_attr_stat_rxflow); | |
1711 | device_remove_file(&intf->dev, &dev_attr_stat_uscorr); | |
1712 | device_remove_file(&intf->dev, &dev_attr_stat_dscorr); | |
1713 | device_remove_file(&intf->dev, &dev_attr_stat_usunc); | |
1714 | device_remove_file(&intf->dev, &dev_attr_stat_dsunc); | |
1715 | } | |
1716 | ||
1717 | static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf) | |
1718 | { | |
1719 | struct uea_softc *sc = usbatm->driver_data; | |
1720 | ||
1721 | destroy_fs_entries(sc, intf); | |
1722 | uea_stop(sc); | |
1723 | kfree(sc); | |
1724 | } | |
1725 | ||
1726 | static struct usbatm_driver uea_usbatm_driver = { | |
1727 | .driver_name = "ueagle-atm", | |
b72458a8 | 1728 | .bind = uea_bind, |
1729 | .atm_start = uea_atm_open, | |
1730 | .unbind = uea_unbind, | |
1731 | .heavy_init = uea_heavy, | |
80aae7a1 DS |
1732 | .bulk_in = UEA_BULK_DATA_PIPE, |
1733 | .bulk_out = UEA_BULK_DATA_PIPE, | |
3c9666cc | 1734 | .isoc_in = UEA_ISO_DATA_PIPE, |
b72458a8 | 1735 | }; |
1736 | ||
1737 | static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id) | |
1738 | { | |
1739 | struct usb_device *usb = interface_to_usbdev(intf); | |
1740 | ||
1741 | uea_enters(usb); | |
1742 | uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) : %s\n", | |
1743 | le16_to_cpu(usb->descriptor.idVendor), | |
1744 | le16_to_cpu(usb->descriptor.idProduct), | |
1745 | chip_name[UEA_CHIP_VERSION(id)]); | |
1746 | ||
1747 | usb_reset_device(usb); | |
1748 | ||
1749 | if (UEA_IS_PREFIRM(id)) | |
1750 | return uea_load_firmware(usb, UEA_CHIP_VERSION(id)); | |
1751 | ||
1752 | return usbatm_usb_probe(intf, id, &uea_usbatm_driver); | |
1753 | } | |
1754 | ||
1755 | static void uea_disconnect(struct usb_interface *intf) | |
1756 | { | |
1757 | struct usb_device *usb = interface_to_usbdev(intf); | |
1758 | int ifnum = intf->altsetting->desc.bInterfaceNumber; | |
1759 | uea_enters(usb); | |
1760 | ||
1761 | /* ADI930 has 2 interfaces and eagle 3 interfaces. | |
1762 | * Pre-firmware device has one interface | |
1763 | */ | |
1764 | if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) { | |
ab3c81ff | 1765 | mutex_lock(&uea_mutex); |
b72458a8 | 1766 | usbatm_usb_disconnect(intf); |
ab3c81ff | 1767 | mutex_unlock(&uea_mutex); |
b72458a8 | 1768 | uea_info(usb, "ADSL device removed\n"); |
1769 | } | |
1770 | ||
1771 | uea_leaves(usb); | |
1772 | } | |
1773 | ||
1774 | /* | |
1775 | * List of supported VID/PID | |
1776 | */ | |
1777 | static const struct usb_device_id uea_ids[] = { | |
1778 | {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM), .driver_info = ADI930 | PREFIRM}, | |
1779 | {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM}, | |
1780 | {USB_DEVICE(EAGLE_VID, EAGLE_I_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM}, | |
1781 | {USB_DEVICE(EAGLE_VID, EAGLE_I_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM}, | |
1782 | {USB_DEVICE(EAGLE_VID, EAGLE_II_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM}, | |
1783 | {USB_DEVICE(EAGLE_VID, EAGLE_II_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM}, | |
1784 | {USB_DEVICE(EAGLE_VID, EAGLE_IIC_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM}, | |
1785 | {USB_DEVICE(EAGLE_VID, EAGLE_IIC_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM}, | |
1786 | {USB_DEVICE(EAGLE_VID, EAGLE_III_PID_PREFIRM), .driver_info = EAGLE_III | PREFIRM}, | |
1787 | {USB_DEVICE(EAGLE_VID, EAGLE_III_PID_PSTFIRM), .driver_info = EAGLE_III | PSTFIRM}, | |
1788 | {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM}, | |
1789 | {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM}, | |
1790 | {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM}, | |
1791 | {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM}, | |
1792 | {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM}, | |
1793 | {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM}, | |
1794 | {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM}, | |
1795 | {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM}, | |
1796 | {} | |
1797 | }; | |
1798 | ||
1799 | /* | |
1800 | * USB driver descriptor | |
1801 | */ | |
1802 | static struct usb_driver uea_driver = { | |
b72458a8 | 1803 | .name = "ueagle-atm", |
1804 | .id_table = uea_ids, | |
1805 | .probe = uea_probe, | |
1806 | .disconnect = uea_disconnect, | |
1807 | }; | |
1808 | ||
1809 | MODULE_DEVICE_TABLE(usb, uea_ids); | |
1810 | ||
1811 | /** | |
1812 | * uea_init - Initialize the module. | |
1813 | * Register to USB subsystem | |
1814 | */ | |
1815 | static int __init uea_init(void) | |
1816 | { | |
1817 | printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n"); | |
1818 | ||
1819 | usb_register(&uea_driver); | |
1820 | ||
1821 | return 0; | |
1822 | } | |
1823 | ||
1824 | module_init(uea_init); | |
1825 | ||
1826 | /** | |
1827 | * uea_exit - Destroy module | |
1828 | * Deregister with USB subsystem | |
1829 | */ | |
1830 | static void __exit uea_exit(void) | |
1831 | { | |
1832 | /* | |
1833 | * This calls automatically the uea_disconnect method if necessary: | |
1834 | */ | |
1835 | usb_deregister(&uea_driver); | |
1836 | ||
1837 | printk(KERN_INFO "[ueagle-atm] driver unloaded\n"); | |
1838 | } | |
1839 | ||
1840 | module_exit(uea_exit); | |
1841 | ||
1842 | MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka"); | |
1843 | MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver"); | |
1844 | MODULE_LICENSE("Dual BSD/GPL"); |