Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * speedtch.c - Alcatel SpeedTouch USB xDSL modem driver |
| 3 | * |
| 4 | * Copyright (C) 2001, Alcatel |
| 5 | * Copyright (C) 2003, Duncan Sands |
| 6 | * Copyright (C) 2004, David Woodhouse |
| 7 | * |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 8 | * Based on "modem_run.c", copyright (C) 2001, Benoit Papillault |
| 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the Free |
| 12 | * Software Foundation; either version 2 of the License, or (at your option) |
| 13 | * any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 18 | * more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along with |
| 21 | * this program; if not, write to the Free Software Foundation, Inc., 59 |
| 22 | * Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 | * |
| 24 | ******************************************************************************/ |
| 25 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 26 | #include <asm/page.h> |
| 27 | #include <linux/device.h> |
| 28 | #include <linux/errno.h> |
| 29 | #include <linux/firmware.h> |
| 30 | #include <linux/gfp.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/module.h> |
| 34 | #include <linux/moduleparam.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/slab.h> |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 36 | #include <linux/stat.h> |
| 37 | #include <linux/timer.h> |
| 38 | #include <linux/workqueue.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 40 | #include "usbatm.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | #define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 43 | #define DRIVER_VERSION "1.9" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION |
| 45 | |
| 46 | static const char speedtch_driver_name[] = "speedtch"; |
| 47 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 48 | #define CTRL_TIMEOUT 2000 /* milliseconds */ |
| 49 | #define DATA_TIMEOUT 2000 /* milliseconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 51 | #define OFFSET_7 0 /* size 1 */ |
| 52 | #define OFFSET_b 1 /* size 8 */ |
| 53 | #define OFFSET_d 9 /* size 4 */ |
| 54 | #define OFFSET_e 13 /* size 1 */ |
| 55 | #define OFFSET_f 14 /* size 1 */ |
| 56 | #define TOTAL 15 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 58 | #define SIZE_7 1 |
| 59 | #define SIZE_b 8 |
| 60 | #define SIZE_d 4 |
| 61 | #define SIZE_e 1 |
| 62 | #define SIZE_f 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 64 | #define MIN_POLL_DELAY 5000 /* milliseconds */ |
| 65 | #define MAX_POLL_DELAY 60000 /* milliseconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 67 | #define RESUBMIT_DELAY 1000 /* milliseconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 69 | #define DEFAULT_ALTSETTING 1 |
| 70 | #define DEFAULT_DL_512_FIRST 0 |
| 71 | #define DEFAULT_SW_BUFFERING 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 73 | static int altsetting = DEFAULT_ALTSETTING; |
| 74 | static int dl_512_first = DEFAULT_DL_512_FIRST; |
| 75 | static int sw_buffering = DEFAULT_SW_BUFFERING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 77 | module_param(altsetting, int, S_IRUGO | S_IWUSR); |
| 78 | MODULE_PARM_DESC(altsetting, |
| 79 | "Alternative setting for data interface (default: " |
| 80 | __MODULE_STRING(DEFAULT_ALTSETTING) ")"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 82 | module_param(dl_512_first, bool, S_IRUGO | S_IWUSR); |
| 83 | MODULE_PARM_DESC(dl_512_first, |
| 84 | "Read 512 bytes before sending firmware (default: " |
| 85 | __MODULE_STRING(DEFAULT_DL_512_FIRST) ")"); |
| 86 | |
| 87 | module_param(sw_buffering, bool, S_IRUGO | S_IWUSR); |
| 88 | MODULE_PARM_DESC(sw_buffering, |
| 89 | "Enable software buffering (default: " |
| 90 | __MODULE_STRING(DEFAULT_SW_BUFFERING) ")"); |
| 91 | |
| 92 | #define ENDPOINT_INT 0x81 |
| 93 | #define ENDPOINT_DATA 0x07 |
| 94 | #define ENDPOINT_FIRMWARE 0x05 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | #define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) ) |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | struct speedtch_instance_data { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 99 | struct usbatm_data *usbatm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 101 | struct work_struct status_checker; |
| 102 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 103 | unsigned char last_status; |
| 104 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 105 | int poll_delay; /* milliseconds */ |
| 106 | |
| 107 | struct timer_list resubmit_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | struct urb *int_urb; |
| 109 | unsigned char int_data[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 111 | unsigned char scratch_buffer[TOTAL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | /*************** |
| 115 | ** firmware ** |
| 116 | ***************/ |
| 117 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 118 | static void speedtch_set_swbuff(struct speedtch_instance_data *instance, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 120 | struct usbatm_data *usbatm = instance->usbatm; |
| 121 | struct usb_device *usb_dev = usbatm->usb_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | int ret; |
| 123 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 124 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
| 125 | 0x32, 0x40, state ? 0x01 : 0x00, 0x00, NULL, 0, CTRL_TIMEOUT); |
| 126 | if (ret < 0) |
| 127 | usb_warn(usbatm, |
| 128 | "%sabling SW buffering: usb_control_msg returned %d\n", |
| 129 | state ? "En" : "Dis", ret); |
| 130 | else |
| 131 | dbg("speedtch_set_swbuff: %sbled SW buffering", state ? "En" : "Dis"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static void speedtch_test_sequence(struct speedtch_instance_data *instance) |
| 135 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 136 | struct usbatm_data *usbatm = instance->usbatm; |
| 137 | struct usb_device *usb_dev = usbatm->usb_dev; |
| 138 | unsigned char *buf = instance->scratch_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | int ret; |
| 140 | |
| 141 | /* URB 147 */ |
| 142 | buf[0] = 0x1c; |
| 143 | buf[1] = 0x50; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 144 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
| 145 | 0x01, 0x40, 0x0b, 0x00, buf, 2, CTRL_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | if (ret < 0) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 147 | usb_warn(usbatm, "%s failed on URB147: %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | /* URB 148 */ |
| 150 | buf[0] = 0x32; |
| 151 | buf[1] = 0x00; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 152 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
| 153 | 0x01, 0x40, 0x02, 0x00, buf, 2, CTRL_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | if (ret < 0) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 155 | usb_warn(usbatm, "%s failed on URB148: %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | /* URB 149 */ |
| 158 | buf[0] = 0x01; |
| 159 | buf[1] = 0x00; |
| 160 | buf[2] = 0x01; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 161 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
| 162 | 0x01, 0x40, 0x03, 0x00, buf, 3, CTRL_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | if (ret < 0) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 164 | usb_warn(usbatm, "%s failed on URB149: %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | /* URB 150 */ |
| 167 | buf[0] = 0x01; |
| 168 | buf[1] = 0x00; |
| 169 | buf[2] = 0x01; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 170 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
| 171 | 0x01, 0x40, 0x04, 0x00, buf, 3, CTRL_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | if (ret < 0) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 173 | usb_warn(usbatm, "%s failed on URB150: %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 176 | static int speedtch_upload_firmware(struct speedtch_instance_data *instance, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | const struct firmware *fw1, |
| 178 | const struct firmware *fw2) |
| 179 | { |
| 180 | unsigned char *buffer; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 181 | struct usbatm_data *usbatm = instance->usbatm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | struct usb_interface *intf; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 183 | struct usb_device *usb_dev = usbatm->usb_dev; |
| 184 | int actual_length; |
| 185 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | int offset; |
| 187 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 188 | usb_dbg(usbatm, "%s entered\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | if (!(buffer = (unsigned char *)__get_free_page(GFP_KERNEL))) { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 191 | ret = -ENOMEM; |
| 192 | usb_dbg(usbatm, "%s: no memory for buffer!\n", __func__); |
| 193 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 196 | if (!(intf = usb_ifnum_to_if(usb_dev, 2))) { |
| 197 | ret = -ENODEV; |
| 198 | usb_dbg(usbatm, "%s: interface not found!\n", __func__); |
| 199 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /* URB 7 */ |
| 203 | if (dl_512_first) { /* some modems need a read before writing the firmware */ |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 204 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | buffer, 0x200, &actual_length, 2000); |
| 206 | |
| 207 | if (ret < 0 && ret != -ETIMEDOUT) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 208 | usb_dbg(usbatm, "%s: read BLOCK0 from modem failed (%d)!\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | else |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 210 | usb_dbg(usbatm, "%s: BLOCK0 downloaded (%d bytes)\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /* URB 8 : both leds are static green */ |
| 214 | for (offset = 0; offset < fw1->size; offset += PAGE_SIZE) { |
| 215 | int thislen = min_t(int, PAGE_SIZE, fw1->size - offset); |
| 216 | memcpy(buffer, fw1->data + offset, thislen); |
| 217 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 218 | ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | buffer, thislen, &actual_length, DATA_TIMEOUT); |
| 220 | |
| 221 | if (ret < 0) { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 222 | usb_dbg(usbatm, "%s: write BLOCK1 to modem failed (%d)!\n", __func__, ret); |
| 223 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 225 | usb_dbg(usbatm, "%s: BLOCK1 uploaded (%zu bytes)\n", __func__, fw1->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /* USB led blinking green, ADSL led off */ |
| 229 | |
| 230 | /* URB 11 */ |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 231 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | buffer, 0x200, &actual_length, DATA_TIMEOUT); |
| 233 | |
| 234 | if (ret < 0) { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 235 | usb_dbg(usbatm, "%s: read BLOCK2 from modem failed (%d)!\n", __func__, ret); |
| 236 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 238 | usb_dbg(usbatm, "%s: BLOCK2 downloaded (%d bytes)\n", __func__, actual_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | /* URBs 12 to 139 - USB led blinking green, ADSL led off */ |
| 241 | for (offset = 0; offset < fw2->size; offset += PAGE_SIZE) { |
| 242 | int thislen = min_t(int, PAGE_SIZE, fw2->size - offset); |
| 243 | memcpy(buffer, fw2->data + offset, thislen); |
| 244 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 245 | ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | buffer, thislen, &actual_length, DATA_TIMEOUT); |
| 247 | |
| 248 | if (ret < 0) { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 249 | usb_dbg(usbatm, "%s: write BLOCK3 to modem failed (%d)!\n", __func__, ret); |
| 250 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | } |
| 252 | } |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 253 | usb_dbg(usbatm, "%s: BLOCK3 uploaded (%zu bytes)\n", __func__, fw2->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | /* USB led static green, ADSL led static red */ |
| 256 | |
| 257 | /* URB 142 */ |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 258 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | buffer, 0x200, &actual_length, DATA_TIMEOUT); |
| 260 | |
| 261 | if (ret < 0) { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 262 | usb_dbg(usbatm, "%s: read BLOCK4 from modem failed (%d)!\n", __func__, ret); |
| 263 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /* success */ |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 267 | usb_dbg(usbatm, "%s: BLOCK4 downloaded (%d bytes)\n", __func__, actual_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
| 269 | /* Delay to allow firmware to start up. We can do this here |
| 270 | because we're in our own kernel thread anyway. */ |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 271 | msleep_interruptible(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
| 273 | /* Enable software buffering, if requested */ |
| 274 | if (sw_buffering) |
| 275 | speedtch_set_swbuff(instance, 1); |
| 276 | |
| 277 | /* Magic spell; don't ask us what this does */ |
| 278 | speedtch_test_sequence(instance); |
| 279 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 280 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 282 | out_free: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | free_page((unsigned long)buffer); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 284 | out: |
| 285 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 288 | static int speedtch_find_firmware(struct usb_interface *intf, int phase, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | const struct firmware **fw_p) |
| 290 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 291 | struct device *dev = &intf->dev; |
| 292 | const u16 bcdDevice = le16_to_cpu(interface_to_usbdev(intf)->descriptor.bcdDevice); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | const u8 major_revision = bcdDevice >> 8; |
| 294 | const u8 minor_revision = bcdDevice & 0xff; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 295 | char buf[24]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 298 | dev_dbg(dev, "%s: looking for %s\n", __func__, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 300 | if (request_firmware(fw_p, buf, dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 302 | dev_dbg(dev, "%s: looking for %s\n", __func__, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 304 | if (request_firmware(fw_p, buf, dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | sprintf(buf, "speedtch-%d.bin", phase); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 306 | dev_dbg(dev, "%s: looking for %s\n", __func__, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 308 | if (request_firmware(fw_p, buf, dev)) { |
| 309 | dev_warn(dev, "no stage %d firmware found!\n", phase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | return -ENOENT; |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 315 | dev_info(dev, "found stage %d firmware %s\n", phase, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 320 | static int speedtch_heavy_init(struct usbatm_data *usbatm, struct usb_interface *intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | { |
| 322 | const struct firmware *fw1, *fw2; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 323 | struct speedtch_instance_data *instance = usbatm->driver_data; |
| 324 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 326 | if ((ret = speedtch_find_firmware(intf, 1, &fw1)) < 0) |
| 327 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 329 | if ((ret = speedtch_find_firmware(intf, 2, &fw2)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | release_firmware(fw1); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 331 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 334 | ret = speedtch_upload_firmware(instance, fw1, fw2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 336 | release_firmware(fw2); |
| 337 | release_firmware(fw1); |
| 338 | |
| 339 | return ret; |
| 340 | } |
| 341 | |
| 342 | |
| 343 | /********** |
| 344 | ** ATM ** |
| 345 | **********/ |
| 346 | |
| 347 | static int speedtch_read_status(struct speedtch_instance_data *instance) |
| 348 | { |
| 349 | struct usbatm_data *usbatm = instance->usbatm; |
| 350 | struct usb_device *usb_dev = usbatm->usb_dev; |
| 351 | unsigned char *buf = instance->scratch_buffer; |
| 352 | int ret; |
| 353 | |
| 354 | memset(buf, 0, TOTAL); |
| 355 | |
| 356 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 357 | 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7, |
| 358 | CTRL_TIMEOUT); |
| 359 | if (ret < 0) { |
| 360 | atm_dbg(usbatm, "%s: MSG 7 failed\n", __func__); |
| 361 | return ret; |
| 362 | } |
| 363 | |
| 364 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 365 | 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b, |
| 366 | CTRL_TIMEOUT); |
| 367 | if (ret < 0) { |
| 368 | atm_dbg(usbatm, "%s: MSG B failed\n", __func__); |
| 369 | return ret; |
| 370 | } |
| 371 | |
| 372 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 373 | 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d, |
| 374 | CTRL_TIMEOUT); |
| 375 | if (ret < 0) { |
| 376 | atm_dbg(usbatm, "%s: MSG D failed\n", __func__); |
| 377 | return ret; |
| 378 | } |
| 379 | |
| 380 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 381 | 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e, |
| 382 | CTRL_TIMEOUT); |
| 383 | if (ret < 0) { |
| 384 | atm_dbg(usbatm, "%s: MSG E failed\n", __func__); |
| 385 | return ret; |
| 386 | } |
| 387 | |
| 388 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 389 | 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f, |
| 390 | CTRL_TIMEOUT); |
| 391 | if (ret < 0) { |
| 392 | atm_dbg(usbatm, "%s: MSG F failed\n", __func__); |
| 393 | return ret; |
| 394 | } |
| 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | return 0; |
| 397 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 399 | static int speedtch_start_synchro(struct speedtch_instance_data *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 401 | struct usbatm_data *usbatm = instance->usbatm; |
| 402 | struct usb_device *usb_dev = usbatm->usb_dev; |
| 403 | unsigned char *buf = instance->scratch_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 406 | atm_dbg(usbatm, "%s entered\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 408 | memset(buf, 0, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 410 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 411 | 0x12, 0xc0, 0x04, 0x00, |
| 412 | buf, 2, CTRL_TIMEOUT); |
| 413 | |
| 414 | if (ret < 0) |
| 415 | atm_warn(usbatm, "failed to start ADSL synchronisation: %d\n", ret); |
| 416 | else |
| 417 | atm_dbg(usbatm, "%s: modem prodded. %d bytes returned: %02x %02x\n", |
| 418 | __func__, ret, buf[0], buf[1]); |
| 419 | |
| 420 | return ret; |
| 421 | } |
| 422 | |
| 423 | static void speedtch_check_status(struct speedtch_instance_data *instance) |
| 424 | { |
| 425 | struct usbatm_data *usbatm = instance->usbatm; |
| 426 | struct atm_dev *atm_dev = usbatm->atm_dev; |
| 427 | unsigned char *buf = instance->scratch_buffer; |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 428 | int down_speed, up_speed, ret; |
| 429 | unsigned char status; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 430 | |
| 431 | atm_dbg(usbatm, "%s entered\n", __func__); |
| 432 | |
| 433 | ret = speedtch_read_status(instance); |
| 434 | if (ret < 0) { |
| 435 | atm_warn(usbatm, "error %d fetching device status\n", ret); |
Duncan Sands | cd5c08f | 2005-06-23 09:23:10 +0200 | [diff] [blame] | 436 | instance->poll_delay = min(2 * instance->poll_delay, MAX_POLL_DELAY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | return; |
| 438 | } |
| 439 | |
Duncan Sands | cd5c08f | 2005-06-23 09:23:10 +0200 | [diff] [blame] | 440 | instance->poll_delay = max(instance->poll_delay / 2, MIN_POLL_DELAY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 442 | status = buf[OFFSET_7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 444 | atm_dbg(usbatm, "%s: line state %02x\n", __func__, status); |
| 445 | |
| 446 | if ((status != instance->last_status) || !status) { |
| 447 | switch (status) { |
| 448 | case 0: |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 449 | atm_dev->signal = ATM_PHY_SIG_LOST; |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 450 | if (instance->last_status) |
David S. Miller | 52fbae2 | 2005-07-25 19:54:35 -0700 | [diff] [blame] | 451 | atm_info(usbatm, "ADSL line is down\n"); |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 452 | /* It may never resync again unless we ask it to... */ |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 453 | ret = speedtch_start_synchro(instance); |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 454 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 456 | case 0x08: |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 457 | atm_dev->signal = ATM_PHY_SIG_UNKNOWN; |
David S. Miller | 52fbae2 | 2005-07-25 19:54:35 -0700 | [diff] [blame] | 458 | atm_info(usbatm, "ADSL line is blocked?\n"); |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 459 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 461 | case 0x10: |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 462 | atm_dev->signal = ATM_PHY_SIG_LOST; |
David S. Miller | 52fbae2 | 2005-07-25 19:54:35 -0700 | [diff] [blame] | 463 | atm_info(usbatm, "ADSL line is synchronising\n"); |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 464 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 466 | case 0x20: |
| 467 | down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 468 | | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24); |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 469 | up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8) |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 470 | | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 472 | if (!(down_speed & 0x0000ffff) && !(up_speed & 0x0000ffff)) { |
| 473 | down_speed >>= 16; |
| 474 | up_speed >>= 16; |
| 475 | } |
| 476 | |
| 477 | atm_dev->link_rate = down_speed * 1000 / 424; |
| 478 | atm_dev->signal = ATM_PHY_SIG_FOUND; |
| 479 | |
| 480 | atm_info(usbatm, |
Duncan Sands | 322a95b | 2005-06-23 09:20:50 +0200 | [diff] [blame] | 481 | "ADSL line is up (%d kb/s down | %d kb/s up)\n", |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 482 | down_speed, up_speed); |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 483 | break; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 484 | |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 485 | default: |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 486 | atm_dev->signal = ATM_PHY_SIG_UNKNOWN; |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 487 | atm_info(usbatm, "Unknown line state %02x\n", status); |
| 488 | break; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 489 | } |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 490 | |
| 491 | instance->last_status = status; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 492 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 495 | static void speedtch_status_poll(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 497 | struct speedtch_instance_data *instance = (void *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 499 | schedule_work(&instance->status_checker); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 501 | /* The following check is racy, but the race is harmless */ |
| 502 | if (instance->poll_delay < MAX_POLL_DELAY) |
| 503 | mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(instance->poll_delay)); |
| 504 | else |
David S. Miller | 52fbae2 | 2005-07-25 19:54:35 -0700 | [diff] [blame] | 505 | atm_warn(instance->usbatm, "Too many failures - disabling line status polling\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 508 | static void speedtch_resubmit_int(unsigned long data) |
| 509 | { |
| 510 | struct speedtch_instance_data *instance = (void *)data; |
| 511 | struct urb *int_urb = instance->int_urb; |
| 512 | int ret; |
| 513 | |
| 514 | atm_dbg(instance->usbatm, "%s entered\n", __func__); |
| 515 | |
| 516 | if (int_urb) { |
| 517 | ret = usb_submit_urb(int_urb, GFP_ATOMIC); |
| 518 | if (!ret) |
| 519 | schedule_work(&instance->status_checker); |
| 520 | else { |
| 521 | atm_dbg(instance->usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret); |
| 522 | mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY)); |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | static void speedtch_handle_int(struct urb *int_urb, struct pt_regs *regs) |
| 528 | { |
| 529 | struct speedtch_instance_data *instance = int_urb->context; |
| 530 | struct usbatm_data *usbatm = instance->usbatm; |
| 531 | unsigned int count = int_urb->actual_length; |
| 532 | int ret = int_urb->status; |
| 533 | |
| 534 | /* The magic interrupt for "up state" */ |
| 535 | const static unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 }; |
| 536 | /* The magic interrupt for "down state" */ |
| 537 | const static unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
| 538 | |
| 539 | atm_dbg(usbatm, "%s entered\n", __func__); |
| 540 | |
| 541 | if (ret < 0) { |
| 542 | atm_dbg(usbatm, "%s: nonzero urb status %d!\n", __func__, ret); |
| 543 | goto fail; |
| 544 | } |
| 545 | |
| 546 | if ((count == 6) && !memcmp(up_int, instance->int_data, 6)) { |
| 547 | del_timer(&instance->status_checker.timer); |
David S. Miller | 52fbae2 | 2005-07-25 19:54:35 -0700 | [diff] [blame] | 548 | atm_info(usbatm, "DSL line goes up\n"); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 549 | } else if ((count == 6) && !memcmp(down_int, instance->int_data, 6)) { |
David S. Miller | 52fbae2 | 2005-07-25 19:54:35 -0700 | [diff] [blame] | 550 | atm_info(usbatm, "DSL line goes down\n"); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 551 | } else { |
| 552 | int i; |
| 553 | |
| 554 | atm_dbg(usbatm, "%s: unknown interrupt packet of length %d:", __func__, count); |
| 555 | for (i = 0; i < count; i++) |
| 556 | printk(" %02x", instance->int_data[i]); |
| 557 | printk("\n"); |
| 558 | goto fail; |
| 559 | } |
| 560 | |
| 561 | if ((int_urb = instance->int_urb)) { |
| 562 | ret = usb_submit_urb(int_urb, GFP_ATOMIC); |
| 563 | schedule_work(&instance->status_checker); |
| 564 | if (ret < 0) { |
| 565 | atm_dbg(usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret); |
| 566 | goto fail; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | return; |
| 571 | |
| 572 | fail: |
| 573 | if ((int_urb = instance->int_urb)) |
| 574 | mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY)); |
| 575 | } |
| 576 | |
| 577 | static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_dev) |
| 578 | { |
| 579 | struct usb_device *usb_dev = usbatm->usb_dev; |
| 580 | struct speedtch_instance_data *instance = usbatm->driver_data; |
| 581 | int i, ret; |
| 582 | unsigned char mac_str[13]; |
| 583 | |
| 584 | atm_dbg(usbatm, "%s entered\n", __func__); |
| 585 | |
| 586 | if ((ret = usb_set_interface(usb_dev, 1, altsetting)) < 0) { |
| 587 | atm_dbg(usbatm, "%s: usb_set_interface returned %d!\n", __func__, ret); |
| 588 | return ret; |
| 589 | } |
| 590 | |
| 591 | /* Set MAC address, it is stored in the serial number */ |
| 592 | memset(atm_dev->esi, 0, sizeof(atm_dev->esi)); |
| 593 | if (usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) { |
| 594 | for (i = 0; i < 6; i++) |
| 595 | atm_dev->esi[i] = (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1])); |
| 596 | } |
| 597 | |
| 598 | /* Start modem synchronisation */ |
| 599 | ret = speedtch_start_synchro(instance); |
| 600 | |
| 601 | /* Set up interrupt endpoint */ |
| 602 | if (instance->int_urb) { |
| 603 | ret = usb_submit_urb(instance->int_urb, GFP_KERNEL); |
| 604 | if (ret < 0) { |
| 605 | /* Doesn't matter; we'll poll anyway */ |
| 606 | atm_dbg(usbatm, "%s: submission of interrupt URB failed (%d)!\n", __func__, ret); |
| 607 | usb_free_urb(instance->int_urb); |
| 608 | instance->int_urb = NULL; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | /* Start status polling */ |
| 613 | mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(1000)); |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | static void speedtch_atm_stop(struct usbatm_data *usbatm, struct atm_dev *atm_dev) |
| 619 | { |
| 620 | struct speedtch_instance_data *instance = usbatm->driver_data; |
| 621 | struct urb *int_urb = instance->int_urb; |
| 622 | |
| 623 | atm_dbg(usbatm, "%s entered\n", __func__); |
| 624 | |
| 625 | del_timer_sync(&instance->status_checker.timer); |
| 626 | |
| 627 | /* |
| 628 | * Since resubmit_timer and int_urb can schedule themselves and |
| 629 | * each other, shutting them down correctly takes some care |
| 630 | */ |
| 631 | instance->int_urb = NULL; /* signal shutdown */ |
| 632 | mb(); |
| 633 | usb_kill_urb(int_urb); |
| 634 | del_timer_sync(&instance->resubmit_timer); |
| 635 | /* |
| 636 | * At this point, speedtch_handle_int and speedtch_resubmit_int |
| 637 | * can run or be running, but instance->int_urb == NULL means that |
| 638 | * they will not reschedule |
| 639 | */ |
| 640 | usb_kill_urb(int_urb); |
| 641 | del_timer_sync(&instance->resubmit_timer); |
| 642 | usb_free_urb(int_urb); |
| 643 | |
| 644 | flush_scheduled_work(); |
| 645 | } |
| 646 | |
| 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | /********** |
| 649 | ** USB ** |
| 650 | **********/ |
| 651 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 652 | static struct usb_device_id speedtch_usb_ids[] = { |
| 653 | {USB_DEVICE(0x06b9, 0x4061)}, |
| 654 | {} |
| 655 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 657 | MODULE_DEVICE_TABLE(usb, speedtch_usb_ids); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 659 | static int speedtch_usb_probe(struct usb_interface *, const struct usb_device_id *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 661 | static struct usb_driver speedtch_usb_driver = { |
| 662 | .owner = THIS_MODULE, |
| 663 | .name = speedtch_driver_name, |
| 664 | .probe = speedtch_usb_probe, |
| 665 | .disconnect = usbatm_usb_disconnect, |
| 666 | .id_table = speedtch_usb_ids |
| 667 | }; |
| 668 | |
| 669 | static void speedtch_release_interfaces(struct usb_device *usb_dev, int num_interfaces) { |
| 670 | struct usb_interface *cur_intf; |
| 671 | int i; |
| 672 | |
| 673 | for(i = 0; i < num_interfaces; i++) |
| 674 | if ((cur_intf = usb_ifnum_to_if(usb_dev, i))) { |
| 675 | usb_set_intfdata(cur_intf, NULL); |
| 676 | usb_driver_release_interface(&speedtch_usb_driver, cur_intf); |
| 677 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 680 | static int speedtch_bind(struct usbatm_data *usbatm, |
| 681 | struct usb_interface *intf, |
| 682 | const struct usb_device_id *id, |
| 683 | int *need_heavy_init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 685 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
| 686 | struct usb_interface *cur_intf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | struct speedtch_instance_data *instance; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 688 | int ifnum = intf->altsetting->desc.bInterfaceNumber; |
| 689 | int num_interfaces = usb_dev->actconfig->desc.bNumInterfaces; |
| 690 | int i, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 692 | usb_dbg(usbatm, "%s entered\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 694 | if (usb_dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) { |
| 695 | usb_dbg(usbatm, "%s: wrong device class %d\n", __func__, usb_dev->descriptor.bDeviceClass); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | return -ENODEV; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 697 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 699 | /* claim all interfaces */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 701 | for (i=0; i < num_interfaces; i++) { |
| 702 | cur_intf = usb_ifnum_to_if(usb_dev, i); |
| 703 | |
| 704 | if ((i != ifnum) && cur_intf) { |
| 705 | ret = usb_driver_claim_interface(&speedtch_usb_driver, cur_intf, usbatm); |
| 706 | |
| 707 | if (ret < 0) { |
| 708 | usb_dbg(usbatm, "%s: failed to claim interface %d (%d)\n", __func__, i, ret); |
| 709 | speedtch_release_interfaces(usb_dev, i); |
| 710 | return ret; |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | instance = kmalloc(sizeof(*instance), GFP_KERNEL); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | if (!instance) { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 718 | usb_dbg(usbatm, "%s: no memory for instance data!\n", __func__); |
| 719 | ret = -ENOMEM; |
| 720 | goto fail_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | memset(instance, 0, sizeof(struct speedtch_instance_data)); |
| 724 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 725 | instance->usbatm = usbatm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 727 | INIT_WORK(&instance->status_checker, (void *)speedtch_check_status, instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 729 | instance->status_checker.timer.function = speedtch_status_poll; |
| 730 | instance->status_checker.timer.data = (unsigned long)instance; |
Duncan Sands | 1a7aad1 | 2005-06-23 09:37:56 +0200 | [diff] [blame] | 731 | instance->last_status = 0xff; |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 732 | instance->poll_delay = MIN_POLL_DELAY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 734 | init_timer(&instance->resubmit_timer); |
| 735 | instance->resubmit_timer.function = speedtch_resubmit_int; |
| 736 | instance->resubmit_timer.data = (unsigned long)instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 738 | instance->int_urb = usb_alloc_urb(0, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 740 | if (instance->int_urb) |
| 741 | usb_fill_int_urb(instance->int_urb, usb_dev, |
| 742 | usb_rcvintpipe(usb_dev, ENDPOINT_INT), |
| 743 | instance->int_data, sizeof(instance->int_data), |
| 744 | speedtch_handle_int, instance, 50); |
| 745 | else |
| 746 | usb_dbg(usbatm, "%s: no memory for interrupt urb!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 748 | /* check whether the modem already seems to be alive */ |
| 749 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
| 750 | 0x12, 0xc0, 0x07, 0x00, |
| 751 | instance->scratch_buffer + OFFSET_7, SIZE_7, 500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 753 | *need_heavy_init = (ret != SIZE_7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 755 | usb_dbg(usbatm, "%s: firmware %s loaded\n", __func__, need_heavy_init ? "not" : "already"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 757 | if (*need_heavy_init) |
| 758 | if ((ret = usb_reset_device(usb_dev)) < 0) |
| 759 | goto fail_free; |
| 760 | |
| 761 | usbatm->driver_data = instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | |
| 763 | return 0; |
| 764 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 765 | fail_free: |
| 766 | usb_free_urb(instance->int_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | kfree(instance); |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 768 | fail_release: |
| 769 | speedtch_release_interfaces(usb_dev, num_interfaces); |
| 770 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 773 | static void speedtch_unbind(struct usbatm_data *usbatm, struct usb_interface *intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 775 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
| 776 | struct speedtch_instance_data *instance = usbatm->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 778 | usb_dbg(usbatm, "%s entered\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 780 | speedtch_release_interfaces(usb_dev, usb_dev->actconfig->desc.bNumInterfaces); |
| 781 | usb_free_urb(instance->int_urb); |
| 782 | kfree(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 785 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | /*********** |
| 787 | ** init ** |
| 788 | ***********/ |
| 789 | |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 790 | static struct usbatm_driver speedtch_usbatm_driver = { |
| 791 | .owner = THIS_MODULE, |
| 792 | .driver_name = speedtch_driver_name, |
| 793 | .bind = speedtch_bind, |
| 794 | .heavy_init = speedtch_heavy_init, |
| 795 | .unbind = speedtch_unbind, |
| 796 | .atm_start = speedtch_atm_start, |
| 797 | .atm_stop = speedtch_atm_stop, |
| 798 | .in = ENDPOINT_DATA, |
| 799 | .out = ENDPOINT_DATA |
| 800 | }; |
| 801 | |
| 802 | static int speedtch_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 803 | { |
| 804 | return usbatm_usb_probe(intf, id, &speedtch_usbatm_driver); |
| 805 | } |
| 806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | static int __init speedtch_usb_init(void) |
| 808 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 809 | dbg("%s: driver version %s", __func__, DRIVER_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
| 811 | return usb_register(&speedtch_usb_driver); |
| 812 | } |
| 813 | |
| 814 | static void __exit speedtch_usb_cleanup(void) |
| 815 | { |
Duncan Sands | 48da726 | 2005-05-11 20:20:40 +0200 | [diff] [blame] | 816 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
| 818 | usb_deregister(&speedtch_usb_driver); |
| 819 | } |
| 820 | |
| 821 | module_init(speedtch_usb_init); |
| 822 | module_exit(speedtch_usb_cleanup); |
| 823 | |
| 824 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 825 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 826 | MODULE_LICENSE("GPL"); |
| 827 | MODULE_VERSION(DRIVER_VERSION); |