| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 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> | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 66 | #include <linux/mutex.h> | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 67 | #include <asm/unaligned.h> | 
|  | 68 |  | 
|  | 69 | #include "usbatm.h" | 
|  | 70 |  | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 71 | #define EAGLEUSBVERSION "ueagle 1.3" | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 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 |  | 
| matthieu castet | 22fcceb | 2006-04-02 18:44:20 +0200 | [diff] [blame] | 246 | #define ACK_TIMEOUT msecs_to_jiffies(3000) | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 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)) | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 317 | #define GETSA1(a) ((a >> 8) & 0xff) | 
|  | 318 | #define GETSA2(a) (a & 0xff) | 
|  | 319 | #define GETSA3(a) ((a >> 24) & 0xff) | 
|  | 320 | #define GETSA4(a) ((a >> 16) & 0xff) | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 321 |  | 
|  | 322 | #define SA_CNTL MAKESA('C', 'N', 'T', 'L') | 
|  | 323 | #define SA_DIAG MAKESA('D', 'I', 'A', 'G') | 
|  | 324 | #define SA_INFO MAKESA('I', 'N', 'F', 'O') | 
|  | 325 | #define SA_OPTN MAKESA('O', 'P', 'T', 'N') | 
|  | 326 | #define SA_RATE MAKESA('R', 'A', 'T', 'E') | 
|  | 327 | #define SA_STAT MAKESA('S', 'T', 'A', 'T') | 
|  | 328 | __le16 wOffsetAddress; | 
|  | 329 | __le32 dwData; | 
|  | 330 | } __attribute__ ((packed)); | 
|  | 331 | #define CMV_SIZE 16 | 
|  | 332 |  | 
|  | 333 | /* structure representing swap information */ | 
|  | 334 | struct swap_info { | 
|  | 335 | __u8 bSwapPageNo; | 
|  | 336 | __u8 bOvl;		/* overlay */ | 
|  | 337 | } __attribute__ ((packed)); | 
|  | 338 |  | 
|  | 339 | /* structure representing interrupt data */ | 
|  | 340 | struct intr_pkt { | 
|  | 341 | __u8 bType; | 
|  | 342 | __u8 bNotification; | 
|  | 343 | __le16 wValue; | 
|  | 344 | __le16 wIndex; | 
|  | 345 | __le16 wLength; | 
|  | 346 | __le16 wInterrupt; | 
|  | 347 | #define INT_LOADSWAPPAGE 0x0001 | 
|  | 348 | #define INT_INCOMINGCMV  0x0002 | 
|  | 349 | union { | 
|  | 350 | struct { | 
|  | 351 | struct swap_info swapinfo; | 
|  | 352 | __le16 wDataSize; | 
|  | 353 | } __attribute__ ((packed)) s1; | 
|  | 354 |  | 
|  | 355 | struct { | 
|  | 356 | struct cmv cmv; | 
|  | 357 | __le16 wDataSize; | 
|  | 358 | } __attribute__ ((packed)) s2; | 
|  | 359 | } __attribute__ ((packed)) u; | 
|  | 360 | #define bSwapPageNo	u.s1.swapinfo.bSwapPageNo | 
|  | 361 | #define bOvl		u.s1.swapinfo.bOvl | 
|  | 362 | } __attribute__ ((packed)); | 
|  | 363 | #define INTR_PKT_SIZE 28 | 
|  | 364 |  | 
|  | 365 | static struct usb_driver uea_driver; | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 366 | static DEFINE_MUTEX(uea_mutex); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 367 | static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III"}; | 
|  | 368 |  | 
|  | 369 | static int modem_index; | 
|  | 370 | static unsigned int debug; | 
| matthieu castet | 3c9666c | 2006-01-18 07:38:19 +0100 | [diff] [blame] | 371 | static int use_iso[NB_MODEM] = {[0 ... (NB_MODEM - 1)] = 1}; | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 372 | static int sync_wait[NB_MODEM]; | 
|  | 373 | static char *cmv_file[NB_MODEM]; | 
|  | 374 |  | 
|  | 375 | module_param(debug, uint, 0644); | 
|  | 376 | MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)"); | 
| matthieu castet | 3c9666c | 2006-01-18 07:38:19 +0100 | [diff] [blame] | 377 | module_param_array(use_iso, bool, NULL, 0644); | 
|  | 378 | MODULE_PARM_DESC(use_iso, "use isochronous usb pipe for incoming traffic"); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 379 | module_param_array(sync_wait, bool, NULL, 0644); | 
|  | 380 | MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM"); | 
|  | 381 | module_param_array(cmv_file, charp, NULL, 0644); | 
|  | 382 | MODULE_PARM_DESC(cmv_file, | 
|  | 383 | "file name with configuration and management variables"); | 
|  | 384 |  | 
|  | 385 | #define UPDATE_ATM_STAT(type, val) \ | 
|  | 386 | do { \ | 
|  | 387 | if (sc->usbatm->atm_dev) \ | 
|  | 388 | sc->usbatm->atm_dev->type = val; \ | 
|  | 389 | } while (0) | 
|  | 390 |  | 
|  | 391 | /* Firmware loading */ | 
|  | 392 | #define LOAD_INTERNAL     0xA0 | 
|  | 393 | #define F8051_USBCS       0x7f92 | 
|  | 394 |  | 
|  | 395 | /** | 
|  | 396 | * uea_send_modem_cmd - Send a command for pre-firmware devices. | 
|  | 397 | */ | 
|  | 398 | static int uea_send_modem_cmd(struct usb_device *usb, | 
|  | 399 | u16 addr, u16 size, u8 * buff) | 
|  | 400 | { | 
|  | 401 | int ret = -ENOMEM; | 
|  | 402 | u8 *xfer_buff; | 
|  | 403 |  | 
|  | 404 | xfer_buff = kmalloc(size, GFP_KERNEL); | 
|  | 405 | if (xfer_buff) { | 
|  | 406 | memcpy(xfer_buff, buff, size); | 
|  | 407 | ret = usb_control_msg(usb, | 
|  | 408 | usb_sndctrlpipe(usb, 0), | 
|  | 409 | LOAD_INTERNAL, | 
|  | 410 | USB_DIR_OUT | USB_TYPE_VENDOR | | 
|  | 411 | USB_RECIP_DEVICE, addr, 0, xfer_buff, | 
|  | 412 | size, CTRL_TIMEOUT); | 
|  | 413 | kfree(xfer_buff); | 
|  | 414 | } | 
|  | 415 |  | 
|  | 416 | if (ret < 0) | 
|  | 417 | return ret; | 
|  | 418 |  | 
|  | 419 | return (ret == size) ? 0 : -EIO; | 
|  | 420 | } | 
|  | 421 |  | 
|  | 422 | static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *context) | 
|  | 423 | { | 
|  | 424 | struct usb_device *usb = context; | 
|  | 425 | u8 *pfw, value; | 
|  | 426 | u32 crc = 0; | 
|  | 427 | int ret, size; | 
|  | 428 |  | 
|  | 429 | uea_enters(usb); | 
|  | 430 | if (!fw_entry) { | 
|  | 431 | uea_err(usb, "firmware is not available\n"); | 
|  | 432 | goto err; | 
|  | 433 | } | 
|  | 434 |  | 
|  | 435 | pfw = fw_entry->data; | 
|  | 436 | size = fw_entry->size; | 
| matthieu castet | 8d7802e | 2005-11-08 00:02:30 +0100 | [diff] [blame] | 437 | if (size < 4) | 
|  | 438 | goto err_fw_corrupted; | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 439 |  | 
|  | 440 | crc = FW_GET_LONG(pfw); | 
|  | 441 | pfw += 4; | 
|  | 442 | size -= 4; | 
| matthieu castet | 8d7802e | 2005-11-08 00:02:30 +0100 | [diff] [blame] | 443 | if (crc32_be(0, pfw, size) != crc) | 
|  | 444 | goto err_fw_corrupted; | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 445 |  | 
|  | 446 | /* | 
|  | 447 | * Start to upload formware : send reset | 
|  | 448 | */ | 
|  | 449 | value = 1; | 
|  | 450 | ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value); | 
|  | 451 |  | 
|  | 452 | if (ret < 0) { | 
|  | 453 | uea_err(usb, "modem reset failed with error %d\n", ret); | 
|  | 454 | goto err; | 
|  | 455 | } | 
|  | 456 |  | 
| matthieu castet | 8d7802e | 2005-11-08 00:02:30 +0100 | [diff] [blame] | 457 | while (size > 3) { | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 458 | u8 len = FW_GET_BYTE(pfw); | 
|  | 459 | u16 add = FW_GET_WORD(pfw + 1); | 
| matthieu castet | 8d7802e | 2005-11-08 00:02:30 +0100 | [diff] [blame] | 460 |  | 
|  | 461 | size -= len + 3; | 
|  | 462 | if (size < 0) | 
|  | 463 | goto err_fw_corrupted; | 
|  | 464 |  | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 465 | ret = uea_send_modem_cmd(usb, add, len, pfw + 3); | 
|  | 466 | if (ret < 0) { | 
|  | 467 | uea_err(usb, "uploading firmware data failed " | 
|  | 468 | "with error %d\n", ret); | 
|  | 469 | goto err; | 
|  | 470 | } | 
|  | 471 | pfw += len + 3; | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 472 | } | 
|  | 473 |  | 
| matthieu castet | 8d7802e | 2005-11-08 00:02:30 +0100 | [diff] [blame] | 474 | if (size != 0) | 
|  | 475 | goto err_fw_corrupted; | 
|  | 476 |  | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 477 | /* | 
|  | 478 | * Tell the modem we finish : de-assert reset | 
|  | 479 | */ | 
|  | 480 | value = 0; | 
|  | 481 | ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value); | 
|  | 482 | if (ret < 0) | 
|  | 483 | uea_err(usb, "modem de-assert failed with error %d\n", ret); | 
|  | 484 | else | 
|  | 485 | uea_info(usb, "firmware uploaded\n"); | 
|  | 486 |  | 
| matthieu castet | 8d7802e | 2005-11-08 00:02:30 +0100 | [diff] [blame] | 487 | uea_leaves(usb); | 
|  | 488 | return; | 
|  | 489 |  | 
|  | 490 | err_fw_corrupted: | 
|  | 491 | uea_err(usb, "firmware is corrupted\n"); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 492 | err: | 
|  | 493 | uea_leaves(usb); | 
|  | 494 | } | 
|  | 495 |  | 
|  | 496 | /** | 
|  | 497 | * uea_load_firmware - Load usb firmware for pre-firmware devices. | 
|  | 498 | */ | 
|  | 499 | static int uea_load_firmware(struct usb_device *usb, unsigned int ver) | 
|  | 500 | { | 
|  | 501 | int ret; | 
|  | 502 | char *fw_name = FW_DIR "eagle.fw"; | 
|  | 503 |  | 
|  | 504 | uea_enters(usb); | 
|  | 505 | uea_info(usb, "pre-firmware device, uploading firmware\n"); | 
|  | 506 |  | 
|  | 507 | switch (ver) { | 
|  | 508 | case ADI930: | 
|  | 509 | fw_name = FW_DIR "adi930.fw"; | 
|  | 510 | break; | 
|  | 511 | case EAGLE_I: | 
|  | 512 | fw_name = FW_DIR "eagleI.fw"; | 
|  | 513 | break; | 
|  | 514 | case EAGLE_II: | 
|  | 515 | fw_name = FW_DIR "eagleII.fw"; | 
|  | 516 | break; | 
|  | 517 | case EAGLE_III: | 
|  | 518 | fw_name = FW_DIR "eagleIII.fw"; | 
|  | 519 | break; | 
|  | 520 | } | 
|  | 521 |  | 
|  | 522 | ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware); | 
|  | 523 | if (ret) | 
|  | 524 | uea_err(usb, "firmware %s is not available\n", fw_name); | 
|  | 525 | else | 
|  | 526 | uea_info(usb, "loading firmware %s\n", fw_name); | 
|  | 527 |  | 
|  | 528 | uea_leaves(usb); | 
|  | 529 | return ret; | 
|  | 530 | } | 
|  | 531 |  | 
|  | 532 | /* modem management : dsp firmware, send/read CMV, monitoring statistic | 
|  | 533 | */ | 
|  | 534 |  | 
|  | 535 | /* | 
|  | 536 | * Make sure that the DSP code provided is safe to use. | 
|  | 537 | */ | 
|  | 538 | static int check_dsp(u8 *dsp, unsigned int len) | 
|  | 539 | { | 
|  | 540 | u8 pagecount, blockcount; | 
|  | 541 | u16 blocksize; | 
|  | 542 | u32 pageoffset; | 
|  | 543 | unsigned int i, j, p, pp; | 
|  | 544 |  | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 545 | pagecount = FW_GET_BYTE(dsp); | 
|  | 546 | p = 1; | 
|  | 547 |  | 
|  | 548 | /* enough space for page offsets? */ | 
|  | 549 | if (p + 4 * pagecount > len) | 
|  | 550 | return 1; | 
|  | 551 |  | 
|  | 552 | for (i = 0; i < pagecount; i++) { | 
|  | 553 |  | 
|  | 554 | pageoffset = FW_GET_LONG(dsp + p); | 
|  | 555 | p += 4; | 
|  | 556 |  | 
|  | 557 | if (pageoffset == 0) | 
|  | 558 | continue; | 
|  | 559 |  | 
|  | 560 | /* enough space for blockcount? */ | 
|  | 561 | if (pageoffset >= len) | 
|  | 562 | return 1; | 
|  | 563 |  | 
|  | 564 | pp = pageoffset; | 
|  | 565 | blockcount = FW_GET_BYTE(dsp + pp); | 
|  | 566 | pp += 1; | 
|  | 567 |  | 
|  | 568 | for (j = 0; j < blockcount; j++) { | 
|  | 569 |  | 
|  | 570 | /* enough space for block header? */ | 
|  | 571 | if (pp + 4 > len) | 
|  | 572 | return 1; | 
|  | 573 |  | 
|  | 574 | pp += 2;	/* skip blockaddr */ | 
|  | 575 | blocksize = FW_GET_WORD(dsp + pp); | 
|  | 576 | pp += 2; | 
|  | 577 |  | 
|  | 578 | /* enough space for block data? */ | 
|  | 579 | if (pp + blocksize > len) | 
|  | 580 | return 1; | 
|  | 581 |  | 
|  | 582 | pp += blocksize; | 
|  | 583 | } | 
|  | 584 | } | 
|  | 585 |  | 
|  | 586 | return 0; | 
|  | 587 | } | 
|  | 588 |  | 
|  | 589 | /* | 
|  | 590 | * send data to the idma pipe | 
|  | 591 | * */ | 
|  | 592 | static int uea_idma_write(struct uea_softc *sc, void *data, u32 size) | 
|  | 593 | { | 
|  | 594 | int ret = -ENOMEM; | 
|  | 595 | u8 *xfer_buff; | 
|  | 596 | int bytes_read; | 
|  | 597 |  | 
|  | 598 | xfer_buff = kmalloc(size, GFP_KERNEL); | 
|  | 599 | if (!xfer_buff) { | 
|  | 600 | uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n"); | 
|  | 601 | return ret; | 
|  | 602 | } | 
|  | 603 |  | 
|  | 604 | memcpy(xfer_buff, data, size); | 
|  | 605 |  | 
|  | 606 | ret = usb_bulk_msg(sc->usb_dev, | 
|  | 607 | usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE), | 
|  | 608 | xfer_buff, size, &bytes_read, BULK_TIMEOUT); | 
|  | 609 |  | 
|  | 610 | kfree(xfer_buff); | 
|  | 611 | if (ret < 0) | 
|  | 612 | return ret; | 
|  | 613 | if (size != bytes_read) { | 
|  | 614 | uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size, | 
|  | 615 | bytes_read); | 
|  | 616 | return -EIO; | 
|  | 617 | } | 
|  | 618 |  | 
|  | 619 | return 0; | 
|  | 620 | } | 
|  | 621 |  | 
|  | 622 | static int request_dsp(struct uea_softc *sc) | 
|  | 623 | { | 
|  | 624 | int ret; | 
|  | 625 | char *dsp_name; | 
|  | 626 |  | 
|  | 627 | if (UEA_CHIP_VERSION(sc) == ADI930) { | 
|  | 628 | if (IS_ISDN(sc)) | 
|  | 629 | dsp_name = FW_DIR "DSP9i.bin"; | 
|  | 630 | else | 
|  | 631 | dsp_name = FW_DIR "DSP9p.bin"; | 
|  | 632 | } else { | 
|  | 633 | if (IS_ISDN(sc)) | 
|  | 634 | dsp_name = FW_DIR "DSPei.bin"; | 
|  | 635 | else | 
|  | 636 | dsp_name = FW_DIR "DSPep.bin"; | 
|  | 637 | } | 
|  | 638 |  | 
| matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 639 | ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 640 | if (ret < 0) { | 
|  | 641 | uea_err(INS_TO_USBDEV(sc), | 
|  | 642 | "requesting firmware %s failed with error %d\n", | 
|  | 643 | dsp_name, ret); | 
|  | 644 | return ret; | 
|  | 645 | } | 
|  | 646 |  | 
|  | 647 | if (check_dsp(sc->dsp_firm->data, sc->dsp_firm->size)) { | 
|  | 648 | uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", | 
|  | 649 | dsp_name); | 
|  | 650 | release_firmware(sc->dsp_firm); | 
|  | 651 | sc->dsp_firm = NULL; | 
|  | 652 | return -EILSEQ; | 
|  | 653 | } | 
|  | 654 |  | 
|  | 655 | return 0; | 
|  | 656 | } | 
|  | 657 |  | 
|  | 658 | /* | 
|  | 659 | * The uea_load_page() function must be called within a process context | 
|  | 660 | */ | 
|  | 661 | static void uea_load_page(void *xsc) | 
|  | 662 | { | 
|  | 663 | struct uea_softc *sc = xsc; | 
|  | 664 | u16 pageno = sc->pageno; | 
|  | 665 | u16 ovl = sc->ovl; | 
|  | 666 | struct block_info bi; | 
|  | 667 |  | 
|  | 668 | u8 *p; | 
|  | 669 | u8 pagecount, blockcount; | 
|  | 670 | u16 blockaddr, blocksize; | 
|  | 671 | u32 pageoffset; | 
|  | 672 | int i; | 
|  | 673 |  | 
|  | 674 | /* reload firmware when reboot start and it's loaded already */ | 
|  | 675 | if (ovl == 0 && pageno == 0 && sc->dsp_firm) { | 
|  | 676 | release_firmware(sc->dsp_firm); | 
|  | 677 | sc->dsp_firm = NULL; | 
|  | 678 | } | 
|  | 679 |  | 
|  | 680 | if (sc->dsp_firm == NULL && request_dsp(sc) < 0) | 
|  | 681 | return; | 
|  | 682 |  | 
|  | 683 | p = sc->dsp_firm->data; | 
|  | 684 | pagecount = FW_GET_BYTE(p); | 
|  | 685 | p += 1; | 
|  | 686 |  | 
|  | 687 | if (pageno >= pagecount) | 
|  | 688 | goto bad1; | 
|  | 689 |  | 
|  | 690 | p += 4 * pageno; | 
|  | 691 | pageoffset = FW_GET_LONG(p); | 
|  | 692 |  | 
|  | 693 | if (pageoffset == 0) | 
|  | 694 | goto bad1; | 
|  | 695 |  | 
|  | 696 | p = sc->dsp_firm->data + pageoffset; | 
|  | 697 | blockcount = FW_GET_BYTE(p); | 
|  | 698 | p += 1; | 
|  | 699 |  | 
|  | 700 | uea_dbg(INS_TO_USBDEV(sc), | 
|  | 701 | "sending %u blocks for DSP page %u\n", blockcount, pageno); | 
|  | 702 |  | 
|  | 703 | bi.wHdr = cpu_to_le16(UEA_BIHDR); | 
|  | 704 | bi.wOvl = cpu_to_le16(ovl); | 
|  | 705 | bi.wOvlOffset = cpu_to_le16(ovl | 0x8000); | 
|  | 706 |  | 
|  | 707 | for (i = 0; i < blockcount; i++) { | 
|  | 708 | blockaddr = FW_GET_WORD(p); | 
|  | 709 | p += 2; | 
|  | 710 |  | 
|  | 711 | blocksize = FW_GET_WORD(p); | 
|  | 712 | p += 2; | 
|  | 713 |  | 
|  | 714 | bi.wSize = cpu_to_le16(blocksize); | 
|  | 715 | bi.wAddress = cpu_to_le16(blockaddr); | 
|  | 716 | bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0); | 
|  | 717 |  | 
|  | 718 | /* send block info through the IDMA pipe */ | 
|  | 719 | if (uea_idma_write(sc, &bi, BLOCK_INFO_SIZE)) | 
|  | 720 | goto bad2; | 
|  | 721 |  | 
|  | 722 | /* send block data through the IDMA pipe */ | 
|  | 723 | if (uea_idma_write(sc, p, blocksize)) | 
|  | 724 | goto bad2; | 
|  | 725 |  | 
|  | 726 | p += blocksize; | 
|  | 727 | } | 
|  | 728 |  | 
|  | 729 | return; | 
|  | 730 |  | 
|  | 731 | bad2: | 
|  | 732 | uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i); | 
|  | 733 | return; | 
|  | 734 | bad1: | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 735 | uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 736 | } | 
|  | 737 |  | 
|  | 738 | static inline void wake_up_cmv_ack(struct uea_softc *sc) | 
|  | 739 | { | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 740 | BUG_ON(sc->cmv_ack); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 741 | sc->cmv_ack = 1; | 
|  | 742 | wake_up(&sc->cmv_ack_wait); | 
|  | 743 | } | 
|  | 744 |  | 
|  | 745 | static inline int wait_cmv_ack(struct uea_softc *sc) | 
|  | 746 | { | 
|  | 747 | int ret = wait_event_timeout(sc->cmv_ack_wait, | 
|  | 748 | sc->cmv_ack, ACK_TIMEOUT); | 
|  | 749 | sc->cmv_ack = 0; | 
|  | 750 |  | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 751 | uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n", | 
|  | 752 | jiffies_to_msecs(ret)); | 
|  | 753 |  | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 754 | if (ret < 0) | 
|  | 755 | return ret; | 
|  | 756 |  | 
|  | 757 | return (ret == 0) ? -ETIMEDOUT : 0; | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 758 | } | 
|  | 759 |  | 
|  | 760 | #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00 | 
|  | 761 |  | 
|  | 762 | static int uea_request(struct uea_softc *sc, | 
|  | 763 | u16 value, u16 index, u16 size, void *data) | 
|  | 764 | { | 
|  | 765 | u8 *xfer_buff; | 
|  | 766 | int ret = -ENOMEM; | 
|  | 767 |  | 
|  | 768 | xfer_buff = kmalloc(size, GFP_KERNEL); | 
|  | 769 | if (!xfer_buff) { | 
|  | 770 | uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n"); | 
|  | 771 | return ret; | 
|  | 772 | } | 
|  | 773 | memcpy(xfer_buff, data, size); | 
|  | 774 |  | 
|  | 775 | ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0), | 
|  | 776 | UCDC_SEND_ENCAPSULATED_COMMAND, | 
|  | 777 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | 
|  | 778 | value, index, xfer_buff, size, CTRL_TIMEOUT); | 
|  | 779 |  | 
|  | 780 | kfree(xfer_buff); | 
|  | 781 | if (ret < 0) { | 
|  | 782 | uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret); | 
|  | 783 | return ret; | 
|  | 784 | } | 
|  | 785 |  | 
|  | 786 | if (ret != size) { | 
|  | 787 | uea_err(INS_TO_USBDEV(sc), | 
|  | 788 | "usb_control_msg send only %d bytes (instead of %d)\n", | 
|  | 789 | ret, size); | 
|  | 790 | return -EIO; | 
|  | 791 | } | 
|  | 792 |  | 
|  | 793 | return 0; | 
|  | 794 | } | 
|  | 795 |  | 
|  | 796 | static int uea_cmv(struct uea_softc *sc, | 
|  | 797 | u8 function, u32 address, u16 offset, u32 data) | 
|  | 798 | { | 
|  | 799 | struct cmv cmv; | 
|  | 800 | int ret; | 
|  | 801 |  | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 802 | uea_enters(INS_TO_USBDEV(sc)); | 
|  | 803 | uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, " | 
|  | 804 | "offset : 0x%04x, data : 0x%08x\n", | 
|  | 805 | FUNCTION_TYPE(function), FUNCTION_SUBTYPE(function), | 
|  | 806 | GETSA1(address), GETSA2(address), GETSA3(address), | 
|  | 807 | GETSA4(address), offset, data); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 808 | /* we send a request, but we expect a reply */ | 
|  | 809 | sc->cmv_function = function | 0x2; | 
|  | 810 | sc->cmv_idx++; | 
|  | 811 | sc->cmv_address = address; | 
|  | 812 | sc->cmv_offset = offset; | 
|  | 813 |  | 
|  | 814 | cmv.wPreamble = cpu_to_le16(PREAMBLE); | 
|  | 815 | cmv.bDirection = HOSTTOMODEM; | 
|  | 816 | cmv.bFunction = function; | 
|  | 817 | cmv.wIndex = cpu_to_le16(sc->cmv_idx); | 
|  | 818 | put_unaligned(cpu_to_le32(address), &cmv.dwSymbolicAddress); | 
|  | 819 | cmv.wOffsetAddress = cpu_to_le16(offset); | 
|  | 820 | put_unaligned(cpu_to_le32(data >> 16 | data << 16), &cmv.dwData); | 
|  | 821 |  | 
|  | 822 | ret = uea_request(sc, UEA_SET_BLOCK, UEA_MPTX_START, CMV_SIZE, &cmv); | 
|  | 823 | if (ret < 0) | 
|  | 824 | return ret; | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 825 | ret = wait_cmv_ack(sc); | 
|  | 826 | uea_leaves(INS_TO_USBDEV(sc)); | 
|  | 827 | return ret; | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 828 | } | 
|  | 829 |  | 
|  | 830 | static inline int uea_read_cmv(struct uea_softc *sc, | 
|  | 831 | u32 address, u16 offset, u32 *data) | 
|  | 832 | { | 
|  | 833 | int ret = uea_cmv(sc, MAKEFUNCTION(MEMACCESS, REQUESTREAD), | 
|  | 834 | address, offset, 0); | 
|  | 835 | if (ret < 0) | 
|  | 836 | uea_err(INS_TO_USBDEV(sc), | 
|  | 837 | "reading cmv failed with error %d\n", ret); | 
|  | 838 | else | 
|  | 839 | *data = sc->data; | 
|  | 840 |  | 
|  | 841 | return ret; | 
|  | 842 | } | 
|  | 843 |  | 
|  | 844 | static inline int uea_write_cmv(struct uea_softc *sc, | 
|  | 845 | u32 address, u16 offset, u32 data) | 
|  | 846 | { | 
|  | 847 | int ret = uea_cmv(sc, MAKEFUNCTION(MEMACCESS, REQUESTWRITE), | 
|  | 848 | address, offset, data); | 
|  | 849 | if (ret < 0) | 
|  | 850 | uea_err(INS_TO_USBDEV(sc), | 
|  | 851 | "writing cmv failed with error %d\n", ret); | 
|  | 852 |  | 
|  | 853 | return ret; | 
|  | 854 | } | 
|  | 855 |  | 
|  | 856 | /* | 
|  | 857 | * Monitor the modem and update the stat | 
|  | 858 | * return 0 if everything is ok | 
|  | 859 | * return < 0 if an error occurs (-EAGAIN reboot needed) | 
|  | 860 | */ | 
|  | 861 | static int uea_stat(struct uea_softc *sc) | 
|  | 862 | { | 
|  | 863 | u32 data; | 
|  | 864 | int ret; | 
|  | 865 |  | 
|  | 866 | uea_enters(INS_TO_USBDEV(sc)); | 
|  | 867 | data = sc->stats.phy.state; | 
|  | 868 |  | 
|  | 869 | ret = uea_read_cmv(sc, SA_STAT, 0, &sc->stats.phy.state); | 
|  | 870 | if (ret < 0) | 
|  | 871 | return ret; | 
|  | 872 |  | 
|  | 873 | switch (GET_STATUS(sc->stats.phy.state)) { | 
|  | 874 | case 0:		/* not yet synchronized */ | 
|  | 875 | uea_dbg(INS_TO_USBDEV(sc), | 
|  | 876 | "modem not yet synchronized\n"); | 
|  | 877 | return 0; | 
|  | 878 |  | 
|  | 879 | case 1:		/* initialization */ | 
|  | 880 | uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n"); | 
|  | 881 | return 0; | 
|  | 882 |  | 
|  | 883 | case 2:		/* operational */ | 
|  | 884 | uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n"); | 
|  | 885 | break; | 
|  | 886 |  | 
|  | 887 | case 3:		/* fail ... */ | 
|  | 888 | uea_info(INS_TO_USBDEV(sc), "modem synchronization failed\n"); | 
|  | 889 | return -EAGAIN; | 
|  | 890 |  | 
|  | 891 | case 4 ... 6:	/* test state */ | 
|  | 892 | uea_warn(INS_TO_USBDEV(sc), | 
|  | 893 | "modem in test mode - not supported\n"); | 
|  | 894 | return -EAGAIN; | 
|  | 895 |  | 
|  | 896 | case 7:		/* fast-retain ... */ | 
|  | 897 | uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n"); | 
|  | 898 | return 0; | 
|  | 899 | default: | 
|  | 900 | uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n", | 
|  | 901 | GET_STATUS(sc->stats.phy.state)); | 
|  | 902 | return -EAGAIN; | 
|  | 903 | } | 
|  | 904 |  | 
|  | 905 | if (GET_STATUS(data) != 2) { | 
|  | 906 | uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL); | 
|  | 907 | uea_info(INS_TO_USBDEV(sc), "modem operational\n"); | 
|  | 908 |  | 
|  | 909 | /* release the dsp firmware as it is not needed until | 
|  | 910 | * the next failure | 
|  | 911 | */ | 
|  | 912 | if (sc->dsp_firm) { | 
|  | 913 | release_firmware(sc->dsp_firm); | 
|  | 914 | sc->dsp_firm = NULL; | 
|  | 915 | } | 
|  | 916 |  | 
|  | 917 | ret = uea_read_cmv(sc, SA_INFO, 10, &sc->stats.phy.firmid); | 
|  | 918 | if (ret < 0) | 
|  | 919 | return ret; | 
|  | 920 | uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n", | 
|  | 921 | sc->stats.phy.firmid); | 
|  | 922 | } | 
|  | 923 |  | 
|  | 924 | /* always update it as atm layer could not be init when we switch to | 
|  | 925 | * operational state | 
|  | 926 | */ | 
|  | 927 | UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND); | 
|  | 928 |  | 
|  | 929 | /* wake up processes waiting for synchronization */ | 
|  | 930 | wake_up(&sc->sync_q); | 
|  | 931 |  | 
|  | 932 | ret = uea_read_cmv(sc, SA_DIAG, 2, &sc->stats.phy.flags); | 
|  | 933 | if (ret < 0) | 
|  | 934 | return ret; | 
|  | 935 | sc->stats.phy.mflags |= sc->stats.phy.flags; | 
|  | 936 |  | 
|  | 937 | /* in case of a flags ( for example delineation LOSS (& 0x10)), | 
|  | 938 | * we check the status again in order to detect the failure earlier | 
|  | 939 | */ | 
|  | 940 | if (sc->stats.phy.flags) { | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 941 | uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n", | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 942 | sc->stats.phy.flags); | 
|  | 943 | return 0; | 
|  | 944 | } | 
|  | 945 |  | 
|  | 946 | ret = uea_read_cmv(sc, SA_RATE, 0, &data); | 
|  | 947 | if (ret < 0) | 
|  | 948 | return ret; | 
|  | 949 |  | 
|  | 950 | /* in bulk mode the modem have problem with high rate | 
|  | 951 | * changing internal timing could improve things, but the | 
|  | 952 | * value is misterious. | 
|  | 953 | * ADI930 don't support it (-EPIPE error). | 
|  | 954 | */ | 
|  | 955 | if (UEA_CHIP_VERSION(sc) != ADI930 | 
| matthieu castet | 3c9666c | 2006-01-18 07:38:19 +0100 | [diff] [blame] | 956 | && !use_iso[sc->modem_index] | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 957 | && sc->stats.phy.dsrate != (data >> 16) * 32) { | 
|  | 958 | /* Original timming from ADI(used in windows driver) | 
|  | 959 | * 0x20ffff>>16 * 32 = 32 * 32 = 1Mbits | 
|  | 960 | */ | 
|  | 961 | u16 timeout = (data <= 0x20ffff) ? 0 : 1; | 
|  | 962 | ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL); | 
|  | 963 | uea_info(INS_TO_USBDEV(sc), | 
|  | 964 | "setting new timeout %d%s\n", timeout, | 
|  | 965 | ret < 0?" failed":""); | 
|  | 966 | } | 
|  | 967 | sc->stats.phy.dsrate = (data >> 16) * 32; | 
|  | 968 | sc->stats.phy.usrate = (data & 0xffff) * 32; | 
|  | 969 | UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424); | 
|  | 970 |  | 
|  | 971 | ret = uea_read_cmv(sc, SA_DIAG, 23, &data); | 
|  | 972 | if (ret < 0) | 
|  | 973 | return ret; | 
|  | 974 | sc->stats.phy.dsattenuation = (data & 0xff) / 2; | 
|  | 975 |  | 
|  | 976 | ret = uea_read_cmv(sc, SA_DIAG, 47, &data); | 
|  | 977 | if (ret < 0) | 
|  | 978 | return ret; | 
|  | 979 | sc->stats.phy.usattenuation = (data & 0xff) / 2; | 
|  | 980 |  | 
|  | 981 | ret = uea_read_cmv(sc, SA_DIAG, 25, &sc->stats.phy.dsmargin); | 
|  | 982 | if (ret < 0) | 
|  | 983 | return ret; | 
|  | 984 |  | 
|  | 985 | ret = uea_read_cmv(sc, SA_DIAG, 49, &sc->stats.phy.usmargin); | 
|  | 986 | if (ret < 0) | 
|  | 987 | return ret; | 
|  | 988 |  | 
|  | 989 | ret = uea_read_cmv(sc, SA_DIAG, 51, &sc->stats.phy.rxflow); | 
|  | 990 | if (ret < 0) | 
|  | 991 | return ret; | 
|  | 992 |  | 
|  | 993 | ret = uea_read_cmv(sc, SA_DIAG, 52, &sc->stats.phy.txflow); | 
|  | 994 | if (ret < 0) | 
|  | 995 | return ret; | 
|  | 996 |  | 
|  | 997 | ret = uea_read_cmv(sc, SA_DIAG, 54, &sc->stats.phy.dsunc); | 
|  | 998 | if (ret < 0) | 
|  | 999 | return ret; | 
|  | 1000 |  | 
|  | 1001 | /* only for atu-c */ | 
|  | 1002 | ret = uea_read_cmv(sc, SA_DIAG, 58, &sc->stats.phy.usunc); | 
|  | 1003 | if (ret < 0) | 
|  | 1004 | return ret; | 
|  | 1005 |  | 
|  | 1006 | ret = uea_read_cmv(sc, SA_DIAG, 53, &sc->stats.phy.dscorr); | 
|  | 1007 | if (ret < 0) | 
|  | 1008 | return ret; | 
|  | 1009 |  | 
|  | 1010 | /* only for atu-c */ | 
|  | 1011 | ret = uea_read_cmv(sc, SA_DIAG, 57, &sc->stats.phy.uscorr); | 
|  | 1012 | if (ret < 0) | 
|  | 1013 | return ret; | 
|  | 1014 |  | 
|  | 1015 | ret = uea_read_cmv(sc, SA_INFO, 8, &sc->stats.phy.vidco); | 
|  | 1016 | if (ret < 0) | 
|  | 1017 | return ret; | 
|  | 1018 |  | 
|  | 1019 | ret = uea_read_cmv(sc, SA_INFO, 13, &sc->stats.phy.vidcpe); | 
|  | 1020 | if (ret < 0) | 
|  | 1021 | return ret; | 
|  | 1022 |  | 
|  | 1023 | return 0; | 
|  | 1024 | } | 
|  | 1025 |  | 
|  | 1026 | static int request_cmvs(struct uea_softc *sc, | 
|  | 1027 | struct uea_cmvs **cmvs, const struct firmware **fw) | 
|  | 1028 | { | 
|  | 1029 | int ret, size; | 
|  | 1030 | u8 *data; | 
|  | 1031 | char *file; | 
| matthieu castet | fdf290f | 2006-01-18 07:39:27 +0100 | [diff] [blame] | 1032 | char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */ | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1033 |  | 
|  | 1034 | if (cmv_file[sc->modem_index] == NULL) { | 
|  | 1035 | if (UEA_CHIP_VERSION(sc) == ADI930) | 
|  | 1036 | file = (IS_ISDN(sc)) ? "CMV9i.bin" : "CMV9p.bin"; | 
|  | 1037 | else | 
|  | 1038 | file = (IS_ISDN(sc)) ? "CMVei.bin" : "CMVep.bin"; | 
|  | 1039 | } else | 
|  | 1040 | file = cmv_file[sc->modem_index]; | 
|  | 1041 |  | 
|  | 1042 | strcpy(cmv_name, FW_DIR); | 
|  | 1043 | strlcat(cmv_name, file, sizeof(cmv_name)); | 
|  | 1044 |  | 
|  | 1045 | ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev); | 
|  | 1046 | if (ret < 0) { | 
|  | 1047 | uea_err(INS_TO_USBDEV(sc), | 
|  | 1048 | "requesting firmware %s failed with error %d\n", | 
|  | 1049 | cmv_name, ret); | 
|  | 1050 | return ret; | 
|  | 1051 | } | 
|  | 1052 |  | 
|  | 1053 | data = (u8 *) (*fw)->data; | 
|  | 1054 | size = *data * sizeof(struct uea_cmvs) + 1; | 
|  | 1055 | if (size != (*fw)->size) { | 
|  | 1056 | uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", | 
|  | 1057 | cmv_name); | 
|  | 1058 | release_firmware(*fw); | 
|  | 1059 | return -EILSEQ; | 
|  | 1060 | } | 
|  | 1061 |  | 
|  | 1062 | *cmvs = (struct uea_cmvs *)(data + 1); | 
|  | 1063 | return *data; | 
|  | 1064 | } | 
|  | 1065 |  | 
|  | 1066 | /* Start boot post firmware modem: | 
|  | 1067 | * - send reset commands through usb control pipe | 
|  | 1068 | * - start workqueue for DSP loading | 
|  | 1069 | * - send CMV options to modem | 
|  | 1070 | */ | 
|  | 1071 |  | 
|  | 1072 | static int uea_start_reset(struct uea_softc *sc) | 
|  | 1073 | { | 
|  | 1074 | u16 zero = 0;	/* ;-) */ | 
|  | 1075 | int i, len, ret; | 
|  | 1076 | struct uea_cmvs *cmvs; | 
|  | 1077 | const struct firmware *cmvs_fw; | 
|  | 1078 |  | 
|  | 1079 | uea_enters(INS_TO_USBDEV(sc)); | 
|  | 1080 | uea_info(INS_TO_USBDEV(sc), "(re)booting started\n"); | 
|  | 1081 |  | 
| matthieu castet | 22fcceb | 2006-04-02 18:44:20 +0200 | [diff] [blame] | 1082 | /* mask interrupt */ | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1083 | sc->booting = 1; | 
| matthieu castet | 22fcceb | 2006-04-02 18:44:20 +0200 | [diff] [blame] | 1084 | /* We need to set this here because, a ack timeout could have occured, | 
|  | 1085 | * but before we start the reboot, the ack occurs and set this to 1. | 
|  | 1086 | * So we will failed to wait Ready CMV. | 
|  | 1087 | */ | 
|  | 1088 | sc->cmv_ack = 0; | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1089 | UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST); | 
|  | 1090 |  | 
|  | 1091 | /* reset statistics */ | 
|  | 1092 | memset(&sc->stats, 0, sizeof(struct uea_stats)); | 
|  | 1093 |  | 
|  | 1094 | /* tell the modem that we want to boot in IDMA mode */ | 
|  | 1095 | uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL); | 
|  | 1096 | uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL); | 
|  | 1097 |  | 
|  | 1098 | /* enter reset mode */ | 
|  | 1099 | uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL); | 
|  | 1100 |  | 
|  | 1101 | /* original driver use 200ms, but windows driver use 100ms */ | 
|  | 1102 | msleep(100); | 
|  | 1103 |  | 
|  | 1104 | /* leave reset mode */ | 
|  | 1105 | uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL); | 
|  | 1106 |  | 
|  | 1107 | /* clear tx and rx mailboxes */ | 
|  | 1108 | uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero); | 
|  | 1109 | uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero); | 
|  | 1110 | uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero); | 
|  | 1111 |  | 
|  | 1112 | msleep(1000); | 
|  | 1113 | sc->cmv_function = MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY); | 
| matthieu castet | 22fcceb | 2006-04-02 18:44:20 +0200 | [diff] [blame] | 1114 | /* demask interrupt */ | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1115 | sc->booting = 0; | 
|  | 1116 |  | 
|  | 1117 | /* start loading DSP */ | 
|  | 1118 | sc->pageno = 0; | 
|  | 1119 | sc->ovl = 0; | 
|  | 1120 | schedule_work(&sc->task); | 
|  | 1121 |  | 
|  | 1122 | /* wait for modem ready CMV */ | 
|  | 1123 | ret = wait_cmv_ack(sc); | 
|  | 1124 | if (ret < 0) | 
|  | 1125 | return ret; | 
|  | 1126 |  | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1127 | uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n"); | 
|  | 1128 |  | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1129 | /* Enter in R-IDLE (cmv) until instructed otherwise */ | 
|  | 1130 | ret = uea_write_cmv(sc, SA_CNTL, 0, 1); | 
|  | 1131 | if (ret < 0) | 
|  | 1132 | return ret; | 
|  | 1133 |  | 
|  | 1134 | /* get options */ | 
|  | 1135 | ret = len = request_cmvs(sc, &cmvs, &cmvs_fw); | 
|  | 1136 | if (ret < 0) | 
|  | 1137 | return ret; | 
|  | 1138 |  | 
|  | 1139 | /* send options */ | 
|  | 1140 | for (i = 0; i < len; i++) { | 
|  | 1141 | ret = uea_write_cmv(sc, FW_GET_LONG(&cmvs[i].address), | 
|  | 1142 | FW_GET_WORD(&cmvs[i].offset), | 
|  | 1143 | FW_GET_LONG(&cmvs[i].data)); | 
|  | 1144 | if (ret < 0) | 
|  | 1145 | goto out; | 
|  | 1146 | } | 
|  | 1147 | /* Enter in R-ACT-REQ */ | 
|  | 1148 | ret = uea_write_cmv(sc, SA_CNTL, 0, 2); | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1149 | uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n"); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1150 | out: | 
|  | 1151 | release_firmware(cmvs_fw); | 
|  | 1152 | sc->reset = 0; | 
|  | 1153 | uea_leaves(INS_TO_USBDEV(sc)); | 
|  | 1154 | return ret; | 
|  | 1155 | } | 
|  | 1156 |  | 
|  | 1157 | /* | 
|  | 1158 | * In case of an error wait 1s before rebooting the modem | 
|  | 1159 | * if the modem don't request reboot (-EAGAIN). | 
|  | 1160 | * Monitor the modem every 1s. | 
|  | 1161 | */ | 
|  | 1162 |  | 
|  | 1163 | static int uea_kthread(void *data) | 
|  | 1164 | { | 
|  | 1165 | struct uea_softc *sc = data; | 
|  | 1166 | int ret = -EAGAIN; | 
|  | 1167 |  | 
|  | 1168 | uea_enters(INS_TO_USBDEV(sc)); | 
|  | 1169 | while (!kthread_should_stop()) { | 
|  | 1170 | if (ret < 0 || sc->reset) | 
|  | 1171 | ret = uea_start_reset(sc); | 
|  | 1172 | if (!ret) | 
|  | 1173 | ret = uea_stat(sc); | 
|  | 1174 | if (ret != -EAGAIN) | 
|  | 1175 | msleep(1000); | 
|  | 1176 | } | 
|  | 1177 | uea_leaves(INS_TO_USBDEV(sc)); | 
|  | 1178 | return ret; | 
|  | 1179 | } | 
|  | 1180 |  | 
|  | 1181 | /* Load second usb firmware for ADI930 chip */ | 
|  | 1182 | static int load_XILINX_firmware(struct uea_softc *sc) | 
|  | 1183 | { | 
|  | 1184 | const struct firmware *fw_entry; | 
|  | 1185 | int ret, size, u, ln; | 
|  | 1186 | u8 *pfw, value; | 
|  | 1187 | char *fw_name = FW_DIR "930-fpga.bin"; | 
|  | 1188 |  | 
|  | 1189 | uea_enters(INS_TO_USBDEV(sc)); | 
|  | 1190 |  | 
|  | 1191 | ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev); | 
|  | 1192 | if (ret) { | 
|  | 1193 | uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n", | 
|  | 1194 | fw_name); | 
|  | 1195 | goto err0; | 
|  | 1196 | } | 
|  | 1197 |  | 
|  | 1198 | pfw = fw_entry->data; | 
|  | 1199 | size = fw_entry->size; | 
|  | 1200 | if (size != 0x577B) { | 
|  | 1201 | uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", | 
|  | 1202 | fw_name); | 
|  | 1203 | ret = -EILSEQ; | 
|  | 1204 | goto err1; | 
|  | 1205 | } | 
|  | 1206 | for (u = 0; u < size; u += ln) { | 
|  | 1207 | ln = min(size - u, 64); | 
|  | 1208 | ret = uea_request(sc, 0xe, 0, ln, pfw + u); | 
|  | 1209 | if (ret < 0) { | 
|  | 1210 | uea_err(INS_TO_USBDEV(sc), | 
|  | 1211 | "elsa download data failed (%d)\n", ret); | 
|  | 1212 | goto err1; | 
|  | 1213 | } | 
|  | 1214 | } | 
|  | 1215 |  | 
| matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 1216 | /* finish to send the fpga */ | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1217 | ret = uea_request(sc, 0xe, 1, 0, NULL); | 
|  | 1218 | if (ret < 0) { | 
|  | 1219 | uea_err(INS_TO_USBDEV(sc), | 
|  | 1220 | "elsa download data failed (%d)\n", ret); | 
|  | 1221 | goto err1; | 
|  | 1222 | } | 
|  | 1223 |  | 
| matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 1224 | /* Tell the modem we finish : de-assert reset */ | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1225 | value = 0; | 
|  | 1226 | ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value); | 
|  | 1227 | if (ret < 0) | 
|  | 1228 | uea_err(sc->usb_dev, "elsa de-assert failed with error %d\n", ret); | 
|  | 1229 |  | 
|  | 1230 |  | 
|  | 1231 | err1: | 
|  | 1232 | release_firmware(fw_entry); | 
|  | 1233 | err0: | 
|  | 1234 | uea_leaves(INS_TO_USBDEV(sc)); | 
|  | 1235 | return ret; | 
|  | 1236 | } | 
|  | 1237 |  | 
| matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 1238 | /* The modem send us an ack. First with check if it right */ | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1239 | static void uea_dispatch_cmv(struct uea_softc *sc, struct cmv* cmv) | 
|  | 1240 | { | 
|  | 1241 | uea_enters(INS_TO_USBDEV(sc)); | 
|  | 1242 | if (le16_to_cpu(cmv->wPreamble) != PREAMBLE) | 
|  | 1243 | goto bad1; | 
|  | 1244 |  | 
|  | 1245 | if (cmv->bDirection != MODEMTOHOST) | 
|  | 1246 | goto bad1; | 
|  | 1247 |  | 
|  | 1248 | /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to | 
|  | 1249 | * the first MEMACESS cmv. Ignore it... | 
|  | 1250 | */ | 
|  | 1251 | if (cmv->bFunction != sc->cmv_function) { | 
|  | 1252 | if (UEA_CHIP_VERSION(sc) == ADI930 | 
|  | 1253 | && cmv->bFunction ==  MAKEFUNCTION(2, 2)) { | 
|  | 1254 | cmv->wIndex = cpu_to_le16(sc->cmv_idx); | 
|  | 1255 | put_unaligned(cpu_to_le32(sc->cmv_address), &cmv->dwSymbolicAddress); | 
|  | 1256 | cmv->wOffsetAddress = cpu_to_le16(sc->cmv_offset); | 
|  | 1257 | } | 
|  | 1258 | else | 
|  | 1259 | goto bad2; | 
|  | 1260 | } | 
|  | 1261 |  | 
|  | 1262 | if (cmv->bFunction == MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY)) { | 
|  | 1263 | wake_up_cmv_ack(sc); | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1264 | uea_leaves(INS_TO_USBDEV(sc)); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1265 | return; | 
|  | 1266 | } | 
|  | 1267 |  | 
|  | 1268 | /* in case of MEMACCESS */ | 
|  | 1269 | if (le16_to_cpu(cmv->wIndex) != sc->cmv_idx || | 
|  | 1270 | le32_to_cpu(get_unaligned(&cmv->dwSymbolicAddress)) != | 
|  | 1271 | sc->cmv_address | 
|  | 1272 | || le16_to_cpu(cmv->wOffsetAddress) != sc->cmv_offset) | 
|  | 1273 | goto bad2; | 
|  | 1274 |  | 
|  | 1275 | sc->data = le32_to_cpu(get_unaligned(&cmv->dwData)); | 
|  | 1276 | sc->data = sc->data << 16 | sc->data >> 16; | 
|  | 1277 |  | 
|  | 1278 | wake_up_cmv_ack(sc); | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1279 | uea_leaves(INS_TO_USBDEV(sc)); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1280 | return; | 
|  | 1281 |  | 
|  | 1282 | bad2: | 
|  | 1283 | uea_err(INS_TO_USBDEV(sc), "unexpected cmv received," | 
|  | 1284 | "Function : %d, Subfunction : %d\n", | 
|  | 1285 | FUNCTION_TYPE(cmv->bFunction), | 
|  | 1286 | FUNCTION_SUBTYPE(cmv->bFunction)); | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1287 | uea_leaves(INS_TO_USBDEV(sc)); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1288 | return; | 
|  | 1289 |  | 
|  | 1290 | bad1: | 
|  | 1291 | uea_err(INS_TO_USBDEV(sc), "invalid cmv received, " | 
|  | 1292 | "wPreamble %d, bDirection %d\n", | 
|  | 1293 | le16_to_cpu(cmv->wPreamble), cmv->bDirection); | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1294 | uea_leaves(INS_TO_USBDEV(sc)); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1295 | } | 
|  | 1296 |  | 
|  | 1297 | /* | 
|  | 1298 | * interrupt handler | 
|  | 1299 | */ | 
|  | 1300 | static void uea_intr(struct urb *urb, struct pt_regs *regs) | 
|  | 1301 | { | 
| matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 1302 | struct uea_softc *sc = urb->context; | 
|  | 1303 | struct intr_pkt *intr = urb->transfer_buffer; | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1304 | uea_enters(INS_TO_USBDEV(sc)); | 
|  | 1305 |  | 
| matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 1306 | if (unlikely(urb->status < 0)) { | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1307 | uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n", | 
|  | 1308 | urb->status); | 
|  | 1309 | return; | 
|  | 1310 | } | 
|  | 1311 |  | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1312 | /* device-to-host interrupt */ | 
|  | 1313 | if (intr->bType != 0x08 || sc->booting) { | 
| matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 1314 | uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n"); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1315 | goto resubmit; | 
|  | 1316 | } | 
|  | 1317 |  | 
|  | 1318 | switch (le16_to_cpu(intr->wInterrupt)) { | 
|  | 1319 | case INT_LOADSWAPPAGE: | 
|  | 1320 | sc->pageno = intr->bSwapPageNo; | 
|  | 1321 | sc->ovl = intr->bOvl >> 4 | intr->bOvl << 4; | 
|  | 1322 | schedule_work(&sc->task); | 
|  | 1323 | break; | 
|  | 1324 |  | 
|  | 1325 | case INT_INCOMINGCMV: | 
|  | 1326 | uea_dispatch_cmv(sc, &intr->u.s2.cmv); | 
|  | 1327 | break; | 
|  | 1328 |  | 
|  | 1329 | default: | 
| matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 1330 | uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n", | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1331 | le16_to_cpu(intr->wInterrupt)); | 
|  | 1332 | } | 
|  | 1333 |  | 
|  | 1334 | resubmit: | 
|  | 1335 | usb_submit_urb(sc->urb_int, GFP_ATOMIC); | 
|  | 1336 | } | 
|  | 1337 |  | 
|  | 1338 | /* | 
|  | 1339 | * Start the modem : init the data and start kernel thread | 
|  | 1340 | */ | 
|  | 1341 | static int uea_boot(struct uea_softc *sc) | 
|  | 1342 | { | 
|  | 1343 | int ret; | 
|  | 1344 | struct intr_pkt *intr; | 
|  | 1345 |  | 
|  | 1346 | uea_enters(INS_TO_USBDEV(sc)); | 
|  | 1347 |  | 
|  | 1348 | INIT_WORK(&sc->task, uea_load_page, sc); | 
|  | 1349 | init_waitqueue_head(&sc->sync_q); | 
|  | 1350 | init_waitqueue_head(&sc->cmv_ack_wait); | 
|  | 1351 |  | 
|  | 1352 | if (UEA_CHIP_VERSION(sc) == ADI930) | 
|  | 1353 | load_XILINX_firmware(sc); | 
|  | 1354 |  | 
|  | 1355 | intr = kmalloc(INTR_PKT_SIZE, GFP_KERNEL); | 
|  | 1356 | if (!intr) { | 
|  | 1357 | uea_err(INS_TO_USBDEV(sc), | 
|  | 1358 | "cannot allocate interrupt package\n"); | 
|  | 1359 | uea_leaves(INS_TO_USBDEV(sc)); | 
|  | 1360 | return -ENOMEM; | 
|  | 1361 | } | 
|  | 1362 |  | 
|  | 1363 | sc->urb_int = usb_alloc_urb(0, GFP_KERNEL); | 
|  | 1364 | if (!sc->urb_int) { | 
|  | 1365 | uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n"); | 
|  | 1366 | goto err; | 
|  | 1367 | } | 
|  | 1368 |  | 
|  | 1369 | usb_fill_int_urb(sc->urb_int, sc->usb_dev, | 
|  | 1370 | usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE), | 
|  | 1371 | intr, INTR_PKT_SIZE, uea_intr, sc, | 
|  | 1372 | sc->usb_dev->actconfig->interface[0]->altsetting[0]. | 
|  | 1373 | endpoint[0].desc.bInterval); | 
|  | 1374 |  | 
|  | 1375 | ret = usb_submit_urb(sc->urb_int, GFP_KERNEL); | 
|  | 1376 | if (ret < 0) { | 
|  | 1377 | uea_err(INS_TO_USBDEV(sc), | 
|  | 1378 | "urb submition failed with error %d\n", ret); | 
| matthieu castet | 4d45e21 | 2006-04-02 18:45:46 +0200 | [diff] [blame] | 1379 | goto err; | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1380 | } | 
|  | 1381 |  | 
|  | 1382 | sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm"); | 
|  | 1383 | if (sc->kthread == ERR_PTR(-ENOMEM)) { | 
|  | 1384 | uea_err(INS_TO_USBDEV(sc), "failed to create thread\n"); | 
|  | 1385 | goto err2; | 
|  | 1386 | } | 
|  | 1387 |  | 
|  | 1388 | uea_leaves(INS_TO_USBDEV(sc)); | 
|  | 1389 | return 0; | 
|  | 1390 |  | 
|  | 1391 | err2: | 
|  | 1392 | usb_kill_urb(sc->urb_int); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1393 | err: | 
|  | 1394 | usb_free_urb(sc->urb_int); | 
| matthieu castet | 4d45e21 | 2006-04-02 18:45:46 +0200 | [diff] [blame] | 1395 | sc->urb_int = NULL; | 
|  | 1396 | kfree(intr); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1397 | uea_leaves(INS_TO_USBDEV(sc)); | 
|  | 1398 | return -ENOMEM; | 
|  | 1399 | } | 
|  | 1400 |  | 
|  | 1401 | /* | 
|  | 1402 | * Stop the modem : kill kernel thread and free data | 
|  | 1403 | */ | 
|  | 1404 | static void uea_stop(struct uea_softc *sc) | 
|  | 1405 | { | 
|  | 1406 | int ret; | 
|  | 1407 | uea_enters(INS_TO_USBDEV(sc)); | 
|  | 1408 | ret = kthread_stop(sc->kthread); | 
| matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 1409 | uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1410 |  | 
|  | 1411 | /* stop any pending boot process */ | 
|  | 1412 | flush_scheduled_work(); | 
|  | 1413 |  | 
|  | 1414 | uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL); | 
|  | 1415 |  | 
|  | 1416 | usb_kill_urb(sc->urb_int); | 
|  | 1417 | kfree(sc->urb_int->transfer_buffer); | 
|  | 1418 | usb_free_urb(sc->urb_int); | 
|  | 1419 |  | 
|  | 1420 | if (sc->dsp_firm) | 
|  | 1421 | release_firmware(sc->dsp_firm); | 
|  | 1422 | uea_leaves(INS_TO_USBDEV(sc)); | 
|  | 1423 | } | 
|  | 1424 |  | 
|  | 1425 | /* syfs interface */ | 
|  | 1426 | static struct uea_softc *dev_to_uea(struct device *dev) | 
|  | 1427 | { | 
|  | 1428 | struct usb_interface *intf; | 
|  | 1429 | struct usbatm_data *usbatm; | 
|  | 1430 |  | 
|  | 1431 | intf = to_usb_interface(dev); | 
|  | 1432 | if (!intf) | 
|  | 1433 | return NULL; | 
|  | 1434 |  | 
|  | 1435 | usbatm = usb_get_intfdata(intf); | 
|  | 1436 | if (!usbatm) | 
|  | 1437 | return NULL; | 
|  | 1438 |  | 
|  | 1439 | return usbatm->driver_data; | 
|  | 1440 | } | 
|  | 1441 |  | 
|  | 1442 | static ssize_t read_status(struct device *dev, struct device_attribute *attr, | 
|  | 1443 | char *buf) | 
|  | 1444 | { | 
|  | 1445 | int ret = -ENODEV; | 
|  | 1446 | struct uea_softc *sc; | 
|  | 1447 |  | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 1448 | mutex_lock(&uea_mutex); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1449 | sc = dev_to_uea(dev); | 
|  | 1450 | if (!sc) | 
|  | 1451 | goto out; | 
|  | 1452 | ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state); | 
|  | 1453 | out: | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 1454 | mutex_unlock(&uea_mutex); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1455 | return ret; | 
|  | 1456 | } | 
|  | 1457 |  | 
|  | 1458 | static ssize_t reboot(struct device *dev, struct device_attribute *attr, | 
|  | 1459 | const char *buf, size_t count) | 
|  | 1460 | { | 
|  | 1461 | int ret = -ENODEV; | 
|  | 1462 | struct uea_softc *sc; | 
|  | 1463 |  | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 1464 | mutex_lock(&uea_mutex); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1465 | sc = dev_to_uea(dev); | 
|  | 1466 | if (!sc) | 
|  | 1467 | goto out; | 
|  | 1468 | sc->reset = 1; | 
|  | 1469 | ret = count; | 
|  | 1470 | out: | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 1471 | mutex_unlock(&uea_mutex); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1472 | return ret; | 
|  | 1473 | } | 
|  | 1474 |  | 
|  | 1475 | static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot); | 
|  | 1476 |  | 
|  | 1477 | static ssize_t read_human_status(struct device *dev, struct device_attribute *attr, | 
|  | 1478 | char *buf) | 
|  | 1479 | { | 
|  | 1480 | int ret = -ENODEV; | 
|  | 1481 | struct uea_softc *sc; | 
|  | 1482 |  | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 1483 | mutex_lock(&uea_mutex); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1484 | sc = dev_to_uea(dev); | 
|  | 1485 | if (!sc) | 
|  | 1486 | goto out; | 
|  | 1487 |  | 
|  | 1488 | switch (GET_STATUS(sc->stats.phy.state)) { | 
|  | 1489 | case 0: | 
|  | 1490 | ret = sprintf(buf, "Modem is booting\n"); | 
|  | 1491 | break; | 
|  | 1492 | case 1: | 
|  | 1493 | ret = sprintf(buf, "Modem is initializing\n"); | 
|  | 1494 | break; | 
|  | 1495 | case 2: | 
|  | 1496 | ret = sprintf(buf, "Modem is operational\n"); | 
|  | 1497 | break; | 
|  | 1498 | default: | 
|  | 1499 | ret = sprintf(buf, "Modem synchronization failed\n"); | 
|  | 1500 | break; | 
|  | 1501 | } | 
|  | 1502 | out: | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 1503 | mutex_unlock(&uea_mutex); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1504 | return ret; | 
|  | 1505 | } | 
|  | 1506 |  | 
|  | 1507 | static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, read_human_status, NULL); | 
|  | 1508 |  | 
|  | 1509 | static ssize_t read_delin(struct device *dev, struct device_attribute *attr, | 
|  | 1510 | char *buf) | 
|  | 1511 | { | 
|  | 1512 | int ret = -ENODEV; | 
|  | 1513 | struct uea_softc *sc; | 
|  | 1514 |  | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 1515 | mutex_lock(&uea_mutex); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1516 | sc = dev_to_uea(dev); | 
|  | 1517 | if (!sc) | 
|  | 1518 | goto out; | 
|  | 1519 |  | 
|  | 1520 | if (sc->stats.phy.flags & 0x0C00) | 
|  | 1521 | ret = sprintf(buf, "ERROR\n"); | 
|  | 1522 | else if (sc->stats.phy.flags & 0x0030) | 
|  | 1523 | ret = sprintf(buf, "LOSS\n"); | 
|  | 1524 | else | 
|  | 1525 | ret = sprintf(buf, "GOOD\n"); | 
|  | 1526 | out: | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 1527 | mutex_unlock(&uea_mutex); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1528 | return ret; | 
|  | 1529 | } | 
|  | 1530 |  | 
|  | 1531 | static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL); | 
|  | 1532 |  | 
|  | 1533 | #define UEA_ATTR(name, reset) 					\ | 
|  | 1534 | \ | 
|  | 1535 | static ssize_t read_##name(struct device *dev, 			\ | 
|  | 1536 | struct device_attribute *attr, char *buf)	\ | 
|  | 1537 | { 								\ | 
|  | 1538 | int ret = -ENODEV; 					\ | 
|  | 1539 | struct uea_softc *sc; 					\ | 
|  | 1540 | \ | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1541 | mutex_lock(&uea_mutex); 				\ | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1542 | sc = dev_to_uea(dev);					\ | 
|  | 1543 | if (!sc) 						\ | 
|  | 1544 | goto out; 					\ | 
|  | 1545 | ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name);	\ | 
|  | 1546 | if (reset)						\ | 
|  | 1547 | sc->stats.phy.name = 0;				\ | 
|  | 1548 | out: 								\ | 
| matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1549 | mutex_unlock(&uea_mutex); 				\ | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1550 | return ret; 						\ | 
|  | 1551 | } 								\ | 
|  | 1552 | \ | 
|  | 1553 | static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL) | 
|  | 1554 |  | 
|  | 1555 | UEA_ATTR(mflags, 1); | 
|  | 1556 | UEA_ATTR(vidcpe, 0); | 
|  | 1557 | UEA_ATTR(usrate, 0); | 
|  | 1558 | UEA_ATTR(dsrate, 0); | 
|  | 1559 | UEA_ATTR(usattenuation, 0); | 
|  | 1560 | UEA_ATTR(dsattenuation, 0); | 
|  | 1561 | UEA_ATTR(usmargin, 0); | 
|  | 1562 | UEA_ATTR(dsmargin, 0); | 
|  | 1563 | UEA_ATTR(txflow, 0); | 
|  | 1564 | UEA_ATTR(rxflow, 0); | 
|  | 1565 | UEA_ATTR(uscorr, 0); | 
|  | 1566 | UEA_ATTR(dscorr, 0); | 
|  | 1567 | UEA_ATTR(usunc, 0); | 
|  | 1568 | UEA_ATTR(dsunc, 0); | 
|  | 1569 |  | 
|  | 1570 | /* Retrieve the device End System Identifier (MAC) */ | 
|  | 1571 |  | 
|  | 1572 | #define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10) | 
|  | 1573 | static int uea_getesi(struct uea_softc *sc, u_char * esi) | 
|  | 1574 | { | 
|  | 1575 | unsigned char mac_str[2 * ETH_ALEN + 1]; | 
|  | 1576 | int i; | 
|  | 1577 | if (usb_string | 
|  | 1578 | (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str, | 
|  | 1579 | sizeof(mac_str)) != 2 * ETH_ALEN) | 
|  | 1580 | return 1; | 
|  | 1581 |  | 
|  | 1582 | for (i = 0; i < ETH_ALEN; i++) | 
|  | 1583 | esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]); | 
|  | 1584 |  | 
|  | 1585 | return 0; | 
|  | 1586 | } | 
|  | 1587 |  | 
|  | 1588 | /* ATM stuff */ | 
|  | 1589 | static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev) | 
|  | 1590 | { | 
|  | 1591 | struct uea_softc *sc = usbatm->driver_data; | 
|  | 1592 |  | 
|  | 1593 | return uea_getesi(sc, atm_dev->esi); | 
|  | 1594 | } | 
|  | 1595 |  | 
|  | 1596 | static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf) | 
|  | 1597 | { | 
|  | 1598 | struct uea_softc *sc = usbatm->driver_data; | 
|  | 1599 |  | 
|  | 1600 | wait_event(sc->sync_q, IS_OPERATIONAL(sc)); | 
|  | 1601 |  | 
|  | 1602 | return 0; | 
|  | 1603 |  | 
|  | 1604 | } | 
|  | 1605 |  | 
|  | 1606 | static int claim_interface(struct usb_device *usb_dev, | 
|  | 1607 | struct usbatm_data *usbatm, int ifnum) | 
|  | 1608 | { | 
|  | 1609 | int ret; | 
|  | 1610 | struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum); | 
|  | 1611 |  | 
|  | 1612 | if (!intf) { | 
|  | 1613 | uea_err(usb_dev, "interface %d not found\n", ifnum); | 
|  | 1614 | return -ENODEV; | 
|  | 1615 | } | 
|  | 1616 |  | 
|  | 1617 | ret = usb_driver_claim_interface(&uea_driver, intf, usbatm); | 
|  | 1618 | if (ret != 0) | 
|  | 1619 | uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum, | 
|  | 1620 | ret); | 
|  | 1621 | return ret; | 
|  | 1622 | } | 
|  | 1623 |  | 
|  | 1624 | static void create_fs_entries(struct uea_softc *sc, struct usb_interface *intf) | 
|  | 1625 | { | 
|  | 1626 | /* sysfs interface */ | 
|  | 1627 | device_create_file(&intf->dev, &dev_attr_stat_status); | 
|  | 1628 | device_create_file(&intf->dev, &dev_attr_stat_mflags); | 
|  | 1629 | device_create_file(&intf->dev, &dev_attr_stat_human_status); | 
|  | 1630 | device_create_file(&intf->dev, &dev_attr_stat_delin); | 
|  | 1631 | device_create_file(&intf->dev, &dev_attr_stat_vidcpe); | 
|  | 1632 | device_create_file(&intf->dev, &dev_attr_stat_usrate); | 
|  | 1633 | device_create_file(&intf->dev, &dev_attr_stat_dsrate); | 
|  | 1634 | device_create_file(&intf->dev, &dev_attr_stat_usattenuation); | 
|  | 1635 | device_create_file(&intf->dev, &dev_attr_stat_dsattenuation); | 
|  | 1636 | device_create_file(&intf->dev, &dev_attr_stat_usmargin); | 
|  | 1637 | device_create_file(&intf->dev, &dev_attr_stat_dsmargin); | 
|  | 1638 | device_create_file(&intf->dev, &dev_attr_stat_txflow); | 
|  | 1639 | device_create_file(&intf->dev, &dev_attr_stat_rxflow); | 
|  | 1640 | device_create_file(&intf->dev, &dev_attr_stat_uscorr); | 
|  | 1641 | device_create_file(&intf->dev, &dev_attr_stat_dscorr); | 
|  | 1642 | device_create_file(&intf->dev, &dev_attr_stat_usunc); | 
|  | 1643 | device_create_file(&intf->dev, &dev_attr_stat_dsunc); | 
|  | 1644 | } | 
|  | 1645 |  | 
|  | 1646 | static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf, | 
| Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 1647 | const struct usb_device_id *id) | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1648 | { | 
|  | 1649 | struct usb_device *usb = interface_to_usbdev(intf); | 
|  | 1650 | struct uea_softc *sc; | 
|  | 1651 | int ret, ifnum = intf->altsetting->desc.bInterfaceNumber; | 
|  | 1652 |  | 
|  | 1653 | uea_enters(usb); | 
|  | 1654 |  | 
|  | 1655 | /* interface 0 is for firmware/monitoring */ | 
|  | 1656 | if (ifnum != UEA_INTR_IFACE_NO) | 
|  | 1657 | return -ENODEV; | 
|  | 1658 |  | 
| Duncan Sands | 0dfcd3e | 2006-01-13 09:36:20 +0100 | [diff] [blame] | 1659 | usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1660 |  | 
|  | 1661 | /* interface 1 is for outbound traffic */ | 
|  | 1662 | ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO); | 
|  | 1663 | if (ret < 0) | 
|  | 1664 | return ret; | 
|  | 1665 |  | 
| matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 1666 | /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */ | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1667 | if (UEA_CHIP_VERSION(id) != ADI930) { | 
|  | 1668 | /* interface 2 is for inbound traffic */ | 
|  | 1669 | ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO); | 
|  | 1670 | if (ret < 0) | 
|  | 1671 | return ret; | 
|  | 1672 | } | 
|  | 1673 |  | 
|  | 1674 | sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL); | 
|  | 1675 | if (!sc) { | 
| matthieu castet | 584958c | 2006-04-02 18:44:48 +0200 | [diff] [blame] | 1676 | uea_err(usb, "uea_init: not enough memory !\n"); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1677 | return -ENOMEM; | 
|  | 1678 | } | 
|  | 1679 |  | 
|  | 1680 | sc->usb_dev = usb; | 
|  | 1681 | usbatm->driver_data = sc; | 
|  | 1682 | sc->usbatm = usbatm; | 
|  | 1683 | sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0; | 
|  | 1684 | sc->driver_info = id->driver_info; | 
|  | 1685 |  | 
| matthieu castet | 3c9666c | 2006-01-18 07:38:19 +0100 | [diff] [blame] | 1686 | /* ADI930 don't support iso */ | 
|  | 1687 | if (UEA_CHIP_VERSION(id) != ADI930 && use_iso[sc->modem_index]) { | 
|  | 1688 | int i; | 
|  | 1689 |  | 
|  | 1690 | /* try set fastest alternate for inbound traffic interface */ | 
|  | 1691 | for (i = FASTEST_ISO_INTF; i > 0; i--) | 
|  | 1692 | if (usb_set_interface(usb, UEA_DS_IFACE_NO, i) == 0) | 
|  | 1693 | break; | 
|  | 1694 |  | 
|  | 1695 | if (i > 0) { | 
|  | 1696 | uea_dbg(usb, "set alternate %d for 2 interface\n", i); | 
|  | 1697 | uea_info(usb, "using iso mode\n"); | 
|  | 1698 | usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ; | 
|  | 1699 | } else { | 
|  | 1700 | uea_err(usb, "setting any alternate failed for " | 
|  | 1701 | "2 interface, using bulk mode\n"); | 
|  | 1702 | } | 
|  | 1703 | } | 
|  | 1704 |  | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1705 | ret = uea_boot(sc); | 
|  | 1706 | if (ret < 0) { | 
|  | 1707 | kfree(sc); | 
|  | 1708 | return ret; | 
|  | 1709 | } | 
|  | 1710 |  | 
|  | 1711 | create_fs_entries(sc, intf); | 
|  | 1712 | return 0; | 
|  | 1713 | } | 
|  | 1714 |  | 
|  | 1715 | static void destroy_fs_entries(struct uea_softc *sc, struct usb_interface *intf) | 
|  | 1716 | { | 
|  | 1717 | /* sysfs interface */ | 
|  | 1718 | device_remove_file(&intf->dev, &dev_attr_stat_status); | 
|  | 1719 | device_remove_file(&intf->dev, &dev_attr_stat_mflags); | 
|  | 1720 | device_remove_file(&intf->dev, &dev_attr_stat_human_status); | 
|  | 1721 | device_remove_file(&intf->dev, &dev_attr_stat_delin); | 
|  | 1722 | device_remove_file(&intf->dev, &dev_attr_stat_vidcpe); | 
|  | 1723 | device_remove_file(&intf->dev, &dev_attr_stat_usrate); | 
|  | 1724 | device_remove_file(&intf->dev, &dev_attr_stat_dsrate); | 
|  | 1725 | device_remove_file(&intf->dev, &dev_attr_stat_usattenuation); | 
|  | 1726 | device_remove_file(&intf->dev, &dev_attr_stat_dsattenuation); | 
|  | 1727 | device_remove_file(&intf->dev, &dev_attr_stat_usmargin); | 
|  | 1728 | device_remove_file(&intf->dev, &dev_attr_stat_dsmargin); | 
|  | 1729 | device_remove_file(&intf->dev, &dev_attr_stat_txflow); | 
|  | 1730 | device_remove_file(&intf->dev, &dev_attr_stat_rxflow); | 
|  | 1731 | device_remove_file(&intf->dev, &dev_attr_stat_uscorr); | 
|  | 1732 | device_remove_file(&intf->dev, &dev_attr_stat_dscorr); | 
|  | 1733 | device_remove_file(&intf->dev, &dev_attr_stat_usunc); | 
|  | 1734 | device_remove_file(&intf->dev, &dev_attr_stat_dsunc); | 
|  | 1735 | } | 
|  | 1736 |  | 
|  | 1737 | static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf) | 
|  | 1738 | { | 
|  | 1739 | struct uea_softc *sc = usbatm->driver_data; | 
|  | 1740 |  | 
|  | 1741 | destroy_fs_entries(sc, intf); | 
|  | 1742 | uea_stop(sc); | 
|  | 1743 | kfree(sc); | 
|  | 1744 | } | 
|  | 1745 |  | 
|  | 1746 | static struct usbatm_driver uea_usbatm_driver = { | 
|  | 1747 | .driver_name = "ueagle-atm", | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1748 | .bind = uea_bind, | 
|  | 1749 | .atm_start = uea_atm_open, | 
|  | 1750 | .unbind = uea_unbind, | 
|  | 1751 | .heavy_init = uea_heavy, | 
| Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 1752 | .bulk_in = UEA_BULK_DATA_PIPE, | 
|  | 1753 | .bulk_out = UEA_BULK_DATA_PIPE, | 
| matthieu castet | 3c9666c | 2006-01-18 07:38:19 +0100 | [diff] [blame] | 1754 | .isoc_in = UEA_ISO_DATA_PIPE, | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1755 | }; | 
|  | 1756 |  | 
|  | 1757 | static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id) | 
|  | 1758 | { | 
|  | 1759 | struct usb_device *usb = interface_to_usbdev(intf); | 
|  | 1760 |  | 
|  | 1761 | uea_enters(usb); | 
|  | 1762 | uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) : %s\n", | 
|  | 1763 | le16_to_cpu(usb->descriptor.idVendor), | 
|  | 1764 | le16_to_cpu(usb->descriptor.idProduct), | 
|  | 1765 | chip_name[UEA_CHIP_VERSION(id)]); | 
|  | 1766 |  | 
|  | 1767 | usb_reset_device(usb); | 
|  | 1768 |  | 
|  | 1769 | if (UEA_IS_PREFIRM(id)) | 
|  | 1770 | return uea_load_firmware(usb, UEA_CHIP_VERSION(id)); | 
|  | 1771 |  | 
|  | 1772 | return usbatm_usb_probe(intf, id, &uea_usbatm_driver); | 
|  | 1773 | } | 
|  | 1774 |  | 
|  | 1775 | static void uea_disconnect(struct usb_interface *intf) | 
|  | 1776 | { | 
|  | 1777 | struct usb_device *usb = interface_to_usbdev(intf); | 
|  | 1778 | int ifnum = intf->altsetting->desc.bInterfaceNumber; | 
|  | 1779 | uea_enters(usb); | 
|  | 1780 |  | 
|  | 1781 | /* ADI930 has 2 interfaces and eagle 3 interfaces. | 
|  | 1782 | * Pre-firmware device has one interface | 
|  | 1783 | */ | 
|  | 1784 | if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) { | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 1785 | mutex_lock(&uea_mutex); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1786 | usbatm_usb_disconnect(intf); | 
| Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 1787 | mutex_unlock(&uea_mutex); | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1788 | uea_info(usb, "ADSL device removed\n"); | 
|  | 1789 | } | 
|  | 1790 |  | 
|  | 1791 | uea_leaves(usb); | 
|  | 1792 | } | 
|  | 1793 |  | 
|  | 1794 | /* | 
|  | 1795 | * List of supported VID/PID | 
|  | 1796 | */ | 
|  | 1797 | static const struct usb_device_id uea_ids[] = { | 
|  | 1798 | {USB_DEVICE(ELSA_VID,	ELSA_PID_PREFIRM),	.driver_info = ADI930 | PREFIRM}, | 
|  | 1799 | {USB_DEVICE(ELSA_VID,	ELSA_PID_PSTFIRM),	.driver_info = ADI930 | PSTFIRM}, | 
|  | 1800 | {USB_DEVICE(EAGLE_VID,	EAGLE_I_PID_PREFIRM),	.driver_info = EAGLE_I | PREFIRM}, | 
|  | 1801 | {USB_DEVICE(EAGLE_VID,	EAGLE_I_PID_PSTFIRM),	.driver_info = EAGLE_I | PSTFIRM}, | 
|  | 1802 | {USB_DEVICE(EAGLE_VID,	EAGLE_II_PID_PREFIRM),	.driver_info = EAGLE_II | PREFIRM}, | 
|  | 1803 | {USB_DEVICE(EAGLE_VID,	EAGLE_II_PID_PSTFIRM),	.driver_info = EAGLE_II | PSTFIRM}, | 
|  | 1804 | {USB_DEVICE(EAGLE_VID,	EAGLE_IIC_PID_PREFIRM),	.driver_info = EAGLE_II | PREFIRM}, | 
|  | 1805 | {USB_DEVICE(EAGLE_VID,	EAGLE_IIC_PID_PSTFIRM),	.driver_info = EAGLE_II | PSTFIRM}, | 
|  | 1806 | {USB_DEVICE(EAGLE_VID,	EAGLE_III_PID_PREFIRM),	.driver_info = EAGLE_III | PREFIRM}, | 
|  | 1807 | {USB_DEVICE(EAGLE_VID,	EAGLE_III_PID_PSTFIRM),	.driver_info = EAGLE_III | PSTFIRM}, | 
|  | 1808 | {USB_DEVICE(USR_VID,	MILLER_A_PID_PREFIRM),	.driver_info = EAGLE_I | PREFIRM}, | 
|  | 1809 | {USB_DEVICE(USR_VID,	MILLER_A_PID_PSTFIRM),	.driver_info = EAGLE_I | PSTFIRM}, | 
|  | 1810 | {USB_DEVICE(USR_VID,	MILLER_B_PID_PREFIRM),	.driver_info = EAGLE_I | PREFIRM}, | 
|  | 1811 | {USB_DEVICE(USR_VID,	MILLER_B_PID_PSTFIRM),	.driver_info = EAGLE_I | PSTFIRM}, | 
|  | 1812 | {USB_DEVICE(USR_VID,	HEINEKEN_A_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM}, | 
|  | 1813 | {USB_DEVICE(USR_VID,	HEINEKEN_A_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM}, | 
|  | 1814 | {USB_DEVICE(USR_VID,	HEINEKEN_B_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM}, | 
|  | 1815 | {USB_DEVICE(USR_VID,	HEINEKEN_B_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM}, | 
|  | 1816 | {} | 
|  | 1817 | }; | 
|  | 1818 |  | 
|  | 1819 | /* | 
|  | 1820 | * USB driver descriptor | 
|  | 1821 | */ | 
|  | 1822 | static struct usb_driver uea_driver = { | 
| matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1823 | .name = "ueagle-atm", | 
|  | 1824 | .id_table = uea_ids, | 
|  | 1825 | .probe = uea_probe, | 
|  | 1826 | .disconnect = uea_disconnect, | 
|  | 1827 | }; | 
|  | 1828 |  | 
|  | 1829 | MODULE_DEVICE_TABLE(usb, uea_ids); | 
|  | 1830 |  | 
|  | 1831 | /** | 
|  | 1832 | * uea_init - Initialize the module. | 
|  | 1833 | *      Register to USB subsystem | 
|  | 1834 | */ | 
|  | 1835 | static int __init uea_init(void) | 
|  | 1836 | { | 
|  | 1837 | printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n"); | 
|  | 1838 |  | 
|  | 1839 | usb_register(&uea_driver); | 
|  | 1840 |  | 
|  | 1841 | return 0; | 
|  | 1842 | } | 
|  | 1843 |  | 
|  | 1844 | module_init(uea_init); | 
|  | 1845 |  | 
|  | 1846 | /** | 
|  | 1847 | * uea_exit  -  Destroy module | 
|  | 1848 | *    Deregister with USB subsystem | 
|  | 1849 | */ | 
|  | 1850 | static void __exit uea_exit(void) | 
|  | 1851 | { | 
|  | 1852 | /* | 
|  | 1853 | * This calls automatically the uea_disconnect method if necessary: | 
|  | 1854 | */ | 
|  | 1855 | usb_deregister(&uea_driver); | 
|  | 1856 |  | 
|  | 1857 | printk(KERN_INFO "[ueagle-atm] driver unloaded\n"); | 
|  | 1858 | } | 
|  | 1859 |  | 
|  | 1860 | module_exit(uea_exit); | 
|  | 1861 |  | 
|  | 1862 | MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka"); | 
|  | 1863 | MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver"); | 
|  | 1864 | MODULE_LICENSE("Dual BSD/GPL"); |