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