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