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 | * |
Stanislaw Gruszka | 0eb0226 | 2007-08-20 23:21:19 +0200 | [diff] [blame] | 5 | * Copyright (c) 2005-2007 Matthieu Castet <castet.matthieu@free.fr> |
| 6 | * Copyright (c) 2005-2007 Stanislaw Gruszka <stf_xl@wp.pl> |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 7 | * |
| 8 | * This software is available to you under a choice of one of two |
| 9 | * licenses. You may choose to be licensed under the terms of the GNU |
| 10 | * General Public License (GPL) Version 2, available from the file |
| 11 | * COPYING in the main directory of this source tree, or the |
| 12 | * BSD license below: |
| 13 | * |
| 14 | * Redistribution and use in source and binary forms, with or without |
| 15 | * modification, are permitted provided that the following conditions |
| 16 | * are met: |
| 17 | * 1. Redistributions of source code must retain the above copyright |
| 18 | * notice unmodified, this list of conditions, and the following |
| 19 | * disclaimer. |
| 20 | * 2. Redistributions in binary form must reproduce the above copyright |
| 21 | * notice, this list of conditions and the following disclaimer in the |
| 22 | * documentation and/or other materials provided with the distribution. |
| 23 | * |
| 24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | * SUCH DAMAGE. |
| 35 | * |
| 36 | * GPL license : |
| 37 | * This program is free software; you can redistribute it and/or |
| 38 | * modify it under the terms of the GNU General Public License |
| 39 | * as published by the Free Software Foundation; either version 2 |
| 40 | * of the License, or (at your option) any later version. |
| 41 | * |
| 42 | * This program is distributed in the hope that it will be useful, |
| 43 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 44 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 45 | * GNU General Public License for more details. |
| 46 | * |
| 47 | * You should have received a copy of the GNU General Public License |
| 48 | * along with this program; if not, write to the Free Software |
| 49 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 50 | * |
| 51 | * |
| 52 | * HISTORY : some part of the code was base on ueagle 1.3 BSD driver, |
| 53 | * Damien Bergamini agree to put his code under a DUAL GPL/BSD license. |
| 54 | * |
| 55 | * The rest of the code was was rewritten from scratch. |
| 56 | */ |
| 57 | |
| 58 | #include <linux/module.h> |
| 59 | #include <linux/moduleparam.h> |
| 60 | #include <linux/init.h> |
| 61 | #include <linux/crc32.h> |
| 62 | #include <linux/usb.h> |
| 63 | #include <linux/firmware.h> |
| 64 | #include <linux/ctype.h> |
Randy Dunlap | 5371f80 | 2007-02-16 01:47:33 -0800 | [diff] [blame] | 65 | #include <linux/sched.h> |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 66 | #include <linux/kthread.h> |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 67 | #include <linux/mutex.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 68 | #include <linux/freezer.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 69 | #include <linux/slab.h> |
Andy Shevchenko | e644814 | 2010-06-15 17:04:44 +0300 | [diff] [blame] | 70 | #include <linux/kernel.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 71 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 72 | #include <asm/unaligned.h> |
| 73 | |
| 74 | #include "usbatm.h" |
| 75 | |
matthieu castet | a7a0c9c | 2006-10-03 21:44:11 +0200 | [diff] [blame] | 76 | #define EAGLEUSBVERSION "ueagle 1.4" |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 77 | |
| 78 | |
| 79 | /* |
| 80 | * Debug macros |
| 81 | */ |
| 82 | #define uea_dbg(usb_dev, format, args...) \ |
| 83 | do { \ |
| 84 | if (debug >= 1) \ |
| 85 | dev_dbg(&(usb_dev)->dev, \ |
| 86 | "[ueagle-atm dbg] %s: " format, \ |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 87 | __func__, ##args); \ |
matthieu castet | a7a0c9c | 2006-10-03 21:44:11 +0200 | [diff] [blame] | 88 | } while (0) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 89 | |
| 90 | #define uea_vdbg(usb_dev, format, args...) \ |
| 91 | do { \ |
| 92 | if (debug >= 2) \ |
| 93 | dev_dbg(&(usb_dev)->dev, \ |
| 94 | "[ueagle-atm vdbg] " format, ##args); \ |
matthieu castet | a7a0c9c | 2006-10-03 21:44:11 +0200 | [diff] [blame] | 95 | } while (0) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 96 | |
| 97 | #define uea_enters(usb_dev) \ |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 98 | uea_vdbg(usb_dev, "entering %s\n" , __func__) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 99 | |
| 100 | #define uea_leaves(usb_dev) \ |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 101 | uea_vdbg(usb_dev, "leaving %s\n" , __func__) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 102 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 103 | #define uea_err(usb_dev, format, args...) \ |
| 104 | dev_err(&(usb_dev)->dev , "[UEAGLE-ATM] " format , ##args) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 105 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 106 | #define uea_warn(usb_dev, format, args...) \ |
| 107 | dev_warn(&(usb_dev)->dev , "[Ueagle-atm] " format, ##args) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 108 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 109 | #define uea_info(usb_dev, format, args...) \ |
| 110 | dev_info(&(usb_dev)->dev , "[ueagle-atm] " format, ##args) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 111 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 112 | struct intr_pkt; |
| 113 | |
| 114 | /* cmv's from firmware */ |
| 115 | struct uea_cmvs_v1 { |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 116 | u32 address; |
| 117 | u16 offset; |
| 118 | u32 data; |
| 119 | } __attribute__ ((packed)); |
| 120 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 121 | struct uea_cmvs_v2 { |
| 122 | u32 group; |
| 123 | u32 address; |
| 124 | u32 offset; |
| 125 | u32 data; |
| 126 | } __attribute__ ((packed)); |
| 127 | |
| 128 | /* information about currently processed cmv */ |
| 129 | struct cmv_dsc_e1 { |
| 130 | u8 function; |
| 131 | u16 idx; |
| 132 | u32 address; |
| 133 | u16 offset; |
| 134 | }; |
| 135 | |
| 136 | struct cmv_dsc_e4 { |
| 137 | u16 function; |
| 138 | u16 offset; |
| 139 | u16 address; |
| 140 | u16 group; |
| 141 | }; |
| 142 | |
| 143 | union cmv_dsc { |
| 144 | struct cmv_dsc_e1 e1; |
| 145 | struct cmv_dsc_e4 e4; |
| 146 | }; |
| 147 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 148 | struct uea_softc { |
| 149 | struct usb_device *usb_dev; |
| 150 | struct usbatm_data *usbatm; |
| 151 | |
| 152 | int modem_index; |
| 153 | unsigned int driver_info; |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 154 | int annex; |
| 155 | #define ANNEXA 0 |
| 156 | #define ANNEXB 1 |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 157 | |
| 158 | int booting; |
| 159 | int reset; |
| 160 | |
| 161 | wait_queue_head_t sync_q; |
| 162 | |
| 163 | struct task_struct *kthread; |
| 164 | u32 data; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 165 | u32 data1; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 166 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 167 | int cmv_ack; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 168 | union cmv_dsc cmv_dsc; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 169 | |
| 170 | struct work_struct task; |
Stanislaw Gruszka | 04ea02f | 2007-08-20 23:21:10 +0200 | [diff] [blame] | 171 | struct workqueue_struct *work_q; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 172 | u16 pageno; |
| 173 | u16 ovl; |
| 174 | |
| 175 | const struct firmware *dsp_firm; |
| 176 | struct urb *urb_int; |
| 177 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 178 | void (*dispatch_cmv) (struct uea_softc *, struct intr_pkt *); |
| 179 | void (*schedule_load_page) (struct uea_softc *, struct intr_pkt *); |
| 180 | int (*stat) (struct uea_softc *); |
| 181 | int (*send_cmvs) (struct uea_softc *); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 182 | |
| 183 | /* keep in sync with eaglectl */ |
| 184 | struct uea_stats { |
| 185 | struct { |
| 186 | u32 state; |
| 187 | u32 flags; |
| 188 | u32 mflags; |
| 189 | u32 vidcpe; |
| 190 | u32 vidco; |
| 191 | u32 dsrate; |
| 192 | u32 usrate; |
| 193 | u32 dsunc; |
| 194 | u32 usunc; |
| 195 | u32 dscorr; |
| 196 | u32 uscorr; |
| 197 | u32 txflow; |
| 198 | u32 rxflow; |
| 199 | u32 usattenuation; |
| 200 | u32 dsattenuation; |
| 201 | u32 dsmargin; |
| 202 | u32 usmargin; |
| 203 | u32 firmid; |
| 204 | } phy; |
| 205 | } stats; |
| 206 | }; |
| 207 | |
| 208 | /* |
| 209 | * Elsa IDs |
| 210 | */ |
| 211 | #define ELSA_VID 0x05CC |
| 212 | #define ELSA_PID_PSTFIRM 0x3350 |
| 213 | #define ELSA_PID_PREFIRM 0x3351 |
| 214 | |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 215 | #define ELSA_PID_A_PREFIRM 0x3352 |
| 216 | #define ELSA_PID_A_PSTFIRM 0x3353 |
| 217 | #define ELSA_PID_B_PREFIRM 0x3362 |
| 218 | #define ELSA_PID_B_PSTFIRM 0x3363 |
| 219 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 220 | /* |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 221 | * Devolo IDs : pots if (pid & 0x10) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 222 | */ |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 223 | #define DEVOLO_VID 0x1039 |
| 224 | #define DEVOLO_EAGLE_I_A_PID_PSTFIRM 0x2110 |
| 225 | #define DEVOLO_EAGLE_I_A_PID_PREFIRM 0x2111 |
| 226 | |
| 227 | #define DEVOLO_EAGLE_I_B_PID_PSTFIRM 0x2100 |
| 228 | #define DEVOLO_EAGLE_I_B_PID_PREFIRM 0x2101 |
| 229 | |
| 230 | #define DEVOLO_EAGLE_II_A_PID_PSTFIRM 0x2130 |
| 231 | #define DEVOLO_EAGLE_II_A_PID_PREFIRM 0x2131 |
| 232 | |
| 233 | #define DEVOLO_EAGLE_II_B_PID_PSTFIRM 0x2120 |
| 234 | #define DEVOLO_EAGLE_II_B_PID_PREFIRM 0x2121 |
| 235 | |
| 236 | /* |
| 237 | * Reference design USB IDs |
| 238 | */ |
| 239 | #define ANALOG_VID 0x1110 |
| 240 | #define ADI930_PID_PREFIRM 0x9001 |
| 241 | #define ADI930_PID_PSTFIRM 0x9000 |
| 242 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 243 | #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */ |
| 244 | #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */ |
| 245 | |
| 246 | #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */ |
| 247 | #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */ |
| 248 | |
| 249 | #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */ |
| 250 | #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */ |
| 251 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 252 | #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */ |
| 253 | #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */ |
| 254 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 255 | #define EAGLE_IV_PID_PREFIRM 0x9042 /* Eagle IV */ |
| 256 | #define EAGLE_IV_PID_PSTFIRM 0x9041 /* Eagle IV */ |
| 257 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 258 | /* |
| 259 | * USR USB IDs |
| 260 | */ |
| 261 | #define USR_VID 0x0BAF |
| 262 | #define MILLER_A_PID_PREFIRM 0x00F2 |
| 263 | #define MILLER_A_PID_PSTFIRM 0x00F1 |
| 264 | #define MILLER_B_PID_PREFIRM 0x00FA |
| 265 | #define MILLER_B_PID_PSTFIRM 0x00F9 |
| 266 | #define HEINEKEN_A_PID_PREFIRM 0x00F6 |
| 267 | #define HEINEKEN_A_PID_PSTFIRM 0x00F5 |
| 268 | #define HEINEKEN_B_PID_PREFIRM 0x00F8 |
| 269 | #define HEINEKEN_B_PID_PSTFIRM 0x00F7 |
| 270 | |
| 271 | #define PREFIRM 0 |
| 272 | #define PSTFIRM (1<<7) |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 273 | #define AUTO_ANNEX_A (1<<8) |
| 274 | #define AUTO_ANNEX_B (1<<9) |
| 275 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 276 | enum { |
| 277 | ADI930 = 0, |
| 278 | EAGLE_I, |
| 279 | EAGLE_II, |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 280 | EAGLE_III, |
| 281 | EAGLE_IV |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 282 | }; |
| 283 | |
| 284 | /* macros for both struct usb_device_id and struct uea_softc */ |
| 285 | #define UEA_IS_PREFIRM(x) \ |
| 286 | (!((x)->driver_info & PSTFIRM)) |
| 287 | #define UEA_CHIP_VERSION(x) \ |
| 288 | ((x)->driver_info & 0xf) |
| 289 | |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 290 | #define IS_ISDN(x) \ |
| 291 | ((x)->annex & ANNEXB) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 292 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 293 | #define INS_TO_USBDEV(ins) (ins->usb_dev) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 294 | |
| 295 | #define GET_STATUS(data) \ |
| 296 | ((data >> 8) & 0xf) |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 297 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 298 | #define IS_OPERATIONAL(sc) \ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 299 | ((UEA_CHIP_VERSION(sc) != EAGLE_IV) ? \ |
| 300 | (GET_STATUS(sc->stats.phy.state) == 2) : \ |
| 301 | (sc->stats.phy.state == 7)) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 302 | |
| 303 | /* |
| 304 | * Set of macros to handle unaligned data in the firmware blob. |
| 305 | * The FW_GET_BYTE() macro is provided only for consistency. |
| 306 | */ |
| 307 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 308 | #define FW_GET_BYTE(p) (*((__u8 *) (p))) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 309 | |
| 310 | #define FW_DIR "ueagle-atm/" |
Samuel Ortiz | ade901d | 2009-05-27 00:49:32 +0200 | [diff] [blame] | 311 | #define UEA_FW_NAME_MAX 30 |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 312 | #define NB_MODEM 4 |
| 313 | |
| 314 | #define BULK_TIMEOUT 300 |
| 315 | #define CTRL_TIMEOUT 1000 |
| 316 | |
matthieu castet | 22fcceb | 2006-04-02 18:44:20 +0200 | [diff] [blame] | 317 | #define ACK_TIMEOUT msecs_to_jiffies(3000) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 318 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 319 | #define UEA_INTR_IFACE_NO 0 |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 320 | #define UEA_US_IFACE_NO 1 |
| 321 | #define UEA_DS_IFACE_NO 2 |
| 322 | |
| 323 | #define FASTEST_ISO_INTF 8 |
| 324 | |
| 325 | #define UEA_BULK_DATA_PIPE 0x02 |
| 326 | #define UEA_IDMA_PIPE 0x04 |
| 327 | #define UEA_INTR_PIPE 0x04 |
| 328 | #define UEA_ISO_DATA_PIPE 0x08 |
| 329 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 330 | #define UEA_E1_SET_BLOCK 0x0001 |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 331 | #define UEA_E4_SET_BLOCK 0x002c |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 332 | #define UEA_SET_MODE 0x0003 |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 333 | #define UEA_SET_2183_DATA 0x0004 |
| 334 | #define UEA_SET_TIMEOUT 0x0011 |
| 335 | |
| 336 | #define UEA_LOOPBACK_OFF 0x0002 |
| 337 | #define UEA_LOOPBACK_ON 0x0003 |
| 338 | #define UEA_BOOT_IDMA 0x0006 |
| 339 | #define UEA_START_RESET 0x0007 |
| 340 | #define UEA_END_RESET 0x0008 |
| 341 | |
| 342 | #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000) |
| 343 | #define UEA_MPTX_START (0x3fce | 0x4000) |
| 344 | #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000) |
| 345 | #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000) |
| 346 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 347 | /* block information in eagle4 dsp firmware */ |
| 348 | struct block_index { |
| 349 | __le32 PageOffset; |
| 350 | __le32 NotLastBlock; |
| 351 | __le32 dummy; |
| 352 | __le32 PageSize; |
| 353 | __le32 PageAddress; |
| 354 | __le16 dummy1; |
| 355 | __le16 PageNumber; |
| 356 | } __attribute__ ((packed)); |
| 357 | |
| 358 | #define E4_IS_BOOT_PAGE(PageSize) ((le32_to_cpu(PageSize)) & 0x80000000) |
| 359 | #define E4_PAGE_BYTES(PageSize) ((le32_to_cpu(PageSize) & 0x7fffffff) * 4) |
| 360 | |
| 361 | #define E4_L1_STRING_HEADER 0x10 |
| 362 | #define E4_MAX_PAGE_NUMBER 0x58 |
| 363 | #define E4_NO_SWAPPAGE_HEADERS 0x31 |
| 364 | |
| 365 | /* l1_code is eagle4 dsp firmware format */ |
| 366 | struct l1_code { |
| 367 | u8 string_header[E4_L1_STRING_HEADER]; |
| 368 | u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER]; |
| 369 | struct block_index page_header[E4_NO_SWAPPAGE_HEADERS]; |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 370 | u8 code[0]; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 371 | } __attribute__ ((packed)); |
| 372 | |
| 373 | /* structures describing a block within a DSP page */ |
| 374 | struct block_info_e1 { |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 375 | __le16 wHdr; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 376 | __le16 wAddress; |
| 377 | __le16 wSize; |
| 378 | __le16 wOvlOffset; |
| 379 | __le16 wOvl; /* overlay */ |
| 380 | __le16 wLast; |
| 381 | } __attribute__ ((packed)); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 382 | #define E1_BLOCK_INFO_SIZE 12 |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 383 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 384 | struct block_info_e4 { |
| 385 | __be16 wHdr; |
| 386 | __u8 bBootPage; |
| 387 | __u8 bPageNumber; |
| 388 | __be32 dwSize; |
| 389 | __be32 dwAddress; |
| 390 | __be16 wReserved; |
| 391 | } __attribute__ ((packed)); |
| 392 | #define E4_BLOCK_INFO_SIZE 14 |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 393 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 394 | #define UEA_BIHDR 0xabcd |
| 395 | #define UEA_RESERVED 0xffff |
| 396 | |
| 397 | /* constants describing cmv type */ |
| 398 | #define E1_PREAMBLE 0x535c |
| 399 | #define E1_MODEMTOHOST 0x01 |
| 400 | #define E1_HOSTTOMODEM 0x10 |
| 401 | |
| 402 | #define E1_MEMACCESS 0x1 |
| 403 | #define E1_ADSLDIRECTIVE 0x7 |
| 404 | #define E1_FUNCTION_TYPE(f) ((f) >> 4) |
| 405 | #define E1_FUNCTION_SUBTYPE(f) ((f) & 0x0f) |
| 406 | |
| 407 | #define E4_MEMACCESS 0 |
| 408 | #define E4_ADSLDIRECTIVE 0xf |
| 409 | #define E4_FUNCTION_TYPE(f) ((f) >> 8) |
| 410 | #define E4_FUNCTION_SIZE(f) ((f) & 0x0f) |
| 411 | #define E4_FUNCTION_SUBTYPE(f) (((f) >> 4) & 0x0f) |
| 412 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 413 | /* for MEMACCESS */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 414 | #define E1_REQUESTREAD 0x0 |
| 415 | #define E1_REQUESTWRITE 0x1 |
| 416 | #define E1_REPLYREAD 0x2 |
| 417 | #define E1_REPLYWRITE 0x3 |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 418 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 419 | #define E4_REQUESTREAD 0x0 |
| 420 | #define E4_REQUESTWRITE 0x4 |
| 421 | #define E4_REPLYREAD (E4_REQUESTREAD | 1) |
| 422 | #define E4_REPLYWRITE (E4_REQUESTWRITE | 1) |
| 423 | |
| 424 | /* for ADSLDIRECTIVE */ |
| 425 | #define E1_KERNELREADY 0x0 |
| 426 | #define E1_MODEMREADY 0x1 |
| 427 | |
| 428 | #define E4_KERNELREADY 0x0 |
| 429 | #define E4_MODEMREADY 0x1 |
| 430 | |
| 431 | #define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf)) |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 432 | #define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | \ |
| 433 | ((st) & 0xf) << 4 | ((s) & 0xf)) |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 434 | |
| 435 | #define E1_MAKESA(a, b, c, d) \ |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 436 | (((c) & 0xff) << 24 | \ |
| 437 | ((d) & 0xff) << 16 | \ |
| 438 | ((a) & 0xff) << 8 | \ |
| 439 | ((b) & 0xff)) |
| 440 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 441 | #define E1_GETSA1(a) ((a >> 8) & 0xff) |
| 442 | #define E1_GETSA2(a) (a & 0xff) |
| 443 | #define E1_GETSA3(a) ((a >> 24) & 0xff) |
| 444 | #define E1_GETSA4(a) ((a >> 16) & 0xff) |
| 445 | |
| 446 | #define E1_SA_CNTL E1_MAKESA('C', 'N', 'T', 'L') |
| 447 | #define E1_SA_DIAG E1_MAKESA('D', 'I', 'A', 'G') |
| 448 | #define E1_SA_INFO E1_MAKESA('I', 'N', 'F', 'O') |
| 449 | #define E1_SA_OPTN E1_MAKESA('O', 'P', 'T', 'N') |
| 450 | #define E1_SA_RATE E1_MAKESA('R', 'A', 'T', 'E') |
| 451 | #define E1_SA_STAT E1_MAKESA('S', 'T', 'A', 'T') |
| 452 | |
| 453 | #define E4_SA_CNTL 1 |
| 454 | #define E4_SA_STAT 2 |
| 455 | #define E4_SA_INFO 3 |
| 456 | #define E4_SA_TEST 4 |
| 457 | #define E4_SA_OPTN 5 |
| 458 | #define E4_SA_RATE 6 |
| 459 | #define E4_SA_DIAG 7 |
| 460 | #define E4_SA_CNFG 8 |
| 461 | |
| 462 | /* structures representing a CMV (Configuration and Management Variable) */ |
| 463 | struct cmv_e1 { |
| 464 | __le16 wPreamble; |
| 465 | __u8 bDirection; |
| 466 | __u8 bFunction; |
| 467 | __le16 wIndex; |
| 468 | __le32 dwSymbolicAddress; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 469 | __le16 wOffsetAddress; |
| 470 | __le32 dwData; |
| 471 | } __attribute__ ((packed)); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 472 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 473 | struct cmv_e4 { |
| 474 | __be16 wGroup; |
| 475 | __be16 wFunction; |
| 476 | __be16 wOffset; |
| 477 | __be16 wAddress; |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 478 | __be32 dwData[6]; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 479 | } __attribute__ ((packed)); |
| 480 | |
| 481 | /* structures representing swap information */ |
| 482 | struct swap_info_e1 { |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 483 | __u8 bSwapPageNo; |
| 484 | __u8 bOvl; /* overlay */ |
| 485 | } __attribute__ ((packed)); |
| 486 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 487 | struct swap_info_e4 { |
| 488 | __u8 bSwapPageNo; |
| 489 | } __attribute__ ((packed)); |
| 490 | |
| 491 | /* structures representing interrupt data */ |
| 492 | #define e1_bSwapPageNo u.e1.s1.swapinfo.bSwapPageNo |
| 493 | #define e1_bOvl u.e1.s1.swapinfo.bOvl |
| 494 | #define e4_bSwapPageNo u.e4.s1.swapinfo.bSwapPageNo |
| 495 | |
| 496 | #define INT_LOADSWAPPAGE 0x0001 |
| 497 | #define INT_INCOMINGCMV 0x0002 |
| 498 | |
| 499 | union intr_data_e1 { |
| 500 | struct { |
| 501 | struct swap_info_e1 swapinfo; |
| 502 | __le16 wDataSize; |
| 503 | } __attribute__ ((packed)) s1; |
| 504 | struct { |
| 505 | struct cmv_e1 cmv; |
| 506 | __le16 wDataSize; |
| 507 | } __attribute__ ((packed)) s2; |
| 508 | } __attribute__ ((packed)); |
| 509 | |
| 510 | union intr_data_e4 { |
| 511 | struct { |
| 512 | struct swap_info_e4 swapinfo; |
| 513 | __le16 wDataSize; |
| 514 | } __attribute__ ((packed)) s1; |
| 515 | struct { |
| 516 | struct cmv_e4 cmv; |
| 517 | __le16 wDataSize; |
| 518 | } __attribute__ ((packed)) s2; |
| 519 | } __attribute__ ((packed)); |
| 520 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 521 | struct intr_pkt { |
| 522 | __u8 bType; |
| 523 | __u8 bNotification; |
| 524 | __le16 wValue; |
| 525 | __le16 wIndex; |
| 526 | __le16 wLength; |
| 527 | __le16 wInterrupt; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 528 | union { |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 529 | union intr_data_e1 e1; |
| 530 | union intr_data_e4 e4; |
| 531 | } u; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 532 | } __attribute__ ((packed)); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 533 | |
| 534 | #define E1_INTR_PKT_SIZE 28 |
| 535 | #define E4_INTR_PKT_SIZE 64 |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 536 | |
| 537 | static struct usb_driver uea_driver; |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 538 | static DEFINE_MUTEX(uea_mutex); |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 539 | static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III", |
| 540 | "Eagle IV"}; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 541 | |
| 542 | static int modem_index; |
| 543 | static unsigned int debug; |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 544 | static unsigned int altsetting[NB_MODEM] = { |
| 545 | [0 ... (NB_MODEM - 1)] = FASTEST_ISO_INTF}; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 546 | static int sync_wait[NB_MODEM]; |
| 547 | static char *cmv_file[NB_MODEM]; |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 548 | static int annex[NB_MODEM]; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 549 | |
| 550 | module_param(debug, uint, 0644); |
| 551 | MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)"); |
Stanislaw Gruszka | 503add4 | 2007-08-20 23:21:06 +0200 | [diff] [blame] | 552 | module_param_array(altsetting, uint, NULL, 0644); |
| 553 | MODULE_PARM_DESC(altsetting, "alternate setting for incoming traffic: 0=bulk, " |
| 554 | "1=isoc slowest, ... , 8=isoc fastest (default)"); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 555 | module_param_array(sync_wait, bool, NULL, 0644); |
| 556 | MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM"); |
| 557 | module_param_array(cmv_file, charp, NULL, 0644); |
| 558 | MODULE_PARM_DESC(cmv_file, |
| 559 | "file name with configuration and management variables"); |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 560 | module_param_array(annex, uint, NULL, 0644); |
| 561 | MODULE_PARM_DESC(annex, |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 562 | "manually set annex a/b (0=auto, 1=annex a, 2=annex b)"); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 563 | |
Stanislaw Gruszka | 337427f | 2007-08-20 23:21:14 +0200 | [diff] [blame] | 564 | #define uea_wait(sc, cond, timeo) \ |
| 565 | ({ \ |
| 566 | int _r = wait_event_interruptible_timeout(sc->sync_q, \ |
| 567 | (cond) || kthread_should_stop(), timeo); \ |
| 568 | if (kthread_should_stop()) \ |
| 569 | _r = -ENODEV; \ |
| 570 | _r; \ |
| 571 | }) |
| 572 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 573 | #define UPDATE_ATM_STAT(type, val) \ |
| 574 | do { \ |
| 575 | if (sc->usbatm->atm_dev) \ |
| 576 | sc->usbatm->atm_dev->type = val; \ |
| 577 | } while (0) |
| 578 | |
Karl Hiramoto | cc7b86c | 2010-07-08 20:55:38 +0000 | [diff] [blame] | 579 | #define UPDATE_ATM_SIGNAL(val) \ |
| 580 | do { \ |
| 581 | if (sc->usbatm->atm_dev) \ |
| 582 | atm_dev_signal_change(sc->usbatm->atm_dev, val); \ |
| 583 | } while (0) |
| 584 | |
| 585 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 586 | /* Firmware loading */ |
| 587 | #define LOAD_INTERNAL 0xA0 |
| 588 | #define F8051_USBCS 0x7f92 |
| 589 | |
| 590 | /** |
| 591 | * uea_send_modem_cmd - Send a command for pre-firmware devices. |
| 592 | */ |
| 593 | static int uea_send_modem_cmd(struct usb_device *usb, |
David Woodhouse | aafcd2f | 2008-05-24 00:05:10 +0100 | [diff] [blame] | 594 | u16 addr, u16 size, const u8 *buff) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 595 | { |
| 596 | int ret = -ENOMEM; |
| 597 | u8 *xfer_buff; |
| 598 | |
Eric Sesterhenn | 5d7efe5 | 2006-10-26 21:06:24 +0200 | [diff] [blame] | 599 | xfer_buff = kmemdup(buff, size, GFP_KERNEL); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 600 | if (xfer_buff) { |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 601 | ret = usb_control_msg(usb, |
| 602 | usb_sndctrlpipe(usb, 0), |
| 603 | LOAD_INTERNAL, |
| 604 | USB_DIR_OUT | USB_TYPE_VENDOR | |
| 605 | USB_RECIP_DEVICE, addr, 0, xfer_buff, |
| 606 | size, CTRL_TIMEOUT); |
| 607 | kfree(xfer_buff); |
| 608 | } |
| 609 | |
| 610 | if (ret < 0) |
| 611 | return ret; |
| 612 | |
| 613 | return (ret == size) ? 0 : -EIO; |
| 614 | } |
| 615 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 616 | static void uea_upload_pre_firmware(const struct firmware *fw_entry, |
| 617 | void *context) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 618 | { |
| 619 | struct usb_device *usb = context; |
David Woodhouse | aafcd2f | 2008-05-24 00:05:10 +0100 | [diff] [blame] | 620 | const u8 *pfw; |
| 621 | u8 value; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 622 | u32 crc = 0; |
| 623 | int ret, size; |
| 624 | |
| 625 | uea_enters(usb); |
| 626 | if (!fw_entry) { |
| 627 | uea_err(usb, "firmware is not available\n"); |
| 628 | goto err; |
| 629 | } |
| 630 | |
| 631 | pfw = fw_entry->data; |
| 632 | size = fw_entry->size; |
matthieu castet | 8d7802e | 2005-11-08 00:02:30 +0100 | [diff] [blame] | 633 | if (size < 4) |
| 634 | goto err_fw_corrupted; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 635 | |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 636 | crc = get_unaligned_le32(pfw); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 637 | pfw += 4; |
| 638 | size -= 4; |
matthieu castet | 8d7802e | 2005-11-08 00:02:30 +0100 | [diff] [blame] | 639 | if (crc32_be(0, pfw, size) != crc) |
| 640 | goto err_fw_corrupted; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 641 | |
| 642 | /* |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 643 | * Start to upload firmware : send reset |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 644 | */ |
| 645 | value = 1; |
| 646 | ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value); |
| 647 | |
| 648 | if (ret < 0) { |
| 649 | uea_err(usb, "modem reset failed with error %d\n", ret); |
| 650 | goto err; |
| 651 | } |
| 652 | |
matthieu castet | 8d7802e | 2005-11-08 00:02:30 +0100 | [diff] [blame] | 653 | while (size > 3) { |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 654 | u8 len = FW_GET_BYTE(pfw); |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 655 | u16 add = get_unaligned_le16(pfw + 1); |
matthieu castet | 8d7802e | 2005-11-08 00:02:30 +0100 | [diff] [blame] | 656 | |
| 657 | size -= len + 3; |
| 658 | if (size < 0) |
| 659 | goto err_fw_corrupted; |
| 660 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 661 | ret = uea_send_modem_cmd(usb, add, len, pfw + 3); |
| 662 | if (ret < 0) { |
| 663 | uea_err(usb, "uploading firmware data failed " |
| 664 | "with error %d\n", ret); |
| 665 | goto err; |
| 666 | } |
| 667 | pfw += len + 3; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 668 | } |
| 669 | |
matthieu castet | 8d7802e | 2005-11-08 00:02:30 +0100 | [diff] [blame] | 670 | if (size != 0) |
| 671 | goto err_fw_corrupted; |
| 672 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 673 | /* |
| 674 | * Tell the modem we finish : de-assert reset |
| 675 | */ |
| 676 | value = 0; |
| 677 | ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value); |
| 678 | if (ret < 0) |
| 679 | uea_err(usb, "modem de-assert failed with error %d\n", ret); |
| 680 | else |
| 681 | uea_info(usb, "firmware uploaded\n"); |
| 682 | |
Johannes Berg | 9ebfbd4 | 2009-10-29 12:36:02 +0100 | [diff] [blame] | 683 | goto err; |
matthieu castet | 8d7802e | 2005-11-08 00:02:30 +0100 | [diff] [blame] | 684 | |
| 685 | err_fw_corrupted: |
| 686 | uea_err(usb, "firmware is corrupted\n"); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 687 | err: |
Johannes Berg | 9ebfbd4 | 2009-10-29 12:36:02 +0100 | [diff] [blame] | 688 | release_firmware(fw_entry); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 689 | uea_leaves(usb); |
| 690 | } |
| 691 | |
| 692 | /** |
| 693 | * uea_load_firmware - Load usb firmware for pre-firmware devices. |
| 694 | */ |
| 695 | static int uea_load_firmware(struct usb_device *usb, unsigned int ver) |
| 696 | { |
| 697 | int ret; |
| 698 | char *fw_name = FW_DIR "eagle.fw"; |
| 699 | |
| 700 | uea_enters(usb); |
| 701 | uea_info(usb, "pre-firmware device, uploading firmware\n"); |
| 702 | |
| 703 | switch (ver) { |
| 704 | case ADI930: |
| 705 | fw_name = FW_DIR "adi930.fw"; |
| 706 | break; |
| 707 | case EAGLE_I: |
| 708 | fw_name = FW_DIR "eagleI.fw"; |
| 709 | break; |
| 710 | case EAGLE_II: |
| 711 | fw_name = FW_DIR "eagleII.fw"; |
| 712 | break; |
| 713 | case EAGLE_III: |
| 714 | fw_name = FW_DIR "eagleIII.fw"; |
| 715 | break; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 716 | case EAGLE_IV: |
| 717 | fw_name = FW_DIR "eagleIV.fw"; |
| 718 | break; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 719 | } |
| 720 | |
Johannes Berg | 9ebfbd4 | 2009-10-29 12:36:02 +0100 | [diff] [blame] | 721 | ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 722 | GFP_KERNEL, usb, |
| 723 | uea_upload_pre_firmware); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 724 | if (ret) |
| 725 | uea_err(usb, "firmware %s is not available\n", fw_name); |
| 726 | else |
| 727 | uea_info(usb, "loading firmware %s\n", fw_name); |
| 728 | |
| 729 | uea_leaves(usb); |
| 730 | return ret; |
| 731 | } |
| 732 | |
| 733 | /* modem management : dsp firmware, send/read CMV, monitoring statistic |
| 734 | */ |
| 735 | |
| 736 | /* |
| 737 | * Make sure that the DSP code provided is safe to use. |
| 738 | */ |
David Woodhouse | aafcd2f | 2008-05-24 00:05:10 +0100 | [diff] [blame] | 739 | static int check_dsp_e1(const u8 *dsp, unsigned int len) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 740 | { |
| 741 | u8 pagecount, blockcount; |
| 742 | u16 blocksize; |
| 743 | u32 pageoffset; |
| 744 | unsigned int i, j, p, pp; |
| 745 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 746 | pagecount = FW_GET_BYTE(dsp); |
| 747 | p = 1; |
| 748 | |
| 749 | /* enough space for page offsets? */ |
| 750 | if (p + 4 * pagecount > len) |
| 751 | return 1; |
| 752 | |
| 753 | for (i = 0; i < pagecount; i++) { |
| 754 | |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 755 | pageoffset = get_unaligned_le32(dsp + p); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 756 | p += 4; |
| 757 | |
| 758 | if (pageoffset == 0) |
| 759 | continue; |
| 760 | |
| 761 | /* enough space for blockcount? */ |
| 762 | if (pageoffset >= len) |
| 763 | return 1; |
| 764 | |
| 765 | pp = pageoffset; |
| 766 | blockcount = FW_GET_BYTE(dsp + pp); |
| 767 | pp += 1; |
| 768 | |
| 769 | for (j = 0; j < blockcount; j++) { |
| 770 | |
| 771 | /* enough space for block header? */ |
| 772 | if (pp + 4 > len) |
| 773 | return 1; |
| 774 | |
| 775 | pp += 2; /* skip blockaddr */ |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 776 | blocksize = get_unaligned_le16(dsp + pp); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 777 | pp += 2; |
| 778 | |
| 779 | /* enough space for block data? */ |
| 780 | if (pp + blocksize > len) |
| 781 | return 1; |
| 782 | |
| 783 | pp += blocksize; |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | |
David Woodhouse | aafcd2f | 2008-05-24 00:05:10 +0100 | [diff] [blame] | 790 | static int check_dsp_e4(const u8 *dsp, int len) |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 791 | { |
| 792 | int i; |
| 793 | struct l1_code *p = (struct l1_code *) dsp; |
| 794 | unsigned int sum = p->code - dsp; |
| 795 | |
| 796 | if (len < sum) |
| 797 | return 1; |
| 798 | |
| 799 | if (strcmp("STRATIPHY ANEXA", p->string_header) != 0 && |
| 800 | strcmp("STRATIPHY ANEXB", p->string_header) != 0) |
| 801 | return 1; |
| 802 | |
| 803 | for (i = 0; i < E4_MAX_PAGE_NUMBER; i++) { |
| 804 | struct block_index *blockidx; |
| 805 | u8 blockno = p->page_number_to_block_index[i]; |
| 806 | if (blockno >= E4_NO_SWAPPAGE_HEADERS) |
| 807 | continue; |
| 808 | |
| 809 | do { |
| 810 | u64 l; |
| 811 | |
| 812 | if (blockno >= E4_NO_SWAPPAGE_HEADERS) |
| 813 | return 1; |
| 814 | |
| 815 | blockidx = &p->page_header[blockno++]; |
| 816 | if ((u8 *)(blockidx + 1) - dsp >= len) |
| 817 | return 1; |
| 818 | |
| 819 | if (le16_to_cpu(blockidx->PageNumber) != i) |
| 820 | return 1; |
| 821 | |
| 822 | l = E4_PAGE_BYTES(blockidx->PageSize); |
| 823 | sum += l; |
| 824 | l += le32_to_cpu(blockidx->PageOffset); |
| 825 | if (l > len) |
| 826 | return 1; |
| 827 | |
| 828 | /* zero is zero regardless endianes */ |
| 829 | } while (blockidx->NotLastBlock); |
| 830 | } |
| 831 | |
| 832 | return (sum == len) ? 0 : 1; |
| 833 | } |
| 834 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 835 | /* |
| 836 | * send data to the idma pipe |
| 837 | * */ |
David Woodhouse | aafcd2f | 2008-05-24 00:05:10 +0100 | [diff] [blame] | 838 | static int uea_idma_write(struct uea_softc *sc, const void *data, u32 size) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 839 | { |
| 840 | int ret = -ENOMEM; |
| 841 | u8 *xfer_buff; |
| 842 | int bytes_read; |
| 843 | |
Eric Sesterhenn | 5d7efe5 | 2006-10-26 21:06:24 +0200 | [diff] [blame] | 844 | xfer_buff = kmemdup(data, size, GFP_KERNEL); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 845 | if (!xfer_buff) { |
| 846 | uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n"); |
| 847 | return ret; |
| 848 | } |
| 849 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 850 | ret = usb_bulk_msg(sc->usb_dev, |
| 851 | usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE), |
| 852 | xfer_buff, size, &bytes_read, BULK_TIMEOUT); |
| 853 | |
| 854 | kfree(xfer_buff); |
| 855 | if (ret < 0) |
| 856 | return ret; |
| 857 | if (size != bytes_read) { |
| 858 | uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size, |
| 859 | bytes_read); |
| 860 | return -EIO; |
| 861 | } |
| 862 | |
| 863 | return 0; |
| 864 | } |
| 865 | |
| 866 | static int request_dsp(struct uea_softc *sc) |
| 867 | { |
| 868 | int ret; |
| 869 | char *dsp_name; |
| 870 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 871 | if (UEA_CHIP_VERSION(sc) == EAGLE_IV) { |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 872 | if (IS_ISDN(sc)) |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 873 | dsp_name = FW_DIR "DSP4i.bin"; |
| 874 | else |
| 875 | dsp_name = FW_DIR "DSP4p.bin"; |
| 876 | } else if (UEA_CHIP_VERSION(sc) == ADI930) { |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 877 | if (IS_ISDN(sc)) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 878 | dsp_name = FW_DIR "DSP9i.bin"; |
| 879 | else |
| 880 | dsp_name = FW_DIR "DSP9p.bin"; |
| 881 | } else { |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 882 | if (IS_ISDN(sc)) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 883 | dsp_name = FW_DIR "DSPei.bin"; |
| 884 | else |
| 885 | dsp_name = FW_DIR "DSPep.bin"; |
| 886 | } |
| 887 | |
matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 888 | ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 889 | if (ret < 0) { |
| 890 | uea_err(INS_TO_USBDEV(sc), |
| 891 | "requesting firmware %s failed with error %d\n", |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 892 | dsp_name, ret); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 893 | return ret; |
| 894 | } |
| 895 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 896 | if (UEA_CHIP_VERSION(sc) == EAGLE_IV) |
| 897 | ret = check_dsp_e4(sc->dsp_firm->data, sc->dsp_firm->size); |
| 898 | else |
| 899 | ret = check_dsp_e1(sc->dsp_firm->data, sc->dsp_firm->size); |
| 900 | |
| 901 | if (ret) { |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 902 | uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", |
| 903 | dsp_name); |
| 904 | release_firmware(sc->dsp_firm); |
| 905 | sc->dsp_firm = NULL; |
| 906 | return -EILSEQ; |
| 907 | } |
| 908 | |
| 909 | return 0; |
| 910 | } |
| 911 | |
| 912 | /* |
| 913 | * The uea_load_page() function must be called within a process context |
| 914 | */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 915 | static void uea_load_page_e1(struct work_struct *work) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 916 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 917 | struct uea_softc *sc = container_of(work, struct uea_softc, task); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 918 | u16 pageno = sc->pageno; |
| 919 | u16 ovl = sc->ovl; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 920 | struct block_info_e1 bi; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 921 | |
David Woodhouse | aafcd2f | 2008-05-24 00:05:10 +0100 | [diff] [blame] | 922 | const u8 *p; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 923 | u8 pagecount, blockcount; |
| 924 | u16 blockaddr, blocksize; |
| 925 | u32 pageoffset; |
| 926 | int i; |
| 927 | |
| 928 | /* reload firmware when reboot start and it's loaded already */ |
| 929 | if (ovl == 0 && pageno == 0 && sc->dsp_firm) { |
| 930 | release_firmware(sc->dsp_firm); |
| 931 | sc->dsp_firm = NULL; |
| 932 | } |
| 933 | |
| 934 | if (sc->dsp_firm == NULL && request_dsp(sc) < 0) |
| 935 | return; |
| 936 | |
| 937 | p = sc->dsp_firm->data; |
| 938 | pagecount = FW_GET_BYTE(p); |
| 939 | p += 1; |
| 940 | |
| 941 | if (pageno >= pagecount) |
| 942 | goto bad1; |
| 943 | |
| 944 | p += 4 * pageno; |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 945 | pageoffset = get_unaligned_le32(p); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 946 | |
| 947 | if (pageoffset == 0) |
| 948 | goto bad1; |
| 949 | |
| 950 | p = sc->dsp_firm->data + pageoffset; |
| 951 | blockcount = FW_GET_BYTE(p); |
| 952 | p += 1; |
| 953 | |
| 954 | uea_dbg(INS_TO_USBDEV(sc), |
| 955 | "sending %u blocks for DSP page %u\n", blockcount, pageno); |
| 956 | |
| 957 | bi.wHdr = cpu_to_le16(UEA_BIHDR); |
| 958 | bi.wOvl = cpu_to_le16(ovl); |
| 959 | bi.wOvlOffset = cpu_to_le16(ovl | 0x8000); |
| 960 | |
| 961 | for (i = 0; i < blockcount; i++) { |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 962 | blockaddr = get_unaligned_le16(p); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 963 | p += 2; |
| 964 | |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 965 | blocksize = get_unaligned_le16(p); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 966 | p += 2; |
| 967 | |
| 968 | bi.wSize = cpu_to_le16(blocksize); |
| 969 | bi.wAddress = cpu_to_le16(blockaddr); |
| 970 | bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0); |
| 971 | |
| 972 | /* send block info through the IDMA pipe */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 973 | if (uea_idma_write(sc, &bi, E1_BLOCK_INFO_SIZE)) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 974 | goto bad2; |
| 975 | |
| 976 | /* send block data through the IDMA pipe */ |
| 977 | if (uea_idma_write(sc, p, blocksize)) |
| 978 | goto bad2; |
| 979 | |
| 980 | p += blocksize; |
| 981 | } |
| 982 | |
| 983 | return; |
| 984 | |
| 985 | bad2: |
| 986 | uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i); |
| 987 | return; |
| 988 | bad1: |
matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 989 | 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] | 990 | } |
| 991 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 992 | static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot) |
| 993 | { |
| 994 | struct block_info_e4 bi; |
| 995 | struct block_index *blockidx; |
| 996 | struct l1_code *p = (struct l1_code *) sc->dsp_firm->data; |
| 997 | u8 blockno = p->page_number_to_block_index[pageno]; |
| 998 | |
| 999 | bi.wHdr = cpu_to_be16(UEA_BIHDR); |
| 1000 | bi.bBootPage = boot; |
| 1001 | bi.bPageNumber = pageno; |
| 1002 | bi.wReserved = cpu_to_be16(UEA_RESERVED); |
| 1003 | |
| 1004 | do { |
David Woodhouse | aafcd2f | 2008-05-24 00:05:10 +0100 | [diff] [blame] | 1005 | const u8 *blockoffset; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1006 | unsigned int blocksize; |
| 1007 | |
| 1008 | blockidx = &p->page_header[blockno]; |
| 1009 | blocksize = E4_PAGE_BYTES(blockidx->PageSize); |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1010 | blockoffset = sc->dsp_firm->data + le32_to_cpu( |
| 1011 | blockidx->PageOffset); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1012 | |
| 1013 | bi.dwSize = cpu_to_be32(blocksize); |
Al Viro | fd05e72 | 2008-04-28 07:00:16 +0100 | [diff] [blame] | 1014 | bi.dwAddress = cpu_to_be32(le32_to_cpu(blockidx->PageAddress)); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1015 | |
| 1016 | uea_dbg(INS_TO_USBDEV(sc), |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1017 | "sending block %u for DSP page " |
| 1018 | "%u size %u address %x\n", |
| 1019 | blockno, pageno, blocksize, |
| 1020 | le32_to_cpu(blockidx->PageAddress)); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1021 | |
| 1022 | /* send block info through the IDMA pipe */ |
| 1023 | if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE)) |
| 1024 | goto bad; |
| 1025 | |
| 1026 | /* send block data through the IDMA pipe */ |
| 1027 | if (uea_idma_write(sc, blockoffset, blocksize)) |
| 1028 | goto bad; |
| 1029 | |
| 1030 | blockno++; |
| 1031 | } while (blockidx->NotLastBlock); |
| 1032 | |
| 1033 | return; |
| 1034 | |
| 1035 | bad: |
| 1036 | uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", blockno); |
| 1037 | return; |
| 1038 | } |
| 1039 | |
| 1040 | static void uea_load_page_e4(struct work_struct *work) |
| 1041 | { |
| 1042 | struct uea_softc *sc = container_of(work, struct uea_softc, task); |
| 1043 | u8 pageno = sc->pageno; |
| 1044 | int i; |
| 1045 | struct block_info_e4 bi; |
| 1046 | struct l1_code *p; |
| 1047 | |
| 1048 | uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno); |
| 1049 | |
| 1050 | /* reload firmware when reboot start and it's loaded already */ |
| 1051 | if (pageno == 0 && sc->dsp_firm) { |
| 1052 | release_firmware(sc->dsp_firm); |
| 1053 | sc->dsp_firm = NULL; |
| 1054 | } |
| 1055 | |
| 1056 | if (sc->dsp_firm == NULL && request_dsp(sc) < 0) |
| 1057 | return; |
| 1058 | |
| 1059 | p = (struct l1_code *) sc->dsp_firm->data; |
Al Viro | fd05e72 | 2008-04-28 07:00:16 +0100 | [diff] [blame] | 1060 | if (pageno >= le16_to_cpu(p->page_header[0].PageNumber)) { |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1061 | uea_err(INS_TO_USBDEV(sc), "invalid DSP " |
| 1062 | "page %u requested\n", pageno); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1063 | return; |
| 1064 | } |
| 1065 | |
| 1066 | if (pageno != 0) { |
| 1067 | __uea_load_page_e4(sc, pageno, 0); |
| 1068 | return; |
| 1069 | } |
| 1070 | |
| 1071 | uea_dbg(INS_TO_USBDEV(sc), |
| 1072 | "sending Main DSP page %u\n", p->page_header[0].PageNumber); |
| 1073 | |
| 1074 | for (i = 0; i < le16_to_cpu(p->page_header[0].PageNumber); i++) { |
| 1075 | if (E4_IS_BOOT_PAGE(p->page_header[i].PageSize)) |
| 1076 | __uea_load_page_e4(sc, i, 1); |
| 1077 | } |
| 1078 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1079 | uea_dbg(INS_TO_USBDEV(sc) , "sending start bi\n"); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1080 | |
| 1081 | bi.wHdr = cpu_to_be16(UEA_BIHDR); |
| 1082 | bi.bBootPage = 0; |
| 1083 | bi.bPageNumber = 0xff; |
| 1084 | bi.wReserved = cpu_to_be16(UEA_RESERVED); |
| 1085 | bi.dwSize = cpu_to_be32(E4_PAGE_BYTES(p->page_header[0].PageSize)); |
Al Viro | fd05e72 | 2008-04-28 07:00:16 +0100 | [diff] [blame] | 1086 | bi.dwAddress = cpu_to_be32(le32_to_cpu(p->page_header[0].PageAddress)); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1087 | |
| 1088 | /* send block info through the IDMA pipe */ |
| 1089 | if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE)) |
| 1090 | uea_err(INS_TO_USBDEV(sc), "sending DSP start bi failed\n"); |
| 1091 | } |
| 1092 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1093 | static inline void wake_up_cmv_ack(struct uea_softc *sc) |
| 1094 | { |
matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1095 | BUG_ON(sc->cmv_ack); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1096 | sc->cmv_ack = 1; |
Stanislaw Gruszka | 337427f | 2007-08-20 23:21:14 +0200 | [diff] [blame] | 1097 | wake_up(&sc->sync_q); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | static inline int wait_cmv_ack(struct uea_softc *sc) |
| 1101 | { |
Stanislaw Gruszka | 337427f | 2007-08-20 23:21:14 +0200 | [diff] [blame] | 1102 | int ret = uea_wait(sc, sc->cmv_ack , ACK_TIMEOUT); |
| 1103 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1104 | sc->cmv_ack = 0; |
| 1105 | |
matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1106 | uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n", |
| 1107 | jiffies_to_msecs(ret)); |
| 1108 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1109 | if (ret < 0) |
| 1110 | return ret; |
| 1111 | |
| 1112 | return (ret == 0) ? -ETIMEDOUT : 0; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00 |
| 1116 | |
| 1117 | static int uea_request(struct uea_softc *sc, |
David Woodhouse | aafcd2f | 2008-05-24 00:05:10 +0100 | [diff] [blame] | 1118 | u16 value, u16 index, u16 size, const void *data) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1119 | { |
| 1120 | u8 *xfer_buff; |
| 1121 | int ret = -ENOMEM; |
| 1122 | |
Eric Sesterhenn | 5d7efe5 | 2006-10-26 21:06:24 +0200 | [diff] [blame] | 1123 | xfer_buff = kmemdup(data, size, GFP_KERNEL); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1124 | if (!xfer_buff) { |
| 1125 | uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n"); |
| 1126 | return ret; |
| 1127 | } |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1128 | |
| 1129 | ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0), |
| 1130 | UCDC_SEND_ENCAPSULATED_COMMAND, |
| 1131 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 1132 | value, index, xfer_buff, size, CTRL_TIMEOUT); |
| 1133 | |
| 1134 | kfree(xfer_buff); |
| 1135 | if (ret < 0) { |
| 1136 | uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret); |
| 1137 | return ret; |
| 1138 | } |
| 1139 | |
| 1140 | if (ret != size) { |
| 1141 | uea_err(INS_TO_USBDEV(sc), |
| 1142 | "usb_control_msg send only %d bytes (instead of %d)\n", |
| 1143 | ret, size); |
| 1144 | return -EIO; |
| 1145 | } |
| 1146 | |
| 1147 | return 0; |
| 1148 | } |
| 1149 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1150 | static int uea_cmv_e1(struct uea_softc *sc, |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1151 | u8 function, u32 address, u16 offset, u32 data) |
| 1152 | { |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1153 | struct cmv_e1 cmv; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1154 | int ret; |
| 1155 | |
matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1156 | uea_enters(INS_TO_USBDEV(sc)); |
| 1157 | uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, " |
| 1158 | "offset : 0x%04x, data : 0x%08x\n", |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1159 | E1_FUNCTION_TYPE(function), |
| 1160 | E1_FUNCTION_SUBTYPE(function), |
| 1161 | E1_GETSA1(address), E1_GETSA2(address), |
| 1162 | E1_GETSA3(address), |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1163 | E1_GETSA4(address), offset, data); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1164 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1165 | /* we send a request, but we expect a reply */ |
| 1166 | sc->cmv_dsc.e1.function = function | 0x2; |
| 1167 | sc->cmv_dsc.e1.idx++; |
| 1168 | sc->cmv_dsc.e1.address = address; |
| 1169 | sc->cmv_dsc.e1.offset = offset; |
| 1170 | |
| 1171 | cmv.wPreamble = cpu_to_le16(E1_PREAMBLE); |
| 1172 | cmv.bDirection = E1_HOSTTOMODEM; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1173 | cmv.bFunction = function; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1174 | cmv.wIndex = cpu_to_le16(sc->cmv_dsc.e1.idx); |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 1175 | put_unaligned_le32(address, &cmv.dwSymbolicAddress); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1176 | cmv.wOffsetAddress = cpu_to_le16(offset); |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 1177 | put_unaligned_le32(data >> 16 | data << 16, &cmv.dwData); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1178 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1179 | ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START, |
| 1180 | sizeof(cmv), &cmv); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1181 | if (ret < 0) |
| 1182 | return ret; |
matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1183 | ret = wait_cmv_ack(sc); |
| 1184 | uea_leaves(INS_TO_USBDEV(sc)); |
| 1185 | return ret; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1186 | } |
| 1187 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1188 | static int uea_cmv_e4(struct uea_softc *sc, |
| 1189 | u16 function, u16 group, u16 address, u16 offset, u32 data) |
| 1190 | { |
| 1191 | struct cmv_e4 cmv; |
| 1192 | int ret; |
| 1193 | |
| 1194 | uea_enters(INS_TO_USBDEV(sc)); |
| 1195 | memset(&cmv, 0, sizeof(cmv)); |
| 1196 | |
| 1197 | uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Group : 0x%04x, " |
| 1198 | "Address : 0x%04x, offset : 0x%04x, data : 0x%08x\n", |
| 1199 | E4_FUNCTION_TYPE(function), E4_FUNCTION_SUBTYPE(function), |
| 1200 | group, address, offset, data); |
| 1201 | |
| 1202 | /* we send a request, but we expect a reply */ |
| 1203 | sc->cmv_dsc.e4.function = function | (0x1 << 4); |
| 1204 | sc->cmv_dsc.e4.offset = offset; |
| 1205 | sc->cmv_dsc.e4.address = address; |
| 1206 | sc->cmv_dsc.e4.group = group; |
| 1207 | |
| 1208 | cmv.wFunction = cpu_to_be16(function); |
| 1209 | cmv.wGroup = cpu_to_be16(group); |
| 1210 | cmv.wAddress = cpu_to_be16(address); |
| 1211 | cmv.wOffset = cpu_to_be16(offset); |
| 1212 | cmv.dwData[0] = cpu_to_be32(data); |
| 1213 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1214 | ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START, |
| 1215 | sizeof(cmv), &cmv); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1216 | if (ret < 0) |
| 1217 | return ret; |
| 1218 | ret = wait_cmv_ack(sc); |
| 1219 | uea_leaves(INS_TO_USBDEV(sc)); |
| 1220 | return ret; |
| 1221 | } |
| 1222 | |
| 1223 | static inline int uea_read_cmv_e1(struct uea_softc *sc, |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1224 | u32 address, u16 offset, u32 *data) |
| 1225 | { |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1226 | int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTREAD), |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1227 | address, offset, 0); |
| 1228 | if (ret < 0) |
| 1229 | uea_err(INS_TO_USBDEV(sc), |
| 1230 | "reading cmv failed with error %d\n", ret); |
| 1231 | else |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1232 | *data = sc->data; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1233 | |
| 1234 | return ret; |
| 1235 | } |
| 1236 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1237 | static inline int uea_read_cmv_e4(struct uea_softc *sc, |
| 1238 | u8 size, u16 group, u16 address, u16 offset, u32 *data) |
| 1239 | { |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1240 | int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, |
| 1241 | E4_REQUESTREAD, size), |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1242 | group, address, offset, 0); |
| 1243 | if (ret < 0) |
| 1244 | uea_err(INS_TO_USBDEV(sc), |
| 1245 | "reading cmv failed with error %d\n", ret); |
| 1246 | else { |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1247 | *data = sc->data; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1248 | /* size is in 16-bit word quantities */ |
| 1249 | if (size > 2) |
| 1250 | *(data + 1) = sc->data1; |
| 1251 | } |
| 1252 | return ret; |
| 1253 | } |
| 1254 | |
| 1255 | static inline int uea_write_cmv_e1(struct uea_softc *sc, |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1256 | u32 address, u16 offset, u32 data) |
| 1257 | { |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1258 | int ret = uea_cmv_e1(sc, E1_MAKEFUNCTION(E1_MEMACCESS, E1_REQUESTWRITE), |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1259 | address, offset, data); |
| 1260 | if (ret < 0) |
| 1261 | uea_err(INS_TO_USBDEV(sc), |
| 1262 | "writing cmv failed with error %d\n", ret); |
| 1263 | |
| 1264 | return ret; |
| 1265 | } |
| 1266 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1267 | static inline int uea_write_cmv_e4(struct uea_softc *sc, |
| 1268 | u8 size, u16 group, u16 address, u16 offset, u32 data) |
| 1269 | { |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1270 | int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, |
| 1271 | E4_REQUESTWRITE, size), |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1272 | group, address, offset, data); |
| 1273 | if (ret < 0) |
| 1274 | uea_err(INS_TO_USBDEV(sc), |
| 1275 | "writing cmv failed with error %d\n", ret); |
| 1276 | |
| 1277 | return ret; |
| 1278 | } |
| 1279 | |
| 1280 | static void uea_set_bulk_timeout(struct uea_softc *sc, u32 dsrate) |
| 1281 | { |
| 1282 | int ret; |
| 1283 | u16 timeout; |
| 1284 | |
| 1285 | /* in bulk mode the modem have problem with high rate |
| 1286 | * changing internal timing could improve things, but the |
| 1287 | * value is misterious. |
| 1288 | * ADI930 don't support it (-EPIPE error). |
| 1289 | */ |
| 1290 | |
| 1291 | if (UEA_CHIP_VERSION(sc) == ADI930 || |
Stanislaw Gruszka | 503add4 | 2007-08-20 23:21:06 +0200 | [diff] [blame] | 1292 | altsetting[sc->modem_index] > 0 || |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1293 | sc->stats.phy.dsrate == dsrate) |
| 1294 | return; |
| 1295 | |
| 1296 | /* Original timming (1Mbit/s) from ADI (used in windows driver) */ |
| 1297 | timeout = (dsrate <= 1024*1024) ? 0 : 1; |
| 1298 | ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL); |
| 1299 | uea_info(INS_TO_USBDEV(sc), "setting new timeout %d%s\n", |
| 1300 | timeout, ret < 0 ? " failed" : ""); |
| 1301 | |
| 1302 | } |
| 1303 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1304 | /* |
| 1305 | * Monitor the modem and update the stat |
| 1306 | * return 0 if everything is ok |
| 1307 | * return < 0 if an error occurs (-EAGAIN reboot needed) |
| 1308 | */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1309 | static int uea_stat_e1(struct uea_softc *sc) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1310 | { |
| 1311 | u32 data; |
| 1312 | int ret; |
| 1313 | |
| 1314 | uea_enters(INS_TO_USBDEV(sc)); |
| 1315 | data = sc->stats.phy.state; |
| 1316 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1317 | ret = uea_read_cmv_e1(sc, E1_SA_STAT, 0, &sc->stats.phy.state); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1318 | if (ret < 0) |
| 1319 | return ret; |
| 1320 | |
| 1321 | switch (GET_STATUS(sc->stats.phy.state)) { |
| 1322 | case 0: /* not yet synchronized */ |
| 1323 | uea_dbg(INS_TO_USBDEV(sc), |
| 1324 | "modem not yet synchronized\n"); |
| 1325 | return 0; |
| 1326 | |
| 1327 | case 1: /* initialization */ |
| 1328 | uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n"); |
| 1329 | return 0; |
| 1330 | |
| 1331 | case 2: /* operational */ |
| 1332 | uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n"); |
| 1333 | break; |
| 1334 | |
| 1335 | case 3: /* fail ... */ |
matthieu castet | a7a0c9c | 2006-10-03 21:44:11 +0200 | [diff] [blame] | 1336 | uea_info(INS_TO_USBDEV(sc), "modem synchronization failed" |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1337 | " (may be try other cmv/dsp)\n"); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1338 | return -EAGAIN; |
| 1339 | |
| 1340 | case 4 ... 6: /* test state */ |
| 1341 | uea_warn(INS_TO_USBDEV(sc), |
| 1342 | "modem in test mode - not supported\n"); |
| 1343 | return -EAGAIN; |
| 1344 | |
| 1345 | case 7: /* fast-retain ... */ |
| 1346 | uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n"); |
| 1347 | return 0; |
| 1348 | default: |
| 1349 | uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n", |
| 1350 | GET_STATUS(sc->stats.phy.state)); |
| 1351 | return -EAGAIN; |
| 1352 | } |
| 1353 | |
| 1354 | if (GET_STATUS(data) != 2) { |
| 1355 | uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL); |
| 1356 | uea_info(INS_TO_USBDEV(sc), "modem operational\n"); |
| 1357 | |
| 1358 | /* release the dsp firmware as it is not needed until |
| 1359 | * the next failure |
| 1360 | */ |
| 1361 | if (sc->dsp_firm) { |
| 1362 | release_firmware(sc->dsp_firm); |
| 1363 | sc->dsp_firm = NULL; |
| 1364 | } |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | /* always update it as atm layer could not be init when we switch to |
| 1368 | * operational state |
| 1369 | */ |
Karl Hiramoto | cc7b86c | 2010-07-08 20:55:38 +0000 | [diff] [blame] | 1370 | UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1371 | |
| 1372 | /* wake up processes waiting for synchronization */ |
| 1373 | wake_up(&sc->sync_q); |
| 1374 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1375 | ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 2, &sc->stats.phy.flags); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1376 | if (ret < 0) |
| 1377 | return ret; |
| 1378 | sc->stats.phy.mflags |= sc->stats.phy.flags; |
| 1379 | |
| 1380 | /* in case of a flags ( for example delineation LOSS (& 0x10)), |
| 1381 | * we check the status again in order to detect the failure earlier |
| 1382 | */ |
| 1383 | if (sc->stats.phy.flags) { |
matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1384 | uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n", |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1385 | sc->stats.phy.flags); |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1389 | ret = uea_read_cmv_e1(sc, E1_SA_RATE, 0, &data); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1390 | if (ret < 0) |
| 1391 | return ret; |
| 1392 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1393 | uea_set_bulk_timeout(sc, (data >> 16) * 32); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1394 | sc->stats.phy.dsrate = (data >> 16) * 32; |
| 1395 | sc->stats.phy.usrate = (data & 0xffff) * 32; |
| 1396 | UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424); |
| 1397 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1398 | ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 23, &data); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1399 | if (ret < 0) |
| 1400 | return ret; |
| 1401 | sc->stats.phy.dsattenuation = (data & 0xff) / 2; |
| 1402 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1403 | ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 47, &data); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1404 | if (ret < 0) |
| 1405 | return ret; |
| 1406 | sc->stats.phy.usattenuation = (data & 0xff) / 2; |
| 1407 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1408 | ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 25, &sc->stats.phy.dsmargin); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1409 | if (ret < 0) |
| 1410 | return ret; |
| 1411 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1412 | ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 49, &sc->stats.phy.usmargin); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1413 | if (ret < 0) |
| 1414 | return ret; |
| 1415 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1416 | ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 51, &sc->stats.phy.rxflow); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1417 | if (ret < 0) |
| 1418 | return ret; |
| 1419 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1420 | ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 52, &sc->stats.phy.txflow); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1421 | if (ret < 0) |
| 1422 | return ret; |
| 1423 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1424 | ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 54, &sc->stats.phy.dsunc); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1425 | if (ret < 0) |
| 1426 | return ret; |
| 1427 | |
| 1428 | /* only for atu-c */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1429 | ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 58, &sc->stats.phy.usunc); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1430 | if (ret < 0) |
| 1431 | return ret; |
| 1432 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1433 | ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 53, &sc->stats.phy.dscorr); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1434 | if (ret < 0) |
| 1435 | return ret; |
| 1436 | |
| 1437 | /* only for atu-c */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1438 | ret = uea_read_cmv_e1(sc, E1_SA_DIAG, 57, &sc->stats.phy.uscorr); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1439 | if (ret < 0) |
| 1440 | return ret; |
| 1441 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1442 | ret = uea_read_cmv_e1(sc, E1_SA_INFO, 8, &sc->stats.phy.vidco); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1443 | if (ret < 0) |
| 1444 | return ret; |
| 1445 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1446 | ret = uea_read_cmv_e1(sc, E1_SA_INFO, 13, &sc->stats.phy.vidcpe); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1447 | if (ret < 0) |
| 1448 | return ret; |
| 1449 | |
| 1450 | return 0; |
| 1451 | } |
| 1452 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1453 | static int uea_stat_e4(struct uea_softc *sc) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1454 | { |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1455 | u32 data; |
| 1456 | u32 tmp_arr[2]; |
| 1457 | int ret; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1458 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1459 | uea_enters(INS_TO_USBDEV(sc)); |
| 1460 | data = sc->stats.phy.state; |
| 1461 | |
| 1462 | /* XXX only need to be done before operationnal... */ |
| 1463 | ret = uea_read_cmv_e4(sc, 1, E4_SA_STAT, 0, 0, &sc->stats.phy.state); |
| 1464 | if (ret < 0) |
| 1465 | return ret; |
| 1466 | |
| 1467 | switch (sc->stats.phy.state) { |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1468 | case 0x0: /* not yet synchronized */ |
| 1469 | case 0x1: |
| 1470 | case 0x3: |
| 1471 | case 0x4: |
| 1472 | uea_dbg(INS_TO_USBDEV(sc), "modem not yet " |
| 1473 | "synchronized\n"); |
| 1474 | return 0; |
| 1475 | case 0x5: /* initialization */ |
| 1476 | case 0x6: |
| 1477 | case 0x9: |
| 1478 | case 0xa: |
| 1479 | uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n"); |
| 1480 | return 0; |
| 1481 | case 0x2: /* fail ... */ |
| 1482 | uea_info(INS_TO_USBDEV(sc), "modem synchronization " |
| 1483 | "failed (may be try other cmv/dsp)\n"); |
| 1484 | return -EAGAIN; |
| 1485 | case 0x7: /* operational */ |
| 1486 | break; |
| 1487 | default: |
| 1488 | uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n", |
| 1489 | sc->stats.phy.state); |
| 1490 | return 0; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | if (data != 7) { |
| 1494 | uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL); |
| 1495 | uea_info(INS_TO_USBDEV(sc), "modem operational\n"); |
| 1496 | |
| 1497 | /* release the dsp firmware as it is not needed until |
| 1498 | * the next failure |
| 1499 | */ |
| 1500 | if (sc->dsp_firm) { |
| 1501 | release_firmware(sc->dsp_firm); |
| 1502 | sc->dsp_firm = NULL; |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | /* always update it as atm layer could not be init when we switch to |
| 1507 | * operational state |
| 1508 | */ |
Karl Hiramoto | cc7b86c | 2010-07-08 20:55:38 +0000 | [diff] [blame] | 1509 | UPDATE_ATM_SIGNAL(ATM_PHY_SIG_FOUND); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1510 | |
| 1511 | /* wake up processes waiting for synchronization */ |
| 1512 | wake_up(&sc->sync_q); |
| 1513 | |
| 1514 | /* TODO improve this state machine : |
| 1515 | * we need some CMV info : what they do and their unit |
| 1516 | * we should find the equivalent of eagle3- CMV |
| 1517 | */ |
| 1518 | /* check flags */ |
| 1519 | ret = uea_read_cmv_e4(sc, 1, E4_SA_DIAG, 0, 0, &sc->stats.phy.flags); |
| 1520 | if (ret < 0) |
| 1521 | return ret; |
| 1522 | sc->stats.phy.mflags |= sc->stats.phy.flags; |
| 1523 | |
| 1524 | /* in case of a flags ( for example delineation LOSS (& 0x10)), |
| 1525 | * we check the status again in order to detect the failure earlier |
| 1526 | */ |
| 1527 | if (sc->stats.phy.flags) { |
| 1528 | uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n", |
| 1529 | sc->stats.phy.flags); |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1530 | if (sc->stats.phy.flags & 1) /* delineation LOSS */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1531 | return -EAGAIN; |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1532 | if (sc->stats.phy.flags & 0x4000) /* Reset Flag */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1533 | return -EAGAIN; |
| 1534 | return 0; |
| 1535 | } |
| 1536 | |
| 1537 | /* rate data may be in upper or lower half of 64 bit word, strange */ |
| 1538 | ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 0, 0, tmp_arr); |
| 1539 | if (ret < 0) |
| 1540 | return ret; |
| 1541 | data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1]; |
| 1542 | sc->stats.phy.usrate = data / 1000; |
| 1543 | |
| 1544 | ret = uea_read_cmv_e4(sc, 4, E4_SA_RATE, 1, 0, tmp_arr); |
| 1545 | if (ret < 0) |
| 1546 | return ret; |
| 1547 | data = (tmp_arr[0]) ? tmp_arr[0] : tmp_arr[1]; |
| 1548 | uea_set_bulk_timeout(sc, data / 1000); |
| 1549 | sc->stats.phy.dsrate = data / 1000; |
| 1550 | UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424); |
| 1551 | |
| 1552 | ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 1, &data); |
| 1553 | if (ret < 0) |
| 1554 | return ret; |
| 1555 | sc->stats.phy.dsattenuation = data / 10; |
| 1556 | |
| 1557 | ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 1, &data); |
| 1558 | if (ret < 0) |
| 1559 | return ret; |
| 1560 | sc->stats.phy.usattenuation = data / 10; |
| 1561 | |
| 1562 | ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 68, 3, &data); |
| 1563 | if (ret < 0) |
| 1564 | return ret; |
| 1565 | sc->stats.phy.dsmargin = data / 2; |
| 1566 | |
| 1567 | ret = uea_read_cmv_e4(sc, 1, E4_SA_INFO, 69, 3, &data); |
| 1568 | if (ret < 0) |
| 1569 | return ret; |
| 1570 | sc->stats.phy.usmargin = data / 10; |
| 1571 | |
| 1572 | return 0; |
| 1573 | } |
| 1574 | |
| 1575 | static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver) |
| 1576 | { |
| 1577 | char file_arr[] = "CMVxy.bin"; |
| 1578 | char *file; |
| 1579 | |
Rusty Russell | d6d1b65 | 2010-08-11 23:04:27 -0600 | [diff] [blame^] | 1580 | kparam_block_sysfs_write(cmv_file); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1581 | /* set proper name corresponding modem version and line type */ |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1582 | if (cmv_file[sc->modem_index] == NULL) { |
| 1583 | if (UEA_CHIP_VERSION(sc) == ADI930) |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1584 | file_arr[3] = '9'; |
| 1585 | else if (UEA_CHIP_VERSION(sc) == EAGLE_IV) |
| 1586 | file_arr[3] = '4'; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1587 | else |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1588 | file_arr[3] = 'e'; |
| 1589 | |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 1590 | file_arr[4] = IS_ISDN(sc) ? 'i' : 'p'; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1591 | file = file_arr; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1592 | } else |
| 1593 | file = cmv_file[sc->modem_index]; |
| 1594 | |
| 1595 | strcpy(cmv_name, FW_DIR); |
Samuel Ortiz | ade901d | 2009-05-27 00:49:32 +0200 | [diff] [blame] | 1596 | strlcat(cmv_name, file, UEA_FW_NAME_MAX); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1597 | if (ver == 2) |
Samuel Ortiz | ade901d | 2009-05-27 00:49:32 +0200 | [diff] [blame] | 1598 | strlcat(cmv_name, ".v2", UEA_FW_NAME_MAX); |
Rusty Russell | d6d1b65 | 2010-08-11 23:04:27 -0600 | [diff] [blame^] | 1599 | kparam_unblock_sysfs_write(cmv_file); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1600 | } |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1601 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1602 | static int request_cmvs_old(struct uea_softc *sc, |
| 1603 | void **cmvs, const struct firmware **fw) |
| 1604 | { |
| 1605 | int ret, size; |
| 1606 | u8 *data; |
Samuel Ortiz | ade901d | 2009-05-27 00:49:32 +0200 | [diff] [blame] | 1607 | char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1608 | |
| 1609 | cmvs_file_name(sc, cmv_name, 1); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1610 | ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev); |
| 1611 | if (ret < 0) { |
| 1612 | uea_err(INS_TO_USBDEV(sc), |
| 1613 | "requesting firmware %s failed with error %d\n", |
| 1614 | cmv_name, ret); |
| 1615 | return ret; |
| 1616 | } |
| 1617 | |
| 1618 | data = (u8 *) (*fw)->data; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1619 | size = (*fw)->size; |
| 1620 | if (size < 1) |
| 1621 | goto err_fw_corrupted; |
| 1622 | |
| 1623 | if (size != *data * sizeof(struct uea_cmvs_v1) + 1) |
| 1624 | goto err_fw_corrupted; |
| 1625 | |
| 1626 | *cmvs = (void *)(data + 1); |
| 1627 | return *data; |
| 1628 | |
| 1629 | err_fw_corrupted: |
| 1630 | uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name); |
| 1631 | release_firmware(*fw); |
| 1632 | return -EILSEQ; |
| 1633 | } |
| 1634 | |
| 1635 | static int request_cmvs(struct uea_softc *sc, |
| 1636 | void **cmvs, const struct firmware **fw, int *ver) |
| 1637 | { |
| 1638 | int ret, size; |
| 1639 | u32 crc; |
| 1640 | u8 *data; |
Samuel Ortiz | ade901d | 2009-05-27 00:49:32 +0200 | [diff] [blame] | 1641 | char cmv_name[UEA_FW_NAME_MAX]; /* 30 bytes stack variable */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1642 | |
| 1643 | cmvs_file_name(sc, cmv_name, 2); |
| 1644 | ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev); |
| 1645 | if (ret < 0) { |
| 1646 | /* if caller can handle old version, try to provide it */ |
| 1647 | if (*ver == 1) { |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1648 | uea_warn(INS_TO_USBDEV(sc), "requesting " |
| 1649 | "firmware %s failed, " |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1650 | "try to get older cmvs\n", cmv_name); |
| 1651 | return request_cmvs_old(sc, cmvs, fw); |
| 1652 | } |
| 1653 | uea_err(INS_TO_USBDEV(sc), |
| 1654 | "requesting firmware %s failed with error %d\n", |
| 1655 | cmv_name, ret); |
| 1656 | return ret; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1657 | } |
| 1658 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1659 | size = (*fw)->size; |
| 1660 | data = (u8 *) (*fw)->data; |
| 1661 | if (size < 4 || strncmp(data, "cmv2", 4) != 0) { |
| 1662 | if (*ver == 1) { |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1663 | uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted," |
| 1664 | " try to get older cmvs\n", cmv_name); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1665 | release_firmware(*fw); |
| 1666 | return request_cmvs_old(sc, cmvs, fw); |
| 1667 | } |
| 1668 | goto err_fw_corrupted; |
| 1669 | } |
| 1670 | |
| 1671 | *ver = 2; |
| 1672 | |
| 1673 | data += 4; |
| 1674 | size -= 4; |
| 1675 | if (size < 5) |
| 1676 | goto err_fw_corrupted; |
| 1677 | |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 1678 | crc = get_unaligned_le32(data); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1679 | data += 4; |
| 1680 | size -= 4; |
| 1681 | if (crc32_be(0, data, size) != crc) |
| 1682 | goto err_fw_corrupted; |
| 1683 | |
| 1684 | if (size != *data * sizeof(struct uea_cmvs_v2) + 1) |
| 1685 | goto err_fw_corrupted; |
| 1686 | |
| 1687 | *cmvs = (void *) (data + 1); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1688 | return *data; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1689 | |
| 1690 | err_fw_corrupted: |
| 1691 | uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", cmv_name); |
| 1692 | release_firmware(*fw); |
| 1693 | return -EILSEQ; |
| 1694 | } |
| 1695 | |
| 1696 | static int uea_send_cmvs_e1(struct uea_softc *sc) |
| 1697 | { |
| 1698 | int i, ret, len; |
| 1699 | void *cmvs_ptr; |
| 1700 | const struct firmware *cmvs_fw; |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1701 | int ver = 1; /* we can handle v1 cmv firmware version; */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1702 | |
| 1703 | /* Enter in R-IDLE (cmv) until instructed otherwise */ |
| 1704 | ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1); |
| 1705 | if (ret < 0) |
| 1706 | return ret; |
| 1707 | |
| 1708 | /* Dump firmware version */ |
| 1709 | ret = uea_read_cmv_e1(sc, E1_SA_INFO, 10, &sc->stats.phy.firmid); |
| 1710 | if (ret < 0) |
| 1711 | return ret; |
| 1712 | uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n", |
| 1713 | sc->stats.phy.firmid); |
| 1714 | |
| 1715 | /* get options */ |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1716 | ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1717 | if (ret < 0) |
| 1718 | return ret; |
| 1719 | |
| 1720 | /* send options */ |
| 1721 | if (ver == 1) { |
| 1722 | struct uea_cmvs_v1 *cmvs_v1 = cmvs_ptr; |
| 1723 | |
| 1724 | uea_warn(INS_TO_USBDEV(sc), "use deprecated cmvs version, " |
| 1725 | "please update your firmware\n"); |
| 1726 | |
| 1727 | for (i = 0; i < len; i++) { |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1728 | ret = uea_write_cmv_e1(sc, |
| 1729 | get_unaligned_le32(&cmvs_v1[i].address), |
| 1730 | get_unaligned_le16(&cmvs_v1[i].offset), |
| 1731 | get_unaligned_le32(&cmvs_v1[i].data)); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1732 | if (ret < 0) |
| 1733 | goto out; |
| 1734 | } |
| 1735 | } else if (ver == 2) { |
| 1736 | struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr; |
| 1737 | |
| 1738 | for (i = 0; i < len; i++) { |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1739 | ret = uea_write_cmv_e1(sc, |
| 1740 | get_unaligned_le32(&cmvs_v2[i].address), |
| 1741 | (u16) get_unaligned_le32(&cmvs_v2[i].offset), |
| 1742 | get_unaligned_le32(&cmvs_v2[i].data)); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1743 | if (ret < 0) |
| 1744 | goto out; |
| 1745 | } |
| 1746 | } else { |
| 1747 | /* This realy should not happen */ |
| 1748 | uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver); |
| 1749 | goto out; |
| 1750 | } |
| 1751 | |
| 1752 | /* Enter in R-ACT-REQ */ |
| 1753 | ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2); |
| 1754 | uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n"); |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1755 | uea_info(INS_TO_USBDEV(sc), "modem started, waiting " |
| 1756 | "synchronization...\n"); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1757 | out: |
| 1758 | release_firmware(cmvs_fw); |
| 1759 | return ret; |
| 1760 | } |
| 1761 | |
| 1762 | static int uea_send_cmvs_e4(struct uea_softc *sc) |
| 1763 | { |
| 1764 | int i, ret, len; |
| 1765 | void *cmvs_ptr; |
| 1766 | const struct firmware *cmvs_fw; |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1767 | int ver = 2; /* we can only handle v2 cmv firmware version; */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1768 | |
| 1769 | /* Enter in R-IDLE (cmv) until instructed otherwise */ |
| 1770 | ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1); |
| 1771 | if (ret < 0) |
| 1772 | return ret; |
| 1773 | |
| 1774 | /* Dump firmware version */ |
| 1775 | /* XXX don't read the 3th byte as it is always 6 */ |
| 1776 | ret = uea_read_cmv_e4(sc, 2, E4_SA_INFO, 55, 0, &sc->stats.phy.firmid); |
| 1777 | if (ret < 0) |
| 1778 | return ret; |
| 1779 | uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n", |
| 1780 | sc->stats.phy.firmid); |
| 1781 | |
| 1782 | |
| 1783 | /* get options */ |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1784 | ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1785 | if (ret < 0) |
| 1786 | return ret; |
| 1787 | |
| 1788 | /* send options */ |
| 1789 | if (ver == 2) { |
| 1790 | struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr; |
| 1791 | |
| 1792 | for (i = 0; i < len; i++) { |
| 1793 | ret = uea_write_cmv_e4(sc, 1, |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1794 | get_unaligned_le32(&cmvs_v2[i].group), |
| 1795 | get_unaligned_le32(&cmvs_v2[i].address), |
| 1796 | get_unaligned_le32(&cmvs_v2[i].offset), |
| 1797 | get_unaligned_le32(&cmvs_v2[i].data)); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1798 | if (ret < 0) |
| 1799 | goto out; |
| 1800 | } |
| 1801 | } else { |
| 1802 | /* This realy should not happen */ |
| 1803 | uea_err(INS_TO_USBDEV(sc), "bad cmvs version %d\n", ver); |
| 1804 | goto out; |
| 1805 | } |
| 1806 | |
| 1807 | /* Enter in R-ACT-REQ */ |
| 1808 | ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2); |
| 1809 | uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n"); |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1810 | uea_info(INS_TO_USBDEV(sc), "modem started, waiting " |
| 1811 | "synchronization...\n"); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1812 | out: |
| 1813 | release_firmware(cmvs_fw); |
| 1814 | return ret; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | /* Start boot post firmware modem: |
| 1818 | * - send reset commands through usb control pipe |
| 1819 | * - start workqueue for DSP loading |
| 1820 | * - send CMV options to modem |
| 1821 | */ |
| 1822 | |
| 1823 | static int uea_start_reset(struct uea_softc *sc) |
| 1824 | { |
| 1825 | u16 zero = 0; /* ;-) */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1826 | int ret; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1827 | |
| 1828 | uea_enters(INS_TO_USBDEV(sc)); |
| 1829 | uea_info(INS_TO_USBDEV(sc), "(re)booting started\n"); |
| 1830 | |
matthieu castet | 22fcceb | 2006-04-02 18:44:20 +0200 | [diff] [blame] | 1831 | /* mask interrupt */ |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1832 | sc->booting = 1; |
matthieu castet | 22fcceb | 2006-04-02 18:44:20 +0200 | [diff] [blame] | 1833 | /* We need to set this here because, a ack timeout could have occured, |
| 1834 | * but before we start the reboot, the ack occurs and set this to 1. |
| 1835 | * So we will failed to wait Ready CMV. |
| 1836 | */ |
| 1837 | sc->cmv_ack = 0; |
Karl Hiramoto | cc7b86c | 2010-07-08 20:55:38 +0000 | [diff] [blame] | 1838 | UPDATE_ATM_SIGNAL(ATM_PHY_SIG_LOST); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1839 | |
| 1840 | /* reset statistics */ |
| 1841 | memset(&sc->stats, 0, sizeof(struct uea_stats)); |
| 1842 | |
| 1843 | /* tell the modem that we want to boot in IDMA mode */ |
| 1844 | uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL); |
| 1845 | uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL); |
| 1846 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1847 | /* enter reset mode */ |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1848 | uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL); |
| 1849 | |
| 1850 | /* original driver use 200ms, but windows driver use 100ms */ |
Stanislaw Gruszka | 337427f | 2007-08-20 23:21:14 +0200 | [diff] [blame] | 1851 | ret = uea_wait(sc, 0, msecs_to_jiffies(100)); |
| 1852 | if (ret < 0) |
| 1853 | return ret; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1854 | |
| 1855 | /* leave reset mode */ |
| 1856 | uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL); |
| 1857 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1858 | if (UEA_CHIP_VERSION(sc) != EAGLE_IV) { |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1859 | /* clear tx and rx mailboxes */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1860 | uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero); |
| 1861 | uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero); |
| 1862 | uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero); |
| 1863 | } |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1864 | |
Stanislaw Gruszka | 337427f | 2007-08-20 23:21:14 +0200 | [diff] [blame] | 1865 | ret = uea_wait(sc, 0, msecs_to_jiffies(1000)); |
| 1866 | if (ret < 0) |
| 1867 | return ret; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1868 | |
| 1869 | if (UEA_CHIP_VERSION(sc) == EAGLE_IV) |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1870 | sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, |
| 1871 | E4_MODEMREADY, 1); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1872 | else |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1873 | sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, |
| 1874 | E1_MODEMREADY); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1875 | |
matthieu castet | 22fcceb | 2006-04-02 18:44:20 +0200 | [diff] [blame] | 1876 | /* demask interrupt */ |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1877 | sc->booting = 0; |
| 1878 | |
| 1879 | /* start loading DSP */ |
| 1880 | sc->pageno = 0; |
| 1881 | sc->ovl = 0; |
Stanislaw Gruszka | 04ea02f | 2007-08-20 23:21:10 +0200 | [diff] [blame] | 1882 | queue_work(sc->work_q, &sc->task); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1883 | |
| 1884 | /* wait for modem ready CMV */ |
| 1885 | ret = wait_cmv_ack(sc); |
| 1886 | if (ret < 0) |
| 1887 | return ret; |
| 1888 | |
matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 1889 | uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n"); |
| 1890 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1891 | ret = sc->send_cmvs(sc); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1892 | if (ret < 0) |
| 1893 | return ret; |
| 1894 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1895 | sc->reset = 0; |
| 1896 | uea_leaves(INS_TO_USBDEV(sc)); |
| 1897 | return ret; |
| 1898 | } |
| 1899 | |
| 1900 | /* |
| 1901 | * In case of an error wait 1s before rebooting the modem |
| 1902 | * if the modem don't request reboot (-EAGAIN). |
| 1903 | * Monitor the modem every 1s. |
| 1904 | */ |
| 1905 | |
| 1906 | static int uea_kthread(void *data) |
| 1907 | { |
| 1908 | struct uea_softc *sc = data; |
| 1909 | int ret = -EAGAIN; |
| 1910 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 1911 | set_freezable(); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1912 | uea_enters(INS_TO_USBDEV(sc)); |
| 1913 | while (!kthread_should_stop()) { |
| 1914 | if (ret < 0 || sc->reset) |
| 1915 | ret = uea_start_reset(sc); |
| 1916 | if (!ret) |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1917 | ret = sc->stat(sc); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1918 | if (ret != -EAGAIN) |
Stanislaw Gruszka | 337427f | 2007-08-20 23:21:14 +0200 | [diff] [blame] | 1919 | uea_wait(sc, 0, msecs_to_jiffies(1000)); |
Stanislaw Gruszka | 0eb0226 | 2007-08-20 23:21:19 +0200 | [diff] [blame] | 1920 | try_to_freeze(); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1921 | } |
| 1922 | uea_leaves(INS_TO_USBDEV(sc)); |
| 1923 | return ret; |
| 1924 | } |
| 1925 | |
| 1926 | /* Load second usb firmware for ADI930 chip */ |
| 1927 | static int load_XILINX_firmware(struct uea_softc *sc) |
| 1928 | { |
| 1929 | const struct firmware *fw_entry; |
| 1930 | int ret, size, u, ln; |
David Woodhouse | aafcd2f | 2008-05-24 00:05:10 +0100 | [diff] [blame] | 1931 | const u8 *pfw; |
| 1932 | u8 value; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1933 | char *fw_name = FW_DIR "930-fpga.bin"; |
| 1934 | |
| 1935 | uea_enters(INS_TO_USBDEV(sc)); |
| 1936 | |
| 1937 | ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev); |
| 1938 | if (ret) { |
| 1939 | uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n", |
| 1940 | fw_name); |
| 1941 | goto err0; |
| 1942 | } |
| 1943 | |
| 1944 | pfw = fw_entry->data; |
| 1945 | size = fw_entry->size; |
| 1946 | if (size != 0x577B) { |
| 1947 | uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n", |
| 1948 | fw_name); |
| 1949 | ret = -EILSEQ; |
| 1950 | goto err1; |
| 1951 | } |
| 1952 | for (u = 0; u < size; u += ln) { |
| 1953 | ln = min(size - u, 64); |
| 1954 | ret = uea_request(sc, 0xe, 0, ln, pfw + u); |
| 1955 | if (ret < 0) { |
| 1956 | uea_err(INS_TO_USBDEV(sc), |
| 1957 | "elsa download data failed (%d)\n", ret); |
| 1958 | goto err1; |
| 1959 | } |
| 1960 | } |
| 1961 | |
matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 1962 | /* finish to send the fpga */ |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1963 | ret = uea_request(sc, 0xe, 1, 0, NULL); |
| 1964 | if (ret < 0) { |
| 1965 | uea_err(INS_TO_USBDEV(sc), |
| 1966 | "elsa download data failed (%d)\n", ret); |
| 1967 | goto err1; |
| 1968 | } |
| 1969 | |
matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 1970 | /* Tell the modem we finish : de-assert reset */ |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1971 | value = 0; |
| 1972 | ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value); |
| 1973 | if (ret < 0) |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 1974 | uea_err(sc->usb_dev, "elsa de-assert failed with error" |
| 1975 | " %d\n", ret); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1976 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1977 | err1: |
| 1978 | release_firmware(fw_entry); |
| 1979 | err0: |
| 1980 | uea_leaves(INS_TO_USBDEV(sc)); |
| 1981 | return ret; |
| 1982 | } |
| 1983 | |
matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 1984 | /* The modem send us an ack. First with check if it right */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1985 | static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1986 | { |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1987 | struct cmv_dsc_e1 *dsc = &sc->cmv_dsc.e1; |
| 1988 | struct cmv_e1 *cmv = &intr->u.e1.s2.cmv; |
| 1989 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1990 | uea_enters(INS_TO_USBDEV(sc)); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1991 | if (le16_to_cpu(cmv->wPreamble) != E1_PREAMBLE) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1992 | goto bad1; |
| 1993 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 1994 | if (cmv->bDirection != E1_MODEMTOHOST) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1995 | goto bad1; |
| 1996 | |
| 1997 | /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1998 | * the first MEMACCESS cmv. Ignore it... |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 1999 | */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2000 | if (cmv->bFunction != dsc->function) { |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2001 | if (UEA_CHIP_VERSION(sc) == ADI930 |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2002 | && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) { |
| 2003 | cmv->wIndex = cpu_to_le16(dsc->idx); |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2004 | put_unaligned_le32(dsc->address, |
| 2005 | &cmv->dwSymbolicAddress); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2006 | cmv->wOffsetAddress = cpu_to_le16(dsc->offset); |
| 2007 | } else |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2008 | goto bad2; |
| 2009 | } |
| 2010 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2011 | if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, |
| 2012 | E1_MODEMREADY)) { |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2013 | wake_up_cmv_ack(sc); |
matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 2014 | uea_leaves(INS_TO_USBDEV(sc)); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2015 | return; |
| 2016 | } |
| 2017 | |
| 2018 | /* in case of MEMACCESS */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2019 | if (le16_to_cpu(cmv->wIndex) != dsc->idx || |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 2020 | get_unaligned_le32(&cmv->dwSymbolicAddress) != dsc->address || |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2021 | le16_to_cpu(cmv->wOffsetAddress) != dsc->offset) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2022 | goto bad2; |
| 2023 | |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 2024 | sc->data = get_unaligned_le32(&cmv->dwData); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2025 | sc->data = sc->data << 16 | sc->data >> 16; |
| 2026 | |
| 2027 | wake_up_cmv_ack(sc); |
matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 2028 | uea_leaves(INS_TO_USBDEV(sc)); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2029 | return; |
| 2030 | |
| 2031 | bad2: |
Joe Perches | fec8de3 | 2007-11-19 17:53:33 -0800 | [diff] [blame] | 2032 | uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, " |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2033 | "Function : %d, Subfunction : %d\n", |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2034 | E1_FUNCTION_TYPE(cmv->bFunction), |
| 2035 | E1_FUNCTION_SUBTYPE(cmv->bFunction)); |
matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 2036 | uea_leaves(INS_TO_USBDEV(sc)); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2037 | return; |
| 2038 | |
| 2039 | bad1: |
| 2040 | uea_err(INS_TO_USBDEV(sc), "invalid cmv received, " |
| 2041 | "wPreamble %d, bDirection %d\n", |
| 2042 | le16_to_cpu(cmv->wPreamble), cmv->bDirection); |
matthieu castet | 2a99b50 | 2006-04-02 18:43:53 +0200 | [diff] [blame] | 2043 | uea_leaves(INS_TO_USBDEV(sc)); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2044 | } |
| 2045 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2046 | /* The modem send us an ack. First with check if it right */ |
| 2047 | static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr) |
| 2048 | { |
| 2049 | struct cmv_dsc_e4 *dsc = &sc->cmv_dsc.e4; |
| 2050 | struct cmv_e4 *cmv = &intr->u.e4.s2.cmv; |
| 2051 | |
| 2052 | uea_enters(INS_TO_USBDEV(sc)); |
| 2053 | uea_dbg(INS_TO_USBDEV(sc), "cmv %x %x %x %x %x %x\n", |
| 2054 | be16_to_cpu(cmv->wGroup), be16_to_cpu(cmv->wFunction), |
| 2055 | be16_to_cpu(cmv->wOffset), be16_to_cpu(cmv->wAddress), |
| 2056 | be32_to_cpu(cmv->dwData[0]), be32_to_cpu(cmv->dwData[1])); |
| 2057 | |
| 2058 | if (be16_to_cpu(cmv->wFunction) != dsc->function) |
| 2059 | goto bad2; |
| 2060 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2061 | if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, |
| 2062 | E4_MODEMREADY, 1)) { |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2063 | wake_up_cmv_ack(sc); |
| 2064 | uea_leaves(INS_TO_USBDEV(sc)); |
| 2065 | return; |
| 2066 | } |
| 2067 | |
| 2068 | /* in case of MEMACCESS */ |
| 2069 | if (be16_to_cpu(cmv->wOffset) != dsc->offset || |
| 2070 | be16_to_cpu(cmv->wGroup) != dsc->group || |
| 2071 | be16_to_cpu(cmv->wAddress) != dsc->address) |
| 2072 | goto bad2; |
| 2073 | |
| 2074 | sc->data = be32_to_cpu(cmv->dwData[0]); |
| 2075 | sc->data1 = be32_to_cpu(cmv->dwData[1]); |
| 2076 | wake_up_cmv_ack(sc); |
| 2077 | uea_leaves(INS_TO_USBDEV(sc)); |
| 2078 | return; |
| 2079 | |
| 2080 | bad2: |
Joe Perches | fec8de3 | 2007-11-19 17:53:33 -0800 | [diff] [blame] | 2081 | uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, " |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2082 | "Function : %d, Subfunction : %d\n", |
| 2083 | E4_FUNCTION_TYPE(cmv->wFunction), |
| 2084 | E4_FUNCTION_SUBTYPE(cmv->wFunction)); |
| 2085 | uea_leaves(INS_TO_USBDEV(sc)); |
| 2086 | return; |
| 2087 | } |
| 2088 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2089 | static void uea_schedule_load_page_e1(struct uea_softc *sc, |
| 2090 | struct intr_pkt *intr) |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2091 | { |
| 2092 | sc->pageno = intr->e1_bSwapPageNo; |
| 2093 | sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4; |
Stanislaw Gruszka | 04ea02f | 2007-08-20 23:21:10 +0200 | [diff] [blame] | 2094 | queue_work(sc->work_q, &sc->task); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2095 | } |
| 2096 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2097 | static void uea_schedule_load_page_e4(struct uea_softc *sc, |
| 2098 | struct intr_pkt *intr) |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2099 | { |
| 2100 | sc->pageno = intr->e4_bSwapPageNo; |
Stanislaw Gruszka | 04ea02f | 2007-08-20 23:21:10 +0200 | [diff] [blame] | 2101 | queue_work(sc->work_q, &sc->task); |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2102 | } |
| 2103 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2104 | /* |
| 2105 | * interrupt handler |
| 2106 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 2107 | static void uea_intr(struct urb *urb) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2108 | { |
matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 2109 | struct uea_softc *sc = urb->context; |
| 2110 | struct intr_pkt *intr = urb->transfer_buffer; |
Greg Kroah-Hartman | 508330e | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 2111 | int status = urb->status; |
| 2112 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2113 | uea_enters(INS_TO_USBDEV(sc)); |
| 2114 | |
Greg Kroah-Hartman | 508330e | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 2115 | if (unlikely(status < 0)) { |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2116 | uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n", |
Greg Kroah-Hartman | 508330e | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 2117 | status); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2118 | return; |
| 2119 | } |
| 2120 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2121 | /* device-to-host interrupt */ |
| 2122 | if (intr->bType != 0x08 || sc->booting) { |
matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 2123 | uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n"); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2124 | goto resubmit; |
| 2125 | } |
| 2126 | |
| 2127 | switch (le16_to_cpu(intr->wInterrupt)) { |
| 2128 | case INT_LOADSWAPPAGE: |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2129 | sc->schedule_load_page(sc, intr); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2130 | break; |
| 2131 | |
| 2132 | case INT_INCOMINGCMV: |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2133 | sc->dispatch_cmv(sc, intr); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2134 | break; |
| 2135 | |
| 2136 | default: |
matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 2137 | uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n", |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2138 | le16_to_cpu(intr->wInterrupt)); |
| 2139 | } |
| 2140 | |
| 2141 | resubmit: |
| 2142 | usb_submit_urb(sc->urb_int, GFP_ATOMIC); |
| 2143 | } |
| 2144 | |
| 2145 | /* |
| 2146 | * Start the modem : init the data and start kernel thread |
| 2147 | */ |
| 2148 | static int uea_boot(struct uea_softc *sc) |
| 2149 | { |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2150 | int ret, size; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2151 | struct intr_pkt *intr; |
| 2152 | |
| 2153 | uea_enters(INS_TO_USBDEV(sc)); |
| 2154 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2155 | if (UEA_CHIP_VERSION(sc) == EAGLE_IV) { |
| 2156 | size = E4_INTR_PKT_SIZE; |
| 2157 | sc->dispatch_cmv = uea_dispatch_cmv_e4; |
| 2158 | sc->schedule_load_page = uea_schedule_load_page_e4; |
| 2159 | sc->stat = uea_stat_e4; |
| 2160 | sc->send_cmvs = uea_send_cmvs_e4; |
| 2161 | INIT_WORK(&sc->task, uea_load_page_e4); |
| 2162 | } else { |
| 2163 | size = E1_INTR_PKT_SIZE; |
| 2164 | sc->dispatch_cmv = uea_dispatch_cmv_e1; |
| 2165 | sc->schedule_load_page = uea_schedule_load_page_e1; |
| 2166 | sc->stat = uea_stat_e1; |
| 2167 | sc->send_cmvs = uea_send_cmvs_e1; |
| 2168 | INIT_WORK(&sc->task, uea_load_page_e1); |
| 2169 | } |
| 2170 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2171 | init_waitqueue_head(&sc->sync_q); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2172 | |
Stanislaw Gruszka | 04ea02f | 2007-08-20 23:21:10 +0200 | [diff] [blame] | 2173 | sc->work_q = create_workqueue("ueagle-dsp"); |
| 2174 | if (!sc->work_q) { |
| 2175 | uea_err(INS_TO_USBDEV(sc), "cannot allocate workqueue\n"); |
| 2176 | uea_leaves(INS_TO_USBDEV(sc)); |
| 2177 | return -ENOMEM; |
| 2178 | } |
| 2179 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2180 | if (UEA_CHIP_VERSION(sc) == ADI930) |
| 2181 | load_XILINX_firmware(sc); |
| 2182 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2183 | intr = kmalloc(size, GFP_KERNEL); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2184 | if (!intr) { |
| 2185 | uea_err(INS_TO_USBDEV(sc), |
| 2186 | "cannot allocate interrupt package\n"); |
Stanislaw Gruszka | 04ea02f | 2007-08-20 23:21:10 +0200 | [diff] [blame] | 2187 | goto err0; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | sc->urb_int = usb_alloc_urb(0, GFP_KERNEL); |
| 2191 | if (!sc->urb_int) { |
| 2192 | uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n"); |
Stanislaw Gruszka | 04ea02f | 2007-08-20 23:21:10 +0200 | [diff] [blame] | 2193 | goto err1; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2194 | } |
| 2195 | |
| 2196 | usb_fill_int_urb(sc->urb_int, sc->usb_dev, |
| 2197 | usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE), |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2198 | intr, size, uea_intr, sc, |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2199 | sc->usb_dev->actconfig->interface[0]->altsetting[0]. |
| 2200 | endpoint[0].desc.bInterval); |
| 2201 | |
| 2202 | ret = usb_submit_urb(sc->urb_int, GFP_KERNEL); |
| 2203 | if (ret < 0) { |
| 2204 | uea_err(INS_TO_USBDEV(sc), |
| 2205 | "urb submition failed with error %d\n", ret); |
Stanislaw Gruszka | 04ea02f | 2007-08-20 23:21:10 +0200 | [diff] [blame] | 2206 | goto err1; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm"); |
| 2210 | if (sc->kthread == ERR_PTR(-ENOMEM)) { |
| 2211 | uea_err(INS_TO_USBDEV(sc), "failed to create thread\n"); |
| 2212 | goto err2; |
| 2213 | } |
| 2214 | |
| 2215 | uea_leaves(INS_TO_USBDEV(sc)); |
| 2216 | return 0; |
| 2217 | |
| 2218 | err2: |
| 2219 | usb_kill_urb(sc->urb_int); |
Stanislaw Gruszka | 04ea02f | 2007-08-20 23:21:10 +0200 | [diff] [blame] | 2220 | err1: |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2221 | usb_free_urb(sc->urb_int); |
matthieu castet | 4d45e21 | 2006-04-02 18:45:46 +0200 | [diff] [blame] | 2222 | sc->urb_int = NULL; |
| 2223 | kfree(intr); |
Stanislaw Gruszka | 04ea02f | 2007-08-20 23:21:10 +0200 | [diff] [blame] | 2224 | err0: |
| 2225 | destroy_workqueue(sc->work_q); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2226 | uea_leaves(INS_TO_USBDEV(sc)); |
| 2227 | return -ENOMEM; |
| 2228 | } |
| 2229 | |
| 2230 | /* |
| 2231 | * Stop the modem : kill kernel thread and free data |
| 2232 | */ |
| 2233 | static void uea_stop(struct uea_softc *sc) |
| 2234 | { |
| 2235 | int ret; |
| 2236 | uea_enters(INS_TO_USBDEV(sc)); |
| 2237 | ret = kthread_stop(sc->kthread); |
matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 2238 | 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] | 2239 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2240 | uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL); |
| 2241 | |
| 2242 | usb_kill_urb(sc->urb_int); |
| 2243 | kfree(sc->urb_int->transfer_buffer); |
| 2244 | usb_free_urb(sc->urb_int); |
| 2245 | |
Stanislaw Gruszka | 04ea02f | 2007-08-20 23:21:10 +0200 | [diff] [blame] | 2246 | /* stop any pending boot process, when no one can schedule work */ |
| 2247 | destroy_workqueue(sc->work_q); |
| 2248 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2249 | if (sc->dsp_firm) |
| 2250 | release_firmware(sc->dsp_firm); |
| 2251 | uea_leaves(INS_TO_USBDEV(sc)); |
| 2252 | } |
| 2253 | |
| 2254 | /* syfs interface */ |
| 2255 | static struct uea_softc *dev_to_uea(struct device *dev) |
| 2256 | { |
| 2257 | struct usb_interface *intf; |
| 2258 | struct usbatm_data *usbatm; |
| 2259 | |
| 2260 | intf = to_usb_interface(dev); |
| 2261 | if (!intf) |
| 2262 | return NULL; |
| 2263 | |
| 2264 | usbatm = usb_get_intfdata(intf); |
| 2265 | if (!usbatm) |
| 2266 | return NULL; |
| 2267 | |
| 2268 | return usbatm->driver_data; |
| 2269 | } |
| 2270 | |
| 2271 | static ssize_t read_status(struct device *dev, struct device_attribute *attr, |
| 2272 | char *buf) |
| 2273 | { |
| 2274 | int ret = -ENODEV; |
| 2275 | struct uea_softc *sc; |
| 2276 | |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 2277 | mutex_lock(&uea_mutex); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2278 | sc = dev_to_uea(dev); |
| 2279 | if (!sc) |
| 2280 | goto out; |
| 2281 | ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state); |
| 2282 | out: |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 2283 | mutex_unlock(&uea_mutex); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2284 | return ret; |
| 2285 | } |
| 2286 | |
| 2287 | static ssize_t reboot(struct device *dev, struct device_attribute *attr, |
| 2288 | const char *buf, size_t count) |
| 2289 | { |
| 2290 | int ret = -ENODEV; |
| 2291 | struct uea_softc *sc; |
| 2292 | |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 2293 | mutex_lock(&uea_mutex); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2294 | sc = dev_to_uea(dev); |
| 2295 | if (!sc) |
| 2296 | goto out; |
| 2297 | sc->reset = 1; |
| 2298 | ret = count; |
| 2299 | out: |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 2300 | mutex_unlock(&uea_mutex); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2301 | return ret; |
| 2302 | } |
| 2303 | |
| 2304 | static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot); |
| 2305 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2306 | static ssize_t read_human_status(struct device *dev, |
| 2307 | struct device_attribute *attr, char *buf) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2308 | { |
| 2309 | int ret = -ENODEV; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2310 | int modem_state; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2311 | struct uea_softc *sc; |
| 2312 | |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 2313 | mutex_lock(&uea_mutex); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2314 | sc = dev_to_uea(dev); |
| 2315 | if (!sc) |
| 2316 | goto out; |
| 2317 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2318 | if (UEA_CHIP_VERSION(sc) == EAGLE_IV) { |
| 2319 | switch (sc->stats.phy.state) { |
| 2320 | case 0x0: /* not yet synchronized */ |
| 2321 | case 0x1: |
| 2322 | case 0x3: |
| 2323 | case 0x4: |
| 2324 | modem_state = 0; |
| 2325 | break; |
| 2326 | case 0x5: /* initialization */ |
| 2327 | case 0x6: |
| 2328 | case 0x9: |
| 2329 | case 0xa: |
| 2330 | modem_state = 1; |
| 2331 | break; |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2332 | case 0x7: /* operational */ |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2333 | modem_state = 2; |
| 2334 | break; |
| 2335 | case 0x2: /* fail ... */ |
| 2336 | modem_state = 3; |
| 2337 | break; |
| 2338 | default: /* unknown */ |
| 2339 | modem_state = 4; |
| 2340 | break; |
| 2341 | } |
| 2342 | } else |
| 2343 | modem_state = GET_STATUS(sc->stats.phy.state); |
| 2344 | |
| 2345 | switch (modem_state) { |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2346 | case 0: |
| 2347 | ret = sprintf(buf, "Modem is booting\n"); |
| 2348 | break; |
| 2349 | case 1: |
| 2350 | ret = sprintf(buf, "Modem is initializing\n"); |
| 2351 | break; |
| 2352 | case 2: |
| 2353 | ret = sprintf(buf, "Modem is operational\n"); |
| 2354 | break; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2355 | case 3: |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2356 | ret = sprintf(buf, "Modem synchronization failed\n"); |
| 2357 | break; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2358 | default: |
| 2359 | ret = sprintf(buf, "Modem state is unknown\n"); |
| 2360 | break; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2361 | } |
| 2362 | out: |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 2363 | mutex_unlock(&uea_mutex); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2364 | return ret; |
| 2365 | } |
| 2366 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2367 | static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, |
| 2368 | read_human_status, NULL); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2369 | |
| 2370 | static ssize_t read_delin(struct device *dev, struct device_attribute *attr, |
| 2371 | char *buf) |
| 2372 | { |
| 2373 | int ret = -ENODEV; |
| 2374 | struct uea_softc *sc; |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2375 | char *delin = "GOOD"; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2376 | |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 2377 | mutex_lock(&uea_mutex); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2378 | sc = dev_to_uea(dev); |
| 2379 | if (!sc) |
| 2380 | goto out; |
| 2381 | |
Stanislaw Gruszka | c8e4637 | 2007-08-20 23:23:12 +0200 | [diff] [blame] | 2382 | if (UEA_CHIP_VERSION(sc) == EAGLE_IV) { |
| 2383 | if (sc->stats.phy.flags & 0x4000) |
| 2384 | delin = "RESET"; |
| 2385 | else if (sc->stats.phy.flags & 0x0001) |
| 2386 | delin = "LOSS"; |
| 2387 | } else { |
| 2388 | if (sc->stats.phy.flags & 0x0C00) |
| 2389 | delin = "ERROR"; |
| 2390 | else if (sc->stats.phy.flags & 0x0030) |
| 2391 | delin = "LOSS"; |
| 2392 | } |
| 2393 | |
| 2394 | ret = sprintf(buf, "%s\n", delin); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2395 | out: |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 2396 | mutex_unlock(&uea_mutex); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2397 | return ret; |
| 2398 | } |
| 2399 | |
| 2400 | static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL); |
| 2401 | |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2402 | #define UEA_ATTR(name, reset) \ |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2403 | \ |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2404 | static ssize_t read_##name(struct device *dev, \ |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2405 | struct device_attribute *attr, char *buf) \ |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2406 | { \ |
| 2407 | int ret = -ENODEV; \ |
| 2408 | struct uea_softc *sc; \ |
| 2409 | \ |
| 2410 | mutex_lock(&uea_mutex); \ |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2411 | sc = dev_to_uea(dev); \ |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2412 | if (!sc) \ |
| 2413 | goto out; \ |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2414 | ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \ |
| 2415 | if (reset) \ |
| 2416 | sc->stats.phy.name = 0; \ |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2417 | out: \ |
| 2418 | mutex_unlock(&uea_mutex); \ |
| 2419 | return ret; \ |
| 2420 | } \ |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2421 | \ |
| 2422 | static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL) |
| 2423 | |
| 2424 | UEA_ATTR(mflags, 1); |
| 2425 | UEA_ATTR(vidcpe, 0); |
| 2426 | UEA_ATTR(usrate, 0); |
| 2427 | UEA_ATTR(dsrate, 0); |
| 2428 | UEA_ATTR(usattenuation, 0); |
| 2429 | UEA_ATTR(dsattenuation, 0); |
| 2430 | UEA_ATTR(usmargin, 0); |
| 2431 | UEA_ATTR(dsmargin, 0); |
| 2432 | UEA_ATTR(txflow, 0); |
| 2433 | UEA_ATTR(rxflow, 0); |
| 2434 | UEA_ATTR(uscorr, 0); |
| 2435 | UEA_ATTR(dscorr, 0); |
| 2436 | UEA_ATTR(usunc, 0); |
| 2437 | UEA_ATTR(dsunc, 0); |
matthieu castet | a7a0c9c | 2006-10-03 21:44:11 +0200 | [diff] [blame] | 2438 | UEA_ATTR(firmid, 0); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2439 | |
| 2440 | /* Retrieve the device End System Identifier (MAC) */ |
| 2441 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2442 | static int uea_getesi(struct uea_softc *sc, u_char * esi) |
| 2443 | { |
| 2444 | unsigned char mac_str[2 * ETH_ALEN + 1]; |
| 2445 | int i; |
| 2446 | if (usb_string |
| 2447 | (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str, |
| 2448 | sizeof(mac_str)) != 2 * ETH_ALEN) |
| 2449 | return 1; |
| 2450 | |
| 2451 | for (i = 0; i < ETH_ALEN; i++) |
Andy Shevchenko | e644814 | 2010-06-15 17:04:44 +0300 | [diff] [blame] | 2452 | esi[i] = hex_to_bin(mac_str[2 * i]) * 16 + |
| 2453 | hex_to_bin(mac_str[2 * i + 1]); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2454 | |
| 2455 | return 0; |
| 2456 | } |
| 2457 | |
| 2458 | /* ATM stuff */ |
| 2459 | static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev) |
| 2460 | { |
| 2461 | struct uea_softc *sc = usbatm->driver_data; |
| 2462 | |
| 2463 | return uea_getesi(sc, atm_dev->esi); |
| 2464 | } |
| 2465 | |
| 2466 | static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf) |
| 2467 | { |
| 2468 | struct uea_softc *sc = usbatm->driver_data; |
| 2469 | |
matthieu castet | 531a39b | 2006-10-03 21:49:29 +0200 | [diff] [blame] | 2470 | wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc)); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2471 | |
| 2472 | return 0; |
| 2473 | |
| 2474 | } |
| 2475 | |
| 2476 | static int claim_interface(struct usb_device *usb_dev, |
| 2477 | struct usbatm_data *usbatm, int ifnum) |
| 2478 | { |
| 2479 | int ret; |
| 2480 | struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum); |
| 2481 | |
| 2482 | if (!intf) { |
| 2483 | uea_err(usb_dev, "interface %d not found\n", ifnum); |
| 2484 | return -ENODEV; |
| 2485 | } |
| 2486 | |
| 2487 | ret = usb_driver_claim_interface(&uea_driver, intf, usbatm); |
| 2488 | if (ret != 0) |
| 2489 | uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum, |
| 2490 | ret); |
| 2491 | return ret; |
| 2492 | } |
| 2493 | |
Greg Kroah-Hartman | e7ccdfe | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 2494 | static struct attribute *attrs[] = { |
| 2495 | &dev_attr_stat_status.attr, |
| 2496 | &dev_attr_stat_mflags.attr, |
| 2497 | &dev_attr_stat_human_status.attr, |
| 2498 | &dev_attr_stat_delin.attr, |
| 2499 | &dev_attr_stat_vidcpe.attr, |
| 2500 | &dev_attr_stat_usrate.attr, |
| 2501 | &dev_attr_stat_dsrate.attr, |
| 2502 | &dev_attr_stat_usattenuation.attr, |
| 2503 | &dev_attr_stat_dsattenuation.attr, |
| 2504 | &dev_attr_stat_usmargin.attr, |
| 2505 | &dev_attr_stat_dsmargin.attr, |
| 2506 | &dev_attr_stat_txflow.attr, |
| 2507 | &dev_attr_stat_rxflow.attr, |
| 2508 | &dev_attr_stat_uscorr.attr, |
| 2509 | &dev_attr_stat_dscorr.attr, |
| 2510 | &dev_attr_stat_usunc.attr, |
| 2511 | &dev_attr_stat_dsunc.attr, |
matthieu castet | a7a0c9c | 2006-10-03 21:44:11 +0200 | [diff] [blame] | 2512 | &dev_attr_stat_firmid.attr, |
matthieu castet | 9ab99c8 | 2006-10-11 14:20:56 -0700 | [diff] [blame] | 2513 | NULL, |
Greg Kroah-Hartman | e7ccdfe | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 2514 | }; |
| 2515 | static struct attribute_group attr_grp = { |
| 2516 | .attrs = attrs, |
| 2517 | }; |
| 2518 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2519 | static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf, |
Duncan Sands | 35644b0 | 2006-01-17 11:16:13 +0100 | [diff] [blame] | 2520 | const struct usb_device_id *id) |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2521 | { |
| 2522 | struct usb_device *usb = interface_to_usbdev(intf); |
| 2523 | struct uea_softc *sc; |
| 2524 | int ret, ifnum = intf->altsetting->desc.bInterfaceNumber; |
Stanislaw Gruszka | 503add4 | 2007-08-20 23:21:06 +0200 | [diff] [blame] | 2525 | unsigned int alt; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2526 | |
| 2527 | uea_enters(usb); |
| 2528 | |
| 2529 | /* interface 0 is for firmware/monitoring */ |
| 2530 | if (ifnum != UEA_INTR_IFACE_NO) |
| 2531 | return -ENODEV; |
| 2532 | |
Duncan Sands | 0dfcd3e | 2006-01-13 09:36:20 +0100 | [diff] [blame] | 2533 | usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2534 | |
| 2535 | /* interface 1 is for outbound traffic */ |
| 2536 | ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO); |
| 2537 | if (ret < 0) |
| 2538 | return ret; |
| 2539 | |
matthieu castet | e40abaf | 2006-01-18 07:38:37 +0100 | [diff] [blame] | 2540 | /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */ |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2541 | if (UEA_CHIP_VERSION(id) != ADI930) { |
| 2542 | /* interface 2 is for inbound traffic */ |
| 2543 | ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO); |
| 2544 | if (ret < 0) |
| 2545 | return ret; |
| 2546 | } |
| 2547 | |
| 2548 | sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL); |
| 2549 | if (!sc) { |
matthieu castet | 584958c | 2006-04-02 18:44:48 +0200 | [diff] [blame] | 2550 | uea_err(usb, "uea_init: not enough memory !\n"); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2551 | return -ENOMEM; |
| 2552 | } |
| 2553 | |
| 2554 | sc->usb_dev = usb; |
| 2555 | usbatm->driver_data = sc; |
| 2556 | sc->usbatm = usbatm; |
| 2557 | sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0; |
| 2558 | sc->driver_info = id->driver_info; |
| 2559 | |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 2560 | /* first try to use module parameter */ |
| 2561 | if (annex[sc->modem_index] == 1) |
| 2562 | sc->annex = ANNEXA; |
| 2563 | else if (annex[sc->modem_index] == 2) |
| 2564 | sc->annex = ANNEXB; |
| 2565 | /* try to autodetect annex */ |
| 2566 | else if (sc->driver_info & AUTO_ANNEX_A) |
| 2567 | sc->annex = ANNEXA; |
| 2568 | else if (sc->driver_info & AUTO_ANNEX_B) |
| 2569 | sc->annex = ANNEXB; |
| 2570 | else |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2571 | sc->annex = (le16_to_cpu |
| 2572 | (sc->usb_dev->descriptor.bcdDevice) & 0x80) ? ANNEXB : ANNEXA; |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 2573 | |
Stanislaw Gruszka | 503add4 | 2007-08-20 23:21:06 +0200 | [diff] [blame] | 2574 | alt = altsetting[sc->modem_index]; |
matthieu castet | 3c9666c | 2006-01-18 07:38:19 +0100 | [diff] [blame] | 2575 | /* ADI930 don't support iso */ |
Stanislaw Gruszka | 503add4 | 2007-08-20 23:21:06 +0200 | [diff] [blame] | 2576 | if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) { |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2577 | if (alt <= 8 && |
| 2578 | usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) { |
Stanislaw Gruszka | 503add4 | 2007-08-20 23:21:06 +0200 | [diff] [blame] | 2579 | uea_dbg(usb, "set alternate %u for 2 interface\n", alt); |
matthieu castet | 3c9666c | 2006-01-18 07:38:19 +0100 | [diff] [blame] | 2580 | uea_info(usb, "using iso mode\n"); |
| 2581 | usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ; |
| 2582 | } else { |
Stanislaw Gruszka | 503add4 | 2007-08-20 23:21:06 +0200 | [diff] [blame] | 2583 | uea_err(usb, "setting alternate %u failed for " |
| 2584 | "2 interface, using bulk mode\n", alt); |
matthieu castet | 3c9666c | 2006-01-18 07:38:19 +0100 | [diff] [blame] | 2585 | } |
| 2586 | } |
| 2587 | |
matthieu castet | 9ab99c8 | 2006-10-11 14:20:56 -0700 | [diff] [blame] | 2588 | ret = sysfs_create_group(&intf->dev.kobj, &attr_grp); |
| 2589 | if (ret < 0) |
| 2590 | goto error; |
| 2591 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2592 | ret = uea_boot(sc); |
matthieu castet | 9ab99c8 | 2006-10-11 14:20:56 -0700 | [diff] [blame] | 2593 | if (ret < 0) |
Stanislaw Gruszka | 4c132e7 | 2007-08-20 23:20:49 +0200 | [diff] [blame] | 2594 | goto error_rm_grp; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2595 | |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2596 | return 0; |
Stanislaw Gruszka | 4c132e7 | 2007-08-20 23:20:49 +0200 | [diff] [blame] | 2597 | |
| 2598 | error_rm_grp: |
| 2599 | sysfs_remove_group(&intf->dev.kobj, &attr_grp); |
matthieu castet | 9ab99c8 | 2006-10-11 14:20:56 -0700 | [diff] [blame] | 2600 | error: |
| 2601 | kfree(sc); |
| 2602 | return ret; |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf) |
| 2606 | { |
| 2607 | struct uea_softc *sc = usbatm->driver_data; |
| 2608 | |
matthieu castet | 9ab99c8 | 2006-10-11 14:20:56 -0700 | [diff] [blame] | 2609 | sysfs_remove_group(&intf->dev.kobj, &attr_grp); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2610 | uea_stop(sc); |
| 2611 | kfree(sc); |
| 2612 | } |
| 2613 | |
| 2614 | static struct usbatm_driver uea_usbatm_driver = { |
| 2615 | .driver_name = "ueagle-atm", |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2616 | .bind = uea_bind, |
| 2617 | .atm_start = uea_atm_open, |
| 2618 | .unbind = uea_unbind, |
| 2619 | .heavy_init = uea_heavy, |
Duncan Sands | 80aae7a | 2006-01-13 10:59:23 +0100 | [diff] [blame] | 2620 | .bulk_in = UEA_BULK_DATA_PIPE, |
| 2621 | .bulk_out = UEA_BULK_DATA_PIPE, |
matthieu castet | 3c9666c | 2006-01-18 07:38:19 +0100 | [diff] [blame] | 2622 | .isoc_in = UEA_ISO_DATA_PIPE, |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2623 | }; |
| 2624 | |
| 2625 | static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 2626 | { |
| 2627 | struct usb_device *usb = interface_to_usbdev(intf); |
| 2628 | |
| 2629 | uea_enters(usb); |
Stanislaw Gruszka | 603cf60 | 2007-08-20 23:21:01 +0200 | [diff] [blame] | 2630 | uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) Rev (%#X): %s\n", |
| 2631 | le16_to_cpu(usb->descriptor.idVendor), |
| 2632 | le16_to_cpu(usb->descriptor.idProduct), |
| 2633 | le16_to_cpu(usb->descriptor.bcdDevice), |
| 2634 | chip_name[UEA_CHIP_VERSION(id)]); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2635 | |
| 2636 | usb_reset_device(usb); |
| 2637 | |
| 2638 | if (UEA_IS_PREFIRM(id)) |
| 2639 | return uea_load_firmware(usb, UEA_CHIP_VERSION(id)); |
| 2640 | |
| 2641 | return usbatm_usb_probe(intf, id, &uea_usbatm_driver); |
| 2642 | } |
| 2643 | |
| 2644 | static void uea_disconnect(struct usb_interface *intf) |
| 2645 | { |
| 2646 | struct usb_device *usb = interface_to_usbdev(intf); |
| 2647 | int ifnum = intf->altsetting->desc.bInterfaceNumber; |
| 2648 | uea_enters(usb); |
| 2649 | |
| 2650 | /* ADI930 has 2 interfaces and eagle 3 interfaces. |
| 2651 | * Pre-firmware device has one interface |
| 2652 | */ |
| 2653 | if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) { |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 2654 | mutex_lock(&uea_mutex); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2655 | usbatm_usb_disconnect(intf); |
Arjan van de Ven | ab3c81f | 2006-01-13 15:52:55 +0100 | [diff] [blame] | 2656 | mutex_unlock(&uea_mutex); |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2657 | uea_info(usb, "ADSL device removed\n"); |
| 2658 | } |
| 2659 | |
| 2660 | uea_leaves(usb); |
| 2661 | } |
| 2662 | |
| 2663 | /* |
| 2664 | * List of supported VID/PID |
| 2665 | */ |
| 2666 | static const struct usb_device_id uea_ids[] = { |
Javier Blanco de Torres (Neurowork) | 4545f7e | 2010-04-12 09:21:13 +0200 | [diff] [blame] | 2667 | {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM), |
| 2668 | .driver_info = ADI930 | PREFIRM}, |
| 2669 | {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM), |
| 2670 | .driver_info = ADI930 | PSTFIRM}, |
| 2671 | {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM), |
| 2672 | .driver_info = EAGLE_I | PREFIRM}, |
| 2673 | {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM), |
| 2674 | .driver_info = EAGLE_I | PSTFIRM}, |
| 2675 | {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM), |
| 2676 | .driver_info = EAGLE_II | PREFIRM}, |
| 2677 | {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM), |
| 2678 | .driver_info = EAGLE_II | PSTFIRM}, |
| 2679 | {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM), |
| 2680 | .driver_info = EAGLE_II | PREFIRM}, |
| 2681 | {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM), |
| 2682 | .driver_info = EAGLE_II | PSTFIRM}, |
| 2683 | {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM), |
| 2684 | .driver_info = EAGLE_III | PREFIRM}, |
| 2685 | {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM), |
| 2686 | .driver_info = EAGLE_III | PSTFIRM}, |
| 2687 | {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM), |
| 2688 | .driver_info = EAGLE_IV | PREFIRM}, |
| 2689 | {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM), |
| 2690 | .driver_info = EAGLE_IV | PSTFIRM}, |
| 2691 | {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM), |
| 2692 | .driver_info = EAGLE_I | PREFIRM}, |
| 2693 | {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM), |
| 2694 | .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A}, |
| 2695 | {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM), |
| 2696 | .driver_info = EAGLE_I | PREFIRM}, |
| 2697 | {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM), |
| 2698 | .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B}, |
| 2699 | {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM), |
| 2700 | .driver_info = EAGLE_II | PREFIRM}, |
| 2701 | {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM), |
| 2702 | .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A}, |
| 2703 | {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM), |
| 2704 | .driver_info = EAGLE_II | PREFIRM}, |
| 2705 | {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM), |
| 2706 | .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B}, |
| 2707 | {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM), |
| 2708 | .driver_info = ADI930 | PREFIRM}, |
| 2709 | {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM), |
| 2710 | .driver_info = ADI930 | PSTFIRM}, |
| 2711 | {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM), |
| 2712 | .driver_info = ADI930 | PREFIRM}, |
| 2713 | {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM), |
| 2714 | .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A}, |
| 2715 | {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM), |
| 2716 | .driver_info = ADI930 | PREFIRM}, |
| 2717 | {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM), |
| 2718 | .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B}, |
| 2719 | {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM), |
| 2720 | .driver_info = EAGLE_I | PREFIRM}, |
| 2721 | {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM), |
| 2722 | .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A}, |
| 2723 | {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM), |
| 2724 | .driver_info = EAGLE_I | PREFIRM}, |
| 2725 | {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM), |
| 2726 | .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B}, |
| 2727 | {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM), |
| 2728 | .driver_info = EAGLE_I | PREFIRM}, |
| 2729 | {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM), |
| 2730 | .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A}, |
| 2731 | {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM), |
| 2732 | .driver_info = EAGLE_I | PREFIRM}, |
| 2733 | {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM), |
| 2734 | .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B}, |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2735 | {} |
| 2736 | }; |
| 2737 | |
| 2738 | /* |
| 2739 | * USB driver descriptor |
| 2740 | */ |
| 2741 | static struct usb_driver uea_driver = { |
matthieu castet | b72458a | 2005-11-07 23:27:13 +0100 | [diff] [blame] | 2742 | .name = "ueagle-atm", |
| 2743 | .id_table = uea_ids, |
| 2744 | .probe = uea_probe, |
| 2745 | .disconnect = uea_disconnect, |
| 2746 | }; |
| 2747 | |
| 2748 | MODULE_DEVICE_TABLE(usb, uea_ids); |
| 2749 | |
| 2750 | /** |
| 2751 | * uea_init - Initialize the module. |
| 2752 | * Register to USB subsystem |
| 2753 | */ |
| 2754 | static int __init uea_init(void) |
| 2755 | { |
| 2756 | printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n"); |
| 2757 | |
| 2758 | usb_register(&uea_driver); |
| 2759 | |
| 2760 | return 0; |
| 2761 | } |
| 2762 | |
| 2763 | module_init(uea_init); |
| 2764 | |
| 2765 | /** |
| 2766 | * uea_exit - Destroy module |
| 2767 | * Deregister with USB subsystem |
| 2768 | */ |
| 2769 | static void __exit uea_exit(void) |
| 2770 | { |
| 2771 | /* |
| 2772 | * This calls automatically the uea_disconnect method if necessary: |
| 2773 | */ |
| 2774 | usb_deregister(&uea_driver); |
| 2775 | |
| 2776 | printk(KERN_INFO "[ueagle-atm] driver unloaded\n"); |
| 2777 | } |
| 2778 | |
| 2779 | module_exit(uea_exit); |
| 2780 | |
| 2781 | MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka"); |
| 2782 | MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver"); |
| 2783 | MODULE_LICENSE("Dual BSD/GPL"); |